VirtualBox

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

Last change on this file since 51856 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/** @file
2 * HGCMThread - Host-Guest Communication Manager worker threads header.
3 */
4
5/*
6 * Copyright (C) 2006-2010 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef __HGCMThread_h__
18#define __HGCMThread_h__
19
20#include <VBox/types.h>
21
22#include "HGCMObjects.h"
23
24/** A handle for HGCM message. */
25typedef uint32_t HGCMMSGHANDLE;
26
27/** A handle for HGCM worker threads. */
28typedef uint32_t HGCMTHREADHANDLE;
29
30/* Forward declaration of message core class. */
31class HGCMMsgCore;
32
33/** @todo comment */
34
35typedef HGCMMsgCore *FNHGCMNEWMSGALLOC(uint32_t u32MsgId);
36typedef FNHGCMNEWMSGALLOC *PFNHGCMNEWMSGALLOC;
37
38/** Function that is called after message processing by worker thread,
39 * or if an error occurred during message handling after successfully
40 * posting (hgcmMsgPost) the message to worker thread.
41 *
42 * @param result Return code either from the service which actually processed the message
43 * or from HGCM.
44 * @param pMsgCore Pointer to just processed message.
45 */
46typedef DECLCALLBACK(void) HGCMMSGCALLBACK (int32_t result, HGCMMsgCore *pMsgCore);
47typedef HGCMMSGCALLBACK *PHGCMMSGCALLBACK;
48
49/* Forward declaration of the worker thread class. */
50class HGCMThread;
51
52/** HGCM core message. */
53class HGCMMsgCore: public HGCMObject
54{
55 private:
56 friend class HGCMThread;
57
58 /** Version of message header. */
59 uint32_t m_u32Version;
60
61 /** Thread the message belongs to, referenced by the message. */
62 HGCMThread *m_pThread;
63
64 /** Message number/identifier. */
65 uint32_t m_u32Msg;
66
67 /** Callback function pointer. */
68 PHGCMMSGCALLBACK m_pfnCallback;
69
70 /** Next element in a message queue. */
71 HGCMMsgCore *m_pNext;
72 /** @todo seems not necessary. Previous element in a message queue. */
73 HGCMMsgCore *m_pPrev;
74
75 /** Various internal flags. */
76 uint32_t m_fu32Flags;
77
78 /** Result code for a Send */
79 int32_t m_rcSend;
80
81 void InitializeCore (uint32_t u32MsgId, HGCMTHREADHANDLE hThread);
82
83 protected:
84 virtual ~HGCMMsgCore ();
85
86 public:
87 HGCMMsgCore () : HGCMObject(HGCMOBJ_MSG) {};
88
89 uint32_t MsgId (void) { return m_u32Msg; };
90
91 HGCMThread *Thread (void) { return m_pThread; };
92
93 /** Initialize message after it was allocated. */
94 virtual void Initialize (void) {};
95
96 /** Uninitialize message. */
97 virtual void Uninitialize (void) {};
98
99};
100
101
102/** HGCM worker thread function.
103 *
104 * @param ThreadHandle Handle of the thread.
105 * @param pvUser User specified thread parameter.
106 */
107typedef DECLCALLBACK(void) FNHGCMTHREAD (HGCMTHREADHANDLE ThreadHandle, void *pvUser);
108typedef FNHGCMTHREAD *PFNHGCMTHREAD;
109
110
111/**
112 * Thread API.
113 * Based on thread handles. Internals of a thread are not exposed to users.
114 */
115
116/** Initialize threads.
117 *
118 * @return VBox error code
119 */
120int hgcmThreadInit (void);
121void hgcmThreadUninit (void);
122
123
124/** Create a HGCM worker thread.
125 *
126 * @param pHandle Where to store the returned worker thread handle.
127 * @param pszThreadName Name of the thread, needed by runtime.
128 * @param pfnThread The worker thread function.
129 * @param pvUser A pointer passed to worker thread.
130 *
131 * @return VBox error code
132 */
133int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser);
134
135/** Wait for termination of a HGCM worker thread.
136 *
137 * @param handle The HGCM thread handle.
138 *
139 * @return VBox error code
140 */
141int hgcmThreadWait (HGCMTHREADHANDLE handle);
142
143/** Allocate a message to be posted to HGCM worker thread.
144 *
145 * @param hThread Worker thread handle.
146 * @param pHandle Where to store the returned message handle.
147 * @param u32MsgId Message identifier.
148 * @param pfnNewMessage New message allocation callback.
149 *
150 * @return VBox error code
151 */
152int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
153
154/** Post a message to HGCM worker thread.
155 *
156 * @param hMsg Message handle.
157 * @param pfnCallback Message completion callback.
158 *
159 * @return VBox error code
160 */
161int hgcmMsgPost (HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback);
162
163/** Send a message to HGCM worker thread.
164 * The function will return after message is processed by thread.
165 *
166 * @param hMsg Message handle.
167 *
168 * @return VBox error code
169 */
170int hgcmMsgSend (HGCMMSGHANDLE hMsg);
171
172
173/* Wait for and get a message.
174 *
175 * @param hThread The thread handle.
176 * @param ppMsg Where to store returned message pointer.
177 *
178 * @return VBox error code
179 *
180 * @thread worker thread
181 */
182int hgcmMsgGet (HGCMTHREADHANDLE hThread, HGCMMsgCore **ppMsg);
183
184
185/** Worker thread has processed a message previously obtained with hgcmMsgGet.
186 *
187 * @param pMsg Processed message pointer.
188 * @param result Result code, VBox erro code.
189 *
190 * @return VBox error code
191 *
192 * @thread worker thread
193 */
194void hgcmMsgComplete (HGCMMsgCore *pMsg, int32_t result);
195
196
197#endif /* __HGCMThread_h__ */
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