%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
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}"
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
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}"
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
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}"
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}"
./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
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
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
%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/
%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/
%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/
%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/
'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',
+ ],
+ }]
],
},
],
}
};
+// 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();
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",
// 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() {
#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"
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();
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();
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()));
}
}
}
}
+#if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
void AlarmManager::GetAlarmNotification(const picojson::value& args, picojson::object& out) {
using namespace extension::notification;
ScopeLogger();
ReportSuccess(result, out);
}
-
+#endif
static bool AlarmIterateCB(int alarm_id, void* user_data) {
ScopeLogger();
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);
void AlarmManager::GetNextScheduledDate(const picojson::value& args, picojson::object& out) {
ScopeLogger();
-
int id = 0;
if (args.contains("id") && args.get("id").is<double>()) {
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
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_;
}
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()));
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);
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;
}
};
- LoggerD("Kill async, setting callback");
+ LoggerD("Kill, setting callback");
handler->set_pid(pid);
ret = app_manager_set_app_context_event_cb(terminate_callback, handler);
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);
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) {
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;
}
};
- 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) {
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
}
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;
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) {
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
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_;
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();
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);
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);
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);
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);
}
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"),
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);
'XW_Extension.cc',
],
'cflags': [
- '-std=c++0x',
'-fPIC',
'-fvisibility=hidden',
'-Wall',
+ '-Werror',
+ ],
+ 'cflags_c': [
+ '-std=c11',
+ ],
+ 'cflags_cc': [
+ '-std=c++14',
],
'libraries' : [
'-L .',
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() {
} // 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_
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)) {
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;
}
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;
}
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) &&
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];
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);
}
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): {
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;
}
}
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) {
}
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();
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();
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
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
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);
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");
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) {
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");
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) {
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");
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) {
}
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());
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,
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)) {
}, 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);
}
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() {
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);
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);
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);
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);
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);
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 {
}
PlatformResult SetListener(JsonCallback callback, const picojson::value& args) {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
auto result = IsSupported();
if (!result) {
}
PlatformResult UnsetListener() {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
auto result = IsSupported();
if (!result) {
}
PlatformResult GetData(picojson::value* data) {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
auto result = IsSupported();
if (!result) {
}
PlatformResult StartDataRecorder(int interval, int retention_period) {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
auto result = IsSupported();
if (!result) {
}
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) {
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;
: 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;
}
virtual PlatformResult SetListenerImpl(const picojson::value&) override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
if (!handle_) {
int ret = gesture_create(&handle_);
}
virtual PlatformResult UnsetListenerImpl() override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
if (handle_) {
int ret = gesture_stop_recognition(handle_);
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;
}
virtual PlatformResult SetListenerImpl(const picojson::value& args) override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
if (!handle_) {
sensor_h sensor_handle = nullptr;
}
virtual PlatformResult UnsetListenerImpl() override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
if (handle_) {
int ret = sensor_listener_stop(handle_);
}
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");
}
virtual PlatformResult StartDataRecorderImpl(int interval, int retention_period) const override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
sensor_recorder_option_h option = nullptr;
}
virtual PlatformResult StopDataRecorderImpl() const override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
int ret = sensor_recorder_stop(sensor_);
if (SENSOR_ERROR_NONE != ret) {
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;
: 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);
}
virtual PlatformResult SetListenerImpl(const picojson::value& args) override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
int ret = 0;
}
virtual PlatformResult UnsetListenerImpl() override {
- ScopeLogger(type());
+ ScopeLogger("type %s", type().c_str());
if (handle_) {
int ret = location_manager_stop_batch(handle_);
}
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");
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();
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);
}
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;
PresenceMap presence_map_;
FoundRemotesMap remotes_map_;
+ IdVector ids_;
};
} // namespace iotcon
}
};
-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>());
}
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;
ret = IotconUtils::ConvertIotconError(err);
if (CallbackDataManager::GetInstance()->IfExists(data.get())) {
LoggerD("user_data was called earlier, so ignore.");
- data.release();
return;
}
break;
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");
}
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;
}
}
}
- 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) {
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;
}
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) {
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;
}
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(
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;
}
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);
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();
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;
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;
}
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));
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();
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;
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;
}
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));
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();
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>;
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;
}
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;
}
: common::dbus::Proxy(kDBusPathEmailStorageChange, kDBusIfaceEmailStorageChange,
kDBusNameSignalEmail, kDBusPathEmailStorageChange,
kDBusIfaceEmailStorageChange),
- email_manager_(manager) {
+ email_manager_(manager) {
ScopeLogger();
}
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);
}
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;
}
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>
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;
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);
}
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);
}
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);
}
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);
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);
}
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);
}
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);
}
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 {
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) {
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;
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;
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 {
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;
}
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(),
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;
break;
default:
- LoggerE("Unexpected folder ID: %d", folder_id);
+ LoggerE("Unexpected folder ID: %ld", static_cast<long>(folder_id));
folder_id = -1;
break;
}
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_;
};
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());
}
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);
}
}
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);
}
"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 {
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);
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;
}
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);
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);
"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) {
}
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);
}
SensorData::~SensorData() {
- ScopeLogger(type_to_string_map[type()]);
+ ScopeLogger("type: %s", type_to_string_map[type()].c_str());
if (listener_) {
sensor_destroy_listener(listener_);
}
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_) {
}
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;
}
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);
}
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;
}
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
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) {
}
PlatformResult SensorData::Stop() {
- ScopeLogger(type_to_string_map[type()]);
+ ScopeLogger("type: %s", type_to_string_map[type()].c_str());
auto res = CheckInitialization();
}
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();
}
PlatformResult SensorData::UnsetChangeListener() {
- ScopeLogger(type_to_string_map[type()]);
+ ScopeLogger("type: %s", type_to_string_map[type()].c_str());
auto res = CheckInitialization();
}
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();
}
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();
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);
}
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));
}
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()) {
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()) {
}
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_) {
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);
}
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,
}
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);
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;
}
};
+Utils.prototype.checkProfile = function() {
+ var result = native_.callSync('Utils_checkProfile', {});
+
+ return native_.getResultObject(result);
+};
+
+
/////////////////////////////////////////////////////////////////////////////
/** @constructor */
var Type = function() {};
}
};
-/*
- *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.
Utils.prototype.converter = _converter;
Utils.prototype.validator = _validator;
Utils.prototype.NativeManager = NativeManager;
-Utils.prototype.NativeBridge = NativeBridge;
var native_ = new NativeManager(extension);
Object.freeze(exports.utils);
Object.freeze(Utils.prototype);
Object.freeze(NativeManager.prototype);
-Object.freeze(NativeBridge.prototype);
CheckBackwardCompabilityPrivilegeAccess);
REGISTER_SYNC("Utils_toLongLong", ToLongLong);
REGISTER_SYNC("Utils_toUnsignedLongLong", ToUnsignedLongLong);
+ REGISTER_SYNC("Utils_checkProfile", CheckProfile);
#undef REGISTER_SYNC
#undef REGISTER_ASYNC
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
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