2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include "api/notification_ex.h"
26 #include "api/notification_ex_internal.h"
27 #include "notification-ex/reporter.h"
28 #include "notification-ex/app_control_action.h"
29 #include "notification-ex/button_item.h"
30 #include "notification-ex/chat_message_item.h"
31 #include "notification-ex/checkbox_item.h"
32 #include "notification-ex/entry_item.h"
33 #include "notification-ex/group_item.h"
34 #include "notification-ex/input_selector_item.h"
35 #include "notification-ex/abstract_item.h"
36 #include "notification-ex/progress_item.h"
37 #include "notification-ex/time_item.h"
38 #include "notification-ex/visibility_action.h"
39 #include "notification-ex/event_info_internal.h"
40 #include "notification-ex/manager.h"
41 #include "notification-ex/dbus_sender.h"
42 #include "notification-ex/dbus_event_listener.h"
43 #include "notification-ex/exception.h"
44 #include "notification-ex/iitem_info_internal.h"
45 #include "notification-ex/icon_item.h"
50 #define LOG_TAG "NOTIFICATION_EX"
55 #define EXPORT_API __attribute__((visibility("default")))
58 using namespace tizen_base;
59 using namespace notification::item;
60 using namespace notification;
66 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
67 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
68 : ref_(nullptr), ptr_(move(ptr)) { }
69 virtual ~Handle() = default;
70 item::AbstractItem* Get() const {
76 bool IsValidType(int type) const {
77 return (Get()->GetType() == type
78 || Get()->GetType() >= AbstractItem::Custom);
81 std::shared_ptr<item::AbstractItem> GetPtr() const {
83 return std::shared_ptr<item::AbstractItem>({});
88 item::AbstractItem* ref_;
89 std::shared_ptr<item::AbstractItem> ptr_;
92 class ManagerCallbackInfo {
94 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
95 : user_data_(user_data) {
97 cb_.updated = cb.updated;
98 cb_.deleted = cb.deleted;
102 void InvokeAdded(Manager* manager, const IEventInfo& info,
103 list<shared_ptr<AbstractItem>> addedItem) {
104 if (cb_.added == nullptr)
106 noti_ex_item_h* added_item =
107 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
108 if (added_item == nullptr) {
109 LOGE("Out of memory");
114 for (auto& i : addedItem) {
116 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
119 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
120 cb_.added(static_cast<noti_ex_manager_h>(manager),
121 static_cast<noti_ex_event_info_h>(c_info), added_item,
122 addedItem.size(), user_data_);
125 void InvokeUpdated(Manager* manager, const IEventInfo& info,
126 shared_ptr<item::AbstractItem> updatedItem) {
127 if (cb_.updated == nullptr)
129 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
130 cb_.updated(static_cast<noti_ex_manager_h>(manager),
131 static_cast<noti_ex_event_info_h>(c_info),
132 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
135 void InvokeDeleted(Manager* manager, const IEventInfo& info,
136 shared_ptr<item::AbstractItem> deletedItem) {
137 if (cb_.deleted == nullptr)
139 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
140 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
141 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
142 static_cast<noti_ex_event_info_h>(c_info),
143 nullptr, user_data_);
145 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
146 static_cast<noti_ex_event_info_h>(c_info),
147 static_cast<noti_ex_item_h>(
148 new Handle(deletedItem)), user_data_);
152 void InvokeError(Manager* manager, NotificationError error, int requestId) {
153 if (cb_.error == nullptr)
155 cb_.error(static_cast<noti_ex_manager_h>(manager),
156 static_cast<noti_ex_error_e>(error), requestId, user_data_);
160 noti_ex_manager_events_s cb_;
164 class ManagerStub : public Manager {
166 ManagerStub(std::unique_ptr<IEventSender> sender,
167 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
168 : Manager(move(sender), move(listener), receiver_group) {
171 void OnAdd(const IEventInfo& info,
172 list<shared_ptr<AbstractItem>> addedItem) override {
173 cb_->InvokeAdded(this, info, addedItem);
176 void OnUpdate(const IEventInfo& info,
177 std::shared_ptr<item::AbstractItem> updatedItem) override {
178 cb_->InvokeUpdated(this, info, updatedItem);
181 void OnDelete(const IEventInfo& info,
182 shared_ptr<item::AbstractItem> deletedItem) override {
183 cb_->InvokeDeleted(this, info, deletedItem);
186 void OnError(NotificationError error, int requestId) override {
187 cb_->InvokeError(this, error, requestId);
190 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
192 return NOTI_EX_ERROR_NONE;
195 int ClearManagerCallbackInfo() {
197 return NOTI_EX_ERROR_NONE;
201 unique_ptr<ManagerCallbackInfo> cb_;
205 class ReporterCallbackInfo {
207 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
208 : user_data_(user_data) {
209 cb_.event = cb.event;
210 cb_.error = cb.error;
213 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
214 list<shared_ptr<AbstractItem>> notiList) {
215 if (cb_.event == nullptr)
217 noti_ex_item_h* noti_list =
218 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
219 if (noti_list == nullptr) {
220 LOGE("Out of memory");
225 for (auto& i : notiList) {
227 static_cast<noti_ex_item_h>(new Handle(i));
230 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
231 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
232 static_cast<noti_ex_event_info_h>(c_info), noti_list,
233 notiList.size(), user_data_);
237 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
238 if (cb_.error == nullptr)
240 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
241 static_cast<noti_ex_error_e>(error), requestId, user_data_);
245 noti_ex_reporter_events_s cb_;
249 class ReporterStub : public Reporter {
251 ReporterStub(std::unique_ptr<IEventSender> sender,
252 std::unique_ptr<IEventListener> listener)
253 : Reporter(move(sender), move(listener)) {
256 void OnEvent(const IEventInfo& info,
257 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
258 cb_->InvokeEvent(this, info, notiList);
261 void OnError(NotificationError error, int requestId) override {
262 cb_->InvokeError(this, error, requestId);
265 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
267 return NOTI_EX_ERROR_NONE;
270 int ClearReporterCallbackInfo() {
272 return NOTI_EX_ERROR_NONE;
276 unique_ptr<ReporterCallbackInfo> cb_;
281 void __noti_ex_free_str_array(char** val, int length) {
283 for (i = 0; i < length ; i++)
288 extern "C" EXPORT_API int noti_ex_action_app_control_create(
289 noti_ex_action_h *handle, app_control_h app_control,
291 if (handle == nullptr || app_control == nullptr) {
292 LOGE("Invalid parameter");
293 return NOTI_EX_ERROR_INVALID_PARAMETER;
296 shared_ptr<AbstractAction>* p;
299 p = new (std::nothrow) shared_ptr<AbstractAction>(
300 new (std::nothrow) AppControlAction(app_control, extra));
302 p = new (std::nothrow) shared_ptr<AbstractAction>(
303 new (std::nothrow) AppControlAction(app_control));
307 LOGE("Out-of-memory");
308 return NOTI_EX_ERROR_OUT_OF_MEMORY;
313 return NOTI_EX_ERROR_NONE;
316 extern "C" EXPORT_API int noti_ex_action_app_control_set(
317 noti_ex_action_h handle, app_control_h app_control) {
318 if (handle == nullptr || app_control == nullptr) {
319 LOGE("Invalid parameter");
320 return NOTI_EX_ERROR_INVALID_PARAMETER;
323 shared_ptr<AbstractAction>* ptr =
324 static_cast<shared_ptr<AbstractAction>*>(handle);
325 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
326 action->SetAppControl(app_control);
328 return NOTI_EX_ERROR_NONE;
331 extern "C" EXPORT_API int noti_ex_action_app_control_get(
332 noti_ex_action_h handle, app_control_h *app_control) {
333 if (handle == nullptr || app_control == nullptr) {
334 LOGE("Invalid parameter");
335 return NOTI_EX_ERROR_INVALID_PARAMETER;
338 shared_ptr<AbstractAction>* ptr =
339 static_cast<shared_ptr<AbstractAction>*>(handle);
340 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
343 int r = app_control_clone(&clone, action->GetAppControl());
344 if (r != APP_CONTROL_ERROR_NONE) {
345 LOGE("failed to create a app_control handle : %d", r);
346 return NOTI_EX_ERROR_INVALID_PARAMETER;
349 *app_control = clone;
351 return NOTI_EX_ERROR_NONE;
354 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
355 const char *id, const char *title) {
358 if (handle == nullptr || title == nullptr) {
359 LOGE("Invalid parameter");
360 return NOTI_EX_ERROR_INVALID_PARAMETER;
364 p = new (std::nothrow) ButtonItem(id, title);
366 p = new (std::nothrow) ButtonItem(title);
369 LOGE("Out-of-memory");
370 return NOTI_EX_ERROR_OUT_OF_MEMORY;
372 *handle = new Handle(shared_ptr<AbstractItem>(p));
374 return NOTI_EX_ERROR_NONE;
377 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
379 if (handle == nullptr || title == nullptr) {
380 LOGE("Invalid parameter");
381 return NOTI_EX_ERROR_INVALID_PARAMETER;
384 Handle* sp = static_cast<Handle*>(handle);
385 if (!sp->IsValidType(AbstractItem::Button)) {
386 LOGE("Invalid handle type");
387 return NOTI_EX_ERROR_INVALID_PARAMETER;
390 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
392 if (p->GetMultiLanguage() != nullptr &&
393 !p->GetMultiLanguage()->GetTranslatedString().empty())
394 str = p->GetMultiLanguage()->GetTranslatedString();
395 else if (!p->GetTitle().empty())
398 *title = strdup(str.c_str());
399 if (*title == nullptr) {
400 LOGE("Out-of-memory");
401 return NOTI_EX_ERROR_OUT_OF_MEMORY;
404 return NOTI_EX_ERROR_NONE;
407 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
408 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
409 if (handle == nullptr) {
410 LOGE("Invalid parameter");
411 return NOTI_EX_ERROR_INVALID_PARAMETER;
414 Handle* p = static_cast<Handle*>(handle);
415 if (!p->IsValidType(AbstractItem::Button)) {
416 LOGE("Invalid handle type");
417 return NOTI_EX_ERROR_INVALID_PARAMETER;
420 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
421 if (multi == nullptr) {
422 bi->SetMultiLanguage(nullptr);
423 return NOTI_EX_ERROR_NONE;
426 shared_ptr<MultiLanguage> mul_ptr =
427 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
429 mul_ptr->UpdateString();
430 bi->SetMultiLanguage(mul_ptr);
432 return NOTI_EX_ERROR_NONE;
435 extern "C" EXPORT_API int noti_ex_item_button_set_image(
436 noti_ex_item_h handle, const char *path) {
437 if (handle == nullptr || path == nullptr) {
438 LOGE("Invalid parameter");
439 return NOTI_EX_ERROR_INVALID_PARAMETER;
442 Handle* h = static_cast<Handle*>(handle);
443 if (!h->IsValidType(AbstractItem::Button)) {
444 LOGE("Invalid handle type");
445 return NOTI_EX_ERROR_INVALID_PARAMETER;
448 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
451 return NOTI_EX_ERROR_NONE;
454 extern "C" EXPORT_API int noti_ex_item_button_get_image(
455 noti_ex_item_h handle, char **path) {
456 if (handle == nullptr || path == nullptr) {
457 LOGE("Invalid parameter");
458 return NOTI_EX_ERROR_INVALID_PARAMETER;
461 Handle* h = static_cast<Handle*>(handle);
462 if (!h->IsValidType(AbstractItem::Button)) {
463 LOGE("Invalid handle type");
464 return NOTI_EX_ERROR_INVALID_PARAMETER;
467 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
468 if (!p->GetImgPath().empty())
469 *path = strdup(p->GetImgPath().c_str());
473 return NOTI_EX_ERROR_NONE;
476 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
477 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
478 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
479 noti_ex_item_chat_message_type_e message_type) {
480 if (handle == nullptr || (text == nullptr && image == nullptr)
481 || name == nullptr || time == nullptr
482 || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
483 LOGE("Invalid parameter");
484 return NOTI_EX_ERROR_INVALID_PARAMETER;
490 auto* p = new (std::nothrow) ChatMessageItem(id,
491 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
492 text == nullptr ? nullptr
493 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
494 image == nullptr ? nullptr
495 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
496 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
497 static_cast<ChatMessageItem::Type>(message_type));
499 LOGE("Out-of-memory");
500 return NOTI_EX_ERROR_OUT_OF_MEMORY;
503 *handle = new Handle(shared_ptr<AbstractItem>(p));
505 return NOTI_EX_ERROR_NONE;
508 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
509 noti_ex_item_h handle, noti_ex_item_h *name) {
510 if (handle == nullptr || name == nullptr) {
511 LOGE("Invalid parameter");
512 return NOTI_EX_ERROR_INVALID_PARAMETER;
514 Handle* h = static_cast<Handle*>(handle);
515 if (!h->IsValidType(AbstractItem::ChatMessage)) {
516 LOGE("Invalid handle type");
517 return NOTI_EX_ERROR_INVALID_PARAMETER;
519 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
520 if (p->GetNameItem().GetType() == AbstractItem::NullObject)
523 *name = new Handle(&(p->GetNameItem()));
525 return NOTI_EX_ERROR_NONE;
528 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
529 noti_ex_item_h handle, noti_ex_item_h *text) {
530 if (handle == nullptr || text == nullptr) {
531 LOGE("Invalid parameter");
532 return NOTI_EX_ERROR_INVALID_PARAMETER;
535 Handle* h = static_cast<Handle*>(handle);
536 if (!h->IsValidType(AbstractItem::ChatMessage)) {
537 LOGE("Invalid handle type");
538 return NOTI_EX_ERROR_INVALID_PARAMETER;
540 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
541 if (p->GetTextItem().GetType() == AbstractItem::NullObject)
544 *text = new Handle(&(p->GetTextItem()));
546 return NOTI_EX_ERROR_NONE;
549 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
550 noti_ex_item_h handle, noti_ex_item_h *image) {
551 if (handle == nullptr || image == nullptr) {
552 LOGE("Invalid parameter");
553 return NOTI_EX_ERROR_INVALID_PARAMETER;
556 Handle* h = static_cast<Handle*>(handle);
557 if (!h->IsValidType(AbstractItem::ChatMessage)) {
558 LOGE("Invalid handle type");
559 return NOTI_EX_ERROR_INVALID_PARAMETER;
561 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
562 if (p->GetImageItem().GetType() == AbstractItem::NullObject)
565 *image = new Handle(&(p->GetImageItem()));
567 return NOTI_EX_ERROR_NONE;
570 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
571 noti_ex_item_h handle, noti_ex_item_h *time) {
572 if (handle == nullptr || time == nullptr) {
573 LOGE("Invalid parameter");
574 return NOTI_EX_ERROR_INVALID_PARAMETER;
577 Handle* h = static_cast<Handle*>(handle);
578 if (!h->IsValidType(AbstractItem::ChatMessage)) {
579 LOGE("Invalid handle type");
580 return NOTI_EX_ERROR_INVALID_PARAMETER;
582 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
583 if (p->GetTimeItem().GetType() == AbstractItem::NullObject)
586 *time = new Handle(&(p->GetTimeItem()));
588 return NOTI_EX_ERROR_NONE;
591 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
592 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
593 if (handle == nullptr || message_type == nullptr) {
594 LOGE("Invalid parameter");
595 return NOTI_EX_ERROR_INVALID_PARAMETER;
598 Handle* h = static_cast<Handle*>(handle);
599 if (!h->IsValidType(AbstractItem::ChatMessage)) {
600 LOGE("Invalid handle type");
601 return NOTI_EX_ERROR_INVALID_PARAMETER;
603 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
604 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
606 return NOTI_EX_ERROR_NONE;
609 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
610 const char *id, const char *title, bool checked) {
613 if (handle == nullptr || title == nullptr) {
614 LOGE("Invalid parameter");
615 return NOTI_EX_ERROR_INVALID_PARAMETER;
621 p = new (std::nothrow) CheckBoxItem(id, title, checked);
623 LOGE("Out-of-memory");
624 return NOTI_EX_ERROR_OUT_OF_MEMORY;
627 *handle = new Handle(shared_ptr<AbstractItem>(p));
629 return NOTI_EX_ERROR_NONE;
632 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
634 if (handle == nullptr || title == nullptr) {
635 LOGE("Invalid parameter");
636 return NOTI_EX_ERROR_INVALID_PARAMETER;
638 Handle* h = static_cast<Handle*>(handle);
639 if (!h->IsValidType(AbstractItem::CheckBox)) {
640 LOGE("Invalid handle type");
641 return NOTI_EX_ERROR_INVALID_PARAMETER;
644 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
646 if (p->GetMultiLanguage() != nullptr &&
647 !p->GetMultiLanguage()->GetTranslatedString().empty())
648 str = p->GetMultiLanguage()->GetTranslatedString();
649 else if (!p->GetTitle().empty())
652 *title = strdup(str.c_str());
653 if (*title == nullptr) {
654 LOGE("Out-of-memory");
655 return NOTI_EX_ERROR_OUT_OF_MEMORY;
658 return NOTI_EX_ERROR_NONE;
661 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
662 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
663 if (handle == nullptr) {
664 LOGE("Invalid parameter");
665 return NOTI_EX_ERROR_INVALID_PARAMETER;
668 Handle* p = static_cast<Handle*>(handle);
669 if (!p->IsValidType(AbstractItem::CheckBox)) {
670 LOGE("Invalid handle type");
671 return NOTI_EX_ERROR_INVALID_PARAMETER;
674 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
675 if (multi == nullptr) {
676 ci->SetMultiLanguage(nullptr);
677 return NOTI_EX_ERROR_NONE;
680 shared_ptr<MultiLanguage> mul_ptr =
681 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
682 mul_ptr->UpdateString();
683 ci->SetMultiLanguage(mul_ptr);
685 return NOTI_EX_ERROR_NONE;
688 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
689 noti_ex_item_h handle, bool *checked) {
690 if (handle == nullptr || checked == nullptr) {
691 LOGE("Invalid parameter");
692 return NOTI_EX_ERROR_INVALID_PARAMETER;
694 Handle* h = static_cast<Handle*>(handle);
695 if (!h->IsValidType(AbstractItem::CheckBox)) {
696 LOGE("Invalid handle type");
697 return NOTI_EX_ERROR_INVALID_PARAMETER;
699 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
700 *checked = p->IsChecked();
702 return NOTI_EX_ERROR_NONE;
705 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
706 noti_ex_item_h handle, bool checked) {
707 if (handle == nullptr) {
708 LOGE("Invalid parameter");
709 return NOTI_EX_ERROR_INVALID_PARAMETER;
712 Handle* h = static_cast<Handle*>(handle);
713 if (!h->IsValidType(AbstractItem::CheckBox)) {
714 LOGE("Invalid handle type");
715 return NOTI_EX_ERROR_INVALID_PARAMETER;
718 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
719 p->SetChecked(checked);
721 return NOTI_EX_ERROR_NONE;
724 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
728 if (handle == nullptr) {
729 LOGE("Invalid parameter");
730 return NOTI_EX_ERROR_INVALID_PARAMETER;
734 p = new (std::nothrow) EntryItem(id);
736 p = new (std::nothrow) EntryItem();
739 LOGE("Out-of-memory");
740 return NOTI_EX_ERROR_OUT_OF_MEMORY;
743 *handle = new Handle(shared_ptr<AbstractItem>(p));
745 return NOTI_EX_ERROR_NONE;
748 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
750 if (handle == nullptr || text == nullptr) {
751 LOGE("Invalid parameter");
752 return NOTI_EX_ERROR_INVALID_PARAMETER;
755 Handle* h = static_cast<Handle*>(handle);
756 if (!h->IsValidType(AbstractItem::Entry)) {
757 LOGE("Invalid handle type");
758 return NOTI_EX_ERROR_INVALID_PARAMETER;
761 EntryItem* p = static_cast<EntryItem*>(h->Get());
763 if (p->GetMultiLanguage() != nullptr &&
764 !p->GetMultiLanguage()->GetTranslatedString().empty())
765 str = p->GetMultiLanguage()->GetTranslatedString();
766 else if (!p->GetText().empty())
769 *text = strdup(str.c_str());
770 if (*text == nullptr) {
771 LOGE("Out-of-memory");
772 return NOTI_EX_ERROR_OUT_OF_MEMORY;
775 return NOTI_EX_ERROR_NONE;
778 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
780 if (handle == nullptr || text == nullptr) {
781 LOGE("Invalid parameter");
782 return NOTI_EX_ERROR_INVALID_PARAMETER;
784 Handle* h = static_cast<Handle*>(handle);
785 if (!h->IsValidType(AbstractItem::Entry)) {
786 LOGE("Invalid handle type");
787 return NOTI_EX_ERROR_INVALID_PARAMETER;
789 EntryItem* p = static_cast<EntryItem*>(h->Get());
790 p->SetText(std::string(text));
792 return NOTI_EX_ERROR_NONE;
795 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
796 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
797 if (handle == nullptr) {
798 LOGE("Invalid parameter");
799 return NOTI_EX_ERROR_INVALID_PARAMETER;
802 Handle* p = static_cast<Handle*>(handle);
803 if (!p->IsValidType(AbstractItem::Entry)) {
804 LOGE("Invalid handle type");
805 return NOTI_EX_ERROR_INVALID_PARAMETER;
808 EntryItem* ei = static_cast<EntryItem*>(p->Get());
809 if (multi == nullptr) {
810 ei->SetMultiLanguage(nullptr);
811 return NOTI_EX_ERROR_NONE;
814 shared_ptr<MultiLanguage> mul_ptr =
815 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
816 ei->SetMultiLanguage(mul_ptr);
817 ei->GetMultiLanguage()->UpdateString();
819 return NOTI_EX_ERROR_NONE;
822 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
823 noti_ex_event_info_h* cloned_handle) {
824 if (handle == nullptr || cloned_handle == nullptr) {
825 LOGE("Invalid parameter");
826 return NOTI_EX_ERROR_INVALID_PARAMETER;
829 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
830 EventInfo* info = new EventInfo(cloned);
831 *cloned_handle = info;
832 return NOTI_EX_ERROR_NONE;
835 extern "C" EXPORT_API int noti_ex_event_info_destroy(
836 noti_ex_event_info_h handle) {
837 if (handle == nullptr) {
838 LOGE("Invalid parameter");
839 return NOTI_EX_ERROR_INVALID_PARAMETER;
841 EventInfo* info = static_cast<EventInfo*>(handle);
843 return NOTI_EX_ERROR_NONE;
846 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
847 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
848 if (handle == nullptr || event_type == nullptr) {
849 LOGE("Invalid parameter");
850 return NOTI_EX_ERROR_INVALID_PARAMETER;
852 EventInfo* info = static_cast<EventInfo*>(handle);
853 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
855 return NOTI_EX_ERROR_NONE;
858 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
859 noti_ex_event_info_h handle, char **owner) {
860 if (handle == nullptr || owner == nullptr) {
861 LOGE("Invalid parameter");
862 return NOTI_EX_ERROR_INVALID_PARAMETER;
864 EventInfo* info = static_cast<EventInfo*>(handle);
865 *owner = strdup(info->GetOwner().c_str());
866 return NOTI_EX_ERROR_NONE;
869 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
870 noti_ex_event_info_h handle, char **channel) {
871 if (handle == nullptr || channel == nullptr) {
872 LOGE("Invalid parameter");
873 return NOTI_EX_ERROR_INVALID_PARAMETER;
875 EventInfo* info = static_cast<EventInfo*>(handle);
876 *channel = strdup(info->GetChannel().c_str());
877 return NOTI_EX_ERROR_NONE;
880 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
881 noti_ex_event_info_h handle, char **item_id) {
882 if (handle == nullptr || item_id == nullptr) {
883 LOGE("Invalid parameter");
884 return NOTI_EX_ERROR_INVALID_PARAMETER;
886 EventInfo* info = static_cast<EventInfo*>(handle);
887 *item_id = strdup(info->GetItemId().c_str());
888 return NOTI_EX_ERROR_NONE;
891 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
892 noti_ex_event_info_h handle, int *req_id) {
893 if (handle == nullptr || req_id == nullptr) {
894 LOGE("Invalid parameter");
895 return NOTI_EX_ERROR_INVALID_PARAMETER;
897 EventInfo* info = static_cast<EventInfo*>(handle);
898 *req_id = info->GetRequestId();
899 return NOTI_EX_ERROR_NONE;
902 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
906 if (handle == nullptr) {
907 LOGE("Invalid parameter");
908 return NOTI_EX_ERROR_INVALID_PARAMETER;
912 p = new (std::nothrow) GroupItem(id);
914 p = new (std::nothrow) GroupItem();
917 LOGE("Out-of-memory");
918 return NOTI_EX_ERROR_OUT_OF_MEMORY;
921 *handle = new Handle(shared_ptr<AbstractItem>(p));
923 return NOTI_EX_ERROR_NONE;
926 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
928 if (handle == nullptr) {
929 LOGE("Invalid parameter");
930 return NOTI_EX_ERROR_INVALID_PARAMETER;
932 Handle* h = static_cast<Handle*>(handle);
933 if (!h->IsValidType(AbstractItem::Group)) {
934 LOGE("Invalid handle type");
935 return NOTI_EX_ERROR_INVALID_PARAMETER;
937 GroupItem* p = static_cast<GroupItem*>(h->Get());
938 p->SetDirection(vertical);
940 return NOTI_EX_ERROR_NONE;
943 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
945 if (handle == nullptr) {
946 LOGE("Invalid parameter");
947 return NOTI_EX_ERROR_INVALID_PARAMETER;
949 Handle* h = static_cast<Handle*>(handle);
950 if (!h->IsValidType(AbstractItem::Group)) {
951 LOGE("Invalid handle type");
952 return NOTI_EX_ERROR_INVALID_PARAMETER;
954 GroupItem* p = static_cast<GroupItem*>(h->Get());
955 *vertical = p->IsVertical();
957 return NOTI_EX_ERROR_NONE;
960 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
962 if (handle == nullptr) {
963 LOGE("Invalid parameter");
964 return NOTI_EX_ERROR_INVALID_PARAMETER;
966 Handle* h = static_cast<Handle*>(handle);
967 if (!h->IsValidType(AbstractItem::Group)) {
968 LOGE("Invalid handle type");
969 return NOTI_EX_ERROR_INVALID_PARAMETER;
971 GroupItem* p = static_cast<GroupItem*>(h->Get());
972 if (!p->GetAppLabel().empty()) {
973 *label = strdup(p->GetAppLabel().c_str());
974 if (*label == nullptr) {
975 LOGE("Out-of-memory");
976 return NOTI_EX_ERROR_OUT_OF_MEMORY;
980 return NOTI_EX_ERROR_NONE;
983 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
984 noti_ex_item_h child) {
985 if (handle == nullptr || child == nullptr) {
986 LOGE("Invalid parameter");
987 return NOTI_EX_ERROR_INVALID_PARAMETER;
989 Handle* h = static_cast<Handle*>(handle);
990 if (!h->IsValidType(AbstractItem::Group)) {
991 LOGE("Invalid handle type");
992 return NOTI_EX_ERROR_INVALID_PARAMETER;
994 auto p = static_cast<GroupItem*>(h->Get());
995 p->AddChild((static_cast<Handle*>(child))->GetPtr());
997 return NOTI_EX_ERROR_NONE;
1000 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
1001 const char *item_id) {
1002 if (handle == nullptr || item_id == nullptr) {
1003 LOGE("Invalid parameter");
1004 return NOTI_EX_ERROR_INVALID_PARAMETER;
1006 Handle* h = static_cast<Handle*>(handle);
1007 if (!h->IsValidType(AbstractItem::Group)) {
1008 LOGE("Invalid handle type");
1009 return NOTI_EX_ERROR_INVALID_PARAMETER;
1011 GroupItem* p = static_cast<GroupItem*>(h->Get());
1012 p->RemoveChild(std::string(item_id));
1014 return NOTI_EX_ERROR_NONE;
1017 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
1018 noti_ex_item_group_foreach_child_cb callback, void *data) {
1019 if (handle == nullptr || callback == nullptr) {
1020 LOGE("Invalid parameter");
1021 return NOTI_EX_ERROR_INVALID_PARAMETER;
1024 Handle* h = static_cast<Handle*>(handle);
1025 if (!h->IsValidType(AbstractItem::Group)) {
1026 LOGE("Invalid handle type");
1027 return NOTI_EX_ERROR_INVALID_PARAMETER;
1029 GroupItem* p = static_cast<GroupItem*>(h->Get());
1030 list<shared_ptr<AbstractItem>> children = p->GetChildren();
1031 LOGI("Retrive (%zd)", children.size());
1032 for (auto i : children) {
1034 static_cast<noti_ex_item_h>(new Handle(i)), data);
1035 if (ret != NOTI_EX_ERROR_NONE) {
1036 LOGW("callback return (%d) stop foreach", ret);
1041 return NOTI_EX_ERROR_NONE;
1044 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1045 const char *id, const char *image_path) {
1048 if (handle == nullptr || image_path == nullptr) {
1049 LOGE("Invalid parameter");
1050 return NOTI_EX_ERROR_INVALID_PARAMETER;
1054 p = new (std::nothrow) ImageItem(id, image_path);
1056 p = new (std::nothrow) ImageItem(image_path);
1059 LOGE("Out-of-memory");
1060 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1063 *handle = new Handle(shared_ptr<AbstractItem>(p));
1065 return NOTI_EX_ERROR_NONE;
1068 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1069 noti_ex_item_h handle, char **image_path) {
1070 if (handle == nullptr || image_path == nullptr) {
1071 LOGE("Invalid parameter");
1072 return NOTI_EX_ERROR_INVALID_PARAMETER;
1074 Handle* h = static_cast<Handle*>(handle);
1075 if (!h->IsValidType(AbstractItem::Image)) {
1076 LOGE("Invalid handle type");
1077 return NOTI_EX_ERROR_INVALID_PARAMETER;
1079 ImageItem* p = static_cast<ImageItem*>(h->Get());
1080 if (!p->GetImagePath().empty()) {
1081 *image_path = strdup(p->GetImagePath().c_str());
1082 if (*image_path == nullptr) {
1083 LOGE("Out-of-memory");
1084 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1087 *image_path = nullptr;
1090 return NOTI_EX_ERROR_NONE;
1093 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1094 noti_ex_item_h *handle, const char *id) {
1095 InputSelectorItem* p;
1097 if (handle == nullptr) {
1098 LOGE("Invalid parameter");
1099 return NOTI_EX_ERROR_INVALID_PARAMETER;
1103 p = new (std::nothrow) InputSelectorItem(id);
1105 p = new (std::nothrow) InputSelectorItem();
1108 LOGE("Out-of-memory");
1109 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1112 *handle = new Handle(shared_ptr<AbstractItem>(p));
1114 return NOTI_EX_ERROR_NONE;
1117 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1118 noti_ex_item_h handle, char ***contents_list, int *count) {
1119 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1120 LOGE("Invalid parameter");
1121 return NOTI_EX_ERROR_INVALID_PARAMETER;
1124 Handle* h = static_cast<Handle*>(handle);
1125 if (!h->IsValidType(AbstractItem::InputSelector)) {
1126 LOGE("Invalid handle type");
1127 return NOTI_EX_ERROR_INVALID_PARAMETER;
1130 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1131 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1132 list<string> contents;
1133 if (arr.size() == 0) {
1134 contents = p->GetContents();
1136 for (auto& i : arr) {
1137 contents.push_back(i->GetTranslatedString());
1141 char **list = (char**)calloc(contents.size(), sizeof(char*));
1142 if (list == nullptr) {
1143 LOGE("Out of memory");
1144 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1148 for (auto& i : contents) {
1149 list[idx] = strdup(i.c_str());
1150 if (list[idx] == nullptr) {
1151 __noti_ex_free_str_array(list, idx);
1152 LOGE("Out of memory");
1153 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1158 *count = contents.size();
1159 *contents_list = list;
1161 return NOTI_EX_ERROR_NONE;
1164 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1165 noti_ex_item_h handle, const char **contents, int count) {
1166 if (handle == nullptr || contents == nullptr) {
1167 LOGE("Invalid parameter");
1168 return NOTI_EX_ERROR_INVALID_PARAMETER;
1171 list<string> new_contents;
1172 Handle* h = static_cast<Handle*>(handle);
1173 if (!h->IsValidType(AbstractItem::InputSelector)) {
1174 LOGE("Invalid handle type");
1175 return NOTI_EX_ERROR_INVALID_PARAMETER;
1177 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1178 for (int i = 0; i < count; i++) {
1179 new_contents.push_back(contents[i]);
1181 p->SetContents(move(new_contents));
1183 return NOTI_EX_ERROR_NONE;
1186 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1187 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1188 if (handle == nullptr) {
1189 LOGE("Invalid parameter");
1190 return NOTI_EX_ERROR_INVALID_PARAMETER;
1193 Handle* p = static_cast<Handle*>(handle);
1194 if (!p->IsValidType(AbstractItem::InputSelector)) {
1195 LOGE("Invalid handle type");
1196 return NOTI_EX_ERROR_INVALID_PARAMETER;
1199 vector<shared_ptr<MultiLanguage>> m_list;
1200 for (int i = 0; i < count; i++) {
1201 shared_ptr<MultiLanguage> mul_ptr =
1202 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1203 mul_ptr->UpdateString();
1204 m_list.push_back(mul_ptr);
1207 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1208 input->SetMultiLanguage(m_list);
1210 return NOTI_EX_ERROR_NONE;
1213 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1214 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1215 if (handle == nullptr) {
1216 LOGE("Invalid parameter");
1217 return NOTI_EX_ERROR_INVALID_PARAMETER;
1220 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1221 new (std::nothrow) Color(a, r, g, b));
1222 if (ptr == nullptr || ptr->get() == nullptr) {
1223 LOGE("Out-of-memory");
1224 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1229 return NOTI_EX_ERROR_NONE;
1232 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1233 if (handle == nullptr) {
1234 LOGE("Invalid parameter");
1235 return NOTI_EX_ERROR_INVALID_PARAMETER;
1238 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1241 return NOTI_EX_ERROR_NONE;
1244 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1245 unsigned char *val) {
1246 if (handle == nullptr || val == nullptr) {
1247 LOGE("Invalid parameter");
1248 return NOTI_EX_ERROR_INVALID_PARAMETER;
1251 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1252 *val = (*p)->GetAVal();
1254 return NOTI_EX_ERROR_NONE;
1257 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1258 unsigned char *val) {
1259 if (handle == nullptr || val == nullptr) {
1260 LOGE("Invalid parameter");
1261 return NOTI_EX_ERROR_INVALID_PARAMETER;
1264 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1265 *val = (*p)->GetRVal();
1267 return NOTI_EX_ERROR_NONE;
1270 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1271 unsigned char *val) {
1272 if (handle == nullptr || val == nullptr) {
1273 LOGE("Invalid parameter");
1274 return NOTI_EX_ERROR_INVALID_PARAMETER;
1277 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1278 *val = (*p)->GetGVal();
1280 return NOTI_EX_ERROR_NONE;
1283 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1284 unsigned char *val) {
1285 if (handle == nullptr || val == nullptr) {
1286 LOGE("Invalid parameter");
1287 return NOTI_EX_ERROR_INVALID_PARAMETER;
1290 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1291 *val = (*p)->GetBVal();
1293 return NOTI_EX_ERROR_NONE;
1296 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1297 int left, int top, int right, int bottom) {
1298 if (handle == nullptr) {
1299 LOGE("Invalid parameter");
1300 return NOTI_EX_ERROR_INVALID_PARAMETER;
1303 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1304 new (std::nothrow) Padding(left, top, right, bottom));
1305 if (ptr == nullptr || ptr->get() == nullptr) {
1306 LOGE("Out-of-memory");
1307 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1312 return NOTI_EX_ERROR_NONE;
1315 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1316 if (handle == nullptr) {
1317 LOGE("Invalid parameter");
1318 return NOTI_EX_ERROR_INVALID_PARAMETER;
1321 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1324 return NOTI_EX_ERROR_NONE;
1327 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1329 if (handle == nullptr || val == nullptr) {
1330 LOGE("Invalid parameter");
1331 return NOTI_EX_ERROR_INVALID_PARAMETER;
1334 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1335 *val = (*p)->GetLeft();
1337 return NOTI_EX_ERROR_NONE;
1340 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1342 if (handle == nullptr || val == nullptr) {
1343 LOGE("Invalid parameter");
1344 return NOTI_EX_ERROR_INVALID_PARAMETER;
1347 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1348 *val = (*p)->GetTop();
1350 return NOTI_EX_ERROR_NONE;
1353 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1355 if (handle == nullptr || val == nullptr) {
1356 LOGE("Invalid parameter");
1357 return NOTI_EX_ERROR_INVALID_PARAMETER;
1360 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1361 *val = (*p)->GetRight();
1363 return NOTI_EX_ERROR_NONE;
1366 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1368 if (handle == nullptr || val == nullptr) {
1369 LOGE("Invalid parameter");
1370 return NOTI_EX_ERROR_INVALID_PARAMETER;
1373 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1374 *val = (*p)->GetBottom();
1376 return NOTI_EX_ERROR_NONE;
1379 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1380 int x, int y, int w, int h) {
1381 if (handle == nullptr) {
1382 LOGE("Invalid parameter");
1383 return NOTI_EX_ERROR_INVALID_PARAMETER;
1386 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1387 new (std::nothrow) Geometry(x, y, w, h));
1388 if (ptr == nullptr || ptr->get() == nullptr) {
1389 LOGE("Out-of-memory");
1390 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1395 return NOTI_EX_ERROR_NONE;
1398 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1399 if (handle == nullptr) {
1400 LOGE("Invalid parameter");
1401 return NOTI_EX_ERROR_INVALID_PARAMETER;
1404 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1407 return NOTI_EX_ERROR_NONE;
1410 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1412 if (handle == nullptr || val == nullptr) {
1413 LOGE("Invalid parameter");
1414 return NOTI_EX_ERROR_INVALID_PARAMETER;
1417 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1418 *val = (*p)->GetX();
1420 return NOTI_EX_ERROR_NONE;
1423 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1425 if (handle == nullptr || val == nullptr) {
1426 LOGE("Invalid parameter");
1427 return NOTI_EX_ERROR_INVALID_PARAMETER;
1430 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1431 *val = (*p)->GetY();
1433 return NOTI_EX_ERROR_NONE;
1436 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1438 if (handle == nullptr || val == nullptr) {
1439 LOGE("Invalid parameter");
1440 return NOTI_EX_ERROR_INVALID_PARAMETER;
1443 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1444 *val = (*p)->GetWidth();
1446 return NOTI_EX_ERROR_NONE;
1449 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1451 if (handle == nullptr || val == nullptr) {
1452 LOGE("Invalid parameter");
1453 return NOTI_EX_ERROR_INVALID_PARAMETER;
1456 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1457 *val = (*p)->GetHeight();
1459 return NOTI_EX_ERROR_NONE;
1462 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1463 noti_ex_color_h color,
1464 noti_ex_padding_h padding,
1465 noti_ex_geometry_h geometry) {
1466 if (handle == nullptr) {
1467 LOGE("Invalid parameter");
1468 return NOTI_EX_ERROR_INVALID_PARAMETER;
1471 shared_ptr<Color> col = (color == nullptr) ?
1472 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1473 shared_ptr<Padding> padd = (padding == nullptr) ?
1474 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1475 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1476 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1478 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1479 new (std::nothrow) Style(col, padd, geo));
1480 if (ptr == nullptr || ptr->get() == nullptr) {
1481 LOGE("Out-of-memory");
1482 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1487 return NOTI_EX_ERROR_NONE;
1490 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1491 if (handle == nullptr) {
1492 LOGE("Invalid parameter");
1493 return NOTI_EX_ERROR_INVALID_PARAMETER;
1496 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1499 return NOTI_EX_ERROR_NONE;
1502 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1503 noti_ex_padding_h *padding) {
1504 if (handle == nullptr || padding == nullptr) {
1505 LOGE("Invalid parameter");
1506 return NOTI_EX_ERROR_INVALID_PARAMETER;
1509 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1510 if ((*p)->GetPadding() == nullptr) {
1511 LOGW("Padding info is null");
1512 return NOTI_EX_ERROR_INVALID_PARAMETER;
1515 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1516 new (std::nothrow) Padding(*((*p)->GetPadding())));
1517 if (padd == nullptr || padd->get() == nullptr) {
1518 LOGE("Out-of-memory");
1520 return NOTI_EX_ERROR_NONE;
1525 return NOTI_EX_ERROR_NONE;
1529 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1530 noti_ex_padding_h padding) {
1531 if (handle == nullptr) {
1532 LOGE("Invalid parameter");
1533 return NOTI_EX_ERROR_INVALID_PARAMETER;
1536 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1537 if (padding == nullptr) {
1538 (*p)->SetPadding(nullptr);
1539 return NOTI_EX_ERROR_NONE;
1542 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1543 (*p)->SetPadding(*padd);
1545 return NOTI_EX_ERROR_NONE;
1548 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1549 noti_ex_color_h *color) {
1550 if (handle == nullptr || color == nullptr) {
1551 LOGE("Invalid parameter");
1552 return NOTI_EX_ERROR_INVALID_PARAMETER;
1555 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1556 if ((*p)->GetColor() == nullptr) {
1557 LOGW("Color info is null");
1559 return NOTI_EX_ERROR_NONE;
1562 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1563 new (std::nothrow) Color(*((*p)->GetColor())));
1564 if (col == nullptr || col->get() == nullptr) {
1565 LOGE("Out-of-memory");
1566 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1571 return NOTI_EX_ERROR_NONE;
1574 extern "C" EXPORT_API int noti_ex_style_set_color(
1575 noti_ex_style_h handle, noti_ex_color_h color) {
1576 if (handle == nullptr) {
1577 LOGE("Invalid parameter");
1578 return NOTI_EX_ERROR_INVALID_PARAMETER;
1581 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1582 if (color == nullptr) {
1583 (*p)->SetColor(nullptr);
1584 return NOTI_EX_ERROR_NONE;
1587 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1588 (*p)->SetColor(*col);
1590 return NOTI_EX_ERROR_NONE;
1593 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1594 noti_ex_geometry_h *geometry) {
1595 if (handle == nullptr || geometry == nullptr) {
1596 LOGE("Invalid parameter");
1597 return NOTI_EX_ERROR_INVALID_PARAMETER;
1600 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1601 if ((*p)->GetGeometry() == nullptr) {
1602 LOGW("Geometry info is null");
1603 *geometry = nullptr;
1604 return NOTI_EX_ERROR_NONE;
1607 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1608 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1609 if (geo == nullptr || geo->get() == nullptr) {
1610 LOGE("Out-of-memory");
1611 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1616 return NOTI_EX_ERROR_NONE;
1619 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1620 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1621 if (handle == nullptr) {
1622 LOGE("Invalid parameter");
1623 return NOTI_EX_ERROR_INVALID_PARAMETER;
1626 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1627 if (geometry == nullptr) {
1628 (*p)->SetGeometry(nullptr);
1629 return NOTI_EX_ERROR_NONE;
1632 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1633 (*p)->SetGeometry(*geo);
1635 return NOTI_EX_ERROR_NONE;
1638 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1639 noti_ex_style_h handle, char** background_image) {
1640 if (handle == nullptr || background_image == nullptr) {
1641 LOGE("Invalid parameter");
1642 return NOTI_EX_ERROR_INVALID_PARAMETER;
1645 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1647 if ((*p)->GetBackgroundImage().empty())
1648 *background_image = nullptr;
1650 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1652 return NOTI_EX_ERROR_NONE;
1655 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1656 noti_ex_style_h handle, char* background_image) {
1657 if (handle == nullptr) {
1658 LOGE("Invalid parameter");
1659 return NOTI_EX_ERROR_INVALID_PARAMETER;
1662 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1663 if (background_image == nullptr)
1664 (*p)->SetBackgroundImage("");
1666 (*p)->SetBackgroundImage(background_image);
1668 return NOTI_EX_ERROR_NONE;
1671 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1672 noti_ex_style_h handle, noti_ex_color_h* color) {
1673 if (handle == nullptr || color == nullptr) {
1674 LOGE("Invalid parameter");
1675 return NOTI_EX_ERROR_INVALID_PARAMETER;
1678 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1679 if ((*p)->GetBackgroundColor() == nullptr) {
1680 LOGW("Color info is null");
1682 return NOTI_EX_ERROR_NONE;
1685 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1686 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1687 if (col == nullptr || col->get() == nullptr) {
1688 LOGE("Out-of-memory");
1689 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1694 return NOTI_EX_ERROR_NONE;
1697 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1698 noti_ex_style_h handle, noti_ex_color_h color) {
1699 if (handle == nullptr) {
1700 LOGE("Invalid parameter");
1701 return NOTI_EX_ERROR_INVALID_PARAMETER;
1704 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1705 if (color == nullptr) {
1706 (*p)->SetBackgroundColor(nullptr);
1707 return NOTI_EX_ERROR_NONE;
1710 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1711 (*p)->SetBackgroundColor(*col);
1713 return NOTI_EX_ERROR_NONE;
1716 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1717 noti_ex_color_h color) {
1718 if (handle == nullptr || color == nullptr) {
1719 LOGE("Invalid parameter");
1720 return NOTI_EX_ERROR_INVALID_PARAMETER;
1723 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1724 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1725 new (std::nothrow) LEDInfo(*color_ptr));
1727 LOGE("Out-of-memory");
1728 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1733 return NOTI_EX_ERROR_NONE;
1736 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1737 if (handle == nullptr) {
1738 LOGE("Invalid parameter");
1739 return NOTI_EX_ERROR_INVALID_PARAMETER;
1742 shared_ptr<LEDInfo>* led_ptr =
1743 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1745 return NOTI_EX_ERROR_NONE;
1748 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1749 noti_ex_led_info_h handle, int ms) {
1750 if (handle == nullptr) {
1751 LOGE("Invalid parameter");
1752 return NOTI_EX_ERROR_INVALID_PARAMETER;
1755 shared_ptr<LEDInfo>* led_ptr =
1756 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1757 (*led_ptr)->SetOnPeriod(ms);
1759 return NOTI_EX_ERROR_NONE;
1762 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1763 noti_ex_led_info_h handle, int *ms) {
1764 if (handle == nullptr || ms == nullptr) {
1765 LOGE("Invalid parameter");
1766 return NOTI_EX_ERROR_INVALID_PARAMETER;
1769 shared_ptr<LEDInfo>* led_ptr =
1770 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1771 *ms = (*led_ptr)->GetOnPeriod();
1773 return NOTI_EX_ERROR_NONE;
1776 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1777 noti_ex_led_info_h handle, int ms) {
1778 if (handle == nullptr) {
1779 LOGE("Invalid parameter");
1780 return NOTI_EX_ERROR_INVALID_PARAMETER;
1783 shared_ptr<LEDInfo>* led_ptr =
1784 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1785 (*led_ptr)->SetOffPeriod(ms);
1787 return NOTI_EX_ERROR_NONE;
1790 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1791 noti_ex_led_info_h handle, int *ms) {
1792 if (handle == nullptr) {
1793 LOGE("Invalid parameter");
1794 return NOTI_EX_ERROR_INVALID_PARAMETER;
1797 shared_ptr<LEDInfo>* led_ptr =
1798 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1799 *ms = (*led_ptr)->GetOffPeriod();
1801 return NOTI_EX_ERROR_NONE;
1804 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1805 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1806 if (handle == nullptr) {
1807 LOGE("Invalid parameter");
1808 return NOTI_EX_ERROR_INVALID_PARAMETER;
1811 shared_ptr<LEDInfo>* led_ptr =
1812 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1813 if ((*led_ptr)->GetColor() == nullptr) {
1814 LOGW("Color is null");
1816 return NOTI_EX_ERROR_NONE;
1819 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1820 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1821 if (col == nullptr || col->get() == nullptr) {
1822 LOGE("Out-of-memory");
1823 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1828 return NOTI_EX_ERROR_NONE;
1831 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1832 noti_ex_led_info_h handle, noti_ex_color_h color) {
1833 if (handle == nullptr) {
1834 LOGE("Invalid parameter");
1835 return NOTI_EX_ERROR_INVALID_PARAMETER;
1838 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1839 if (color == nullptr) {
1840 (*p)->SetColor(nullptr);
1841 return NOTI_EX_ERROR_NONE;
1844 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1845 (*p)->SetColor(*col);
1847 return NOTI_EX_ERROR_NONE;
1850 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1851 if (handle == nullptr) {
1852 LOGE("Invalid parameter");
1853 return NOTI_EX_ERROR_INVALID_PARAMETER;
1856 shared_ptr<AbstractAction>* ptr =
1857 static_cast<shared_ptr<AbstractAction>*>(handle);
1860 return NOTI_EX_ERROR_NONE;
1863 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1865 if (handle == nullptr || type == nullptr) {
1866 LOGE("Invalid parameter");
1867 return NOTI_EX_ERROR_INVALID_PARAMETER;
1870 shared_ptr<AbstractAction>* ptr =
1871 static_cast<shared_ptr<AbstractAction>*>(handle);
1872 *type = (*ptr)->GetType();
1874 return NOTI_EX_ERROR_NONE;
1877 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1879 if (handle == nullptr || local == nullptr) {
1880 LOGE("Invalid parameter");
1881 return NOTI_EX_ERROR_INVALID_PARAMETER;
1884 shared_ptr<AbstractAction>* ptr =
1885 static_cast<shared_ptr<AbstractAction>*>(handle);
1886 *local = (*ptr)->IsLocal();
1888 return NOTI_EX_ERROR_NONE;
1891 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1892 noti_ex_item_h item) {
1893 if (handle == nullptr || item == nullptr) {
1894 LOGE("Invalid parameter");
1895 return NOTI_EX_ERROR_INVALID_PARAMETER;
1897 shared_ptr<AbstractAction>* ptr =
1898 static_cast<shared_ptr<AbstractAction>*>(handle);
1899 Handle* ih = static_cast<Handle*>(item);
1900 (*ptr)->Execute(ih->GetPtr());
1902 return NOTI_EX_ERROR_NONE;
1905 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1907 if (handle == nullptr || extra == nullptr) {
1908 LOGE("Invalid parameter");
1909 return NOTI_EX_ERROR_INVALID_PARAMETER;
1912 shared_ptr<AbstractAction>* ptr =
1913 static_cast<shared_ptr<AbstractAction>*>(handle);
1914 if (!(*ptr)->GetExtra().empty()) {
1915 *extra = strdup((*ptr)->GetExtra().c_str());
1916 if (*extra == nullptr) {
1917 LOGE("Out-of-memory");
1918 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1924 return NOTI_EX_ERROR_NONE;
1927 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1928 noti_ex_item_info_h handle, int *hide_time) {
1929 if (handle == nullptr || hide_time == nullptr) {
1930 LOGE("Invalid parameter");
1931 return NOTI_EX_ERROR_INVALID_PARAMETER;
1933 IItemInfo* p = static_cast<IItemInfo*>(handle);
1934 *hide_time = p->GetHideTime();
1935 return NOTI_EX_ERROR_NONE;
1938 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1939 noti_ex_item_info_h handle, int hide_time) {
1940 if (handle == nullptr) {
1941 LOGE("Invalid parameter");
1942 return NOTI_EX_ERROR_INVALID_PARAMETER;
1944 IItemInfo* p = static_cast<IItemInfo*>(handle);
1945 p->SetHideTime(hide_time);
1946 return NOTI_EX_ERROR_NONE;
1949 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1950 noti_ex_item_info_h handle, int *delete_time) {
1951 if (handle == nullptr || delete_time == nullptr) {
1952 LOGE("Invalid parameter");
1953 return NOTI_EX_ERROR_INVALID_PARAMETER;
1955 IItemInfo* p = static_cast<IItemInfo*>(handle);
1956 *delete_time = p->GetDeleteTime();
1957 return NOTI_EX_ERROR_NONE;
1960 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1961 noti_ex_item_info_h handle, int delete_time) {
1962 if (handle == nullptr) {
1963 LOGE("Invalid parameter");
1964 return NOTI_EX_ERROR_INVALID_PARAMETER;
1966 IItemInfo* p = static_cast<IItemInfo*>(handle);
1967 p->SetDeleteTime(delete_time);
1968 return NOTI_EX_ERROR_NONE;
1971 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1972 noti_ex_item_info_h handle, time_t *time) {
1973 if (handle == nullptr || time == nullptr) {
1974 LOGE("Invalid parameter");
1975 return NOTI_EX_ERROR_INVALID_PARAMETER;
1978 IItemInfo* p = static_cast<IItemInfo*>(handle);
1979 *time = p->GetTime();
1980 return NOTI_EX_ERROR_NONE;
1983 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1984 if (handle == nullptr) {
1985 LOGE("Invalid parameter");
1986 return NOTI_EX_ERROR_INVALID_PARAMETER;
1989 Handle* h = static_cast<Handle*>(handle);
1991 return NOTI_EX_ERROR_NONE;
1994 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1995 const char *id, noti_ex_item_h *item) {
1996 if (handle == nullptr) {
1997 LOGE("Invalid parameter");
1998 return NOTI_EX_ERROR_INVALID_PARAMETER;
2001 Handle* p = static_cast<Handle*>(handle);
2002 AbstractItem& find_item = p->Get()->FindByID(string(id));
2003 if (find_item.GetType() == AbstractItem::NullObject) {
2004 LOGW("Not exist ID");
2006 return NOTI_EX_ERROR_NONE;
2009 *item = new Handle(&find_item);
2010 return NOTI_EX_ERROR_NONE;
2013 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2015 if (handle == nullptr || type == nullptr) {
2016 LOGE("Invalid parameter");
2017 return NOTI_EX_ERROR_INVALID_PARAMETER;
2020 Handle* h = static_cast<Handle*>(handle);
2021 AbstractItem* p = h->Get();
2022 *type = p->GetType();
2023 return NOTI_EX_ERROR_NONE;
2026 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2028 if (handle == nullptr || id == nullptr) {
2029 LOGE("Invalid parameter");
2030 return NOTI_EX_ERROR_INVALID_PARAMETER;
2032 Handle* h = static_cast<Handle*>(handle);
2033 AbstractItem* p = h->Get();
2034 *id = strdup(p->GetId().c_str());
2035 return NOTI_EX_ERROR_NONE;
2038 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2040 if (handle == nullptr || id == nullptr) {
2041 LOGE("Invalid parameter");
2042 return NOTI_EX_ERROR_INVALID_PARAMETER;
2044 Handle* p = static_cast<Handle*>(handle);
2045 p->Get()->SetId(id);
2046 return NOTI_EX_ERROR_NONE;
2049 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2050 noti_ex_action_h *action) {
2051 if (handle == nullptr || action == nullptr) {
2052 LOGE("Invalid parameter");
2053 return NOTI_EX_ERROR_INVALID_PARAMETER;
2055 Handle* p = static_cast<Handle*>(handle);
2056 if (p->Get()->GetAction() == nullptr) {
2058 return NOTI_EX_ERROR_NONE;
2060 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2061 p->Get()->GetAction()));
2063 return NOTI_EX_ERROR_NONE;
2066 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2067 noti_ex_action_h action) {
2068 if (handle == nullptr) {
2069 LOGE("Invalid parameter");
2070 return NOTI_EX_ERROR_INVALID_PARAMETER;
2073 Handle* p = static_cast<Handle*>(handle);
2074 if (action == nullptr) {
2075 p->Get()->SetAction(nullptr);
2076 return NOTI_EX_ERROR_NONE;
2079 shared_ptr<AbstractAction>* ptr =
2080 static_cast<shared_ptr<AbstractAction>*>(action);
2081 p->Get()->SetAction(*ptr);
2082 return NOTI_EX_ERROR_NONE;
2085 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2086 noti_ex_style_h *style) {
2087 if (handle == nullptr || style == nullptr) {
2088 LOGE("Invalid parameter");
2089 return NOTI_EX_ERROR_INVALID_PARAMETER;
2092 Handle* p = static_cast<Handle*>(handle);
2093 shared_ptr<Style> s = p->Get()->GetStyle();
2094 if (s.get() == nullptr) {
2095 LOGW("Style is null");
2097 return NOTI_EX_ERROR_NONE;
2100 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2101 if (ptr == nullptr || ptr->get() == nullptr) {
2102 LOGE("Out of memory");
2103 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2107 return NOTI_EX_ERROR_NONE;
2110 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2111 noti_ex_style_h style) {
2112 if (handle == nullptr) {
2113 LOGE("Invalid parameter");
2114 return NOTI_EX_ERROR_INVALID_PARAMETER;
2117 Handle* p = static_cast<Handle*>(handle);
2118 if (style == nullptr) {
2119 p->Get()->SetStyle(nullptr);
2120 return NOTI_EX_ERROR_NONE;
2123 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2124 p->Get()->SetStyle(*s);
2125 return NOTI_EX_ERROR_NONE;
2128 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2130 if (handle == nullptr) {
2131 LOGE("Invalid parameter");
2132 return NOTI_EX_ERROR_INVALID_PARAMETER;
2135 Handle* p = static_cast<Handle*>(handle);
2136 p->Get()->SetVisible(visible);
2137 return NOTI_EX_ERROR_NONE;
2140 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2142 if (handle == nullptr || visible == nullptr) {
2143 LOGE("Invalid parameter");
2144 return NOTI_EX_ERROR_INVALID_PARAMETER;
2147 Handle* p = static_cast<Handle*>(handle);
2148 *visible = p->Get()->GetVisible();
2149 return NOTI_EX_ERROR_NONE;
2152 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2154 if (handle == nullptr) {
2155 LOGE("Invalid parameter");
2156 return NOTI_EX_ERROR_INVALID_PARAMETER;
2159 Handle* p = static_cast<Handle*>(handle);
2160 p->Get()->SetEnable(enable);
2161 return NOTI_EX_ERROR_NONE;
2164 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2166 if (handle == nullptr || enable == nullptr) {
2167 LOGE("Invalid parameter");
2168 return NOTI_EX_ERROR_INVALID_PARAMETER;
2171 Handle* p = static_cast<Handle*>(handle);
2172 *enable = p->Get()->GetEnable();
2173 return NOTI_EX_ERROR_NONE;
2176 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2177 const char *receiver_group) {
2178 if (handle == nullptr || receiver_group == nullptr) {
2179 LOGE("Invalid parameter");
2180 return NOTI_EX_ERROR_INVALID_PARAMETER;
2183 Handle* p = static_cast<Handle*>(handle);
2184 p->Get()->AddReceiver(receiver_group);
2185 return NOTI_EX_ERROR_NONE;
2188 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2189 const char *receiver_group) {
2190 if (handle == nullptr || receiver_group == nullptr) {
2191 LOGE("Invalid parameter");
2192 return NOTI_EX_ERROR_INVALID_PARAMETER;
2195 Handle* p = static_cast<Handle*>(handle);
2196 p->Get()->RemoveReceiver(receiver_group);
2197 return NOTI_EX_ERROR_NONE;
2200 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2201 char ***receiver_list, int *count) {
2202 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2203 LOGE("Invalid parameter");
2204 return NOTI_EX_ERROR_INVALID_PARAMETER;
2207 Handle* p = static_cast<Handle*>(handle);
2208 list<string> receivers = p->Get()->GetReceiverList();
2209 if (receivers.size() == 0) {
2210 *receiver_list = nullptr;
2212 return NOTI_EX_ERROR_NONE;
2215 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2216 if (tmp_list == nullptr) {
2217 LOGE("Out of memory");
2218 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2222 for (auto& i : receivers) {
2223 tmp_list[idx] = strdup(i.c_str());
2224 if (tmp_list[idx] == nullptr) {
2225 __noti_ex_free_str_array(tmp_list, idx);
2226 LOGE("Out of memory");
2227 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2232 *receiver_list = tmp_list;
2233 *count = receivers.size();
2234 return NOTI_EX_ERROR_NONE;
2237 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2239 if (handle == nullptr) {
2240 LOGE("Invalid parameter");
2241 return NOTI_EX_ERROR_INVALID_PARAMETER;
2244 Handle* p = static_cast<Handle*>(handle);
2245 p->Get()->SetPolicy(policy);
2246 return NOTI_EX_ERROR_NONE;
2249 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2251 if (handle == nullptr || policy == nullptr) {
2252 LOGE("Invalid parameter");
2253 return NOTI_EX_ERROR_INVALID_PARAMETER;
2256 Handle* p = static_cast<Handle*>(handle);
2257 *policy = p->Get()->GetPolicy();
2258 return NOTI_EX_ERROR_NONE;
2261 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2263 if (handle == nullptr || channel == nullptr) {
2264 LOGE("Invalid parameter");
2265 return NOTI_EX_ERROR_INVALID_PARAMETER;
2268 Handle* p = static_cast<Handle*>(handle);
2269 if (!p->Get()->GetChannel().empty())
2270 *channel = strdup(p->Get()->GetChannel().c_str());
2274 return NOTI_EX_ERROR_NONE;
2277 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2278 const char *channel) {
2279 if (handle == nullptr) {
2280 LOGE("Invalid parameter");
2281 return NOTI_EX_ERROR_INVALID_PARAMETER;
2284 Handle* p = static_cast<Handle*>(handle);
2285 p->Get()->SetChannel(channel);
2286 return NOTI_EX_ERROR_NONE;
2289 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2290 noti_ex_led_info_h led) {
2291 if (handle == nullptr) {
2292 LOGE("Invalid parameter");
2293 return NOTI_EX_ERROR_INVALID_PARAMETER;
2296 Handle* p = static_cast<Handle*>(handle);
2297 if (led == nullptr) {
2298 p->Get()->SetLEDInfo(nullptr);
2299 return NOTI_EX_ERROR_NONE;
2301 shared_ptr<LEDInfo>* led_ptr =
2302 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2303 p->Get()->SetLEDInfo(*led_ptr);
2304 return NOTI_EX_ERROR_NONE;
2307 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2308 noti_ex_led_info_h *led) {
2309 if (handle == nullptr) {
2310 LOGE("Invalid parameter");
2311 return NOTI_EX_ERROR_INVALID_PARAMETER;
2314 Handle* p = static_cast<Handle*>(handle);
2315 if (p->Get()->GetLEDInfo() != nullptr)
2316 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2319 return NOTI_EX_ERROR_NONE;
2322 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2324 if (handle == nullptr) {
2325 LOGE("Invalid parameter");
2326 return NOTI_EX_ERROR_INVALID_PARAMETER;
2329 Handle* p = static_cast<Handle*>(handle);
2330 if (path == nullptr)
2331 p->Get()->SetSoundPath("");
2333 p->Get()->SetSoundPath(path);
2334 return NOTI_EX_ERROR_NONE;
2337 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2339 if (handle == nullptr) {
2340 LOGE("Invalid parameter");
2341 return NOTI_EX_ERROR_INVALID_PARAMETER;
2344 Handle* p = static_cast<Handle*>(handle);
2345 if (path == nullptr)
2346 p->Get()->SetVibrationPath("");
2348 p->Get()->SetVibrationPath(path);
2349 return NOTI_EX_ERROR_NONE;
2352 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2354 if (handle == nullptr || path == nullptr) {
2355 LOGE("Invalid parameter");
2356 return NOTI_EX_ERROR_INVALID_PARAMETER;
2359 Handle* p = static_cast<Handle*>(handle);
2360 if (p->Get()->GetSoundPath().empty())
2363 *path = strdup(p->Get()->GetSoundPath().c_str());
2364 return NOTI_EX_ERROR_NONE;
2367 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2369 if (handle == nullptr || path == nullptr) {
2370 LOGE("Invalid parameter");
2371 return NOTI_EX_ERROR_INVALID_PARAMETER;
2374 Handle* p = static_cast<Handle*>(handle);
2375 if (p->Get()->GetVibrationPath().empty())
2378 *path = strdup(p->Get()->GetVibrationPath().c_str());
2379 return NOTI_EX_ERROR_NONE;
2382 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2383 noti_ex_item_info_h *info) {
2384 if (handle == nullptr || info == nullptr) {
2385 LOGE("Invalid parameter");
2386 return NOTI_EX_ERROR_INVALID_PARAMETER;
2389 Handle* p = static_cast<Handle*>(handle);
2390 if (p->Get()->GetInfo() == nullptr)
2393 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2394 return NOTI_EX_ERROR_NONE;
2397 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2399 if (handle == nullptr || id == nullptr) {
2400 LOGE("Invalid parameter");
2401 return NOTI_EX_ERROR_INVALID_PARAMETER;
2404 Handle* p = static_cast<Handle*>(handle);
2405 if (p->Get()->GetSenderAppId().empty())
2408 *id = strdup(p->Get()->GetSenderAppId().c_str());
2409 return NOTI_EX_ERROR_NONE;
2412 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2414 if (handle == nullptr || tag == nullptr) {
2415 LOGE("Invalid parameter");
2416 return NOTI_EX_ERROR_INVALID_PARAMETER;
2419 Handle* p = static_cast<Handle*>(handle);
2420 if (p->Get()->GetTag().empty())
2423 *tag = strdup(p->Get()->GetTag().c_str());
2424 return NOTI_EX_ERROR_NONE;
2427 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2429 if (handle == nullptr) {
2430 LOGE("Invalid parameter");
2431 return NOTI_EX_ERROR_INVALID_PARAMETER;
2434 Handle* p = static_cast<Handle*>(handle);
2436 p->Get()->SetTag("");
2438 p->Get()->SetTag(tag);
2439 return NOTI_EX_ERROR_NONE;
2442 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2444 if (handle == nullptr || ongoing == nullptr) {
2445 LOGE("Invalid parameter");
2446 return NOTI_EX_ERROR_INVALID_PARAMETER;
2449 Handle* p = static_cast<Handle*>(handle);
2450 *ongoing = p->Get()->GetOnGoingState();
2452 return NOTI_EX_ERROR_NONE;
2455 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2457 if (handle == nullptr) {
2458 LOGE("Invalid parameter");
2459 return NOTI_EX_ERROR_INVALID_PARAMETER;
2462 Handle* p = static_cast<Handle*>(handle);
2463 p->Get()->SetOnGoingState(ongoing);
2465 return NOTI_EX_ERROR_NONE;
2468 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2469 int type, bool* exist) {
2470 if (handle == nullptr || exist == nullptr) {
2471 LOGE("Invalid parameter");
2472 return NOTI_EX_ERROR_INVALID_PARAMETER;
2475 Handle* p = static_cast<Handle*>(handle);
2476 *exist = p->Get()->IsItemTypeExist(type);
2478 return NOTI_EX_ERROR_NONE;
2481 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2483 if (handle == nullptr || type == nullptr) {
2484 LOGE("Invalid parameter");
2485 return NOTI_EX_ERROR_INVALID_PARAMETER;
2488 Handle* p = static_cast<Handle*>(handle);
2489 *type = p->Get()->GetMainType();
2491 return NOTI_EX_ERROR_NONE;
2494 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2495 const char* id, int type) {
2496 if (handle == nullptr || id == nullptr) {
2497 LOGE("Invalid parameter");
2498 return NOTI_EX_ERROR_INVALID_PARAMETER;
2501 Handle* p = static_cast<Handle*>(handle);
2502 if (!(p->Get()->SetMainType(string(id),
2503 static_cast<AbstractItem::MainType>(type))))
2504 return NOTI_EX_ERROR_INVALID_PARAMETER;
2506 return NOTI_EX_ERROR_NONE;
2509 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2510 int type, noti_ex_item_h* item) {
2511 if (handle == nullptr || item == nullptr) {
2512 LOGE("Invalid parameter");
2513 return NOTI_EX_ERROR_INVALID_PARAMETER;
2516 Handle* h = static_cast<Handle*>(handle);
2517 if (!h->IsValidType(AbstractItem::Group)) {
2518 LOGE("Invalid handle type");
2519 return NOTI_EX_ERROR_INVALID_PARAMETER;
2522 GroupItem* p = static_cast<GroupItem*>(h->Get());
2523 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2524 if (find_item.GetType() == AbstractItem::NullObject) {
2525 LOGW("Not exist ID");
2527 return NOTI_EX_ERROR_NONE;
2529 *item = new Handle(&find_item);
2531 return NOTI_EX_ERROR_NONE;
2534 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2535 const char *key, bundle **value) {
2536 if (handle == nullptr || key == nullptr || value == nullptr) {
2537 LOGE("Invalid handle type");
2538 return NOTI_EX_ERROR_INVALID_PARAMETER;
2541 Handle* p = static_cast<Handle*>(handle);
2543 Bundle b = p->Get()->GetExtensionData(key);
2544 if (b.GetCount() == 0)
2547 *value = bundle_dup(b.GetHandle());
2549 return NOTI_EX_ERROR_NONE;
2552 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2553 const char *key, bundle *value) {
2554 if (handle == nullptr || key == nullptr || value == nullptr) {
2555 LOGE("Invalid handle type");
2556 return NOTI_EX_ERROR_INVALID_PARAMETER;
2559 Bundle b = Bundle(value);
2561 Handle* p = static_cast<Handle*>(handle);
2562 p->Get()->SetExtensionData(key, b);
2564 return NOTI_EX_ERROR_NONE;
2567 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2568 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2570 if (handle == nullptr) {
2571 LOGE("Invalid parameter");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2575 string receiver_group_str = "";
2577 receiver_group_str = string(receiver_group);
2579 ManagerStub* stub = new (std::nothrow) ManagerStub(
2580 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2581 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2582 receiver_group_str);
2583 if (stub == nullptr) {
2584 LOGE("Fail to create manager");
2585 return NOTI_EX_ERROR_IO_ERROR;
2587 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2588 new ManagerCallbackInfo(event_callbacks, data)));
2589 *handle = static_cast<noti_ex_manager_h>(stub);
2591 return NOTI_EX_ERROR_NONE;
2594 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2595 if (handle == nullptr) {
2596 LOGE("Invalid parameter");
2597 return NOTI_EX_ERROR_INVALID_PARAMETER;
2599 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2601 return NOTI_EX_ERROR_NONE;
2604 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2605 noti_ex_item_h **items, int *count) {
2606 if (handle == nullptr || items == nullptr || count == nullptr) {
2607 LOGE("Invalid parameter");
2608 return NOTI_EX_ERROR_INVALID_PARAMETER;
2612 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2613 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2614 if (item_list.size() == 0) {
2617 return NOTI_EX_ERROR_NONE;
2619 noti_ex_item_h* added_item =
2620 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2621 if (added_item == nullptr) {
2622 LOGE("Fail to create items");
2623 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2627 for (auto& i : item_list) {
2628 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2630 *items = added_item;
2631 *count = item_list.size();
2632 } catch (Exception &ex) {
2633 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2634 return NOTI_EX_ERROR_IO_ERROR;
2636 return NOTI_EX_ERROR_NONE;
2639 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2640 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2641 if (handle == nullptr || channel == nullptr ||
2642 items == nullptr || count == nullptr) {
2643 LOGE("Invalid parameter");
2644 return NOTI_EX_ERROR_INVALID_PARAMETER;
2648 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2649 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2650 if (item_list.size() == 0) {
2653 return NOTI_EX_ERROR_NONE;
2655 noti_ex_item_h* added_item =
2656 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2657 if (added_item == nullptr) {
2658 LOGE("Fail to create items");
2659 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2663 for (auto& i : item_list) {
2664 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2666 *items = added_item;
2667 *count = item_list.size();
2668 } catch (Exception &ex) {
2669 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2670 return NOTI_EX_ERROR_IO_ERROR;
2673 return NOTI_EX_ERROR_NONE;
2676 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2677 noti_ex_item_h noti, int *request_id) {
2678 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2679 LOGE("Invalid parameter");
2680 return NOTI_EX_ERROR_INVALID_PARAMETER;
2683 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2684 Handle* sp = static_cast<Handle*>(noti);
2685 if (sp->GetPtr().get() == nullptr) {
2686 LOGE("Invalid noti reference can not be sended");
2687 return NOTI_EX_ERROR_INVALID_PARAMETER;
2689 *request_id = stub->Update(sp->GetPtr());
2691 } catch (Exception &ex) {
2692 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2693 return NOTI_EX_ERROR_IO_ERROR;
2695 return NOTI_EX_ERROR_NONE;
2698 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2699 noti_ex_item_h noti, int *request_id) {
2700 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2701 LOGE("Invalid parameter");
2702 return NOTI_EX_ERROR_INVALID_PARAMETER;
2705 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2706 Handle* item = static_cast<Handle*>(noti);
2707 if (item->GetPtr().get() == nullptr) {
2708 LOGE("Invalid noti reference can not be sended");
2709 return NOTI_EX_ERROR_INVALID_PARAMETER;
2711 *request_id = stub->Delete(item->GetPtr());
2713 } catch (Exception &ex) {
2714 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2715 return NOTI_EX_ERROR_IO_ERROR;
2717 return NOTI_EX_ERROR_NONE;
2720 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2722 if (handle == nullptr || request_id == nullptr) {
2723 LOGE("Invalid parameter");
2724 return NOTI_EX_ERROR_INVALID_PARAMETER;
2727 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2728 *request_id = stub->DeleteAll();
2729 } catch (Exception &ex) {
2730 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2731 return NOTI_EX_ERROR_IO_ERROR;
2733 return NOTI_EX_ERROR_NONE;
2736 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2737 noti_ex_manager_h handle, const char* channel, int* request_id) {
2738 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2739 LOGE("Invalid parameter");
2740 return NOTI_EX_ERROR_INVALID_PARAMETER;
2744 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2745 *request_id = stub->DeleteByChannel(channel);
2746 } catch (Exception &ex) {
2747 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2748 return NOTI_EX_ERROR_IO_ERROR;
2751 return NOTI_EX_ERROR_NONE;
2754 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2755 noti_ex_manager_h handle, const char* app_id, int* request_id) {
2756 if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2757 LOGE("Invalid parameter");
2758 return NOTI_EX_ERROR_INVALID_PARAMETER;
2762 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2763 *request_id = stub->DeleteByAppId(app_id);
2764 } catch (Exception &ex) {
2765 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2766 return NOTI_EX_ERROR_IO_ERROR;
2769 return NOTI_EX_ERROR_NONE;
2772 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2773 noti_ex_item_h noti, int *request_id) {
2774 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2775 LOGE("Invalid parameter");
2776 return NOTI_EX_ERROR_INVALID_PARAMETER;
2779 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2780 Handle* item = static_cast<Handle*>(noti);
2781 if (item->GetPtr().get() == nullptr) {
2782 LOGE("Invalid noti reference can not be sended");
2783 return NOTI_EX_ERROR_INVALID_PARAMETER;
2785 *request_id = stub->Hide(item->GetPtr());
2787 } catch (Exception &ex) {
2788 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2789 return NOTI_EX_ERROR_IO_ERROR;
2791 return NOTI_EX_ERROR_NONE;
2794 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2795 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2796 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2797 LOGE("Invalid parameter");
2798 return NOTI_EX_ERROR_INVALID_PARAMETER;
2801 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2802 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2803 if (ptr == nullptr) {
2804 LOGW("Not exist ID");
2806 return NOTI_EX_ERROR_NONE;
2808 *item = new Handle(ptr);
2809 } catch (Exception &ex) {
2810 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2811 return NOTI_EX_ERROR_IO_ERROR;
2813 return NOTI_EX_ERROR_NONE;
2816 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2817 noti_ex_event_info_h info, noti_ex_error_e error) {
2818 if (handle == nullptr || info == nullptr) {
2819 LOGE("Invalid parameter");
2820 return NOTI_EX_ERROR_INVALID_PARAMETER;
2823 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2824 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2825 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2826 static_cast<NotificationError>(error));
2827 } catch (Exception &ex) {
2828 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2829 return NOTI_EX_ERROR_IO_ERROR;
2831 return NOTI_EX_ERROR_NONE;
2834 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2835 noti_ex_manager_h handle, int *cnt) {
2837 if (handle == nullptr || cnt == nullptr) {
2838 LOGE("Invalid parameter");
2839 return NOTI_EX_ERROR_INVALID_PARAMETER;
2842 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2843 *cnt = stub->GetCount();
2844 } catch (Exception &ex) {
2845 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2846 return NOTI_EX_ERROR_IO_ERROR;
2848 return NOTI_EX_ERROR_NONE;
2851 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2852 const char *id, float min, float current, float max) {
2855 if (handle == nullptr) {
2856 LOGE("Invalid parameter");
2857 return NOTI_EX_ERROR_INVALID_PARAMETER;
2861 p = new (std::nothrow) ProgressItem(id, min, current, max);
2863 p = new (std::nothrow) ProgressItem(min, current, max);
2866 LOGE("Out-of-memory");
2867 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2870 *handle = new Handle(shared_ptr<AbstractItem>(p));
2872 return NOTI_EX_ERROR_NONE;
2875 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2876 noti_ex_item_h handle, float *current) {
2877 if (handle == nullptr || current == nullptr) {
2878 LOGE("Invalid parameter");
2879 return NOTI_EX_ERROR_INVALID_PARAMETER;
2882 Handle *h = static_cast<Handle*>(handle);
2883 if (!h->IsValidType(AbstractItem::Progress)) {
2884 LOGE("Invalid handle type");
2885 return NOTI_EX_ERROR_INVALID_PARAMETER;
2887 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2888 *current = p->GetCurrent();
2890 return NOTI_EX_ERROR_NONE;
2893 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2894 noti_ex_item_h handle, float current) {
2895 if (handle == nullptr) {
2896 LOGE("Invalid parameter");
2897 return NOTI_EX_ERROR_INVALID_PARAMETER;
2900 Handle *h = static_cast<Handle*>(handle);
2901 if (!h->IsValidType(AbstractItem::Progress)) {
2902 LOGE("Invalid handle type");
2903 return NOTI_EX_ERROR_INVALID_PARAMETER;
2905 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2906 p->SetCurrent(current);
2908 return NOTI_EX_ERROR_NONE;
2911 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2913 if (handle == nullptr || min == nullptr) {
2914 LOGE("Invalid parameter");
2915 return NOTI_EX_ERROR_INVALID_PARAMETER;
2918 Handle *h = static_cast<Handle*>(handle);
2919 if (!h->IsValidType(AbstractItem::Progress)) {
2920 LOGE("Invalid handle type");
2921 return NOTI_EX_ERROR_INVALID_PARAMETER;
2923 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2926 return NOTI_EX_ERROR_NONE;
2929 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2931 if (handle == nullptr || max == nullptr) {
2932 LOGE("Invalid parameter");
2933 return NOTI_EX_ERROR_INVALID_PARAMETER;
2936 Handle *h = static_cast<Handle*>(handle);
2937 if (!h->IsValidType(AbstractItem::Progress)) {
2938 LOGE("Invalid handle type");
2939 return NOTI_EX_ERROR_INVALID_PARAMETER;
2941 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2944 return NOTI_EX_ERROR_NONE;
2947 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2949 if (handle == nullptr || type == nullptr) {
2950 LOGE("Invalid parameter");
2951 return NOTI_EX_ERROR_INVALID_PARAMETER;
2954 Handle *h = static_cast<Handle*>(handle);
2955 if (!h->IsValidType(AbstractItem::Progress)) {
2956 LOGE("Invalid handle type");
2957 return NOTI_EX_ERROR_INVALID_PARAMETER;
2959 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2960 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2962 return NOTI_EX_ERROR_NONE;
2965 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2967 if (handle == nullptr) {
2968 LOGE("Invalid parameter");
2969 return NOTI_EX_ERROR_INVALID_PARAMETER;
2972 Handle *h = static_cast<Handle*>(handle);
2973 if (!h->IsValidType(AbstractItem::Progress)) {
2974 LOGE("Invalid handle type");
2975 return NOTI_EX_ERROR_INVALID_PARAMETER;
2977 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2978 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2980 return NOTI_EX_ERROR_NONE;
2983 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2984 noti_ex_reporter_events_s event_callbacks, void *data) {
2985 if (handle == nullptr) {
2986 LOGE("Invalid parameter");
2987 return NOTI_EX_ERROR_INVALID_PARAMETER;
2990 ReporterStub* stub = new (std::nothrow) ReporterStub(
2991 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2992 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2993 if (stub == nullptr) {
2994 LOGE("Fail to create manager");
2995 return NOTI_EX_ERROR_IO_ERROR;
2997 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2998 new ReporterCallbackInfo(event_callbacks, data)));
3000 *handle = static_cast<noti_ex_reporter_h>(stub);
3002 return NOTI_EX_ERROR_NONE;
3005 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3006 if (handle == nullptr) {
3007 LOGE("Invalid parameter");
3008 return NOTI_EX_ERROR_INVALID_PARAMETER;
3010 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3012 return NOTI_EX_ERROR_NONE;
3015 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3016 noti_ex_event_info_h info, noti_ex_error_e error) {
3017 if (handle == nullptr || info == nullptr) {
3018 LOGE("Invalid parameter");
3019 return NOTI_EX_ERROR_INVALID_PARAMETER;
3022 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3023 IEventInfo* c_info = static_cast<IEventInfo*>(info);
3024 stub->SendError(static_cast<const IEventInfo&>(*c_info),
3025 static_cast<NotificationError>(error));
3026 } catch (Exception &ex) {
3027 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3028 return NOTI_EX_ERROR_IO_ERROR;
3030 return NOTI_EX_ERROR_NONE;
3033 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3034 noti_ex_item_h noti, int *request_id) {
3035 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3036 LOGE("Invalid parameter");
3037 return NOTI_EX_ERROR_INVALID_PARAMETER;
3040 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3041 Handle* h = static_cast<Handle*>(noti);
3042 if (h->GetPtr().get() == nullptr) {
3043 LOGE("Invalid noti reference can not be sended");
3044 return NOTI_EX_ERROR_INVALID_PARAMETER;
3046 *request_id = stub->Post(h->GetPtr());
3048 } catch (Exception &ex) {
3049 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3050 return NOTI_EX_ERROR_IO_ERROR;
3052 return NOTI_EX_ERROR_NONE;
3055 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3056 noti_ex_item_h *noti_list, int count, int *request_id) {
3058 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3059 LOGE("Invalid parameter");
3060 return NOTI_EX_ERROR_INVALID_PARAMETER;
3063 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3064 list<shared_ptr<item::AbstractItem>> notiList;
3065 for (int i = 0; i < count; i++) {
3066 Handle* item = static_cast<Handle*>(noti_list[i]);
3067 notiList.push_back(item->GetPtr());
3069 *request_id = stub->Post(notiList);
3070 } catch (Exception &ex) {
3071 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3072 return NOTI_EX_ERROR_IO_ERROR;
3074 return NOTI_EX_ERROR_NONE;
3077 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3078 noti_ex_item_h noti, int *request_id) {
3079 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3080 LOGE("Invalid parameter");
3081 return NOTI_EX_ERROR_INVALID_PARAMETER;
3084 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3085 Handle* item = static_cast<Handle*>(noti);
3086 if (item->GetPtr().get() == nullptr) {
3087 LOGE("Invalid noti reference can not be sended");
3088 return NOTI_EX_ERROR_INVALID_PARAMETER;
3090 *request_id = stub->Update(item->GetPtr());
3092 } catch (Exception &ex) {
3093 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3094 return NOTI_EX_ERROR_IO_ERROR;
3096 return NOTI_EX_ERROR_NONE;
3099 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3100 noti_ex_item_h noti, int *request_id) {
3101 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3102 LOGE("Invalid parameter");
3103 return NOTI_EX_ERROR_INVALID_PARAMETER;
3106 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3107 Handle* item = static_cast<Handle*>(noti);
3108 if (item->GetPtr().get() == nullptr) {
3109 LOGE("Invalid noti reference can not be sended");
3110 return NOTI_EX_ERROR_INVALID_PARAMETER;
3112 *request_id = stub->Delete(item->GetPtr());
3114 } catch (Exception &ex) {
3115 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3116 return NOTI_EX_ERROR_IO_ERROR;
3118 return NOTI_EX_ERROR_NONE;
3121 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3122 noti_ex_reporter_h handle, int *request_id) {
3123 if (handle == nullptr || request_id == nullptr) {
3124 LOGE("Invalid parameter");
3125 return NOTI_EX_ERROR_INVALID_PARAMETER;
3128 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3129 *request_id = stub->DeleteAll();
3130 } catch (Exception &ex) {
3131 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3132 return NOTI_EX_ERROR_IO_ERROR;
3134 return NOTI_EX_ERROR_NONE;
3137 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3138 noti_ex_reporter_h handle, const char* channel, int* request_id) {
3139 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3140 LOGE("Invalid parameter");
3141 return NOTI_EX_ERROR_INVALID_PARAMETER;
3145 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3146 *request_id = stub->DeleteByChannel(channel);
3147 } catch (Exception &ex) {
3148 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3149 return NOTI_EX_ERROR_IO_ERROR;
3152 return NOTI_EX_ERROR_NONE;
3155 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3156 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3157 if (handle == nullptr || root_id == nullptr || item == nullptr) {
3158 LOGE("Invalid parameter");
3159 return NOTI_EX_ERROR_INVALID_PARAMETER;
3162 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3163 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3164 if (ptr == nullptr) {
3165 LOGW("Not exist ID");
3167 return NOTI_EX_ERROR_NONE;
3169 *item = new Handle(ptr);
3170 } catch (Exception &ex) {
3171 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3172 return NOTI_EX_ERROR_IO_ERROR;
3174 return NOTI_EX_ERROR_NONE;
3177 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3178 const char *channel, noti_ex_item_h **noti_list, int *count) {
3179 if (handle == nullptr || channel == nullptr || noti_list == nullptr
3180 || count == nullptr) {
3181 LOGE("Invalid parameter");
3182 return NOTI_EX_ERROR_INVALID_PARAMETER;
3185 Handle** list_item = nullptr;
3188 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3189 list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3190 if (list_ptr.empty()) {
3191 LOGW("Not exist ID");
3192 *noti_list = nullptr;
3193 return NOTI_EX_ERROR_NONE;
3196 int size = list_ptr.size();
3199 list_item = (Handle**)calloc(size, sizeof(Handle*));
3200 for (auto& ptr : list_ptr)
3201 list_item[i++] = new Handle(std::move(ptr));
3203 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3205 } catch (Exception &ex) {
3206 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3208 return NOTI_EX_ERROR_IO_ERROR;
3211 return NOTI_EX_ERROR_NONE;
3214 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3215 noti_ex_item_h **noti_list, int *count) {
3216 if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3217 LOGE("Invalid parameter");
3218 return NOTI_EX_ERROR_INVALID_PARAMETER;
3221 Handle** list_item = nullptr;
3224 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3225 list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3226 if (list_ptr.empty()) {
3227 LOGW("Not exist ID");
3228 *noti_list = nullptr;
3229 return NOTI_EX_ERROR_NONE;
3232 int size = list_ptr.size();
3235 list_item = (Handle**)calloc(size, sizeof(Handle*));
3236 for (auto& ptr : list_ptr)
3237 list_item[i++] = new Handle(std::move(ptr));
3239 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3241 } catch (Exception &ex) {
3242 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3244 return NOTI_EX_ERROR_IO_ERROR;
3247 return NOTI_EX_ERROR_NONE;
3250 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3251 const char *id, const char *text, const char *hyperlink) {
3252 if (handle == nullptr || text == nullptr) {
3253 LOGE("Invalid parameter");
3254 return NOTI_EX_ERROR_INVALID_PARAMETER;
3263 p = new (std::nothrow) TextItem(id, std::string(text),
3264 std::string(hyperlink));
3266 p = new (std::nothrow) TextItem(id, std::string(text));
3269 LOGE("Out-of-memory");
3270 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3273 *handle = new Handle(shared_ptr<AbstractItem>(p));
3275 return NOTI_EX_ERROR_NONE;
3278 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3279 const char *contents) {
3280 if (handle == nullptr || contents == nullptr) {
3281 LOGE("Invalid parameter");
3282 return NOTI_EX_ERROR_INVALID_PARAMETER;
3285 Handle* p = static_cast<Handle*>(handle);
3286 if (!p->IsValidType(AbstractItem::Text)) {
3287 LOGE("Invalid handle type");
3288 return NOTI_EX_ERROR_INVALID_PARAMETER;
3290 TextItem* ti = static_cast<TextItem*>(p->Get());
3291 ti->SetContents(std::string(contents));
3293 return NOTI_EX_ERROR_NONE;
3296 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3298 if (handle == nullptr || contents == nullptr) {
3299 LOGE("Invalid parameter");
3300 return NOTI_EX_ERROR_INVALID_PARAMETER;
3303 Handle* p = static_cast<Handle*>(handle);
3304 if (!p->IsValidType(AbstractItem::Text)) {
3305 LOGE("Invalid handle type");
3306 return NOTI_EX_ERROR_INVALID_PARAMETER;
3309 TextItem* ti = static_cast<TextItem*>(p->Get());
3311 if (ti->GetMultiLanguage() != nullptr &&
3312 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3313 str = ti->GetMultiLanguage()->GetTranslatedString();
3314 else if (!ti->GetContents().empty())
3315 str = ti->GetContents();
3317 *contents = strdup(str.c_str());
3318 if (*contents == nullptr) {
3319 LOGE("Out-of-memory");
3320 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3323 return NOTI_EX_ERROR_NONE;
3326 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3327 noti_ex_item_h handle, char **hyper_link) {
3328 if (handle == nullptr || hyper_link == nullptr) {
3329 LOGE("Invalid parameter");
3330 return NOTI_EX_ERROR_INVALID_PARAMETER;
3333 Handle* p = static_cast<Handle*>(handle);
3334 if (!p->IsValidType(AbstractItem::Text)) {
3335 LOGE("Invalid handle type");
3336 return NOTI_EX_ERROR_INVALID_PARAMETER;
3338 TextItem* ti = static_cast<TextItem*>(p->Get());
3339 if (!ti->GetHyperLink().empty()) {
3340 *hyper_link = strdup(ti->GetHyperLink().c_str());
3341 if (*hyper_link == nullptr) {
3342 LOGE("Out-of-memory");
3343 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3346 *hyper_link = nullptr;
3349 return NOTI_EX_ERROR_NONE;
3352 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3353 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3354 if (handle == nullptr) {
3355 LOGE("Invalid parameter");
3356 return NOTI_EX_ERROR_INVALID_PARAMETER;
3359 Handle* p = static_cast<Handle*>(handle);
3360 if (!p->IsValidType(AbstractItem::Text)) {
3361 LOGE("Invalid handle type");
3362 return NOTI_EX_ERROR_INVALID_PARAMETER;
3365 TextItem* ti = static_cast<TextItem*>(p->Get());
3366 if (multi == nullptr) {
3367 ti->SetMultiLanguage(nullptr);
3368 return NOTI_EX_ERROR_NONE;
3371 shared_ptr<MultiLanguage> mul_ptr =
3372 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3373 ti->SetMultiLanguage(mul_ptr);
3374 ti->GetMultiLanguage()->UpdateString();
3376 return NOTI_EX_ERROR_NONE;
3379 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3380 const char *id, time_t time) {
3383 if (handle == nullptr) {
3384 LOGE("Invalid parameter");
3385 return NOTI_EX_ERROR_INVALID_PARAMETER;
3390 p = new (std::nothrow) TimeItem(id, time);
3392 p = new (std::nothrow) TimeItem(time);
3394 p = new (std::nothrow) TimeItem();
3398 LOGE("Out-of-memory");
3399 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3402 *handle = new Handle(shared_ptr<AbstractItem>(p));
3404 return NOTI_EX_ERROR_NONE;
3407 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3409 if (handle == nullptr || time == nullptr) {
3410 LOGE("Invalid parameter");
3411 return NOTI_EX_ERROR_INVALID_PARAMETER;
3413 Handle* h = static_cast<Handle*>(handle);
3414 if (!h->IsValidType(AbstractItem::Time)) {
3415 LOGE("Invalid handle type");
3416 return NOTI_EX_ERROR_INVALID_PARAMETER;
3418 TimeItem* p = static_cast<TimeItem*>(h->Get());
3419 *time = p->GetTime();
3421 return NOTI_EX_ERROR_NONE;
3424 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3426 if (handle == nullptr) {
3427 LOGE("Invalid parameter");
3428 return NOTI_EX_ERROR_INVALID_PARAMETER;
3430 Handle* h = static_cast<Handle*>(handle);
3431 if (!h->IsValidType(AbstractItem::Time)) {
3432 LOGE("Invalid handle type");
3433 return NOTI_EX_ERROR_INVALID_PARAMETER;
3435 TimeItem* p = static_cast<TimeItem*>(h->Get());
3438 return NOTI_EX_ERROR_NONE;
3441 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3442 noti_ex_action_h *handle, const char *extra) {
3443 if (handle == nullptr) {
3444 LOGE("Invalid parameter");
3445 return NOTI_EX_ERROR_INVALID_PARAMETER;
3448 string extra_str = "";
3450 extra_str = string(extra);
3452 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3453 new (std::nothrow) VisibilityAction(extra_str));
3454 if (ptr == nullptr) {
3455 LOGE("Out-of-memory");
3456 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3461 return NOTI_EX_ERROR_NONE;
3464 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3465 const char *id, bool visible) {
3466 if (handle == nullptr || id == nullptr) {
3467 LOGE("Invalid parameter");
3468 return NOTI_EX_ERROR_INVALID_PARAMETER;
3471 shared_ptr<AbstractAction>* ptr =
3472 static_cast<shared_ptr<AbstractAction>*>(handle);
3473 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3474 action->SetVisibility(id, visible);
3476 return NOTI_EX_ERROR_NONE;
3479 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3480 const char* msgid, const char* format, ...) {
3481 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3482 LOGE("Invalid parameter");
3483 return NOTI_EX_ERROR_INVALID_PARAMETER;
3486 const char* format_idx = format;
3489 va_start(args, format);
3490 while (*format_idx != '\0') {
3491 char* arg = nullptr;
3494 stringstream stream;
3495 if (*format_idx == '%') {
3496 switch (*(format_idx + 1)) {
3498 arg = va_arg(args, char *);
3499 arr.push_back(string(arg));
3502 arg_i = va_arg(args, int);
3503 arr.push_back(to_string(arg_i));
3506 arg_f = va_arg(args, double);
3507 stream << std::fixed << std::setprecision(2) << arg_f;
3508 arr.push_back(stream.str());
3516 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3518 LOGE("Out-of-memory");
3519 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3521 *handle = new shared_ptr<MultiLanguage>(p);
3523 return NOTI_EX_ERROR_NONE;
3526 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3527 if (handle == nullptr) {
3528 LOGE("Invalid parameter");
3529 return NOTI_EX_ERROR_INVALID_PARAMETER;
3532 shared_ptr<MultiLanguage>* mul_ptr =
3533 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3535 return NOTI_EX_ERROR_NONE;
3538 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3539 noti_ex_item_h item, int64_t* private_id) {
3540 if (item == nullptr || private_id == nullptr) {
3541 LOGE("Invalid parameter");
3542 return NOTI_EX_ERROR_INVALID_PARAMETER;
3545 Handle* h = static_cast<Handle*>(item);
3546 *private_id = static_pointer_cast<IItemInfoInternal>(
3547 h->Get()->GetInfo())->GetPrivateId();
3549 return NOTI_EX_ERROR_NONE;
3552 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3553 noti_ex_item_h item, int64_t priv_id) {
3554 if (item == nullptr) {
3555 LOGE("Invalid parameter");
3556 return NOTI_EX_ERROR_INVALID_PARAMETER;
3559 Handle* h = static_cast<Handle*>(item);
3560 static_pointer_cast<IItemInfoInternal>(
3561 h->Get()->GetInfo())->SetPrivateId(priv_id);
3563 return NOTI_EX_ERROR_NONE;
3566 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3567 if (list == nullptr) {
3568 LOGE("Invalid parameter");
3569 return NOTI_EX_ERROR_INVALID_PARAMETER;
3572 LOGI("Free strings (%d)", count);
3573 for (int i = 0; i < count; i++)
3577 return NOTI_EX_ERROR_NONE;
3580 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3581 if (handle == nullptr) {
3582 LOGE("Invalid parameter");
3583 return NOTI_EX_ERROR_INVALID_PARAMETER;
3585 Handle* h = static_cast<Handle*>(handle);
3586 if (!h->IsValidType(AbstractItem::Group)) {
3587 LOGE("Invalid handle type");
3588 return NOTI_EX_ERROR_INVALID_PARAMETER;
3590 GroupItem* p = static_cast<GroupItem*>(h->Get());
3591 p->RemoveChildren();
3593 return NOTI_EX_ERROR_NONE;
3596 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3597 const char *id, const char *icon_path) {
3598 if (handle == nullptr || icon_path == nullptr) {
3599 LOGE("Invalid parameter");
3600 return NOTI_EX_ERROR_INVALID_PARAMETER;
3605 p = new (std::nothrow) IconItem(id, icon_path);
3607 p = new (std::nothrow) IconItem(icon_path);
3610 LOGE("Out-of-memory");
3611 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3614 *handle = new Handle(shared_ptr<AbstractItem>(p));
3616 return NOTI_EX_ERROR_NONE;
3619 int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3620 if (handle == nullptr || icon_path == nullptr) {
3621 LOGE("Invalid parameter");
3622 return NOTI_EX_ERROR_INVALID_PARAMETER;
3625 Handle* h = static_cast<Handle*>(handle);
3626 if (!h->IsValidType(AbstractItem::Icon)) {
3627 LOGE("Invalid handle type");
3628 return NOTI_EX_ERROR_INVALID_PARAMETER;
3631 IconItem* p = static_cast<IconItem*>(h->Get());
3632 if (!p->GetImagePath().empty()) {
3633 *icon_path = strdup(p->GetImagePath().c_str());
3634 if (*icon_path == nullptr) {
3635 LOGE("Out-of-memory");
3636 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3639 *icon_path = nullptr;
3642 return NOTI_EX_ERROR_NONE;