voipplugins/sipconnectionprovider/ipvoicemailengine/src/ipvmbxeventmonitor.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Monitors Events from VoiceMailBox -server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <mcetransactiondatacontainer.h>
       
    21 #include <mceevent.h>
       
    22 #include <siperr.h>
       
    23 
       
    24 #include "ipvmbxeventmonitor.h"
       
    25 #include "ipvmbxengine.h"
       
    26 #include "ipvmbxlogger.h"
       
    27 #include "ipvmbxpanic.h"
       
    28 #include "ipvmbxbase.h"
       
    29 #include "ipvmbxconstants.h"
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ==============================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 TIpVmbxEventMonitor::TIpVmbxEventMonitor( CIpVmbxEngine& aEngine ) :
       
    40     iEngine( aEngine )
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // 
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 void TIpVmbxEventMonitor::EventStateChanged(
       
    50     CMceEvent& aEvent,
       
    51     TMceTransactionDataContainer* /*aContainer*/ )
       
    52     {
       
    53     IPVMEPRINT2( 
       
    54         "CIpVmbxEventMonitor::EventStateChanged: %d", 
       
    55         aEvent.State() );
       
    56     
       
    57     CIpVmbxBase* subscription( 
       
    58         iEngine.SubscriptionByRecipient( aEvent.Recipient() ) );
       
    59     if ( subscription )
       
    60         {
       
    61         CIpVmbxEngine::TIpVmbxMessages message = 
       
    62             CIpVmbxEngine::EEngineUndefined;
       
    63         
       
    64         switch ( aEvent.State() )
       
    65             {
       
    66             case CMceEvent::ETerminated:
       
    67                 {
       
    68                 if ( CIpVmbxBase::ETerminating == subscription->State() )
       
    69                     {
       
    70                     IPVMEPRINT( 
       
    71                         "CIpVmbxEventMonitor state: CMceEvent::ETerminated" );
       
    72                     // Normal unsubscription case
       
    73                     message = CIpVmbxEngine::EEngineTerminated;
       
    74                     }
       
    75                 else 
       
    76                     if ( CIpVmbxBase::ERegistered == subscription->State() )
       
    77                         {
       
    78                         // Network stops responding
       
    79                         message = CIpVmbxEngine::EEngineNetworkLost;
       
    80                         }
       
    81                     else
       
    82                         {
       
    83                         // Network does not accept subscription
       
    84                         message = CIpVmbxEngine::EEngineSubscribeRejected;
       
    85                         }
       
    86                 break;
       
    87                 }
       
    88             case CMceEvent::EPending:
       
    89                 // Occures on rare 
       
    90                 message = CIpVmbxEngine::EEngineSubscribeRejected;
       
    91                 break;
       
    92             case CMceEvent::EActive:
       
    93             case CMceEvent::EIdle:
       
    94                 {
       
    95                 // This should never happen
       
    96                 message = CIpVmbxEngine::EEngineUndefined;
       
    97                 break;
       
    98                 }                
       
    99             default:
       
   100                 IPVMEPRINT( "Unhandled message!" );
       
   101             }
       
   102     
       
   103         iEngine.HandleMessage( subscription->ServiceProviderId(), message );
       
   104         }
       
   105     }
       
   106 
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // 
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 void TIpVmbxEventMonitor::NotifyReceived(
       
   113     CMceEvent& aEvent,
       
   114     TMceTransactionDataContainer* /*aContainer*/ )
       
   115     {
       
   116     IPVMEPRINT( "CIpVmbxEventMonitor::NotifyReceived - IN" );
       
   117     CMceEvent::TState eventState( CMceEvent::EIdle );
       
   118     eventState = aEvent.State();
       
   119     TBool firstNotify = EFalse;
       
   120 
       
   121     CIpVmbxBase* subscription( 
       
   122         iEngine.SubscriptionByRecipient( aEvent.Recipient() ) );
       
   123     if ( subscription )
       
   124         {
       
   125         CIpVmbxEngine::TIpVmbxMessages message = 
       
   126             CIpVmbxEngine::EEngineUndefined;
       
   127         
       
   128         switch ( eventState )
       
   129             {
       
   130             case CMceEvent::EActive:
       
   131                 {
       
   132                 IPVMEPRINT( 
       
   133                     "CIpVmbxEventMonitor state: CMceEvent::EActive" );
       
   134                 if ( CIpVmbxBase::ETerminating != subscription->State() && 
       
   135                     CIpVmbxBase::ERegistered != subscription->State() )
       
   136                     {
       
   137                     
       
   138                     subscription->SetStateRegistered();
       
   139                     IPVMEPRINT( "CIpVmbxEventMonitor::NotifyReceived - firstNotify" );
       
   140                     firstNotify = ETrue;
       
   141                     }
       
   142     
       
   143                 TRAPD( err, iEngine.EventReceivedL( aEvent.Recipient() ) );
       
   144                 if ( err )
       
   145                     {
       
   146                     if ( KErrNoMemory == err )
       
   147                         {
       
   148                         message = CIpVmbxEngine::EEngineSmsOom;
       
   149                         }
       
   150                     else
       
   151                         {
       
   152                         message = CIpVmbxEngine::EEngineSmsError;
       
   153                         }
       
   154                     }
       
   155                 else if ( firstNotify )
       
   156                     {
       
   157                     message = CIpVmbxEngine::EEngineSubscribed;
       
   158                     }
       
   159                 else
       
   160                     {
       
   161                     message = CIpVmbxEngine::EEngineUndefined;
       
   162                     }
       
   163                 }
       
   164                 break;
       
   165             case CMceEvent::ETerminated:
       
   166             // flow through
       
   167             case CMceEvent::EIdle:
       
   168             // flow through
       
   169             case CMceEvent::EPending:
       
   170             // flow through
       
   171             default:
       
   172                 IPVMEPRINT( "Unhandled message!" );
       
   173             }
       
   174         
       
   175         iEngine.HandleMessage( subscription->ServiceProviderId(), message );
       
   176         }
       
   177     }
       
   178 
       
   179 
       
   180 // ----------------------------------------------------------------------------
       
   181 // 
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 void TIpVmbxEventMonitor::EventConnectionStateChanged( 
       
   185                     CMceEvent& /*aEvent*/, 
       
   186                     TBool /*aActive*/ )
       
   187     {
       
   188     IPVMEPRINT( "CIpVmbxEventMonitor::EventConnectionStateChanged" );
       
   189     }
       
   190 
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // 
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 void TIpVmbxEventMonitor::Failed( CMceEvent& aEvent, TInt aError )
       
   197     {
       
   198     IPVMEPRINT2( "CIpVmbxEventMonitor::Failed: %d", aError );
       
   199     CIpVmbxBase* subscription( 
       
   200         iEngine.SubscriptionByRecipient( aEvent.Recipient() ) );
       
   201     if ( subscription )
       
   202         {
       
   203         CIpVmbxEngine::TIpVmbxMessages message = 
       
   204             CIpVmbxEngine::EEngineUndefined;
       
   205         
       
   206         switch ( aError )
       
   207             {
       
   208             case KErrSIPTransportFailure:
       
   209                 message = CIpVmbxEngine::EEngineIncorrectAccount;
       
   210                 break;
       
   211             case KErrTimedOut:
       
   212                 message = CIpVmbxEngine::EEngineSubscribeRejected;
       
   213                 break;
       
   214             case KErrSIPResolvingFailure:
       
   215                 message = CIpVmbxEngine::EEngineFatalNetworkError;
       
   216                 break;              
       
   217             default:
       
   218                 message = CIpVmbxEngine::EEngineNetworkError;
       
   219             }
       
   220     
       
   221         iEngine.HandleMessage( subscription->ServiceProviderId(), message );
       
   222         }
       
   223     }