}
};
-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");
}
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();