VirtualBox

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

Last change on this file since 45540 was 45482, checked in by vboxsync, 12 years ago

GuestCtrl: Added abstract IGuestProcessIOEvent event, removed duplicate code, making the testdriver execution tests pass.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1
2/* $Id: GuestProcessImpl.h 45482 2013-04-11 11:11:42Z vboxsync $ */
3/** @file
4 * VirtualBox Main - Guest process handling.
5 */
6
7/*
8 * Copyright (C) 2012-2013 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 * Class for handling a guest process.
30 */
31class ATL_NO_VTABLE GuestProcess :
32 public VirtualBoxBase,
33 public GuestObject,
34 VBOX_SCRIPTABLE_IMPL(IGuestProcess)
35{
36public:
37 /** @name COM and internal init/term/mapping cruft.
38 * @{ */
39 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestProcess, IGuestProcess)
40 DECLARE_NOT_AGGREGATABLE(GuestProcess)
41 DECLARE_PROTECT_FINAL_CONSTRUCT()
42 BEGIN_COM_MAP(GuestProcess)
43 VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestProcess)
44 COM_INTERFACE_ENTRY(IProcess)
45 END_COM_MAP()
46 DECLARE_EMPTY_CTOR_DTOR(GuestProcess)
47
48 int init(Console *aConsole, GuestSession *aSession, ULONG aProcessID, const GuestProcessStartupInfo &aProcInfo);
49 void uninit(void);
50 HRESULT FinalConstruct(void);
51 void FinalRelease(void);
52 /** @} */
53
54 /** @name IProcess interface.
55 * @{ */
56 STDMETHOD(COMGETTER(Arguments))(ComSafeArrayOut(BSTR, aArguments));
57 STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
58 STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
59 STDMETHOD(COMGETTER(ExecutablePath))(BSTR *aExecutablePath);
60 STDMETHOD(COMGETTER(ExitCode))(LONG *aExitCode);
61 STDMETHOD(COMGETTER(Name))(BSTR *aName);
62 STDMETHOD(COMGETTER(PID))(ULONG *aPID);
63 STDMETHOD(COMGETTER(Status))(ProcessStatus_T *aStatus);
64
65 STDMETHOD(Read)(ULONG aHandle, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData));
66 STDMETHOD(Terminate)(void);
67 STDMETHOD(WaitFor)(ULONG aWaitFlags, ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
68 STDMETHOD(WaitForArray)(ComSafeArrayIn(ProcessWaitForFlag_T, aFlags), ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
69 STDMETHOD(Write)(ULONG aHandle, ULONG aFlags, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
70 STDMETHOD(WriteArray)(ULONG aHandle, ComSafeArrayIn(ProcessInputFlag_T, aFlags), ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
71 /** @} */
72
73public:
74 /** @name Public internal methods.
75 * @{ */
76 int callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
77 inline int checkPID(uint32_t uPID);
78 static Utf8Str guestErrorToString(int guestRc);
79 bool isReady(void);
80 int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead, int *pGuestRc);
81 static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
82 int startProcess(int *pGuestRc);
83 int startProcessAsync(void);
84 int terminateProcess(int *pGuestRc);
85 int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
86 int waitForEvents(uint32_t uTimeoutMS, ComSafeArrayIn(VBoxEventType_T, pEvents), VBoxEventType_T *pType, IEvent **ppEvent);
87 int waitForInputNotify(uint32_t uHandle, uint32_t uTimeoutMS, ProcessInputStatus_T *pInputStatus, uint32_t *pcbProcessed);
88 int waitForOutput(uint32_t uHandle, uint32_t uTimeoutMS, void* pvData, size_t cbData, uint32_t *pcbRead);
89 int waitForStatusChange(uint32_t fWaitFlags, uint32_t uTimeoutMS, ProcessStatus_T *pProcessStatus, int *pGuestRc);
90 int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
91 /** @} */
92
93protected:
94 /** @name Protected internal methods.
95 * @{ */
96 inline bool isAlive(void);
97 int onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
98 int onProcessInputStatus(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
99 int onProcessNotifyIO(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
100 int onProcessStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
101 int onProcessOutput(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
102 int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
103 int setProcessStatus(ProcessStatus_T procStatus, int procRc);
104 static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
105 /** @} */
106
107private:
108
109 /**
110 * This can safely be used without holding any locks.
111 * An AutoCaller suffices to prevent it being destroy while in use and
112 * internally there is a lock providing the necessary serialization.
113 */
114 const ComObjPtr<EventSource> mEventSource;
115
116 struct Data
117 {
118 /** The process startup information. */
119 GuestProcessStartupInfo mProcess;
120 /** Exit code if process has been terminated. */
121 LONG mExitCode;
122 /** PID reported from the guest. */
123 ULONG mPID;
124 /** The current process status. */
125 ProcessStatus_T mStatus;
126 /** The last returned process status
127 * returned from the guest side. */
128 int mRC;
129 } mData;
130};
131
132/**
133 * Guest process tool flags.
134 */
135/** No flags specified. */
136#define GUESTPROCESSTOOL_FLAG_NONE 0
137/** Run until next stream block from stdout has been
138 * read in completely, then return.
139 */
140#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK RT_BIT(0)
141
142/**
143 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
144 */
145class GuestProcessTool
146{
147public:
148
149 GuestProcessTool(void);
150
151 virtual ~GuestProcessTool(void);
152
153public:
154
155 int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
156
157 GuestProcessStream &GetStdOut(void) { return mStdOut; }
158
159 GuestProcessStream &GetStdErr(void) { return mStdErr; }
160
161 int Wait(uint32_t fFlags, int *pGuestRc);
162
163 int WaitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
164
165 int GetCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
166
167 bool IsRunning(void);
168
169 int TerminatedOk(LONG *pExitCode);
170
171 void Terminate(void);
172
173protected:
174
175 GuestSession *pSession;
176 ComObjPtr<GuestProcess> pProcess;
177 GuestProcessStartupInfo mStartupInfo;
178 GuestProcessStream mStdOut;
179 GuestProcessStream mStdErr;
180};
181
182#endif /* !____H_GUESTPROCESSIMPL */
183
Note: See TracBrowser for help on using the repository browser.

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