1 | /* $Id: GuestDnDPrivate.h 51556 2014-06-05 14:38:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Private guest drag and drop code, used by GuestDnDTarget +
|
---|
4 | * GuestDnDSource.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011-2014 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_GUESTDNDPRIVATE
|
---|
20 | #define ____H_GUESTDNDPRIVATE
|
---|
21 |
|
---|
22 | #include "VBox/hgcmsvc.h" /* For PVBOXHGCMSVCPARM. */
|
---|
23 |
|
---|
24 | /* Forward prototype declarations. */
|
---|
25 | class Guest;
|
---|
26 | class Progress;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Class for handling drag'n drop responses from
|
---|
30 | * the guest side.
|
---|
31 | */
|
---|
32 | class GuestDnDResponse
|
---|
33 | {
|
---|
34 |
|
---|
35 | public:
|
---|
36 |
|
---|
37 | GuestDnDResponse(const ComObjPtr<Guest>& pGuest);
|
---|
38 |
|
---|
39 | virtual ~GuestDnDResponse(void);
|
---|
40 |
|
---|
41 | public:
|
---|
42 |
|
---|
43 | int notifyAboutGuestResponse(void);
|
---|
44 | int waitForGuestResponse(RTMSINTERVAL msTimeout = 500);
|
---|
45 |
|
---|
46 | void setDefAction(uint32_t a) { m_defAction = a; }
|
---|
47 | uint32_t defAction(void) const { return m_defAction; }
|
---|
48 |
|
---|
49 | void setAllActions(uint32_t a) { m_allActions = a; }
|
---|
50 | uint32_t allActions() const { return m_allActions; }
|
---|
51 |
|
---|
52 | void setFormat(const Utf8Str &strFormat) { m_strFormat = strFormat; }
|
---|
53 | Utf8Str format(void) const { return m_strFormat; }
|
---|
54 |
|
---|
55 | void setDropDir(const Utf8Str &strDropDir) { m_strDropDir = strDropDir; }
|
---|
56 | Utf8Str dropDir(void) const { return m_strDropDir; }
|
---|
57 |
|
---|
58 | int dataAdd(const void *pvData, uint32_t cbData, uint32_t *pcbCurSize);
|
---|
59 | int dataSetStatus(size_t cbDataAdd, size_t cbDataTotal = 0);
|
---|
60 | void reset(void);
|
---|
61 | const void *data(void) { return m_pvData; }
|
---|
62 | size_t size(void) const { return m_cbData; }
|
---|
63 |
|
---|
64 | int setProgress(unsigned uPercentage, uint32_t uState, int rcOp = VINF_SUCCESS);
|
---|
65 | HRESULT resetProgress(const ComObjPtr<Guest>& pParent);
|
---|
66 | HRESULT queryProgressTo(IProgress **ppProgress);
|
---|
67 |
|
---|
68 | int writeToFile(const char *pszPath, size_t cbPath, void *pvData, size_t cbData, uint32_t fMode);
|
---|
69 |
|
---|
70 | public:
|
---|
71 |
|
---|
72 | Utf8Str errorToString(const ComObjPtr<Guest>& pGuest, int guestRc);
|
---|
73 |
|
---|
74 | private:
|
---|
75 | RTSEMEVENT m_EventSem;
|
---|
76 | uint32_t m_defAction;
|
---|
77 | uint32_t m_allActions;
|
---|
78 | Utf8Str m_strFormat;
|
---|
79 |
|
---|
80 | /** The actual MIME data.*/
|
---|
81 | void *m_pvData;
|
---|
82 | /** Size (in bytes) of MIME data. */
|
---|
83 | uint32_t m_cbData;
|
---|
84 |
|
---|
85 | size_t m_cbDataCurrent;
|
---|
86 | size_t m_cbDataTotal;
|
---|
87 | /** Dropped files directory on the host. */
|
---|
88 | Utf8Str m_strDropDir;
|
---|
89 | /** The handle of the currently opened file being written to
|
---|
90 | * or read from. */
|
---|
91 | RTFILE m_hFile;
|
---|
92 | Utf8Str m_strFile;
|
---|
93 |
|
---|
94 | ComObjPtr<Guest> m_parent;
|
---|
95 | ComObjPtr<Progress> m_progress;
|
---|
96 | };
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Private singleton class for the guest's DnD
|
---|
100 | * implementation. Can't be instanciated directly, only via
|
---|
101 | * the factory pattern.
|
---|
102 | */
|
---|
103 | class GuestDnD
|
---|
104 | {
|
---|
105 | public:
|
---|
106 |
|
---|
107 | static GuestDnD *createInstance(const ComObjPtr<Guest>& pGuest)
|
---|
108 | {
|
---|
109 | Assert(NULL == GuestDnD::s_pInstance);
|
---|
110 | GuestDnD::s_pInstance = new GuestDnD(pGuest);
|
---|
111 | return GuestDnD::s_pInstance;
|
---|
112 | }
|
---|
113 |
|
---|
114 | static void destroyInstance(void)
|
---|
115 | {
|
---|
116 | if (GuestDnD::s_pInstance)
|
---|
117 | {
|
---|
118 | delete GuestDnD::s_pInstance;
|
---|
119 | GuestDnD::s_pInstance = NULL;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | static inline GuestDnD *getInstance(void)
|
---|
124 | {
|
---|
125 | AssertPtr(GuestDnD::s_pInstance);
|
---|
126 | return GuestDnD::s_pInstance;
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected:
|
---|
130 |
|
---|
131 | GuestDnD(const ComObjPtr<Guest>& pGuest);
|
---|
132 | virtual ~GuestDnD(void);
|
---|
133 |
|
---|
134 | public:
|
---|
135 |
|
---|
136 | /** @name Public helper functions.
|
---|
137 | * @{ */
|
---|
138 | int adjustScreenCoordinates(ULONG uScreenId, ULONG *puX, ULONG *puY) const;
|
---|
139 | int hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
|
---|
140 | GuestDnDResponse *response(void) { return m_pResponse; }
|
---|
141 | std::vector<com::Utf8Str> defaultFormats(void) const { return m_strDefaultFormats; }
|
---|
142 | /** @} */
|
---|
143 |
|
---|
144 | public:
|
---|
145 |
|
---|
146 | /** @name Static low-level HGCM callback handler.
|
---|
147 | * @{ */
|
---|
148 | static DECLCALLBACK(int) notifyDnDDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
|
---|
149 | /** @} */
|
---|
150 |
|
---|
151 | /** @name Static helper methods.
|
---|
152 | * @{ */
|
---|
153 | static com::Utf8Str toFormatString(const std::vector<com::Utf8Str> &lstSupportedFormats, const std::vector<com::Utf8Str> &lstFormats);
|
---|
154 | static void toFormatVector(const std::vector<com::Utf8Str> &lstSupportedFormats, const com::Utf8Str &strFormats, std::vector<com::Utf8Str> &vecformats);
|
---|
155 | static DnDAction_T toMainAction(uint32_t uAction);
|
---|
156 | static void toMainActions(uint32_t uActions, std::vector<DnDAction_T> &vecActions);
|
---|
157 | static uint32_t toHGCMAction(DnDAction_T enmAction);
|
---|
158 | static void toHGCMActions(DnDAction_T enmDefAction, uint32_t *puDefAction, const std::vector<DnDAction_T> vecAllowedActions, uint32_t *puAllowedActions);
|
---|
159 | /** @} */
|
---|
160 |
|
---|
161 | protected:
|
---|
162 |
|
---|
163 | /** @name Singleton properties.
|
---|
164 | * @{ */
|
---|
165 | /** List of supported default MIME/Content-type formats. */
|
---|
166 | std::vector<com::Utf8Str> m_strDefaultFormats;
|
---|
167 | /** Pointer to guest implementation. */
|
---|
168 | const ComObjPtr<Guest> m_pGuest;
|
---|
169 | /** The current (last) response from the guest. At the
|
---|
170 | * moment we only support only response a time (ARQ-style). */
|
---|
171 | GuestDnDResponse *m_pResponse;
|
---|
172 | /** @} */
|
---|
173 |
|
---|
174 | protected:
|
---|
175 |
|
---|
176 | #ifdef VBOX_WITH_DRAG_AND_DROP_GH
|
---|
177 | /** @name Dispatch handlers for the HGCM callbacks.
|
---|
178 | * @{ */
|
---|
179 | int onGHSendData(GuestDnDResponse *pResp, const void *pvData, size_t cbData, size_t cbTotalSize);
|
---|
180 | int onGHSendDir(GuestDnDResponse *pResp, const char *pszPath, size_t cbPath, uint32_t fMode);
|
---|
181 | int onGHSendFile(GuestDnDResponse *pResp, const char *pszPath, size_t cbPath, void *pvData, size_t cbData, uint32_t fMode);
|
---|
182 | /** @} */
|
---|
183 | #endif /* VBOX_WITH_DRAG_AND_DROP_GH */
|
---|
184 |
|
---|
185 | private:
|
---|
186 |
|
---|
187 | /** Staic pointer to singleton instance. */
|
---|
188 | static GuestDnD *s_pInstance;
|
---|
189 | };
|
---|
190 |
|
---|
191 | /** Access to the GuestDnD's singleton instance. */
|
---|
192 | #define GuestDnDInst() GuestDnD::getInstance()
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * IDnDBase class implementation for sharing code between
|
---|
196 | * IGuestDnDSource and IGuestDnDTarget implementation.
|
---|
197 | */
|
---|
198 | class GuestDnDBase
|
---|
199 | {
|
---|
200 | protected:
|
---|
201 |
|
---|
202 | GuestDnDBase(void);
|
---|
203 |
|
---|
204 | protected:
|
---|
205 |
|
---|
206 | /** Shared IDnDBase method implementations.
|
---|
207 | * @{ */
|
---|
208 | HRESULT isFormatSupported(const com::Utf8Str &aFormat, BOOL *aSupported);
|
---|
209 | HRESULT getFormats(std::vector<com::Utf8Str> &aFormats);
|
---|
210 | HRESULT addFormats(const std::vector<com::Utf8Str> &aFormats);
|
---|
211 | HRESULT removeFormats(const std::vector<com::Utf8Str> &aFormats);
|
---|
212 | /** @} */
|
---|
213 |
|
---|
214 | protected:
|
---|
215 |
|
---|
216 | /** @name Attributes.
|
---|
217 | * @{ */
|
---|
218 | /** Pointer to guest implementation. */
|
---|
219 | const ComObjPtr<Guest> m_pGuest;
|
---|
220 | /** List of supported MIME/Content-type formats. */
|
---|
221 | std::vector<com::Utf8Str> m_strFormats;
|
---|
222 | /** @} */
|
---|
223 | };
|
---|
224 |
|
---|
225 | #endif /* ____H_GUESTDNDPRIVATE */
|
---|
226 |
|
---|