1 /* 2 Derived from source code of TrueCrypt 7.1a, which is 3 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed 4 by the TrueCrypt License 3.0. 5 6 Modifications and additions to the original source code (contained in this file) 7 and all other portions of this file are Copyright (c) 2013-2017 IDRIX 8 and are governed by the Apache License 2.0 the full text of which is 9 contained in the file License.txt included in VeraCrypt binary and source 10 code distribution packages. 11 */ 12 13 #include "Event.h" 14 15 namespace VeraCrypt 16 { 17 void Event::Connect (const EventConnectorBase &connector) 18 { 19 ScopeLock lock (HandlersMutex); 20 ConnectedHandlers.push_back (shared_ptr <EventConnectorBase> (connector.CloneNew())); 21 } 22 23 void Event::Disconnect (void *handler) 24 { 25 ScopeLock lock (HandlersMutex); 26 27 EventHandlerList newConnectedHandlers; 28 foreach (shared_ptr <EventConnectorBase> h, ConnectedHandlers) 29 { 30 if (h->GetHandler() != handler) 31 newConnectedHandlers.push_back (h); 32 } 33 34 ConnectedHandlers = newConnectedHandlers; 35 } 36 37 void Event::Raise () 38 { 39 EventArgs args; 40 Raise (args); 41 } 42 43 void Event::Raise (EventArgs &args) 44 { 45 ScopeLock lock (HandlersMutex); 46 foreach_ref (EventConnectorBase &handler, ConnectedHandlers) 47 { 48 handler (args); 49 } 50 } 51 }