VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestProcessImpl.h@ 43870

Last change on this file since 43870 was 43162, checked in by vboxsync, 12 years ago

Main/Guest Control 2.0: Cleanup, separated guest error handling.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1
2/* $Id: GuestProcessImpl.h 43162 2012-09-04 13:53:59Z 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
25class Console;
26class GuestSession;
27
28/**
29 * TODO
30 */
31class ATL_NO_VTABLE GuestProcess :
32 public VirtualBoxBase,
33 VBOX_SCRIPTABLE_IMPL(IGuestProcess)
34{
35public:
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
71public:
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 static Utf8Str guestErrorToString(int guestRc);
78 bool isReady(void);
79 ULONG getProcessID(void) { return mData.mProcessID; }
80 int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead, int *pGuestRc);
81 static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
82 int startProcess(int *pGuestRc);
83 int startProcessAsync(void);
84 int terminateProcess(void);
85 int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
86 int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
87 /** @} */
88
89protected:
90 /** @name Protected internal methods.
91 * @{ */
92 inline int callbackAdd(GuestCtrlCallback *pCallback, uint32_t *puContextID);
93 inline int callbackRemove(uint32_t uContextID);
94 inline bool isAlive(void);
95 int onGuestDisconnected(GuestCtrlCallback *pCallback, PCALLBACKDATACLIENTDISCONNECTED pData);
96 int onProcessInputStatus(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECINSTATUS pData);
97 int onProcessNotifyIO(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
98 int onProcessStatusChange(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
99 int onProcessOutput(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECOUT pData);
100 int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
101 int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
102 int setProcessStatus(ProcessStatus_T procStatus, int procRc);
103 int signalWaiters(ProcessWaitResult_T enmWaitResult, int rc = VINF_SUCCESS);
104 static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
105 /** @} */
106
107private:
108
109 struct Data
110 {
111 /** Pointer to parent session. Per definition
112 * this objects *always* lives shorter than the
113 * parent. */
114 GuestSession *mParent;
115 /** Pointer to the console object. Needed
116 * for HGCM (VMMDev) communication. */
117 Console *mConsole;
118 /** All related callbacks to this process. */
119 GuestCtrlCallbacks mCallbacks;
120 /** The process start information. */
121 GuestProcessStartupInfo mProcess;
122 /** Exit code if process has been terminated. */
123 LONG mExitCode;
124 /** PID reported from the guest. */
125 ULONG mPID;
126 /** Internal, host-side process ID. */
127 ULONG mProcessID;
128 /** The current process status. */
129 ProcessStatus_T mStatus;
130 int mRC;
131 /** The next upcoming context ID. */
132 ULONG mNextContextID;
133 /** The mutex for protecting the waiter(s). */
134 RTSEMMUTEX mWaitMutex;
135 /** How many waiters? At the moment there can only
136 * be one. */
137 uint32_t mWaitCount;
138 /** The actual process event for doing the waits.
139 * At the moment we only support one wait a time. */
140 GuestProcessWaitEvent *mWaitEvent;
141 } mData;
142};
143
144/**
145 * Guest process tool flags.
146 */
147/** No flags specified. */
148#define GUESTPROCESSTOOL_FLAG_NONE 0
149/** Run until next stream block from stdout has been
150 * read in completely, then return.
151 */
152#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK RT_BIT(0)
153
154/**
155 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
156 */
157class GuestProcessTool
158{
159public:
160
161 GuestProcessTool(void);
162
163 virtual ~GuestProcessTool(void);
164
165public:
166
167 int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
168
169 GuestProcessStream &GetStdOut(void) { return mStdOut; }
170
171 GuestProcessStream &GetStdErr(void) { return mStdErr; }
172
173 int Wait(uint32_t fFlags, int *pGuestRc);
174
175 int WaitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
176
177 int GetCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
178
179 bool IsRunning(void);
180
181 int TerminatedOk(LONG *pExitCode);
182
183 void Terminate(void);
184
185protected:
186
187 GuestSession *pSession;
188 ComObjPtr<GuestProcess> pProcess;
189 GuestProcessStartupInfo mStartupInfo;
190 GuestProcessStream mStdOut;
191 GuestProcessStream mStdErr;
192};
193
194#endif /* !____H_GUESTPROCESSIMPL */
195
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette