/* * 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 #include #include #include #include "api/notification_ex.h" #include "api/notification_ex_internal.h" #include "notification-ex/reporter.h" #include "notification-ex/app_control_action.h" #include "notification-ex/button_item.h" #include "notification-ex/chat_message_item.h" #include "notification-ex/checkbox_item.h" #include "notification-ex/entry_item.h" #include "notification-ex/group_item.h" #include "notification-ex/input_selector_item.h" #include "notification-ex/abstract_item.h" #include "notification-ex/progress_item.h" #include "notification-ex/time_item.h" #include "notification-ex/visibility_action.h" #include "notification-ex/event_info_internal.h" #include "notification-ex/manager.h" #include "notification-ex/dbus_sender.h" #include "notification-ex/dbus_event_listener.h" #include "notification-ex/exception.h" #include "notification-ex/iitem_info_internal.h" #include "notification-ex/icon_item.h" #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "NOTIFICATION_EX" #ifdef EXPORT_API #undef EXPORT_API #endif #define EXPORT_API __attribute__((visibility("default"))) using namespace std; using namespace tizen_base; using namespace notification::item; using namespace notification; namespace { class Handle { public: explicit Handle(item::AbstractItem* ref) : ref_(ref) { } explicit Handle(std::shared_ptr ptr) : ref_(nullptr), ptr_(move(ptr)) { } virtual ~Handle() = default; item::AbstractItem* Get() const { if (ptr_ == nullptr) return ref_; return ptr_.get(); } bool IsValidType(int type) const { return (Get()->GetType() == type || Get()->GetType() >= AbstractItem::Custom); } std::shared_ptr GetPtr() const { if (ptr_ == nullptr) return std::shared_ptr({}); return ptr_; } private: item::AbstractItem* ref_; std::shared_ptr ptr_; }; class ManagerCallbackInfo { public: ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data) : user_data_(user_data) { cb_.added = cb.added; cb_.updated = cb.updated; cb_.deleted = cb.deleted; cb_.error = cb.error; } void InvokeAdded(Manager* manager, const IEventInfo& info, list> addedItem) { if (cb_.added == nullptr) return; noti_ex_item_h* added_item = (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h)); if (added_item == nullptr) { LOGE("Out of memory"); return; } int idx = 0; for (auto& i : addedItem) { added_item[idx++] = static_cast(new Handle(shared_ptr(i))); } IEventInfo* c_info = const_cast(&info); cb_.added(static_cast(manager), static_cast(c_info), added_item, addedItem.size(), user_data_); } void InvokeUpdated(Manager* manager, const IEventInfo& info, shared_ptr updatedItem) { if (cb_.updated == nullptr) return; IEventInfo* c_info = const_cast(&info); cb_.updated(static_cast(manager), static_cast(c_info), static_cast(new Handle(updatedItem)), user_data_); } void InvokeDeleted(Manager* manager, const IEventInfo& info, shared_ptr deletedItem) { if (cb_.deleted == nullptr) return; IEventInfo* c_info = const_cast(&info); if (c_info->GetEventType() == static_cast(IEventInfo::EventType::DeleteAll)) { cb_.deleted(static_cast(manager), static_cast(c_info), nullptr, user_data_); } else { cb_.deleted(static_cast(manager), static_cast(c_info), static_cast( new Handle(deletedItem)), user_data_); } } void InvokeError(Manager* manager, NotificationError error, int requestId) { if (cb_.error == nullptr) return; cb_.error(static_cast(manager), static_cast(error), requestId, user_data_); } private: noti_ex_manager_events_s cb_; void* user_data_; }; class ManagerStub : public Manager { public: ManagerStub(std::unique_ptr sender, std::unique_ptr listener, std::string receiver_group = "") : Manager(move(sender), move(listener), receiver_group) { } void OnAdd(const IEventInfo& info, list> addedItem) override { cb_->InvokeAdded(this, info, addedItem); } void OnUpdate(const IEventInfo& info, std::shared_ptr updatedItem) override { cb_->InvokeUpdated(this, info, updatedItem); } void OnDelete(const IEventInfo& info, shared_ptr deletedItem) override { cb_->InvokeDeleted(this, info, deletedItem); } void OnError(NotificationError error, int requestId) override { cb_->InvokeError(this, error, requestId); } int SetManagerCallbackInfo(unique_ptr ci) { cb_ = move(ci); return NOTI_EX_ERROR_NONE; } int ClearManagerCallbackInfo() { cb_.reset(); return NOTI_EX_ERROR_NONE; } private: unique_ptr cb_; }; class ReporterCallbackInfo { public: ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data) : user_data_(user_data) { cb_.event = cb.event; cb_.error = cb.error; } void InvokeEvent(Reporter* reporter, const IEventInfo& info, list> notiList) { if (cb_.event == nullptr) return; noti_ex_item_h* noti_list = (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h)); if (noti_list == nullptr) { LOGE("Out of memory"); return; } int idx = 0; for (auto& i : notiList) { noti_list[idx++] = static_cast(new Handle(i)); } IEventInfo* c_info = const_cast(&info); cb_.event(static_cast(reporter), static_cast(c_info), noti_list, notiList.size(), user_data_); free(noti_list); } void InvokeError(Reporter* reporter, NotificationError error, int requestId) { if (cb_.error == nullptr) return; cb_.error(static_cast(reporter), static_cast(error), requestId, user_data_); } private: noti_ex_reporter_events_s cb_; void* user_data_; }; class ReporterStub : public Reporter { public: ReporterStub(std::unique_ptr sender, std::unique_ptr listener) : Reporter(move(sender), move(listener)) { } void OnEvent(const IEventInfo& info, std::list> notiList) override { cb_->InvokeEvent(this, info, notiList); } void OnError(NotificationError error, int requestId) override { cb_->InvokeError(this, error, requestId); } int SetReporterCallbackInfo(unique_ptr ci) { cb_ = move(ci); return NOTI_EX_ERROR_NONE; } int ClearReporterCallbackInfo() { cb_.reset(); return NOTI_EX_ERROR_NONE; } private: unique_ptr cb_; }; } // namespace void __noti_ex_free_str_array(char** val, int length) { int i; for (i = 0; i < length ; i++) free(val[i]); free(val); } extern "C" EXPORT_API int noti_ex_action_app_control_create( noti_ex_action_h *handle, app_control_h app_control, const char *extra) { if (handle == nullptr || app_control == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p; if (extra) { p = new (std::nothrow) shared_ptr( new (std::nothrow) AppControlAction(app_control, extra)); } else { p = new (std::nothrow) shared_ptr( new (std::nothrow) AppControlAction(app_control)); } if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = p; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_action_app_control_set( noti_ex_action_h handle, app_control_h app_control) { if (handle == nullptr || app_control == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* ptr = static_cast*>(handle); AppControlAction* action = static_cast(ptr->get()); action->SetAppControl(app_control); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_action_app_control_get( noti_ex_action_h handle, app_control_h *app_control) { if (handle == nullptr || app_control == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* ptr = static_cast*>(handle); AppControlAction* action = static_cast(ptr->get()); app_control_h clone; int r = app_control_clone(&clone, action->GetAppControl()); if (r != APP_CONTROL_ERROR_NONE) { LOGE("failed to create a app_control handle : %d", r); return NOTI_EX_ERROR_INVALID_PARAMETER; } *app_control = clone; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle, const char *id, const char *title) { ButtonItem* p; if (handle == nullptr || title == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } if (id) p = new (std::nothrow) ButtonItem(id, title); else p = new (std::nothrow) ButtonItem(title); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle, char **title) { if (handle == nullptr || title == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* sp = static_cast(handle); if (!sp->IsValidType(AbstractItem::Button)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ButtonItem* p = static_cast(sp->Get()); string str; if (p->GetMultiLanguage() != nullptr && !p->GetMultiLanguage()->GetTranslatedString().empty()) str = p->GetMultiLanguage()->GetTranslatedString(); else if (!p->GetTitle().empty()) str = p->GetTitle(); *title = strdup(str.c_str()); if (*title == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title( noti_ex_item_h handle, noti_ex_multi_lang_h multi) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* p = static_cast(handle); if (!p->IsValidType(AbstractItem::Button)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ButtonItem* bi = static_cast(p->Get()); if (multi == nullptr) { bi->SetMultiLanguage(nullptr); return NOTI_EX_ERROR_NONE; } shared_ptr mul_ptr = *reinterpret_cast*>(multi); mul_ptr->UpdateString(); bi->SetMultiLanguage(mul_ptr); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_button_set_image( noti_ex_item_h handle, char *path) { if (handle == nullptr || path == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Button)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ButtonItem* p = static_cast(h->Get()); p->SetImgPath(path); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_button_get_image( noti_ex_item_h handle, char **path) { if (handle == nullptr || path == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Button)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ButtonItem* p = static_cast(h->Get()); if (!p->GetImgPath().empty()) *path = strdup(p->GetImgPath().c_str()); else *path = nullptr; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_create( noti_ex_item_h *handle, const char *id, noti_ex_item_h name, noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time, noti_ex_item_chat_message_type_e message_type) { if (handle == nullptr || (text == nullptr && image == nullptr) || name == nullptr || time == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto* p = new (std::nothrow) ChatMessageItem(id, dynamic_pointer_cast(static_cast(name)->GetPtr()), text == nullptr ? nullptr : dynamic_pointer_cast(static_cast(text)->GetPtr()), image == nullptr ? nullptr : dynamic_pointer_cast(static_cast(image)->GetPtr()), dynamic_pointer_cast(static_cast(time)->GetPtr()), static_cast(message_type)); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_get_name( noti_ex_item_h handle, noti_ex_item_h *name) { if (handle == nullptr || name == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::ChatMessage)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ChatMessageItem* p = static_cast(h->Get()); if (p->GetNameItem().GetType() == AbstractItem::NullObject) *name = nullptr; else *name = new Handle(&(p->GetNameItem())); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_get_text( noti_ex_item_h handle, noti_ex_item_h *text) { if (handle == nullptr || text == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::ChatMessage)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ChatMessageItem* p = static_cast(h->Get()); if (p->GetTextItem().GetType() == AbstractItem::NullObject) *text = nullptr; else *text = new Handle(&(p->GetTextItem())); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_get_image( noti_ex_item_h handle, noti_ex_item_h *image) { if (handle == nullptr || image == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::ChatMessage)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ChatMessageItem* p = static_cast(h->Get()); if (p->GetImageItem().GetType() == AbstractItem::NullObject) *image = nullptr; else *image = new Handle(&(p->GetImageItem())); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_get_time( noti_ex_item_h handle, noti_ex_item_h *time) { if (handle == nullptr || time == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::ChatMessage)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ChatMessageItem* p = static_cast(h->Get()); if (p->GetTimeItem().GetType() == AbstractItem::NullObject) *time = nullptr; else *time = new Handle(&(p->GetTimeItem())); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type( noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) { if (handle == nullptr || message_type == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::ChatMessage)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ChatMessageItem* p = static_cast(h->Get()); *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle, const char *id, const char *title, bool checked) { CheckBoxItem* p; if (handle == nullptr || title == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } p = new (std::nothrow) CheckBoxItem(id, title, checked); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle, char **title) { if (handle == nullptr || title == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::CheckBox)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } CheckBoxItem* p = static_cast(h->Get()); string str; if (p->GetMultiLanguage() != nullptr && !p->GetMultiLanguage()->GetTranslatedString().empty()) str = p->GetMultiLanguage()->GetTranslatedString(); else if (!p->GetTitle().empty()) str = p->GetTitle(); *title = strdup(str.c_str()); if (*title == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title( noti_ex_item_h handle, noti_ex_multi_lang_h multi) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* p = static_cast(handle); if (!p->IsValidType(AbstractItem::CheckBox)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } CheckBoxItem* ci = static_cast(p->Get()); if (multi == nullptr) { ci->SetMultiLanguage(nullptr); return NOTI_EX_ERROR_NONE; } shared_ptr mul_ptr = *reinterpret_cast*>(multi); mul_ptr->UpdateString(); ci->SetMultiLanguage(mul_ptr); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state( noti_ex_item_h handle, bool *checked) { if (handle == nullptr || checked == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::CheckBox)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } CheckBoxItem* p = static_cast(h->Get()); *checked = p->IsChecked(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state( noti_ex_item_h handle, bool checked) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::CheckBox)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } CheckBoxItem* p = static_cast(h->Get()); p->SetChecked(checked); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle, const char *id) { EntryItem* p; if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } p = new (std::nothrow) EntryItem(id); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle, char **text) { if (handle == nullptr || text == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Entry)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EntryItem* p = static_cast(h->Get()); string str; if (p->GetMultiLanguage() != nullptr && !p->GetMultiLanguage()->GetTranslatedString().empty()) str = p->GetMultiLanguage()->GetTranslatedString(); else if (!p->GetText().empty()) str = p->GetText(); *text = strdup(str.c_str()); if (*text == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle, const char *text) { if (handle == nullptr || text == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Entry)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EntryItem* p = static_cast(h->Get()); p->SetText(std::string(text)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language( noti_ex_item_h handle, noti_ex_multi_lang_h multi) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* p = static_cast(handle); if (!p->IsValidType(AbstractItem::Entry)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EntryItem* ei = static_cast(p->Get()); if (multi == nullptr) { ei->SetMultiLanguage(nullptr); return NOTI_EX_ERROR_NONE; } shared_ptr mul_ptr = *reinterpret_cast*>(multi); ei->SetMultiLanguage(mul_ptr); ei->GetMultiLanguage()->UpdateString(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle, noti_ex_event_info_h* cloned_handle) { if (handle == nullptr || cloned_handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Bundle cloned = static_cast(handle)->Serialize(); EventInfo* info = new EventInfo(cloned); *cloned_handle = info; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_destroy( noti_ex_event_info_h handle) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); delete info; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_get_event_type( noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) { if (handle == nullptr || event_type == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); *event_type = static_cast(info->GetEventType()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_get_owner( noti_ex_event_info_h handle, char **owner) { if (handle == nullptr || owner == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); *owner = strdup(info->GetOwner().c_str()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_get_channel( noti_ex_event_info_h handle, char **channel) { if (handle == nullptr || channel == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); *channel = strdup(info->GetChannel().c_str()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_get_item_id( noti_ex_event_info_h handle, char **item_id) { if (handle == nullptr || item_id == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); *item_id = strdup(info->GetItemId().c_str()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_event_info_get_request_id( noti_ex_event_info_h handle, int *req_id) { if (handle == nullptr || req_id == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } EventInfo* info = static_cast(handle); *req_id = info->GetRequestId(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle, const char *id) { GroupItem* p; if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } if (id) p = new (std::nothrow) GroupItem(id); else p = new (std::nothrow) GroupItem(); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle, bool vertical) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } GroupItem* p = static_cast(h->Get()); p->SetDirection(vertical); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle, bool *vertical) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } GroupItem* p = static_cast(h->Get()); *vertical = p->IsVertical(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle, char **label) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } GroupItem* p = static_cast(h->Get()); if (!p->GetAppLabel().empty()) { *label = strdup(p->GetAppLabel().c_str()); if (*label == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle, noti_ex_item_h child) { if (handle == nullptr || child == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto p = static_cast(h->Get()); p->AddChild((static_cast(child))->GetPtr()); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle, const char *item_id) { if (handle == nullptr || item_id == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } GroupItem* p = static_cast(h->Get()); p->RemoveChild(std::string(item_id)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle, noti_ex_item_group_foreach_child_cb callback, void *data) { if (handle == nullptr || callback == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Group)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } GroupItem* p = static_cast(h->Get()); list> children = p->GetChildren(); LOGI("Retrive (%zd)", children.size()); for (auto i : children) { int ret = callback( static_cast(new Handle(i)), data); if (ret != NOTI_EX_ERROR_NONE) { LOGW("callback return (%d) stop foreach", ret); break; } } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle, const char *id, const char *image_path) { ImageItem* p; if (handle == nullptr || image_path == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } if (id) p = new (std::nothrow) ImageItem(id, image_path); else p = new (std::nothrow) ImageItem(image_path); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_image_get_image_path( noti_ex_item_h handle, char **image_path) { if (handle == nullptr || image_path == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::Image)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } ImageItem* p = static_cast(h->Get()); if (!p->GetImagePath().empty()) { *image_path = strdup(p->GetImagePath().c_str()); if (*image_path == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } } else { *image_path = nullptr; } return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_input_selector_create( noti_ex_item_h *handle, const char *id) { InputSelectorItem* p; if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } if (id) p = new (std::nothrow) InputSelectorItem(id); else p = new (std::nothrow) InputSelectorItem(); if (p == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = new Handle(shared_ptr(p)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents( noti_ex_item_h handle, char ***contents_list, int *count) { if (handle == nullptr || contents_list == nullptr || count == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::InputSelector)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } InputSelectorItem* p = static_cast(h->Get()); vector> arr = p->GetMultiLanguageArr(); list contents; if (arr.size() == 0) { contents = p->GetContents(); } else { for (auto& i : arr) { contents.push_back(i->GetTranslatedString()); } } char **list = (char**)calloc(contents.size(), sizeof(char*)); if (list == nullptr) { LOGE("Out of memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } int idx = 0; for (auto& i : contents) { list[idx] = strdup(i.c_str()); if (list[idx] == nullptr) { __noti_ex_free_str_array(list, idx); LOGE("Out of memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } idx++; } *count = contents.size(); *contents_list = list; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents( noti_ex_item_h handle, const char **contents, int count) { if (handle == nullptr || contents == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } list new_contents; Handle* h = static_cast(handle); if (!h->IsValidType(AbstractItem::InputSelector)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } InputSelectorItem* p = static_cast(h->Get()); for (int i = 0; i < count; i++) { new_contents.push_back(contents[i]); } p->SetContents(move(new_contents)); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents( noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } Handle* p = static_cast(handle); if (!p->IsValidType(AbstractItem::InputSelector)) { LOGE("Invalid handle type"); return NOTI_EX_ERROR_INVALID_PARAMETER; } vector> m_list; for (int i = 0; i < count; i++) { shared_ptr mul_ptr = *reinterpret_cast*>(multi_language_list[i]); mul_ptr->UpdateString(); m_list.push_back(mul_ptr); } InputSelectorItem* input = static_cast(p->Get()); input->SetMultiLanguage(m_list); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle, unsigned char a, unsigned char r, unsigned char g, unsigned char b) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto* ptr = new (std::nothrow) shared_ptr( new (std::nothrow) Color(a, r, g, b)); if (ptr == nullptr || ptr->get() == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = ptr; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); delete p; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle, unsigned char *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetAVal(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle, unsigned char *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetRVal(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle, unsigned char *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetGVal(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle, unsigned char *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetBVal(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle, int left, int top, int right, int bottom) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto* ptr = new (std::nothrow) shared_ptr( new (std::nothrow) Padding(left, top, right, bottom)); if (ptr == nullptr || ptr->get() == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = ptr; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); delete p; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetLeft(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetTop(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetRight(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetBottom(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle, int x, int y, int w, int h) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto* ptr = new (std::nothrow) shared_ptr( new (std::nothrow) Geometry(x, y, w, h)); if (ptr == nullptr || ptr->get() == nullptr) { LOGE("Out-of-memory"); return NOTI_EX_ERROR_OUT_OF_MEMORY; } *handle = ptr; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); delete p; return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetX(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetY(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetWidth(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle, int *val) { if (handle == nullptr || val == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr* p = static_cast*>(handle); *val = (*p)->GetHeight(); return NOTI_EX_ERROR_NONE; } extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle, noti_ex_color_h color, noti_ex_padding_h padding, noti_ex_geometry_h geometry) { if (handle == nullptr) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } shared_ptr col = (color == nullptr) ? nullptr : *(static_cast*>(color)); shared_ptr padd = (padding == nullptr) ? nullptr : *(static_cast*>(padding)); shared_ptr geo = (geometry == nullptr) ? nullptr : *(static_cast*>(geometry)); auto* ptr = new (std::nothrow) shared_ptr