phoneplugins/csplugin/src/cspaudiohandler.cpp
changeset 65 2a5d4ab426d3
parent 37 ba76fc04e6c2
equal deleted inserted replaced
60:1eef62f5c541 65:2a5d4ab426d3
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "cspaudiohandler.h"
    18 #include "cspaudiohandler.h"
    19 #include "tmshandler.h"
    19 #include "tmshandler.h"
       
    20 #include "csptimer.h"
    20 #include "csplogger.h"
    21 #include "csplogger.h"
       
    22 #include "mcspaudiohandlerobserver.h"
    21 
    23 
    22 // ---------------------------------------------------------------------------
    24 // ---------------------------------------------------------------------------
    23 // CSPAudioHandler::NewL.
    25 // CSPAudioHandler::NewL.
    24 // ---------------------------------------------------------------------------
    26 // ---------------------------------------------------------------------------
    25 //
    27 //
    26 CSPAudioHandler* CSPAudioHandler::NewL()
    28 CSPAudioHandler* CSPAudioHandler::NewL()
    27     {
    29     {
    28     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::NewL()" );
    30     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::NewL()");
    29     CSPAudioHandler* self = new (ELeave) CSPAudioHandler();
    31     CSPAudioHandler* self = new (ELeave) CSPAudioHandler();
    30     CleanupStack::PushL(self);
    32     CleanupStack::PushL(self);
    31     self->ConstructL();
    33     self->ConstructL();
    32     CleanupStack::Pop(self);
    34     CleanupStack::Pop(self);
    33     return self;
    35     return self;
    37 // Destructs the object by canceling first ongoing monitoring.
    39 // Destructs the object by canceling first ongoing monitoring.
    38 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    39 //
    41 //
    40 CSPAudioHandler::~CSPAudioHandler()
    42 CSPAudioHandler::~CSPAudioHandler()
    41     {
    43     {
    42     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::~CSPAudioHandler()" );
    44     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::~CSPAudioHandler()");
       
    45     if (iTimer)
       
    46         {
       
    47         iTimer->CancelNotify();
       
    48         delete iTimer;
       
    49         }
    43     delete iTmsHandler;
    50     delete iTmsHandler;
    44     }
    51     }
    45 
    52 
    46 // ---------------------------------------------------------------------------
    53 // ---------------------------------------------------------------------------
       
    54 // CSPAudioHandler::SetObserver
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CSPAudioHandler::SetObserver(MCSPAudioHandlerObserver& aObserver)
       
    58     {
       
    59     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::SetObserver()");
       
    60     iObserver = &aObserver;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
    47 // CSPAudioHandler::Start
    64 // CSPAudioHandler::Start
       
    65 // Note: Client must pass the observer through SetObserver() prior to calling
       
    66 // Start(), otherwise MTmsHandlerObserver callbacks will be missed.
    48 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    49 //
    68 //
    50 void CSPAudioHandler::Start()
    69 void CSPAudioHandler::Start()
    51     {
    70     {
    52     iCallCount++;
    71     iCallCount++;
    53     CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Start callcount: %d", iCallCount);
    72     CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Start callcount: %d", iCallCount);
    54 
       
    55     if (iTmsHandler && iCallCount == 1)
    73     if (iTmsHandler && iCallCount == 1)
    56         {
    74         {
    57         iTmsHandler->StartStreams();
    75         TInt err = iTmsHandler->StartStreams();
       
    76         if (err != KErrNone)
       
    77             {
       
    78             AudioStreamsError(err);
       
    79             }
    58         }
    80         }
    59     }
    81     }
    60 
    82 
    61 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    62 // CSPAudioHandler::Stop
    84 // CSPAudioHandler::Stop
    63 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    64 //
    86 //
    65 void CSPAudioHandler::Stop()
    87 void CSPAudioHandler::Stop()
    66     {
    88     {
    67     CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Stop callcount: %d", iCallCount);
    89     CSPLOGSTRING2(CSPINT, "CSPAudioHandler::Stop callcount: %d", iCallCount);
       
    90     if (iTimer)
       
    91         {
       
    92         iTimer->CancelNotify();
       
    93         }
    68     if (iTmsHandler && iCallCount == 1)
    94     if (iTmsHandler && iCallCount == 1)
    69         {
    95         {
    70         iTmsHandler->StopStreams();
    96         iTmsHandler->StopStreams();
    71         iCallCount--;
    97         iCallCount--;
    72         }
    98         }
    75         iCallCount--;
   101         iCallCount--;
    76         }
   102         }
    77     }
   103     }
    78 
   104 
    79 // ---------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------
       
   106 // CSPAudioHandler::ReportAudioFailureAfterTimeout
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CSPAudioHandler::ReportAudioFailureAfterTimeout(TInt aTimeout)
       
   110     {
       
   111     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::ReportAudioFailureAfterTimeout()");
       
   112 
       
   113     if (iTmsHandler)
       
   114         {
       
   115         // Make sure audio streams are not already active, so we don't
       
   116         // accidentaly hangup the call by setting the timer.
       
   117         if (iTimer && !iTmsHandler->AreStreamsStarted())
       
   118             {
       
   119             if (iTimer->IsNotifyOngoing())
       
   120                 {
       
   121                 iTimer->CancelNotify();
       
   122                 }
       
   123             iTimer->NotifyAfter(aTimeout, *this);
       
   124             }
       
   125         }
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CSPAudioHandler::AudioStreamsStarted
       
   130 // From MTmsHandlerObserver
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CSPAudioHandler::AudioStreamsStarted()
       
   134     {
       
   135     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::AudioStreamsStarted()");
       
   136     if (iTimer)
       
   137         {
       
   138         iTimer->CancelNotify();
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CSPAudioHandler::AudioStreamsError
       
   144 // From MTmsHandlerObserver
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CSPAudioHandler::AudioStreamsError(TInt /*aError*/)
       
   148     {
       
   149     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::AudioStreamsError()");
       
   150     if (iTimer)
       
   151         {
       
   152         iTimer->CancelNotify();
       
   153         }
       
   154 
       
   155     // Note: The observer must be provided in SetObserver() prior to Start()
       
   156     // request, otherwise error conditions will not be propagated to the client.
       
   157     if (iObserver)
       
   158         {
       
   159         iObserver->AudioStartingFailed();
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSPAudioHandler::TimerEvent
       
   165 // From MCSPTimerObserver
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CSPAudioHandler::TimerEvent()
       
   169     {
       
   170     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::TimerEvent()");
       
   171     if (iObserver)
       
   172         {
       
   173         iObserver->AudioStartingFailed();
       
   174         }
       
   175     if (iTmsHandler)
       
   176         {
       
   177         iTmsHandler->StopStreams();
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
    80 // Constructs the monitor.
   182 // Constructs the monitor.
    81 // ---------------------------------------------------------------------------
   183 // ---------------------------------------------------------------------------
    82 //
   184 //
    83 CSPAudioHandler::CSPAudioHandler()
   185 CSPAudioHandler::CSPAudioHandler()
    84     {
   186     {
    90 // Second phase construction.
   192 // Second phase construction.
    91 // ---------------------------------------------------------------------------
   193 // ---------------------------------------------------------------------------
    92 //
   194 //
    93 void CSPAudioHandler::ConstructL()
   195 void CSPAudioHandler::ConstructL()
    94     {
   196     {
    95     if (!iTmsHandler)
   197     CSPLOGSTRING(CSPOBJECT, "CSPAudioHandler::ConstructL()");
    96         {
   198     iTmsHandler = TmsHandler::NewL(*this);
    97         iTmsHandler = TmsHandler::NewL();
   199     iTimer = CSPTimer::NewL();
    98         }
       
    99     }
   200     }
   100 
   201 
   101 // End of file
   202 // End of file