customization/DMUtils/inc/TARMDmStreamAdapter.h
changeset 0 3ce708148e4d
child 15 a04cc51a130f
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002-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: Implementation of customization components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __TARMDmStreamAdapter_H__
       
    20 #define __TARMDmStreamAdapter_H__
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <s32file.h> //RFileWriteStream
       
    25 #include "TARMDmAdapter.h"
       
    26 
       
    27 /**
       
    28 * This class adds streaming support to CTARMDmAdapter
       
    29 *
       
    30 * To enable streaming in your adapter:
       
    31 *
       
    32 * 1) Inherit from CTARMDmStreamAdapter
       
    33 * 2) Implement StreamingSupport (to return ETrue and set item size)
       
    34 * 3) Implement StreamType to return the stream support type
       
    35 *
       
    36 * Stream types:
       
    37 *
       
    38 * - EStreamToBuffer to get data in aObject argument
       
    39 * - EStreamToFile to get data in a file, file name is in iFileStoreFileName
       
    40 * - EStreamToNone to use streaming methods of CTARMDmAdapter
       
    41 *
       
    42 * 4) Use CTARMDmStreamAdapter::StreamCommittedL()
       
    43 *
       
    44 * StreamCommittedL will complete operation with call to the non-streaming method:
       
    45 *
       
    46 * - _UpdateLeafObjectL or
       
    47 * - _ExecuteCommandL
       
    48 *
       
    49 *
       
    50 */
       
    51 class CTARMDmStreamAdapter : public CTARMDmAdapter
       
    52 	{
       
    53 public:
       
    54     enum TAdapterStreamType
       
    55         {
       
    56         EStreamToNone,        
       
    57         EStreamToBuffer,
       
    58         EStreamToFile
       
    59         };
       
    60 
       
    61     class CTARMDmStreamAdapterBuffer : public CBase
       
    62         {
       
    63         public:
       
    64         
       
    65             enum TTARMDMAction
       
    66                 {
       
    67                 ETARMActionNone,
       
    68                 ETARMActionUpdate,
       
    69                 ETARMActionExecute,
       
    70                 };
       
    71         private:
       
    72             HBufC8 *iURI;
       
    73             HBufC8 *iLUID;
       
    74             HBufC8 *iType;
       
    75             TInt iStatusRef;
       
    76             TInt iResultRef;
       
    77             CTARMDmStreamAdapterBuffer::TTARMDMAction iAction; 
       
    78         public:
       
    79             CTARMDmStreamAdapterBuffer::CTARMDmStreamAdapterBuffer()
       
    80                 : iURI( 0 )
       
    81                 , iLUID( 0 )
       
    82                 , iType( 0 )
       
    83                 , iStatusRef( 0 )
       
    84                 , iResultRef( 0 )
       
    85                 , iAction( CTARMDmStreamAdapterBuffer::ETARMActionNone )
       
    86                 {
       
    87                 }
       
    88              static CTARMDmStreamAdapterBuffer* CTARMDmStreamAdapterBuffer::NewL(
       
    89                         const TDesC8 &aURI,
       
    90                         const TDesC8 &aLUID,
       
    91                         const TDesC8 &aType,
       
    92                         TInt aStatusRef,
       
    93                         TInt aResultRef,
       
    94                         CTARMDmStreamAdapterBuffer::TTARMDMAction aAction
       
    95                         )
       
    96                 {
       
    97                 CTARMDmStreamAdapterBuffer* newObject = new (ELeave) CTARMDmStreamAdapterBuffer();
       
    98                 newObject->iURI  = aURI.AllocL();
       
    99                 newObject->iLUID = aLUID.AllocL();
       
   100                 newObject->iType = aType.AllocL();
       
   101                 newObject->iStatusRef = aStatusRef;
       
   102                 newObject->iResultRef = aResultRef;
       
   103                 newObject->iAction = aAction;
       
   104                 return newObject;
       
   105                 }
       
   106             CTARMDmStreamAdapterBuffer::~CTARMDmStreamAdapterBuffer()
       
   107                 {
       
   108                 delete iURI;
       
   109                 delete iLUID;
       
   110                 delete iType;
       
   111                 }
       
   112             const TDesC8& CTARMDmStreamAdapterBuffer::URI() const
       
   113                 {
       
   114                 return *iURI;
       
   115                 }
       
   116             const TDesC8& CTARMDmStreamAdapterBuffer::LUID() const
       
   117                 {
       
   118                 return *iLUID;
       
   119                 }
       
   120             const TDesC8& CTARMDmStreamAdapterBuffer::Type() const
       
   121                 {
       
   122                 return *iType;
       
   123                 }
       
   124             TInt CTARMDmStreamAdapterBuffer::StatusRef() const
       
   125                 {
       
   126                 return iStatusRef;
       
   127                 }
       
   128             TInt CTARMDmStreamAdapterBuffer::ResultRef() const
       
   129                 {
       
   130                 return iResultRef;
       
   131                 }
       
   132             CTARMDmStreamAdapterBuffer::TTARMDMAction CTARMDmStreamAdapterBuffer::Action() const
       
   133                 {
       
   134                 return iAction;
       
   135                 }
       
   136         };
       
   137 
       
   138 	// Implementation of MSmlDmAdapter interface functions that make policy checks
       
   139 	// ===========================================================================
       
   140 private:
       
   141 	void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef );
       
   142 	void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef );
       
   143 
       
   144 	// Implementation of MSmlDmAdapter interface functions AFTER policy checks
       
   145 	// =======================================================================
       
   146 public:
       
   147 	virtual void _UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType, TInt aStatusRef ) = 0;
       
   148 	virtual void _ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, const TDesC8& aType, TInt aStatusRef ) = 0;
       
   149 	virtual void _UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef ) = 0;
       
   150 	virtual void _ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef ) = 0;
       
   151 
       
   152 	// Other
       
   153 	virtual TAdapterStreamType StreamType( const TDesC8& aURI );
       
   154 	void StreamToBufferL( RWriteStream*& aStream );
       
   155 	void StreamToFileL( RWriteStream*& aStream );
       
   156 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
   157 		virtual void StreamCommittedL( RWriteStream& aStream );
       
   158 #else
       
   159 		virtual void StreamCommittedL();
       
   160 #endif	
       
   161 
       
   162     void SetActionInfoL( CTARMDmStreamAdapterBuffer::TTARMDMAction aAction,
       
   163                          const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aType,
       
   164                          TInt aStatusRef, TInt aResultRef );
       
   165     void ClearActionInfo();
       
   166     CTARMDmStreamAdapterBuffer& ActionInfoL();
       
   167     void CommitActionL( const TDesC8& aObject );
       
   168 
       
   169 protected:
       
   170 	CTARMDmStreamAdapter( MSmlDmCallback* aCallback );
       
   171 	virtual ~CTARMDmStreamAdapter();
       
   172 
       
   173 private:
       
   174     RFs                 iFs;
       
   175     RFileWriteStream    iWriteStream;
       
   176     TFileName           iFileStoreFileName;
       
   177     TAdapterStreamType  iStreamType;
       
   178 
       
   179     CTARMDmStreamAdapterBuffer *iActionInfo;
       
   180 	};
       
   181 
       
   182 #endif      // __TARMDmStreamAdapter_H__
       
   183 
       
   184 // End of File