VirtualBox

source: vbox/trunk/src/VBox/Main/include/HGCMObjects.h@ 98120

Last change on this file since 98120 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: HGCMObjects.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * HGCMObjects - Host-Guest Communication Manager objects header.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_HGCMObjects_h
29#define MAIN_INCLUDED_HGCMObjects_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <iprt/assert.h>
35#include <iprt/avl.h>
36#include <iprt/critsect.h>
37#include <iprt/asm.h>
38
39class HGCMObject;
40
41typedef struct ObjectAVLCore
42{
43 AVLU32NODECORE AvlCore;
44 HGCMObject *pSelf;
45} ObjectAVLCore;
46
47typedef enum
48{
49 HGCMOBJ_CLIENT,
50 HGCMOBJ_THREAD,
51 HGCMOBJ_MSG,
52 HGCMOBJ_SizeHack = 0x7fffffff
53} HGCMOBJ_TYPE;
54
55
56/**
57 * A referenced object.
58 */
59class HGCMReferencedObject
60{
61 private:
62 int32_t volatile m_cRefs;
63 HGCMOBJ_TYPE m_enmObjType;
64
65 protected:
66 virtual ~HGCMReferencedObject()
67 {}
68
69 public:
70 HGCMReferencedObject(HGCMOBJ_TYPE enmObjType)
71 : m_cRefs(0) /** @todo change to 1! */
72 , m_enmObjType(enmObjType)
73 {}
74
75 void Reference()
76 {
77 int32_t cRefs = ASMAtomicIncS32(&m_cRefs);
78 NOREF(cRefs);
79 Log(("Reference(%p/%d): cRefs = %d\n", this, m_enmObjType, cRefs));
80 }
81
82 void Dereference()
83 {
84 int32_t cRefs = ASMAtomicDecS32(&m_cRefs);
85 Log(("Dereference(%p/%d): cRefs = %d \n", this, m_enmObjType, cRefs));
86 AssertRelease(cRefs >= 0);
87
88 if (cRefs)
89 { /* likely */ }
90 else
91 delete this;
92 }
93
94 HGCMOBJ_TYPE Type()
95 {
96 return m_enmObjType;
97 }
98};
99
100
101class HGCMObject : public HGCMReferencedObject
102{
103 private:
104 friend uint32_t hgcmObjMake(HGCMObject *pObject, uint32_t u32HandleIn);
105
106 ObjectAVLCore m_core;
107
108 protected:
109 virtual ~HGCMObject()
110 {}
111
112 public:
113 HGCMObject(HGCMOBJ_TYPE enmObjType)
114 : HGCMReferencedObject(enmObjType)
115 {}
116
117 uint32_t Handle()
118 {
119 return (uint32_t)m_core.AvlCore.Key;
120 }
121};
122
123int hgcmObjInit();
124void hgcmObjUninit();
125
126uint32_t hgcmObjGenerateHandle(HGCMObject *pObject);
127uint32_t hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
128
129void hgcmObjDeleteHandle(uint32_t handle);
130
131HGCMObject *hgcmObjReference(uint32_t handle, HGCMOBJ_TYPE enmObjType);
132void hgcmObjDereference(HGCMObject *pObject);
133
134uint32_t hgcmObjQueryHandleCount();
135void hgcmObjSetHandleCount(uint32_t u32HandleCount);
136
137
138#endif /* !MAIN_INCLUDED_HGCMObjects_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette