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, 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;
487 auto* p = new (std::nothrow) ChatMessageItem(id,
488 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
489 text == nullptr ? nullptr
490 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
491 image == nullptr ? nullptr
492 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
493 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
494 static_cast<ChatMessageItem::Type>(message_type));
496 LOGE("Out-of-memory");
497 return NOTI_EX_ERROR_OUT_OF_MEMORY;
500 *handle = new Handle(shared_ptr<AbstractItem>(p));
502 return NOTI_EX_ERROR_NONE;
505 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
506 noti_ex_item_h handle, noti_ex_item_h *name) {
507 if (handle == nullptr || name == nullptr) {
508 LOGE("Invalid parameter");
509 return NOTI_EX_ERROR_INVALID_PARAMETER;
511 Handle* h = static_cast<Handle*>(handle);
512 if (!h->IsValidType(AbstractItem::ChatMessage)) {
513 LOGE("Invalid handle type");
514 return NOTI_EX_ERROR_INVALID_PARAMETER;
516 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
517 if (p->GetNameItem().GetType() == AbstractItem::NullObject)
520 *name = new Handle(&(p->GetNameItem()));
522 return NOTI_EX_ERROR_NONE;
525 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
526 noti_ex_item_h handle, noti_ex_item_h *text) {
527 if (handle == nullptr || text == nullptr) {
528 LOGE("Invalid parameter");
529 return NOTI_EX_ERROR_INVALID_PARAMETER;
532 Handle* h = static_cast<Handle*>(handle);
533 if (!h->IsValidType(AbstractItem::ChatMessage)) {
534 LOGE("Invalid handle type");
535 return NOTI_EX_ERROR_INVALID_PARAMETER;
537 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
538 if (p->GetTextItem().GetType() == AbstractItem::NullObject)
541 *text = new Handle(&(p->GetTextItem()));
543 return NOTI_EX_ERROR_NONE;
546 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
547 noti_ex_item_h handle, noti_ex_item_h *image) {
548 if (handle == nullptr || image == nullptr) {
549 LOGE("Invalid parameter");
550 return NOTI_EX_ERROR_INVALID_PARAMETER;
553 Handle* h = static_cast<Handle*>(handle);
554 if (!h->IsValidType(AbstractItem::ChatMessage)) {
555 LOGE("Invalid handle type");
556 return NOTI_EX_ERROR_INVALID_PARAMETER;
558 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
559 if (p->GetImageItem().GetType() == AbstractItem::NullObject)
562 *image = new Handle(&(p->GetImageItem()));
564 return NOTI_EX_ERROR_NONE;
567 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
568 noti_ex_item_h handle, noti_ex_item_h *time) {
569 if (handle == nullptr || time == nullptr) {
570 LOGE("Invalid parameter");
571 return NOTI_EX_ERROR_INVALID_PARAMETER;
574 Handle* h = static_cast<Handle*>(handle);
575 if (!h->IsValidType(AbstractItem::ChatMessage)) {
576 LOGE("Invalid handle type");
577 return NOTI_EX_ERROR_INVALID_PARAMETER;
579 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
580 if (p->GetTimeItem().GetType() == AbstractItem::NullObject)
583 *time = new Handle(&(p->GetTimeItem()));
585 return NOTI_EX_ERROR_NONE;
588 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
589 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
590 if (handle == nullptr || message_type == nullptr) {
591 LOGE("Invalid parameter");
592 return NOTI_EX_ERROR_INVALID_PARAMETER;
595 Handle* h = static_cast<Handle*>(handle);
596 if (!h->IsValidType(AbstractItem::ChatMessage)) {
597 LOGE("Invalid handle type");
598 return NOTI_EX_ERROR_INVALID_PARAMETER;
600 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
601 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
603 return NOTI_EX_ERROR_NONE;
606 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
607 const char *id, const char *title, bool checked) {
610 if (handle == nullptr || title == nullptr) {
611 LOGE("Invalid parameter");
612 return NOTI_EX_ERROR_INVALID_PARAMETER;
615 p = new (std::nothrow) CheckBoxItem(id, title, checked);
617 LOGE("Out-of-memory");
618 return NOTI_EX_ERROR_OUT_OF_MEMORY;
621 *handle = new Handle(shared_ptr<AbstractItem>(p));
623 return NOTI_EX_ERROR_NONE;
626 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
628 if (handle == nullptr || title == nullptr) {
629 LOGE("Invalid parameter");
630 return NOTI_EX_ERROR_INVALID_PARAMETER;
632 Handle* h = static_cast<Handle*>(handle);
633 if (!h->IsValidType(AbstractItem::CheckBox)) {
634 LOGE("Invalid handle type");
635 return NOTI_EX_ERROR_INVALID_PARAMETER;
638 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
640 if (p->GetMultiLanguage() != nullptr &&
641 !p->GetMultiLanguage()->GetTranslatedString().empty())
642 str = p->GetMultiLanguage()->GetTranslatedString();
643 else if (!p->GetTitle().empty())
646 *title = strdup(str.c_str());
647 if (*title == nullptr) {
648 LOGE("Out-of-memory");
649 return NOTI_EX_ERROR_OUT_OF_MEMORY;
652 return NOTI_EX_ERROR_NONE;
655 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
656 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
657 if (handle == nullptr) {
658 LOGE("Invalid parameter");
659 return NOTI_EX_ERROR_INVALID_PARAMETER;
662 Handle* p = static_cast<Handle*>(handle);
663 if (!p->IsValidType(AbstractItem::CheckBox)) {
664 LOGE("Invalid handle type");
665 return NOTI_EX_ERROR_INVALID_PARAMETER;
668 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
669 if (multi == nullptr) {
670 ci->SetMultiLanguage(nullptr);
671 return NOTI_EX_ERROR_NONE;
674 shared_ptr<MultiLanguage> mul_ptr =
675 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
676 mul_ptr->UpdateString();
677 ci->SetMultiLanguage(mul_ptr);
679 return NOTI_EX_ERROR_NONE;
682 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
683 noti_ex_item_h handle, bool *checked) {
684 if (handle == nullptr || checked == nullptr) {
685 LOGE("Invalid parameter");
686 return NOTI_EX_ERROR_INVALID_PARAMETER;
688 Handle* h = static_cast<Handle*>(handle);
689 if (!h->IsValidType(AbstractItem::CheckBox)) {
690 LOGE("Invalid handle type");
691 return NOTI_EX_ERROR_INVALID_PARAMETER;
693 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
694 *checked = p->IsChecked();
696 return NOTI_EX_ERROR_NONE;
699 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
700 noti_ex_item_h handle, bool checked) {
701 if (handle == nullptr) {
702 LOGE("Invalid parameter");
703 return NOTI_EX_ERROR_INVALID_PARAMETER;
706 Handle* h = static_cast<Handle*>(handle);
707 if (!h->IsValidType(AbstractItem::CheckBox)) {
708 LOGE("Invalid handle type");
709 return NOTI_EX_ERROR_INVALID_PARAMETER;
712 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
713 p->SetChecked(checked);
715 return NOTI_EX_ERROR_NONE;
718 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
722 if (handle == nullptr) {
723 LOGE("Invalid parameter");
724 return NOTI_EX_ERROR_INVALID_PARAMETER;
727 p = new (std::nothrow) EntryItem(id);
729 LOGE("Out-of-memory");
730 return NOTI_EX_ERROR_OUT_OF_MEMORY;
733 *handle = new Handle(shared_ptr<AbstractItem>(p));
735 return NOTI_EX_ERROR_NONE;
738 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
740 if (handle == nullptr || text == nullptr) {
741 LOGE("Invalid parameter");
742 return NOTI_EX_ERROR_INVALID_PARAMETER;
745 Handle* h = static_cast<Handle*>(handle);
746 if (!h->IsValidType(AbstractItem::Entry)) {
747 LOGE("Invalid handle type");
748 return NOTI_EX_ERROR_INVALID_PARAMETER;
751 EntryItem* p = static_cast<EntryItem*>(h->Get());
753 if (p->GetMultiLanguage() != nullptr &&
754 !p->GetMultiLanguage()->GetTranslatedString().empty())
755 str = p->GetMultiLanguage()->GetTranslatedString();
756 else if (!p->GetText().empty())
759 *text = strdup(str.c_str());
760 if (*text == nullptr) {
761 LOGE("Out-of-memory");
762 return NOTI_EX_ERROR_OUT_OF_MEMORY;
765 return NOTI_EX_ERROR_NONE;
768 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
770 if (handle == nullptr || text == nullptr) {
771 LOGE("Invalid parameter");
772 return NOTI_EX_ERROR_INVALID_PARAMETER;
774 Handle* h = static_cast<Handle*>(handle);
775 if (!h->IsValidType(AbstractItem::Entry)) {
776 LOGE("Invalid handle type");
777 return NOTI_EX_ERROR_INVALID_PARAMETER;
779 EntryItem* p = static_cast<EntryItem*>(h->Get());
780 p->SetText(std::string(text));
782 return NOTI_EX_ERROR_NONE;
785 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
786 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
787 if (handle == nullptr) {
788 LOGE("Invalid parameter");
789 return NOTI_EX_ERROR_INVALID_PARAMETER;
792 Handle* p = static_cast<Handle*>(handle);
793 if (!p->IsValidType(AbstractItem::Entry)) {
794 LOGE("Invalid handle type");
795 return NOTI_EX_ERROR_INVALID_PARAMETER;
798 EntryItem* ei = static_cast<EntryItem*>(p->Get());
799 if (multi == nullptr) {
800 ei->SetMultiLanguage(nullptr);
801 return NOTI_EX_ERROR_NONE;
804 shared_ptr<MultiLanguage> mul_ptr =
805 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
806 ei->SetMultiLanguage(mul_ptr);
807 ei->GetMultiLanguage()->UpdateString();
809 return NOTI_EX_ERROR_NONE;
812 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
813 noti_ex_event_info_h* cloned_handle) {
814 if (handle == nullptr || cloned_handle == nullptr) {
815 LOGE("Invalid parameter");
816 return NOTI_EX_ERROR_INVALID_PARAMETER;
819 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
820 EventInfo* info = new EventInfo(cloned);
821 *cloned_handle = info;
822 return NOTI_EX_ERROR_NONE;
825 extern "C" EXPORT_API int noti_ex_event_info_destroy(
826 noti_ex_event_info_h handle) {
827 if (handle == nullptr) {
828 LOGE("Invalid parameter");
829 return NOTI_EX_ERROR_INVALID_PARAMETER;
831 EventInfo* info = static_cast<EventInfo*>(handle);
833 return NOTI_EX_ERROR_NONE;
836 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
837 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
838 if (handle == nullptr || event_type == nullptr) {
839 LOGE("Invalid parameter");
840 return NOTI_EX_ERROR_INVALID_PARAMETER;
842 EventInfo* info = static_cast<EventInfo*>(handle);
843 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
845 return NOTI_EX_ERROR_NONE;
848 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
849 noti_ex_event_info_h handle, char **owner) {
850 if (handle == nullptr || owner == nullptr) {
851 LOGE("Invalid parameter");
852 return NOTI_EX_ERROR_INVALID_PARAMETER;
854 EventInfo* info = static_cast<EventInfo*>(handle);
855 *owner = strdup(info->GetOwner().c_str());
856 return NOTI_EX_ERROR_NONE;
859 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
860 noti_ex_event_info_h handle, char **channel) {
861 if (handle == nullptr || channel == nullptr) {
862 LOGE("Invalid parameter");
863 return NOTI_EX_ERROR_INVALID_PARAMETER;
865 EventInfo* info = static_cast<EventInfo*>(handle);
866 *channel = strdup(info->GetChannel().c_str());
867 return NOTI_EX_ERROR_NONE;
870 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
871 noti_ex_event_info_h handle, char **item_id) {
872 if (handle == nullptr || item_id == nullptr) {
873 LOGE("Invalid parameter");
874 return NOTI_EX_ERROR_INVALID_PARAMETER;
876 EventInfo* info = static_cast<EventInfo*>(handle);
877 *item_id = strdup(info->GetItemId().c_str());
878 return NOTI_EX_ERROR_NONE;
881 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
882 noti_ex_event_info_h handle, int *req_id) {
883 if (handle == nullptr || req_id == nullptr) {
884 LOGE("Invalid parameter");
885 return NOTI_EX_ERROR_INVALID_PARAMETER;
887 EventInfo* info = static_cast<EventInfo*>(handle);
888 *req_id = info->GetRequestId();
889 return NOTI_EX_ERROR_NONE;
892 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
896 if (handle == nullptr) {
897 LOGE("Invalid parameter");
898 return NOTI_EX_ERROR_INVALID_PARAMETER;
902 p = new (std::nothrow) GroupItem(id);
904 p = new (std::nothrow) GroupItem();
907 LOGE("Out-of-memory");
908 return NOTI_EX_ERROR_OUT_OF_MEMORY;
911 *handle = new Handle(shared_ptr<AbstractItem>(p));
913 return NOTI_EX_ERROR_NONE;
916 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
918 if (handle == nullptr) {
919 LOGE("Invalid parameter");
920 return NOTI_EX_ERROR_INVALID_PARAMETER;
922 Handle* h = static_cast<Handle*>(handle);
923 if (!h->IsValidType(AbstractItem::Group)) {
924 LOGE("Invalid handle type");
925 return NOTI_EX_ERROR_INVALID_PARAMETER;
927 GroupItem* p = static_cast<GroupItem*>(h->Get());
928 p->SetDirection(vertical);
930 return NOTI_EX_ERROR_NONE;
933 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
935 if (handle == nullptr) {
936 LOGE("Invalid parameter");
937 return NOTI_EX_ERROR_INVALID_PARAMETER;
939 Handle* h = static_cast<Handle*>(handle);
940 if (!h->IsValidType(AbstractItem::Group)) {
941 LOGE("Invalid handle type");
942 return NOTI_EX_ERROR_INVALID_PARAMETER;
944 GroupItem* p = static_cast<GroupItem*>(h->Get());
945 *vertical = p->IsVertical();
947 return NOTI_EX_ERROR_NONE;
950 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
952 if (handle == nullptr) {
953 LOGE("Invalid parameter");
954 return NOTI_EX_ERROR_INVALID_PARAMETER;
956 Handle* h = static_cast<Handle*>(handle);
957 if (!h->IsValidType(AbstractItem::Group)) {
958 LOGE("Invalid handle type");
959 return NOTI_EX_ERROR_INVALID_PARAMETER;
961 GroupItem* p = static_cast<GroupItem*>(h->Get());
962 if (!p->GetAppLabel().empty()) {
963 *label = strdup(p->GetAppLabel().c_str());
964 if (*label == nullptr) {
965 LOGE("Out-of-memory");
966 return NOTI_EX_ERROR_OUT_OF_MEMORY;
970 return NOTI_EX_ERROR_NONE;
973 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
974 noti_ex_item_h child) {
975 if (handle == nullptr || child == nullptr) {
976 LOGE("Invalid parameter");
977 return NOTI_EX_ERROR_INVALID_PARAMETER;
979 Handle* h = static_cast<Handle*>(handle);
980 if (!h->IsValidType(AbstractItem::Group)) {
981 LOGE("Invalid handle type");
982 return NOTI_EX_ERROR_INVALID_PARAMETER;
984 auto p = static_cast<GroupItem*>(h->Get());
985 p->AddChild((static_cast<Handle*>(child))->GetPtr());
987 return NOTI_EX_ERROR_NONE;
990 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
991 const char *item_id) {
992 if (handle == nullptr || item_id == nullptr) {
993 LOGE("Invalid parameter");
994 return NOTI_EX_ERROR_INVALID_PARAMETER;
996 Handle* h = static_cast<Handle*>(handle);
997 if (!h->IsValidType(AbstractItem::Group)) {
998 LOGE("Invalid handle type");
999 return NOTI_EX_ERROR_INVALID_PARAMETER;
1001 GroupItem* p = static_cast<GroupItem*>(h->Get());
1002 p->RemoveChild(std::string(item_id));
1004 return NOTI_EX_ERROR_NONE;
1007 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
1008 noti_ex_item_group_foreach_child_cb callback, void *data) {
1009 if (handle == nullptr || callback == nullptr) {
1010 LOGE("Invalid parameter");
1011 return NOTI_EX_ERROR_INVALID_PARAMETER;
1014 Handle* h = static_cast<Handle*>(handle);
1015 if (!h->IsValidType(AbstractItem::Group)) {
1016 LOGE("Invalid handle type");
1017 return NOTI_EX_ERROR_INVALID_PARAMETER;
1019 GroupItem* p = static_cast<GroupItem*>(h->Get());
1020 list<shared_ptr<AbstractItem>> children = p->GetChildren();
1021 LOGI("Retrive (%zd)", children.size());
1022 for (auto i : children) {
1024 static_cast<noti_ex_item_h>(new Handle(i)), data);
1025 if (ret != NOTI_EX_ERROR_NONE) {
1026 LOGW("callback return (%d) stop foreach", ret);
1031 return NOTI_EX_ERROR_NONE;
1034 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1035 const char *id, const char *image_path) {
1038 if (handle == nullptr || image_path == nullptr) {
1039 LOGE("Invalid parameter");
1040 return NOTI_EX_ERROR_INVALID_PARAMETER;
1044 p = new (std::nothrow) ImageItem(id, image_path);
1046 p = new (std::nothrow) ImageItem(image_path);
1049 LOGE("Out-of-memory");
1050 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1053 *handle = new Handle(shared_ptr<AbstractItem>(p));
1055 return NOTI_EX_ERROR_NONE;
1058 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1059 noti_ex_item_h handle, char **image_path) {
1060 if (handle == nullptr || image_path == nullptr) {
1061 LOGE("Invalid parameter");
1062 return NOTI_EX_ERROR_INVALID_PARAMETER;
1064 Handle* h = static_cast<Handle*>(handle);
1065 if (!h->IsValidType(AbstractItem::Image)) {
1066 LOGE("Invalid handle type");
1067 return NOTI_EX_ERROR_INVALID_PARAMETER;
1069 ImageItem* p = static_cast<ImageItem*>(h->Get());
1070 if (!p->GetImagePath().empty()) {
1071 *image_path = strdup(p->GetImagePath().c_str());
1072 if (*image_path == nullptr) {
1073 LOGE("Out-of-memory");
1074 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1077 *image_path = nullptr;
1080 return NOTI_EX_ERROR_NONE;
1083 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1084 noti_ex_item_h *handle, const char *id) {
1085 InputSelectorItem* p;
1087 if (handle == nullptr) {
1088 LOGE("Invalid parameter");
1089 return NOTI_EX_ERROR_INVALID_PARAMETER;
1093 p = new (std::nothrow) InputSelectorItem(id);
1095 p = new (std::nothrow) InputSelectorItem();
1098 LOGE("Out-of-memory");
1099 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1102 *handle = new Handle(shared_ptr<AbstractItem>(p));
1104 return NOTI_EX_ERROR_NONE;
1107 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1108 noti_ex_item_h handle, char ***contents_list, int *count) {
1109 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1110 LOGE("Invalid parameter");
1111 return NOTI_EX_ERROR_INVALID_PARAMETER;
1114 Handle* h = static_cast<Handle*>(handle);
1115 if (!h->IsValidType(AbstractItem::InputSelector)) {
1116 LOGE("Invalid handle type");
1117 return NOTI_EX_ERROR_INVALID_PARAMETER;
1120 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1121 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1122 list<string> contents;
1123 if (arr.size() == 0) {
1124 contents = p->GetContents();
1126 for (auto& i : arr) {
1127 contents.push_back(i->GetTranslatedString());
1131 char **list = (char**)calloc(contents.size(), sizeof(char*));
1132 if (list == nullptr) {
1133 LOGE("Out of memory");
1134 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1138 for (auto& i : contents) {
1139 list[idx] = strdup(i.c_str());
1140 if (list[idx] == nullptr) {
1141 __noti_ex_free_str_array(list, idx);
1142 LOGE("Out of memory");
1143 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1148 *count = contents.size();
1149 *contents_list = list;
1151 return NOTI_EX_ERROR_NONE;
1154 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1155 noti_ex_item_h handle, const char **contents, int count) {
1156 if (handle == nullptr || contents == nullptr) {
1157 LOGE("Invalid parameter");
1158 return NOTI_EX_ERROR_INVALID_PARAMETER;
1161 list<string> new_contents;
1162 Handle* h = static_cast<Handle*>(handle);
1163 if (!h->IsValidType(AbstractItem::InputSelector)) {
1164 LOGE("Invalid handle type");
1165 return NOTI_EX_ERROR_INVALID_PARAMETER;
1167 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1168 for (int i = 0; i < count; i++) {
1169 new_contents.push_back(contents[i]);
1171 p->SetContents(move(new_contents));
1173 return NOTI_EX_ERROR_NONE;
1176 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1177 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1178 if (handle == nullptr) {
1179 LOGE("Invalid parameter");
1180 return NOTI_EX_ERROR_INVALID_PARAMETER;
1183 Handle* p = static_cast<Handle*>(handle);
1184 if (!p->IsValidType(AbstractItem::InputSelector)) {
1185 LOGE("Invalid handle type");
1186 return NOTI_EX_ERROR_INVALID_PARAMETER;
1189 vector<shared_ptr<MultiLanguage>> m_list;
1190 for (int i = 0; i < count; i++) {
1191 shared_ptr<MultiLanguage> mul_ptr =
1192 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1193 mul_ptr->UpdateString();
1194 m_list.push_back(mul_ptr);
1197 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1198 input->SetMultiLanguage(m_list);
1200 return NOTI_EX_ERROR_NONE;
1203 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1204 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1205 if (handle == nullptr) {
1206 LOGE("Invalid parameter");
1207 return NOTI_EX_ERROR_INVALID_PARAMETER;
1210 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1211 new (std::nothrow) Color(a, r, g, b));
1212 if (ptr == nullptr || ptr->get() == nullptr) {
1213 LOGE("Out-of-memory");
1214 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1219 return NOTI_EX_ERROR_NONE;
1222 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1223 if (handle == nullptr) {
1224 LOGE("Invalid parameter");
1225 return NOTI_EX_ERROR_INVALID_PARAMETER;
1228 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1231 return NOTI_EX_ERROR_NONE;
1234 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1235 unsigned char *val) {
1236 if (handle == nullptr || val == nullptr) {
1237 LOGE("Invalid parameter");
1238 return NOTI_EX_ERROR_INVALID_PARAMETER;
1241 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1242 *val = (*p)->GetAVal();
1244 return NOTI_EX_ERROR_NONE;
1247 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1248 unsigned char *val) {
1249 if (handle == nullptr || val == nullptr) {
1250 LOGE("Invalid parameter");
1251 return NOTI_EX_ERROR_INVALID_PARAMETER;
1254 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1255 *val = (*p)->GetRVal();
1257 return NOTI_EX_ERROR_NONE;
1260 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1261 unsigned char *val) {
1262 if (handle == nullptr || val == nullptr) {
1263 LOGE("Invalid parameter");
1264 return NOTI_EX_ERROR_INVALID_PARAMETER;
1267 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1268 *val = (*p)->GetGVal();
1270 return NOTI_EX_ERROR_NONE;
1273 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1274 unsigned char *val) {
1275 if (handle == nullptr || val == nullptr) {
1276 LOGE("Invalid parameter");
1277 return NOTI_EX_ERROR_INVALID_PARAMETER;
1280 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1281 *val = (*p)->GetBVal();
1283 return NOTI_EX_ERROR_NONE;
1286 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1287 int left, int top, int right, int bottom) {
1288 if (handle == nullptr) {
1289 LOGE("Invalid parameter");
1290 return NOTI_EX_ERROR_INVALID_PARAMETER;
1293 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1294 new (std::nothrow) Padding(left, top, right, bottom));
1295 if (ptr == nullptr || ptr->get() == nullptr) {
1296 LOGE("Out-of-memory");
1297 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1302 return NOTI_EX_ERROR_NONE;
1305 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1306 if (handle == nullptr) {
1307 LOGE("Invalid parameter");
1308 return NOTI_EX_ERROR_INVALID_PARAMETER;
1311 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1314 return NOTI_EX_ERROR_NONE;
1317 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1319 if (handle == nullptr || val == nullptr) {
1320 LOGE("Invalid parameter");
1321 return NOTI_EX_ERROR_INVALID_PARAMETER;
1324 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1325 *val = (*p)->GetLeft();
1327 return NOTI_EX_ERROR_NONE;
1330 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1332 if (handle == nullptr || val == nullptr) {
1333 LOGE("Invalid parameter");
1334 return NOTI_EX_ERROR_INVALID_PARAMETER;
1337 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1338 *val = (*p)->GetTop();
1340 return NOTI_EX_ERROR_NONE;
1343 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1345 if (handle == nullptr || val == nullptr) {
1346 LOGE("Invalid parameter");
1347 return NOTI_EX_ERROR_INVALID_PARAMETER;
1350 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1351 *val = (*p)->GetRight();
1353 return NOTI_EX_ERROR_NONE;
1356 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1358 if (handle == nullptr || val == nullptr) {
1359 LOGE("Invalid parameter");
1360 return NOTI_EX_ERROR_INVALID_PARAMETER;
1363 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1364 *val = (*p)->GetBottom();
1366 return NOTI_EX_ERROR_NONE;
1369 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1370 int x, int y, int w, int h) {
1371 if (handle == nullptr) {
1372 LOGE("Invalid parameter");
1373 return NOTI_EX_ERROR_INVALID_PARAMETER;
1376 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1377 new (std::nothrow) Geometry(x, y, w, h));
1378 if (ptr == nullptr || ptr->get() == nullptr) {
1379 LOGE("Out-of-memory");
1380 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1385 return NOTI_EX_ERROR_NONE;
1388 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1389 if (handle == nullptr) {
1390 LOGE("Invalid parameter");
1391 return NOTI_EX_ERROR_INVALID_PARAMETER;
1394 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1397 return NOTI_EX_ERROR_NONE;
1400 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1402 if (handle == nullptr || val == nullptr) {
1403 LOGE("Invalid parameter");
1404 return NOTI_EX_ERROR_INVALID_PARAMETER;
1407 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1408 *val = (*p)->GetX();
1410 return NOTI_EX_ERROR_NONE;
1413 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1415 if (handle == nullptr || val == nullptr) {
1416 LOGE("Invalid parameter");
1417 return NOTI_EX_ERROR_INVALID_PARAMETER;
1420 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1421 *val = (*p)->GetY();
1423 return NOTI_EX_ERROR_NONE;
1426 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1428 if (handle == nullptr || val == nullptr) {
1429 LOGE("Invalid parameter");
1430 return NOTI_EX_ERROR_INVALID_PARAMETER;
1433 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1434 *val = (*p)->GetWidth();
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1441 if (handle == nullptr || val == nullptr) {
1442 LOGE("Invalid parameter");
1443 return NOTI_EX_ERROR_INVALID_PARAMETER;
1446 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1447 *val = (*p)->GetHeight();
1449 return NOTI_EX_ERROR_NONE;
1452 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1453 noti_ex_color_h color,
1454 noti_ex_padding_h padding,
1455 noti_ex_geometry_h geometry) {
1456 if (handle == nullptr) {
1457 LOGE("Invalid parameter");
1458 return NOTI_EX_ERROR_INVALID_PARAMETER;
1461 shared_ptr<Color> col = (color == nullptr) ?
1462 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1463 shared_ptr<Padding> padd = (padding == nullptr) ?
1464 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1465 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1466 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1468 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1469 new (std::nothrow) Style(col, padd, geo));
1470 if (ptr == nullptr || ptr->get() == nullptr) {
1471 LOGE("Out-of-memory");
1472 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1477 return NOTI_EX_ERROR_NONE;
1480 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1481 if (handle == nullptr) {
1482 LOGE("Invalid parameter");
1483 return NOTI_EX_ERROR_INVALID_PARAMETER;
1486 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1489 return NOTI_EX_ERROR_NONE;
1492 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1493 noti_ex_padding_h *padding) {
1494 if (handle == nullptr || padding == nullptr) {
1495 LOGE("Invalid parameter");
1496 return NOTI_EX_ERROR_INVALID_PARAMETER;
1499 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1500 if ((*p)->GetPadding() == nullptr) {
1501 LOGW("Padding info is null");
1502 return NOTI_EX_ERROR_INVALID_PARAMETER;
1505 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1506 new (std::nothrow) Padding(*((*p)->GetPadding())));
1507 if (padd == nullptr || padd->get() == nullptr) {
1508 LOGE("Out-of-memory");
1510 return NOTI_EX_ERROR_NONE;
1515 return NOTI_EX_ERROR_NONE;
1519 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1520 noti_ex_padding_h padding) {
1521 if (handle == nullptr) {
1522 LOGE("Invalid parameter");
1523 return NOTI_EX_ERROR_INVALID_PARAMETER;
1526 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1527 if (padding == nullptr) {
1528 (*p)->SetPadding(nullptr);
1529 return NOTI_EX_ERROR_NONE;
1532 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1533 (*p)->SetPadding(*padd);
1535 return NOTI_EX_ERROR_NONE;
1538 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1539 noti_ex_color_h *color) {
1540 if (handle == nullptr || color == nullptr) {
1541 LOGE("Invalid parameter");
1542 return NOTI_EX_ERROR_INVALID_PARAMETER;
1545 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1546 if ((*p)->GetColor() == nullptr) {
1547 LOGW("Color info is null");
1549 return NOTI_EX_ERROR_NONE;
1552 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1553 new (std::nothrow) Color(*((*p)->GetColor())));
1554 if (col == nullptr || col->get() == nullptr) {
1555 LOGE("Out-of-memory");
1556 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_style_set_color(
1565 noti_ex_style_h handle, noti_ex_color_h color) {
1566 if (handle == nullptr) {
1567 LOGE("Invalid parameter");
1568 return NOTI_EX_ERROR_INVALID_PARAMETER;
1571 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1572 if (color == nullptr) {
1573 (*p)->SetColor(nullptr);
1574 return NOTI_EX_ERROR_NONE;
1577 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1578 (*p)->SetColor(*col);
1580 return NOTI_EX_ERROR_NONE;
1583 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1584 noti_ex_geometry_h *geometry) {
1585 if (handle == nullptr || geometry == nullptr) {
1586 LOGE("Invalid parameter");
1587 return NOTI_EX_ERROR_INVALID_PARAMETER;
1590 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1591 if ((*p)->GetGeometry() == nullptr) {
1592 LOGW("Geometry info is null");
1593 *geometry = nullptr;
1594 return NOTI_EX_ERROR_NONE;
1597 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1598 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1599 if (geo == nullptr || geo->get() == nullptr) {
1600 LOGE("Out-of-memory");
1601 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1606 return NOTI_EX_ERROR_NONE;
1609 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1610 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1611 if (handle == nullptr) {
1612 LOGE("Invalid parameter");
1613 return NOTI_EX_ERROR_INVALID_PARAMETER;
1616 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1617 if (geometry == nullptr) {
1618 (*p)->SetGeometry(nullptr);
1619 return NOTI_EX_ERROR_NONE;
1622 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1623 (*p)->SetGeometry(*geo);
1625 return NOTI_EX_ERROR_NONE;
1628 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1629 noti_ex_style_h handle, char** background_image) {
1630 if (handle == nullptr || background_image == nullptr) {
1631 LOGE("Invalid parameter");
1632 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1637 if ((*p)->GetBackgroundImage().empty())
1638 *background_image = nullptr;
1640 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1642 return NOTI_EX_ERROR_NONE;
1645 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1646 noti_ex_style_h handle, char* background_image) {
1647 if (handle == nullptr) {
1648 LOGE("Invalid parameter");
1649 return NOTI_EX_ERROR_INVALID_PARAMETER;
1652 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1653 if (background_image == nullptr)
1654 (*p)->SetBackgroundImage("");
1656 (*p)->SetBackgroundImage(background_image);
1658 return NOTI_EX_ERROR_NONE;
1661 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1662 noti_ex_style_h handle, noti_ex_color_h* color) {
1663 if (handle == nullptr || color == nullptr) {
1664 LOGE("Invalid parameter");
1665 return NOTI_EX_ERROR_INVALID_PARAMETER;
1668 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1669 if ((*p)->GetBackgroundColor() == nullptr) {
1670 LOGW("Color info is null");
1672 return NOTI_EX_ERROR_NONE;
1675 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1676 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1677 if (col == nullptr || col->get() == nullptr) {
1678 LOGE("Out-of-memory");
1679 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1684 return NOTI_EX_ERROR_NONE;
1687 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1688 noti_ex_style_h handle, noti_ex_color_h color) {
1689 if (handle == nullptr) {
1690 LOGE("Invalid parameter");
1691 return NOTI_EX_ERROR_INVALID_PARAMETER;
1694 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1695 if (color == nullptr) {
1696 (*p)->SetBackgroundColor(nullptr);
1697 return NOTI_EX_ERROR_NONE;
1700 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1701 (*p)->SetBackgroundColor(*col);
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1707 noti_ex_color_h color) {
1708 if (handle == nullptr || color == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1714 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1715 new (std::nothrow) LEDInfo(*color_ptr));
1717 LOGE("Out-of-memory");
1718 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1723 return NOTI_EX_ERROR_NONE;
1726 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1727 if (handle == nullptr) {
1728 LOGE("Invalid parameter");
1729 return NOTI_EX_ERROR_INVALID_PARAMETER;
1732 shared_ptr<LEDInfo>* led_ptr =
1733 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1735 return NOTI_EX_ERROR_NONE;
1738 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1739 noti_ex_led_info_h handle, int ms) {
1740 if (handle == nullptr) {
1741 LOGE("Invalid parameter");
1742 return NOTI_EX_ERROR_INVALID_PARAMETER;
1745 shared_ptr<LEDInfo>* led_ptr =
1746 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1747 (*led_ptr)->SetOnPeriod(ms);
1749 return NOTI_EX_ERROR_NONE;
1752 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1753 noti_ex_led_info_h handle, int *ms) {
1754 if (handle == nullptr || ms == nullptr) {
1755 LOGE("Invalid parameter");
1756 return NOTI_EX_ERROR_INVALID_PARAMETER;
1759 shared_ptr<LEDInfo>* led_ptr =
1760 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1761 *ms = (*led_ptr)->GetOnPeriod();
1763 return NOTI_EX_ERROR_NONE;
1766 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1767 noti_ex_led_info_h handle, int ms) {
1768 if (handle == nullptr) {
1769 LOGE("Invalid parameter");
1770 return NOTI_EX_ERROR_INVALID_PARAMETER;
1773 shared_ptr<LEDInfo>* led_ptr =
1774 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1775 (*led_ptr)->SetOffPeriod(ms);
1777 return NOTI_EX_ERROR_NONE;
1780 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1781 noti_ex_led_info_h handle, int *ms) {
1782 if (handle == nullptr) {
1783 LOGE("Invalid parameter");
1784 return NOTI_EX_ERROR_INVALID_PARAMETER;
1787 shared_ptr<LEDInfo>* led_ptr =
1788 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1789 *ms = (*led_ptr)->GetOffPeriod();
1791 return NOTI_EX_ERROR_NONE;
1794 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1795 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1796 if (handle == nullptr) {
1797 LOGE("Invalid parameter");
1798 return NOTI_EX_ERROR_INVALID_PARAMETER;
1801 shared_ptr<LEDInfo>* led_ptr =
1802 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1803 if ((*led_ptr)->GetColor() == nullptr) {
1804 LOGW("Color is null");
1806 return NOTI_EX_ERROR_NONE;
1809 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1810 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1811 if (col == nullptr || col->get() == nullptr) {
1812 LOGE("Out-of-memory");
1813 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1818 return NOTI_EX_ERROR_NONE;
1821 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1822 noti_ex_led_info_h handle, noti_ex_color_h color) {
1823 if (handle == nullptr) {
1824 LOGE("Invalid parameter");
1825 return NOTI_EX_ERROR_INVALID_PARAMETER;
1828 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1829 if (color == nullptr) {
1830 (*p)->SetColor(nullptr);
1831 return NOTI_EX_ERROR_NONE;
1834 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1835 (*p)->SetColor(*col);
1837 return NOTI_EX_ERROR_NONE;
1840 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1841 if (handle == nullptr) {
1842 LOGE("Invalid parameter");
1843 return NOTI_EX_ERROR_INVALID_PARAMETER;
1846 shared_ptr<AbstractAction>* ptr =
1847 static_cast<shared_ptr<AbstractAction>*>(handle);
1850 return NOTI_EX_ERROR_NONE;
1853 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1855 if (handle == nullptr || type == nullptr) {
1856 LOGE("Invalid parameter");
1857 return NOTI_EX_ERROR_INVALID_PARAMETER;
1860 shared_ptr<AbstractAction>* ptr =
1861 static_cast<shared_ptr<AbstractAction>*>(handle);
1862 *type = (*ptr)->GetType();
1864 return NOTI_EX_ERROR_NONE;
1867 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1869 if (handle == nullptr || local == nullptr) {
1870 LOGE("Invalid parameter");
1871 return NOTI_EX_ERROR_INVALID_PARAMETER;
1874 shared_ptr<AbstractAction>* ptr =
1875 static_cast<shared_ptr<AbstractAction>*>(handle);
1876 *local = (*ptr)->IsLocal();
1878 return NOTI_EX_ERROR_NONE;
1881 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1882 noti_ex_item_h item) {
1883 if (handle == nullptr || item == nullptr) {
1884 LOGE("Invalid parameter");
1885 return NOTI_EX_ERROR_INVALID_PARAMETER;
1887 shared_ptr<AbstractAction>* ptr =
1888 static_cast<shared_ptr<AbstractAction>*>(handle);
1889 Handle* ih = static_cast<Handle*>(item);
1890 (*ptr)->Execute(ih->GetPtr());
1892 return NOTI_EX_ERROR_NONE;
1895 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1897 if (handle == nullptr || extra == nullptr) {
1898 LOGE("Invalid parameter");
1899 return NOTI_EX_ERROR_INVALID_PARAMETER;
1902 shared_ptr<AbstractAction>* ptr =
1903 static_cast<shared_ptr<AbstractAction>*>(handle);
1904 if (!(*ptr)->GetExtra().empty()) {
1905 *extra = strdup((*ptr)->GetExtra().c_str());
1906 if (*extra == nullptr) {
1907 LOGE("Out-of-memory");
1908 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1914 return NOTI_EX_ERROR_NONE;
1917 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1918 noti_ex_item_info_h handle, int *hide_time) {
1919 if (handle == nullptr || hide_time == nullptr) {
1920 LOGE("Invalid parameter");
1921 return NOTI_EX_ERROR_INVALID_PARAMETER;
1923 IItemInfo* p = static_cast<IItemInfo*>(handle);
1924 *hide_time = p->GetHideTime();
1925 return NOTI_EX_ERROR_NONE;
1928 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1929 noti_ex_item_info_h handle, int hide_time) {
1930 if (handle == nullptr) {
1931 LOGE("Invalid parameter");
1932 return NOTI_EX_ERROR_INVALID_PARAMETER;
1934 IItemInfo* p = static_cast<IItemInfo*>(handle);
1935 p->SetHideTime(hide_time);
1936 return NOTI_EX_ERROR_NONE;
1939 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1940 noti_ex_item_info_h handle, int *delete_time) {
1941 if (handle == nullptr || delete_time == nullptr) {
1942 LOGE("Invalid parameter");
1943 return NOTI_EX_ERROR_INVALID_PARAMETER;
1945 IItemInfo* p = static_cast<IItemInfo*>(handle);
1946 *delete_time = p->GetDeleteTime();
1947 return NOTI_EX_ERROR_NONE;
1950 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1951 noti_ex_item_info_h handle, int delete_time) {
1952 if (handle == nullptr) {
1953 LOGE("Invalid parameter");
1954 return NOTI_EX_ERROR_INVALID_PARAMETER;
1956 IItemInfo* p = static_cast<IItemInfo*>(handle);
1957 p->SetDeleteTime(delete_time);
1958 return NOTI_EX_ERROR_NONE;
1961 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1962 noti_ex_item_info_h handle, time_t *time) {
1963 if (handle == nullptr || time == nullptr) {
1964 LOGE("Invalid parameter");
1965 return NOTI_EX_ERROR_INVALID_PARAMETER;
1968 IItemInfo* p = static_cast<IItemInfo*>(handle);
1969 *time = p->GetTime();
1970 return NOTI_EX_ERROR_NONE;
1973 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1974 if (handle == nullptr) {
1975 LOGE("Invalid parameter");
1976 return NOTI_EX_ERROR_INVALID_PARAMETER;
1979 Handle* h = static_cast<Handle*>(handle);
1981 return NOTI_EX_ERROR_NONE;
1984 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1985 const char *id, noti_ex_item_h *item) {
1986 if (handle == nullptr) {
1987 LOGE("Invalid parameter");
1988 return NOTI_EX_ERROR_INVALID_PARAMETER;
1991 Handle* p = static_cast<Handle*>(handle);
1992 AbstractItem& find_item = p->Get()->FindByID(string(id));
1993 if (find_item.GetType() == AbstractItem::NullObject) {
1994 LOGW("Not exist ID");
1996 return NOTI_EX_ERROR_NONE;
1999 *item = new Handle(&find_item);
2000 return NOTI_EX_ERROR_NONE;
2003 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2005 if (handle == nullptr || type == nullptr) {
2006 LOGE("Invalid parameter");
2007 return NOTI_EX_ERROR_INVALID_PARAMETER;
2010 Handle* h = static_cast<Handle*>(handle);
2011 AbstractItem* p = h->Get();
2012 *type = p->GetType();
2013 return NOTI_EX_ERROR_NONE;
2016 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2018 if (handle == nullptr || id == nullptr) {
2019 LOGE("Invalid parameter");
2020 return NOTI_EX_ERROR_INVALID_PARAMETER;
2022 Handle* h = static_cast<Handle*>(handle);
2023 AbstractItem* p = h->Get();
2024 *id = strdup(p->GetId().c_str());
2025 return NOTI_EX_ERROR_NONE;
2028 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2030 if (handle == nullptr || id == nullptr) {
2031 LOGE("Invalid parameter");
2032 return NOTI_EX_ERROR_INVALID_PARAMETER;
2034 Handle* p = static_cast<Handle*>(handle);
2035 p->Get()->SetId(id);
2036 return NOTI_EX_ERROR_NONE;
2039 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2040 noti_ex_action_h *action) {
2041 if (handle == nullptr || action == nullptr) {
2042 LOGE("Invalid parameter");
2043 return NOTI_EX_ERROR_INVALID_PARAMETER;
2045 Handle* p = static_cast<Handle*>(handle);
2046 if (p->Get()->GetAction() == nullptr) {
2048 return NOTI_EX_ERROR_NONE;
2050 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2051 p->Get()->GetAction()));
2053 return NOTI_EX_ERROR_NONE;
2056 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2057 noti_ex_action_h action) {
2058 if (handle == nullptr) {
2059 LOGE("Invalid parameter");
2060 return NOTI_EX_ERROR_INVALID_PARAMETER;
2063 Handle* p = static_cast<Handle*>(handle);
2064 if (action == nullptr) {
2065 p->Get()->SetAction(nullptr);
2066 return NOTI_EX_ERROR_NONE;
2069 shared_ptr<AbstractAction>* ptr =
2070 static_cast<shared_ptr<AbstractAction>*>(action);
2071 p->Get()->SetAction(*ptr);
2072 return NOTI_EX_ERROR_NONE;
2075 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2076 noti_ex_style_h *style) {
2077 if (handle == nullptr || style == nullptr) {
2078 LOGE("Invalid parameter");
2079 return NOTI_EX_ERROR_INVALID_PARAMETER;
2082 Handle* p = static_cast<Handle*>(handle);
2083 shared_ptr<Style> s = p->Get()->GetStyle();
2084 if (s.get() == nullptr) {
2085 LOGW("Style is null");
2087 return NOTI_EX_ERROR_NONE;
2090 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2091 if (ptr == nullptr || ptr->get() == nullptr) {
2092 LOGE("Out of memory");
2093 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2097 return NOTI_EX_ERROR_NONE;
2100 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2101 noti_ex_style_h style) {
2102 if (handle == nullptr) {
2103 LOGE("Invalid parameter");
2104 return NOTI_EX_ERROR_INVALID_PARAMETER;
2107 Handle* p = static_cast<Handle*>(handle);
2108 if (style == nullptr) {
2109 p->Get()->SetStyle(nullptr);
2110 return NOTI_EX_ERROR_NONE;
2113 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2114 p->Get()->SetStyle(*s);
2115 return NOTI_EX_ERROR_NONE;
2118 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2120 if (handle == nullptr) {
2121 LOGE("Invalid parameter");
2122 return NOTI_EX_ERROR_INVALID_PARAMETER;
2125 Handle* p = static_cast<Handle*>(handle);
2126 p->Get()->SetVisible(visible);
2127 return NOTI_EX_ERROR_NONE;
2130 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2132 if (handle == nullptr || visible == nullptr) {
2133 LOGE("Invalid parameter");
2134 return NOTI_EX_ERROR_INVALID_PARAMETER;
2137 Handle* p = static_cast<Handle*>(handle);
2138 *visible = p->Get()->GetVisible();
2139 return NOTI_EX_ERROR_NONE;
2142 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2144 if (handle == nullptr) {
2145 LOGE("Invalid parameter");
2146 return NOTI_EX_ERROR_INVALID_PARAMETER;
2149 Handle* p = static_cast<Handle*>(handle);
2150 p->Get()->SetEnable(enable);
2151 return NOTI_EX_ERROR_NONE;
2154 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2156 if (handle == nullptr || enable == nullptr) {
2157 LOGE("Invalid parameter");
2158 return NOTI_EX_ERROR_INVALID_PARAMETER;
2161 Handle* p = static_cast<Handle*>(handle);
2162 *enable = p->Get()->GetEnable();
2163 return NOTI_EX_ERROR_NONE;
2166 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2167 const char *receiver_group) {
2168 if (handle == nullptr || receiver_group == nullptr) {
2169 LOGE("Invalid parameter");
2170 return NOTI_EX_ERROR_INVALID_PARAMETER;
2173 Handle* p = static_cast<Handle*>(handle);
2174 p->Get()->AddReceiver(receiver_group);
2175 return NOTI_EX_ERROR_NONE;
2178 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2179 const char *receiver_group) {
2180 if (handle == nullptr || receiver_group == nullptr) {
2181 LOGE("Invalid parameter");
2182 return NOTI_EX_ERROR_INVALID_PARAMETER;
2185 Handle* p = static_cast<Handle*>(handle);
2186 p->Get()->RemoveReceiver(receiver_group);
2187 return NOTI_EX_ERROR_NONE;
2190 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2191 char ***receiver_list, int *count) {
2192 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2193 LOGE("Invalid parameter");
2194 return NOTI_EX_ERROR_INVALID_PARAMETER;
2197 Handle* p = static_cast<Handle*>(handle);
2198 list<string> receivers = p->Get()->GetReceiverList();
2199 if (receivers.size() == 0) {
2200 *receiver_list = nullptr;
2202 return NOTI_EX_ERROR_NONE;
2205 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2206 if (tmp_list == nullptr) {
2207 LOGE("Out of memory");
2208 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2212 for (auto& i : receivers) {
2213 tmp_list[idx] = strdup(i.c_str());
2214 if (tmp_list[idx] == nullptr) {
2215 __noti_ex_free_str_array(tmp_list, idx);
2216 LOGE("Out of memory");
2217 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2222 *receiver_list = tmp_list;
2223 *count = receivers.size();
2224 return NOTI_EX_ERROR_NONE;
2227 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2229 if (handle == nullptr) {
2230 LOGE("Invalid parameter");
2231 return NOTI_EX_ERROR_INVALID_PARAMETER;
2234 Handle* p = static_cast<Handle*>(handle);
2235 p->Get()->SetPolicy(policy);
2236 return NOTI_EX_ERROR_NONE;
2239 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2241 if (handle == nullptr || policy == nullptr) {
2242 LOGE("Invalid parameter");
2243 return NOTI_EX_ERROR_INVALID_PARAMETER;
2246 Handle* p = static_cast<Handle*>(handle);
2247 *policy = p->Get()->GetPolicy();
2248 return NOTI_EX_ERROR_NONE;
2251 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2253 if (handle == nullptr || channel == nullptr) {
2254 LOGE("Invalid parameter");
2255 return NOTI_EX_ERROR_INVALID_PARAMETER;
2258 Handle* p = static_cast<Handle*>(handle);
2259 if (!p->Get()->GetChannel().empty())
2260 *channel = strdup(p->Get()->GetChannel().c_str());
2264 return NOTI_EX_ERROR_NONE;
2267 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2268 const char *channel) {
2269 if (handle == nullptr) {
2270 LOGE("Invalid parameter");
2271 return NOTI_EX_ERROR_INVALID_PARAMETER;
2274 Handle* p = static_cast<Handle*>(handle);
2275 p->Get()->SetChannel(channel);
2276 return NOTI_EX_ERROR_NONE;
2279 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2280 noti_ex_led_info_h led) {
2281 if (handle == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2286 Handle* p = static_cast<Handle*>(handle);
2287 if (led == nullptr) {
2288 p->Get()->SetLEDInfo(nullptr);
2289 return NOTI_EX_ERROR_NONE;
2291 shared_ptr<LEDInfo>* led_ptr =
2292 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2293 p->Get()->SetLEDInfo(*led_ptr);
2294 return NOTI_EX_ERROR_NONE;
2297 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2298 noti_ex_led_info_h *led) {
2299 if (handle == nullptr) {
2300 LOGE("Invalid parameter");
2301 return NOTI_EX_ERROR_INVALID_PARAMETER;
2304 Handle* p = static_cast<Handle*>(handle);
2305 if (p->Get()->GetLEDInfo() != nullptr)
2306 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2309 return NOTI_EX_ERROR_NONE;
2312 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2314 if (handle == nullptr) {
2315 LOGE("Invalid parameter");
2316 return NOTI_EX_ERROR_INVALID_PARAMETER;
2319 Handle* p = static_cast<Handle*>(handle);
2320 if (path == nullptr)
2321 p->Get()->SetSoundPath("");
2323 p->Get()->SetSoundPath(path);
2324 return NOTI_EX_ERROR_NONE;
2327 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2329 if (handle == nullptr) {
2330 LOGE("Invalid parameter");
2331 return NOTI_EX_ERROR_INVALID_PARAMETER;
2334 Handle* p = static_cast<Handle*>(handle);
2335 if (path == nullptr)
2336 p->Get()->SetVibrationPath("");
2338 p->Get()->SetVibrationPath(path);
2339 return NOTI_EX_ERROR_NONE;
2342 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2344 if (handle == nullptr || path == nullptr) {
2345 LOGE("Invalid parameter");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2349 Handle* p = static_cast<Handle*>(handle);
2350 if (p->Get()->GetSoundPath().empty())
2353 *path = strdup(p->Get()->GetSoundPath().c_str());
2354 return NOTI_EX_ERROR_NONE;
2357 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2359 if (handle == nullptr || path == nullptr) {
2360 LOGE("Invalid parameter");
2361 return NOTI_EX_ERROR_INVALID_PARAMETER;
2364 Handle* p = static_cast<Handle*>(handle);
2365 if (p->Get()->GetVibrationPath().empty())
2368 *path = strdup(p->Get()->GetVibrationPath().c_str());
2369 return NOTI_EX_ERROR_NONE;
2372 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2373 noti_ex_item_info_h *info) {
2374 if (handle == nullptr || info == nullptr) {
2375 LOGE("Invalid parameter");
2376 return NOTI_EX_ERROR_INVALID_PARAMETER;
2379 Handle* p = static_cast<Handle*>(handle);
2380 if (p->Get()->GetInfo() == nullptr)
2383 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2384 return NOTI_EX_ERROR_NONE;
2387 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2389 if (handle == nullptr || id == nullptr) {
2390 LOGE("Invalid parameter");
2391 return NOTI_EX_ERROR_INVALID_PARAMETER;
2394 Handle* p = static_cast<Handle*>(handle);
2395 if (p->Get()->GetSenderAppId().empty())
2398 *id = strdup(p->Get()->GetSenderAppId().c_str());
2399 return NOTI_EX_ERROR_NONE;
2402 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2404 if (handle == nullptr || tag == nullptr) {
2405 LOGE("Invalid parameter");
2406 return NOTI_EX_ERROR_INVALID_PARAMETER;
2409 Handle* p = static_cast<Handle*>(handle);
2410 if (p->Get()->GetTag().empty())
2413 *tag = strdup(p->Get()->GetTag().c_str());
2414 return NOTI_EX_ERROR_NONE;
2417 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2419 if (handle == nullptr) {
2420 LOGE("Invalid parameter");
2421 return NOTI_EX_ERROR_INVALID_PARAMETER;
2424 Handle* p = static_cast<Handle*>(handle);
2426 p->Get()->SetTag("");
2428 p->Get()->SetTag(tag);
2429 return NOTI_EX_ERROR_NONE;
2432 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2434 if (handle == nullptr || ongoing == nullptr) {
2435 LOGE("Invalid parameter");
2436 return NOTI_EX_ERROR_INVALID_PARAMETER;
2439 Handle* p = static_cast<Handle*>(handle);
2440 *ongoing = p->Get()->GetOnGoingState();
2442 return NOTI_EX_ERROR_NONE;
2445 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2447 if (handle == nullptr) {
2448 LOGE("Invalid parameter");
2449 return NOTI_EX_ERROR_INVALID_PARAMETER;
2452 Handle* p = static_cast<Handle*>(handle);
2453 p->Get()->SetOnGoingState(ongoing);
2455 return NOTI_EX_ERROR_NONE;
2458 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2459 int type, bool* exist) {
2460 if (handle == nullptr || exist == nullptr) {
2461 LOGE("Invalid parameter");
2462 return NOTI_EX_ERROR_INVALID_PARAMETER;
2465 Handle* p = static_cast<Handle*>(handle);
2466 *exist = p->Get()->IsItemTypeExist(type);
2468 return NOTI_EX_ERROR_NONE;
2471 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2473 if (handle == nullptr || type == nullptr) {
2474 LOGE("Invalid parameter");
2475 return NOTI_EX_ERROR_INVALID_PARAMETER;
2478 Handle* p = static_cast<Handle*>(handle);
2479 *type = p->Get()->GetMainType();
2481 return NOTI_EX_ERROR_NONE;
2484 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2485 const char* id, int type) {
2486 if (handle == nullptr || id == nullptr) {
2487 LOGE("Invalid parameter");
2488 return NOTI_EX_ERROR_INVALID_PARAMETER;
2491 Handle* p = static_cast<Handle*>(handle);
2492 if (!(p->Get()->SetMainType(string(id),
2493 static_cast<AbstractItem::MainType>(type))))
2494 return NOTI_EX_ERROR_INVALID_PARAMETER;
2496 return NOTI_EX_ERROR_NONE;
2499 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2500 int type, noti_ex_item_h* item) {
2501 if (handle == nullptr || item == nullptr) {
2502 LOGE("Invalid parameter");
2503 return NOTI_EX_ERROR_INVALID_PARAMETER;
2506 Handle* h = static_cast<Handle*>(handle);
2507 if (!h->IsValidType(AbstractItem::Group)) {
2508 LOGE("Invalid handle type");
2509 return NOTI_EX_ERROR_INVALID_PARAMETER;
2512 GroupItem* p = static_cast<GroupItem*>(h->Get());
2513 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2514 if (find_item.GetType() == AbstractItem::NullObject) {
2515 LOGW("Not exist ID");
2517 return NOTI_EX_ERROR_NONE;
2519 *item = new Handle(&find_item);
2521 return NOTI_EX_ERROR_NONE;
2524 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2525 const char *key, bundle **value) {
2526 if (handle == nullptr || key == nullptr || value == nullptr) {
2527 LOGE("Invalid handle type");
2528 return NOTI_EX_ERROR_INVALID_PARAMETER;
2531 Handle* p = static_cast<Handle*>(handle);
2533 Bundle b = p->Get()->GetExtensionData(key);
2534 if (b.GetCount() == 0)
2537 *value = b.GetHandle();
2539 return NOTI_EX_ERROR_NONE;
2542 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2543 const char *key, bundle *value) {
2544 if (handle == nullptr || key == nullptr || value == nullptr) {
2545 LOGE("Invalid handle type");
2546 return NOTI_EX_ERROR_INVALID_PARAMETER;
2549 Bundle b = Bundle(value);
2551 Handle* p = static_cast<Handle*>(handle);
2552 p->Get()->SetExtensionData(key, b);
2554 return NOTI_EX_ERROR_NONE;
2557 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2558 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2560 if (handle == nullptr) {
2561 LOGE("Invalid parameter");
2562 return NOTI_EX_ERROR_INVALID_PARAMETER;
2565 string receiver_group_str = "";
2567 receiver_group_str = string(receiver_group);
2569 ManagerStub* stub = new (std::nothrow) ManagerStub(
2570 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2571 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2572 receiver_group_str);
2573 if (stub == nullptr) {
2574 LOGE("Fail to create manager");
2575 return NOTI_EX_ERROR_IO_ERROR;
2577 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2578 new ManagerCallbackInfo(event_callbacks, data)));
2579 *handle = static_cast<noti_ex_manager_h>(stub);
2581 return NOTI_EX_ERROR_NONE;
2584 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2585 if (handle == nullptr) {
2586 LOGE("Invalid parameter");
2587 return NOTI_EX_ERROR_INVALID_PARAMETER;
2589 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2591 return NOTI_EX_ERROR_NONE;
2594 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2595 noti_ex_item_h **items, int *count) {
2596 if (handle == nullptr || items == nullptr || count == nullptr) {
2597 LOGE("Invalid parameter");
2598 return NOTI_EX_ERROR_INVALID_PARAMETER;
2602 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2603 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2604 if (item_list.size() == 0) {
2607 return NOTI_EX_ERROR_NONE;
2609 noti_ex_item_h* added_item =
2610 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2611 if (added_item == nullptr) {
2612 LOGE("Fail to create items");
2613 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2617 for (auto& i : item_list) {
2618 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2620 *items = added_item;
2621 *count = item_list.size();
2622 } catch (Exception &ex) {
2623 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2624 return NOTI_EX_ERROR_IO_ERROR;
2626 return NOTI_EX_ERROR_NONE;
2629 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2630 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2631 if (handle == nullptr || channel == nullptr ||
2632 items == nullptr || count == nullptr) {
2633 LOGE("Invalid parameter");
2634 return NOTI_EX_ERROR_INVALID_PARAMETER;
2638 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2639 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2640 if (item_list.size() == 0) {
2643 return NOTI_EX_ERROR_NONE;
2645 noti_ex_item_h* added_item =
2646 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2647 if (added_item == nullptr) {
2648 LOGE("Fail to create items");
2649 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2653 for (auto& i : item_list) {
2654 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2656 *items = added_item;
2657 *count = item_list.size();
2658 } catch (Exception &ex) {
2659 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2660 return NOTI_EX_ERROR_IO_ERROR;
2663 return NOTI_EX_ERROR_NONE;
2666 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2667 noti_ex_item_h noti, int *request_id) {
2668 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2669 LOGE("Invalid parameter");
2670 return NOTI_EX_ERROR_INVALID_PARAMETER;
2673 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2674 Handle* sp = static_cast<Handle*>(noti);
2675 if (sp->GetPtr().get() == nullptr) {
2676 LOGE("Invalid noti reference can not be sended");
2677 return NOTI_EX_ERROR_INVALID_PARAMETER;
2679 *request_id = stub->Update(sp->GetPtr());
2681 } catch (Exception &ex) {
2682 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2683 return NOTI_EX_ERROR_IO_ERROR;
2685 return NOTI_EX_ERROR_NONE;
2688 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2689 noti_ex_item_h noti, int *request_id) {
2690 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2691 LOGE("Invalid parameter");
2692 return NOTI_EX_ERROR_INVALID_PARAMETER;
2695 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2696 Handle* item = static_cast<Handle*>(noti);
2697 if (item->GetPtr().get() == nullptr) {
2698 LOGE("Invalid noti reference can not be sended");
2699 return NOTI_EX_ERROR_INVALID_PARAMETER;
2701 *request_id = stub->Delete(item->GetPtr());
2703 } catch (Exception &ex) {
2704 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2705 return NOTI_EX_ERROR_IO_ERROR;
2707 return NOTI_EX_ERROR_NONE;
2710 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2712 if (handle == nullptr || request_id == nullptr) {
2713 LOGE("Invalid parameter");
2714 return NOTI_EX_ERROR_INVALID_PARAMETER;
2717 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2718 *request_id = stub->DeleteAll();
2719 } catch (Exception &ex) {
2720 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2721 return NOTI_EX_ERROR_IO_ERROR;
2723 return NOTI_EX_ERROR_NONE;
2726 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2727 noti_ex_manager_h handle, char* channel, int* request_id) {
2728 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2729 LOGE("Invalid parameter");
2730 return NOTI_EX_ERROR_INVALID_PARAMETER;
2734 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2735 *request_id = stub->DeleteByChannel(channel);
2736 } catch (Exception &ex) {
2737 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2738 return NOTI_EX_ERROR_IO_ERROR;
2741 return NOTI_EX_ERROR_NONE;
2744 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2745 noti_ex_item_h noti, int *request_id) {
2746 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2747 LOGE("Invalid parameter");
2748 return NOTI_EX_ERROR_INVALID_PARAMETER;
2751 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2752 Handle* item = static_cast<Handle*>(noti);
2753 if (item->GetPtr().get() == nullptr) {
2754 LOGE("Invalid noti reference can not be sended");
2755 return NOTI_EX_ERROR_INVALID_PARAMETER;
2757 *request_id = stub->Hide(item->GetPtr());
2759 } catch (Exception &ex) {
2760 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2761 return NOTI_EX_ERROR_IO_ERROR;
2763 return NOTI_EX_ERROR_NONE;
2766 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2767 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2768 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2769 LOGE("Invalid parameter");
2770 return NOTI_EX_ERROR_INVALID_PARAMETER;
2773 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2774 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2775 if (ptr == nullptr) {
2776 LOGW("Not exist ID");
2778 return NOTI_EX_ERROR_NONE;
2780 *item = new Handle(ptr);
2781 } catch (Exception &ex) {
2782 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2783 return NOTI_EX_ERROR_IO_ERROR;
2785 return NOTI_EX_ERROR_NONE;
2788 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2789 noti_ex_event_info_h info, noti_ex_error_e error) {
2790 if (handle == nullptr || info == nullptr) {
2791 LOGE("Invalid parameter");
2792 return NOTI_EX_ERROR_INVALID_PARAMETER;
2795 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2796 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2797 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2798 static_cast<NotificationError>(error));
2799 } catch (Exception &ex) {
2800 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2801 return NOTI_EX_ERROR_IO_ERROR;
2803 return NOTI_EX_ERROR_NONE;
2806 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2807 noti_ex_manager_h handle, int *cnt) {
2809 if (handle == nullptr || cnt == nullptr) {
2810 LOGE("Invalid parameter");
2811 return NOTI_EX_ERROR_INVALID_PARAMETER;
2814 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2815 *cnt = stub->GetCount();
2816 } catch (Exception &ex) {
2817 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2818 return NOTI_EX_ERROR_IO_ERROR;
2820 return NOTI_EX_ERROR_NONE;
2823 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2824 const char *id, float min, float current, float max) {
2827 if (handle == nullptr) {
2828 LOGE("Invalid parameter");
2829 return NOTI_EX_ERROR_INVALID_PARAMETER;
2833 p = new (std::nothrow) ProgressItem(id, min, current, max);
2835 p = new (std::nothrow) ProgressItem(min, current, max);
2838 LOGE("Out-of-memory");
2839 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2842 *handle = new Handle(shared_ptr<AbstractItem>(p));
2844 return NOTI_EX_ERROR_NONE;
2847 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2848 noti_ex_item_h handle, float *current) {
2849 if (handle == nullptr || current == nullptr) {
2850 LOGE("Invalid parameter");
2851 return NOTI_EX_ERROR_INVALID_PARAMETER;
2854 Handle *h = static_cast<Handle*>(handle);
2855 if (!h->IsValidType(AbstractItem::Progress)) {
2856 LOGE("Invalid handle type");
2857 return NOTI_EX_ERROR_INVALID_PARAMETER;
2859 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2860 *current = p->GetCurrent();
2862 return NOTI_EX_ERROR_NONE;
2865 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2866 noti_ex_item_h handle, float current) {
2867 if (handle == nullptr) {
2868 LOGE("Invalid parameter");
2869 return NOTI_EX_ERROR_INVALID_PARAMETER;
2872 Handle *h = static_cast<Handle*>(handle);
2873 if (!h->IsValidType(AbstractItem::Progress)) {
2874 LOGE("Invalid handle type");
2875 return NOTI_EX_ERROR_INVALID_PARAMETER;
2877 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2878 p->SetCurrent(current);
2880 return NOTI_EX_ERROR_NONE;
2883 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2885 if (handle == nullptr || min == nullptr) {
2886 LOGE("Invalid parameter");
2887 return NOTI_EX_ERROR_INVALID_PARAMETER;
2890 Handle *h = static_cast<Handle*>(handle);
2891 if (!h->IsValidType(AbstractItem::Progress)) {
2892 LOGE("Invalid handle type");
2893 return NOTI_EX_ERROR_INVALID_PARAMETER;
2895 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2898 return NOTI_EX_ERROR_NONE;
2901 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2903 if (handle == nullptr || max == nullptr) {
2904 LOGE("Invalid parameter");
2905 return NOTI_EX_ERROR_INVALID_PARAMETER;
2908 Handle *h = static_cast<Handle*>(handle);
2909 if (!h->IsValidType(AbstractItem::Progress)) {
2910 LOGE("Invalid handle type");
2911 return NOTI_EX_ERROR_INVALID_PARAMETER;
2913 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2916 return NOTI_EX_ERROR_NONE;
2919 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2921 if (handle == nullptr || type == nullptr) {
2922 LOGE("Invalid parameter");
2923 return NOTI_EX_ERROR_INVALID_PARAMETER;
2926 Handle *h = static_cast<Handle*>(handle);
2927 if (!h->IsValidType(AbstractItem::Progress)) {
2928 LOGE("Invalid handle type");
2929 return NOTI_EX_ERROR_INVALID_PARAMETER;
2931 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2932 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2934 return NOTI_EX_ERROR_NONE;
2937 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2939 if (handle == nullptr) {
2940 LOGE("Invalid parameter");
2941 return NOTI_EX_ERROR_INVALID_PARAMETER;
2944 Handle *h = static_cast<Handle*>(handle);
2945 if (!h->IsValidType(AbstractItem::Progress)) {
2946 LOGE("Invalid handle type");
2947 return NOTI_EX_ERROR_INVALID_PARAMETER;
2949 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2950 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2952 return NOTI_EX_ERROR_NONE;
2955 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2956 noti_ex_reporter_events_s event_callbacks, void *data) {
2957 if (handle == nullptr) {
2958 LOGE("Invalid parameter");
2959 return NOTI_EX_ERROR_INVALID_PARAMETER;
2962 ReporterStub* stub = new (std::nothrow) ReporterStub(
2963 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2964 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2965 if (stub == nullptr) {
2966 LOGE("Fail to create manager");
2967 return NOTI_EX_ERROR_IO_ERROR;
2969 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2970 new ReporterCallbackInfo(event_callbacks, data)));
2972 *handle = static_cast<noti_ex_reporter_h>(stub);
2974 return NOTI_EX_ERROR_NONE;
2977 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2978 if (handle == nullptr) {
2979 LOGE("Invalid parameter");
2980 return NOTI_EX_ERROR_INVALID_PARAMETER;
2982 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2984 return NOTI_EX_ERROR_NONE;
2987 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2988 noti_ex_event_info_h info, noti_ex_error_e error) {
2989 if (handle == nullptr || info == nullptr) {
2990 LOGE("Invalid parameter");
2991 return NOTI_EX_ERROR_INVALID_PARAMETER;
2994 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2995 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2996 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2997 static_cast<NotificationError>(error));
2998 } catch (Exception &ex) {
2999 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3000 return NOTI_EX_ERROR_IO_ERROR;
3002 return NOTI_EX_ERROR_NONE;
3005 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3006 noti_ex_item_h noti, int *request_id) {
3007 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3008 LOGE("Invalid parameter");
3009 return NOTI_EX_ERROR_INVALID_PARAMETER;
3012 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3013 Handle* h = static_cast<Handle*>(noti);
3014 if (h->GetPtr().get() == nullptr) {
3015 LOGE("Invalid noti reference can not be sended");
3016 return NOTI_EX_ERROR_INVALID_PARAMETER;
3018 *request_id = stub->Post(h->GetPtr());
3020 } catch (Exception &ex) {
3021 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3022 return NOTI_EX_ERROR_IO_ERROR;
3024 return NOTI_EX_ERROR_NONE;
3027 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3028 noti_ex_item_h *noti_list, int count, int *request_id) {
3030 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3031 LOGE("Invalid parameter");
3032 return NOTI_EX_ERROR_INVALID_PARAMETER;
3035 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3036 list<shared_ptr<item::AbstractItem>> notiList;
3037 for (int i = 0; i < count; i++) {
3038 Handle* item = static_cast<Handle*>(noti_list[i]);
3039 notiList.push_back(item->GetPtr());
3041 *request_id = stub->Post(notiList);
3042 } catch (Exception &ex) {
3043 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3044 return NOTI_EX_ERROR_IO_ERROR;
3046 return NOTI_EX_ERROR_NONE;
3049 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3050 noti_ex_item_h noti, int *request_id) {
3051 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3052 LOGE("Invalid parameter");
3053 return NOTI_EX_ERROR_INVALID_PARAMETER;
3056 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3057 Handle* item = static_cast<Handle*>(noti);
3058 if (item->GetPtr().get() == nullptr) {
3059 LOGE("Invalid noti reference can not be sended");
3060 return NOTI_EX_ERROR_INVALID_PARAMETER;
3062 *request_id = stub->Update(item->GetPtr());
3064 } catch (Exception &ex) {
3065 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3066 return NOTI_EX_ERROR_IO_ERROR;
3068 return NOTI_EX_ERROR_NONE;
3071 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3072 noti_ex_item_h noti, int *request_id) {
3073 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3074 LOGE("Invalid parameter");
3075 return NOTI_EX_ERROR_INVALID_PARAMETER;
3078 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3079 Handle* item = static_cast<Handle*>(noti);
3080 if (item->GetPtr().get() == nullptr) {
3081 LOGE("Invalid noti reference can not be sended");
3082 return NOTI_EX_ERROR_INVALID_PARAMETER;
3084 *request_id = stub->Delete(item->GetPtr());
3086 } catch (Exception &ex) {
3087 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3088 return NOTI_EX_ERROR_IO_ERROR;
3090 return NOTI_EX_ERROR_NONE;
3093 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3094 noti_ex_reporter_h handle, int *request_id) {
3095 if (handle == nullptr || request_id == nullptr) {
3096 LOGE("Invalid parameter");
3097 return NOTI_EX_ERROR_INVALID_PARAMETER;
3100 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3101 *request_id = stub->DeleteAll();
3102 } catch (Exception &ex) {
3103 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3104 return NOTI_EX_ERROR_IO_ERROR;
3106 return NOTI_EX_ERROR_NONE;
3109 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3110 noti_ex_reporter_h handle, char* channel, int* request_id) {
3111 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3112 LOGE("Invalid parameter");
3113 return NOTI_EX_ERROR_INVALID_PARAMETER;
3117 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3118 *request_id = stub->DeleteByChannel(channel);
3119 } catch (Exception &ex) {
3120 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3121 return NOTI_EX_ERROR_IO_ERROR;
3124 return NOTI_EX_ERROR_NONE;
3127 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3128 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3129 if (handle == nullptr || root_id == nullptr || item == nullptr) {
3130 LOGE("Invalid parameter");
3131 return NOTI_EX_ERROR_INVALID_PARAMETER;
3134 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3135 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3136 if (ptr == nullptr) {
3137 LOGW("Not exist ID");
3139 return NOTI_EX_ERROR_NONE;
3141 *item = new Handle(ptr);
3142 } catch (Exception &ex) {
3143 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3144 return NOTI_EX_ERROR_IO_ERROR;
3146 return NOTI_EX_ERROR_NONE;
3149 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3150 const char *id, const char *text, const char *hyperlink) {
3151 if (handle == nullptr || text == nullptr) {
3152 LOGE("Invalid parameter");
3153 return NOTI_EX_ERROR_INVALID_PARAMETER;
3162 p = new (std::nothrow) TextItem(id, std::string(text),
3163 std::string(hyperlink));
3165 p = new (std::nothrow) TextItem(id, std::string(text));
3168 LOGE("Out-of-memory");
3169 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3172 *handle = new Handle(shared_ptr<AbstractItem>(p));
3174 return NOTI_EX_ERROR_NONE;
3177 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3178 const char *contents) {
3179 if (handle == nullptr || contents == nullptr) {
3180 LOGE("Invalid parameter");
3181 return NOTI_EX_ERROR_INVALID_PARAMETER;
3184 Handle* p = static_cast<Handle*>(handle);
3185 if (!p->IsValidType(AbstractItem::Text)) {
3186 LOGE("Invalid handle type");
3187 return NOTI_EX_ERROR_INVALID_PARAMETER;
3189 TextItem* ti = static_cast<TextItem*>(p->Get());
3190 ti->SetContents(std::string(contents));
3192 return NOTI_EX_ERROR_NONE;
3195 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3197 if (handle == nullptr || contents == nullptr) {
3198 LOGE("Invalid parameter");
3199 return NOTI_EX_ERROR_INVALID_PARAMETER;
3202 Handle* p = static_cast<Handle*>(handle);
3203 if (!p->IsValidType(AbstractItem::Text)) {
3204 LOGE("Invalid handle type");
3205 return NOTI_EX_ERROR_INVALID_PARAMETER;
3208 TextItem* ti = static_cast<TextItem*>(p->Get());
3210 if (ti->GetMultiLanguage() != nullptr &&
3211 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3212 str = ti->GetMultiLanguage()->GetTranslatedString();
3213 else if (!ti->GetContents().empty())
3214 str = ti->GetContents();
3216 *contents = strdup(str.c_str());
3217 if (*contents == nullptr) {
3218 LOGE("Out-of-memory");
3219 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3222 return NOTI_EX_ERROR_NONE;
3225 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3226 noti_ex_item_h handle, char **hyper_link) {
3227 if (handle == nullptr || hyper_link == nullptr) {
3228 LOGE("Invalid parameter");
3229 return NOTI_EX_ERROR_INVALID_PARAMETER;
3232 Handle* p = static_cast<Handle*>(handle);
3233 if (!p->IsValidType(AbstractItem::Text)) {
3234 LOGE("Invalid handle type");
3235 return NOTI_EX_ERROR_INVALID_PARAMETER;
3237 TextItem* ti = static_cast<TextItem*>(p->Get());
3238 if (!ti->GetHyperLink().empty()) {
3239 *hyper_link = strdup(ti->GetHyperLink().c_str());
3240 if (*hyper_link == nullptr) {
3241 LOGE("Out-of-memory");
3242 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3245 *hyper_link = nullptr;
3248 return NOTI_EX_ERROR_NONE;
3251 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3252 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3253 if (handle == nullptr) {
3254 LOGE("Invalid parameter");
3255 return NOTI_EX_ERROR_INVALID_PARAMETER;
3258 Handle* p = static_cast<Handle*>(handle);
3259 if (!p->IsValidType(AbstractItem::Text)) {
3260 LOGE("Invalid handle type");
3261 return NOTI_EX_ERROR_INVALID_PARAMETER;
3264 TextItem* ti = static_cast<TextItem*>(p->Get());
3265 if (multi == nullptr) {
3266 ti->SetMultiLanguage(nullptr);
3267 return NOTI_EX_ERROR_NONE;
3270 shared_ptr<MultiLanguage> mul_ptr =
3271 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3272 ti->SetMultiLanguage(mul_ptr);
3273 ti->GetMultiLanguage()->UpdateString();
3275 return NOTI_EX_ERROR_NONE;
3278 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3279 const char *id, time_t time) {
3282 if (handle == nullptr) {
3283 LOGE("Invalid parameter");
3284 return NOTI_EX_ERROR_INVALID_PARAMETER;
3289 p = new (std::nothrow) TimeItem(id, time);
3291 p = new (std::nothrow) TimeItem(time);
3293 p = new (std::nothrow) TimeItem();
3297 LOGE("Out-of-memory");
3298 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3301 *handle = new Handle(shared_ptr<AbstractItem>(p));
3303 return NOTI_EX_ERROR_NONE;
3306 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3308 if (handle == nullptr || time == nullptr) {
3309 LOGE("Invalid parameter");
3310 return NOTI_EX_ERROR_INVALID_PARAMETER;
3312 Handle* h = static_cast<Handle*>(handle);
3313 if (!h->IsValidType(AbstractItem::Time)) {
3314 LOGE("Invalid handle type");
3315 return NOTI_EX_ERROR_INVALID_PARAMETER;
3317 TimeItem* p = static_cast<TimeItem*>(h->Get());
3318 *time = p->GetTime();
3320 return NOTI_EX_ERROR_NONE;
3323 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3325 if (handle == nullptr) {
3326 LOGE("Invalid parameter");
3327 return NOTI_EX_ERROR_INVALID_PARAMETER;
3329 Handle* h = static_cast<Handle*>(handle);
3330 if (!h->IsValidType(AbstractItem::Time)) {
3331 LOGE("Invalid handle type");
3332 return NOTI_EX_ERROR_INVALID_PARAMETER;
3334 TimeItem* p = static_cast<TimeItem*>(h->Get());
3337 return NOTI_EX_ERROR_NONE;
3340 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3341 noti_ex_action_h *handle, const char *extra) {
3342 if (handle == nullptr) {
3343 LOGE("Invalid parameter");
3344 return NOTI_EX_ERROR_INVALID_PARAMETER;
3347 string extra_str = "";
3349 extra_str = string(extra);
3351 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3352 new (std::nothrow) VisibilityAction(extra_str));
3353 if (ptr == nullptr) {
3354 LOGE("Out-of-memory");
3355 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3360 return NOTI_EX_ERROR_NONE;
3363 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3364 const char *id, bool visible) {
3365 if (handle == nullptr || id == nullptr) {
3366 LOGE("Invalid parameter");
3367 return NOTI_EX_ERROR_INVALID_PARAMETER;
3370 shared_ptr<AbstractAction>* ptr =
3371 static_cast<shared_ptr<AbstractAction>*>(handle);
3372 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3373 action->SetVisibility(id, visible);
3375 return NOTI_EX_ERROR_NONE;
3378 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3379 const char* msgid, const char* format, ...) {
3380 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3381 LOGE("Invalid parameter");
3382 return NOTI_EX_ERROR_INVALID_PARAMETER;
3385 const char* format_idx = format;
3388 va_start(args, format);
3389 while (*format_idx != '\0') {
3390 char* arg = nullptr;
3393 stringstream stream;
3394 if (*format_idx == '%') {
3395 switch (*(format_idx + 1)) {
3397 arg = va_arg(args, char *);
3398 arr.push_back(string(arg));
3401 arg_i = va_arg(args, int);
3402 arr.push_back(to_string(arg_i));
3405 arg_f = va_arg(args, double);
3406 stream << std::fixed << std::setprecision(2) << arg_f;
3407 arr.push_back(stream.str());
3415 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3417 LOGE("Out-of-memory");
3418 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3420 *handle = new shared_ptr<MultiLanguage>(p);
3422 return NOTI_EX_ERROR_NONE;
3425 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3426 if (handle == nullptr) {
3427 LOGE("Invalid parameter");
3428 return NOTI_EX_ERROR_INVALID_PARAMETER;
3431 shared_ptr<MultiLanguage>* mul_ptr =
3432 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3434 return NOTI_EX_ERROR_NONE;
3437 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3438 noti_ex_item_h item, int64_t* private_id) {
3439 if (item == nullptr || private_id == nullptr) {
3440 LOGE("Invalid parameter");
3441 return NOTI_EX_ERROR_INVALID_PARAMETER;
3444 Handle* h = static_cast<Handle*>(item);
3445 *private_id = static_pointer_cast<IItemInfoInternal>(
3446 h->Get()->GetInfo())->GetPrivateId();
3448 return NOTI_EX_ERROR_NONE;
3451 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3452 noti_ex_item_h item, int64_t priv_id) {
3453 if (item == nullptr) {
3454 LOGE("Invalid parameter");
3455 return NOTI_EX_ERROR_INVALID_PARAMETER;
3458 Handle* h = static_cast<Handle*>(item);
3459 static_pointer_cast<IItemInfoInternal>(
3460 h->Get()->GetInfo())->SetPrivateId(priv_id);
3462 return NOTI_EX_ERROR_NONE;
3465 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3466 if (list == nullptr) {
3467 LOGE("Invalid parameter");
3468 return NOTI_EX_ERROR_INVALID_PARAMETER;
3471 LOGI("Free strings (%d)", count);
3472 for (int i = 0; i < count; i++)
3476 return NOTI_EX_ERROR_NONE;
3479 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3480 if (handle == nullptr) {
3481 LOGE("Invalid parameter");
3482 return NOTI_EX_ERROR_INVALID_PARAMETER;
3484 Handle* h = static_cast<Handle*>(handle);
3485 if (!h->IsValidType(AbstractItem::Group)) {
3486 LOGE("Invalid handle type");
3487 return NOTI_EX_ERROR_INVALID_PARAMETER;
3489 GroupItem* p = static_cast<GroupItem*>(h->Get());
3490 p->RemoveChildren();
3492 return NOTI_EX_ERROR_NONE;
3495 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3496 const char *id, const char *icon_path) {
3497 if (handle == nullptr || icon_path == nullptr) {
3498 LOGE("Invalid parameter");
3499 return NOTI_EX_ERROR_INVALID_PARAMETER;
3504 p = new (std::nothrow) IconItem(id, icon_path);
3506 p = new (std::nothrow) IconItem(icon_path);
3509 LOGE("Out-of-memory");
3510 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3513 *handle = new Handle(shared_ptr<AbstractItem>(p));
3515 return NOTI_EX_ERROR_NONE;
3518 int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3519 if (handle == nullptr || icon_path == nullptr) {
3520 LOGE("Invalid parameter");
3521 return NOTI_EX_ERROR_INVALID_PARAMETER;
3524 Handle* h = static_cast<Handle*>(handle);
3525 if (!h->IsValidType(AbstractItem::Icon)) {
3526 LOGE("Invalid handle type");
3527 return NOTI_EX_ERROR_INVALID_PARAMETER;
3530 IconItem* p = static_cast<IconItem*>(h->Get());
3531 if (!p->GetImagePath().empty()) {
3532 *icon_path = strdup(p->GetImagePath().c_str());
3533 if (*icon_path == nullptr) {
3534 LOGE("Out-of-memory");
3535 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3538 *icon_path = nullptr;
3541 return NOTI_EX_ERROR_NONE;