homescreensrv_plat/sapi_homescreenplugin/src/hspscallback.cpp
changeset 85 7feec50967db
parent 4 1a2a00e78665
child 86 e492551a0d54
equal deleted inserted replaced
4:1a2a00e78665 85:7feec50967db
     1 /*
       
     2 * Copyright (c) 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hspscallback.h"
       
    19 #include "hspsconfigurationservice.h"
       
    20 #include "hspsliwvocabulary.hrh"
       
    21 #include "hspsserviceutilities.h"
       
    22 #include <hspsdefinitionrepository.h>
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Two-phase Constructor
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CHspsReqNotifCallback* CHspsReqNotifCallback::NewL( MLiwNotifyCallback *aPtrNotifyCallback, 
       
    29                                   const CLiwGenericParamList& aPtrInParamList, 
       
    30                                   TInt32 aTransactionId, CHspsConfigurationService& aHspsConfigurationService  )
       
    31     {
       
    32     return new (ELeave)    CHspsReqNotifCallback( aPtrNotifyCallback, aPtrInParamList, aTransactionId,
       
    33         aHspsConfigurationService );
       
    34     }
       
    35     
       
    36 // ---------------------------------------------------------------------------
       
    37 //  Constructor
       
    38 // ---------------------------------------------------------------------------
       
    39 //    
       
    40 CHspsReqNotifCallback::CHspsReqNotifCallback( MLiwNotifyCallback *aPtrNotifyCallback, 
       
    41                             const CLiwGenericParamList& aPtrInParamList, 
       
    42                             TInt32 aTransactionId, CHspsConfigurationService& aHspsConfigurationService )
       
    43     {
       
    44     iPtrNotifyCallback = aPtrNotifyCallback; 
       
    45     iPtrInParamList = &aPtrInParamList;
       
    46     iTransactionId = aTransactionId;
       
    47     iHspsConfigurationService = &aHspsConfigurationService;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 //  Destructor
       
    52 // ---------------------------------------------------------------------------
       
    53 //  
       
    54 CHspsReqNotifCallback::~CHspsReqNotifCallback()
       
    55     {
       
    56     
       
    57     }
       
    58 // ---------------------------------------------------------------------------
       
    59 // Gives the result of asynchronous SAPI calls
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CHspsReqNotifCallback::NotifyResultL( TInt aErrCode,
       
    63         ChspsRequestNotificationParams& aParams, RArray<TInt>& aIds )
       
    64     {
       
    65     
       
    66 
       
    67 
       
    68     CLiwGenericParamList* outParams = CLiwGenericParamList::NewL();
       
    69 
       
    70     CleanupStack::PushL( outParams );
       
    71                             
       
    72     
       
    73     if (  aErrCode == KErrNone )
       
    74         {
       
    75         CLiwDefaultMap* notifMap = CLiwDefaultMap::NewL();       
       
    76         CleanupStack::PushL( notifMap );
       
    77         
       
    78         
       
    79         TPtrC8 event = ConvertEvent2LiwData(aParams.iEvent);
       
    80          
       
    81         notifMap->InsertL( KReqNotifEvent, TLiwVariant( event ) );
       
    82        
       
    83         if( aParams.iAppConfUid )
       
    84             {
       
    85             TBuf8<10> appConfUid;
       
    86             appConfUid.Append( '0' );
       
    87             appConfUid.Append( 'x' );
       
    88             appConfUid.AppendNum( aParams.iAppConfUid, EHex );
       
    89                  
       
    90             notifMap->InsertL( KHspsLiwAppConfUid, TLiwVariant( appConfUid ) );
       
    91             }
       
    92         else
       
    93             {
       
    94             notifMap->InsertL( KHspsLiwAppConfUid, TLiwVariant( KHspsLiwEmptyValue ) );
       
    95             }
       
    96 
       
    97         if( aParams.iOrigUid )
       
    98             {
       
    99             TBuf8<10> origUid;
       
   100             origUid.Append( '0' );
       
   101             origUid.Append( 'x' );
       
   102             origUid.AppendNum( aParams.iOrigUid, EHex );
       
   103                      
       
   104             notifMap->InsertL( KHspsLiwOrigUid, TLiwVariant( origUid ) );
       
   105             }
       
   106         else
       
   107             {
       
   108             notifMap->InsertL( KHspsLiwOrigUid, TLiwVariant( KHspsLiwEmptyValue ) );
       
   109             }
       
   110 
       
   111         if( aParams.Name().Length() > 0 )
       
   112             {
       
   113             TBufC<255> buf(aParams.Name());
       
   114             TDesC& name16 = const_cast<TDesC&>(aParams.Name());            
       
   115             //name ( 16 bit string to 8 bit string )
       
   116             HBufC8* name8 = HBufC8::NewL(  name16.Length() );
       
   117             CleanupStack::PushL( name8 );
       
   118             TPtr8 namePtr = name8->Des();
       
   119             namePtr.Copy( aParams.Name() );
       
   120         
       
   121             notifMap->InsertL( KHspsLiwName, TLiwVariant(  namePtr ));
       
   122             CleanupStack::PopAndDestroy( name8 );
       
   123             }
       
   124         else
       
   125             {
       
   126             notifMap->InsertL( KHspsLiwName, TLiwVariant(  KHspsLiwEmptyValue ));
       
   127             }
       
   128         if( aParams.iPluginUid )
       
   129             {
       
   130             TBuf8<10> pluginUid;
       
   131             pluginUid.Append( '0' );
       
   132             pluginUid.Append( 'x' );
       
   133             pluginUid.AppendNum( aParams.iPluginUid, EHex );
       
   134                      
       
   135             notifMap->InsertL( KHspsLiwPluginUid, TLiwVariant( pluginUid ) );
       
   136             }
       
   137         else
       
   138             {
       
   139             notifMap->InsertL( KHspsLiwPluginUid, TLiwVariant(  KHspsLiwEmptyValue ));
       
   140             }
       
   141          
       
   142         CLiwDefaultList* list = CLiwDefaultList::NewL();
       
   143         CleanupStack::PushL( list );
       
   144         
       
   145        
       
   146         for(TInt i = 0; i< aIds.Count(); i++)
       
   147             {
       
   148             TBuf8<10> pluginId;
       
   149             pluginId.AppendNum( aIds[i], EDecimal );
       
   150             list->AppendL(TLiwVariant( pluginId ));
       
   151             }
       
   152         notifMap->InsertL(KHspsLiwPluginIds, list);
       
   153         
       
   154         
       
   155         
       
   156         TLiwVariant rootMapVariant;
       
   157         rootMapVariant.Set( notifMap );
       
   158         //Put iterable into outParamList
       
   159         TLiwGenericParam rootMapParam;
       
   160         rootMapParam.SetNameAndValueL( KHspsLiwNotification, rootMapVariant );
       
   161         outParams->AppendL( rootMapParam );
       
   162         CleanupStack::Pop( list );
       
   163         list->DecRef(); 
       
   164                 
       
   165         CleanupStack::Pop( notifMap );
       
   166         notifMap->DecRef();
       
   167         rootMapParam.Reset();
       
   168         rootMapVariant.Reset();  
       
   169         }
       
   170     else
       
   171         {
       
   172         outParams->AppendL( TLiwGenericParam(KHspsLiwStatus, 
       
   173                                         TLiwVariant((TInt32) aErrCode )));
       
   174         }
       
   175         
       
   176     //KLiwEventCompleted is used currently since our test cases and system
       
   177     //are not supported  KLiwEventInProgress type of notification mechanism
       
   178     TInt event = KLiwEventInProgress;
       
   179     if ( aErrCode == KErrCancel )
       
   180         {
       
   181    //     event = KLiwEventCanceled;
       
   182         }
       
   183     else if ( aErrCode != KErrNone )
       
   184         {
       
   185    //     event = KLiwEventStopped;
       
   186          
       
   187         outParams->AppendL( TLiwGenericParam(KErrorMessage, 
       
   188                  TLiwVariant(_L("HSPS:RequestNotification:Notification stopped"))));
       
   189         }
       
   190      
       
   191     ((MLiwNotifyCallback*)iPtrNotifyCallback)->HandleNotifyL( iTransactionId, 
       
   192                                                  event, 
       
   193                                                  *outParams, 
       
   194                                                  *((CLiwGenericParamList*)iPtrInParamList) ); 
       
   195                                                  
       
   196     CleanupStack::PopAndDestroy( outParams ); 
       
   197        
       
   198     }
       
   199 // ---------------------------------------------------------------------------
       
   200 // Convert plugin Registry notification event to LIW format
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 const TDesC8& CHspsReqNotifCallback::ConvertEvent2LiwData( TInt aEvent )
       
   204     {
       
   205    
       
   206     if( aEvent == EhspsODTAdded )
       
   207         {
       
   208         return KReqNotifPluginInstalledEvent;
       
   209         }
       
   210     else if( aEvent == EhspsODTUpdated )
       
   211         {
       
   212         return KReqNotifPluginUpdatedEvent;
       
   213         }
       
   214     else if( aEvent == EhspsODTRemoved )
       
   215         {
       
   216         return KReqNotifRemovePluginEvent;
       
   217         }
       
   218     else if( aEvent == EhspsODTModified )
       
   219         {
       
   220         return KReqNotifAddPluginEvent;
       
   221         }
       
   222     else if( aEvent == EhspsSettingsChanged )
       
   223         {
       
   224         return KReqNotifSettingsChangedEvent;
       
   225         }
       
   226     else if( aEvent == EhspsODTActivated )
       
   227         {
       
   228         return KReqNotifAppConfActivetedEvent;
       
   229         }
       
   230     else if( aEvent == EhspsClean )
       
   231         {
       
   232         return KReqNotifPluginUnInstalledEvent;
       
   233         }
       
   234     else if ( aEvent == EhspsPluginActivated )
       
   235         {
       
   236         return KReqNotifPluginActivatedEvent;
       
   237         }
       
   238     else if ( aEvent == EhspsPluginReplaced )
       
   239         {
       
   240         return KReqNotifPluginReplacedEvent;
       
   241         }
       
   242     else
       
   243         {
       
   244         return KNullDesC8;
       
   245         }
       
   246     }
       
   247 
       
   248 // End of file