#include "common/extension.h"
#include "common/logger.h"
#include "common/picojson.h"
-#include "tizen/tizen.h"
+
+#include "common/platform_result.h"
+
+using common::ErrorCode;
namespace extension {
namespace application {
const picojson::value& Application::Value() {
if (!app_info_->IsValid()) {
- LoggerD("WebApiAPIErrors::UNKNOWN_ERR");
+ LoggerD("ErrorCode::UNKNOWN_ERR");
picojson::object obj;
- obj["error"] =
- picojson::value(static_cast<double>(WebApiAPIErrors::UNKNOWN_ERR));
+ obj["error"] = picojson::value(static_cast<double>(ErrorCode::UNKNOWN_ERR));
value_ = picojson::value(obj);
} else {
picojson::object obj;
return value_;
}
-
} // namespace application
} // namespace extension
'callback_user_data.h',
#'multi_callback_user_data.cc',
#'multi_callback_user_data.h',
+ 'platform_result.cc',
+ 'platform_result.h'
],
'cflags': [
'-std=c++0x',
#include <string>
#include <map>
+#include "common/logger.h"
+
namespace {
common::Extension* g_extension = NULL;
tools::ReportError(ex, out);
}
+void ParsedInstance::ReportError(const PlatformResult& error, picojson::object* out) {
+ tools::ReportError(error, out);
+}
+
void ParsedInstance::HandleMessage(const char* msg) {
HandleMessage(msg, false);
}
SendSyncReply(result.serialize().c_str());
}
+void ParsedInstance::HandleError(const PlatformResult& e) {
+ LoggerE("Error: %s", static_cast<int>(e.error_code()));
+ picojson::value result = picojson::value(picojson::object());
+ ReportError(e, &result.get<picojson::object>());
+ SendSyncReply(result.serialize().c_str());
+}
+
namespace tools {
void ReportSuccess(picojson::object& out) {
out.insert(std::make_pair("status", picojson::value("success")));
out.insert(std::make_pair("status", picojson::value("error")));
out.insert(std::make_pair("error", ex.ToJSON()));
}
+
+void ReportError(const PlatformResult& error, picojson::object* out) {
+ out->insert(std::make_pair("status", picojson::value("error")));
+ out->insert(std::make_pair("error", error.ToJSON()));
+}
} // namespace tools
} // namespace common
#include <map>
#include <functional>
+#include "common/platform_exception.h"
+#include "common/platform_result.h"
#include "common/XW_Extension.h"
#include "common/XW_Extension_EntryPoints.h"
#include "common/XW_Extension_Permissions.h"
#include "common/XW_Extension_Runtime.h"
#include "common/XW_Extension_SyncMessage.h"
-#include "common/platform_exception.h"
namespace common {
void ReportSuccess(const picojson::value& result, picojson::object& out);
void ReportError(picojson::object& out);
void ReportError(const PlatformException& ex, picojson::object& out);
+ void ReportError(const PlatformResult& error, picojson::object* out);
private:
void HandleMessage(const char* msg);
void HandleMessage(const char* msg, bool is_sync);
void HandleException(const PlatformException& ex);
+ void HandleError(const PlatformResult& error);
std::map<std::string, NativeHandler> handler_map_;
};
void ReportSuccess(const picojson::value& result, picojson::object& out);
void ReportError(picojson::object& out);
void ReportError(const PlatformException& ex, picojson::object& out);
+void ReportError(const PlatformResult& error, picojson::object* out);
} // namespace tools
} // namespace common
--- /dev/null
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "common/platform_result.h"
+
+namespace common {
+
+PlatformResult::PlatformResult(const ErrorCode& error_code,
+ const std::string& message)
+ : error_code_(error_code), message_(message) {
+}
+
+picojson::value PlatformResult::ToJSON() const {
+ picojson::value::object obj;
+ obj["code"] = picojson::value(static_cast<double>(error_code_));
+ if (!message_.empty())
+ obj["message"] = picojson::value(message_);
+ picojson::value ret(obj);
+ return ret;
+}
+
+} // namespace common
+
+
--- /dev/null
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SRC_COMMON_PLATFORM_RESULT_H_
+#define SRC_COMMON_PLATFORM_RESULT_H_
+
+#include <string>
+
+#include "common/picojson.h"
+
+namespace common {
+
+// WARNING! This list should be in sync with the equivalent list
+// located at tizen/tizen_api.js. Remember to update tizen/tizen_api.js if you
+// change something here.
+enum class ErrorCode : int {
+ // NO_ERROR is not really a valid error, but can be used
+ // to indicate that no error occoured instead of having an
+ // extra field in the message protocol just for that.
+ NO_ERROR = 0,
+
+ INDEX_SIZE_ERR = 1,
+ DOMSTRING_SIZE_ERR = 2,
+ HIERARCHY_REQUEST_ERR = 3,
+ WRONG_DOCUMENT_ERR = 4,
+ INVALID_CHARACTER_ERR = 5,
+ NO_DATA_ALLOWED_ERR = 6,
+ NO_MODIFICATION_ALLOWED_ERR = 7,
+ NOT_FOUND_ERR = 8,
+ NOT_SUPPORTED_ERR = 9,
+ INUSE_ATTRIBUTE_ERR = 10,
+ INVALID_STATE_ERR = 11,
+ SYNTAX_ERR = 12,
+ INVALID_MODIFICATION_ERR = 13,
+ NAMESPACE_ERR = 14,
+ INVALID_ACCESS_ERR = 15,
+ VALIDATION_ERR = 16,
+ TYPE_MISMATCH_ERR = 17,
+ SECURITY_ERR = 18,
+ NETWORK_ERR = 19,
+ ABORT_ERR = 20,
+ URL_MISMATCH_ERR = 21,
+ QUOTA_EXCEEDED_ERR = 22,
+ TIMEOUT_ERR = 23,
+ INVALID_NODE_TYPE_ERR = 24,
+ DATA_CLONE_ERR = 25,
+
+ // Error codes for these errors are not really defined anywhere.
+ INVALID_VALUES_ERR = 100,
+ IO_ERR = 101,
+ PERMISSION_DENIED_ERR = 102,
+ SERVICE_NOT_AVAILABLE_ERR = 103,
+ DATABASE_ERR = 104,
+
+ UNKNOWN_ERR = -1
+};
+
+class PlatformResult {
+ public:
+ explicit PlatformResult(const ErrorCode& error_code,
+ const std::string& message = "");
+
+ ErrorCode error_code() const { return error_code_; }
+ std::string message() const { return message_; }
+
+ bool IsSuccess() const { return error_code() == ErrorCode::NO_ERROR; }
+ bool IsError() const { return !IsSuccess(); }
+ explicit operator bool() const { return IsSuccess(); }
+
+ picojson::value ToJSON() const;
+
+ protected:
+ ErrorCode error_code_;
+ std::string message_;
+};
+
+} // namespace common
+
+#endif // SRC_COMMON_PLATFORM_RESULT_H_
#include "common/logger.h"
#include "common/converter.h"
-#include "tizen/tizen.h"
-
namespace extension {
namespace datasync {
g_free(profile_dir_name);
}
-void DataSyncManager::Failed(picojson::object& response_obj, picojson::object& answer_obj, int code,
+void DataSyncManager::Failed(picojson::object& response_obj, picojson::object& answer_obj,
+ const common::ErrorCode& code,
const std::string& name, const std::string& message) {
LoggerE("%s", message.c_str());
response_obj["callback_name"] = picojson::value("onfailed");
callbacks_.erase(it);
if (!progress) {
- Failed(response_obj, answer_obj, UNKNOWN_ERR, "Exception", "nullptr status");
+ Failed(response_obj, answer_obj, ErrorCode::UNKNOWN_ERR, "Exception", "nullptr status");
} else if (0 == strncmp(progress, "DONE", 4)) {
response_obj["callback_name"] = picojson::value("oncompleted");
} else if (0 == strncmp(progress, "CANCEL", 6)) {
response_obj["callback_name"] = picojson::value("onstopped");
} else if (0 == strncmp(progress, "ERROR", 5)) {
- Failed(response_obj, answer_obj, UNKNOWN_ERR, "Exception", "Datasync failed");
+ Failed(response_obj, answer_obj, ErrorCode::UNKNOWN_ERR, "Exception", "Datasync failed");
} else {
- Failed(response_obj, answer_obj, UNKNOWN_ERR, "Exception", "Undefined status");
+ Failed(response_obj, answer_obj, ErrorCode::UNKNOWN_ERR, "Exception", "Undefined status");
}
}
answer_obj["totalPerService"] = picojson::value(static_cast<double>(total_per_db));
answer_obj["syncedPerService"] = picojson::value(static_cast<double>(synced_per_db));
} else {
- Failed(response_obj, answer_obj, UNKNOWN_ERR, "Exception", "Wrong service type");
+ Failed(response_obj, answer_obj, ErrorCode::UNKNOWN_ERR, "Exception", "Wrong service type");
}
}
#include "common/utils.h"
#include "common/picojson.h"
+#include "common/platform_result.h"
namespace extension {
namespace datasync {
void Item(ds_profile_h* profile_h, const picojson::object& args);
void Item(const std::string& id, ds_profile_h* profile_h, picojson::object& out);
void GetProfileId(sync_agent_event_data_s* request, std::string& profile_id);
- void Failed(picojson::object& response_obj, picojson::object& answer_obj, int code,
- const std::string& name, const std::string& message);
+ void Failed(picojson::object& response_obj, picojson::object& answer_obj,
+ const common::ErrorCode& code, const std::string& name,
+ const std::string& message);
inline void PrepareResponseObj(const std::string& profile_id, picojson::value& response,
picojson::object& response_obj, picojson::value& answer,
picojson::object& answer_obj);
#ifndef TIZEN_TIZEN_H_
#define TIZEN_TIZEN_H_
-// WARNING! This list should be in sync with the equivalent list
-// located at tizen_api.js. Remember to update tizen_api.js if you
-// change something here.
-enum WebApiAPIErrors {
- // NO_ERROR is not really a valid error, but can be used
- // to indicate that no error occoured instead of having an
- // extra field in the message protocol just for that.
- NO_ERROR = -1,
-
- UNKNOWN_ERR = 0,
- INDEX_SIZE_ERR = 1,
- DOMSTRING_SIZE_ERR = 2,
- HIERARCHY_REQUEST_ERR = 3,
- WRONG_DOCUMENT_ERR = 4,
- INVALID_CHARACTER_ERR = 5,
- NO_DATA_ALLOWED_ERR = 6,
- NO_MODIFICATION_ALLOWED_ERR = 7,
- NOT_FOUND_ERR = 8,
- NOT_SUPPORTED_ERR = 9,
- INUSE_ATTRIBUTE_ERR = 10,
- INVALID_STATE_ERR = 11,
- SYNTAX_ERR = 12,
- INVALID_MODIFICATION_ERR = 13,
- NAMESPACE_ERR = 14,
- INVALID_ACCESS_ERR = 15,
- VALIDATION_ERR = 16,
- TYPE_MISMATCH_ERR = 17,
- SECURITY_ERR = 18,
- NETWORK_ERR = 19,
- ABORT_ERR = 20,
- URL_MISMATCH_ERR = 21,
- QUOTA_EXCEEDED_ERR = 22,
- TIMEOUT_ERR = 23,
- INVALID_NODE_TYPE_ERR = 24,
- DATA_CLONE_ERR = 25,
-
- // Error codes for these errors are not really defined anywhere.
- INVALID_VALUES_ERR = 100,
- IO_ERR = 101,
- PERMISSION_DENIED_ERR = 102,
- SERVICE_NOT_AVAILABLE_ERR = 103,
- DATABASE_ERR = 104,
-};
-
#define STR_MATCH_EXACTLY "EXACTLY"
#define STR_MATCH_FULLSTRING "FULLSTRING"
#define STR_MATCH_CONTAINS "CONTAINS"
#include <unistd.h>
#include <utility>
+#include "common/platform_result.h"
#include "websetting/websetting_extension_utils.h"
+using common::ErrorCode;
+
namespace {
const char kRuntimeServiceName[] = "org.crosswalkproject.Runtime1";
std::unique_ptr<picojson::value> WebSetting::RemoveAllCookies() {
if (!running_app_proxy_) {
if (!(running_app_proxy_ = CreateRunningAppProxy(app_id_)))
- return CreateResultMessage(WebApiAPIErrors::UNKNOWN_ERR);
+ return CreateResultMessage(ErrorCode::UNKNOWN_ERR);
}
GError* error = NULL;
GVariant* result = g_dbus_proxy_call_sync(running_app_proxy_, "RemoveAllCookies", NULL,
if (!result) {
std::cerr << "Fail to call 'RemoveuserAgentAllCookies':" << error->message << std::endl;
g_error_free(error);
- return CreateResultMessage(WebApiAPIErrors::UNKNOWN_ERR);
+ return CreateResultMessage(ErrorCode::UNKNOWN_ERR);
}
return CreateResultMessage();
}
std::unique_ptr<picojson::value> WebSetting::SetUserAgentString(const std::string& user_agent) {
if (!running_app_proxy_) {
if (!(running_app_proxy_ = CreateRunningAppProxy(app_id_)))
- return CreateResultMessage(WebApiAPIErrors::UNKNOWN_ERR);
+ return CreateResultMessage(ErrorCode::UNKNOWN_ERR);
}
GError* error = NULL;
GVariant* result = g_dbus_proxy_call_sync(running_app_proxy_, "SetUserAgentString",
if (!result) {
std::cerr << "Fail to call 'SetUserAgentString':" << error->message << std::endl;
g_error_free(error);
- return CreateResultMessage(WebApiAPIErrors::UNKNOWN_ERR);
+ return CreateResultMessage(ErrorCode::UNKNOWN_ERR);
}
return CreateResultMessage();
}
#include <memory>
#include "common/picojson.h"
+#include "common/platform_result.h"
#include "tizen/tizen.h"
std::unique_ptr<picojson::value> CreateResultMessage() {
return std::unique_ptr<picojson::value>(new picojson::value(obj));
}
-std::unique_ptr<picojson::value> CreateResultMessage(WebApiAPIErrors error) {
+std::unique_ptr<picojson::value> CreateResultMessage(const common::ErrorCode& error) {
picojson::object obj;
obj["error"] = picojson::value(static_cast<double>(error));
return std::unique_ptr<picojson::value>(new picojson::value(obj));