contextframework/cfw/src/cfclient/cfscriptservice.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2008-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:  CCFScriptService class implementation.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "cfscriptservice.h"
       
    25 #include "cftrace.h"
       
    26 #include "cfcommon.h"
       
    27 #include "CFClientSession.h"
       
    28 #include "cfscriptmessagelistener.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // C++ constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CCFScriptService::CCFScriptService( RCFClientSession& aSession,
       
    37     MCFListener& aListener ):
       
    38     CCFServiceBase( CCFServiceBase::ECFScriptService, aSession, aListener )
       
    39     {
       
    40     FUNC_LOG;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Symbian 2nd phase constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void CCFScriptService::ConstructL( )
       
    48     {
       
    49     FUNC_LOG;
       
    50     
       
    51     iMessageListener = CCFScriptMessageListener::NewL( iSession, iListener );
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // Symbian two phased constructor.
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCFScriptService* CCFScriptService::NewL( RCFClientSession& aSession,
       
    59     MCFListener& aListener )
       
    60     {
       
    61     FUNC_LOG;
       
    62 
       
    63     CCFScriptService* self = CCFScriptService::NewLC( aSession, aListener );
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Symbian two phased constructor.
       
    70 // Leaves pointer in the cleanup stack.
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CCFScriptService* CCFScriptService::NewLC( RCFClientSession& aSession,
       
    74     MCFListener& aListener )
       
    75     {
       
    76     FUNC_LOG;
       
    77 
       
    78     CCFScriptService* self = new( ELeave ) CCFScriptService(
       
    79         aSession,
       
    80         aListener );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL( );
       
    83     return self;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // C++ destructor.
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CCFScriptService::~CCFScriptService( )
       
    91     {
       
    92     FUNC_LOG;
       
    93     
       
    94     delete iMessageListener;
       
    95     }
       
    96 
       
    97 //----------------------------------------------------------------------------
       
    98 // CCFScriptService::RegisterScript
       
    99 //----------------------------------------------------------------------------
       
   100 //
       
   101 TInt CCFScriptService::RegisterScript( const TDesC& aScriptFileName )
       
   102     {
       
   103     FUNC_LOG;
       
   104 
       
   105     TInt scriptId = KErrNotFound;
       
   106     TRAPD( err, scriptId = ShareFileAndSendSyncL(
       
   107         aScriptFileName, ERegisterScriptByName ) );
       
   108 
       
   109     if( err == KErrNone )
       
   110         {
       
   111         if( !iMessageListener->IsActive() )
       
   112             {
       
   113             // Activate listening for the first time
       
   114             iMessageListener->RequestNotification();
       
   115             }
       
   116         err = scriptId;
       
   117         }
       
   118     
       
   119     return err;
       
   120     }
       
   121 
       
   122 //----------------------------------------------------------------------------
       
   123 // CCFScriptService::RegisterScript
       
   124 //----------------------------------------------------------------------------
       
   125 //
       
   126 TInt CCFScriptService::RegisterScript( const TDesC8& aScript,
       
   127     const TDesC& aScriptFileName )
       
   128     {
       
   129     FUNC_LOG;
       
   130     
       
   131     TInt err = KErrNone;
       
   132     
       
   133     // Check arguments
       
   134     if( aScriptFileName.Length() > 0 && aScript.Length() > 0 )
       
   135         {
       
   136         TIpcArgs args( &aScript, &aScriptFileName );
       
   137         err = iSession.SendSync( ERegisterScriptByNameAndDesc, args );
       
   138         }
       
   139     else
       
   140         {
       
   141         err = KErrArgument;
       
   142         }
       
   143 
       
   144     return err;
       
   145     }
       
   146 
       
   147 //----------------------------------------------------------------------------
       
   148 // CCFScriptService::DeregisterScript
       
   149 //----------------------------------------------------------------------------
       
   150 //
       
   151 TInt CCFScriptService::DeregisterScript( TInt aScriptId )
       
   152     {
       
   153     FUNC_LOG;
       
   154     
       
   155     TIpcArgs args( aScriptId );
       
   156     TInt err = iSession.SendSync( EDeregisterScriptById, args );
       
   157     
       
   158     return err;
       
   159     }
       
   160 
       
   161 //----------------------------------------------------------------------------
       
   162 // CCFScriptService::SaveScript
       
   163 //----------------------------------------------------------------------------
       
   164 //
       
   165 TInt CCFScriptService::SaveScript( const TDesC& aScriptFileName )
       
   166     {
       
   167     FUNC_LOG;
       
   168     
       
   169     TInt scriptId = KErrNotFound;
       
   170     TRAPD( err, scriptId = ShareFileAndSendSyncL(
       
   171         aScriptFileName, ESaveScriptByName ) );
       
   172     
       
   173     if( err == KErrNone )
       
   174         {
       
   175         err = scriptId;
       
   176         }
       
   177     
       
   178     return err;
       
   179     }
       
   180 
       
   181 //----------------------------------------------------------------------------
       
   182 // CCFScriptService::SaveScript
       
   183 //----------------------------------------------------------------------------
       
   184 //
       
   185 TInt CCFScriptService::SaveScript( const TDesC8& aScript,
       
   186     const TDesC& aScriptFileName )
       
   187     {
       
   188     FUNC_LOG;
       
   189     
       
   190     TInt err = KErrNone;
       
   191     
       
   192     // Check arguments
       
   193     if( aScriptFileName.Length() > 0 && aScript.Length() > 0 )
       
   194         {
       
   195         TIpcArgs args( &aScript, &aScriptFileName );
       
   196         err = iSession.SendSync( ESaveScriptByNameAndDesc, args );
       
   197         }
       
   198     else
       
   199         {
       
   200         err = KErrArgument;
       
   201         }
       
   202     
       
   203     return err;
       
   204     }
       
   205 
       
   206 //----------------------------------------------------------------------------
       
   207 // CCFScriptService::DeleteScript
       
   208 //----------------------------------------------------------------------------
       
   209 //
       
   210 TInt CCFScriptService::DeleteScript(
       
   211     const TDesC& aScriptFileName )
       
   212     {
       
   213     FUNC_LOG;
       
   214 
       
   215     TInt err = KErrNone;
       
   216     
       
   217     // Check arguments
       
   218     if( aScriptFileName.Length() > 0 )
       
   219         {
       
   220         TIpcArgs args( &aScriptFileName );
       
   221         err = iSession.SendSync( EDeleteScriptByName, args );
       
   222         }
       
   223     else
       
   224         {
       
   225         err = KErrArgument;
       
   226         }
       
   227     
       
   228     return err;
       
   229     }
       
   230 
       
   231 //----------------------------------------------------------------------------
       
   232 // CCFScriptService::DeleteScripts
       
   233 //----------------------------------------------------------------------------
       
   234 //
       
   235 TInt CCFScriptService::DeleteScripts()
       
   236     {
       
   237     FUNC_LOG;
       
   238 
       
   239     return iSession.SendSync( EDeleteScriptByUid );
       
   240     }
       
   241 
       
   242 //----------------------------------------------------------------------------
       
   243 // CCFScriptService::UpgradeRomScriptL
       
   244 //----------------------------------------------------------------------------
       
   245 //
       
   246 TInt CCFScriptService::UpgradeRomScript( const TDesC& aScriptFileName )
       
   247     {
       
   248     FUNC_LOG;
       
   249 
       
   250     TRAPD( err, ShareFileAndSendSyncL( aScriptFileName, EUpgradeRomScriptByName ) );
       
   251     return err;
       
   252     }
       
   253 
       
   254 //----------------------------------------------------------------------------
       
   255 // CCFScriptService::UpgradeRomScriptDes
       
   256 //----------------------------------------------------------------------------
       
   257 //
       
   258 TInt CCFScriptService::UpgradeRomScriptDes( const TDesC& aScriptFileName,
       
   259     const TDesC8& aScript )
       
   260     {
       
   261     FUNC_LOG;
       
   262     
       
   263     TInt err = KErrNone;
       
   264     
       
   265     // Check arguments
       
   266     if( aScriptFileName.Length() > 0 && aScript.Length() > 0 )
       
   267         {
       
   268         TIpcArgs args( &aScript, &aScriptFileName );
       
   269         err = iSession.SendSync( EUpgradeRomScriptByNameAndDesc, args );
       
   270         }
       
   271     else
       
   272         {
       
   273         err = KErrArgument;
       
   274         }
       
   275 
       
   276     return err;
       
   277     }
       
   278 
       
   279 //----------------------------------------------------------------------------
       
   280 // CCFScriptService::RestoreRomScript
       
   281 //----------------------------------------------------------------------------
       
   282 //
       
   283 TInt CCFScriptService::RestoreRomScript( const TDesC& aScriptFileName )
       
   284     {
       
   285     FUNC_LOG;
       
   286     
       
   287     TInt err = KErrNone;
       
   288     
       
   289     // Check argument
       
   290     if( aScriptFileName.Length() > 0 )
       
   291         {
       
   292         TIpcArgs args( &aScriptFileName );
       
   293         err = iSession.SendSync( ERestoreRomScript, args );
       
   294         }
       
   295     else
       
   296         {
       
   297         err = KErrArgument;
       
   298         }
       
   299     
       
   300     return err;
       
   301     }
       
   302 
       
   303 //----------------------------------------------------------------------------
       
   304 // CCFScriptService::ShareFileAndSendSyncL
       
   305 //----------------------------------------------------------------------------
       
   306 //
       
   307 TInt CCFScriptService::ShareFileAndSendSyncL( const TDesC& aScriptFileName,
       
   308     TInt aOpCode )
       
   309     {
       
   310     FUNC_LOG;
       
   311     
       
   312     RFs fs;
       
   313     CleanupClosePushL( fs );
       
   314     User::LeaveIfError( fs.Connect() );
       
   315     
       
   316     // make possible to share the file server session with the CF server
       
   317     User::LeaveIfError( fs.ShareProtected() );
       
   318     
       
   319     // open the file
       
   320     RFile scriptFile;
       
   321     CleanupClosePushL( scriptFile );
       
   322     User::LeaveIfError( scriptFile.Open( fs, aScriptFileName, EFileRead ) );
       
   323     
       
   324     // deliver the file handle to the server
       
   325     TIpcArgs args;
       
   326     User::LeaveIfError( scriptFile.TransferToServer( args, 0, 1 ) );
       
   327     
       
   328     // Register and install script to disk
       
   329     TInt err = iSession.SendSync( aOpCode, args );
       
   330     User::LeaveIfError( err );
       
   331 
       
   332     // Cleanup
       
   333     CleanupStack::PopAndDestroy( &scriptFile );
       
   334     CleanupStack::PopAndDestroy( &fs );
       
   335 
       
   336     return err;
       
   337     }
       
   338 
       
   339 // End of file