aboutsummaryrefslogtreecommitdiff
path: root/common/binder_utils.h
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2015-12-21 16:30:37 -0800
committerAlex Vakulenko <avakulenko@google.com>2016-01-07 16:10:17 -0800
commitae29f7d91a0b4178556eeb6b99fd05d90fcefd3d (patch)
tree9d16fd4dfa8b925ab436145905385b97cab481f2 /common/binder_utils.h
parent10e9f3a80e2d6da0eef16576a9a8fde9e8fdb108 (diff)
downloadweaved-ae29f7d91a0b4178556eeb6b99fd05d90fcefd3d.tar.gz
Add Binder support to weaved and remove D-Bus interface
Added binder-based IPC to weaved instead of D-Bus. Removed the old weave commands based on D-Bus and redesigned client library interface to be more in line with how Binder operates. BUG: 23782171, 25523591 Change-Id: Ic39a6a2edf2e033e506d233919c9d04e4fab8d01
Diffstat (limited to 'common/binder_utils.h')
-rw-r--r--common/binder_utils.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/common/binder_utils.h b/common/binder_utils.h
new file mode 100644
index 0000000..65b462d
--- /dev/null
+++ b/common/binder_utils.h
@@ -0,0 +1,63 @@
+// Copyright 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 COMMON_BINDER_UTILS_H_
+#define COMMON_BINDER_UTILS_H_
+
+#include <memory>
+#include <string>
+
+#include <base/values.h>
+#include <binder/Status.h>
+#include <utils/String8.h>
+#include <utils/String16.h>
+#include <weave/error.h>
+#include <brillo/errors/error.h>
+
+namespace weaved {
+namespace binder_utils {
+
+// Converts the result of weave API call into a binder Status object.
+// If |success| is true, return binder::Status::ok(), otherwise the method
+// constructs a service-specific failure status with an error message obtained
+// from the |error| object.
+android::binder::Status ToStatus(bool success, weave::ErrorPtr* error);
+
+// Converts a binder status code to a Brillo error object. Returns true if the
+// status was isOk(), otherwise returns false and provides error information
+// in the |error| object.
+bool StatusToError(android::binder::Status status, brillo::ErrorPtr* error);
+
+// Converts binder's UTF16 string into a regular UTF8-encoded standard string.
+inline std::string ToString(const android::String16& value) {
+ return android::String8{value}.string();
+}
+
+// Converts regular UTF8-encoded standard string into a binder's UTF16 string.
+inline android::String16 ToString16(const std::string& value) {
+ return android::String16{value.c_str()};
+}
+
+// Serializes a dictionary to a string for transferring over binder.
+android::String16 ToString16(const base::Value& value);
+
+// De-serializes a dictionary from a binder string.
+android::binder::Status ParseDictionary(
+ const android::String16& json,
+ std::unique_ptr<base::DictionaryValue>* dict);
+
+} // namespace binder_utils
+} // namespace weaved
+
+#endif // COMMON_BINDER_UTILS_H_