#include <net_connection.h>
+#include "common/tools.h"
#include "common/picojson.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
#include "common/typeutil.h"
#include "common/virtual_fs.h"
std::vector<DownloadInstance*> DownloadInstance::instances_;
std::mutex DownloadInstance::instances_mutex_;
-using common::NotFoundException;
-using common::UnknownException;
-using common::NetworkException;
-using common::SecurityException;
-using common::QuotaExceededException;
-using common::NotSupportedException;
-using common::InvalidStateException;
-using common::IOException;
-using common::InvalidValuesException;
-using common::ServiceNotAvailableException;
-using common::TypeMismatchException;
-
DownloadInstance::DownloadInstance() {
LoggerD("Entered");
using std::placeholders::_1;
DownloadInstance::~DownloadInstance() {
LoggerD("Entered");
int ret;
- for (DownloadCallbackMap::iterator it = downCbMap.begin();
- it != downCbMap.end(); ++it) {
+ for (DownloadCallbackMap::iterator it = download_callbacks.begin();
+ it != download_callbacks.end(); ++it) {
DownloadInfoPtr diPtr = it->second->instance->diMap[it->second->callbackId];
SLoggerD("~DownloadInstance() for callbackID %d Called", it->second->callbackId);
return false;
}
+common::PlatformResult DownloadInstance::convertError(int err) {
+ char* error = get_error_message(err);
+ LoggerE("%s",error);
+ switch (err) {
+ case DOWNLOAD_ERROR_INVALID_PARAMETER:
+ return common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR,
+ error);
+ case DOWNLOAD_ERROR_OUT_OF_MEMORY:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_NETWORK_UNREACHABLE:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_CONNECTION_TIMED_OUT:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_NO_SPACE:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_PERMISSION_DENIED:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_NOT_SUPPORTED:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_INVALID_STATE:
+ return common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR,
+ error);
+ case DOWNLOAD_ERROR_CONNECTION_FAILED:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_INVALID_URL:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_INVALID_DESTINATION:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_QUEUE_FULL:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_ALREADY_COMPLETED:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_FILE_ALREADY_EXISTS:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_CANNOT_RESUME:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_FIELD_NOT_FOUND:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_TOO_MANY_REDIRECTS:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_UNHANDLED_HTTP_CODE:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_REQUEST_TIMEOUT:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_RESPONSE_TIMEOUT:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_SYSTEM_DOWN:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_ID_NOT_FOUND:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_INVALID_NETWORK_TYPE:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_NO_DATA:
+ return common::PlatformResult(
+ common::ErrorCode::UNKNOWN_ERR,
+ error);
+ case DOWNLOAD_ERROR_IO_ERROR:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ error);
+ default:
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR,
+ "Unknown error.");
+ }
+}
+
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) {\
- ReportError(TypeMismatchException(name" is required argument"), out);\
+ ReportError(common::PlatformResult(common::ErrorCode::TYPE_MISMATCH_ERR, name" is required argument"), &out);\
return;\
}
void DownloadInstance::OnStateChanged(int download_id,
download_state_e state, void* user_data) {
LoggerD("Entered");
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
downCbPtr->state = state;
downCbPtr->downloadId = download_id;
gboolean DownloadInstance::OnProgressChanged(void* user_data) {
LoggerD("Entered");
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return FALSE;
picojson::value(static_cast<double>(downCbPtr->received));
out["totalSize"] = picojson::value(static_cast<double>(diPtr->file_size));
- SLoggerD("OnProgressChanged for callbackId %d Called: Received: %ld",
+ LoggerD("OnProgressChanged for callbackId %d Called: Received: %ld",
downCbPtr->callbackId, downCbPtr->received);
picojson::value v = picojson::value(out);
LoggerD("Entered");
unsigned long long totalSize;
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return;
LoggerD("Entered");
char* fullPath = NULL;
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return FALSE;
}
- DownloadInfoPtr diPtr = downCbPtr->instance->diMap[downCbPtr->callbackId];
+ int callback_id = downCbPtr->callbackId;
+ DownloadInfoPtr diPtr = downCbPtr->instance->diMap[callback_id];
- SLoggerD("OnFinished for callbackID %d Called", downCbPtr->callbackId);
+ LoggerD("OnFinished for callbackID %d Called", callback_id);
- download_get_downloaded_file_path(downCbPtr->downloadId, &fullPath);
+ picojson::value::object out;
- download_unset_state_changed_cb(diPtr->download_id);
- download_unset_progress_cb(diPtr->download_id);
- download_destroy(diPtr->download_id);
+ int ret = download_get_downloaded_file_path(downCbPtr->downloadId, &fullPath);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ common::tools::ReportError(convertError(ret), &out);
+ } else {
+ ret = download_unset_state_changed_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerW("%s", get_error_message(ret));
+ }
+ ret = download_unset_progress_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerW("%s", get_error_message(ret));
+ }
+ ret = download_destroy(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerW("%s", get_error_message(ret));
+ }
+ out["status"] = picojson::value("completed");
+ }
- picojson::value::object out;
- out["status"] = picojson::value("completed");
- out["callbackId"] =
- picojson::value(static_cast<double>(downCbPtr->callbackId));
+ out["callbackId"] = picojson::value(static_cast<double>(callback_id));
out["fullPath"] = picojson::value(common::VirtualFs::GetInstance().GetVirtualPath(fullPath));
Instance::PostMessage(downCbPtr->instance, picojson::value(out).serialize().c_str());
- downCbPtr->instance->downCbMap.erase(downCbPtr->callbackId);
+ downCbPtr->instance->download_callbacks.erase(callback_id);
delete (downCbPtr);
free(fullPath);
gboolean DownloadInstance::OnPaused(void* user_data) {
LoggerD("Entered");
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return FALSE;
}
- DownloadInfoPtr diPtr = downCbPtr->instance->diMap[downCbPtr->callbackId];
+ int callback_id = downCbPtr->callbackId;
+ DownloadInfoPtr diPtr = downCbPtr->instance->diMap[callback_id];
- SLoggerD("OnPaused for callbackID %d Called", downCbPtr->callbackId);
+ LoggerD("OnPaused for callbackID %d Called", callback_id);
picojson::value::object out;
out["status"] = picojson::value("paused");
out["callbackId"] =
- picojson::value(static_cast<double>(downCbPtr->callbackId));
+ picojson::value(static_cast<double>(callback_id));
Instance::PostMessage(downCbPtr->instance, picojson::value(out).serialize().c_str());
return FALSE;
gboolean DownloadInstance::OnCanceled(void* user_data) {
LoggerD("Entered");
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return FALSE;
}
- DownloadInfoPtr diPtr = downCbPtr->instance->diMap[downCbPtr->callbackId];
+ int callback_id = downCbPtr->callbackId;
+ DownloadInfoPtr diPtr = downCbPtr->instance->diMap[callback_id];
+
+ LoggerD("OnCanceled for callbackID %d Called", callback_id);
- SLoggerD("OnCanceled for callbackID %d Called", downCbPtr->callbackId);
+ int ret = download_unset_state_changed_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ }
+
+ ret = download_unset_progress_cb(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ }
- download_unset_state_changed_cb(diPtr->download_id);
- download_unset_progress_cb(diPtr->download_id);
- download_destroy(diPtr->download_id);
+ ret = download_destroy(diPtr->download_id);
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ }
picojson::value::object out;
out["status"] = picojson::value("canceled");
out["callbackId"] =
- picojson::value(static_cast<double>(downCbPtr->callbackId));
+ picojson::value(static_cast<double>(callback_id));
Instance::PostMessage(downCbPtr->instance, picojson::value(out).serialize().c_str());
- downCbPtr->instance->downCbMap.erase(downCbPtr->callbackId);
+ downCbPtr->instance->download_callbacks.erase(callback_id);
delete (downCbPtr);
return FALSE;
download_error_e error;
picojson::object out;
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
std::lock_guard<std::mutex> lock(instances_mutex_);
if (!CheckInstance(downCbPtr->instance)) {
return FALSE;
DownloadInstance* instance = downCbPtr->instance;
- SLoggerD("OnFailed for callbackID %d Called", downCbPtr->callbackId);
+ LoggerD("OnFailed for callbackID %d Called", downCbPtr->callbackId);
download_get_error(downCbPtr->downloadId, &error);
- switch (error) {
- case DOWNLOAD_ERROR_INVALID_PARAMETER:
- instance->ReportError(NotFoundException("not found"), out);
- break;
- case DOWNLOAD_ERROR_OUT_OF_MEMORY:
- instance->ReportError(UnknownException("Out of memory"), out);
- break;
- case DOWNLOAD_ERROR_NETWORK_UNREACHABLE:
- instance->ReportError(NetworkException("Network is unreachable"), out);
- break;
- case DOWNLOAD_ERROR_CONNECTION_TIMED_OUT:
- instance->ReportError(NetworkException("HTTP session timeout"), out);
- break;
- case DOWNLOAD_ERROR_NO_SPACE:
- instance->ReportError(QuotaExceededException(
- "No space left on device"), out);
- break;
- case DOWNLOAD_ERROR_PERMISSION_DENIED:
- instance->ReportError(SecurityException(
- "The application does not have the privilege to call this method."),
- out);
- break;
- case DOWNLOAD_ERROR_NOT_SUPPORTED:
- instance->ReportError(NotSupportedException("Not supported"), out);
- break;
- case DOWNLOAD_ERROR_INVALID_STATE:
- instance->ReportError(InvalidStateException("Invalid state"), out);
- break;
- case DOWNLOAD_ERROR_CONNECTION_FAILED:
- instance->ReportError(NetworkException("Connection failed"), out);
- break;
- case DOWNLOAD_ERROR_INVALID_URL:
- instance->ReportError(InvalidValuesException("Invalid URL"), out);
- break;
- case DOWNLOAD_ERROR_INVALID_DESTINATION:
- instance->ReportError(InvalidValuesException(
- "Invalid destination"), out);
- break;
- case DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS:
- instance->ReportError(QuotaExceededException(
- "Too many simultaneous downloads"), out);
- break;
- case DOWNLOAD_ERROR_QUEUE_FULL:
- instance->ReportError(QuotaExceededException(
- "Download server queue is full"), out);
- break;
- case DOWNLOAD_ERROR_ALREADY_COMPLETED:
- instance->ReportError(InvalidStateException(
- "The download is already completed"), out);
- break;
- case DOWNLOAD_ERROR_FILE_ALREADY_EXISTS:
- instance->ReportError(IOException(
- "Failed to rename the downloaded file"), out);
- break;
- case DOWNLOAD_ERROR_CANNOT_RESUME:
- instance->ReportError(NotSupportedException("Cannot resume"), out);
- break;
- case DOWNLOAD_ERROR_FIELD_NOT_FOUND:
- instance->ReportError(NotFoundException(
- "Specified field not found"), out);
- break;
- case DOWNLOAD_ERROR_TOO_MANY_REDIRECTS:
- instance->ReportError(NetworkException(
- "Too many redirects from HTTP response header"), out);
- break;
- case DOWNLOAD_ERROR_UNHANDLED_HTTP_CODE:
- instance->ReportError(NetworkException(
- "The download cannot handle the HTTP status value"), out);
- break;
- case DOWNLOAD_ERROR_REQUEST_TIMEOUT:
- instance->ReportError(NetworkException(
- "No action after client creates a download ID"), out);
- break;
- case DOWNLOAD_ERROR_RESPONSE_TIMEOUT:
- instance->ReportError(NetworkException(
- "No call to start API for some time although the download is created"),
- out);
- break;
- case DOWNLOAD_ERROR_SYSTEM_DOWN:
- instance->ReportError(ServiceNotAvailableException(
- "No response from client after rebooting download daemon"), out);
- break;
- case DOWNLOAD_ERROR_ID_NOT_FOUND:
- instance->ReportError(NotFoundException(
- "Download ID does not exist in download service module"), out);
- break;
- case DOWNLOAD_ERROR_INVALID_NETWORK_TYPE:
- instance->ReportError(InvalidValuesException(
- "Network bonding is set but network type is not set as ALL"), out);
- break;
- case DOWNLOAD_ERROR_NO_DATA:
- instance->ReportError(NotFoundException(
- "No data because the set API is not called"), out);
- break;
- case DOWNLOAD_ERROR_IO_ERROR:
- instance->ReportError(IOException("Internal I/O error"), out);
- break;
- case DOWNLOAD_ERROR_NONE:
- break;
+ if (DOWNLOAD_ERROR_NONE != error) {
+ common::tools::ReportError(convertError(error), &out);
}
out["callbackId"] =
void DownloadInstance::progress_changed_cb
(int download_id, long long unsigned received, void* user_data) {
LoggerD("Entered");
- DownloadCallback* downCbPtr = static_cast<DownloadCallback*>(user_data);
+ CallbackPtr downCbPtr = static_cast<CallbackPtr>(user_data);
downCbPtr->received = received;
downCbPtr->downloadId = download_id;
} else {
LoggerE("The input parameter contains an invalid network type");
ReportError(
- InvalidValuesException(
- "The input parameter contains an invalid network type."),
- out);
+ common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR,
+ "The input parameter contains an invalid network type."),
+ &out);
return;
}
if (!network_support) {
- SLoggerE("Requested network type (%s) is not supported.", networkType.c_str());
- LoggerE("Requested network type is not supported");
+ LoggerE("Requested network type (%s) is not supported.", networkType.c_str());
ReportError(
common::PlatformResult(common::ErrorCode::NOT_SUPPORTED_ERR,
"The networkType of the given DownloadRequest "
}
if (!network_available) {
- SLoggerE("Requested network type (%s) is not available.", networkType.c_str());
- LoggerE("Requested network type is not available");
+ LoggerE("Requested network type (%s) is not available.", networkType.c_str());
ReportError(
common::PlatformResult(common::ErrorCode::NETWORK_ERR,
"The networkType of the given DownloadRequest "
return;
}
- DownloadCallback* downCbPtr(new DownloadCallback);
+ CallbackPtr downCbPtr(new DownloadCallback);
downCbPtr->callbackId = diPtr->callbackId;
downCbPtr->instance = this;
- downCbMap[downCbPtr->callbackId] = downCbPtr;
+ download_callbacks[downCbPtr->callbackId] = downCbPtr;
ret = download_create(&diPtr->download_id);
- ret =
- download_set_state_changed_cb
- (diPtr->download_id, OnStateChanged, static_cast<void*>(downCbPtr));
- ret =
- download_set_progress_cb
- (diPtr->download_id, progress_changed_cb, static_cast<void*>(downCbPtr));
- ret =
- download_set_url(diPtr->download_id, diPtr->url.c_str());
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
+
+ ret = download_set_state_changed_cb (diPtr->download_id, OnStateChanged,
+ static_cast<void*>(downCbPtr));
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
+
+ ret = download_set_progress_cb (diPtr->download_id, progress_changed_cb,
+ static_cast<void*>(downCbPtr));
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
+
+ ret = download_set_url(diPtr->download_id, diPtr->url.c_str());
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
if (diPtr->destination.size() != 0) {
ret = download_set_destination(diPtr->download_id, diPtr->destination.c_str());
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
}
if (!diPtr->file_name.empty()) {
ret = download_set_file_name(diPtr->download_id, diPtr->file_name.c_str());
+ if (ret != DOWNLOAD_ERROR_NONE) {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ return;
+ }
}
ret = download_set_network_type(diPtr->download_id, diPtr->network_type);
ret = download_start(diPtr->download_id);
- if (ret == DOWNLOAD_ERROR_NONE)
+ if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(out);
- else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER)
- ReportError(InvalidValuesException
- ("The input parameter contains an invalid value."), out);
- else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY)
- ReportError(UnknownException("Out of memory"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_STATE)
- ReportError(InvalidValuesException("Invalid state"), out);
- else if (ret == DOWNLOAD_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_URL)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid url."), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_DESTINATION)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid destination."), out);
- else if (ret == DOWNLOAD_ERROR_ID_NOT_FOUND)
- ReportError(InvalidValuesException("No such a download ID found"), out);
- else if (ret == DOWNLOAD_ERROR_QUEUE_FULL)
- ReportError(UnknownException("Download server queue is full"), out);
- else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED)
- ReportError(SecurityException(
- "The application does not have the privilege to call this method."), out);
- else
- ReportError(UnknownException("Unknown Error"), out);
+ } else {
+ LoggerE("%s", get_error_message(ret));
+ common::tools::ReportError(convertError(ret), &out);
+ }
}
void DownloadInstance::DownloadManagerCancel
if (!GetDownloadID(callbackId, downloadId)) {
LoggerE("The identifier does not match any download operation in progress");
- ReportError(NotFoundException
- ("The identifier does not match any download operation in progress"),
- out);
+ ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ "The identifier does not match any download operation in progress"),
+ &out);
return;
}
ret = download_cancel(downloadId);
- if (ret == DOWNLOAD_ERROR_NONE)
+ if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(out);
- else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER)
- ReportError(InvalidValuesException
- ("The input parameter contains an invalid value."), out);
- else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY)
- ReportError(UnknownException("Out of memory"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_STATE)
- ReportError(InvalidValuesException("Invalid state"), out);
- else if (ret == DOWNLOAD_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error"), out);
- else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED)
- ReportError(UnknownException("Permission denied"), out);
- else
- ReportError(UnknownException("Unknown Error"), out);
+ } else {
+ common::tools::ReportError(convertError(ret), &out);
+ }
}
void DownloadInstance::DownloadManagerPause
if (!GetDownloadID(callbackId, downloadId)) {
LoggerE("The identifier does not match any download operation in progress");
- ReportError(NotFoundException(
+ ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
"The identifier does not match any download operation in progress"),
- out);
+ &out);
return;
}
ret = download_pause(downloadId);
- if (ret == DOWNLOAD_ERROR_NONE)
+ if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(out);
- else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid value."), out);
- else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY)
- ReportError(UnknownException("Out of memory"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_STATE)
- ReportError(InvalidValuesException("Invalid state"), out);
- else if (ret == DOWNLOAD_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error"), out);
- else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED)
- ReportError(UnknownException("Permission denied"), out);
- else
- ReportError(UnknownException("Unknown Error"), out);
+ } else {
+ common::tools::ReportError(convertError(ret), &out);
+ }
}
void DownloadInstance::DownloadManagerResume
int callbackId = static_cast<int>(args.get("downloadId").get<double>());
if (!GetDownloadID(callbackId, downloadId)) {
- ReportError(NotFoundException
- ("The identifier does not match any download operation in progress"),
- out);
+ ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ "The identifier does not match any download operation in progress"),
+ &out);
return;
}
ret = download_start(downloadId);
- if (ret == DOWNLOAD_ERROR_NONE)
+ if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(out);
- else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid value."), out);
- else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY)
- ReportError(UnknownException("Out of memory"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_STATE)
- ReportError(InvalidValuesException("Invalid state"), out);
- else if (ret == DOWNLOAD_ERROR_IO_ERROR)
- ReportError(UnknownException("Internal I/O error"), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_URL)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid url."), out);
- else if (ret == DOWNLOAD_ERROR_INVALID_DESTINATION)
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid destination."), out);
- else if (ret == DOWNLOAD_ERROR_ID_NOT_FOUND)
- ReportError(InvalidValuesException("No such a download ID found"), out);
- else if (ret == DOWNLOAD_ERROR_QUEUE_FULL)
- ReportError(UnknownException("Download server queue is full"), out);
- else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED)
- ReportError(SecurityException(
- "Application does not have the privilege to call this method."), out);
- else
- ReportError(UnknownException("Unknown Error"), out);
+ } else {
+ common::tools::ReportError(convertError(ret), &out);
+ }
}
+
void DownloadInstance::DownloadManagerGetstate
(const picojson::value& args, picojson::object& out) {
LoggerD("Entered");
if (!GetDownloadID(callbackId, downloadId)) {
LoggerE("The identifier does not match any download operation in progress");
- ReportError(NotFoundException
- ("The identifier does not match any download operation in progress"),
- out);
+ ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ "The identifier does not match any download operation in progress"),
+ &out);
return;
}
}
ReportSuccess(picojson::value(stateValue), out);
- } else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER) {
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid value."), out);
- } else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY) {
- ReportError(UnknownException("Out of memory"), out);
- } else if (ret == DOWNLOAD_ERROR_INVALID_STATE) {
- ReportError(InvalidValuesException("Invalid state"), out);
- } else if (ret == DOWNLOAD_ERROR_IO_ERROR) {
- ReportError(UnknownException("Internal I/O error"), out);
- } else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED) {
- ReportError(UnknownException("Permission denied"), out);
} else {
- ReportError(UnknownException("Unknown Error"), out);
+ common::tools::ReportError(convertError(ret), &out);
}
}
int callbackId = static_cast<int>(args.get("downloadId").get<double>());
if (!GetDownloadID(callbackId, downloadId)) {
- ReportError(NotFoundException
- ("The identifier does not match any download operation in progress"),
- out);
+ ReportError(common::PlatformResult(common::ErrorCode::NOT_FOUND_ERR,
+ "The identifier does not match any download operation in progress"),
+ &out);
return;
}
if (ret == DOWNLOAD_ERROR_NONE) {
ReportSuccess(picojson::value(mimetype), out);
- } else if (ret == DOWNLOAD_ERROR_INVALID_PARAMETER) {
- ReportError(InvalidValuesException(
- "The input parameter contains an invalid value."), out);
- } else if (ret == DOWNLOAD_ERROR_OUT_OF_MEMORY) {
- ReportError(UnknownException("Out of memory"), out);
- } else if (ret == DOWNLOAD_ERROR_INVALID_STATE) {
- ReportError(InvalidValuesException("Invalid state"), out);
- } else if (ret == DOWNLOAD_ERROR_IO_ERROR) {
- ReportError(UnknownException("Internal I/O error"), out);
- } else if (ret == DOWNLOAD_ERROR_PERMISSION_DENIED) {
- ReportError(UnknownException("Permission denied"), out);
} else {
- ReportError(UnknownException("Unknown Error"), out);
+ common::tools::ReportError(convertError(ret), &out);
}
free(mimetype);
}