VirtualBox

source: vbox/trunk/src/VBox/Main/include/GuestShClPrivate.h

Last change on this file was 100651, checked in by vboxsync, 10 months ago

Shared Clipboard: Also give the registered service extension the chance of calling an optional callback. Only used by VRDE so far (and probably never will be used by anything else, historical reasons). bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: GuestShClPrivate.h 100651 2023-07-19 11:52:59Z vboxsync $ */
2/** @file
3 * Private Shared Clipboard code for the Main API.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_GuestShClPrivate_h
29#define MAIN_INCLUDED_GuestShClPrivate_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/HostServices/VBoxClipboardExt.h>
35
36/**
37 * Forward prototype declarations.
38 */
39class Console;
40
41/**
42 * Struct for keeping a Shared Clipboard service extension.
43 */
44struct SHCLSVCEXT
45{
46 /** Service extension callback function.
47 * Setting this to NULL deactivates the extension. */
48 PFNHGCMSVCEXT pfnExt;
49 /** User-supplied service extension data. Might be NULL if not being used. */
50 void * pvExt;
51 /** Pointer to an optional extension callback.
52 * Might be NULL if not being used. */
53 PFNSHCLEXTCALLBACK pfnExtCallback;
54};
55/** Pointer to a Shared Clipboard service extension. */
56typedef SHCLSVCEXT *PSHCLSVCEXT;
57
58/**
59 * Private singleton class for managing the Shared Clipboard implementation within Main.
60 *
61 * Can't be instanciated directly, only via the factory pattern via GuestShCl::createInstance().
62 */
63class GuestShCl
64{
65public:
66
67 /**
68 * Creates the Singleton GuestShCl object.
69 *
70 * @returns Newly created Singleton object, or NULL on failure.
71 * @param pConsole Pointer to parent console.
72 */
73 static GuestShCl *createInstance(Console *pConsole)
74 {
75 AssertPtrReturn(pConsole, NULL);
76 Assert(NULL == GuestShCl::s_pInstance);
77 GuestShCl::s_pInstance = new GuestShCl(pConsole);
78 return GuestShCl::s_pInstance;
79 }
80
81 /**
82 * Destroys the Singleton GuestShCl object.
83 */
84 static void destroyInstance(void)
85 {
86 if (GuestShCl::s_pInstance)
87 {
88 delete GuestShCl::s_pInstance;
89 GuestShCl::s_pInstance = NULL;
90 }
91 }
92
93 /**
94 * Returns the Singleton GuestShCl object.
95 *
96 * @returns Pointer to Singleton GuestShCl object, or NULL if not created yet.
97 */
98 static inline GuestShCl *getInstance(void)
99 {
100 AssertPtr(GuestShCl::s_pInstance);
101 return GuestShCl::s_pInstance;
102 }
103
104protected:
105
106 /** Constructor; will throw vrc on failure. */
107 GuestShCl(Console *pConsole);
108 virtual ~GuestShCl(void);
109
110 void uninit(void);
111
112 int lock(void);
113 int unlock(void);
114
115public:
116
117 /** @name Public helper functions.
118 * @{ */
119 int hostCall(uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms) const;
120 int reportError(const char *pcszId, int vrc, const char *pcszMsgFmt, ...);
121 int RegisterServiceExtension(PFNHGCMSVCEXT pfnExtension, void *pvExtension);
122 int UnregisterServiceExtension(PFNHGCMSVCEXT pfnExtension);
123 /** @} */
124
125public:
126
127 /** @name Static low-level HGCM callback handler.
128 * @{ */
129 static DECLCALLBACK(int) hgcmDispatcher(void *pvExtension, uint32_t u32Function, void *pvParms, uint32_t cbParms);
130 /** @} */
131
132protected:
133
134 /** @name Singleton properties.
135 * @{ */
136 /** Pointer to console.
137 * Does not need any locking, as this object is a member of the console itself. */
138 Console *m_pConsole;
139 /** Critical section to serialize access. */
140 RTCRITSECT m_CritSect;
141 /** Pointer an additional service extension handle to serve (daisy chaining).
142 *
143 * This currently only is being used by the Console VRDP server helper class (historical reasons).
144 * We might want to transform this into a map later if we (ever) need more than one service extension,
145 * or drop this concept althogether when we move the service stuff out of the VM process (later). */
146 SHCLSVCEXT m_SvcExtVRDP;
147 /** Pointer to an optional extension callback.
148 * Might be NULL if not being used. */
149 PFNSHCLEXTCALLBACK m_pfnExtCallback;
150 /** @} */
151
152private:
153
154 /** Static pointer to singleton instance. */
155 static GuestShCl *s_pInstance;
156};
157
158/** Access to the GuestShCl's singleton instance. */
159#define GuestShClInst() GuestShCl::getInstance()
160
161#endif /* !MAIN_INCLUDED_GuestShClPrivate_h */
162
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use