aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2016-01-21 11:01:05 -0800
committerBertrand SIMONNET <bsimonnet@google.com>2016-01-21 15:06:55 -0800
commit7f93d026d18ace0471397ef67992d54a6611ad23 (patch)
treeaf06abce187b331242b12a4c926b296e1169c7dc
parent9c62696baaf037b62d21829b93291ece6b530ee9 (diff)
downloadperipheralmanager-7f93d026d18ace0471397ef67992d54a6611ad23.tar.gz
peripheralman: Add the provider interface.
This ProviderInterface will be implemented by the BSP and will be used by peripheral manager to setup peripherals before handing it to the client. Bug: 26189976 Test: builds. Change-Id: I363b495e5750c65e3f95e85970b210af0af15636
-rw-r--r--daemon/Android.mk1
-rw-r--r--daemon/main.cc12
-rw-r--r--fake_provider/Android.mk39
-rw-r--r--fake_provider/fake_provider.cc69
-rw-r--r--fake_provider/include/peripheralprovider/fake_provider.h40
-rw-r--r--peripheralprovider/Android.mk26
-rw-r--r--peripheralprovider/include/peripheralprovider/provider_builder.h26
-rw-r--r--peripheralprovider/include/peripheralprovider/provider_interface.h53
8 files changed, 264 insertions, 2 deletions
diff --git a/daemon/Android.mk b/daemon/Android.mk
index 02b4f60..3fc2851 100644
--- a/daemon/Android.mk
+++ b/daemon/Android.mk
@@ -37,6 +37,7 @@ LOCAL_REQUIRED_MODULES := peripheralman.rc
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(peripheralman_CommonCFlags)
LOCAL_STATIC_LIBRARIES := \
+ libfake_peripheral_provider \
libperipheralman_internal \
libperipheralman_binder \
diff --git a/daemon/main.cc b/daemon/main.cc
index 6d3287a..7efa3b3 100644
--- a/daemon/main.cc
+++ b/daemon/main.cc
@@ -24,20 +24,28 @@
#include <brillo/flag_helper.h>
#include "peripheral_manager.h"
+#include "peripheralprovider/provider_builder.h"
+#include "peripheralprovider/provider_interface.h"
namespace {
class PeripheralManagerDaemon : public brillo::Daemon {
public:
- PeripheralManagerDaemon() = default;
+ PeripheralManagerDaemon(peripheralprovider::ProviderInterface* provider)
+ : provider_(provider){};
+
~PeripheralManagerDaemon() override = default;
private:
+ std::unique_ptr<peripheralprovider::ProviderInterface> provider_;
// brillo::Daemon:
int OnInit() override {
int result = brillo::Daemon::OnInit();
if (result != EX_OK)
return result;
+ if (!provider_->Init()) {
+ return EX_OSERR;
+ }
android::BinderWrapper::Create();
if (!binder_watcher_.Init())
@@ -60,5 +68,5 @@ class PeripheralManagerDaemon : public brillo::Daemon {
int main(int argc, char *argv[]) {
brillo::FlagHelper::Init(argc, argv, "Peripheral management daemon");
logging::InitLogging(logging::LoggingSettings());
- return PeripheralManagerDaemon().Run();
+ return PeripheralManagerDaemon(peripheralprovider::CreateProvider()).Run();
}
diff --git a/fake_provider/Android.mk b/fake_provider/Android.mk
new file mode 100644
index 0000000..e08281e
--- /dev/null
+++ b/fake_provider/Android.mk
@@ -0,0 +1,39 @@
+#
+# 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)
+
+peripheralprovider_CommonCFlags := -Wall -Werror -Wno-unused-parameter
+peripheralprovider_CommonCIncludes := \
+ $(LOCAL_PATH)/include \
+ external/gtest/include \
+
+# libfake_peripheral_provider static lib
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libfake_peripheral_provider
+LOCAL_CPP_EXTENSION := .cc
+LOCAL_CFLAGS := $(peripheralprovider_CommonCFlags)
+LOCAL_C_INCLUDES := $(peripheralprovider_CommonCIncludes)
+LOCAL_EXPORT_C_INCLUDE_DIRS := \
+ $(LOCAL_PATH)/include \
+ $(LOCAL_PATH)/../peripheralprovider/include \
+
+LOCAL_SRC_FILES := fake_provider.cc
+LOCAL_STATIC_LIBRARIES := libperipheral_provider_interface
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/fake_provider/fake_provider.cc b/fake_provider/fake_provider.cc
new file mode 100644
index 0000000..95b3f0a
--- /dev/null
+++ b/fake_provider/fake_provider.cc
@@ -0,0 +1,69 @@
+/*
+ * 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 <string>
+#include <vector>
+
+#include "peripheralprovider/fake_provider.h"
+#include "peripheralprovider/provider_builder.h"
+
+using peripheralprovider::Status;
+using std::string;
+using std::vector;
+
+bool FakeProvider::Init() {
+ return true;
+}
+
+Status FakeProvider::EnableGPIO(const string& pin_name, string* path) {
+ return Status::Ok;
+}
+
+Status FakeProvider::ReleaseGPIO(const string& pin_name) {
+ return Status::Ok;
+}
+
+vector<string> FakeProvider::ListGPIOPins() {
+ return vector<string>();
+}
+
+Status FakeProvider::EnableSPI(const string& bus_name, string* path) {
+ return Status::Ok;
+}
+
+Status FakeProvider::ReleaseSPI(const string& bus_name) {
+ return Status::Ok;
+}
+
+vector<string> FakeProvider::ListSPIBuses() {
+ return vector<string>();
+}
+
+Status FakeProvider::EnableI2C(const string& bus_name, string* path) {
+ return Status::Ok;
+}
+
+Status FakeProvider::ReleaseI2C(const string& bus_name) {
+ return Status::Ok;
+}
+
+vector<string> FakeProvider::ListI2CBuses() {
+ return vector<string>();
+}
+
+peripheralprovider::ProviderInterface* peripheralprovider::CreateProvider() {
+ return new FakeProvider();
+}
diff --git a/fake_provider/include/peripheralprovider/fake_provider.h b/fake_provider/include/peripheralprovider/fake_provider.h
new file mode 100644
index 0000000..1756b2b
--- /dev/null
+++ b/fake_provider/include/peripheralprovider/fake_provider.h
@@ -0,0 +1,40 @@
+/*
+ * 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 "peripheralprovider/provider_interface.h"
+
+class FakeProvider : public peripheralprovider::ProviderInterface {
+ public:
+ FakeProvider() = default;
+ ~FakeProvider() override{};
+
+ bool Init() override;
+
+ peripheralprovider::Status EnableGPIO(const std::string& pin_name,
+ std::string* path) override;
+ peripheralprovider::Status ReleaseGPIO(const std::string& pin_name) override;
+ std::vector<std::string> ListGPIOPins() override;
+
+ peripheralprovider::Status EnableI2C(const std::string& bus_name,
+ std::string* path) override;
+ peripheralprovider::Status ReleaseI2C(const std::string& bus_name) override;
+ std::vector<std::string> ListI2CBuses() override;
+
+ peripheralprovider::Status EnableSPI(const std::string& bus_name,
+ std::string* path) override;
+ peripheralprovider::Status ReleaseSPI(const std::string& bus_name) override;
+ std::vector<std::string> ListSPIBuses() override;
+};
diff --git a/peripheralprovider/Android.mk b/peripheralprovider/Android.mk
new file mode 100644
index 0000000..8818e38
--- /dev/null
+++ b/peripheralprovider/Android.mk
@@ -0,0 +1,26 @@
+#
+# 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)
+
+# peripheralprovider interface static lib.
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libperipheral_provider_interface
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/peripheralprovider/include/peripheralprovider/provider_builder.h b/peripheralprovider/include/peripheralprovider/provider_builder.h
new file mode 100644
index 0000000..5882e12
--- /dev/null
+++ b/peripheralprovider/include/peripheralprovider/provider_builder.h
@@ -0,0 +1,26 @@
+/*
+ * 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 PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_BUILDER_H_
+#define PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_BUILDER_H_
+
+#include "peripheralprovider/provider_interface.h"
+
+namespace peripheralprovider {
+ ProviderInterface* CreateProvider();
+}
+
+#endif // PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_BUILDER_H_
diff --git a/peripheralprovider/include/peripheralprovider/provider_interface.h b/peripheralprovider/include/peripheralprovider/provider_interface.h
new file mode 100644
index 0000000..40518ce
--- /dev/null
+++ b/peripheralprovider/include/peripheralprovider/provider_interface.h
@@ -0,0 +1,53 @@
+/*
+ * 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 PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_INTERFACE_H_
+#define PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_INTERFACE_H_
+
+#include <string>
+#include <vector>
+
+namespace peripheralprovider {
+
+enum Status {
+ Ok,
+ UnsupportedOperation,
+ ConflictingConfiguration
+};
+
+class ProviderInterface {
+ public:
+ virtual ~ProviderInterface() {};
+
+ virtual bool Init() = 0;
+
+ virtual Status EnableGPIO(const std::string& pin_name, std::string* path) = 0;
+ virtual Status ReleaseGPIO(const std::string& pin_name) = 0;
+
+ virtual std::vector<std::string> ListGPIOPins() = 0;
+
+ virtual Status EnableI2C(const std::string& bus_name, std::string* path) = 0;
+ virtual Status ReleaseI2C(const std::string& bus_name) = 0;
+ virtual std::vector<std::string> ListI2CBuses() = 0;
+
+ virtual Status EnableSPI(const std::string& bus_name, std::string* path) = 0;
+ virtual Status ReleaseSPI(const std::string& bus_name) = 0;
+ virtual std::vector<std::string> ListSPIBuses() = 0;
+};
+
+} // namespace peripheralprovider
+
+#endif // PERIPHERALMANAGER_PERIPHERALPROVIDER_PROVIDER_INTERFACE_H_