VirtualBox

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

Last change on this file since 53517 was 51321, checked in by vboxsync, 11 years ago

Main: Fixed broken documentation due to wrapper changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* $Id: GuestProcessImpl.h 51321 2014-05-21 13:02:44Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest process handling implementation.
4 */
5
6/*
7 * Copyright (C) 2012-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_GUESTPROCESSIMPL
19#define ____H_GUESTPROCESSIMPL
20
21#include "GuestCtrlImplPrivate.h"
22#include "GuestProcessWrap.h"
23
24class Console;
25class GuestSession;
26
27/**
28 * Class for handling a guest process.
29 */
30class ATL_NO_VTABLE GuestProcess :
31 public GuestProcessWrap,
32 public GuestObject
33{
34public:
35 /** @name COM and internal init/term/mapping cruft.
36 * @{ */
37 DECLARE_EMPTY_CTOR_DTOR(GuestProcess)
38
39 int init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo);
40 void uninit(void);
41 HRESULT FinalConstruct(void);
42 void FinalRelease(void);
43 /** @} */
44
45public:
46 /** @name Public internal methods.
47 * @{ */
48 int i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
49 inline int i_checkPID(uint32_t uPID);
50 static Utf8Str i_guestErrorToString(int guestRc);
51 int i_onRemove(void);
52 int i_readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData,
53 size_t cbData, uint32_t *pcbRead, int *pGuestRc);
54 static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
55 int i_startProcess(uint32_t uTimeoutMS, int *pGuestRc);
56 int i_startProcessAsync(void);
57 int i_terminateProcess(uint32_t uTimeoutMS, int *pGuestRc);
58 static ProcessWaitResult_T i_waitFlagsToResultEx(uint32_t fWaitFlags, ProcessStatus_T oldStatus,
59 ProcessStatus_T newStatus, uint32_t uProcFlags,
60 uint32_t uProtocol);
61 ProcessWaitResult_T i_waitFlagsToResult(uint32_t fWaitFlags);
62 int i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
63 int i_waitForInputNotify(GuestWaitEvent *pEvent, uint32_t uHandle, uint32_t uTimeoutMS,
64 ProcessInputStatus_T *pInputStatus, uint32_t *pcbProcessed);
65 int i_waitForOutput(GuestWaitEvent *pEvent, uint32_t uHandle, uint32_t uTimeoutMS,
66 void* pvData, size_t cbData, uint32_t *pcbRead);
67 int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS,
68 ProcessStatus_T *pProcessStatus, int *pGuestRc);
69 static bool i_waitResultImpliesEx(ProcessWaitResult_T waitResult, ProcessStatus_T procStatus,
70 uint32_t uProcFlags, uint32_t uProtocol);
71 int i_writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData,
72 uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
73 /** @} */
74
75protected:
76 /** @name Protected internal methods.
77 * @{ */
78 inline bool i_isAlive(void);
79 inline bool i_hasEnded(void);
80 int i_onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
81 int i_onProcessInputStatus(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
82 int i_onProcessNotifyIO(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
83 int i_onProcessStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
84 int i_onProcessOutput(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
85 int i_prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
86 int i_setProcessStatus(ProcessStatus_T procStatus, int procRc);
87 static DECLCALLBACK(int) i_startProcessThread(RTTHREAD Thread, void *pvUser);
88 /** @} */
89
90private:
91 /** Wrapped @name IProcess properties.
92 * @{ */
93 HRESULT getArguments(std::vector<com::Utf8Str> &aArguments);
94 HRESULT getEnvironment(std::vector<com::Utf8Str> &aEnvironment);
95 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
96 HRESULT getExecutablePath(com::Utf8Str &aExecutablePath);
97 HRESULT getExitCode(LONG *aExitCode);
98 HRESULT getName(com::Utf8Str &aName);
99 HRESULT getPID(ULONG *aPID);
100 HRESULT getStatus(ProcessStatus_T *aStatus);
101 /** @} */
102
103 /** Wrapped @name IProcess methods.
104 * @{ */
105 HRESULT waitFor(ULONG aWaitFor,
106 ULONG aTimeoutMS,
107 ProcessWaitResult_T *aReason);
108 HRESULT waitForArray(const std::vector<ProcessWaitForFlag_T> &aWaitFor,
109 ULONG aTimeoutMS,
110 ProcessWaitResult_T *aReason);
111 HRESULT read(ULONG aHandle,
112 ULONG aToRead,
113 ULONG aTimeoutMS,
114 std::vector<BYTE> &aData);
115 HRESULT write(ULONG aHandle,
116 ULONG aFlags,
117 const std::vector<BYTE> &aData,
118 ULONG aTimeoutMS,
119 ULONG *aWritten);
120 HRESULT writeArray(ULONG aHandle,
121 const std::vector<ProcessInputFlag_T> &aFlags,
122 const std::vector<BYTE> &aData,
123 ULONG aTimeoutMS,
124 ULONG *aWritten);
125 HRESULT terminate(void);
126 /** @} */
127
128 /**
129 * This can safely be used without holding any locks.
130 * An AutoCaller suffices to prevent it being destroy while in use and
131 * internally there is a lock providing the necessary serialization.
132 */
133 const ComObjPtr<EventSource> mEventSource;
134
135 struct Data
136 {
137 /** The process startup information. */
138 GuestProcessStartupInfo mProcess;
139 /** Exit code if process has been terminated. */
140 LONG mExitCode;
141 /** PID reported from the guest. */
142 ULONG mPID;
143 /** The current process status. */
144 ProcessStatus_T mStatus;
145 /** The last returned process status
146 * returned from the guest side. */
147 int mLastError;
148 } mData;
149};
150
151/**
152 * Guest process tool flags.
153 */
154/** No flags specified; wait until process terminates.
155 * The maximum waiting time is set in the process' startup
156 * info. */
157#define GUESTPROCESSTOOL_FLAG_NONE 0
158/** Wait until next stream block from stdout has been
159 * read in completely, then return.
160 */
161#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK RT_BIT(0)
162
163/**
164 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
165 */
166class GuestProcessTool
167{
168public:
169
170 GuestProcessTool(void);
171
172 virtual ~GuestProcessTool(void);
173
174public:
175
176 int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
177
178 GuestProcessStream &i_getStdOut(void) { return mStdOut; }
179
180 GuestProcessStream &i_getStdErr(void) { return mStdErr; }
181
182 int i_wait(uint32_t fFlags, int *pGuestRc);
183
184 int i_waitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
185
186 int i_getCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
187
188 bool i_isRunning(void);
189
190 static int i_run(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, int *pGuestRc);
191
192 static int i_runEx(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo,
193 GuestCtrlStreamObjects *pStrmOutObjects, uint32_t cStrmOutObjects, int *pGuestRc);
194
195 int i_terminatedOk(LONG *pExitCode);
196
197 int i_terminate(uint32_t uTimeoutMS, int *pGuestRc);
198
199protected:
200
201 ComObjPtr<GuestSession> pSession;
202 ComObjPtr<GuestProcess> pProcess;
203 GuestProcessStartupInfo mStartupInfo;
204 GuestProcessStream mStdOut;
205 GuestProcessStream mStdErr;
206};
207
208#endif /* !____H_GUESTPROCESSIMPL */
209
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