binder: Add binder skeletal code for Android
[mech_eap.git] / wpa_supplicant / binder / binder_manager.cpp
1 /*
2  * binder interface for wpa_supplicant daemon
3  * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9
10 #include <binder/IServiceManager.h>
11
12 #include "binder_manager.h"
13
14 extern "C" {
15 #include "utils/includes.h"
16 #include "utils/common.h"
17 }
18
19 namespace wpa_supplicant_binder {
20
21 const char BinderManager::kBinderServiceName[] = "fi.w1.wpa_supplicant";
22 BinderManager *BinderManager::instance_ = NULL;
23
24
25 BinderManager * BinderManager::getInstance()
26 {
27         if (!instance_)
28                 instance_ = new BinderManager();
29         return instance_;
30 }
31
32
33 void BinderManager::destroyInstance()
34 {
35         if (instance_)
36                 delete instance_;
37         instance_ = NULL;
38 }
39
40
41 int BinderManager::registerBinderService(struct wpa_global *global)
42 {
43         /* Create the main binder service object and register with
44          * system service manager. */
45         supplicant_object_ = new Supplicant(global);
46         android::String16 service_name(kBinderServiceName);
47         android::defaultServiceManager()->addService(
48                 service_name,
49                 android::IInterface::asBinder(supplicant_object_));
50         return 0;
51 }
52
53 } /* namespace wpa_supplicant_binder */