value: null,
writable: true,
enumerable: false
+ },
+ _isStarted : {
+ value: false,
+ writable: true,
+ enumerable: false
}
});
native_.callIfPossible(s._connectCallback, s);
break;
case 'onStart':
+ s._isStarted = true;
native_.callIfPossible(s._startCallback,
new ChannelInfo(result.channel.uri, result.channel.id), null);
break;
new ChannelInfo(result.channel.uri, result.channel.id), null);
break;
case 'onStop':
+ s._isStarted = false;
native_.callIfPossible(s._stopCallback,
new ChannelInfo(result.channel.uri, result.channel.id), null);
break;
{
name: 'successCallback',
type: types_.FUNCTION,
- //values: ConnectSuccessCallback,
optional: false,
nullable: false
},
{
name: 'errorCallback',
type: types_.FUNCTION,
- //values: ErrorCallback,
optional: true,
nullable: true
}
]);
- // TODO check if the service is connected and started
- // Raise the exception instead
+ if (this._isStarted) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Service already started.');
+ }
var lid = this._serviceId;
this._startCallback = successCallback;
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
}
});
+
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
{
name: 'successCallback',
type: types_.FUNCTION,
- //values: ConnectSuccessCallback,
optional: true,
nullable: true
},
{
name: 'errorCallback',
type: types_.FUNCTION,
- //values: ErrorCallback,
optional: true,
nullable: true
}
]);
- // TODO check if the service is connected and started
- // Raise the exception instead
+ if (!this._isStarted) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Service is not started.');
+ }
var lid = -1;
if (successCallback) {
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
}
});
+
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
},
{
name: 'payload',
- type: types_.PLATFORM_OBJECT,
- values: [tizen.PayloadString, tizen.PayloadRawBytes],
+ type: types_.ARRAY,
optional: false,
nullable: false
},
{
name: 'successCallback',
type: types_.FUNCTION,
- //values: ConnectSuccessCallback,
optional: false,
nullable: false
},
{
name: 'errorCallback',
type: types_.FUNCTION,
- //values: ErrorCallback,
optional: true,
nullable: true
}
]);
- // TODO check if the service is connected and started
- // Raise the exception instead
+ if (!this._isStarted) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Service is not started.');
+ }
var lid = this._serviceId;
this._sendCallback = successCallback;
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
}
});
+
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
common::TizenResult ConvergenceAppCommunicationService::Start(
- ConvergenceChannel *channel,
+ ConvergenceChannel& channel,
const int cur_listener_id) {
ScopeLogger();
conv_service_h service_handle = FindServiceHandle();
if (!service_handle) {
- LoggerE("AAAAAA!!! Service not found");
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
-LoggerI("1");
-
UpdateListener(cur_listener_id);
-LoggerI("2");
-
-
- { // DBG
- conv_channel_h ch = channel->GetHandle();
- char *id = NULL;
- conv_channel_get_string(ch, "channel_id", &id);
- char *uri = NULL;
- conv_channel_get_string(ch, "uri", &uri);
- LoggerI("===== CHANNEL ID [%s] URI [%s]", id, uri);
- }
-
- const int error = conv_service_start(service_handle,
- channel->GetHandle(), nullptr);
+ const int error = conv_service_start(service_handle, channel.GetHandle(), nullptr);
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_service_start");
+ return LogAndCreateTizenError(AbortError, "Failed to start service");
}
-LoggerI("3");
- delete channel;
-LoggerI("4");
return TizenSuccess();
}
common::TizenResult ConvergenceAppCommunicationService::Stop(
- ConvergenceChannel *channel,
+ ConvergenceChannel& channel,
const int cur_listener_id) {
ScopeLogger();
conv_service_h service_handle = FindServiceHandle();
if (!service_handle) {
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
UpdateListener(cur_listener_id);
- const int error = conv_service_stop(service_handle,
- channel->GetHandle(), nullptr);
+ const int error = conv_service_stop(service_handle, channel.GetHandle(), nullptr);
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_service_stop");
+ return LogAndCreateTizenError(AbortError, "Failed to stop service");
}
- delete channel;
return TizenSuccess();
}
common::TizenResult ConvergenceAppCommunicationService::Send(
- ConvergenceChannel *channel,
- ConvergencePayloadArray *payload,
+ ConvergenceChannel& channel,
+ ConvergencePayloadArray& payload,
const int cur_listener_id) {
ScopeLogger();
conv_service_h service_handle = FindServiceHandle();
if (!service_handle) {
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
UpdateListener(cur_listener_id);
- { // DBG
- LoggerI("...PUBLISHING for service handle [0x0%x]", service_handle);
-
- conv_service_e t = CONV_SERVICE_NONE;
- int e = conv_service_get_type(service_handle, &t);
- if (CONV_ERROR_NONE != e) {
- trace_conv_error(e, __LINE__, "get service type");
- }
- LoggerI("....type [%d]", t);
-
- char *sid = nullptr;
- e = conv_service_get_property_string(service_handle, CONV_SERVICE_ID, &sid);
- if (CONV_ERROR_NONE != e) {
- trace_conv_error(e, __LINE__, "get service id");
- }
- LoggerI("....id [%s]", sid);
- free(sid);
-
- conv_channel_h ch = channel->GetHandle();
- char *id = NULL;
- conv_channel_get_string(ch, "channel_id", &id);
- char *uri = NULL;
- conv_channel_get_string(ch, "uri", &uri);
- LoggerI("===== CHANNEL ID [%s] URI [%s]", id, uri);
- }
-
- const int error = conv_service_publish(service_handle,
- channel->GetHandle(), payload->GetHandle());
+ const int error = conv_service_publish(service_handle, channel.GetHandle(), payload.GetHandle());
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_service_publish");
+ return LogAndCreateTizenError(AbortError, "Failed to publish message");
} else {
LoggerI("PUBLISHED SUCCESSFULY listener is [%d]", cur_listener_id);
}
- delete channel;
- delete payload;
return TizenSuccess();
}
-
// TODO move to Payload class
}
common::TizenResult ConvergenceAppCommunicationServerService::Start(
- ConvergenceChannel *channel,
+ ConvergenceChannel& channel,
const int cur_listener_id) {
ScopeLogger();
picojson::object param;
param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
- // The object 'channel' will be deleted in the super::Start() so we should
- // add its json before
- param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle()); // Define string as constant
+ param[kChannel] = ConvergenceChannel::ToJson(channel.GetHandle()); // Define string as constant
param[kServiceResultType] = picojson::value(kServiceResultTypeOnStart);
- common::TizenResult result = ConvergenceAppCommunicationService::Start(
- channel, cur_listener_id);
+ common::TizenResult result = ConvergenceAppCommunicationService::Start(channel, cur_listener_id);
if (!result) {
return result;
}
- convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback,
- cur_listener_id, true, param);
+ convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback, cur_listener_id, true, param);
return result;
}
common::TizenResult ConvergenceAppCommunicationServerService::Stop(
- ConvergenceChannel *channel,
+ ConvergenceChannel& channel,
const int cur_listener_id) {
ScopeLogger();
picojson::object param;
param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusOk);
- // The object 'channel' will be deleted in the super::Start() so we should
- // add its json before
- param[kChannel] = ConvergenceChannel::ToJson(channel->GetHandle());
+ param[kChannel] = ConvergenceChannel::ToJson(channel.GetHandle());
param[kServiceResultType] = picojson::value(kServiceResultTypeOnStop);
- common::TizenResult result = ConvergenceAppCommunicationService::Stop(
- channel, cur_listener_id);
+ common::TizenResult result = ConvergenceAppCommunicationService::Stop(channel, cur_listener_id);
if (!result) {
return result;
}
- convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback,
- cur_listener_id, true, param);
+ convergence_plugin_->ReplyAsync(kAppCommunicationListenerCallback, cur_listener_id, true, param);
return result;
}
ConvergenceAppCommunicationService& operator=(const ConvergenceAppCommunicationService&) = delete;
ConvergenceAppCommunicationService& operator=(ConvergenceAppCommunicationService&&) = delete;
public:
- virtual common::TizenResult Start(ConvergenceChannel *channel,
- const int cur_listener_id);
- virtual common::TizenResult Stop(ConvergenceChannel *channel,
- const int cur_listener_id);
- virtual common::TizenResult Send(ConvergenceChannel *channel,
- ConvergencePayloadArray *payload,
- const int cur_listener_id);
+ virtual common::TizenResult Start(ConvergenceChannel& channel, const int cur_listener_id);
+ virtual common::TizenResult Stop(ConvergenceChannel& channel, const int cur_listener_id);
+ virtual common::TizenResult Send(ConvergenceChannel& channel,
+ ConvergencePayloadArray& payload,
+ const int cur_listener_id);
common::TizenResult SetListener(const int cur_listener_id);
common::TizenResult RemoveListener();
private:
ConvergenceAppCommunicationServerService& operator=(ConvergenceAppCommunicationServerService&&) = delete;
public:
- virtual common::TizenResult Start(ConvergenceChannel *channel,
+ virtual common::TizenResult Start(ConvergenceChannel& channel,
const int cur_listener_id);
- virtual common::TizenResult Stop(ConvergenceChannel *channel,
+ virtual common::TizenResult Stop(ConvergenceChannel& channel,
const int cur_listener_id);
};
result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
} else {
// Running the service start procedure
- result = service->Start(new ConvergenceChannel(ConvergenceUtils::GetArg(args, kJSArgumentChannel)),
- static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>()));
+ ConvergenceChannel channel(ConvergenceUtils::GetArg(args, kJSArgumentChannel));
+ const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
+
+ result = service->Start(channel, id);
}
- this->Post(token, result);
+ //in case of failure call error callback, success callback will be triggered by listener
+ if (!result) {
+ this->Post(token, result);
+ }
};
std::thread(start, token).detach();
result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
} else {
// Running the service send procedure
- result = service->Send(new ConvergenceChannel(ConvergenceUtils::GetArg(args, kJSArgumentChannel)),
- new ConvergencePayloadArray(ConvergenceUtils::GetArg(args, kJSArgumentPayload)),
- static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>()));
+ ConvergenceChannel channel(ConvergenceUtils::GetArg(args, kJSArgumentChannel));
+ ConvergencePayloadArray payload(ConvergenceUtils::GetArg(args, kJSArgumentPayload));
+ const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
+ result = service->Send(channel, payload, id);
}
- this->Post(token, result);
+ //in case of failure call error callback, success callback will be triggered by listener
+ if (!result) {
+ this->Post(token, result);
+ }
};
std::thread(send, token).detach();
result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
} else {
// Running the service stop procedure
- result = service->Stop(new ConvergenceChannel(ConvergenceUtils::GetArg(args, kJSArgumentChannel)),
- static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>()));
+ ConvergenceChannel channel(ConvergenceUtils::GetArg(args, kJSArgumentChannel));
+ const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
+
+ result = service->Stop(channel, id);
}
- this->Post(token, result);
+ //in case of failure call error callback, success callback will be triggered by listener
+ if (!result) {
+ this->Post(token, result);
+ }
};
std::thread(stop, token).detach();