From 690cba7400e8e97044d97580cbb0ccc16cd9a825 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Mon, 18 Mar 2019 13:34:05 +0900 Subject: [PATCH] Make a class ItemInfo to avoid exporting some methods Change-Id: Iaed432aaec5f65069b503d4057d1b5aaaaafe243 Signed-off-by: Junghoon Park --- notification-ex/abstract_item.cc | 27 ++++-------- notification-ex/abstract_item.h | 6 +-- notification-ex/abstract_item_implementation.h | 3 +- notification-ex/iitem_info.h | 32 +++++++++++++++ notification-ex/iitem_info_internal.h | 34 ++++++++++++++++ notification-ex/item_info.cc | 52 ++++++++++++++++++++++++ notification-ex/{item.h => item_info_internal.h} | 37 +++++++---------- 7 files changed, 146 insertions(+), 45 deletions(-) create mode 100644 notification-ex/iitem_info.h create mode 100644 notification-ex/iitem_info_internal.h create mode 100644 notification-ex/item_info.cc rename notification-ex/{item.h => item_info_internal.h} (55%) diff --git a/notification-ex/abstract_item.cc b/notification-ex/abstract_item.cc index 3aad57d..0bdcdcc 100644 --- a/notification-ex/abstract_item.cc +++ b/notification-ex/abstract_item.cc @@ -22,6 +22,7 @@ #include "notification-ex/exception.h" #include "notification-ex/abstract_item.h" #include "notification-ex/abstract_item_implementation.h" +#include "notification-ex/item_info_internal.h" #ifdef LOG_TAG #undef LOG_TAG @@ -47,14 +48,16 @@ AbstractItem::AbstractItem(std::string id, AbstractItem::Impl::Impl(AbstractItem* parent, string id, std::shared_ptr action) - : id_(id), action_(action), parent_(parent) { - LOGI("GroupItem created"); + : id_(id), action_(action), parent_(parent), + info_(std::make_shared(this)) { + LOGI("Item created"); } AbstractItem::Impl::Impl(AbstractItem* parent, std::shared_ptr action) - : action_(action), parent_(parent) { - LOGI("GroupItem created"); + : action_(action), parent_(parent), + info_(std::make_shared(this)) { + LOGI("Item created"); } AbstractItem::~AbstractItem() = default; @@ -137,20 +140,8 @@ AbstractItem::Policy AbstractItem::GetPolicy() const { return impl_->policy_; } -int AbstractItem::GetVersion() const { - return impl_->version_; -} - -void AbstractItem::SetVersion(int ver) { - impl_->version_ = ver; -} - -int AbstractItem::GetHideTime() const { - return impl_->hide_time_; -} - -int AbstractItem::GetDeleteTime() const { - return impl_->delete_time_; +std::shared_ptr AbstractItem::GetInfo() const { + return impl_->info_; } string AbstractItem::GetChannel() const { diff --git a/notification-ex/abstract_item.h b/notification-ex/abstract_item.h index 8f9f8de..e5b5e7f 100644 --- a/notification-ex/abstract_item.h +++ b/notification-ex/abstract_item.h @@ -24,6 +24,7 @@ #include "notification-ex/abstract_action.h" #include "notification-ex/ex_bundle.h" +#include "notification-ex/iitem_info.h" #ifndef EXPORT_API #define EXPORT_API __attribute__((visibility("default"))) @@ -213,10 +214,6 @@ class EXPORT_API AbstractItem { bool CanReceive(std::string id) const; void SetPolicy(Policy policy); Policy GetPolicy() const; - int GetVersion() const; - void SetVersion(int ver); - int GetHideTime() const; - int GetDeleteTime() const; std::string GetChannel() const; void SetChannel(std::string channel); void SetLEDInfo(std::shared_ptr led); @@ -225,6 +222,7 @@ class EXPORT_API AbstractItem { void SetVibrationPath(std::string path); std::string GetSoundPath() const; std::string GetVibrationPath() const; + std::shared_ptr GetInfo() const; private: class Impl; diff --git a/notification-ex/abstract_item_implementation.h b/notification-ex/abstract_item_implementation.h index 23a7ed4..4f4b942 100644 --- a/notification-ex/abstract_item_implementation.h +++ b/notification-ex/abstract_item_implementation.h @@ -28,6 +28,7 @@ namespace item { class AbstractItem::Impl { public: + class ItemInfo; virtual ~Impl() = default; private: @@ -40,7 +41,6 @@ class AbstractItem::Impl { private: friend class AbstractItem; - std::string channel_; std::string id_; std::shared_ptr led_ = nullptr; @@ -57,6 +57,7 @@ class AbstractItem::Impl { AbstractItem* parent_; std::string sound_path_; std::string vibration_path_; + std::shared_ptr info_; }; } // namespace item diff --git a/notification-ex/iitem_info.h b/notification-ex/iitem_info.h new file mode 100644 index 0000000..049bf97 --- /dev/null +++ b/notification-ex/iitem_info.h @@ -0,0 +1,32 @@ +/* + * 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_IITEM_INFO_H_ +#define NOTIFICATION_EX_IITEM_INFO_H_ + +namespace notification { +namespace item { + +class EXPORT_API IItemInfo { + public: + virtual ~IItemInfo() = default; + virtual int GetVersion() const = 0; + virtual void SetVersion(int ver) = 0; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_IITEM_INFO_H_ diff --git a/notification-ex/iitem_info_internal.h b/notification-ex/iitem_info_internal.h new file mode 100644 index 0000000..56f667b --- /dev/null +++ b/notification-ex/iitem_info_internal.h @@ -0,0 +1,34 @@ +/* + * 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_IITEM_INFO_INTERNAL_H_ +#define NOTIFICATION_EX_IITEM_INFO_INTERNAL_H_ + +#include "notification-ex/iitem_info.h" + +namespace notification { +namespace item { + +class IItemInfoInternal : public IItemInfo{ + public: + virtual ~IItemInfoInternal() = default; + virtual int GetHideTime() const = 0; + virtual int GetDeleteTime() const = 0; +}; + +} // namespace item +} // nampace notification +#endif // NOTIFICATION_EX_IITEM_INFO_INTERNAL_H_ diff --git a/notification-ex/item_info.cc b/notification-ex/item_info.cc new file mode 100644 index 0000000..2b456ce --- /dev/null +++ b/notification-ex/item_info.cc @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#include + +#include + +#include "notification-ex/item_info_internal.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "NOTIFICATION_EX" + +using namespace std; +namespace notification { +namespace item { + +AbstractItem::Impl::ItemInfo::ItemInfo(AbstractItem::Impl* impl) : impl_(impl) {} + +int AbstractItem::Impl::ItemInfo::GetVersion() const { + return impl_->version_; +} + +void AbstractItem::Impl::ItemInfo::SetVersion(int ver) { + impl_->version_ = ver; +} + +int AbstractItem::Impl::ItemInfo::GetHideTime() const { + return impl_->hide_time_; +} + +int AbstractItem::Impl::ItemInfo::GetDeleteTime() const { + return impl_->delete_time_; +} + +} // namespace item +} // namespace notification diff --git a/notification-ex/item.h b/notification-ex/item_info_internal.h similarity index 55% rename from notification-ex/item.h rename to notification-ex/item_info_internal.h index 7e5f6a9..5c9d1b1 100644 --- a/notification-ex/item.h +++ b/notification-ex/item_info_internal.h @@ -14,35 +14,28 @@ * limitations under the License. */ -#ifndef NOTIFICATION_EX_ITEM_H_ -#define NOTIFICATION_EX_ITEM_H_ +#ifndef NOTIFICATION_EX_ITEM_INFO_H_ +#define NOTIFICATION_EX_ITEM_INFO_H_ -#include - -#include -#include -#include - -#include "notification-ex/abstract_item.h" -#include "notification-ex/ex_bundle.h" - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif +#include "notification-ex/abstract_item_implementation.h" +#include "notification-ex/iitem_info_internal.h" namespace notification { namespace item { -class EXPORT_API CustomItem : public AbstractItem { +class AbstractItem::Impl::ItemInfo : public IItemInfoInternal { public: - CustomItem(); - virtual ~CustomItem(); + ItemInfo(AbstractItem::Impl* impl); + virtual ~ItemInfo() = default; + int GetVersion() const override; + void SetVersion(int ver) override; + int GetHideTime() const override; + int GetDeleteTime() const override; - Bundle Serialize() override; - void Deserialize(Bundle b) override; - AbstractItem& FindByID(std::string id) override; -}; // class CustomItem + private: + AbstractItem::Impl* impl_; +}; } // namespace item } // nampace notification -#endif // NOTIFICATION_EX_ITEM_H_ +#endif // NOTIFICATION_EX_ITEM_INFO_H_ -- 2.7.4