1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Guest Control - Private data definitions / classes.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_GUESTIMPLPRIVATE
|
---|
19 | #define ____H_GUESTIMPLPRIVATE
|
---|
20 |
|
---|
21 | #include <VBox/com/com.h>
|
---|
22 | #include <VBox/com/string.h>
|
---|
23 | #include <VBox/com/VirtualBox.h>
|
---|
24 |
|
---|
25 | #include <map>
|
---|
26 | #include <vector>
|
---|
27 |
|
---|
28 | using namespace com;
|
---|
29 |
|
---|
30 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
31 | # include <VBox/HostServices/GuestControlSvc.h>
|
---|
32 | using namespace guestControl;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | class Guest;
|
---|
36 | class Progress;
|
---|
37 |
|
---|
38 | /** Structure representing the "value" side of a "key=value" pair. */
|
---|
39 | class VBOXGUESTCTRL_STREAMVALUE
|
---|
40 | {
|
---|
41 | public:
|
---|
42 |
|
---|
43 | VBOXGUESTCTRL_STREAMVALUE() { }
|
---|
44 | VBOXGUESTCTRL_STREAMVALUE(const char *pszValue)
|
---|
45 | : mValue(pszValue) {}
|
---|
46 |
|
---|
47 | VBOXGUESTCTRL_STREAMVALUE(const VBOXGUESTCTRL_STREAMVALUE& aThat)
|
---|
48 | : mValue(aThat.mValue) {}
|
---|
49 |
|
---|
50 | Utf8Str mValue;
|
---|
51 | };
|
---|
52 |
|
---|
53 | /** Map containing "key=value" pairs of a guest process stream. */
|
---|
54 | typedef std::pair< Utf8Str, VBOXGUESTCTRL_STREAMVALUE > GuestCtrlStreamPair;
|
---|
55 | typedef std::map < Utf8Str, VBOXGUESTCTRL_STREAMVALUE > GuestCtrlStreamPairMap;
|
---|
56 | typedef std::map < Utf8Str, VBOXGUESTCTRL_STREAMVALUE >::iterator GuestCtrlStreamPairMapIter;
|
---|
57 | typedef std::map < Utf8Str, VBOXGUESTCTRL_STREAMVALUE >::const_iterator GuestCtrlStreamPairMapIterConst;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Class representing a block of stream pairs (key=value). Each block in a raw guest
|
---|
61 | * output stream is separated by "\0\0", each pair is separated by "\0". The overall
|
---|
62 | * end of a guest stream is marked by "\0\0\0\0".
|
---|
63 | */
|
---|
64 | class GuestProcessStreamBlock
|
---|
65 | {
|
---|
66 | public:
|
---|
67 |
|
---|
68 | GuestProcessStreamBlock();
|
---|
69 |
|
---|
70 | //GuestProcessStreamBlock(GuestProcessStreamBlock &);
|
---|
71 |
|
---|
72 | virtual ~GuestProcessStreamBlock();
|
---|
73 |
|
---|
74 | public:
|
---|
75 |
|
---|
76 | void Clear();
|
---|
77 |
|
---|
78 | int GetInt64Ex(const char *pszKey, int64_t *piVal);
|
---|
79 |
|
---|
80 | int64_t GetInt64(const char *pszKey);
|
---|
81 |
|
---|
82 | size_t GetCount();
|
---|
83 |
|
---|
84 | const char* GetString(const char *pszKey);
|
---|
85 |
|
---|
86 | int GetUInt32Ex(const char *pszKey, uint32_t *puVal);
|
---|
87 |
|
---|
88 | uint32_t GetUInt32(const char *pszKey);
|
---|
89 |
|
---|
90 | int SetValue(const char *pszKey, const char *pszValue);
|
---|
91 |
|
---|
92 | protected:
|
---|
93 |
|
---|
94 | GuestCtrlStreamPairMap m_mapPairs;
|
---|
95 | };
|
---|
96 |
|
---|
97 | /** Vector containing multiple allocated stream pair objects. */
|
---|
98 | typedef std::vector< GuestProcessStreamBlock > GuestCtrlStreamObjects;
|
---|
99 | typedef std::vector< GuestProcessStreamBlock >::iterator GuestCtrlStreamObjectsIter;
|
---|
100 | typedef std::vector< GuestProcessStreamBlock >::const_iterator GuestCtrlStreamObjectsIterConst;
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Class for parsing machine-readable guest process output by VBoxService'
|
---|
104 | * toolbox commands ("vbox_ls", "vbox_stat" etc), aka "guest stream".
|
---|
105 | */
|
---|
106 | class GuestProcessStream
|
---|
107 | {
|
---|
108 |
|
---|
109 | public:
|
---|
110 |
|
---|
111 | GuestProcessStream();
|
---|
112 |
|
---|
113 | virtual ~GuestProcessStream();
|
---|
114 |
|
---|
115 | public:
|
---|
116 |
|
---|
117 | int AddData(const BYTE *pbData, size_t cbData);
|
---|
118 |
|
---|
119 | void Destroy();
|
---|
120 |
|
---|
121 | uint32_t GetOffset();
|
---|
122 |
|
---|
123 | uint32_t GetSize();
|
---|
124 |
|
---|
125 | int ParseBlock(GuestProcessStreamBlock &streamBlock);
|
---|
126 |
|
---|
127 | protected:
|
---|
128 |
|
---|
129 | /** Currently allocated size of internal stream buffer. */
|
---|
130 | uint32_t m_cbAllocated;
|
---|
131 | /** Currently used size of allocated internal stream buffer. */
|
---|
132 | uint32_t m_cbSize;
|
---|
133 | /** Current offset within the internal stream buffer. */
|
---|
134 | uint32_t m_cbOffset;
|
---|
135 | /** Internal stream buffer. */
|
---|
136 | BYTE *m_pbBuffer;
|
---|
137 | };
|
---|
138 |
|
---|
139 | class GuestTask
|
---|
140 | {
|
---|
141 |
|
---|
142 | public:
|
---|
143 |
|
---|
144 | enum TaskType
|
---|
145 | {
|
---|
146 | /** Copies a file from host to the guest. */
|
---|
147 | TaskType_CopyFileToGuest = 50,
|
---|
148 | /** Copies a file from guest to the host. */
|
---|
149 | TaskType_CopyFileFromGuest = 55,
|
---|
150 | /** Update Guest Additions by directly copying the required installer
|
---|
151 | * off the .ISO file, transfer it to the guest and execute the installer
|
---|
152 | * with system privileges. */
|
---|
153 | TaskType_UpdateGuestAdditions = 100
|
---|
154 | };
|
---|
155 |
|
---|
156 | GuestTask(TaskType aTaskType, Guest *aThat, Progress *aProgress);
|
---|
157 |
|
---|
158 | virtual ~GuestTask();
|
---|
159 |
|
---|
160 | int startThread();
|
---|
161 |
|
---|
162 | static int taskThread(RTTHREAD aThread, void *pvUser);
|
---|
163 | static int uploadProgress(unsigned uPercent, void *pvUser);
|
---|
164 | static HRESULT setProgressErrorInfo(HRESULT hr,
|
---|
165 | ComObjPtr<Progress> pProgress, const char * pszText, ...);
|
---|
166 | static HRESULT setProgressErrorInfo(HRESULT hr,
|
---|
167 | ComObjPtr<Progress> pProgress, ComObjPtr<Guest> pGuest);
|
---|
168 |
|
---|
169 | TaskType taskType;
|
---|
170 | Guest *pGuest;
|
---|
171 | ComObjPtr<Progress> progress;
|
---|
172 | HRESULT rc;
|
---|
173 |
|
---|
174 | /* Task data. */
|
---|
175 | Utf8Str strSource;
|
---|
176 | Utf8Str strDest;
|
---|
177 | Utf8Str strUserName;
|
---|
178 | Utf8Str strPassword;
|
---|
179 | ULONG uFlags;
|
---|
180 | };
|
---|
181 | #endif // ____H_GUESTIMPLPRIVATE
|
---|
182 |
|
---|