Merge "[version] 0.57" into tizen_2.4
authorHyunjin Park <hj.na.park@samsung.com>
Mon, 12 Oct 2015 01:14:20 +0000 (10:14 +0900)
committerGerrit Code Review <gerrit@s001>
Mon, 12 Oct 2015 01:14:20 +0000 (10:14 +0900)
76 files changed:
src/alarm/alarm_manager.cc
src/application/application.cc
src/application/application_manager.cc
src/application/requested_application_control.cc
src/bluetooth/bluetooth_adapter.cc
src/bluetooth/bluetooth_device.cc
src/bluetooth/bluetooth_gatt_service.cc
src/bluetooth/bluetooth_health_application.cc
src/bluetooth/bluetooth_health_channel.cc
src/bluetooth/bluetooth_health_profile_handler.cc
src/bluetooth/bluetooth_instance.cc
src/bluetooth/bluetooth_service_handler.cc
src/bluetooth/bluetooth_socket.cc
src/callhistory/callhistory.cc
src/common/GDBus/proxy.h
src/common/callback_user_data.cc [deleted file]
src/common/callback_user_data.h [deleted file]
src/common/common.gyp
src/common/dbus_operation.cc
src/common/dbus_operation.h
src/common/extension.cc
src/common/extension.h
src/common/task-queue.cpp
src/common/task-queue.h
src/common/virtual_fs.h
src/contact/addressbook.cc
src/contact/contact_manager.cc
src/contact/contact_search_engine.cc
src/contact/contact_util.cc
src/contact/js/address_book.js
src/contact/js/common.js
src/contact/js/contact_manager.js
src/contact/js/person.js
src/contact/person.cc
src/content/content_instance.cc
src/content/content_manager.cc
src/filesystem/js/file_stream.js
src/messaging/DBus/LoadAttachmentProxy.cpp
src/messaging/DBus/LoadBodyProxy.cpp
src/messaging/DBus/SyncProxy.cpp
src/messaging/DBus/SyncProxy.h
src/messaging/callback_user_data.cc [new file with mode: 0755]
src/messaging/callback_user_data.h [new file with mode: 0755]
src/messaging/conversation_callback_data.cc
src/messaging/conversation_callback_data.h
src/messaging/conversations_change_callback.cc
src/messaging/email_manager.cc
src/messaging/email_manager.h
src/messaging/find_msg_callback_user_data.cc
src/messaging/find_msg_callback_user_data.h
src/messaging/folders_callback_data.cc
src/messaging/folders_callback_data.h
src/messaging/folders_change_callback.cc
src/messaging/message_callback_user_data.cc
src/messaging/message_callback_user_data.h
src/messaging/message_service.cc
src/messaging/message_service.h
src/messaging/message_service_email.cc
src/messaging/message_service_short_msg.cc
src/messaging/message_storage_short_msg.cc
src/messaging/messages_callback_user_data.cc
src/messaging/messages_callback_user_data.h
src/messaging/messages_change_callback.cc
src/messaging/messaging.gyp
src/messaging/messaging_instance.cc
src/messaging/short_message_manager.cc
src/power/power_manager.cc
src/power/power_manager.h
src/power/power_platform_proxy.cc
src/power/power_platform_proxy.h
src/radio/radio_manager.cc
src/secureelement/secureelement_seservice.cc
src/sensor/sensor_service.cc
src/sound/sound_manager.cc
src/systeminfo/systeminfo_manager.cc
src/utils/utils_instance.cc

index 2c37c71..cc3604c 100755 (executable)
@@ -24,6 +24,7 @@
 #include "common/logger.h"
 #include "common/converter.h"
 #include "common/scope_exit.h"
+#include "common/tools.h"
 
 #include "alarm_instance.h"
 #include "alarm_utils.h"
index d6522c5..2c54611 100755 (executable)
@@ -19,6 +19,7 @@
 #include "common/extension.h"
 #include "common/logger.h"
 #include "common/platform_result.h"
+#include "common/tools.h"
 
 using namespace common;
 using namespace tools;
index fdbd750..100372d 100755 (executable)
 #include <bundle.h>
 #include <bundle_internal.h>
 
-#include "application/application_instance.h"
-#include "application/application_utils.h"
 #include "common/current_application.h"
 #include "common/logger.h"
 #include "common/platform_result.h"
-#include "common/task-queue.h"
 #include "common/scope_exit.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
+#include "application/application_instance.h"
+#include "application/application_utils.h"
 
 using namespace common;
 using namespace tools;
index 709fe6f..de6bffd 100755 (executable)
@@ -22,6 +22,8 @@
 #include <bundle_internal.h>
 
 #include "common/logger.h"
+#include "common/tools.h"
+
 #include "application/application_utils.h"
 
 using namespace common;
index e9a3b66..6ff5fe8 100755 (executable)
 #include "bluetooth_internal.h"
 
 #include "common/converter.h"
+#include "common/extension.h"
 #include "common/logger.h"
 #include "common/platform_result.h"
-#include "common/extension.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 #include "bluetooth/bluetooth_class.h"
 #include "bluetooth/bluetooth_device.h"
index 9d9a809..5315d39 100755 (executable)
@@ -17,8 +17,9 @@
 #include "bluetooth_device.h"
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_class.h"
index e069c0f..293c0f0 100755 (executable)
 
 #include <sstream>
 
+#include "common/extension.h"
 #include "common/logger.h"
 #include "common/platform_result.h"
-#include "common/extension.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 #include "bluetooth/bluetooth_instance.h"
 #include "bluetooth/bluetooth_util.h"
index 4670815..457e5d5 100755 (executable)
@@ -17,8 +17,9 @@
 #include "bluetooth_health_application.h"
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 #include "bluetooth_health_profile_handler.h"
 #include "bluetooth_util.h"
index 3825d32..1209021 100755 (executable)
@@ -19,8 +19,9 @@
 #include <memory>
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 #include "bluetooth_device.h"
 #include "bluetooth_util.h"
index 34dc7d4..1f0432d 100755 (executable)
 #include "bluetooth_health_profile_handler.h"
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 #include "bluetooth/bluetooth_adapter.h"
 #include "bluetooth/bluetooth_instance.h"
index 2351162..c919693 100755 (executable)
@@ -19,6 +19,7 @@
 #include "common/converter.h"
 #include "common/logger.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 namespace extension {
 namespace bluetooth {
index f7b3040..d9b6e1e 100755 (executable)
@@ -17,8 +17,9 @@
 #include "bluetooth_service_handler.h"
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_util.h"
index 518223f..8f858bc 100755 (executable)
@@ -19,8 +19,9 @@
 #include <memory>
 
 #include "common/converter.h"
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_device.h"
index 5591b56..a794303 100755 (executable)
 
 #include "common/logger.h"
 #include "common/platform_exception.h"
-#include "common/task-queue.h"
 #include "common/scope_exit.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
 #include "callhistory_instance.h"
 #include "callhistory_types.h"
 
index ed00283..b394974 100644 (file)
@@ -27,7 +27,6 @@
 #include <string>
 #include <mutex>
 #include <map>
-#include "common/callback_user_data.h"
 #include "common/picojson.h"
 #include "common/platform_result.h"
 
diff --git a/src/common/callback_user_data.cc b/src/common/callback_user_data.cc
deleted file mode 100755 (executable)
index 266cbee..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    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.
- */
-
-#include "common/callback_user_data.h"
-
-namespace common {
-
-CallbackUserData::CallbackUserData() :
-    m_is_act(true) {
-}
-
-CallbackUserData::~CallbackUserData() {
-}
-
-void CallbackUserData::setActive(bool act) {
-  m_is_act = act;
-}
-
-bool CallbackUserData::isActive() const {
-  return m_is_act;
-}
-
-void CallbackUserData::setJson(std::shared_ptr<picojson::value> json) {
-  m_json = json;
-}
-
-std::shared_ptr<picojson::value> CallbackUserData::getJson() const {
-  return m_json;
-}
-
-}  // common
diff --git a/src/common/callback_user_data.h b/src/common/callback_user_data.h
deleted file mode 100755 (executable)
index 26bed79..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    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.
- */
-
-// Class added for backward compatibility with WRT plugins.
-// TODO To be cleaned/replaced in the future.
-
-#ifndef COMMON_CALLBACK_USER_DATA_H_
-#define COMMON_CALLBACK_USER_DATA_H_
-
-#include "common/picojson.h"
-
-#include <memory>
-
-namespace common {
-
-class CallbackUserData {
-public:
-  CallbackUserData();
-
-  virtual ~CallbackUserData();
-
-  void setActive(bool act);
-  bool isActive() const;
-
-  void setJson(std::shared_ptr<picojson::value> json);
-  std::shared_ptr<picojson::value> getJson() const;
-
-  virtual void setError(const std::string& err_name,
-                        const std::string& err_message) = 0;
-
-protected:
-  std::shared_ptr<picojson::value> m_json;
-
-private:
-  bool m_is_act;
-};
-
-} // common
-
-#endif  // COMMON_CALLBACK_USER_DATA_H_
index b9ac108..43567a3 100644 (file)
@@ -33,8 +33,6 @@
         'task-queue.h',
         'tools.cc',
         'tools.h',
-        'callback_user_data.cc',
-        'callback_user_data.h',
         'optional.h',
         'platform_result.cc',
         'platform_result.h',
index 3e027e6..c100397 100755 (executable)
@@ -24,8 +24,7 @@
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
-#include "logger.h"
-#include "platform_exception.h"
+#include "common/logger.h"
 
 #define DBUS_REPLY_TIMEOUT (-1)
 
@@ -105,7 +104,8 @@ void DBusOperationArguments::AddArgumentString(const std::string& val) {
     const int length = val.length();
 
     char* p_val = new char[length+1];
-    strncpy(p_val, val.c_str(), length+1); // TODO: is it safe?
+    // copy 'length' characters and add a NULL-character at 'length+1' position
+    strncpy(p_val, val.c_str(), length+1);
 
     arguments_.push_back(ArgumentElement(ArgType::kTypeString, p_val));
 }
@@ -179,73 +179,6 @@ DBusOperation::~DBusOperation() {
     }
 }
 
-int DBusOperation::InvokeSyncGetInt(const std::string& method,
-                                    DBusOperationArguments* args) {
-
-    LoggerD("Enter");
-    if (!connection_) {
-        connection_ = dbus_bus_get_private(DBUS_BUS_SYSTEM, nullptr);
-    }
-
-    if (!connection_) {
-        LoggerE("dbus_bus_get_private error");
-        throw UnknownException("Failed to get dbus connection");
-    }
-
-    DBusMessage* msg = dbus_message_new_method_call(destination_.c_str(),
-                                                    path_.c_str(),
-                                                    interface_.c_str(),
-                                                    method.c_str());
-
-    if (!msg) {
-        LoggerE("dbus_message_new_method_call error");
-        throw UnknownException("Failed to create dbus message");
-    }
-
-    DBusMessageIter iter;
-    dbus_message_iter_init_append(msg, &iter);
-
-    if (nullptr != args) {
-        try {
-            args->AppendVariant(&iter);
-        } catch (const UnknownException& ex) {
-            LoggerE("append_variant error");
-            dbus_message_unref(msg);
-            throw UnknownException("Failed to append dbus variable");
-        }
-    }
-
-    DBusError err;
-    dbus_error_init(&err);
-    DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection_,
-                                                                   msg,
-                                                                   DBUS_REPLY_TIMEOUT,
-                                                                   &err);
-    dbus_message_unref(msg);
-
-    if (!reply) {
-        LoggerE("dbus_connection_send_with_reply_and_block error %s: %s", err.name, err.message);
-        dbus_error_free(&err);
-        throw UnknownException("Failed to send request via dbus");
-    }
-
-    int result = 0;
-    dbus_bool_t ret = dbus_message_get_args(reply,
-                                            &err,
-                                            DBUS_TYPE_INT32,
-                                            &result,
-                                            DBUS_TYPE_INVALID);
-    dbus_message_unref(reply);
-
-    if (!ret) {
-        LoggerE("dbus_message_get_args error %s: %s", err.name, err.message);
-        dbus_error_free(&err);
-        throw UnknownException("Failed to get reply from dbus");
-    }
-
-    return result;
-}
-
 PlatformResult DBusOperation::InvokeSyncGetInt(const std::string& method,
                                     DBusOperationArguments* args, int* result) {
 
index 7a0d6ab..72fcb37 100755 (executable)
@@ -22,7 +22,8 @@
 #include <set>
 
 #include <dbus/dbus.h>
-#include "platform_result.h"
+
+#include "common/platform_result.h"
 
 namespace common {
 
@@ -73,9 +74,6 @@ class DBusOperation {
           const std::string& interface);
   virtual ~DBusOperation();
 
-  int InvokeSyncGetInt(const std::string& method,
-             DBusOperationArguments* args);
-  //TODO remove throwing methods when they would be not needed any more.
   common::PlatformResult InvokeSyncGetInt(const std::string& method,
              DBusOperationArguments* args, int* result);
 
index 8192686..042f0ad 100755 (executable)
@@ -9,8 +9,10 @@
 #include <vector>
 #include <string>
 #include <map>
-#include "common/logger.h"
+
 #include "common/assert.h"
+#include "common/logger.h"
+#include "common/tools.h"
 
 // This function is hidden, because each plugin needs to have own implementation.
 __attribute__ ((visibility ("hidden"))) common::Extension* CreateExtension() {
index 9fd8025..4abf525 100755 (executable)
@@ -26,9 +26,6 @@
 
 #include "common/platform_exception.h"
 #include "common/platform_result.h"
-// TODO: this include should be moved to source file
-//       it's here, so we don't break other modules using it implicitly
-#include "common/tools.h"
 #include "common/XW_Extension.h"
 #include "common/XW_Extension_EntryPoints.h"
 #include "common/XW_Extension_Permissions.h"
index 342d529..2fc305c 100755 (executable)
@@ -64,11 +64,4 @@ void TaskQueue::Async(const std::function<void()>& work) {
     g_idle_add(AfterWorkCallback<void>, d);
 }
 
-//TODO check if it would be needed in future
-//void TaskQueue::AsyncResponse(int callback_handle, const std::shared_ptr<picojson::value>& response) {
-//    Async<picojson::value>([callback_handle](const std::shared_ptr<picojson::value>& response) {
-//        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-//                                                                 response->serialize());
-//    }, response);
-//}
 } // namespace common
index a9d6d47..94df211 100755 (executable)
@@ -73,9 +73,6 @@ public:
      */
     void Async(const std::function<void()>& work);
 
-    //TODO not needed now, but maybe in future
-//    void AsyncResponse(int callback_handle, const std::shared_ptr<picojson::value>& response);
-
 private:
     TaskQueue() {}
 
index c79a8c0..e4b2551 100755 (executable)
@@ -75,8 +75,6 @@ class VirtualFs {
 
   std::vector<VirtualStorage> GetStorages() const;
 
-  // TODO: add stat method
-
   static VirtualFs& GetInstance();
 
  private:
index 570fff2..2a20319 100755 (executable)
@@ -85,6 +85,7 @@ PlatformResult AddressBookAdd(const JsonObject& args, JsonObject& out) {
   if (status.IsError()) return status;
 
   const JsonObject& contact = FromJson<JsonObject>(args, "contact");
+  long addressBookId = common::stol(FromJson<JsonString>(args, "addressBookId"));
 
   if (!IsNull(contact, "id")) {
     LoggerW("Contact already exists");
@@ -107,6 +108,10 @@ PlatformResult AddressBookAdd(const JsonObject& args, JsonObject& out) {
       ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
   if (status.IsError()) return status;
 
+  status = ContactUtil::SetIntInRecord(
+      contacts_record, _contacts_contact.address_book_id, addressBookId);
+  if (status.IsError()) return status;
+
   int id = -1;
   err = contacts_db_insert_record(*contacts_record_ptr, &id);
   if (CONTACTS_ERROR_NONE != err) {
@@ -139,7 +144,6 @@ PlatformResult AddressBookUpdate(const JsonObject& args, JsonObject& out) {
   if (status.IsError()) return status;
 
   const JsonObject& contact = FromJson<JsonObject>(args, "contact");
-  const JsonObject& addressbook = FromJson<JsonObject>(args, "addressBook");
   long contactId = common::stol(FromJson<JsonString>(contact, "id"));
 
   if (IsNull(contact, "id")) {
@@ -147,12 +151,6 @@ PlatformResult AddressBookUpdate(const JsonObject& args, JsonObject& out) {
     return PlatformResult(ErrorCode::UNKNOWN_ERR, "Contact doesn't exist");
   }
 
-  if (IsNull(addressbook, "id")) {
-    LoggerE("Contact is not saved in database");
-    return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Contact is not saved in database");
-  }
-
   contacts_record_h to_update = nullptr;
   int err = contacts_db_get_record(_contacts_contact._uri, contactId, &to_update);
   if (CONTACTS_ERROR_NONE != err) {
@@ -306,12 +304,6 @@ PlatformResult AddressBookUpdateBatch(const JsonObject& args, JsonArray& out) {
   if (status.IsError()) return status;
 
   const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
-  const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
-  if (IsNull(addressBook, "id")) {
-    LoggerE("Contact is not saved in database");
-    return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Contact is not saved in database");
-  }
   contacts_list_h contacts_list = NULL;
   int err = 0;
   err = contacts_list_create(&contacts_list);
@@ -378,12 +370,6 @@ PlatformResult AddressBookRemoveBatch(const JsonObject& args) {
   PlatformResult status = ContactUtil::CheckDBConnection();
   if (status.IsError()) return status;
   const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
-  const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
-  if (IsNull(addressBook, "id")) {
-    LoggerE("Contact is not saved in database");
-    return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
-                          "Contact is not saved in database");
-  }
   int length = static_cast<int>(batch_args.size());
   int ids[length], i=0;
   for (auto& item : batch_args) {
@@ -497,9 +483,7 @@ PlatformResult AddressBookGetGroup(const JsonObject& args, JsonObject& out) {
 
   ContactUtil::ContactsRecordHPtr record(&contacts_record,
                                          ContactUtil::ContactsDeleter);
-
-  long addressbook_id =
-      common::stol(FromJson<JsonString>(args, "addressBook", "id"));
+  long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
   if (IsUnified(addressbook_id)) {
     int address_book_id = 0;
     status = ContactUtil::GetIntFromRecord(
@@ -593,7 +577,7 @@ PlatformResult AddressBookRemoveGroup(const JsonObject& args, JsonObject&) {
   }
 
   int err;
-  long addressbook_id = AddressBookId(args);
+  long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
   if (!IsUnified(addressbook_id)) {
     contacts_record_h contacts_record = nullptr;
     err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
index 98d4e2f..971d99b 100755 (executable)
@@ -800,6 +800,26 @@ PlatformResult ContactManagerFind(const JsonObject& args, JsonArray& out) {
     if (status.IsError()) return status;
   }
 
+  const auto sort_mode_it = args.find("sortMode");
+  if (args.end() != sort_mode_it) {
+    if (!sort_mode_it->second.is<picojson::object>()) {
+      LoggerD("Failed to set sort mode.");
+      return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Failed to set sort mode");
+    }
+    const auto sort_mode = sort_mode_it->second;
+    std::string attribute = sort_mode.get("attributeName").to_str();
+
+    Person::PersonProperty property;
+    status = Person::PersonPropertyFromString(attribute, &property);
+    if (status.IsError()) return status;
+
+    bool is_asc = sort_mode.get("order").to_str() == "ASC";
+    error_code = contacts_query_set_sort(contacts_query, property.propertyId, is_asc);
+    status = ContactUtil::ErrorChecker(error_code,
+                                       "Failed contacts_query_set_sort");
+    if (status.IsError()) return status;
+  }
+
   contacts_list_h person_list = nullptr;
   error_code =
       contacts_db_get_records_with_query(contacts_query, 0, 0, &person_list);
index d084e2f..68faf00 100644 (file)
@@ -127,9 +127,6 @@ ContactSearchEngine::PropertiesMap ContactSearchEngine::s_properties_map_ = {
 };
 
 // implementation ported from wrt-plugins-tizen
-// TODO: instead of executing multiple queries and combining the results,
-//       create multiple filters, combine them into one, add sorting and
-//       execute a single query
 
 ContactSearchEngine::ContactSearchEngine()
     : addressbook_id_(0),
@@ -224,7 +221,7 @@ PlatformResult ContactSearchEngine::SetSortMode(const picojson::value& sort_mode
 
   is_sort_mode_set_ = true;
   sort_mode_attribute_ = attribute;
-  is_sort_mode_asc_ = sort_mode.get("attributeName").to_str() == "ASC";
+  is_sort_mode_asc_ = sort_mode.get("order").to_str() == "ASC";
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
@@ -1052,7 +1049,6 @@ PlatformResult ContactSearchEngine::QueryAttributeRangeString(
     ContactUtil::ContactsFilterPtr sub_filter_ptr(sub_filter,
                                                   ContactUtil::ContactsFilterDeleter);
 
-    // TODO To be supported: start
     error_code = contacts_filter_add_str(sub_filter, property_id,
                                          CONTACTS_MATCH_STARTSWITH,
                                          initial_value);
index b3ed9e4..4697fca 100755 (executable)
@@ -627,8 +627,6 @@ PlatformResult ExportContactNameToContactsRecord(
     nickname_ptr.release();
   }
 
-  // TODO update displayName in JS!
-
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
index 6cd5d57..ab61ae4 100755 (executable)
@@ -177,8 +177,6 @@ AddressBook.prototype.get = function() {
   }
 
   var result = native_.callSync('AddressBook_get', {
-    // TODO move to only sending the address book id (in all functions)
-    addressBook: this,
     id: args.id
   });
 
@@ -224,8 +222,7 @@ AddressBook.prototype.add = function() {
   ]);
 
   var result = native_.callSync('AddressBook_add', {
-    // TODO move to only sending the address book id (in all functions)
-    addressBook: this,
+    addressBookId: this.id,
     contact: _toJsonObject(args.contact)
   });
 
@@ -323,8 +320,11 @@ AddressBook.prototype.update = function() {
     }
   ]);
 
+  if (args.contact.addressBookId !== this.id && UNIFIED_ADDRESSBOOK_ID !== this.id) {
+    throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+  }
+
   var result = native_.callSync('AddressBook_update', {
-    addressBook: this,
     contact: _toJsonObject(args.contact)
   });
 
@@ -387,8 +387,20 @@ AddressBook.prototype.updateBatch = function() {
     native_.callIfPossible(args.successCallback);
   };
 
+  var thatId = this.id;
+  args.contacts.forEach(function(c) {
+    if (c.addressBookId !== thatId && UNIFIED_ADDRESSBOOK_ID !== thatId) {
+      setTimeout(function() {
+        native_.callIfPossible(args.errorCallback, new WebAPIException(
+        WebAPIException.INVALID_VALUES_ERR,
+        'Contact is not saved in database'));
+      }, 0);
+
+      return;
+    }
+  });
+
   native_.call('AddressBook_updateBatch', {
-    addressBook: this,
     batchArgs: _toJsonObject(args.contacts)
   }, callback);
 };
@@ -409,7 +421,6 @@ AddressBook.prototype.remove = function() {
   }
 
   var result = native_.callSync('AddressBook_remove', {
-    addressBook: this,
     id: args.id
   });
 
@@ -453,7 +464,6 @@ AddressBook.prototype.removeBatch = function(ids, successCallback, errorCallback
   };
 
   native_.call('AddressBook_removeBatch', {
-    addressBook: this,
     batchArgs: args.ids
   }, callback);
 };
@@ -619,7 +629,7 @@ AddressBook.prototype.getGroup = function() {
   }
 
   var result = native_.callSync('AddressBook_getGroup', {
-    addressBook: this,
+    addressBookId: this.id,
     id: args.groupId
   });
   if (native_.isFailure(result)) {
@@ -693,7 +703,7 @@ AddressBook.prototype.removeGroup = function() {
   }
 
   var result = native_.callSync('AddressBook_removeGroup',
-      {addressBook: this, id: args.groupId});
+      {addressBookId: this.id, id: args.groupId});
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
   }
index 5f25a91..1681cdc 100755 (executable)
@@ -119,47 +119,4 @@ EditGuard.prototype.isEditEnabled = function() {
   return _canEdit > 0;
 };
 
-var _editGuard = new EditGuard();
-
-//TODO: Move sorting and filtering to native code
-var Common = function() {};
-Common.prototype.sort = function(arr, sortMode) {
-  var _getSortProperty = function(obj, props) {
-    for (var i = 0; i < props.length; ++i) {
-      if (!obj.hasOwnProperty(props[i])) {
-        return null;
-      }
-      obj = obj[props[i]];
-    }
-    return obj;
-  };
-
-  if (sortMode instanceof tizen.SortMode) {
-    var props = sortMode.attributeName.split('.');
-    arr.sort(function(a, b) {
-      var aValue = _getSortProperty(a, props);
-      var bValue = _getSortProperty(b, props);
-
-      if (sortMode.order === 'DESC') {
-        return aValue < bValue;
-      }
-      return bValue < aValue;
-    });
-  }
-  return arr;
-};
-
-Common.prototype.filter = function(arr, filter) {
-  if (type_.isNullOrUndefined(arr))
-    return arr;
-  if (filter instanceof tizen.AttributeFilter ||
-      filter instanceof tizen.AttributeRangeFilter ||
-      filter instanceof tizen.CompositeFilter) {
-    arr = arr.filter(function(element) {
-      return filter._filter(element);
-    });
-  }
-  return arr;
-};
-
-var C = new Common();
+var _editGuard = new EditGuard();
\ No newline at end of file
index 11ea6fd..d24257c 100755 (executable)
@@ -396,7 +396,6 @@ ContactManager.prototype.find = function() {
     }
   ]);
 
-  // TODO implement contact filtering/sorting.
   var data = {
     filter: utils_.repackFilter(args.filter),
     sortMode: args.sortMode
@@ -411,8 +410,6 @@ ContactManager.prototype.find = function() {
       for (var i = 0; i < _result.length; ++i) {
         retval.push(self.get(String(_result[i])));
       }
-      //TODO: Move sorting to native code
-      retval = C.sort(retval, args.sortMode);
       args.successCallback(retval);
     } else {
       native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
index 6161f7b..0185d90 100755 (executable)
@@ -152,8 +152,7 @@ Person.prototype.link = function() {
   }
 
   var result = native_.callSync('Person_link', {
-    // TODO move to only sending the person id (in all functions)
-    person: this,
+    personId: this.id,
     id: args.personId
   });
   if (native_.isFailure(result)) {
@@ -182,8 +181,7 @@ Person.prototype.unlink = function(contactId) {
   }
 
   var result = native_.callSync('Person_unlink', {
-    // TODO move to only sending the person id (in all functions)
-    person: this,
+    personId: this.id,
     id: args.contactId
   });
   if (native_.isFailure(result)) {
index 1490c2c..7166be4 100755 (executable)
@@ -44,7 +44,7 @@ PlatformResult PersonLink(const JsonObject& args, JsonObject&) {
   if (status.IsError()) return status;
 
   long id = common::stol(FromJson<JsonString>(args, "id"));
-  long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+  long person_id = common::stol(FromJson<JsonString>(args, "personId"));
 
   contacts_record_h contacts_record = nullptr;
 
@@ -94,7 +94,7 @@ PlatformResult PersonUnlink(const JsonObject& args, JsonObject& out) {
                                      "Contact is not a member of person");
   if (status.IsError()) return status;
 
-  long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+  long person_id = common::stol(FromJson<JsonString>(args, "personId"));
   if (contacts_person_id != person_id) {
     LoggerW("Contact is not a member of person (wrong id's)");
     return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
index 9909052..2bed6d7 100755 (executable)
@@ -27,7 +27,9 @@
 #include "common/picojson.h"
 #include "common/platform_result.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 #include "common/virtual_fs.h"
+
 #include "content/content_manager.h"
 
 namespace extension {
index 18d9f5c..6e1f0f2 100755 (executable)
 #include "common/converter.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
+#include "common/tools.h"
 #include "common/virtual_fs.h"
+
 #include "content/content_filter.h"
-#include "common/virtual_fs.h"
 
 using namespace std;
 using namespace common;
index b0e8953..1d9f5a6 100755 (executable)
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
  */
+function _checkClosed(stream) {
+  if (stream._closed) {
+    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is closed.');
+  }
+}
+
+function _checkReadAccess(mode) {
+  if (mode !== 'r' && mode !== 'rw') {
+    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in read mode.');
+  }
+}
+
+function _checkWriteAccess(mode) {
+  if (mode !== 'a' && mode !== 'w' && mode !== 'rw') {
+    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in write mode.');
+  }
+}
 
 function FileStream(data, mode, encoding) {
   var _totalBytes = data.fileSize || 0;
@@ -20,9 +37,12 @@ function FileStream(data, mode, encoding) {
 
   Object.defineProperties(this, {
     eof: {
-      value: false,
-      enumerable: true,
-      writable: false
+      get: function() {
+        return _totalBytes < _position;
+      },
+      set: function(v) {
+      },
+      enumerable: true
     },
     position: {
       get: function() {
@@ -34,9 +54,12 @@ function FileStream(data, mode, encoding) {
       enumerable: true
     },
     bytesAvailable: {
-      value: this.eof ? -1 : Math.max(0, _totalBytes - _position),
-      enumerable: true,
-      writable: false
+      get: function() {
+        return this.eof ? -1 : Math.max(0, _totalBytes - _position);
+      },
+      set: function(v) {
+      },
+      enumerable: true
     },
     _mode: {
       value: mode,
@@ -59,12 +82,69 @@ function FileStream(data, mode, encoding) {
       enumerable: false
     }
   });
-}
 
-function _checkClosed(stream) {
-  if (stream._closed) {
-    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is closed.');
-  }
+  this.write = function() {
+    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
+
+    var args = validator_.validateArgs(arguments, [
+      {
+        name: 'stringData',
+        type: types_.STRING
+      }
+    ]);
+
+    _checkClosed(this);
+    _checkWriteAccess(this._mode);
+    if (!arguments.length) {
+      throw new WebAPIException(WebAPIException.NOT_FOUND_ERR,
+          'Argument "stringData" missing');
+    }
+
+    var data = {
+      location: commonFS_.toRealPath(this._file.fullPath),
+      offset: this.position,
+      length: args.stringData.length,
+      is_base64: false,
+    };
+    var result = native_.callSyncData('File_writeSync', data, "string", args.stringData);
+    if (native_.isFailure(result.reply)) {
+      throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
+    }
+    this.position = this.position + result.reply.data_size;
+    _totalBytes = Math.max(this.position, _totalBytes);
+  };
+
+  this.writeBytes = function() {
+    xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
+
+    var args = validator_.validateArgs(arguments, [
+      {
+        name: 'byteData',
+        type: types_.ARRAY
+      }
+    ]);
+    _checkClosed(this);
+    _checkWriteAccess(this._mode);
+    if (!arguments.length) {
+      throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
+          'Argument "byteData" missing');
+    }
+
+    var data = {
+      location: commonFS_.toRealPath(this._file.fullPath),
+      offset: this.position,
+      length: args.byteData.length,
+      is_base64: false,
+    };
+
+    var result = native_.callSyncData('File_writeSync', data, "octet", args.byteData);
+
+    if (native_.isFailure(result.reply)) {
+      throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
+    }
+    this.position = this.position + result.reply.data_size;
+    _totalBytes = Math.max(this.position, _totalBytes);
+  };
 }
 
 FileStream.prototype.close = function() {
@@ -72,18 +152,6 @@ FileStream.prototype.close = function() {
   this._closed = true;
 };
 
-function _checkReadAccess(mode) {
-  if (mode !== 'r' && mode !== 'rw') {
-    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in read mode.');
-  }
-}
-
-function _checkWriteAccess(mode) {
-  if (mode !== 'a' && mode !== 'w' && mode !== 'rw') {
-    throw new WebAPIException(WebAPIException.IO_ERR, 'Stream is not in write mode.');
-  }
-}
-
 FileStream.prototype.read = function() {
   xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ);
 
@@ -213,68 +281,6 @@ FileStream.prototype.readBase64 = function() {
   return result.output;
 };
 
-FileStream.prototype.write = function() {
-  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
-
-  var args = validator_.validateArgs(arguments, [
-    {
-      name: 'stringData',
-      type: types_.STRING
-    }
-  ]);
-
-  _checkClosed(this);
-  _checkWriteAccess(this._mode);
-  if (!arguments.length) {
-    throw new WebAPIException(WebAPIException.NOT_FOUND_ERR,
-        'Argument "stringData" missing');
-  }
-
-  var data = {
-    location: commonFS_.toRealPath(this._file.fullPath),
-    offset: this.position,
-    length: args.stringData.length,
-    is_base64: false,
-  };
-  var result = native_.callSyncData('File_writeSync', data, "string", args.stringData);
-  if (native_.isFailure(result.reply)) {
-    throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
-  }
-  this.position = this.position + result.reply.data_size;
-};
-
-FileStream.prototype.writeBytes = function() {
-  xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_WRITE);
-
-  var args = validator_.validateArgs(arguments, [
-    {
-      name: 'byteData',
-      type: types_.ARRAY
-    }
-  ]);
-  _checkClosed(this);
-  _checkWriteAccess(this._mode);
-  if (!arguments.length) {
-    throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR,
-        'Argument "byteData" missing');
-  }
-
-  var data = {
-    location: commonFS_.toRealPath(this._file.fullPath),
-    offset: this.position,
-    length: args.byteData.length,
-    is_base64: false,
-  };
-
-  var result = native_.callSyncData('File_writeSync', data, "octet", args.byteData);
-
-  if (native_.isFailure(result.reply)) {
-    throw new WebAPIException(WebAPIException.IO_ERR, 'Could not write');
-  }
-  this.position = this.position + result.reply.data_size;
-
-};
-
 function _isBase64(str) {
   var base64 = new RegExp('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$');
   return base64.test(str);
index df4105b..115f375 100644 (file)
@@ -206,19 +206,12 @@ void LoadAttachmentProxy::handleEmailSignal(const int status,
         if (!ret.IsError()) {
             LoggerD("Updated Message attachment object");
 
-            auto json = callback->getJson();
-            picojson::object& obj = json->get<picojson::object>();
-            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
             picojson::object args;
             args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(
                     callback->getMessageAttachment());
-            obj[JSON_DATA] = picojson::value(args);
 
-            callback->getQueue().resolve(
-                    obj.at(JSON_CALLBACK_ID).get<double>(),
-                    json->serialize()
-            );
+            callback->SetSuccess(picojson::value(args));
+            callback->Post();
         }
     } else if(NOTI_DOWNLOAD_ATTACH_FAIL) {
         LoggerD("Load message attachment failed!");
@@ -226,11 +219,8 @@ void LoadAttachmentProxy::handleEmailSignal(const int status,
     }
     if (ret.IsError()) {
         LoggerE("Exception in signal callback");
-        callback->setError(ret);
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
+        callback->SetError(ret);
+        callback->Post();
     }
 
     if(callback) {
index 395ce78..8916409 100644 (file)
@@ -166,19 +166,12 @@ void LoadBodyProxy::handleEmailSignal(const int status,
             if (!ret.IsError()) {
                 LoggerD("Calling success callback");
 
-                auto json = callback->getJson();
-                picojson::object& obj = json->get<picojson::object>();
-                obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
                 picojson::object args;
                 args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(
                         callback->getMessage()->getBody());
-                obj[JSON_DATA] = picojson::value(args);
 
-                callback->getQueue().resolve(
-                        obj.at(JSON_CALLBACK_ID).get<double>(),
-                        json->serialize()
-                );
+                callback->SetSuccess(picojson::value(args));
+                callback->Post();
             }
         } else if(NOTI_DOWNLOAD_BODY_FAIL == status) {
             LoggerD("Load message body failed!");
@@ -186,11 +179,8 @@ void LoadBodyProxy::handleEmailSignal(const int status,
         }
 
         if (ret.IsError()) {
-            callback->setError(ret);
-            callback->getQueue().resolve(
-                    callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                    callback->getJson()->serialize()
-            );
+            callback->SetError(ret);
+            callback->Post();
         }
 
         removeCallback(callback);
index b04556e..ea096c7 100644 (file)
@@ -57,13 +57,13 @@ PlatformResult SyncProxy::create(const std::string& path,
     }
 }
 
-void SyncProxy::addCallback(long op_id, common::CallbackUserData* callbackOwned)
+void SyncProxy::addCallback(long op_id, CallbackUserData* callbackOwned)
 {
     m_callback_map.insert(std::make_pair(op_id, callbackOwned));
 }
 
-common::CallbackUserData* SyncProxy::getCallback(long op_id) {
-  common::CallbackUserData* cb = nullptr;
+CallbackUserData* SyncProxy::getCallback(long op_id) {
+  CallbackUserData* cb = nullptr;
   const auto it = m_callback_map.find(op_id);
 
   if (it != m_callback_map.end()) {
@@ -123,28 +123,18 @@ void SyncProxy::handleEmailSignal(const int status,
         return;
     }
 
-    std::shared_ptr<picojson::value> response = callback->getJson();
-    picojson::object& obj = response->get<picojson::object>();
     switch (status) {
         case NOTI_DOWNLOAD_FINISH:
             LoggerD("Sync finished!");
-            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-            callback->getQueue().resolve(
-                    obj.at(JSON_CALLBACK_ID).get<double>(),
-                    response->serialize()
-            );
+            callback->SetSuccess();
+            callback->Post();
             break;
 
         case NOTI_DOWNLOAD_FAIL:
-        {
             LoggerD("Sync failed!");
-            callback->setError("UnknownError", "Sync failed!");
-            callback->getQueue().resolve(
-                    obj.at(JSON_CALLBACK_ID).get<double>(),
-                    response->serialize()
-            );
-        }
-        break;
+            callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sync failed!"));
+            callback->Post();
+            break;
 
     }
 
index bd7f379..183f0ba 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef __TIZEN_DBUS_SYNC_PROXY_H__
 #define __TIZEN_DBUS_SYNC_PROXY_H__
 
+#include "messaging/callback_user_data.h"
 #include "EmailSignalProxy.h"
 #include "common/platform_result.h"
 
@@ -36,7 +37,7 @@ class SyncProxy : public EmailSignalProxy {
 public:
 
     // Callback is owned by this map
-    typedef std::map<long, common::CallbackUserData*> CallbackMap;
+    typedef std::map<long, CallbackUserData*> CallbackMap;
 
     virtual ~SyncProxy();
 
@@ -44,8 +45,8 @@ public:
                                          const std::string& iface,
                                          SyncProxyPtr* sync_proxy);
     //Passed callback will be owned by this proxy
-    void addCallback(long op_id, common::CallbackUserData* callbackOwned);
-    common::CallbackUserData* getCallback(long op_id);
+    void addCallback(long op_id, CallbackUserData* callbackOwned);
+    CallbackUserData* getCallback(long op_id);
     void removeCallback(long op_id);
 
 protected:
diff --git a/src/messaging/callback_user_data.cc b/src/messaging/callback_user_data.cc
new file mode 100755 (executable)
index 0000000..ae1cf0b
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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.
+ */
+
+#include "messaging/callback_user_data.h"
+
+#include "common/logger.h"
+
+namespace extension {
+namespace messaging {
+
+CallbackUserData::CallbackUserData(PostQueue& queue, long cid, bool keep /* = false */)
+    : json_(picojson::object()),
+      obj_(json_.get<picojson::object>()),
+      cid_(cid),
+      queue_(queue),
+      result_(common::ErrorCode::NO_ERROR) {
+  LoggerD("Entered");
+  AddJsonData(JSON_CALLBACK_ID, picojson::value(static_cast<double>(cid_)));
+  AddJsonData(JSON_CALLBACK_KEEP, picojson::value(keep));
+}
+
+CallbackUserData::~CallbackUserData() {
+  LoggerD("Entered");
+}
+
+bool CallbackUserData::IsError() const {
+  LoggerD("Entered");
+  return result_.IsError();
+}
+
+void CallbackUserData::SetError(const common::PlatformResult& error) {
+  LoggerD("Entered");
+
+  // keep only the first error
+  if (!IsError()) {
+    result_ = error;
+    SetAction(JSON_CALLBACK_ERROR, error.ToJSON());
+  }
+}
+
+void CallbackUserData::SetSuccess(const picojson::value& data /* = picojson::value()*/) {
+  LoggerD("Entered");
+
+  // do not allow to overwrite the error
+  if (!IsError()) {
+    SetAction(JSON_CALLBACK_SUCCCESS, data);
+  }
+}
+
+void CallbackUserData::SetAction(const char* action, const picojson::value& data) {
+  LoggerD("Entered");
+
+  AddJsonData(JSON_ACTION, picojson::value(action));
+  AddJsonData(JSON_DATA, data);
+}
+
+void CallbackUserData::AddToQueue() {
+  LoggerD("Entered");
+  queue_.add(cid_, PostPriority::HIGH);
+}
+
+void CallbackUserData::Post() {
+  LoggerD("Entered");
+  queue_.resolve(cid_, json_.serialize());
+}
+
+void CallbackUserData::AddAndPost(PostPriority p) {
+  queue_.addAndResolve(cid_, p, json_.serialize());
+}
+
+bool CallbackUserData::HasQueue(const PostQueue& q) const {
+  LoggerD("Entered");
+  return &q == &queue_;
+}
+
+void CallbackUserData::AddJsonData(const char* key, const picojson::value& value) {
+  LoggerD("Entered");
+  // always overwrite
+  obj_[key] = value;
+}
+
+}  // messaging
+}  // extension
diff --git a/src/messaging/callback_user_data.h b/src/messaging/callback_user_data.h
new file mode 100755 (executable)
index 0000000..5b62e2b
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 MESSAGING_CALLBACK_USER_DATA_H_
+#define MESSAGING_CALLBACK_USER_DATA_H_
+
+#include <memory>
+
+#include "common/picojson.h"
+
+#include "messaging/messaging_util.h"
+
+namespace extension {
+namespace messaging {
+
+class CallbackUserData {
+ public:
+  CallbackUserData(PostQueue& queue, long cid, bool keep = false);
+  virtual ~CallbackUserData();
+
+  bool IsError() const;
+  void SetError(const common::PlatformResult& error);
+  void SetSuccess(const picojson::value& data = picojson::value());
+  void SetAction(const char* action, const picojson::value& data);
+
+  void AddToQueue();
+  void Post();
+  void AddAndPost(PostPriority p);
+  bool HasQueue(const PostQueue& q) const;
+
+ private:
+  void AddJsonData(const char* key, const picojson::value& value);
+
+  picojson::value json_;
+  picojson::object& obj_;
+  long cid_;
+  PostQueue& queue_;
+  common::PlatformResult result_;
+};
+
+}  // messaging
+}  // extension
+
+#endif  // MESSAGING_CALLBACK_USER_DATA_H_
index 8bf1191..18a917c 100755 (executable)
 namespace extension {
 namespace messaging {
 
-ConversationCallbackData::ConversationCallbackData(PostQueue& queue):
-        m_filter(),
-        m_sort(),
-        m_limit(0),
-        m_offset(0),
-        m_is_error(false),
-        m_account_id(0),
-        m_service_type(UNDEFINED),
-        queue_(queue)
-{
-    LoggerD("Entered");
-}
-
-ConversationCallbackData::ConversationCallbackData(long cid, PostQueue& queue, bool keep):
-        m_filter(),
-        m_sort(),
-        m_limit(0),
-        m_offset(0),
-        m_is_error(false),
-        m_account_id(0),
-        m_service_type(UNDEFINED),
-        queue_(queue)
-{
-    LoggerD("Entered");
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& o = json->get<picojson::object>();
-    o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
-    o[JSON_CALLBACK_KEEP] = picojson::value(keep);
-    setJson(json);
+ConversationCallbackData::ConversationCallbackData(PostQueue& queue, long cid, bool keep /* = false */) :
+    CallbackUserData(queue, cid, keep),
+    m_limit(0),
+    m_offset(0),
+    m_account_id(0),
+    m_service_type(UNDEFINED) {
+  LoggerD("Entered");
 }
 
 ConversationCallbackData::~ConversationCallbackData()
@@ -86,58 +64,6 @@ std::vector<std::shared_ptr<MessageConversation>> ConversationCallbackData::getC
     return m_conversations;
 }
 
-void ConversationCallbackData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-        auto objData = picojson::object();
-
-        objData[JSON_ERROR_NAME] = picojson::value(err_name);
-        objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
-        obj[JSON_DATA] = picojson::value(objData);
-
-        m_is_error = true;
-        m_err_name = err_name;
-        m_err_message = err_message;
-    }
-}
-
-void ConversationCallbackData::SetError(const common::PlatformResult& error)
-{
-    LoggerD("Entered");
-  // keep only first error in chain
-  if (!m_is_error) {
-      LoggerD("Error has not been set yet");
-    m_is_error = true;
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_data = picojson::object();
-    obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-    obj[JSON_DATA] = picojson::value(obj_data);
-  }
-}
-bool ConversationCallbackData::isError() const
-{
-    return m_is_error;
-}
-
-std::string ConversationCallbackData::getErrorName() const
-{
-    return m_err_name;
-}
-
-std::string ConversationCallbackData::getErrorMessage() const
-{
-    return m_err_message;
-}
-
 void ConversationCallbackData::setAccountId(int account_id){
     m_account_id = account_id;
 }
index 17cb5df..9d82d82 100755 (executable)
 #ifndef MESSAGING_CONVERSATION_CALLBACK_DATA_H_
 #define MESSAGING_CONVERSATION_CALLBACK_DATA_H_
 
-#include "common/callback_user_data.h"
 #include <memory>
 #include <string>
 #include <vector>
+
+#include "messaging/callback_user_data.h"
 #include "MsgCommon/AttributeFilter.h"
 #include "MsgCommon/SortMode.h"
 #include "messaging_util.h"
@@ -33,10 +34,9 @@ namespace messaging {
 class Message;
 class MessageConversation;
 
-class ConversationCallbackData: public common::CallbackUserData {
+class ConversationCallbackData : public CallbackUserData {
 public:
-    ConversationCallbackData(PostQueue& queue);
-    ConversationCallbackData(long cid, PostQueue& queue, bool keep = false);
+    ConversationCallbackData(PostQueue& queue, long cid, bool keep = false);
     virtual ~ConversationCallbackData();
 
     void setFilter(AbstractFilterPtr filter);
@@ -47,13 +47,6 @@ public:
 
     std::vector<std::shared_ptr<MessageConversation>> getConversations() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void SetError(const common::PlatformResult& error);
-    bool isError() const;
-    std::string getErrorName() const;
-    std::string getErrorMessage() const;
-
     void setAccountId(int account_id);
     int getAccountId() const;
 
@@ -64,19 +57,14 @@ public:
     long getLimit() const;
     long getOffset() const;
 
-    PostQueue& getQueue() { return queue_;};
 private:
     AbstractFilterPtr m_filter;
     SortModePtr m_sort;
     long m_limit;
     long m_offset;
-    bool m_is_error;
-    std::string m_err_name;
-    std::string m_err_message;
     std::vector<std::shared_ptr<MessageConversation>> m_conversations;
     int m_account_id;
     MessageType m_service_type;
-    PostQueue& queue_;
 };
 
 }//messaging
index 841fef6..d98308f 100755 (executable)
@@ -44,7 +44,7 @@ ConversationsChangeCallback::ConversationsChangeCallback(
         int service_id,
         MessageType service_type,
         PostQueue& queue) :
-        m_callback_data(cid, queue, true),
+        m_callback_data(queue, cid, true),
         m_id(service_id),
         m_msg_type(service_type),
         m_is_act(true)
@@ -116,13 +116,8 @@ void ConversationsChangeCallback::added(
     LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSADDED,
         filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(CONVERSATIONSADDED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    m_callback_data.getQueue().addAndResolve(obj.at(
-                JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
+    m_callback_data.SetAction(CONVERSATIONSADDED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::MEDIUM);
 }
 
 void ConversationsChangeCallback::updated(
@@ -150,13 +145,8 @@ void ConversationsChangeCallback::updated(
     LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSUPDATED,
         filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(CONVERSATIONSUPDATED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    m_callback_data.getQueue().addAndResolve(obj.at(
-                JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
+    m_callback_data.SetAction(CONVERSATIONSUPDATED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LOW);
 }
 
 void ConversationsChangeCallback::removed(
@@ -184,13 +174,8 @@ void ConversationsChangeCallback::removed(
     LoggerD("Calling:%s with:%d added conversations", CONVERSATIONSREMOVED,
         filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(CONVERSATIONSREMOVED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    m_callback_data.getQueue().addAndResolve(obj.at(
-                JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
+    m_callback_data.SetAction(CONVERSATIONSREMOVED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LAST);
 }
 
 void ConversationsChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
index 84bd13a..c7fbbf7 100755 (executable)
@@ -304,33 +304,19 @@ static gboolean addDraftMessageCompleteCB(void *data)
         return false;
     }
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-        if (callback->isError()) {
-            LoggerD("Calling error callback");
-            callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                             json->serialize()
-            );
-            callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
-        } else {
-            LoggerD("Calling success callback");
-            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-            picojson::object args;
-            args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
-            obj[JSON_DATA] = picojson::value(args);
-
-            callback->getQueue().resolve(
-                    obj.at(JSON_CALLBACK_ID).get<double>(),
-                    json->serialize()
-            );
-        }
-    } else {
-        LoggerE("Callback id is missing");
+    if (callback->IsError()) {
+        LoggerD("Calling error callback");
         callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
+    } else {
+        LoggerD("Calling success callback");
+
+        picojson::object args;
+        args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
+        callback->SetSuccess(picojson::value(args));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 
@@ -351,7 +337,7 @@ void EmailManager::addDraftMessage(MessageCallbackUserData* callback)
     PlatformResult ret = addDraftMessagePlatform(callback->getAccountId(), message);
     if (ret.IsError()) {
       LoggerE("%d (%s)", ret.error_code(), ret.message().c_str());
-      callback->setError(ret);
+      callback->SetError(ret);
     }
   }
   //Complete task
@@ -374,49 +360,37 @@ static gboolean sendEmailCompleteCB(void* data)
         return false;
     }
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-        if (callback->isError()) {
-            LoggerD("Calling error callback");
-            callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                             json->serialize()
-            );
-            callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
-        }
-        else {
-            LoggerD("Calling success callback");
-            obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-            std::vector<picojson::value> recipients;
-            auto addToRecipients = [&recipients](std::string& e)->void {
-                recipients.push_back(picojson::value(e));
-            };
-
-            auto toVect = callback->getMessage()->getTO();
-            std::for_each(toVect.begin(), toVect.end(), addToRecipients);
-
-            auto ccVect = callback->getMessage()->getCC();
-            std::for_each(ccVect.begin(), ccVect.end(), addToRecipients);
-
-            auto bccVect = callback->getMessage()->getBCC();
-            std::for_each(bccVect.begin(), bccVect.end(), addToRecipients);
-
-            picojson::object data;
-            data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
-            data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
-            obj[JSON_DATA] = picojson::value(data);
-
-            callback->getQueue().resolve(
-                    obj.at(JSON_CALLBACK_ID).get<double>(),
-                    json->serialize()
-            );
-            callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
-        }
-    } else {
-        LoggerE("Callback id is missing");
+    if (callback->IsError()) {
+        LoggerD("Calling error callback");
+        callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
+    }
+    else {
+        LoggerD("Calling success callback");
+
+        std::vector<picojson::value> recipients;
+        auto addToRecipients = [&recipients](std::string& e)->void {
+            recipients.push_back(picojson::value(e));
+        };
+
+        auto toVect = callback->getMessage()->getTO();
+        std::for_each(toVect.begin(), toVect.end(), addToRecipients);
+
+        auto ccVect = callback->getMessage()->getCC();
+        std::for_each(ccVect.begin(), ccVect.end(), addToRecipients);
+
+        auto bccVect = callback->getMessage()->getBCC();
+        std::for_each(bccVect.begin(), bccVect.end(), addToRecipients);
+
+        picojson::object data;
+        data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
+        data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
+
+        callback->SetSuccess(picojson::value(data));
+        callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 
@@ -476,7 +450,7 @@ PlatformResult EmailManager::sendMessage(MessageRecipientsCallbackData* callback
   if (!platform_result) {
     LoggerE("Message send failed");
 
-    callback->setError(platform_result);
+    callback->SetError(platform_result);
 
     if (!g_idle_add(sendEmailCompleteCB, static_cast<void*>(callback))) {
       LoggerE("g_idle addition failed");
@@ -523,14 +497,12 @@ void EmailManager::sendStatusCallback(int mail_id,
                 case EMAIL_ERROR_NO_RESPONSE:
                 {
                     LoggerE("Network error %d", error_code);
-                    common::NetworkException e("Failed to send message");
-                    callback->setError(e.name(), e.message());
+                    callback->SetError(PlatformResult(ErrorCode::NETWORK_ERR, "Failed to send message"));
                     break;
                 }
                 default:
                     LoggerE("Unknown error %d", error_code);
-                    common::UnknownException ex("Failed to send message");
-                    callback->setError(ex.name(),ex.message());
+                    callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to send message"));
                     break;
             }
         } else if (NOTI_SEND_FINISH == status) {
@@ -824,18 +796,10 @@ void EmailManager::stopSync(long op_id)
     LoggerE("Email cancel job failed, %d", err);
   }
 
-  std::shared_ptr<picojson::value> response = callback->getJson();
-  picojson::object& obj = response->get<picojson::object>();
-
-  if (response->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-    callback->setError(PlatformResult(ErrorCode::ABORT_ERR, "Sync aborted by user"));
+  callback->SetError(PlatformResult(ErrorCode::ABORT_ERR, "Sync aborted by user"));
 
-    callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                     response->serialize());
-    m_proxy_sync->removeCallback(op_id);
-  } else {
-    LoggerE("Callback id is missing");
-  }
+  callback->Post();
+  m_proxy_sync->removeCallback(op_id);
 }
 
 //################################## ^stopSync #################################
@@ -849,7 +813,7 @@ void EmailManager::RemoveCallbacksByQueue(const PostQueue& q) {
   LoggerD("Entered");
 
   for (auto it = m_sendRequests.begin(); it != m_sendRequests.end();) {
-    if (&it->second->getQueue() == &q) {
+    if (it->second->HasQueue(q)) {
       delete it->second;
       m_sendRequests.erase(it++);
     } else {
@@ -866,26 +830,18 @@ void removeEmailCompleteCB(MessagesCallbackUserData* callback)
     return;
   }
 
-  auto json = callback->getJson();
-  picojson::object& obj = json->get<picojson::object>();
-  if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-    if (callback->isError()) {
-      LoggerD("Calling error callback");
-      callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                       json->serialize()
-      );
-    } else {
-      LoggerD("Calling success callback");
 
-      obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-      callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                       json->serialize()
-      );
-    }
+  if (callback->IsError()) {
+    LoggerD("Calling error callback");
+
   } else {
-    LoggerE("Callback id is missing");
+    LoggerD("Calling success callback");
+
+    callback->SetSuccess();
   }
 
+  callback->Post();
+
   delete callback;
   callback = NULL;
 }
@@ -922,8 +878,7 @@ void EmailManager::removeStatusCallback(const std::vector<int> &ids,
         MessagesCallbackUserData* callback = it->callback;
         if (NOTI_MAIL_DELETE_FAIL == status) {
             LoggerD("Failed to remove mail");
-            UnknownException e("Messages remove failed");
-            callback->setError(e.name(), e.message());
+            callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Messages remove failed"));
         }
         //if one of mails failed, call error callback
         //if all mails are deleted, call success.
@@ -1077,32 +1032,23 @@ void EmailManager::updateMessages(MessagesCallbackUserData* callback)
       callback->SetError(ret);
     }
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      if (callback->isError()) {
-        LoggerD("Calling error callback");
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
-      } else {
-        LoggerD("Calling success callback");
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        picojson::array array;
-        auto messages = callback->getMessages();
-        size_t messages_size = messages.size();
-        for (size_t i = 0 ; i < messages_size; ++i) {
-          array.push_back(MessagingUtil::messageToJson(messages[i]));
-        }
-        obj[JSON_DATA] = picojson::value(array);
+    if (callback->IsError()) {
+      LoggerD("Calling error callback");
+    } else {
+      LoggerD("Calling success callback");
 
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize()
-        );
+      picojson::array array;
+      auto messages = callback->getMessages();
+      size_t messages_size = messages.size();
+      for (size_t i = 0 ; i < messages_size; ++i) {
+        array.push_back(MessagingUtil::messageToJson(messages[i]));
       }
-    } else {
-      LoggerE("Callback id is missing");
+
+      callback->SetSuccess(picojson::value(array));
     }
+
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -1157,33 +1103,25 @@ void EmailManager::findMessages(FindMsgCallbackUserData* callback)
   }
 
   //Complete task
-  LoggerD("callback: %p error: %d messages.size() = %d", callback, callback->isError(),
+  LoggerD("callback: %p error: %d messages.size() = %d", callback, callback->IsError(),
           callback->getMessages().size());
 
-  auto json = callback->getJson();
-  picojson::object& obj = json->get<picojson::object>();
-  if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-    if (callback->isError()) {
-      LoggerD("Calling error callback");
-      callback->getQueue().resolve( obj.at(JSON_CALLBACK_ID).get<double>(),
-                                        json->serialize());
-    } else {
-      LoggerD("Calling success callback");
-      std::vector<picojson::value> response;
-      auto messages = callback->getMessages();
-      std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
-        response.push_back(MessagingUtil::messageToJson(message));
-      });
-      obj[JSON_DATA] = picojson::value(response);
-      obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+  if (callback->IsError()) {
+    LoggerD("Calling error callback");
 
-      callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                       json->serialize());
-    }
   } else {
-    LoggerE("Failed to call findMessages callback.");
+    LoggerD("Calling success callback");
+    std::vector<picojson::value> response;
+    auto messages = callback->getMessages();
+    std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
+      response.push_back(MessagingUtil::messageToJson(message));
+    });
+
+    callback->SetSuccess(picojson::value(response));
   }
 
+  callback->Post();
+
   delete callback;
   callback = NULL;
 }
@@ -1229,37 +1167,27 @@ void EmailManager::findConversations(ConversationCallbackData* callback)
     }
 
     //Complete task
-    LoggerD("callback: %p error:%d conversations.size()=%d", callback, callback->isError(),
+    LoggerD("callback: %p error:%d conversations.size()=%d", callback, callback->IsError(),
             callback->getConversations().size());
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      if (callback->isError()) {
-        LoggerD("Calling error callback");
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
-      } else {
-        LoggerD("Calling success callback");
-
-        std::vector<picojson::value> response;
-        auto messages = callback->getConversations();
-        std::for_each(messages.begin(), messages.end(),
-                      [&response](std::shared_ptr<MessageConversation> &conversation) {
-          response.push_back(MessagingUtil::conversationToJson(conversation));
-        }
-        );
-        obj[JSON_DATA] = picojson::value(response);
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+    if (callback->IsError()) {
+      LoggerD("Calling error callback");
+    } else {
+      LoggerD("Calling success callback");
 
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize()
-        );
+      std::vector<picojson::value> response;
+      auto messages = callback->getConversations();
+      std::for_each(messages.begin(), messages.end(),
+                    [&response](std::shared_ptr<MessageConversation> &conversation) {
+        response.push_back(MessagingUtil::conversationToJson(conversation));
       }
-    } else {
-      LoggerE("Failed to call findConversations callback.");
+      );
+
+      callback->SetSuccess(picojson::value(response));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -1370,36 +1298,27 @@ void EmailManager::findFolders(FoldersCallbackData* callback)
     }
 
     //Complete task
-    LoggerD("callback: %p error:%d folders.size()=%d", callback, callback->isError(),
+    LoggerD("callback: %p error:%d folders.size()=%d", callback, callback->IsError(),
             callback->getFolders().size());
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      if (callback->isError()) {
-        LoggerD("Calling error callback");
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
-      } else {
-        LoggerD("Calling success callback");
-
-        std::vector<picojson::value> response;
-        auto folders = callback->getFolders();
-        std::for_each(folders.begin(), folders.end(),
-                      [&response](std::shared_ptr<MessageFolder> &folder) {
-          response.push_back(MessagingUtil::folderToJson(folder));
-        }
-        );
-        obj[JSON_DATA] = picojson::value(response);
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+    if (callback->IsError()) {
+      LoggerD("Calling error callback");
+    } else {
+      LoggerD("Calling success callback");
 
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
+      std::vector<picojson::value> response;
+      auto folders = callback->getFolders();
+      std::for_each(folders.begin(), folders.end(),
+                    [&response](std::shared_ptr<MessageFolder> &folder) {
+        response.push_back(MessagingUtil::folderToJson(folder));
       }
-    } else {
-      LoggerE("Unknown error when calling findFolders callback.");
+      );
+
+      callback->SetSuccess(picojson::value(response));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -1465,24 +1384,16 @@ void EmailManager::removeConversations(ConversationCallbackData* callback)
       callback->SetError(ret);
     }
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      if (callback->isError()) {
-        LoggerD("Calling error callback");
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
-      } else {
-        LoggerD("Calling success callback");
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        callback->getQueue().resolve(obj.at(JSON_CALLBACK_ID).get<double>(),
-                                         json->serialize());
-      }
+    if (callback->IsError()) {
+      LoggerD("Calling error callback");
     } else {
-      LoggerE("Unknown error when calling removeConversations callback.");
+      LoggerD("Calling success callback");
+
+      callback->SetSuccess();
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
index d38ef79..8828d29 100755 (executable)
@@ -32,7 +32,7 @@
 #include "email-api-mail.h"
 #include "email-api-mailbox.h"
 
-#include "common/callback_user_data.h"
+#include "messaging/callback_user_data.h"
 #include "common/GDBus/connection.h"
 #include "common/platform_exception.h"
 #include "common/platform_result.h"
index fa8cc97..0cef06c 100755 (executable)
 namespace extension {
 namespace messaging {
 
-FindMsgCallbackUserData::FindMsgCallbackUserData(PostQueue& queue):
-        CallbackUserData(),
-        m_limit(0),
-        m_offset(0),
-        m_is_error(false),
-        m_account_id(0),
-        m_service_type(UNDEFINED),
-        queue_(queue)
-{
-    LoggerD("Entered");
+FindMsgCallbackUserData::FindMsgCallbackUserData(PostQueue& queue, long cid) :
+    CallbackUserData(queue, cid),
+    m_limit(0),
+    m_offset(0),
+    m_account_id(0),
+    m_service_type(UNDEFINED) {
+  LoggerD("Entered");
 }
 
 FindMsgCallbackUserData::~FindMsgCallbackUserData()
@@ -70,58 +67,6 @@ std::vector<std::shared_ptr<Message>> FindMsgCallbackUserData::getMessages() con
     return m_messages;
 }
 
-void FindMsgCallbackUserData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        m_is_error = true;
-        m_err_name = err_name;
-        m_err_message = err_message;
-
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
-        auto obj_error = picojson::object();
-        obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
-        obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-        obj[JSON_DATA] = picojson::value(obj_error);
-    }
-}
-
-void FindMsgCallbackUserData::SetError(const common::PlatformResult& error)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-    LoggerD("Error has not been set yet");
-    m_is_error = true;
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_data = picojson::object();
-    obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-    obj[JSON_DATA] = picojson::value(obj_data);
-  }
-}
-
-bool FindMsgCallbackUserData::isError() const
-{
-    return m_is_error;
-}
-
-std::string FindMsgCallbackUserData::getErrorName() const
-{
-    return m_err_name;
-}
-
-std::string FindMsgCallbackUserData::getErrorMessage() const
-{
-    return m_err_message;
-}
-
 void FindMsgCallbackUserData::setAccountId(int account_id){
     m_account_id = account_id;
 }
index 48e6067..d778228 100755 (executable)
 #ifndef __TIZEN_FIND_MSG_CALLBACK_USER_DATA_H
 #define __TIZEN_FIND_MSG_CALLBACK_USER_DATA_H
 
-#include "common/callback_user_data.h"
 #include <memory>
 #include <string>
 #include <vector>
+
+#include "messaging/callback_user_data.h"
 #include "MsgCommon/AttributeFilter.h"
 #include "MsgCommon/SortMode.h"
 #include "messaging_util.h"
@@ -37,9 +38,9 @@ namespace messaging {
 
 class Message;
 
-class FindMsgCallbackUserData: public common::CallbackUserData {
+class FindMsgCallbackUserData : public CallbackUserData {
 public:
-    FindMsgCallbackUserData(PostQueue& queue);
+    FindMsgCallbackUserData(PostQueue& queue, long cid);
     virtual ~FindMsgCallbackUserData();
 
     void setFilter(AbstractFilterPtr filter);
@@ -49,13 +50,6 @@ public:
     void addMessage(std::shared_ptr<Message> msg);
     std::vector<std::shared_ptr<Message>> getMessages() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void SetError(const common::PlatformResult& error);
-    bool isError() const;
-    std::string getErrorName() const;
-    std::string getErrorMessage() const;
-
     void setAccountId(int account_id);
     int getAccountId() const;
 
@@ -66,19 +60,14 @@ public:
     long getLimit() const;
     long getOffset() const;
 
-    PostQueue& getQueue() { return queue_;};
 private:
     AbstractFilterPtr m_filter;
     SortModePtr m_sort;
     long m_limit;
     long m_offset;
-    bool m_is_error;
-    std::string m_err_name;
-    std::string m_err_message;
     std::vector<std::shared_ptr<Message>> m_messages;
     int m_account_id;
     MessageType m_service_type;
-    PostQueue& queue_;
 };
 
 }//Messaging
index ad34e66..e5566b9 100755 (executable)
 namespace extension {
 namespace messaging {
 
-
-FoldersCallbackData::FoldersCallbackData(PostQueue& queue):
-        m_filter(),
-        m_is_error(false),
-        queue_(queue)
-{
-    LoggerD("Entered");
-}
-
-FoldersCallbackData::FoldersCallbackData(long cid, PostQueue& queue, bool keep):
-        m_filter(),
-        m_is_error(false),
-        queue_(queue)
-{
-    LoggerD("Entered");
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& o = json->get<picojson::object>();
-    o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
-    o[JSON_CALLBACK_KEEP] = picojson::value(keep);
-    setJson(json);
-}
-
 FoldersCallbackData::~FoldersCallbackData() {
     LoggerD("Entered");
 }
@@ -65,57 +43,5 @@ tizen::AbstractFilterPtr FoldersCallbackData::getFilter() const
     return m_filter;
 }
 
-void FoldersCallbackData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        m_is_error = true;
-        m_err_name = err_name;
-        m_err_message = err_message;
-
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
-        auto obj_error = picojson::object();
-        obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
-        obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-        obj[JSON_DATA] = picojson::value(obj_error);
-    }
-}
-
-void FoldersCallbackData::SetError(const common::PlatformResult& error)
-{
-    LoggerD("Entered");
-  // keep only first error in chain
-  if (!m_is_error) {
-      LoggerD("Error has not been set yet");
-    m_is_error = true;
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_data = picojson::object();
-    obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-    obj[JSON_DATA] = picojson::value(obj_data);
-  }
-}
-
-bool FoldersCallbackData::isError() const
-{
-    return m_is_error;
-}
-
-std::string FoldersCallbackData::getErrorName() const
-{
-    return m_err_name;
-}
-
-std::string FoldersCallbackData::getErrorMessage() const
-{
-    return m_err_message;
-}
-
 }//messaging
 }//extension
index 0fcfcd9..34a5076 100755 (executable)
 #ifndef __TIZEN_FOLDERS_CALLBACK_DATA_H__
 #define __TIZEN_FOLDERS_CALLBACK_DATA_H__
 
-#include "common/callback_user_data.h"
 #include "common/platform_result.h"
 
 #include <memory>
 #include <vector>
 #include <string>
 
+#include "messaging/callback_user_data.h"
 #include "MsgCommon/AbstractFilter.h"
 
 #include "message_folder.h"
@@ -34,10 +34,9 @@ namespace messaging {
 
 class MessageFolder;
 
-class FoldersCallbackData: public common::CallbackUserData {
+class FoldersCallbackData : public CallbackUserData {
 public:
-    FoldersCallbackData(PostQueue& queue);
-    FoldersCallbackData(long cid, PostQueue& queue, bool keep = false);
+    using CallbackUserData::CallbackUserData;
     virtual ~FoldersCallbackData();
 
     void addFolder(std::shared_ptr<MessageFolder> folder);
@@ -46,22 +45,9 @@ public:
     void setFilter(tizen::AbstractFilterPtr filter);
     tizen::AbstractFilterPtr getFilter() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void SetError(const common::PlatformResult& error);
-    bool isError() const;
-    std::string getErrorName() const;
-    std::string getErrorMessage() const;
-
-    PostQueue& getQueue() { return queue_;};
 private:
     std::vector<std::shared_ptr<MessageFolder>> m_folders;
     tizen::AbstractFilterPtr m_filter;
-    bool m_is_error;
-    std::string m_err_name;
-    std::string m_err_message;
-    PostQueue& queue_;
-
 };
 
 }//messaging
index 504f8b5..1998e55 100755 (executable)
@@ -32,7 +32,7 @@ FoldersChangeCallback::FoldersChangeCallback(
         int service_id,
         MessageType service_type,
         PostQueue& queue):
-    m_callback_data(cid, queue, true),
+    m_callback_data(queue, cid, true),
     m_id(service_id),
     m_msg_type(service_type),
     m_is_act(true)
@@ -99,17 +99,8 @@ void FoldersChangeCallback::added(const FolderPtrVector& folders)
     LoggerD("Calling:%s with:%d added folders", FOLDERSADDED,
             filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(FOLDERSADDED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
-    } else {
-      LoggerE("Callback id is missing");
-    }
+    m_callback_data.SetAction(FOLDERSADDED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::MEDIUM);
 }
 
 void FoldersChangeCallback::updated(const FolderPtrVector& folders)
@@ -136,17 +127,8 @@ void FoldersChangeCallback::updated(const FolderPtrVector& folders)
     LoggerD("Calling:%s with:%d updated folders", FOLDERSUPDATED,
             filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(FOLDERSUPDATED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
-    } else {
-      LoggerE("Callback id is missing");
-    }
+    m_callback_data.SetAction(FOLDERSUPDATED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LOW);
 }
 
 void FoldersChangeCallback::removed(const FolderPtrVector& folders)
@@ -173,17 +155,8 @@ void FoldersChangeCallback::removed(const FolderPtrVector& folders)
     LoggerD("Calling:%s with:%d removed folders", FOLDERSREMOVED,
             filtered.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(FOLDERSREMOVED);
-    obj[JSON_DATA] = picojson::value(array);
-
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
-    } else {
-      LoggerE("Callback id is missing");
-    }
+    m_callback_data.SetAction(FOLDERSREMOVED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LAST);
 }
 
 void FoldersChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
index e584261..82d521f 100755 (executable)
 namespace extension {
 namespace messaging {
 
-MessageCallbackUserData::MessageCallbackUserData(PostQueue& queue):
-        common::CallbackUserData(),
-        m_is_error(false),
-        queue_(queue),
-        m_account_id(-1)
-{
-    LoggerD("Entered");
+MessageCallbackUserData::MessageCallbackUserData(PostQueue& queue, long cid) :
+    CallbackUserData(queue, cid),
+    m_account_id(0) {
+  LoggerD("Entered");
 }
 
 MessageCallbackUserData::~MessageCallbackUserData() {
@@ -50,60 +47,5 @@ int MessageCallbackUserData::getAccountId() const
     return m_account_id;
 }
 
-void MessageCallbackUserData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-        auto objData = picojson::object();
-
-        objData[JSON_ERROR_NAME] = picojson::value(err_name);
-        objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
-        obj[JSON_DATA] = picojson::value(objData);
-
-        m_is_error = true;
-        m_err_name = err_name;
-        m_err_message = err_message;
-    }
-}
-
-void MessageCallbackUserData::setError(const common::PlatformResult& error)
-{
-  LoggerD("Entered");
-  // keep only first error in chain
-  if (!m_is_error) {
-    LoggerD("Error has not been set yet");
-    m_is_error = true;
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_data = picojson::object();
-
-    obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
-    obj[JSON_DATA] = picojson::value(obj_data);
-  }
-}
-
-bool MessageCallbackUserData::isError() const
-{
-    return m_is_error;
-}
-
-std::string MessageCallbackUserData::getErrorName() const
-{
-    return m_err_name;
-}
-
-std::string MessageCallbackUserData::getErrorMessage() const
-{
-    return m_err_message;
-}
-
 }//messaging
 }//extension
index d6afe5c..098c8cd 100755 (executable)
 #ifndef MESSAGING_MESSAGE_CALLBACK_USER_DATA_H_
 #define MESSAGING_MESSAGE_CALLBACK_USER_DATA_H_
 
-#include "common/callback_user_data.h"
 #include "common/platform_result.h"
 
 #include <memory>
 #include <string>
+#include "messaging/callback_user_data.h"
 
 namespace extension {
 namespace messaging {
@@ -29,9 +29,9 @@ namespace messaging {
 class Message;
 class PostQueue;
 
-class MessageCallbackUserData: public common::CallbackUserData {
+class MessageCallbackUserData : public CallbackUserData {
 public:
-    MessageCallbackUserData(PostQueue& queue);
+    MessageCallbackUserData(PostQueue& queue, long cid);
     virtual ~MessageCallbackUserData();
 
     void setMessage(std::shared_ptr<Message> message);
@@ -40,23 +40,9 @@ public:
     void setAccountId(int account_id);
     int getAccountId() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void setError(const common::PlatformResult& error);
-    bool isError() const;
-    std::string getErrorName() const;
-    std::string getErrorMessage() const;
-
-    PostQueue& getQueue() { return queue_;};
-
 private:
-    bool m_is_error;
-    PostQueue& queue_;
-    std::string m_err_name;
-    std::string m_err_message;
     std::shared_ptr<Message> m_message;
     int m_account_id;
-
 };
 
 }//messaging
index 0ee7c0e..f420ccc 100755 (executable)
@@ -41,15 +41,12 @@ const char* JSON_SERVICE_NAME = "name";
 
 //#################### MessageRecipientsCallbackData ####################
 
-MessageRecipientsCallbackData::MessageRecipientsCallbackData(PostQueue& queue):
-        m_is_error(false),
-        m_account_id(-1),
-        m_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
-        m_default_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
-        queue_(queue)
-{
-    LoggerD("Entered");
-    m_msg_recipients = std::vector<std::string>();
+MessageRecipientsCallbackData::MessageRecipientsCallbackData(PostQueue& queue, long cid) :
+    CallbackUserData(queue, cid),
+    m_account_id(-1),
+    m_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN),
+    m_default_sim_index(TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN) {
+  LoggerD("Entered");
 }
 
 MessageRecipientsCallbackData::~MessageRecipientsCallbackData()
@@ -78,50 +75,6 @@ const std::vector<std::string>& MessageRecipientsCallbackData::getMessageRecipie
     return m_msg_recipients;
 }
 
-void MessageRecipientsCallbackData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        m_is_error = true;
-
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-        auto obj_error = picojson::object();
-
-        obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
-        obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
-        obj[JSON_DATA] = picojson::value(obj_error);
-    }
-}
-
-void MessageRecipientsCallbackData::setError(const PlatformResult& error)
-{
-  LoggerD("Entered");
-  // keep only first error in chain
-  if (!m_is_error) {
-    LoggerD("Error has not been set yet");
-    m_is_error = true;
-
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_error = picojson::object();
-
-    obj_error[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_error[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
-    obj[JSON_DATA] = picojson::value(obj_error);
-  }
-}
-
-bool MessageRecipientsCallbackData::isError() const
-{
-    return m_is_error;
-}
-
 void MessageRecipientsCallbackData::setAccountId(int account_id){
     m_account_id = account_id;
 }
@@ -149,8 +102,7 @@ bool MessageRecipientsCallbackData::setSimIndex(
     sim_index--;
     if (sim_index >= sim_count || sim_index < -1) {
         LoggerE("Sim index out of bound %d : %d", sim_index, sim_count);
-        common::InvalidValuesException err("The index of sim is out of bound");
-        this->setError(err.name(), err.message());
+        this->SetError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "The index of sim is out of bound"));
         return false;
     }
 
@@ -182,13 +134,10 @@ TelNetworkDefaultDataSubs_t MessageRecipientsCallbackData::getDefaultSimIndex()
 
 //#################### BaseMessageServiceCallbackData ####################
 
-BaseMessageServiceCallbackData::BaseMessageServiceCallbackData():
-//        CallbackUserData(globalCtx),
-        m_is_error(false),
-        m_op_handle(-1),
-        m_callback_id(-1)
-{
-    LoggerD("Entered");
+BaseMessageServiceCallbackData::BaseMessageServiceCallbackData(PostQueue& queue, long cid) :
+    CallbackUserData(queue, cid),
+    m_op_handle(-1) {
+  LoggerD("Entered");
 }
 
 BaseMessageServiceCallbackData::~BaseMessageServiceCallbackData()
@@ -196,49 +145,6 @@ BaseMessageServiceCallbackData::~BaseMessageServiceCallbackData()
     LoggerD("Entered");
 }
 
-void BaseMessageServiceCallbackData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        m_is_error = true;
-
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-
-        auto obj_error = picojson::object();
-        obj_error[JSON_ERROR_NAME] = picojson::value(err_name);
-        obj_error[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-        obj[JSON_DATA] = picojson::value(obj_error);
-    }
-}
-
-void BaseMessageServiceCallbackData::setError(const PlatformResult& error)
-{
-  LoggerD("Entered");
-  // keep only first error in chain
-  if (!m_is_error) {
-    LoggerD("Error has not been set yet");
-    m_is_error = true;
-
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_error = picojson::object();
-
-    obj_error[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_error[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-
-    obj[JSON_DATA] = picojson::value(obj_error);
-  }
-}
-
-bool BaseMessageServiceCallbackData::isError() const
-{
-    return m_is_error;
-}
-
 void BaseMessageServiceCallbackData::setOperationHandle(const int op_handle)
 {
     m_op_handle = op_handle;
@@ -249,24 +155,8 @@ int BaseMessageServiceCallbackData::getOperationHandle() const
     return m_op_handle;
 }
 
-void BaseMessageServiceCallbackData::setCallbackId(const double callback_id)
-{
-    m_callback_id = callback_id;
-}
-
-double BaseMessageServiceCallbackData::getCallbackId() const
-{
-    return m_callback_id;
-}
-
 //#################### MessageBodyCallbackData ####################
 
-MessageBodyCallbackData::MessageBodyCallbackData(PostQueue& queue):
-    queue_(queue)
-{
-    LoggerD("Entered");
-}
-
 MessageBodyCallbackData::~MessageBodyCallbackData()
 {
     LoggerD("Entered");
@@ -284,11 +174,10 @@ std::shared_ptr<Message> MessageBodyCallbackData::getMessage() const
 
 //#################### MessageAttachmentCallbackData ####################
 
-MessageAttachmentCallbackData::MessageAttachmentCallbackData(PostQueue& queue):
-        m_nth(0),
-        queue_(queue)
-{
-    LoggerD("Entered");
+MessageAttachmentCallbackData::MessageAttachmentCallbackData(PostQueue& queue, long cid) :
+    BaseMessageServiceCallbackData(queue, cid),
+    m_nth(0) {
+  LoggerD("Entered");
 }
 
 MessageAttachmentCallbackData::~MessageAttachmentCallbackData()
@@ -320,15 +209,14 @@ int MessageAttachmentCallbackData::getNth() const
 
 //#################### SyncCallbackData ####################
 
-SyncCallbackData::SyncCallbackData(PostQueue& queue):
-//        BaseMessageServiceCallbackData(globalCtx),
-        m_is_limit(false),
-        m_limit(0),
-        m_op_id(-1),
-        m_account_id(-1),
-        queue_(queue)
-{
-    LoggerD("Entered");
+
+SyncCallbackData::SyncCallbackData(PostQueue& queue, long cid) :
+    BaseMessageServiceCallbackData(queue, cid),
+    m_is_limit(false),
+    m_limit(0),
+    m_op_id(-1),
+    m_account_id(-1) {
+  LoggerD("Entered");
 }
 
 SyncCallbackData::~SyncCallbackData()
@@ -374,12 +262,6 @@ int SyncCallbackData::getAccountId() const
 
 //#################### SyncFolderCallbackData ####################
 
-SyncFolderCallbackData::SyncFolderCallbackData(PostQueue& queue):
-    SyncCallbackData(queue)
-{
-    LoggerD("Entered");
-}
-
 SyncFolderCallbackData::~SyncFolderCallbackData()
 {
     LoggerD("Entered");
index 8952362..5aab33e 100755 (executable)
@@ -21,8 +21,8 @@
 #include <memory>
 #include <string>
 
+#include "messaging/callback_user_data.h"
 #include "common/picojson.h"
-#include "common/callback_user_data.h"
 #include "common/platform_result.h"
 
 #include "messaging_util.h"
@@ -39,9 +39,9 @@ enum MessageServiceAccountId
     MMS_ACCOUNT_ID = 102
 };
 
-class MessageRecipientsCallbackData : public common::CallbackUserData {
+class MessageRecipientsCallbackData : public CallbackUserData {
 public:
-    MessageRecipientsCallbackData(PostQueue& queue);
+    MessageRecipientsCallbackData(PostQueue& queue, long cid);
     virtual ~MessageRecipientsCallbackData();
 
     void setMessage(std::shared_ptr<Message> message);
@@ -50,11 +50,6 @@ public:
     void setMessageRecipients(const std::vector<std::string>& msgRecipients);
     const std::vector<std::string>& getMessageRecipients() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void setError(const common::PlatformResult& error);
-    bool isError() const;
-
     void setAccountId(int account_id);
     int getAccountId() const;
 
@@ -64,28 +59,19 @@ public:
     TelNetworkDefaultDataSubs_t getDefaultSimIndex() const;
     bool isSetSimIndex() const;
 
-    PostQueue& getQueue() { return queue_;};
-
 private:
     std::shared_ptr<Message> m_message;
-    bool m_is_error;
     std::vector<std::string> m_msg_recipients;
     int m_account_id;
     TelNetworkDefaultDataSubs_t m_sim_index;
     TelNetworkDefaultDataSubs_t m_default_sim_index;
-    PostQueue& queue_;
 };
 
-class BaseMessageServiceCallbackData : public common::CallbackUserData {
+class BaseMessageServiceCallbackData : public CallbackUserData {
 public:
-    BaseMessageServiceCallbackData();
+    BaseMessageServiceCallbackData(PostQueue& queue, long cid);
     virtual ~BaseMessageServiceCallbackData();
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void setError(const common::PlatformResult& error);
-    bool isError() const;
-
     /**
      * This handle is returned from various native API functions:
      *   int email_sync_header(..., int *handle);
@@ -96,33 +82,26 @@ public:
      */
     void setOperationHandle(const int op_handle);
     int getOperationHandle() const;
-    void setCallbackId(const double callback_id);
-    double getCallbackId() const;
 
 protected:
-    bool m_is_error;
-
     int m_op_handle;
-    double m_callback_id;
 };
 
 class MessageBodyCallbackData : public BaseMessageServiceCallbackData {
 public:
-    MessageBodyCallbackData(PostQueue& queue);
+    using BaseMessageServiceCallbackData::BaseMessageServiceCallbackData;
     virtual ~MessageBodyCallbackData();
 
     void setMessage(std::shared_ptr<Message> message);
     std::shared_ptr<Message> getMessage() const;
 
-    PostQueue& getQueue() { return queue_;};
 private:
     std::shared_ptr<Message> m_message;
-    PostQueue& queue_;
 };
 
 class MessageAttachmentCallbackData : public BaseMessageServiceCallbackData {
 public:
-    MessageAttachmentCallbackData(PostQueue& queue);
+    MessageAttachmentCallbackData(PostQueue& queue, long cid);
     virtual ~MessageAttachmentCallbackData();
 
     void setMessageAttachment(std::shared_ptr<MessageAttachment> messageAttachment);
@@ -138,16 +117,14 @@ public:
     void setNth(const int nth);
     int getNth() const;
 
-    PostQueue& getQueue() { return queue_;};
 private:
     std::shared_ptr<MessageAttachment> m_message_attachment;
     int m_nth;
-    PostQueue& queue_;
 };
 
 class SyncCallbackData : public BaseMessageServiceCallbackData {
 public:
-    SyncCallbackData(PostQueue& queue);
+    SyncCallbackData(PostQueue& queue, long cid);
     virtual ~SyncCallbackData();
 
     void setLimit(const unsigned long limit);
@@ -159,19 +136,17 @@ public:
     void setAccountId(int account_id);
     int getAccountId() const;
 
-    PostQueue& getQueue() { return queue_;};
 protected:
     bool m_is_limit;
     unsigned long m_limit;
 
     long m_op_id;
     int m_account_id;
-    PostQueue& queue_;
 };
 
 class SyncFolderCallbackData : public SyncCallbackData {
 public:
-    SyncFolderCallbackData(PostQueue& queue);
+    using SyncCallbackData::SyncCallbackData;
     virtual ~SyncFolderCallbackData();
 
     void setMessageFolder(std::shared_ptr<MessageFolder> message_folder);
index 9c5ee86..cfee4b6 100755 (executable)
@@ -115,22 +115,12 @@ static gboolean loadMessageAttachmentTask(void* data)
 
     // if the attachment is already saved, then it doesn't need to load again.
     if (att->isFilePathSet() && att->isSaved()) {
-      auto json = callback->getJson();
-      picojson::object& obj = json->get<picojson::object>();
-      obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-      if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-        picojson::object args;
-        args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(att);
-        obj[JSON_DATA] = picojson::value(args);
-
-        callback->getQueue().resolve(
-            obj.at(JSON_CALLBACK_ID).get<double>(),
-            json->serialize()
-        );
-      } else {
-        LoggerE("json is incorrect - missing required member");
-      }
+      picojson::object args;
+      args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(att);
+
+      callback->SetSuccess(picojson::value(args));
+      callback->Post();
+
       delete callback;
       callback = nullptr;
     } else {
index 0c405f5..32b800f 100755 (executable)
@@ -136,22 +136,12 @@ static gboolean loadMessageBodyTask(void* data)
     }
 
     std::shared_ptr<MessageBody> body = callback->getMessage()->getBody();
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      picojson::object args;
-      args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(body);
-      obj[JSON_DATA] = picojson::value(args);
-
-      callback->getQueue().resolve(
-          obj.at(JSON_CALLBACK_ID).get<double>(),
-          json->serialize()
-      );
-    } else {
-      LoggerE("json is incorrect - missing required member");
-    }
+    picojson::object args;
+    args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(body);
+
+    callback->SetSuccess(picojson::value(args));
+    callback->Post();
+
     return FALSE;
 }
 
index 0c81118..2691a3e 100755 (executable)
@@ -206,29 +206,17 @@ static gboolean findFoldersCB(void* data)
 
     FoldersCallbackData *callback = static_cast<FoldersCallbackData*>(data);
 
-    auto json = callback->getJson();
-    picojson::object& obj = json->get<picojson::object>();
+    picojson::array array;
+    auto each = [&array](std::shared_ptr<MessageFolder> folder)->void {
+      array.push_back(MessagingUtil::folderToJson(folder));
+    };
 
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      picojson::array array;
-      auto each = [&array](std::shared_ptr<MessageFolder> folder)->void {
-        array.push_back(MessagingUtil::folderToJson(folder));
-      };
+    auto folders = callback->getFolders();
+    for_each(folders.begin(), folders.end(), each);
 
-      auto folders = callback->getFolders();
-      for_each(folders.begin(), folders.end(), each);
+    callback->SetSuccess(picojson::value(array));
+    callback->Post();
 
-      obj[JSON_DATA] = picojson::value(array);
-      obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-
-     callback->getQueue().resolve(
-          obj.at(JSON_CALLBACK_ID).get<double>(),
-          json->serialize()
-      );
-    } else {
-      LoggerE("json is incorrect - missing required member");
-    }
     delete callback;
     callback = NULL;
 
index 92838f6..37cdf76 100755 (executable)
 namespace extension {
 namespace messaging {
 
-MessagesCallbackUserData::MessagesCallbackUserData(PostQueue& queue):
-        common::CallbackUserData(),
-        m_is_error(false),
-        m_service_type(MessageType::UNDEFINED),
-        queue_(queue)
-{
-    LoggerD("Entered");
-}
-
-MessagesCallbackUserData::MessagesCallbackUserData(long cid, PostQueue& queue, bool keep):
-        common::CallbackUserData(),
-        m_is_error(false),
-        m_service_type(MessageType::UNDEFINED),
-        queue_(queue)
-{
-    LoggerD("Entered");
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& o = json->get<picojson::object>();
-    o[JSON_CALLBACK_ID] = picojson::value(static_cast<double>(cid));
-    o[JSON_CALLBACK_KEEP] = picojson::value(keep);
-    setJson(json);
+MessagesCallbackUserData::MessagesCallbackUserData(PostQueue& queue, long cid, bool keep /* = false*/) :
+    CallbackUserData(queue, cid, keep),
+    m_service_type(UNDEFINED) {
+  LoggerD("Entered");
 }
 
 MessagesCallbackUserData::~MessagesCallbackUserData() {
@@ -57,58 +40,6 @@ std::vector<std::shared_ptr<Message>> MessagesCallbackUserData::getMessages() co
     return m_messages;
 }
 
-void MessagesCallbackUserData::setError(const std::string& err_name,
-        const std::string& err_message)
-{
-    LoggerD("Entered");
-    // keep only first error in chain
-    if (!m_is_error) {
-        LoggerD("Error has not been set yet");
-        picojson::object& obj = m_json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-        auto objData = picojson::object();
-
-        objData[JSON_ERROR_NAME] = picojson::value(err_name);
-        objData[JSON_ERROR_MESSAGE] = picojson::value(err_message);
-
-        obj[JSON_DATA] = picojson::value(objData);
-
-        m_is_error = true;
-        m_err_name = err_name;
-        m_err_message = err_message;
-    }
-}
-
-void MessagesCallbackUserData::SetError(const common::PlatformResult& error)
-{
-  // keep only first error in chain
-  if (!m_is_error) {
-    LoggerD("Error has not been set yet");
-    m_is_error = true;
-    picojson::object& obj = m_json->get<picojson::object>();
-    obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR);
-    auto obj_data = picojson::object();
-    obj_data[JSON_ERROR_CODE] = picojson::value(static_cast<double>(error.error_code()));
-    obj_data[JSON_ERROR_MESSAGE] = picojson::value(error.message());
-    obj[JSON_DATA] = picojson::value(obj_data);
-  }
-}
-
-bool MessagesCallbackUserData::isError() const
-{
-    return m_is_error;
-}
-
-std::string MessagesCallbackUserData::getErrorName() const
-{
-    return m_err_name;
-}
-
-std::string MessagesCallbackUserData::getErrorMessage() const
-{
-    return m_err_message;
-}
-
 void MessagesCallbackUserData::setMessageServiceType(MessageType m_msg_type)
 {
     m_service_type = m_msg_type;
index d1ee4ee..4efa84f 100755 (executable)
 #ifndef MESSAGING_MESSAGES_CALLBACK_USER_DATA_H_
 #define MESSAGING_MESSAGES_CALLBACK_USER_DATA_H_
 
-#include "common/callback_user_data.h"
 #include "common/platform_result.h"
 
 #include <memory>
 #include <string>
 
+#include "messaging/callback_user_data.h"
 #include "messaging_util.h"
 
 namespace extension {
@@ -30,34 +30,20 @@ namespace messaging {
 
 class Message;
 
-class MessagesCallbackUserData: public common::CallbackUserData {
+class MessagesCallbackUserData : public CallbackUserData {
 public:
-    MessagesCallbackUserData(PostQueue& queue);
-    MessagesCallbackUserData(long cid, PostQueue& queue, bool keep = false);
+    MessagesCallbackUserData(PostQueue& queue, long cid, bool keep = false);
     virtual ~MessagesCallbackUserData();
 
     void addMessage(std::shared_ptr<Message> msg);
     std::vector<std::shared_ptr<Message>> getMessages() const;
 
-    void setError(const std::string& err_name,
-            const std::string& err_message);
-    void SetError(const common::PlatformResult& error);
-    bool isError() const;
-    std::string getErrorName() const;
-    std::string getErrorMessage() const;
-
     void setMessageServiceType(MessageType m_msg_type);
     MessageType getMessageServiceType() const;
 
-    PostQueue& getQueue() { return queue_;};
-
 private:
     std::vector<std::shared_ptr<Message>> m_messages;
-    bool m_is_error;
-    std::string m_err_name;
-    std::string m_err_message;
     MessageType m_service_type;
-    PostQueue& queue_;
 };
 
 }//messaging
index 19bdec5..e2fcdb6 100755 (executable)
@@ -53,7 +53,7 @@ MessagesChangeCallback::MessagesChangeCallback(
         int service_id,
         MessageType service_type,
         PostQueue& queue) :
-        m_callback_data(cid, queue, true),
+        m_callback_data(queue, cid, true),
         m_service_id(service_id),
         m_msg_type(service_type),
         m_is_act(true)
@@ -136,17 +136,8 @@ void MessagesChangeCallback::added(const MessagePtrVector& msgs)
     LoggerD("Calling:%s with:%d added messages", MESSAGESADDED,
         filtered_msgs.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      obj[JSON_ACTION] = picojson::value(MESSAGESADDED);
-      obj[JSON_DATA] = picojson::value(array);
-
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::MEDIUM, json->serialize());
-    } else {
-      LoggerE("json is incorrect - missing required member");
-    }
+    m_callback_data.SetAction(MESSAGESADDED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::MEDIUM);
 }
 
 void MessagesChangeCallback::updated(const MessagePtrVector& msgs)
@@ -173,17 +164,8 @@ void MessagesChangeCallback::updated(const MessagePtrVector& msgs)
     LoggerD("Calling:%s with:%d updated messages", MESSAGESUPDATED,
         filtered_msgs.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      obj[JSON_ACTION] = picojson::value(MESSAGESUPDATED);
-      obj[JSON_DATA] = picojson::value(array);
-
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::LOW, json->serialize());
-    } else {
-      LoggerE("json is incorrect - missing required member");
-    }
+    m_callback_data.SetAction(MESSAGESUPDATED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LOW);
 }
 
 void MessagesChangeCallback::removed(const MessagePtrVector& msgs)
@@ -211,18 +193,8 @@ void MessagesChangeCallback::removed(const MessagePtrVector& msgs)
     LoggerD("Calling:%s with:%d removed messages", MESSAGESREMOVED,
         filtered_msgs.size());
 
-    auto json = m_callback_data.getJson();
-    picojson::object& obj = json->get<picojson::object>();
-    if (json->contains(JSON_CALLBACK_ID) && obj.at(JSON_CALLBACK_ID).is<double>()) {
-      obj[JSON_ACTION] = picojson::value(MESSAGESREMOVED);
-      LoggerD("MESSAGES: %s", picojson::value(array).serialize().c_str());
-      obj[JSON_DATA] = picojson::value(array);
-
-      m_callback_data.getQueue().addAndResolve(obj.at(
-          JSON_CALLBACK_ID).get<double>(), PostPriority::LAST, json->serialize());
-    } else {
-      LoggerE("json is incorrect - missing required member");
-    }
+    m_callback_data.SetAction(MESSAGESREMOVED, picojson::value(array));
+    m_callback_data.AddAndPost(PostPriority::LAST);
 }
 
 void MessagesChangeCallback::setFilter(tizen::AbstractFilterPtr filter)
index a92e434..1847b47 100644 (file)
@@ -26,6 +26,8 @@
       },
       'sources': [
         'messaging_api.js',
+        'callback_user_data.cc',
+        'callback_user_data.h',
         'email_manager.cc',
         'email_manager.h',
         'messaging_instance.cc',
index 3f9053e..f07657b 100755 (executable)
@@ -215,11 +215,10 @@ void MessagingInstance::MessageServiceSendMessage(const picojson::value& args,
       POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
     }
 
-    MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData(queue_);
+    MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData(queue_, callbackId);
     long simIndex = 0;
     int serviceId = 0;
 
-    callback->setJson(json);
     callback->setMessage(message);
     serviceId = getServiceIdFromJSON(data);
     callback->setAccountId(serviceId);
@@ -233,7 +232,7 @@ void MessagingInstance::MessageServiceSendMessage(const picojson::value& args,
                       json, obj, JSON_CALLBACK_ERROR)
     }
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto service = manager_.getMessageService(serviceId);
 
     ret = service->sendMessage(callback);
@@ -268,12 +267,11 @@ void MessagingInstance::MessageServiceLoadMessageBody(const picojson::value& arg
       POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
     }
 
-    MessageBodyCallbackData* callback = new MessageBodyCallbackData(queue_);
+    MessageBodyCallbackData* callback = new MessageBodyCallbackData(queue_, callbackId);
 
-    callback->setJson(json);
     callback->setMessage(message);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
     ret = service->loadMessageBody(callback);
     if (ret.IsError()) {
@@ -296,18 +294,16 @@ void MessagingInstance::MessageServiceLoadMessageAttachment(const picojson::valu
     picojson::value attachment = data.at(LOAD_MESSAGE_ATTACHMENT_ARGS_ATTACHMENT);
     const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
 
-    MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData(queue_);
+    MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData(queue_, callbackId);
     callback->setMessageAttachment(MessagingUtil::jsonToMessageAttachment(attachment));
 
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-    callback->setJson(json);
-
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
     const auto result = service->loadMessageAttachment(callback);
     if (result.IsError()) {
+      auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+      picojson::object& obj = json->get<picojson::object>();
+      obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
       POST_AND_RETURN(result, json, obj, JSON_CALLBACK_ERROR)
     }
 }
@@ -341,16 +337,11 @@ void MessagingInstance::MessageServiceSync(const picojson::value& args,
         limit = static_cast<long>(v_limit.get<double>());
     }
 
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-
-    SyncCallbackData *callback = new SyncCallbackData(queue_);
-    callback->setJson(json);
+    SyncCallbackData *callback = new SyncCallbackData(queue_, callbackId);
     callback->setAccountId(id);
     callback->setLimit(limit);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     long op_id = -1;
 
     const auto result = manager_.getMessageService(id)->sync(callback, &op_id);
@@ -393,17 +384,12 @@ void MessagingInstance::MessageServiceSyncFolder(const picojson::value& args,
         limit = static_cast<long>(v_limit.get<double>());
     }
 
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-
-    SyncFolderCallbackData *callback = new SyncFolderCallbackData(queue_);
-    callback->setJson(json);
+    SyncFolderCallbackData *callback = new SyncFolderCallbackData(queue_, callbackId);
     callback->setAccountId(id);
     callback->setMessageFolder(MessagingUtil::jsonToMessageFolder(v_folder));
     callback->setLimit(limit);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     long op_id = -1;
 
     const auto result = manager_.getMessageService(id)->syncFolder(callback, &op_id);
@@ -483,15 +469,13 @@ void MessagingInstance::MessageStorageAddDraft(const picojson::value& args,
       POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
     }
 
-    MessageCallbackUserData* callback = new MessageCallbackUserData(queue_);
+    MessageCallbackUserData* callback = new MessageCallbackUserData(queue_, callbackId);
     callback->setMessage(message);
 
     int serviceId = getServiceIdFromJSON(data);
     callback->setAccountId(serviceId);
 
-    callback->setJson(json);
-
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto service = manager_.getMessageService(serviceId);
     service->getMsgStorage()->addDraftMessage(callback);
 }
@@ -530,15 +514,14 @@ void MessagingInstance::MessageStorageFindMessages(const picojson::value& args,
     int serviceId = getServiceIdFromJSON(data);
     auto storage = manager_.getMessageService(serviceId)->getMsgStorage();
 
-    FindMsgCallbackUserData* callback = new FindMsgCallbackUserData(queue_);
+    FindMsgCallbackUserData* callback = new FindMsgCallbackUserData(queue_, callbackId);
     callback->setFilter(filter);
     callback->setLimit(limit);
     callback->setOffset(offset);
     callback->setAccountId(serviceId);
     callback->setSortMode(sortMode);
-    callback->setJson(json);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     storage->findMessages(callback);
 }
 
@@ -557,7 +540,7 @@ void MessagingInstance::MessageStorageRemoveMessages(const picojson::value& args
     picojson::array messages = data.at(REMOVE_MESSAGES_ARGS_MESSAGES).get<picojson::array>();
     const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
 
-    MessagesCallbackUserData* callback = new MessagesCallbackUserData(queue_);
+    MessagesCallbackUserData* callback = new MessagesCallbackUserData(queue_, callbackId);
 
     auto each = [callback] (picojson::value& v)->void {
       std::shared_ptr<Message> message;
@@ -569,14 +552,9 @@ void MessagingInstance::MessageStorageRemoveMessages(const picojson::value& args
 
     for_each(messages.begin(), messages.end(), each);
 
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-    callback->setJson(json);
-
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     service->getMsgStorage()->removeMessages(callback);
 }
 
@@ -596,7 +574,7 @@ void MessagingInstance::MessageStorageUpdateMessages(const picojson::value& args
     auto pico_array = pico_messages.get<picojson::array>();
     const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
 
-    auto callback = new MessagesCallbackUserData(queue_);
+    auto callback = new MessagesCallbackUserData(queue_, callbackId);
 
     std::for_each(pico_array.begin(), pico_array.end(), [&callback](picojson::value& v)->void {
        std::shared_ptr<Message> message;
@@ -606,14 +584,9 @@ void MessagingInstance::MessageStorageUpdateMessages(const picojson::value& args
        }
     });
 
-    auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-    picojson::object& obj = json->get<picojson::object>();
-    obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
-    callback->setJson(json);
-
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     service->getMsgStorage()->updateMessages(callback);
 }
 
@@ -648,15 +621,14 @@ void MessagingInstance::MessageStorageFindConversations(const picojson::value& a
 
     int serviceId = getServiceIdFromJSON(data);
 
-    ConversationCallbackData* callback = new ConversationCallbackData(queue_);
+    ConversationCallbackData* callback = new ConversationCallbackData(queue_, callbackId);
     callback->setFilter(filter);
     callback->setLimit(limit);
     callback->setOffset(offset);
     callback->setAccountId(serviceId);
     callback->setSortMode(sortMode);
-    callback->setJson(json);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto storage = manager_.getMessageService(serviceId)->getMsgStorage();
     storage->findConversations(callback);
 }
@@ -680,7 +652,7 @@ void MessagingInstance::MessageStorageRemoveConversations(const picojson::value&
     picojson::object& obj = json->get<picojson::object>();
     obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
 
-    ConversationCallbackData* callback = new ConversationCallbackData(queue_);
+    ConversationCallbackData* callback = new ConversationCallbackData(queue_, callbackId);
 
     PlatformResult ret(ErrorCode::NO_ERROR);
     for (auto it = conversations.begin(); it != conversations.end(); ++it) {
@@ -693,11 +665,9 @@ void MessagingInstance::MessageStorageRemoveConversations(const picojson::value&
       callback->addConversation(conversation);
     }
 
-    callback->setJson(json);
-
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     service->getMsgStorage()->removeConversations(callback);
 }
 
@@ -725,11 +695,10 @@ void MessagingInstance::MessageStorageFindFolders(const picojson::value& args,
       POST_AND_RETURN(ret, json, obj, JSON_CALLBACK_ERROR)
     }
 
-    FoldersCallbackData* callback = new FoldersCallbackData(queue_);
+    FoldersCallbackData* callback = new FoldersCallbackData(queue_, callbackId);
     callback->setFilter(filter);
-    callback->setJson(json);
 
-    queue_.add(static_cast<long>(callbackId), PostPriority::HIGH);
+    callback->AddToQueue();
     auto service = manager_.getMessageService(getServiceIdFromJSON(data));
     service->getMsgStorage()->findFolders(callback);
 }
index 88e040a..918eb66 100755 (executable)
@@ -58,11 +58,7 @@ static gboolean sendMessageCompleteCB(void* data)
         return false;
     }
 
-    if (callback->isError()) {
-      callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
+    if (callback->IsError()) {
         callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
     }
     else {
@@ -70,10 +66,6 @@ static gboolean sendMessageCompleteCB(void* data)
 
         LoggerD("Calling success callback with: %d recipients", message->getTO().size());
 
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
         std::vector<picojson::value> recipients;
         auto addToRecipients = [&recipients](std::string& e)->void {
             recipients.push_back(picojson::value(e));
@@ -85,15 +77,13 @@ static gboolean sendMessageCompleteCB(void* data)
         picojson::object data;
         data[JSON_DATA_RECIPIENTS] = picojson::value(recipients);
         data[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(message);
-        obj[JSON_DATA] = picojson::value(data);
 
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess(picojson::value(data));
         callback->getMessage()->setMessageStatus(MessageStatus::STATUS_SENT);
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 
@@ -109,31 +99,21 @@ static gboolean addDraftMessageCompleteCB(void *data)
         return FALSE;
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
 
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
         callback->getMessage()->setMessageStatus(MessageStatus::STATUS_FAILED);
     } else {
         LoggerD("Calling success callback");
 
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
         picojson::object args;
         args[JSON_DATA_MESSAGE] = MessagingUtil::messageToJson(callback->getMessage());
-        obj[JSON_DATA] = picojson::value(args);
 
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess(picojson::value(args));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 
@@ -364,7 +344,7 @@ PlatformResult ShortMsgManager::sendMessage(MessageRecipientsCallbackData* callb
   if (!platform_result) {
     LoggerE("Message send failed");
 
-    callback->setError(platform_result);
+    callback->SetError(platform_result);
 
     if (!g_idle_add(sendMessageCompleteCB, static_cast<void*>(callback))) {
       LoggerE("g_idle addition failed");
@@ -410,8 +390,7 @@ void ShortMsgManager::sendStatusCallback(msg_struct_t sent_status)
                 callback->getMessage()->getId(),
                 (MSG_NETWORK_SEND_FAIL == status ? "FAIL" : "TIMEOUT"));
 
-            common::UnknownException e("Send message failed");
-            callback->setError(e.name(), e.message());
+            callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Send message failed"));
         }
 
         if (!g_idle_add(sendMessageCompleteCB, static_cast<void*>(callback))) {
@@ -742,7 +721,7 @@ void ShortMsgManager::addDraftMessage(MessageCallbackUserData* callback)
       PlatformResult ret = addDraftMessagePlatform(message);
       if (ret.IsError()) {
         LoggerE("%d (%s)", ret.error_code(), ret.message().c_str());
-        callback->setError(ret);
+        callback->SetError(ret);
       }
     }
 
@@ -777,7 +756,7 @@ void ShortMsgManager::removeMessages(MessagesCallbackUserData* callback)
             }
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             for (auto it = messages.begin() ; it != messages.end(); ++it) {
                 const int id = (*it)->getId();
 
@@ -802,25 +781,15 @@ void ShortMsgManager::removeMessages(MessagesCallbackUserData* callback)
         }
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
     } else {
         LoggerD("Calling success callback");
-
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess();
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -847,7 +816,7 @@ void ShortMsgManager::updateMessages(MessagesCallbackUserData* callback)
                 break;
             }
         }
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             for (auto it = messages.begin() ; it != messages.end(); ++it) {
                 LoggerD("updating Message(%p) msg_id:%d", (*it).get(), (*it)->getId());
 
@@ -876,19 +845,11 @@ void ShortMsgManager::updateMessages(MessagesCallbackUserData* callback)
         }
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
-
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
     } else {
         LoggerD("Calling success callback");
 
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-
         auto messages = callback->getMessages();
         picojson::array array;
         auto each = [&array] (std::shared_ptr<Message> m)->void {
@@ -897,16 +858,11 @@ void ShortMsgManager::updateMessages(MessagesCallbackUserData* callback)
 
         for_each(messages.begin(), messages.end(), each);
 
-        obj[JSON_DATA] = picojson::value(array);
-
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess(picojson::value(array));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -982,7 +938,7 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback)
             callback->SetError(ret);
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             int msgListCount = messagesIds.size();
             LoggerD("Found %d messages", msgListCount);
 
@@ -1014,7 +970,7 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback)
                     callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get platform Message structure"));
                     break;
                 }
-                if (!callback->isError()) {
+                if (!callback->IsError()) {
                     callback->addMessage(std::shared_ptr<Message>{message});
                     LoggerD("Created message with id %d:", messagesIds[i]);
                 }
@@ -1022,34 +978,23 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback)
         }
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
     } else {
         LoggerD("Calling success callback with %d messages:",
                 callback->getMessages().size());
 
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-
         std::vector<picojson::value> response;
         auto messages = callback->getMessages();
         std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){
             response.push_back(MessagingUtil::messageToJson(message));
         });
 
-        obj[JSON_DATA] = picojson::value(response);
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess(picojson::value(response));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -1073,7 +1018,7 @@ void ShortMsgManager::findConversations(ConversationCallbackData* callback)
             callback->SetError(ret);
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             int convListCount = conversationsIds.size();
             LoggerD("Found %d conversations", convListCount);
 
@@ -1090,16 +1035,10 @@ void ShortMsgManager::findConversations(ConversationCallbackData* callback)
         }
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
     } else {
         LoggerD("Calling success callback");
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
 
         std::vector<picojson::value> response;
         auto conversations = callback->getConversations();
@@ -1108,15 +1047,12 @@ void ShortMsgManager::findConversations(ConversationCallbackData* callback)
                     response.push_back(MessagingUtil::conversationToJson(conversation));
                 }
         );
-        obj[JSON_DATA] = picojson::value(response);
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
 
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess(picojson::value(response));
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
@@ -1147,7 +1083,7 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback)
             callback->SetError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error while creatng message handle"));
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
           for(auto it = conversations.begin() ; it != conversations.end(); ++it) {
               if((*it)->getType() != type) {
                   LoggerE("Invalid message type");
@@ -1158,7 +1094,7 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback)
           }
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             if(MessageType::SMS == type) {
                 msg_id_conv_id_map = &m_sms_removed_msg_id_conv_id_map;
                 conv_id_object_map = &m_sms_removed_conv_id_object_map;
@@ -1171,7 +1107,7 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback)
             }
         }
 
-        if (!callback->isError()) {
+        if (!callback->IsError()) {
             int conv_index = 0;
             for (auto it = conversations.begin() ; it != conversations.end();
                         ++it, ++conv_index) {
@@ -1222,32 +1158,23 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback)
         }
     }
 
-    if (!callback->isError()) {
+    if (!callback->IsError()) {
         error = msg_close_msg_handle(&handle);
         if (MSG_SUCCESS != error) {
             LoggerW("Cannot close message handle: %d", error);
         }
     }
 
-    if (callback->isError()) {
+    if (callback->IsError()) {
         LoggerD("Calling error callback");
-        callback->getQueue().resolve(
-                callback->getJson()->get<picojson::object>().at(JSON_CALLBACK_ID).get<double>(),
-                callback->getJson()->serialize()
-        );
     } else {
         LoggerD("Calling success callback");
 
-        auto json = callback->getJson();
-        picojson::object& obj = json->get<picojson::object>();
-        obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
-        callback->getQueue().resolve(
-                obj.at(JSON_CALLBACK_ID).get<double>(),
-                json->serialize()
-        );
+        callback->SetSuccess();
     }
 
+    callback->Post();
+
     delete callback;
     callback = NULL;
 }
index 5965b6f..9788d89 100755 (executable)
@@ -143,9 +143,10 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) {
     return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "invalid PowerState");
 
   if(current_requested_state_ == POWER_STATE_SCREEN_DIM) {
-    int ret = PowerPlatformProxy::GetInstance().UnlockState();
-    if (ret < 0) {
-      LoggerE("deviceUnlockState error %d", ret);
+    int result = 0;
+    auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result);
+    if (!error_code || result < 0) {
+      LoggerE("deviceUnlockState error %d", result);
       return PlatformResult(ErrorCode::UNKNOWN_ERR,
                             "device_power_request_unlock error");
     }
@@ -165,9 +166,10 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) {
     }
     case POWER_STATE_SCREEN_DIM:
     {
-      ret = PowerPlatformProxy::GetInstance().LockState();
-      if (ret < 0) {
-        LoggerE("device_power_request_lock error %d", ret);
+      int result = 0;
+      auto error_code = PowerPlatformProxy::GetInstance().LockState(&result);
+      if (!error_code || result < 0) {
+        LoggerE("device_power_request_lock error %d", result);
         return PlatformResult(ErrorCode::UNKNOWN_ERR,
                               "device_power_request_lock error");
       }
@@ -244,9 +246,10 @@ PlatformResult PowerManager::Release(PowerResource resource) {
       LoggerE("Platform return value from dim unlock: %d", ret);
 
     if (bright_state_enabled_) {
-      ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings();
-      if (DEVICE_ERROR_NONE != ret) {
-        LoggerE("Platform error while setting restore brightness %d", ret);
+      int result = 0;
+      auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result);
+      if (!error_code || DEVICE_ERROR_NONE != result) {
+        LoggerE("Platform error while setting restore brightness %d", result);
         return  PlatformResult(ErrorCode::UNKNOWN_ERR,
                     "Platform error while setting restore brightness");
       }
@@ -255,9 +258,10 @@ PlatformResult PowerManager::Release(PowerResource resource) {
 
     display_state_e platform_state = DISPLAY_STATE_NORMAL;
     if(current_requested_state_ == POWER_STATE_SCREEN_DIM) {
-      ret = PowerPlatformProxy::GetInstance().UnlockState();
-      if (DEVICE_ERROR_NONE != ret) {
-        LoggerE("Failed to UnlockState (%d)", ret);
+      int result = 0;
+      auto error_code = PowerPlatformProxy::GetInstance().UnlockState(&result);
+      if (!error_code || DEVICE_ERROR_NONE != result) {
+        LoggerE("Failed to UnlockState (%d)", result);
       }
     }
     ret = device_display_get_state(&platform_state);
@@ -281,7 +285,15 @@ PlatformResult PowerManager::Release(PowerResource resource) {
 
 PlatformResult PowerManager::GetScreenBrightness(double* output) {
   LoggerD("Enter");
-  int brightness = GetPlatformBrightness();
+  int brightness = 0;
+
+  auto error_code = GetPlatformBrightness(&brightness);
+
+  if (!error_code) {
+    LoggerE("Failed to obtain brightness value from platform.");
+    return error_code;
+  }
+
   LoggerD("Brightness value: %d", brightness);
 
   int max_brightness;
@@ -363,9 +375,10 @@ PlatformResult PowerManager::SetScreenState(bool onoff) {
 
 PlatformResult PowerManager::RestoreScreenBrightness() {
   LoggerD("Enter");
-  int ret = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings();
-  if (DEVICE_ERROR_NONE != ret) {
-    LoggerE("Platform error while restoring brightness %d", ret);
+  int result = 0;
+  auto error_code = PowerPlatformProxy::GetInstance().SetBrightnessFromSettings(&result);
+  if (!error_code || DEVICE_ERROR_NONE != result) {
+    LoggerE("Platform error while restoring brightness %d", result);
     return PlatformResult(ErrorCode::UNKNOWN_ERR,
                           "Platform error while restoring brightness");
   }
@@ -388,9 +401,10 @@ PlatformResult PowerManager::SetPlatformBrightness(int brightness) {
     should_be_read_from_cache_ = false;
   }
 
-  int ret = PowerPlatformProxy::GetInstance().SetBrightness(brightness);
-  if (ret != 0) {
-    LoggerE("Platform error while setting %d brightness: %d", brightness, ret);
+  int result = 0;
+  auto error_code = PowerPlatformProxy::GetInstance().SetBrightness(brightness, &result);
+  if (!error_code || result != 0) {
+    LoggerE("Platform error while setting %d brightness: %d", brightness, result);
     return PlatformResult(ErrorCode::UNKNOWN_ERR,
                           "Platform error while setting brightness.");
   }
@@ -399,15 +413,23 @@ PlatformResult PowerManager::SetPlatformBrightness(int brightness) {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-int PowerManager::GetPlatformBrightness(){
+PlatformResult PowerManager::GetPlatformBrightness(int* result) {
   LoggerD("Entered");
 
   int brightness = 0;
 
-  int is_custom_mode = PowerPlatformProxy::GetInstance().IsCustomBrightness();
+  int is_custom_mode = 0;
+  auto error_code = PowerPlatformProxy::GetInstance().IsCustomBrightness(&is_custom_mode);
+
+  if (!error_code) {
+    LoggerE("Failed to check if custom brightness is set.");
+    return error_code;
+  }
+
   if ((is_custom_mode && current_brightness_ != -1) || should_be_read_from_cache_) {
     LoggerD("return custom brightness %d", current_brightness_);
-    return current_brightness_;
+    *result = current_brightness_;
+    return PlatformResult(ErrorCode::NO_ERROR);
   }
 
   int is_auto_brightness = 0;
@@ -420,11 +442,19 @@ int PowerManager::GetPlatformBrightness(){
     }
   } else {
     LoggerD("Brightness via DBUS");
-    brightness = PowerPlatformProxy::GetInstance().GetBrightness();
+    error_code = PowerPlatformProxy::GetInstance().GetBrightness(&brightness);
+
+    if (!error_code) {
+      LoggerE("Failed to obtain brightness via DBUS.");
+      return error_code;
+    }
   }
+
   LoggerD("BRIGHTNESS(%s) %d", is_auto_brightness == 1 ? "auto" : "fix" , brightness);
 
-  return brightness;
+  *result = brightness;
+
+  return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 
index 56191ac..7af09e4 100755 (executable)
@@ -59,7 +59,7 @@ class PowerManager {
 
   static PowerManager* GetInstance();
  private:
-  int GetPlatformBrightness();
+  common::PlatformResult GetPlatformBrightness(int* result);
   common::PlatformResult SetPlatformBrightness(int brightness);
   common::PlatformResult RestoreSettedBrightness();
 
index 568b71e..5a9c470 100755 (executable)
@@ -45,7 +45,7 @@ PowerPlatformProxy& PowerPlatformProxy::GetInstance()
   return instance;
 }
 
-int PowerPlatformProxy::LockState()
+common::PlatformResult PowerPlatformProxy::LockState(int* result)
 {
   LoggerD("Entered");
   DBusOperationArguments args;
@@ -54,42 +54,42 @@ int PowerPlatformProxy::LockState()
   args.AddArgumentString("NULL");
   args.AddArgumentInt32(0);
 
-  return dbus_op_.InvokeSyncGetInt("lockstate", &args);
+  return dbus_op_.InvokeSyncGetInt("lockstate", &args, result);
 }
 
-int PowerPlatformProxy::UnlockState()
+common::PlatformResult PowerPlatformProxy::UnlockState(int* result)
 {
   LoggerD("Entered");
   DBusOperationArguments args;
   args.AddArgumentString("lcddim");
   args.AddArgumentString("keeptimer");
 
-  return dbus_op_.InvokeSyncGetInt("unlockstate", &args);
+  return dbus_op_.InvokeSyncGetInt("unlockstate", &args, result);
 }
 
-int PowerPlatformProxy::SetBrightnessFromSettings()
+common::PlatformResult PowerPlatformProxy::SetBrightnessFromSettings(int* result)
 {
   LoggerD("Entered");
-  return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", NULL);
+  return dbus_op_.InvokeSyncGetInt("ReleaseBrightness", nullptr, result);
 }
 
-int PowerPlatformProxy::SetBrightness(int val)
+common::PlatformResult PowerPlatformProxy::SetBrightness(int val, int* result)
 {
   LoggerD("Entered");
   DBusOperationArguments args;
   args.AddArgumentInt32(val);
 
-  return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args);
+  return dbus_op_.InvokeSyncGetInt("HoldBrightness", &args, result);
 }
 
-int PowerPlatformProxy::GetBrightness() {
+common::PlatformResult PowerPlatformProxy::GetBrightness(int* result) {
   LoggerD("Entered");
-  return dbus_op_.InvokeSyncGetInt("CurrentBrightness", NULL);
+  return dbus_op_.InvokeSyncGetInt("CurrentBrightness", nullptr, result);
 }
 
-int PowerPlatformProxy::IsCustomBrightness() {
+common::PlatformResult PowerPlatformProxy::IsCustomBrightness(int* result) {
   LoggerD("Entered");
-  return dbus_op_.InvokeSyncGetInt("CustomBrightness", NULL);
+  return dbus_op_.InvokeSyncGetInt("CustomBrightness", nullptr, result);
 }
 
 } // namespace power
index 25cacff..1c42a18 100755 (executable)
@@ -24,13 +24,13 @@ namespace power {
 
 class PowerPlatformProxy {
  public:
-       int LockState();
-       int UnlockState();
-       int SetBrightnessFromSettings();
-       int SetBrightness(int val);
+  common::PlatformResult LockState(int* result);
+  common::PlatformResult UnlockState(int* result);
+  common::PlatformResult SetBrightnessFromSettings(int* result);
+  common::PlatformResult SetBrightness(int val, int* result);
 
-  int GetBrightness();
-  int IsCustomBrightness();
+  common::PlatformResult GetBrightness(int* result);
+  common::PlatformResult IsCustomBrightness(int* result);
 
   static PowerPlatformProxy& GetInstance();
 
@@ -38,7 +38,7 @@ class PowerPlatformProxy {
   PowerPlatformProxy();
   virtual ~PowerPlatformProxy();
 
-       common::DBusOperation dbus_op_;
+  common::DBusOperation dbus_op_;
 };
 
 } // namespace power
index 1e122f5..81bb0de 100755 (executable)
 #include <runtime_info.h>
 #include <vconf.h>
 
-#include "common/logger.h"
 #include "common/extension.h"
+#include "common/logger.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 #include "radio/radio_instance.h"
 
index 290bd94..27bf86a 100644 (file)
@@ -17,8 +17,9 @@
 #include "secureelement/secureelement_seservice.h"
 
 #include "common/logger.h"
-#include "common/task-queue.h"
 #include "common/platform_result.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
 
 
 #include "secureelement/secureelement_instance.h"
index cdb0914..544ccfd 100644 (file)
 #include <memory>
 #include <mutex>
 
-#include "common/task-queue.h"
 #include "common/logger.h"
 #include "common/optional.h"
 #include "common/platform_exception.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
 #include "sensor_instance.h"
 
 using namespace common;
index c0ef677..4bc7e0d 100644 (file)
 #include <vconf.h>
 #include <vconf-keys.h>
 
+#include "common/converter.h"
+#include "common/logger.h"
 #include "common/task-queue.h"
+#include "common/tools.h"
 
 //This constant was originally defined in vconf.h. However, in tizen 3, it
 //appears, it is removed (or defined only in vconf-internals.h)
@@ -30,8 +33,6 @@
 #endif
 
 #include "sound/sound_instance.h"
-#include "common/logger.h"
-#include "common/converter.h"
 
 namespace extension {
 namespace sound {
index 8634b73..6bf0d43 100644 (file)
 #include <sensor_internal.h>
 #include <wifi.h>
 
+#include "common/converter.h"
+#include "common/logger.h"
+#include "common/task-queue.h"
+#include "common/tools.h"
+
 #include "systeminfo/systeminfo_instance.h"
 #include "systeminfo/systeminfo_device_capability.h"
 #include "systeminfo/systeminfo-utils.h"
-#include "common/logger.h"
-#include "common/converter.h"
-#include "common/task-queue.h"
 
 using common::PlatformResult;
 using common::ErrorCode;
index 71d7aca..5ba21ca 100644 (file)
@@ -8,8 +8,11 @@
 #include <unistd.h>
 #include <app_manager.h>
 #include <pkgmgr-info.h>
-#include "common/scope_exit.h"
+
 #include "common/logger.h"
+#include "common/scope_exit.h"
+#include "common/tools.h"
+
 #include "utils/utils_instance.h"
 
 using common::PlatformResult;