VirtualBox

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

Last change on this file since 47148 was 45780, checked in by vboxsync, 12 years ago

Main/GuestCtrl: Use active listeners instead of passive ones because of performance reasons (untested).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1
2/* $Id: GuestProcessImpl.h 45780 2013-04-26 15:19:33Z 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 waitForInputNotify(GuestWaitEvent *pEvent, uint32_t uHandle, uint32_t uTimeoutMS, ProcessInputStatus_T *pInputStatus, uint32_t *pcbProcessed);
87 int waitForOutput(GuestWaitEvent *pEvent, uint32_t uHandle, uint32_t uTimeoutMS, void* pvData, size_t cbData, uint32_t *pcbRead);
88 int waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS, ProcessStatus_T *pProcessStatus, int *pGuestRc);
89 int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
90 /** @} */
91
92protected:
93 /** @name Protected internal methods.
94 * @{ */
95 inline bool isAlive(void);
96 int onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
97 int onProcessInputStatus(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
98 int onProcessNotifyIO(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
99 int onProcessStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
100 int onProcessOutput(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
101 int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
102 int setProcessStatus(ProcessStatus_T procStatus, int procRc);
103 static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
104 /** @} */
105
106private:
107
108 /**
109 * This can safely be used without holding any locks.
110 * An AutoCaller suffices to prevent it being destroy while in use and
111 * internally there is a lock providing the necessary serialization.
112 */
113 const ComObjPtr<EventSource> mEventSource;
114
115 struct Data
116 {
117 /** The process startup information. */
118 GuestProcessStartupInfo mProcess;
119 /** Exit code if process has been terminated. */
120 LONG mExitCode;
121 /** PID reported from the guest. */
122 ULONG mPID;
123 /** The current process status. */
124 ProcessStatus_T mStatus;
125 /** The last returned process status
126 * returned from the guest side. */
127 int mRC;
128 } mData;
129};
130
131/**
132 * Guest process tool flags.
133 */
134/** No flags specified. */
135#define GUESTPROCESSTOOL_FLAG_NONE 0
136/** Run until next stream block from stdout has been
137 * read in completely, then return.
138 */
139#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK RT_BIT(0)
140
141/**
142 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
143 */
144class GuestProcessTool
145{
146public:
147
148 GuestProcessTool(void);
149
150 virtual ~GuestProcessTool(void);
151
152public:
153
154 int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
155
156 GuestProcessStream &GetStdOut(void) { return mStdOut; }
157
158 GuestProcessStream &GetStdErr(void) { return mStdErr; }
159
160 int Wait(uint32_t fFlags, int *pGuestRc);
161
162 int WaitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
163
164 int GetCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
165
166 bool IsRunning(void);
167
168 int TerminatedOk(LONG *pExitCode);
169
170 void Terminate(void);
171
172protected:
173
174 GuestSession *pSession;
175 ComObjPtr<GuestProcess> pProcess;
176 GuestProcessStartupInfo mStartupInfo;
177 GuestProcessStream mStdOut;
178 GuestProcessStream mStdErr;
179};
180
181#endif /* !____H_GUESTPROCESSIMPL */
182
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