core/src/pipe_line.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // pipe_line.h
       
     2 // 
       
     3 // Copyright (c) 2006 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #ifndef __PIPE_LINE_H__
       
    14 #define __PIPE_LINE_H__
       
    15 
       
    16 #include <e32base.h>
       
    17 #include "command_wrappers.h"
       
    18 
       
    19 class TError;
       
    20 class CPipeLine;
       
    21 class MConsole;
       
    22 class CCommandFactory;
       
    23 namespace IoUtils
       
    24 	{
       
    25 	class CEnvironment;
       
    26 	}
       
    27 
       
    28 
       
    29 class MPipeLineObserver
       
    30 	{
       
    31 public:
       
    32 	virtual void HandlePipeLineComplete(CPipeLine& aPipeLine, const TError& aError) = 0;
       
    33 	};
       
    34 
       
    35 
       
    36 class RPipeSection
       
    37 	{
       
    38 public:
       
    39 	RPipeSection();
       
    40 	void Close();
       
    41 	HBufC* GetCommandArguments() const;
       
    42 public:
       
    43 	class TRedirection
       
    44 		{
       
    45 	public:
       
    46 		enum TType
       
    47 			{
       
    48 			ENotRedirected,
       
    49 			EFile,
       
    50 			EFileAppend,
       
    51 			EHandle,
       
    52 			ENull
       
    53 			};
       
    54 		enum THandle
       
    55 			{
       
    56 			EUnknown,
       
    57 			EStdin,
       
    58 			EStdout,
       
    59 			EStderr
       
    60 			};
       
    61 	public:
       
    62 		TRedirection();
       
    63 		void SetFileNameL(const TDesC& aCwd, const TDesC& aName);
       
    64 	public:
       
    65 		TType iType;
       
    66 		IoUtils::TFileName2* iFileName;
       
    67 		THandle iHandle;
       
    68 		};
       
    69 public:
       
    70 	TPtrC iFullName;
       
    71 	TPtrC iCommandName;
       
    72 	RArray<TPtrC> iCommandArguments;
       
    73 	TRedirection iStdinRedirection;
       
    74 	TRedirection iStdoutRedirection;
       
    75 	TRedirection iStderrRedirection;
       
    76 private:
       
    77 	mutable HBufC* iCommandArgumentsBuf;
       
    78 	};
       
    79 
       
    80 
       
    81 class CPipeLine : public CBase, public MCommandObserver
       
    82 	{
       
    83 public:
       
    84 	static CPipeLine* NewL(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, IoUtils::CEnvironment& aEnv, CCommandFactory& aFactory, const RArray<RPipeSection>& aPipeSections, TBool aBackground, MPipeLineObserver* aObserver, TError& aErrorContext);
       
    85 	static CPipeLine* NewLC(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, IoUtils::CEnvironment& aEnv, CCommandFactory& aFactory, const RArray<RPipeSection>& aPipeSections, TBool aBackground, MPipeLineObserver* aObserver, TError& aErrorContext);
       
    86 	~CPipeLine();
       
    87 	void Kill();
       
    88 	TInt Suspend();
       
    89 	TInt Resume();
       
    90 	TInt BringToForeground();
       
    91 	void SendToBackground();
       
    92 	const TDesC& Name() const;
       
    93 	TInt Reattach(RIoEndPoint& aStdinEndPoint, RIoEndPoint& aStdoutEndPoint, RIoEndPoint& aStderrEndPoint);
       
    94 	TBool IsDisownable() const;
       
    95 	void Disown();
       
    96 private:
       
    97 	CPipeLine(RIoSession& aIoSession, RIoReadHandle& aStdin, RIoWriteHandle& aStdout, RIoWriteHandle& aStderr, IoUtils::CEnvironment& aEnv, CCommandFactory& aFactory, MPipeLineObserver* aObserver);
       
    98 	void ConstructL(const RArray<RPipeSection>& aPipeSections, TBool aBackground, TError& aErrorContext);
       
    99 	static TInt CompletionCallBack(TAny* aSelf);
       
   100 private:	// From MCommandObserver.
       
   101 	virtual void HandleCommandComplete(MCommand& aCommand, TInt aError);
       
   102 private:
       
   103 	class RPipedCommand
       
   104 		{
       
   105 	public:
       
   106 		RPipedCommand();
       
   107 		void Close();
       
   108 	public:
       
   109 		MCommand* iCommand;
       
   110 		TInt iCompletionError;
       
   111 		HBufC* iCommandName;
       
   112 		TBool iStdinRedirected;
       
   113 		TBool iStdoutRedirected;
       
   114 		TBool iStderrRedirected;
       
   115 		};
       
   116 private:
       
   117 	TPtrC iName;
       
   118 	RIoSession& iIoSession;
       
   119 	RIoReadHandle& iStdin;
       
   120 	RIoWriteHandle& iStdout;
       
   121 	RIoWriteHandle& iStderr;
       
   122 	IoUtils::CEnvironment& iEnv;
       
   123 	CCommandFactory& iFactory;
       
   124 	MPipeLineObserver* iObserver;
       
   125 	RArray<RPipedCommand> iCommands;
       
   126 	CAsyncCallBack* iCompletionCallBack;
       
   127 	TError iCompletionError;
       
   128 	};
       
   129 
       
   130 
       
   131 #endif // __PIPE_LINE_H__