#include "notification-ex/dbus_event_listener_implementation.h"
#include "notification-ex/exception.h"
#include "notification-ex/ex_util.h"
+#include "notification-ex/event_info_internal.h"
#ifdef LOG_TAG
#undef LOG_TAG
}
void DBusEventListener::NotifyObserver(
- const EventInfo& info, list<Bundle> serialized) {
+ const IEventInfo& info, list<Bundle> serialized) {
impl_->observer_->OnEvent(info, serialized);
}
-list<Bundle> DBusEventListener::NotifyObserver(const EventInfo& info) {
+list<Bundle> DBusEventListener::NotifyObserver(const IEventInfo& info) {
return impl_->observer_->OnRequest(info);
}
void RegisterObserver(IEventObserver* observer) override;
void UnRegisterObserver(IEventObserver* observer) override;
void NotifyObserver(
- const EventInfo& info, std::list<Bundle> serialized) override;
- std::list<Bundle> NotifyObserver(const EventInfo& info) override;
+ const IEventInfo& info, std::list<Bundle> serialized) override;
+ std::list<Bundle> NotifyObserver(const IEventInfo& info) override;
private:
class Impl;
#include "notification-ex/dbus_connection_manager.h"
#include "notification-ex/dbus_sender.h"
#include "notification-ex/dbus_sender_implementation.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_internal.h"
#include "notification-ex/ex_util.h"
#ifdef LOG_TAG
return result;
}
-void DBusSender::Notify(const EventInfo& info, list<Bundle> serialized,
+void DBusSender::Notify(const IEventInfo& info, list<Bundle> serialized,
string dest_appid) {
string signal_name = EventInfo::GetString(info.GetEventType());
string appid = util::GetAppId();
return reply;
}
-std::list<Bundle> DBusSender::Request(const EventInfo& info) {
+std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
string appid = util::GetAppId();
string method_name = EventInfo::GetString(info.GetEventType());
Bundle serialized = info.Serialize();
#include "notification-ex/ex_bundle.h"
#include "notification-ex/event_sender_interface.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/ievent_info.h"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
DBusSender(std::string path);
virtual ~DBusSender();
- void Notify(const EventInfo& info, std::list<Bundle> serialized,
+ void Notify(const IEventInfo& info, std::list<Bundle> serialized,
std::string dest_appid = "") override;
- std::list<Bundle> Request(const EventInfo& info) override;
+ std::list<Bundle> Request(const IEventInfo& info) override;
private:
class Impl;
*/
#include <dlog.h>
+#include <unistd.h>
#include <memory>
-#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_internal.h"
#include "notification-ex/event_info_implementation.h"
#ifdef LOG_TAG
#define NOTIFICATION_EX_EVENT_CHANNEL_KEY "__NOTIFICATION_EX_EVENT_CHANNEL_KEY__"
#define NOTIFICATION_EX_EVENT_ITEM_ID_KEY "__NOTIFICATION_EX_EVENT_ITEM_ID_KEY__"
#define NOTIFICATION_EX_EVENT_TAG_KEY "__NOTIFICATION_EX_EVENT_TAG_KEY__"
+#define NOTIFICATION_EX_EVENT_UID_KEY "__NOTIFICATION_EX_EVENT_UID_KEY__"
using namespace std;
namespace notification {
-EventInfo::EventInfo(EventInfo::EventType type, std::string owner,
+EventInfo::EventInfo(IEventInfo::EventType type, std::string owner,
std::string channel, std::string item_id, std::string tag)
: impl_(new Impl(this, type, owner, channel, item_id, tag)) {
}
EventInfo::~EventInfo() = default;
EventInfo::Impl::~Impl() = default;
-EventInfo::Impl::Impl(EventInfo* parent, EventInfo::EventType type, std::string owner,
+EventInfo::Impl::Impl(EventInfo* parent, IEventInfo::EventType type, std::string owner,
std::string channel, std::string item_id, std::string tag)
: type_(type), owner_(owner), channel_(channel), item_id_(item_id),
tag_(tag), parent_(parent) {
+ uid_ = getuid();
LOGI("EventInfo impl created");
}
EventInfo::EventInfo(Bundle serialized)
: impl_(new Impl(this, EventInfo::Post, "", "", "", "")) {
string event_str = serialized.GetString(NOTIFICATION_EX_EVENT_TYPE_KEY);
- impl_->type_ = (EventInfo::EventType)(int)strtol(event_str.c_str(), NULL, 10);
+ impl_->type_ = (IEventInfo::EventType)(int)strtol(event_str.c_str(), NULL, 10);
impl_->owner_ = serialized.GetString(NOTIFICATION_EX_EVENT_OWNER_KEY);
impl_->channel_ = serialized.GetString(NOTIFICATION_EX_EVENT_CHANNEL_KEY);
impl_->item_id_ = serialized.GetString(NOTIFICATION_EX_EVENT_ITEM_ID_KEY);
impl_->tag_ = serialized.GetString(NOTIFICATION_EX_EVENT_TAG_KEY);
+ string uid_str = serialized.GetString(NOTIFICATION_EX_EVENT_UID_KEY);
+ impl_->uid_ = (uid_t)strtol(uid_str.c_str(), NULL, 10);
}
-string EventInfo::GetString(EventInfo::EventType type) {
+string EventInfo::GetString(IEventInfo::EventType type) {
switch(type) {
case Post:
return "Post";
serialized.Add(NOTIFICATION_EX_EVENT_CHANNEL_KEY, impl_->channel_);
serialized.Add(NOTIFICATION_EX_EVENT_ITEM_ID_KEY, impl_->item_id_);
serialized.Add(NOTIFICATION_EX_EVENT_TAG_KEY, impl_->tag_);
+ serialized.Add(NOTIFICATION_EX_EVENT_UID_KEY, to_string((int)impl_->uid_));
return serialized;
}
-EventInfo::EventType EventInfo::GetEventType() const {
+IEventInfo::EventType EventInfo::GetEventType() const {
return impl_->type_;
}
return impl_->tag_;
}
+uid_t EventInfo::GetUid() const {
+ return impl_->uid_;
+}
+
+void EventInfo::SetUid(uid_t uid) {
+ impl_->uid_ = uid;
+}
+
} // namespace notification
#include <memory>
#include <list>
+#include <sys/types.h>
+
#include "notification-ex/dbus_sender.h"
+#include "notification-ex/ievent_info.h"
namespace notification {
private:
friend class EventInfo;
- Impl(EventInfo* parent, EventInfo::EventType type, std::string owner,
+ Impl(EventInfo* parent, IEventInfo::EventType type, std::string owner,
std::string channel, std::string item_id, std::string tag);
private:
std::string channel_;
std::string item_id_;
std::string tag_;
+ uid_t uid_;
EventInfo* parent_;
};
* limitations under the License.
*/
-#ifndef NOTIFICATION_EX_EVENT_INFO_H_
-#define NOTIFICATION_EX_EVENT_INFO_H_
+#ifndef NOTIFICATION_EX_EVENT_INFO_INTERNAL_H_
+#define NOTIFICATION_EX_EVENT_INFO_INTERNAL_H_
#include <string>
#include <list>
#include "notification-ex/ex_bundle.h"
+#include "notification-ex/ievent_info_internal.h"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
namespace notification {
-class EXPORT_API EventInfo {
+class EventInfo : public IEventInfoInternal {
public:
- enum EventType {
- Post,
- Update,
- Delete,
- Get,
- };
- EventInfo(EventType type, std::string owner,
+ EventInfo(IEventInfo::EventType type, std::string owner,
std::string channel = "",
std::string item_id = "",
std::string tag = "");
EventInfo(Bundle serialized);
- ~EventInfo();
-
+ virtual ~EventInfo();
+ uid_t GetUid() const override;
+ void SetUid(uid_t uid) override;
+ EventType GetEventType() const override;
+ std::string GetOwner() const override;
+ std::string GetChannel() const override;
+ std::string GetItemId() const override;
+ std::string GetTag() const override;
+ Bundle Serialize() const override;
static std::string GetString(EventType type);
- EventType GetEventType() const;
- std::string GetOwner() const;
- std::string GetChannel() const;
- std::string GetItemId() const;
- std::string GetTag() const;
- Bundle Serialize() const;
private:
class Impl;
} // namespace notification
-#endif // NOTIFICATION_EX_EVENT_INFO_H_
+#endif // NOTIFICATION_EX_EVENT_INFO_INTERNAL_H_
#ifndef NOTIFICATION_EX_EVENT_LISTENER_INTERFACE_H_
#define NOTIFICATION_EX_EVENT_LISTENER_INTERFACE_H_
+#include <list>
+
#include "notification-ex/event_observer_interface.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/ievent_info.h"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
virtual ~IEventListener() = default;
virtual void RegisterObserver(IEventObserver* observer) = 0;
virtual void UnRegisterObserver(IEventObserver* observer) = 0;
- virtual void NotifyObserver(const EventInfo& info, std::list<Bundle> serialized) = 0;
- virtual std::list<Bundle> NotifyObserver(const EventInfo& info) = 0;
+ virtual void NotifyObserver(const IEventInfo& info, std::list<Bundle> serialized) = 0;
+ virtual std::list<Bundle> NotifyObserver(const IEventInfo& info) = 0;
};
} // namespace notification
#ifndef NOTIFICATION_EX_OBSERVER_INTERFACE_H_
#define NOTIFICATION_EX_OBSERVER_INTERFACE_H_
+#include <list>
+
#include "notification-ex/ex_bundle.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/ievent_info.h"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
class EXPORT_API IEventObserver {
public:
virtual ~IEventObserver() = default;
- virtual void OnEvent(const EventInfo& info, std::list<Bundle> serialized) = 0;
- virtual std::list<Bundle> OnRequest(const EventInfo& info) = 0;
+ virtual void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) = 0;
+ virtual std::list<Bundle> OnRequest(const IEventInfo& info) = 0;
};
} // namespace notification
#ifndef NOTIFICATION_EX_EVENT_SENDER_INTERFACE_H_
#define NOTIFICATION_EX_EVENT_SENDER_INTERFACE_H_
+#include <list>
+
#include "notification-ex/ex_bundle.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/ievent_info.h"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
class EXPORT_API IEventSender {
public:
- virtual void Notify(const EventInfo& info, std::list<Bundle> serialized,
+ virtual void Notify(const IEventInfo& info, std::list<Bundle> serialized,
std::string dest_appid = "") = 0;
- virtual std::list<Bundle> Request(const EventInfo &info) = 0;
+ virtual std::list<Bundle> Request(const IEventInfo &info) = 0;
};
} // namespace notification
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_IEVENT_INFO_H_
+#define NOTIFICATION_EX_IEVENT_INFO_H_
+
+#include "notification-ex/ex_bundle.h"
+
+namespace notification {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API IEventInfo {
+ public:
+ enum EventType {
+ Post,
+ Update,
+ Delete,
+ Get,
+ };
+ virtual ~IEventInfo() = default;
+ virtual EventType GetEventType() const = 0;
+ virtual std::string GetOwner() const = 0;
+ virtual std::string GetChannel() const = 0;
+ virtual std::string GetItemId() const = 0;
+ virtual std::string GetTag() const = 0;
+ virtual Bundle Serialize() const = 0;
+};
+
+} // nampace notification
+#endif // NOTIFICATION_EX_IEVENT_INFO_H_
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_
+#define NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_
+
+#include "notification-ex/ievent_info.h"
+
+namespace notification {
+
+class IEventInfoInternal : public IEventInfo {
+ public:
+ virtual ~IEventInfoInternal() = default;
+ virtual uid_t GetUid() const = 0;
+ virtual void SetUid(uid_t uid) = 0;
+};
+
+} // nampace notification
+#endif // NOTIFICATION_EX_IEVENT_INFO_INTERNAL_H_
#include "notification-ex/item_inflator.h"
#include "notification-ex/manager.h"
#include "notification-ex/manager_implementation.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_internal.h"
#include "notification-ex/dbus_connection_manager.h"
#include "notification-ex/ex_util.h"
#include "notification-ex/item_info_internal.h"
}
void Manager::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
- EventInfo::EventType type) {
+ IEventInfo::EventType type) {
Bundle serialized = noti->Serialize();
EventInfo info(type, util::GetAppId(), noti->GetChannel());
list<Bundle> serialized_list {serialized};
return gen_list;
}
-void Manager::SendEvent(const EventInfo& info,
+void Manager::SendEvent(const IEventInfo& info,
shared_ptr<item::AbstractItem> noti) {
Bundle serialized = noti->Serialize();
Bundle serialized_info = info.Serialize();
impl_->sender_->Notify(info, serialized_list, noti->GetSenderAppId());
}
-list<Bundle> Manager::OnRequest(const EventInfo& info) {
+list<Bundle> Manager::OnRequest(const IEventInfo& info) {
list<shared_ptr<item::AbstractItem>> item_list = OnRequestEvent(info);
list<Bundle> serialized_list;
for (auto& i : item_list) {
return serialized_list;
}
-void Manager::OnEvent(const EventInfo& info, list<Bundle> serialized) {
+void Manager::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
shared_ptr<AbstractItem> gen_item;
- const EventInfo::EventType type = info.GetEventType();
+ const IEventInfo::EventType type = info.GetEventType();
switch(type) {
case EventInfo::Post: {
list<shared_ptr<item::AbstractItem>> added;
}
}
-void Manager::OnAdd(const EventInfo& info,
+void Manager::OnAdd(const IEventInfo& info,
list<shared_ptr<item::AbstractItem>> addedItem) {
}
-void Manager::OnUpdate(const EventInfo& info,
+void Manager::OnUpdate(const IEventInfo& info,
shared_ptr<item::AbstractItem> updatedItem) {
}
-void Manager::OnDelete(const EventInfo& info,
+void Manager::OnDelete(const IEventInfo& info,
shared_ptr<item::AbstractItem> deletedItem) {
}
-list<shared_ptr<item::AbstractItem>> Manager::OnRequestEvent(const EventInfo& info) {
+list<shared_ptr<item::AbstractItem>> Manager::OnRequestEvent(const IEventInfo& info) {
return list<shared_ptr<item::AbstractItem>>({});
}
void Remove(std::shared_ptr<item::AbstractItem> noti);
void Hide(std::shared_ptr<item::AbstractItem> noti);
std::shared_ptr<item::AbstractItem> FindByRootID(std::string id);
- void SendEvent(const EventInfo& info, std::shared_ptr<item::AbstractItem> noti);
- void OnEvent(const EventInfo& info, std::list<Bundle> serialized) override;
- std::list<Bundle> OnRequest(const EventInfo& info) override;
+ void 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;
static std::string GetPath();
protected:
- virtual void OnAdd(const EventInfo& info, std::list<std::shared_ptr<item::AbstractItem>> addedItem);
- virtual void OnUpdate(const EventInfo& info, std::shared_ptr<item::AbstractItem> updatedItem);
- virtual void OnDelete(const EventInfo& info, std::shared_ptr<item::AbstractItem> deletedItem);
+ 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 std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
- const EventInfo& info);
+ const IEventInfo& info);
private:
class Impl;
private:
friend class Manager;
void SendNotify(std::shared_ptr<item::AbstractItem> noti,
- EventInfo::EventType type);
+ IEventInfo::EventType type);
std::unique_ptr<IEventSender> sender_;
std::unique_ptr<IEventListener> listener_;
std::string receiver_group_;
#include "notification-ex/reporter.h"
#include "notification-ex/reporter_implementation.h"
-#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_internal.h"
#include "notification-ex/item_inflator.h"
#include "notification-ex/dbus_connection_manager.h"
#include "notification-ex/ex_util.h"
}
void Reporter::Impl::SendNotify(shared_ptr<item::AbstractItem> noti,
- EventInfo::EventType type) {
+ IEventInfo::EventType type) {
Bundle serialized = noti->Serialize();
EventInfo info(type, util::GetAppId(), noti->GetChannel());
list<Bundle> serialized_list {serialized};
return gen_item;
}
-void Reporter::SendEvent(const EventInfo& info,
+void Reporter::SendEvent(const IEventInfo& info,
shared_ptr<item::AbstractItem> noti) {
Bundle serialized = noti->Serialize();
list<Bundle> serialized_list {serialized};
impl_->sender_->Notify(info, serialized_list);
}
-void Reporter::OnEvent(const EventInfo& info, list<Bundle> serialized) {
+void Reporter::OnEvent(const IEventInfo& info, list<Bundle> serialized) {
list<shared_ptr<item::AbstractItem>> item_list;
for (auto& i : serialized) {
shared_ptr<AbstractItem> gen_item = ItemInflator::Create(i);
OnEvent(info, item_list);
}
-list<shared_ptr<item::AbstractItem>> Reporter::OnRequestEvent(const EventInfo& info) {
+list<shared_ptr<item::AbstractItem>> Reporter::OnRequestEvent(const IEventInfo& info) {
return list<shared_ptr<item::AbstractItem>>({});
}
-list<Bundle> Reporter::OnRequest(const EventInfo& info) {
+list<Bundle> Reporter::OnRequest(const IEventInfo& info) {
list<shared_ptr<item::AbstractItem>> item_list = OnRequestEvent(info);
list<Bundle> serialized_list;
for (auto& i : item_list) {
}
void Reporter::OnEvent(
- const EventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
+ const IEventInfo& info, list<shared_ptr<item::AbstractItem>> notiList) {
}
string Reporter::GetPath() {
#include <list>
#include <memory>
-#include "notification-ex/event_info.h"
+#include "notification-ex/ievent_info.h"
#include "notification-ex/event_observer_interface.h"
#include "notification-ex/event_sender_interface.h"
#include "notification-ex/event_listener_interface.h"
std::unique_ptr<IEventListener> listener);
virtual ~Reporter();
- void SendEvent(const EventInfo& info, std::shared_ptr<item::AbstractItem> noti);
+ void SendEvent(const IEventInfo& info, std::shared_ptr<item::AbstractItem> noti);
void Post(std::shared_ptr<item::AbstractItem> noti);
void Post(std::list<std::shared_ptr<item::AbstractItem>> notiList);
void Update(std::shared_ptr<item::AbstractItem> noti);
void Remove(std::shared_ptr<item::AbstractItem> noti);
std::shared_ptr<item::AbstractItem> FindByRootID(std::string id);
- virtual void OnEvent(const EventInfo& info,
+ virtual void OnEvent(const IEventInfo& info,
std::list<std::shared_ptr<item::AbstractItem>> notiList);
virtual std::list<std::shared_ptr<item::AbstractItem>> OnRequestEvent(
- const EventInfo& info);
- void OnEvent(const EventInfo& info, std::list<Bundle> serialized) override;
- std::list<Bundle> OnRequest(const EventInfo& info) override;
+ const IEventInfo& info);
+ void OnEvent(const IEventInfo& info, std::list<Bundle> serialized) override;
+ std::list<Bundle> OnRequest(const IEventInfo& info) override;
static std::string GetPath();
private:
private:
friend class Reporter;
void SendNotify(std::shared_ptr<item::AbstractItem> noti,
- EventInfo::EventType type);
+ IEventInfo::EventType type);
std::unique_ptr<IEventSender> sender_;
std::unique_ptr<IEventListener> listener_;
Reporter* parent_;
#include <gmock/gmock.h>
-#include "notification-ex/event_info.h"
+#include "notification-ex/event_info_internal.h"
using namespace notification;
using namespace std;
ASSERT_EQ(serialized.GetChannel(), info.GetChannel());
ASSERT_EQ(serialized.GetItemId(), info.GetItemId());
ASSERT_EQ(serialized.GetTag(), info.GetTag());
+ ASSERT_EQ(serialized.GetUid(), info.GetUid());
}
TEST_F(EventInfoTest, GetString) {