convergedconnectionhandler/cchclientapi/src/cchimpl.cpp
changeset 0 a4daefaec16c
child 12 876a3df1f464
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  cch client api implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cchimpl.h"
       
    21 #include "cchlogger.h"
       
    22 #include "cch.h"
       
    23 #include "cchserviceimpl.h"
       
    24 
       
    25 #ifdef CCHAPI_USE_CCHUI
       
    26 #include "cchuiprivateapi.h"
       
    27 #endif
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // None
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES
       
    33 // None
       
    34 
       
    35 // CONSTANTS
       
    36 // None
       
    37 
       
    38 // MACROS
       
    39 // None
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 // None
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 // None
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 // None
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 // None
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS =============================
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS =============================
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCchImpl::CCchImpl
       
    59 // C++ default constructor can NOT contain any code, that might leave.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CCchImpl::CCchImpl()
       
    63      : CActive ( EPriorityStandard ),
       
    64        iCchUi(0), 
       
    65        iConnectivityDialogsAllowed( EFalse )
       
    66 	{
       
    67 	CActiveScheduler::Add( this );
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCchImpl::destructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //    
       
    74 CCchImpl::~CCchImpl()
       
    75     {
       
    76     CCHLOGSTRING( "CCchImpl::~CCchImpl: IN" );
       
    77     
       
    78     delete iCchUi;
       
    79 
       
    80     iCchServiceImpls.ResetAndDestroy();
       
    81     iCchServiceImpls.Close();
       
    82     Cancel();
       
    83     
       
    84     iCchClient.Close();
       
    85     iCchServer.Close();
       
    86     
       
    87     CCHLOGSTRING( "CCchImpl::~CCchImpl: OUT" );
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CCchImpl::ConstructL
       
    92 // Symbian 2nd phase constructor can leave.
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CCchImpl::ConstructL( CCch& aCch )
       
    96     {
       
    97     CCHLOGSTRING( "CCchImpl::ConstructL: IN" );
       
    98 
       
    99     User::LeaveIfError( iCchServer.Connect() );
       
   100     User::LeaveIfError( iCchClient.Open( iCchServer ) );
       
   101 
       
   102 #ifdef CCHAPI_USE_CCHUI
       
   103     iCchUi = CCchUiPrivateApi::NewL( aCch );
       
   104 #endif
       
   105 
       
   106     iCchClient.RegisterToServer( iStatus );
       
   107     SetActive();
       
   108     
       
   109     CCHLOGSTRING( "CCchImpl::ConstructL: OUT" );
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CCchImpl::NewL
       
   114 // Two-phased constructor.
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 CCchImpl* CCchImpl::NewL( CCch& aCch )
       
   118     {
       
   119     CCHLOGSTRING( "CCchImpl::NewL: IN" );
       
   120     CCchImpl* self = 
       
   121         CCchImpl::NewLC( aCch );
       
   122     CleanupStack::Pop( self );
       
   123     CCHLOGSTRING( "CCchImpl::NewL: OUT" );
       
   124     return self;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CCchImpl::NewLC
       
   129 // Two-phased constructor.
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 CCchImpl* CCchImpl::NewLC( CCch& aCch )
       
   133     {
       
   134     CCHLOGSTRING( "CCchImpl::NewLC: IN" );
       
   135     CCchImpl* self = 
       
   136         new (ELeave) CCchImpl( );
       
   137     CleanupStack::PushL( self );
       
   138     self->ConstructL( aCch );
       
   139     CCHLOGSTRING( "CCchImpl::NewLC: OUT" );
       
   140     return self;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CCchImpl::NewLC
       
   145 // Returns the RCCHClient 
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 RCCHClient& CCchImpl::CchClient( )
       
   149 	{
       
   150 	CCHLOGSTRING( "CCchImpl::CchClient: IN OUT" );
       
   151 	return iCchClient;
       
   152 	}
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CCchImpl::GetService
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 CCchService* CCchImpl::GetService( TInt aId )
       
   159 	{
       
   160 	CCHLOGSTRING( "CCchImpl::GetService: IN" );
       
   161 	
       
   162 	CCchServiceImpl* cchServiceImpl = NULL;
       
   163 	
       
   164 	TInt idx = FindService( aId );
       
   165 	if( idx == KErrNotFound )
       
   166 		{
       
   167 		TInt error = KErrNone;
       
   168 	    TRAP( error, cchServiceImpl = GetServiceL( aId ) );
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 		cchServiceImpl = iCchServiceImpls[ idx ];
       
   173 		}
       
   174 	CCHLOGSTRING( "CCchImpl::GetService: OUT" );
       
   175 	return cchServiceImpl;
       
   176 	}
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CCchImpl::GetServiceL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 CCchServiceImpl* CCchImpl::GetServiceL( TInt aId )
       
   183 	{
       
   184 	CCchServiceImpl* cchServiceImpl = NULL;	
       
   185 	
       
   186 	CArrayFixFlat<TCCHService>* cchServices =
       
   187 		new ( ELeave ) CArrayFixFlat<TCCHService>( 1 );
       
   188 	CleanupStack::PushL( cchServices );
       
   189 	if( KErrNone == GetCchServicesL( aId, ECCHUnknown , *cchServices ) )
       
   190 		{
       
   191 		if( cchServices->Count() )
       
   192 		    {
       
   193     		TCCHService service = cchServices->At( 0 );
       
   194     		cchServiceImpl = CCchServiceImpl::NewL( *this, 
       
   195     		                                        service.iServiceId, 
       
   196     		                                        *iCchUi );
       
   197     		
       
   198     		TInt error = iCchServiceImpls.Append( cchServiceImpl );
       
   199     		if( error == KErrNone )
       
   200     			{
       
   201     			cchServiceImpl = iCchServiceImpls[ iCchServiceImpls.Count() - 1 ];
       
   202     			}
       
   203     		else
       
   204     			{
       
   205     			delete cchServiceImpl;
       
   206     			cchServiceImpl = NULL;
       
   207     			}
       
   208 		    }
       
   209 		}
       
   210 	cchServices->Reset();
       
   211 	CleanupStack::PopAndDestroy( cchServices );
       
   212 	return cchServiceImpl;
       
   213 	}
       
   214 
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CCchImpl::GetCchServiceL
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 TInt CCchImpl::GetCchServicesL( TInt aServiceId, TCCHSubserviceType aType, 
       
   221 								CArrayFixFlat<TCCHService>& aServices )
       
   222 	{
       
   223 	TServiceSelection selection( aServiceId, aType, ECchInitial  );
       
   224     TRequestStatus status = KErrNone;
       
   225 
       
   226     iCchClient.GetServicesL( selection, aServices, status );			
       
   227 	//even the cchclient api seems to be asynchronous, 
       
   228 	//this method is completed immediately
       
   229 	User::WaitForRequest( status );
       
   230 	return status.Int();
       
   231 	}
       
   232 	
       
   233 // ---------------------------------------------------------------------------
       
   234 // CCchImpl::GetServiceIdsL
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CCchImpl::GetServiceIdsL( RArray<TInt>& aIds )
       
   238     {
       
   239 	CCHLOGSTRING( "CCchImpl::GetServiceIdsL: IN" );
       
   240 
       
   241 	TRequestStatus status( KErrNone );
       
   242     CArrayFixFlat<TCCHService>* cchServices = new (ELeave) CArrayFixFlat<TCCHService>(1);
       
   243     CleanupStack::PushL( cchServices );
       
   244 
       
   245     iCchClient.GetServicesL( *cchServices, status );
       
   246 	    
       
   247 	//even the cchclient api seems to be asynchronous, 
       
   248 	//this method is completed immediately	
       
   249 	User::WaitForRequest( status );
       
   250 	if( KErrNone == status.Int() )
       
   251 		{
       
   252 		for ( TInt i = 0; i < cchServices->Count(); i++ )
       
   253 			{
       
   254 			TCCHService service = cchServices->At( i );
       
   255 			User::LeaveIfError( aIds.Append( service.iServiceId ) );
       
   256 			}
       
   257 		}
       
   258 	else
       
   259 		{
       
   260 		User::Leave( status.Int() );
       
   261 		}	
       
   262     CleanupStack::PopAndDestroy( cchServices );
       
   263 
       
   264 	CCHLOGSTRING( "CCchImpl::GetServiceIdsL: OUT" );
       
   265     }
       
   266     
       
   267 // ---------------------------------------------------------------------------
       
   268 // CCchImpl::GetServiceIds
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TInt CCchImpl::GetServiceIds( RArray<TInt>& aIds )
       
   272 	{
       
   273 	TRAPD( err, GetServiceIdsL( aIds ) );
       
   274 	
       
   275 	return err;
       
   276 	}
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CCchImpl::GetServices
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TInt CCchImpl::GetServices( TCCHSubserviceType aType, 
       
   283         RPointerArray<CCchService>& aServices )
       
   284 	{
       
   285 	TInt err = KErrNone;
       
   286 	TRAP( err, GetServicesL( aType, aServices ) );
       
   287 	return err;
       
   288 	}
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CCchImpl::GetServicesL
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CCchImpl::GetServicesL( TCCHSubserviceType aType, 
       
   295         RPointerArray<CCchService>& aServices )
       
   296 	{
       
   297 	TInt error = KErrNone;
       
   298 	TServiceSelection selection( 0, aType, ECchInitial );
       
   299 	CCHLOGSTRING( "CCchImpl::GetServices: IN" );
       
   300 	CCchServiceImpl* cchServiceImpl = NULL;
       
   301 	CArrayFixFlat<TCCHService>* cchServices;
       
   302 	cchServices = new (ELeave) CArrayFixFlat<TCCHService>(1);
       
   303 	CleanupStack::PushL( cchServices );
       
   304 	error = GetCchServicesL( 0, aType, *cchServices );
       
   305 	if( KErrNone == error )
       
   306 		{
       
   307 		for ( TInt i = 0; i < cchServices->Count(); i++ )
       
   308 			{
       
   309 			TCCHService service = cchServices->At( i );
       
   310 			TInt idx =idx = FindService( service.iServiceId );
       
   311 			if( idx == KErrNotFound )
       
   312 				{
       
   313 				cchServiceImpl = CCchServiceImpl::NewL( *this, service.iServiceId, 
       
   314 				    *iCchUi );
       
   315 				error = iCchServiceImpls.Append( cchServiceImpl );
       
   316 				if( error == KErrNone )
       
   317 					{
       
   318 					cchServiceImpl = iCchServiceImpls[ iCchServiceImpls.Count() - 1 ];
       
   319 					}
       
   320 				else
       
   321 					{
       
   322 					delete cchServiceImpl;
       
   323 					cchServiceImpl = NULL;
       
   324 					}
       
   325 				}
       
   326 			else
       
   327 				{
       
   328 				cchServiceImpl = iCchServiceImpls[ idx ];
       
   329 				}
       
   330 			error = aServices.Append( cchServiceImpl );
       
   331 			if( error )
       
   332 				{
       
   333 				delete cchServiceImpl;
       
   334 				cchServiceImpl = NULL;
       
   335 				}
       
   336 			}
       
   337 		}
       
   338 	cchServices->Reset();
       
   339 	CleanupStack::PopAndDestroy( cchServices );
       
   340 	CCHLOGSTRING( "CCchImpl::GetServices: OUT" );
       
   341 	User::LeaveIfError( error );
       
   342 	}
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // CCCHServiceHandler::FindService
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 TInt CCchImpl::FindService( TInt aServiceId ) const
       
   349     {
       
   350     TBool exist = EFalse;
       
   351     TInt index = KErrNotFound;
       
   352     CCHLOGSTRING2( "CCchImpl::FindService: serviceId %d", aServiceId );
       
   353     for ( TInt i = 0; i < iCchServiceImpls.Count() && !exist; i++ )
       
   354         {
       
   355         exist = iCchServiceImpls[i]->ServiceId() == aServiceId;
       
   356         index = i;
       
   357         }
       
   358     return !exist ? KErrNotFound : index;
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CCCHServiceHandler::ConnectivityDialogsAllowed
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TBool CCchImpl::ConnectivityDialogsAllowed() const
       
   366     {
       
   367     CCHLOGSTRING( "CCchImpl::ConnectivityDialogsAllowed" );
       
   368     CCHLOGSTRING2( "  --> iConnectivityDialogsAllowed=%d", 
       
   369         iConnectivityDialogsAllowed );
       
   370     
       
   371     return iConnectivityDialogsAllowed;
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CCCHServiceHandler::SetConnectivityDialogsAllowed
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CCchImpl::SetConnectivityDialogsAllowed( 
       
   379     TBool aConnectivityDialogsAllowed )
       
   380     {
       
   381     iConnectivityDialogsAllowed = aConnectivityDialogsAllowed;
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CCCHServiceHandler::CchUiApi
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 MCchUi& CCchImpl::CchUiApi() const
       
   389     {
       
   390     return *iCchUi;
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // CCchImpl::DoCancel
       
   395 // ---------------------------------------------------------------------------
       
   396 //
       
   397 void CCchImpl::DoCancel()
       
   398     {
       
   399     CCHLOGSTRING( "CCchImpl::DoCancel: IN" );
       
   400 	iCchClient.RegisterToServerCancel();
       
   401 	CCHLOGSTRING( "CCchImpl::DoCancel: OUT" );
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // CCchImpl::RunL
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 void CCchImpl::RunL()
       
   409     {
       
   410     CCHLOGSTRING( "CCchImpl::RunL: IN" );
       
   411     if ( iStatus.Int() == KErrServerTerminated )
       
   412         {
       
   413         // clean
       
   414         Cancel();
       
   415         iCchClient.Close();
       
   416         iCchServer.Close();
       
   417         
       
   418         // create new
       
   419         User::LeaveIfError( iCchServer.Connect() );
       
   420         User::LeaveIfError( iCchClient.Open( iCchServer ) );
       
   421 
       
   422         iCchClient.RegisterToServer( iStatus );
       
   423         SetActive();
       
   424         }
       
   425     CCHLOGSTRING( "CCchImpl::RunL: OUT" );
       
   426     }
       
   427     
       
   428 // ---------------------------------------------------------------------------
       
   429 // CCchImpl::RunL
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 TInt CCchImpl::RunError( TInt /*aError*/ )
       
   433     {
       
   434     return KErrNone;
       
   435     }    
       
   436 
       
   437 //  End of File