Update AppControl
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 20 Apr 2015 06:44:01 +0000 (15:44 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 21 Apr 2015 03:27:22 +0000 (12:27 +0900)
 - support default contructor
 - add setter
 - add launch request method

Change-Id: I2212a7671893e4668d0d6930de6e509ba6ad8d45

src/runtime/app_control.cc
src/runtime/app_control.h

index ed10b4e..42195f5 100755 (executable)
@@ -49,17 +49,17 @@ static bool BundleAddDataArray(bundle* target, const std::string& key,
 AppControl::AppControl(app_control_h app_control) {
   app_control_clone(&app_control_, 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() {
+  app_control_create(&app_control_);
+  app_control_to_bundle(app_control_, &app_control_bundle_);
 }
 
 AppControl::~AppControl() {
   if (app_control_ != NULL) {
     app_control_destroy(app_control_);
   }
-  if (app_control_bundle_raw_ != NULL) {
-    bundle_free_encoded_rawdata(&app_control_bundle_raw_);
-  }
 }
 
 std::string AppControl::operation() const {
@@ -72,6 +72,10 @@ std::string AppControl::operation() const {
   }
 }
 
+void AppControl::set_operation(const std::string& operation) {
+  appsvc_set_operation(app_control_bundle_, operation.c_str());
+}
+
 std::string AppControl::mime() const {
   const char* mime = appsvc_get_mime(app_control_bundle_);
 
@@ -82,6 +86,10 @@ std::string AppControl::mime() const {
   }
 }
 
+void AppControl::set_mime(const std::string& mime) {
+  appsvc_set_mime(app_control_bundle_, mime.c_str());
+}
+
 std::string AppControl::uri() const {
   const char* uri = appsvc_get_uri(app_control_bundle_);
 
@@ -92,6 +100,10 @@ std::string AppControl::uri() const {
   }
 }
 
+void AppControl::set_uri(const std::string& uri) {
+  appsvc_set_uri(app_control_bundle_, uri.c_str());
+}
+
 std::string AppControl::category() const {
   const char* category = appsvc_get_category(app_control_bundle_);
 
@@ -102,6 +114,10 @@ std::string AppControl::category() const {
   }
 }
 
+void AppControl::set_category(const std::string& category) {
+  appsvc_set_category(app_control_bundle_, category.c_str());
+}
+
 std::string AppControl::data(const std::string& key) const {
   const char* data = appsvc_get_data(app_control_bundle_, key.c_str());
 
@@ -126,9 +142,13 @@ std::vector<std::string> AppControl::data_array(const std::string& key) const {
   return data_vector;
 }
 
-std::string AppControl::encoded_bundle() const {
-  return std::string(reinterpret_cast<char*>(app_control_bundle_raw_),
-                     app_control_bundle_raw_len_);
+std::string AppControl::encoded_bundle() {
+  bundle_raw* encoded_data;
+  int len;
+  bundle_encode(app_control_bundle_, &encoded_data, &len);
+  std::unique_ptr<bundle_raw*, decltype(bundle_free_encoded_rawdata)*>
+    ptr { &encoded_data, bundle_free_encoded_rawdata};
+  return std::string(reinterpret_cast<char*>(encoded_data), len);
 }
 
 bool AppControl::IsDataArray(const std::string& key) {
@@ -171,4 +191,9 @@ bool AppControl::Reply(const std::map<std::string,
   return ret == APPSVC_RET_OK ? true : false;
 }
 
+bool AppControl::LaunchRequest() {
+  return (app_control_send_launch_request(app_control_, NULL, NULL) ==
+          APP_CONTROL_ERROR_NONE);
+}
+
 }  // namespace wrt
index 94c80df..f2d8fa8 100755 (executable)
@@ -16,30 +16,34 @@ namespace wrt {
 class AppControl {
  public:
   explicit AppControl(app_control_h app_control);
+  AppControl();
   ~AppControl();
   // disable copy
   AppControl(const AppControl& src) = delete;
   AppControl& operator=(const AppControl&) = delete;
 
   std::string operation() const;
+  void set_operation(const std::string& operation);
   std::string mime() const;
+  void set_mime(const std::string& mime);
   std::string uri() const;
+  void set_uri(const std::string& uri);
   std::string category() const;
+  void set_category(const std::string& category);
   std::string data(const std::string& key) const;
   std::vector<std::string> data_array(const std::string& key) const;
-  std::string encoded_bundle() const;
+  std::string encoded_bundle();
 
   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);
   bool Reply(const std::map<std::string, std::vector<std::string>>& data);
+  bool LaunchRequest();
 
  private:
   app_control_h app_control_;
   bundle* app_control_bundle_;
-  bundle_raw* app_control_bundle_raw_;
-  int app_control_bundle_raw_len_;
 };
 
 }  // namespace wrt