binder: Expose an aidl interface module
[mech_eap.git] / wpa_supplicant / binder / binder_manager.cpp
index 9c35b23..62a1d36 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <binder/IServiceManager.h>
 
+#include "binder_constants.h"
 #include "binder_manager.h"
 
 extern "C" {
@@ -18,10 +19,8 @@ extern "C" {
 
 namespace wpa_supplicant_binder {
 
-const char BinderManager::kBinderServiceName[] = "fi.w1.wpa_supplicant";
 BinderManager *BinderManager::instance_ = NULL;
 
-
 BinderManager * BinderManager::getInstance()
 {
        if (!instance_)
@@ -43,11 +42,65 @@ int BinderManager::registerBinderService(struct wpa_global *global)
        /* Create the main binder service object and register with
         * system service manager. */
        supplicant_object_ = new Supplicant(global);
-       android::String16 service_name(kBinderServiceName);
+       android::String16 service_name(binder_constants::kServiceName);
        android::defaultServiceManager()->addService(
                service_name,
                android::IInterface::asBinder(supplicant_object_));
        return 0;
 }
 
+
+int BinderManager::registerInterface(struct wpa_supplicant *wpa_s)
+{
+       if (!wpa_s)
+               return 1;
+
+       /* Using the corresponding wpa_supplicant pointer as key to our
+        * object map. */
+       const void *iface_key = wpa_s;
+
+       /* Return failure if we already have an object for that iface_key. */
+       if (iface_object_map_.find(iface_key) != iface_object_map_.end())
+               return 1;
+
+       iface_object_map_[iface_key] = new Iface(wpa_s);
+       if (!iface_object_map_[iface_key].get())
+               return 1;
+
+       wpa_s->binder_object_key = iface_key;
+
+       return 0;
+}
+
+
+int BinderManager::unregisterInterface(struct wpa_supplicant *wpa_s)
+{
+       if (!wpa_s || !wpa_s->binder_object_key)
+               return 1;
+
+       const void *iface_key = wpa_s;
+       if (iface_object_map_.find(iface_key) == iface_object_map_.end())
+               return 1;
+
+       /* Delete the corresponding iface object from our map. */
+       iface_object_map_.erase(iface_key);
+       wpa_s->binder_object_key = NULL;
+       return 0;
+}
+
+
+int BinderManager::getIfaceBinderObjectByKey(
+       const void *iface_object_key,
+       android::sp<fi::w1::wpa_supplicant::IIface> *iface_object)
+{
+       if (!iface_object_key || !iface_object)
+               return 1;
+
+       if (iface_object_map_.find(iface_object_key) == iface_object_map_.end())
+               return 1;
+
+       *iface_object = iface_object_map_[iface_object_key];
+       return 0;
+}
+
 } /* namespace wpa_supplicant_binder */