phoneengine/servicehandling/src/cpeservicehandling.cpp
branchRCL_3
changeset 24 41a7f70b3818
parent 6 38529f706030
child 25 5266b1f337bd
equal deleted inserted replaced
23:40a3f856b14d 24:41a7f70b3818
    18 
    18 
    19 #include <mpephonemodelinternal.h>
    19 #include <mpephonemodelinternal.h>
    20 #include <mpedatastore.h>
    20 #include <mpedatastore.h>
    21 #include <pevirtualengine.h>
    21 #include <pevirtualengine.h>
    22 #include <e32debug.h>
    22 #include <e32debug.h>
    23 #include <talogger.h>
       
    24 
    23 
       
    24 #include "talogger.h"
    25 #include "cpeservicehandling.h"
    25 #include "cpeservicehandling.h"
    26 
    26 
    27 // ======== MEMBER FUNCTIONS ========
    27 // ======== MEMBER FUNCTIONS ========
    28 
    28 
    29 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    74 //
    74 //
    75 EXPORT_C CPEServiceHandling::~CPEServiceHandling()
    75 EXPORT_C CPEServiceHandling::~CPEServiceHandling()
    76     {
    76     {
    77     TEFLOGSTRING( KTAOBJECT, "PE CPEServiceHandling::~CPEServiceHandling" );
    77     TEFLOGSTRING( KTAOBJECT, "PE CPEServiceHandling::~CPEServiceHandling" );
    78     delete iCchClient;
       
    79     }
    78     }
    80 
    79 
    81 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    82 // CPEServiceHandling::EnableService
    81 // CPEServiceHandling::EnableService
    83 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    84 //
    83 //
    85 void CPEServiceHandling::EnableServiceL( TInt aServiceId )
    84 void CPEServiceHandling::EnableServiceL( TInt /*aServiceId*/ )
    86 	{
    85     {
    87     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::EnableServiceL" );
    86     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::EnableServiceL" );
    88 	
    87     User::LeaveIfError( 0 );
    89     if ( !iCchClient )
    88     iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabled );
    90         {
       
    91         iCchClient = CCch::NewL();
       
    92         }
       
    93 
       
    94 	CCchService* service = iCchClient->GetService( aServiceId );
       
    95 	
       
    96 	TInt error( KErrNotFound );
       
    97 	if( service )
       
    98 		{
       
    99 		iCurrentServiceId = aServiceId;
       
   100 		
       
   101 		TCchServiceStatus serviceStatus;
       
   102  		error = service->GetStatus( ECCHVoIPSub, serviceStatus );
       
   103 		TCCHSubserviceState state = serviceStatus.State();
       
   104 	
       
   105 		if( error == KErrNone )
       
   106 		    {
       
   107 		    if ( serviceStatus.Error() == KErrNone )
       
   108 		        {
       
   109 		        error = EnableServiceIfNeeded( state, *service );
       
   110 		        }
       
   111 		    else
       
   112 		        {
       
   113 		        TEFLOGSTRING2( KTAERROR,
       
   114 		                "PE CPEServiceHandling::EnableServiceL, error: %d"
       
   115 		                , serviceStatus.Error() );
       
   116 		        SendErrorMessage( serviceStatus.Error());
       
   117 		        }
       
   118     		}
       
   119 		}
       
   120 	
       
   121 	if ( error != KErrNone )
       
   122 	    {
       
   123 	    if ( error == KErrNotFound )
       
   124 	         {
       
   125 	         iModel.SendMessage( MEngineMonitor::EPEMessageNoService );
       
   126 	         }
       
   127 	     else
       
   128 	         {
       
   129 	         TEFLOGSTRING2( KTAERROR,
       
   130 	                  "PE CPEServiceHandling::EnableServiceL, Error: %d"
       
   131 	                  , error );
       
   132 	         SendErrorMessage( error );
       
   133 	       
       
   134              iCurrentServiceId = KErrNotFound;
       
   135              service->RemoveObserver( *this );	
       
   136 	         }
       
   137 	    }
       
   138 	
       
   139 	TEFLOGSTRING2( KTAINT, 
       
   140             "PE CPEServiceHandling::EnableServiceL, error: %d", error );		
       
   141 	}
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CPEServiceHandling::EnableServiceIfNeeded
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CPEServiceHandling::EnableServiceIfNeeded( 
       
   148         const TCCHSubserviceState& aState, 
       
   149         CCchService& aService )
       
   150     {
       
   151     TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::EnableServiceIfNeeded" );
       
   152     TInt error = KErrNone;
       
   153     
       
   154     TEFLOGSTRING2( KTAINT, 
       
   155             "PE CPEServiceHandling::EnableServiceIfNeeded, aState: %d", aState );
       
   156     switch ( aState )
       
   157         {
       
   158         case ECCHEnabled:
       
   159             {
       
   160             iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabled );
       
   161             }
       
   162             break;
       
   163         case ECCHUninitialized:
       
   164         case ECCHDisabled:
       
   165         case ECCHConnecting:
       
   166             {
       
   167             // Temporary solution, it will be fixed as soon as possible. 
       
   168             // Message have to send before enable is called. Reason is so that progress bar 
       
   169             //(global note) doesn't hide Networks's "Connection Needed" global note.
       
   170             iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabling );
       
   171             aService.AddObserver( *this );
       
   172             error = aService.Enable( ECCHUnknown );  
       
   173             }
       
   174             break;
       
   175         case ECCHDisconnecting:
       
   176             {
       
   177             error = KErrNotFound;
       
   178             }
       
   179             break;
       
   180         default:
       
   181             break;
       
   182         }
       
   183     TEFLOGSTRING2( KTAINT, 
       
   184             "PE CPEServiceHandling::EnableServiceIfNeeded, error: %d", error );
       
   185     return error;
       
   186     }
    89     }
   187     
    90     
   188 // ---------------------------------------------------------------------------
       
   189 // CPEServiceHandling::ServiceStatusChanged
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CPEServiceHandling::ServiceStatusChanged(
       
   193     TInt aServiceId,
       
   194 	const TCCHSubserviceType aType,
       
   195 	const TCchServiceStatus& aServiceStatus )
       
   196 	{
       
   197 	TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::ServiceStatusChanged <" );
       
   198 	
       
   199 	if( aServiceId == iCurrentServiceId && aType == ECCHVoIPSub )
       
   200 	    {
       
   201     	TEFLOGSTRING3( KTAINT,
       
   202     	        "PE CPEServiceHandling::ServiceStatusChanged, state: %d, error: %d"
       
   203     	        , aServiceStatus.State()
       
   204     	        , aServiceStatus.Error() );
       
   205 
       
   206        	CCchService* service = iCchClient->GetService( aServiceId );
       
   207        	if( service )
       
   208        	    {
       
   209     	    if( aServiceStatus.Error() != KErrNone )
       
   210     	        {
       
   211     	        TEFLOGSTRING( KTAERROR, 
       
   212     	                "PE CPEServiceHandling::ServiceStatusChanged, error" );
       
   213     	        SendErrorMessage( aServiceStatus.Error());
       
   214     	        CancelServiceEnabling();
       
   215     	        }
       
   216     	    else 
       
   217     	        {
       
   218     	        if( aServiceStatus.State() == ECCHEnabled )
       
   219     	            {
       
   220                     TEFLOGSTRING( KTAINT, 
       
   221                              "PE CPEServiceHandling::ServiceStatusChanged, enabled" );
       
   222                     iModel.SendMessage( MEngineMonitor::EPEMessageServiceEnabled );
       
   223     	            }
       
   224 
       
   225 
       
   226     	        // Notify UI, that service is disabled.
       
   227     	        else if( aServiceStatus.State() == ECCHDisabled ) 
       
   228                      {
       
   229                      TEFLOGSTRING( KTAERROR, 
       
   230                               "PE CPEServiceHandling::ServiceStatusChanged, disabled" );
       
   231                      iModel.SendMessage( MEngineMonitor::EPEMessageServiceDisabled );
       
   232                      }
       
   233     	        }
       
   234     	    
       
   235     	    // don't remove observer, if state are connecting or disconnecting
       
   236     	    if ( aServiceStatus.State() != ECCHConnecting && 
       
   237     	         aServiceStatus.State() != ECCHDisconnecting )
       
   238     	        {
       
   239     	        service->RemoveObserver( *this );
       
   240     	        }
       
   241        	    }//if( service )
       
   242        	else
       
   243        	    {
       
   244             TEFLOGSTRING( KTAERROR, 
       
   245                     "PE CPEServiceHandling::ServiceStatusChanged, no service" );
       
   246        	    }
       
   247 	    }
       
   248 	TEFLOGSTRING( KTAINT, "PE CPEServiceHandling::ServiceStatusChanged >" );
       
   249 	}
       
   250 	
       
   251 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
   252 // CPEServiceHandling::CancelServiceEnabling
    92 // CPEServiceHandling::CancelServiceEnabling
   253 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
   254 //
    94 //
   255 void CPEServiceHandling::CancelServiceEnabling() const
    95 void CPEServiceHandling::CancelServiceEnabling() const
   256     {
    96     {
   257     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::CancelServiceEnabling" );
    97     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::CancelServiceEnabling" );
   258     
    98     }
   259     if ( iCchClient )
       
   260         {
       
   261         CCchService* service = iCchClient->GetService( iCurrentServiceId );
       
   262         
    99         
   263         if ( service )
       
   264             {
       
   265             TCchServiceStatus serviceStatus;
       
   266             TInt error = service->GetStatus( ECCHVoIPSub, serviceStatus );
       
   267             TCCHSubserviceState state = serviceStatus.State();
       
   268             
       
   269             // Disable only, if service is connecting state
       
   270             if ( error == KErrNone && state == ECCHConnecting )
       
   271                 {
       
   272                 TEFLOGSTRING( KTAREQOUT,
       
   273                   "PE CPEServiceHandling::CancelServiceEnabling, CCchService->Disable" );
       
   274                 service->Disable( ECCHUnknown );
       
   275                 }
       
   276             }
       
   277         }
       
   278     }
       
   279 		
       
   280 // -----------------------------------------------------------------------------
       
   281 // CPEServiceHandling::SendErrorMessage
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 void CPEServiceHandling::SendErrorMessage(
       
   285         TInt aErrorCode )
       
   286     {
       
   287     TEFLOGSTRING2( KTAINT, 
       
   288         "PE CPEServiceHandling::SendErrorMessage, aErrorCode: %d", 
       
   289         aErrorCode );
       
   290 
       
   291     iModel.DataStore()->SetErrorCode( aErrorCode );
       
   292     iModel.SendMessage( MEngineMonitor::EPEMessageServiceHandlingError );
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   296 // CPEServiceHandling::DisableService
   101 // CPEServiceHandling::DisableService
   297 // -----------------------------------------------------------------------------
   102 // -----------------------------------------------------------------------------
   298 //
   103 //
   299 void CPEServiceHandling::DisableService() const
   104 void CPEServiceHandling::DisableService() const
   300     {
   105     {
   301     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::DisableService" );
   106     TEFLOGSTRING( KTAREQIN, "PE CPEServiceHandling::DisableService" );
   302 
   107     } 
   303     CCchService* service = iCchClient->GetService( iCurrentServiceId );
       
   304     
       
   305     if ( service )
       
   306         {
       
   307         TEFLOGSTRING( KTAREQOUT,
       
   308           "PE CPEServiceHandling::DisableService, CCchService->Disable" );
       
   309         service->Disable( ECCHUnknown );
       
   310         }
       
   311     }
       
   312 
   108 
   313 //  End of File
   109 //  End of File