Merge branch 'tizen_4.0' into tizen 00/167100/1 accepted/tizen/unified/20180116.074414 submit/tizen/20180115.103658
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 15 Jan 2018 09:51:03 +0000 (10:51 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 15 Jan 2018 09:51:13 +0000 (10:51 +0100)
Change-Id: Ifdbc9dc1034e82a33cef52fffc1656cd91920da7

57 files changed:
packaging/webapi-plugins.spec
src/alarm/alarm.gyp
src/alarm/alarm_api.js
src/alarm/alarm_instance.cc
src/alarm/alarm_manager.cc
src/alarm/alarm_manager.h
src/application/application_manager.cc
src/archive/archive_callback_data.cc
src/bluetooth/bluetooth_le_device.cc
src/bluetooth/bluetooth_le_device.h
src/calendar/calendar.cc
src/calendar/calendar_item.cc
src/calendar/calendar_manager.cc
src/common/common.gypi
src/common/logger.h
src/contact/addressbook.cc
src/contact/contact_search_engine.cc
src/datacontrol/datacontrol_api.js
src/download/download_instance.cc
src/exif/exif_information.cc
src/exif/exif_tag_saver.cc
src/exif/rational.cc
src/filesystem/filesystem_file.cc
src/filesystem/filesystem_file.h
src/filesystem/filesystem_instance.cc
src/filesystem/filesystem_manager.cc
src/filesystem/filesystem_manager.h
src/filesystem/js/file.js
src/filesystem/js/file_stream.js
src/humanactivitymonitor/humanactivitymonitor_manager.cc
src/iotcon/iotcon_client_manager.cc
src/iotcon/iotcon_client_manager.h
src/iotcon/iotcon_instance.cc
src/iotcon/iotcon_utils.h
src/mediacontroller/mediacontroller_client.cc
src/mediacontroller/mediacontroller_server.cc
src/messaging/DBus/MessageProxy.cpp
src/messaging/MsgCommon/AbstractFilter.cpp
src/messaging/change_listener_container.cc
src/messaging/email_manager.cc
src/messaging/message.cc
src/messaging/message_conversation.cc
src/messaging/message_service_email.cc
src/messaging/message_service_short_msg.cc
src/messaging/messages_change_callback.cc
src/messaging/messaging_database_manager.cc
src/messaging/messaging_instance.h
src/messaging/short_message_manager.cc
src/nfc/nfc_adapter.cc
src/notification/notification_manager.cc
src/package/package_instance.cc
src/radio/radio_manager.cc
src/sensor/sensor_service.cc
src/sound/sound_manager.cc
src/utils/utils_api.js
src/utils/utils_instance.cc
src/utils/utils_instance.h

index 1d34ae0..cbdade1 100644 (file)
@@ -8,7 +8,7 @@
 %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions}
 
 Name:       webapi-plugins
-Version:    2.09
+Version:    2.13
 Release:    0
 License:    Apache-2.0 and BSD-3-Clause and MIT
 Group:      Development/Libraries
@@ -655,10 +655,8 @@ webapi-plugins development headers
 
 export GYP_GENERATORS='ninja'
 
-%if "%{?unified_build}" == "1"
-# Build All Profiles
-
-# Mobile
+%if "%{?unified_build}" == "1" || "%{?profile}" == "mobile"
+# MOBILE
 GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=mobile -Dprivilege_engine=%{tizen_mobile_privilege_engine}"
 GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
 GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
@@ -721,6 +719,9 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_pp
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_mobile
+%if "%{?profile}" == "mobile"
+ln -sf bin_mobile Default
+%endif
 popd
 
 # mobile-extension-emulator
@@ -808,9 +809,14 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_pp
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_mobile_emulator
-popd
+%if "%{?profile}" == "mobile"
+ln -sf bin_mobile_emulator Default
 %endif
+popd
+%endif # mobile-extension-emulator
+%endif # MOBILE
 
+%if "%{?unified_build}" == "1" || "%{?profile}" == "wearable"
 # WEARABLE
 GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=wearable -Dprivilege_engine=%{tizen_wearable_privilege_engine}"
 GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
@@ -874,6 +880,9 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_wearable
+%if "%{?profile}" == "wearable"
+ln -sf bin_wearable Default
+%endif
 popd
 
 # wearable-extension-emulator
@@ -956,9 +965,14 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_wearable_emulator
-popd
+%if "%{?profile}" == "wearable"
+ln -sf bin_wearable_emulator Default
 %endif
+popd
+%endif # wearable-extension-emulator
+%endif # WEARABLE
 
+%if "%{?unified_build}" == "1" || "%{?profile}" == "tv"
 # TV
 GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=tv -Dprivilege_engine=%{tizen_tv_privilege_engine}"
 GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
@@ -1022,16 +1036,18 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_tv_feature_ppm_su
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_tv
+%if "%{?profile}" == "tv"
+ln -sf bin_tv Default
+%endif
 popd
 
-%endif
+%endif # TV
+
+%if "%{?unified_build}" == "1" || "%{?profile}" == "common" || "%{?profile}" == "ivi"
 
-# Unified: common/ Others: its own profile
-%if "%{?profile}" != "mobile" && "%{?profile}" != "tv" && "%{?profile}" != "wearable" && "%{?profile}" != "ivi"
+# UNIFIED / COMMON or IVI
 GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=common -Dprivilege_engine=%{tizen_common_privilege_engine}"
-%else
-GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=%{profile} -Dprivilege_engine=%{tizen_privilege_engine}"
-%endif
+
 GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}"
 GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}"
 
@@ -1090,7 +1106,8 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_common_feature_pp
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
-%if "%{?profile}" != "mobile" && "%{?profile}" != "tv" && "%{?profile}" != "wearable" && "%{?profile}" != "ivi"
+%if "%{?unified_build}" == "1"
+# UNIFIED
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_common
@@ -1101,13 +1118,15 @@ ln -sf bin_common Default
 cp -R bin_common bin_ivi
 
 popd
-%else
+%else # UNIFIED
+# COMMON or IVI
 ninja -C out/Default %{?_smp_mflags}
 pushd out
 mv Default bin_%{?profile}
 ln -sf bin_%{?profile} Default
 popd
-%endif
+%endif # COMMON or IVI
+%endif # UNIFIED / COMMON or IVI
 
 %install
 
@@ -1168,7 +1187,7 @@ install -p -m 644 plugins.json %{buildroot}%{crosswalk_extensions_path}/wearable
 mkdir -p %{buildroot}%{crosswalk_extensions_path}/wearable_emulator
 install -p -m 644 out/bin_wearable_emulator/libtizen*.so %{buildroot}%{crosswalk_extensions_path}/wearable_emulator
 # execute desc_gentool
-LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%{buildroot}%{crosswalk_extensions_path}/mobile_emulator out/Default/desc_gentool \
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%{buildroot}%{crosswalk_extensions_path}/wearable_emulator out/Default/desc_gentool \
        %{crosswalk_extensions_path}/wearable_emulator \
        %{buildroot}%{crosswalk_extensions_path}/wearable_emulator > plugins.json
 
@@ -1247,8 +1266,12 @@ ln -sf %{crosswalk_extensions_path}/mobile/* %{crosswalk_extensions_path}
 %preun profile_mobile
 # This is an un-installation.
 if [ "$1" == "0" ]; then
-  rm %{crosswalk_extensions_path}/libtizen*.so
-  rm %{crosswalk_extensions_path}/plugins.json
+  if [ -n "$(ls %{crosswalk_extensions_path}/ | grep libtizen*.so)" ]; then
+    rm %{crosswalk_extensions_path}/libtizen*.so
+  fi
+  if [ -f %{crosswalk_extensions_path}/plugins.json ]; then
+    rm %{crosswalk_extensions_path}/plugins.json
+  fi
 fi
 %files profile_mobile
 %dir %{crosswalk_extensions_path}/mobile/
@@ -1263,8 +1286,12 @@ ln -sf %{crosswalk_extensions_path}/mobile_emulator/* %{crosswalk_extensions_pat
 %preun mobile-extension-emulator
 # This is an un-installation.
 if [ "$1" == "0" ]; then
-  rm %{crosswalk_extensions_path}/libtizen*.so
-  rm %{crosswalk_extensions_path}/plugins.json
+  if [ -n "$(ls %{crosswalk_extensions_path}/ | grep libtizen*.so)" ]; then
+    rm %{crosswalk_extensions_path}/libtizen*.so
+  fi
+  if [ -f %{crosswalk_extensions_path}/plugins.json ]; then
+    rm %{crosswalk_extensions_path}/plugins.json
+  fi
 fi
 %files mobile-extension-emulator
 %dir %{crosswalk_extensions_path}/mobile_emulator/
@@ -1280,8 +1307,12 @@ ln -sf %{crosswalk_extensions_path}/wearable/* %{crosswalk_extensions_path}
 %preun profile_wearable
 # This is an un-installation.
 if [ "$1" == "0" ]; then
-  rm %{crosswalk_extensions_path}/libtizen*.so
-  rm %{crosswalk_extensions_path}/plugins.json
+  if [ -n "$(ls %{crosswalk_extensions_path}/ | grep libtizen*.so)" ]; then
+    rm %{crosswalk_extensions_path}/libtizen*.so
+  fi
+  if [ -f %{crosswalk_extensions_path}/plugins.json ]; then
+    rm %{crosswalk_extensions_path}/plugins.json
+  fi
 fi
 %files profile_wearable
 %dir %{crosswalk_extensions_path}/wearable/
@@ -1296,8 +1327,12 @@ ln -sf %{crosswalk_extensions_path}/wearable_emulator/* %{crosswalk_extensions_p
 %preun wearable-extension-emulator
 # This is an un-installation.
 if [ "$1" == "0" ]; then
-  rm %{crosswalk_extensions_path}/libtizen*.so
-  rm %{crosswalk_extensions_path}/plugins.json
+  if [ -n "$(ls %{crosswalk_extensions_path}/ | grep libtizen*.so)" ]; then
+    rm %{crosswalk_extensions_path}/libtizen*.so
+  fi
+  if [ -f %{crosswalk_extensions_path}/plugins.json ]; then
+    rm %{crosswalk_extensions_path}/plugins.json
+  fi
 fi
 %files wearable-extension-emulator
 %dir %{crosswalk_extensions_path}/wearable_emulator/
index 5d212ec..6a5739e 100644 (file)
@@ -8,7 +8,6 @@
       'type': 'loadable_module',
       'dependencies': [
         '../common/common.gyp:tizen_common',
-        '../notification/notification.gyp:tizen_notification',
       ],
       'sources': [
         'alarm_api.js',
             ]
           },
         }],
+        ['extension_host_os == "mobile"', {
+            'dependencies': [
+              '../notification/notification.gyp:tizen_notification',
+            ],
+        }],
+        ['extension_host_os == "wearable"', {
+            'dependencies': [
+             '../notification/notification.gyp:tizen_notification',
+            ],
+        }]
       ],
     },
   ],
index cfa5f98..e8507f6 100755 (executable)
@@ -486,5 +486,44 @@ tizen.AlarmAbsolute.prototype.getNextScheduledDate = function () {
     }
 };
 
+// Singleton to check on which profile plugins are executed
+var ProfileAlarm = (function() {
+    var m_profile = null;
+    function ProfileAlarm() {
+       if (m_profile == null) {
+           m_profile = privUtils_.checkProfile();
+       }
+       Object.defineProperties(this, {
+           profile: {
+               get: function() {
+                   return m_profile;
+               },
+               set: function() {},
+               enumerable: true
+           }
+       })
+    };
+
+    var instance;
+    return {
+        getInstance: function() {
+            if (instance == null) {
+                instance = new ProfileAlarm();
+                // Hide the constructor so the returned objected can't be new'd...
+                instance.constructor = null;
+            }
+            return instance;
+        }
+   };
+})();
+
+var _profile = ProfileAlarm.getInstance().profile;
+
+// Notifications feature are available on mobile and wearable profile
+if (_profile != 'mobile' && _profile != 'wearable') {
+    delete AlarmManager.prototype.addAlarmNotification;
+    delete AlarmManager.prototype.getAlarmNotification;
+}
+
 //exports //////////////////////////////////////////////////////////////
 exports = new AlarmManager();
index a65a604..504149c 100644 (file)
@@ -29,14 +29,10 @@ AlarmInstance::AlarmInstance() {
   using namespace std::placeholders;
 
   RegisterSyncHandler("AlarmManager_add", std::bind(&AlarmManager::Add, &manager_, _1, _2));
-  RegisterSyncHandler("AlarmManager_addAlarmNotification",
-                      std::bind(&AlarmManager::AddAlarmNotification, &manager_, _1, _2));
   RegisterSyncHandler("AlarmManager_remove", std::bind(&AlarmManager::Remove, &manager_, _1, _2));
   RegisterSyncHandler("AlarmManager_removeAll",
                       std::bind(&AlarmManager::RemoveAll, &manager_, _1, _2));
   RegisterSyncHandler("AlarmManager_get", std::bind(&AlarmManager::Get, &manager_, _1, _2));
-  RegisterSyncHandler("AlarmManager_getAlarmNotification",
-                      std::bind(&AlarmManager::GetAlarmNotification, &manager_, _1, _2));
   RegisterSyncHandler("AlarmManager_getAll", std::bind(&AlarmManager::GetAll, &manager_, _1, _2));
   // AlarmRelative
   RegisterSyncHandler("AlarmRelative_getRemainingSeconds",
@@ -44,6 +40,14 @@ AlarmInstance::AlarmInstance() {
   // AlarmAbsolute
   RegisterSyncHandler("AlarmAbsolute_getNextScheduledDate",
                       std::bind(&AlarmManager::GetNextScheduledDate, &manager_, _1, _2));
+
+  // Block of code related to Notification
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+  RegisterSyncHandler("AlarmManager_addAlarmNotification",
+                      std::bind(&AlarmManager::AddAlarmNotification, &manager_, _1, _2));
+  RegisterSyncHandler("AlarmManager_getAlarmNotification",
+                      std::bind(&AlarmManager::GetAlarmNotification, &manager_, _1, _2));
+#endif
 }
 
 AlarmInstance::~AlarmInstance() {
index 8ca564b..c7d67a1 100644 (file)
 #include <app.h>
 #include <app_alarm.h>
 #include <app_control_internal.h>
+
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
 #include <notification_internal.h>
+#endif
 
 #include "common/converter.h"
 #include "common/logger.h"
@@ -245,6 +248,7 @@ void AlarmManager::Add(const picojson::value& args, picojson::object& out) {
   ReportSuccess(result, out);
 }
 
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
 void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::object& out) {
   using namespace extension::notification;
   ScopeLogger();
@@ -466,6 +470,7 @@ void AlarmManager::AddAlarmNotification(const picojson::value& args, picojson::o
   result_obj.insert(std::make_pair("id", picojson::value(std::to_string(alarm_id))));
   ReportSuccess(result, out);
 }
+#endif
 
 void AlarmManager::Remove(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
@@ -541,7 +546,7 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) {
       if (!platform_result) {
         return LogAndCreateResult(
             platform_result.error_code(), platform_result.message().c_str(),
-            ("Failed to get AppControl: %d (%s)", platform_result.error_code(),
+            ("Failed to get AppControl: %d (%s)", static_cast<int>(platform_result.error_code()),
              platform_result.message().c_str()));
       }
     }
@@ -664,6 +669,7 @@ void AlarmManager::Get(const picojson::value& args, picojson::object& out) {
   }
 }
 
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
 void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::object& out) {
   using namespace extension::notification;
   ScopeLogger();
@@ -711,7 +717,7 @@ void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::o
 
   ReportSuccess(result, out);
 }
-
+#endif
 static bool AlarmIterateCB(int alarm_id, void* user_data) {
   ScopeLogger();
 
@@ -720,10 +726,10 @@ static bool AlarmIterateCB(int alarm_id, void* user_data) {
   alarm_ids->push_back(alarm_id);
   return true;
 }
+#include <stdio.h>
 
 void AlarmManager::GetAll(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
-
   std::vector<int> alarm_ids;
   int ret = alarm_foreach_registered_alarm(AlarmIterateCB, &alarm_ids);
 
@@ -793,7 +799,6 @@ void AlarmManager::GetRemainingSeconds(const picojson::value& args, picojson::ob
 
 void AlarmManager::GetNextScheduledDate(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
-
   int id = 0;
 
   if (args.contains("id") && args.get("id").is<double>()) {
index f7c0f3f..df5559b 100644 (file)
@@ -29,13 +29,15 @@ class AlarmManager {
   virtual ~AlarmManager();
 
   void Add(const picojson::value& args, picojson::object& out);
-  void AddAlarmNotification(const picojson::value& args, picojson::object& out);
   void Remove(const picojson::value& args, picojson::object& out);
   void RemoveAll(const picojson::value& args, picojson::object& out);
   void Get(const picojson::value& args, picojson::object& out);
-  void GetAlarmNotification(const picojson::value& args, picojson::object& out);
   void GetAll(const picojson::value& args, picojson::object& out);
 
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
+  void AddAlarmNotification(const picojson::value& args, picojson::object& out);
+  void GetAlarmNotification(const picojson::value& args, picojson::object& out);
+#endif
   // AlarmRelative
   void GetRemainingSeconds(const picojson::value& args, picojson::object& out);
   // AlarmAbsolute
index e6a3cee..67e92d3 100644 (file)
@@ -189,42 +189,7 @@ class TerminateHandler {
         response);
   }
 
-  void LaunchCheckTerminate() {
-    ScopeLogger();
-    timeout_id_ = g_timeout_add(3000, CheckTerminate, this);
-    LoggerD("END");
-  }
-
  private:
-  static gboolean CheckTerminate(gpointer user_data) {
-    ScopeLogger();
-    TerminateHandler* that = static_cast<TerminateHandler*>(user_data);
-    LoggerD("PID: %d", that->pid_);
-
-    // we're canceling the callback by returning false, no need for Invoke() to do that again
-    that->timeout_id_ = 0;
-
-    char* app_id = nullptr;
-    std::shared_ptr<picojson::value> response{new picojson::value(picojson::object())};
-
-    LoggerD("checking if application is still alive");
-    int ret = app_manager_get_app_id(that->pid_, &app_id);
-    if (APP_MANAGER_ERROR_NONE == ret) {
-      free(app_id);
-      // context is still alive, report error
-      LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to kill application."),
-                        &response->get<picojson::object>(), ("application is alive - failure"));
-    } else {
-      LoggerD("application is dead - success: %d (%s)", ret, get_error_message(ret));
-      ReportSuccess(response->get<picojson::object>());
-    }
-
-    that->Invoke(response);
-    delete that;
-
-    return false;
-  }
-
   int callback_handle_;
   pid_t pid_;
   guint timeout_id_;
@@ -284,7 +249,7 @@ void ApplicationManager::Kill(const picojson::value& args) {
   }
 
   auto kill = [this, callback_id, context_id]() -> void {
-    ScopeLogger("Kill async");
+    ScopeLogger("Kill");
 
     std::shared_ptr<picojson::value> response =
         std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
@@ -312,7 +277,7 @@ void ApplicationManager::Kill(const picojson::value& args) {
       CHECK_RESULT(result, response, handler)
     }
 
-    LoggerD("Kill async, pid: %d", pid);
+    LoggerD("Kill, pid: %d", pid);
 
     char* app_id = nullptr;
     int ret = app_manager_get_app_id(pid, &app_id);
@@ -326,7 +291,7 @@ void ApplicationManager::Kill(const picojson::value& args) {
       CHECK_RESULT(result, response, handler)
     }
 
-    LoggerD("Kill async, app ID: %s", app_id);
+    LoggerD("Kill, app ID: %s", app_id);
 
     // acquire application context
     app_context_h app_context = nullptr;
@@ -372,7 +337,7 @@ void ApplicationManager::Kill(const picojson::value& args) {
       }
     };
 
-    LoggerD("Kill async, setting callback");
+    LoggerD("Kill, setting callback");
     handler->set_pid(pid);
     ret = app_manager_set_app_context_event_cb(terminate_callback, handler);
 
@@ -383,12 +348,7 @@ void ApplicationManager::Kill(const picojson::value& args) {
       CHECK_RESULT(result, response, handler)
     }
 
-    // due to platform issue, sometimes termination event is not reported to callback
-    // registered with app_manager_set_app_context_event_cb()
-    // this is a workaround, it should be removed when issue is solved
-    // handler->LaunchCheckTerminate();
-
-    LoggerD("Kill async, KILL!!!!!!!!!");
+    LoggerD("Kill, calling native function");
 
     // terminate application
     ret = app_manager_terminate_app(app_context);
@@ -400,10 +360,10 @@ void ApplicationManager::Kill(const picojson::value& args) {
       CHECK_RESULT(result, response, handler)
     }
 
-    LoggerD("Kill async, end, waiting for notification");
+    LoggerD("Kill, end, waiting for notification");
   };
 
-  TaskQueue::GetInstance().Queue(kill);
+  kill();
 }
 
 void ApplicationManager::Launch(const picojson::value& args) {
@@ -429,7 +389,7 @@ void ApplicationManager::Launch(const picojson::value& args) {
   const std::string& id = app_id.get<std::string>();
 
   auto launch = [id](const std::shared_ptr<picojson::value>& response) -> void {
-    ScopeLogger("Entered into asynchronous function, launch");
+    ScopeLogger("launch");
     PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
     const char* app_id = id.c_str();
     const int retry_count = 3;
@@ -478,11 +438,8 @@ void ApplicationManager::Launch(const picojson::value& args) {
     }
   };
 
-  auto launch_response = [this](const std::shared_ptr<picojson::value>& response) -> void {
-    Instance::PostMessage(&this->instance_, response->serialize().c_str());
-  };
-
-  TaskQueue::GetInstance().Queue<picojson::value>(launch, launch_response, response);
+  launch(response);
+  Instance::PostMessage(&this->instance_, response->serialize().c_str());
 }
 
 void ApplicationManager::LaunchAppControl(const picojson::value& args) {
@@ -671,13 +628,8 @@ void ApplicationManager::LaunchAppControl(const picojson::value& args) {
     ReportSuccess(response->get<picojson::object>());
   };
 
-  auto launch_response = [this](const std::shared_ptr<picojson::value>& response) -> void {
-    ScopeLogger("launch_response");
-
-    Instance::PostMessage(&this->instance_, response->serialize().c_str());
-  };
-
-  TaskQueue::GetInstance().Queue<picojson::value>(launch, launch_response, response);
+  launch(response);
+  Instance::PostMessage(&this->instance_, response->serialize().c_str());
 }
 
 // internal impl of app_control_foreach_app_matched() for handling APP_CONTROL_ERROR_APP_NOT_FOUND
index f761270..8924616 100644 (file)
@@ -58,7 +58,7 @@ OperationCallbackData::~OperationCallbackData() {
 }
 
 void OperationCallbackData::setError(const ErrorCode& err_code, const std::string& err_message) {
-  ScopeLogger("Setting error, code is: [%d]", err_code);
+  ScopeLogger("Setting error, code is: [%d]", static_cast<int>(err_code));
   // store only first error
   if (!m_is_error) {
     m_err_code = err_code;
index c10ebc8..b0f6413 100644 (file)
@@ -426,22 +426,63 @@ void BluetoothLEDevice::GetServiceAllUuids(const picojson::value& data, picojson
 void BluetoothLEDevice::GattConnectionState(int result, bool connected, const char* remote_address,
                                             void* user_data) {
   ScopeLogger("%s connected: %d", remote_address, connected);
-  auto le_device = static_cast<BluetoothLEDevice*>(user_data);
-
-  if (!le_device) {
+  if (!user_data) {
     LoggerE("user_data is NULL");
     return;
   }
+  BluetoothLEDevice* le_device = static_cast<BluetoothLEDevice*>(user_data);
+
+  // check state change success
+  PlatformResult operation_success = ValidateConnectionChange(result);
+  if (operation_success) {
+    if (connected) { // connect success
+      le_device->is_connected_.insert(remote_address);
+    } else { // disconnect success
+      le_device->CleanClientInfo(remote_address);
+    }
+  }
 
-  if (connected) {
-    le_device->is_connected_.insert(remote_address);
+  // trigger connect/disconnect callback (success or error)
+  le_device->TriggerConnectCallback(remote_address, operation_success);
+
+  // trigger state change listener, if operation succeed
+  if (operation_success) {
+    le_device->TriggerConnectStateChangeListener(remote_address, connected);
+  }
+}
+
+PlatformResult BluetoothLEDevice::ValidateConnectionChange(int err_code) {
+  ScopeLogger();
+  if (BT_ERROR_NONE != err_code) {
+    return LogAndCreateResult(
+        ErrorCode::UNKNOWN_ERR, "Failed to get connection state",
+        ("GattConnectionState error: %d (%s)", err_code, get_error_message(err_code)));
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+void BluetoothLEDevice::CleanClientInfo(const char* remote_address) {
+  ScopeLogger();
+  is_connected_.erase(remote_address);
+  // inform that this device is not connected anymore
+  service_.TryDestroyClient(remote_address);
+}
+
+void BluetoothLEDevice::TriggerConnectCallback(const char* remote_address, PlatformResult result) {
+  ScopeLogger();
+  auto it = connecting_.find(remote_address);
+  if (connecting_.end() != it) {
+    instance_.AsyncResponse(it->second, result);
+    connecting_.erase(it);
   } else {
-    le_device->is_connected_.erase(remote_address);
-    // inform that this device is not connected anymore
-    le_device->service_.TryDestroyClient(remote_address);
+    LoggerW("Given address is not in waiting connections list");
   }
+}
 
-  if (le_device->is_listener_set_) {
+void BluetoothLEDevice::TriggerConnectStateChangeListener(const char* remote_address,
+                                                          bool connected) {
+  ScopeLogger();
+  if (is_listener_set_) {
     picojson::value value = picojson::value(picojson::object());
     picojson::object* data_obj = &value.get<picojson::object>();
     if (connected) {
@@ -451,29 +492,12 @@ void BluetoothLEDevice::GattConnectionState(int result, bool connected, const ch
       LoggerD("OnDisconnected");
       data_obj->insert(std::make_pair(kAction, picojson::value(kOnDisconnected)));
     }
-
     data_obj->insert(std::make_pair(kDeviceAddress, picojson::value(remote_address)));
-
-    le_device->instance_.FireEvent(kConnectChangeEvent, value);
-  }
-
-  auto it = le_device->connecting_.find(remote_address);
-  if (le_device->connecting_.end() == it) {
-    LoggerW("Given address is not in waiting connections list");
-    return;
-  }
-
-  PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
-  if (BT_ERROR_NONE != result) {
-    ret = LogAndCreateResult(
-        ErrorCode::UNKNOWN_ERR, "Failed to get connection state",
-        ("GattConnectionState error: %d (%s)", result, get_error_message(result)));
+    instance_.FireEvent(kConnectChangeEvent, value);
+  } else {
+    LoggerD("Listener is not registered - ignoring event");
   }
-
-  le_device->instance_.AsyncResponse(it->second, ret);
-
-  le_device->connecting_.erase(it);
-}
+};
 
 }  // namespace bluetooth
 }  // namespace extension
index 2715bcf..e2a161a 100644 (file)
@@ -53,7 +53,11 @@ class BluetoothLEDevice {
  private:
   static void GattConnectionState(int result, bool connected, const char* remote_address,
                                   void* user_data);
-
+  bool IsInConnecting(const char* remote_address);
+  static common::PlatformResult ValidateConnectionChange(int err_code);
+  void TriggerConnectCallback(const char* remote_address, common::PlatformResult result);
+  void CleanClientInfo(const char* remote_address);
+  void TriggerConnectStateChangeListener(const char* remote_address, bool connected);
   BluetoothInstance& instance_;
   BluetoothGATTService& service_;
   std::unordered_map<std::string, double> connecting_;
index ef161c0..556274d 100644 (file)
@@ -598,7 +598,7 @@ PlatformResult Calendar::Find(const picojson::object& args, picojson::array& arr
           if ((status = ErrorChecker(error_code)).IsError()) return status;
         } else {
           return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid union type!",
-                                    ("Invalid union type: %d", calType));
+                                    ("Invalid union type: %d", static_cast<int>(calType)));
         }
       }
       intermediate_filters.pop_back();
index 7e209b4..d42f743 100644 (file)
@@ -384,7 +384,7 @@ PlatformResult CalendarItem::SetInt(int type, calendar_record_h rec, const std::
 
 PlatformResult CalendarItem::SetInt(int type, calendar_record_h rec, const std::string& property,
                                     int value) {
-  ScopeLogger("set: %s" + property);
+  ScopeLogger("set: %s", property.c_str());
 
   unsigned int prop;
   PlatformResult status = GetPlatformProperty(type, property, &prop);
@@ -397,7 +397,7 @@ PlatformResult CalendarItem::SetInt(int type, calendar_record_h rec, const std::
 
 PlatformResult CalendarItem::GetInt(int type, calendar_record_h rec, const std::string& property,
                                     int* value) {
-  ScopeLogger("set: %s" + property);
+  ScopeLogger("set: %s", property.c_str());
 
   unsigned int prop;
   PlatformResult status = GetPlatformProperty(type, property, &prop);
@@ -541,7 +541,7 @@ PlatformResult CalendarItem::SetCaltime(calendar_record_h rec, unsigned int prop
 PlatformResult CalendarItem::GetCaltime(int type, calendar_record_h rec,
                                         const std::string& property, calendar_time_s* cal_time,
                                         bool throw_on_error) {
-  ScopeLogger("set: %s" + property);
+  ScopeLogger("set: %s", property.c_str());
 
   unsigned int prop;
   PlatformResult status = GetPlatformProperty(type, property, &prop);
@@ -588,7 +588,7 @@ PlatformResult CalendarItem::SetLli(calendar_record_h rec, unsigned int property
 
 PlatformResult CalendarItem::GetLli(int type, calendar_record_h rec, const std::string& property,
                                     long long int* lli) {
-  ScopeLogger("set: %s" + property);
+  ScopeLogger("set: %s", property.c_str());
 
   unsigned int prop;
   PlatformResult status = GetPlatformProperty(type, property, &prop);
@@ -615,7 +615,7 @@ PlatformResult CalendarItem::GetLli(calendar_record_h rec, unsigned int property
 }
 
 Date CalendarItem::DateFromJson(const picojson::object& in) {
-  ScopeLogger("json date " + picojson::value(in).serialize());
+  ScopeLogger("json date %s", picojson::value(in).serialize().c_str());
 
   Date date = {(long long int)common::FromJson<double>(in, "UTCTimestamp"),
                (int)common::FromJson<double>(in, "year"),
index 4c2edaf..3a6abd5 100644 (file)
@@ -162,7 +162,7 @@ PlatformResult CalendarManager::GetCalendar(const JsonObject& args, JsonObject&
 
   if (type != calendar_type) {
     return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Calendar not found",
-                              ("Calendar type doesn't match requested type %s", type));
+                              ("Calendar type doesn't match requested type %d", type));
   }
 
   status = CalendarRecord::CalendarToJson(record_ptr.get(), &out);
index 0e15003..cf4fed8 100644 (file)
       'XW_Extension.cc',
     ],
     'cflags': [
-      '-std=c++0x',
       '-fPIC',
       '-fvisibility=hidden',
       '-Wall',
+      '-Werror',
+    ],
+    'cflags_c': [
+      '-std=c11',
+    ],
+    'cflags_cc': [
+      '-std=c++14',
     ],
     'libraries' : [
       '-L .',
index fd159bb..93b0ee5 100644 (file)
@@ -233,18 +233,6 @@ class ScopeLogger {
  public:
   ScopeLogger(const std::string& f, const std::string& m, int l, const std::string& ex = "")
       : file_(f), method_(m), extra_(ex) {
-    LoggerD("%s: %s(%d) > Enter %s", file_.c_str(), method_.c_str(), l, extra_.c_str());
-  }
-
-  template <typename... Args>
-  ScopeLogger(const std::string& f, const std::string& m, int l, const std::string& ex,
-              Args... args)
-      : file_(f), method_(m), extra_(ex) {
-#ifdef TIZEN_DEBUG_ENABLE
-    __dlog_print(LOG_ID_MAIN, DLOG_DEBUG, LOGGER_TAG,
-                 ("%s: %s(%d) > %s: %s(%d) > Enter " + extra_).c_str(), __MODULE__, __func__,
-                 __LINE__, file_.c_str(), method_.c_str(), l, args...);
-#endif
   }
 
   ~ScopeLogger() {
@@ -259,9 +247,15 @@ class ScopeLogger {
 
 }  // common
 
-#define ScopeLogger(EX, args...)               \
-  const common::ScopeLogger __sl__ {           \
-    __MODULE__, __func__, __LINE__, EX, ##args \
-  }
+#ifdef TIZEN_DEBUG_ENABLE
+#define ScopeLogger(EX, args...)                                                                 \
+  __dlog_print(LOG_ID_MAIN, DLOG_DEBUG, LOGGER_TAG,                                              \
+               "logger.h: ScopeLogger > %s: %s(%d) > Enter " EX, __MODULE__, __func__, __LINE__, \
+               ##args);                                                                          \
+  const common::ScopeLogger __sl__{__MODULE__, __func__, __LINE__, EX};
+
+#else
+#define ScopeLogger(EX, args...)
+#endif
 
 #endif  // COMMON_LOGGER_H_
index 447b171..012e921 100644 (file)
@@ -364,7 +364,7 @@ PlatformResult AddressBookFind(const JsonObject& args, JsonArray& array) {
 
   long address_book_id = common::stol(FromJson<std::string>(args, "addressBookId"));
 
-  LoggerD("Searching in address book: %d", address_book_id);
+  LoggerD("Searching in address book: %ld", address_book_id);
 
   ContactSearchEngine engine;
   if (!IsUnified(address_book_id)) {
index 2769e2c..cee971e 100644 (file)
@@ -671,7 +671,7 @@ PlatformResult ContactSearchEngine::GetContacts(Iterator begin, Iterator end,
     contacts_record_h record = nullptr;
     int error_code = contacts_db_get_record(_contacts_contact._uri, id, &record);
     if (CONTACTS_ERROR_NONE != error_code) {
-      LoggerE("Failed to get contact with ID: %d", id);
+      LoggerE("Failed to get contact with ID: %ld", static_cast<long>(id));
       continue;
     }
 
@@ -683,7 +683,7 @@ PlatformResult ContactSearchEngine::GetContacts(Iterator begin, Iterator end,
       error_code =
           contacts_record_get_int(record, _contacts_contact.address_book_id, &address_book_id);
       if (CONTACTS_ERROR_NONE != error_code) {
-        LoggerE("Failed to get address book ID of contact with ID: %d", id);
+        LoggerE("Failed to get address book ID of contact with ID: %ld", static_cast<long>(id));
         continue;
       }
 
index 24a78c6..5de955e 100755 (executable)
@@ -105,10 +105,11 @@ var DataControlListenersManager = (function() {
           dataId: dataId,
           type: type
         }, callback);
-      result = native_.getResultObject(result);
+
       if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
       } else {
+        result = native_.getResultObject(result);
         _realWatchId = converter_.toLong(result.watchId, true);
       }
       if (type_.isEmptyObject(this._SQLDataControlCbMap) &&
index e34d1aa..52923da 100644 (file)
@@ -61,6 +61,9 @@ DownloadInstance::DownloadInstance() {
 DownloadInstance::~DownloadInstance() {
   ScopeLogger();
   int ret;
+
+  std::lock_guard<std::mutex> lock(instances_mutex_);
+
   for (DownloadCallbackMap::iterator it = download_callbacks.begin();
        it != download_callbacks.end(); ++it) {
     DownloadInfoPtr diPtr = it->second->instance->diMap[it->second->callbackId];
@@ -89,7 +92,6 @@ DownloadInstance::~DownloadInstance() {
     delete (it->second);
   }
 
-  std::lock_guard<std::mutex> lock(instances_mutex_);
   for (auto it = instances_.begin(); it != instances_.end(); it++) {
     if (*it == this) {
       instances_.erase(it);
index ac3f4cc..9a07286 100644 (file)
@@ -456,7 +456,7 @@ void ExifInformation::unset(ExifInformationAttribute attribute) {
 }
 
 void ExifInformation::set(std::string attributeName, const picojson::value& v) {
-  ScopeLogger(attributeName);
+  ScopeLogger("%s", attributeName.c_str());
 
   switch (str2int(attributeName.c_str())) {
     case str2int(EI_URI): {
index 7ead390..0d91766 100644 (file)
@@ -28,10 +28,10 @@ namespace extension {
 namespace exif {
 
 void ExifTagSaver::removeExifEntryWithTag(const ExifTag tag, ExifData* exif_data) {
-  ScopeLogger("tag:%d (0x%x)", tag, exif_data);
+  ScopeLogger("tag: %d (%p)", tag, exif_data);
   ExifEntry* exif_entry = exif_data_get_entry(exif_data, tag);
   if (!exif_entry) {
-    LoggerE("Exif entry with tag:%d (0x%x) is not present", tag, tag);
+    LoggerE("Exif entry with tag: %d (0x%x) is not present", tag, tag);
     return;
   }
 
@@ -319,7 +319,7 @@ common::PlatformResult ExifTagSaver::saveGpsLocationToExif(const ExifGPSLocation
 }
 
 ExifEntry* ExifTagSaver::prepareEntry(ExifData* exif_data, ExifTag tag) {
-  ScopeLogger("tag:%d (0x%x)", tag, exif_data);
+  ScopeLogger("tag: %d (%p)", tag, exif_data);
 
   ExifEntry* exif_entry = exif_data_get_entry(exif_data, tag);
   if (!exif_entry) {
index 93bf5bd..987a61b 100644 (file)
@@ -44,7 +44,7 @@ Rational::Rational(const ExifRational& exif_rational)
 }
 
 Rational Rational::createFromDouble(const double value, const long precision) {
-  ScopeLogger("value:%f precision:%d", value, precision);
+  ScopeLogger("value: %f precision: %ld", value, precision);
   if (value < 0.0) {
     LoggerW("Trying to create negative Rational: %f!", value);
     return Rational();
index dd2cf8a..b5cba79 100644 (file)
@@ -215,6 +215,59 @@ bool FilesystemFile::Read(FilesystemBuffer* data, size_t offset, size_t length)
   return true;
 }
 
+bool FilesystemFile::ReadString(std::vector<char>* data, size_t offset, size_t length) {
+  ScopeLogger();
+  if (!data) {
+    LoggerE("Missing output buffer");
+    return false;
+  }
+
+  data->resize(length);
+  FILE* file = fopen(path.c_str(), "r");
+  if (!file) {
+    LoggerE("Cannot open file %s to read!", path.c_str());
+    return false;
+  }
+  SCOPE_EXIT {
+    int status = fclose(file);
+    if (status) {
+      LoggerE("Cannot close file!");
+    }
+  };
+  int status;
+  status = fseek(file, offset, SEEK_SET);
+  if (status) {
+    LoggerE("Cannot perform seek!");
+    return false;
+  }
+
+  size_t readed = 0;
+  char* data_p = data->data();
+  size_t data_size = length;
+  while (readed < data->size()) {
+    size_t part = fread(data_p, 1, data_size, file);
+
+    readed += part;
+    data_p += part;
+    data_size -= part;
+
+    LoggerD("Readed part %u bytes", readed);
+
+    if (ferror(file)) {
+      LoggerE("Error during file write!");
+      return false;
+    }
+
+    if (feof(file)) {
+      LoggerD("File is at end before buffer is filled. Finish.");
+      break;
+    }
+  }
+  LoggerD("Readed %u bytes", readed);
+  data->resize(readed);
+  return true;
+}
+
 bool FilesystemFile::Write(const FilesystemBuffer& data, size_t offset, bool rewrite) {
   ScopeLogger();
 
@@ -276,5 +329,68 @@ bool FilesystemFile::Write(const FilesystemBuffer& data, size_t offset, bool rew
 
   return true;
 }
+
+bool FilesystemFile::WriteString(const std::string& data, size_t offset, bool rewrite) {
+  ScopeLogger();
+
+  FILE* file = nullptr;
+  if (rewrite) {
+    file = fopen(path.c_str(), "w");
+  } else {
+    file = fopen(path.c_str(), "r+");
+  }
+
+  if (!file) {
+    LoggerE("Cannot open file %s to write!", path.c_str());
+    return false;
+  }
+
+  SCOPE_EXIT {
+    int status = fclose(file);
+    if (status) {
+      LoggerE("Cannot close file!");
+    }
+  };
+
+  int status;
+  status = fseek(file, offset, SEEK_SET);
+  LoggerD("Offset is %u, writing %i bytes", offset, data.size());
+  if (status) {
+    LoggerE("Cannot perform seek!");
+    return false;
+  }
+
+  size_t written = 0;
+  uint8_t* data_p = (uint8_t*)(data.c_str());
+  size_t data_size = data.size();
+
+  while (written < data.size()) {
+    size_t part = fwrite(data_p, 1, data_size, file);
+
+    if (ferror(file)) {
+      LoggerE("Error during file write!");
+      return false;
+    }
+
+    written += part;
+    data_p += part;
+    data_size -= part;
+  }
+
+  status = fflush(file);
+  if (status) {
+    LoggerE("Cannot flush file!");
+    return false;
+  }
+
+  status = fsync(fileno(file));
+  if (status) {
+    LoggerE("Cannot sync file!");
+    return false;
+  }
+  LoggerD("Written %u bytes", written);
+
+  return true;
+}
 }  // namespace filesystem
 }  // namespace extension
index 124467e..1e2d5c8 100644 (file)
@@ -45,7 +45,9 @@ class FilesystemFile {
   FilesystemFile(const std::string& path_);
 
   bool Read(FilesystemBuffer* data, size_t offset, size_t length);
+  bool ReadString(std::vector<char>* data, size_t offset, size_t length);
   bool Write(const FilesystemBuffer& data, size_t offset, bool rewrite);
+  bool WriteString(const std::string& data, size_t offset, bool rewrite);
 };
 
 }  // namespace filesystem
index 7a6e3f0..08c0fe5 100644 (file)
@@ -51,7 +51,6 @@ FilesystemInstance::FilesystemInstance() {
   REGISTER_SYNC("File_createSync", FileCreateSync);
   REGISTER_ASYNC("File_readDir", ReadDir);
   REGISTER_ASYNC("File_rename", FileRename);
-  REGISTER_ASYNC("File_read", FileRead);
   REGISTER_SYNC("File_readSync", FileReadSync);
   REGISTER_ASYNC("File_write", FileWrite);
   REGISTER_SYNC("File_writeSync", FileWriteSync);
@@ -136,51 +135,18 @@ void FilesystemInstance::FileRename(const picojson::value& args, picojson::objec
       std::bind(&FilesystemManager::Rename, &fsm, oldPath, newPath, onSuccess, onError));
 }
 
-void FilesystemInstance::FileRead(const picojson::value& args, picojson::object& out) {
-  ScopeLogger();
-  CHECK_EXIST(args, "callbackId", out)
-  CHECK_EXIST(args, "location", out)
-  CHECK_EXIST(args, "offset", out)
-  CHECK_EXIST(args, "length", out)
-
-  double callback_id = args.get("callbackId").get<double>();
-  const std::string& location = args.get("location").get<std::string>();
-  size_t offset = static_cast<size_t>(args.get("offset").get<double>());
-  size_t length = static_cast<size_t>(args.get("length").get<double>());
-
-  auto onSuccess = [this, callback_id](const std::string& data) {
-    ScopeLogger("Entered into asynchronous function, onSuccess");
-    picojson::value response = picojson::value(picojson::object());
-    picojson::object& obj = response.get<picojson::object>();
-    obj["callbackId"] = picojson::value(callback_id);
-    ReportSuccess(picojson::value(data), obj);
-    PostMessage(response.serialize().c_str());
-  };
-
-  auto onError = [this, callback_id](FilesystemError e) {
-    ScopeLogger("Entered into asynchronous function, onError");
-    picojson::value response = picojson::value(picojson::object());
-    picojson::object& obj = response.get<picojson::object>();
-    obj["callbackId"] = picojson::value(callback_id);
-    PrepareError(e, obj);
-    PostMessage(response.serialize().c_str());
-  };
-
-  FilesystemManager& fsm = FilesystemManager::GetInstance();
-  common::TaskQueue::GetInstance().Async(
-      std::bind(&FilesystemManager::FileRead, &fsm, location, offset, length, onSuccess, onError));
-}
-
 void FilesystemInstance::FileReadSync(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
   CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out);
   CHECK_EXIST(args, "location", out)
   CHECK_EXIST(args, "offset", out)
   CHECK_EXIST(args, "length", out)
+  CHECK_EXIST(args, "isString", out)
 
   const std::string& location = args.get("location").get<std::string>();
   size_t offset = static_cast<size_t>(args.get("offset").get<double>());
   size_t length = static_cast<size_t>(args.get("length").get<double>());
+  bool is_string = static_cast<bool>(args.get("isString").get<bool>());
 
   auto onSuccess = [this, &out](const std::string& data) {
     ScopeLogger("Entered into asynchronous function, onSuccess");
@@ -192,7 +158,7 @@ void FilesystemInstance::FileReadSync(const picojson::value& args, picojson::obj
     PrepareError(e, out);
   };
 
-  FilesystemManager::GetInstance().FileRead(location, offset, length, onSuccess, onError);
+  FilesystemManager::GetInstance().FileRead(location, offset, length, is_string, onSuccess, onError);
 }
 
 void FilesystemInstance::FileWrite(const picojson::value& args, picojson::object& out) {
@@ -202,12 +168,14 @@ void FilesystemInstance::FileWrite(const picojson::value& args, picojson::object
   CHECK_EXIST(args, "data", out)
   CHECK_EXIST(args, "offset", out)
   CHECK_EXIST(args, "rewrite", out)
+  CHECK_EXIST(args, "isString", out)
 
   double callback_id = args.get("callbackId").get<double>();
   const std::string& location = args.get("location").get<std::string>();
   const std::string& data = args.get("data").get<std::string>();
   size_t offset = static_cast<size_t>(args.get("location").get<double>());
-  bool rewrite = static_cast<size_t>(args.get("rewrite").get<bool>());
+  bool rewrite = static_cast<bool>(args.get("rewrite").get<bool>());
+  bool is_string = static_cast<bool>(args.get("isString").get<bool>());
 
   auto onSuccess = [this, callback_id]() {
     ScopeLogger("Entered into asynchronous function, onSuccess");
@@ -229,7 +197,8 @@ void FilesystemInstance::FileWrite(const picojson::value& args, picojson::object
 
   FilesystemManager& fsm = FilesystemManager::GetInstance();
   common::TaskQueue::GetInstance().Async(std::bind(&FilesystemManager::FileWrite, &fsm, location,
-                                                   data, offset, rewrite, onSuccess, onError));
+                                                   data, offset, rewrite, is_string, onSuccess,
+                                                   onError));
 }
 
 void FilesystemInstance::FileWriteSync(const picojson::value& args, picojson::object& out) {
@@ -239,11 +208,13 @@ void FilesystemInstance::FileWriteSync(const picojson::value& args, picojson::ob
   CHECK_EXIST(args, "data", out)
   CHECK_EXIST(args, "offset", out)
   CHECK_EXIST(args, "rewrite", out)
+  CHECK_EXIST(args, "isString", out)
 
   const std::string& location = args.get("location").get<std::string>();
   const std::string& data = args.get("data").get<std::string>();
   size_t offset = static_cast<size_t>(args.get("offset").get<double>());
-  bool rewrite = static_cast<size_t>(args.get("rewrite").get<bool>());
+  bool rewrite = static_cast<bool>(args.get("rewrite").get<bool>());
+  bool is_string = static_cast<bool>(args.get("isString").get<bool>());
 
   auto onSuccess = [this, &out]() {
     ScopeLogger("Entered into asynchronous function, onSuccess");
@@ -255,7 +226,8 @@ void FilesystemInstance::FileWriteSync(const picojson::value& args, picojson::ob
     PrepareError(e, out);
   };
 
-  FilesystemManager::GetInstance().FileWrite(location, data, offset, rewrite, onSuccess, onError);
+  FilesystemManager::GetInstance().FileWrite(location, data, offset, rewrite, is_string, onSuccess,
+                                             onError);
 }
 
 void FilesystemInstance::FileStat(const picojson::value& args, picojson::object& out) {
index 987b8d8..75e2fb7 100644 (file)
@@ -398,35 +398,55 @@ void FilesystemManager::RemoveDirectory(const std::string& path,
 }
 
 void FilesystemManager::FileRead(const std::string& path, size_t offset, size_t length,
+                                 bool is_string,
                                  const std::function<void(const std::string&)>& success_cb,
                                  const std::function<void(FilesystemError)>& error_cb) {
   ScopeLogger();
   FilesystemFile file(path);
-  FilesystemBuffer buffer;
-  if (!file.Read(&buffer, offset, length)) {
-    LoggerE("Cannot read file %s", path.c_str());
-    error_cb(FilesystemError::Other);
-    return;
-  }
 
-  std::string out_data = buffer.EncodeData();
-  success_cb(out_data);
+  // Encode data if its type is not string
+  if (!is_string) {
+    FilesystemBuffer buffer;
+    if (!file.Read(&buffer, offset, length)) {
+      LoggerE("Cannot read file %s", path.c_str());
+      error_cb(FilesystemError::Other);
+      return;
+    }
+    std::string out_data = buffer.EncodeData();
+    success_cb(out_data);
+  } else {
+    std::vector<char> buffer(length);
+    if (!file.ReadString(&buffer, offset, length)) {
+      LoggerE("Cannot read file %s", path.c_str());
+      error_cb(FilesystemError::Other);
+      return;
+    }
+    std::string out_data(buffer.begin(), buffer.end());
+    success_cb(out_data);
+  }
 }
 
 void FilesystemManager::FileWrite(const std::string& path, const std::string& data, size_t offset,
-                                  bool rewrite, const std::function<void()>& success_cb,
+                                  bool rewrite, bool is_string,
+                                  const std::function<void()>& success_cb,
                                   const std::function<void(FilesystemError)>& error_cb) {
   ScopeLogger();
   FilesystemFile file(path);
   FilesystemBuffer buffer;
-  // Decode buffer data
-  if (!buffer.DecodeData(data)) {
-    LoggerE("Cannot decode file data!");
-    error_cb(FilesystemError::Other);
-    return;
-  }
-
-  if (file.Write(buffer, offset, rewrite)) {
+  // Decode buffer data if type is not string
+  if (!is_string) {
+    if (!buffer.DecodeData(data)) {
+      LoggerE("Cannot decode file data!");
+      error_cb(FilesystemError::Other);
+      return;
+    }
+    if (file.Write(buffer, offset, rewrite)) {
+      success_cb();
+    } else {
+      LoggerE("Cannot write to file %s!", path.c_str());
+      error_cb(FilesystemError::Other);
+    }
+  } else if (file.WriteString(data, offset, rewrite)) {
     success_cb();
   } else {
     LoggerE("Cannot write to file %s!", path.c_str());
index 41903ce..f4e8c72 100644 (file)
@@ -83,12 +83,12 @@ class FilesystemManager {
   void RemoveDirectory(const std::string& path, const std::function<void()>& success_cb,
                        const std::function<void(FilesystemError)>& error_cb);
 
-  void FileRead(const std::string& path, size_t offset, size_t length,
+  void FileRead(const std::string& path, size_t offset, size_t length, bool is_string,
                 const std::function<void(const std::string&)>& success_cb,
                 const std::function<void(FilesystemError)>& error_cb);
 
   void FileWrite(const std::string& path, const std::string& data, size_t offset, bool rewrite,
-                 const std::function<void()>& success_cb,
+                 bool is_string, const std::function<void()>& success_cb,
                  const std::function<void(FilesystemError)>& error_cb);
 
   void CopyTo(const std::string& originFilePath, const std::string& destinationFilePath,
index 7622d53..44d5487 100644 (file)
@@ -317,12 +317,14 @@ function readAsText() {
     location: commonFS_.toRealPath(this.fullPath),
     offset: 0,
     length: 65536,
-    encoding: args.encoding
+    encoding: args.encoding,
+    isString: true
   };
 
   function readFile() {
     var result, encoded, buffers = [];
 
+    var output = "";
     do {
       result = native_.callSync('File_readSync', data);
       if (native_.isFailure(result)) {
@@ -331,17 +333,15 @@ function readAsText() {
         }, 0);
         return;
       }
-      encoded = native_.getResultObject(result);
-      if (encoded.length) {
-        buffers.push( Base64.decode(encoded) );
+      result = native_.getResultObject(result);
+      if (result.length) {
         data.offset += data.length;
       }
-    } while (encoded.length);
-
-    var buffer = Array.prototype.concat.apply([], buffers);
+      output = output + result;
+    } while (result.length)
 
     setTimeout(function() {
-      native_.callIfPossible(args.onsuccess, Base64._utf8_decode(buffer) );
+      native_.callIfPossible(args.onsuccess, output);
     }, 0);
   }
 
index 221f87e..2eb097e 100644 (file)
@@ -135,24 +135,25 @@ function read() {
   var data = {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position || 0,
-    length: args.charCount > _count ? _count : args.charCount
+    length: args.charCount > _count ? _count : args.charCount,
+    isString: true
   };
 
   var result = native_.callSync('File_readSync', data);
   if (native_.isFailure(result)) {
     throw new WebAPIException(WebAPIException.IO_ERR, 'Could not read');
   }
-  var decoded = Base64.decodeString(native_.getResultObject(result));
+  var outData = native_.getResultObject(result);
 
-  if (decoded.length) {
+  if (outData.length) {
     can_change_size = true;
-    this.position += decoded.length;
+    this.position += outData.length;
     can_change_size = false;
   } else {
     this.position += 1;   // Set EOF
   }
 
-  return decoded;
+  return outData;
 };
 
 FileStream.prototype.read = function() {
@@ -180,7 +181,8 @@ function readBytes() {
   var data = {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position || 0,
-    length: args.byteCount > _count ? _count : args.byteCount
+    length: args.byteCount > _count ? _count : args.byteCount,
+    isString: false
   };
 
   var result = native_.callSync('File_readSync', data);
@@ -238,7 +240,8 @@ function readBase64() {
   var data = {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position || 0,
-    length: args.byteCount > _count ? _count : args.byteCount
+    length: args.byteCount > _count ? _count : args.byteCount,
+    isString: false
   };
 
   var result = native_.callSync('File_readSync', data);
@@ -282,8 +285,9 @@ function write() {
   var data = {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position,
-    data: Base64.encodeString(args.stringData),
-    rewrite: this._rewrite
+    data: args.stringData,
+    rewrite: this._rewrite,
+    isString: true
   };
 
   var result = native_.callSync('File_writeSync', data);
@@ -322,7 +326,8 @@ function writeBytes() {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position,
     data: Base64.encode(args.byteData),
-    rewrite: this._rewrite
+    rewrite: this._rewrite,
+    isString: false
   };
 
   var result = native_.callSync('File_writeSync', data);
@@ -369,7 +374,8 @@ function writeBase64() {
     location: commonFS_.toRealPath(this._file.fullPath),
     offset: this.position,
     data: args.base64Data,
-    rewrite: this._rewrite
+    rewrite: this._rewrite,
+    isString: false
   };
 
   var result = native_.callSync('File_writeSync', data);
index 10385c6..8e8e58d 100644 (file)
@@ -271,11 +271,11 @@ class HumanActivityMonitorManager::Monitor {
   class GpsMonitor;
 
   explicit Monitor(const std::string& t) : type_(t) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
   }
 
   virtual ~Monitor() {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
   }
 
   std::string type() const {
@@ -287,7 +287,7 @@ class HumanActivityMonitorManager::Monitor {
   }
 
   PlatformResult SetListener(JsonCallback callback, const picojson::value& args) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     auto result = IsSupported();
     if (!result) {
@@ -304,7 +304,7 @@ class HumanActivityMonitorManager::Monitor {
   }
 
   PlatformResult UnsetListener() {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     auto result = IsSupported();
     if (!result) {
@@ -321,7 +321,7 @@ class HumanActivityMonitorManager::Monitor {
   }
 
   PlatformResult GetData(picojson::value* data) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     auto result = IsSupported();
     if (!result) {
@@ -332,7 +332,7 @@ class HumanActivityMonitorManager::Monitor {
   }
 
   PlatformResult StartDataRecorder(int interval, int retention_period) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     auto result = IsSupported();
     if (!result) {
@@ -343,13 +343,13 @@ class HumanActivityMonitorManager::Monitor {
   }
 
   PlatformResult StopDataRecorder() {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     return StopDataRecorderImpl();
   }
 
   PlatformResult ReadRecorderData(picojson::array* data, const picojson::value& query) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     auto result = IsSupported();
     if (!result) {
@@ -361,44 +361,44 @@ class HumanActivityMonitorManager::Monitor {
 
  protected:
   virtual PlatformResult IsSupportedImpl(bool* supported) const {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     *supported = false;
     return PlatformResult(ErrorCode::NO_ERROR);
   }
 
   virtual PlatformResult SetListenerImpl(const picojson::value& args) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
   virtual PlatformResult UnsetListenerImpl() {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
   virtual PlatformResult GetDataImpl(picojson::value* data) const {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
   virtual PlatformResult StartDataRecorderImpl(int interval, int retention_period) const {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
   virtual PlatformResult StopDataRecorderImpl() const {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
   virtual PlatformResult ReadRecorderDataImpl(picojson::array* data, const picojson::value& query) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "NOT_SUPPORTED_ERR");
   }
 
  public:
   PlatformResult IsSupported() {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (!is_supported_) {
       bool is_supported = false;
@@ -427,17 +427,17 @@ class HumanActivityMonitorManager::Monitor::GestureMonitor
     : public HumanActivityMonitorManager::Monitor {
  public:
   explicit GestureMonitor(const std::string& t) : Monitor(t), handle_(nullptr) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
   }
 
   virtual ~GestureMonitor() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     UnsetListenerImpl();
   }
 
  protected:
   virtual PlatformResult IsSupportedImpl(bool* s) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     bool supported = false;
 
@@ -459,7 +459,7 @@ class HumanActivityMonitorManager::Monitor::GestureMonitor
   }
 
   virtual PlatformResult SetListenerImpl(const picojson::value&) override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (!handle_) {
       int ret = gesture_create(&handle_);
@@ -482,7 +482,7 @@ class HumanActivityMonitorManager::Monitor::GestureMonitor
   }
 
   virtual PlatformResult UnsetListenerImpl() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (handle_) {
       int ret = gesture_stop_recognition(handle_);
@@ -538,17 +538,17 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
         converter_(c),
         converter_recorded_(r),
         recorded_data_(nullptr) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
   }
 
   virtual ~SensorMonitor() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     UnsetListenerImpl();
   }
 
  protected:
   virtual PlatformResult IsSupportedImpl(bool* s) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     bool supported = false;
 
@@ -564,7 +564,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
   }
 
   virtual PlatformResult SetListenerImpl(const picojson::value& args) override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (!handle_) {
       sensor_h sensor_handle = nullptr;
@@ -617,7 +617,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
   }
 
   virtual PlatformResult UnsetListenerImpl() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (handle_) {
       int ret = sensor_listener_stop(handle_);
@@ -648,7 +648,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
   }
 
   virtual PlatformResult GetDataImpl(picojson::value* data) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (!handle_) {
       return LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "SERVICE_NOT_AVAILABLE_ERR");
@@ -679,7 +679,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
   }
 
   virtual PlatformResult StartDataRecorderImpl(int interval, int retention_period) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     sensor_recorder_option_h option = nullptr;
 
@@ -710,7 +710,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
   }
 
   virtual PlatformResult StopDataRecorderImpl() const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     int ret = sensor_recorder_stop(sensor_);
     if (SENSOR_ERROR_NONE != ret) {
@@ -724,7 +724,7 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor
 
   virtual PlatformResult ReadRecorderDataImpl(picojson::array* data,
                                               const picojson::value& query) override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     std::lock_guard<std::mutex> lock(mutex_);
     this->recorded_data_ = data;
@@ -879,17 +879,17 @@ class HumanActivityMonitorManager::Monitor::GpsMonitor
     : public HumanActivityMonitorManager::Monitor {
  public:
   explicit GpsMonitor(const std::string& t) : Monitor(t), handle_(nullptr) {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
   }
 
   virtual ~GpsMonitor() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
     UnsetListenerImpl();
   }
 
  protected:
   virtual PlatformResult IsSupportedImpl(bool* s) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     int ret = 0;
     ret = system_info_get_platform_bool("http://tizen.org/feature/location.batch", s);
@@ -902,7 +902,7 @@ class HumanActivityMonitorManager::Monitor::GpsMonitor
   }
 
   virtual PlatformResult SetListenerImpl(const picojson::value& args) override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     int ret = 0;
 
@@ -959,7 +959,7 @@ class HumanActivityMonitorManager::Monitor::GpsMonitor
   }
 
   virtual PlatformResult UnsetListenerImpl() override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (handle_) {
       int ret = location_manager_stop_batch(handle_);
@@ -991,7 +991,7 @@ class HumanActivityMonitorManager::Monitor::GpsMonitor
   }
 
   virtual PlatformResult GetDataImpl(picojson::value* data) const override {
-    ScopeLogger(type());
+    ScopeLogger("type %s", type().c_str());
 
     if (!handle_) {
       return LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "SERVICE_NOT_AVAILABLE_ERR");
index bfa83fe..e34193f 100644 (file)
@@ -43,6 +43,42 @@ IotconClientManager& IotconClientManager::GetInstance() {
   return instance;
 }
 
+long long* IotconClientManager::Add(long long id) {
+  ScopeLogger();
+  ids_.push_back(new long long(id));
+  return ids_.back();
+}
+
+void IotconClientManager::Remove(long long id) {
+  ScopeLogger();
+  auto it = ids_.end();
+  while (it > ids_.begin()) {
+    --it;
+    if (**it == id) {
+      ids_.erase(it);
+      return;
+    }
+  }
+}
+
+bool IotconClientManager::IfExists(long long id) {
+  ScopeLogger();
+  for (auto v : ids_) {
+    if (*v == id) {
+      return true;
+    }
+  }
+  return false;
+}
+
+FoundRemoteInfoPtr IotconClientManager::GetFoundRemoteInfoPtr(long long id) {
+  ScopeLogger();
+  if (IfExists(id)) {
+    return remotes_map_.at(id);
+  }
+  return nullptr;
+}
+
 void IotconClientManager::PresenceHandler(iotcon_presence_h presence, iotcon_error_e err,
                                           iotcon_presence_response_h response, void* user_data) {
   ScopeLogger();
@@ -118,6 +154,7 @@ picojson::value IotconClientManager::RemoveRemoteResource(FoundRemoteInfoPtr ptr
   ptr->ref_count--;
   if (ptr->ref_count <= 0) {
     LoggerD("Handle not needed anymore, removing from map");
+    Remove(ptr->id);
     remotes_map_.erase(ptr->id);
     return PrepareManageIdAnswer(false);
   }
index 56bd87e..f3fccef 100644 (file)
@@ -42,6 +42,10 @@ class IotconClientManager {
   picojson::value RemoveRemoteResource(FoundRemoteInfoPtr ptr);
   common::TizenResult GetRemoteById(long long id, FoundRemoteInfoPtr* res_pointer) const;
   picojson::value PrepareManageIdAnswer(bool keep_id, long long id = 0);
+  long long* Add(long long id);
+  void Remove(long long id);
+  bool IfExists(long long id);
+  FoundRemoteInfoPtr GetFoundRemoteInfoPtr(long long id);
 
  private:
   IotconClientManager() = default;
@@ -55,6 +59,7 @@ class IotconClientManager {
 
   PresenceMap presence_map_;
   FoundRemotesMap remotes_map_;
+  IdVector ids_;
 };
 
 }  // namespace iotcon
index c71deeb..d650699 100644 (file)
@@ -45,11 +45,6 @@ struct CallbackData {
   }
 };
 
-struct CallbackData2 {
-  common::PostCallback fun;
-  bool callback_called;
-};
-
 long long GetId(const picojson::object& args) {
   return static_cast<long long>(args.find(kId)->second.get<double>());
 }
@@ -110,7 +105,6 @@ void RemoteResourceResponseCallback(iotcon_remote_resource_h resource, iotcon_er
         ret = IotconUtils::ResponseToJson(response, &value.get<picojson::object>());
         if (CallbackDataManager::GetInstance()->IfExists(data.get())) {
           LoggerD("user_data was called earlier, so ignore.");
-          data.release();
           return;
         }
         break;
@@ -119,7 +113,6 @@ void RemoteResourceResponseCallback(iotcon_remote_resource_h resource, iotcon_er
         ret = IotconUtils::ConvertIotconError(err);
         if (CallbackDataManager::GetInstance()->IfExists(data.get())) {
           LoggerD("user_data was called earlier, so ignore.");
-          data.release();
           return;
         }
         break;
@@ -127,13 +120,13 @@ void RemoteResourceResponseCallback(iotcon_remote_resource_h resource, iotcon_er
         ret = IotconUtils::ConvertIotconError(err);
         if (CallbackDataManager::GetInstance()->IfExists(data.get())) {
           LoggerD("user_data was called earlier, so ignore.");
-          data.release();
           return;
         }
         break;
     }
     CallbackDataManager::GetInstance()->Add(data.get());
     data->fun(ret, value);
+    data.release();
   } else {
     LoggerE("Native callback data is null");
   }
@@ -936,9 +929,12 @@ common::TizenResult IotconInstance::RemoteResourceMethodDelete(const picojson::o
 static void ObserveCallback(iotcon_remote_resource_h resource, iotcon_error_e err,
                             int sequence_number, iotcon_response_h response, void* user_data) {
   ScopeLogger();
-  FoundRemoteInfo* ptr = static_cast<FoundRemoteInfo*>(user_data);
+  long long* id = static_cast<long long*>(user_data);
+
+  FoundRemoteInfoPtr ptr = IotconClientManager::GetInstance().GetFoundRemoteInfoPtr(*id);
+
   if (nullptr == ptr) {
-    LoggerE("ObserveCallback() failed.  Ignoring callback");
+    LoggerE("ObserveCallback() failed. Ignoring callback");
     return;
   }
 
@@ -1015,14 +1011,17 @@ common::TizenResult IotconInstance::RemoteResourceStartObserving(const picojson:
     }
   }
 
-  result = IotconUtils::ConvertIotconError(iotcon_remote_resource_observe_register(
-      ptr->handle, observe_policy, query, ObserveCallback, ptr.get()));
+  picojson::value ret = IotconClientManager::GetInstance().StoreRemoteResource(ptr);
+  result = IotconUtils::ConvertIotconError(
+      iotcon_remote_resource_observe_register(ptr->handle, observe_policy, query, ObserveCallback,
+                                              IotconClientManager::GetInstance().Add(ptr->id)));
   if (!result) {
+    IotconClientManager::GetInstance().RemoveRemoteResource(ptr);
     return result;
   }
 
   observing_started_ = true;
-  return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(ptr)};
+  return common::TizenSuccess{ret};
 }
 
 common::TizenResult IotconInstance::RemoteResourceStopObserving(const picojson::object& args) {
@@ -1078,9 +1077,12 @@ common::TizenResult IotconInstance::RemoteResourceStopObserving(const picojson::
 static void RepresentationChangedCallback(iotcon_remote_resource_h resource,
                                           iotcon_representation_h representation, void* user_data) {
   ScopeLogger();
-  FoundRemoteInfo* ptr = static_cast<FoundRemoteInfo*>(user_data);
+  long long* id = static_cast<long long*>(user_data);
+
+  FoundRemoteInfoPtr ptr = IotconClientManager::GetInstance().GetFoundRemoteInfoPtr(*id);
+
   if (nullptr == ptr) {
-    LoggerE("RepresentationChangeCallback() failed.  Ignoring callback");
+    LoggerE("RepresentationChangeCallback() failed. Ignoring callback");
     return;
   }
 
@@ -1121,14 +1123,16 @@ common::TizenResult IotconInstance::RemoteResourceStartCaching(const picojson::o
     Post(kRemoteResourceCacheChangeListener, common::TizenSuccess{response});
   };
 
-  result = IotconUtils::ConvertIotconError(
-      iotcon_remote_resource_start_caching(ptr->handle, RepresentationChangedCallback, ptr.get()));
+  picojson::value ret = IotconClientManager::GetInstance().StoreRemoteResource(ptr);
+  result = IotconUtils::ConvertIotconError(iotcon_remote_resource_start_caching(
+      ptr->handle, RepresentationChangedCallback, IotconClientManager::GetInstance().Add(ptr->id)));
   if (!result) {
+    IotconClientManager::GetInstance().RemoveRemoteResource(ptr);
     return result;
   }
 
   caching_started_ = true;
-  return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(ptr)};
+  return common::TizenSuccess{ret};
 }
 
 common::TizenResult IotconInstance::RemoteResourceStopCaching(const picojson::object& args) {
@@ -1164,9 +1168,12 @@ common::TizenResult IotconInstance::RemoteResourceStopCaching(const picojson::ob
 static void MonitoringCallback(iotcon_remote_resource_h resource,
                                iotcon_remote_resource_state_e state, void* user_data) {
   ScopeLogger();
-  FoundRemoteInfo* ptr = static_cast<FoundRemoteInfo*>(user_data);
+  long long* id = static_cast<long long*>(user_data);
+
+  FoundRemoteInfoPtr ptr = IotconClientManager::GetInstance().GetFoundRemoteInfoPtr(*id);
+
   if (nullptr == ptr) {
-    LoggerE("MonitoringCallback() failed.  Ignoring callback");
+    LoggerE("MonitoringCallback() failed. Ignoring callback");
     return;
   }
 
@@ -1201,13 +1208,15 @@ common::TizenResult IotconInstance::RemoteResourceSetResourceStateChangeListener
     Post(kRemoteResourceStateChangeListener, common::TizenSuccess{response});
   };
 
-  result = IotconUtils::ConvertIotconError(
-      iotcon_remote_resource_start_monitoring(ptr->handle, MonitoringCallback, ptr.get()));
+  picojson::value ret = IotconClientManager::GetInstance().StoreRemoteResource(ptr);
+  result = IotconUtils::ConvertIotconError(iotcon_remote_resource_start_monitoring(
+      ptr->handle, MonitoringCallback, IotconClientManager::GetInstance().Add(ptr->id)));
   if (!result) {
+    IotconClientManager::GetInstance().RemoveRemoteResource(ptr);
     return result;
   }
   monitoring_started_ = true;
-  return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(ptr)};
+  return common::TizenSuccess{ret};
 }
 
 common::TizenResult IotconInstance::RemoteResourceUnsetResourceStateChangeListener(
@@ -1286,38 +1295,28 @@ common::TizenResult IotconInstance::RemoteResourceSetTimeInterval(const picojson
 bool IotconInstance::ResourceFoundCallback(iotcon_remote_resource_h resource, iotcon_error_e result,
                                            void* user_data) {
   ScopeLogger();
-  CallbackData2* data = static_cast<CallbackData2*>(user_data);
+  CallbackData* data = static_cast<CallbackData*>(user_data);
   if (nullptr == data) {
     LoggerE("ResourceFoundCallback() failed.  Ignoring callback");
     return IOTCON_FUNC_STOP;
   }
 
+  picojson::value v{picojson::object{}};
+  common::TizenResult ret = common::TizenSuccess();
   switch (result) {
     case IOTCON_ERROR_NONE:
+      ret = IotconUtils::RemoteResourceToJson(resource, &v.get<picojson::object>());
       break;
     case IOTCON_ERROR_TIMEOUT:
-      LoggerD("IOTCON_TIMEOUT data->callback_called :%d", data->callback_called);
-      if (!data->callback_called) {
-        auto ret = IotconUtils::ConvertIotconError(result);
-        data->fun(ret, picojson::value{});
-      }
-      delete data;
-      return IOTCON_FUNC_STOP;
+      LoggerD("IOTCON_TIMEOUT");
     default:
-      auto ret = IotconUtils::ConvertIotconError(result);
-      data->fun(ret, picojson::value{});
-      return IOTCON_FUNC_STOP;
+      ret = IotconUtils::ConvertIotconError(result);
   }
 
-  picojson::value json_result = picojson::value(picojson::object());
-
-  auto ret = IotconUtils::RemoteResourceToJson(resource, &(json_result.get<picojson::object>()));
+  data->fun(ret, v);
   if (!ret) {
-    data->fun(ret, picojson::value{});
     return IOTCON_FUNC_STOP;
   }
-  data->callback_called = true;
-  data->fun(ret, json_result);
 
   return IOTCON_FUNC_CONTINUE;
 }
@@ -1370,9 +1369,7 @@ common::TizenResult IotconInstance::ClientFindResource(const picojson::object& a
     Post(kFindResourceListenerToken, common::TizenSuccess{response});
   };
 
-  CallbackData2* data = new CallbackData2{};
-  data->fun = response;
-  data->callback_called = false;
+  CallbackData* data = new CallbackData{response};
 
   LoggerD("Running find with:\nhost_address: %s,\nconnectivity_type: %d", host_address,
           connectivity_type);
@@ -1381,6 +1378,20 @@ common::TizenResult IotconInstance::ClientFindResource(const picojson::object& a
   if (!result) {
     delete data;
     LogAndReturnTizenError(result);
+  } else {
+    int timeout = 60; //default value set much bigger than default value for iotcon = 30s
+    auto result = IotconUtils::ConvertIotconError(iotcon_get_timeout(&timeout));
+    if (!result) {
+      LoggerE("iotcon_get_timeout - function call failed, using default value %d", timeout);
+    } else {
+      timeout = timeout + 10; //add 10 extra second to prevent too fast delete
+    }
+    // adding listener to delete data, when find would be finished
+    std::thread([data, timeout]() {
+      std::this_thread::sleep_for(std::chrono::seconds(timeout));
+      LoggerD("Deleting resource find data: %p", data);
+      delete data;
+    }).detach();
   }
 
   return common::TizenSuccess();
@@ -1455,7 +1466,7 @@ common::TizenResult IotconInstance::ClientRemovePresenceEventListener(
 bool IotconDeviceInfoCb(iotcon_device_info_h device_info, iotcon_error_e result, void* user_data) {
   ScopeLogger();
 
-  CallbackData2* data = static_cast<CallbackData2*>(user_data);
+  CallbackData* data = static_cast<CallbackData*>(user_data);
   if (nullptr == data) {
     LoggerE("IotconDeviceInfoCb() failed.  Ignoring callback");
     return IOTCON_FUNC_STOP;
@@ -1467,21 +1478,17 @@ bool IotconDeviceInfoCb(iotcon_device_info_h device_info, iotcon_error_e result,
   switch (result) {
     case IOTCON_ERROR_NONE:
       ret = IotconUtils::DeviceInfoToJson(device_info, &v.get<picojson::object>());
-      data->callback_called = true;
       break;
     case IOTCON_ERROR_TIMEOUT:
-      LoggerD("IOTCON_TIMEOUT data->callback_called :%d", data->callback_called);
-      if (!data->callback_called) {
-        ret = IotconUtils::ConvertIotconError(result);
-        data->fun(ret, v);
-      }
-      delete data;
-      return IOTCON_FUNC_STOP;
+      LoggerD("IOTCON_TIMEOUT");
     default:
       ret = IotconUtils::ConvertIotconError(result);
   }
 
   data->fun(ret, v);
+  if (!ret) {
+    return IOTCON_FUNC_STOP;
+  }
 
   return IOTCON_FUNC_CONTINUE;
 }
@@ -1534,9 +1541,7 @@ common::TizenResult IotconInstance::ClientFindDeviceInfo(const picojson::object&
     Post(kFindDeviceInfoListenerToken, common::TizenSuccess{response});
   };
 
-  CallbackData2* data = new CallbackData2{};
-  data->fun = response;
-  data->callback_called = false;
+  CallbackData* data = new CallbackData{response};
 
   auto result = IotconUtils::ConvertIotconError(
       iotcon_find_device_info(host_address, con_type_e, query, IotconDeviceInfoCb, data));
@@ -1544,6 +1549,20 @@ common::TizenResult IotconInstance::ClientFindDeviceInfo(const picojson::object&
   if (!result) {
     delete data;
     LogAndReturnTizenError(result);
+  } else {
+    int timeout = 60; //default value set much bigger than default value for iotcon = 30s
+    auto result = IotconUtils::ConvertIotconError(iotcon_get_timeout(&timeout));
+    if (!result) {
+      LoggerE("iotcon_get_timeout - function call failed, using default value %d", timeout);
+    } else {
+      timeout = timeout + 10; //add 10 extra second to prevent too fast delete
+    }
+    // adding listener to delete data, when find would be finished
+    std::thread([data, timeout]() {
+      std::this_thread::sleep_for(std::chrono::seconds(timeout));
+      LoggerD("Deleting resource find data: %p", data);
+      delete data;
+    }).detach();
   }
 
   return common::TizenSuccess();
@@ -1553,7 +1572,7 @@ bool IotconPlatformInfoCb(iotcon_platform_info_h platform_info, iotcon_error_e r
                           void* user_data) {
   ScopeLogger();
 
-  CallbackData2* data = static_cast<CallbackData2*>(user_data);
+  CallbackData* data = static_cast<CallbackData*>(user_data);
   if (nullptr == data) {
     LoggerE("IotconPlatformInfoCb() failed.  Ignoring callback");
     return IOTCON_FUNC_STOP;
@@ -1565,21 +1584,17 @@ bool IotconPlatformInfoCb(iotcon_platform_info_h platform_info, iotcon_error_e r
   switch (result) {
     case IOTCON_ERROR_NONE:
       ret = IotconUtils::PlatformInfoToJson(platform_info, &v.get<picojson::object>());
-      data->callback_called = true;
       break;
     case IOTCON_ERROR_TIMEOUT:
-      LoggerD("IOTCON_TIMEOUT data->callback_called :%d", data->callback_called);
-      if (!data->callback_called) {
-        ret = IotconUtils::ConvertIotconError(result);
-        data->fun(ret, v);
-      }
-      delete data;
-      return IOTCON_FUNC_STOP;
+      LoggerD("IOTCON_TIMEOUT");
     default:
       ret = IotconUtils::ConvertIotconError(result);
   }
 
   data->fun(ret, v);
+  if (!ret) {
+    return IOTCON_FUNC_STOP;
+  }
 
   return IOTCON_FUNC_CONTINUE;
 }
@@ -1632,9 +1647,7 @@ common::TizenResult IotconInstance::ClientFindPlatformInfo(const picojson::objec
     Post(kFindPlatformInfoListenerToken, common::TizenSuccess{response});
   };
 
-  CallbackData2* data = new CallbackData2{};
-  data->fun = response;
-  data->callback_called = false;
+  CallbackData* data = new CallbackData{response};
 
   auto result = IotconUtils::ConvertIotconError(
       iotcon_find_platform_info(host_address, con_type_e, query, IotconPlatformInfoCb, data));
@@ -1642,6 +1655,20 @@ common::TizenResult IotconInstance::ClientFindPlatformInfo(const picojson::objec
   if (!result) {
     delete data;
     LogAndReturnTizenError(result);
+  } else {
+    int timeout = 60; //default value set much bigger than default value for iotcon = 30s
+    auto result = IotconUtils::ConvertIotconError(iotcon_get_timeout(&timeout));
+    if (!result) {
+      LoggerE("iotcon_get_timeout - function call failed, using default value %d", timeout);
+    } else {
+      timeout = timeout + 10; //add 10 extra second to prevent too fast delete
+    }
+    // adding listener to delete data, when find would be finished
+    std::thread([data, timeout]() {
+      std::this_thread::sleep_for(std::chrono::seconds(timeout));
+      LoggerD("Deleting resource find data: %p", data);
+      delete data;
+    }).detach();
   }
 
   return common::TizenSuccess();
index aa37b5d..47a75c9 100644 (file)
@@ -78,6 +78,7 @@ typedef std::shared_ptr<PresenceEvent> PresenceEventPtr;
 typedef std::map<long long, PresenceEventPtr> PresenceMap;
 typedef std::shared_ptr<FoundRemoteInfo> FoundRemoteInfoPtr;
 typedef std::map<long long, FoundRemoteInfoPtr> FoundRemotesMap;
+typedef std::vector<long long*> IdVector;
 
 using ResponsePtr = std::shared_ptr<std::remove_pointer<iotcon_response_h>::type>;
 
index 99ca583..e6597e5 100644 (file)
@@ -463,7 +463,7 @@ void MediaControllerClient::OnMetadataUpdate(const char* server_name, mc_metadat
   picojson::value metadata = picojson::value(picojson::object());
   PlatformResult result = Types::ConvertMetadata(metadata_h, &metadata.get<picojson::object>());
   if (!result) {
-    LoggerE("ConvertMetadata failed, error: ", result.message().c_str());
+    LoggerE("ConvertMetadata failed, error: %s", result.message().c_str());
     return;
   }
 
index 0c4d811..66c6b3a 100644 (file)
@@ -212,7 +212,7 @@ void MediaControllerServer::OnCommandReceived(const char* client_name, const cha
   std::string err;
   picojson::parse(data, data_str, data_str + strlen(data_str), &err);
   if (!err.empty()) {
-    LoggerE("Failed to parse bundle data: %d", err);
+    LoggerE("Failed to parse bundle data: %s", err.c_str());
     return;
   }
 
index 30e17b5..ffe8f4b 100644 (file)
@@ -35,7 +35,7 @@ MessageProxy::MessageProxy(EmailManager& manager)
     : common::dbus::Proxy(kDBusPathEmailStorageChange, kDBusIfaceEmailStorageChange,
                           kDBusNameSignalEmail, kDBusPathEmailStorageChange,
                           kDBusIfaceEmailStorageChange),
-                          email_manager_(manager) {
+      email_manager_(manager) {
   ScopeLogger();
 }
 
@@ -97,7 +97,7 @@ void MessageProxy::signalCallback(GDBusConnection* connection, const gchar* send
       LoggerD("Unrecognized status: %d", status);
   }
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
   }
   g_free(name);
 }
index 3f30d4d..b036581 100644 (file)
@@ -176,8 +176,9 @@ bool FilterUtils::isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& in
 
   bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time);
 
-  LoggerD("%d is%s in time range <%d, %d>", time_stamp, (is_in_range ? "" : " NOT"), from_time,
-          to_time);
+  LoggerD("%lld is%s in time range <%lld, %lld>", static_cast<long long>(time_stamp),
+          (is_in_range ? "" : " NOT"), static_cast<long long>(from_time),
+          static_cast<long long>(to_time));
 
   return is_in_range;
 }
index b082446..bd764dd 100644 (file)
@@ -58,12 +58,12 @@ class ChangeListenerContainer::ChangeListeners {
 
     for (auto& it : groups_) {
       if (it.second->Remove(id)) {
-        LoggerD("Listener with id: %d removed from group: %d", id, it.first);
+        LoggerD("Listener with id: %ld removed from group: %d", id, it.first);
         return;
       }
     }
 
-    LoggerW("WatchId %d not found", id);
+    LoggerW("WatchId %ld not found", id);
   }
 
   template <class CallbackType, class EventType>
@@ -155,11 +155,11 @@ class ChangeListenerContainer::ChangeListeners {
       bool ret = false;
 
       if (true == (ret = message_callbacks_.Remove(id))) {
-        LoggerD("Message listener with id: %d removed", id);
+        LoggerD("Message listener with id: %ld removed", id);
       } else if (true == (ret = conversation_callbacks_.Remove(id))) {
-        LoggerD("Conversation listener with id: %d removed", id);
+        LoggerD("Conversation listener with id: %ld removed", id);
       } else if (true == (ret = folder_callbacks_.Remove(id))) {
-        LoggerD("Folder listener with id: %d removed", id);
+        LoggerD("Folder listener with id: %ld removed", id);
       }
 
       return ret;
index 9a80c0d..0654d6a 100644 (file)
@@ -925,7 +925,7 @@ void EmailManager::removeMessages(MessagesCallbackUserData* callback) {
 
   PlatformResult ret = RemoveMessagesPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
     removeEmailCompleteCB(callback);
   }
@@ -1003,7 +1003,7 @@ void EmailManager::updateMessages(MessagesCallbackUserData* callback) {
 
   PlatformResult ret = UpdateMessagesPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
   }
 
@@ -1071,7 +1071,7 @@ void EmailManager::findMessages(FindMsgCallbackUserData* callback) {
 
   PlatformResult ret = FindMessagesPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
   }
 
@@ -1117,7 +1117,7 @@ PlatformResult EmailManager::FindConversationsPlatform(ConversationCallbackData*
     PlatformResult ret = MessageConversation::convertEmailConversationToObject(
         conversationsInfo.at(i).id, &conversation);
     if (ret.IsError()) {
-      LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+      LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
       return ret;
     }
     conversation->setUnreadMessages(conversationsInfo.at(i).unreadMessages);
@@ -1137,7 +1137,7 @@ void EmailManager::findConversations(ConversationCallbackData* callback) {
 
   PlatformResult ret = FindConversationsPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
   }
 
@@ -1256,7 +1256,7 @@ void EmailManager::findFolders(FoldersCallbackData* callback) {
 
   PlatformResult ret = FindFoldersPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
   }
 
@@ -1338,7 +1338,7 @@ void EmailManager::removeConversations(ConversationCallbackData* callback) {
 
   PlatformResult ret = RemoveConversationsPlatform(callback);
   if (ret.IsError()) {
-    LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
+    LoggerE("%d (%s)", static_cast<int>(ret.error_code()), (ret.message()).c_str());
     callback->SetError(ret);
   }
 
index d439357..ca7b00e 100644 (file)
@@ -1176,7 +1176,8 @@ PlatformResult Message::setMMSBodyAndAttachmentsFromStruct(Message* message, msg
 
               LoggerD("Loaded body: %s", message->getBody()->getPlainBody().c_str());
             } else {
-              LoggerE("Unhandled error: %d (%s)!", ret.error_code(), ret.message().c_str());
+              LoggerE("Unhandled error: %d (%s)!", static_cast<int>(ret.error_code()),
+                      ret.message().c_str());
               LoggerD("[p:%d, m:%d] body is not set", p, m);
             }
           } else {
@@ -1670,7 +1671,7 @@ bool Message::isMatchingAttribute(const std::string& attribute_name,
 
 bool Message::isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value,
                                        AnyPtr end_value) const {
-  ScopeLogger(attribute_name);
+  ScopeLogger("attribute name: %s", attribute_name.c_str());
 
   using namespace MESSAGE_FILTER_ATTRIBUTE;
   if (TIMESTAMP == attribute_name) {
index 5d1ea2c..3937eb4 100644 (file)
@@ -473,7 +473,7 @@ bool MessageConversation::isMatchingAttribute(const std::string& attribute_name,
 
 bool MessageConversation::isMatchingAttributeRange(const std::string& attribute_name,
                                                    AnyPtr initial_value, AnyPtr end_value) const {
-  ScopeLogger("attribute_name: " + attribute_name);
+  ScopeLogger("attribute_name: %s", attribute_name.c_str());
 
   using namespace CONVERSATION_FILTER_ATTRIBUTE;
 
index 9a8a874..ac15312 100644 (file)
@@ -47,7 +47,7 @@ static gboolean sendMessageTask(void* data) {
   auto ret = callback->getEmailManager().sendMessage(callback);
 
   if (!ret) {
-    LoggerE("Error: %d - %s", ret.error_code(), ret.message().c_str());
+    LoggerE("Error: %d - %s", static_cast<int>(ret.error_code()), ret.message().c_str());
   }
 
   return FALSE;
@@ -116,7 +116,7 @@ static gboolean loadMessageAttachmentTask(void* data) {
       const auto ret = callback->getEmailManager().loadMessageAttachment(callback);
 
       if (!ret) {
-        LoggerE("Error: %d - %s", ret.error_code(), ret.message().c_str());
+        LoggerE("Error: %d - %s", static_cast<int>(ret.error_code()), ret.message().c_str());
       }
     }
   } else {
index a5ca744..235b483 100644 (file)
@@ -54,7 +54,7 @@ static gboolean sendMessageThread(void* data) {
   auto ret = callback->getShortMsgManager().sendMessage(callback);
 
   if (!ret) {
-    LoggerE("Error: %d - %s", ret.error_code(), ret.message().c_str());
+    LoggerE("Error: %d - %s", static_cast<int>(ret.error_code()), ret.message().c_str());
   }
 
   return FALSE;
index d476d9c..e0567dc 100644 (file)
@@ -81,17 +81,17 @@ MessagePtrVector MessagesChangeCallback::filterMessages(tizen::AbstractFilterPtr
       }
 
       LoggerD("[%d] is Message(%p) {", i, message.get());
-      LoggerD("[%d] messageId: %d", i, message->getId());
-      LoggerD("[%d] message subject: %s", i, message->getSubject().c_str());
-      LoggerD("[%d] from: %s", i, message->getFrom().c_str());
+      LoggerD("messageId: %d", message->getId());
+      LoggerD("message subject: %s", message->getSubject().c_str());
+      LoggerD("from: %s", message->getFrom().c_str());
 
       if (message->getBody()) {
         const std::string& pBody = message->getBody()->getPlainBody();
-        LoggerD("[%d] message plainBody: %s", i, limitedString(pBody).c_str());
+        LoggerD("message plainBody: %s", limitedString(pBody).c_str());
       }
 
-      LoggerD("[%d] matched filter: %s", i, matched ? "YES" : "NO");
-      LoggerD("[%d] }");
+      LoggerD("matched filter: %s", matched ? "YES" : "NO");
+      LoggerD("}");
     }
 
     LoggerD("returning matching %d of %d messages", filtered_messages.size(),
index 4e4edff..f0df6e6 100644 (file)
@@ -203,9 +203,9 @@ msg_error_t MessagingDatabaseManager::connect() {
       return MSG_ERR_DB_CONNECT;
     }
 
-    LoggerD("DB connecting success: [%d]", sqlHandle);
+    LoggerD("DB connecting success: [%p]", sqlHandle);
   } else {
-    LoggerD("DB connection exists: [%d]", sqlHandle);
+    LoggerD("DB connection exists: [%p]", sqlHandle);
   }
 
   return MSG_SUCCESS;
@@ -474,7 +474,7 @@ PlatformResult MessagingDatabaseManager::getAttributeFilterQuery(AbstractFilterP
           break;
 
         default:
-          LoggerE("Unexpected folder ID: %d", folder_id);
+          LoggerE("Unexpected folder ID: %ld", static_cast<long>(folder_id));
           folder_id = -1;
           break;
       }
index d5ff5d7..c3f11e0 100644 (file)
@@ -58,9 +58,9 @@ class MessagingInstance : public common::ParsedInstance {
   void MessageStorageRemoveChangeListener(const picojson::value& args, picojson::object& out);
   void MessageGetMessageStatus(const picojson::value& args, picojson::object& out);
 
-  MessagingManager manager_;
   ShortMsgManager short_msg_manager_;
   EmailManager email_manager_;
+  MessagingManager manager_;
   PostQueue queue_;
 };
 
index 6007a59..050971f 100644 (file)
@@ -431,7 +431,7 @@ PlatformResult ShortMsgManager::callProperEventMessages(EventMessages* event,
             updated_conv.push_back(cur_conv);
           }
 
-          LoggerD("%s conversation with id:%d last_msg_id:d", (new_conv ? "ADDED" : "UPDATED"),
+          LoggerD("%s conversation with id:%d last_msg_id:%d", (new_conv ? "ADDED" : "UPDATED"),
                   cur_conv->getConversationId(), cur_conv->getLastMessageId());
         }
 
@@ -675,7 +675,7 @@ void ShortMsgManager::addDraftMessage(MessageCallbackUserData* callback) {
 
     PlatformResult ret = addDraftMessagePlatform(message);
     if (ret.IsError()) {
-      LoggerE("%d (%s)", ret.error_code(), ret.message().c_str());
+      LoggerE("%d (%s)", static_cast<int>(ret.error_code()), ret.message().c_str());
       callback->SetError(ret);
     }
   }
@@ -892,7 +892,8 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback) {
     PlatformResult ret =
         MessagingDatabaseManager::getInstance().findShortMessages(callback, &messagesIds);
     if (ret.IsError()) {
-      LoggerE("Failed to find short message: %s (%d)", ret.message().c_str(), ret.error_code());
+      LoggerE("Failed to find short message: %s (%d)", ret.message().c_str(),
+              static_cast<int>(ret.error_code()));
       callback->SetError(ret);
     }
 
@@ -1090,7 +1091,7 @@ void ShortMsgManager::removeConversations(ConversationCallbackData* callback) {
                   "saved MessageConversation(%p) with conv_id:%d",
                   conv_index, msg_index, cur_msg_id, conv.get(), conv_id);
             } else {
-              LoggerE("[%d] Couldn't get msg_id, error: %d!", error);
+              LoggerE("[%d] Couldn't get msg_id, error: %s!", error, get_error_message(error));
             }
           }
         } else {
index cad6baa..0c81b29 100644 (file)
@@ -846,7 +846,7 @@ PlatformResult NFCAdapter::TagNDEFSizeGetter(int /*tag_id*/, unsigned int* size)
 
   int err = nfc_tag_get_ndef_size(m_last_tag_handle, size);
   if (NFC_ERROR_NONE != err) {
-    LoggerE("Failed to get tag NDEF size: %d, %s", err);
+    LoggerE("Failed to get tag NDEF size: %d, %s", err, get_error_message(err));
     return NFCUtil::CodeToResult(err, "Failed to get tag NDEF size");
   }
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -1259,7 +1259,7 @@ PlatformResult NFCAdapter::GetCachedMessage(picojson::object& out) {
   PlatformResult ret = NFCMessageUtils::ReportNdefMessageFromData(raw_data, size, out);
   free(raw_data);
   if (ret.IsError()) {
-    LoggerE("Error: %d", ret.message().c_str());
+    LoggerE("Error: %s", ret.message().c_str());
     NFCMessageUtils::RemoveMessageHandle(message_handle);
     return ret;
   }
index a7b3418..8d0a0e2 100644 (file)
@@ -236,7 +236,7 @@ PlatformResult NotificationManager::PlayLEDCustomEffect(const picojson::object&
   ret = device_led_play_custom(timeOn, timeOff, color, platformFlags);
   if (DEVICE_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot play LED custom effect",
-                              ("Cannot play LED custom effect: ", ret));
+                              ("Cannot play LED custom effect: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -248,7 +248,7 @@ PlatformResult NotificationManager::StopLEDCustomEffect() {
   int ret = device_led_stop_custom();
   if (DEVICE_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot stop LED custom effect",
-                              ("Cannot stop LED custom effect: ", ret));
+                              ("Cannot stop LED custom effect: %d", ret));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
index 0bf31f7..d0a1147 100644 (file)
@@ -359,6 +359,8 @@ void PackageInstance::PackageManagerUninstall(const picojson::value& args, picoj
                            "any other platform error occurs"));
     }
   } else {
+    // pkg_info was gathered in this case, need to release memory - it is not needed
+    package_info_destroy(pkg_info);
     int request_id = 0;
     int ret = package_manager_request_uninstall(request_, id.c_str(), &request_id);
     if (ret != PACKAGE_MANAGER_ERROR_NONE) {
index e33cd4c..2e9ea1e 100644 (file)
@@ -353,7 +353,7 @@ FMRadioManager::~FMRadioManager() {
 }
 
 PlatformResult FMRadioManager::Start(double frequency) {
-  ScopeLogger("freq: %d", frequency);
+  ScopeLogger("freq: %lf", frequency);
 
   radio_state_e state;
   const auto err = radio_get_state(radio_instance_, &state);
index 8c65220..1dcc339 100644 (file)
@@ -284,7 +284,7 @@ SensorData::SensorData(SensorInstance& instance, sensor_type_e type_enum, const
 }
 
 SensorData::~SensorData() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   if (listener_) {
     sensor_destroy_listener(listener_);
@@ -337,7 +337,7 @@ void SensorData::SensorCallback(sensor_h sensor, sensor_event_s* event, void* us
 }
 
 PlatformResult SensorData::CheckInitialization() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   std::lock_guard<std::mutex> lock(initialization_mutex_);
   if (!handle_) {
@@ -360,7 +360,7 @@ PlatformResult SensorData::CheckInitialization() {
 }
 
 PlatformResult SensorData::IsSupported(bool* supported) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   if (!is_supported_) {
     bool is_supported = false;
@@ -377,7 +377,7 @@ PlatformResult SensorData::IsSupported(bool* supported) {
 }
 
 PlatformResult SensorData::IsSupportedImpl(bool* supported) const {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   bool is_supported = false;
   int ret = sensor_is_supported(type_enum_, &is_supported);
@@ -392,7 +392,7 @@ PlatformResult SensorData::IsSupportedImpl(bool* supported) const {
 }
 
 bool SensorData::is_supported() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   if (!is_supported_) {
     bool is_supported = false;
@@ -408,7 +408,7 @@ bool SensorData::is_supported() {
 }
 
 bool SensorData::UpdateEvent(sensor_event_s* event) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   if (comparator_(&previous_event_, event, sensor_value_count_)) {
     // previous and current events are the same -> no update
@@ -444,7 +444,7 @@ PlatformResult SensorData::AddDelayedStartSuccessCb(const std::function<void()>&
 PlatformResult SensorData::Start(
     const std::shared_ptr<picojson::value>& result,
     const std::function<void(const std::shared_ptr<picojson::value>&)>& report_result) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   auto res = CheckInitialization();
 
   if (!res) {
@@ -484,7 +484,7 @@ PlatformResult SensorData::Start(
 }
 
 PlatformResult SensorData::Stop() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   auto res = CheckInitialization();
 
@@ -513,7 +513,7 @@ PlatformResult SensorData::Stop() {
 }
 
 PlatformResult SensorData::SetChangeListener(unsigned int interval, unsigned int batch_latency) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   auto res = CheckInitialization();
 
@@ -544,7 +544,7 @@ PlatformResult SensorData::SetChangeListener(unsigned int interval, unsigned int
 }
 
 PlatformResult SensorData::UnsetChangeListener() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   auto res = CheckInitialization();
 
@@ -568,7 +568,7 @@ PlatformResult SensorData::UnsetChangeListener() {
 }
 
 PlatformResult SensorData::GetSensorData(picojson::object* data) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   auto res = CheckInitialization();
 
@@ -590,7 +590,7 @@ PlatformResult SensorData::GetSensorData(picojson::object* data) {
 }
 
 PlatformResult SensorData::GetHardwareInfo(picojson::object* data) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 
   auto res = CheckInitialization();
 
@@ -629,42 +629,42 @@ PlatformResult SensorData::GetHardwareInfo(picojson::object* data) {
 
   int ret = sensor_get_name(handle_, &name);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_name error code: %d", &ret);
+    LoggerE("Failed to sensor_get_name error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_vendor(handle_, &vendor);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_vendor error code: %d", &ret);
+    LoggerE("Failed to sensor_get_vendor error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_type(handle_, &type);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_type error code: %d", &ret);
+    LoggerE("Failed to sensor_get_type error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_min_range(handle_, &min_range);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_min_range error code: %d", &ret);
+    LoggerE("Failed to sensor_get_min_range error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_max_range(handle_, &max_range);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_max_range error code: %d", &ret);
+    LoggerE("Failed to sensor_get_max_range error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_resolution(handle_, &resolution);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_resolution error code: %d", &ret);
+    LoggerE("Failed to sensor_get_resolution error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_min_interval(handle_, &min_interval);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_min_interval error code: %d", &ret);
+    LoggerE("Failed to sensor_get_min_interval error code: %d", ret);
     return native_result(ret);
   }
   ret = sensor_get_max_batch_count(handle_, &max_batch_count);
   if (ret != SENSOR_ERROR_NONE) {
-    LoggerE("Failed to sensor_get_max_batch_count error code: %d", &ret);
+    LoggerE("Failed to sensor_get_max_batch_count error code: %d", ret);
     return native_result(ret);
   }
 
@@ -710,7 +710,7 @@ class HrmSensorData : public SensorData {
 
 HrmSensorData::HrmSensorData(SensorInstance& instance)
     : SensorData(instance, SENSOR_CUSTOM, "HRM_RAW", 1) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   // For amount of retrieved values from sensors please refer to native guides.
   AddSensor(new SensorData(instance, SENSOR_HRM_LED_IR, "LED_IR", 1));
   AddSensor(new SensorData(instance, SENSOR_HRM_LED_RED, "LED_RED", 1));
@@ -718,16 +718,16 @@ HrmSensorData::HrmSensorData(SensorInstance& instance)
 }
 
 HrmSensorData::~HrmSensorData() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
 }
 
 void HrmSensorData::AddSensor(SensorData* sensor) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   hrm_sensors_.insert(std::make_pair(sensor->type(), std::shared_ptr<SensorData>(sensor)));
 }
 
 PlatformResult HrmSensorData::CallMember(PlatformResult (SensorData::*member)()) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   bool is_any_supported = false;
   for (const auto& sensor : hrm_sensors_) {
     if (sensor.second->is_supported()) {
@@ -751,7 +751,7 @@ PlatformResult HrmSensorData::CallMember(
         const std::function<void(const std::shared_ptr<picojson::value>&)>&),
     const std::shared_ptr<picojson::value>& result,
     const std::function<void(const std::shared_ptr<picojson::value>&)>& work) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   bool is_any_supported = false;
   for (const auto& sensor : hrm_sensors_) {
     if (sensor.second->is_supported()) {
@@ -770,7 +770,7 @@ PlatformResult HrmSensorData::CallMember(
 }
 
 PlatformResult HrmSensorData::IsSupportedImpl(bool* supported) const {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   bool result = false;
 
   for (const auto& sensor : hrm_sensors_) {
@@ -790,17 +790,17 @@ PlatformResult HrmSensorData::IsSupportedImpl(bool* supported) const {
 PlatformResult HrmSensorData::Start(
     const std::shared_ptr<picojson::value>& result,
     const std::function<void(const std::shared_ptr<picojson::value>&)>& work) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   return CallMember(&SensorData::Start, result, work);
 }
 
 PlatformResult HrmSensorData::Stop() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   return CallMember(&SensorData::Stop);
 }
 
 PlatformResult HrmSensorData::SetChangeListener(unsigned int interval, unsigned int batch_latency) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   for (const auto& sensor : hrm_sensors_) {
     if (sensor.second->is_supported()) {
       auto res = sensor.second->SetChangeListener(interval, batch_latency);
@@ -813,12 +813,12 @@ PlatformResult HrmSensorData::SetChangeListener(unsigned int interval, unsigned
 }
 
 PlatformResult HrmSensorData::UnsetChangeListener() {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   return CallMember(&SensorData::UnsetChangeListener);
 }
 
 PlatformResult HrmSensorData::GetSensorData(picojson::object* data) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   for (const auto& sensor : hrm_sensors_) {
     if (sensor.second->is_supported()) {
       // HRMRawSensor.getHRMRawSensorData() can return only one value,
@@ -840,7 +840,7 @@ PlatformResult HrmSensorData::GetSensorData(picojson::object* data) {
 }
 
 PlatformResult HrmSensorData::GetHardwareInfo(picojson::object* data) {
-  ScopeLogger(type_to_string_map[type()]);
+  ScopeLogger("type: %s", type_to_string_map[type()].c_str());
   for (const auto& sensor : hrm_sensors_) {
     if (sensor.second->is_supported()) {
       return sensor.second->GetHardwareInfo(data);
index 3174436..8c98163 100644 (file)
@@ -274,7 +274,7 @@ PlatformResult SoundManager::SetVolume(const picojson::object& args) {
   auto it = max_volume_map_.find(sound_type);
   if (it == max_volume_map_.end()) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to find maxVolume",
-                              ("Failed to find maxVolume of type: %d", type.c_str()));
+                              ("Failed to find maxVolume of type: %s", type.c_str()));
   }
 
   int max_volume = it->second;
index 07dfedb..00722d5 100644 (file)
@@ -287,6 +287,13 @@ Utils.prototype.checkBackwardCompabilityPrivilegeAccess = function(current_privi
   }
 };
 
+Utils.prototype.checkProfile = function() {
+  var result = native_.callSync('Utils_checkProfile', {});
+
+  return native_.getResultObject(result);
+};
+
+
 /////////////////////////////////////////////////////////////////////////////
 /** @constructor */
 var Type = function() {};
@@ -1161,255 +1168,6 @@ NativeManager.prototype.callIfPossible = function(callback) {
   }
 };
 
-/*
- *bridge is a two way communication interface
- *Example usage:
- *var bridge = new NativeBridge(extension);
- *    To send sync method:
- *    var result = bridge.sync({
- *        cmd: 'my_cpp_function_symbol',
- *        args: {
- *            name: 'My name',
- *            age: 28
- *        }
- *    });
- *    xwalk.utils.log(result);
- *
- *    To send async method and handle response:
- *    bridge.async({
- *        cmd: 'my_cpp_function_symbol',
- *        args: {
- *            name: 'My name'
- *        }
- *    }).then({
- *        success: function (data) {
- *            var age = data.age;
- *            args.successCallback(age);
- *        },
- *        error: function (e) {...},
- *        someCallback: function (data) {...}
- *    });
- *bridge.async will add special param to passed data called cid
- *that param need to be kept and returned with respons
- *To determine which callback should be invoked, response should
- *contain "action" param. Value of "action" param indicates name of
- *triggered callback.
- *Callbask are removed from listenr by defoult to prevent that behaviour
- *param "keep" should be assigned to value true
- *Example of c++ async response:
- *    Simple succes with data:
- *    {
- *        cid: 23,
- *        action: 'success',
- *        args: {
- *            age: 23
- *        }
- *    }
- *    More complicated example:
- *    {
- *        cid: 23,
- *        action: 'progress',
- *        keep: true,
- *        args: {
- *            age: 23
- *        }
- *    }
- */
-var NativeBridge = (function (extension, debug) {
-    debug = !!debug;
-    var Callbacks = (function () {
-        var _collection = {};
-        var _cid = 0;
-        var _next = function () {
-            return (_cid += 1);
-        };
-
-        var CallbackManager = function () {};
-
-        CallbackManager.prototype = {
-            add: function (/*callbacks, cid?*/) {
-                if (debug) xwalk.utils.log('bridge.CallbackManager.add');
-                var args = Array.prototype.slice.call(arguments);
-                var c = args.shift();
-                var cid = args.pop();
-                if (cid) {
-                    if (c !== null && typeof c === 'object') {
-                        for (var key in c) {
-                            if (c.hasOwnProperty(key)) _collection[cid][key] = c[key];
-                        }
-                    }
-                } else {
-                    cid = _next();
-                    _collection[cid] = c;
-                }
-                return cid;
-            },
-            remove: function (cid) {
-                if (debug)  xwalk.utils.log('bridge.CallbackManager.remove, cid: ' + cid);
-                if (_collection[cid]) delete _collection[cid];
-            },
-            call: function (cid, key, args, keep) {
-                if (debug) xwalk.utils.log('bridge.CallbackManager.call, cid: '+ cid + ', key: ' + key);
-                var callbacks = _collection[cid];
-                keep = !!keep;
-                if (callbacks) {
-                    var fn = callbacks[key];
-                    if (fn) {
-                        fn.apply(null, args);
-                        if (!keep) this.remove(cid)
-                    }
-                }
-            }
-        };
-
-        return {
-            getInstance: function () {
-                return this.instance || (this.instance = new CallbackManager);
-            }
-        };
-    })();
-
-
-    var Listeners = (function () {
-        var _listeners = {};
-        var _id = 0;
-        var _next = function () {
-            return (_id += 1);
-        };
-
-        var ListenerManager = function () {};
-
-        ListenerManager.prototype = {
-            add: function (l) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.add');
-                var id = _next();
-                _listeners[id] = l;
-                return id;
-            },
-            resolve: function (id, action, data, keep) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.resolve, id: ' + id + ', action: ' + action);
-                keep = !!keep;
-                var l = _listeners[id];
-                if (l) {
-                    var cm = Callbacks.getInstance();
-                    cm.call(l.cid, action, [data], keep);
-                }
-                return l;
-            },
-            remove: function (id) {
-                if (debug) xwalk.utils.log('bridge.ListenerManager.remove, id: ' + id);
-                var l = _listeners[id];
-                if (l) {
-                    var cm = Callbacks.getInstance();
-                    if (l.cid) cm.remove(l.cid);
-                    delete _listeners[id];
-                }
-            },
-            attach: function (id, key, value) {
-                if (_listeners[id]) {
-                    _listeners[id][key] = value;
-                    return true;
-                }
-                return false;
-            },
-            find: function (key, value) {
-                var result = [];
-                for (var p in _listeners) {
-                    if (_listeners.hasOwnProperty(p)) {
-                        var l = _listeners[p];
-                        if (l[key] === value) result.push({id: p, listener: l});
-                    }
-                }
-                return result;
-            }
-        }
-
-        return {
-            getInstance: function () {
-                return this.instance || (this.instance = new ListenerManager);
-            }
-        };
-    })();
-
-    var Listener = function () {
-        if (debug) xwalk.utils.log('bridge: Listener constructor');
-        this.cid = null;
-    };
-    Listener.prototype = {
-        then: function (c) {
-            if (debug) xwalk.utils.log('bridge.Listener.then');
-            var cm = Callbacks.getInstance();
-            this.cid = cm.add(c, this.cid);
-            return this;
-        }
-    };
-
-    var Bridge = function () {};
-    Bridge.prototype = {
-        sync: function (data) {
-            var json = JSON_.stringify({
-              cmd: data.cmd,
-              args: data
-            });
-            if (debug) xwalk.utilss.log('bridge.sync, json: ' + json);
-            var result = extension.internal.sendSyncMessage(json);
-            var obj = JSON_.parse(result);
-            if (obj.error)
-                throw new WebAPIException(obj.code, obj.name, obj.message);
-            return obj.result;
-        },
-        async: function (data) {
-            var l = new Listener();
-            data.cid = Listeners.getInstance().add(l);
-            var json = JSON_.stringify({
-                cmd: data.cmd,
-                args: data
-            });
-            if (debug) xwalk.utils.log('bridge.async, json: ' + json);
-            setTimeout(function () {
-                extension.postMessage(json);
-            });
-            return l;
-        },
-        listener: function (c) {
-            var l = (new Listener()).then(c);
-            var cid = Listeners.getInstance().add(l);
-            return cid;
-        },
-        attach: function (id, key, value) {
-            return Listeners.getInstance().attach(id, key, value);
-        },
-        find: function (key, value) {
-            return Listeners.getInstance().find(key, value);
-        },
-        remove: function (id) {
-            Listeners.getInstance().remove(id);
-        }
-    };
-
-    extension.setMessageListener(function (json) {
-        /*
-         *Expected response:
-         *{
-         *    cid: 23,                        // callback id
-         *    action: 'success',              // expected callback action
-         *    keep: false                     // optional param
-         *    args: {...}                     // data pased to callback
-         *}
-         */
-
-        if (debug) xwalk.utils.log('bridge.setMessageListener, json: ' + json);
-        var data = JSON_.parse(json);
-        if (data.cid && data.action) {
-            setTimeout(function() {
-                Listeners.getInstance().resolve(data.cid, data.action, data.args, data.keep);
-            }, 0);
-        }
-    });
-
-    return new Bridge;
-});
-
 // WebAPIException and WebAPIError definition moved to Utils for compliance
 // reasons with blink-wrt environment.
 // In blink-wrt the original Tizen module is loaded, which is not providing exception constructor.
@@ -1612,7 +1370,6 @@ Utils.prototype.type = _type;
 Utils.prototype.converter = _converter;
 Utils.prototype.validator = _validator;
 Utils.prototype.NativeManager = NativeManager;
-Utils.prototype.NativeBridge = NativeBridge;
 
 var native_ = new NativeManager(extension);
 
@@ -1622,5 +1379,4 @@ Object.freeze(exports);
 Object.freeze(exports.utils);
 Object.freeze(Utils.prototype);
 Object.freeze(NativeManager.prototype);
-Object.freeze(NativeBridge.prototype);
 
index 65f5995..9cb9dd5 100644 (file)
@@ -33,6 +33,7 @@ UtilsInstance::UtilsInstance() {
                 CheckBackwardCompabilityPrivilegeAccess);
   REGISTER_SYNC("Utils_toLongLong", ToLongLong);
   REGISTER_SYNC("Utils_toUnsignedLongLong", ToUnsignedLongLong);
+  REGISTER_SYNC("Utils_checkProfile", CheckProfile);
 
 #undef REGISTER_SYNC
 #undef REGISTER_ASYNC
@@ -116,5 +117,22 @@ void UtilsInstance::ToUnsignedLongLong(const picojson::value& args, picojson::ob
   ReportSuccess(picojson::value(static_cast<double>(output)), out);
 }
 
+void UtilsInstance::CheckProfile(const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+
+  std::string profile = "common";
+#if defined(TIZEN_MOBILE)
+  profile = "mobile";
+#elif defined(TIZEN_WEARABLE)
+  profile = "wearable";
+#elif defined(TIZEN_TV) || defined(USBHOST)
+  profile = "tv";
+#elif defined(TIZEN_IVI)
+  profile = "ivi";
+#endif
+
+  ReportSuccess(picojson::value(profile), out);
+}
+
 }  // namespace utils
 }  // namespace extension
index fee0d41..c39a91d 100644 (file)
@@ -24,6 +24,7 @@ class UtilsInstance : public common::ParsedInstance {
 
   void ToLongLong(const picojson::value& args, picojson::object& out);
   void ToUnsignedLongLong(const picojson::value& args, picojson::object& out);
+  void CheckProfile(const picojson::value& args, picojson::object& out);
 };
 }  // namespace utils
 }  // namespace extension