GuestCtrlImplPrivate.h revision 35e6d303696e46d969aaf9a59cc381333a483b0b
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/** @file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Internal helpers/structures for guest control functionality.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (C) 2011-2012 Oracle Corporation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifndef ____H_GUESTIMPLPRIVATE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define ____H_GUESTIMPLPRIVATE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <iprt/asm.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <iprt/semaphore.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <VBox/com/com.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <VBox/com/ErrorInfo.h>
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington#include <VBox/com/string.h>
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington#include <VBox/com/VirtualBox.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <map>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <vector>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterusing namespace com;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef VBOX_WITH_GUEST_CONTROL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster# include <VBox/HostServices/GuestControlSvc.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterusing namespace guestControl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef LOG_GROUP
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster #undef LOG_GROUP
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include <VBox/log.h>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum number of guest sessions a VM can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_MAX_SESSIONS 255
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum of guest processes a guest session can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_MAX_PROCESSES 255
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Maximum of callback contexts a guest process can have. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_MAX_CONTEXTS _64K - 1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
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 ( (uint32_t)((uSession) & 0xff) << 24 \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster | (uint32_t)((uProcess) & 0xff) << 16 \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster | (uint32_t)((uCount) & 0xffff) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster )
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Gets the session ID out of a context ID. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((uContextID) >> 24)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Gets the process ID out of a context ID. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID) \
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (((uContextID) >> 16) & 0xff)
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 ((uContextID) & 0xffff)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Vector holding a process' CPU affinity. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector <LONG> ProcessAffinity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Vector holding process startup arguments. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector <Utf8Str> ProcessArguments;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Generic class for a all guest control callbacks/events.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestCtrlEvent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestCtrlEvent(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestCtrlEvent(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** @todo Copy/comparison operator? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Cancel(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bool Canceled(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual void Destroy(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Init(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual int Signal(int rc = VINF_SUCCESS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int GetResultCode(void) { return mRC; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Wait(ULONG uTimeoutMS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Was the callback canceled? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bool fCanceled;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Did the callback complete? */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bool fCompleted;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The event semaphore for triggering
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the actual event. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RTSEMEVENT hEventSem;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The waiting mutex. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster RTSEMMUTEX hEventMutex;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Overall result code. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int mRC;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing a guest control callback.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestCtrlCallback : public GuestCtrlEvent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestCtrlCallback(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestCtrlCallback(eVBoxGuestCtrlCallbackType enmType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestCtrlCallback(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Destroy(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Init(eVBoxGuestCtrlCallbackType enmType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster eVBoxGuestCtrlCallbackType GetCallbackType(void) { return mType; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const void* GetDataRaw(void) const { return pvData; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t GetDataSize(void) { return cbData; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const void* GetPayloadRaw(void) const { return pvPayload; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t GetPayloadSize(void) { return cbPayload; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetData(const void *pvCallback, size_t cbCallback);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetPayload(const void *pvToWrite, size_t cbToWrite);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Pointer to actual callback data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void *pvData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Size of user-supplied data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t cbData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The callback type. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster eVBoxGuestCtrlCallbackType mType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Callback flags. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t uFlags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Payload which will be available on successful
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * waiting (optional). */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void *pvPayload;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Size of the payload (optional). */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t cbPayload;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::map < uint32_t, GuestCtrlCallback* > GuestCtrlCallbacks;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstruct GuestProcessWaitResult
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The wait result when returning from the wait call. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ProcessWaitResult_T mResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int mRC;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing a guest control process event.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestProcessEvent : public GuestCtrlEvent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessEvent(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessEvent(uint32_t uWaitFlags);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestProcessEvent(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Destroy(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Init(uint32_t uWaitFlags);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t GetWaitFlags(void) { return ASMAtomicReadU32(&mWaitFlags); }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessWaitResult GetResult(void) { return mWaitResult; }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Signal(ProcessWaitResult_T enmResult, int rc = VINF_SUCCESS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The waiting flag(s). The specifies what to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * wait for. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t mWaitFlags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Structure containing the overall result. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessWaitResult mWaitResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Simple structure mantaining guest credentials.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstruct GuestCredentials
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mUser;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mPassword;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mDomain;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fostertypedef std::vector <Utf8Str> GuestEnvironmentArray;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestEnvironment
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int BuildEnvironmentBlock(void **ppvEnv, size_t *pcbEnv, uint32_t *pcEnvVars);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Clear(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int CopyFrom(const GuestEnvironmentArray &environment);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int CopyTo(GuestEnvironmentArray &environment);
a14393818a78c503f7715c393044b33c86e90195Phill Cunnington
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington static void FreeEnvironmentBlock(void *pvEnv);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str Get(const Utf8Str &strKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str Get(size_t nPos);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bool Has(const Utf8Str &strKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Set(const Utf8Str &strKey, const Utf8Str &strValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Set(const Utf8Str &strPair);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t Size(void);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int Unset(const Utf8Str &strKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestEnvironment& operator=(const GuestEnvironmentArray &that);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestEnvironment& operator=(const GuestEnvironment &that);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int appendToEnvBlock(const char *pszEnv, void **ppvList, size_t *pcbList, uint32_t *pcEnvVars);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster std::map <Utf8Str, Utf8Str> mEnvironment;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Structure for keeping all the relevant process
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * starting parameters around.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstruct GuestProcessInfo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The process' friendly name. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** The actual command to execute. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mCommand;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ProcessArguments mArguments;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestEnvironment mEnvironment;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t mFlags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ULONG mTimeoutMS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ProcessPriority_T mPriority;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ProcessAffinity mAffinity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Class representing the "value" side of a "key=value" pair.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestProcessStreamValue
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStreamValue() { }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStreamValue(const char *pszValue)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster : mValue(pszValue) {}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStreamValue(const GuestProcessStreamValue& aThat)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster : mValue(aThat.mValue) {}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str mValue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
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
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestProcessStreamBlock
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStreamBlock();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //GuestProcessStreamBlock(GuestProcessStreamBlock &);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestProcessStreamBlock();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Clear();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef DEBUG
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Dump();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int GetInt64Ex(const char *pszKey, int64_t *piVal);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int64_t GetInt64(const char *pszKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size_t GetCount();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const char* GetString(const char *pszKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t GetUInt32(const char *pszKey);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int SetValue(const char *pszKey, const char *pszValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestCtrlStreamPairMap m_mapPairs;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
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
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestProcessStream
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestProcessStream();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestProcessStream();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int AddData(const BYTE *pbData, size_t cbData);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Destroy();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef DEBUG
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster void Dump(const char *pszFile);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t GetOffset();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t GetSize();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int ParseBlock(GuestProcessStreamBlock &streamBlock);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterprotected:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Currently allocated size of internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t m_cbAllocated;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Currently used size of allocated internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t m_cbSize;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Current offset within the internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uint32_t m_cbOffset;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Internal stream buffer. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BYTE *m_pbBuffer;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass Guest;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass Progress;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass GuestTask
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster enum TaskType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Copies a file from host to the guest. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster TaskType_CopyFileToGuest = 50,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** Copies a file from guest to the host. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster TaskType_CopyFileFromGuest = 55,
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 TaskType_UpdateGuestAdditions = 100
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster virtual ~GuestTask();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int startThread();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
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 static HRESULT setProgressErrorMsg(HRESULT hr,
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
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster TaskType taskType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ComObjPtr<Guest> pGuest;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ComObjPtr<Progress> pProgress;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HRESULT rc;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Task data. */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str strSource;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str strDest;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str strUserName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utf8Str strPassword;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ULONG uFlags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif // ____H_GUESTIMPLPRIVATE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster