Create Service and ServiceManager classes
Change-Id: I363a5e4751ad83d2f4096882a6fbbeddca03acfe
diff --git a/init/keychords.cpp b/init/keychords.cpp
index c4ebdf9..7a7838d 100644
--- a/init/keychords.cpp
+++ b/init/keychords.cpp
@@ -26,20 +26,21 @@
#include "init.h"
#include "log.h"
#include "property_service.h"
+#include "service.h"
static struct input_keychord *keychords = 0;
static int keychords_count = 0;
static int keychords_length = 0;
static int keychord_fd = -1;
-void add_service_keycodes(struct service *svc)
+void add_service_keycodes(Service* svc)
{
struct input_keychord *keychord;
- int i, size;
+ size_t i, size;
- if (svc->keycodes) {
+ if (!svc->keycodes().empty()) {
/* add a new keychord to the list */
- size = sizeof(*keychord) + svc->nkeycodes * sizeof(keychord->keycodes[0]);
+ size = sizeof(*keychord) + svc->keycodes().size() * sizeof(keychord->keycodes[0]);
keychords = (input_keychord*) realloc(keychords, keychords_length + size);
if (!keychords) {
ERROR("could not allocate keychords\n");
@@ -51,11 +52,11 @@
keychord = (struct input_keychord *)((char *)keychords + keychords_length);
keychord->version = KEYCHORD_VERSION;
keychord->id = keychords_count + 1;
- keychord->count = svc->nkeycodes;
- svc->keychord_id = keychord->id;
+ keychord->count = svc->keycodes().size();
+ svc->set_keychord_id(keychord->id);
- for (i = 0; i < svc->nkeycodes; i++) {
- keychord->keycodes[i] = svc->keycodes[i];
+ for (i = 0; i < svc->keycodes().size(); i++) {
+ keychord->keycodes[i] = svc->keycodes()[i];
}
keychords_count++;
keychords_length += size;
@@ -63,7 +64,6 @@
}
static void handle_keychord() {
- struct service *svc;
int ret;
__u16 id;
@@ -76,10 +76,10 @@
// Only handle keychords if adb is enabled.
std::string adb_enabled = property_get("init.svc.adbd");
if (adb_enabled == "running") {
- svc = service_find_by_keychord(id);
+ Service* svc = ServiceManager::GetInstance().FindServiceByKeychord(id);
if (svc) {
- INFO("Starting service %s from keychord\n", svc->name);
- service_start(svc, NULL);
+ INFO("Starting service %s from keychord\n", svc->name().c_str());
+ svc->Start();
} else {
ERROR("service for keychord %d not found\n", id);
}
@@ -87,7 +87,7 @@
}
void keychord_init() {
- service_for_each(add_service_keycodes);
+ ServiceManager::GetInstance().ForEachService(add_service_keycodes);
// Nothing to do if no services require keychords.
if (!keychords) {