VirtualBox

source: vbox/trunk/src/VBox/Main/include/HGCMThread.h@ 94134

Last change on this file since 94134 was 93444, checked in by vboxsync, 3 years ago

VMM,Main,HostServices: Use a function table for accessing the VBoxVMM.dll/so/dylib functionality, and load it dynamically when the Console object is initialized. Also converted a few drivers in Main to use device helpers to get config values and such. bugref:10074

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: HGCMThread.h 93444 2022-01-26 18:01:15Z vboxsync $ */
2/** @file
3 * HGCMThread - Host-Guest Communication Manager worker threads header.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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 MAIN_INCLUDED_HGCMThread_h
19#define MAIN_INCLUDED_HGCMThread_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/types.h>
25
26#include "HGCMObjects.h"
27
28/* Forward declaration of the worker thread class. */
29class HGCMThread;
30
31/** A handle for HGCM message. */
32typedef uint32_t HGCMMSGHANDLE;
33
34/* Forward declaration of message core class. */
35class HGCMMsgCore;
36
37/** @todo comment */
38
39typedef HGCMMsgCore *FNHGCMNEWMSGALLOC(uint32_t u32MsgId);
40typedef FNHGCMNEWMSGALLOC *PFNHGCMNEWMSGALLOC;
41
42/** Function that is called after message processing by worker thread,
43 * or if an error occurred during message handling after successfully
44 * posting (hgcmMsgPost) the message to worker thread.
45 *
46 * @param result Return code either from the service which actually processed the message
47 * or from HGCM.
48 * @param pMsgCore Pointer to just processed message.
49 *
50 * @return Restricted set of VBox status codes when guest call message:
51 * @retval VINF_SUCCESS on success
52 * @retval VERR_CANCELLED if the request was cancelled.
53 * @retval VERR_ALREADY_RESET if the VM is resetting.
54 * @retval VERR_NOT_AVAILABLE if HGCM has been disconnected from the VMMDev
55 * (shouldn't happen).
56 */
57typedef DECLCALLBACKTYPE(int, FNHGCMMSGCALLBACK,(int32_t result, HGCMMsgCore *pMsgCore));
58/** Pointer to a message completeion callback function. */
59typedef FNHGCMMSGCALLBACK *PFNHGCMMSGCALLBACK;
60
61
62/** HGCM core message. */
63class HGCMMsgCore : public HGCMReferencedObject
64{
65 private:
66 friend class HGCMThread;
67
68 /** Version of message header. */
69 uint32_t m_u32Version;
70
71 /** Message number/identifier. */
72 uint32_t m_u32Msg;
73
74 /** Thread the message belongs to, referenced by the message. */
75 HGCMThread *m_pThread;
76
77 /** Callback function pointer. */
78 PFNHGCMMSGCALLBACK m_pfnCallback;
79
80 /** Next element in a message queue. */
81 HGCMMsgCore *m_pNext;
82 /** Previous element in a message queue.
83 * @todo seems not necessary. */
84 HGCMMsgCore *m_pPrev;
85
86 /** Various internal flags. */
87 uint32_t m_fu32Flags;
88
89 /** Result code for a Send */
90 int32_t m_rcSend;
91
92 protected:
93 void InitializeCore(uint32_t u32MsgId, HGCMThread *pThread);
94
95 virtual ~HGCMMsgCore();
96
97 public:
98 HGCMMsgCore() : HGCMReferencedObject(HGCMOBJ_MSG) {};
99
100 uint32_t MsgId(void) { return m_u32Msg; };
101
102 HGCMThread *Thread(void) { return m_pThread; };
103
104 /** Initialize message after it was allocated. */
105 virtual void Initialize(void) {};
106
107 /** Uninitialize message. */
108 virtual void Uninitialize(void) {};
109};
110
111
112/** HGCM worker thread function.
113 *
114 * @param pThread The HGCM thread instance.
115 * @param pvUser User specified thread parameter.
116 */
117typedef DECLCALLBACKTYPE(void, FNHGCMTHREAD,(HGCMThread *pThread, void *pvUser));
118typedef FNHGCMTHREAD *PFNHGCMTHREAD;
119
120
121/**
122 * Thread API.
123 * Based on thread handles. Internals of a thread are not exposed to users.
124 */
125
126/** Initialize threads.
127 *
128 * @return VBox status code.
129 */
130int hgcmThreadInit(void);
131void hgcmThreadUninit(void);
132
133
134/** Create a HGCM worker thread.
135 *
136 * @param ppThread Where to return the pointer to the worker thread.
137 * @param pszThreadName Name of the thread, needed by runtime.
138 * @param pfnThread The worker thread function.
139 * @param pvUser A pointer passed to worker thread.
140 * @param pszStatsSubDir The "sub-directory" under "/HGCM/" where thread
141 * statistics should be registered. The caller,
142 * HGCMService, will deregister them. NULL if no stats.
143 * @param pUVM The user mode VM handle to register statistics with.
144 * NULL if no stats.
145 * @param pVMM The VMM vtable for statistics registration. NULL if
146 * no stats.
147 *
148 * @return VBox status code.
149 */
150int hgcmThreadCreate(HGCMThread **ppThread, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser,
151 const char *pszStatsSubDir, PUVM pUVM, PCVMMR3VTABLE pVMM);
152
153/** Wait for termination of a HGCM worker thread.
154 *
155 * @param pThread The HGCM thread. The passed in reference is always
156 * consumed.
157 *
158 * @return VBox status code.
159 */
160int hgcmThreadWait(HGCMThread *pThread);
161
162/** Allocate a message to be posted to HGCM worker thread.
163 *
164 * @param pThread The HGCM worker thread.
165 * @param ppHandle Where to store the pointer to the new message.
166 * @param u32MsgId Message identifier.
167 * @param pfnNewMessage New message allocation callback.
168 *
169 * @return VBox status code.
170 */
171int hgcmMsgAlloc(HGCMThread *pThread, HGCMMsgCore **ppHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
172
173/** Post a message to HGCM worker thread.
174 *
175 * @param pMsg The message. Reference will be consumed!
176 * @param pfnCallback Message completion callback.
177 *
178 * @return VBox status code.
179 * @retval VINF_HGCM_ASYNC_EXECUTE on success.
180 *
181 * @thread any
182 */
183int hgcmMsgPost(HGCMMsgCore *pMsg, PFNHGCMMSGCALLBACK pfnCallback);
184
185/** Send a message to HGCM worker thread.
186 *
187 * The function will return after message is processed by thread.
188 *
189 * @param pMsg The message. Reference will be consumed!
190 *
191 * @return VBox status code.
192 *
193 * @thread any
194 */
195int hgcmMsgSend(HGCMMsgCore *pMsg);
196
197
198/* Wait for and get a message.
199 *
200 * @param pThread The HGCM worker thread.
201 * @param ppMsg Where to store returned message pointer.
202 *
203 * @return VBox status code.
204 *
205 * @thread worker thread
206 */
207int hgcmMsgGet(HGCMThread *pThread, HGCMMsgCore **ppMsg);
208
209
210/** Worker thread has processed a message previously obtained with hgcmMsgGet.
211 *
212 * @param pMsg Processed message pointer.
213 * @param result Result code, VBox status code.
214 *
215 * @return Restricted set of VBox status codes when guest call message:
216 * @retval VINF_SUCCESS on success
217 * @retval VERR_CANCELLED if the request was cancelled.
218 * @retval VERR_ALREADY_RESET if the VM is resetting.
219 * @retval VERR_NOT_AVAILABLE if HGCM has been disconnected from the VMMDev
220 * (shouldn't happen).
221 *
222 * @thread worker thread
223 */
224int hgcmMsgComplete(HGCMMsgCore *pMsg, int32_t result);
225
226
227#endif /* !MAIN_INCLUDED_HGCMThread_h */
228
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette