console.log('Entered ConvergenceManager.startDiscovery()');
if (discoveryStarted)
- throw new WebAPIException('InvalidStateError', 'Discovery has been started.');
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has been started.');
var args = validator_.validateArgs(arguments, [
{name: 'successCallback', type: types_.LISTENER, values: ['onfound', 'onfinished' ]},
]);
// Indicate, that discovery procedure is on
+ if (discoveryStarted === true)
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has already started.');
+
discoveryStarted = true;
// Reset currently available device list
native_.callIfPossible(successCallback.onfound, d);
} else if (result.discovery_status == 'discovery_finished') {
+
+ discoveryStarted = false;
+
// Unregister discovery listener, because Convergence Manager is a
// singleton object and no one else can receive discovery results
native_.removeListener('CONVERGENCE_DISCOVERY_LISTENER');
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
}
});
+
if (native_.isFailure(result)) {
+ discoveryStarted = false;
throw native_.getErrorObject(result);
}
};
ConvergenceManager.prototype.stopDiscovery = function() {
console.log('Entered ConvergenceManager.stopDiscovery()');
- if (!discoveryStarted)
- throw new WebAPIException('InvalidStateError', 'Discovery has not started yet.');
+ if (discoveryStarted === false)
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Discovery has not started yet.');
discoveryStarted = false;
}
]);
- if (this.connectionState == ConnectionState.CONNECTED) {
+ if (this.connectionState === ConnectionState.CONNECTED) {
throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.');
}
if (native_.isFailure(result))
native_.callIfPossible(errorCallback, native_.getErrorObject(result));
});
+
if (native_.isFailure(result))
throw native_.getErrorObject(result);
};
}
]);
- if (this.connectionState != ConnectionState.CONNECTED) {
+ if (this.connectionState !== ConnectionState.CONNECTED) {
throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
}
nullable: true
}]);
-/*
- if (this.serviceState == ConnectionState.CONNECTED)
- throw new WebAPIException('InvalidStateError', 'Service is connected already.');
-*/
+
+ if (this.connectionState === ConnectionState.NOT_CONNECTED) {
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
+ }
var lid = this._serviceId;
this._startCallback = args.successCallback;
deviceId: this._deviceId,
curListenerId: lid
});
+
if (native_.isFailure(result))
throw native_.getErrorObject(result);
deviceId: this._deviceId
//curListenerId: id // not needed in below layers
});
+
if (native_.isFailure(result))
throw native_.getErrorObject(result);
]);
if (this.connectionState == ConnectionState.CONNECTED)
- throw new WebAPIException('InvalidStateError', 'Service is connected already.');
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is connected already.');
var lid = this._serviceId;
this._connectCallback = successCallback;
}
]);
if (this.connectionState != ConnectionState.CONNECTED)
- throw new WebAPIException('InvalidStateError', 'Service is not connected yet.');
+ throw new WebAPIException(WebAPIException.INVALID_STATE_ERR, 'Service is not connected yet.');
var result = native_.call('AppCommunicationClientService_disconnect', {
deviceId: this._deviceId
const int error = conv_service_start(service_handle, channel->GetHandle(), nullptr);
if (CONV_ERROR_NONE != error) {
- return LogAndCreateTizenError(AbortError, "Failed to start service");
+ return LogAndCreateTizenError(AbortError, "conv_service_start [fail]");
}
opened_channels.push_back(ch_ptr.release());
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_publish(service_handle, channel->GetHandle(), payload.GetHandle());
if (CONV_ERROR_NONE != error) {
- return LogAndCreateTizenError(AbortError, "Failed to publish message");
+ return LogAndCreateTizenError(AbortError, "conv_service_publish [fail]");
} else {
LoggerI("PUBLISHED SUCCESSFULY listener is [%d]", cur_listener_id);
}
if (CONV_ERROR_NONE != error) { // Error occured during connection
picojson::object param;
- param[kServiceListenerStatus] = picojson::value(kServiceListenerStatusError);
- param[kServiceListenerError] = picojson::value(static_cast<double>(error));
+ param[kServiceListenerError] = LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR").ToJSON();
callbackParam->plugin_->ReplyAsync(kAppCommunicationListenerCallback,
callbackParam->callback_id_, false, param);
return;
common::TizenResult ConvergenceAppCommunicationService::SetListener(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");
+ if (!service_handle) {
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
+ }
UpdateListener(cur_listener_id);
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");
}
const int error = conv_service_unset_listener_cb(service_handle);
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_service_set_listener_cb");
- return LogAndCreateTizenError(NotFoundError,
- "Unset Listener Failed");
+ return LogAndCreateTizenError(AbortError, "conv_service_unset_listener_cb [Fail]");
}
return TizenSuccess();
conv_service_h service = FindServiceHandle();
if (!service) {
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service is NULL");
}
// TODO: make a garbage collection and release this memory when service is disconnected
if (CONV_ERROR_NONE != error) {
// TODO: Handle error
trace_conv_error(error, __LINE__, "conv_service_connect");
+ return LogAndCreateTizenError(AbortError, "conv_service_connect [fail]");
}
return TizenSuccess();
conv_service_h service = FindServiceHandle();
if (!service)
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service is NULL");
const int error = conv_service_disconnect(service);
if (CONV_ERROR_NONE != error) {
// TODO: Handle error
trace_conv_error(error, __LINE__, "conv_service_disconnect");
+ return LogAndCreateTizenError(AbortError, "conv_service_disconnect [fail]");
}
return TizenSuccess();
} // namespace convergence
-} // namespace extension
+} // namespace extension
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
// Running the service connect procedure
result = service->Connect(static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>()));
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
result = service->Disconnect();
}
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
// Running the service start procedure
result = service->Start(static_cast<bool>(ConvergenceUtils::GetArg(args, kJSArgumentReply).get<bool>()),
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
// Running the service stop procedure
result = service->Stop(static_cast<bool>(ConvergenceUtils::GetArg(args, kJSArgumentReply).get<bool>()),
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
result = service->Launch(
ConvergenceUtils::GetArg(args, kJSArgumentAppId).to_str().c_str(),
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_REMOTE_APP_CONTROL));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
result = service->LaunchAppControl(ConvergenceUtils::GetArg(args, kJSArgumentAppControl).get<picojson::object>(),
ConvergenceUtils::GetArg(args, kJSArgumentAppId).to_str().c_str(),
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Service is NULL",
+ ("Service is NULL"));
} else {
// Running the service start procedure
auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel);
std::vector<ConvergenceChannel*>::iterator channel_it = service->GetChannel(channel_arg);
if (service->IsChannelStarted(channel_it)) {
- result = LogAndCreateTizenError(InvalidStateError, "Service is already started for the channel.");
+ result = LogAndCreateTizenError(InvalidStateError, "Service is already started for the channel.",
+ ("Service is already started for the channel."));
} else {
ConvergenceChannel* channel = new ConvergenceChannel(channel_arg); // memory would be managed in Start method
const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "service is NULL",
+ ("service is NULL"));
} else {
// Running the service send procedure
auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel);
std::vector<ConvergenceChannel*>::iterator channel_it = service->GetChannel(channel_arg);
if (!service->IsChannelStarted(channel_it)) {
- result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.");
+ result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.",
+ ("Service is not started for the channel."));
} else {
ConvergencePayloadArray payload(ConvergenceUtils::GetArg(args, kJSArgumentPayload));
const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Service is NULL",
+ ("Service is NULL"));
} else {
// Running the service stop procedure
auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel);
std::vector<ConvergenceChannel*>::iterator channel_it = service->GetChannel(channel_arg);
if (!service->IsChannelStarted(channel_it)) {
- result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.");
+ result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.",
+ ("Service is not started for the channel."));
} else {
const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
} else {
// Running the service getClientList procedure
auto channel_arg = ConvergenceUtils::GetArg(args, kJSArgumentChannel);
std::vector<ConvergenceChannel*>::iterator channel_it = service->GetChannel(channel_arg);
if (!service->IsChannelStarted(channel_it)) {
- result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.");
+ result = LogAndCreateTizenError(InvalidStateError, "Service is not started for the channel.",
+ ("Service is not started for the channel."));
} else {
const int id = static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>());
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1"));
+ return LogAndCreateTizenError(AbortError, "service is NULL",
+ ("service is NULL"));
}
// Running the service stop procedure
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1"));
+ return LogAndCreateTizenError(AbortError, "service is NULL",
+ ("service is NULL"));
}
// Running the service stop procedure
ConvergenceManager::GetInstance(this).RegisterLocalService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- LogAndReturnTizenError(common::NotFoundError("Can not find the service type = 1"));
+ return LogAndCreateTizenError(AbortError, "Can not find the service type = 1",
+ ("Can not find the service type = 1"));
}
return common::TizenSuccess();
common::TizenResult ConvergenceInstance::AppCommunicationClientServiceConnect(const picojson::object& args,
const common::AsyncToken& token) {
ScopeLogger();
+
+ // [TK] SecurityError
CHECK_PRIVILEGE(kPrivilegeInternet);
CHECK_PRIVILEGE(kPrivilegeBluetooth);
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Service is NULL",
+ ("service is NULL"));
} else {
// Running the service connect procedure
result = service->Connect(static_cast<int>(ConvergenceUtils::GetArg(args, kJSCurrentListenerId).get<double>()));
ConvergenceManager::GetInstance(this).GetService(ConvergenceUtils::GetArg(args, kJSArgumentDeviceId).to_str().c_str(),
CONV_SERVICE_APP_TO_APP_COMMUNICATION));
if (!service) {
- result = LogAndCreateTizenError(NotFoundError, "Can not find the service type = 1");
+ result = LogAndCreateTizenError(AbortError, "Service is NULL",
+ ("Service is NULL"));
} else {
// Running the service disconnect procedure
result = service->Disconnect();
static const std::string kDiscoveryStatusDeviceFound = "device_found";
static const std::string kDiscoveryStatusFinished = "discovery_finished";
static const std::string kDiscoveryStatusError = "discovery_error";
-static const std::string kDiscoveryError = "discovery_error";
+static const std::string kDiscoveryError = "error";
} // namespace
case CONV_DISCOVERY_RESULT_ERROR: {
LoggerE("Discovery Error");
picojson::object param;
- param[kDiscoveryStatus] = picojson::value(kDiscoveryStatusError);
- param[kDiscoveryError] = picojson::value(static_cast<double>(result));
+ param[kDiscoveryError] = LogAndCreateTizenError(AbortError, "DiscoveryCb return CONV_DISCOVERY_RESULT_ERROR").ToJSON();
owner->convergence_plugin_->ReplyAsync(kConvergenceManagerDiscoveryCallback,
-1,
false,
const int error = conv_discovery_start(convergence_manager_,
(const int)timeout, DiscoveryCb, this);
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_discovery_start");
+ return LogAndCreateTizenError(AbortError, "conv_discovery_start [fail]");
}
return TizenSuccess();
}
ScopeLogger();
const int error = conv_discovery_stop(convergence_manager_);
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_discovery_stop");
+ return LogAndCreateTizenError(AbortError, "conv_discovery_stop [fail]");
}
return TizenSuccess();
}
conv_service_h service = FindServiceHandle();
if (!service) {
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
CallbackParam *param = new CallbackParam(convergence_plugin_, cur_listener_id);
const int error = conv_service_connect(service, ServiceConnectedCb, param);
-
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
delete param;
- trace_conv_error(error, __LINE__, "conv_service_connect");
+ return LogAndCreateTizenError(AbortError, "conv_service_connect [Fail]");
} else {
// Hopefully we are sure that the service is disconnected
connect_callback_param_ = param;
conv_service_h service = FindServiceHandle();
if (!service)
- return LogAndCreateTizenError(NotFoundError,
- "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
const int error = conv_service_disconnect(service);
-
if (CONV_ERROR_NONE != error) {
- // TODO: Handle error
- trace_conv_error(error, __LINE__, "conv_service_disconnect");
+ return LogAndCreateTizenError(AbortError, "conv_service_disconnect [Fail]");
} else {
delete connect_callback_param_;
connect_callback_param_ = nullptr;
conv_service_h service = FindServiceHandle();
if (!service) {
- return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
if (reply) {
conv_service_h service = FindServiceHandle();
if (!service) {
- return LogAndCreateTizenError(NotFoundError, "Service with specified type does not exist");
+ return LogAndCreateTizenError(AbortError, "Service with specified type does not exist");
}
if (reply) {
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");
}
int ret = conv_payload_create(&payload);
// Get service_handle
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");
}
// Create payload
}
}
+common::TizenResult ConvergenceUtils::ConvertConvergenceError(int error) {
+ switch (error) {
+ case CONV_ERROR_NONE:
+ return common::TizenSuccess();
+ case CONV_ERROR_INVALID_OPERATION:
+ case CONV_ERROR_PERMISSION_DENIED: // Never return
+ case CONV_ERROR_NOT_SUPPORTED: // Never return
+ case CONV_ERROR_INVALID_PARAMETER: // Never return
+ return common::InvalidStateError(error);
+ case CONV_ERROR_OUT_OF_MEMORY:
+ case CONV_ERROR_NO_DATA:
+
+ // return common::IoError(error);
+ // return common::SecurityError(error);
+ // return common::NotSupportedError(error);
+ // return common::InvalidValuesError(error);
+ // return common::TimeoutError(error);
+ // return common::TypeMismatchError(error);
+ // return common::InvalidStateError(error);
+ return common::AbortError(error);
+ }
+}
+
} // namespace convergence
-} // namespace extension
+} // namespace extension
\ No newline at end of file
static const std::string kServiceListenerStatus = "listener_status";
static const std::string kServiceListenerStatusOk = "listener_ok";
static const std::string kServiceListenerStatusError = "listener_error";
-static const std::string kServiceListenerError = "listener_error";
+static const std::string kServiceListenerError = "error";
} // namespace
struct CallbackParam {
class ConvergenceUtils {
public:
static const picojson::value& GetArg(const picojson::object& args, const std::string& name);
+ static common::TizenResult ConvertConvergenceError(int error);
};
} // namespace convergence