Loading configstore/Android.bp +1 −0 Original line number Diff line number Diff line // This is an autogenerated file, do not edit. subdirs = [ "1.0", "utils", ] configstore/utils/Android.bp 0 → 100644 +28 −0 Original line number Diff line number Diff line // // Copyright (C) 2017 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. // cc_library_static { name: "android.hardware.configstore-utils", export_include_dirs: ["include"], srcs: [], shared_libs: [ "android.hardware.configstore@1.0", ], export_shared_lib_headers: [ "android.hardware.configstore@1.0", ], } configstore/utils/include/configstore/Utils.h 0 → 100644 +94 −0 Original line number Diff line number Diff line // // Copyright (C) 2017 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 ANDROID_HARDWARE_CONFIGSTORE_UTILS_H #define ANDROID_HARDWARE_CONFIGSTORE_UTILS_H #include <hidl/Status.h> #include <stdatomic.h> namespace android { namespace hardware { namespace configstore { // arguments V: type for the value (i.e., OptionalXXX) // I: interface class name // func: member function pointer using namespace V1_0; template<typename V, typename I, android::hardware::Return<void> (I::* func) (std::function<void(const V&)>)> decltype(V::value) get(const decltype(V::value) &defValue) { auto getHelper = []()->V { V ret; sp<I> configs = I::getService(); if (!configs.get()) { // fallback to the default value ret.specified = false; } else { (*configs.*func)([&ret](V v) { ret = v; }); } return ret; }; static V cachedValue = getHelper(); return cachedValue.specified ? cachedValue.value : defValue; } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalBool&)>)> bool getBool(const bool defValue) { return get<OptionalBool, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalInt32&)>)> int32_t getInt32(const int32_t defValue) { return get<OptionalInt32, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalUInt32&)>)> uint32_t getUInt32(const uint32_t defValue) { return get<OptionalUInt32, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalInt64&)>)> int64_t getInt64(const int64_t defValue) { return get<OptionalInt64, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalUInt64&)>)> uint64_t getUInt64(const uint64_t defValue) { return get<OptionalUInt64, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalString&)>)> std::string getString(const std::string &defValue) { return get<OptionalString, I, func>(defValue); } } // namespace configstore } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_CONFIGSTORE_UTILS_H Loading
configstore/Android.bp +1 −0 Original line number Diff line number Diff line // This is an autogenerated file, do not edit. subdirs = [ "1.0", "utils", ]
configstore/utils/Android.bp 0 → 100644 +28 −0 Original line number Diff line number Diff line // // Copyright (C) 2017 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. // cc_library_static { name: "android.hardware.configstore-utils", export_include_dirs: ["include"], srcs: [], shared_libs: [ "android.hardware.configstore@1.0", ], export_shared_lib_headers: [ "android.hardware.configstore@1.0", ], }
configstore/utils/include/configstore/Utils.h 0 → 100644 +94 −0 Original line number Diff line number Diff line // // Copyright (C) 2017 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 ANDROID_HARDWARE_CONFIGSTORE_UTILS_H #define ANDROID_HARDWARE_CONFIGSTORE_UTILS_H #include <hidl/Status.h> #include <stdatomic.h> namespace android { namespace hardware { namespace configstore { // arguments V: type for the value (i.e., OptionalXXX) // I: interface class name // func: member function pointer using namespace V1_0; template<typename V, typename I, android::hardware::Return<void> (I::* func) (std::function<void(const V&)>)> decltype(V::value) get(const decltype(V::value) &defValue) { auto getHelper = []()->V { V ret; sp<I> configs = I::getService(); if (!configs.get()) { // fallback to the default value ret.specified = false; } else { (*configs.*func)([&ret](V v) { ret = v; }); } return ret; }; static V cachedValue = getHelper(); return cachedValue.specified ? cachedValue.value : defValue; } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalBool&)>)> bool getBool(const bool defValue) { return get<OptionalBool, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalInt32&)>)> int32_t getInt32(const int32_t defValue) { return get<OptionalInt32, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalUInt32&)>)> uint32_t getUInt32(const uint32_t defValue) { return get<OptionalUInt32, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalInt64&)>)> int64_t getInt64(const int64_t defValue) { return get<OptionalInt64, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalUInt64&)>)> uint64_t getUInt64(const uint64_t defValue) { return get<OptionalUInt64, I, func>(defValue); } template<typename I, android::hardware::Return<void> (I::* func) (std::function<void(const OptionalString&)>)> std::string getString(const std::string &defValue) { return get<OptionalString, I, func>(defValue); } } // namespace configstore } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_CONFIGSTORE_UTILS_H