2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include "api/notification_ex.h"
26 #include "api/notification_ex_internal.h"
27 #include "notification-ex/reporter.h"
28 #include "notification-ex/app_control_action.h"
29 #include "notification-ex/button_item.h"
30 #include "notification-ex/chat_message_item.h"
31 #include "notification-ex/checkbox_item.h"
32 #include "notification-ex/entry_item.h"
33 #include "notification-ex/group_item.h"
34 #include "notification-ex/input_selector_item.h"
35 #include "notification-ex/abstract_item.h"
36 #include "notification-ex/progress_item.h"
37 #include "notification-ex/time_item.h"
38 #include "notification-ex/visibility_action.h"
39 #include "notification-ex/event_info_internal.h"
40 #include "notification-ex/manager.h"
41 #include "notification-ex/dbus_sender.h"
42 #include "notification-ex/dbus_event_listener.h"
43 #include "notification-ex/exception.h"
44 #include "notification-ex/iitem_info_internal.h"
45 #include "notification-ex/icon_item.h"
50 #define LOG_TAG "NOTIFICATION_EX"
55 #define EXPORT_API __attribute__((visibility("default")))
58 using namespace tizen_base;
59 using namespace notification::item;
60 using namespace notification;
66 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
67 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
68 : ref_(nullptr), ptr_(move(ptr)) { }
69 virtual ~Handle() = default;
70 item::AbstractItem* Get() const {
76 bool IsValidType(int type) const {
77 return (Get()->GetType() == type
78 || Get()->GetType() >= AbstractItem::Custom);
81 std::shared_ptr<item::AbstractItem> GetPtr() const {
83 return std::shared_ptr<item::AbstractItem>({});
88 item::AbstractItem* ref_;
89 std::shared_ptr<item::AbstractItem> ptr_;
92 class ManagerCallbackInfo {
94 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
95 : user_data_(user_data) {
97 cb_.updated = cb.updated;
98 cb_.deleted = cb.deleted;
102 void InvokeAdded(Manager* manager, const IEventInfo& info,
103 list<shared_ptr<AbstractItem>> addedItem) {
104 if (cb_.added == nullptr)
106 noti_ex_item_h* added_item =
107 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
108 if (added_item == nullptr) {
109 LOGE("Out of memory");
114 for (auto& i : addedItem) {
116 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
119 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
120 cb_.added(static_cast<noti_ex_manager_h>(manager),
121 static_cast<noti_ex_event_info_h>(c_info), added_item,
122 addedItem.size(), user_data_);
125 void InvokeUpdated(Manager* manager, const IEventInfo& info,
126 shared_ptr<item::AbstractItem> updatedItem) {
127 if (cb_.updated == nullptr)
129 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
130 cb_.updated(static_cast<noti_ex_manager_h>(manager),
131 static_cast<noti_ex_event_info_h>(c_info),
132 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
135 void InvokeDeleted(Manager* manager, const IEventInfo& info,
136 shared_ptr<item::AbstractItem> deletedItem) {
137 if (cb_.deleted == nullptr)
139 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
140 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
141 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
142 static_cast<noti_ex_event_info_h>(c_info),
143 nullptr, user_data_);
145 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
146 static_cast<noti_ex_event_info_h>(c_info),
147 static_cast<noti_ex_item_h>(
148 new Handle(deletedItem)), user_data_);
152 void InvokeError(Manager* manager, NotificationError error, int requestId) {
153 if (cb_.error == nullptr)
155 cb_.error(static_cast<noti_ex_manager_h>(manager),
156 static_cast<noti_ex_error_e>(error), requestId, user_data_);
160 noti_ex_manager_events_s cb_;
164 class ManagerStub : public Manager {
166 ManagerStub(std::unique_ptr<IEventSender> sender,
167 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
168 : Manager(move(sender), move(listener), receiver_group) {
171 void OnAdd(const IEventInfo& info,
172 list<shared_ptr<AbstractItem>> addedItem) override {
173 cb_->InvokeAdded(this, info, addedItem);
176 void OnUpdate(const IEventInfo& info,
177 std::shared_ptr<item::AbstractItem> updatedItem) override {
178 cb_->InvokeUpdated(this, info, updatedItem);
181 void OnDelete(const IEventInfo& info,
182 shared_ptr<item::AbstractItem> deletedItem) override {
183 cb_->InvokeDeleted(this, info, deletedItem);
186 void OnError(NotificationError error, int requestId) override {
187 cb_->InvokeError(this, error, requestId);
190 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
192 return NOTI_EX_ERROR_NONE;
195 int ClearManagerCallbackInfo() {
197 return NOTI_EX_ERROR_NONE;
201 unique_ptr<ManagerCallbackInfo> cb_;
205 class ReporterCallbackInfo {
207 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
208 : user_data_(user_data) {
209 cb_.event = cb.event;
210 cb_.error = cb.error;
213 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
214 list<shared_ptr<AbstractItem>> notiList) {
215 if (cb_.event == nullptr)
217 noti_ex_item_h* noti_list =
218 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
219 if (noti_list == nullptr) {
220 LOGE("Out of memory");
225 for (auto& i : notiList) {
227 static_cast<noti_ex_item_h>(new Handle(i));
230 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
231 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
232 static_cast<noti_ex_event_info_h>(c_info), noti_list,
233 notiList.size(), user_data_);
237 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
238 if (cb_.error == nullptr)
240 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
241 static_cast<noti_ex_error_e>(error), requestId, user_data_);
245 noti_ex_reporter_events_s cb_;
249 class ReporterStub : public Reporter {
251 ReporterStub(std::unique_ptr<IEventSender> sender,
252 std::unique_ptr<IEventListener> listener)
253 : Reporter(move(sender), move(listener)) {
256 void OnEvent(const IEventInfo& info,
257 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
258 cb_->InvokeEvent(this, info, notiList);
261 void OnError(NotificationError error, int requestId) override {
262 cb_->InvokeError(this, error, requestId);
265 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
267 return NOTI_EX_ERROR_NONE;
270 int ClearReporterCallbackInfo() {
272 return NOTI_EX_ERROR_NONE;
276 unique_ptr<ReporterCallbackInfo> cb_;
281 void __noti_ex_free_str_array(char** val, int length) {
283 for (i = 0; i < length ; i++)
288 extern "C" EXPORT_API int noti_ex_action_app_control_create(
289 noti_ex_action_h *handle, app_control_h app_control,
291 if (handle == nullptr || app_control == nullptr) {
292 LOGE("Invalid parameter");
293 return NOTI_EX_ERROR_INVALID_PARAMETER;
296 shared_ptr<AbstractAction>* p;
299 p = new (std::nothrow) shared_ptr<AbstractAction>(
300 new (std::nothrow) AppControlAction(app_control, extra));
302 p = new (std::nothrow) shared_ptr<AbstractAction>(
303 new (std::nothrow) AppControlAction(app_control));
307 LOGE("Out-of-memory");
308 return NOTI_EX_ERROR_OUT_OF_MEMORY;
313 return NOTI_EX_ERROR_NONE;
316 extern "C" EXPORT_API int noti_ex_action_app_control_set(
317 noti_ex_action_h handle, app_control_h app_control) {
318 if (handle == nullptr || app_control == nullptr) {
319 LOGE("Invalid parameter");
320 return NOTI_EX_ERROR_INVALID_PARAMETER;
323 shared_ptr<AbstractAction>* ptr =
324 static_cast<shared_ptr<AbstractAction>*>(handle);
325 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
326 action->SetAppControl(app_control);
328 return NOTI_EX_ERROR_NONE;
331 extern "C" EXPORT_API int noti_ex_action_app_control_get(
332 noti_ex_action_h handle, app_control_h *app_control) {
333 if (handle == nullptr || app_control == nullptr) {
334 LOGE("Invalid parameter");
335 return NOTI_EX_ERROR_INVALID_PARAMETER;
338 shared_ptr<AbstractAction>* ptr =
339 static_cast<shared_ptr<AbstractAction>*>(handle);
340 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
343 int r = app_control_clone(&clone, action->GetAppControl());
344 if (r != APP_CONTROL_ERROR_NONE) {
345 LOGE("failed to create a app_control handle : %d", r);
346 return NOTI_EX_ERROR_INVALID_PARAMETER;
349 *app_control = clone;
351 return NOTI_EX_ERROR_NONE;
354 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
355 const char *id, const char *title) {
358 if (handle == nullptr || title == nullptr) {
359 LOGE("Invalid parameter");
360 return NOTI_EX_ERROR_INVALID_PARAMETER;
364 p = new (std::nothrow) ButtonItem(id, title);
366 p = new (std::nothrow) ButtonItem(title);
369 LOGE("Out-of-memory");
370 return NOTI_EX_ERROR_OUT_OF_MEMORY;
372 *handle = new Handle(shared_ptr<AbstractItem>(p));
374 return NOTI_EX_ERROR_NONE;
377 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
379 if (handle == nullptr || title == nullptr) {
380 LOGE("Invalid parameter");
381 return NOTI_EX_ERROR_INVALID_PARAMETER;
384 Handle* sp = static_cast<Handle*>(handle);
385 if (!sp->IsValidType(AbstractItem::Button)) {
386 LOGE("Invalid handle type");
387 return NOTI_EX_ERROR_INVALID_PARAMETER;
390 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
392 if (p->GetMultiLanguage() != nullptr &&
393 !p->GetMultiLanguage()->GetTranslatedString().empty())
394 str = p->GetMultiLanguage()->GetTranslatedString();
395 else if (!p->GetTitle().empty())
398 *title = strdup(str.c_str());
399 if (*title == nullptr) {
400 LOGE("Out-of-memory");
401 return NOTI_EX_ERROR_OUT_OF_MEMORY;
404 return NOTI_EX_ERROR_NONE;
407 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
408 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
409 if (handle == nullptr) {
410 LOGE("Invalid parameter");
411 return NOTI_EX_ERROR_INVALID_PARAMETER;
414 Handle* p = static_cast<Handle*>(handle);
415 if (!p->IsValidType(AbstractItem::Button)) {
416 LOGE("Invalid handle type");
417 return NOTI_EX_ERROR_INVALID_PARAMETER;
420 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
421 if (multi == nullptr) {
422 bi->SetMultiLanguage(nullptr);
423 return NOTI_EX_ERROR_NONE;
426 shared_ptr<MultiLanguage> mul_ptr =
427 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
429 mul_ptr->UpdateString();
430 bi->SetMultiLanguage(mul_ptr);
432 return NOTI_EX_ERROR_NONE;
435 extern "C" EXPORT_API int noti_ex_item_button_set_image(
436 noti_ex_item_h handle, const char *path) {
437 if (handle == nullptr || path == nullptr) {
438 LOGE("Invalid parameter");
439 return NOTI_EX_ERROR_INVALID_PARAMETER;
442 Handle* h = static_cast<Handle*>(handle);
443 if (!h->IsValidType(AbstractItem::Button)) {
444 LOGE("Invalid handle type");
445 return NOTI_EX_ERROR_INVALID_PARAMETER;
448 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
451 return NOTI_EX_ERROR_NONE;
454 extern "C" EXPORT_API int noti_ex_item_button_get_image(
455 noti_ex_item_h handle, char **path) {
456 if (handle == nullptr || path == nullptr) {
457 LOGE("Invalid parameter");
458 return NOTI_EX_ERROR_INVALID_PARAMETER;
461 Handle* h = static_cast<Handle*>(handle);
462 if (!h->IsValidType(AbstractItem::Button)) {
463 LOGE("Invalid handle type");
464 return NOTI_EX_ERROR_INVALID_PARAMETER;
467 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
468 if (!p->GetImgPath().empty())
469 *path = strdup(p->GetImgPath().c_str());
473 return NOTI_EX_ERROR_NONE;
476 extern "C" EXPORT_API int noti_ex_item_button_set_contents(
477 noti_ex_item_h handle, const char *contents) {
478 if (handle == nullptr || contents == nullptr) {
479 LOGE("Invalid parameter");
480 return NOTI_EX_ERROR_INVALID_PARAMETER;
483 Handle* h = static_cast<Handle*>(handle);
484 if (!h->IsValidType(AbstractItem::Button)) {
485 LOGE("Invalid handle type");
486 return NOTI_EX_ERROR_INVALID_PARAMETER;
489 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
490 p->SetContents(std::string(contents));
492 return NOTI_EX_ERROR_NONE;
495 extern "C" EXPORT_API int noti_ex_item_button_get_contents(
496 noti_ex_item_h handle, char **contents) {
497 if (handle == nullptr || contents == nullptr) {
498 LOGE("Invalid parameter");
499 return NOTI_EX_ERROR_INVALID_PARAMETER;
502 Handle* h = static_cast<Handle*>(handle);
503 if (!h->IsValidType(AbstractItem::Button)) {
504 LOGE("Invalid handle type");
505 return NOTI_EX_ERROR_INVALID_PARAMETER;
508 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
509 if (!p->GetContents().empty())
510 *contents = strdup(p->GetContents().c_str());
514 return NOTI_EX_ERROR_NONE;
517 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
518 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
519 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
520 noti_ex_item_chat_message_type_e message_type) {
521 if (handle == nullptr || (text == nullptr && image == nullptr)
522 || name == nullptr || time == nullptr
523 || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
524 LOGE("Invalid parameter");
525 return NOTI_EX_ERROR_INVALID_PARAMETER;
531 auto* p = new (std::nothrow) ChatMessageItem(id,
532 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
533 text == nullptr ? nullptr
534 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
535 image == nullptr ? nullptr
536 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
537 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
538 static_cast<ChatMessageItem::Type>(message_type));
540 LOGE("Out-of-memory");
541 return NOTI_EX_ERROR_OUT_OF_MEMORY;
544 *handle = new Handle(shared_ptr<AbstractItem>(p));
546 return NOTI_EX_ERROR_NONE;
549 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
550 noti_ex_item_h handle, noti_ex_item_h *name) {
551 if (handle == nullptr || name == nullptr) {
552 LOGE("Invalid parameter");
553 return NOTI_EX_ERROR_INVALID_PARAMETER;
555 Handle* h = static_cast<Handle*>(handle);
556 if (!h->IsValidType(AbstractItem::ChatMessage)) {
557 LOGE("Invalid handle type");
558 return NOTI_EX_ERROR_INVALID_PARAMETER;
560 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
561 if (p->GetNameItem().GetType() == AbstractItem::NullObject)
564 *name = new Handle(&(p->GetNameItem()));
566 return NOTI_EX_ERROR_NONE;
569 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
570 noti_ex_item_h handle, noti_ex_item_h *text) {
571 if (handle == nullptr || text == nullptr) {
572 LOGE("Invalid parameter");
573 return NOTI_EX_ERROR_INVALID_PARAMETER;
576 Handle* h = static_cast<Handle*>(handle);
577 if (!h->IsValidType(AbstractItem::ChatMessage)) {
578 LOGE("Invalid handle type");
579 return NOTI_EX_ERROR_INVALID_PARAMETER;
581 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
582 if (p->GetTextItem().GetType() == AbstractItem::NullObject)
585 *text = new Handle(&(p->GetTextItem()));
587 return NOTI_EX_ERROR_NONE;
590 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
591 noti_ex_item_h handle, noti_ex_item_h *image) {
592 if (handle == nullptr || image == nullptr) {
593 LOGE("Invalid parameter");
594 return NOTI_EX_ERROR_INVALID_PARAMETER;
597 Handle* h = static_cast<Handle*>(handle);
598 if (!h->IsValidType(AbstractItem::ChatMessage)) {
599 LOGE("Invalid handle type");
600 return NOTI_EX_ERROR_INVALID_PARAMETER;
602 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
603 if (p->GetImageItem().GetType() == AbstractItem::NullObject)
606 *image = new Handle(&(p->GetImageItem()));
608 return NOTI_EX_ERROR_NONE;
611 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
612 noti_ex_item_h handle, noti_ex_item_h *time) {
613 if (handle == nullptr || time == nullptr) {
614 LOGE("Invalid parameter");
615 return NOTI_EX_ERROR_INVALID_PARAMETER;
618 Handle* h = static_cast<Handle*>(handle);
619 if (!h->IsValidType(AbstractItem::ChatMessage)) {
620 LOGE("Invalid handle type");
621 return NOTI_EX_ERROR_INVALID_PARAMETER;
623 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
624 if (p->GetTimeItem().GetType() == AbstractItem::NullObject)
627 *time = new Handle(&(p->GetTimeItem()));
629 return NOTI_EX_ERROR_NONE;
632 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
633 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
634 if (handle == nullptr || message_type == nullptr) {
635 LOGE("Invalid parameter");
636 return NOTI_EX_ERROR_INVALID_PARAMETER;
639 Handle* h = static_cast<Handle*>(handle);
640 if (!h->IsValidType(AbstractItem::ChatMessage)) {
641 LOGE("Invalid handle type");
642 return NOTI_EX_ERROR_INVALID_PARAMETER;
644 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
645 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
647 return NOTI_EX_ERROR_NONE;
650 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
651 const char *id, const char *title, bool checked) {
654 if (handle == nullptr || title == nullptr) {
655 LOGE("Invalid parameter");
656 return NOTI_EX_ERROR_INVALID_PARAMETER;
662 p = new (std::nothrow) CheckBoxItem(id, title, checked);
664 LOGE("Out-of-memory");
665 return NOTI_EX_ERROR_OUT_OF_MEMORY;
668 *handle = new Handle(shared_ptr<AbstractItem>(p));
670 return NOTI_EX_ERROR_NONE;
673 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
675 if (handle == nullptr || title == nullptr) {
676 LOGE("Invalid parameter");
677 return NOTI_EX_ERROR_INVALID_PARAMETER;
679 Handle* h = static_cast<Handle*>(handle);
680 if (!h->IsValidType(AbstractItem::CheckBox)) {
681 LOGE("Invalid handle type");
682 return NOTI_EX_ERROR_INVALID_PARAMETER;
685 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
687 if (p->GetMultiLanguage() != nullptr &&
688 !p->GetMultiLanguage()->GetTranslatedString().empty())
689 str = p->GetMultiLanguage()->GetTranslatedString();
690 else if (!p->GetTitle().empty())
693 *title = strdup(str.c_str());
694 if (*title == nullptr) {
695 LOGE("Out-of-memory");
696 return NOTI_EX_ERROR_OUT_OF_MEMORY;
699 return NOTI_EX_ERROR_NONE;
702 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
703 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
704 if (handle == nullptr) {
705 LOGE("Invalid parameter");
706 return NOTI_EX_ERROR_INVALID_PARAMETER;
709 Handle* p = static_cast<Handle*>(handle);
710 if (!p->IsValidType(AbstractItem::CheckBox)) {
711 LOGE("Invalid handle type");
712 return NOTI_EX_ERROR_INVALID_PARAMETER;
715 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
716 if (multi == nullptr) {
717 ci->SetMultiLanguage(nullptr);
718 return NOTI_EX_ERROR_NONE;
721 shared_ptr<MultiLanguage> mul_ptr =
722 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
723 mul_ptr->UpdateString();
724 ci->SetMultiLanguage(mul_ptr);
726 return NOTI_EX_ERROR_NONE;
729 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
730 noti_ex_item_h handle, bool *checked) {
731 if (handle == nullptr || checked == nullptr) {
732 LOGE("Invalid parameter");
733 return NOTI_EX_ERROR_INVALID_PARAMETER;
735 Handle* h = static_cast<Handle*>(handle);
736 if (!h->IsValidType(AbstractItem::CheckBox)) {
737 LOGE("Invalid handle type");
738 return NOTI_EX_ERROR_INVALID_PARAMETER;
740 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
741 *checked = p->IsChecked();
743 return NOTI_EX_ERROR_NONE;
746 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
747 noti_ex_item_h handle, bool checked) {
748 if (handle == nullptr) {
749 LOGE("Invalid parameter");
750 return NOTI_EX_ERROR_INVALID_PARAMETER;
753 Handle* h = static_cast<Handle*>(handle);
754 if (!h->IsValidType(AbstractItem::CheckBox)) {
755 LOGE("Invalid handle type");
756 return NOTI_EX_ERROR_INVALID_PARAMETER;
759 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
760 p->SetChecked(checked);
762 return NOTI_EX_ERROR_NONE;
765 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
769 if (handle == nullptr) {
770 LOGE("Invalid parameter");
771 return NOTI_EX_ERROR_INVALID_PARAMETER;
775 p = new (std::nothrow) EntryItem(id);
777 p = new (std::nothrow) EntryItem();
780 LOGE("Out-of-memory");
781 return NOTI_EX_ERROR_OUT_OF_MEMORY;
784 *handle = new Handle(shared_ptr<AbstractItem>(p));
786 return NOTI_EX_ERROR_NONE;
789 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
791 if (handle == nullptr || text == nullptr) {
792 LOGE("Invalid parameter");
793 return NOTI_EX_ERROR_INVALID_PARAMETER;
796 Handle* h = static_cast<Handle*>(handle);
797 if (!h->IsValidType(AbstractItem::Entry)) {
798 LOGE("Invalid handle type");
799 return NOTI_EX_ERROR_INVALID_PARAMETER;
802 EntryItem* p = static_cast<EntryItem*>(h->Get());
804 if (p->GetMultiLanguage() != nullptr &&
805 !p->GetMultiLanguage()->GetTranslatedString().empty())
806 str = p->GetMultiLanguage()->GetTranslatedString();
807 else if (!p->GetText().empty())
810 *text = strdup(str.c_str());
811 if (*text == nullptr) {
812 LOGE("Out-of-memory");
813 return NOTI_EX_ERROR_OUT_OF_MEMORY;
816 return NOTI_EX_ERROR_NONE;
819 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
821 if (handle == nullptr || text == nullptr) {
822 LOGE("Invalid parameter");
823 return NOTI_EX_ERROR_INVALID_PARAMETER;
825 Handle* h = static_cast<Handle*>(handle);
826 if (!h->IsValidType(AbstractItem::Entry)) {
827 LOGE("Invalid handle type");
828 return NOTI_EX_ERROR_INVALID_PARAMETER;
830 EntryItem* p = static_cast<EntryItem*>(h->Get());
831 p->SetText(std::string(text));
833 return NOTI_EX_ERROR_NONE;
836 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
837 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
838 if (handle == nullptr) {
839 LOGE("Invalid parameter");
840 return NOTI_EX_ERROR_INVALID_PARAMETER;
843 Handle* p = static_cast<Handle*>(handle);
844 if (!p->IsValidType(AbstractItem::Entry)) {
845 LOGE("Invalid handle type");
846 return NOTI_EX_ERROR_INVALID_PARAMETER;
849 EntryItem* ei = static_cast<EntryItem*>(p->Get());
850 if (multi == nullptr) {
851 ei->SetMultiLanguage(nullptr);
852 return NOTI_EX_ERROR_NONE;
855 shared_ptr<MultiLanguage> mul_ptr =
856 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
857 ei->SetMultiLanguage(mul_ptr);
858 ei->GetMultiLanguage()->UpdateString();
860 return NOTI_EX_ERROR_NONE;
863 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
864 noti_ex_event_info_h* cloned_handle) {
865 if (handle == nullptr || cloned_handle == nullptr) {
866 LOGE("Invalid parameter");
867 return NOTI_EX_ERROR_INVALID_PARAMETER;
870 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
871 EventInfo* info = new EventInfo(cloned);
872 *cloned_handle = info;
873 return NOTI_EX_ERROR_NONE;
876 extern "C" EXPORT_API int noti_ex_event_info_destroy(
877 noti_ex_event_info_h handle) {
878 if (handle == nullptr) {
879 LOGE("Invalid parameter");
880 return NOTI_EX_ERROR_INVALID_PARAMETER;
882 EventInfo* info = static_cast<EventInfo*>(handle);
884 return NOTI_EX_ERROR_NONE;
887 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
888 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
889 if (handle == nullptr || event_type == nullptr) {
890 LOGE("Invalid parameter");
891 return NOTI_EX_ERROR_INVALID_PARAMETER;
893 EventInfo* info = static_cast<EventInfo*>(handle);
894 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
896 return NOTI_EX_ERROR_NONE;
899 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
900 noti_ex_event_info_h handle, char **owner) {
901 if (handle == nullptr || owner == nullptr) {
902 LOGE("Invalid parameter");
903 return NOTI_EX_ERROR_INVALID_PARAMETER;
905 EventInfo* info = static_cast<EventInfo*>(handle);
906 *owner = strdup(info->GetOwner().c_str());
907 return NOTI_EX_ERROR_NONE;
910 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
911 noti_ex_event_info_h handle, char **channel) {
912 if (handle == nullptr || channel == nullptr) {
913 LOGE("Invalid parameter");
914 return NOTI_EX_ERROR_INVALID_PARAMETER;
916 EventInfo* info = static_cast<EventInfo*>(handle);
917 *channel = strdup(info->GetChannel().c_str());
918 return NOTI_EX_ERROR_NONE;
921 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
922 noti_ex_event_info_h handle, char **item_id) {
923 if (handle == nullptr || item_id == nullptr) {
924 LOGE("Invalid parameter");
925 return NOTI_EX_ERROR_INVALID_PARAMETER;
927 EventInfo* info = static_cast<EventInfo*>(handle);
928 *item_id = strdup(info->GetItemId().c_str());
929 return NOTI_EX_ERROR_NONE;
932 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
933 noti_ex_event_info_h handle, int *req_id) {
934 if (handle == nullptr || req_id == nullptr) {
935 LOGE("Invalid parameter");
936 return NOTI_EX_ERROR_INVALID_PARAMETER;
938 EventInfo* info = static_cast<EventInfo*>(handle);
939 *req_id = info->GetRequestId();
940 return NOTI_EX_ERROR_NONE;
943 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
947 if (handle == nullptr) {
948 LOGE("Invalid parameter");
949 return NOTI_EX_ERROR_INVALID_PARAMETER;
953 p = new (std::nothrow) GroupItem(id);
955 p = new (std::nothrow) GroupItem();
958 LOGE("Out-of-memory");
959 return NOTI_EX_ERROR_OUT_OF_MEMORY;
962 *handle = new Handle(shared_ptr<AbstractItem>(p));
964 return NOTI_EX_ERROR_NONE;
967 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
969 if (handle == nullptr) {
970 LOGE("Invalid parameter");
971 return NOTI_EX_ERROR_INVALID_PARAMETER;
973 Handle* h = static_cast<Handle*>(handle);
974 if (!h->IsValidType(AbstractItem::Group)) {
975 LOGE("Invalid handle type");
976 return NOTI_EX_ERROR_INVALID_PARAMETER;
978 GroupItem* p = static_cast<GroupItem*>(h->Get());
979 p->SetDirection(vertical);
981 return NOTI_EX_ERROR_NONE;
984 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
986 if (handle == nullptr) {
987 LOGE("Invalid parameter");
988 return NOTI_EX_ERROR_INVALID_PARAMETER;
990 Handle* h = static_cast<Handle*>(handle);
991 if (!h->IsValidType(AbstractItem::Group)) {
992 LOGE("Invalid handle type");
993 return NOTI_EX_ERROR_INVALID_PARAMETER;
995 GroupItem* p = static_cast<GroupItem*>(h->Get());
996 *vertical = p->IsVertical();
998 return NOTI_EX_ERROR_NONE;
1001 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
1003 if (handle == nullptr) {
1004 LOGE("Invalid parameter");
1005 return NOTI_EX_ERROR_INVALID_PARAMETER;
1007 Handle* h = static_cast<Handle*>(handle);
1008 if (!h->IsValidType(AbstractItem::Group)) {
1009 LOGE("Invalid handle type");
1010 return NOTI_EX_ERROR_INVALID_PARAMETER;
1012 GroupItem* p = static_cast<GroupItem*>(h->Get());
1013 if (!p->GetAppLabel().empty()) {
1014 *label = strdup(p->GetAppLabel().c_str());
1015 if (*label == nullptr) {
1016 LOGE("Out-of-memory");
1017 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1021 return NOTI_EX_ERROR_NONE;
1024 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
1025 noti_ex_item_h child) {
1026 if (handle == nullptr || child == nullptr) {
1027 LOGE("Invalid parameter");
1028 return NOTI_EX_ERROR_INVALID_PARAMETER;
1030 Handle* h = static_cast<Handle*>(handle);
1031 if (!h->IsValidType(AbstractItem::Group)) {
1032 LOGE("Invalid handle type");
1033 return NOTI_EX_ERROR_INVALID_PARAMETER;
1035 auto p = static_cast<GroupItem*>(h->Get());
1036 p->AddChild((static_cast<Handle*>(child))->GetPtr());
1038 return NOTI_EX_ERROR_NONE;
1041 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
1042 const char *item_id) {
1043 if (handle == nullptr || item_id == nullptr) {
1044 LOGE("Invalid parameter");
1045 return NOTI_EX_ERROR_INVALID_PARAMETER;
1047 Handle* h = static_cast<Handle*>(handle);
1048 if (!h->IsValidType(AbstractItem::Group)) {
1049 LOGE("Invalid handle type");
1050 return NOTI_EX_ERROR_INVALID_PARAMETER;
1052 GroupItem* p = static_cast<GroupItem*>(h->Get());
1053 p->RemoveChild(std::string(item_id));
1055 return NOTI_EX_ERROR_NONE;
1058 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
1059 noti_ex_item_group_foreach_child_cb callback, void *data) {
1060 if (handle == nullptr || callback == nullptr) {
1061 LOGE("Invalid parameter");
1062 return NOTI_EX_ERROR_INVALID_PARAMETER;
1065 Handle* h = static_cast<Handle*>(handle);
1066 if (!h->IsValidType(AbstractItem::Group)) {
1067 LOGE("Invalid handle type");
1068 return NOTI_EX_ERROR_INVALID_PARAMETER;
1070 GroupItem* p = static_cast<GroupItem*>(h->Get());
1071 list<shared_ptr<AbstractItem>> children = p->GetChildren();
1072 LOGI("Retrive (%zd)", children.size());
1073 for (auto i : children) {
1075 static_cast<noti_ex_item_h>(new Handle(i)), data);
1076 if (ret != NOTI_EX_ERROR_NONE) {
1077 LOGW("callback return (%d) stop foreach", ret);
1082 return NOTI_EX_ERROR_NONE;
1085 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1086 const char *id, const char *image_path) {
1089 if (handle == nullptr || image_path == nullptr) {
1090 LOGE("Invalid parameter");
1091 return NOTI_EX_ERROR_INVALID_PARAMETER;
1095 p = new (std::nothrow) ImageItem(id, image_path);
1097 p = new (std::nothrow) ImageItem(image_path);
1100 LOGE("Out-of-memory");
1101 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1104 *handle = new Handle(shared_ptr<AbstractItem>(p));
1106 return NOTI_EX_ERROR_NONE;
1109 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1110 noti_ex_item_h handle, char **image_path) {
1111 if (handle == nullptr || image_path == nullptr) {
1112 LOGE("Invalid parameter");
1113 return NOTI_EX_ERROR_INVALID_PARAMETER;
1115 Handle* h = static_cast<Handle*>(handle);
1116 if (!h->IsValidType(AbstractItem::Image)) {
1117 LOGE("Invalid handle type");
1118 return NOTI_EX_ERROR_INVALID_PARAMETER;
1120 ImageItem* p = static_cast<ImageItem*>(h->Get());
1121 if (!p->GetImagePath().empty()) {
1122 *image_path = strdup(p->GetImagePath().c_str());
1123 if (*image_path == nullptr) {
1124 LOGE("Out-of-memory");
1125 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1128 *image_path = nullptr;
1131 return NOTI_EX_ERROR_NONE;
1134 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1135 noti_ex_item_h *handle, const char *id) {
1136 InputSelectorItem* p;
1138 if (handle == nullptr) {
1139 LOGE("Invalid parameter");
1140 return NOTI_EX_ERROR_INVALID_PARAMETER;
1144 p = new (std::nothrow) InputSelectorItem(id);
1146 p = new (std::nothrow) InputSelectorItem();
1149 LOGE("Out-of-memory");
1150 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1153 *handle = new Handle(shared_ptr<AbstractItem>(p));
1155 return NOTI_EX_ERROR_NONE;
1158 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1159 noti_ex_item_h handle, char ***contents_list, int *count) {
1160 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1161 LOGE("Invalid parameter");
1162 return NOTI_EX_ERROR_INVALID_PARAMETER;
1165 Handle* h = static_cast<Handle*>(handle);
1166 if (!h->IsValidType(AbstractItem::InputSelector)) {
1167 LOGE("Invalid handle type");
1168 return NOTI_EX_ERROR_INVALID_PARAMETER;
1171 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1172 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1173 list<string> contents;
1174 if (arr.size() == 0) {
1175 contents = p->GetContents();
1177 for (auto& i : arr) {
1178 contents.push_back(i->GetTranslatedString());
1182 char **list = (char**)calloc(contents.size(), sizeof(char*));
1183 if (list == nullptr) {
1184 LOGE("Out of memory");
1185 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1189 for (auto& i : contents) {
1190 list[idx] = strdup(i.c_str());
1191 if (list[idx] == nullptr) {
1192 __noti_ex_free_str_array(list, idx);
1193 LOGE("Out of memory");
1194 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1199 *count = contents.size();
1200 *contents_list = list;
1202 return NOTI_EX_ERROR_NONE;
1205 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1206 noti_ex_item_h handle, const char **contents, int count) {
1207 if (handle == nullptr || contents == nullptr) {
1208 LOGE("Invalid parameter");
1209 return NOTI_EX_ERROR_INVALID_PARAMETER;
1212 list<string> new_contents;
1213 Handle* h = static_cast<Handle*>(handle);
1214 if (!h->IsValidType(AbstractItem::InputSelector)) {
1215 LOGE("Invalid handle type");
1216 return NOTI_EX_ERROR_INVALID_PARAMETER;
1218 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1219 for (int i = 0; i < count; i++) {
1220 new_contents.push_back(contents[i]);
1222 p->SetContents(move(new_contents));
1224 return NOTI_EX_ERROR_NONE;
1227 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1228 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1229 if (handle == nullptr) {
1230 LOGE("Invalid parameter");
1231 return NOTI_EX_ERROR_INVALID_PARAMETER;
1234 Handle* p = static_cast<Handle*>(handle);
1235 if (!p->IsValidType(AbstractItem::InputSelector)) {
1236 LOGE("Invalid handle type");
1237 return NOTI_EX_ERROR_INVALID_PARAMETER;
1240 vector<shared_ptr<MultiLanguage>> m_list;
1241 for (int i = 0; i < count; i++) {
1242 shared_ptr<MultiLanguage> mul_ptr =
1243 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1244 mul_ptr->UpdateString();
1245 m_list.push_back(mul_ptr);
1248 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1249 input->SetMultiLanguage(m_list);
1251 return NOTI_EX_ERROR_NONE;
1254 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1255 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1256 if (handle == nullptr) {
1257 LOGE("Invalid parameter");
1258 return NOTI_EX_ERROR_INVALID_PARAMETER;
1261 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1262 new (std::nothrow) Color(a, r, g, b));
1263 if (ptr == nullptr || ptr->get() == nullptr) {
1264 LOGE("Out-of-memory");
1265 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1270 return NOTI_EX_ERROR_NONE;
1273 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1274 if (handle == nullptr) {
1275 LOGE("Invalid parameter");
1276 return NOTI_EX_ERROR_INVALID_PARAMETER;
1279 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1282 return NOTI_EX_ERROR_NONE;
1285 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1286 unsigned char *val) {
1287 if (handle == nullptr || val == nullptr) {
1288 LOGE("Invalid parameter");
1289 return NOTI_EX_ERROR_INVALID_PARAMETER;
1292 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1293 *val = (*p)->GetAVal();
1295 return NOTI_EX_ERROR_NONE;
1298 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1299 unsigned char *val) {
1300 if (handle == nullptr || val == nullptr) {
1301 LOGE("Invalid parameter");
1302 return NOTI_EX_ERROR_INVALID_PARAMETER;
1305 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1306 *val = (*p)->GetRVal();
1308 return NOTI_EX_ERROR_NONE;
1311 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1312 unsigned char *val) {
1313 if (handle == nullptr || val == nullptr) {
1314 LOGE("Invalid parameter");
1315 return NOTI_EX_ERROR_INVALID_PARAMETER;
1318 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1319 *val = (*p)->GetGVal();
1321 return NOTI_EX_ERROR_NONE;
1324 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1325 unsigned char *val) {
1326 if (handle == nullptr || val == nullptr) {
1327 LOGE("Invalid parameter");
1328 return NOTI_EX_ERROR_INVALID_PARAMETER;
1331 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1332 *val = (*p)->GetBVal();
1334 return NOTI_EX_ERROR_NONE;
1337 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1338 int left, int top, int right, int bottom) {
1339 if (handle == nullptr) {
1340 LOGE("Invalid parameter");
1341 return NOTI_EX_ERROR_INVALID_PARAMETER;
1344 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1345 new (std::nothrow) Padding(left, top, right, bottom));
1346 if (ptr == nullptr || ptr->get() == nullptr) {
1347 LOGE("Out-of-memory");
1348 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1353 return NOTI_EX_ERROR_NONE;
1356 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1357 if (handle == nullptr) {
1358 LOGE("Invalid parameter");
1359 return NOTI_EX_ERROR_INVALID_PARAMETER;
1362 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1365 return NOTI_EX_ERROR_NONE;
1368 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1370 if (handle == nullptr || val == nullptr) {
1371 LOGE("Invalid parameter");
1372 return NOTI_EX_ERROR_INVALID_PARAMETER;
1375 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1376 *val = (*p)->GetLeft();
1378 return NOTI_EX_ERROR_NONE;
1381 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1383 if (handle == nullptr || val == nullptr) {
1384 LOGE("Invalid parameter");
1385 return NOTI_EX_ERROR_INVALID_PARAMETER;
1388 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1389 *val = (*p)->GetTop();
1391 return NOTI_EX_ERROR_NONE;
1394 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1396 if (handle == nullptr || val == nullptr) {
1397 LOGE("Invalid parameter");
1398 return NOTI_EX_ERROR_INVALID_PARAMETER;
1401 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1402 *val = (*p)->GetRight();
1404 return NOTI_EX_ERROR_NONE;
1407 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1409 if (handle == nullptr || val == nullptr) {
1410 LOGE("Invalid parameter");
1411 return NOTI_EX_ERROR_INVALID_PARAMETER;
1414 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1415 *val = (*p)->GetBottom();
1417 return NOTI_EX_ERROR_NONE;
1420 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1421 int x, int y, int w, int h) {
1422 if (handle == nullptr) {
1423 LOGE("Invalid parameter");
1424 return NOTI_EX_ERROR_INVALID_PARAMETER;
1427 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1428 new (std::nothrow) Geometry(x, y, w, h));
1429 if (ptr == nullptr || ptr->get() == nullptr) {
1430 LOGE("Out-of-memory");
1431 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1440 if (handle == nullptr) {
1441 LOGE("Invalid parameter");
1442 return NOTI_EX_ERROR_INVALID_PARAMETER;
1445 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1448 return NOTI_EX_ERROR_NONE;
1451 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1453 if (handle == nullptr || val == nullptr) {
1454 LOGE("Invalid parameter");
1455 return NOTI_EX_ERROR_INVALID_PARAMETER;
1458 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1459 *val = (*p)->GetX();
1461 return NOTI_EX_ERROR_NONE;
1464 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1466 if (handle == nullptr || val == nullptr) {
1467 LOGE("Invalid parameter");
1468 return NOTI_EX_ERROR_INVALID_PARAMETER;
1471 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1472 *val = (*p)->GetY();
1474 return NOTI_EX_ERROR_NONE;
1477 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1479 if (handle == nullptr || val == nullptr) {
1480 LOGE("Invalid parameter");
1481 return NOTI_EX_ERROR_INVALID_PARAMETER;
1484 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1485 *val = (*p)->GetWidth();
1487 return NOTI_EX_ERROR_NONE;
1490 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1492 if (handle == nullptr || val == nullptr) {
1493 LOGE("Invalid parameter");
1494 return NOTI_EX_ERROR_INVALID_PARAMETER;
1497 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1498 *val = (*p)->GetHeight();
1500 return NOTI_EX_ERROR_NONE;
1503 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1504 noti_ex_color_h color,
1505 noti_ex_padding_h padding,
1506 noti_ex_geometry_h geometry) {
1507 if (handle == nullptr) {
1508 LOGE("Invalid parameter");
1509 return NOTI_EX_ERROR_INVALID_PARAMETER;
1512 shared_ptr<Color> col = (color == nullptr) ?
1513 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1514 shared_ptr<Padding> padd = (padding == nullptr) ?
1515 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1516 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1517 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1519 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1520 new (std::nothrow) Style(col, padd, geo));
1521 if (ptr == nullptr || ptr->get() == nullptr) {
1522 LOGE("Out-of-memory");
1523 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1528 return NOTI_EX_ERROR_NONE;
1531 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1532 if (handle == nullptr) {
1533 LOGE("Invalid parameter");
1534 return NOTI_EX_ERROR_INVALID_PARAMETER;
1537 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1540 return NOTI_EX_ERROR_NONE;
1543 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1544 noti_ex_padding_h *padding) {
1545 if (handle == nullptr || padding == nullptr) {
1546 LOGE("Invalid parameter");
1547 return NOTI_EX_ERROR_INVALID_PARAMETER;
1550 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1551 if ((*p)->GetPadding() == nullptr) {
1552 LOGW("Padding info is null");
1553 return NOTI_EX_ERROR_INVALID_PARAMETER;
1556 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1557 new (std::nothrow) Padding(*((*p)->GetPadding())));
1558 if (padd == nullptr || padd->get() == nullptr) {
1559 LOGE("Out-of-memory");
1561 return NOTI_EX_ERROR_NONE;
1566 return NOTI_EX_ERROR_NONE;
1570 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1571 noti_ex_padding_h padding) {
1572 if (handle == nullptr) {
1573 LOGE("Invalid parameter");
1574 return NOTI_EX_ERROR_INVALID_PARAMETER;
1577 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1578 if (padding == nullptr) {
1579 (*p)->SetPadding(nullptr);
1580 return NOTI_EX_ERROR_NONE;
1583 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1584 (*p)->SetPadding(*padd);
1586 return NOTI_EX_ERROR_NONE;
1589 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1590 noti_ex_color_h *color) {
1591 if (handle == nullptr || color == nullptr) {
1592 LOGE("Invalid parameter");
1593 return NOTI_EX_ERROR_INVALID_PARAMETER;
1596 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1597 if ((*p)->GetColor() == nullptr) {
1598 LOGW("Color info is null");
1600 return NOTI_EX_ERROR_NONE;
1603 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1604 new (std::nothrow) Color(*((*p)->GetColor())));
1605 if (col == nullptr || col->get() == nullptr) {
1606 LOGE("Out-of-memory");
1607 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1612 return NOTI_EX_ERROR_NONE;
1615 extern "C" EXPORT_API int noti_ex_style_set_color(
1616 noti_ex_style_h handle, noti_ex_color_h color) {
1617 if (handle == nullptr) {
1618 LOGE("Invalid parameter");
1619 return NOTI_EX_ERROR_INVALID_PARAMETER;
1622 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1623 if (color == nullptr) {
1624 (*p)->SetColor(nullptr);
1625 return NOTI_EX_ERROR_NONE;
1628 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1629 (*p)->SetColor(*col);
1631 return NOTI_EX_ERROR_NONE;
1634 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1635 noti_ex_geometry_h *geometry) {
1636 if (handle == nullptr || geometry == nullptr) {
1637 LOGE("Invalid parameter");
1638 return NOTI_EX_ERROR_INVALID_PARAMETER;
1641 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1642 if ((*p)->GetGeometry() == nullptr) {
1643 LOGW("Geometry info is null");
1644 *geometry = nullptr;
1645 return NOTI_EX_ERROR_NONE;
1648 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1649 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1650 if (geo == nullptr || geo->get() == nullptr) {
1651 LOGE("Out-of-memory");
1652 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1657 return NOTI_EX_ERROR_NONE;
1660 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1661 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1662 if (handle == nullptr) {
1663 LOGE("Invalid parameter");
1664 return NOTI_EX_ERROR_INVALID_PARAMETER;
1667 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1668 if (geometry == nullptr) {
1669 (*p)->SetGeometry(nullptr);
1670 return NOTI_EX_ERROR_NONE;
1673 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1674 (*p)->SetGeometry(*geo);
1676 return NOTI_EX_ERROR_NONE;
1679 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1680 noti_ex_style_h handle, char** background_image) {
1681 if (handle == nullptr || background_image == nullptr) {
1682 LOGE("Invalid parameter");
1683 return NOTI_EX_ERROR_INVALID_PARAMETER;
1686 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1688 if ((*p)->GetBackgroundImage().empty())
1689 *background_image = nullptr;
1691 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1693 return NOTI_EX_ERROR_NONE;
1696 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1697 noti_ex_style_h handle, char* background_image) {
1698 if (handle == nullptr) {
1699 LOGE("Invalid parameter");
1700 return NOTI_EX_ERROR_INVALID_PARAMETER;
1703 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1704 if (background_image == nullptr)
1705 (*p)->SetBackgroundImage("");
1707 (*p)->SetBackgroundImage(background_image);
1709 return NOTI_EX_ERROR_NONE;
1712 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1713 noti_ex_style_h handle, noti_ex_color_h* color) {
1714 if (handle == nullptr || color == nullptr) {
1715 LOGE("Invalid parameter");
1716 return NOTI_EX_ERROR_INVALID_PARAMETER;
1719 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1720 if ((*p)->GetBackgroundColor() == nullptr) {
1721 LOGW("Color info is null");
1723 return NOTI_EX_ERROR_NONE;
1726 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1727 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1728 if (col == nullptr || col->get() == nullptr) {
1729 LOGE("Out-of-memory");
1730 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1735 return NOTI_EX_ERROR_NONE;
1738 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1739 noti_ex_style_h handle, noti_ex_color_h color) {
1740 if (handle == nullptr) {
1741 LOGE("Invalid parameter");
1742 return NOTI_EX_ERROR_INVALID_PARAMETER;
1745 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1746 if (color == nullptr) {
1747 (*p)->SetBackgroundColor(nullptr);
1748 return NOTI_EX_ERROR_NONE;
1751 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1752 (*p)->SetBackgroundColor(*col);
1754 return NOTI_EX_ERROR_NONE;
1757 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1758 noti_ex_color_h color) {
1759 if (handle == nullptr || color == nullptr) {
1760 LOGE("Invalid parameter");
1761 return NOTI_EX_ERROR_INVALID_PARAMETER;
1764 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1765 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1766 new (std::nothrow) LEDInfo(*color_ptr));
1768 LOGE("Out-of-memory");
1769 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1774 return NOTI_EX_ERROR_NONE;
1777 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1778 if (handle == nullptr) {
1779 LOGE("Invalid parameter");
1780 return NOTI_EX_ERROR_INVALID_PARAMETER;
1783 shared_ptr<LEDInfo>* led_ptr =
1784 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1786 return NOTI_EX_ERROR_NONE;
1789 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1790 noti_ex_led_info_h handle, int ms) {
1791 if (handle == nullptr) {
1792 LOGE("Invalid parameter");
1793 return NOTI_EX_ERROR_INVALID_PARAMETER;
1796 shared_ptr<LEDInfo>* led_ptr =
1797 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1798 (*led_ptr)->SetOnPeriod(ms);
1800 return NOTI_EX_ERROR_NONE;
1803 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1804 noti_ex_led_info_h handle, int *ms) {
1805 if (handle == nullptr || ms == nullptr) {
1806 LOGE("Invalid parameter");
1807 return NOTI_EX_ERROR_INVALID_PARAMETER;
1810 shared_ptr<LEDInfo>* led_ptr =
1811 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1812 *ms = (*led_ptr)->GetOnPeriod();
1814 return NOTI_EX_ERROR_NONE;
1817 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1818 noti_ex_led_info_h handle, int ms) {
1819 if (handle == nullptr) {
1820 LOGE("Invalid parameter");
1821 return NOTI_EX_ERROR_INVALID_PARAMETER;
1824 shared_ptr<LEDInfo>* led_ptr =
1825 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1826 (*led_ptr)->SetOffPeriod(ms);
1828 return NOTI_EX_ERROR_NONE;
1831 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1832 noti_ex_led_info_h handle, int *ms) {
1833 if (handle == nullptr) {
1834 LOGE("Invalid parameter");
1835 return NOTI_EX_ERROR_INVALID_PARAMETER;
1838 shared_ptr<LEDInfo>* led_ptr =
1839 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1840 *ms = (*led_ptr)->GetOffPeriod();
1842 return NOTI_EX_ERROR_NONE;
1845 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1846 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1847 if (handle == nullptr) {
1848 LOGE("Invalid parameter");
1849 return NOTI_EX_ERROR_INVALID_PARAMETER;
1852 shared_ptr<LEDInfo>* led_ptr =
1853 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1854 if ((*led_ptr)->GetColor() == nullptr) {
1855 LOGW("Color is null");
1857 return NOTI_EX_ERROR_NONE;
1860 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1861 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1862 if (col == nullptr || col->get() == nullptr) {
1863 LOGE("Out-of-memory");
1864 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1869 return NOTI_EX_ERROR_NONE;
1872 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1873 noti_ex_led_info_h handle, noti_ex_color_h color) {
1874 if (handle == nullptr) {
1875 LOGE("Invalid parameter");
1876 return NOTI_EX_ERROR_INVALID_PARAMETER;
1879 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1880 if (color == nullptr) {
1881 (*p)->SetColor(nullptr);
1882 return NOTI_EX_ERROR_NONE;
1885 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1886 (*p)->SetColor(*col);
1888 return NOTI_EX_ERROR_NONE;
1891 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1892 if (handle == nullptr) {
1893 LOGE("Invalid parameter");
1894 return NOTI_EX_ERROR_INVALID_PARAMETER;
1897 shared_ptr<AbstractAction>* ptr =
1898 static_cast<shared_ptr<AbstractAction>*>(handle);
1901 return NOTI_EX_ERROR_NONE;
1904 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1906 if (handle == nullptr || type == nullptr) {
1907 LOGE("Invalid parameter");
1908 return NOTI_EX_ERROR_INVALID_PARAMETER;
1911 shared_ptr<AbstractAction>* ptr =
1912 static_cast<shared_ptr<AbstractAction>*>(handle);
1913 *type = (*ptr)->GetType();
1915 return NOTI_EX_ERROR_NONE;
1918 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1920 if (handle == nullptr || local == nullptr) {
1921 LOGE("Invalid parameter");
1922 return NOTI_EX_ERROR_INVALID_PARAMETER;
1925 shared_ptr<AbstractAction>* ptr =
1926 static_cast<shared_ptr<AbstractAction>*>(handle);
1927 *local = (*ptr)->IsLocal();
1929 return NOTI_EX_ERROR_NONE;
1932 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1933 noti_ex_item_h item) {
1934 if (handle == nullptr || item == nullptr) {
1935 LOGE("Invalid parameter");
1936 return NOTI_EX_ERROR_INVALID_PARAMETER;
1938 shared_ptr<AbstractAction>* ptr =
1939 static_cast<shared_ptr<AbstractAction>*>(handle);
1940 Handle* ih = static_cast<Handle*>(item);
1941 (*ptr)->Execute(ih->GetPtr());
1943 return NOTI_EX_ERROR_NONE;
1946 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1948 if (handle == nullptr || extra == nullptr) {
1949 LOGE("Invalid parameter");
1950 return NOTI_EX_ERROR_INVALID_PARAMETER;
1953 shared_ptr<AbstractAction>* ptr =
1954 static_cast<shared_ptr<AbstractAction>*>(handle);
1955 if (!(*ptr)->GetExtra().empty()) {
1956 *extra = strdup((*ptr)->GetExtra().c_str());
1957 if (*extra == nullptr) {
1958 LOGE("Out-of-memory");
1959 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1965 return NOTI_EX_ERROR_NONE;
1968 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1969 noti_ex_item_info_h handle, int *hide_time) {
1970 if (handle == nullptr || hide_time == nullptr) {
1971 LOGE("Invalid parameter");
1972 return NOTI_EX_ERROR_INVALID_PARAMETER;
1974 IItemInfo* p = static_cast<IItemInfo*>(handle);
1975 *hide_time = p->GetHideTime();
1976 return NOTI_EX_ERROR_NONE;
1979 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1980 noti_ex_item_info_h handle, int hide_time) {
1981 if (handle == nullptr) {
1982 LOGE("Invalid parameter");
1983 return NOTI_EX_ERROR_INVALID_PARAMETER;
1985 IItemInfo* p = static_cast<IItemInfo*>(handle);
1986 p->SetHideTime(hide_time);
1987 return NOTI_EX_ERROR_NONE;
1990 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1991 noti_ex_item_info_h handle, int *delete_time) {
1992 if (handle == nullptr || delete_time == nullptr) {
1993 LOGE("Invalid parameter");
1994 return NOTI_EX_ERROR_INVALID_PARAMETER;
1996 IItemInfo* p = static_cast<IItemInfo*>(handle);
1997 *delete_time = p->GetDeleteTime();
1998 return NOTI_EX_ERROR_NONE;
2001 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
2002 noti_ex_item_info_h handle, int delete_time) {
2003 if (handle == nullptr) {
2004 LOGE("Invalid parameter");
2005 return NOTI_EX_ERROR_INVALID_PARAMETER;
2007 IItemInfo* p = static_cast<IItemInfo*>(handle);
2008 p->SetDeleteTime(delete_time);
2009 return NOTI_EX_ERROR_NONE;
2012 extern "C" EXPORT_API int noti_ex_item_info_get_time(
2013 noti_ex_item_info_h handle, time_t *time) {
2014 if (handle == nullptr || time == nullptr) {
2015 LOGE("Invalid parameter");
2016 return NOTI_EX_ERROR_INVALID_PARAMETER;
2019 IItemInfo* p = static_cast<IItemInfo*>(handle);
2020 *time = p->GetTime();
2021 return NOTI_EX_ERROR_NONE;
2024 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
2025 if (handle == nullptr) {
2026 LOGE("Invalid parameter");
2027 return NOTI_EX_ERROR_INVALID_PARAMETER;
2030 Handle* h = static_cast<Handle*>(handle);
2032 return NOTI_EX_ERROR_NONE;
2035 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
2036 const char *id, noti_ex_item_h *item) {
2037 if (handle == nullptr) {
2038 LOGE("Invalid parameter");
2039 return NOTI_EX_ERROR_INVALID_PARAMETER;
2042 Handle* p = static_cast<Handle*>(handle);
2043 AbstractItem& find_item = p->Get()->FindByID(string(id));
2044 if (find_item.GetType() == AbstractItem::NullObject) {
2045 LOGW("Not exist ID");
2047 return NOTI_EX_ERROR_NONE;
2050 *item = new Handle(&find_item);
2051 return NOTI_EX_ERROR_NONE;
2054 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2056 if (handle == nullptr || type == nullptr) {
2057 LOGE("Invalid parameter");
2058 return NOTI_EX_ERROR_INVALID_PARAMETER;
2061 Handle* h = static_cast<Handle*>(handle);
2062 AbstractItem* p = h->Get();
2063 *type = p->GetType();
2064 return NOTI_EX_ERROR_NONE;
2067 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2069 if (handle == nullptr || id == nullptr) {
2070 LOGE("Invalid parameter");
2071 return NOTI_EX_ERROR_INVALID_PARAMETER;
2073 Handle* h = static_cast<Handle*>(handle);
2074 AbstractItem* p = h->Get();
2075 *id = strdup(p->GetId().c_str());
2076 return NOTI_EX_ERROR_NONE;
2079 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2081 if (handle == nullptr || id == nullptr) {
2082 LOGE("Invalid parameter");
2083 return NOTI_EX_ERROR_INVALID_PARAMETER;
2085 Handle* p = static_cast<Handle*>(handle);
2086 p->Get()->SetId(id);
2087 return NOTI_EX_ERROR_NONE;
2090 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2091 noti_ex_action_h *action) {
2092 if (handle == nullptr || action == nullptr) {
2093 LOGE("Invalid parameter");
2094 return NOTI_EX_ERROR_INVALID_PARAMETER;
2096 Handle* p = static_cast<Handle*>(handle);
2097 if (p->Get()->GetAction() == nullptr) {
2099 return NOTI_EX_ERROR_NONE;
2101 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2102 p->Get()->GetAction()));
2104 return NOTI_EX_ERROR_NONE;
2107 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2108 noti_ex_action_h action) {
2109 if (handle == nullptr) {
2110 LOGE("Invalid parameter");
2111 return NOTI_EX_ERROR_INVALID_PARAMETER;
2114 Handle* p = static_cast<Handle*>(handle);
2115 if (action == nullptr) {
2116 p->Get()->SetAction(nullptr);
2117 return NOTI_EX_ERROR_NONE;
2120 shared_ptr<AbstractAction>* ptr =
2121 static_cast<shared_ptr<AbstractAction>*>(action);
2122 p->Get()->SetAction(*ptr);
2123 return NOTI_EX_ERROR_NONE;
2126 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2127 noti_ex_style_h *style) {
2128 if (handle == nullptr || style == nullptr) {
2129 LOGE("Invalid parameter");
2130 return NOTI_EX_ERROR_INVALID_PARAMETER;
2133 Handle* p = static_cast<Handle*>(handle);
2134 shared_ptr<Style> s = p->Get()->GetStyle();
2135 if (s.get() == nullptr) {
2136 LOGW("Style is null");
2138 return NOTI_EX_ERROR_NONE;
2141 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2142 if (ptr == nullptr || ptr->get() == nullptr) {
2143 LOGE("Out of memory");
2144 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2148 return NOTI_EX_ERROR_NONE;
2151 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2152 noti_ex_style_h style) {
2153 if (handle == nullptr) {
2154 LOGE("Invalid parameter");
2155 return NOTI_EX_ERROR_INVALID_PARAMETER;
2158 Handle* p = static_cast<Handle*>(handle);
2159 if (style == nullptr) {
2160 p->Get()->SetStyle(nullptr);
2161 return NOTI_EX_ERROR_NONE;
2164 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2165 p->Get()->SetStyle(*s);
2166 return NOTI_EX_ERROR_NONE;
2169 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2171 if (handle == nullptr) {
2172 LOGE("Invalid parameter");
2173 return NOTI_EX_ERROR_INVALID_PARAMETER;
2176 Handle* p = static_cast<Handle*>(handle);
2177 p->Get()->SetVisible(visible);
2178 return NOTI_EX_ERROR_NONE;
2181 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2183 if (handle == nullptr || visible == nullptr) {
2184 LOGE("Invalid parameter");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2188 Handle* p = static_cast<Handle*>(handle);
2189 *visible = p->Get()->GetVisible();
2190 return NOTI_EX_ERROR_NONE;
2193 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2195 if (handle == nullptr) {
2196 LOGE("Invalid parameter");
2197 return NOTI_EX_ERROR_INVALID_PARAMETER;
2200 Handle* p = static_cast<Handle*>(handle);
2201 p->Get()->SetEnable(enable);
2202 return NOTI_EX_ERROR_NONE;
2205 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2207 if (handle == nullptr || enable == nullptr) {
2208 LOGE("Invalid parameter");
2209 return NOTI_EX_ERROR_INVALID_PARAMETER;
2212 Handle* p = static_cast<Handle*>(handle);
2213 *enable = p->Get()->GetEnable();
2214 return NOTI_EX_ERROR_NONE;
2217 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2218 const char *receiver_group) {
2219 if (handle == nullptr || receiver_group == nullptr) {
2220 LOGE("Invalid parameter");
2221 return NOTI_EX_ERROR_INVALID_PARAMETER;
2224 Handle* p = static_cast<Handle*>(handle);
2225 p->Get()->AddReceiver(receiver_group);
2226 return NOTI_EX_ERROR_NONE;
2229 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2230 const char *receiver_group) {
2231 if (handle == nullptr || receiver_group == nullptr) {
2232 LOGE("Invalid parameter");
2233 return NOTI_EX_ERROR_INVALID_PARAMETER;
2236 Handle* p = static_cast<Handle*>(handle);
2237 p->Get()->RemoveReceiver(receiver_group);
2238 return NOTI_EX_ERROR_NONE;
2241 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2242 char ***receiver_list, int *count) {
2243 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2244 LOGE("Invalid parameter");
2245 return NOTI_EX_ERROR_INVALID_PARAMETER;
2248 Handle* p = static_cast<Handle*>(handle);
2249 list<string> receivers = p->Get()->GetReceiverList();
2250 if (receivers.size() == 0) {
2251 *receiver_list = nullptr;
2253 return NOTI_EX_ERROR_NONE;
2256 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2257 if (tmp_list == nullptr) {
2258 LOGE("Out of memory");
2259 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2263 for (auto& i : receivers) {
2264 tmp_list[idx] = strdup(i.c_str());
2265 if (tmp_list[idx] == nullptr) {
2266 __noti_ex_free_str_array(tmp_list, idx);
2267 LOGE("Out of memory");
2268 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2273 *receiver_list = tmp_list;
2274 *count = receivers.size();
2275 return NOTI_EX_ERROR_NONE;
2278 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2280 if (handle == nullptr) {
2281 LOGE("Invalid parameter");
2282 return NOTI_EX_ERROR_INVALID_PARAMETER;
2285 Handle* p = static_cast<Handle*>(handle);
2286 p->Get()->SetPolicy(policy);
2287 return NOTI_EX_ERROR_NONE;
2290 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2292 if (handle == nullptr || policy == nullptr) {
2293 LOGE("Invalid parameter");
2294 return NOTI_EX_ERROR_INVALID_PARAMETER;
2297 Handle* p = static_cast<Handle*>(handle);
2298 *policy = p->Get()->GetPolicy();
2299 return NOTI_EX_ERROR_NONE;
2302 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2304 if (handle == nullptr || channel == nullptr) {
2305 LOGE("Invalid parameter");
2306 return NOTI_EX_ERROR_INVALID_PARAMETER;
2309 Handle* p = static_cast<Handle*>(handle);
2310 if (!p->Get()->GetChannel().empty())
2311 *channel = strdup(p->Get()->GetChannel().c_str());
2315 return NOTI_EX_ERROR_NONE;
2318 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2319 const char *channel) {
2320 if (handle == nullptr) {
2321 LOGE("Invalid parameter");
2322 return NOTI_EX_ERROR_INVALID_PARAMETER;
2325 Handle* p = static_cast<Handle*>(handle);
2326 p->Get()->SetChannel(channel);
2327 return NOTI_EX_ERROR_NONE;
2330 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2331 noti_ex_led_info_h led) {
2332 if (handle == nullptr) {
2333 LOGE("Invalid parameter");
2334 return NOTI_EX_ERROR_INVALID_PARAMETER;
2337 Handle* p = static_cast<Handle*>(handle);
2338 if (led == nullptr) {
2339 p->Get()->SetLEDInfo(nullptr);
2340 return NOTI_EX_ERROR_NONE;
2342 shared_ptr<LEDInfo>* led_ptr =
2343 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2344 p->Get()->SetLEDInfo(*led_ptr);
2345 return NOTI_EX_ERROR_NONE;
2348 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2349 noti_ex_led_info_h *led) {
2350 if (handle == nullptr) {
2351 LOGE("Invalid parameter");
2352 return NOTI_EX_ERROR_INVALID_PARAMETER;
2355 Handle* p = static_cast<Handle*>(handle);
2356 if (p->Get()->GetLEDInfo() != nullptr)
2357 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2360 return NOTI_EX_ERROR_NONE;
2363 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2365 if (handle == nullptr) {
2366 LOGE("Invalid parameter");
2367 return NOTI_EX_ERROR_INVALID_PARAMETER;
2370 Handle* p = static_cast<Handle*>(handle);
2371 if (path == nullptr)
2372 p->Get()->SetSoundPath("");
2374 p->Get()->SetSoundPath(path);
2375 return NOTI_EX_ERROR_NONE;
2378 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2380 if (handle == nullptr) {
2381 LOGE("Invalid parameter");
2382 return NOTI_EX_ERROR_INVALID_PARAMETER;
2385 Handle* p = static_cast<Handle*>(handle);
2386 if (path == nullptr)
2387 p->Get()->SetVibrationPath("");
2389 p->Get()->SetVibrationPath(path);
2390 return NOTI_EX_ERROR_NONE;
2393 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2395 if (handle == nullptr || path == nullptr) {
2396 LOGE("Invalid parameter");
2397 return NOTI_EX_ERROR_INVALID_PARAMETER;
2400 Handle* p = static_cast<Handle*>(handle);
2401 if (p->Get()->GetSoundPath().empty())
2404 *path = strdup(p->Get()->GetSoundPath().c_str());
2405 return NOTI_EX_ERROR_NONE;
2408 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2410 if (handle == nullptr || path == nullptr) {
2411 LOGE("Invalid parameter");
2412 return NOTI_EX_ERROR_INVALID_PARAMETER;
2415 Handle* p = static_cast<Handle*>(handle);
2416 if (p->Get()->GetVibrationPath().empty())
2419 *path = strdup(p->Get()->GetVibrationPath().c_str());
2420 return NOTI_EX_ERROR_NONE;
2423 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2424 noti_ex_item_info_h *info) {
2425 if (handle == nullptr || info == nullptr) {
2426 LOGE("Invalid parameter");
2427 return NOTI_EX_ERROR_INVALID_PARAMETER;
2430 Handle* p = static_cast<Handle*>(handle);
2431 if (p->Get()->GetInfo() == nullptr)
2434 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2435 return NOTI_EX_ERROR_NONE;
2438 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2440 if (handle == nullptr || id == nullptr) {
2441 LOGE("Invalid parameter");
2442 return NOTI_EX_ERROR_INVALID_PARAMETER;
2445 Handle* p = static_cast<Handle*>(handle);
2446 if (p->Get()->GetSenderAppId().empty())
2449 *id = strdup(p->Get()->GetSenderAppId().c_str());
2450 return NOTI_EX_ERROR_NONE;
2453 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2455 if (handle == nullptr || tag == nullptr) {
2456 LOGE("Invalid parameter");
2457 return NOTI_EX_ERROR_INVALID_PARAMETER;
2460 Handle* p = static_cast<Handle*>(handle);
2461 if (p->Get()->GetTag().empty())
2464 *tag = strdup(p->Get()->GetTag().c_str());
2465 return NOTI_EX_ERROR_NONE;
2468 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2470 if (handle == nullptr) {
2471 LOGE("Invalid parameter");
2472 return NOTI_EX_ERROR_INVALID_PARAMETER;
2475 Handle* p = static_cast<Handle*>(handle);
2477 p->Get()->SetTag("");
2479 p->Get()->SetTag(tag);
2480 return NOTI_EX_ERROR_NONE;
2483 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2485 if (handle == nullptr || ongoing == nullptr) {
2486 LOGE("Invalid parameter");
2487 return NOTI_EX_ERROR_INVALID_PARAMETER;
2490 Handle* p = static_cast<Handle*>(handle);
2491 *ongoing = p->Get()->GetOnGoingState();
2493 return NOTI_EX_ERROR_NONE;
2496 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2498 if (handle == nullptr) {
2499 LOGE("Invalid parameter");
2500 return NOTI_EX_ERROR_INVALID_PARAMETER;
2503 Handle* p = static_cast<Handle*>(handle);
2504 p->Get()->SetOnGoingState(ongoing);
2506 return NOTI_EX_ERROR_NONE;
2509 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2510 int type, bool* exist) {
2511 if (handle == nullptr || exist == nullptr) {
2512 LOGE("Invalid parameter");
2513 return NOTI_EX_ERROR_INVALID_PARAMETER;
2516 Handle* p = static_cast<Handle*>(handle);
2517 *exist = p->Get()->IsItemTypeExist(type);
2519 return NOTI_EX_ERROR_NONE;
2522 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2524 if (handle == nullptr || type == nullptr) {
2525 LOGE("Invalid parameter");
2526 return NOTI_EX_ERROR_INVALID_PARAMETER;
2529 Handle* p = static_cast<Handle*>(handle);
2530 *type = p->Get()->GetMainType();
2532 return NOTI_EX_ERROR_NONE;
2535 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2536 const char* id, int type) {
2537 if (handle == nullptr || id == nullptr) {
2538 LOGE("Invalid parameter");
2539 return NOTI_EX_ERROR_INVALID_PARAMETER;
2542 Handle* p = static_cast<Handle*>(handle);
2543 if (!(p->Get()->SetMainType(string(id),
2544 static_cast<AbstractItem::MainType>(type))))
2545 return NOTI_EX_ERROR_INVALID_PARAMETER;
2547 return NOTI_EX_ERROR_NONE;
2550 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2551 int type, noti_ex_item_h* item) {
2552 if (handle == nullptr || item == nullptr) {
2553 LOGE("Invalid parameter");
2554 return NOTI_EX_ERROR_INVALID_PARAMETER;
2557 Handle* h = static_cast<Handle*>(handle);
2558 if (!h->IsValidType(AbstractItem::Group)) {
2559 LOGE("Invalid handle type");
2560 return NOTI_EX_ERROR_INVALID_PARAMETER;
2563 GroupItem* p = static_cast<GroupItem*>(h->Get());
2564 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2565 if (find_item.GetType() == AbstractItem::NullObject) {
2566 LOGW("Not exist ID");
2568 return NOTI_EX_ERROR_NONE;
2570 *item = new Handle(&find_item);
2572 return NOTI_EX_ERROR_NONE;
2575 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2576 const char *key, bundle **value) {
2577 if (handle == nullptr || key == nullptr || value == nullptr) {
2578 LOGE("Invalid handle type");
2579 return NOTI_EX_ERROR_INVALID_PARAMETER;
2582 Handle* p = static_cast<Handle*>(handle);
2584 Bundle b = p->Get()->GetExtensionData(key);
2585 if (b.GetCount() == 0)
2588 *value = bundle_dup(b.GetHandle());
2590 return NOTI_EX_ERROR_NONE;
2593 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2594 const char *key, bundle *value) {
2595 if (handle == nullptr || key == nullptr || value == nullptr) {
2596 LOGE("Invalid handle type");
2597 return NOTI_EX_ERROR_INVALID_PARAMETER;
2600 Bundle b = Bundle(value);
2602 Handle* p = static_cast<Handle*>(handle);
2603 p->Get()->SetExtensionData(key, b);
2605 return NOTI_EX_ERROR_NONE;
2608 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2609 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2611 if (handle == nullptr) {
2612 LOGE("Invalid parameter");
2613 return NOTI_EX_ERROR_INVALID_PARAMETER;
2616 string receiver_group_str = "";
2618 receiver_group_str = string(receiver_group);
2620 ManagerStub* stub = new (std::nothrow) ManagerStub(
2621 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2622 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2623 receiver_group_str);
2624 if (stub == nullptr) {
2625 LOGE("Fail to create manager");
2626 return NOTI_EX_ERROR_IO_ERROR;
2628 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2629 new ManagerCallbackInfo(event_callbacks, data)));
2630 *handle = static_cast<noti_ex_manager_h>(stub);
2632 return NOTI_EX_ERROR_NONE;
2635 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2636 if (handle == nullptr) {
2637 LOGE("Invalid parameter");
2638 return NOTI_EX_ERROR_INVALID_PARAMETER;
2640 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2642 return NOTI_EX_ERROR_NONE;
2645 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2646 noti_ex_item_h **items, int *count) {
2647 if (handle == nullptr || items == nullptr || count == nullptr) {
2648 LOGE("Invalid parameter");
2649 return NOTI_EX_ERROR_INVALID_PARAMETER;
2653 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2654 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2655 if (item_list.size() == 0) {
2658 return NOTI_EX_ERROR_NONE;
2660 noti_ex_item_h* added_item =
2661 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2662 if (added_item == nullptr) {
2663 LOGE("Fail to create items");
2664 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2668 for (auto& i : item_list) {
2669 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2671 *items = added_item;
2672 *count = item_list.size();
2673 } catch (Exception &ex) {
2674 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2675 return NOTI_EX_ERROR_IO_ERROR;
2677 return NOTI_EX_ERROR_NONE;
2680 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2681 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2682 if (handle == nullptr || channel == nullptr ||
2683 items == nullptr || count == nullptr) {
2684 LOGE("Invalid parameter");
2685 return NOTI_EX_ERROR_INVALID_PARAMETER;
2689 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2690 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2691 if (item_list.size() == 0) {
2694 return NOTI_EX_ERROR_NONE;
2696 noti_ex_item_h* added_item =
2697 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2698 if (added_item == nullptr) {
2699 LOGE("Fail to create items");
2700 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2704 for (auto& i : item_list) {
2705 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2707 *items = added_item;
2708 *count = item_list.size();
2709 } catch (Exception &ex) {
2710 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2711 return NOTI_EX_ERROR_IO_ERROR;
2714 return NOTI_EX_ERROR_NONE;
2717 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2718 noti_ex_item_h noti, int *request_id) {
2719 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2720 LOGE("Invalid parameter");
2721 return NOTI_EX_ERROR_INVALID_PARAMETER;
2724 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2725 Handle* sp = static_cast<Handle*>(noti);
2726 if (sp->GetPtr().get() == nullptr) {
2727 LOGE("Invalid noti reference can not be sended");
2728 return NOTI_EX_ERROR_INVALID_PARAMETER;
2730 *request_id = stub->Update(sp->GetPtr());
2732 } catch (Exception &ex) {
2733 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2734 return NOTI_EX_ERROR_IO_ERROR;
2736 return NOTI_EX_ERROR_NONE;
2739 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2740 noti_ex_item_h noti, int *request_id) {
2741 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2742 LOGE("Invalid parameter");
2743 return NOTI_EX_ERROR_INVALID_PARAMETER;
2746 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2747 Handle* item = static_cast<Handle*>(noti);
2748 if (item->GetPtr().get() == nullptr) {
2749 LOGE("Invalid noti reference can not be sended");
2750 return NOTI_EX_ERROR_INVALID_PARAMETER;
2752 *request_id = stub->Delete(item->GetPtr());
2754 } catch (Exception &ex) {
2755 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2756 return NOTI_EX_ERROR_IO_ERROR;
2758 return NOTI_EX_ERROR_NONE;
2761 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2763 if (handle == nullptr || request_id == nullptr) {
2764 LOGE("Invalid parameter");
2765 return NOTI_EX_ERROR_INVALID_PARAMETER;
2768 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2769 *request_id = stub->DeleteAll();
2770 } catch (Exception &ex) {
2771 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2772 return NOTI_EX_ERROR_IO_ERROR;
2774 return NOTI_EX_ERROR_NONE;
2777 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2778 noti_ex_manager_h handle, const char* channel, int* request_id) {
2779 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2780 LOGE("Invalid parameter");
2781 return NOTI_EX_ERROR_INVALID_PARAMETER;
2785 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2786 *request_id = stub->DeleteByChannel(channel);
2787 } catch (Exception &ex) {
2788 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2789 return NOTI_EX_ERROR_IO_ERROR;
2792 return NOTI_EX_ERROR_NONE;
2795 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2796 noti_ex_manager_h handle, const char* app_id, int* request_id) {
2797 if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2798 LOGE("Invalid parameter");
2799 return NOTI_EX_ERROR_INVALID_PARAMETER;
2803 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2804 *request_id = stub->DeleteByAppId(app_id);
2805 } catch (Exception &ex) {
2806 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2807 return NOTI_EX_ERROR_IO_ERROR;
2810 return NOTI_EX_ERROR_NONE;
2813 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2814 noti_ex_item_h noti, int *request_id) {
2815 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2816 LOGE("Invalid parameter");
2817 return NOTI_EX_ERROR_INVALID_PARAMETER;
2820 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2821 Handle* item = static_cast<Handle*>(noti);
2822 if (item->GetPtr().get() == nullptr) {
2823 LOGE("Invalid noti reference can not be sended");
2824 return NOTI_EX_ERROR_INVALID_PARAMETER;
2826 *request_id = stub->Hide(item->GetPtr());
2828 } catch (Exception &ex) {
2829 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2830 return NOTI_EX_ERROR_IO_ERROR;
2832 return NOTI_EX_ERROR_NONE;
2835 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2836 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2837 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2838 LOGE("Invalid parameter");
2839 return NOTI_EX_ERROR_INVALID_PARAMETER;
2842 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2843 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2844 if (ptr == nullptr) {
2845 LOGW("Not exist ID");
2847 return NOTI_EX_ERROR_NONE;
2849 *item = new Handle(ptr);
2850 } catch (Exception &ex) {
2851 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2852 return NOTI_EX_ERROR_IO_ERROR;
2854 return NOTI_EX_ERROR_NONE;
2857 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2858 noti_ex_event_info_h info, noti_ex_error_e error) {
2859 if (handle == nullptr || info == nullptr) {
2860 LOGE("Invalid parameter");
2861 return NOTI_EX_ERROR_INVALID_PARAMETER;
2864 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2865 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2866 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2867 static_cast<NotificationError>(error));
2868 } catch (Exception &ex) {
2869 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2870 return NOTI_EX_ERROR_IO_ERROR;
2872 return NOTI_EX_ERROR_NONE;
2875 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2876 noti_ex_manager_h handle, int *cnt) {
2878 if (handle == nullptr || cnt == nullptr) {
2879 LOGE("Invalid parameter");
2880 return NOTI_EX_ERROR_INVALID_PARAMETER;
2883 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2884 *cnt = stub->GetCount();
2885 } catch (Exception &ex) {
2886 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2887 return NOTI_EX_ERROR_IO_ERROR;
2889 return NOTI_EX_ERROR_NONE;
2892 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2893 const char *id, float min, float current, float max) {
2896 if (handle == nullptr) {
2897 LOGE("Invalid parameter");
2898 return NOTI_EX_ERROR_INVALID_PARAMETER;
2902 p = new (std::nothrow) ProgressItem(id, min, current, max);
2904 p = new (std::nothrow) ProgressItem(min, current, max);
2907 LOGE("Out-of-memory");
2908 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2911 *handle = new Handle(shared_ptr<AbstractItem>(p));
2913 return NOTI_EX_ERROR_NONE;
2916 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2917 noti_ex_item_h handle, float *current) {
2918 if (handle == nullptr || current == nullptr) {
2919 LOGE("Invalid parameter");
2920 return NOTI_EX_ERROR_INVALID_PARAMETER;
2923 Handle *h = static_cast<Handle*>(handle);
2924 if (!h->IsValidType(AbstractItem::Progress)) {
2925 LOGE("Invalid handle type");
2926 return NOTI_EX_ERROR_INVALID_PARAMETER;
2928 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2929 *current = p->GetCurrent();
2931 return NOTI_EX_ERROR_NONE;
2934 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2935 noti_ex_item_h handle, float current) {
2936 if (handle == nullptr) {
2937 LOGE("Invalid parameter");
2938 return NOTI_EX_ERROR_INVALID_PARAMETER;
2941 Handle *h = static_cast<Handle*>(handle);
2942 if (!h->IsValidType(AbstractItem::Progress)) {
2943 LOGE("Invalid handle type");
2944 return NOTI_EX_ERROR_INVALID_PARAMETER;
2946 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2947 p->SetCurrent(current);
2949 return NOTI_EX_ERROR_NONE;
2952 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2954 if (handle == nullptr || min == nullptr) {
2955 LOGE("Invalid parameter");
2956 return NOTI_EX_ERROR_INVALID_PARAMETER;
2959 Handle *h = static_cast<Handle*>(handle);
2960 if (!h->IsValidType(AbstractItem::Progress)) {
2961 LOGE("Invalid handle type");
2962 return NOTI_EX_ERROR_INVALID_PARAMETER;
2964 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2967 return NOTI_EX_ERROR_NONE;
2970 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2972 if (handle == nullptr || max == nullptr) {
2973 LOGE("Invalid parameter");
2974 return NOTI_EX_ERROR_INVALID_PARAMETER;
2977 Handle *h = static_cast<Handle*>(handle);
2978 if (!h->IsValidType(AbstractItem::Progress)) {
2979 LOGE("Invalid handle type");
2980 return NOTI_EX_ERROR_INVALID_PARAMETER;
2982 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2985 return NOTI_EX_ERROR_NONE;
2988 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2990 if (handle == nullptr || type == nullptr) {
2991 LOGE("Invalid parameter");
2992 return NOTI_EX_ERROR_INVALID_PARAMETER;
2995 Handle *h = static_cast<Handle*>(handle);
2996 if (!h->IsValidType(AbstractItem::Progress)) {
2997 LOGE("Invalid handle type");
2998 return NOTI_EX_ERROR_INVALID_PARAMETER;
3000 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3001 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
3003 return NOTI_EX_ERROR_NONE;
3006 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
3008 if (handle == nullptr) {
3009 LOGE("Invalid parameter");
3010 return NOTI_EX_ERROR_INVALID_PARAMETER;
3013 Handle *h = static_cast<Handle*>(handle);
3014 if (!h->IsValidType(AbstractItem::Progress)) {
3015 LOGE("Invalid handle type");
3016 return NOTI_EX_ERROR_INVALID_PARAMETER;
3018 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3019 p->SetProgressType(static_cast<ProgressItem::Type>(type));
3021 return NOTI_EX_ERROR_NONE;
3024 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
3025 noti_ex_reporter_events_s event_callbacks, void *data) {
3026 if (handle == nullptr) {
3027 LOGE("Invalid parameter");
3028 return NOTI_EX_ERROR_INVALID_PARAMETER;
3031 ReporterStub* stub = new (std::nothrow) ReporterStub(
3032 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
3033 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
3034 if (stub == nullptr) {
3035 LOGE("Fail to create manager");
3036 return NOTI_EX_ERROR_IO_ERROR;
3038 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
3039 new ReporterCallbackInfo(event_callbacks, data)));
3041 *handle = static_cast<noti_ex_reporter_h>(stub);
3043 return NOTI_EX_ERROR_NONE;
3046 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3047 if (handle == nullptr) {
3048 LOGE("Invalid parameter");
3049 return NOTI_EX_ERROR_INVALID_PARAMETER;
3051 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3053 return NOTI_EX_ERROR_NONE;
3056 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3057 noti_ex_event_info_h info, noti_ex_error_e error) {
3058 if (handle == nullptr || info == nullptr) {
3059 LOGE("Invalid parameter");
3060 return NOTI_EX_ERROR_INVALID_PARAMETER;
3063 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3064 IEventInfo* c_info = static_cast<IEventInfo*>(info);
3065 stub->SendError(static_cast<const IEventInfo&>(*c_info),
3066 static_cast<NotificationError>(error));
3067 } catch (Exception &ex) {
3068 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3069 return NOTI_EX_ERROR_IO_ERROR;
3071 return NOTI_EX_ERROR_NONE;
3074 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3075 noti_ex_item_h noti, int *request_id) {
3076 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3077 LOGE("Invalid parameter");
3078 return NOTI_EX_ERROR_INVALID_PARAMETER;
3081 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3082 Handle* h = static_cast<Handle*>(noti);
3083 if (h->GetPtr().get() == nullptr) {
3084 LOGE("Invalid noti reference can not be sended");
3085 return NOTI_EX_ERROR_INVALID_PARAMETER;
3087 *request_id = stub->Post(h->GetPtr());
3089 } catch (Exception &ex) {
3090 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3091 return NOTI_EX_ERROR_IO_ERROR;
3093 return NOTI_EX_ERROR_NONE;
3096 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3097 noti_ex_item_h *noti_list, int count, int *request_id) {
3099 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3100 LOGE("Invalid parameter");
3101 return NOTI_EX_ERROR_INVALID_PARAMETER;
3104 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3105 list<shared_ptr<item::AbstractItem>> notiList;
3106 for (int i = 0; i < count; i++) {
3107 Handle* item = static_cast<Handle*>(noti_list[i]);
3108 notiList.push_back(item->GetPtr());
3110 *request_id = stub->Post(notiList);
3111 } catch (Exception &ex) {
3112 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3113 return NOTI_EX_ERROR_IO_ERROR;
3115 return NOTI_EX_ERROR_NONE;
3118 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3119 noti_ex_item_h noti, int *request_id) {
3120 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3121 LOGE("Invalid parameter");
3122 return NOTI_EX_ERROR_INVALID_PARAMETER;
3125 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3126 Handle* item = static_cast<Handle*>(noti);
3127 if (item->GetPtr().get() == nullptr) {
3128 LOGE("Invalid noti reference can not be sended");
3129 return NOTI_EX_ERROR_INVALID_PARAMETER;
3131 *request_id = stub->Update(item->GetPtr());
3133 } catch (Exception &ex) {
3134 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3135 return NOTI_EX_ERROR_IO_ERROR;
3137 return NOTI_EX_ERROR_NONE;
3140 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3141 noti_ex_item_h noti, int *request_id) {
3142 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3143 LOGE("Invalid parameter");
3144 return NOTI_EX_ERROR_INVALID_PARAMETER;
3147 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3148 Handle* item = static_cast<Handle*>(noti);
3149 if (item->GetPtr().get() == nullptr) {
3150 LOGE("Invalid noti reference can not be sended");
3151 return NOTI_EX_ERROR_INVALID_PARAMETER;
3153 *request_id = stub->Delete(item->GetPtr());
3155 } catch (Exception &ex) {
3156 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3157 return NOTI_EX_ERROR_IO_ERROR;
3159 return NOTI_EX_ERROR_NONE;
3162 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3163 noti_ex_reporter_h handle, int *request_id) {
3164 if (handle == nullptr || request_id == nullptr) {
3165 LOGE("Invalid parameter");
3166 return NOTI_EX_ERROR_INVALID_PARAMETER;
3169 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3170 *request_id = stub->DeleteAll();
3171 } catch (Exception &ex) {
3172 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3173 return NOTI_EX_ERROR_IO_ERROR;
3175 return NOTI_EX_ERROR_NONE;
3178 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3179 noti_ex_reporter_h handle, const char* channel, int* request_id) {
3180 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3181 LOGE("Invalid parameter");
3182 return NOTI_EX_ERROR_INVALID_PARAMETER;
3186 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3187 *request_id = stub->DeleteByChannel(channel);
3188 } catch (Exception &ex) {
3189 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3190 return NOTI_EX_ERROR_IO_ERROR;
3193 return NOTI_EX_ERROR_NONE;
3196 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3197 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3198 if (handle == nullptr || root_id == nullptr || item == nullptr) {
3199 LOGE("Invalid parameter");
3200 return NOTI_EX_ERROR_INVALID_PARAMETER;
3203 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3204 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3205 if (ptr == nullptr) {
3206 LOGW("Not exist ID");
3208 return NOTI_EX_ERROR_NONE;
3210 *item = new Handle(ptr);
3211 } catch (Exception &ex) {
3212 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3213 return NOTI_EX_ERROR_IO_ERROR;
3215 return NOTI_EX_ERROR_NONE;
3218 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3219 const char *channel, noti_ex_item_h **noti_list, int *count) {
3220 if (handle == nullptr || channel == nullptr || noti_list == nullptr
3221 || count == nullptr) {
3222 LOGE("Invalid parameter");
3223 return NOTI_EX_ERROR_INVALID_PARAMETER;
3226 Handle** list_item = nullptr;
3229 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3230 list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3231 if (list_ptr.empty()) {
3232 LOGW("Not exist ID");
3233 *noti_list = nullptr;
3234 return NOTI_EX_ERROR_NONE;
3237 int size = list_ptr.size();
3240 list_item = (Handle**)calloc(size, sizeof(Handle*));
3241 for (auto& ptr : list_ptr)
3242 list_item[i++] = new Handle(std::move(ptr));
3244 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3246 } catch (Exception &ex) {
3247 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3249 return NOTI_EX_ERROR_IO_ERROR;
3252 return NOTI_EX_ERROR_NONE;
3255 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3256 noti_ex_item_h **noti_list, int *count) {
3257 if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3258 LOGE("Invalid parameter");
3259 return NOTI_EX_ERROR_INVALID_PARAMETER;
3262 Handle** list_item = nullptr;
3265 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3266 list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3267 if (list_ptr.empty()) {
3268 LOGW("Not exist ID");
3269 *noti_list = nullptr;
3270 return NOTI_EX_ERROR_NONE;
3273 int size = list_ptr.size();
3276 list_item = (Handle**)calloc(size, sizeof(Handle*));
3277 for (auto& ptr : list_ptr)
3278 list_item[i++] = new Handle(std::move(ptr));
3280 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3282 } catch (Exception &ex) {
3283 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3285 return NOTI_EX_ERROR_IO_ERROR;
3288 return NOTI_EX_ERROR_NONE;
3291 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3292 const char *id, const char *text, const char *hyperlink) {
3293 if (handle == nullptr || text == nullptr) {
3294 LOGE("Invalid parameter");
3295 return NOTI_EX_ERROR_INVALID_PARAMETER;
3304 p = new (std::nothrow) TextItem(id, std::string(text),
3305 std::string(hyperlink));
3307 p = new (std::nothrow) TextItem(id, std::string(text));
3310 LOGE("Out-of-memory");
3311 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3314 *handle = new Handle(shared_ptr<AbstractItem>(p));
3316 return NOTI_EX_ERROR_NONE;
3319 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3320 const char *contents) {
3321 if (handle == nullptr || contents == nullptr) {
3322 LOGE("Invalid parameter");
3323 return NOTI_EX_ERROR_INVALID_PARAMETER;
3326 Handle* p = static_cast<Handle*>(handle);
3327 if (!p->IsValidType(AbstractItem::Text)) {
3328 LOGE("Invalid handle type");
3329 return NOTI_EX_ERROR_INVALID_PARAMETER;
3331 TextItem* ti = static_cast<TextItem*>(p->Get());
3332 ti->SetContents(std::string(contents));
3334 return NOTI_EX_ERROR_NONE;
3337 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3339 if (handle == nullptr || contents == nullptr) {
3340 LOGE("Invalid parameter");
3341 return NOTI_EX_ERROR_INVALID_PARAMETER;
3344 Handle* p = static_cast<Handle*>(handle);
3345 if (!p->IsValidType(AbstractItem::Text)) {
3346 LOGE("Invalid handle type");
3347 return NOTI_EX_ERROR_INVALID_PARAMETER;
3350 TextItem* ti = static_cast<TextItem*>(p->Get());
3352 if (ti->GetMultiLanguage() != nullptr &&
3353 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3354 str = ti->GetMultiLanguage()->GetTranslatedString();
3355 else if (!ti->GetContents().empty())
3356 str = ti->GetContents();
3358 *contents = strdup(str.c_str());
3359 if (*contents == nullptr) {
3360 LOGE("Out-of-memory");
3361 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3364 return NOTI_EX_ERROR_NONE;
3367 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3368 noti_ex_item_h handle, char **hyper_link) {
3369 if (handle == nullptr || hyper_link == nullptr) {
3370 LOGE("Invalid parameter");
3371 return NOTI_EX_ERROR_INVALID_PARAMETER;
3374 Handle* p = static_cast<Handle*>(handle);
3375 if (!p->IsValidType(AbstractItem::Text)) {
3376 LOGE("Invalid handle type");
3377 return NOTI_EX_ERROR_INVALID_PARAMETER;
3379 TextItem* ti = static_cast<TextItem*>(p->Get());
3380 if (!ti->GetHyperLink().empty()) {
3381 *hyper_link = strdup(ti->GetHyperLink().c_str());
3382 if (*hyper_link == nullptr) {
3383 LOGE("Out-of-memory");
3384 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3387 *hyper_link = nullptr;
3390 return NOTI_EX_ERROR_NONE;
3393 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3394 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3395 if (handle == nullptr) {
3396 LOGE("Invalid parameter");
3397 return NOTI_EX_ERROR_INVALID_PARAMETER;
3400 Handle* p = static_cast<Handle*>(handle);
3401 if (!p->IsValidType(AbstractItem::Text)) {
3402 LOGE("Invalid handle type");
3403 return NOTI_EX_ERROR_INVALID_PARAMETER;
3406 TextItem* ti = static_cast<TextItem*>(p->Get());
3407 if (multi == nullptr) {
3408 ti->SetMultiLanguage(nullptr);
3409 return NOTI_EX_ERROR_NONE;
3412 shared_ptr<MultiLanguage> mul_ptr =
3413 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3414 ti->SetMultiLanguage(mul_ptr);
3415 ti->GetMultiLanguage()->UpdateString();
3417 return NOTI_EX_ERROR_NONE;
3420 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3421 const char *id, time_t time) {
3424 if (handle == nullptr) {
3425 LOGE("Invalid parameter");
3426 return NOTI_EX_ERROR_INVALID_PARAMETER;
3431 p = new (std::nothrow) TimeItem(id, time);
3433 p = new (std::nothrow) TimeItem(time);
3435 p = new (std::nothrow) TimeItem();
3439 LOGE("Out-of-memory");
3440 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3443 *handle = new Handle(shared_ptr<AbstractItem>(p));
3445 return NOTI_EX_ERROR_NONE;
3448 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3450 if (handle == nullptr || time == nullptr) {
3451 LOGE("Invalid parameter");
3452 return NOTI_EX_ERROR_INVALID_PARAMETER;
3454 Handle* h = static_cast<Handle*>(handle);
3455 if (!h->IsValidType(AbstractItem::Time)) {
3456 LOGE("Invalid handle type");
3457 return NOTI_EX_ERROR_INVALID_PARAMETER;
3459 TimeItem* p = static_cast<TimeItem*>(h->Get());
3460 *time = p->GetTime();
3462 return NOTI_EX_ERROR_NONE;
3465 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3467 if (handle == nullptr) {
3468 LOGE("Invalid parameter");
3469 return NOTI_EX_ERROR_INVALID_PARAMETER;
3471 Handle* h = static_cast<Handle*>(handle);
3472 if (!h->IsValidType(AbstractItem::Time)) {
3473 LOGE("Invalid handle type");
3474 return NOTI_EX_ERROR_INVALID_PARAMETER;
3476 TimeItem* p = static_cast<TimeItem*>(h->Get());
3479 return NOTI_EX_ERROR_NONE;
3482 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3483 noti_ex_action_h *handle, const char *extra) {
3484 if (handle == nullptr) {
3485 LOGE("Invalid parameter");
3486 return NOTI_EX_ERROR_INVALID_PARAMETER;
3489 string extra_str = "";
3491 extra_str = string(extra);
3493 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3494 new (std::nothrow) VisibilityAction(extra_str));
3495 if (ptr == nullptr) {
3496 LOGE("Out-of-memory");
3497 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3502 return NOTI_EX_ERROR_NONE;
3505 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3506 const char *id, bool visible) {
3507 if (handle == nullptr || id == nullptr) {
3508 LOGE("Invalid parameter");
3509 return NOTI_EX_ERROR_INVALID_PARAMETER;
3512 shared_ptr<AbstractAction>* ptr =
3513 static_cast<shared_ptr<AbstractAction>*>(handle);
3514 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3515 action->SetVisibility(id, visible);
3517 return NOTI_EX_ERROR_NONE;
3520 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3521 const char* msgid, const char* format, ...) {
3522 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3523 LOGE("Invalid parameter");
3524 return NOTI_EX_ERROR_INVALID_PARAMETER;
3527 const char* format_idx = format;
3530 va_start(args, format);
3531 while (*format_idx != '\0') {
3532 char* arg = nullptr;
3535 stringstream stream;
3536 if (*format_idx == '%') {
3537 switch (*(format_idx + 1)) {
3539 arg = va_arg(args, char *);
3540 arr.push_back(string(arg));
3543 arg_i = va_arg(args, int);
3544 arr.push_back(to_string(arg_i));
3547 arg_f = va_arg(args, double);
3548 stream << std::fixed << std::setprecision(2) << arg_f;
3549 arr.push_back(stream.str());
3557 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3559 LOGE("Out-of-memory");
3560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3562 *handle = new shared_ptr<MultiLanguage>(p);
3564 return NOTI_EX_ERROR_NONE;
3567 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3568 if (handle == nullptr) {
3569 LOGE("Invalid parameter");
3570 return NOTI_EX_ERROR_INVALID_PARAMETER;
3573 shared_ptr<MultiLanguage>* mul_ptr =
3574 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3576 return NOTI_EX_ERROR_NONE;
3579 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3580 noti_ex_item_h item, int64_t* private_id) {
3581 if (item == nullptr || private_id == nullptr) {
3582 LOGE("Invalid parameter");
3583 return NOTI_EX_ERROR_INVALID_PARAMETER;
3586 Handle* h = static_cast<Handle*>(item);
3587 *private_id = static_pointer_cast<IItemInfoInternal>(
3588 h->Get()->GetInfo())->GetPrivateId();
3590 return NOTI_EX_ERROR_NONE;
3593 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3594 noti_ex_item_h item, int64_t priv_id) {
3595 if (item == nullptr) {
3596 LOGE("Invalid parameter");
3597 return NOTI_EX_ERROR_INVALID_PARAMETER;
3600 Handle* h = static_cast<Handle*>(item);
3601 static_pointer_cast<IItemInfoInternal>(
3602 h->Get()->GetInfo())->SetPrivateId(priv_id);
3604 return NOTI_EX_ERROR_NONE;
3607 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3608 if (list == nullptr) {
3609 LOGE("Invalid parameter");
3610 return NOTI_EX_ERROR_INVALID_PARAMETER;
3613 LOGI("Free strings (%d)", count);
3614 for (int i = 0; i < count; i++)
3618 return NOTI_EX_ERROR_NONE;
3621 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3622 if (handle == nullptr) {
3623 LOGE("Invalid parameter");
3624 return NOTI_EX_ERROR_INVALID_PARAMETER;
3626 Handle* h = static_cast<Handle*>(handle);
3627 if (!h->IsValidType(AbstractItem::Group)) {
3628 LOGE("Invalid handle type");
3629 return NOTI_EX_ERROR_INVALID_PARAMETER;
3631 GroupItem* p = static_cast<GroupItem*>(h->Get());
3632 p->RemoveChildren();
3634 return NOTI_EX_ERROR_NONE;
3637 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3638 const char *id, const char *icon_path) {
3639 if (handle == nullptr || icon_path == nullptr) {
3640 LOGE("Invalid parameter");
3641 return NOTI_EX_ERROR_INVALID_PARAMETER;
3646 p = new (std::nothrow) IconItem(id, icon_path);
3648 p = new (std::nothrow) IconItem(icon_path);
3651 LOGE("Out-of-memory");
3652 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3655 *handle = new Handle(shared_ptr<AbstractItem>(p));
3657 return NOTI_EX_ERROR_NONE;
3660 int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3661 if (handle == nullptr || icon_path == nullptr) {
3662 LOGE("Invalid parameter");
3663 return NOTI_EX_ERROR_INVALID_PARAMETER;
3666 Handle* h = static_cast<Handle*>(handle);
3667 if (!h->IsValidType(AbstractItem::Icon)) {
3668 LOGE("Invalid handle type");
3669 return NOTI_EX_ERROR_INVALID_PARAMETER;
3672 IconItem* p = static_cast<IconItem*>(h->Get());
3673 if (!p->GetImagePath().empty()) {
3674 *icon_path = strdup(p->GetImagePath().c_str());
3675 if (*icon_path == nullptr) {
3676 LOGE("Out-of-memory");
3677 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3680 *icon_path = nullptr;
3683 return NOTI_EX_ERROR_NONE;