VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 20 months 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
RevLine 
[55401]1/* $Id: HGCMObjects.h 98103 2023-01-17 14:15:46Z vboxsync $ */
[1]2/** @file
3 * HGCMObjects - Host-Guest Communication Manager objects header.
4 */
5
6/*
[98103]7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[1]8 *
[96407]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
[1]26 */
27
[76562]28#ifndef MAIN_INCLUDED_HGCMObjects_h
29#define MAIN_INCLUDED_HGCMObjects_h
[76487]30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
[1]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
[91113]41typedef struct ObjectAVLCore
[1]42{
[91112]43 AVLU32NODECORE AvlCore;
[1]44 HGCMObject *pSelf;
45} ObjectAVLCore;
46
[1080]47typedef enum
48{
49 HGCMOBJ_CLIENT,
50 HGCMOBJ_THREAD,
51 HGCMOBJ_MSG,
52 HGCMOBJ_SizeHack = 0x7fffffff
53} HGCMOBJ_TYPE;
54
[75539]55
56/**
57 * A referenced object.
58 */
59class HGCMReferencedObject
[1]60{
61 private:
[24989]62 int32_t volatile m_cRefs;
63 HGCMOBJ_TYPE m_enmObjType;
[1]64
65 protected:
[75539]66 virtual ~HGCMReferencedObject()
[75535]67 {}
[1]68
69 public:
[75539]70 HGCMReferencedObject(HGCMOBJ_TYPE enmObjType)
[75541]71 : m_cRefs(0) /** @todo change to 1! */
[75539]72 , m_enmObjType(enmObjType)
73 {}
[1]74
[24989]75 void Reference()
[1]76 {
[75539]77 int32_t cRefs = ASMAtomicIncS32(&m_cRefs);
78 NOREF(cRefs);
[75541]79 Log(("Reference(%p/%d): cRefs = %d\n", this, m_enmObjType, cRefs));
[1]80 }
81
[24989]82 void Dereference()
[1]83 {
[75539]84 int32_t cRefs = ASMAtomicDecS32(&m_cRefs);
[75541]85 Log(("Dereference(%p/%d): cRefs = %d \n", this, m_enmObjType, cRefs));
[75539]86 AssertRelease(cRefs >= 0);
[1]87
[75539]88 if (cRefs)
89 { /* likely */ }
90 else
91 delete this;
92 }
[24989]93
[75539]94 HGCMOBJ_TYPE Type()
95 {
96 return m_enmObjType;
97 }
98};
[1]99
100
[75539]101class HGCMObject : public HGCMReferencedObject
102{
103 private:
104 friend uint32_t hgcmObjMake(HGCMObject *pObject, uint32_t u32HandleIn);
[1]105
[75539]106 ObjectAVLCore m_core;
107
108 protected:
109 virtual ~HGCMObject()
110 {}
111
112 public:
113 HGCMObject(HGCMOBJ_TYPE enmObjType)
114 : HGCMReferencedObject(enmObjType)
115 {}
116
[24989]117 uint32_t Handle()
[1]118 {
[62379]119 return (uint32_t)m_core.AvlCore.Key;
[75535]120 }
[1]121};
122
[75539]123int hgcmObjInit();
124void hgcmObjUninit();
[1]125
[75539]126uint32_t hgcmObjGenerateHandle(HGCMObject *pObject);
127uint32_t hgcmObjAssignHandle(HGCMObject *pObject, uint32_t u32Handle);
[1]128
[75539]129void hgcmObjDeleteHandle(uint32_t handle);
[1]130
[24989]131HGCMObject *hgcmObjReference(uint32_t handle, HGCMOBJ_TYPE enmObjType);
[75541]132void hgcmObjDereference(HGCMObject *pObject);
[1]133
[75539]134uint32_t hgcmObjQueryHandleCount();
135void hgcmObjSetHandleCount(uint32_t u32HandleCount);
[1]136
[1080]137
[76562]138#endif /* !MAIN_INCLUDED_HGCMObjects_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use