serviceproviders/sapi_sysinfo/src/sysinfoobserver.cpp
changeset 5 989d2f495d90
child 46 5146369cfdc9
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2002 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:  CSysInfoObserver class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <liwgenericparam.h>
       
    21 #include <liwcommon.h>
       
    22 
       
    23 #include "sysinfointerface.h"
       
    24 #include "sysinfoobserver.h"
       
    25 #include "../../inc/serviceerrno.h"
       
    26 #include "sysinfoaiwparams.hrh"
       
    27 
       
    28 using namespace LIW;
       
    29 using namespace sysinfoaiwparams;
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CSysInfoObserver::NewL( CSysInfoInterface* aSysInfoIf )
       
    35 // Two-phased constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSysInfoObserver* CSysInfoObserver::NewL( CSysInfoInterface* aSysInfoIf )
       
    39     {
       
    40     CSysInfoObserver* self = new (ELeave) CSysInfoObserver(aSysInfoIf);
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSysInfoObserver::CSysInfoObserver( CSysInfoInterface* aSysInfoIf )
       
    46 // C++ default constructor can NOT contain any code, that might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSysInfoObserver::CSysInfoObserver( CSysInfoInterface* aSysInfoIf )
       
    50                                                 :iSysInfoIf(aSysInfoIf)
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSysInfoObserver::HandleResponseL( const TDesC& aEntity,const TDesC& aKey, 
       
    56 // 		CSysData* aOutput, TInt32 aTransID,TInt aError) 
       
    57 // Pack the outputs and call the callback function.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CSysInfoObserver::HandleResponseL(const TDesC& aEntity,const TDesC& aKey, 
       
    61                                             CSysData* aOutput, TInt32 aTransID, 
       
    62                                             TSysRequest::TRequestType aType,
       
    63                                             TInt aError )
       
    64     {
       
    65     TInt SapiErr = SErrNone;
       
    66     TBool ownership(EFalse);
       
    67     MLiwNotifyCallback* callback=NULL;
       
    68     //retrieve callback
       
    69     if( TSysRequest::EASyncONESHOT == aType )
       
    70         callback = iSysInfoIf->GetCallbackAndRemove(aTransID);
       
    71     else
       
    72         callback = iSysInfoIf->GetCallback(aTransID);
       
    73 
       
    74     if( !callback )
       
    75         {
       
    76         delete aOutput;
       
    77         return;
       
    78         }
       
    79 
       
    80     //Create param list
       
    81     CLiwGenericParamList* eventParamList = CLiwGenericParamList::NewL();
       
    82     CleanupStack::PushL(eventParamList);
       
    83     CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL();
       
    84     CleanupStack::PushL(inParamList);
       
    85 
       
    86     if ( aError != KErrNone )
       
    87         {
       
    88         SapiErr = iSysInfoIf->SapiError(aError);
       
    89         eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr)));
       
    90         TRAP_IGNORE(callback->HandleNotifyL(aTransID, KLiwEventError,
       
    91                                         *eventParamList,*inParamList));
       
    92         }
       
    93     else
       
    94         {
       
    95         //pack to aOutParamList
       
    96         eventParamList->AppendL(TLiwGenericParam(KErrorCode,TLiwVariant((TInt32)SapiErr)));
       
    97         CLiwMap* outparam=NULL;
       
    98 
       
    99         if( (aOutput->DataType() == CSysData::EAccessoryList) ||
       
   100                 (aOutput->DataType() == CSysData::EConnectionList) )
       
   101             ownership = ETrue;
       
   102 
       
   103         CSysInfoInterface::ConvertSysData2AiwParamL(aOutput,outparam);
       
   104         //Add Entity and Key to the output map.
       
   105         if(outparam)
       
   106             {
       
   107             outparam->InsertL(KEntity,TLiwVariant(aEntity));
       
   108             outparam->InsertL(KKey,TLiwVariant(aKey));
       
   109             }
       
   110 
       
   111         eventParamList->AppendL(TLiwGenericParam(KReturnValue,TLiwVariant(outparam)));
       
   112         outparam->DecRef();
       
   113         if( TSysRequest::EASyncONESHOT == aType )
       
   114             {
       
   115             TRAP_IGNORE(callback->HandleNotifyL(aTransID, KLiwEventCompleted,
       
   116                                             *eventParamList,*inParamList));
       
   117             }
       
   118         else
       
   119             {
       
   120             TRAP_IGNORE(callback->HandleNotifyL(aTransID, KLiwEventInProgress,
       
   121                                             *eventParamList,*inParamList));
       
   122             }
       
   123 
       
   124         if(!ownership)
       
   125             {
       
   126             delete 	aOutput;
       
   127             aOutput = NULL;
       
   128             }
       
   129         }
       
   130     CleanupStack::PopAndDestroy(inParamList);
       
   131     CleanupStack::PopAndDestroy(eventParamList);
       
   132     }
       
   133 
       
   134 //End of file
       
   135 
       
   136