Implement AppControl class
authorJoonghyun Cho <jh5.cho@samsung.com>
Tue, 14 Apr 2015 01:07:58 +0000 (10:07 +0900)
committerJoonghyun Cho <jh5.cho@samsung.com>
Wed, 15 Apr 2015 08:49:41 +0000 (17:49 +0900)
Change-Id: Ic248039261621aada5a59c1d45c0e89f68d07bab

packaging/wrt.spec
src/runtime/CMakeLists.txt
src/runtime/app_control.cc [new file with mode: 0644]
src/runtime/app_control.h [new file with mode: 0644]

index c7f9f83..9ffd028 100755 (executable)
@@ -12,6 +12,8 @@ Source0:    %{name}-%{version}.tar.gz
 
 BuildRequires: cmake
 BuildRequires: edje-tools
+BuildRequires: pkgconfig(appsvc)
+BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(capi-appfw-application)
index f86405e..ebe254a 100755 (executable)
@@ -11,6 +11,8 @@ IF(WAYLAND_SUPPORT)
 ENDIF(WAYLAND_SUPPORT)
 
 PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS
+  appsvc
+  bundle
   dlog
   ${WIN_PKG}
   elementary
@@ -34,6 +36,7 @@ SET(TARGET_RUNTIME_LIBS
 
 # Source Files
 SET(TARGET_RUNTIME_SRCS
+  ${BASE_SRCDIR}/runtime/app_control.cc
   ${BASE_SRCDIR}/runtime/command_line.cc
   ${BASE_SRCDIR}/runtime/native_window.cc
   ${BASE_SRCDIR}/runtime/native_app_window.cc
diff --git a/src/runtime/app_control.cc b/src/runtime/app_control.cc
new file mode 100644 (file)
index 0000000..8c87041
--- /dev/null
@@ -0,0 +1,135 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "runtime/app_control.h"
+
+#include <appsvc.h>
+#include <algorithm>
+#include <memory>
+
+#include "common/logger.h"
+
+namespace wrt {
+
+namespace {
+}  // namespace
+
+AppControl::AppControl(app_control_h app_control) {
+  app_control_to_bundle(app_control, &app_control_bundle_);
+  bundle_encode(app_control_bundle_, &app_control_bundle_raw_,
+                &app_control_bundle_raw_len_);
+}
+
+AppControl::~AppControl() {
+  if (app_control_bundle_ != NULL) {
+    bundle_free(app_control_bundle_);
+  }
+  if (app_control_bundle_raw_ != NULL) {
+    bundle_free_encoded_rawdata(&app_control_bundle_raw_);
+  }
+}
+
+std::string AppControl::operation() const {
+  const char* operation = appsvc_get_operation(app_control_bundle_);
+
+  if (operation != NULL) {
+    return std::string(operation);
+  } else {
+    return std::string();
+  }
+}
+
+std::string AppControl::mime() const {
+  const char* mime = appsvc_get_mime(app_control_bundle_);
+
+  if (mime != NULL) {
+    return std::string(mime);
+  } else {
+    return std::string();
+  }
+}
+
+std::string AppControl::uri() const {
+  const char* uri = appsvc_get_uri(app_control_bundle_);
+
+  if (uri != NULL) {
+    return std::string(uri);
+  } else {
+    return std::string();
+  }
+}
+
+std::string AppControl::category() const {
+  const char* category = appsvc_get_category(app_control_bundle_);
+
+  if (category != NULL) {
+    return std::string(category);
+  } else {
+    return std::string();
+  }
+}
+
+std::string AppControl::data(const std::string& key) const {
+  const char* data = appsvc_get_data(app_control_bundle_, key.c_str());
+
+  if (data != NULL) {
+    return std::string(data);
+  } else {
+    return std::string();
+  }
+}
+
+std::vector<std::string> AppControl::data_array(const std::string& key) const {
+  int data_array_len = 0;
+  const char** data_array = appsvc_get_data_array(app_control_bundle_,
+                                                  key.c_str(), &data_array_len);
+  std::vector<std::string> data_vector;
+
+  if (data_array_len > 0) {
+    for (int i = 0; i < data_array_len; i++) {
+      data_vector.push_back(data_array[i]);
+    }
+  }
+  return data_vector;
+}
+
+std::string AppControl::encoded_bundle() const {
+  return std::string(reinterpret_cast<char*>(app_control_bundle_raw_),
+                     app_control_bundle_raw_len_);
+}
+
+bool AppControl::IsDataArray(const std::string& key) {
+  return appsvc_data_is_array(app_control_bundle_, key.c_str());
+}
+
+bool AppControl::AddData(const std::string& key, const std::string& value) {
+  int result = appsvc_add_data(app_control_bundle_, key.c_str(), value.c_str());
+  if (result < 0) {
+    LoggerE("AppControl::AddData Fail");
+    return false;
+  } else {
+    return true;
+  }
+}
+
+bool AppControl::AddDataArray(const std::string& key,
+                              const std::vector<std::string>& value_array) {
+  int n = value_array.size();
+  std::vector<const char*> v;
+  std::for_each(value_array.begin(), value_array.end(),
+                [&v] (std::string str) {
+                  v.push_back(static_cast<const char*>(str.c_str()));
+                });
+
+  int result = appsvc_add_data_array(app_control_bundle_, key.c_str(),
+                                     v.data(), n);
+  if (result < 0) {
+    LoggerE("AppControl::AddDataArray Fail");
+    return false;
+  } else {
+    return true;
+  }
+}
+
+}  // namespace wrt
diff --git a/src/runtime/app_control.h b/src/runtime/app_control.h
new file mode 100644 (file)
index 0000000..662f63a
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WRT_RUNTIME_APP_CONTROL_H_
+#define WRT_RUNTIME_APP_CONTROL_H_
+
+#include <app_control.h>
+#include <bundle.h>
+#include <string>
+#include <vector>
+
+namespace wrt {
+
+class AppControl {
+ public:
+  explicit AppControl(app_control_h app_control);
+  ~AppControl();
+
+  std::string operation() const;
+  std::string mime() const;
+  std::string uri() const;
+  std::string category() const;
+  std::string data(const std::string& key) const;
+  std::vector<std::string> data_array(const std::string& key) const;
+  std::string encoded_bundle() const;
+
+  bool IsDataArray(const std::string& key);
+  bool AddData(const std::string& key, const std::string& value);
+  bool AddDataArray(const std::string& key,
+                    const std::vector<std::string>& value_array);
+
+ private:
+  bundle* app_control_bundle_;
+  bundle_raw* app_control_bundle_raw_;
+  int app_control_bundle_raw_len_;
+};
+
+}  // namespace wrt
+
+#endif  // WRT_RUNTIME_APP_CONTROL_H_