genericopenlibs/cstdlib/INC/PIPEDESC.H
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 // Support for pipes between processes
       
    15 // CPipeDesc is in the parent process, CPipeChildDesc is in the child
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "FDESC.H"
       
    20 #include <sys/ioctl.h>
       
    21 
       
    22 NONSHARABLE_CLASS(CPipeDesc) : public CFileDescBase
       
    23 /**
       
    24 @internalComponent
       
    25 */
       
    26 	{
       
    27 public:
       
    28 	CPipeDesc(TInt anIndex);
       
    29 
       
    30 	void SetClientSide(CPipeDesc*& aClientPointer);
       
    31 	TInt LSeek(int& offset, int whence);
       
    32 	void Read(TDes8& aDesc, TRequestStatus& aStatus);
       
    33 	TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
       
    34 	void ReadCancel();
       
    35 	void Write(TDes8& aDesc, TRequestStatus& aStatus);
       
    36 	TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
       
    37 	void WriteCancel();
       
    38 	TInt FStat(struct stat *st);
       
    39 	void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
       
    40 	TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
       
    41 	void IoctlCancel();
       
    42 
       
    43 	void ClientRead(const RMessage2& aMessage);
       
    44 	void ClientWrite(const RMessage2& aMessage);
       
    45 	void ClientIoctl(const RMessage2& aMessage);
       
    46 	void ClientCancel(const RMessage2& aMessage);
       
    47 	void ClientClose();
       
    48 protected:
       
    49 	TInt FinalClose();
       
    50 private:
       
    51 	void Cancel();
       
    52 	TInt IsWriteable() { return !iIndex; }	// 0 => child STDIN
       
    53 	TInt IsReadable() { return iIndex; }
       
    54 	TInt SelectMask()       { return (iIndex)? E32SELECT_READ :E32SELECT_WRITE; }
       
    55 	TInt ClientSelectMask() { return (iIndex)? E32SELECT_WRITE:E32SELECT_READ;  }
       
    56 	TInt ClientIoctlPending() { return iClientIoctlPending; }
       
    57 
       
    58 	void TransferFromClient();
       
    59 	void TransferToClient();
       
    60 	void CompleteClientIoctl(TInt ret);
       
    61 	void CompleteClientIoctl();
       
    62 	void Panic(TInt aReason);
       
    63 	void Panic(RMessage2& aMessage, TInt aReason);
       
    64 private:
       
    65 	TInt iIndex;	// index into per-process table of pipes, also implies direction.
       
    66 	CPipeDesc** iClientSide;
       
    67 	TInt iClientClosed;
       
    68 	// Pending info for parent operation
       
    69 	TRequestStatus* iStatus;	// null implies "no pending operation"
       
    70 	TRequestStatus* iIoctlStatus;
       
    71 	TPtrC8 iWriteBuf;
       
    72 	TDes8* iReadBuf;
       
    73 	// Pending info for child operation
       
    74 	TInt iClientLength;		// 0 implies "no pending operation"
       
    75 	TInt iClientOffset;
       
    76 	RMessage2 iMessage;
       
    77 	TInt iClientIoctlPending;
       
    78 	RMessage2 iIoctlMessage;
       
    79 	};
       
    80 
       
    81 class RPosixSession;
       
    82 NONSHARABLE_CLASS(CPipeChildDesc) : public CFileDescBase
       
    83 /**
       
    84 CPipeChildDesc
       
    85 Basically just forwards requests to the parent CPosixServer, where the related CPipeDesc
       
    86 does the actual work.
       
    87 @internalComponent
       
    88 */
       
    89 	{
       
    90 public:
       
    91 	CPipeChildDesc(TInt anIndex, RPosixSession& aSession); 
       
    92 
       
    93 	TInt LSeek(int& offset, int whence);
       
    94 	void Read(TDes8& aDesc, TRequestStatus& aStatus);
       
    95 	TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
       
    96 	void ReadCancel();
       
    97 	void Write(TDes8& aDesc, TRequestStatus& aStatus);
       
    98 	TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
       
    99 	void WriteCancel();
       
   100 	TInt FStat(struct stat *st);
       
   101 	void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
       
   102 	void IoctlCancel();
       
   103 
       
   104 	void ClientClose() { iClientClosed=1; }
       
   105 
       
   106 protected:
       
   107 	TInt FinalClose();
       
   108 private:
       
   109 	void Cancel(TInt aType);
       
   110 	TInt IsWriteable() { return iIndex; }	// 0 => child STDIN
       
   111 	TInt IsReadable() { return !iIndex; }
       
   112 	TInt SelectMask() { return (!iIndex)? E32SELECT_READ:E32SELECT_WRITE; }
       
   113 
       
   114 	TInt iIndex;	// index into per-process table of pipes, also implies direction.
       
   115 	RPosixSession& iSession;
       
   116 	TInt iClientClosed;
       
   117 	TPtr8 iParamDes;
       
   118 	};