VirtualBox

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

Last change on this file since 465 was 1, checked in by vboxsync, 55 years ago

import

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