PECengine/PresenceManager2/SrcAttribute/CPEngAttributeTransaction2Imp.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:  Presence attribute transactions.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngAttributeTransaction2Imp.h"
       
    20 #include "CPEngAsyncOperation.h"
       
    21 #include "CPEngNWSessionSlotID2.h"
       
    22 #include "CPEngNWSessionSlotStorageProxy.h"
       
    23 
       
    24 
       
    25 #include "CPEngAttributePublishOp.h"
       
    26 #include "CPEngAttributeFetchOp.h"
       
    27 
       
    28 
       
    29 //LOCAL constants
       
    30 #ifdef _DEBUG
       
    31 namespace
       
    32     {
       
    33     //Panic
       
    34     _LIT( KPEngAttrTransPanic, "PEngAttrTrans" );
       
    35 
       
    36     //Panic reasons
       
    37     enum TPEngAttrTransPanicReasons
       
    38         {
       
    39         EAttrTransUnkownTransOp
       
    40         };
       
    41 
       
    42     void AttrTransPanic( TPEngAttrTransPanicReasons aPanicReason )
       
    43         {
       
    44         User::Panic( KPEngAttrTransPanic, aPanicReason );
       
    45         }
       
    46     }
       
    47 #endif
       
    48 
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CPEngAttributeTransaction2Imp::NewL()
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CPEngAttributeTransaction2Imp* CPEngAttributeTransaction2Imp::NewL(
       
    59     CPEngAttributeTransaction2& aInterface,
       
    60     TInt aPriority,
       
    61     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    62     {
       
    63     CPEngAttributeTransaction2Imp* self =
       
    64         new ( ELeave ) CPEngAttributeTransaction2Imp( aInterface, aPriority );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aNWSessionSlotID );
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 
       
    73 // Destructor
       
    74 CPEngAttributeTransaction2Imp::~CPEngAttributeTransaction2Imp()
       
    75     {
       
    76     //Cancel also deletes the operation objects
       
    77     CancelPublishOwnAttributes();
       
    78     CancelFetchAttributes();
       
    79     iTransactionServer.Close();
       
    80     delete iUsedSlot;
       
    81     }
       
    82 
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPEngAttributeTransaction2Imp::CPEngAttributeTransaction2Imp
       
    87 // C++ default constructor can NOT contain any code, that
       
    88 // might leave.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CPEngAttributeTransaction2Imp::CPEngAttributeTransaction2Imp(
       
    92     CPEngAttributeTransaction2& aInterface,
       
    93     TInt aPriority )
       
    94         : iInterface( aInterface ),
       
    95         iCActivePriority( aPriority )
       
    96     {
       
    97     }
       
    98 
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CPEngAttributeTransaction2Imp::ConstructL()
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CPEngAttributeTransaction2Imp::ConstructL(
       
   106     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
   107     {
       
   108     iUsedSlot = CPEngNWSessionSlotStorageProxy::NewL( aNWSessionSlotID );
       
   109     User::LeaveIfError( iTransactionServer.Connect() );
       
   110     }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CPEngAttributeTransaction2Imp::IsPublishOwnAttributesActive()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TBool CPEngAttributeTransaction2Imp::IsPublishOwnAttributesActive() const
       
   118     {
       
   119     return ( iAttributePublishOp != NULL );     // CSI: 64 #
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CPEngAttributeTransaction2Imp::PublishAndUnLockOwnAttribute()
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 TInt CPEngAttributeTransaction2Imp::PublishAndUnLockOwnAttribute(
       
   128     MPEngPresenceAttrModel2*& aModel,
       
   129     MPEngAttributeTransactionObserver2& aObserver )
       
   130     {
       
   131     RPointerArray< MPEngPresenceAttrModel2 > models;
       
   132     TInt err = models.Append( aModel );
       
   133     if ( err == KErrNone )
       
   134         {
       
   135         err = PublishAndUnLockOwnAttributes( models, aObserver );
       
   136         }
       
   137 
       
   138     if ( err == KErrNone )
       
   139         {
       
   140         aModel = NULL;
       
   141         }
       
   142 
       
   143     models.Reset();
       
   144     return err;
       
   145     }
       
   146 
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPEngAttributeTransaction2Imp::PublishAndUnLockOwnAttributes()
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TInt CPEngAttributeTransaction2Imp::PublishAndUnLockOwnAttributes(
       
   153     RPointerArray<MPEngPresenceAttrModel2>& aModels,
       
   154     MPEngAttributeTransactionObserver2& aObserver )
       
   155     {
       
   156     if ( iAttributePublishOp )
       
   157         {
       
   158         return KErrInUse;
       
   159         }
       
   160 
       
   161     CPEngAttributePublishOp* op = NULL;
       
   162     TRAPD( err,
       
   163            op = CPEngAttributePublishOp::NewL( iCActivePriority,
       
   164                                                iInterface,
       
   165                                                *iUsedSlot,
       
   166                                                aModels,
       
   167                                                aObserver,
       
   168                                                iTransactionServer ); );
       
   169 
       
   170     if ( err == KErrNone )
       
   171         {
       
   172         //Success
       
   173         //==> Ownership of passed attribute objects is now  on the publish operation
       
   174         op->Publish();
       
   175         op->SetOwner( *this );
       
   176         iAttributePublishOp = op;
       
   177 
       
   178         aModels.Reset();
       
   179         }
       
   180 
       
   181     return err;
       
   182     }
       
   183 
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CPEngAttributeTransaction2Imp::CancelPublishOwnAttributes()
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CPEngAttributeTransaction2Imp::CancelPublishOwnAttributes()
       
   190     {
       
   191     if ( iAttributePublishOp )
       
   192         {
       
   193         iAttributePublishOp->CancelOpD();
       
   194         iAttributePublishOp = NULL;
       
   195         }
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CPEngAttributeTransaction2Imp::IsFetchAttributesActive()
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 TBool CPEngAttributeTransaction2Imp::IsFetchAttributesActive() const
       
   205     {
       
   206     return( iAttributeFetchOp != NULL );        // CSI: 64 #
       
   207     }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CPEngAttributeTransaction2Imp::FetchAttributes()
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TInt CPEngAttributeTransaction2Imp::FetchAttributes(
       
   215     const MDesCArray& aPresenceIDs,
       
   216     const TArray<TUint32>& aTypes,
       
   217     MPEngAttributeTransactionObserver2& aObserver,
       
   218     TInt aOptions,
       
   219     TBool aResultAsLoclObjects )
       
   220     {
       
   221     if ( iAttributeFetchOp )
       
   222         {
       
   223         return KErrInUse;
       
   224         }
       
   225 
       
   226     if ( aOptions != 0 )
       
   227         {
       
   228         return KErrArgument;
       
   229         }
       
   230 
       
   231 
       
   232     CPEngAttributeFetchOp* op = NULL;
       
   233     TRAPD( err,
       
   234            op = CPEngAttributeFetchOp::NewL( iCActivePriority,
       
   235                                              iInterface,
       
   236                                              *iUsedSlot,
       
   237                                              aResultAsLoclObjects,
       
   238                                              aPresenceIDs,
       
   239                                              aTypes,
       
   240                                              aObserver,
       
   241                                              iTransactionServer ); );
       
   242 
       
   243     if ( err == KErrNone )
       
   244         {
       
   245         op->Fetch();
       
   246         op->SetOwner( *this );
       
   247         iAttributeFetchOp = op;
       
   248         }
       
   249 
       
   250     return err;
       
   251     }
       
   252 
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CPEngAttributeTransaction2Imp::CancelFetchAttributes()
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CPEngAttributeTransaction2Imp::CancelFetchAttributes()
       
   259     {
       
   260     if ( iAttributeFetchOp )
       
   261         {
       
   262         iAttributeFetchOp->CancelOpD();
       
   263         iAttributeFetchOp = NULL;
       
   264         }
       
   265     }
       
   266 
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CPEngAttributeTransaction2Imp::GetFetchedAttributes()
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 TInt CPEngAttributeTransaction2Imp::GetFetchedAttributes(
       
   273     RPointerArray< MPEngPresenceAttrModel2>& aModels )
       
   274     {
       
   275     if ( iAttributeFetchOp )
       
   276         {
       
   277         return iAttributeFetchOp->GetFetchedAttributes( aModels );
       
   278         }
       
   279 
       
   280     return KErrNotReady;
       
   281     }
       
   282 
       
   283 
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CPEngAttributeTransaction2Imp::HandleAsyncOperationDestruction()
       
   287 // from MPEngAsyncOperationOwner
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CPEngAttributeTransaction2Imp::HandleAsyncOperationDestruction(
       
   291     CPEngAsyncOperation* aOperation )
       
   292     {
       
   293     if ( aOperation == iAttributeFetchOp )
       
   294         {
       
   295         iAttributeFetchOp = NULL;
       
   296         return;
       
   297         }
       
   298 
       
   299     if ( aOperation == iAttributePublishOp )
       
   300         {
       
   301         iAttributePublishOp = NULL;
       
   302         return;
       
   303         }
       
   304 
       
   305     __ASSERT_DEBUG( EFalse, AttrTransPanic( EAttrTransUnkownTransOp ) );
       
   306     }
       
   307 
       
   308 
       
   309 // End of File
       
   310 
       
   311