1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/INC/PIPEDESC.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,118 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Support for pipes between processes
1.18 +// CPipeDesc is in the parent process, CPipeChildDesc is in the child
1.19 +//
1.20 +//
1.21 +
1.22 +#include "FDESC.H"
1.23 +#include <sys/ioctl.h>
1.24 +
1.25 +NONSHARABLE_CLASS(CPipeDesc) : public CFileDescBase
1.26 +/**
1.27 +@internalComponent
1.28 +*/
1.29 + {
1.30 +public:
1.31 + CPipeDesc(TInt anIndex);
1.32 +
1.33 + void SetClientSide(CPipeDesc*& aClientPointer);
1.34 + TInt LSeek(int& offset, int whence);
1.35 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.36 + TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
1.37 + void ReadCancel();
1.38 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.39 + TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
1.40 + void WriteCancel();
1.41 + TInt FStat(struct stat *st);
1.42 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.43 + TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus);
1.44 + void IoctlCancel();
1.45 +
1.46 + void ClientRead(const RMessage2& aMessage);
1.47 + void ClientWrite(const RMessage2& aMessage);
1.48 + void ClientIoctl(const RMessage2& aMessage);
1.49 + void ClientCancel(const RMessage2& aMessage);
1.50 + void ClientClose();
1.51 +protected:
1.52 + TInt FinalClose();
1.53 +private:
1.54 + void Cancel();
1.55 + TInt IsWriteable() { return !iIndex; } // 0 => child STDIN
1.56 + TInt IsReadable() { return iIndex; }
1.57 + TInt SelectMask() { return (iIndex)? E32SELECT_READ :E32SELECT_WRITE; }
1.58 + TInt ClientSelectMask() { return (iIndex)? E32SELECT_WRITE:E32SELECT_READ; }
1.59 + TInt ClientIoctlPending() { return iClientIoctlPending; }
1.60 +
1.61 + void TransferFromClient();
1.62 + void TransferToClient();
1.63 + void CompleteClientIoctl(TInt ret);
1.64 + void CompleteClientIoctl();
1.65 + void Panic(TInt aReason);
1.66 + void Panic(RMessage2& aMessage, TInt aReason);
1.67 +private:
1.68 + TInt iIndex; // index into per-process table of pipes, also implies direction.
1.69 + CPipeDesc** iClientSide;
1.70 + TInt iClientClosed;
1.71 + // Pending info for parent operation
1.72 + TRequestStatus* iStatus; // null implies "no pending operation"
1.73 + TRequestStatus* iIoctlStatus;
1.74 + TPtrC8 iWriteBuf;
1.75 + TDes8* iReadBuf;
1.76 + // Pending info for child operation
1.77 + TInt iClientLength; // 0 implies "no pending operation"
1.78 + TInt iClientOffset;
1.79 + RMessage2 iMessage;
1.80 + TInt iClientIoctlPending;
1.81 + RMessage2 iIoctlMessage;
1.82 + };
1.83 +
1.84 +class RPosixSession;
1.85 +NONSHARABLE_CLASS(CPipeChildDesc) : public CFileDescBase
1.86 +/**
1.87 +CPipeChildDesc
1.88 +Basically just forwards requests to the parent CPosixServer, where the related CPipeDesc
1.89 +does the actual work.
1.90 +@internalComponent
1.91 +*/
1.92 + {
1.93 +public:
1.94 + CPipeChildDesc(TInt anIndex, RPosixSession& aSession);
1.95 +
1.96 + TInt LSeek(int& offset, int whence);
1.97 + void Read(TDes8& aDesc, TRequestStatus& aStatus);
1.98 + TInt ReadCompletion(TDes8& aDesc, TInt aStatus);
1.99 + void ReadCancel();
1.100 + void Write(TDes8& aDesc, TRequestStatus& aStatus);
1.101 + TInt WriteCompletion(TDes8& aDesc, TInt aStatus);
1.102 + void WriteCancel();
1.103 + TInt FStat(struct stat *st);
1.104 + void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus);
1.105 + void IoctlCancel();
1.106 +
1.107 + void ClientClose() { iClientClosed=1; }
1.108 +
1.109 +protected:
1.110 + TInt FinalClose();
1.111 +private:
1.112 + void Cancel(TInt aType);
1.113 + TInt IsWriteable() { return iIndex; } // 0 => child STDIN
1.114 + TInt IsReadable() { return !iIndex; }
1.115 + TInt SelectMask() { return (!iIndex)? E32SELECT_READ:E32SELECT_WRITE; }
1.116 +
1.117 + TInt iIndex; // index into per-process table of pipes, also implies direction.
1.118 + RPosixSession& iSession;
1.119 + TInt iClientClosed;
1.120 + TPtr8 iParamDes;
1.121 + };