×
Namespaces

Variants
Actions

Inter-Process Data Transfer

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: vvsnaresh (02 Apr 2007)
Last edited: hamishwillee (25 Jul 2012)

Contents

Introduction

If two threads belong to different processes, they cannot manipulate each other’s data directly because they don’t share the same address space. Two methods of RThread, ReadL() and WriteL(), can be used to copy 8- or 16-bit data between the address spaces of the current thread and a thread represented by the RThread handle. The current thread and the other thread can belong to the same or to different processes.

Data transfer is implemented by copying descriptors or part of them. RThread provides functions to return the length and maximum length of a descriptor located in its address space.

Reading from the descriptor of another thread

void ReadL(const TAny* aPtr,TDes8& aDes,TInt anOffset) const; 
void ReadL(const TAny* aPtr,TDes16 &aDes,TInt anOffset) const;

The ReadL() method copies a block of data from the descriptor (pointed to by aPtr) of the other thread to the descriptor aDes of the current thread. The aPtr pointer must point to a valid descriptor within the address space of the thread represented by the RThread handle. The contents of the source descriptor starting from the anOffset position are copied into the target descriptor aDes. The copied data will be truncated if its length exceeds the maximum length of aDes.


Writing to the descriptor of another thread

void WriteL(const TAny* aPtr,const TDesC8& aDes,TInt anOffset) const; 
void WriteL(const TAny* aPtr,const TDesC16& aDes,TInt anOffset) const;

The WriteL() method copies all data from descriptor aDes of the current thread to the descriptor of the other thread (pointed to by aPtr). The anOffset parameter sets the initial copy position of a target descriptor. The aPtr pointer must point to a valid modifiable descriptor within the current thread’s address space. If the length of data to be copied plus anOffset exceeds the maximum length of the target descriptor, the function leaves.

Descriptor helper functions

TInt GetDesLength(const TAny* aPtr) const;
TInt GetDesMaxLength(const TAny* aPtr) const;

The RThread method GetDesLength() returns the length of a descriptor pointed to by aPtr. The descriptor must be located within the address space of the thread represented by this RThread handle. The RThread method GetMaxDesLength() returns the maximum length of a descriptor pointed to by aPtr. The descriptor must be located within the address space of the thread represented by this RThread handle. The use of these functions before calling ReadL() and WriteL() is recommended.

Using TPckgBuf

The following code demonstrates how to pack/unpack TUint32 into an TPckgBuf

// Packing
TInt res=0;
TPckgBuf<TUint32> pckg(aIapID);
 
// Note that TPckgBuf is of type TDes8
TIpcArgs args(&pckg);
// This is where you send the command
// SendReceive(EServerCmd /*your command*/, args);
 
 
// Unpacking
TInt res=0;
TPckgBuf<TUint32> pckg;
 
// Note that TPckgBuf is of type TDes8
TIpcArgs args(&pckg);
SendReceive(EServerCmd /*your command*/, args);
 
// Extract the value returned from the server.
res = pckg();

--

This page was last modified on 25 July 2012, at 12:20.
36 page views in the last 30 days.
×