aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Campbell <leecam@google.com>2016-01-20 23:31:46 -0800
committerLee Campbell <leecam@google.com>2016-01-21 13:56:02 -0800
commit0f7b1e25b16a5feb1e9bb58fc573943c004831ae (patch)
tree9839363641a8ee5badd56c3420108d51aa09e0be
parent3ae37fef7ae4256b43c1d54c8c7a878a668d57cb (diff)
downloadperipheralmanager-0f7b1e25b16a5feb1e9bb58fc573943c004831ae.tar.gz
peripheralman: Add dummy aidl service
Set up all the boilerplate to setup the IPC interface using AIDL. Also add an example CLI tool. Change-Id: Icd2837b99deb016f8b70e9823ba96c44fd36286f TEST: service registers and example runs.
-rw-r--r--client/Android.mk4
-rw-r--r--client/peripheral_manager_client.cc21
-rw-r--r--daemon/Android.mk17
-rw-r--r--daemon/main.cc13
-rw-r--r--daemon/peripheral_manager.cc38
-rw-r--r--daemon/peripheral_manager.h45
-rw-r--r--example/Android.mk38
-rw-r--r--example/peripheralmanager_example.cc41
-rw-r--r--include/peripheralmanager/peripheral_manager_client.h16
-rw-r--r--ipc/Android.mk25
-rw-r--r--ipc/android/os/IPeripheralManager.aidl22
11 files changed, 270 insertions, 10 deletions
diff --git a/client/Android.mk b/client/Android.mk
index 4495558..b8ba86c 100644
--- a/client/Android.mk
+++ b/client/Android.mk
@@ -20,8 +20,11 @@ libperipheralman_CommonCFlags := -Wall -Werror -Wno-unused-parameter
libperipheralman_CommonCFlags += -Wno-sign-promo # for libchrome
libperipheralman_CommonCIncludes := $(LOCAL_PATH)/../include
libperipheralman_CommonSharedLibraries := \
+ libbinder \
+ libbinderwrapper \
libbrillo \
libchrome \
+ libutils \
# libperipheralman shared library
# ========================================================
@@ -33,6 +36,7 @@ LOCAL_CFLAGS := $(libperipheralman_CommonCFlags)
LOCAL_C_INCLUDES := $(libperipheralman_CommonCIncludes)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include
LOCAL_SHARED_LIBRARIES := $(libperipheralman_CommonSharedLibraries)
+LOCAL_STATIC_LIBRARIES := libperipheralman_binder
LOCAL_SRC_FILES := \
peripheral_manager_client.cc \
diff --git a/client/peripheral_manager_client.cc b/client/peripheral_manager_client.cc
index 7cd1431..8499f53 100644
--- a/client/peripheral_manager_client.cc
+++ b/client/peripheral_manager_client.cc
@@ -16,16 +16,33 @@
#include <peripheralmanager/peripheral_manager_client.h>
+#include <android/os/IPeripheralManager.h>
+#include <base/logging.h>
+#include <binder/IBinder.h>
+#include <binderwrapper/binder_wrapper.h>
+
namespace android {
-namespace {
-} // namespace
PeripheralManagerClient::PeripheralManagerClient() {}
PeripheralManagerClient::~PeripheralManagerClient() {}
bool PeripheralManagerClient::Init() {
+ const char kServiceName[] = "android.os.IPeripheralManager";
+ sp<IBinder> pmanager_binder = BinderWrapper::Get()->GetService(kServiceName);
+ if (!pmanager_binder.get()) {
+ LOG(ERROR) << "Didn't get " << kServiceName << " service";
+ return false;
+ }
+ pmanager_ = interface_cast<os::IPeripheralManager>(pmanager_binder);
return true;
}
+int PeripheralManagerClient::AddInts(int a, int b) {
+ DCHECK(pmanager_.get());
+ int result = 0;
+ pmanager_->AddInts(a, b, &result);
+ return result;
+}
+
} // namespace android
diff --git a/daemon/Android.mk b/daemon/Android.mk
index 73ca216..02b4f60 100644
--- a/daemon/Android.mk
+++ b/daemon/Android.mk
@@ -23,8 +23,10 @@ peripheralman_CommonCIncludes := \
external/gtest/include \
peripheralman_CommonSharedLibraries := \
- libbrillo \
+ libbinder \
+ libbinderwrapper \
libchrome \
+ libutils \
# peripheralman executable
# ========================================================
@@ -34,9 +36,14 @@ LOCAL_MODULE := peripheralman
LOCAL_REQUIRED_MODULES := peripheralman.rc
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(peripheralman_CommonCFlags)
-LOCAL_STATIC_LIBRARIES := libperipheralman_internal
+LOCAL_STATIC_LIBRARIES := \
+ libperipheralman_internal \
+ libperipheralman_binder \
+
LOCAL_SHARED_LIBRARIES := \
$(peripheralman_CommonSharedLibraries) \
+ libbrillo \
+ libbrillo-binder \
LOCAL_SRC_FILES := main.cc
@@ -66,12 +73,14 @@ LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(peripheralman_CommonCFlags)
LOCAL_C_INCLUDES := $(peripheralman_CommonCIncludes)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/../include
+LOCAL_STATIC_LIBRARIES := \
+ libperipheralman_binder \
+
LOCAL_SHARED_LIBRARIES := \
$(peripheralman_CommonSharedLibraries) \
- libbrillo \
LOCAL_SRC_FILES := \
-# peripheral_manager.cc \
+ peripheral_manager.cc \
include $(BUILD_STATIC_LIBRARY)
diff --git a/daemon/main.cc b/daemon/main.cc
index 76b03c3..6d3287a 100644
--- a/daemon/main.cc
+++ b/daemon/main.cc
@@ -18,9 +18,13 @@
#include <base/logging.h>
#include <base/macros.h>
+#include <binderwrapper/binder_wrapper.h>
+#include <brillo/binder_watcher.h>
#include <brillo/daemons/daemon.h>
#include <brillo/flag_helper.h>
+#include "peripheral_manager.h"
+
namespace {
class PeripheralManagerDaemon : public brillo::Daemon {
@@ -35,12 +39,19 @@ class PeripheralManagerDaemon : public brillo::Daemon {
if (result != EX_OK)
return result;
- // TODO(leecam): Startup PeripheralManager Here
+ android::BinderWrapper::Create();
+ if (!binder_watcher_.Init())
+ return EX_OSERR;
+ if (!peripheral_manager_.Init())
+ return EX_OSERR;
LOG(INFO) << "Initialization complete";
return EX_OK;
}
+ brillo::BinderWatcher binder_watcher_;
+ android::PeripheralManager peripheral_manager_;
+
DISALLOW_COPY_AND_ASSIGN(PeripheralManagerDaemon);
};
diff --git a/daemon/peripheral_manager.cc b/daemon/peripheral_manager.cc
new file mode 100644
index 0000000..16adfbe
--- /dev/null
+++ b/daemon/peripheral_manager.cc
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "peripheral_manager.h"
+
+#include <base/logging.h>
+#include <binderwrapper/binder_wrapper.h>
+
+namespace android {
+
+PeripheralManager::PeripheralManager() {}
+
+PeripheralManager::~PeripheralManager() = default;
+
+bool PeripheralManager::Init() {
+ String8 interface_desc(getInterfaceDescriptor());
+ return BinderWrapper::Get()->RegisterService(interface_desc.string(), this);
+}
+
+Status PeripheralManager::AddInts(int32_t a, int32_t b, int32_t* _aidl_return) {
+ *_aidl_return = a + b;
+ return Status::ok();
+}
+
+} // namespace android
diff --git a/daemon/peripheral_manager.h b/daemon/peripheral_manager.h
new file mode 100644
index 0000000..8356d96
--- /dev/null
+++ b/daemon/peripheral_manager.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_H_
+#define SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_H_
+
+#include <base/macros.h>
+
+#include <android/os/BnPeripheralManager.h>
+
+using android::binder::Status;
+using android::os::BnPeripheralManager;
+
+namespace android {
+
+class PeripheralManager : public BnPeripheralManager {
+ public:
+ PeripheralManager();
+ ~PeripheralManager();
+
+ bool Init();
+
+ // IPeripheralManager Interface
+ Status AddInts(int32_t a, int32_t b, int32_t* _aidl_return);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PeripheralManager);
+};
+
+} // namespace android
+
+#endif // SYSTEM_PERIPHERALMANAGER_DAEMON_PERIPHERAL_MANAGER_H_
diff --git a/example/Android.mk b/example/Android.mk
new file mode 100644
index 0000000..82a1a6e
--- /dev/null
+++ b/example/Android.mk
@@ -0,0 +1,38 @@
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+# peripheralmanager_example executable
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := peripheralmanager_example
+LOCAL_CPP_EXTENSION := .cc
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-sign-promo # for libchrome
+LOCAL_SHARED_LIBRARIES := \
+ libbinder \
+ libbinderwrapper \
+ libbrillo \
+ libchrome \
+ libperipheralman \
+ libutils \
+
+LOCAL_SRC_FILES := \
+ peripheralmanager_example.cc \
+
+include $(BUILD_EXECUTABLE)
diff --git a/example/peripheralmanager_example.cc b/example/peripheralmanager_example.cc
new file mode 100644
index 0000000..aa2541b
--- /dev/null
+++ b/example/peripheralmanager_example.cc
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+
+#include <memory>
+
+#include <base/at_exit.h>
+#include <base/logging.h>
+#include <base/message_loop/message_loop.h>
+#include <base/sys_info.h>
+#include <base/time/time.h>
+#include <binderwrapper/binder_wrapper.h>
+#include <brillo/flag_helper.h>
+#include <peripheralmanager/peripheral_manager_client.h>
+
+int main(int argc, char* argv[]) {
+ brillo::FlagHelper::Init(argc, argv, "Example PeripheralManager client.");
+ logging::InitLogging(logging::LoggingSettings());
+ android::BinderWrapper::Create();
+
+ android::PeripheralManagerClient client;
+ CHECK(client.Init());
+
+ LOG(INFO) << "AddInts " << client.AddInts(10, 20);
+ LOG(INFO) << "Exiting";
+ return 0;
+}
diff --git a/include/peripheralmanager/peripheral_manager_client.h b/include/peripheralmanager/peripheral_manager_client.h
index e54f234..9eabb8c 100644
--- a/include/peripheralmanager/peripheral_manager_client.h
+++ b/include/peripheralmanager/peripheral_manager_client.h
@@ -14,13 +14,18 @@
* limitations under the License.
*/
-#ifndef SYSTEM_PERIPHERALMANAGER_INCLUDE_PERIPHERAL_MANAGER_H_
-#define SYSTEM_PERIPHERALMANAGER_INCLUDE_PERIPHERAL_MANAGER_H_
+#ifndef SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_
+#define SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_
#include <base/macros.h>
+#include <utils/StrongPointer.h>
namespace android {
+namespace os {
+class IPeripheralManager;
+}
+
// Used to communicate with the peripheral manager.
class PeripheralManagerClient {
public:
@@ -31,10 +36,15 @@ class PeripheralManagerClient {
// any other methods.
bool Init();
+ // Dummy method to test IPC
+ int AddInts(int a, int b);
+
private:
+ sp<os::IPeripheralManager> pmanager_;
+
DISALLOW_COPY_AND_ASSIGN(PeripheralManagerClient);
};
} // namespace android
-#endif // SYSTEM_PERIPHERALMANAGER_INCLUDE_PERIPHERAL_MANAGER_H_
+#endif // SYSTEM_PERIPHERALMANAGER_PERIPHERAL_MANAGER_CLIENT_H_
diff --git a/ipc/Android.mk b/ipc/Android.mk
new file mode 100644
index 0000000..25e5279
--- /dev/null
+++ b/ipc/Android.mk
@@ -0,0 +1,25 @@
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libperipheralman_binder
+
+LOCAL_SRC_FILES := \
+ android/os/IPeripheralManager.aidl\
+
+include $(BUILD_STATIC_LIBRARY) \ No newline at end of file
diff --git a/ipc/android/os/IPeripheralManager.aidl b/ipc/android/os/IPeripheralManager.aidl
new file mode 100644
index 0000000..6c805cf
--- /dev/null
+++ b/ipc/android/os/IPeripheralManager.aidl
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.os;
+
+interface IPeripheralManager {
+ int AddInts(int a, int b);
+} \ No newline at end of file