contextframework/cfw/src/cfclient/CFClientImpl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  CFClientImpl class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <cfcontextdataobject.h>
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "CFClientImpl.h"
       
    24 #include "cfactionsubscription.h"
       
    25 #include "cftrace.h"
       
    26 #include "cfcontextservice.h"
       
    27 #include "cfactionservice.h"
       
    28 #include "cfscriptservice.h"
       
    29 
       
    30 CCFClientImpl* CCFClientImpl::NewL(
       
    31     MCFListener& aListener )
       
    32     {
       
    33     FUNC_LOG;
       
    34     
       
    35     CCFClientImpl* self = CCFClientImpl::NewLC( aListener );
       
    36     CleanupStack::Pop( self );
       
    37     
       
    38     return self;
       
    39     }
       
    40 
       
    41 CCFClientImpl* CCFClientImpl::NewLC(
       
    42     MCFListener& aListener )
       
    43     {
       
    44     FUNC_LOG;
       
    45     
       
    46     CCFClientImpl* self = new( ELeave ) CCFClientImpl;
       
    47     
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aListener );
       
    50     
       
    51     return self;
       
    52     }
       
    53     
       
    54 CCFClientImpl::~CCFClientImpl()
       
    55     {
       
    56     FUNC_LOG;
       
    57 
       
    58     delete iContextService;
       
    59     delete iActionService;
       
    60     delete iScriptService;
       
    61     iCFClientSession.Close();
       
    62     }
       
    63     
       
    64 void CCFClientImpl::ConstructL( MCFListener& aListener )
       
    65     {
       
    66     FUNC_LOG;
       
    67     
       
    68     // Connect to cfserver
       
    69     iCFClientSession.ConnectL();
       
    70     
       
    71     // Create services
       
    72     iContextService = CCFContextService::NewL( iCFClientSession, aListener );
       
    73     iActionService = CCFActionService::NewL( iCFClientSession, aListener );
       
    74     iScriptService = CCFScriptService::NewL( iCFClientSession, aListener );
       
    75     }
       
    76     
       
    77 CCFClientImpl::CCFClientImpl()
       
    78     {
       
    79     FUNC_LOG;
       
    80     }
       
    81 
       
    82 // METHODS
       
    83 
       
    84 //----------------------------------------------------------------------------
       
    85 // CCFClientImpl::DefineContext
       
    86 //----------------------------------------------------------------------------
       
    87 //
       
    88 TInt CCFClientImpl::DefineContext( const TDesC& aContextSource,
       
    89     const TDesC& aContextType,
       
    90     const TSecurityPolicy& aSecurityPolicy )
       
    91     {
       
    92     FUNC_LOG;
       
    93     
       
    94     INFO_2( "Defining context through CFClient: [%S: %S]",
       
    95         &aContextSource,
       
    96         &aContextType );
       
    97     
       
    98     TInt err = iContextService->DefineContext( aContextSource,
       
    99         aContextType,
       
   100         aSecurityPolicy, aSecurityPolicy );
       
   101 
       
   102     ERROR_1( err, "Define context failed with code: %d", err );
       
   103 
       
   104     return err;
       
   105     }
       
   106 
       
   107 //----------------------------------------------------------------------------
       
   108 // CCFClientImpl::DefineContext
       
   109 //----------------------------------------------------------------------------
       
   110 //
       
   111 TInt CCFClientImpl::DefineContext( const TDesC& aContextSource,
       
   112     const TDesC& aContextType,
       
   113     const TSecurityPolicy& aReadPolicy,
       
   114     const TSecurityPolicy& aWritePolicy )
       
   115     {
       
   116     FUNC_LOG;
       
   117     
       
   118     INFO_2( "Defining context through CFClient: [%S: %S]",
       
   119         &aContextSource,
       
   120         &aContextType );
       
   121         
       
   122     TInt err = iContextService->DefineContext( aContextSource,
       
   123         aContextType,
       
   124         aReadPolicy, aWritePolicy );
       
   125 
       
   126     ERROR_1( err, "Define context failed with code: %d", err );
       
   127 
       
   128     return err;
       
   129     }
       
   130 
       
   131 //----------------------------------------------------------------------------
       
   132 // CCFClientImpl::PublishContext
       
   133 //----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CCFClientImpl::PublishContext( CCFContextObject& aContext )
       
   136     {
       
   137     FUNC_LOG;
       
   138     
       
   139     INFO_2( "Publishing context through CFClient: [%S: %S]",
       
   140         &aContext.Source(),
       
   141         &aContext.Type() );
       
   142     
       
   143     TRAPD( err, iContextService->PublishContextL( aContext ) );
       
   144         
       
   145     ERROR_1( err, "Publish context failed with code: %d", err );
       
   146 
       
   147     return err;
       
   148     }
       
   149 
       
   150 //----------------------------------------------------------------------------
       
   151 // CCFClientImpl::PublishContext
       
   152 //----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CCFClientImpl::PublishContext( CCFContextObject& aContext,
       
   155     CCFContextDataObject& aData )
       
   156     {
       
   157     FUNC_LOG;
       
   158 
       
   159     INFO_2( "Publishing context through CFClient: [%S: %S]",
       
   160         &aContext.Source(),
       
   161         &aContext.Type() );
       
   162     INFO_1( "Publishing context data through CFClient: [%x]",
       
   163         aData.Uid() );
       
   164     
       
   165     TRAPD( err, iContextService->PublishContextL( aContext, aData ) );
       
   166         
       
   167     ERROR_1( err, "Publish context failed with code: %d", err );
       
   168     
       
   169     return err;
       
   170     }
       
   171 
       
   172 //----------------------------------------------------------------------------
       
   173 // CCFClientImpl::SubscribeContext
       
   174 //----------------------------------------------------------------------------
       
   175 //
       
   176 TInt CCFClientImpl::SubscribeContext( CCFContextSubscription& aSubscription )
       
   177     {
       
   178     FUNC_LOG;
       
   179     
       
   180     INFO_2( "Subscribing context through CFClient: [%S: %S]",
       
   181         &aSubscription.ContextSource(),
       
   182         &aSubscription.ContextType() );
       
   183     
       
   184     TRAPD( err, iContextService->SubscribeContextL( aSubscription ) );
       
   185     
       
   186     ERROR_1( err, "Subscribe context failed with code: %d", err );
       
   187 
       
   188     return err;
       
   189     }
       
   190 
       
   191 //----------------------------------------------------------------------------
       
   192 // CCFClientImpl::Unsubscribe
       
   193 //----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CCFClientImpl::UnsubscribeContext( CCFContextSubscription& aSubscription )
       
   196     {
       
   197     FUNC_LOG;
       
   198     
       
   199     INFO_2( "Unsubscribing context through CFClient: [%S: %S]",
       
   200         &aSubscription.ContextSource(),
       
   201         &aSubscription.ContextType() );
       
   202 
       
   203     TRAPD( err, iContextService->UnsubscribeContextL( aSubscription ) );
       
   204     
       
   205     ERROR_1( err, "Unsubscribe context failed with code: %d", err );
       
   206 
       
   207     return err;
       
   208     }
       
   209 
       
   210 //----------------------------------------------------------------------------
       
   211 // CCFClientImpl::RequestContext
       
   212 //----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CCFClientImpl::RequestContext( CCFContextQuery& aContextQuery,
       
   215     RContextObjectArray& aRequestResults)
       
   216     {
       
   217     FUNC_LOG;
       
   218     
       
   219     INFO_2( "Requesting context through CFClient: [%S: %S]",
       
   220         &aContextQuery.Source(),
       
   221         &aContextQuery.Type() );
       
   222 
       
   223     TRAPD( err, iContextService->RequestContextL(
       
   224         aContextQuery, aRequestResults ) );
       
   225 
       
   226     ERROR_1( err, "Request context failed with code: %d", err );
       
   227     
       
   228     return err;
       
   229     }
       
   230 
       
   231 //----------------------------------------------------------------------------
       
   232 // CCFClientImpl::RequestContextSet
       
   233 //----------------------------------------------------------------------------
       
   234 //
       
   235 TInt CCFClientImpl::RequestContextSet( RContextQueryArray& aContextQuerySet,
       
   236     RContextObjectArray& aRequestResults)
       
   237     {
       
   238     FUNC_LOG;
       
   239     
       
   240     TInt count = aContextQuerySet.Count();
       
   241     for( TInt i = 0; i < count; i++ )
       
   242         {
       
   243         INFO_2( "Requesting context through CFClient: [%S: %S]",
       
   244             &aContextQuerySet[i]->Source(),
       
   245             &aContextQuerySet[i]->Type() );
       
   246         }
       
   247     
       
   248     TRAPD( err, iContextService->RequestContextSetL(
       
   249         aContextQuerySet, aRequestResults ) );
       
   250 
       
   251     ERROR_1( err, "Request context set failed with code: %d", err );
       
   252 
       
   253     return err;
       
   254     }
       
   255 
       
   256 //----------------------------------------------------------------------------
       
   257 // CCFClientImpl::SubscribeAction
       
   258 //----------------------------------------------------------------------------
       
   259 //
       
   260 TInt CCFClientImpl::SubscribeAction( CCFActionSubscription& aSubscription )
       
   261     {
       
   262     FUNC_LOG;
       
   263     
       
   264     INFO_1( "Subscribing action through CFClient: [%S]",
       
   265         &aSubscription.ActionIdentifier() );
       
   266     
       
   267     TRAPD( err, iActionService->SubscribeActionL( aSubscription ) );
       
   268     
       
   269     ERROR_1( err, "Subscribe action failed with code: %d", err );
       
   270     
       
   271     return err;
       
   272     }
       
   273 
       
   274 //----------------------------------------------------------------------------
       
   275 // CCFClientImpl::UnsubscribeAction
       
   276 //----------------------------------------------------------------------------
       
   277 //
       
   278 TInt CCFClientImpl::UnsubscribeAction( CCFActionSubscription& aSubscription )
       
   279     {
       
   280     FUNC_LOG;
       
   281     
       
   282     INFO_1( "Unsubscribing action through CFClient: [%S]",
       
   283         &aSubscription.ActionIdentifier() );
       
   284     
       
   285     TRAPD( err, iActionService->UnsubscribeActionL( aSubscription ) );
       
   286     
       
   287     ERROR_1( err, "Unsubscribe action failed with code: %d", err );
       
   288     
       
   289     return err;
       
   290     }
       
   291 
       
   292 //----------------------------------------------------------------------------
       
   293 // CCFClientImpl::RegisterScript
       
   294 //----------------------------------------------------------------------------
       
   295 //
       
   296 TInt CCFClientImpl::RegisterScript( const TDesC& aScript, TInt& aScriptId )
       
   297     {
       
   298     FUNC_LOG;
       
   299     
       
   300     INFO( "Registering script through CFClient" );
       
   301 
       
   302     TInt scriptId = iScriptService->RegisterScript( aScript );
       
   303     if (scriptId < 0)
       
   304     	{
       
   305     	ERROR_1( scriptId, "Script registering failed with code: %d",
       
   306     		scriptId );
       
   307     	return scriptId; // returned as an error
       
   308     	}
       
   309     else 
       
   310     	{
       
   311     	aScriptId = scriptId;
       
   312     	return KErrNone;
       
   313     	}
       
   314     }
       
   315 
       
   316 //----------------------------------------------------------------------------
       
   317 // CCFClientImpl::RegisterScript
       
   318 //----------------------------------------------------------------------------
       
   319 //
       
   320 TInt CCFClientImpl::RegisterScript( const TDesC& aScriptFileName,
       
   321     const TDesC8& aScript,
       
   322     TInt& aScriptId )
       
   323     {
       
   324     FUNC_LOG;
       
   325     
       
   326     INFO( "Registering script through CFClient" );
       
   327 
       
   328     TInt scriptId = iScriptService->RegisterScript(
       
   329         aScript, aScriptFileName );
       
   330     if (scriptId < 0)
       
   331     	{
       
   332     	ERROR_1( scriptId, "Script registering failed with code: %d",
       
   333     		scriptId );
       
   334     	return scriptId; // returned as an error
       
   335     	}
       
   336     else 
       
   337     	{
       
   338     	aScriptId = scriptId;
       
   339     	return KErrNone;
       
   340     	}
       
   341     }
       
   342 
       
   343 //----------------------------------------------------------------------------
       
   344 // CCFClientImpl::DeregisterScript
       
   345 //----------------------------------------------------------------------------
       
   346 //
       
   347 TInt CCFClientImpl::DeregisterScript( TInt aScriptId )
       
   348     {
       
   349     FUNC_LOG;
       
   350     
       
   351     INFO_1( "Deregistering script with id [%d] through CFClient", aScriptId );
       
   352 
       
   353     TInt err = iScriptService->DeregisterScript( aScriptId );
       
   354     
       
   355     ERROR( err, "Script deregistering failed!" );
       
   356 
       
   357     return err;
       
   358     }
       
   359 
       
   360 //----------------------------------------------------------------------------
       
   361 // CCFClientImpl::DefineAction
       
   362 //----------------------------------------------------------------------------
       
   363 //
       
   364 TInt CCFClientImpl::DefineAction( const TDesC& aActionIdentifier,
       
   365     const TSecurityPolicy& aSecurityPolicy )
       
   366     {
       
   367     FUNC_LOG;
       
   368     
       
   369     INFO_1( "Defining action through CFClient: [%S]", &aActionIdentifier );
       
   370     
       
   371     TInt err = iActionService->DefineAction(
       
   372         aActionIdentifier,
       
   373         aSecurityPolicy );
       
   374     
       
   375     ERROR_1( err, "Define action failed with code: %d", err );
       
   376     
       
   377     return err;
       
   378     }
       
   379 
       
   380 //----------------------------------------------------------------------------
       
   381 // CCFClientImpl::SaveContextSourceSetting
       
   382 //----------------------------------------------------------------------------
       
   383 //
       
   384 TInt CCFClientImpl::SaveContextSourceSetting( const TDesC& aSettingFilename,
       
   385     const TUid& aContextSourceUid )
       
   386     {
       
   387     FUNC_LOG;
       
   388     
       
   389     INFO_1( "Installing context source setting [%S] through CFClient",
       
   390             &aSettingFilename );
       
   391     
       
   392     TInt err = iContextService->InstallContextSourceSetting( aSettingFilename,
       
   393             aContextSourceUid );
       
   394     
       
   395     ERROR_1( err, "Installing context source setting [%S] through CFClient failed",
       
   396             &aSettingFilename );
       
   397 
       
   398     return err;
       
   399     }
       
   400 
       
   401 //----------------------------------------------------------------------------
       
   402 // CCFClientImpl::DeleteContextSourceSetting
       
   403 //----------------------------------------------------------------------------
       
   404 //
       
   405 TInt CCFClientImpl::DeleteContextSourceSetting( const TDesC& aSettingFilename,
       
   406     const TUid& aContextSourceUid )
       
   407     {
       
   408     FUNC_LOG;
       
   409     
       
   410     INFO_1( "Uninstalling context source setting [%S] through CFClient",
       
   411             &aSettingFilename );
       
   412     
       
   413     TInt err = iContextService->UninstallContextSourceSetting( aSettingFilename,
       
   414             aContextSourceUid );
       
   415     
       
   416     ERROR_1( err, "Uninstalling context source setting [%S] through CFClient failed",
       
   417             &aSettingFilename );
       
   418 
       
   419     return err;
       
   420     }
       
   421 
       
   422 //----------------------------------------------------------------------------
       
   423 // CCFClientImpl::DeleteContextSourceSettings
       
   424 //----------------------------------------------------------------------------
       
   425 //
       
   426 TInt CCFClientImpl::DeleteContextSourceSettings( const TUid& aContextSourceUid )
       
   427     {
       
   428     FUNC_LOG;
       
   429     
       
   430     INFO( "Uninstalling context source settings through CFClient" );
       
   431     
       
   432     TInt err = iContextService->UninstallContextSourceSettings(
       
   433             aContextSourceUid );
       
   434     
       
   435     ERROR( err, "Uninstalling context source settings through CFClient failed" );
       
   436 
       
   437     return err;
       
   438     }
       
   439 
       
   440 //----------------------------------------------------------------------------
       
   441 // CCFClientImpl::SaveScript
       
   442 //----------------------------------------------------------------------------
       
   443 //
       
   444 TInt CCFClientImpl::SaveScript( const TDesC& aScriptFileName,
       
   445     TInt& aScriptId )
       
   446     {
       
   447     FUNC_LOG;
       
   448     
       
   449     INFO( "Register and save script through CFClient" );
       
   450 
       
   451     TInt err = iScriptService->SaveScript( aScriptFileName );
       
   452     if( err >= KErrNone )
       
   453         {
       
   454         aScriptId = err;
       
   455         err = KErrNone;
       
   456         }
       
   457     
       
   458     ERROR( err, "Register and save script through CFClient failed" );
       
   459     
       
   460     return err;
       
   461     }
       
   462 
       
   463 //----------------------------------------------------------------------------
       
   464 // CCFClientImpl::SaveScript
       
   465 //----------------------------------------------------------------------------
       
   466 //
       
   467 TInt CCFClientImpl::SaveScript( const TDesC& aScriptFileName,
       
   468     const TDesC8& aScript,
       
   469     TInt& aScriptId )
       
   470     {
       
   471     FUNC_LOG;
       
   472 
       
   473     INFO( "Register and save script stream through CFClient" );
       
   474 
       
   475     TInt err = iScriptService->SaveScript(
       
   476         aScript, aScriptFileName );
       
   477     if( err >= KErrNone )
       
   478         {
       
   479         aScriptId = err;
       
   480         err = KErrNone;
       
   481         }
       
   482     
       
   483     ERROR( err, "Register and save script stream through CFClient failed" );
       
   484     
       
   485     return err;
       
   486     }
       
   487 
       
   488 //----------------------------------------------------------------------------
       
   489 // CCFClientImpl::DeleteScript
       
   490 //----------------------------------------------------------------------------
       
   491 //
       
   492 TInt CCFClientImpl::DeleteScript( const TDesC& aScriptFileName )
       
   493     {
       
   494     FUNC_LOG;
       
   495     
       
   496     INFO( "Deregister and delete script through CFClient" );
       
   497     
       
   498     TInt err = iScriptService->DeleteScript( aScriptFileName );
       
   499     
       
   500     ERROR( err, "Deregister and delete script through CFClient failed" );
       
   501     
       
   502     return err;
       
   503     }
       
   504 
       
   505 //----------------------------------------------------------------------------
       
   506 // CCFClientImpl::DeleteScript
       
   507 //----------------------------------------------------------------------------
       
   508 //
       
   509 TInt CCFClientImpl::DeleteScripts()
       
   510     {
       
   511     FUNC_LOG;
       
   512     
       
   513     INFO( "Deregister and delete scripts through CFClient" );
       
   514     
       
   515     TInt err = iScriptService->DeleteScripts();
       
   516     
       
   517     ERROR( err, "Deregister and delete scripts through CFClient failed" );
       
   518 
       
   519     return err;
       
   520     }
       
   521 
       
   522 //----------------------------------------------------------------------------
       
   523 // CCFClientImpl::UpgradeRomScript
       
   524 //----------------------------------------------------------------------------
       
   525 //
       
   526 TInt CCFClientImpl::UpgradeRomScript( const TDesC& aScriptFileName )
       
   527     {
       
   528     FUNC_LOG;
       
   529     
       
   530     INFO( "Upgrade rom script through CFClient" );
       
   531 
       
   532     TInt err = iScriptService->UpgradeRomScript( aScriptFileName );
       
   533     
       
   534     ERROR( err, "Upgrade rom script through CFClient failed" );
       
   535 
       
   536     return err;
       
   537     }
       
   538 
       
   539 //----------------------------------------------------------------------------
       
   540 // CCFClientImpl::UpgradeRomScript
       
   541 //----------------------------------------------------------------------------
       
   542 //
       
   543 TInt CCFClientImpl::UpgradeRomScript( const TDesC& aScriptFileName,
       
   544     const TDesC8& aScript )
       
   545     {
       
   546     FUNC_LOG;
       
   547     
       
   548     INFO( "Upgrade rom script des through CFClient" );
       
   549 
       
   550     TInt err = iScriptService->UpgradeRomScriptDes( aScriptFileName, aScript );
       
   551     
       
   552     ERROR( err, "Upgrade rom script des through CFClient failed" );
       
   553 
       
   554     return err;
       
   555     }
       
   556 
       
   557 //----------------------------------------------------------------------------
       
   558 // CCFClientImpl::RestoreRomScript
       
   559 //----------------------------------------------------------------------------
       
   560 //
       
   561 TInt CCFClientImpl::RestoreRomScript( const TDesC& aScriptFileName )
       
   562     {
       
   563     FUNC_LOG;
       
   564     
       
   565     INFO( "Restore rom script through CFClient" );
       
   566 
       
   567     TInt err = iScriptService->RestoreRomScript( aScriptFileName );
       
   568     
       
   569     ERROR( err, "Restore rom script through CFClient failed" );
       
   570 
       
   571     return err;
       
   572     }
       
   573 
       
   574 // End of file