diff options
author | Bertrand SIMONNET <bsimonnet@google.com> | 2016-03-01 14:29:01 -0800 |
---|---|---|
committer | Bertrand Simonnet <bsimonnet@google.com> | 2016-03-03 20:06:17 +0000 |
commit | f866d3a310074b5e7e5ca491d676a562d7d3bde2 (patch) | |
tree | 568a69104071b52b17d1853f860f2bbc1fd63f28 | |
parent | 933ced6dcece5eccb48eef26c47f710192b45bc9 (diff) | |
download | peripheralmanager-f866d3a310074b5e7e5ca491d676a562d7d3bde2.tar.gz |
Consolidate constants for client and daemon.
Instead of defining the enum constants twice, consolidate them into a
header only library.
Bug: 27435044
Change-Id: I768375aabb53caa1baa5f3973c39ae0ec4fee43f
-rw-r--r-- | client/Android.mk | 5 | ||||
-rw-r--r-- | client/gpio_impl.cc | 55 | ||||
-rw-r--r-- | client/gpio_impl.h | 11 | ||||
-rw-r--r-- | client/wrapper.cc | 18 | ||||
-rw-r--r-- | common/peripheralmanager/constants.h | 42 | ||||
-rw-r--r-- | daemon/Android.mk | 3 | ||||
-rw-r--r-- | daemon/gpio_driver.h | 10 | ||||
-rw-r--r-- | daemon/gpio_driver_sysfs.cc | 4 | ||||
-rw-r--r-- | daemon/gpio_driver_sysfs.h | 2 | ||||
-rw-r--r-- | daemon/gpio_manager.h | 2 | ||||
-rw-r--r-- | daemon/peripheral_manager_client.cc | 2 |
11 files changed, 131 insertions, 23 deletions
diff --git a/client/Android.mk b/client/Android.mk index 762c5dd..9b92b9c 100644 --- a/client/Android.mk +++ b/client/Android.mk @@ -18,7 +18,10 @@ LOCAL_PATH := $(call my-dir) libperipheralman_CommonCFlags := -Wall -Werror -Wno-unused-parameter libperipheralman_CommonCFlags += -Wno-sign-promo # for libchrome -libperipheralman_CommonCIncludes := $(LOCAL_PATH)/../include +libperipheralman_CommonCIncludes := \ + $(LOCAL_PATH)/../common \ + $(LOCAL_PATH)/../include \ + libperipheralman_CommonSharedLibraries := \ libbinder \ libbinderwrapper \ diff --git a/client/gpio_impl.cc b/client/gpio_impl.cc index 1caa800..ce16c3d 100644 --- a/client/gpio_impl.cc +++ b/client/gpio_impl.cc @@ -18,26 +18,75 @@ #include <binder/Status.h> +#include "peripheralmanager/constants.h" #include "peripheralmanager/errors.h" +#include "peripheralmanager/gpio.h" using android::binder::Status; using android::os::IPeripheralManagerClient; +using android::GpioActiveType; +using android::GpioDirection; +using android::GpioEdgeType; + +bool ActiveTypeFromInt(int type, GpioActiveType* out) { + if (type == ACTIVE_LOW) { + *out = android::kActiveLow; + return true; + } else if (type == ACTIVE_HIGH) { + *out = android::kActiveHigh; + return true; + } + return false; +} + +bool DirectionFromInt(int direction, android::GpioDirection* out) { + switch (direction) { + case DIRECTION_IN: + *out = android::kDirectionIn; + return true; + case DIRECTION_OUT_INITIALLY_HIGH: + *out = android::kDirectionOutInitiallyHigh; + return true; + case DIRECTION_OUT_INITIALLY_LOW: + *out = android::kDirectionOutInitiallyLow; + return true; + } + return false; +} + +bool EdgeTypeFromInt(int type, android::GpioEdgeType* out) { + switch (type) { + case NONE_EDGE: + *out = android::kEdgeNone; + return true; + case RISING_EDGE: + *out = android::kEdgeRising; + return true; + case FALLING_EDGE: + *out = android::kEdgeFalling; + return true; + case BOTH_EDGE: + *out = android::kEdgeBoth; + return true; + } + return false; +} GpioImpl::GpioImpl(const std::string name, android::sp<IPeripheralManagerClient> client) : name_(name), client_(client) {} -int GpioImpl::SetDirection(int direction) { +int GpioImpl::SetDirection(GpioDirection direction) { Status ret = client_->SetGpioDirection(name_, direction); return ret.serviceSpecificErrorCode(); } -int GpioImpl::SetEdgeTriggerType(int type) { +int GpioImpl::SetEdgeTriggerType(GpioEdgeType type) { Status ret = client_->SetGpioEdge(name_, type); return ret.serviceSpecificErrorCode(); } -int GpioImpl::SetActiveType(int type) { +int GpioImpl::SetActiveType(GpioActiveType type) { Status ret = client_->SetGpioActiveType(name_, type); return ret.serviceSpecificErrorCode(); } diff --git a/client/gpio_impl.h b/client/gpio_impl.h index 8d515f9..aeb3285 100644 --- a/client/gpio_impl.h +++ b/client/gpio_impl.h @@ -21,17 +21,22 @@ #include <android/os/IPeripheralManagerClient.h> #include <utils/StrongPointer.h> +#include "peripheralmanager/constants.h" + +bool ActiveTypeFromInt(int type, android::GpioActiveType* out); +bool DirectionFromInt(int direction, android::GpioDirection* out); +bool EdgeTypeFromInt(int type, android::GpioEdgeType* out); class GpioImpl { public: GpioImpl(const std::string name, android::sp<android::os::IPeripheralManagerClient> client); - int SetDirection(int direction); + int SetDirection(android::GpioDirection direction); - int SetEdgeTriggerType(int type); + int SetEdgeTriggerType(android::GpioEdgeType type); - int SetActiveType(int type); + int SetActiveType(android::GpioActiveType type); int SetValue(int value); diff --git a/client/wrapper.cc b/client/wrapper.cc index 9381bda..2476b21 100644 --- a/client/wrapper.cc +++ b/client/wrapper.cc @@ -56,15 +56,27 @@ int BPeripheralManagerClient_openGpio(const BPeripheralManagerClient* client, } int BGpio_setDirection(const BGpio* gpio, int direction) { - return gpio->impl->SetDirection(direction); + android::GpioDirection dir; + if (!DirectionFromInt(direction, &dir)) + return PERIPHERAL_IO_UNKNOWN; + + return gpio->impl->SetDirection(dir); } int BGpio_setEdgeTriggerType(const BGpio* gpio, int type) { - return gpio->impl->SetEdgeTriggerType(type); + android::GpioEdgeType t; + if (!EdgeTypeFromInt(type, &t)) + return PERIPHERAL_IO_UNKNOWN; + + return gpio->impl->SetEdgeTriggerType(t); } int BGpio_setActiveType(const BGpio* gpio, int type) { - return gpio->impl->SetActiveType(type); + android::GpioActiveType t; + if (!ActiveTypeFromInt(type, &t)) + return PERIPHERAL_IO_UNKNOWN; + + return gpio->impl->SetActiveType(t); } int BGpio_setValue(const BGpio* gpio, int value) { diff --git a/common/peripheralmanager/constants.h b/common/peripheralmanager/constants.h new file mode 100644 index 0000000..ce9c32a --- /dev/null +++ b/common/peripheralmanager/constants.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 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_PERIPHERALMANAGER_CONSTANTS_H_ +#define SYSTEM_PERIPHERALMANAGER_PERIPHERALMANAGER_CONSTANTS_H_ + +namespace android { + +enum GpioEdgeType { + kEdgeNone, + kEdgeRising, + kEdgeFalling, + kEdgeBoth, +}; + +enum GpioDirection { + kDirectionIn, + kDirectionOutInitiallyHigh, + kDirectionOutInitiallyLow, +}; + +enum GpioActiveType { + kActiveLow, + kActiveHigh, +}; + +} // namespace android + +#endif // SYSTEM_PERIPHERALMANAGER_PERIPHERALMANAGER_CONSTANTS_H_ diff --git a/daemon/Android.mk b/daemon/Android.mk index a34ae75..3689d38 100644 --- a/daemon/Android.mk +++ b/daemon/Android.mk @@ -19,6 +19,7 @@ LOCAL_PATH := $(call my-dir) peripheralman_CommonCFlags := -Wall -Werror -Wno-unused-parameter peripheralman_CommonCFlags += -Wno-sign-promo # for libchrome peripheralman_CommonCIncludes := \ + $(LOCAL_PATH)/../common \ $(LOCAL_PATH)/../include \ external/gtest/include \ @@ -37,6 +38,8 @@ LOCAL_MODULE := peripheralman LOCAL_REQUIRED_MODULES := peripheralman.rc LOCAL_CPP_EXTENSION := .cc LOCAL_CFLAGS := $(peripheralman_CommonCFlags) +LOCAL_C_INCLUDES := $(peripheralman_CommonCIncludes) + LOCAL_STATIC_LIBRARIES := \ libperipheralman_internal \ libperipheralman_binder \ diff --git a/daemon/gpio_driver.h b/daemon/gpio_driver.h index b160a41..ecfd2d3 100644 --- a/daemon/gpio_driver.h +++ b/daemon/gpio_driver.h @@ -23,16 +23,10 @@ #include <string> #include <base/macros.h> +#include <peripheralmanager/constants.h> namespace android { -// TODO(leecam): Get this from the hal header when it lands. -enum Direction { - kDirectionIn, - kDirectionOutInitiallyHigh, - kDirectionOutInitiallyLow, -}; - // This interface must be implemented by all // Gpio drivers. class GpioDriverInterface { @@ -45,7 +39,7 @@ class GpioDriverInterface { virtual bool SetValue(bool val) = 0; virtual bool GetValue(bool* val) = 0; - virtual bool SetDirection(Direction direction) = 0; + virtual bool SetDirection(GpioDirection direction) = 0; }; // The following is driver boilerplate. diff --git a/daemon/gpio_driver_sysfs.cc b/daemon/gpio_driver_sysfs.cc index ecc83ce..1d51eac 100644 --- a/daemon/gpio_driver_sysfs.cc +++ b/daemon/gpio_driver_sysfs.cc @@ -93,7 +93,7 @@ bool GpioDriverSysfs::GetValue(bool* val) { return true; } -bool GpioDriverSysfs::SetDirection(Direction direction) { +bool GpioDriverSysfs::SetDirection(GpioDirection direction) { switch (direction) { case kDirectionIn: return WriteToFile(kDirection, kDirIn); @@ -167,4 +167,4 @@ bool GpioDriverSysfs::ExportGpio(uint32_t index) { return true; } -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/daemon/gpio_driver_sysfs.h b/daemon/gpio_driver_sysfs.h index 7fce7c0..0aca650 100644 --- a/daemon/gpio_driver_sysfs.h +++ b/daemon/gpio_driver_sysfs.h @@ -37,7 +37,7 @@ class GpioDriverSysfs : public GpioDriverInterface { // Gpio Driver interface. bool SetValue(bool val) override; bool GetValue(bool* val) override; - bool SetDirection(Direction direction) override; + bool SetDirection(GpioDirection direction) override; private: bool Enable(); diff --git a/daemon/gpio_manager.h b/daemon/gpio_manager.h index 177af84..c0072bf 100644 --- a/daemon/gpio_manager.h +++ b/daemon/gpio_manager.h @@ -53,7 +53,7 @@ class GpioPin { bool GetValue(bool* val) { return pin_->driver_->GetValue(val); } - bool SetDirection(Direction direction) { + bool SetDirection(GpioDirection direction) { if (!pin_->mux.empty()) { bool dir = true; if (direction == kDirectionIn) diff --git a/daemon/peripheral_manager_client.cc b/daemon/peripheral_manager_client.cc index 718cb3f..575015b 100644 --- a/daemon/peripheral_manager_client.cc +++ b/daemon/peripheral_manager_client.cc @@ -54,7 +54,7 @@ Status PeripheralManagerClient::SetGpioDirection(const std::string& name, if (!gpios_.count(name)) return Status::fromServiceSpecificError(PERIPHERAL_IO_UNKNOWN_DEVICE); - gpios_.find(name)->second->SetDirection(android::Direction(direction)); + gpios_.find(name)->second->SetDirection(GpioDirection(direction)); return Status::ok(); } |