webengine/widgetregistry/Server/src/WidgetRegistrySession.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006, 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <S32MEM.H>
       
    20 
       
    21 // User includes
       
    22 #include "WidgetRegistry.h"
       
    23 #include "WidgetRegistryConstants.h"
       
    24 #include "widgetregistryserver.h"
       
    25 #include "WidgetRegistryConstants.h"
       
    26 #include "WidgetRegistrySession.h"
       
    27 
       
    28 
       
    29 CWidgetRegistry* CWidgetRegistryServerSession::iWidgetRegistry = 0;
       
    30 
       
    31 // ============================================================================
       
    32 // CWidgetRegistryServerSession::CWidgetRegistryServerSession()
       
    33 // C++ constructor
       
    34 //
       
    35 // @since 3.1
       
    36 // ============================================================================
       
    37 //
       
    38 CWidgetRegistryServerSession::CWidgetRegistryServerSession()
       
    39     {
       
    40     }
       
    41 
       
    42 // ============================================================================
       
    43 // CWidgetRegistryServerSession::~CWidgetRegistryServerSession()
       
    44 // Destructor
       
    45 //
       
    46 // @since 3.1
       
    47 // ============================================================================
       
    48 //
       
    49 CWidgetRegistryServerSession::~CWidgetRegistryServerSession()
       
    50     {
       
    51     CWidgetRegistryServer* server( static_cast<CWidgetRegistryServer*>(
       
    52         const_cast<CServer2*>( Server() ) ) );
       
    53 
       
    54     if ( server && server->SessionCount() <= 0 )
       
    55         {
       
    56         delete iWidgetRegistry;
       
    57         iWidgetRegistry = NULL;
       
    58         iRfs.Close(); // after delete registry because registry/mmc refs it
       
    59         }
       
    60     }
       
    61 
       
    62 
       
    63 // ============================================================================
       
    64 // CWidgetRegistryServerSession::CreateL()
       
    65 // Called by the CServer framework
       
    66 //
       
    67 // @since 3.1
       
    68 // ============================================================================
       
    69 //
       
    70 void CWidgetRegistryServerSession::CreateL()
       
    71     {
       
    72     CWidgetRegistryServer* server;
       
    73 
       
    74     server = static_cast<CWidgetRegistryServer*>(
       
    75         const_cast<CServer2*>( Server() ) );
       
    76     User::LeaveIfNull ( server );
       
    77 
       
    78     if ( !iWidgetRegistry )
       
    79         {
       
    80         User::LeaveIfError( iRfs.Connect() );
       
    81         iWidgetRegistry = CWidgetRegistry::NewL( iRfs );
       
    82         }
       
    83 
       
    84     server->AddSession();
       
    85     }
       
    86 
       
    87 // ============================================================================
       
    88 // CWidgetRegistryServerSession::ConstructL()
       
    89 // ConstructL method
       
    90 //
       
    91 // @since 3.1
       
    92 // ============================================================================
       
    93 //
       
    94 void CWidgetRegistryServerSession::ConstructL(
       
    95     CWidgetRegistryServer& /*aServer*/,
       
    96     const RMessage2& /*aMessage*/ )
       
    97     {
       
    98     if ( !iWidgetRegistry )
       
    99         {
       
   100         User::LeaveIfError( iRfs.Connect() );
       
   101         iRfs.CreatePrivatePath( EDriveC );
       
   102         iRfs.SetSessionToPrivate( EDriveC );
       
   103         iRfs.ShareProtected();
       
   104         iWidgetRegistry = CWidgetRegistry::NewL( iRfs );
       
   105         }
       
   106     }
       
   107 
       
   108 // ============================================================================
       
   109 // CWidgetRegistryServerSession::NewL()
       
   110 //
       
   111 // @since 3.1
       
   112 // ============================================================================
       
   113 //
       
   114 CWidgetRegistryServerSession* CWidgetRegistryServerSession::NewL(
       
   115     CWidgetRegistryServer& aServer, const RMessage2& aMessage )
       
   116     {
       
   117     CWidgetRegistryServerSession* self;
       
   118 
       
   119     self = new ( ELeave ) CWidgetRegistryServerSession();
       
   120     CleanupStack::PushL( self );
       
   121     self->ConstructL( aServer, aMessage );
       
   122     CleanupStack::Pop( self );
       
   123     return self;
       
   124     }
       
   125 
       
   126 // ============================================================================
       
   127 // CWidgetRegistryServerSession::ServiceL()
       
   128 // Handles messages from client
       
   129 //
       
   130 // @since 3.1
       
   131 // ============================================================================
       
   132 //
       
   133 void CWidgetRegistryServerSession::ServiceL( const RMessage2& aMessage )
       
   134     {
       
   135     TBool retBool( EFalse );
       
   136     TInt len = 0;
       
   137     TInt uid = 0;
       
   138     TInt count = 0;
       
   139     TInt policyId = 0;
       
   140     TInt error;
       
   141     const TInt function = aMessage.Function();
       
   142 
       
   143     // TBD seems like we should trap leaves and return error codes so
       
   144     // as not to exit the server
       
   145     switch ( function )
       
   146         {
       
   147         case EOpCodeRegisterWidget:
       
   148             OpRegisterWidgetL( aMessage );
       
   149             aMessage.Complete( KErrNone );
       
   150             break;
       
   151         case EOpCodeWidgetExists:
       
   152             retBool = OpWidgetExists( aMessage );
       
   153             aMessage.Complete( retBool );
       
   154             break;
       
   155         case EOpCodeIsWidget:
       
   156             retBool = OpIsWidget( aMessage );
       
   157             aMessage.Complete( retBool );
       
   158             break;
       
   159         case EOpCodeIsWidgetRunning:
       
   160             retBool = OpIsWidgetRunning( aMessage );
       
   161             aMessage.Complete( retBool );
       
   162             break;
       
   163         case EOpWidgetSapiAccessState:
       
   164             retBool = OpWidgetSapiAccessState( aMessage );
       
   165             aMessage.Complete( retBool );
       
   166             break;
       
   167         case EOpCodeIsWidgetInMiniView:
       
   168             retBool = OpIsWidgetInMiniView( aMessage );
       
   169             aMessage.Complete( retBool );
       
   170             break;
       
   171         case EOpCodeIsWidgetInFullView:
       
   172             retBool = OpIsWidgetInFullView( aMessage );
       
   173             aMessage.Complete( retBool );
       
   174             break;
       
   175         case EOpCodeIsWidgetPromptNeeded:
       
   176             retBool = OpIsWidgetPromptNeeded( aMessage );
       
   177             aMessage.Complete( retBool );
       
   178             break;
       
   179         case EOpCodeWidgetCount:
       
   180             count = OpWidgetCount( aMessage );
       
   181             aMessage.Complete( count );
       
   182             break;
       
   183         case EOpCodeInstalledWidgetsPhase1:
       
   184             len = OpInstalledWidgetsPhase1L( aMessage );
       
   185             aMessage.Complete( len );
       
   186             break;
       
   187         case EOpCodeInstalledWidgetsPhase2:
       
   188             len = OpInstalledWidgetsPhase2L( aMessage );
       
   189             aMessage.Complete( len );
       
   190             break;
       
   191         case EOpCodeRunningWidgetsPhase1:
       
   192             len = OpRunningWidgetsPhase1L( aMessage );
       
   193             aMessage.Complete( len );
       
   194             break;
       
   195         case EOpCodeRunningWidgetsPhase2:
       
   196             len = OpRunningWidgetsPhase2L( aMessage );
       
   197             aMessage.Complete( len );
       
   198             break;
       
   199         case EOpCodeGetWidgetBundleId:
       
   200             len = OpGetWidgetBundleId( aMessage );
       
   201             aMessage.Complete( len );
       
   202             break;
       
   203         case EOpCodeGetWidgetBundleName:
       
   204             len = OpGetWidgetBundleName( aMessage );
       
   205             aMessage.Complete( len );
       
   206             break;
       
   207         case EOpCodeGetWidgetPropertyValue:
       
   208             error = OpGetWidgetPropertyValueL( aMessage );
       
   209             aMessage.Complete( error );
       
   210             break;
       
   211         case EOpCodeGetWidgetPath:
       
   212             len = OpGetWidgetPath( aMessage );
       
   213             aMessage.Complete( len );
       
   214             break;
       
   215         case EOpCodeGetWidgetUid:
       
   216             uid = OpGetWidgetUid( aMessage );
       
   217             aMessage.Complete( uid );
       
   218             break;
       
   219         case EOpCodeGetWidgetUidForUrl:
       
   220             uid = OpGetWidgetUidForUrl( aMessage );
       
   221             aMessage.Complete( uid );
       
   222             break;
       
   223         case EOpCodeDeRegisterWidget:
       
   224             OpDeRegisterWidgetL( aMessage );
       
   225             aMessage.Complete( KErrNone );
       
   226             break;
       
   227         case EOpCodeGetAvailableUid:
       
   228             uid = OpGetAvailableUidL( aMessage );
       
   229             aMessage.Complete( uid );
       
   230             break;
       
   231         case EOpCodeSetActive:
       
   232             OpSetActive( aMessage );
       
   233             aMessage.Complete( KErrNone );
       
   234             break;
       
   235         case EOpCodeWidgetRegistryDisconnect:
       
   236             OpDisconnect( aMessage );
       
   237             aMessage.Complete( KErrNone );
       
   238             break;
       
   239         case EOpCodeGetLprojName:
       
   240             len = OpGetLprojNameL( aMessage );
       
   241             aMessage.Complete( len );
       
   242             break;
       
   243         case EOpCodeSecurityPolicyId:
       
   244             policyId = OpSecurityPolicyId( aMessage );
       
   245             aMessage.Complete( policyId );
       
   246             break;        
       
   247         case EOpCodeSetWidgetInMiniView:
       
   248             OpSetMiniView( aMessage );
       
   249             aMessage.Complete( KErrNone );
       
   250             break;	
       
   251         case EOpCodeSetWidgetInFullView:
       
   252             OpSetFullView( aMessage );
       
   253             aMessage.Complete( KErrNone );
       
   254             break;
       
   255         case EOpCodeSetWidgetPromptNeeded:
       
   256             OpSetPromptNeeded( aMessage );
       
   257             aMessage.Complete( KErrNone );
       
   258             break;
       
   259         default:
       
   260             User::Leave( KErrNotSupported );
       
   261             break;
       
   262         }
       
   263     }
       
   264 
       
   265 // ============================================================================
       
   266 // CWidgetRegistryServerSession::ServiceError()
       
   267 // Handles leaves from ServiceL()
       
   268 //
       
   269 // @since 3.1
       
   270 // ============================================================================
       
   271 //
       
   272 void CWidgetRegistryServerSession::ServiceError( const RMessage2& aMessage,
       
   273                                                  TInt aError )
       
   274     {
       
   275     const TInt function = aMessage.Function();
       
   276 
       
   277     // supply the correct error return message params for each opcode
       
   278     switch ( function )
       
   279         {
       
   280         // TODO many of these opcodes have no provision for proper
       
   281         // error signalling and need to be reworked to communicate
       
   282         // error codes
       
   283         case EOpCodeRegisterWidget:
       
   284             aMessage.Complete( aError );
       
   285             break;
       
   286         case EOpCodeWidgetExists:
       
   287             aMessage.Complete( EFalse );
       
   288             break;
       
   289         case EOpCodeIsWidget:
       
   290             aMessage.Complete( EFalse );
       
   291             break;
       
   292         case EOpCodeIsWidgetRunning:
       
   293             aMessage.Complete( EFalse );
       
   294             break;
       
   295         case EOpCodeIsWidgetInMiniView:
       
   296             aMessage.Complete( EFalse );
       
   297             break;
       
   298         case EOpCodeIsWidgetInFullView:
       
   299             aMessage.Complete( EFalse );
       
   300             break;
       
   301         case EOpCodeIsWidgetPromptNeeded:
       
   302             aMessage.Complete( EFalse );
       
   303             break;
       
   304         case EOpCodeWidgetCount:
       
   305             aMessage.Complete( 0 );
       
   306             break;
       
   307         case EOpCodeInstalledWidgetsPhase1:
       
   308             aMessage.Complete( 0 );
       
   309             break;
       
   310         case EOpCodeInstalledWidgetsPhase2:
       
   311             aMessage.Complete( 0 );
       
   312             break;
       
   313         case EOpCodeRunningWidgetsPhase1:
       
   314             aMessage.Complete( 0 );
       
   315             break;
       
   316         case EOpCodeRunningWidgetsPhase2:
       
   317             aMessage.Complete( 0 );
       
   318             break;
       
   319         case EOpCodeGetWidgetBundleId:
       
   320             aMessage.Complete( 0 );
       
   321             break;
       
   322         case EOpCodeGetWidgetBundleName:
       
   323             aMessage.Complete( 0 );
       
   324             break;
       
   325         case EOpCodeGetWidgetPropertyValue:
       
   326             aMessage.Complete( aError );
       
   327             break;
       
   328         case EOpCodeGetWidgetPath:
       
   329             aMessage.Complete( 0 );
       
   330             break;
       
   331         case EOpCodeGetWidgetUid:
       
   332             aMessage.Complete( KNullUid.iUid );
       
   333             break;
       
   334         case EOpCodeGetWidgetUidForUrl:
       
   335             aMessage.Complete( KNullUid.iUid );
       
   336             break;
       
   337         case EOpCodeDeRegisterWidget:
       
   338             aMessage.Complete( aError );
       
   339             break;
       
   340         case EOpCodeGetAvailableUid:
       
   341             aMessage.Complete( KNullUid.iUid );
       
   342             break;
       
   343         case EOpCodeSetActive:
       
   344             aMessage.Complete( aError );
       
   345             break;
       
   346         case EOpCodeWidgetRegistryDisconnect:
       
   347             aMessage.Complete( aError );
       
   348             break;
       
   349         case EOpCodeGetLprojName:
       
   350             aMessage.Complete( 0 );
       
   351             break;
       
   352         case EOpCodeSecurityPolicyId:
       
   353             aMessage.Complete( 0 );
       
   354             break;  
       
   355         case EOpCodeSetWidgetInMiniView:
       
   356             aMessage.Complete( EFalse );
       
   357             break;
       
   358         case EOpCodeSetWidgetInFullView:
       
   359             aMessage.Complete( EFalse );
       
   360             break;
       
   361         case EOpCodeSetWidgetPromptNeeded:
       
   362             aMessage.Complete( EFalse );
       
   363             break;
       
   364         case EOpWidgetSapiAccessState:
       
   365             aMessage.Complete( EFalse );
       
   366             break;        
       
   367         default:
       
   368             aMessage.Complete( aError );
       
   369             break;
       
   370         }
       
   371     }
       
   372 
       
   373 
       
   374 // ============================================================================
       
   375 // CWidgetRegistryServerSession::OpRegisterWidgetL()
       
   376 // Registers the widget
       
   377 //
       
   378 // @since 3.1
       
   379 // ============================================================================
       
   380 //
       
   381 TInt CWidgetRegistryServerSession::OpRegisterWidgetL(
       
   382     const RMessage2& aMessage )
       
   383     {
       
   384     // ARGS: 0 -> descriptor to buf of serialized property values
       
   385     TInt l = aMessage.GetDesMaxLength( 0 );
       
   386     HBufC8* msgData = HBufC8::NewLC( l );
       
   387     TPtr8 readPtr( msgData->Des() );
       
   388     aMessage.ReadL( 0, readPtr );
       
   389     RDesReadStream stream( *msgData );
       
   390     CleanupClosePushL( stream );
       
   391 
       
   392     iWidgetRegistry->RegisterWidgetL( stream );
       
   393 
       
   394     CleanupStack::PopAndDestroy( 2 ); //stream, msgData,
       
   395     return KErrNone;
       
   396     }
       
   397 
       
   398 // ============================================================================
       
   399 // CWidgetRegistryServerSession::OpIsWidget()
       
   400 // Returns true if the given UId falls within the range allocated for widgets
       
   401 //
       
   402 // @since 3.1
       
   403 // ============================================================================
       
   404 //
       
   405 TBool CWidgetRegistryServerSession::OpIsWidget(
       
   406     const RMessage2& aMessage )
       
   407     {
       
   408     TInt uid = 0;
       
   409     TBool retVal( EFalse );
       
   410 
       
   411     uid = aMessage.Int0();
       
   412     retVal = iWidgetRegistry->IsWidget( TUid::Uid( uid ) );
       
   413 
       
   414     return retVal;
       
   415     }
       
   416 
       
   417 // ============================================================================
       
   418 // CWidgetRegistryServerSession::OpWidgetExists()
       
   419 // Returns true if the widget with the given UId has been installed.
       
   420 //
       
   421 // @since 3.1
       
   422 // ============================================================================
       
   423 //
       
   424 TBool CWidgetRegistryServerSession::OpWidgetExists(
       
   425     const RMessage2& aMessage )
       
   426     {
       
   427     TBool retVal( EFalse );
       
   428     TBuf<KWidgetRegistryVal> bundleId;
       
   429     TInt len = aMessage.Int1();
       
   430 
       
   431     if ( len < 1 || len > KWidgetRegistryVal )
       
   432         {
       
   433         return retVal;
       
   434         }
       
   435 
       
   436     bundleId.SetLength( len );
       
   437     TRAP_IGNORE( aMessage.ReadL( 0, bundleId ) )
       
   438 
       
   439     retVal = iWidgetRegistry->WidgetExists( bundleId );
       
   440 
       
   441     return retVal;
       
   442     }
       
   443 
       
   444 
       
   445 // ============================================================================
       
   446 // CWidgetRegistryServerSession::OpIsWidgetRunning()
       
   447 // Returns running status of the widget with the given UId.
       
   448 //
       
   449 // @since 3.1
       
   450 // ============================================================================
       
   451 //
       
   452 TBool CWidgetRegistryServerSession::OpIsWidgetRunning(
       
   453     const RMessage2& aMessage )
       
   454     {
       
   455     TInt uid = 0;
       
   456     TBool retVal( EFalse );
       
   457 
       
   458     uid = aMessage.Int0();
       
   459     retVal = iWidgetRegistry->IsWidgetRunning( TUid::Uid( uid ) );
       
   460 
       
   461     return retVal;
       
   462     }
       
   463 // ============================================================================
       
   464 // CWidgetRegistryServerSession::OpWidgetSapiAccessState()
       
   465 // Returns widget sapi access state is prompted, promptless or denied.
       
   466 //
       
   467 // @since 5.0
       
   468 // ============================================================================
       
   469 //
       
   470 TInt CWidgetRegistryServerSession::OpWidgetSapiAccessState(
       
   471     const RMessage2& aMessage )
       
   472     {
       
   473     TInt uid = 0;
       
   474     TInt retVal( -1 );
       
   475 
       
   476     uid = aMessage.Int0();
       
   477     retVal = iWidgetRegistry->WidgetSapiAccessState( TUid::Uid( uid ) );
       
   478 
       
   479     return retVal;
       
   480     }
       
   481 
       
   482 // ============================================================================
       
   483 // CWidgetRegistryServerSession::OpIsWidgetInMiniView()
       
   484 // Returns status whether widget is started in miniview or not.
       
   485 //
       
   486 // @since 
       
   487 // ============================================================================
       
   488 //
       
   489 TBool CWidgetRegistryServerSession::OpIsWidgetInMiniView(
       
   490     const RMessage2& aMessage )
       
   491     {
       
   492     TInt uid = 0;
       
   493     TBool retVal( EFalse );
       
   494 
       
   495     uid = aMessage.Int0();
       
   496     retVal = iWidgetRegistry->IsWidgetInMiniView( TUid::Uid( uid ) );
       
   497 
       
   498     return retVal;
       
   499     }
       
   500 
       
   501 // ============================================================================
       
   502 // CWidgetRegistryServerSession::OpIsWidgetInFullView()
       
   503 // Returns status whether widget is started in full view or not.
       
   504 //
       
   505 // @since 
       
   506 // ============================================================================
       
   507 //
       
   508 TBool CWidgetRegistryServerSession::OpIsWidgetInFullView(
       
   509     const RMessage2& aMessage )
       
   510     {
       
   511     TInt uid = 0;
       
   512     TBool retVal( EFalse );
       
   513 
       
   514     uid = aMessage.Int0();
       
   515     retVal = iWidgetRegistry->IsWidgetInFullView( TUid::Uid( uid ) );
       
   516 
       
   517     return retVal;
       
   518     }
       
   519 
       
   520 // ============================================================================
       
   521 // CWidgetRegistryServerSession::OpIsWidgetPromptNeeded()
       
   522 // Returns status whether miniview platform access prompt is needed or not.
       
   523 //
       
   524 // @since  5.0
       
   525 // ============================================================================
       
   526 //
       
   527 TBool CWidgetRegistryServerSession::OpIsWidgetPromptNeeded(
       
   528     const RMessage2& aMessage )
       
   529     {
       
   530     TInt uid = 0;
       
   531     TBool retVal( EFalse );
       
   532 
       
   533     uid = aMessage.Int0();
       
   534     retVal = iWidgetRegistry->IsBlanketPermGranted( TUid::Uid( uid ) );
       
   535 
       
   536     return retVal;
       
   537     }
       
   538 
       
   539 // ============================================================================
       
   540 // CWidgetRegistryServerSession::OpWidgetCount()
       
   541 // Returns count of installed widgets
       
   542 //
       
   543 // @since 3.1
       
   544 // ============================================================================
       
   545 //
       
   546 TInt CWidgetRegistryServerSession::OpWidgetCount(
       
   547     const RMessage2& /*aMessage*/ )
       
   548     {
       
   549     return iWidgetRegistry->WidgetCount();
       
   550     }
       
   551 
       
   552 // ============================================================================
       
   553 // CWidgetRegistryServerSession::OpInstalledWidgetsPhase1L()
       
   554 // gets total size of all elements in the widgetinfo array in terms of
       
   555 // buffer length; negative value means one of the system-wide error
       
   556 //
       
   557 // @since 3.1
       
   558 // ============================================================================
       
   559 //
       
   560 TInt CWidgetRegistryServerSession::OpInstalledWidgetsPhase1L(
       
   561     const RMessage2& /*aMessage*/ )
       
   562     {
       
   563     TInt ret = 0;
       
   564 
       
   565     RWidgetInfoArray widgetInfoArr;
       
   566     CleanupStack::PushL( TCleanupItem( 
       
   567             CWidgetRegistryServerSession::ResetAndDestroy, &widgetInfoArr ) );
       
   568     
       
   569     iWidgetRegistry->InstalledWidgetsL( widgetInfoArr );
       
   570         
       
   571     if ( widgetInfoArr.Count() > 0 )
       
   572         {
       
   573         ret = widgetInfoArr.Count() * ( 4 * sizeof( TInt ) +
       
   574             KWidgetRegistryVal + 1 + KMaxDriveName + 1 + 1 );
       
   575         }
       
   576 
       
   577     CleanupStack::PopAndDestroy(&widgetInfoArr);
       
   578     
       
   579     return ret;
       
   580     }
       
   581 
       
   582 // ============================================================================
       
   583 // CWidgetRegistryServerSession::OpInstalledWidgetsPhase2L()
       
   584 // Sets widgetinfo array of the installed widgets in the message itself
       
   585 //
       
   586 // @since 3.1
       
   587 // ============================================================================
       
   588 //
       
   589 TInt CWidgetRegistryServerSession::OpInstalledWidgetsPhase2L(
       
   590     const RMessage2& aMessage )
       
   591     {
       
   592     TInt ret = 0;
       
   593 
       
   594     RWidgetInfoArray widgetInfoArr;
       
   595     CleanupStack::PushL( TCleanupItem(
       
   596             CWidgetRegistryServerSession::ResetAndDestroy, &widgetInfoArr) );
       
   597     iWidgetRegistry->InstalledWidgetsL( widgetInfoArr );
       
   598 
       
   599     TInt error = KErrNone;
       
   600     HBufC8* widgetInfoDes = NULL;
       
   601 
       
   602     TRAP( error, widgetInfoDes = MarshalDataL( widgetInfoArr ) );
       
   603     CleanupStack::PushL( widgetInfoDes );
       
   604 
       
   605     if ( error == KErrNone )
       
   606         {
       
   607         ret = widgetInfoArr.Count();
       
   608         aMessage.WriteL( 0, *widgetInfoDes );
       
   609         }
       
   610 
       
   611     
       
   612     CleanupStack::PopAndDestroy( 2 );
       
   613 
       
   614     return ret;
       
   615     }
       
   616 
       
   617 // ============================================================================
       
   618 // CWidgetRegistryServerSession::OpRunningWidgetsPhase1L()
       
   619 // gets total size of all elements in the widgetinfo array in terms of
       
   620 // buffer length; negative value means one of the system-wide error
       
   621 //
       
   622 // @since 3.1
       
   623 // ============================================================================
       
   624 //
       
   625 TInt CWidgetRegistryServerSession::OpRunningWidgetsPhase1L(
       
   626     const RMessage2& /*aMessage*/ )
       
   627     {
       
   628     TInt ret = 0;
       
   629 
       
   630     RWidgetInfoArray widgetInfoArr;
       
   631     CleanupStack::PushL( TCleanupItem(
       
   632             CWidgetRegistryServerSession::ResetAndDestroy, &widgetInfoArr ));
       
   633     iWidgetRegistry->RunningWidgetsL( widgetInfoArr );
       
   634 
       
   635     if ( widgetInfoArr.Count() > 0 )
       
   636         {
       
   637         ret = widgetInfoArr.Count() * ( 4 * sizeof( TInt ) +
       
   638             KWidgetRegistryVal + 1 + KMaxDriveName + 1 + 1 );
       
   639         }
       
   640 
       
   641     
       
   642     CleanupStack::PopAndDestroy();
       
   643 
       
   644     return ret;
       
   645     }
       
   646 
       
   647 // ============================================================================
       
   648 // CWidgetRegistryServerSession::OpRunningWidgetsPhase2L()
       
   649 // Sets widgetinfo array of the running widgets in the message itself
       
   650 //
       
   651 // @since 3.1
       
   652 // ============================================================================
       
   653 //
       
   654 TInt CWidgetRegistryServerSession::OpRunningWidgetsPhase2L(
       
   655     const RMessage2& aMessage )
       
   656     {
       
   657     TInt ret = 0;
       
   658 
       
   659     RWidgetInfoArray widgetInfoArr;
       
   660     CleanupStack::PushL( TCleanupItem(
       
   661             CWidgetRegistryServerSession::ResetAndDestroy, &widgetInfoArr) );
       
   662     iWidgetRegistry->RunningWidgetsL( widgetInfoArr );
       
   663 
       
   664     TInt error = KErrNone;
       
   665     HBufC8* widgetInfoDes = NULL;
       
   666 
       
   667     TRAP( error, widgetInfoDes = MarshalDataL( widgetInfoArr ) );
       
   668     CleanupStack::PushL( widgetInfoDes );
       
   669 
       
   670     if ( error == KErrNone )
       
   671         {
       
   672         ret = widgetInfoArr.Count();
       
   673         aMessage.WriteL( 0, *widgetInfoDes );
       
   674         }
       
   675 
       
   676     CleanupStack::PopAndDestroy( 2 );
       
   677 
       
   678     return ret;
       
   679     }
       
   680 
       
   681 // ============================================================================
       
   682 // CWidgetRegistryServerSession::OpGetWidgetBundleId()
       
   683 // Returns bundleId of the widget with the given UId.
       
   684 //
       
   685 // @since 3.1
       
   686 // ============================================================================
       
   687 //
       
   688 TInt CWidgetRegistryServerSession::OpGetWidgetBundleId(
       
   689     const RMessage2& aMessage )
       
   690     {
       
   691     TInt ret = 0;
       
   692     TInt uid = aMessage.Int2();
       
   693     TBuf<KWidgetRegistryVal> buf;
       
   694 
       
   695     buf.SetLength( aMessage.Int1() );
       
   696     TRAP_IGNORE( aMessage.ReadL( 0, buf ) )
       
   697     iWidgetRegistry->GetWidgetBundleId( TUid::Uid( uid ), buf );
       
   698     TRAP_IGNORE( aMessage.WriteL( 0, buf ) )
       
   699     ret = buf.Length();
       
   700 
       
   701     return ret;
       
   702     }
       
   703 
       
   704 // ============================================================================
       
   705 // CWidgetRegistryServerSession::OpGetWidgetBundleName()
       
   706 // Returns bundle display name of the widget with the given UId.
       
   707 //
       
   708 // @since 3.1
       
   709 // ============================================================================
       
   710 //
       
   711 TInt CWidgetRegistryServerSession::OpGetWidgetBundleName(
       
   712     const RMessage2& aMessage )
       
   713     {
       
   714     TInt ret = 0;
       
   715     TInt uid = aMessage.Int2();
       
   716     TBuf<KWidgetRegistryVal> buf;
       
   717     buf.SetLength( aMessage.Int1() );
       
   718     iWidgetRegistry->GetWidgetBundleName( TUid::Uid( uid ), buf );
       
   719     TRAP_IGNORE( aMessage.WriteL( 0, buf ) )
       
   720     ret = buf.Length();
       
   721 
       
   722     return ret;
       
   723     }
       
   724 
       
   725 // ============================================================================
       
   726 // CWidgetRegistryServerSession::OpGetWidgetPropertyValue()
       
   727 // Produces serialized value and error code
       
   728 //
       
   729 // @since 3.1
       
   730 // ============================================================================
       
   731 //
       
   732 TInt CWidgetRegistryServerSession::OpGetWidgetPropertyValueL(
       
   733     const RMessage2& aMessage )
       
   734     {
       
   735     // ARGS( 0 -> UID, 1 -> TWidgetPropertyId,
       
   736     //       2 -> descriptor for buffer to hold serialization of value )
       
   737     // returns error code
       
   738     TRAPD( error,
       
   739     {
       
   740     TUid uid( TUid::Uid( aMessage.Int0() ) );
       
   741     TWidgetPropertyId propId = static_cast<TWidgetPropertyId>(aMessage.Int1());
       
   742     TInt maxLength = aMessage.GetDesMaxLength( 2 );
       
   743 
       
   744     CBufFlat* buf = iWidgetRegistry->GetWidgetPropertyValueL(
       
   745         uid, propId, maxLength );
       
   746 
       
   747     CleanupStack::PushL( buf );
       
   748     aMessage.WriteL( 2, buf->Ptr(0) );
       
   749     CleanupStack::PopAndDestroy(); // buf
       
   750     }
       
   751         );
       
   752     return error;
       
   753     }
       
   754 
       
   755 // ============================================================================
       
   756 // CWidgetRegistryServerSession::OpGetWidgetPath()
       
   757 // Returns path of the widget with the given UId.
       
   758 //
       
   759 // @since 3.1
       
   760 // ============================================================================
       
   761 //
       
   762 TInt CWidgetRegistryServerSession::OpGetWidgetPath(
       
   763     const RMessage2& aMessage )
       
   764     {
       
   765     TInt ret = 0;
       
   766     TInt uid = aMessage.Int2();
       
   767     TBuf<KWidgetRegistryVal> path;
       
   768 
       
   769     path.SetLength( aMessage.Int1() );
       
   770     TRAP_IGNORE( aMessage.ReadL( 0, path ) )
       
   771     iWidgetRegistry->GetWidgetPath( TUid::Uid( uid ), path );
       
   772     TRAP_IGNORE( aMessage.WriteL( 0, path ) )
       
   773     ret = path.Length();
       
   774 
       
   775     return ret;
       
   776     }
       
   777 
       
   778 // ============================================================================
       
   779 // CWidgetRegistryServerSession::OpGetWidgetUid()
       
   780 // Returns UId of the widget with the given bundle Id.
       
   781 //
       
   782 // @since 3.1
       
   783 // ============================================================================
       
   784 //
       
   785 TInt CWidgetRegistryServerSession::OpGetWidgetUid(
       
   786     const RMessage2& aMessage )
       
   787     {
       
   788     TUid uid = TUid::Uid( 0 );
       
   789     TBuf<KWidgetRegistryVal> bundleId;
       
   790     TInt len = aMessage.Int1();
       
   791 
       
   792     if ( len < 1 || len > KWidgetRegistryVal )
       
   793         {
       
   794         return 0;
       
   795         }
       
   796 
       
   797     bundleId.SetLength( len );
       
   798     TRAP_IGNORE( aMessage.ReadL( 0, bundleId ) )
       
   799     uid = iWidgetRegistry->GetWidgetUid( bundleId );
       
   800 
       
   801     return uid.iUid;
       
   802     }
       
   803 
       
   804 // ============================================================================
       
   805 // CWidgetRegistryServerSession::OpGetWidgetUidForUrl()
       
   806 // Returns UId of the widget with the given Url
       
   807 //
       
   808 // @since 3.1
       
   809 // ============================================================================
       
   810 //
       
   811 TInt CWidgetRegistryServerSession::OpGetWidgetUidForUrl(
       
   812     const RMessage2& aMessage )
       
   813     {
       
   814     TBuf<KWidgetRegistryVal> url;
       
   815     TInt len = aMessage.Int1();
       
   816 
       
   817     if ( len < 1 || len > KWidgetRegistryVal )
       
   818         {
       
   819         return 0;
       
   820         }
       
   821 
       
   822     url.SetLength( len );
       
   823     TRAP_IGNORE( aMessage.ReadL( 0, url ) )
       
   824     TInt uid = ( iWidgetRegistry->GetWidgetUidForUrl( url ) ).iUid;
       
   825 
       
   826     return uid;
       
   827     }
       
   828 
       
   829 // ============================================================================
       
   830 // CWidgetRegistryServerSession::OpDeRegisterWidgetL()
       
   831 // Deregister the widget
       
   832 //
       
   833 // @since 3.1
       
   834 // ============================================================================
       
   835 //
       
   836 TInt CWidgetRegistryServerSession::OpDeRegisterWidgetL(
       
   837     const RMessage2& aMessage )
       
   838     {
       
   839     TInt uid;
       
   840     TInt ret = KErrNone;
       
   841 
       
   842     uid = aMessage.Int0();
       
   843     iWidgetRegistry->DeRegisterWidgetL( TUid::Uid( uid ) );
       
   844 
       
   845     return ret;
       
   846     }
       
   847 
       
   848 // ============================================================================
       
   849 // CWidgetRegistryServerSession::OpGetAvailableUidL()
       
   850 // Returns next available UId
       
   851 //
       
   852 // @since 3.1
       
   853 // ============================================================================
       
   854 //
       
   855 TInt CWidgetRegistryServerSession::OpGetAvailableUidL(
       
   856     const RMessage2& aMessage )
       
   857     {
       
   858     TUid uid = TUid::Uid( 0 );
       
   859     uid = iWidgetRegistry->GetAvailableUidL( aMessage.Int0() );
       
   860 
       
   861     return uid.iUid;
       
   862     }
       
   863 
       
   864 // ============================================================================
       
   865 // CWidgetRegistryServerSession::OpGetLprojName()
       
   866 // Returns language project name for directory which holds the localized content
       
   867 //
       
   868 // @since 3.1
       
   869 // ============================================================================
       
   870 //
       
   871 TInt CWidgetRegistryServerSession::OpGetLprojNameL(
       
   872     const RMessage2& aMessage )
       
   873     {
       
   874     TBuf<KWidgetRegistryVal> aLprojName;
       
   875 
       
   876     aLprojName.SetLength( aMessage.Int1() );
       
   877     aMessage.ReadL( 0, aLprojName );
       
   878     iWidgetRegistry->GetLprojNameL( aLprojName );
       
   879     aMessage.WriteL( 0, aLprojName );
       
   880 
       
   881     return aLprojName.Length();
       
   882     }
       
   883 
       
   884 // ============================================================================
       
   885 // CWidgetRegistryServerSession::OpSetActive()
       
   886 // Set/Reset active status of the widget
       
   887 //
       
   888 // @since 3.1
       
   889 // ============================================================================
       
   890 //
       
   891 void CWidgetRegistryServerSession::OpSetActive( const RMessage2& aMessage )
       
   892     {
       
   893     TInt uid = aMessage.Int0();
       
   894     TInt status = aMessage.Int1();
       
   895     iWidgetRegistry->SetActive( TUid::Uid( uid ), status );
       
   896     }
       
   897 
       
   898 // ============================================================================
       
   899 // CWidgetRegistryServerSession::OpSetMiniView()
       
   900 // Set/Reset Widget status for launched in MiniView
       
   901 //
       
   902 // @since 
       
   903 // ============================================================================
       
   904 //
       
   905 void CWidgetRegistryServerSession::OpSetMiniView( const RMessage2& aMessage )
       
   906     {
       
   907     TInt uid = aMessage.Int0();
       
   908     TInt status = aMessage.Int1();
       
   909     iWidgetRegistry->SetMiniView( TUid::Uid( uid ), status );
       
   910     }
       
   911 
       
   912 // ============================================================================
       
   913 // CWidgetRegistryServerSession::OpSetFullView()
       
   914 // Set/Reset Widget status in FullView
       
   915 //
       
   916 // @since 
       
   917 // ============================================================================
       
   918 //
       
   919 void CWidgetRegistryServerSession::OpSetFullView( const RMessage2& aMessage )
       
   920     {
       
   921     TInt uid = aMessage.Int0();
       
   922     TInt status = aMessage.Int1();
       
   923     iWidgetRegistry->SetFullView( TUid::Uid( uid ), status );
       
   924     }
       
   925 
       
   926 // ============================================================================
       
   927 // CWidgetRegistryServerSession::OpSetPromptNeeded()
       
   928 // Set/Reset Widget miniview platform access prompt is needed
       
   929 //
       
   930 // @since 
       
   931 // ============================================================================
       
   932 //
       
   933 void CWidgetRegistryServerSession::OpSetPromptNeeded( const RMessage2& aMessage )
       
   934     {
       
   935     TInt uid = aMessage.Int0();
       
   936     TInt status = aMessage.Int1();
       
   937     TRAP_IGNORE(iWidgetRegistry->SetBlanketPermissionL( TUid::Uid( uid ), status ));
       
   938     }
       
   939 
       
   940 // ============================================================================
       
   941 // CWidgetRegistryServerSession::OpDisconnect()
       
   942 // Disconnects session with server
       
   943 //
       
   944 // @since 3.1
       
   945 // ============================================================================
       
   946 //
       
   947 TInt CWidgetRegistryServerSession::OpDisconnect(
       
   948     const RMessage2& /*aMessage*/ )
       
   949     {
       
   950     TInt ret = KErrNone;
       
   951     CWidgetRegistryServer* server;
       
   952 
       
   953     server = static_cast<CWidgetRegistryServer*>(
       
   954         const_cast<CServer2*>( Server() ) );
       
   955 
       
   956     if ( server )
       
   957         {
       
   958         server->RemoveSession();
       
   959         }
       
   960 
       
   961     return ret;
       
   962     }
       
   963 
       
   964 // ============================================================================
       
   965 // CWidgetRegistryServerSession::OpSecurityPolicyId()
       
   966 // Returns security policy Id
       
   967 //
       
   968 // @since 5.0
       
   969 // ============================================================================
       
   970 //
       
   971 TInt CWidgetRegistryServerSession::OpSecurityPolicyId(
       
   972     const RMessage2& /*aMessage*/ )
       
   973     {
       
   974     return iWidgetRegistry->SecurityPolicyId();
       
   975     }
       
   976 
       
   977 // ============================================================================
       
   978 // CWidgetRegistryServerSession::WidgetRegistryServer()
       
   979 // Returns server object
       
   980 //
       
   981 // @since 3.1
       
   982 // ============================================================================
       
   983 //
       
   984 CWidgetRegistryServer& CWidgetRegistryServerSession::WidgetRegistryServer()
       
   985     {
       
   986     return static_cast<CWidgetRegistryServer&>(
       
   987         *const_cast<CServer2*>( Server() ) );
       
   988     }
       
   989 
       
   990 // ============================================================================
       
   991 // CWidgetRegistryServerSession::MarshalDataL()
       
   992 // Creates and returns heap descriptor which holds contents of RWidgetInfoArray
       
   993 // @since 3.1
       
   994 // ============================================================================
       
   995 //
       
   996 HBufC8* CWidgetRegistryServerSession::MarshalDataL(
       
   997     RWidgetInfoArray& aWidgetInfoArr )
       
   998     {
       
   999     // Create a dynamic flat buffer to hold the data data
       
  1000     const TInt KExpandSize = 128; // "Granularity" of dynamic buffer
       
  1001     CBufFlat* buf = CBufFlat::NewL( KExpandSize );
       
  1002     CleanupStack::PushL( buf );
       
  1003     RBufWriteStream stream( *buf ); // Stream over the buffer
       
  1004     CleanupClosePushL( stream );
       
  1005     ExternalizeL( stream, aWidgetInfoArr );
       
  1006     CleanupStack::PopAndDestroy( &stream );
       
  1007 
       
  1008     // Create a heap descriptor from the buffer
       
  1009     HBufC8* des = HBufC8::NewL( buf->Size() );
       
  1010     TPtr8 ptr( des->Des() );
       
  1011     buf->Read( 0, ptr, buf->Size() );
       
  1012 
       
  1013     CleanupStack::PopAndDestroy( buf ); // Finished with the buffer
       
  1014     return ( des );
       
  1015     }
       
  1016 
       
  1017 // ============================================================================
       
  1018 // CWidgetRegistryServerSession::ExternalizeL()
       
  1019 // Write data to aStream
       
  1020 //
       
  1021 // @since 3.1
       
  1022 // ============================================================================
       
  1023 //
       
  1024 void CWidgetRegistryServerSession::ExternalizeL(
       
  1025     RWriteStream& aStream,
       
  1026     RWidgetInfoArray& aWidgetInfoArr )
       
  1027     {
       
  1028     TInt len = 0;
       
  1029 
       
  1030     for ( TInt i = 0; i < aWidgetInfoArr.Count(); i++ )
       
  1031         {
       
  1032         aStream.WriteInt32L( aWidgetInfoArr[i]->iUid.iUid );
       
  1033         aStream.WriteInt32L( aWidgetInfoArr[i]->iFileSize );
       
  1034 
       
  1035         len = aWidgetInfoArr[i]->iBundleName->Length();
       
  1036         aStream.WriteInt32L( len );
       
  1037         aStream.WriteL( *(aWidgetInfoArr[i]->iBundleName), len );
       
  1038 
       
  1039         len = aWidgetInfoArr[i]->iDriveName->Length();
       
  1040         aStream.WriteInt32L( len );
       
  1041         aStream.WriteL( *(aWidgetInfoArr[i]->iDriveName), len );
       
  1042         }
       
  1043     }
       
  1044 
       
  1045 // ============================================================================
       
  1046 // CWidgetRegistryServerSession::ResetWidgetInfo()
       
  1047 // delete each item in RWidgetInfoArray before closing it
       
  1048 //
       
  1049 // @since 3.1
       
  1050 // ============================================================================
       
  1051 //
       
  1052 void CWidgetRegistryServerSession::ResetWidgetInfo(
       
  1053     RWidgetInfoArray& aWidgetInfoArr )
       
  1054     {
       
  1055     for ( TInt i = 0; i < aWidgetInfoArr.Count(); i++ )
       
  1056         {
       
  1057         CWidgetInfo *item = aWidgetInfoArr[i];
       
  1058         delete item ;
       
  1059         }
       
  1060     }
       
  1061 
       
  1062 // End of File
       
  1063 
       
  1064 
       
  1065