sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Support for pipes between processes sl@0: // CPipeDesc is in the parent process, CPipeChildDesc is in the child sl@0: // sl@0: // sl@0: sl@0: #include "FDESC.H" sl@0: #include sl@0: sl@0: NONSHARABLE_CLASS(CPipeDesc) : public CFileDescBase sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: CPipeDesc(TInt anIndex); sl@0: sl@0: void SetClientSide(CPipeDesc*& aClientPointer); sl@0: TInt LSeek(int& offset, int whence); sl@0: void Read(TDes8& aDesc, TRequestStatus& aStatus); sl@0: TInt ReadCompletion(TDes8& aDesc, TInt aStatus); sl@0: void ReadCancel(); sl@0: void Write(TDes8& aDesc, TRequestStatus& aStatus); sl@0: TInt WriteCompletion(TDes8& aDesc, TInt aStatus); sl@0: void WriteCancel(); sl@0: TInt FStat(struct stat *st); sl@0: void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); sl@0: TInt IoctlCompletion(int aCmd, void* aParam, TInt aStatus); sl@0: void IoctlCancel(); sl@0: sl@0: void ClientRead(const RMessage2& aMessage); sl@0: void ClientWrite(const RMessage2& aMessage); sl@0: void ClientIoctl(const RMessage2& aMessage); sl@0: void ClientCancel(const RMessage2& aMessage); sl@0: void ClientClose(); sl@0: protected: sl@0: TInt FinalClose(); sl@0: private: sl@0: void Cancel(); sl@0: TInt IsWriteable() { return !iIndex; } // 0 => child STDIN sl@0: TInt IsReadable() { return iIndex; } sl@0: TInt SelectMask() { return (iIndex)? E32SELECT_READ :E32SELECT_WRITE; } sl@0: TInt ClientSelectMask() { return (iIndex)? E32SELECT_WRITE:E32SELECT_READ; } sl@0: TInt ClientIoctlPending() { return iClientIoctlPending; } sl@0: sl@0: void TransferFromClient(); sl@0: void TransferToClient(); sl@0: void CompleteClientIoctl(TInt ret); sl@0: void CompleteClientIoctl(); sl@0: void Panic(TInt aReason); sl@0: void Panic(RMessage2& aMessage, TInt aReason); sl@0: private: sl@0: TInt iIndex; // index into per-process table of pipes, also implies direction. sl@0: CPipeDesc** iClientSide; sl@0: TInt iClientClosed; sl@0: // Pending info for parent operation sl@0: TRequestStatus* iStatus; // null implies "no pending operation" sl@0: TRequestStatus* iIoctlStatus; sl@0: TPtrC8 iWriteBuf; sl@0: TDes8* iReadBuf; sl@0: // Pending info for child operation sl@0: TInt iClientLength; // 0 implies "no pending operation" sl@0: TInt iClientOffset; sl@0: RMessage2 iMessage; sl@0: TInt iClientIoctlPending; sl@0: RMessage2 iIoctlMessage; sl@0: }; sl@0: sl@0: class RPosixSession; sl@0: NONSHARABLE_CLASS(CPipeChildDesc) : public CFileDescBase sl@0: /** sl@0: CPipeChildDesc sl@0: Basically just forwards requests to the parent CPosixServer, where the related CPipeDesc sl@0: does the actual work. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: CPipeChildDesc(TInt anIndex, RPosixSession& aSession); sl@0: sl@0: TInt LSeek(int& offset, int whence); sl@0: void Read(TDes8& aDesc, TRequestStatus& aStatus); sl@0: TInt ReadCompletion(TDes8& aDesc, TInt aStatus); sl@0: void ReadCancel(); sl@0: void Write(TDes8& aDesc, TRequestStatus& aStatus); sl@0: TInt WriteCompletion(TDes8& aDesc, TInt aStatus); sl@0: void WriteCancel(); sl@0: TInt FStat(struct stat *st); sl@0: void Ioctl(int aCmd, void* aParam, TRequestStatus& aStatus); sl@0: void IoctlCancel(); sl@0: sl@0: void ClientClose() { iClientClosed=1; } sl@0: sl@0: protected: sl@0: TInt FinalClose(); sl@0: private: sl@0: void Cancel(TInt aType); sl@0: TInt IsWriteable() { return iIndex; } // 0 => child STDIN sl@0: TInt IsReadable() { return !iIndex; } sl@0: TInt SelectMask() { return (!iIndex)? E32SELECT_READ:E32SELECT_WRITE; } sl@0: sl@0: TInt iIndex; // index into per-process table of pipes, also implies direction. sl@0: RPosixSession& iSession; sl@0: TInt iClientClosed; sl@0: TPtr8 iParamDes; sl@0: };