#include <glib.h>
+#include <tizen.h>
#include <algorithm>
#include <functional>
#include <limits>
REGISTER_METHOD(SQLDataControlConsumerRemove);
REGISTER_METHOD(MappedDataControlConsumerRemoveValue);
REGISTER_METHOD(MappedDataControlConsumerUpdateValue);
- REGISTER_METHOD(DataControlManagerGetConsumer);
REGISTER_METHOD(SQLDataControlConsumerInsert);
REGISTER_METHOD(MappedDataControlConsumerGetValue);
REGISTER_METHOD(DataControlConsumerObjectRemoveChangeListener);
void* user_data) {
ScopeLogger();
+ /*
+ * According to the documentation of data_control_map_get_response_cb, result_value_list
+ * should be freed with the code, commented out below.
+ * However, when we free result_value_list, the app crashes.
+ *
+ * We have asked data-control developers about this problem and we are waiting for the
+ * response, telling us wether we should free the list or not.
+ *
+ * TODO (when we get the answer): comment out the SCOPE_EXIT below or remove it from the code.
+ */
+ /*SCOPE_EXIT {
+ for (int i = 0; i < result_value_count; ++i) {
+ free(result_value_list[i]);
+ }
+ free(result_value_list);
+ };*/
+
std::lock_guard<std::mutex> lock(IdMapMutex);
DatacontrolInformation* info = IdMap[requestId];
if (info == NULL) {
return; \
}
-void DatacontrolInstance::DataControlManagerGetConsumer(const picojson::value& args,
- picojson::object& out) {
- ScopeLogger();
- CHECK_PRIVILEGE_ACCESS(kPrivilegeDatacontrol, &out);
-
- CHECK_EXIST(args, "providerId", out)
- CHECK_EXIST(args, "dataId", out)
-}
void DatacontrolInstance::SQLDataControlConsumerInsert(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
picojson::array::size_type size = std::min(columnsLength, valuesLength);
bundle* b = ::bundle_create();
+ if (!b) {
+ auto error_code = get_last_result();
+ LoggerE("bundle_create() failed: %s", get_error_message(error_code));
+ return error_code;
+ }
+
SCOPE_EXIT {
bundle_free(b);
};
picojson::object updateData = args.get("updateData").get<picojson::object>();
if (!updateData.count("columns") || !updateData.count("values")) {
- LogAndReportError(TypeMismatchException("columns and values is required updateData argument"),
+ LogAndReportError(TypeMismatchException("columns and values are required updateData arguments"),
out);
return;
}
picojson::array::size_type size = std::min(columnsLength, valuesLength);
bundle* b = ::bundle_create();
+ if (!b) {
+ auto error_code = get_last_result();
+ LoggerE("bundle_create() failed: %s", get_error_message(error_code));
+ return error_code;
+ }
+
SCOPE_EXIT {
bundle_free(b);
};
break;
}
- std::string& columnName = column.get<std::string>();
- std::string valueString = value.get<std::string>();
+ const std::string& columnName = column.get<std::string>();
+ const std::string& valueString = value.get<std::string>();
- bundle_add_str(b, columnName.c_str(), valueString.c_str());
+ int result = bundle_add_str(b, columnName.c_str(), valueString.c_str());
+ if (BUNDLE_ERROR_NONE != result) {
+ return result;
+ }
}
return ::data_control_sql_update(handle, b, where.c_str(), requestId);
RETURN_IF_FAIL(result, "Creating map data control handle is failed with error");
result = ::data_control_map_set_provider_id(*handle, providerId.c_str());
- RETURN_IF_FAIL(result, "Setting provider id is failed with error");
+ if (result != DATA_CONTROL_ERROR_NONE) {
+ LoggerE("Setting provider id is failed with error : %s", ::get_error_message(result));
+ data_control_map_destroy(*handle);
+ *handle = nullptr;
+ return result;
+ }
result = ::data_control_map_set_data_id(*handle, dataId.c_str());
- RETURN_IF_FAIL(result, "Setting data id is failed the error");
+ if (result != DATA_CONTROL_ERROR_NONE) {
+ LoggerE("Setting data id is failed with error : %s", ::get_error_message(result));
+ data_control_map_destroy(*handle);
+ *handle = nullptr;
+ return result;
+ }
return result;
}
RETURN_IF_FAIL(result, "Creating sql data control handle is failed with error");
result = ::data_control_sql_set_provider_id(*handle, providerId.c_str());
- RETURN_IF_FAIL(result, "Setting provider id is failed with error");
+ if (result != DATA_CONTROL_ERROR_NONE) {
+ LoggerE("Setting provider id is failed with error : %s", ::get_error_message(result));
+ data_control_sql_destroy(*handle);
+ *handle = nullptr;
+ return result;
+ }
result = ::data_control_sql_set_data_id(*handle, dataId.c_str());
- RETURN_IF_FAIL(result, "Setting data id is failed the error");
+ if (result != DATA_CONTROL_ERROR_NONE) {
+ LoggerE("Setting data id is failed with error : %s", ::get_error_message(result));
+ data_control_sql_destroy(*handle);
+ *handle = nullptr;
+ return result;
+ }
return result;
}
// result_callback method is used only for pass information to errorCallback if any error
// occur while adding listener
void DatacontrolInstance::result_callback(data_control_h provider, data_control_error_e result,
- int callback_id, void* user_data) {
+ int watch_id, void* user_data) {
ScopeLogger();
if (DATA_CONTROL_ERROR_NONE != result) {
auto data = static_cast<ReplyCallbackData*>(user_data);
// handled earlier
LogAndReportError(IOException("DataControlConsumerObjectAddChangeListener failed"), obj);
Instance::PostMessage(data->_instance, event.serialize().c_str());
- if (0 != callback_id) {
- data->_instance->EraseMap(callback_id);
+ if (0 != watch_id) {
+ data->_instance->EraseMap(watch_id);
}
}
}