contextframework/cfw/src/cfserver/CFEngine.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:  CFServer class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32svr.h>
       
    20 #include <e32math.h>
       
    21 #include <e32uid.h>
       
    22 #include <ecom/ecom.h>
       
    23 #include <centralrepository.h>
       
    24 
       
    25 #include <cfcontextdataobject.h>
       
    26 #include <cfscriptevent.h>
       
    27 #include <cfcontextsourcecommand.h>
       
    28 
       
    29 #include "CFEngine.h"
       
    30 #include "CFContextManager.h"
       
    31 #include "CFContextSourceManager.h"
       
    32 #include "CFScriptHandler.h"
       
    33 #include "CFActivator.h"
       
    34 #include "CFContextSubscriptionImpl.h"
       
    35 #include "cfstarter.h"
       
    36 #include "cfecomobserver.h"
       
    37 #include "cftrace.h"
       
    38 #include "CFActionSubscriptionImpl.h"
       
    39 #include "ContextFrameworkPrivateCRKeys.h"
       
    40 #include "cfasynccmdqueue.h"
       
    41 #include "cfactioncmd.h"
       
    42 #include "cfpublishcontextcmd.h"
       
    43 #include "cfremovesubscriptioncleanupcmd.h"
       
    44 #include "cfcontextsourcecmd.h"
       
    45 
       
    46 // CONSTANTS
       
    47 
       
    48 #ifdef _DEBUG
       
    49 _LIT( KPanicCat, "CFEngine" );
       
    50 
       
    51 enum TPanicReason
       
    52     {
       
    53     ENULLParam
       
    54     };
       
    55 
       
    56     
       
    57 LOCAL_C void Panic( TPanicReason aReason )
       
    58     {
       
    59     User::Panic( KPanicCat, aReason );
       
    60     }
       
    61 #endif
       
    62 
       
    63 // MEMBER FUNCTIONS
       
    64 
       
    65 CCFEngine* CCFEngine::NewL( MCFSecurityChecker& aSecurityChecker )
       
    66     {
       
    67     FUNC_LOG;
       
    68     
       
    69     CCFEngine* self = CCFEngine::NewLC( aSecurityChecker );
       
    70     CleanupStack::Pop( self );
       
    71     
       
    72     return self;
       
    73     }
       
    74 
       
    75 CCFEngine* CCFEngine::NewLC( MCFSecurityChecker& aSecurityChecker )
       
    76     {
       
    77     FUNC_LOG;
       
    78     
       
    79     CCFEngine* self = new( ELeave ) CCFEngine( aSecurityChecker );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     
       
    83     return self;
       
    84     }
       
    85 
       
    86 CCFEngine::~CCFEngine()
       
    87     {
       
    88     FUNC_LOG;
       
    89 
       
    90     delete iScriptEngine;
       
    91     delete iActivatorEngine;
       
    92     delete iContextSourceManager;
       
    93     delete iContextManager;
       
    94     delete iEComObserver;
       
    95     delete iStarter;
       
    96     delete iAsyncCmdQueue;
       
    97     iFs.Close();
       
    98     }
       
    99 
       
   100 void CCFEngine::ConstructL()
       
   101     {
       
   102     FUNC_LOG;
       
   103     
       
   104     // Open file handle to share it everywhere in context manager
       
   105     User::LeaveIfError( iFs.Connect() );
       
   106     
       
   107     // Construct cf started
       
   108     iStarter = CCFStarter::NewL( *this );
       
   109     
       
   110     // CCFEComObserver
       
   111     iEComObserver = CCFEComObserver::NewL();
       
   112     
       
   113 	// ContextManager
       
   114     iContextManager = CCFContextManager::NewL( *iSecurityChecker );
       
   115 
       
   116     // Context source manager    
       
   117     iContextSourceManager = CCFContextSourceManager::NewL( *this, iFs );
       
   118     iStarter->AddObserverL( iContextSourceManager );
       
   119     iEComObserver->AddObserverL( iContextSourceManager );
       
   120 
       
   121     // Activator engine
       
   122     iActivatorEngine = CCFActivator::NewL();
       
   123     iStarter->AddObserverL( iActivatorEngine );
       
   124     iEComObserver->AddObserverL( iActivatorEngine );
       
   125     
       
   126     // Script engine
       
   127     iScriptEngine = CCFScriptHandler::NewL( *this, iFs,
       
   128     	*this,
       
   129     	*iSecurityChecker );
       
   130     iStarter->AddObserverL( iScriptEngine );
       
   131     iEComObserver->AddObserverL( iScriptEngine );
       
   132 
       
   133     // Queue for asynchronous commands.
       
   134     iAsyncCmdQueue = CCFAsyncCmdQueue::NewL();
       
   135 
       
   136     // Get context data object maximum size
       
   137     CRepository* cenrep = NULL;
       
   138     TRAPD( err, cenrep = CRepository::NewL( KCRUidCFCommonConf ) );
       
   139     if( cenrep && err == KErrNone )
       
   140         {
       
   141         err = cenrep->Get( KContextDataObjectMaxSize, iMaxDataObjectSize );
       
   142         if( err != KErrNone )
       
   143             {
       
   144             iMaxDataObjectSize = KContextDataObjectDefaultSize;
       
   145             }
       
   146         delete cenrep;
       
   147         } 
       
   148     
       
   149     // Start cf starter
       
   150     iStarter->StartL();
       
   151     }
       
   152 
       
   153 CCFEngine::CCFEngine( MCFSecurityChecker& aSecurityChecker ):
       
   154     iSecurityChecker( &aSecurityChecker ),
       
   155     iMaxDataObjectSize( KContextDataObjectDefaultSize )
       
   156     {
       
   157     FUNC_LOG;
       
   158     }
       
   159 
       
   160 // METHODS
       
   161 
       
   162 //----------------------------------------------------------------------------
       
   163 // CCFEngine::DefineContext
       
   164 //----------------------------------------------------------------------------
       
   165 //
       
   166 TInt CCFEngine::DefineContext( const TDesC& aContextSource,
       
   167     const TDesC& aContextType,
       
   168     const TSecurityPolicy& aSecurityPolicy )
       
   169     {
       
   170     FUNC_LOG;
       
   171     
       
   172     INFO_2( "Defining context: [%S: %S]",
       
   173         &aContextSource,
       
   174         &aContextType );
       
   175     
       
   176     TRAPD( err, iContextManager->DefineContextL(
       
   177         aContextSource, aContextType,
       
   178         aSecurityPolicy, aSecurityPolicy ) );
       
   179         
       
   180     ERROR_1( err, "DefineContext returned with code: %d", err );
       
   181         
       
   182     return err;
       
   183     }
       
   184 
       
   185 //----------------------------------------------------------------------------
       
   186 // CCFEngine::DefineContext
       
   187 //----------------------------------------------------------------------------
       
   188 //
       
   189 TInt CCFEngine::DefineContext( const TDesC& aContextSource,
       
   190     const TDesC& aContextType,
       
   191     const TSecurityPolicy& aReadWritePolicy,
       
   192     MCFContextSource& aOwner )
       
   193     {
       
   194     FUNC_LOG;
       
   195     
       
   196     INFO_2( "Defining context: [%S: %S]",
       
   197         &aContextSource,
       
   198         &aContextType );
       
   199 
       
   200     RThread thread;
       
   201 
       
   202     TRAPD( err, iContextManager->DefineContextL(
       
   203         aContextSource, aContextType,
       
   204         aReadWritePolicy, aReadWritePolicy, &aOwner, thread.SecureId() ) );
       
   205 
       
   206     thread.Close();
       
   207     
       
   208     ERROR_1( err, "DefineContext returned with code: %d", err );
       
   209         
       
   210     return err;
       
   211     }
       
   212 
       
   213 //----------------------------------------------------------------------------
       
   214 // CCFEngine::DefineContext
       
   215 //----------------------------------------------------------------------------
       
   216 //
       
   217 TInt CCFEngine::DefineContext( const TDesC& aContextSource,
       
   218     const TDesC& aContextType,
       
   219     const TSecurityPolicy& aReadPolicy,
       
   220     const TSecurityPolicy& aWritePolicy,
       
   221     MCFContextSource& aOwner )
       
   222     {
       
   223     FUNC_LOG;
       
   224     
       
   225     INFO_2( "Defining context: [%S: %S]",
       
   226         &aContextSource,
       
   227         &aContextType );
       
   228     
       
   229     RThread thread;
       
   230     
       
   231     TRAPD( err, iContextManager->DefineContextL(
       
   232         aContextSource, aContextType,
       
   233         aReadPolicy, aWritePolicy, &aOwner, thread.SecureId() ) );
       
   234     
       
   235     thread.Close();
       
   236     
       
   237     ERROR_1( err, "DefineContext returned with code: %d", err );
       
   238         
       
   239     return err;
       
   240     }
       
   241 
       
   242 //----------------------------------------------------------------------------
       
   243 // CCFEngine::PublishContext
       
   244 //----------------------------------------------------------------------------
       
   245 //
       
   246 TInt CCFEngine::PublishContext( CCFContextObject& aContext,
       
   247     RThread& aClientThread )
       
   248     {
       
   249     FUNC_LOG;
       
   250 
       
   251     TRAPD( err, EnqueuePublishContextL( aContext, aClientThread ) );
       
   252 
       
   253     ERROR_3( err, "CCFEngine::EnqueuePublishContextL - Failed for context [%S: %S :%S].",
       
   254             &aContext.Source(),
       
   255             &aContext.Type(),
       
   256             &aContext.Value() );
       
   257 
       
   258     return err;
       
   259     }
       
   260 
       
   261 //----------------------------------------------------------------------------
       
   262 // CCFEngine::PublishContext
       
   263 //----------------------------------------------------------------------------
       
   264 //
       
   265 TInt CCFEngine::PublishContext( CCFContextObject& aContext,
       
   266     CCFContextDataObject& aData,
       
   267     RThread& aClientThread )
       
   268     {
       
   269     FUNC_LOG;
       
   270 
       
   271     TInt err = KErrNone;
       
   272     if( aData.Size() > iMaxDataObjectSize )
       
   273         {
       
   274         err = KErrTooBig;
       
   275         ERROR_GEN_2( "Context data object [0x%x] is too big. Maximum size: [0x%x]",
       
   276             err,
       
   277             iMaxDataObjectSize );
       
   278         }
       
   279     else if( aData.Uid() == KNullUid )
       
   280         {
       
   281         err = KErrNotSupported;
       
   282         ERROR_GEN( "Context data object with NULL UID not supported." );
       
   283         }
       
   284     else
       
   285         {
       
   286         TRAP( err, EnqueuePublishContextL( aContext, aClientThread, &aData ) );
       
   287 
       
   288         ERROR_3( err, "CCFEngine::EnqueuePublishContextL - Failed for context [%S: %S :%S].",
       
   289                 &aContext.Source(),
       
   290                 &aContext.Type(),
       
   291                 &aContext.Value() );
       
   292         ERROR_1( err, "CCFEngine::EnqueuePublishContextL - Failed with data object: [0x%x]",
       
   293                 aData.Uid() );
       
   294         }
       
   295 
       
   296     return err;
       
   297     }
       
   298 
       
   299 //----------------------------------------------------------------------------
       
   300 // CCFEngine::SubscribeContext
       
   301 //----------------------------------------------------------------------------
       
   302 //
       
   303 TInt CCFEngine::SubscribeContext(
       
   304     CCFContextSubscription* aSubscription,
       
   305     MCFContextSubscriptionListener* aListener,
       
   306     RThread& aClientThread )
       
   307     {
       
   308     FUNC_LOG;
       
   309     
       
   310     __ASSERT_DEBUG( aSubscription && aListener, Panic( ENULLParam ) );
       
   311     
       
   312     INFO_2( "Subscribing context: [%S: %S]",
       
   313         &aSubscription->ContextSource(),
       
   314         &aSubscription->ContextType() );
       
   315     
       
   316     TRAPD( err,
       
   317         iContextManager->SubscribeContextL( aSubscription, aListener,
       
   318             aClientThread ) );
       
   319     
       
   320     ERROR_1( err, "SubscribeContext returned with code: %d", err );
       
   321         
       
   322     return err;
       
   323     }
       
   324 
       
   325 //----------------------------------------------------------------------------
       
   326 // CCFEngine::UnsubscribeContext
       
   327 //----------------------------------------------------------------------------
       
   328 //
       
   329 void CCFEngine::UnsubscribeContext(
       
   330     CCFContextSubscription& aSubscription,
       
   331     MCFContextSubscriptionListener& aListener )
       
   332     {
       
   333     FUNC_LOG;
       
   334 
       
   335     INFO_2( "CCFEngine::UnsubscribeContext - For context [%S: %S].",
       
   336             &aSubscription.ContextSource(),
       
   337             &aSubscription.ContextType() );
       
   338 
       
   339     if ( iContextManager->RemoveSubscription( aSubscription, aListener ) )
       
   340         {
       
   341         TInt err = KErrNone;
       
   342         TRAP( err, EnqueueUnsubscribeContextCleanupL() );
       
   343         ERROR( err, "CCFEngine::EnqueueUnsubscribeContextCleanupL - Failed after unsubscribing a context." );
       
   344         }
       
   345     }
       
   346 
       
   347 //----------------------------------------------------------------------------
       
   348 // CCFEngine::UnsubscribeContexts
       
   349 //----------------------------------------------------------------------------
       
   350 //
       
   351 void CCFEngine::UnsubscribeContexts(
       
   352     MCFContextSubscriptionListener& aObserver )
       
   353     {
       
   354     FUNC_LOG;
       
   355 
       
   356     INFO( "CCFEngine::UnsubscribeContexts - For a listener." );
       
   357 
       
   358     if ( iContextManager->RemoveSubscriptions( &aObserver ) )
       
   359         {
       
   360         TInt err = KErrNone;
       
   361         TRAP( err, EnqueueUnsubscribeContextCleanupL() );
       
   362         ERROR( err, "CCFEngine::EnqueueUnsubscribeContextCleanupL - Failed after unsubscribing contexts." );
       
   363         }
       
   364     }
       
   365 
       
   366 //----------------------------------------------------------------------------
       
   367 // CCFEngine::RequestContextL
       
   368 //----------------------------------------------------------------------------
       
   369 //
       
   370 TInt CCFEngine::RequestContext(
       
   371     RContextObjectArray& aResultBuffer,
       
   372     CCFContextQuery& aContextQuery,
       
   373     RThread& aClientThread )
       
   374     {
       
   375     FUNC_LOG;
       
   376     
       
   377     INFO_2( "Requesting context: [%S: %S]",
       
   378         &aContextQuery.Source(),
       
   379         &aContextQuery.Type() );
       
   380     
       
   381     TRAPD( err, iContextManager->RequestContextL( aResultBuffer,
       
   382         aContextQuery,
       
   383         aClientThread ) );
       
   384 
       
   385     ERROR_1( err, "RequestContext returned with code: %d", err );
       
   386         
       
   387     return err;
       
   388     }
       
   389 
       
   390 //----------------------------------------------------------------------------
       
   391 // CCFEngine::GetSecurityPolicy
       
   392 //----------------------------------------------------------------------------
       
   393 //
       
   394 TInt CCFEngine::GetSecurityPolicy( const TDesC& aContextSource,
       
   395     const TDesC& aContextType,
       
   396 	TSecurityPolicy& aPolicy )
       
   397     {
       
   398     FUNC_LOG;
       
   399     
       
   400     INFO_2( "Getting security policy: [%S: %S]",
       
   401         &aContextSource,
       
   402         &aContextType );
       
   403     
       
   404     TRAPD( err, iContextManager->GetWriteSecurityPolicyL( aContextSource,
       
   405         aContextType,
       
   406         aPolicy ) );
       
   407 
       
   408     ERROR_1( err, "RequestContext returned with code: %d", err );
       
   409         
       
   410     return err;
       
   411     }
       
   412 
       
   413 //----------------------------------------------------------------------------
       
   414 // CCFEngine::GetReadSecurityPolicy
       
   415 //----------------------------------------------------------------------------
       
   416 //
       
   417 TInt CCFEngine::GetReadSecurityPolicy( const TDesC& aContextSource,
       
   418 	const TDesC& aContextType,
       
   419 	TSecurityPolicy& aPolicy )
       
   420 	{
       
   421     FUNC_LOG;
       
   422     
       
   423     INFO_2( "Getting security policy: [%S: %S]",
       
   424         &aContextSource,
       
   425         &aContextType );
       
   426     
       
   427     TRAPD( err, iContextManager->GetReadSecurityPolicyL( aContextSource,
       
   428         aContextType,
       
   429         aPolicy ) );
       
   430 
       
   431     ERROR_1( err, "RequestContext returned with code: %d", err );
       
   432         
       
   433     return err;
       
   434     }
       
   435 
       
   436 //----------------------------------------------------------------------------
       
   437 // CCFEngine::GetWriteSecurityPolicy
       
   438 //----------------------------------------------------------------------------
       
   439 //
       
   440 TInt CCFEngine::GetWriteSecurityPolicy( const TDesC& aContextSource,
       
   441 	const TDesC& aContextType,
       
   442 	TSecurityPolicy& aPolicy )
       
   443 	{
       
   444     FUNC_LOG;
       
   445     
       
   446     INFO_2( "Getting security policy: [%S: %S]",
       
   447         &aContextSource,
       
   448         &aContextType );
       
   449     
       
   450     TRAPD( err, iContextManager->GetWriteSecurityPolicyL( aContextSource,
       
   451         aContextType,
       
   452         aPolicy ) );
       
   453 
       
   454     ERROR_1( err, "RequestContext returned with code: %d", err );
       
   455         
       
   456     return err;
       
   457     }
       
   458 
       
   459 
       
   460 //----------------------------------------------------------------------------
       
   461 // CCFEngine::DefineContext
       
   462 //----------------------------------------------------------------------------
       
   463 //
       
   464 TInt CCFEngine::DefineContext( const TDesC& aContextSource,
       
   465     const TDesC& aContextType,
       
   466     const TSecurityPolicy& aReadPolicy,
       
   467     const TSecurityPolicy& aWritePolicy,
       
   468     MCFContextSource* aPublisher,
       
   469     const TUid& aPublisherUid )
       
   470 	{
       
   471     FUNC_LOG;
       
   472 
       
   473     INFO_2( "Defining context: [%S: %S]", &aContextSource, &aContextType );
       
   474 
       
   475     TRAPD( err, iContextManager->DefineContextL(
       
   476         aContextSource, aContextType,
       
   477         aReadPolicy, aWritePolicy, aPublisher, aPublisherUid ) );
       
   478 
       
   479     if ( err == KErrNone )
       
   480         {
       
   481         // Make sure the call is coming from a client and not CF thread.
       
   482         RThread thread;
       
   483         if ( aPublisherUid != thread.SecureId() )
       
   484             {
       
   485             iContextSourceManager->RegisterClientContextSource( aPublisher,
       
   486                     aPublisherUid );
       
   487             }
       
   488         thread.Close();
       
   489         }
       
   490 
       
   491     ERROR_1( err, "DefineContext returned with code: %d", err );
       
   492 
       
   493     return err;
       
   494     }
       
   495     
       
   496 //----------------------------------------------------------------------------
       
   497 // CCFEngine::DeregisterPublisher
       
   498 //----------------------------------------------------------------------------
       
   499 //
       
   500 void CCFEngine::DeregisterPublisher( MCFContextSource& aPublisher )
       
   501 	{
       
   502     FUNC_LOG;
       
   503     
       
   504     INFO( "Deregistering Publisher" );
       
   505     
       
   506     iContextManager->DeregisterPublisher( aPublisher );
       
   507     iContextSourceManager->DeregisterClientContextSource( aPublisher );
       
   508     }
       
   509 	
       
   510 //----------------------------------------------------------------------------
       
   511 // CCFEngine::InstallContextSourceSetting
       
   512 //----------------------------------------------------------------------------
       
   513 //
       
   514 TInt CCFEngine::InstallContextSourceSetting( RFile& aSettingFile,
       
   515     const TUid& aContextSourceUid,
       
   516     RThread& aClientThread )
       
   517     {
       
   518     FUNC_LOG;
       
   519 
       
   520     INFO( "Installing Context Source Setting" );
       
   521 
       
   522     TRAPD( err, iContextSourceManager->InstallSettingL( aSettingFile,
       
   523             aContextSourceUid,
       
   524             aClientThread ) );
       
   525 
       
   526     ERROR( err, "Installing Context Source Setting failed" );
       
   527 
       
   528     return err;
       
   529     }
       
   530 
       
   531 //----------------------------------------------------------------------------
       
   532 // CCFEngine::UninstallContextSourceSetting
       
   533 //----------------------------------------------------------------------------
       
   534 //
       
   535 TInt CCFEngine::UninstallContextSourceSetting( const TDesC& aSettingFilename,
       
   536     const TUid& aContextSourceUid,
       
   537     RThread& aClientThread )
       
   538     {
       
   539     FUNC_LOG;
       
   540 
       
   541     INFO_1( "Uninstalling Context Source Setting [%S]", &aSettingFilename );
       
   542 
       
   543     TRAPD( err, iContextSourceManager->UninstallSettingL( aSettingFilename,
       
   544             aContextSourceUid,
       
   545             aClientThread ) );
       
   546 
       
   547     ERROR_1( err, "Uninstalling Context Source Setting [%S] failed",
       
   548             &aSettingFilename );
       
   549 
       
   550     return err;
       
   551     }
       
   552 
       
   553 //----------------------------------------------------------------------------
       
   554 // CCFEngine::UninstallContextSourceSettings
       
   555 //----------------------------------------------------------------------------
       
   556 //
       
   557 TInt CCFEngine::UninstallContextSourceSettings( const TUid& aContextSourceUid,
       
   558     RThread& aClientThread )
       
   559     {
       
   560     FUNC_LOG;
       
   561 
       
   562     INFO( "Uninstalling Context Source Settings" );
       
   563 
       
   564     TRAPD( err, iContextSourceManager->UninstallSettingsL( aContextSourceUid,
       
   565             aClientThread ) );
       
   566 
       
   567     ERROR( err, "Uninstalling Context Source Settings failed" );
       
   568 
       
   569     return err;
       
   570     }
       
   571 
       
   572 //----------------------------------------------------------------------------
       
   573 // CCFEngine::PublishContextFromAction
       
   574 //----------------------------------------------------------------------------
       
   575 //
       
   576 TInt CCFEngine::PublishContextFromAction( CCFContextObject& aContext,
       
   577     TBool aAutoDefine )
       
   578     {
       
   579     FUNC_LOG;
       
   580 
       
   581     RThread thread;
       
   582     TRAPD( err, iContextManager->ValidatePublishContextL( aContext, thread ) );
       
   583     if ( err == KErrNotFound && aAutoDefine )
       
   584         {
       
   585         // Only cfserver can publish
       
   586         TSecurityPolicy writePolicy( thread.SecureId() );
       
   587         // Every one can subscribe        
       
   588         _LIT_SECURITY_POLICY_PASS( readPolicy );
       
   589         TRAP( err, iContextManager->DefineContextL( aContext.Source(),
       
   590                 aContext.Type(),
       
   591                 readPolicy,
       
   592                 writePolicy,
       
   593                 NULL,
       
   594                 thread.SecureId() ) );
       
   595         ERROR_3( err, "CCFEngine::PublishContextFromAction - Auto-define failed for context [%S: %S :%S].",
       
   596                 &aContext.Source(),
       
   597                 &aContext.Type(),
       
   598                 &aContext.Value() );
       
   599         }
       
   600     thread.Close();
       
   601 
       
   602     if ( err == KErrNone  || err == KErrAlreadyExists )
       
   603         {
       
   604         CCFPublishContextCmd* cmd = NULL;
       
   605         TRAP( err, cmd = CCFPublishContextCmd::NewL( *iContextManager,
       
   606                 aContext ) );
       
   607         ERROR( err, "CCFEngine::PublishContextFromAction - Creating publish context cmd failed." );
       
   608         if ( err == KErrNone )
       
   609             {
       
   610             INFO_3( "CCFEngine::PublishContextFromAction - Appending publish context cmd for context [%S: %S: %S] to async queue.",
       
   611                     &aContext.Source(),
       
   612                     &aContext.Type(),
       
   613                     &aContext.Value() );
       
   614 
       
   615             iAsyncCmdQueue->Add( cmd );
       
   616             }
       
   617         }
       
   618 
       
   619     return err;
       
   620     }
       
   621 
       
   622 
       
   623 //----------------------------------------------------------------------------
       
   624 // CCFEngine::DefineAction
       
   625 //----------------------------------------------------------------------------
       
   626 //
       
   627 TInt CCFEngine::DefineAction( const TDesC& aActionIdentifier,
       
   628     const TSecurityPolicy& aSecurityPolicy,
       
   629     const TUid& aOwnerUid,
       
   630     MCFActionOwner* aOwner )
       
   631     {
       
   632     FUNC_LOG;
       
   633     
       
   634     INFO_1( "Defining action: [%S]", &aActionIdentifier );
       
   635 
       
   636     MCFActivatorCallBackInterface* interface =
       
   637         static_cast<MCFActivatorCallBackInterface*>( iActivatorEngine );
       
   638     TRAPD( err, interface->DefineActionL( aActionIdentifier,
       
   639         aSecurityPolicy, aOwnerUid, aOwner ) );
       
   640     
       
   641     ERROR_1( err, "DefineAction returned with code: %d", err );
       
   642         
       
   643     return err;
       
   644     }
       
   645 
       
   646 //----------------------------------------------------------------------------
       
   647 // CCFEngine::SubscribeAction
       
   648 //----------------------------------------------------------------------------
       
   649 //
       
   650 TInt CCFEngine::SubscribeAction( CCFActionSubscription* aActionSubscription,
       
   651     MCFActionSubscriptionListener* aListener,
       
   652     RThread& aClientThread )
       
   653     {
       
   654     FUNC_LOG;
       
   655     
       
   656     INFO_1( "Subscribing action: [%S]",
       
   657         &aActionSubscription->ActionIdentifier() );
       
   658     
       
   659     MCFActivatorCallBackInterface* interface =
       
   660         static_cast<MCFActivatorCallBackInterface*>( iActivatorEngine );
       
   661     TRAPD( err, interface->SubscribeActionL(
       
   662         aActionSubscription,
       
   663         aListener,
       
   664         aClientThread ) );
       
   665     
       
   666     ERROR_1( err, "SubscribeAction returned with code: %d", err );
       
   667         
       
   668     return err;
       
   669     }
       
   670 
       
   671 //----------------------------------------------------------------------------
       
   672 // CCFEngine::UnsubscribeAction
       
   673 //----------------------------------------------------------------------------
       
   674 //
       
   675 void CCFEngine::UnsubscribeAction( CCFActionSubscription& aActionSubscription,
       
   676     MCFActionSubscriptionListener& aListener )
       
   677     {
       
   678     FUNC_LOG;
       
   679     
       
   680     INFO_1( "Subscribing action: [%S]",
       
   681         &aActionSubscription.ActionIdentifier() );
       
   682 
       
   683     MCFActivatorCallBackInterface* interface =
       
   684         static_cast<MCFActivatorCallBackInterface*>( iActivatorEngine );
       
   685     interface->UnsubscribeAction( aActionSubscription, aListener );
       
   686     }
       
   687 
       
   688 //----------------------------------------------------------------------------
       
   689 // CCFEngine::UnsubscribeActions
       
   690 //----------------------------------------------------------------------------
       
   691 //
       
   692 void CCFEngine::UnsubscribeActions(
       
   693     MCFActionSubscriptionListener& aListener )
       
   694     {
       
   695     FUNC_LOG;
       
   696 
       
   697     MCFActivatorCallBackInterface* interface =
       
   698         static_cast<MCFActivatorCallBackInterface*>( iActivatorEngine );
       
   699     interface->RemoveSubscriptions( aListener );
       
   700     }
       
   701 
       
   702 //------------------------------------------------------------------------------
       
   703 // CCFEngine::DeregisterActions
       
   704 //------------------------------------------------------------------------------
       
   705 //
       
   706 void CCFEngine::DeregisterActions( MCFActionOwner* aOwner )
       
   707     {
       
   708     FUNC_LOG;
       
   709 
       
   710     MCFActivatorCallBackInterface* interface =
       
   711         static_cast<MCFActivatorCallBackInterface*>( iActivatorEngine );
       
   712     interface->DeregisterActions( aOwner );
       
   713     }
       
   714     
       
   715 //----------------------------------------------------------------------------
       
   716 // CCFEngine::RegisterScript
       
   717 //----------------------------------------------------------------------------
       
   718 //
       
   719 TInt CCFEngine::RegisterScript( const TDesC& aName,
       
   720     const TDesC8& aScript,
       
   721     TInt& aScriptId,
       
   722 	const RThread& aClientThread,
       
   723     MCFScriptOwner& aOwner )
       
   724 	{
       
   725     FUNC_LOG;
       
   726 
       
   727     INFO_1( "CCFEngine::RegisterScript - Registering by NAME=[%S]", &aName );
       
   728 
       
   729     MCFScriptEngineInterface* interface =
       
   730         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   731 	TInt err = interface->AddScript( aName, aScript, aClientThread.SecureId(),
       
   732             aClientThread, *this, &aOwner );
       
   733 	
       
   734 	if ( err < 0 )
       
   735 		{
       
   736         INFO_2( "CCFEngine::RegisterScript - Failed by NAME=[%S] with code %d", &aName, err );
       
   737 
       
   738 		return err;
       
   739 		}
       
   740 	else
       
   741 		{
       
   742         INFO_2( "CCFEngine::RegisterScript - Registered by NAME=[%S] into ID=[%d]", &aName, err );
       
   743 
       
   744         aScriptId = err;
       
   745 		return KErrNone;	
       
   746 		}
       
   747 	}
       
   748         
       
   749 //----------------------------------------------------------------------------
       
   750 // CCFEngine::DeregisterScript
       
   751 //----------------------------------------------------------------------------
       
   752 //
       
   753 TInt CCFEngine::DeregisterScript( TInt aScriptId, const RThread& aClientThread )
       
   754 	{
       
   755     FUNC_LOG;
       
   756 
       
   757 	MCFScriptEngineInterface* interface =
       
   758         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   759 	return interface->RemoveScriptById( aScriptId, aClientThread );
       
   760 	}
       
   761 
       
   762 //----------------------------------------------------------------------------
       
   763 // CCFEngine::DeregisterScript
       
   764 //----------------------------------------------------------------------------
       
   765 //
       
   766 TInt CCFEngine::DeregisterScript( const TDesC& aScriptName,
       
   767     const RThread& aClientThread )
       
   768     {
       
   769     FUNC_LOG;
       
   770     
       
   771     MCFScriptEngineInterface* interface =
       
   772         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   773     return interface->RemoveScriptByName( aScriptName, aClientThread.SecureId() );
       
   774     }
       
   775 
       
   776 //----------------------------------------------------------------------------
       
   777 // CCFEngine::DeregisterScripts
       
   778 //----------------------------------------------------------------------------
       
   779 //
       
   780 TInt CCFEngine::DeregisterScripts( const RThread& aClientThread )
       
   781     {
       
   782     FUNC_LOG;
       
   783     
       
   784     MCFScriptEngineInterface* interface =
       
   785         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   786     return interface->RemoveScriptByUid( aClientThread.SecureId() );
       
   787     }
       
   788 
       
   789 //------------------------------------------------------------------------------
       
   790 // CCFEngine::DeregisterScriptOwner
       
   791 //------------------------------------------------------------------------------
       
   792 //
       
   793 void CCFEngine::DeregisterScriptOwner( MCFScriptOwner& aOwner )
       
   794     {
       
   795     FUNC_LOG;
       
   796 
       
   797     MCFScriptEngineInterface* interface =
       
   798         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   799     interface->DeregisterScriptOwner( &aOwner );
       
   800     }
       
   801 
       
   802 //----------------------------------------------------------------------------
       
   803 // CCFEngine::SaveScript
       
   804 //----------------------------------------------------------------------------
       
   805 //
       
   806 TInt CCFEngine::SaveScript( const TDesC8& aScript,
       
   807     TInt aScriptId,
       
   808     const RThread& aClient )
       
   809     {
       
   810     FUNC_LOG;
       
   811     
       
   812     MCFScriptEngineInterface* interface =
       
   813         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   814     return interface->SaveScript( aScript, aScriptId, aClient.SecureId() );
       
   815     }
       
   816 
       
   817 //----------------------------------------------------------------------------
       
   818 // CCFEngine::DeleteScript
       
   819 //----------------------------------------------------------------------------
       
   820 //
       
   821 TInt CCFEngine::DeleteScript( const TDesC& aScriptName,
       
   822     RThread& aClientThread )
       
   823     {
       
   824     FUNC_LOG;
       
   825     
       
   826     MCFScriptEngineInterface* interface =
       
   827         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   828     return interface->DeleteScriptByName( aScriptName,
       
   829         aClientThread.SecureId() );
       
   830     }
       
   831 
       
   832 //----------------------------------------------------------------------------
       
   833 // CCFEngine::DeleteScripts
       
   834 //----------------------------------------------------------------------------
       
   835 //
       
   836 TInt CCFEngine::DeleteScripts( RThread& aClientThread )
       
   837     {
       
   838     FUNC_LOG;
       
   839     
       
   840     MCFScriptEngineInterface* interface =
       
   841         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   842     return interface->DeleteScriptByUid( aClientThread.SecureId() );
       
   843     }
       
   844 
       
   845 //----------------------------------------------------------------------------
       
   846 // CCFEngine::AlreadyExists
       
   847 //----------------------------------------------------------------------------
       
   848 //
       
   849 TBool CCFEngine::AlreadyExists( const TDesC& aScriptName,
       
   850     const RThread& aClient,
       
   851     TInt& aScriptId ) const
       
   852     {
       
   853     FUNC_LOG;
       
   854     
       
   855     MCFScriptEngineInterface* interface =
       
   856         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   857     return interface->AlreadyExists( aScriptName, aClient.SecureId(), aScriptId );
       
   858     }
       
   859 
       
   860 //----------------------------------------------------------------------------
       
   861 // CCFEngine::CleanupPersistentDataByName
       
   862 //----------------------------------------------------------------------------
       
   863 //
       
   864 void CCFEngine::CleanupPersistentDataByName( const TDesC& aScriptName,
       
   865     const RThread& aClientThread )
       
   866     {
       
   867     FUNC_LOG;
       
   868 
       
   869     MCFScriptEngineInterface* interface =
       
   870         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   871     interface->CleanupPersistentDataByName( aScriptName,
       
   872         aClientThread.SecureId() );
       
   873     }
       
   874 
       
   875 //----------------------------------------------------------------------------
       
   876 // CCFEngine::CleanupPersistentDataByUid
       
   877 //----------------------------------------------------------------------------
       
   878 //
       
   879 void CCFEngine::CleanupPersistentDataByUid( const RThread& aClient )
       
   880     {
       
   881     FUNC_LOG;
       
   882 
       
   883     MCFScriptEngineInterface* interface =
       
   884         static_cast<MCFScriptEngineInterface*>( iScriptEngine );
       
   885     interface->CleanupPersistentDataByUid( aClient.SecureId() );
       
   886     }
       
   887 
       
   888 //----------------------------------------------------------------------------
       
   889 // CCFEngine::UpdateScript
       
   890 //----------------------------------------------------------------------------
       
   891 //
       
   892 TInt CCFEngine::UpdateScript( TInt aScriptID,
       
   893     const RThread& aOwnerThread,
       
   894     const TDesC8& aUpdatedScript,
       
   895     MCFScriptOwner& aOwner )
       
   896     {
       
   897     FUNC_LOG;
       
   898 
       
   899     MCFScriptEngineInterface* interface = static_cast
       
   900         <MCFScriptEngineInterface*>( iScriptEngine );
       
   901     return interface->UpdateScript(
       
   902         aScriptID, aOwnerThread, aUpdatedScript, &aOwner );
       
   903     }
       
   904 
       
   905 //----------------------------------------------------------------------------
       
   906 // CCFEngine::UpdateScript
       
   907 //----------------------------------------------------------------------------
       
   908 //
       
   909 TInt CCFEngine::RestoreRomScript( TInt aScriptId,
       
   910     const RThread& aClient )
       
   911     {
       
   912     FUNC_LOG;
       
   913     
       
   914     MCFScriptEngineInterface* interface = static_cast
       
   915         <MCFScriptEngineInterface*>( iScriptEngine );
       
   916     return interface->RestoreRomScript( aScriptId, aClient.SecureId(), aClient );
       
   917     }
       
   918 
       
   919 //----------------------------------------------------------------------------
       
   920 // CCFEngine::IsUpgradeAllowed
       
   921 //----------------------------------------------------------------------------
       
   922 //
       
   923 TInt CCFEngine::IsUpgradeAllowed( const TDesC& aName,
       
   924     const TDesC8& aScript,
       
   925     const RThread& aOwnerThread )
       
   926     {
       
   927     FUNC_LOG;
       
   928     
       
   929     MCFScriptEngineInterface* interface = static_cast
       
   930         <MCFScriptEngineInterface*>( iScriptEngine );
       
   931     return interface->IsUpgradeAllowed( aName, aScript,
       
   932         aOwnerThread.SecureId(), aOwnerThread, *this );
       
   933     }
       
   934 
       
   935 //----------------------------------------------------------------------------
       
   936 // CCFEngine::FireActionL
       
   937 //----------------------------------------------------------------------------
       
   938 //
       
   939 void CCFEngine::FireActionL( CCFScriptEvent* aEvent )
       
   940     {
       
   941     FUNC_LOG;
       
   942 
       
   943     TPtrC actionId( aEvent->Identifier() );
       
   944     INFO_1( "CCFEngine::FireActionL - Enqueueing fire action for id [%S].",
       
   945             &actionId );
       
   946 
       
   947     EnqueueFireActionL( *iActivatorEngine, aEvent );
       
   948     }
       
   949 
       
   950 //----------------------------------------------------------------------------
       
   951 // CCFEngine::FireActionL
       
   952 //----------------------------------------------------------------------------
       
   953 //
       
   954 void CCFEngine::FireActionL( const CCFContextSourceCommand& aCommand )
       
   955     {
       
   956     FUNC_LOG;
       
   957 
       
   958     TPtrC commandName( aCommand.Name() );
       
   959     INFO_1( "CCFEngine::FireActionL - Enqueueing fire action for id [%S].",
       
   960             &commandName );
       
   961 
       
   962     EnqueueSourceCommandActionL( *this, aCommand );
       
   963     }
       
   964 
       
   965 //----------------------------------------------------------------------------
       
   966 // CCFEngine::GetActionSecurityPolicy
       
   967 //----------------------------------------------------------------------------
       
   968 //
       
   969 TInt CCFEngine::GetActionSecurityPolicy( const TDesC& aActionIdentifier,
       
   970     TSecurityPolicy& aPolicy )
       
   971     {
       
   972     FUNC_LOG;
       
   973 
       
   974     return static_cast< MCFActionHandler* >( iActivatorEngine )
       
   975             ->GetActionSecurityPolicy( aActionIdentifier, aPolicy );
       
   976     }
       
   977 
       
   978 //----------------------------------------------------------------------------
       
   979 // CCFEngine::HandleCommandL
       
   980 //----------------------------------------------------------------------------
       
   981 //
       
   982 void CCFEngine::HandleCommandL( const CCFContextSourceCommand& aCommand )
       
   983     {
       
   984     FUNC_LOG;
       
   985 
       
   986     iContextSourceManager->HandleContextSourceCommandL( aCommand );
       
   987     }
       
   988 
       
   989 
       
   990 //----------------------------------------------------------------------------
       
   991 // CCFEngine::EnqueuePublishContextL
       
   992 //----------------------------------------------------------------------------
       
   993 //
       
   994 void CCFEngine::EnqueuePublishContextL( CCFContextObject& aContext,
       
   995     RThread& aClientThread,
       
   996     CCFContextDataObject* aData )
       
   997     {
       
   998     FUNC_LOG;
       
   999 
       
  1000     iContextManager->ValidatePublishContextL( aContext, aClientThread );
       
  1001 
       
  1002     CCFPublishContextCmd* cmd = NULL;
       
  1003     if ( aData )
       
  1004         {
       
  1005         cmd = CCFPublishContextCmd::NewL( *iContextManager, aContext, *aData );
       
  1006         }
       
  1007     else
       
  1008         {
       
  1009         cmd = CCFPublishContextCmd::NewL( *iContextManager, aContext );
       
  1010         }
       
  1011 
       
  1012     INFO_3( "CCFEngine::EnqueuePublishContextL - Appending publish context cmd for context [%S: %S: %S] to async queue.",
       
  1013             &aContext.Source(),
       
  1014             &aContext.Type(),
       
  1015             &aContext.Value() );
       
  1016     if ( aData )
       
  1017         {
       
  1018         INFO_1( "CCFEngine::EnqueuePublishContextL - Appending publish context cmd with data object: [0x%x]",
       
  1019                 aData->Uid() );
       
  1020         }
       
  1021 
       
  1022     iAsyncCmdQueue->Add( cmd );
       
  1023     }
       
  1024 
       
  1025 //----------------------------------------------------------------------------
       
  1026 // CCFEngine::EnqueueUnsubscribeContextCleanupL
       
  1027 //----------------------------------------------------------------------------
       
  1028 //
       
  1029 void CCFEngine::EnqueueUnsubscribeContextCleanupL()
       
  1030     {
       
  1031     FUNC_LOG;
       
  1032 
       
  1033     CCFRemoveSubscriptionCleanupCmd* cmd
       
  1034         = CCFRemoveSubscriptionCleanupCmd::NewL( *iContextManager );
       
  1035 
       
  1036     INFO( "CCFEngine::EnqueueUnsubscribeContextCleanupL - Adding remove subscription cleanup cmd to the front of async queue." );
       
  1037 
       
  1038     iAsyncCmdQueue->AddFirst( cmd );
       
  1039     }
       
  1040 
       
  1041 //----------------------------------------------------------------------------
       
  1042 // CCFEngine::EnqueueFireActionL
       
  1043 //----------------------------------------------------------------------------
       
  1044 //
       
  1045 void CCFEngine::EnqueueFireActionL( MCFActionHandler& aActionHandler,
       
  1046     CCFScriptEvent* aEvent )
       
  1047     {
       
  1048     FUNC_LOG;
       
  1049 
       
  1050     CCFActionCmd* cmd = CCFActionCmd::NewL( aActionHandler, aEvent );
       
  1051 
       
  1052     TPtrC actionId( aEvent->Identifier() );
       
  1053     INFO_1( "CCFEngine::EnqueueFireActionL - Appending action cmd for id [%S] to async queue.",
       
  1054             &actionId );
       
  1055 
       
  1056     iAsyncCmdQueue->Add( cmd );
       
  1057     }
       
  1058 
       
  1059 //----------------------------------------------------------------------------
       
  1060 // CCFEngine::EnqueueSourceCommandActionL
       
  1061 //----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CCFEngine::EnqueueSourceCommandActionL(
       
  1064     MCFContextSourceCommand& aSourceCommandHandler,
       
  1065     const CCFContextSourceCommand& aCommand )
       
  1066     {
       
  1067     FUNC_LOG;
       
  1068 
       
  1069     CCFContextSourceCmd* cmd
       
  1070         = CCFContextSourceCmd::NewL( aSourceCommandHandler, aCommand );
       
  1071 
       
  1072     INFO( "CCFEngine::EnqueueSourceCommandActionL - Appending source command action cmd to async queue." );
       
  1073 
       
  1074     iAsyncCmdQueue->Add( cmd );
       
  1075     }
       
  1076 
       
  1077 // End of file