1 | /* $Id: HGCMObjects.h 75539 2018-11-17 02:35:23Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * HGCMObjects - Host-Guest Communication Manager objects header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___HGCMOBJECTS__H
|
---|
19 | #define ___HGCMOBJECTS__H
|
---|
20 |
|
---|
21 | #include <iprt/assert.h>
|
---|
22 | #include <iprt/avl.h>
|
---|
23 | #include <iprt/critsect.h>
|
---|
24 | #include <iprt/asm.h>
|
---|
25 |
|
---|
26 | class HGCMObject;
|
---|
27 |
|
---|
28 | typedef struct _ObjectAVLCore
|
---|
29 | {
|
---|
30 | AVLULNODECORE AvlCore;
|
---|
31 | HGCMObject *pSelf;
|
---|
32 | } ObjectAVLCore;
|
---|
33 |
|
---|
34 | typedef enum
|
---|
35 | {
|
---|
36 | HGCMOBJ_CLIENT,
|
---|
37 | HGCMOBJ_THREAD,
|
---|
38 | HGCMOBJ_MSG,
|
---|
39 | HGCMOBJ_SizeHack = 0x7fffffff
|
---|
40 | } HGCMOBJ_TYPE;
|
---|
41 |
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * A referenced object.
|
---|
45 | */
|
---|
46 | class HGCMReferencedObject
|
---|
47 | {
|
---|
48 | private:
|
---|
49 | int32_t volatile m_cRefs;
|
---|
50 | HGCMOBJ_TYPE m_enmObjType;
|
---|
51 |
|
---|
52 | protected:
|
---|
53 | virtual ~HGCMReferencedObject()
|
---|
54 | {}
|
---|
55 |
|
---|
56 | public:
|
---|
57 | HGCMReferencedObject(HGCMOBJ_TYPE enmObjType)
|
---|
58 | : m_cRefs(0)
|
---|
59 | , m_enmObjType(enmObjType)
|
---|
60 | {}
|
---|
61 |
|
---|
62 | void Reference()
|
---|
63 | {
|
---|
64 | int32_t cRefs = ASMAtomicIncS32(&m_cRefs);
|
---|
65 | NOREF(cRefs);
|
---|
66 | Log(("Reference: cRefs = %d\n", cRefs));
|
---|
67 | }
|
---|
68 |
|
---|
69 | void Dereference()
|
---|
70 | {
|
---|
71 | int32_t cRefs = ASMAtomicDecS32(&m_cRefs);
|
---|
72 | Log(("Dereference: cRefs = %d\n", cRefs));
|
---|
73 | AssertRelease(cRefs >= 0);
|
---|
74 |
|
---|
75 | if (cRefs)
|
---|
76 | { /* likely */ }
|
---|
77 | else
|
---|
78 | delete this;
|
---|
79 | }
|
---|
80 |
|
---|
81 | HGCMOBJ_TYPE Type()
|
---|
82 | {
|
---|
83 | return m_enmObjType;
|
---|
84 | }
|
---|
85 | };
|
---|
86 |
|
---|
87 |
|
---|
88 | class HGCMObject : public HGCMReferencedObject
|
---|
89 | {
|
---|
90 | private:
|
---|
91 | friend uint32_t hgcmObjMake(HGCMObject *pObject, uint32_t u32HandleIn);
|
---|
92 |
|
---|
93 | ObjectAVLCore m_core;
|
---|
94 |
|
---|
95 | protected:
|
---|
96 | virtual ~HGCMObject()
|
---|
97 | {}
|
---|
98 |
|
---|
99 | public:
|
---|
100 | HGCMObject(HGCMOBJ_TYPE enmObjType)
|
---|
101 | : HGCMReferencedObject(enmObjType)
|
---|
102 | {}
|
---|
103 |
|
---|
104 | uint32_t Handle()
|
---|
105 | {
|
---|
106 | return (uint32_t)m_core.AvlCore.Key;
|
---|
107 | }
|
---|
108 | };
|
---|
109 |
|
---|
110 | int hgcmObjInit();
|
---|
111 | void hgcmObjUninit();
|
---|
112 |
|
---|
113 | uint32_t hgcmObjGenerateHandle(HGCMObject *pObject);
|
---|
114 | uint32_t hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
|
---|
115 |
|
---|
116 | void hgcmObjDeleteHandle(uint32_t handle);
|
---|
117 |
|
---|
118 | HGCMObject *hgcmObjReference(uint32_t handle, HGCMOBJ_TYPE enmObjType);
|
---|
119 | void hgcmObjDereference(HGCMReferencedObject *pObject);
|
---|
120 |
|
---|
121 | uint32_t hgcmObjQueryHandleCount();
|
---|
122 | void hgcmObjSetHandleCount(uint32_t u32HandleCount);
|
---|
123 |
|
---|
124 |
|
---|
125 | #endif /* !___HGCMOBJECTS__H */
|
---|