PECengine/ListLibrary2/AuthSrc/CPEngAuthorizationResponse.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 one reactive authorization response
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include    <e32std.h>
       
    20 #include    <s32strm.h>
       
    21 #include    "CPEngAuthorizationResponse.h"
       
    22 
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CPEngAuthorizationResponse::CPEngAuthorizationResponse()
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CPEngAuthorizationResponse::CPEngAuthorizationResponse( TInt& aSize )
       
    31         : CPEngAuthorizationItem( aSize )
       
    32     {
       
    33     //state, attributes count, 4 bytes per each
       
    34     iSize += 8;
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CPEngAuthorizationResponse::ConstructL()
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 void CPEngAuthorizationResponse::ConstructL( const TDesC& aUserId )
       
    42     {
       
    43     CPEngAuthorizationItem::ConstructL( aUserId );
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPEngAuthorizationResponse::NewLC()
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CPEngAuthorizationResponse* CPEngAuthorizationResponse::NewLC( const TDesC& aUserId,
       
    52                                                                TInt& aSize )
       
    53     {
       
    54     CPEngAuthorizationResponse* self =
       
    55         new ( ELeave ) CPEngAuthorizationResponse( aSize );
       
    56 
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aUserId );
       
    59 
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CPEngAuthorizationResponse::NewLC()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CPEngAuthorizationResponse* CPEngAuthorizationResponse::NewLC( RReadStream& aStream,
       
    68                                                                TInt& aSize )
       
    69     {
       
    70     CPEngAuthorizationResponse* self =
       
    71         new( ELeave ) CPEngAuthorizationResponse( aSize );
       
    72 
       
    73     CleanupStack::PushL( self );
       
    74     self->InternalizeL( aStream );
       
    75 
       
    76     return self;
       
    77     }
       
    78 
       
    79 
       
    80 // Destructor
       
    81 CPEngAuthorizationResponse::~CPEngAuthorizationResponse()
       
    82     {
       
    83     // 4 bytes per number: State
       
    84     iSize -= ( 4 + SizeOfArray( iAttributes ) );
       
    85     iAttributes.Reset();
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPEngAuthorizationResponse::UpdateLocalFlags()
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CPEngAuthorizationResponse::DoUpdateLocalFlags(
       
    94     const CPEngAuthorizationItem& aSource )
       
    95     {
       
    96     const CPEngAuthorizationResponse& source =
       
    97         static_cast< const CPEngAuthorizationResponse&> ( aSource );
       
    98 
       
    99     if ( ( source.AuthorizationStatus() == AuthorizationStatus() )
       
   100          && ( source.AuthorizedAttributes().Count() == iAttributes.Count() ) )
       
   101         {
       
   102         iLocalFlags = source.LocalFlags();
       
   103         }
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CPEngAuthorizationResponse::UserId()
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 const TDesC& CPEngAuthorizationResponse::UserId() const
       
   112     {
       
   113     return Id();
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CPEngAuthorizationResponse::AuthorizationStatus()
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 TInt CPEngAuthorizationResponse::AuthorizationStatus() const
       
   122     {
       
   123     return iResponseType;
       
   124     }
       
   125 
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CPEngAuthorizationResponse::AuthorizedAttributes()
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 const RArray<TUint32>& CPEngAuthorizationResponse::AuthorizedAttributes() const
       
   132     {
       
   133     return iAttributes;
       
   134     }
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPEngAuthorizationResponse::SetResponseType()
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CPEngAuthorizationResponse::SetResponseType( TInt aResponseType )
       
   142     {
       
   143     iResponseType = aResponseType;
       
   144     }
       
   145 
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CPEngAuthorizationResponse::SetAttributesToAuthorizeL()
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CPEngAuthorizationResponse::SetAttributesToAuthorizeL(
       
   152     const TArray<TUint32>& aAttributes,
       
   153     const RArray<TUint32>* aAuthorizedAttributes )
       
   154     {
       
   155     // 4 bytes per each attribute
       
   156     iSize -= ( 4 * iAttributes.Count() );
       
   157     iAttributes.Reset();
       
   158     iSize += CopyArrayContentL( iAttributes, aAttributes );
       
   159     // shall already authorized attributes be included
       
   160     if ( aAuthorizedAttributes )
       
   161         {
       
   162         iSize += CopyArrayContentL( iAttributes, aAuthorizedAttributes->Array() );
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CPEngAuthorizationResponse::AddAttributeL()
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CPEngAuthorizationResponse::AddAttributeL( TUint32 aAttribute )
       
   172     {
       
   173     AddAttributeToArrayL( iAttributes, aAttribute );
       
   174     }
       
   175 
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CPEngAuthorizationResponse::ExternalizeL()
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CPEngAuthorizationResponse::ExternalizeL( RWriteStream& aStream ) const
       
   182     {
       
   183     // base class
       
   184     CPEngAuthorizationItem::ExternalizeL( aStream );
       
   185 
       
   186     // response type
       
   187     aStream.WriteInt32L( iResponseType );
       
   188 
       
   189     // Attributes
       
   190     ExternalizeArrayL( aStream, iAttributes );
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CPEngAuthorizationResponse::ExternalizeCachedL()
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CPEngAuthorizationResponse::InternalizeL( RReadStream& aStream )
       
   199     {
       
   200     // base class
       
   201     CPEngAuthorizationItem::InternalizeL( aStream );
       
   202 
       
   203     // response type
       
   204     iResponseType = aStream.ReadInt32L();
       
   205 
       
   206     // Attributes
       
   207     InternalizeArrayL( aStream, iAttributes, iSize );
       
   208     }
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CPEngAuthorizationResponse::Compare()
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TInt CPEngAuthorizationResponse::Compare( const CPEngAuthorizationResponse& aFirst,
       
   216                                           const CPEngAuthorizationResponse& aSecond )
       
   217     {
       
   218     return aFirst.Id().CompareF( aSecond.Id() ) ;
       
   219     }
       
   220 
       
   221 
       
   222 //  End of File