#include <unistd.h>
#include <string>
+#include <map>
#include <list>
#include "notification-ex/dbus_connection_manager.h"
#define LOG_TAG "NOTIFICATION_EX"
#define MAX_PACKAGE_STR_SIZE 512
#define NORMAL_UID_BASE 5000
+#define MAX_CACHE_COUNT 20
#define DBUS_NAME "org.freedesktop.DBus"
#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
uid_t DBusEventListener::Impl::GetSenderUid(GDBusConnection* connection,
const char* sender_name) {
+ static std::map<std::string, uid_t> cache;
+ auto cp = cache.find(sender_name);
+ if (cp != cache.end())
+ return cp->second;
+
GDBusMessage* msg = nullptr;
GDBusMessage* reply = nullptr;
GError* err = nullptr;
body = g_dbus_message_get_body(reply);
g_variant_get(body, "(u)", &uid);
+ if (cache.size() >= MAX_CACHE_COUNT)
+ cache.clear();
+
+ cache[sender_name] = uid;
+
out:
if (msg)
g_object_unref(msg);
}
pid_t DBusEventListener::Impl::GetSenderPid(GDBusConnection* connection,
- const char* sender_name) {
+ const char* sender_name) {
+ static std::map<std::string, pid_t> cache;
+ auto cp = cache.find(sender_name);
+ if (cp != cache.end())
+ return cp->second;
+
GDBusMessage* msg = nullptr;
GDBusMessage* reply = nullptr;
GError* err = nullptr;
body = g_dbus_message_get_body(reply);
g_variant_get(body, "(u)", &pid);
+ if (cache.size() >= MAX_CACHE_COUNT)
+ cache.clear();
+
+ cache[sender_name] = pid;
+
out:
if (msg)
g_object_unref(msg);
}
}
+void DBusEventListener::Impl::MethodCallHandler(GVariant* parameters,
+ DBusEventListener::Impl* dl, pid_t pid, uid_t uid) {
+ char* appid = nullptr;
+ GVariantIter* iter = nullptr;
+ char* event_info_raw = nullptr;
+
+ g_variant_get(parameters, "(ssa(s))", &appid, &event_info_raw, &iter);
+
+ string sender_appid = string(appid);
+ string cur_appid = util::GetAppId();
+ LOGI("MethodCallHandler!! appid(%s), sender(%s), cur(%s)", appid,
+ sender_appid.c_str(), cur_appid.c_str());
+
+ if (sender_appid == cur_appid)
+ return;
+
+ if ((!DBusConnectionManager::GetInst().IsDataProviderMaster(cur_appid)
+ && !DBusConnectionManager::GetInst().IsDataProviderMaster(sender_appid))
+ || (cur_appid == sender_appid))
+ return;
+
+ char* raw = nullptr;
+ list<Bundle> ret_list;
+ while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) {
+ Bundle ret(raw);
+ ret_list.emplace_back(ret);
+ }
+
+ Bundle b(event_info_raw);
+ EventInfo info(b);
+
+ if (info.GetEventType() == EventInfo::Post
+ || info.GetEventType() == EventInfo::Update) {
+ if (uid >= NORMAL_UID_BASE) {
+ info.SetValidatedOwner(util::GetAppId(pid));
+ info.SetValidatedUid(uid);
+ }
+ }
+
+ dl->parent_->NotifyObserver(info, ret_list);
+}
+
void DBusEventListener::Impl::OnMethodCall(
- GDBusConnection *conn, const gchar *sender, const gchar *object_path,
- const gchar *iface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
+ GDBusConnection* conn, const gchar* sender, const gchar* object_path,
+ const gchar* iface_name, const gchar* method_name,
+ GVariant* parameters, GDBusMethodInvocation* invocation,
gpointer user_data) {
LOGI("method_name[%s] sender[%s]", method_name, sender);
DBusEventListener::Impl* dl = static_cast<DBusEventListener::Impl*>(user_data);
- GVariant *reply_body = NULL;
+ GVariant* reply_body = NULL;
try {
char* appid = NULL;
char* serialized = NULL;
- if (g_strcmp0(method_name, "Get") == 0) {
+
+ uid_t uid = GetSenderUid(conn, sender);
+ pid_t pid = GetSenderPid(conn, sender);
+
+ if (g_strcmp0(method_name, "Post") == 0
+ || g_strcmp0(method_name, "Update") == 0
+ || g_strcmp0(method_name, "Delete") == 0
+ || g_strcmp0(method_name, "Error") == 0
+ || g_strcmp0(method_name, "DeleteAll") == 0
+ || g_strcmp0(method_name, "Register") == 0
+ || g_strcmp0(method_name, "Unregister") == 0) {
+ parameters = g_variant_ref(parameters);
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", 0));
+ MethodCallHandler(parameters, dl, pid, uid);
+ g_variant_unref(parameters);
+ return;
+ } else if (g_strcmp0(method_name, "Count") == 0) {
+ g_variant_get(parameters, "(&s&s)", &appid, &serialized);
+
+ Bundle b(serialized);
+ EventInfo info(b);
+ int num = dl->parent_->NotifyNumberRequest(info);
+ reply_body = g_variant_new("(i)", num);
+ } else if (g_strcmp0(method_name, "Get") == 0) {
g_variant_get(parameters, "(&s&s)", &appid, &serialized);
Bundle b(serialized);
}
reply_body = g_variant_new("(a(s))", builder);
g_variant_builder_unref(builder);
- } else if (g_strcmp0(method_name, "Count") == 0) {
- g_variant_get(parameters, "(&s&s)", &appid, &serialized);
-
- Bundle b(serialized);
- EventInfo info(b);
- int num = dl->parent_->NotifyNumberRequest(info);
- reply_body = g_variant_new("(i)", num);
+ } else {
+ g_dbus_method_invocation_return_error(invocation, noti_ex_error_quark(),
+ ERROR_IO_ERROR, "invalid operation");
+ return;
}
+
g_dbus_method_invocation_return_value(invocation, reply_body);
+
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
g_dbus_method_invocation_return_error(invocation, noti_ex_error_quark(),
static gchar introspection_xml[] =
" <node>"
" <interface name='org.tizen.notification_ex'>"
+ " <method name='Post'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
+ " <method name='Update'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
+ " <method name='Delete'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
" <method name='Get'>"
" <arg type='s' name='appid' direction='in'/>"
" <arg type='s' name='serialized' direction='in'/>"
" <arg type='a(s)' name='noti_arr' direction='out'/>"
" </method>"
+ " <method name='Error'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
" <method name='Count'>"
" <arg type='s' name='appid' direction='in'/>"
" <arg type='s' name='serialized' direction='in'/>"
" <arg type='i' name='num' direction='out'/>"
" </method>"
+ " <method name='DeleteAll'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
+ " <method name='Register'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
+ " <method name='Unregister'>"
+ " <arg type='s' name='appid' direction='in'/>"
+ " <arg type='s' name='info' direction='in'/>"
+ " <arg type='a(s)' name='serialized' direction='in'/>"
+ " <arg type='i' name='ret' direction='out'/>"
+ " </method>"
" </interface>"
" </node>";
GError *error = NULL;
const gchar *iface_name, const gchar *method_name,
GVariant *parameters, GDBusMethodInvocation *invocation,
gpointer user_data);
+ static void MethodCallHandler(GVariant *parameters, Impl* dl, pid_t pid, uid_t uid);
static GDBusInterfaceVTable InterfaceVtable;
static void SignalCb(GDBusConnection* connection,
GDBusMessage* DBusSender::Impl::MethodCall(string appid, string method_name,
Bundle serialized) {
- GError* err = nullptr;
GDBusMessage* msg = g_dbus_message_new_method_call(
DBusConnectionManager::GetInst().GetDataProviderMasterName().c_str(),
path_.c_str(),
LOGI("send message !! (%s) (%s) (%s)",
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);
+ 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);
+ g_error_free(err);
+ }
return reply;
}
+GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
+ list<Bundle> serialized) {
+ 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) {
+ LOGE("Can't allocate new method call");
+ return nullptr;
+ }
+
+ GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ for (auto& i : serialized) {
+ g_variant_builder_add(builder, "(s)",
+ reinterpret_cast<char*>(i.ToRaw().first.get()));
+ }
+
+ g_dbus_message_set_body(msg,
+ g_variant_new("(ssa(s))",
+ appid.c_str(),
+ reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()),
+ builder
+ )
+ );
+
+ LOGI("send message !! (%s) (%s) (%s)",
+ path_.c_str(), 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) {
+ 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);
+ g_error_free(err);
+ }
+
+ g_variant_builder_unref(builder);
+ 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)) {
+ 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;
+ }
+ g_error_free(err);
+ return ret;
+ } else {
+ set_last_result(ERROR_NONE);
+ }
+
+ GVariant *reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret);
+ return ret;
+}
+
std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
string appid = info.GetOwner();
if (appid.length() == 0)
string method_name = EventInfo::GetString(info.GetEventType());
Bundle serialized = info.Serialize();
+ list<Bundle> ret_list;
GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
- GVariant *reply_body = g_dbus_message_get_body(reply);
+ if (!reply)
+ return ret_list;
+
+ 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 ret_list;
+ } else {
+ set_last_result(ERROR_NONE);
+ }
+
+ GVariant *reply_body = g_dbus_message_get_body(reply);
GVariantIter *iter = nullptr;
- list<Bundle> ret_list;
g_variant_get(reply_body, "(a(s))", &iter);
char* raw = nullptr;
while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) {
Bundle serialized = info.Serialize();
GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
- GVariant *reply_body = g_dbus_message_get_body(reply);
+ if (!reply)
+ return 0;
+
+ GError* err = nullptr;
+ if (g_dbus_message_to_gerror(reply, &err)) {
+ LOGE("RequestNumber 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;
}
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,
+ std::string dest_appid = "") override;
std::list<tizen_base::Bundle> Request(const IEventInfo& info) override;
int RequestNumber(const IEventInfo& info) override;
#include <list>
#include "notification-ex/dbus_sender.h"
+#include "notification-ex/ievent_info.h"
namespace notification {
bool EmitSignal(std::string bus_name, std::string signal_name, GVariant* data);
GDBusMessage* MethodCall(std::string appid, std::string method_name,
tizen_base::Bundle serialized);
+ GDBusMessage* MethodCall(std::string appid, const IEventInfo& info,
+ std::list<tizen_base::Bundle> serialized);
std::string path_;
DBusSender* parent_;
};
virtual void Notify(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;
- virtual int RequestNumber(const IEventInfo &info) = 0;
+ virtual int 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;
+ virtual int RequestNumber(const IEventInfo& info) = 0;
};
} // namespace notification
Manager::Impl::~Impl() {
listener_->UnRegisterObserver(parent_);
- list<Bundle> dummy_list {};
+ list<Bundle> serialized_list {};
EventInfo info(EventInfo::Unregister, util::GetAppId(), "", "");
- sender_->Notify(info, dummy_list, DATA_PROVIDER_MASTER_ID);
+ sender_->SendMessage(info, serialized_list, DATA_PROVIDER_MASTER_ID);
}
Manager::Impl::Impl(Manager* parent,
unique_ptr<IEventSender> sender,
LOGI("impl created");
listener_->RegisterObserver(parent_);
+ if (DBusConnectionManager::GetInst().IsDataProviderMaster(util::GetAppId()))
+ return;
+
list<Bundle> serialized_list {};
EventInfo info(EventInfo::Register, util::GetAppId(), receiver_group, "");
- sender_->Notify(info, serialized_list, DATA_PROVIDER_MASTER_ID);
+ sender_->SendMessage(info, serialized_list, DATA_PROVIDER_MASTER_ID);
}
int Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
IEventInfo& i = const_cast<IEventInfo&>(info);
static_cast<IEventInfoInternal&>(i).SetError(error);
static_cast<IEventInfoInternal&>(i).SetEventType(EventInfo::Error);
- impl_->sender_->Notify(info, serialized_list, info.GetOwner());
+ impl_->sender_->SendMessage(info, serialized_list, info.GetOwner());
}
-int Manager::Update(shared_ptr<item::AbstractItem> noti) {
- return impl_->SendNotify(noti, EventInfo::Update);
+int Manager::Update(shared_ptr<item::AbstractItem> noti, int& request_id) {
+ 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(info, serialized_list, noti->GetSenderAppId());
}
-int Manager::Delete(shared_ptr<item::AbstractItem> noti) {
- return impl_->SendNotify(noti, EventInfo::Delete);
+int Manager::Delete(shared_ptr<item::AbstractItem> noti, int& request_id) {
+ 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(info, serialized_list, noti->GetSenderAppId());
}
-int Manager::DeleteAll() {
+int Manager::DeleteAll(int& request_id) {
Bundle serialized;
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
list<Bundle> serialized_list {serialized};
- impl_->sender_->Notify(info, serialized_list, util::GetAppId());
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list, util::GetAppId());
}
-int Manager::DeleteByChannel(string channel) {
+int Manager::DeleteByChannel(string channel, int& request_id) {
Bundle serialized;
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
list<Bundle> serialized_list {serialized};
- impl_->sender_->Notify(info, serialized_list, util::GetAppId());
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list, util::GetAppId());
}
-int Manager::DeleteByAppId(string appId) {
+int Manager::DeleteByAppId(string appId, int& request_id) {
Bundle serialized;
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "", appId);
list<Bundle> serialized_list {serialized};
- impl_->sender_->Notify(info, serialized_list, util::GetAppId());
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list, util::GetAppId());
}
int Manager::GetCount() const {
return num;
}
-int Manager::Hide(shared_ptr<item::AbstractItem> noti) {
+int Manager::Hide(shared_ptr<item::AbstractItem> noti, int& request_id) {
(reinterpret_cast<IItemInfoInternal*>(noti->GetInfo().get()))->AddHideViewer(util::GetAppId());
- return impl_->SendNotify(noti, EventInfo::Update);
+
+ EventInfo info(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(info, serialized_list, noti->GetSenderAppId());
}
unique_ptr<item::AbstractItem> Manager::FindByRootID(string id) {
int Manager::SendEvent(const IEventInfo& info,
shared_ptr<item::AbstractItem> noti) {
+ LOGI("manager-sendevent");
Bundle serialized = noti->Serialize();
Bundle serialized_info = info.Serialize();
list<Bundle> serialized_list {serialized};
int Manager::SendEvent(const IEventInfo& info,
list<shared_ptr<item::AbstractItem>> notiList) {
+ LOGI("manager-sendevent - list");
list<Bundle> serialized_list;
for (auto& i : notiList) {
Bundle b = i->Serialize();
virtual ~Manager();
std::list<std::unique_ptr<item::AbstractItem>> Get(std::string channel = "");
- 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);
+ 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);
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);
IEventInfo& i = const_cast<IEventInfo&>(info);
static_cast<IEventInfoInternal&>(i).SetError(error);
static_cast<IEventInfoInternal&>(i).SetEventType(EventInfo::Error);
- impl_->sender_->Notify(info, serialized_list, info.GetOwner());
+ impl_->sender_->SendMessage(info, serialized_list, info.GetOwner());
}
-int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
+int Reporter::Post(std::shared_ptr<item::AbstractItem> noti, int& request_id) {
LOGI("Post noti");
static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
+ Bundle serialized = noti->Serialize();
+
+ EventInfo info(EventInfo::Post, util::GetAppId(), noti->GetChannel(), noti->GetId());
+ list<Bundle> serialized_list {serialized};
SharedFile::CopyPrivateFile(noti);
- return impl_->SendNotify(noti, EventInfo::Post);
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list);
}
-int Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList) {
+int Reporter::Post(std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
+ LOGI("Post noti list");
EventInfo info(EventInfo::Post, util::GetAppId(), "");
list<Bundle> serialized_list;
for (auto& i : notiList) {
serialized_list.push_back(b);
SharedFile::CopyPrivateFile(i);
}
- impl_->sender_->Notify(info, serialized_list);
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list);
}
-int Reporter::Update(std::shared_ptr<AbstractItem> noti) {
+int Reporter::Update(std::shared_ptr<AbstractItem> noti, int& request_id) {
static_pointer_cast<IItemInfoInternal>(noti->GetInfo())->SetTime(time(NULL));
+ Bundle serialized = noti->Serialize();
+
+ EventInfo info(EventInfo::Update, util::GetAppId(), noti->GetChannel(), noti->GetId());
+ list<Bundle> serialized_list {serialized};
SharedFile::CopyPrivateFile(noti);
- return impl_->SendNotify(noti, EventInfo::Update);
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list);
}
-int Reporter::Update(std::list<std::shared_ptr<AbstractItem>> notiList) {
+int Reporter::Update(std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
EventInfo info(EventInfo::Update, util::GetAppId(), "");
list<Bundle> serialized_list;
for (auto& i : notiList) {
serialized_list.push_back(b);
SharedFile::CopyPrivateFile(i);
}
- impl_->sender_->Notify(info, serialized_list);
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list);
}
-int Reporter::Delete(std::shared_ptr<AbstractItem> noti) {
- return impl_->SendNotify(noti, EventInfo::Delete);
+int Reporter::Delete(std::shared_ptr<AbstractItem> noti, int& request_id) {
+ 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(info, serialized_list, noti->GetSenderAppId());
}
-int Reporter::Delete(std::list<std::shared_ptr<AbstractItem>> notiList) {
+int Reporter::Delete(std::list<std::shared_ptr<AbstractItem>> notiList, int& request_id) {
EventInfo info(EventInfo::Delete, util::GetAppId(), "");
list<Bundle> serialized_list;
for (auto& i : notiList) {
serialized_list.push_back(b);
SharedFile::CopyPrivateFile(i);
}
- impl_->sender_->Notify(info, serialized_list);
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list);
}
-int Reporter::DeleteAll() {
+int Reporter::DeleteAll(int& request_id) {
Bundle serialized;
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), "");
list<Bundle> serialized_list {serialized};
- impl_->sender_->Notify(info, serialized_list, util::GetAppId());
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list, util::GetAppId());
}
-int Reporter::DeleteByChannel(string channel) {
+int Reporter::DeleteByChannel(string channel, int& request_id) {
Bundle serialized;
EventInfo info(EventInfo::DeleteAll, util::GetAppId(), channel);
list<Bundle> serialized_list {serialized};
- impl_->sender_->Notify(info, serialized_list, util::GetAppId());
- return info.GetRequestId();
+
+ request_id = info.GetRequestId();
+ return impl_->sender_->SendMessage(info, serialized_list, util::GetAppId());
}
std::unique_ptr<AbstractItem> Reporter::FindByRootID(std::string id) {
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 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);
+ 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);
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();
LOGE("Fail to create manager");
return NOTI_EX_ERROR_IO_ERROR;
}
+
+ 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);
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));
if (added_item == nullptr) {
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;
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 {
- *request_id = stub->Update(sp->GetPtr());
+ ret = stub->Update(sp->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
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;
}
+
try {
ManagerStub* stub = static_cast<ManagerStub*>(handle);
Handle* item = static_cast<Handle*>(noti);
LOGE("Invalid noti reference can not be sended");
return NOTI_EX_ERROR_INVALID_PARAMETER;
} else {
- *request_id = stub->Delete(item->GetPtr());
+ ret = stub->Delete(item->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+
+ return ret;
}
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);
- *request_id = stub->DeleteAll();
+ ret = stub->DeleteAll(*request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
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);
- *request_id = stub->DeleteByChannel(channel);
+ ret = stub->DeleteByChannel(channel, *request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
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);
- *request_id = stub->DeleteByAppId(app_id);
+ ret = stub->DeleteByAppId(app_id, *request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
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 {
- *request_id = stub->Hide(item->GetPtr());
+ ret = stub->Hide(item->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
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) {
LOGW("Not exist ID");
*item = nullptr;
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) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
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) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
noti_ex_item_h noti, int *request_id) {
+ int ret = NOTI_EX_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 {
- *request_id = stub->Post(h->GetPtr());
+ ret = stub->Post(h->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
noti_ex_item_h *noti_list, int count, int *request_id) {
+ int ret = NOTI_EX_ERROR_NONE;
if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
Handle* item = static_cast<Handle*>(noti_list[i]);
notiList.push_back(item->GetPtr());
}
- *request_id = stub->Post(notiList);
+ ret = stub->Post(notiList, *request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
noti_ex_item_h noti, int *request_id) {
+ int ret = NOTI_EX_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 {
- *request_id = stub->Update(item->GetPtr());
+ ret = stub->Update(item->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_update_list(
noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
int *request_id) {
- if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
- LOGE("Invalid parameter");
- return NOTI_EX_ERROR_INVALID_PARAMETER;
- }
- try {
- ReporterStub* stub = static_cast<ReporterStub*>(handle);
- list<shared_ptr<item::AbstractItem>> notiList;
- for (int i = 0; i < count; i++) {
- Handle* item = static_cast<Handle*>(noti_list[i]);
- notiList.push_back(item->GetPtr());
- }
- *request_id = stub->Update(notiList);
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ int ret = NOTI_EX_ERROR_NONE;
+
+ if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
+ LOGE("Invalid parameter");
+ return NOTI_EX_ERROR_INVALID_PARAMETER;
+ }
+ try {
+ ReporterStub* stub = static_cast<ReporterStub*>(handle);
+ list<shared_ptr<item::AbstractItem>> notiList;
+ for (int i = 0; i < count; i++) {
+ Handle* item = static_cast<Handle*>(noti_list[i]);
+ notiList.push_back(item->GetPtr());
}
- return NOTI_EX_ERROR_NONE;
+ ret = stub->Update(notiList, *request_id);
+ } catch (Exception &ex) {
+ LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ return NOTI_EX_ERROR_IO_ERROR;
+ }
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
noti_ex_item_h noti, int *request_id) {
+ int ret = NOTI_EX_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 {
- *request_id = stub->Delete(item->GetPtr());
+ ret = stub->Delete(item->GetPtr(), *request_id);
}
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_delete_list(
noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
int *request_id) {
- if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
- LOGE("Invalid parameter");
- return NOTI_EX_ERROR_INVALID_PARAMETER;
- }
- try {
- ReporterStub* stub = static_cast<ReporterStub*>(handle);
- list<shared_ptr<item::AbstractItem>> notiList;
- for (int i = 0; i < count; i++) {
- Handle* item = static_cast<Handle*>(noti_list[i]);
- notiList.push_back(item->GetPtr());
- }
- *request_id = stub->Delete(notiList);
- } catch (Exception &ex) {
- LOGE("%s %d", ex.what(), ex.GetErrorCode());
- return NOTI_EX_ERROR_IO_ERROR;
+ int ret = NOTI_EX_ERROR_NONE;
+
+ if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
+ LOGE("Invalid parameter");
+ return NOTI_EX_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ ReporterStub* stub = static_cast<ReporterStub*>(handle);
+ list<shared_ptr<item::AbstractItem>> notiList;
+ for (int i = 0; i < count; i++) {
+ Handle* item = static_cast<Handle*>(noti_list[i]);
+ notiList.push_back(item->GetPtr());
}
- return NOTI_EX_ERROR_NONE;
+ ret = stub->Delete(notiList, *request_id);
+ } catch (Exception &ex) {
+ LOGE("%s %d", ex.what(), ex.GetErrorCode());
+ return NOTI_EX_ERROR_IO_ERROR;
+ }
+
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_delete_all(
noti_ex_reporter_h handle, int *request_id) {
+ int ret = NOTI_EX_ERROR_NONE;
+
if (handle == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
}
+
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
- *request_id = stub->DeleteAll();
+ ret = stub->DeleteAll(*request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
noti_ex_reporter_h handle, const char* channel, int* request_id) {
+ int ret = NOTI_EX_ERROR_NONE;
+
if (handle == nullptr || channel == nullptr || request_id == nullptr) {
LOGE("Invalid parameter");
return NOTI_EX_ERROR_INVALID_PARAMETER;
try {
ReporterStub* stub = static_cast<ReporterStub*>(handle);
- *request_id = stub->DeleteByChannel(channel);
+ ret = stub->DeleteByChannel(channel, *request_id);
} catch (Exception &ex) {
LOGE("%s %d", ex.what(), ex.GetErrorCode());
return NOTI_EX_ERROR_IO_ERROR;
}
- return NOTI_EX_ERROR_NONE;
+ return ret;
}
extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(