1 | /* $Id: HGCMObjects.h 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * HGCMObjects - Host-Guest Communication Manager objects header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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 | class HGCMObject
|
---|
43 | {
|
---|
44 | private:
|
---|
45 | friend uint32_t hgcmObjMake(HGCMObject *pObject, uint32_t u32HandleIn);
|
---|
46 |
|
---|
47 | int32_t volatile m_cRefs;
|
---|
48 | HGCMOBJ_TYPE m_enmObjType;
|
---|
49 |
|
---|
50 | ObjectAVLCore m_core;
|
---|
51 |
|
---|
52 | protected:
|
---|
53 | virtual ~HGCMObject()
|
---|
54 | {};
|
---|
55 |
|
---|
56 | public:
|
---|
57 | HGCMObject(HGCMOBJ_TYPE enmObjType)
|
---|
58 | : m_cRefs(0)
|
---|
59 | {
|
---|
60 | this->m_enmObjType = enmObjType;
|
---|
61 | };
|
---|
62 |
|
---|
63 | void Reference()
|
---|
64 | {
|
---|
65 | int32_t refCnt = ASMAtomicIncS32(&m_cRefs);
|
---|
66 | NOREF(refCnt);
|
---|
67 | Log(("Reference: refCnt = %d\n", refCnt));
|
---|
68 | }
|
---|
69 |
|
---|
70 | void Dereference()
|
---|
71 | {
|
---|
72 | int32_t refCnt = ASMAtomicDecS32(&m_cRefs);
|
---|
73 |
|
---|
74 | Log(("Dereference: refCnt = %d\n", refCnt));
|
---|
75 |
|
---|
76 | AssertRelease(refCnt >= 0);
|
---|
77 |
|
---|
78 | if (refCnt)
|
---|
79 | {
|
---|
80 | return;
|
---|
81 | }
|
---|
82 |
|
---|
83 | delete this;
|
---|
84 | }
|
---|
85 |
|
---|
86 | uint32_t Handle()
|
---|
87 | {
|
---|
88 | return (uint32_t)m_core.AvlCore.Key;
|
---|
89 | };
|
---|
90 |
|
---|
91 | HGCMOBJ_TYPE Type()
|
---|
92 | {
|
---|
93 | return m_enmObjType;
|
---|
94 | };
|
---|
95 | };
|
---|
96 |
|
---|
97 | int hgcmObjInit();
|
---|
98 |
|
---|
99 | void hgcmObjUninit();
|
---|
100 |
|
---|
101 | uint32_t hgcmObjGenerateHandle(HGCMObject *pObject);
|
---|
102 | uint32_t hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
|
---|
103 |
|
---|
104 | void hgcmObjDeleteHandle(uint32_t handle);
|
---|
105 |
|
---|
106 | HGCMObject *hgcmObjReference(uint32_t handle, HGCMOBJ_TYPE enmObjType);
|
---|
107 |
|
---|
108 | void hgcmObjDereference(HGCMObject *pObject);
|
---|
109 |
|
---|
110 | uint32_t hgcmObjQueryHandleCount();
|
---|
111 | void hgcmObjSetHandleCount(uint32_t u32HandleCount);
|
---|
112 |
|
---|
113 | #endif /* !___HGCMOBJECTS__H */
|
---|