VirtualBox

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

Last change on this file since 45049 was 45010, checked in by vboxsync, 12 years ago

GuestCtrl: More code for guest session infrastructure handling (untested, work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1
2/* $Id: GuestProcessImpl.h 45010 2013-03-12 17:47:56Z 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(ExecutablePath))(BSTR *aExecutablePath);
59 STDMETHOD(COMGETTER(ExitCode))(LONG *aExitCode);
60 STDMETHOD(COMGETTER(Name))(BSTR *aName);
61 STDMETHOD(COMGETTER(PID))(ULONG *aPID);
62 STDMETHOD(COMGETTER(Status))(ProcessStatus_T *aStatus);
63
64 STDMETHOD(Read)(ULONG aHandle, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData));
65 STDMETHOD(Terminate)(void);
66 STDMETHOD(WaitFor)(ULONG aWaitFlags, ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
67 STDMETHOD(WaitForArray)(ComSafeArrayIn(ProcessWaitForFlag_T, aFlags), ULONG aTimeoutMS, ProcessWaitResult_T *aReason);
68 STDMETHOD(Write)(ULONG aHandle, ULONG aFlags, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
69 STDMETHOD(WriteArray)(ULONG aHandle, ComSafeArrayIn(ProcessInputFlag_T, aFlags), ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
70 /** @} */
71
72public:
73 /** @name Public internal methods.
74 * @{ */
75 int callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
76 inline int checkPID(uint32_t uPID);
77 static Utf8Str guestErrorToString(int guestRc);
78 bool isReady(void);
79 int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead, int *pGuestRc);
80 static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
81 int startProcess(int *pGuestRc);
82 int startProcessAsync(void);
83 int terminateProcess(int *pGuestRc);
84 int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, ProcessWaitResult_T &waitResult, int *pGuestRc);
85 int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten, int *pGuestRc);
86 /** @} */
87
88protected:
89 /** @name Protected internal methods.
90 * @{ */
91 inline bool isAlive(void);
92 int onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, GuestCtrlCallback *pCallback, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
93 int onProcessInputStatus(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, GuestCtrlCallback *pCallback, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
94 int onProcessNotifyIO(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, GuestCtrlCallback * pCallback, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
95 int onProcessStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, GuestCtrlCallback *pCallback, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
96 int onProcessOutput(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, GuestCtrlCallback *pCallback, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
97 int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
98 int setProcessStatus(ProcessStatus_T procStatus, int procRc);
99 int signalWaiters(ProcessWaitResult_T enmWaitResult, int rc = VINF_SUCCESS);
100 static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
101 /** @} */
102
103private:
104
105 struct Data
106 {
107 /** The process startup information. */
108 GuestProcessStartupInfo mProcess;
109 /** Exit code if process has been terminated. */
110 LONG mExitCode;
111 /** PID reported from the guest. */
112 ULONG mPID;
113 /** The current process status. */
114 ProcessStatus_T mStatus;
115 /** The last returned process status
116 * returned from the guest side. */
117 int mRC;
118 /** How many waiters? At the moment there can only
119 * be one. */
120 uint32_t mWaitCount;
121 /** The actual process event for doing the waits.
122 * At the moment we only support one wait a time. */
123 GuestProcessWaitEvent *mWaitEvent;
124 } mData;
125};
126
127/**
128 * Guest process tool flags.
129 */
130/** No flags specified. */
131#define GUESTPROCESSTOOL_FLAG_NONE 0
132/** Run until next stream block from stdout has been
133 * read in completely, then return.
134 */
135#define GUESTPROCESSTOOL_FLAG_STDOUT_BLOCK RT_BIT(0)
136
137/**
138 * Internal class for handling a VBoxService tool ("vbox_ls", vbox_stat", ...).
139 */
140class GuestProcessTool
141{
142public:
143
144 GuestProcessTool(void);
145
146 virtual ~GuestProcessTool(void);
147
148public:
149
150 int Init(GuestSession *pGuestSession, const GuestProcessStartupInfo &startupInfo, bool fAsync, int *pGuestRc);
151
152 GuestProcessStream &GetStdOut(void) { return mStdOut; }
153
154 GuestProcessStream &GetStdErr(void) { return mStdErr; }
155
156 int Wait(uint32_t fFlags, int *pGuestRc);
157
158 int WaitEx(uint32_t fFlags, GuestProcessStreamBlock *pStreamBlock, int *pGuestRc);
159
160 int GetCurrentBlock(uint32_t uHandle, GuestProcessStreamBlock &strmBlock);
161
162 bool IsRunning(void);
163
164 int TerminatedOk(LONG *pExitCode);
165
166 void Terminate(void);
167
168protected:
169
170 GuestSession *pSession;
171 ComObjPtr<GuestProcess> pProcess;
172 GuestProcessStartupInfo mStartupInfo;
173 GuestProcessStream mStdOut;
174 GuestProcessStream mStdErr;
175};
176
177#endif /* !____H_GUESTPROCESSIMPL */
178
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