#ifndef NOTIFICATION_EX_COMMON_H_
#define NOTIFICATION_EX_COMMON_H_
+#include <tizen.h>
+
namespace notification {
enum NotificationError {
return result;
}
+string DBusSender::Impl::GetBusName(string appid, string dest_appid) const {
+ if (!DBusConnectionManager::GetInst().IsDataProviderMaster(appid))
+ return DBusConnectionManager::GetInst().GetDataProviderMasterName();
+
+ return DBusConnectionManager::GetInst().GetBusName(dest_appid);
+}
+
void DBusSender::Notify(const IEventInfo& info, list<Bundle> serialized,
string dest_appid) {
string signal_name = EventInfo::GetString(info.GetEventType());
string appid = util::GetAppId();
- string bus_name = "";
GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
for (auto& i : serialized) {
GVariant* data = g_variant_new("(ssa(s))",
appid.c_str(),
reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()), builder);
- if (!DBusConnectionManager::GetInst().IsDataProviderMaster(appid)) {
- bus_name = DBusConnectionManager::GetInst().GetDataProviderMasterName();
- impl_->EmitSignal(bus_name, signal_name, data);
- } else {
- bus_name = DBusConnectionManager::GetInst().GetBusName(dest_appid);
- LOGE("bus name %s, %s", dest_appid.c_str(), bus_name.c_str());
- impl_->EmitSignal(bus_name, signal_name, data);
- }
+ 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);
}
public:
DBusSender(std::string path);
virtual ~DBusSender();
-
void Notify(const IEventInfo& info, std::list<Bundle> serialized,
std::string dest_appid = "") override;
std::list<Bundle> Request(const IEventInfo& info) override;
Impl(DBusSender* parent, std::string path);
private:
+ std::string GetBusName(
+ std::string appid, std::string dest_appid) const;
bool EmitSignal(std::string bus_name, std::string signal_name, GVariant* data);
GDBusMessage* MethodCall(std::string appid, std::string method_name, Bundle serialized);
std::string path_;
#define NOTIFICATION_EX_EVENT_TAG_KEY "__NOTIFICATION_EX_EVENT_TAG_KEY__"
#define NOTIFICATION_EX_EVENT_UID_KEY "__NOTIFICATION_EX_EVENT_UID_KEY__"
#define NOTIFICATION_EX_EVENT_REQUEST_ID_KEY "__NOTIFICATION_EX_EVENT_REQUEST_ID_KEY__"
+#define NOTIFICATION_EX_EVENT_ERROR_KEY "__NOTIFICATION_EX_EVENT_ERROR_KEY__"
using namespace std;
namespace notification {
item_id_(item_id), tag_(tag), parent_(parent) {
uid_ = getuid();
request_id_ = util::GetRequestId();
+ error_ = NOTIFICATION_ERROR_NONE;
LOGI("EventInfo impl created");
}
string request_id_str =
serialized.GetString(NOTIFICATION_EX_EVENT_REQUEST_ID_KEY);
impl_->request_id_ = (int)strtol(request_id_str.c_str(), NULL, 10);
+ string error_str =
+ serialized.GetString(NOTIFICATION_EX_EVENT_ERROR_KEY);
+ impl_->error_ = (NotificationError)strtol(error_str.c_str(), NULL, 10);
}
string EventInfo::GetString(IEventInfo::EventType type) {
case Get:
return "Get";
break;
+ case Error:
+ return "Error";
+ break;
}
return "";
}
serialized.Add(NOTIFICATION_EX_EVENT_UID_KEY, to_string((int)impl_->uid_));
serialized.Add(
NOTIFICATION_EX_EVENT_REQUEST_ID_KEY, to_string(impl_->request_id_));
+ serialized.Add(
+ NOTIFICATION_EX_EVENT_ERROR_KEY, to_string(impl_->error_));
return serialized;
}
return impl_->type_;
}
+void EventInfo::SetEventType(EventInfo::EventType type) {
+ impl_->type_ = type;
+}
+
string EventInfo::GetOwner() const {
return impl_->owner_;
}
return impl_->request_id_;
}
+NotificationError EventInfo::GetError() const {
+ return impl_->error_;
+}
+
+void EventInfo::SetError(NotificationError error) {
+ impl_->error_ = error;
+}
+
} // namespace notification
#include "notification-ex/dbus_sender.h"
#include "notification-ex/ievent_info.h"
+#include "notification-ex/common.h"
namespace notification {
std::string tag_;
uid_t uid_;
int request_id_;
+ NotificationError error_;
EventInfo* parent_;
};
#include <string>
#include <list>
+#include "notification-ex/common.h"
#include "notification-ex/ex_bundle.h"
#include "notification-ex/ievent_info_internal.h"
virtual ~EventInfo();
uid_t GetUid() const override;
void SetUid(uid_t uid) override;
+ NotificationError GetError() const override;
+ void SetError(NotificationError error) override;
EventType GetEventType() const override;
+ void SetEventType(EventType type) override;
std::string GetOwner() const override;
std::string GetChannel() const override;
std::string GetItemId() const override;
Update,
Delete,
Get,
+ Error,
};
virtual ~IEventInfo() = default;
virtual EventType GetEventType() const = 0;
#ifndef NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_
#define NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_
+#include "notification-ex/common.h"
#include "notification-ex/ievent_info.h"
namespace notification {
virtual ~IEventInfoInternal() = default;
virtual uid_t GetUid() const = 0;
virtual void SetUid(uid_t uid) = 0;
+ virtual NotificationError GetError() const = 0;
+ virtual void SetError(NotificationError error) = 0;
+ virtual void SetEventType(EventType type) = 0;
};
} // namespace notification
return info.GetRequestId();
}
+void Manager::SendError(const IEventInfo& info, NotificationError error) {
+ list<Bundle> serialized_list {};
+ 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());
+}
+
int Manager::Update(shared_ptr<item::AbstractItem> noti) {
return impl_->SendNotify(noti, EventInfo::Update);
}
void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
shared_ptr<AbstractItem> gen_item;
const IEventInfo::EventType type = info.GetEventType();
+ NotificationError error =
+ (static_cast<const IEventInfoInternal&>(info)).GetError();
+ if (error != NOTIFICATION_ERROR_NONE) {
+ LOGE("Handling error event (%d)", error);
+ OnError(error, info.GetRequestId());
+ return;
+ }
+
switch(type) {
case EventInfo::Post: {
list<shared_ptr<item::AbstractItem>> added;
}
case EventInfo::Get:
break;
+ case EventInfo::Error:
+ break;
}
}
shared_ptr<item::AbstractItem> deletedItem) {
}
+void Manager::OnError(NotificationError error, int requestId) {
+}
+
list<shared_ptr<item::AbstractItem>> Manager::OnRequestEvent(const IEventInfo& info) {
return list<shared_ptr<item::AbstractItem>>({});
}
int SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) override;
std::list<Bundle> OnRequest(const IEventInfo& info) override;
+ void SendError(const IEventInfo& info, NotificationError error);
static std::string GetPath();
protected:
virtual void OnAdd(const IEventInfo& info, std::list<std::shared_ptr<item::AbstractItem>> addedItem);
virtual void OnUpdate(const IEventInfo& info, std::shared_ptr<item::AbstractItem> updatedItem);
virtual void OnDelete(const IEventInfo& info, std::shared_ptr<item::AbstractItem> deletedItem);
+ virtual void OnError(NotificationError error, int requestId);
virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
const IEventInfo& info);
return info.GetRequestId();
}
+void Reporter::SendError(const IEventInfo& info, NotificationError error) {
+ list<Bundle> serialized_list {};
+ 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());
+}
+
int Reporter::Post(std::shared_ptr<item::AbstractItem> noti) {
LOGI("Post noti");
return impl_->SendNotify(noti, EventInfo::Post);
}
void Reporter::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
+ NotificationError error =
+ (static_cast<const IEventInfoInternal&>(info)).GetError();
+ if (info.GetEventType() == EventInfo::Error) {
+ OnError(error, info.GetRequestId());
+ return;
+ }
+
list<shared_ptr<item::AbstractItem>> item_list;
for (auto& i : serialized) {
shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
const IEventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
}
+void Reporter::OnError(NotificationError error, int requestId) {
+}
+
string Reporter::GetPath() {
return NOTIFICATION_EX_REPORTER_OBJECT_PATH;
}
#include <list>
#include <memory>
+#include "notification-ex/common.h"
#include "notification-ex/ievent_info.h"
#include "notification-ex/event_observer_interface.h"
#include "notification-ex/event_sender_interface.h"
virtual ~Reporter();
int SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
+ 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);
std::list<std::shared_ptr<item::AbstractItem>> notiList);
virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
const IEventInfo& info);
+ virtual void OnError(NotificationError error, int requestId);
void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) override;
std::list<Bundle> OnRequest(const IEventInfo& info) override;
static std::string GetPath();