HGCMThread.h revision 571c90a734400801da973f986190fac9fc5efd0d
32ded45b3caba42c8a2315a20bbfabb513fa54c1vboxsync * HGCMThread - Host-Guest Communication Manager worker threads header.
c29fe1f686f1a78237986fbb030e3020cdbbfb77vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7f8c3a19fc6774798746c0782be09b88e54bf960vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7f8c3a19fc6774798746c0782be09b88e54bf960vboxsync * available from http://www.virtualbox.org. This file is free software;
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * you can redistribute it and/or modify it under the terms of the GNU
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * General Public License (GPL) as published by the Free Software
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * additional information or have any questions.
af1bd0025dd5d8be5f1468689d0d77d4839a3be5vboxsync/** A handle for HGCM message. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** A handle for HGCM worker threads. */
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync/* Forward declaration of message core class. */
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync/** @todo comment */
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsynctypedef HGCMMsgCore *FNHGCMNEWMSGALLOC(uint32_t u32MsgId);
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** Function that is called after message processing by worker thread,
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * or if an error occurred during message handling after successfully
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * posting (hgcmMsgPost) the message to worker thread.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param result Return code either from the service which actually processed the message
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * or from HGCM.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pMsgCore Pointer to just processed message.
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsynctypedef DECLCALLBACK(void) HGCMMSGCALLBACK (int32_t result, HGCMMsgCore *pMsgCore);
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync/* Forward declaration of the worker thread class. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** HGCM core message. */
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync /** Version of message header. */
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync /** Thread the message belongs to, referenced by the message. */
be641d8f2dc377d6a4403f3822d8bed08f51e28avboxsync /** Message number/identifier. */
295a2ae5a4db2c930f7096c6cf55b5fa4ee5b018vboxsync /** Callback function pointer. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync /** Next element in a message queue. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync /** @todo seems not necessary. Previous element in a message queue. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync /** Various internal flags. */
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync /** Result code for a Send */
be641d8f2dc377d6a4403f3822d8bed08f51e28avboxsync void InitializeCore (uint32_t u32MsgId, HGCMTHREADHANDLE hThread);
295a2ae5a4db2c930f7096c6cf55b5fa4ee5b018vboxsync /** Initialize message after it was allocated. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync /** Uninitialize message. */
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** HGCM worker thread function.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param ThreadHandle Handle of the thread.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pvUser User specified thread parameter.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsynctypedef DECLCALLBACK(void) FNHGCMTHREAD (HGCMTHREADHANDLE ThreadHandle, void *pvUser);
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * Thread API.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * Based on thread handles. Internals of a thread are not exposed to users.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync/** Initialize threads.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** Create a HGCM worker thread.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @param pHandle Where to store the returned worker thread handle.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pszThreadName Name of the thread, needed by runtime.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pfnThread The worker thread function.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pvUser A pointer passed to worker thread.
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync * @return VBox error code
295a2ae5a4db2c930f7096c6cf55b5fa4ee5b018vboxsyncint hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser);
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync/** Wait for termination of a HGCM worker thread.
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync * @param handle The HGCM thread handle.
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** Allocate a message to be posted to HGCM worker thread.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param hThread Worker thread handle.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pHandle Where to store the returned message handle.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param u32MsgId Message identifier.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pfnNewMessage New message allocation callback.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsyncint hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/** Post a message to HGCM worker thread.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param hMsg Message handle.
9148e7ca5f9ee1d467112d347bfb2de2b97254d2vboxsync * @param pfnCallback Message completion callback.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsyncint hgcmMsgPost (HGCMMSGHANDLE hMsg, PHGCMMSGCALLBACK pfnCallback);
32ded45b3caba42c8a2315a20bbfabb513fa54c1vboxsync/** Send a message to HGCM worker thread.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * The function will return after message is processed by thread.
32ded45b3caba42c8a2315a20bbfabb513fa54c1vboxsync * @param hMsg Message handle.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync/* Wait for and get a message.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @param hThread The thread handle.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param ppMsg Where to store returned message pointer.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @return VBox error code
32ded45b3caba42c8a2315a20bbfabb513fa54c1vboxsync * @thread worker thread
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsyncint hgcmMsgGet (HGCMTHREADHANDLE hThread, HGCMMsgCore **ppMsg);
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync/** Worker thread has processed a message previuosly obtained with hgcmMsgGet.
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @param pMsg Processed message pointer.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @param result Result code, VBox erro code.
1731b00e118d691438a0c8b1f1b4c6e29a0d5bb6vboxsync * @return VBox error code
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync * @thread worker thread
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsyncvoid hgcmMsgComplete (HGCMMsgCore *pMsg, int32_t result);
dc23707aec4dc2ce2c6b6f51af21eef72bb8bf2evboxsync#endif /* __HGCMThread_h__ */