VirtualBox

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

Last change on this file since 42538 was 42525, checked in by vboxsync, 12 years ago

Guest Control 2.0: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1
2/* $Id: GuestProcessImpl.h 42525 2012-08-02 10:24:28Z 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 GuestProcessInfo &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 aSize, 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 void close(void);
77 bool isReady(void);
78 ULONG getPID(void) { return mData.mPID; }
79 int readData(uint32_t uHandle, uint32_t uSize, uint32_t uTimeoutMS, void *pvData, size_t cbData, size_t *pcbRead);
80 int startProcess(void);
81 int startProcessAsync(void);
82 int terminateProcess(void);
83 int waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestProcessWaitResult &guestResult);
84 int writeData(uint32_t uHandle, uint32_t uFlags, void *pvData, size_t cbData, uint32_t uTimeoutMS, uint32_t *puWritten);
85 /** @} */
86
87protected:
88 /** @name Protected internal methods.
89 * @{ */
90 inline int callbackAdd(GuestCtrlCallback *pCallback, uint32_t *puContextID);
91 inline int callbackRemove(uint32_t uContextID);
92 inline bool isAlive(void);
93 int onGuestDisconnected(GuestCtrlCallback *pCallback, PCALLBACKDATACLIENTDISCONNECTED pData);
94 int onProcessInputStatus(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECINSTATUS pData);
95 int onProcessNotifyIO(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
96 int onProcessStatusChange(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECSTATUS pData);
97 int onProcessOutput(GuestCtrlCallback *pCallback, PCALLBACKDATAEXECOUT pData);
98 int prepareExecuteEnv(const char *pszEnv, void **ppvList, ULONG *pcbList, ULONG *pcEnvVars);
99 int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
100 int setErrorInternal(int rc, const Utf8Str &strMessage);
101 int setErrorExternal(void);
102 int signalWaiters(ProcessWaitResult_T enmWaitResult);
103 static DECLCALLBACK(int) startProcessThread(RTTHREAD Thread, void *pvUser);
104 HRESULT waitResultToErrorEx(const GuestProcessWaitResult &waitResult, bool fLog);
105 /** @} */
106
107private:
108
109 struct Data
110 {
111 /** Pointer to parent session. */
112 GuestSession *mParent;
113 /** Pointer to the console object. Needed
114 * for HGCM (VMMDev) communication. */
115 Console *mConsole;
116 /** All related callbacks to this process. */
117 GuestCtrlCallbacks mCallbacks;
118 /** The process start information. */
119 GuestProcessInfo mProcess;
120 /** Exit code if process has been terminated. */
121 LONG mExitCode;
122 /** PID reported from the guest. */
123 ULONG mPID;
124 /** Internal, host-side process ID. */
125 ULONG mProcessID;
126 /** The current process status. */
127 ProcessStatus_T mStatus;
128 /** The overall rc of the process execution. */
129 int mRC;
130 /** The overall error message of the
131 * process execution. */
132 Utf8Str mErrorMsg;
133 /** The next upcoming context ID. */
134 ULONG mNextContextID;
135 /** The mutex for protecting the waiter(s). */
136 RTSEMMUTEX mWaitMutex;
137 /** How many waiters? At the moment there can only
138 * be one. */
139 uint32_t mWaitCount;
140 /** The actual process event for doing the waits.
141 * At the moment we only support one wait a time. */
142 GuestProcessEvent *mWaitEvent;
143 } mData;
144};
145
146#endif /* !____H_GUESTPROCESSIMPL */
147
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