1 |
|
---|
2 | /* $Id: GuestProcessImpl.h 42897 2012-08-21 10:03:52Z vboxsync $ */
|
---|
3 | /** @file
|
---|
4 | * VirtualBox Main - XXX.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ____H_GUESTPROCESSIMPL
|
---|
20 | #define ____H_GUESTPROCESSIMPL
|
---|
21 |
|
---|
22 | #include "VirtualBoxBase.h"
|
---|
23 | #include "GuestCtrlImplPrivate.h"
|
---|
24 |
|
---|
25 | class Console;
|
---|
26 | class GuestSession;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * TODO
|
---|
30 | */
|
---|
31 | class ATL_NO_VTABLE GuestProcess :
|
---|
32 | public VirtualBoxBase,
|
---|
33 | VBOX_SCRIPTABLE_IMPL(IGuestProcess)
|
---|
34 | {
|
---|
35 | public:
|
---|
36 | /** @name COM and internal init/term/mapping cruft.
|
---|
37 | * @{ */
|
---|
38 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestProcess, IGuestProcess)
|
---|
39 | DECLARE_NOT_AGGREGATABLE(GuestProcess)
|
---|
40 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
41 | BEGIN_COM_MAP(GuestProcess)
|
---|
42 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestProcess)
|
---|
43 | COM_INTERFACE_ENTRY(IProcess)
|
---|
44 | END_COM_MAP()
|
---|
45 | DECLARE_EMPTY_CTOR_DTOR(GuestProcess)
|
---|
46 |
|
---|
47 | int init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo);
|
---|
48 | void uninit(void);
|
---|
49 | HRESULT FinalConstruct(void);
|
---|
50 | void FinalRelease(void);
|
---|
51 | /** @} */
|
---|
52 |
|
---|
53 | /** @name IProcess interface.
|
---|
54 | * @{ */
|
---|
55 | STDMETHOD(COMGETTER(Arguments))(ComSafeArrayOut(BSTR, aArguments));
|
---|
56 | STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
|
---|
57 | STDMETHOD(COMGETTER(ExecutablePath))(BSTR *aExecutablePath);
|
---|
58 | STDMETHOD(COMGETTER(ExitCode))(LONG *aExitCode);
|
---|
59 | STDMETHOD(COMGETTER(Name))(BSTR *aName);
|
---|
60 | STDMETHOD(COMGETTER(PID))(ULONG *aPID);
|
---|
61 | STDMETHOD(COMGETTER(Status))(ProcessStatus_T *aStatus);
|
---|
62 |
|
---|
63 | STDMETHOD(Read)(ULONG aHandle, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData));
|
---|
64 | STDMETHOD(Terminate)(void);
|
---|
65 | STDMETHOD(WaitFor)(ULONG aWaitFlags, ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
|
---|
66 | STDMETHOD(WaitForArray)(ComSafeArrayIn(ProcessWaitForFlag_T, aFlags), ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
|
---|
67 | STDMETHOD(Write)(ULONG aHandle, ULONG aFlags, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
|
---|
68 | STDMETHOD(WriteArray)(ULONG aHandle, ComSafeArrayIn(ProcessInputFlag_T, aFlags), ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
|
---|
69 | /** @} */
|
---|
70 |
|
---|
71 | public:
|
---|
72 | /** @name Public internal methods.
|
---|
73 | * @{ */
|
---|
74 | int callbackDispatcher(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
|
---|
75 | inline bool callbackExists(uint32_t uContextID);
|
---|
76 | inline int checkPID(uint32_t uPID);
|
---|
77 | Utf8Str errorMsg(void) { return mData.mErrorMsg; }
|
---|
78 | bool isReady(void);
|
---|
79 | ULONG getProcessID(void) { return mData.mProcessID; }
|
---|
80 | int rc(void) { return mData.mRC; }
|
---|
81 | int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead);
|
---|
82 | int startProcess(void);
|
---|
83 | int startProcessAsync(void);
|
---|
84 | int terminateProcess(void);
|
---|
85 | int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestProcessWaitResult &guestResult);
|
---|
86 | int waitForStart(uint32_t uTimeoutMS);
|
---|
87 | int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten);
|
---|
88 | /** @} */
|
---|
89 |
|
---|
90 | protected:
|
---|
91 | /** @name Protected internal methods.
|
---|
92 | * @{ */
|
---|
93 | inline int callbackAdd(GuestCtrlCallback *pCallback, uint32_t *puContextID);
|
---|
94 | inline int callbackRemove(uint32_t uContextID);
|
---|
95 | inline bool isAlive(void);
|
---|
96 | int onGuestDisconnected(GuestCtrlCallback *pCallback, PCALLBACKDATACLIENTDISCONNECTED pData);
|
---|
97 | int onProcessInputStatus(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECINSTATUS pData);
|
---|
98 | int onProcessNotifyIO(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
|
---|
99 | int onProcessStatusChange(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
|
---|
100 | int onProcessOutput(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECOUT pData);
|
---|
101 | int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
|
---|
102 | int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
|
---|
103 | int setErrorInternal(int rc, const Utf8Str &strMessage);
|
---|
104 | HRESULT setErrorExternal(void);
|
---|
105 | int signalWaiters(ProcessWaitResult_T enmWaitResult);
|
---|
106 | static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
|
---|
107 | /** @} */
|
---|
108 |
|
---|
109 | private:
|
---|
110 |
|
---|
111 | struct Data
|
---|
112 | {
|
---|
113 | /** Pointer to parent session. Per definition
|
---|
114 | * this objects *always* lives shorter than the
|
---|
115 | * parent. */
|
---|
116 | GuestSession *mParent;
|
---|
117 | /** Pointer to the console object. Needed
|
---|
118 | * for HGCM (VMMDev) communication. */
|
---|
119 | Console *mConsole;
|
---|
120 | /** All related callbacks to this process. */
|
---|
121 | GuestCtrlCallbacks mCallbacks;
|
---|
122 | /** The process start information. */
|
---|
123 | GuestProcessStartupInfo mProcess;
|
---|
124 | /** Exit code if process has been terminated. */
|
---|
125 | LONG mExitCode;
|
---|
126 | /** PID reported from the guest. */
|
---|
127 | ULONG mPID;
|
---|
128 | /** Internal, host-side process ID. */
|
---|
129 | ULONG mProcessID;
|
---|
130 | /** The current process status. */
|
---|
131 | ProcessStatus_T mStatus;
|
---|
132 | /** The overall rc of the process execution. */
|
---|
133 | int mRC;
|
---|
134 | /** The overall error message of the
|
---|
135 | * process execution. */
|
---|
136 | Utf8Str mErrorMsg;
|
---|
137 | /** The next upcoming context ID. */
|
---|
138 | ULONG mNextContextID;
|
---|
139 | /** The mutex for protecting the waiter(s). */
|
---|
140 | RTSEMMUTEX mWaitMutex;
|
---|
141 | /** How many waiters? At the moment there can only
|
---|
142 | * be one. */
|
---|
143 | uint32_t mWaitCount;
|
---|
144 | /** The actual process event for doing the waits.
|
---|
145 | * At the moment we only support one wait a time. */
|
---|
146 | GuestProcessEvent *mWaitEvent;
|
---|
147 | } mData;
|
---|
148 | };
|
---|
149 |
|
---|
150 | #endif /* !____H_GUESTPROCESSIMPL */
|
---|
151 |
|
---|