1 | /** @file
|
---|
2 | *
|
---|
3 | * HGCMObjects - Host-Guest Communication Manager objects 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 __HGCMOBJECTS__H
|
---|
23 | #define __HGCMOBJECTS__H
|
---|
24 |
|
---|
25 | #include <iprt/assert.h>
|
---|
26 | #include <iprt/avl.h>
|
---|
27 | #include <iprt/critsect.h>
|
---|
28 | #include <iprt/asm.h>
|
---|
29 |
|
---|
30 | class HGCMObject;
|
---|
31 |
|
---|
32 | typedef struct _ObjectAVLCore
|
---|
33 | {
|
---|
34 | AVLULNODECORE AvlCore;
|
---|
35 | HGCMObject *pSelf;
|
---|
36 | } ObjectAVLCore;
|
---|
37 |
|
---|
38 | typedef enum
|
---|
39 | {
|
---|
40 | HGCMOBJ_CLIENT,
|
---|
41 | HGCMOBJ_THREAD,
|
---|
42 | HGCMOBJ_MSG,
|
---|
43 | HGCMOBJ_SizeHack = 0x7fffffff
|
---|
44 | } HGCMOBJ_TYPE;
|
---|
45 |
|
---|
46 | class HGCMObject
|
---|
47 | {
|
---|
48 | private:
|
---|
49 | friend uint32_t hgcmObjGenerateHandle (HGCMObject *pObject);
|
---|
50 |
|
---|
51 | int32_t volatile cRef;
|
---|
52 | HGCMOBJ_TYPE enmObjType;
|
---|
53 |
|
---|
54 | ObjectAVLCore Core;
|
---|
55 |
|
---|
56 | virtual bool Reuse (void) { return false; };
|
---|
57 |
|
---|
58 | protected:
|
---|
59 | virtual ~HGCMObject (void) {};
|
---|
60 |
|
---|
61 | public:
|
---|
62 | HGCMObject (HGCMOBJ_TYPE enmObjType) : cRef (0)
|
---|
63 | {
|
---|
64 | this->enmObjType = enmObjType;
|
---|
65 | };
|
---|
66 |
|
---|
67 | void Reference (void)
|
---|
68 | {
|
---|
69 | ASMAtomicIncS32 (&cRef);
|
---|
70 | }
|
---|
71 |
|
---|
72 | void Dereference (void)
|
---|
73 | {
|
---|
74 | int32_t refCnt = ASMAtomicDecS32 (&cRef);
|
---|
75 |
|
---|
76 | AssertRelease(refCnt >= 0);
|
---|
77 |
|
---|
78 | if (refCnt)
|
---|
79 | {
|
---|
80 | return;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (!Reuse ())
|
---|
84 | {
|
---|
85 | delete this;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | uint32_t Handle (void)
|
---|
90 | {
|
---|
91 | return Core.AvlCore.Key;
|
---|
92 | };
|
---|
93 |
|
---|
94 | HGCMOBJ_TYPE Type (void)
|
---|
95 | {
|
---|
96 | return enmObjType;
|
---|
97 | };
|
---|
98 | };
|
---|
99 |
|
---|
100 | int hgcmObjInit (void);
|
---|
101 |
|
---|
102 | void hgcmObjUninit (void);
|
---|
103 |
|
---|
104 | uint32_t hgcmObjGenerateHandle (HGCMObject *pObject);
|
---|
105 |
|
---|
106 | void hgcmObjDeleteHandle (uint32_t handle);
|
---|
107 |
|
---|
108 | HGCMObject *hgcmObjReference (uint32_t handle, HGCMOBJ_TYPE enmObjType);
|
---|
109 |
|
---|
110 | void hgcmObjDereference (HGCMObject *pObject);
|
---|
111 |
|
---|
112 | uint32_t hgcmObjQueryHandleCount ();
|
---|
113 | void hgcmObjSetHandleCount (uint32_t u32HandleCount);
|
---|
114 |
|
---|
115 | #endif /* __HGCMOBJECTS__H */
|
---|