VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/HGCMThread.h@ 5999

最後變更 在這個檔案從5999是 5999,由 vboxsync 提交於 17 年 前

The Giant CDDL Dual-License Header Change.

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

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