VirtualBox

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

Last change on this file since 75539 was 75539, checked in by vboxsync, 7 years ago

Main/HGCM: Skip the handle stuff for the HGCMThread class, it just add overhead. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: HGCMThread.h 75539 2018-11-17 02:35:23Z vboxsync $ */
2/** @file
3 * HGCMThread - Host-Guest Communication Manager worker threads header.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 __HGCMThread_h__
19#define __HGCMThread_h__
20
21#include <VBox/types.h>
22
23#include "HGCMObjects.h"
24
25/* Forward declaration of the worker thread class. */
26class HGCMThread;
27
28/** A handle for HGCM message. */
29typedef uint32_t HGCMMSGHANDLE;
30
31/** A handle for HGCM worker threads. */
32typedef class HGCMThread *HGCMTHREADHANDLE;
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 */
50typedef DECLCALLBACK(void) HGCMMSGCALLBACK(int32_t result, HGCMMsgCore *pMsgCore);
51typedef HGCMMSGCALLBACK *PHGCMMSGCALLBACK;
52
53
54/** HGCM core message. */
55class HGCMMsgCore : public HGCMObject
56{
57 private:
58 friend class HGCMThread;
59
60 /** Version of message header. */
61 uint32_t m_u32Version;
62
63 /** Thread the message belongs to, referenced by the message. */
64 HGCMThread *m_pThread;
65
66 /** Message number/identifier. */
67 uint32_t m_u32Msg;
68
69 /** Callback function pointer. */
70 PHGCMMSGCALLBACK m_pfnCallback;
71
72 /** Next element in a message queue. */
73 HGCMMsgCore *m_pNext;
74 /** Previous element in a message queue.
75 * @todo seems not necessary. */
76 HGCMMsgCore *m_pPrev;
77
78 /** Various internal flags. */
79 uint32_t m_fu32Flags;
80
81 /** Result code for a Send */
82 int32_t m_rcSend;
83
84 void InitializeCore(uint32_t u32MsgId, HGCMThread * pThread);
85
86 protected:
87 virtual ~HGCMMsgCore();
88
89 public:
90 HGCMMsgCore() : HGCMObject(HGCMOBJ_MSG) {};
91
92 uint32_t MsgId(void) { return m_u32Msg; };
93
94 HGCMThread *Thread(void) { return m_pThread; };
95
96 /** Initialize message after it was allocated. */
97 virtual void Initialize(void) {};
98
99 /** Uninitialize message. */
100 virtual void Uninitialize(void) {};
101
102};
103
104
105/** HGCM worker thread function.
106 *
107 * @param pThread The HGCM thread instance.
108 * @param pvUser User specified thread parameter.
109 */
110typedef DECLCALLBACK(void) FNHGCMTHREAD(HGCMThread *pThread, void *pvUser);
111typedef FNHGCMTHREAD *PFNHGCMTHREAD;
112
113
114/**
115 * Thread API.
116 * Based on thread handles. Internals of a thread are not exposed to users.
117 */
118
119/** Initialize threads.
120 *
121 * @return VBox error code
122 */
123int hgcmThreadInit(void);
124void hgcmThreadUninit(void);
125
126
127/** Create a HGCM worker thread.
128 *
129 * @param ppThread Where to return the pointer to the worker thread.
130 * @param pszThreadName Name of the thread, needed by runtime.
131 * @param pfnThread The worker thread function.
132 * @param pvUser A pointer passed to worker thread.
133 * @param pszStatsSubDir The "sub-directory" under "/HGCM/" where thread
134 * statistics should be registered. The caller,
135 * HGCMService, will deregister them. NULL if no stats.
136 * @param pUVM The user mode VM handle to register statistics with.
137 * NULL if no stats.
138 *
139 * @return VBox error code
140 */
141int hgcmThreadCreate(HGCMThread **ppThread, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser,
142 const char *pszStatsSubDir, PUVM pUVM);
143
144/** Wait for termination of a HGCM worker thread.
145 *
146 * @param pThread The HGCM thread. The passed in reference is always
147 * consumed.
148 *
149 * @return VBox error code
150 */
151int hgcmThreadWait(HGCMThread *pThread);
152
153/** Allocate a message to be posted to HGCM worker thread.
154 *
155 * @param pThread The HGCM worker thread.
156 * @param pHandle Where to store the returned message handle.
157 * @param u32MsgId Message identifier.
158 * @param pfnNewMessage New message allocation callback.
159 *
160 * @return VBox error code
161 */
162int hgcmMsgAlloc(HGCMThread *pThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
163
164/** Post a message to HGCM worker thread.
165 *
166 * @param hMsg Message handle.
167 * @param pfnCallback Message completion callback.
168 *
169 * @return VBox error code
170 */
171int hgcmMsgPost(HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback);
172
173/** Send a message to HGCM worker thread.
174 * The function will return after message is processed by thread.
175 *
176 * @param hMsg Message handle.
177 *
178 * @return VBox error code
179 */
180int hgcmMsgSend(HGCMMSGHANDLE hMsg);
181
182
183/* Wait for and get a message.
184 *
185 * @param pThread The HGCM worker thread.
186 * @param ppMsg Where to store returned message pointer.
187 *
188 * @return VBox error code
189 *
190 * @thread worker thread
191 */
192int hgcmMsgGet(HGCMThread *pThread, HGCMMsgCore **ppMsg);
193
194
195/** Worker thread has processed a message previously obtained with hgcmMsgGet.
196 *
197 * @param pMsg Processed message pointer.
198 * @param result Result code, VBox erro code.
199 *
200 * @return VBox error code
201 *
202 * @thread worker thread
203 */
204void hgcmMsgComplete(HGCMMsgCore *pMsg, int32_t result);
205
206
207#endif /* __HGCMThread_h__ */
Note: See TracBrowser for help on using the repository browser.

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