1 | /* $Id: ClipboardProvider.cpp 79174 2019-06-17 10:30:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Shared Clipboard - Provider base class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 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 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
23 | #include <VBox/GuestHost/SharedClipboard-uri.h>
|
---|
24 |
|
---|
25 | #include <iprt/asm.h>
|
---|
26 | #include <iprt/assert.h>
|
---|
27 | #include <iprt/dir.h>
|
---|
28 | #include <iprt/errcore.h>
|
---|
29 | #include <iprt/file.h>
|
---|
30 | #include <iprt/path.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | #include <VBox/log.h>
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | SharedClipboardProvider::SharedClipboardProvider(void)
|
---|
39 | : m_cRefs(0)
|
---|
40 | {
|
---|
41 | LogFlowFuncEnter();
|
---|
42 | }
|
---|
43 |
|
---|
44 | SharedClipboardProvider::~SharedClipboardProvider(void)
|
---|
45 | {
|
---|
46 | LogFlowFuncEnter();
|
---|
47 | Assert(m_cRefs == 0);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Creates a Shared Clipboard provider.
|
---|
52 | *
|
---|
53 | * @returns New Shared Clipboard provider instance.
|
---|
54 | * @param pCtx Pointer to creation context.
|
---|
55 | */
|
---|
56 | /* static */
|
---|
57 | SharedClipboardProvider *SharedClipboardProvider::Create(PSHAREDCLIPBOARDPROVIDERCREATIONCTX pCtx)
|
---|
58 | {
|
---|
59 | AssertPtrReturn(pCtx, NULL);
|
---|
60 |
|
---|
61 | SharedClipboardProvider *pProvider = NULL;
|
---|
62 |
|
---|
63 | switch (pCtx->enmSource)
|
---|
64 | {
|
---|
65 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_GUEST
|
---|
66 | case SHAREDCLIPBOARDPROVIDERSOURCE_VBGLR3:
|
---|
67 | pProvider = new SharedClipboardProviderVbglR3(pCtx->u.VbglR3.uClientID);
|
---|
68 | break;
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | #ifdef VBOX_WITH_SHARED_CLIPBOARD_HOST
|
---|
72 | case SHAREDCLIPBOARDPROVIDERSOURCE_HOSTSERVICE:
|
---|
73 | pProvider = new SharedClipboardProviderHostService();
|
---|
74 | break;
|
---|
75 | #endif
|
---|
76 | default:
|
---|
77 | AssertFailed();
|
---|
78 | break;
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (pProvider)
|
---|
82 | pProvider->SetCallbacks(pCtx->pCallbacks);
|
---|
83 |
|
---|
84 | return pProvider;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Adds a reference to a Shared Clipboard provider.
|
---|
89 | *
|
---|
90 | * @returns New reference count.
|
---|
91 | */
|
---|
92 | uint32_t SharedClipboardProvider::AddRef(void)
|
---|
93 | {
|
---|
94 | LogFlowFuncEnter();
|
---|
95 | return ASMAtomicIncU32(&m_cRefs);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Removes a reference from a Shared Clipboard cache.
|
---|
100 | *
|
---|
101 | * @returns New reference count.
|
---|
102 | */
|
---|
103 | uint32_t SharedClipboardProvider::Release(void)
|
---|
104 | {
|
---|
105 | LogFlowFuncEnter();
|
---|
106 | Assert(m_cRefs);
|
---|
107 | return ASMAtomicDecU32(&m_cRefs);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Sets or unsets the callback table to be used for a clipboard provider.
|
---|
112 | *
|
---|
113 | * @returns VBox status code.
|
---|
114 | * @param pCallbacks Pointer to callback table to set. Specify NULL to unset existing callbacks.
|
---|
115 | */
|
---|
116 | void SharedClipboardProvider::SetCallbacks(PSHAREDCLIPBOARDPROVIDERCALLBACKS pCallbacks)
|
---|
117 | {
|
---|
118 | /* pCallbacks might be NULL to unset callbacks. */
|
---|
119 |
|
---|
120 | LogFlowFunc(("pCallbacks=%p\n", pCallbacks));
|
---|
121 |
|
---|
122 | if (pCallbacks)
|
---|
123 | {
|
---|
124 | m_Callbacks = *pCallbacks;
|
---|
125 | }
|
---|
126 | else
|
---|
127 | RT_ZERO(m_Callbacks);
|
---|
128 | }
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * Stubs.
|
---|
132 | */
|
---|
133 |
|
---|
134 | int SharedClipboardProvider::ReadDataHdr(PVBOXCLIPBOARDDATAHDR pDataHdr)
|
---|
135 | {
|
---|
136 | RT_NOREF(pDataHdr);
|
---|
137 | return VERR_NOT_IMPLEMENTED;
|
---|
138 | }
|
---|
139 |
|
---|
140 | int SharedClipboardProvider::WriteDataHdr(const PVBOXCLIPBOARDDATAHDR pDataHdr)
|
---|
141 | {
|
---|
142 | RT_NOREF(pDataHdr);
|
---|
143 | return VERR_NOT_IMPLEMENTED;
|
---|
144 | }
|
---|
145 |
|
---|
146 | int SharedClipboardProvider::ReadDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, void *pvChunk, uint32_t cbChunk,
|
---|
147 | uint32_t *pcbRead, uint32_t fFlags /* = 0 */)
|
---|
148 | {
|
---|
149 | RT_NOREF(pDataHdr, pvChunk, cbChunk, pcbRead, fFlags);
|
---|
150 | return VERR_NOT_IMPLEMENTED;
|
---|
151 | }
|
---|
152 |
|
---|
153 | int SharedClipboardProvider::WriteDataChunk(const PVBOXCLIPBOARDDATAHDR pDataHdr, const void *pvChunk, uint32_t cbChunk,
|
---|
154 | uint32_t *pcbWritten, uint32_t fFlags /* = 0 */)
|
---|
155 | {
|
---|
156 | RT_NOREF(pDataHdr, pvChunk, cbChunk, pcbWritten, fFlags);
|
---|
157 | return VERR_NOT_IMPLEMENTED;
|
---|
158 | }
|
---|
159 |
|
---|
160 | int SharedClipboardProvider::ReadDirectory(PVBOXCLIPBOARDDIRDATA pDirData)
|
---|
161 | {
|
---|
162 | RT_NOREF(pDirData);
|
---|
163 |
|
---|
164 | LogFlowFuncEnter();
|
---|
165 |
|
---|
166 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
167 |
|
---|
168 | LogFlowFuncLeaveRC(rc);
|
---|
169 | return rc;
|
---|
170 | }
|
---|
171 |
|
---|
172 | int SharedClipboardProvider::WriteDirectory(const PVBOXCLIPBOARDDIRDATA pDirData)
|
---|
173 | {
|
---|
174 | RT_NOREF(pDirData);
|
---|
175 |
|
---|
176 | LogFlowFuncEnter();
|
---|
177 |
|
---|
178 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
179 |
|
---|
180 | LogFlowFuncLeaveRC(rc);
|
---|
181 | return rc;
|
---|
182 | }
|
---|
183 |
|
---|
184 | int SharedClipboardProvider::ReadFileHdr(PVBOXCLIPBOARDFILEHDR pFileHdr)
|
---|
185 | {
|
---|
186 | RT_NOREF(pFileHdr);
|
---|
187 |
|
---|
188 | LogFlowFuncEnter();
|
---|
189 |
|
---|
190 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
191 |
|
---|
192 | LogFlowFuncLeaveRC(rc);
|
---|
193 | return rc;
|
---|
194 | }
|
---|
195 |
|
---|
196 | int SharedClipboardProvider::WriteFileHdr(const PVBOXCLIPBOARDFILEHDR pFileHdr)
|
---|
197 | {
|
---|
198 | RT_NOREF(pFileHdr);
|
---|
199 |
|
---|
200 | LogFlowFuncEnter();
|
---|
201 |
|
---|
202 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
203 |
|
---|
204 | LogFlowFuncLeaveRC(rc);
|
---|
205 | return rc;
|
---|
206 | }
|
---|
207 |
|
---|
208 | int SharedClipboardProvider::ReadFileData(PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbRead)
|
---|
209 | {
|
---|
210 | RT_NOREF(pFileData, pcbRead);
|
---|
211 |
|
---|
212 | LogFlowFuncEnter();
|
---|
213 |
|
---|
214 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
215 |
|
---|
216 | LogFlowFuncLeaveRC(rc);
|
---|
217 | return rc;
|
---|
218 | }
|
---|
219 |
|
---|
220 | int SharedClipboardProvider::WriteFileData(const PVBOXCLIPBOARDFILEDATA pFileData, uint32_t *pcbWritten)
|
---|
221 | {
|
---|
222 | RT_NOREF(pFileData, pcbWritten);
|
---|
223 |
|
---|
224 | LogFlowFuncEnter();
|
---|
225 |
|
---|
226 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
227 |
|
---|
228 | LogFlowFuncLeaveRC(rc);
|
---|
229 | return rc;
|
---|
230 | }
|
---|
231 |
|
---|
232 | void SharedClipboardProvider::Reset(void)
|
---|
233 | {
|
---|
234 | }
|
---|
235 |
|
---|
236 | int SharedClipboardProvider::OnRead(PSHAREDCLIPBOARDPROVIDERREADPARMS pParms)
|
---|
237 | {
|
---|
238 | RT_NOREF(pParms);
|
---|
239 |
|
---|
240 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
241 |
|
---|
242 | LogFlowFuncLeaveRC(rc);
|
---|
243 | return rc;
|
---|
244 | }
|
---|
245 |
|
---|
246 | int SharedClipboardProvider::OnWrite(PSHAREDCLIPBOARDPROVIDERWRITEPARMS pParms)
|
---|
247 | {
|
---|
248 | RT_NOREF(pParms);
|
---|
249 |
|
---|
250 | int rc = VERR_NOT_IMPLEMENTED;
|
---|
251 |
|
---|
252 | LogFlowFuncLeaveRC(rc);
|
---|
253 | return rc;
|
---|
254 | }
|
---|
255 |
|
---|