VirtualBox

source: vbox/trunk/src/VBox/Main/include/EventImpl.h@ 94660

Last change on this file since 94660 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: EventImpl.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VirtualBox COM IEvent implementation
4 */
5
6/*
7 * Copyright (C) 2010-2022 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 MAIN_INCLUDED_EventImpl_h
19#define MAIN_INCLUDED_EventImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "EventWrap.h"
25#include "EventSourceWrap.h"
26#include "VetoEventWrap.h"
27
28
29class ATL_NO_VTABLE VBoxEvent
30 : public EventWrap
31{
32public:
33 DECLARE_COMMON_CLASS_METHODS(VBoxEvent)
34
35 HRESULT FinalConstruct();
36 void FinalRelease();
37
38 // public initializer/uninitializer for internal purposes only
39 HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
40 void uninit();
41
42private:
43 // wrapped IEvent properties
44 HRESULT getType(VBoxEventType_T *aType);
45 HRESULT getSource(ComPtr<IEventSource> &aSource);
46 HRESULT getWaitable(BOOL *aWaitable);
47
48 // wrapped IEvent methods
49 HRESULT setProcessed();
50 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
51
52 struct Data;
53 Data* m;
54};
55
56
57class ATL_NO_VTABLE VBoxVetoEvent
58 : public VetoEventWrap
59{
60public:
61 DECLARE_COMMON_CLASS_METHODS(VBoxVetoEvent)
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66 // public initializer/uninitializer for internal purposes only
67 HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
68 void uninit();
69
70private:
71 // wrapped IEvent properties
72 HRESULT getType(VBoxEventType_T *aType);
73 HRESULT getSource(ComPtr<IEventSource> &aSource);
74 HRESULT getWaitable(BOOL *aWaitable);
75
76 // wrapped IEvent methods
77 HRESULT setProcessed();
78 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
79
80 // wrapped IVetoEvent methods
81 HRESULT addVeto(const com::Utf8Str &aReason);
82 HRESULT isVetoed(BOOL *aResult);
83 HRESULT getVetos(std::vector<com::Utf8Str> &aResult);
84 HRESULT addApproval(const com::Utf8Str &aReason);
85 HRESULT isApproved(BOOL *aResult);
86 HRESULT getApprovals(std::vector<com::Utf8Str> &aResult);
87
88 struct Data;
89 Data* m;
90};
91
92class ATL_NO_VTABLE EventSource :
93 public EventSourceWrap
94{
95public:
96 DECLARE_COMMON_CLASS_METHODS(EventSource)
97
98 HRESULT FinalConstruct();
99 void FinalRelease();
100
101 // public initializer/uninitializer for internal purposes only
102 HRESULT init();
103 void uninit();
104
105private:
106 // wrapped IEventSource methods
107 HRESULT createListener(ComPtr<IEventListener> &aListener);
108 HRESULT createAggregator(const std::vector<ComPtr<IEventSource> > &aSubordinates,
109 ComPtr<IEventSource> &aResult);
110 HRESULT registerListener(const ComPtr<IEventListener> &aListener,
111 const std::vector<VBoxEventType_T> &aInteresting,
112 BOOL aActive);
113 HRESULT unregisterListener(const ComPtr<IEventListener> &aListener);
114 HRESULT fireEvent(const ComPtr<IEvent> &aEvent,
115 LONG aTimeout,
116 BOOL *aResult);
117 HRESULT getEvent(const ComPtr<IEventListener> &aListener,
118 LONG aTimeout,
119 ComPtr<IEvent> &aEvent);
120 HRESULT eventProcessed(const ComPtr<IEventListener> &aListener,
121 const ComPtr<IEvent> &aEvent);
122
123
124 struct Data;
125 Data *m;
126
127 friend class ListenerRecord;
128};
129
130class VBoxEventDesc
131{
132public:
133 VBoxEventDesc() : mEvent(0), mEventSource(0)
134 {}
135
136 VBoxEventDesc(IEvent *aEvent, IEventSource *aSource)
137 : mEvent(aEvent), mEventSource(aSource)
138 {}
139
140 ~VBoxEventDesc()
141 {}
142
143 void init(IEvent *aEvent, IEventSource *aSource)
144 {
145 mEvent = aEvent;
146 mEventSource = aSource;
147 }
148
149 void uninit()
150 {
151 mEvent.setNull();
152 mEventSource.setNull();
153 }
154
155 void getEvent(IEvent **aEvent)
156 {
157 mEvent.queryInterfaceTo(aEvent);
158 }
159
160 BOOL fire(LONG aTimeout)
161 {
162 if (mEventSource && mEvent)
163 {
164 BOOL fDelivered = FALSE;
165 HRESULT hrc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
166 AssertComRCReturn(hrc, FALSE);
167 return fDelivered;
168 }
169 return FALSE;
170 }
171
172private:
173 ComPtr<IEvent> mEvent;
174 ComPtr<IEventSource> mEventSource;
175};
176
177
178#endif /* !MAIN_INCLUDED_EventImpl_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