PECengine/ListLibrary2/AuthSrc/CPEngAuthorizationRequest.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Container of the one reactive authorization request
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    "CPEngAuthorizationRequest.h"
       
    20 #include 	"MPEngAuthorizationRequest.h"
       
    21 #include 	"MPEngAuthorizationManagerSet.h"
       
    22 
       
    23 #include    <e32std.h>
       
    24 #include    <s32strm.h>
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CPEngAuthorizationRequest::CPEngAuthorizationRequest()
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CPEngAuthorizationRequest::CPEngAuthorizationRequest( TInt& aSize )
       
    34         : CPEngAuthorizationItem( aSize ),
       
    35         iState( EPEngAuthPending ),
       
    36         iResponseType( MPEngAuthorizationRequest::EPEngAuthUndefined )
       
    37     {
       
    38     // state, response type, 2 array count, 4bytes each
       
    39     iSize += 16;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CPEngAuthorizationRequest::ConstructL()
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CPEngAuthorizationRequest::ConstructL( const TDesC& aUserId )
       
    47     {
       
    48     CPEngAuthorizationItem::ConstructL( aUserId );
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CPEngAuthorizationRequest::NewLC()
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CPEngAuthorizationRequest* CPEngAuthorizationRequest::NewLC( const TDesC& aUserId,
       
    56                                                              TInt& aSize )
       
    57     {
       
    58     CPEngAuthorizationRequest* self = new( ELeave )
       
    59     CPEngAuthorizationRequest( aSize );
       
    60 
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL( aUserId );
       
    63 
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CPEngAuthorizationRequest::NewLC()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CPEngAuthorizationRequest* CPEngAuthorizationRequest::NewLC( RReadStream& aStream,
       
    73                                                              TInt& aSize )
       
    74     {
       
    75     CPEngAuthorizationRequest* self = new( ELeave )
       
    76     CPEngAuthorizationRequest( aSize );
       
    77 
       
    78     CleanupStack::PushL( self );
       
    79     self->InternalizeL( aStream );
       
    80 
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 // Destructor
       
    86 CPEngAuthorizationRequest::~CPEngAuthorizationRequest()
       
    87     {
       
    88     // state, response type, 4bytes each
       
    89     iSize -= ( 8 + SizeOfArray( iRequestedAttr ) + SizeOfArray( iAuthorizedAttr ) );
       
    90     iRequestedAttr.Reset();
       
    91     iAuthorizedAttr.Reset();
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CPEngAuthorizationRequest::UpdateLocalFlags()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPEngAuthorizationRequest::DoUpdateLocalFlags(
       
   100     const CPEngAuthorizationItem& aSource )
       
   101     {
       
   102     const CPEngAuthorizationRequest& source =
       
   103         static_cast< const CPEngAuthorizationRequest&> ( aSource );
       
   104     if ( ( source.AuthorizationState() == AuthorizationState() ) &&
       
   105          ( source.AuthorizationResponse() == AuthorizationResponse() ) )
       
   106         {
       
   107         iLocalFlags = source.LocalFlags();
       
   108         }
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CPEngAuthorizationRequest::UserId()
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 const TDesC& CPEngAuthorizationRequest::UserId() const
       
   117     {
       
   118     return Id();
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CPEngAuthorizationRequest::RequestedAttributes()
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 const RArray<TUint32>& CPEngAuthorizationRequest::RequestedAttributes() const
       
   126     {
       
   127     return iRequestedAttr;
       
   128     }
       
   129 
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CPEngAuthorizationRequest::AuthorizationState()
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 MPEngAuthorizationRequest::TPEngAuthorizationRequestState
       
   136 CPEngAuthorizationRequest::AuthorizationState() const
       
   137     {
       
   138     return iState;
       
   139     }
       
   140 
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CPEngAuthorizationRequest::AuthorizationResponse()
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 MPEngAuthorizationRequest::TPEngAuthorizationResponseType
       
   147 CPEngAuthorizationRequest::AuthorizationResponse()const
       
   148     {
       
   149     return iResponseType;
       
   150     }
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CPEngAuthorizationRequest::AuthorizedAttributes()
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 const RArray<TUint32>& CPEngAuthorizationRequest::AuthorizedAttributes() const
       
   158     {
       
   159     return iAuthorizedAttr;
       
   160     }
       
   161 
       
   162 
       
   163 // =============================================================================
       
   164 // ========== Functions for authorization response setting =====================
       
   165 // =============================================================================
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CPEngAuthorizationRequest::SetAuthorizedAttributesL()
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CPEngAuthorizationRequest::SetAuthorizedAttributesL(
       
   172     TArray<TUint32>& aAttributes,
       
   173     TBool aKeepOldAuthorization /* ETRue */ )
       
   174     {
       
   175     iAuthManager->SetAuthorizedAttributesL( *this,
       
   176                                             aAttributes,
       
   177                                             aKeepOldAuthorization );
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPEngAuthorizationRequest::DenyAuthorizationL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CPEngAuthorizationRequest::DenyAuthorizationL()
       
   186     {
       
   187     if ( iState != MPEngAuthorizationRequest::EPEngAuthPending )
       
   188         {
       
   189         User::Leave( KErrNotReady );
       
   190         }
       
   191     iAuthManager->DenyAuthorizationL( Id() );
       
   192     }
       
   193 
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CPEngAuthorizationRequest::CancelAuthorizationL()
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CPEngAuthorizationRequest::CancelAuthorizationL()
       
   200     {
       
   201     if ( iState == MPEngAuthorizationRequest::EPEngAuthPending )
       
   202         {
       
   203         User::Leave( KErrNotReady );
       
   204         }
       
   205 
       
   206     iAuthManager->CancelAuthorizationL( Id() );
       
   207     }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CPEngAuthorizationRequest::RemoveAuthorizationResponse
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CPEngAuthorizationRequest::RemoveAuthorizationResponse()
       
   215     {
       
   216     iAuthManager->RemoveAuthorizationResponse( Id() );
       
   217     }
       
   218 
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CPEngAuthorizationRequest::SetAuthorizationManager()
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CPEngAuthorizationRequest::SetAuthorizationManager(
       
   225     MPEngAuthorizationManagerSet* aAuthManager )
       
   226     {
       
   227     iAuthManager = aAuthManager;
       
   228     }
       
   229 
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CPEngAuthorizationRequest::SetAuthState()
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CPEngAuthorizationRequest::SetAuthState(
       
   236     TPEngAuthorizationRequestState aState )
       
   237     {
       
   238     iState = aState;
       
   239     }
       
   240 
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CPEngAuthorizationRequest::SetAuthState()
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CPEngAuthorizationRequest::SetAuthResponse(
       
   247     TPEngAuthorizationResponseType aResponse )
       
   248     {
       
   249     iResponseType = aResponse;
       
   250     }
       
   251 
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CPEngAuthorizationRequest::UpdateAuthorizedAttributesL()
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CPEngAuthorizationRequest::UpdateAuthorizedAttributesL(
       
   258     const RArray<TUint32>& aAuthorizedAttr )
       
   259     {
       
   260     // 4 bytes per each attribute
       
   261     iSize -= 4 * iAuthorizedAttr.Count();
       
   262     iAuthorizedAttr.Reset();
       
   263     iSize += CopyArrayContentL( iAuthorizedAttr, aAuthorizedAttr.Array() );
       
   264     }
       
   265 
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CPEngAuthorizationRequest::UpdateRequestedAttributesL()
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CPEngAuthorizationRequest::UpdateRequestedAttributesL(
       
   272     const RArray<TUint32>& aRequestedAttr )
       
   273     {
       
   274     // 4 bytes per each attribute
       
   275     iSize -= 4 * iRequestedAttr.Count();
       
   276     iRequestedAttr.Reset();
       
   277     iSize +=  CopyArrayContentL( iRequestedAttr, aRequestedAttr.Array() );
       
   278     }
       
   279 
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CPEngAuthorizationRequest::AddRequestedAttributeL()
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CPEngAuthorizationRequest::AddRequestedAttributeL( TUint32 aAttribute )
       
   286     {
       
   287     iSize += AddAttributeToArrayL( iRequestedAttr, aAttribute );
       
   288     }
       
   289 
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CPEngAuthorizationRequest::ExternalizeL()
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CPEngAuthorizationRequest::ExternalizeL( RWriteStream& aStream ) const
       
   296     {
       
   297     // base class
       
   298     CPEngAuthorizationItem::ExternalizeL( aStream );
       
   299 
       
   300     // state, response type
       
   301     aStream.WriteInt32L( iState );
       
   302     aStream.WriteInt32L( iResponseType );
       
   303 
       
   304     ExternalizeArrayL( aStream, iRequestedAttr );
       
   305     ExternalizeArrayL( aStream, iAuthorizedAttr );
       
   306     }
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CPEngAuthorizationRequest::ExternalizeCachedL()
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CPEngAuthorizationRequest::InternalizeL( RReadStream& aStream )
       
   314     {
       
   315     // base class
       
   316     CPEngAuthorizationItem::InternalizeL( aStream );
       
   317 
       
   318     // state, response type
       
   319     iState =
       
   320         static_cast<TPEngAuthorizationRequestState>( aStream.ReadInt32L() );
       
   321 
       
   322     iResponseType =
       
   323         static_cast<TPEngAuthorizationResponseType>( aStream.ReadInt32L() );
       
   324 
       
   325     InternalizeArrayL( aStream, iRequestedAttr, iSize );
       
   326     InternalizeArrayL( aStream, iAuthorizedAttr, iSize );
       
   327     }
       
   328 
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CPEngAuthorizationRequest::Compare()
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 TInt CPEngAuthorizationRequest::Compare( const CPEngAuthorizationRequest& aFirst,
       
   335                                          const CPEngAuthorizationRequest& aSecond )
       
   336     {
       
   337     return aFirst.Id().CompareF( aSecond.Id() );
       
   338     }
       
   339 
       
   340 
       
   341 //  End of File