VirtualBox

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

Last change on this file since 71272 was 69500, checked in by vboxsync, 7 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.9 KB
Line 
1/* $Id: EventImpl.h 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * VirtualBox COM IEvent implementation
4 */
5
6/*
7 * Copyright (C) 2010-2017 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 ____H_EVENTIMPL
19#define ____H_EVENTIMPL
20
21#include "EventWrap.h"
22#include "EventSourceWrap.h"
23#include "VetoEventWrap.h"
24
25
26class ATL_NO_VTABLE VBoxEvent :
27 public EventWrap
28{
29public:
30 DECLARE_EMPTY_CTOR_DTOR(VBoxEvent)
31
32 HRESULT FinalConstruct();
33 void FinalRelease();
34
35 // public initializer/uninitializer for internal purposes only
36 HRESULT init(IEventSource *aSource, VBoxEventType_T aType, BOOL aWaitable);
37 void uninit();
38
39private:
40 // wrapped IEvent properties
41 HRESULT getType(VBoxEventType_T *aType);
42 HRESULT getSource(ComPtr<IEventSource> &aSource);
43 HRESULT getWaitable(BOOL *aWaitable);
44
45 // wrapped IEvent methods
46 HRESULT setProcessed();
47 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
48
49 struct Data;
50 Data* m;
51};
52
53
54class ATL_NO_VTABLE VBoxVetoEvent :
55 public VetoEventWrap
56{
57public:
58 DECLARE_EMPTY_CTOR_DTOR(VBoxVetoEvent)
59
60 HRESULT FinalConstruct();
61 void FinalRelease();
62
63 // public initializer/uninitializer for internal purposes only
64 HRESULT init(IEventSource *aSource, VBoxEventType_T aType);
65 void uninit();
66
67private:
68 // wrapped IEvent properties
69 HRESULT getType(VBoxEventType_T *aType);
70 HRESULT getSource(ComPtr<IEventSource> &aSource);
71 HRESULT getWaitable(BOOL *aWaitable);
72
73 // wrapped IEvent methods
74 HRESULT setProcessed();
75 HRESULT waitProcessed(LONG aTimeout, BOOL *aResult);
76
77 // wrapped IVetoEvent methods
78 HRESULT addVeto(const com::Utf8Str &aReason);
79 HRESULT isVetoed(BOOL *aResult);
80 HRESULT getVetos(std::vector<com::Utf8Str> &aResult);
81 HRESULT addApproval(const com::Utf8Str &aReason);
82 HRESULT isApproved(BOOL *aResult);
83 HRESULT getApprovals(std::vector<com::Utf8Str> &aResult);
84
85 struct Data;
86 Data* m;
87};
88
89class ATL_NO_VTABLE EventSource :
90 public EventSourceWrap
91{
92public:
93 DECLARE_EMPTY_CTOR_DTOR(EventSource)
94
95 HRESULT FinalConstruct();
96 void FinalRelease();
97
98 // public initializer/uninitializer for internal purposes only
99 HRESULT init();
100 void uninit();
101
102private:
103 // wrapped IEventSource methods
104 HRESULT createListener(ComPtr<IEventListener> &aListener);
105 HRESULT createAggregator(const std::vector<ComPtr<IEventSource> > &aSubordinates,
106 ComPtr<IEventSource> &aResult);
107 HRESULT registerListener(const ComPtr<IEventListener> &aListener,
108 const std::vector<VBoxEventType_T> &aInteresting,
109 BOOL aActive);
110 HRESULT unregisterListener(const ComPtr<IEventListener> &aListener);
111 HRESULT fireEvent(const ComPtr<IEvent> &aEvent,
112 LONG aTimeout,
113 BOOL *aResult);
114 HRESULT getEvent(const ComPtr<IEventListener> &aListener,
115 LONG aTimeout,
116 ComPtr<IEvent> &aEvent);
117 HRESULT eventProcessed(const ComPtr<IEventListener> &aListener,
118 const ComPtr<IEvent> &aEvent);
119
120
121 struct Data;
122 Data* m;
123
124 friend class ListenerRecord;
125};
126
127class VBoxEventDesc
128{
129public:
130 VBoxEventDesc() : mEvent(0), mEventSource(0)
131 {}
132
133 ~VBoxEventDesc()
134 {}
135
136 /**
137 * This function to be used with some care, as arguments order must match
138 * attribute declaration order event class and its superclasses up to
139 * IEvent. If unsure, consult implementation in generated VBoxEvents.cpp.
140 */
141 HRESULT init(IEventSource* aSource, VBoxEventType_T aType, ...);
142
143 /**
144 * Function similar to the above, but assumes that init() for this type
145 * already called once, so no need to allocate memory, and only reinit
146 * fields. Assumes event is subtype of IReusableEvent, asserts otherwise.
147 */
148 HRESULT reinit(VBoxEventType_T aType, ...);
149
150 void uninit()
151 {
152 mEvent.setNull();
153 mEventSource.setNull();
154 }
155
156 void getEvent(IEvent **aEvent)
157 {
158 mEvent.queryInterfaceTo(aEvent);
159 }
160
161 BOOL fire(LONG aTimeout)
162 {
163 if (mEventSource && mEvent)
164 {
165 BOOL fDelivered = FALSE;
166 int rc = mEventSource->FireEvent(mEvent, aTimeout, &fDelivered);
167 AssertRCReturn(rc, FALSE);
168 return fDelivered;
169 }
170 return FALSE;
171 }
172
173private:
174 ComPtr<IEvent> mEvent;
175 ComPtr<IEventSource> mEventSource;
176};
177
178
179#endif // ____H_EVENTIMPL
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