PECengine/AttributeLibrary2/SrcAttributeBase/CPEngAttrModelAsyncDataSetHook.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Attribute asynhronous data set hook.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CPEngAttrModelAsyncDataSetHook.h"
       
    21 #include    "CPEngPresenceAttrModel.h"
       
    22 #include    "MPEngPresenceAttrModelTypeImp.h"
       
    23 #include    "PresenceDebugPrint.h"
       
    24 #include    <E32Base.h>
       
    25 
       
    26 
       
    27 //LOCAL constants
       
    28 namespace
       
    29     {
       
    30     _LIT( KPEngAsyncDataSetHookPanic, "AsyncDataSetHook" );
       
    31     enum TPEngAsyncDataSetHookPanicReasons
       
    32         {
       
    33         EHookNotReady
       
    34         };
       
    35 
       
    36     void PanicAsyncDataSetHook( TPEngAsyncDataSetHookPanicReasons aPanicReason )
       
    37         {
       
    38         User::Panic( KPEngAsyncDataSetHookPanic, aPanicReason );
       
    39         }
       
    40 
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPEngAttrModelAsyncDataSetHook::CPEngAttrModelAsyncDataSetHook
       
    49 // C++ default constructor can NOT contain any code, that
       
    50 // might leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CPEngAttrModelAsyncDataSetHook::CPEngAttrModelAsyncDataSetHook()
       
    54         : CActive( CActive::EPriorityStandard )
       
    55     {
       
    56     CActiveScheduler::Add( this );
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // Destructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPEngAttrModelAsyncDataSetHook::~CPEngAttrModelAsyncDataSetHook()
       
    65     {
       
    66     CActive::Cancel();
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPEngAttrModelAsyncDataSetHook::InitializeLC()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CPEngAttrModelAsyncDataSetHook::InitializeLC( TRequestStatus& aRequestStatus,
       
    75                                                    CPEngPresenceAttrModel& aAttributeModel,
       
    76                                                    MPEngPresenceAttrModelTypeImp& aTypeImp )
       
    77     {
       
    78     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrInUse ) );
       
    79     CleanupStack::PushL( TCleanupItem( ResetTheHook, this ) );
       
    80 
       
    81     iStatusToComplete = &aRequestStatus;
       
    82     iHookOwner = &aAttributeModel;
       
    83     iHookedImp = &aTypeImp;
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CPEngAttrModelAsyncDataSetHook::Status()
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TRequestStatus& CPEngAttrModelAsyncDataSetHook::Status()
       
    92     {
       
    93     return iStatus;
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CPEngAttrModelAsyncDataSetHook::Activate()
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CPEngAttrModelAsyncDataSetHook::Activate()
       
   102     {
       
   103     __ASSERT_ALWAYS( ( iStatusToComplete && iHookOwner && iHookedImp ),
       
   104                      PanicAsyncDataSetHook( EHookNotReady ) );
       
   105 
       
   106     if ( iStatus == KRequestPending )
       
   107         {
       
   108         PENG_DP_TXT( "CPEngAttrModelAsyncDataSetHook: Puting hook pending." );
       
   109         *iStatusToComplete = KRequestPending;
       
   110         SetActive();
       
   111         }
       
   112 
       
   113     else
       
   114         {
       
   115         PENG_DP_TXT( "CPEngAttrModelAsyncDataSetHook: Hook ended directly." );
       
   116         *iStatusToComplete = iStatus;
       
   117         Reset();
       
   118         }
       
   119     }
       
   120 
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CPEngAttrModelAsyncDataSetHook::RunL()
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CPEngAttrModelAsyncDataSetHook::RunL()
       
   128     {
       
   129     if ( iStatus.Int() == KErrNone )
       
   130         {
       
   131         //Data set done. Update the attribute state.
       
   132         iHookOwner->SetQualifier( ETrue );
       
   133         }
       
   134 
       
   135     //complete the hooked request with return status from real operation
       
   136     User::RequestComplete( iStatusToComplete, iStatus.Int() );
       
   137 
       
   138     Reset();
       
   139     }
       
   140 
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CPEngAttrModelAsyncDataSetHook::DoCancel()
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CPEngAttrModelAsyncDataSetHook::DoCancel()
       
   147     {
       
   148     iHookedImp->CancelSetDataAsync();
       
   149 
       
   150     //then complete the client request
       
   151     User::RequestComplete( iStatusToComplete, KErrCancel );
       
   152 
       
   153     Reset();
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPEngAttrModelAsyncDataSetHook::Reset()
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CPEngAttrModelAsyncDataSetHook::Reset()
       
   162     {
       
   163     //reset the state
       
   164     iHookOwner = NULL;
       
   165     iHookedImp = NULL;
       
   166 
       
   167     iStatusToComplete = NULL;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPEngAttrModelAsyncDataSetHook::ResetTheHook()
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CPEngAttrModelAsyncDataSetHook::ResetTheHook( TAny* aHook )
       
   175     {
       
   176     CPEngAttrModelAsyncDataSetHook* self = static_cast< CPEngAttrModelAsyncDataSetHook* >( aHook );
       
   177     self->Reset();
       
   178     }
       
   179 
       
   180 
       
   181 //  End of File
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 
       
   194 
       
   195 
       
   196 
       
   197 
       
   198 
       
   199 
       
   200 
       
   201