Changeset 52719 in vbox for trunk/src/VBox/Main/src-all/EventImpl.cpp
- Timestamp:
- Sep 12, 2014 12:33:41 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/EventImpl.cpp
r52413 r52719 83 83 }; 84 84 85 DEFINE_EMPTY_CTOR_DTOR(VBoxEvent) 86 85 87 HRESULT VBoxEvent::FinalConstruct() 86 88 { … … 95 97 uninit(); 96 98 delete m; 97 m = 0;98 BaseFinalRelease();99 }99 m = NULL; 100 } 101 BaseFinalRelease(); 100 102 } 101 103 … … 151 153 } 152 154 153 STDMETHODIMP VBoxEvent::COMGETTER(Type)(VBoxEventType_T *aType) 154 { 155 CheckComArgNotNull(aType); 156 157 AutoCaller autoCaller(this); 158 if (FAILED(autoCaller.rc())) 159 return autoCaller.rc(); 160 155 HRESULT VBoxEvent::getType(VBoxEventType_T *aType) 156 { 161 157 // never changes while event alive, no locking 162 158 *aType = m->mType; … … 164 160 } 165 161 166 STDMETHODIMP VBoxEvent::COMGETTER(Source)(IEventSource **aSource) 167 { 168 CheckComArgOutPointerValid(aSource); 169 170 AutoCaller autoCaller(this); 171 if (FAILED(autoCaller.rc())) 172 return autoCaller.rc(); 173 174 m->mSource.queryInterfaceTo(aSource); 175 return S_OK; 176 } 177 178 STDMETHODIMP VBoxEvent::COMGETTER(Waitable)(BOOL *aWaitable) 179 { 180 CheckComArgNotNull(aWaitable); 181 182 AutoCaller autoCaller(this); 183 if (FAILED(autoCaller.rc())) 184 return autoCaller.rc(); 185 162 HRESULT VBoxEvent::getSource(ComPtr<IEventSource> &aSource) 163 { 164 m->mSource.queryInterfaceTo(aSource.asOutParam()); 165 return S_OK; 166 } 167 168 HRESULT VBoxEvent::getWaitable(BOOL *aWaitable) 169 { 186 170 // never changes while event alive, no locking 187 171 *aWaitable = m->mWaitable; … … 189 173 } 190 174 191 192 STDMETHODIMP VBoxEvent::SetProcessed() 193 { 194 AutoCaller autoCaller(this); 195 if (FAILED(autoCaller.rc())) 196 return autoCaller.rc(); 197 175 HRESULT VBoxEvent::setProcessed() 176 { 198 177 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 199 178 … … 209 188 } 210 189 211 STDMETHODIMP VBoxEvent::WaitProcessed(LONG aTimeout, BOOL *aResult) 212 { 213 CheckComArgNotNull(aResult); 214 215 AutoCaller autoCaller(this); 216 if (FAILED(autoCaller.rc())) 217 return autoCaller.rc(); 218 219 { 220 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 221 222 if (m->mProcessed) 223 { 224 *aResult = TRUE; 225 return S_OK; 226 } 227 228 if (aTimeout == 0) 229 { 230 *aResult = m->mProcessed; 231 return S_OK; 232 } 190 HRESULT VBoxEvent::waitProcessed(LONG aTimeout, BOOL *aResult) 191 { 192 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 193 194 if (m->mProcessed) 195 { 196 *aResult = TRUE; 197 return S_OK; 198 } 199 200 if (aTimeout == 0) 201 { 202 *aResult = m->mProcessed; 203 return S_OK; 233 204 } 234 205 … … 252 223 } 253 224 254 typedef std::list< Bstr> VetoList;225 typedef std::list<Utf8Str> VetoList; 255 226 struct VBoxVetoEvent::Data 256 227 { … … 258 229 mVetoed(FALSE) 259 230 {} 231 ComObjPtr<VBoxEvent> mEvent; 260 232 BOOL mVetoed; 261 233 VetoList mVetoList; … … 264 236 HRESULT VBoxVetoEvent::FinalConstruct() 265 237 { 266 VBoxEvent::FinalConstruct();267 238 m = new Data; 268 return S_OK; 239 HRESULT rc = m->mEvent.createObject(); 240 BaseFinalConstruct(); 241 return rc; 269 242 } 270 243 … … 275 248 uninit(); 276 249 delete m; 277 m = 0; 278 } 279 VBoxEvent::FinalRelease(); 280 } 281 250 m = NULL; 251 } 252 BaseFinalRelease(); 253 } 254 255 DEFINE_EMPTY_CTOR_DTOR(VBoxVetoEvent) 282 256 283 257 HRESULT VBoxVetoEvent::init(IEventSource *aSource, VBoxEventType_T aType) … … 285 259 HRESULT rc = S_OK; 286 260 // all veto events are waitable 287 rc = VBoxEvent::init(aSource, aType, TRUE);261 rc = m->mEvent->init(aSource, aType, TRUE); 288 262 if (FAILED(rc)) 289 263 return rc; … … 292 266 m->mVetoList.clear(); 293 267 294 return rc;268 return S_OK; 295 269 } 296 270 297 271 void VBoxVetoEvent::uninit() 298 272 { 299 VBoxEvent::uninit();300 273 if (!m) 301 274 return; 275 302 276 m->mVetoed = FALSE; 303 } 304 305 STDMETHODIMP VBoxVetoEvent::AddVeto(IN_BSTR aVeto) 306 { 307 AutoCaller autoCaller(this); 308 if (FAILED(autoCaller.rc())) 309 return autoCaller.rc(); 310 311 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 312 313 if (aVeto) 314 m->mVetoList.push_back(aVeto); 277 if (!m->mEvent.isNull()) 278 { 279 m->mEvent->uninit(); 280 m->mEvent.setNull(); 281 } 282 } 283 284 HRESULT VBoxVetoEvent::getType(VBoxEventType_T *aType) 285 { 286 return m->mEvent->COMGETTER(Type)(aType); 287 } 288 289 HRESULT VBoxVetoEvent::getSource(ComPtr<IEventSource> &aSource) 290 { 291 return m->mEvent->COMGETTER(Source)(aSource.asOutParam()); 292 } 293 294 HRESULT VBoxVetoEvent::getWaitable(BOOL *aWaitable) 295 { 296 return m->mEvent->COMGETTER(Waitable)(aWaitable); 297 } 298 299 HRESULT VBoxVetoEvent::setProcessed() 300 { 301 return m->mEvent->SetProcessed(); 302 } 303 304 HRESULT VBoxVetoEvent::waitProcessed(LONG aTimeout, BOOL *aResult) 305 { 306 return m->mEvent->WaitProcessed(aTimeout, aResult); 307 } 308 309 HRESULT VBoxVetoEvent::addVeto(const com::Utf8Str &aReason) 310 { 311 // AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 312 if (aReason.length()) 313 m->mVetoList.push_back(aReason); 315 314 316 315 m->mVetoed = TRUE; … … 319 318 } 320 319 321 STDMETHODIMP VBoxVetoEvent::IsVetoed(BOOL *aResult) 322 { 323 CheckComArgOutPointerValid(aResult); 324 325 AutoCaller autoCaller(this); 326 if (FAILED(autoCaller.rc())) 327 return autoCaller.rc(); 328 329 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 330 320 HRESULT VBoxVetoEvent::isVetoed(BOOL *aResult) 321 { 322 // AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 331 323 *aResult = m->mVetoed; 332 324 … … 334 326 } 335 327 336 STDMETHODIMP VBoxVetoEvent::GetVetos(ComSafeArrayOut(BSTR, aVetos)) 337 { 338 if (ComSafeArrayOutIsNull(aVetos)) 339 return E_POINTER; 340 341 AutoCaller autoCaller(this); 342 if (FAILED(autoCaller.rc())) 343 return autoCaller.rc(); 344 345 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 346 com::SafeArray<BSTR> vetos(m->mVetoList.size()); 347 int i = 0; 348 for (VetoList::const_iterator it = m->mVetoList.begin(); 349 it != m->mVetoList.end(); 350 ++it, ++i) 351 { 352 const Bstr &str = *it; 353 str.cloneTo(&vetos[i]); 354 } 355 vetos.detachTo(ComSafeArrayOutArg(aVetos)); 328 HRESULT VBoxVetoEvent::getVetos(std::vector<com::Utf8Str> &aResult) 329 { 330 // AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 331 aResult.resize(m->mVetoList.size()); 332 size_t i = 0; 333 for (VetoList::const_iterator it = m->mVetoList.begin(); it != m->mVetoList.end(); ++it, ++i) 334 aResult[i] = (*it); 356 335 357 336 return S_OK; … … 1006 985 } 1007 986 1008 STDMETHODIMP EventSource::RegisterListener(IEventListener *aListener, 1009 ComSafeArrayIn(VBoxEventType_T, aInterested), 1010 BOOL aActive) 1011 { 1012 CheckComArgNotNull(aListener); 1013 CheckComArgSafeArrayNotNull(aInterested); 1014 1015 AutoCaller autoCaller(this); 1016 if (FAILED(autoCaller.rc())) 1017 return autoCaller.rc(); 1018 1019 { 1020 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1021 1022 if (m->fShutdown) 1023 return setError(VBOX_E_INVALID_OBJECT_STATE, 1024 tr("This event source is already shut down")); 1025 1026 Listeners::const_iterator it = m->mListeners.find(aListener); 1027 if (it != m->mListeners.end()) 1028 return setError(E_INVALIDARG, 1029 tr("This listener already registered")); 1030 1031 com::SafeArray<VBoxEventType_T> interested(ComSafeArrayInArg(aInterested)); 1032 RecordHolder<ListenerRecord> lrh(new ListenerRecord(aListener, interested, aActive, this)); 1033 m->mListeners.insert(Listeners::value_type(aListener, lrh)); 1034 } 987 HRESULT EventSource::registerListener(const ComPtr<IEventListener> &aListener, 988 const std::vector<VBoxEventType_T> &aInteresting, 989 BOOL aActive) 990 { 991 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 992 993 if (m->fShutdown) 994 return setError(VBOX_E_INVALID_OBJECT_STATE, 995 tr("This event source is already shut down")); 996 997 Listeners::const_iterator it = m->mListeners.find(aListener); 998 if (it != m->mListeners.end()) 999 return setError(E_INVALIDARG, 1000 tr("This listener already registered")); 1001 1002 com::SafeArray<VBoxEventType_T> interested(aInteresting); 1003 RecordHolder<ListenerRecord> lrh(new ListenerRecord(aListener, interested, aActive, this)); 1004 m->mListeners.insert(Listeners::value_type((IEventListener *)aListener, lrh)); 1035 1005 1036 1006 VBoxEventDesc evDesc; 1037 evDesc.init(this, VBoxEventType_OnEventSourceChanged, aListener, TRUE);1007 evDesc.init(this, VBoxEventType_OnEventSourceChanged, (IEventListener *)aListener, TRUE); 1038 1008 evDesc.fire(0); 1039 1009 … … 1041 1011 } 1042 1012 1043 STDMETHODIMP EventSource::UnregisterListener(IEventListener *aListener) 1044 { 1045 CheckComArgNotNull(aListener); 1046 1047 AutoCaller autoCaller(this); 1048 if (FAILED(autoCaller.rc())) 1049 return autoCaller.rc(); 1050 1051 HRESULT rc; 1052 { 1053 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1054 1055 Listeners::iterator it = m->mListeners.find(aListener); 1056 1057 if (it != m->mListeners.end()) 1058 { 1059 it->second.obj()->shutdown(); 1060 m->mListeners.erase(it); 1061 // destructor removes refs from the event map 1062 rc = S_OK; 1063 } 1064 else 1065 { 1066 rc = setError(VBOX_E_OBJECT_NOT_FOUND, 1067 tr("Listener was never registered")); 1068 } 1013 HRESULT EventSource::unregisterListener(const ComPtr<IEventListener> &aListener) 1014 { 1015 HRESULT rc = S_OK;; 1016 1017 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1018 1019 Listeners::iterator it = m->mListeners.find(aListener); 1020 1021 if (it != m->mListeners.end()) 1022 { 1023 it->second.obj()->shutdown(); 1024 m->mListeners.erase(it); 1025 // destructor removes refs from the event map 1026 rc = S_OK; 1027 } 1028 else 1029 { 1030 rc = setError(VBOX_E_OBJECT_NOT_FOUND, 1031 tr("Listener was never registered")); 1069 1032 } 1070 1033 … … 1072 1035 { 1073 1036 VBoxEventDesc evDesc; 1074 evDesc.init(this, VBoxEventType_OnEventSourceChanged, aListener, FALSE);1037 evDesc.init(this, VBoxEventType_OnEventSourceChanged, (IEventListener *)aListener, FALSE); 1075 1038 evDesc.fire(0); 1076 1039 } … … 1079 1042 } 1080 1043 1081 STDMETHODIMP EventSource::FireEvent(IEvent *aEvent, 1082 LONG aTimeout, 1083 BOOL *aProcessed) 1084 { 1085 CheckComArgNotNull(aEvent); 1086 CheckComArgOutPointerValid(aProcessed); 1087 1088 AutoCaller autoCaller(this); 1089 if (FAILED(autoCaller.rc())) 1090 return autoCaller.rc(); 1091 1092 HRESULT hrc; 1044 HRESULT EventSource::fireEvent(const ComPtr<IEvent> &aEvent, 1045 LONG aTimeout, 1046 BOOL *aResult) 1047 { 1048 1049 HRESULT hrc = S_OK; 1093 1050 BOOL aWaitable = FALSE; 1094 1051 aEvent->COMGETTER(Waitable)(&aWaitable); … … 1158 1115 1159 1116 if (aWaitable) 1160 hrc = aEvent->WaitProcessed(aTimeout, a Processed);1117 hrc = aEvent->WaitProcessed(aTimeout, aResult); 1161 1118 else 1162 *a Processed= TRUE;1119 *aResult = TRUE; 1163 1120 1164 1121 return hrc; 1165 1122 } 1166 1123 1167 1168 STDMETHODIMP EventSource::GetEvent(IEventListener *aListener, 1169 LONG aTimeout, 1170 IEvent **aEvent) 1171 { 1172 1173 CheckComArgNotNull(aListener); 1174 1175 AutoCaller autoCaller(this); 1176 if (FAILED(autoCaller.rc())) 1177 return autoCaller.rc(); 1178 1124 HRESULT EventSource::getEvent(const ComPtr<IEventListener> &aListener, 1125 LONG aTimeout, 1126 ComPtr<IEvent> &aEvent) 1127 { 1179 1128 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1180 1129 … … 1184 1133 1185 1134 Listeners::iterator it = m->mListeners.find(aListener); 1186 HRESULT rc; 1135 HRESULT rc = S_OK; 1136 1137 IEvent *ae = aEvent; 1187 1138 1188 1139 if (it != m->mListeners.end()) 1189 rc = it->second.obj()->dequeue( aEvent, aTimeout, alock);1140 rc = it->second.obj()->dequeue(&ae, aTimeout, alock); 1190 1141 else 1191 1142 rc = setError(VBOX_E_OBJECT_NOT_FOUND, … … 1198 1149 } 1199 1150 1200 STDMETHODIMP EventSource::EventProcessed(IEventListener *aListener, 1201 IEvent *aEvent) 1202 { 1203 CheckComArgNotNull(aListener); 1204 CheckComArgNotNull(aEvent); 1205 1206 AutoCaller autoCaller(this); 1207 if (FAILED(autoCaller.rc())) 1208 return autoCaller.rc(); 1209 1151 HRESULT EventSource::eventProcessed(const ComPtr<IEventListener> &aListener, 1152 const ComPtr<IEvent> &aEvent) 1153 { 1210 1154 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 1211 1155 … … 1391 1335 1392 1336 // internal public 1393 HRESULT init( ComSafeArrayIn(IEventSource *, aSources));1337 HRESULT init(const std::vector<ComPtr<IEventSource> > aSourcesIn); 1394 1338 1395 1339 // IEventSource methods … … 1423 1367 NS_DECL_CLASSINFO(PassiveEventListener) 1424 1368 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(PassiveEventListener, IEventListener) 1425 NS_DECL_CLASSINFO(VBoxEvent)1426 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxEvent, IEvent)1427 NS_DECL_CLASSINFO(VBoxVetoEvent)1428 1369 NS_IMPL_ISUPPORTS_INHERITED1(VBoxVetoEvent, VBoxEvent, IVetoEvent) 1429 NS_DECL_CLASSINFO(EventSource)1430 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSource, IEventSource)1431 1370 NS_DECL_CLASSINFO(EventSourceAggregator) 1432 1371 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(EventSourceAggregator, IEventSource) … … 1434 1373 1435 1374 1436 STDMETHODIMP EventSource::CreateListener(IEventListener **aListener) 1437 { 1438 CheckComArgOutPointerValid(aListener); 1439 1440 AutoCaller autoCaller(this); 1441 if (FAILED(autoCaller.rc())) 1442 return autoCaller.rc(); 1443 1375 HRESULT EventSource::createListener(ComPtr<IEventListener> &aListener) 1376 { 1444 1377 ComObjPtr<PassiveEventListener> listener; 1445 1378 … … 1447 1380 ComAssertMsgRet(SUCCEEDED(rc), ("Could not create wrapper object (%Rhrc)", rc), 1448 1381 E_FAIL); 1449 listener.queryInterfaceTo(aListener); 1450 return S_OK; 1451 } 1452 1453 1454 STDMETHODIMP EventSource::CreateAggregator(ComSafeArrayIn(IEventSource *, aSubordinates), 1455 IEventSource **aResult) 1456 { 1457 CheckComArgOutPointerValid(aResult); 1458 1459 AutoCaller autoCaller(this); 1460 if (FAILED(autoCaller.rc())) 1461 return autoCaller.rc(); 1462 1382 listener.queryInterfaceTo(aListener.asOutParam()); 1383 return S_OK; 1384 } 1385 1386 HRESULT EventSource::createAggregator(const std::vector<ComPtr<IEventSource> > &aSubordinates, 1387 ComPtr<IEventSource> &aResult) 1388 { 1463 1389 ComObjPtr<EventSourceAggregator> agg; 1464 1390 … … 1467 1393 E_FAIL); 1468 1394 1469 rc = agg->init( ComSafeArrayInArg(aSubordinates));1395 rc = agg->init(aSubordinates); 1470 1396 if (FAILED(rc)) 1471 1397 return rc; 1472 1398 1473 agg.queryInterfaceTo(aResult );1474 return S_OK; 1475 } 1476 1477 HRESULT EventSourceAggregator::init( ComSafeArrayIn(IEventSource *, aSourcesIn))1399 agg.queryInterfaceTo(aResult.asOutParam()); 1400 return S_OK; 1401 } 1402 1403 HRESULT EventSourceAggregator::init(const std::vector<ComPtr<IEventSource> > aSourcesIn) 1478 1404 { 1479 1405 HRESULT rc; … … 1489 1415 E_FAIL); 1490 1416 1491 com::SafeIfaceArray<IEventSource> aSources(ComSafeArrayInArg (aSourcesIn)); 1492 1493 size_t cSize = aSources.size(); 1494 1495 for (size_t i = 0; i < cSize; i++) 1496 { 1497 if (aSources[i] != NULL) 1498 mEventSources.push_back(aSources[i]); 1417 for (size_t i = 0; i < aSourcesIn.size(); i++) 1418 { 1419 if (aSourcesIn[i] != NULL) 1420 mEventSources.push_back(aSourcesIn[i]); 1499 1421 } 1500 1422
Note:
See TracChangeset
for help on using the changeset viewer.