PECengine/PresenceManager2/SrcAttribute/CPEngAttributeFetchOp.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: this class is an operation handler for fetching attributes from network.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngAttributeFetchOp.h"
       
    20 #include "CPEngNWSessionSlotStorageProxy.h"
       
    21 #include "MPEngPresenceAttrManager.h"
       
    22 #include "MPEngAdvTransactionStatus2.h"
       
    23 #include "PEngAttrLibFactory.h"
       
    24 
       
    25 
       
    26 
       
    27 #include <CPEngAttributeTransaction2.h>
       
    28 #include <MPEngAttributeTransactionObserver2.h>
       
    29 #include <MPEngPresenceAttrModel2.h>
       
    30 
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CPEngAttributeFetchOp::NewL()
       
    37 // -----------------------------------------------------------------------------
       
    38 CPEngAttributeFetchOp* CPEngAttributeFetchOp::NewL( TInt aPriority,
       
    39                                                     CPEngAttributeTransaction2& aInterface,
       
    40                                                     CPEngNWSessionSlotStorageProxy& aUsedSlot,
       
    41                                                     TBool aResultAsLocalObjects,
       
    42                                                     const MDesCArray& aPresenceIDs,
       
    43                                                     const TArray<TUint32>& aTypes,
       
    44                                                     MPEngAttributeTransactionObserver2& aObserver,
       
    45                                                     RPEngManagerClient& aServer )
       
    46     {
       
    47     CPEngAttributeFetchOp* self = new ( ELeave ) CPEngAttributeFetchOp( aPriority,
       
    48                                                                         aInterface,
       
    49                                                                         aObserver,
       
    50                                                                         aServer );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aUsedSlot,
       
    53                       aPresenceIDs,
       
    54                       aTypes,
       
    55                       aResultAsLocalObjects );
       
    56     CleanupStack::Pop();
       
    57 
       
    58     return self;
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CPEngAttributeFetchOp::~CPEngAttributeFetchOp()
       
    63 // -----------------------------------------------------------------------------
       
    64 CPEngAttributeFetchOp::~CPEngAttributeFetchOp()
       
    65     {
       
    66     CActive::Cancel();
       
    67 
       
    68     iResultModels.ResetAndDestroy();
       
    69 
       
    70     if ( iAttrManager )
       
    71         {
       
    72         iAttrManager->Close();
       
    73         }
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CPEngAttributeFetchOp::CPEngAttributeFetchOp()
       
    79 // -----------------------------------------------------------------------------
       
    80 CPEngAttributeFetchOp::CPEngAttributeFetchOp( TInt aPriority,
       
    81                                               CPEngAttributeTransaction2& aInterface,
       
    82                                               MPEngAttributeTransactionObserver2& aObserver,
       
    83                                               RPEngManagerClient& aServer )
       
    84         : CPEngAsyncOperation( aPriority, aServer ),
       
    85         iInterface( aInterface ),
       
    86         iObserver( aObserver )
       
    87     {
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CPEngAttributeFetchOp::ConstructL()
       
    93 // -----------------------------------------------------------------------------
       
    94 void CPEngAttributeFetchOp::ConstructL( CPEngNWSessionSlotStorageProxy& aUsedSlot,
       
    95                                         const MDesCArray& aPresenceIDs,
       
    96                                         const TArray<TUint32>& aTypes,
       
    97                                         TBool aResultAsLocalObjects )
       
    98     {
       
    99     CPEngAsyncOperation::BaseConstructL( aUsedSlot );
       
   100     iAttrManager = PEngAttrLibFactory::AttributeManagerInstanceL( aUsedSlot.BaseId() );
       
   101 
       
   102 
       
   103     TInt ii;
       
   104     TInt jj;
       
   105 
       
   106 
       
   107     //Verify attribute types
       
   108     const TInt typesCount( aTypes.Count() );
       
   109     if ( typesCount == 0 )
       
   110         {
       
   111         User::Leave( KErrArgument );
       
   112         }
       
   113 
       
   114 
       
   115     for ( ii = 0; ii < typesCount - 1; ii++ )
       
   116         {
       
   117         for ( jj = ii + 1 ; jj < typesCount; jj++ )
       
   118             {
       
   119             if ( aTypes[ii] == aTypes[jj] )
       
   120                 {
       
   121                 User::Leave( KErrAlreadyExists );
       
   122                 }
       
   123             }
       
   124         }
       
   125 
       
   126     //Check every type can be used in NW operation
       
   127     for ( ii = 0; ii < typesCount; ii++ )
       
   128         {
       
   129         User::LeaveIfError( iAttrManager->ValidNetworkAttribute( aTypes[ii] ) );
       
   130         }
       
   131 
       
   132 
       
   133     //Verify presence ID's
       
   134     const TInt presenceIDCount( aPresenceIDs.MdcaCount() );
       
   135     if ( presenceIDCount == 0 )
       
   136         {
       
   137         User::Leave( KErrArgument );
       
   138         }
       
   139 
       
   140     for ( ii =  0; ii < presenceIDCount - 1; ii++ )
       
   141         {
       
   142         for ( jj = ii + 1; jj < presenceIDCount; jj++ )
       
   143             {
       
   144             if ( aPresenceIDs.MdcaPoint( ii ) ==
       
   145                  aPresenceIDs.MdcaPoint( jj ) )
       
   146                 {
       
   147                 User::Leave( KErrAlreadyExists );
       
   148                 }
       
   149             }
       
   150         }
       
   151 
       
   152     //Generate the request
       
   153     HBufC16* data = iAttrManager->PackFetchRequestL( aPresenceIDs,
       
   154                                                      aTypes );
       
   155 
       
   156     if ( aResultAsLocalObjects )
       
   157         {
       
   158         InitTransaction( data, EPEngTransOpAttributeFetchToObjects );
       
   159         }
       
   160     else
       
   161         {
       
   162         InitTransaction( data, EPEngTransOpAttributeFetchToCache );
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CPEngAttributeFetchOp::Fetch()
       
   169 // -----------------------------------------------------------------------------
       
   170 void CPEngAttributeFetchOp::Fetch()
       
   171     {
       
   172     IssueTransaction();
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CPEngAttributeFetchOp::GetFetchedAttributes()
       
   178 // -----------------------------------------------------------------------------
       
   179 TInt CPEngAttributeFetchOp::GetFetchedAttributes(
       
   180     RPointerArray< MPEngPresenceAttrModel2>& aModels )
       
   181     {
       
   182     const TInt count = iResultModels.Count();
       
   183     for ( TInt ii = 0; ii < count; ii++ )
       
   184         {
       
   185         MPEngPresenceAttrModel2* m = iResultModels[ 0 ];
       
   186         TInt err = aModels.Append( m );
       
   187         if ( err != KErrNone )
       
   188             {
       
   189             return err;
       
   190             }
       
   191 
       
   192         iResultModels.Remove( 0 );
       
   193         }
       
   194 
       
   195     return KErrNone;
       
   196     }
       
   197 
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CPEngAttributeFetchOp::DoHandleOpSuccessL()
       
   201 // -----------------------------------------------------------------------------
       
   202 void CPEngAttributeFetchOp::DoHandleOpSuccessL( MPEngAdvTransactionStatus2& aStatus,
       
   203                                                 TInt aTransactionOperation )
       
   204 
       
   205     {
       
   206     if ( aTransactionOperation == EPEngTransOpAttributeFetchToObjects )
       
   207         {
       
   208         TPtrC16 dataResult( NULL, 0 );
       
   209         aStatus.GetFirstDataResultByOperation( EPEngTransOpAttributeFetchToObjects,
       
   210                                                dataResult );
       
   211         if ( dataResult.Length() > 0 )
       
   212             {
       
   213             iAttrManager->UnpackModelArrayL( dataResult,
       
   214                                              EPEngInstanceOptionsNone,
       
   215                                              iResultModels );
       
   216             }
       
   217         }
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CPEngAttributeFetchOp::DoHandleOpFailure()
       
   223 // -----------------------------------------------------------------------------
       
   224 void CPEngAttributeFetchOp::DoHandleOpFailure(
       
   225     MPEngAdvTransactionStatus2& /*aStatus*/,
       
   226     TInt /*aTransactionOperation*/ )
       
   227     {
       
   228     iResultModels.ResetAndDestroy();
       
   229     }
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CPEngAttributeFetchOp::DoNotifyObserver()
       
   234 // -----------------------------------------------------------------------------
       
   235 TPEngAsyncOpResult CPEngAttributeFetchOp::DoNotifyObserver(
       
   236     MPEngAdvTransactionStatus2& aStatus,
       
   237     TInt aTransactionOperation )
       
   238     {
       
   239     TRAPD( err, iObserver.HandleAttributeTransactionCompleteL(
       
   240                aStatus,
       
   241                iInterface,
       
   242                aTransactionOperation ) );
       
   243     if ( err != KErrNone )
       
   244         {
       
   245         iObserver.HandleAttributeTransactionError( err,
       
   246                                                    iInterface,
       
   247                                                    aTransactionOperation );
       
   248         }
       
   249 
       
   250     return EPEngAsyncOpCompleted;
       
   251     }
       
   252 
       
   253 
       
   254 
       
   255 // End of file