auto cp = cache.find(sender_name);
if (cp != cache.end())
return cp->second;
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+ g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, "GetConnectionUnixUser"),
+ g_object_unref);
- GDBusMessage* msg = nullptr;
- GDBusMessage* reply = nullptr;
+ g_dbus_message_set_body(msg_ptr.get(), g_variant_new("(s)", sender_name));
GError* err = nullptr;
- GVariant* body;
- uid_t uid = 0;
-
- msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
- DBUS_INTERFACE_NAME, "GetConnectionUnixUser");
- if (!msg) {
- LOGE("Failed to alloc new method call");
- goto out;
- }
-
- g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
- reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+ GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
+ connection, msg_ptr.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr,
+ nullptr, &err);
if (!reply) {
if (err != nullptr) {
LOGE("Failed to get uid [%s]", err->message);
g_error_free(err);
}
- goto out;
+ THROW(ERROR_IO_ERROR);
}
- body = g_dbus_message_get_body(reply);
+ GVariant* body = g_dbus_message_get_body(reply);
+ uid_t uid = 0;
g_variant_get(body, "(u)", &uid);
+ g_object_unref(reply);
if (cache.size() >= MAX_CACHE_COUNT)
cache.clear();
cache[sender_name] = uid;
-
-out:
- if (msg)
- g_object_unref(msg);
- if (reply)
- g_object_unref(reply);
-
return uid;
}
if (cp != cache.end())
return cp->second;
- GDBusMessage* msg = nullptr;
- GDBusMessage* reply = nullptr;
- GError* err = nullptr;
- GVariant* body;
- pid_t pid = 0;
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+ g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
+ DBUS_INTERFACE_NAME, "GetConnectionUnixProcessID"),
+ g_object_unref);
- msg = g_dbus_message_new_method_call(DBUS_NAME, DBUS_OBJECT_PATH,
- DBUS_INTERFACE_NAME, "GetConnectionUnixProcessID");
- if (!msg) {
+ if (!msg_ptr || !msg_ptr.get()) {
LOGE("Failed to alloc new method call");
- goto out;
+ THROW(ERROR_OUT_OF_MEMORY);
}
- g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
- reply = g_dbus_connection_send_message_with_reply_sync(connection, msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr, &err);
+ g_dbus_message_set_body(msg_ptr.get(), g_variant_new("(s)", sender_name));
+ GError* err = nullptr;
+ GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
+ connection, msg_ptr.get(), G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1,
+ nullptr, nullptr, &err);
if (!reply) {
if (err != nullptr) {
LOGE("Failed to get uid [%s]", err->message);
g_error_free(err);
}
- goto out;
+ THROW(ERROR_IO_ERROR);
}
- body = g_dbus_message_get_body(reply);
+ GVariant* body = g_dbus_message_get_body(reply);
+ pid_t pid = 0;
g_variant_get(body, "(u)", &pid);
+ g_object_unref(reply);
if (cache.size() >= MAX_CACHE_COUNT)
cache.clear();
cache[sender_name] = pid;
-
-out:
- if (msg)
- g_object_unref(msg);
- if (reply)
- g_object_unref(reply);
-
return pid;
}
}
}
dl->parent_->NotifyObserver(info, ret_list);
- } catch(Exception &ex) {
+ } catch(Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
}
}
ERROR_IO_ERROR, "invalid operation");
return;
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
g_dbus_method_invocation_return_error(invocation, noti_ex_error_quark(),
ERROR_IO_ERROR, "OnMethodCall fail");
#include "notification-ex/event_info_internal.h"
#include "notification-ex/ex_util.h"
#include "notification-ex/socket_handler.h"
+#include "notification-ex/exception.h"
#ifdef LOG_TAG
#undef LOG_TAG
LOGW("Destroyed");
}
-bool DBusSender::Impl::EmitSignal(string bus_name, string signal_name,
+void DBusSender::Impl::EmitSignal(string bus_name, string signal_name,
GVariant* data) {
GError* err = nullptr;
GDBusConnection* conn = DBusConnectionManager::GetInst().GetConnection();
if (result == FALSE) {
LOGE("g_dbus_connection_emit_signal() is failed. error(%s)",
err ? err->message : "Unknown");
+ int err_code = util::ConvertDBusError(err->code);
g_clear_error(&err);
- return false;
+ THROW(err_code);
}
result = g_dbus_connection_flush_sync(conn, NULL, &err);
if (result == FALSE) {
LOGE("g_dbus_connection_flush_sync() is failed. error(%s)",
err ? err->message : "Unknown");
+ int err_code = util::ConvertDBusError(err->code);
g_clear_error(&err);
- return false;
+ THROW(err_code);
}
-
LOGI("Successfully emit signal to %s, %s, %s",
bus_name.c_str(), path_.c_str(), signal_name.c_str());
- return true;
}
string DBusSender::Impl::GetBusName(string appid, string dest_appid) const {
string bus_name = impl_->GetBusName(appid, dest_appid);
LOGI("bus name %s, %s", dest_appid.c_str(), bus_name.c_str());
impl_->EmitSignal(bus_name, signal_name, data);
- g_variant_builder_unref(builder);
}
void DBusSender::Notify(const IEventInfo& info, list<Bundle> serialized,
string dest_appid) {
- GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+
+ std::unique_ptr<GVariantBuilder,
+ decltype(g_variant_builder_unref)*> builder_ptr(
+ g_variant_builder_new(G_VARIANT_TYPE("a(s)")),
+ g_variant_builder_unref);
int idx = 0;
for (auto& i : serialized) {
if (idx != 0 && idx % 10 == 0) {
- Notify(builder, info, dest_appid);
- g_variant_builder_unref(builder);
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ Notify(builder_ptr.get(), info, dest_appid);
+ builder_ptr.reset(g_variant_builder_new(G_VARIANT_TYPE("a(s)")));
}
- g_variant_builder_add(builder, "(s)",
+ g_variant_builder_add(builder_ptr.get(), "(s)",
reinterpret_cast<char*>(i.ToRaw().first.get()));
idx++;
}
- Notify(builder, info, dest_appid);
+ Notify(builder_ptr.get(), info, dest_appid);
}
-
-GDBusMessage* DBusSender::Impl::MethodCall(string appid, string method_name,
+int DBusSender::Impl::MethodCall(string appid, string method_name,
Bundle serialized) {
- GDBusMessage* msg = g_dbus_message_new_method_call(
- DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
- path_.c_str(),
- DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
- method_name.c_str());
- if (!msg) {
+
+ std::string dpm_name = DBusConnectionManager::GetInst()
+ .GetDataProviderMasterName();
+ std::string interface_name = DBusConnectionManager::GetInst()
+ .GetInterfaceName();
+
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+ g_dbus_message_new_method_call(dpm_name.c_str(), path_.c_str(),
+ interface_name.c_str(), method_name.c_str()),
+ g_object_unref);
+ if (!msg_ptr || !msg_ptr.get()) {
LOGE("Can't allocate new method call");
- return nullptr;
+ THROW(ERROR_OUT_OF_MEMORY);
}
- g_dbus_message_set_body(msg,
+ g_dbus_message_set_body(msg_ptr.get(),
g_variant_new("(ss)",
appid.c_str(),
reinterpret_cast<char*>(serialized.ToRaw().first.get())));
path_.c_str(), method_name.c_str(), appid.c_str());
GError* err = nullptr;
- GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
- DBusConnectionManager::GetInst().GetConnection(), msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
+ g_dbus_connection_send_message_with_reply_sync(
+ DBusConnectionManager::GetInst().GetConnection(), msg_ptr.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err),
+ g_object_unref);
if (err != NULL) {
LOGE("MethodCall, err[%s]", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- set_last_result(ERROR_PERMISSION_DENIED);
- else
- set_last_result(ERROR_IO_ERROR);
+ int err_code = util::ConvertDBusError(err->code);
+ g_error_free(err);
+ THROW(err_code);
+ }
+
+ if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
+ LOGE("RequestReturnValue got error %s", err->message);
+ int err_code = util::ConvertDBusError(err->code);
g_error_free(err);
+ THROW(err_code);
}
- g_object_unref(msg);
- return reply;
+ int num;
+ GVariant *reply_body = g_dbus_message_get_body(reply_ptr.get());
+ g_variant_get(reply_body, "(i)", &num);
+ return num;
}
-std::list<Bundle> DBusSender::Impl::MethodCallWithSocket(
+std::list<Bundle> DBusSender::Impl::GetListMethodCall(
string appid, string method_name, Bundle serialized) {
list<Bundle> ret_list;
int fds[2];
int ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds);
if (ret < 0) {
- LOGE("socketpair [%d]", ret);
- return ret_list;
+ LOGE("socketpair fail [%d]", ret);
+ THROW(ERROR_IO_ERROR);
}
SocketHandler send_sock(fds[SEND_SOCK_IDX]);
SocketHandler recv_sock(fds[RECV_SOCK_IDX]);
std::unique_ptr<GUnixFDList, decltype(g_object_unref)*> fd_list_ptr(
GetFdList(send_sock.Get()), g_object_unref);
-
std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
g_dbus_message_new_method_call(
DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
g_object_unref);
if (!msg_ptr || !msg_ptr.get()) {
LOGE("Can't allocate new method call");
- return ret_list;
+ THROW(ERROR_OUT_OF_MEMORY);
}
g_dbus_message_set_unix_fd_list(msg_ptr.get(), fd_list_ptr.get());
g_object_unref);
if (err != NULL) {
LOGE("MethodCall, err[%s]", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- set_last_result(ERROR_PERMISSION_DENIED);
- else
- set_last_result(ERROR_IO_ERROR);
+ int err_code = util::ConvertDBusError(err->code);
g_error_free(err);
- } else if (CheckReplyMessage(reply_ptr.get()) == 0) {
+ THROW(err_code);
+ } else {
+ GError* err = nullptr;
+ if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
+ LOGE("Request got error %s", err->message);
+ int err_code = util::ConvertDBusError(err->code);
+ g_error_free(err);
+ THROW(err_code);
+ }
GVariant *reply_body = g_dbus_message_get_body(reply_ptr.get());
int cnt;
g_variant_get(reply_body, "(i)", &cnt);
ret_list = util::ReadBundleList(recv_sock.Get(), cnt);
+ if (ret_list.size() == 0)
+ THROW(ERROR_NOT_EXIST_ID);
+
+ if (static_cast<int>(ret_list.size()) != cnt)
+ THROW(ERROR_IO_ERROR);
}
return ret_list;
}
return fd_list;
}
-GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
+void DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
list<Bundle> serialized) {
int fds[2];
int ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds);
if (ret < 0) {
- LOGE("socketpair [%d]", ret);
- return nullptr;
+ LOGE("socketpair fail [%d]", ret);
+ THROW(ERROR_IO_ERROR);
}
SocketHandler send_sock(fds[SEND_SOCK_IDX]);
auto fd_list_ptr = std::unique_ptr<GUnixFDList, decltype(g_object_unref)*>(
fd_list, g_object_unref);
- GDBusMessage* msg = g_dbus_message_new_method_call(
- DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
- path_.c_str(),
- DBusConnectionManager::GetInst().GetInterfaceName().c_str(),
- EventInfo::GetString(info.GetEventType()).c_str());
- if (!msg) {
+ std::string dpm_name = DBusConnectionManager::GetInst()
+ .GetDataProviderMasterName();
+ std::string interface_name = DBusConnectionManager::GetInst()
+ .GetInterfaceName();
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_ptr(
+ g_dbus_message_new_method_call(
+ dpm_name.c_str(),
+ path_.c_str(),
+ interface_name.c_str(),
+ EventInfo::GetString(info.GetEventType()).c_str()),
+ g_object_unref);
+ if (!msg_ptr || !msg_ptr.get()) {
LOGE("Can't allocate new method call");
- return nullptr;
+ THROW(ERROR_OUT_OF_MEMORY);
}
- g_dbus_message_set_unix_fd_list(msg, fd_list);
- g_dbus_message_set_body(msg,
+ g_dbus_message_set_unix_fd_list(msg_ptr.get(), fd_list);
+ g_dbus_message_set_body(msg_ptr.get(),
g_variant_new("(ssi)",
appid.c_str(),
reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()),
EventInfo::GetString(info.GetEventType()).c_str(), appid.c_str());
GError* err = nullptr;
- GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
- DBusConnectionManager::GetInst().GetConnection(), msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
- if (err != NULL) {
+ std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_ptr(
+ g_dbus_connection_send_message_with_reply_sync(
+ DBusConnectionManager::GetInst().GetConnection(), msg_ptr.get(),
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err),
+ g_object_unref);
+ if (err != nullptr) {
LOGE("MethodCall, err[%s]", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- set_last_result(ERROR_PERMISSION_DENIED);
- else
- set_last_result(ERROR_IO_ERROR);
+ int err_code = util::ConvertDBusError(err->code);
g_error_free(err);
- } else {
- for (auto& i : serialized) {
- unsigned int data_size = static_cast<unsigned int>(
- strlen(reinterpret_cast<char*>(i.ToRaw().first.get())));
- int ret = util::WriteSocket(send_sock.Get(),
- reinterpret_cast<char*>(&data_size), sizeof(data_size));
- if (ret != 0)
- break;
- ret = util::WriteSocket(send_sock.Get(),
- reinterpret_cast<char*>(i.ToRaw().first.get()), data_size);
- if (ret != 0)
- break;
- }
+ THROW(err_code);
}
- g_object_unref(msg);
- return reply;
-}
-
-int DBusSender::SendMessage(const IEventInfo& info, list<Bundle> serialized,
- string dest_appid) {
- string appid = info.GetOwner();
- if (appid.length() == 0)
- appid = util::GetAppId();
-
- GDBusMessage* reply = impl_->MethodCall(appid, info, serialized);
- if (!reply)
- return ERROR_IO_ERROR;
-
- int ret = ERROR_NONE;
- GError* err = nullptr;
- if (g_dbus_message_to_gerror(reply, &err)) {
+ if (g_dbus_message_to_gerror(reply_ptr.get(), &err)) {
LOGE("SendMessage got error %s", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED) {
- set_last_result(ERROR_PERMISSION_DENIED);
- ret = ERROR_PERMISSION_DENIED;
- } else {
- set_last_result(ERROR_IO_ERROR);
- ret = ERROR_IO_ERROR;
- }
+ int err_code = util::ConvertDBusError(err->code);
g_error_free(err);
- return ret;
- } else {
- set_last_result(ERROR_NONE);
+ THROW(err_code);
}
- return 0;
+ for (auto& i : serialized) {
+ unsigned int data_size = static_cast<unsigned int>(
+ strlen(reinterpret_cast<char*>(i.ToRaw().first.get())));
+ int ret = util::WriteSocket(send_sock.Get(),
+ reinterpret_cast<char*>(&data_size), sizeof(data_size));
+ if (ret != 0)
+ break;
+ ret = util::WriteSocket(send_sock.Get(),
+ reinterpret_cast<char*>(i.ToRaw().first.get()), data_size);
+ if (ret != 0)
+ break;
+ }
}
-int DBusSender::Impl::CheckReplyMessage(GDBusMessage* reply) {
- GError* err = nullptr;
- if (g_dbus_message_to_gerror(reply, &err)) {
- LOGE("Request got error %s", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- set_last_result(ERROR_PERMISSION_DENIED);
- else
- set_last_result(ERROR_IO_ERROR);
-
- g_error_free(err);
- return -1;
- } else {
- set_last_result(ERROR_NONE);
- }
- return 0;
+void DBusSender::SendMessage(const IEventInfo& info, list<Bundle> serialized,
+ string dest_appid) {
+ string appid = info.GetOwner();
+ if (appid.length() == 0)
+ appid = util::GetAppId();
+ impl_->MethodCall(appid, info, serialized);
}
std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
string method_name = EventInfo::GetString(info.GetEventType());
Bundle serialized = info.Serialize();
- return impl_->MethodCallWithSocket(appid, method_name, serialized);
+ return impl_->GetListMethodCall(appid, method_name, serialized);
}
int DBusSender::RequestReturnValue(const IEventInfo& info) {
string method_name = EventInfo::GetString(info.GetEventType());
Bundle serialized = info.Serialize();
-
- GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
- if (!reply)
- return 0;
-
- auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
- reply, g_object_unref);
-
- GError* err = nullptr;
- if (g_dbus_message_to_gerror(reply, &err)) {
- LOGE("RequestReturnValue got error %s", err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- set_last_result(ERROR_PERMISSION_DENIED);
- else
- set_last_result(ERROR_IO_ERROR);
-
- g_error_free(err);
- return 0;
- } else {
- set_last_result(ERROR_NONE);
- }
-
- int num;
- GVariant *reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", &num);
- return num;
+ return impl_->MethodCall(appid, method_name, serialized);
}
} // namespace notification
virtual ~DBusSender();
void Notify(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
std::string dest_appid = "") override;
- int SendMessage(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
+ void SendMessage(const IEventInfo& info, std::list<tizen_base::Bundle> serialized,
std::string dest_appid = "") override;
std::list<tizen_base::Bundle> Request(const IEventInfo& info) override;
int RequestReturnValue(const IEventInfo& info) override;
private:
std::string GetBusName(
std::string appid, std::string dest_appid) const;
- bool EmitSignal(std::string bus_name,
+ void EmitSignal(std::string bus_name,
std::string signal_name, GVariant* data);
- GDBusMessage* MethodCall(std::string appid, std::string method_name,
+ int MethodCall(std::string appid, std::string method_name,
tizen_base::Bundle serialized);
- GDBusMessage* MethodCall(std::string appid, const IEventInfo& info,
+ void MethodCall(std::string appid, const IEventInfo& info,
std::list<tizen_base::Bundle> serialized);
- std::list<tizen_base::Bundle> MethodCallWithSocket(std::string appid,
+ std::list<tizen_base::Bundle> GetListMethodCall(std::string appid,
std::string method_name, tizen_base::Bundle serialized);
GUnixFDList* GetFdList(int fd);
- int CheckReplyMessage(GDBusMessage* reply);
std::string path_;
DBusSender* parent_;
};
virtual void Notify(const IEventInfo& info,
std::list<tizen_base::Bundle> serialized,
std::string dest_appid = "") = 0;
- virtual int SendMessage(const IEventInfo& info,
+ virtual void SendMessage(const IEventInfo& info,
std::list<tizen_base::Bundle> serialized,
std::string dest_appid = "") = 0;
virtual std::list<tizen_base::Bundle> Request(const IEventInfo& info) = 0;
#include "notification-ex/ex_util.h"
#include "notification-ex/socket_handler.h"
+#include "notification-ex/common.h"
#ifdef LOG_TAG
#undef LOG_TAG
return 0;
}
+int ConvertDBusError(int error) {
+ if (error == G_DBUS_ERROR_ACCESS_DENIED)
+ return ERROR_PERMISSION_DENIED;
+
+ return ERROR_IO_ERROR;
+}
+
} // namespace util
} // namespace notification
unsigned int ReadSocket(int fd, char* buffer, unsigned int nbytes);
int WriteSocket(int fd, const char* buffer, unsigned int nbytes);
std::list<tizen_base::Bundle> ReadBundleList(int recvfd, int noti_cnt);
+ int ConvertDBusError(int error);
} // namespace util
} // namespace notification
#include "notification-ex/ex_util.h"
#include "notification-ex/item_info_internal.h"
#include "notification-ex/null_item.h"
+#include "notification-ex/exception.h"
#ifdef LOG_TAG
#undef LOG_TAG
sender_->RequestReturnValue(info);
}
-int Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
- IEventInfo::EventType type) {
- Bundle serialized = noti->Serialize();
- EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId());
- list<Bundle> serialized_list {serialized};
-
- /* Reply to Sender */
- sender_->Notify(info, serialized_list, noti->GetSenderAppId());
- return info.GetRequestId();
-}
-
void Manager::SendError(const IEventInfo& info, NotificationError error) {
list<Bundle> serialized_list {};
IEventInfo& i = const_cast<IEventInfo&>(info);
impl_->sender_->Notify(info, serialized_list, info.GetOwner());
}
-int Manager::Update(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Update(shared_ptr<item::AbstractItem> noti) {
Bundle serialized = noti->Serialize();
EventInfo info(
EventInfo::Update, util::GetAppId(), noti->GetChannel(), noti->GetId());
list<Bundle> serialized_list {serialized};
-
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(
+ impl_->sender_->SendMessage(
info, serialized_list, noti->GetSenderAppId());
+ return info.GetRequestId();
}
-int Manager::Delete(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Delete(shared_ptr<item::AbstractItem> noti) {
Bundle serialized = noti->Serialize();
EventInfo info(
EventInfo::Delete, util::GetAppId(), noti->GetChannel(), noti->GetId());
list<Bundle> serialized_list {serialized};
-
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(
+ impl_->sender_->SendMessage(
info, serialized_list, noti->GetSenderAppId());
+ return info.GetRequestId();
}
-int Manager::DeleteAll(int& request_id) {
+int Manager::DeleteAll() {
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
- request_id = info.GetRequestId();
- return impl_->sender_->RequestReturnValue(info);
+ impl_->sender_->RequestReturnValue(info);
+ return info.GetRequestId();
}
-int Manager::DeleteByChannel(string channel, int& request_id) {
+int Manager::DeleteByChannel(string channel) {
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
- request_id = info.GetRequestId();
- return impl_->sender_->RequestReturnValue(info);
+ impl_->sender_->RequestReturnValue(info);
+ return info.GetRequestId();
}
-int Manager::DeleteByAppId(string appId, int& request_id) {
+int Manager::DeleteByAppId(string appId) {
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "", appId);
- request_id = info.GetRequestId();
- return impl_->sender_->RequestReturnValue(info);
+ impl_->sender_->RequestReturnValue(info);
+ return info.GetRequestId();
}
int Manager::GetCount() const {
return impl_->sender_->RequestReturnValue(info);
}
-int Manager::Hide(shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Manager::Hide(shared_ptr<item::AbstractItem> noti) {
(reinterpret_cast<IItemInfoInternal*>(noti->GetInfo().get()))
->AddHideViewer(util::GetAppId());
EventInfo::Update, util::GetAppId(), noti->GetChannel(), noti->GetId());
Bundle serialized = noti->Serialize();
list<Bundle> serialized_list {serialized};
-
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(
+ impl_->sender_->SendMessage(
info, serialized_list, noti->GetSenderAppId());
+ return info.GetRequestId();
}
unique_ptr<item::AbstractItem> Manager::FindByRootID(string id) {
EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
list<Bundle> result = impl_->sender_->Request(info);
- if (result.size() == 0) {
- LOGE("Fail to get noti");
- return unique_ptr<item::AbstractItem>{};
- }
Bundle b = result.front();
unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
return gen_item;
virtual ~Manager();
std::list<std::unique_ptr<item::AbstractItem>> Get(std::string channel = "");
- int Update(std::shared_ptr<item::AbstractItem> noti, int& request_id);
- int Delete(std::shared_ptr<item::AbstractItem> noti, int& request_id);
- int DeleteAll(int& request_id);
- int DeleteByChannel(std::string channel, int& request_id);
- int DeleteByAppId(std::string appId, int& request_id);
- int Hide(std::shared_ptr<item::AbstractItem> noti, int& request_id);
+ int Update(std::shared_ptr<item::AbstractItem> noti);
+ int Delete(std::shared_ptr<item::AbstractItem> noti);
+ int DeleteAll();
+ int DeleteByChannel(std::string channel);
+ int DeleteByAppId(std::string appId);
+ int Hide(std::shared_ptr<item::AbstractItem> noti);
std::unique_ptr<item::AbstractItem> FindByRootID(std::string id);
int SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
int SendEvent(const IEventInfo& info, std::list<std::shared_ptr<item::AbstractItem>> notiList);
private:
friend class Manager;
- int SendNotify(std::shared_ptr<item::AbstractItem> noti,
- IEventInfo::EventType type);
std::unique_ptr<IEventSender> sender_;
std::unique_ptr<IEventListener> listener_;
std::string receiver_group_;
#include "notification-ex/ex_util.h"
#include "notification-ex/item_info_internal.h"
#include "notification-ex/shared_file.h"
+#include "notification-ex/exception.h"
#ifdef LOG_TAG
#undef LOG_TAG
listener_->RegisterObserver(parent_);
}
-int Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
- IEventInfo::EventType type) {
- Bundle serialized = noti->Serialize();
- EventInfo info(type, util::GetAppId(), noti->GetChannel(), noti->GetId());
- list<Bundle> serialized_list {serialized};
- sender_->Notify(info, serialized_list);
- return info.GetRequestId();
-}
-
void Reporter::SendError(const IEventInfo& info, NotificationError error) {
list<Bundle> serialized_list {};
IEventInfo& i = const_cast<IEventInfo&>(info);
impl_->sender_->Notify(info, serialized_list, info.GetOwner());
}
-int Reporter::Post(std::shared_ptr<item::AbstractItem> noti, int& request_id) {
+int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
LOGI("Post noti");
static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
Bundle serialized = noti->Serialize();
list<Bundle> serialized_list {serialized};
SharedFile::CopyPrivateFile(noti);
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(info, serialized_list);
+ impl_->sender_->SendMessage(info, serialized_list);
+ return info.GetRequestId();
}
-int Reporter::Post(
- std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+int Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
LOGI("Post noti list");
EventInfo info(EventInfo::Post, util::GetAppId(), "");
list<Bundle> serialized_list;
SharedFile::CopyPrivateFile(i);
}
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(info, serialized_list);
+ impl_->sender_->SendMessage(info, serialized_list);
+ return info.GetRequestId();
}
-int Reporter::Update(std::shared_ptr<AbstractItem> noti, int& request_id) {
+int Reporter::Update(std::shared_ptr<AbstractItem> noti) {
static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
Bundle serialized = noti->Serialize();
list<Bundle> serialized_list {serialized};
SharedFile::CopyPrivateFile(noti);
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(info, serialized_list);
+ impl_->sender_->SendMessage(info, serialized_list);
+ return info.GetRequestId();
}
int Reporter::Update(
- std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+ std::list<std::shared_ptr<AbstractItem>> notiList) {
EventInfo info(EventInfo::Update, util::GetAppId(), "");
list<Bundle> serialized_list;
for (auto& i : notiList) {
SharedFile::CopyPrivateFile(i);
}
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(info, serialized_list);
+ impl_->sender_->SendMessage(info, serialized_list);
+ return info.GetRequestId();
}
-int Reporter::Delete(std::shared_ptr<AbstractItem> noti, int& request_id) {
+int Reporter::Delete(std::shared_ptr<AbstractItem> noti) {
Bundle serialized = noti->Serialize();
EventInfo info(
EventInfo::Delete, util::GetAppId(), noti->GetChannel(), noti->GetId());
list<Bundle> serialized_list {serialized};
-
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(
+ impl_->sender_->SendMessage(
info, serialized_list, noti->GetSenderAppId());
+ return info.GetRequestId();
}
int Reporter::Delete(
- std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+ std::list<std::shared_ptr<AbstractItem>> notiList) {
EventInfo info(EventInfo::Delete, util::GetAppId(), "");
list<Bundle> serialized_list;
for (auto& i : notiList) {
SharedFile::CopyPrivateFile(i);
}
- request_id = info.GetRequestId();
- return impl_->sender_->SendMessage(info, serialized_list);
+ impl_->sender_->SendMessage(info, serialized_list);
+ return info.GetRequestId();
}
-int Reporter::DeleteAll(int& request_id) {
+int Reporter::DeleteAll() {
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
- request_id = info.GetRequestId();
- return impl_->sender_->RequestReturnValue(info);
+ impl_->sender_->RequestReturnValue(info);
+ return info.GetRequestId();
}
-int Reporter::DeleteByChannel(string channel, int& request_id) {
+int Reporter::DeleteByChannel(string channel) {
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
- request_id = info.GetRequestId();
- return impl_->sender_->RequestReturnValue(info);
+ impl_->sender_->RequestReturnValue(info);
+ return info.GetRequestId();
}
std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
EventInfo info(EventInfo::Get, util::GetAppId(), "", id);
list<Bundle> result = impl_->sender_->Request(info);
- if (result.size() == 0) {
- LOGE("Fail to get noti");
- return unique_ptr<item::AbstractItem>{};
- }
Bundle b = result.front();
unique_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
return gen_item;
list<unique_ptr<AbstractItem>> Reporter::FindByChannel(string channel) {
EventInfo info(EventInfo::Get, util::GetAppId(), channel, "");
list<Bundle> result = impl_->sender_->Request(info);
- if (result.size() == 0) {
- LOGE("Fail to get noti");
- return list<unique_ptr<item::AbstractItem>>{};
- }
-
list<unique_ptr<AbstractItem>> gen_item_list;
for (auto& i : result)
gen_item_list.push_back(ItemInflator::Create(i));
list<unique_ptr<AbstractItem>> Reporter::FindAll() {
EventInfo info(EventInfo::Get, util::GetAppId(), "", "");
list<Bundle> result = impl_->sender_->Request(info);
- if (result.size() == 0) {
- LOGE("Fail to get noti");
- return list<unique_ptr<item::AbstractItem>>{};
- }
-
list<unique_ptr<AbstractItem>> gen_item_list;
for (auto& i : result)
gen_item_list.push_back(ItemInflator::Create(i));
Bundle b = i->Serialize();
serialized_list.push_back(b);
}
+
impl_->sender_->Notify(info, serialized_list);
return info.GetRequestId();
}
int SendEvent(const IEventInfo& info,
std::list<std::shared_ptr<item::AbstractItem>> notiList);
void SendError(const IEventInfo& info, NotificationError error);
- int Post(std::shared_ptr<item::AbstractItem> noti, int& request_id);
- int Post(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
- int Update(std::shared_ptr<item::AbstractItem> noti, int& request_id);
- int Update(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
- int Delete(std::shared_ptr<item::AbstractItem> noti, int& request_id);
- int Delete(std::list<std::shared_ptr<item::AbstractItem>> notiList, int& request_id);
- int DeleteAll(int& request_id);
- int DeleteByChannel(std::string channel, int& request_id);
+ int Post(std::shared_ptr<item::AbstractItem> noti);
+ int Post(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+ int Update(std::shared_ptr<item::AbstractItem> noti);
+ int Update(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+ int Delete(std::shared_ptr<item::AbstractItem> noti);
+ int Delete(std::list<std::shared_ptr<item::AbstractItem>> notiList);
+ int DeleteAll();
+ int DeleteByChannel(std::string channel);
std::unique_ptr<item::AbstractItem> FindByRootID(std::string id);
std::list<std::unique_ptr<item::AbstractItem>> FindByChannel(std::string channel);
std::list<std::unique_ptr<item::AbstractItem>> FindAll();
private:
friend class Reporter;
- int SendNotify(std::shared_ptr<item::AbstractItem> noti,
- IEventInfo::EventType type);
std::unique_ptr<IEventSender> sender_;
std::unique_ptr<IEventListener> listener_;
Reporter* parent_;
if (receiver_group)
receiver_group_str = string(receiver_group);
- ManagerStub* stub = new (std::nothrow) ManagerStub(
+ try {
+ ManagerStub* stub = new (std::nothrow) ManagerStub(
unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
- receiver_group_str);
- if (stub == nullptr) {
- LOGE("Fail to create manager");
- return NOTI_EX_ERROR_IO_ERROR;
- }
+ receiver_group_str);
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- delete stub;
- return ret;
+ stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
+ new ManagerCallbackInfo(event_callbacks, data)));
+ *handle = static_cast<noti_ex_manager_h>(stub);
+ } catch (Exception& ex) {
+ return ex.GetErrorCode();
}
- stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
- new ManagerCallbackInfo(event_callbacks, data)));
- *handle = static_cast<noti_ex_manager_h>(stub);
return NOTI_EX_ERROR_NONE;
}
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- *items = nullptr;
- *count = 0;
- return ret;
- }
-
- if (item_list.size() == 0) {
- *items = nullptr;
- *count = 0;
- return NOTI_EX_ERROR_NONE;
- }
-
noti_ex_item_h* added_item =
- (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
+ static_cast<noti_ex_item_h*>(
+ calloc(item_list.size(), sizeof(noti_ex_item_h)));
if (added_item == nullptr) {
LOGE("Fail to create items");
return NOTI_EX_ERROR_OUT_OF_MEMORY;
}
*items = added_item;
*count = item_list.size();
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+ *items = nullptr;
+ *count = 0;
+ return NOTI_EX_ERROR_NONE;
+ }
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
- noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
+ noti_ex_manager_h handle, char* channel,
+ noti_ex_item_h** items, int* count) {
if (handle == nullptr || channel == nullptr ||
items == nullptr || count == nullptr) {
LOGE("Invalid parameter");
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- *items = nullptr;
- *count = 0;
- return ret;
- }
-
- if (item_list.size() == 0) {
- *items = nullptr;
- *count = 0;
- return NOTI_EX_ERROR_NONE;
- }
noti_ex_item_h* added_item =
- (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
+ static_cast<noti_ex_item_h*>(
+ calloc(item_list.size(), sizeof(noti_ex_item_h)));
if (added_item == nullptr) {
LOGE("Fail to create items");
return NOTI_EX_ERROR_OUT_OF_MEMORY;
}
*items = added_item;
*count = item_list.size();
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+ *items = nullptr;
+ *count = 0;
+ return NOTI_EX_ERROR_NONE;
+ }
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
noti_ex_item_h noti, int *request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || noti == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Update(sp->GetPtr(), *request_id);
+ *request_id = stub->Update(sp->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
noti_ex_item_h noti, int *request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || noti == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Delete(item->GetPtr(), *request_id);
+ *request_id = stub->Delete(item->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
-
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
int *request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
}
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
- stub->DeleteAll(*request_id);
- ret = get_last_result();
- if (ret != ERROR_NONE) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ *request_id = stub->DeleteAll();
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
noti_ex_manager_h handle, const char* channel, int* request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || channel == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
- stub->DeleteByChannel(channel, *request_id);
- ret = get_last_result();
- if (ret != ERROR_NONE) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ *request_id = stub->DeleteByChannel(channel);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
-
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
noti_ex_manager_h handle, const char* app_id, int* request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
- stub->DeleteByAppId(app_id, *request_id);
- ret = get_last_result();
- if (ret != ERROR_NONE) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ *request_id = stub->DeleteByAppId(app_id);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
noti_ex_item_h noti, int *request_id) {
- int ret = ERROR_NONE;
-
if (handle == nullptr || noti == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Hide(item->GetPtr(), *request_id);
+ *request_id = stub->Hide(item->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
- return ret;
+ return NOTI_EX_ERROR_NONE;
}
extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- return ret;
- }
-
- if (ptr == nullptr) {
+ *item = new Handle(ptr);
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
LOGW("Not exist ID");
*item = nullptr;
return NOTI_EX_ERROR_NONE;
}
- *item = new Handle(ptr);
- } catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
IEventInfo* c_info = static_cast<IEventInfo*>(info);
stub->SendError(static_cast<const IEventInfo&>(*c_info),
static_cast<NotificationError>(error));
-
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
*count = stub->GetCount();
-
- int ret = get_last_result();
- if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
return NOTI_EX_ERROR_INVALID_PARAMETER;
}
- ReporterStub* stub = new (std::nothrow) ReporterStub(
- unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
- unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
- if (stub == nullptr) {
- LOGE("Fail to create manager");
- return NOTI_EX_ERROR_IO_ERROR;
+ try {
+ ReporterStub* stub = new (std::nothrow) ReporterStub(
+ unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
+ unique_ptr<DBusEventListener>(
+ new DBusEventListener(Reporter::GetPath())));
+ stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
+ new ReporterCallbackInfo(event_callbacks, data)));
+ *handle = static_cast<noti_ex_reporter_h>(stub);
+ } catch (Exception& ex) {
+ LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ return ex.GetErrorCode();
}
- stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
- new ReporterCallbackInfo(event_callbacks, data)));
-
- *handle = static_cast<noti_ex_reporter_h>(stub);
-
return NOTI_EX_ERROR_NONE;
}
IEventInfo* c_info = static_cast<IEventInfo*>(info);
stub->SendError(static_cast<const IEventInfo&>(*c_info),
static_cast<NotificationError>(error));
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Post(h->GetPtr(), *request_id);
+ *request_id = stub->Post(h->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
}
Handle* item = static_cast<Handle*>(noti_list[i]);
notiList.push_back(item->GetPtr());
}
- ret = stub->Post(notiList, *request_id);
- } catch (Exception &ex) {
+ *request_id = stub->Post(notiList);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
}
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Update(item->GetPtr(), *request_id);
+ *request_id = stub->Update(item->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
}
Handle* item = static_cast<Handle*>(noti_list[i]);
notiList.push_back(item->GetPtr());
}
- ret = stub->Update(notiList, *request_id);
- } catch (Exception &ex) {
+ *request_id = stub->Update(notiList);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
}
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- ret = stub->Delete(item->GetPtr(), *request_id);
+ *request_id = stub->Delete(item->GetPtr());
}
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
}
Handle* item = static_cast<Handle*>(noti_list[i]);
notiList.push_back(item->GetPtr());
}
- ret = stub->Delete(notiList, *request_id);
- } catch (Exception &ex) {
+ *request_id = stub->Delete(notiList);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
- stub->DeleteAll(*request_id);
- ret = get_last_result();
- if (ret != ERROR_NONE) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ *request_id = stub->DeleteAll();
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
- stub->DeleteByChannel(channel, *request_id);
- ret = get_last_result();
- if (ret != ERROR_NONE) {
- LOGE("error(%d)", ret);
- return ret;
- }
- } catch (Exception &ex) {
+ *request_id = stub->DeleteByChannel(channel);
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return ret;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
- if (ptr == nullptr) {
+ *item = new Handle(ptr);
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
LOGW("Not exist ID");
*item = nullptr;
return NOTI_EX_ERROR_NONE;
}
- *item = new Handle(ptr);
- } catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
}
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
- if (list_ptr.empty()) {
- LOGW("Not exist ID");
- *noti_list = nullptr;
- *count = 0;
- return NOTI_EX_ERROR_NONE;
- }
-
int size = list_ptr.size();
list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
if (list_item == nullptr) {
*noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
*count = size;
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+ LOGW("Not exist ID");
+ *noti_list = nullptr;
+ *count = 0;
+ return NOTI_EX_ERROR_NONE;
+ }
LOGE("%s %d", ex.what(), ex.GetErrorCode());
free(list_item);
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
- if (list_ptr.empty()) {
- LOGW("Not exist ID");
- *noti_list = nullptr;
- return NOTI_EX_ERROR_NONE;
- }
int size = list_ptr.size();
list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
*noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
*count = size;
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
+ if (ex.GetErrorCode() == ERROR_NOT_EXIST_ID) {
+ LOGW("Not exist ID");
+ *noti_list = nullptr;
+ return NOTI_EX_ERROR_NONE;
+ }
LOGE("%s %d", ex.what(), ex.GetErrorCode());
free(list_item);
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
*count = stub->GetCount(channel);
- } catch (Exception &ex) {
+ } catch (Exception& ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ return ex.GetErrorCode();
}
return NOTI_EX_ERROR_NONE;