PECengine/PresenceManager2/SrcAttribute/CPEngAttributePublishOp.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     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: this class is an operation handler for publishing user own attributes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPEngAttributePublishOp.h"
       
    21 #include "CPEngNWSessionSlotStorageProxy.h"
       
    22 #include "MPEngPresenceAttrManager.h"
       
    23 #include "PEngAttrLibFactory.h"
       
    24 #include "MPEngAdvTransactionStatus2.h"
       
    25 
       
    26 
       
    27 #include <CPEngAttributeTransaction2.h>
       
    28 #include <MPEngAttributeTransactionObserver2.h>
       
    29 #include <MPEngPresenceAttrModel2.h>
       
    30 
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 // Two-phased constructor.
       
    35 CPEngAttributePublishOp* CPEngAttributePublishOp::NewL( TInt aPriority,
       
    36                                                         CPEngAttributeTransaction2& aInterface,
       
    37                                                         CPEngNWSessionSlotStorageProxy& aUsedSlot,
       
    38                                                         RPointerArray<MPEngPresenceAttrModel2>& aModels,
       
    39                                                         MPEngAttributeTransactionObserver2& aObserver,
       
    40                                                         RPEngManagerClient& aServer )
       
    41     {
       
    42     CPEngAttributePublishOp* self = new ( ELeave ) CPEngAttributePublishOp( aPriority,
       
    43                                                                             aInterface,
       
    44                                                                             aObserver,
       
    45                                                                             aServer );
       
    46 
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aUsedSlot, aModels );
       
    49     CleanupStack::Pop();
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // Destructor
       
    56 CPEngAttributePublishOp::~CPEngAttributePublishOp()
       
    57     {
       
    58     CActive::Cancel();
       
    59 
       
    60     if ( iModelsOwned )
       
    61         {
       
    62         iModels.ResetAndDestroy();
       
    63         }
       
    64     else
       
    65         {
       
    66         iModels.Reset();
       
    67         }
       
    68 
       
    69     if ( iAttrManager )
       
    70         {
       
    71         iAttrManager->Close();
       
    72         }
       
    73     }
       
    74 
       
    75 
       
    76 // C++ default constructor can NOT contain any code, that
       
    77 // might leave.
       
    78 //
       
    79 CPEngAttributePublishOp::CPEngAttributePublishOp( TInt aPriority,
       
    80                                                   CPEngAttributeTransaction2& aInterface,
       
    81                                                   MPEngAttributeTransactionObserver2& aObserver,
       
    82                                                   RPEngManagerClient& aServer )
       
    83         : CPEngAsyncOperation( aPriority, aServer ),
       
    84         iInterface( aInterface ),
       
    85         iObserver( aObserver )
       
    86     {
       
    87     }
       
    88 
       
    89 
       
    90 
       
    91 // EPOC default constructor can leave.
       
    92 void CPEngAttributePublishOp::ConstructL( CPEngNWSessionSlotStorageProxy& aUsedSlot,
       
    93                                           RPointerArray<MPEngPresenceAttrModel2>& aModels )
       
    94     {
       
    95     BaseConstructL( aUsedSlot );
       
    96     iAttrManager = PEngAttrLibFactory::AttributeManagerInstanceL( aUsedSlot.BaseId() );
       
    97 
       
    98 
       
    99 
       
   100     //Verify parameter models
       
   101     const TInt modelsCount( aModels.Count() );
       
   102     if ( modelsCount == 0 )
       
   103         {
       
   104         User::Leave( KErrArgument );
       
   105         }
       
   106 
       
   107 
       
   108     //Copy models pointers to internal array
       
   109     //Ownership of models remain still on the parameter array
       
   110     //Check at same that each pointer is valid
       
   111     TInt ii;
       
   112     for ( ii = 0; ii < modelsCount; ii++ )
       
   113         {
       
   114         MPEngPresenceAttrModel2* m = aModels[ii];
       
   115         if ( !m )
       
   116             {
       
   117             User::Leave( KErrArgument );
       
   118             }
       
   119 
       
   120         User::LeaveIfError( iModels.Append( aModels[ii] ) );
       
   121         }
       
   122 
       
   123 
       
   124     //Check against duplicates
       
   125     for ( ii = 0; ii < modelsCount - 1; ii++ )
       
   126         {
       
   127         for ( TInt jj( ii + 1 ); jj < modelsCount; jj++ )
       
   128             {
       
   129             if ( aModels[ii]->Type() == aModels[jj]->Type() )
       
   130                 {
       
   131                 User::Leave( KErrAlreadyExists );
       
   132                 }
       
   133             }
       
   134         }
       
   135 
       
   136 
       
   137     //Check every model is properly locked for used NWSessionSlot &
       
   138     //can be used in NW operation
       
   139     for ( ii = 0; ii < modelsCount; ii++ )
       
   140         {
       
   141         MPEngPresenceAttrModel2& model = *aModels[ii];
       
   142         iAttrManager->ModelEditLockedFromThisSlotL( model );
       
   143         User::LeaveIfError( iAttrManager->ValidNetworkAttribute( model.Type() ) );
       
   144         }
       
   145 
       
   146 
       
   147     //Pack the publish request
       
   148     HBufC16* data = iAttrManager->PackModelArrayL( iModels );
       
   149     InitTransaction( data, EPEngTransOpOwnAttributePublish );
       
   150     }
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CPEngAttributePublishOp::Publish()
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CPEngAttributePublishOp::Publish()
       
   160     {
       
   161     iModelsOwned = ETrue;
       
   162     IssueTransaction();
       
   163     }
       
   164 
       
   165 
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CPEngAttributePublishOp::DoHandleOpSuccessL()
       
   170 // -----------------------------------------------------------------------------
       
   171 void CPEngAttributePublishOp::DoHandleOpSuccessL(
       
   172     MPEngAdvTransactionStatus2& /*aStatus*/,
       
   173     TInt /*aTransactionOperation*/ )
       
   174 
       
   175     {
       
   176     //Release the holded attributes models
       
   177     //Model delete frees the edit lock
       
   178     iModels.ResetAndDestroy();
       
   179     }
       
   180 
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CPEngAttributePublishOp::DoHandleOpFailure()
       
   184 // -----------------------------------------------------------------------------
       
   185 void CPEngAttributePublishOp::DoHandleOpFailure(
       
   186     MPEngAdvTransactionStatus2& /*aStatus*/,
       
   187     TInt /*aTransactionOperation*/ )
       
   188     {
       
   189     //Release the holded attributes models
       
   190     //Model delete frees the edit lock
       
   191     iModels.ResetAndDestroy();
       
   192     }
       
   193 
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CPEngAttributePublishOp::DoNotifyObserver()
       
   197 // -----------------------------------------------------------------------------
       
   198 TPEngAsyncOpResult CPEngAttributePublishOp::DoNotifyObserver(
       
   199     MPEngAdvTransactionStatus2& aStatus,
       
   200     TInt aTransactionOperation )
       
   201     {
       
   202     TRAPD( err, iObserver.HandleAttributeTransactionCompleteL(
       
   203                aStatus,
       
   204                iInterface,
       
   205                aTransactionOperation ) );
       
   206     if ( err != KErrNone )
       
   207         {
       
   208         iObserver.HandleAttributeTransactionError( err,
       
   209                                                    iInterface,
       
   210                                                    aTransactionOperation );
       
   211         }
       
   212 
       
   213     return EPEngAsyncOpCompleted;
       
   214     }
       
   215 
       
   216 
       
   217 //End of file
       
   218 
       
   219