menufw/hierarchynavigator/hnutilities/src/hnservicehandler.cpp
changeset 0 f72a12da539e
child 9 f966699dea19
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2007-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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <xmlengdom.h>
       
    20 #include <liwservicehandler.h>
       
    21 
       
    22 #include "hnservicehandler.h"
       
    23 #include "hnliwutils.h"
       
    24 #include "hnglobals.h"
       
    25 #include "hnmdbasekey.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 void CHnServiceHandler::ConstructL(
       
    34         const TDesC8& aService, const TDesC8& aInterface,
       
    35         const TDesC8& aCommand,
       
    36         CLiwGenericParamList* aConstructor,
       
    37         CLiwGenericParamList* aServiceCommand )
       
    38     {
       
    39     iServiceName.CreateL( aService );
       
    40     iInterfaceName.CreateL( aInterface );
       
    41     iCommandName.CreateL( aCommand );
       
    42 
       
    43     iServiceHandler = CLiwServiceHandler::NewL();
       
    44     iInput = CLiwGenericParamList::NewL();
       
    45 
       
    46     iOutputForAS = CLiwGenericParamList::NewL();
       
    47 
       
    48     iServiceInterface = NULL;
       
    49     SetServiceInterfaceL( aConstructor );
       
    50 
       
    51     // Please note that by setting these two member variables
       
    52     // we take ownership of aConstructor and aServiceCommand.
       
    53     // No leaving functions may be called in ConstructL from
       
    54     // now on.
       
    55     iConstructor = aConstructor;
       
    56     iCommand = aServiceCommand;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CHnServiceHandler* CHnServiceHandler::NewL(
       
    64         const TDesC8& aService, const TDesC8& aInterface,
       
    65         const TDesC8& aCommand, TServiceMode aMode,
       
    66         CLiwGenericParamList* aConstructor,
       
    67         CLiwGenericParamList* aServiceCommand )
       
    68     {
       
    69     CHnServiceHandler* self = CHnServiceHandler::NewLC( aService, aInterface,
       
    70             aCommand, aMode,  aConstructor, aServiceCommand );
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CHnServiceHandler* CHnServiceHandler::NewLC(
       
    80         const TDesC8& aService, const TDesC8& aInterface,
       
    81         const TDesC8& aCommandName, TServiceMode aMode,
       
    82         CLiwGenericParamList* aConstructor,
       
    83         CLiwGenericParamList* aServiceCommand )
       
    84     {
       
    85     CHnServiceHandler* self =  new( ELeave ) CHnServiceHandler( aMode );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL( aService, aInterface, aCommandName, aConstructor,
       
    88             aServiceCommand );
       
    89     return self;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CHnServiceHandler::CHnServiceHandler( TServiceMode aMode ) :
       
    97         iMode( aMode )
       
    98     {
       
    99 
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 EXPORT_C CHnServiceHandler::~CHnServiceHandler()
       
   107     {
       
   108 
       
   109     iServiceName.Close();
       
   110     iInterfaceName.Close();
       
   111     iCommandName.Close();
       
   112 
       
   113     if ( iServiceInterface )
       
   114         {
       
   115         iServiceInterface->Close();
       
   116         }
       
   117 
       
   118     delete iInput;
       
   119     delete iConstructor;
       
   120     delete iCommand;
       
   121     delete iOutputForAS;
       
   122     
       
   123     if ( iServiceHandler )
       
   124         {
       
   125         iServiceHandler->Reset();
       
   126         delete iServiceHandler;
       
   127         }
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C TInt CHnServiceHandler::ExecuteL( MLiwNotifyCallback* aCallback,
       
   135         TInt aCmdOptions)
       
   136     {
       
   137     TInt err( KErrNotSupported );
       
   138     if( iServiceInterface )
       
   139         {
       
   140         err = KErrNotSupported;
       
   141         iOutputForAS->Reset();
       
   142         iInput->Reset();
       
   143         iInput->AppendL( *iCommand );
       
   144         switch( iMode )
       
   145             {
       
   146             case EServiceModeAsynchronous:
       
   147                 {
       
   148                 __ASSERT_DEBUG( aCallback , User::Panic( KMatrixPanic , 0 ) );
       
   149                 TRAP(err, iServiceInterface->ExecuteCmdL(
       
   150                  iCommandName, *iInput, *iOutputForAS, aCmdOptions, aCallback ) );
       
   151                 }
       
   152                 break;
       
   153             case EServiceModeSynchronous:
       
   154                 {
       
   155                 TRAP(err, iServiceInterface->ExecuteCmdL(
       
   156                  iCommandName, *iInput, *iOutputForAS, aCmdOptions, NULL ) );
       
   157                 }
       
   158                 break;
       
   159             }
       
   160         }
       
   161     return err;
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C TInt CHnServiceHandler::ExecuteL(
       
   169         CLiwGenericParamList& aOutParamList, TRequestStatus& aStatus )
       
   170     {
       
   171     iClientStatus = &aStatus;
       
   172     (*iClientStatus) = KRequestPending;
       
   173     iOutputForAO = &aOutParamList;
       
   174 
       
   175     TInt err( KErrNotSupported );
       
   176     if( iServiceInterface )
       
   177         {
       
   178         err = KErrNone;
       
   179         iInput->Reset();
       
   180         iInput->AppendL( *iCommand );
       
   181 
       
   182         switch (iMode)
       
   183             {
       
   184             case EServiceModeAsynchronous:
       
   185                 {
       
   186                 TRAP(err, iServiceInterface->ExecuteCmdL(
       
   187                      iCommandName, *iInput, *iOutputForAO, 0, this ) );
       
   188                 if ( err != KErrNone )
       
   189                 	{
       
   190                 	User::RequestComplete( iClientStatus, err );
       
   191                 	}
       
   192                 }
       
   193                 break;
       
   194             case EServiceModeSynchronous:
       
   195                  {
       
   196                  TRAP(err, iServiceInterface->ExecuteCmdL(
       
   197                      iCommandName, *iInput, *iOutputForAO ) );
       
   198                  User::RequestComplete( iClientStatus, KErrNone );
       
   199                  }
       
   200                  break;
       
   201             default:
       
   202                 break;
       
   203             }
       
   204         }
       
   205     else
       
   206     	{
       
   207     	// KErrNone ensures that CHnQueryResultCollector::HandleQueryResultsL()
       
   208     	// is called, empty results are added to list, and 
       
   209     	// CHnMdItem::ResultsCollectedL doesn't get confused
       
   210     	User::RequestComplete( iClientStatus, KErrNone );
       
   211     	}
       
   212 
       
   213     return err;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 // -----------------------------------------------------------------------------
       
   219 EXPORT_C TInt CHnServiceHandler::HandleNotifyL(
       
   220         TInt /*aCmdId*/,
       
   221         TInt /*aEventId*/,
       
   222         CLiwGenericParamList& aEventParamList,
       
   223         const CLiwGenericParamList& /*aInParamList*/ )
       
   224     {
       
   225     // reset
       
   226     if( iOutputForAO )
       
   227         {
       
   228         iOutputForAO->Reset();
       
   229         iOutputForAO->AppendL( aEventParamList );
       
   230         
       
   231         TLiwGenericParam param;
       
   232         TInt error(KErrNone);
       
   233         param.PushL();
       
   234         for (TInt i = 0; i < aEventParamList.Count(); i++)
       
   235             {
       
   236             if ( param.Name().Compare( KErrorCode8 ) == 0
       
   237             		&& param.Value().AsTInt32() == KSErrNoMemory )
       
   238             	{
       
   239             	error = KErrNoMemory;
       
   240             	break;
       
   241             	}
       
   242             }
       
   243         CleanupStack::PopAndDestroy(&param);
       
   244         User::RequestComplete( iClientStatus, error);
       
   245         }
       
   246     return KErrNone;
       
   247     }
       
   248 
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 // -----------------------------------------------------------------------------
       
   253 TInt CHnServiceHandler::SetServiceInterfaceL(
       
   254         CLiwGenericParamList* aConstructor )
       
   255     {
       
   256     CLiwGenericParamList& inParam = iServiceHandler->InParamListL();
       
   257     CLiwGenericParamList& outParam = iServiceHandler->OutParamListL();
       
   258 
       
   259     CLiwCriteriaItem* critItem = CLiwCriteriaItem::NewLC( KLiwCmdAsStr,
       
   260         iInterfaceName, iServiceName );
       
   261 
       
   262     critItem->SetServiceClass( TUid::Uid( KLiwClassBase ) );
       
   263     RCriteriaArray critArr;
       
   264     CleanupClosePushL( critArr );
       
   265     critArr.AppendL( critItem );
       
   266     iServiceHandler->AttachL( critArr );
       
   267     inParam.AppendL( *aConstructor );
       
   268     iServiceHandler->ExecuteServiceCmdL( *critItem, inParam, outParam );
       
   269     CleanupStack::PopAndDestroy( &critArr );
       
   270     CleanupStack::PopAndDestroy( critItem );
       
   271 
       
   272     TInt pos( KErrNone );
       
   273     outParam.FindFirst( pos, iInterfaceName );
       
   274     if ( pos != KErrNotFound )
       
   275         {
       
   276         iServiceInterface = outParam[pos].Value().AsInterface();
       
   277         }
       
   278 
       
   279     return pos;
       
   280     }
       
   281 
       
   282 // End of file