persistentstorage/sql/SRC/Client/IPC/IPCBuf.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __IPCBUF_H__
       
    17 #define __IPCBUF_H__
       
    18 
       
    19 #include <s32buf.h>
       
    20 #include "IpcDefs.h"
       
    21 
       
    22 //Forward declarations
       
    23 class TIpcArgs;
       
    24 class RSqlDbSession;
       
    25 
       
    26 /**
       
    27 HIpcBuf class manages the "client to server" transfer of large data blocks.
       
    28 
       
    29 It caches the data to be sent/retrieved on the client side and sychronises the content of the client-side cache
       
    30 with the content of a similar server-side cache, sending appropriate read/write/sync commands to the server.
       
    31 
       
    32 An instance of TIpcStreamBuf class is uased as a client-side cache.
       
    33 
       
    34 The following code fragment shows how the class can be used to send to the server large blocks of data:
       
    35 
       
    36 @code
       
    37 //Step 1: Create the HIpcBuf instance.
       
    38 HIpcBuf* ipcBuf = HIpcBuf::NewLC(params, function, args);
       
    39 
       
    40 //Step 2: Create a stream instance. It will be used for sending the data to the server. All details about
       
    41 //		  the data transfer will be performed by the ipcBuf object.
       
    42 RWriteStream out(ipcBuf);
       
    43 
       
    44 //Step 3: "TheObject" is some large data object which has to be sent to the server. Let's assume 
       
    45 //		  "TheObject" has ExternalizeL() function which can be used to externalize the object into an output stream.
       
    46 TheObject.ExternalizeL(out);
       
    47 
       
    48 //Step 4: Commit the output stream. After the commit command the server will have all the data transferred.
       
    49 out.CommitL();		
       
    50 
       
    51 //Step 5: Cleanup.
       
    52 CleanupStack::PopAndDestroy(ipcBuf);
       
    53 @endcode
       
    54 
       
    55 @see RSqlDbSession;
       
    56 @see TIpcStreamBuf
       
    57 @see RSessionBase
       
    58 
       
    59 @internalComponent
       
    60 */
       
    61 NONSHARABLE_CLASS(HIpcBuf) : public TStreamBuf
       
    62 	{
       
    63 public:
       
    64 	static HIpcBuf* NewL(RSqlDbSession& aSession, TInt aFunction, TIpcArgs& aArgs);
       
    65 	static HIpcBuf* NewLC(RSqlDbSession& aSession, TInt aFunction, TIpcArgs& aArgs);
       
    66 	virtual ~HIpcBuf();
       
    67 	
       
    68 private:
       
    69 	HIpcBuf(RSqlDbSession& aSession);
       
    70 	void ConstructL(TInt aFunction, TIpcArgs& aArgs);
       
    71 	
       
    72 	// from TStreamBuf
       
    73 	TInt UnderflowL(TInt aMaxLength);
       
    74 	void OverflowL();
       
    75 	void DoRelease();
       
    76 	void DoSynchL();
       
    77 	TInt DoReadL(TAny* aPtr, TInt aMaxLength);
       
    78 	void DoWriteL(const TAny* aPtr, TInt aLength);
       
    79 	TStreamPos DoSeekL(TMark aMark, TStreamLocation aLocation, TInt anOffset);
       
    80 	
       
    81 private:
       
    82 	inline void SetPos(TRead, TInt aPos);
       
    83 	inline void SetPos(TWrite, TInt aPos);
       
    84 	inline TInt Pos(TRead) const;
       
    85 	inline TInt Pos(TWrite) const;
       
    86 	inline TInt MovePos(TRead, TInt aOffset);
       
    87 	TInt IpcReadL(TAny* aPtr, TInt aMaxLength);
       
    88 	void IpcWriteL(const TAny* aPtr, TInt aLength);
       
    89 	TInt EndL();
       
    90 
       
    91 	inline TInt Lag(TRead) const;
       
    92 	inline TInt Lag(TWrite) const;
       
    93 	inline TInt Mark(TRead) const;
       
    94 	inline TInt Mark(TWrite) const;
       
    95 	
       
    96 private:
       
    97 	RSqlDbSession& 	iSession;
       
    98 	TInt			iHandle;
       
    99 	TInt 			iRPos;
       
   100 	TInt 			iWPos;
       
   101 	TIpcStreamBuf	iBuf;
       
   102 	};
       
   103 
       
   104 #include "IPCBuf.inl"
       
   105 
       
   106 #endif//__IPCBUF_H__