]> git.saurik.com Git - apple/security.git/blobdiff - Keychain/KCEventObserver.cpp
Security-163.tar.gz
[apple/security.git] / Keychain / KCEventObserver.cpp
index 09943893aa1a147af1acfe792e734c3aed55db45..416c2637a3c08914eda9768bf4185a79277b0c17 100644 (file)
 
 using namespace Security;
 
-Observer::Observer()
+void Observer::EventReceived (Listener::Domain domain, Listener::Event event, const void* data, size_t dataLength)
 {
-}
-//
-// Upon creation of this object, add this observer for this instance of KeychainCore
-//
-Observer::Observer( CFStringRef name, const void *object, 
-                    CFNotificationSuspensionBehavior suspensionBehavior )
-{
-    add( name, object, suspensionBehavior );
-}
+    secdebug("kcnotify", "Security::Observer::EventReceived got event %u", (unsigned int) event);
 
-//
-// Upon destruction of this object, remove 'this' observer for this instance of KeychainCore
-//
-Observer::~Observer()
-{
-    ::CFNotificationCenterRemoveEveryObserver( CFNotificationCenterGetDistributedCenter(), this );
+       // make a NameValueDictionary from the data we received
+       CssmData dt ((void*) data, dataLength);
+       NameValueDictionary nvd (dt);
+       Event (domain, event, nvd);
 }
 
-//
-// 'callback' is passed in to CFNotificationCenterAddObserver() when this object
-// is constructed when KeychainCore is created.  'callback' is called by CF whenever an event happens.
-//
-void Observer::callback(CFNotificationCenterRef        center, 
-                        void*                                          observer, 
-                        CFStringRef                            name, 
-                        const void*                            object, 
-                        CFDictionaryRef                        userInfo)
+
+
+Observer::Observer (Listener::Domain whichDomain, Listener::EventMask whichEvents)
 {
-    // 'Event' is where this KeychainCore notifies it's clients of the kc event that just happened.
-    //
-       try
-       {
-               reinterpret_cast<Observer *>(observer)->Event( center, name, object, userInfo );
-       }
-       catch(...)
-       {
-               // @@@ do a log to console();
-       }
+       RequestEvents (whichDomain, whichEvents);
 }
 
-//
-// Add 'this' observer to CF for this instance of KeychainCore
-//
-void Observer::add( CFStringRef                                         name, 
-                    const void*                                         object, 
-                    CFNotificationSuspensionBehavior suspensionBehavior )
+
+
+Observer::~Observer ()
 {
-    ::CFNotificationCenterAddObserver( CFNotificationCenterGetDistributedCenter(), 
-                                       this, callback, name, object, suspensionBehavior );
 }