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 | class HGCMObject
|
---|
39 | {
|
---|
40 | private:
|
---|
41 | friend uint32_t hgcmObjGenerateHandle (HGCMObject *pObject);
|
---|
42 |
|
---|
43 | int32_t volatile cRef;
|
---|
44 |
|
---|
45 | ObjectAVLCore Core;
|
---|
46 |
|
---|
47 | virtual bool Reuse (void) { return false; };
|
---|
48 |
|
---|
49 | protected:
|
---|
50 | virtual ~HGCMObject (void) {};
|
---|
51 |
|
---|
52 | public:
|
---|
53 | HGCMObject () : cRef (0) {};
|
---|
54 |
|
---|
55 | void Reference (void)
|
---|
56 | {
|
---|
57 | ASMAtomicIncS32 (&cRef);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void Dereference (void)
|
---|
61 | {
|
---|
62 | int32_t refCnt = ASMAtomicDecS32 (&cRef);
|
---|
63 |
|
---|
64 | AssertRelease(refCnt >= 0);
|
---|
65 |
|
---|
66 | if (refCnt)
|
---|
67 | {
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (!Reuse ())
|
---|
72 | {
|
---|
73 | delete this;
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | uint32_t Handle (void)
|
---|
78 | {
|
---|
79 | return Core.AvlCore.Key;
|
---|
80 | };
|
---|
81 | };
|
---|
82 |
|
---|
83 | int hgcmObjInit (void);
|
---|
84 |
|
---|
85 | void hgcmObjUninit (void);
|
---|
86 |
|
---|
87 | uint32_t hgcmObjGenerateHandle (HGCMObject *pObject);
|
---|
88 |
|
---|
89 | void hgcmObjDeleteHandle (uint32_t handle);
|
---|
90 |
|
---|
91 | HGCMObject *hgcmObjReference (uint32_t handle);
|
---|
92 |
|
---|
93 | void hgcmObjDereference (HGCMObject *pObject);
|
---|
94 |
|
---|
95 | #endif /* __HGCMOBJECTS__H */
|
---|