GuestCtrlImplPrivate.h revision 35e6d303696e46d969aaf9a59cc381333a483b0b
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Internal helpers/structures for guest control functionality.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (C) 2011-2012 Oracle Corporation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This file is part of VirtualBox Open Source Edition (OSE), as
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * available from http://www.virtualbox.org. This file is free software;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * you can redistribute it and/or modify it under the terms of the GNU
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * General Public License (GPL) as published by the Free Software
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Foundation, in version 2 as it comes in the "COPYING" file of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum number of guest sessions a VM can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum of guest processes a guest session can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum of callback contexts a guest process can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Builds a context ID out of the session ID, process ID and an
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * increasing count. */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington#define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uProcess, uCount) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Gets the session ID out of a context ID. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Gets the process ID out of a context ID. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Gets the conext count of a process out of a context ID. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Vector holding a process' CPU affinity. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Vector holding process startup arguments. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Generic class for a all guest control callbacks/events.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** @todo Copy/comparison operator? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Was the callback canceled? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Did the callback complete? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The event semaphore for triggering
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the actual event. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The waiting mutex. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Overall result code. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing a guest control callback.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestCtrlCallback(eVBoxGuestCtrlCallbackType enmType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster eVBoxGuestCtrlCallbackType GetCallbackType(void) { return mType; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const void* GetDataRaw(void) const { return pvData; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const void* GetPayloadRaw(void) const { return pvPayload; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t GetPayloadSize(void) { return cbPayload; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetData(const void *pvCallback, size_t cbCallback);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetPayload(const void *pvToWrite, size_t cbToWrite);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Pointer to actual callback data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Size of user-supplied data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The callback type. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Callback flags. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Payload which will be available on successful
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * waiting (optional). */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Size of the payload (optional). */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::map < uint32_t, GuestCtrlCallback* > GuestCtrlCallbacks;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The wait result when returning from the wait call. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing a guest control process event.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t GetWaitFlags(void) { return ASMAtomicReadU32(&mWaitFlags); }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessWaitResult GetResult(void) { return mWaitResult; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Signal(ProcessWaitResult_T enmResult, int rc = VINF_SUCCESS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The waiting flag(s). The specifies what to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * wait for. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Structure containing the overall result. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Simple structure mantaining guest credentials.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector <Utf8Str> GuestEnvironmentArray;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int BuildEnvironmentBlock(void **ppvEnv, size_t *pcbEnv, uint32_t *pcEnvVars);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int CopyFrom(const GuestEnvironmentArray &environment);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int CopyTo(GuestEnvironmentArray &environment);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington static void FreeEnvironmentBlock(void *pvEnv);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Set(const Utf8Str &strKey, const Utf8Str &strValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestEnvironment& operator=(const GuestEnvironmentArray &that);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestEnvironment& operator=(const GuestEnvironment &that);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int appendToEnvBlock(const char *pszEnv, void **ppvList, size_t *pcbList, uint32_t *pcEnvVars);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Structure for keeping all the relevant process
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * starting parameters around.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The process' friendly name. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The actual command to execute. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing the "value" side of a "key=value" pair.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStreamValue(const GuestProcessStreamValue& aThat)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Map containing "key=value" pairs of a guest process stream. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::pair< Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPair;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::map < Utf8Str, GuestProcessStreamValue > GuestCtrlStreamPairMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::map < Utf8Str, GuestProcessStreamValue >::iterator GuestCtrlStreamPairMapIter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::map < Utf8Str, GuestProcessStreamValue >::const_iterator GuestCtrlStreamPairMapIterConst;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing a block of stream pairs (key=value). Each block in a raw guest
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * output stream is separated by "\0\0", each pair is separated by "\0". The overall
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * end of a guest stream is marked by "\0\0\0\0".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //GuestProcessStreamBlock(GuestProcessStreamBlock &);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int GetInt64Ex(const char *pszKey, int64_t *piVal);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetValue(const char *pszKey, const char *pszValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Vector containing multiple allocated stream pair objects. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector< GuestProcessStreamBlock > GuestCtrlStreamObjects;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector< GuestProcessStreamBlock >::iterator GuestCtrlStreamObjectsIter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector< GuestProcessStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class for parsing machine-readable guest process output by VBoxService'
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int AddData(const BYTE *pbData, size_t cbData);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int ParseBlock(GuestProcessStreamBlock &streamBlock);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Currently allocated size of internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Currently used size of allocated internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Current offset within the internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Copies a file from host to the guest. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Copies a file from guest to the host. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Update Guest Additions by directly copying the required installer
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * off the .ISO file, transfer it to the guest and execute the installer
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with system privileges. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static int taskThread(RTTHREAD aThread, void *pvUser);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static int uploadProgress(unsigned uPercent, void *pvUser);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static HRESULT setProgressSuccess(ComObjPtr<Progress> pProgress);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ComObjPtr<Progress> pProgress, const char * pszText, ...);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static HRESULT setProgressErrorParent(HRESULT hr,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Task data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif // ____H_GUESTIMPLPRIVATE