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_app_control_action.h"
26 #include "api/notification_ex_button.h"
27 #include "api/notification_ex_chat_message.h"
28 #include "api/notification_ex_checkbox.h"
29 #include "api/notification_ex_entry.h"
30 #include "api/notification_ex_event_info.h"
31 #include "api/notification_ex_group.h"
32 #include "api/notification_ex_image.h"
33 #include "api/notification_ex_input_selector.h"
34 #include "api/notification_ex_item.h"
35 #include "api/notification_ex_manager.h"
36 #include "api/notification_ex_progress.h"
37 #include "api/notification_ex_reporter.h"
38 #include "api/notification_ex_text.h"
39 #include "api/notification_ex_time.h"
40 #include "api/notification_ex_visibility_action.h"
41 #include "notification-ex/reporter.h"
42 #include "notification-ex/app_control_action.h"
43 #include "notification-ex/button_item.h"
44 #include "notification-ex/chat_message_item.h"
45 #include "notification-ex/checkbox_item.h"
46 #include "notification-ex/entry_item.h"
47 #include "notification-ex/group_item.h"
48 #include "notification-ex/input_selector_item.h"
49 #include "notification-ex/abstract_item.h"
50 #include "notification-ex/progress_item.h"
51 #include "notification-ex/time_item.h"
52 #include "notification-ex/visibility_action.h"
53 #include "notification-ex/event_info_internal.h"
54 #include "notification-ex/manager.h"
55 #include "notification-ex/dbus_sender.h"
56 #include "notification-ex/dbus_event_listener.h"
57 #include "notification-ex/exception.h"
58 #include "notification-ex/iitem_info_internal.h"
63 #define LOG_TAG "NOTIFICATION_EX"
68 #define EXPORT_API __attribute__((visibility("default")))
71 using namespace tizen_base;
72 using namespace notification::item;
73 using namespace notification;
79 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
80 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
81 : ref_(nullptr), ptr_(move(ptr)) { }
82 virtual ~Handle() = default;
83 item::AbstractItem* Get() const {
89 bool IsValidType(int type) const {
90 return (Get()->GetType() == type
91 || Get()->GetType() >= AbstractItem::Custom);
94 std::shared_ptr<item::AbstractItem> GetPtr() const {
96 return std::shared_ptr<item::AbstractItem>({});
101 item::AbstractItem* ref_;
102 std::shared_ptr<item::AbstractItem> ptr_;
105 class ManagerCallbackInfo {
107 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
108 : user_data_(user_data) {
109 cb_.added = cb.added;
110 cb_.updated = cb.updated;
111 cb_.deleted = cb.deleted;
112 cb_.error = cb.error;
115 void InvokeAdded(Manager* manager, const IEventInfo& info,
116 list<shared_ptr<AbstractItem>> addedItem) {
117 if (cb_.added == nullptr)
119 noti_ex_item_h* added_item =
120 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
121 if (added_item == nullptr) {
122 LOGE("Out of memory");
127 for (auto& i : addedItem) {
129 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
132 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
133 cb_.added(static_cast<noti_ex_manager_h>(manager),
134 static_cast<noti_ex_event_info_h>(c_info), added_item,
135 addedItem.size(), user_data_);
138 void InvokeUpdated(Manager* manager, const IEventInfo& info,
139 shared_ptr<item::AbstractItem> updatedItem) {
140 if (cb_.updated == nullptr)
142 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
143 cb_.updated(static_cast<noti_ex_manager_h>(manager),
144 static_cast<noti_ex_event_info_h>(c_info),
145 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
148 void InvokeDeleted(Manager* manager, const IEventInfo& info,
149 shared_ptr<item::AbstractItem> deletedItem) {
150 if (cb_.deleted == nullptr)
152 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
153 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
154 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
155 static_cast<noti_ex_event_info_h>(c_info),
156 nullptr, user_data_);
158 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
159 static_cast<noti_ex_event_info_h>(c_info),
160 static_cast<noti_ex_item_h>(
161 new Handle(deletedItem)), user_data_);
165 void InvokeError(Manager* manager, NotificationError error, int requestId) {
166 if (cb_.error == nullptr)
168 cb_.error(static_cast<noti_ex_manager_h>(manager),
169 static_cast<noti_ex_error_e>(error), requestId, user_data_);
173 noti_ex_manager_events_s cb_;
177 class ManagerStub : public Manager {
179 ManagerStub(std::unique_ptr<IEventSender> sender,
180 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
181 : Manager(move(sender), move(listener), receiver_group) {
184 void OnAdd(const IEventInfo& info,
185 list<shared_ptr<AbstractItem>> addedItem) override {
186 cb_->InvokeAdded(this, info, addedItem);
189 void OnUpdate(const IEventInfo& info,
190 std::shared_ptr<item::AbstractItem> updatedItem) override {
191 cb_->InvokeUpdated(this, info, updatedItem);
194 void OnDelete(const IEventInfo& info,
195 shared_ptr<item::AbstractItem> deletedItem) override {
196 cb_->InvokeDeleted(this, info, deletedItem);
199 void OnError(NotificationError error, int requestId) override {
200 cb_->InvokeError(this, error, requestId);
203 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
205 return NOTI_EX_ERROR_NONE;
208 int ClearManagerCallbackInfo() {
210 return NOTI_EX_ERROR_NONE;
214 unique_ptr<ManagerCallbackInfo> cb_;
218 class ReporterCallbackInfo {
220 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
221 : user_data_(user_data) {
222 cb_.event = cb.event;
223 cb_.error = cb.error;
226 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
227 list<shared_ptr<AbstractItem>> notiList) {
228 if (cb_.event == nullptr)
230 noti_ex_item_h* noti_list =
231 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
232 if (noti_list == nullptr) {
233 LOGE("Out of memory");
238 for (auto& i : notiList) {
240 static_cast<noti_ex_item_h>(new Handle(i));
243 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
244 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
245 static_cast<noti_ex_event_info_h>(c_info), noti_list,
246 notiList.size(), user_data_);
250 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
251 if (cb_.error == nullptr)
253 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
254 static_cast<noti_ex_error_e>(error), requestId, user_data_);
258 noti_ex_reporter_events_s cb_;
262 class ReporterStub : public Reporter {
264 ReporterStub(std::unique_ptr<IEventSender> sender,
265 std::unique_ptr<IEventListener> listener)
266 : Reporter(move(sender), move(listener)) {
269 void OnEvent(const IEventInfo& info,
270 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
271 cb_->InvokeEvent(this, info, notiList);
274 void OnError(NotificationError error, int requestId) override {
275 cb_->InvokeError(this, error, requestId);
278 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
280 return NOTI_EX_ERROR_NONE;
283 int ClearReporterCallbackInfo() {
285 return NOTI_EX_ERROR_NONE;
289 unique_ptr<ReporterCallbackInfo> cb_;
294 void __noti_ex_free_str_array(char** val, int length) {
296 for (i = 0; i < length ; i++)
301 extern "C" EXPORT_API int noti_ex_action_app_control_create(
302 noti_ex_action_h *handle, app_control_h app_control,
304 if (handle == nullptr || app_control == nullptr) {
305 LOGE("Invalid parameter");
306 return NOTI_EX_ERROR_INVALID_PARAMETER;
309 shared_ptr<AbstractAction>* p;
312 p = new (std::nothrow) shared_ptr<AbstractAction>(
313 new (std::nothrow) AppControlAction(app_control, extra));
315 p = new (std::nothrow) shared_ptr<AbstractAction>(
316 new (std::nothrow) AppControlAction(app_control));
320 LOGE("Out-of-memory");
321 return NOTI_EX_ERROR_OUT_OF_MEMORY;
326 return NOTI_EX_ERROR_NONE;
329 extern "C" EXPORT_API int noti_ex_action_app_control_set(
330 noti_ex_action_h handle, app_control_h app_control) {
331 if (handle == nullptr || app_control == nullptr) {
332 LOGE("Invalid parameter");
333 return NOTI_EX_ERROR_INVALID_PARAMETER;
336 shared_ptr<AbstractAction>* ptr =
337 static_cast<shared_ptr<AbstractAction>*>(handle);
338 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
339 action->SetAppControl(app_control);
341 return NOTI_EX_ERROR_NONE;
344 extern "C" EXPORT_API int noti_ex_action_app_control_get(
345 noti_ex_action_h handle, app_control_h *app_control) {
346 if (handle == nullptr || app_control == nullptr) {
347 LOGE("Invalid parameter");
348 return NOTI_EX_ERROR_INVALID_PARAMETER;
351 shared_ptr<AbstractAction>* ptr =
352 static_cast<shared_ptr<AbstractAction>*>(handle);
353 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
354 *app_control = action->GetAppControl();
356 return NOTI_EX_ERROR_NONE;
359 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
360 const char *id, const char *title) {
363 if (handle == nullptr || title == nullptr) {
364 LOGE("Invalid parameter");
365 return NOTI_EX_ERROR_INVALID_PARAMETER;
369 p = new (std::nothrow) ButtonItem(id, title);
371 p = new (std::nothrow) ButtonItem(title);
374 LOGE("Out-of-memory");
375 return NOTI_EX_ERROR_OUT_OF_MEMORY;
377 *handle = new Handle(shared_ptr<AbstractItem>(p));
379 return NOTI_EX_ERROR_NONE;
382 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
384 if (handle == nullptr || title == nullptr) {
385 LOGE("Invalid parameter");
386 return NOTI_EX_ERROR_INVALID_PARAMETER;
389 Handle* sp = static_cast<Handle*>(handle);
390 if (!sp->IsValidType(AbstractItem::Button)) {
391 LOGE("Invalid handle type");
392 return NOTI_EX_ERROR_INVALID_PARAMETER;
395 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
397 if (p->GetMultiLanguage() != nullptr &&
398 !p->GetMultiLanguage()->GetTranslatedString().empty())
399 str = p->GetMultiLanguage()->GetTranslatedString();
400 else if (!p->GetTitle().empty())
403 *title = strdup(str.c_str());
404 if (*title == nullptr) {
405 LOGE("Out-of-memory");
406 return NOTI_EX_ERROR_OUT_OF_MEMORY;
409 return NOTI_EX_ERROR_NONE;
412 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
413 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
414 if (handle == nullptr) {
415 LOGE("Invalid parameter");
416 return NOTI_EX_ERROR_INVALID_PARAMETER;
419 Handle* p = static_cast<Handle*>(handle);
420 if (!p->IsValidType(AbstractItem::Button)) {
421 LOGE("Invalid handle type");
422 return NOTI_EX_ERROR_INVALID_PARAMETER;
425 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
426 if (multi == nullptr) {
427 bi->SetMultiLanguage(nullptr);
428 return NOTI_EX_ERROR_NONE;
431 shared_ptr<MultiLanguage> mul_ptr =
432 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
434 mul_ptr->UpdateString();
435 bi->SetMultiLanguage(mul_ptr);
437 return NOTI_EX_ERROR_NONE;
440 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
441 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
442 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
443 noti_ex_item_chat_message_type_e message_type) {
444 if (handle == nullptr || (text == nullptr && image == nullptr)
445 || name == nullptr || time == nullptr
446 || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
447 LOGE("Invalid parameter");
448 return NOTI_EX_ERROR_INVALID_PARAMETER;
451 auto* p = new (std::nothrow) ChatMessageItem(id,
452 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
453 text == nullptr ? nullptr
454 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
455 image == nullptr ? nullptr
456 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
457 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
458 static_cast<ChatMessageItem::Type>(message_type));
460 LOGE("Out-of-memory");
461 return NOTI_EX_ERROR_OUT_OF_MEMORY;
464 *handle = new Handle(shared_ptr<AbstractItem>(p));
466 return NOTI_EX_ERROR_NONE;
469 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
470 noti_ex_item_h handle, noti_ex_item_h *name) {
471 if (handle == nullptr || name == nullptr) {
472 LOGE("Invalid parameter");
473 return NOTI_EX_ERROR_INVALID_PARAMETER;
475 Handle* h = static_cast<Handle*>(handle);
476 if (!h->IsValidType(AbstractItem::ChatMessage)) {
477 LOGE("Invalid handle type");
478 return NOTI_EX_ERROR_INVALID_PARAMETER;
480 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
481 *name = new Handle(&(p->GetNameItem()));
483 return NOTI_EX_ERROR_NONE;
486 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
487 noti_ex_item_h handle, noti_ex_item_h *text) {
488 if (handle == nullptr || text == nullptr) {
489 LOGE("Invalid parameter");
490 return NOTI_EX_ERROR_INVALID_PARAMETER;
493 Handle* h = static_cast<Handle*>(handle);
494 if (!h->IsValidType(AbstractItem::ChatMessage)) {
495 LOGE("Invalid handle type");
496 return NOTI_EX_ERROR_INVALID_PARAMETER;
498 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
499 *text = new Handle(&(p->GetTextItem()));
501 return NOTI_EX_ERROR_NONE;
504 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
505 noti_ex_item_h handle, noti_ex_item_h *image) {
506 if (handle == nullptr || image == nullptr) {
507 LOGE("Invalid parameter");
508 return NOTI_EX_ERROR_INVALID_PARAMETER;
511 Handle* h = static_cast<Handle*>(handle);
512 if (!h->IsValidType(AbstractItem::ChatMessage)) {
513 LOGE("Invalid handle type");
514 return NOTI_EX_ERROR_INVALID_PARAMETER;
516 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
517 *image = new Handle(&(p->GetImageItem()));
519 return NOTI_EX_ERROR_NONE;
522 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
523 noti_ex_item_h handle, noti_ex_item_h *time) {
524 if (handle == nullptr || time == nullptr) {
525 LOGE("Invalid parameter");
526 return NOTI_EX_ERROR_INVALID_PARAMETER;
529 Handle* h = static_cast<Handle*>(handle);
530 if (!h->IsValidType(AbstractItem::ChatMessage)) {
531 LOGE("Invalid handle type");
532 return NOTI_EX_ERROR_INVALID_PARAMETER;
534 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
535 *time = new Handle(&(p->GetTimeItem()));
537 return NOTI_EX_ERROR_NONE;
540 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
541 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
542 if (handle == nullptr || message_type == nullptr) {
543 LOGE("Invalid parameter");
544 return NOTI_EX_ERROR_INVALID_PARAMETER;
547 Handle* h = static_cast<Handle*>(handle);
548 if (!h->IsValidType(AbstractItem::ChatMessage)) {
549 LOGE("Invalid handle type");
550 return NOTI_EX_ERROR_INVALID_PARAMETER;
552 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
553 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
555 return NOTI_EX_ERROR_NONE;
558 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
559 const char *id, const char *title, bool checked) {
562 if (handle == nullptr || title == nullptr) {
563 LOGE("Invalid parameter");
564 return NOTI_EX_ERROR_INVALID_PARAMETER;
567 p = new (std::nothrow) CheckBoxItem(id, title, checked);
569 LOGE("Out-of-memory");
570 return NOTI_EX_ERROR_OUT_OF_MEMORY;
573 *handle = new Handle(shared_ptr<AbstractItem>(p));
575 return NOTI_EX_ERROR_NONE;
578 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
580 if (handle == nullptr || title == nullptr) {
581 LOGE("Invalid parameter");
582 return NOTI_EX_ERROR_INVALID_PARAMETER;
584 Handle* h = static_cast<Handle*>(handle);
585 if (!h->IsValidType(AbstractItem::CheckBox)) {
586 LOGE("Invalid handle type");
587 return NOTI_EX_ERROR_INVALID_PARAMETER;
590 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
592 if (p->GetMultiLanguage() != nullptr &&
593 !p->GetMultiLanguage()->GetTranslatedString().empty())
594 str = p->GetMultiLanguage()->GetTranslatedString();
595 else if (!p->GetTitle().empty())
598 *title = strdup(str.c_str());
599 if (*title == nullptr) {
600 LOGE("Out-of-memory");
601 return NOTI_EX_ERROR_OUT_OF_MEMORY;
604 return NOTI_EX_ERROR_NONE;
607 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
608 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
609 if (handle == nullptr) {
610 LOGE("Invalid parameter");
611 return NOTI_EX_ERROR_INVALID_PARAMETER;
614 Handle* p = static_cast<Handle*>(handle);
615 if (!p->IsValidType(AbstractItem::CheckBox)) {
616 LOGE("Invalid handle type");
617 return NOTI_EX_ERROR_INVALID_PARAMETER;
620 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
621 if (multi == nullptr) {
622 ci->SetMultiLanguage(nullptr);
623 return NOTI_EX_ERROR_NONE;
626 shared_ptr<MultiLanguage> mul_ptr =
627 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
628 mul_ptr->UpdateString();
629 ci->SetMultiLanguage(mul_ptr);
631 return NOTI_EX_ERROR_NONE;
634 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
635 noti_ex_item_h handle, bool *checked) {
636 if (handle == nullptr || checked == nullptr) {
637 LOGE("Invalid parameter");
638 return NOTI_EX_ERROR_INVALID_PARAMETER;
640 Handle* h = static_cast<Handle*>(handle);
641 if (!h->IsValidType(AbstractItem::CheckBox)) {
642 LOGE("Invalid handle type");
643 return NOTI_EX_ERROR_INVALID_PARAMETER;
645 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
646 *checked = p->IsChecked();
648 return NOTI_EX_ERROR_NONE;
651 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
652 noti_ex_item_h handle, bool checked) {
653 if (handle == nullptr) {
654 LOGE("Invalid parameter");
655 return NOTI_EX_ERROR_INVALID_PARAMETER;
658 Handle* h = static_cast<Handle*>(handle);
659 if (!h->IsValidType(AbstractItem::CheckBox)) {
660 LOGE("Invalid handle type");
661 return NOTI_EX_ERROR_INVALID_PARAMETER;
664 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
665 p->SetChecked(checked);
667 return NOTI_EX_ERROR_NONE;
670 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
674 if (handle == nullptr) {
675 LOGE("Invalid parameter");
676 return NOTI_EX_ERROR_INVALID_PARAMETER;
679 p = new (std::nothrow) EntryItem(id);
681 LOGE("Out-of-memory");
682 return NOTI_EX_ERROR_OUT_OF_MEMORY;
685 *handle = new Handle(shared_ptr<AbstractItem>(p));
687 return NOTI_EX_ERROR_NONE;
690 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
692 if (handle == nullptr || text == nullptr) {
693 LOGE("Invalid parameter");
694 return NOTI_EX_ERROR_INVALID_PARAMETER;
697 Handle* h = static_cast<Handle*>(handle);
698 if (!h->IsValidType(AbstractItem::Entry)) {
699 LOGE("Invalid handle type");
700 return NOTI_EX_ERROR_INVALID_PARAMETER;
703 EntryItem* p = static_cast<EntryItem*>(h->Get());
705 if (p->GetMultiLanguage() != nullptr &&
706 !p->GetMultiLanguage()->GetTranslatedString().empty())
707 str = p->GetMultiLanguage()->GetTranslatedString();
708 else if (!p->GetText().empty())
711 *text = strdup(str.c_str());
712 if (*text == nullptr) {
713 LOGE("Out-of-memory");
714 return NOTI_EX_ERROR_OUT_OF_MEMORY;
717 return NOTI_EX_ERROR_NONE;
720 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
722 if (handle == nullptr || text == nullptr) {
723 LOGE("Invalid parameter");
724 return NOTI_EX_ERROR_INVALID_PARAMETER;
726 Handle* h = static_cast<Handle*>(handle);
727 if (!h->IsValidType(AbstractItem::Entry)) {
728 LOGE("Invalid handle type");
729 return NOTI_EX_ERROR_INVALID_PARAMETER;
731 EntryItem* p = static_cast<EntryItem*>(h->Get());
732 p->SetText(std::string(text));
734 return NOTI_EX_ERROR_NONE;
737 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
738 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
739 if (handle == nullptr) {
740 LOGE("Invalid parameter");
741 return NOTI_EX_ERROR_INVALID_PARAMETER;
744 Handle* p = static_cast<Handle*>(handle);
745 if (!p->IsValidType(AbstractItem::Entry)) {
746 LOGE("Invalid handle type");
747 return NOTI_EX_ERROR_INVALID_PARAMETER;
750 EntryItem* ei = static_cast<EntryItem*>(p->Get());
751 if (multi == nullptr) {
752 ei->SetMultiLanguage(nullptr);
753 return NOTI_EX_ERROR_NONE;
756 shared_ptr<MultiLanguage> mul_ptr =
757 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
758 ei->SetMultiLanguage(mul_ptr);
759 ei->GetMultiLanguage()->UpdateString();
761 return NOTI_EX_ERROR_NONE;
764 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
765 noti_ex_event_info_h* cloned_handle) {
766 if (handle == nullptr || cloned_handle == nullptr) {
767 LOGE("Invalid parameter");
768 return NOTI_EX_ERROR_INVALID_PARAMETER;
771 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
772 EventInfo* info = new EventInfo(cloned);
773 *cloned_handle = info;
774 return NOTI_EX_ERROR_NONE;
777 extern "C" EXPORT_API int noti_ex_event_info_destroy(
778 noti_ex_event_info_h handle) {
779 if (handle == nullptr) {
780 LOGE("Invalid parameter");
781 return NOTI_EX_ERROR_INVALID_PARAMETER;
783 EventInfo* info = static_cast<EventInfo*>(handle);
785 return NOTI_EX_ERROR_NONE;
788 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
789 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
790 if (handle == nullptr || event_type == nullptr) {
791 LOGE("Invalid parameter");
792 return NOTI_EX_ERROR_INVALID_PARAMETER;
794 EventInfo* info = static_cast<EventInfo*>(handle);
795 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
797 return NOTI_EX_ERROR_NONE;
800 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
801 noti_ex_event_info_h handle, char **owner) {
802 if (handle == nullptr || owner == nullptr) {
803 LOGE("Invalid parameter");
804 return NOTI_EX_ERROR_INVALID_PARAMETER;
806 EventInfo* info = static_cast<EventInfo*>(handle);
807 *owner = strdup(info->GetOwner().c_str());
808 return NOTI_EX_ERROR_NONE;
811 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
812 noti_ex_event_info_h handle, char **channel) {
813 if (handle == nullptr || channel == nullptr) {
814 LOGE("Invalid parameter");
815 return NOTI_EX_ERROR_INVALID_PARAMETER;
817 EventInfo* info = static_cast<EventInfo*>(handle);
818 *channel = strdup(info->GetChannel().c_str());
819 return NOTI_EX_ERROR_NONE;
822 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
823 noti_ex_event_info_h handle, char **item_id) {
824 if (handle == nullptr || item_id == nullptr) {
825 LOGE("Invalid parameter");
826 return NOTI_EX_ERROR_INVALID_PARAMETER;
828 EventInfo* info = static_cast<EventInfo*>(handle);
829 *item_id = strdup(info->GetItemId().c_str());
830 return NOTI_EX_ERROR_NONE;
833 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
834 noti_ex_event_info_h handle, int *req_id) {
835 if (handle == nullptr || req_id == nullptr) {
836 LOGE("Invalid parameter");
837 return NOTI_EX_ERROR_INVALID_PARAMETER;
839 EventInfo* info = static_cast<EventInfo*>(handle);
840 *req_id = info->GetRequestId();
841 return NOTI_EX_ERROR_NONE;
844 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
848 if (handle == nullptr) {
849 LOGE("Invalid parameter");
850 return NOTI_EX_ERROR_INVALID_PARAMETER;
854 p = new (std::nothrow) GroupItem(id);
856 p = new (std::nothrow) GroupItem();
859 LOGE("Out-of-memory");
860 return NOTI_EX_ERROR_OUT_OF_MEMORY;
863 *handle = new Handle(shared_ptr<AbstractItem>(p));
865 return NOTI_EX_ERROR_NONE;
868 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
870 if (handle == nullptr) {
871 LOGE("Invalid parameter");
872 return NOTI_EX_ERROR_INVALID_PARAMETER;
874 Handle* h = static_cast<Handle*>(handle);
875 if (!h->IsValidType(AbstractItem::Group)) {
876 LOGE("Invalid handle type");
877 return NOTI_EX_ERROR_INVALID_PARAMETER;
879 GroupItem* p = static_cast<GroupItem*>(h->Get());
880 p->SetDirection(vertical);
882 return NOTI_EX_ERROR_NONE;
885 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
887 if (handle == nullptr) {
888 LOGE("Invalid parameter");
889 return NOTI_EX_ERROR_INVALID_PARAMETER;
891 Handle* h = static_cast<Handle*>(handle);
892 if (!h->IsValidType(AbstractItem::Group)) {
893 LOGE("Invalid handle type");
894 return NOTI_EX_ERROR_INVALID_PARAMETER;
896 GroupItem* p = static_cast<GroupItem*>(h->Get());
897 *vertical = p->IsVertical();
899 return NOTI_EX_ERROR_NONE;
902 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
904 if (handle == nullptr) {
905 LOGE("Invalid parameter");
906 return NOTI_EX_ERROR_INVALID_PARAMETER;
908 Handle* h = static_cast<Handle*>(handle);
909 if (!h->IsValidType(AbstractItem::Group)) {
910 LOGE("Invalid handle type");
911 return NOTI_EX_ERROR_INVALID_PARAMETER;
913 GroupItem* p = static_cast<GroupItem*>(h->Get());
914 if (!p->GetAppLabel().empty()) {
915 *label = strdup(p->GetAppLabel().c_str());
916 if (*label == nullptr) {
917 LOGE("Out-of-memory");
918 return NOTI_EX_ERROR_OUT_OF_MEMORY;
922 return NOTI_EX_ERROR_NONE;
925 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
926 noti_ex_item_h child) {
927 if (handle == nullptr || child == nullptr) {
928 LOGE("Invalid parameter");
929 return NOTI_EX_ERROR_INVALID_PARAMETER;
931 Handle* h = static_cast<Handle*>(handle);
932 if (!h->IsValidType(AbstractItem::Group)) {
933 LOGE("Invalid handle type");
934 return NOTI_EX_ERROR_INVALID_PARAMETER;
936 auto p = static_cast<GroupItem*>(h->Get());
937 p->AddChild((static_cast<Handle*>(child))->GetPtr());
939 return NOTI_EX_ERROR_NONE;
942 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
943 const char *item_id) {
944 if (handle == nullptr || item_id == nullptr) {
945 LOGE("Invalid parameter");
946 return NOTI_EX_ERROR_INVALID_PARAMETER;
948 Handle* h = static_cast<Handle*>(handle);
949 if (!h->IsValidType(AbstractItem::Group)) {
950 LOGE("Invalid handle type");
951 return NOTI_EX_ERROR_INVALID_PARAMETER;
953 GroupItem* p = static_cast<GroupItem*>(h->Get());
954 p->RemoveChild(std::string(item_id));
956 return NOTI_EX_ERROR_NONE;
959 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
960 noti_ex_item_group_foreach_child_cb callback, void *data) {
961 if (handle == nullptr || callback == nullptr) {
962 LOGE("Invalid parameter");
963 return NOTI_EX_ERROR_INVALID_PARAMETER;
966 Handle* h = static_cast<Handle*>(handle);
967 if (!h->IsValidType(AbstractItem::Group)) {
968 LOGE("Invalid handle type");
969 return NOTI_EX_ERROR_INVALID_PARAMETER;
971 GroupItem* p = static_cast<GroupItem*>(h->Get());
972 list<shared_ptr<AbstractItem>> children = p->GetChildren();
973 LOGI("Retrive (%zd)", children.size());
974 for (auto i : children) {
976 static_cast<noti_ex_item_h>(new Handle(i)), data);
977 if (ret != NOTI_EX_ERROR_NONE) {
978 LOGW("callback return (%d) stop foreach", ret);
983 return NOTI_EX_ERROR_NONE;
986 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
987 const char *id, const char *image_path) {
990 if (handle == nullptr || image_path == nullptr) {
991 LOGE("Invalid parameter");
992 return NOTI_EX_ERROR_INVALID_PARAMETER;
996 p = new (std::nothrow) ImageItem(id, image_path);
998 p = new (std::nothrow) ImageItem(image_path);
1001 LOGE("Out-of-memory");
1002 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1005 *handle = new Handle(shared_ptr<AbstractItem>(p));
1007 return NOTI_EX_ERROR_NONE;
1010 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1011 noti_ex_item_h handle, char **image_path) {
1012 if (handle == nullptr || image_path == nullptr) {
1013 LOGE("Invalid parameter");
1014 return NOTI_EX_ERROR_INVALID_PARAMETER;
1016 Handle* h = static_cast<Handle*>(handle);
1017 if (!h->IsValidType(AbstractItem::Image)) {
1018 LOGE("Invalid handle type");
1019 return NOTI_EX_ERROR_INVALID_PARAMETER;
1021 ImageItem* p = static_cast<ImageItem*>(h->Get());
1022 if (!p->GetImagePath().empty()) {
1023 *image_path = strdup(p->GetImagePath().c_str());
1024 if (*image_path == nullptr) {
1025 LOGE("Out-of-memory");
1026 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1030 return NOTI_EX_ERROR_NONE;
1033 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1034 noti_ex_item_h *handle, const char *id) {
1035 InputSelectorItem* p;
1037 if (handle == nullptr) {
1038 LOGE("Invalid parameter");
1039 return NOTI_EX_ERROR_INVALID_PARAMETER;
1043 p = new (std::nothrow) InputSelectorItem(id);
1045 p = new (std::nothrow) InputSelectorItem();
1048 LOGE("Out-of-memory");
1049 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1052 *handle = new Handle(shared_ptr<AbstractItem>(p));
1054 return NOTI_EX_ERROR_NONE;
1057 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1058 noti_ex_item_h handle, char ***contents_list, int *count) {
1059 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1060 LOGE("Invalid parameter");
1061 return NOTI_EX_ERROR_INVALID_PARAMETER;
1064 Handle* h = static_cast<Handle*>(handle);
1065 if (!h->IsValidType(AbstractItem::InputSelector)) {
1066 LOGE("Invalid handle type");
1067 return NOTI_EX_ERROR_INVALID_PARAMETER;
1070 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1071 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1072 list<string> contents;
1073 if (arr.size() == 0) {
1074 contents = p->GetContents();
1076 for (auto& i : arr) {
1077 contents.push_back(i->GetTranslatedString());
1081 char **list = (char**)calloc(contents.size(), sizeof(char*));
1082 if (list == nullptr) {
1083 LOGE("Out of memory");
1084 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1088 for (auto& i : contents) {
1089 list[idx] = strdup(i.c_str());
1090 if (list[idx] == nullptr) {
1091 __noti_ex_free_str_array(list, idx);
1092 LOGE("Out of memory");
1093 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1098 *count = contents.size();
1099 *contents_list = list;
1101 return NOTI_EX_ERROR_NONE;
1104 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1105 noti_ex_item_h handle, const char **contents, int count) {
1106 if (handle == nullptr || contents == nullptr) {
1107 LOGE("Invalid parameter");
1108 return NOTI_EX_ERROR_INVALID_PARAMETER;
1111 list<string> new_contents;
1112 Handle* h = static_cast<Handle*>(handle);
1113 if (!h->IsValidType(AbstractItem::InputSelector)) {
1114 LOGE("Invalid handle type");
1115 return NOTI_EX_ERROR_INVALID_PARAMETER;
1117 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1118 for (int i = 0; i < count; i++) {
1119 new_contents.push_back(contents[i]);
1121 p->SetContents(move(new_contents));
1123 return NOTI_EX_ERROR_NONE;
1126 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1127 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1128 if (handle == nullptr) {
1129 LOGE("Invalid parameter");
1130 return NOTI_EX_ERROR_INVALID_PARAMETER;
1133 Handle* p = static_cast<Handle*>(handle);
1134 if (!p->IsValidType(AbstractItem::InputSelector)) {
1135 LOGE("Invalid handle type");
1136 return NOTI_EX_ERROR_INVALID_PARAMETER;
1139 vector<shared_ptr<MultiLanguage>> m_list;
1140 for (int i = 0; i < count; i++) {
1141 shared_ptr<MultiLanguage> mul_ptr =
1142 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1143 mul_ptr->UpdateString();
1144 m_list.push_back(mul_ptr);
1147 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1148 input->SetMultiLanguage(m_list);
1150 return NOTI_EX_ERROR_NONE;
1153 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1154 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1155 if (handle == nullptr) {
1156 LOGE("Invalid parameter");
1157 return NOTI_EX_ERROR_INVALID_PARAMETER;
1160 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1161 new (std::nothrow) Color(a, r, g, b));
1162 if (ptr == nullptr || ptr->get() == nullptr) {
1163 LOGE("Out-of-memory");
1164 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1169 return NOTI_EX_ERROR_NONE;
1172 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1173 if (handle == nullptr) {
1174 LOGE("Invalid parameter");
1175 return NOTI_EX_ERROR_INVALID_PARAMETER;
1178 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1181 return NOTI_EX_ERROR_NONE;
1184 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1185 unsigned char *val) {
1186 if (handle == nullptr || val == nullptr) {
1187 LOGE("Invalid parameter");
1188 return NOTI_EX_ERROR_INVALID_PARAMETER;
1191 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1192 *val = (*p)->GetAVal();
1194 return NOTI_EX_ERROR_NONE;
1197 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1198 unsigned char *val) {
1199 if (handle == nullptr || val == nullptr) {
1200 LOGE("Invalid parameter");
1201 return NOTI_EX_ERROR_INVALID_PARAMETER;
1204 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1205 *val = (*p)->GetRVal();
1207 return NOTI_EX_ERROR_NONE;
1210 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1211 unsigned char *val) {
1212 if (handle == nullptr || val == nullptr) {
1213 LOGE("Invalid parameter");
1214 return NOTI_EX_ERROR_INVALID_PARAMETER;
1217 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1218 *val = (*p)->GetGVal();
1220 return NOTI_EX_ERROR_NONE;
1223 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1224 unsigned char *val) {
1225 if (handle == nullptr || val == nullptr) {
1226 LOGE("Invalid parameter");
1227 return NOTI_EX_ERROR_INVALID_PARAMETER;
1230 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1231 *val = (*p)->GetBVal();
1233 return NOTI_EX_ERROR_NONE;
1236 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1237 int left, int top, int right, int bottom) {
1238 if (handle == nullptr) {
1239 LOGE("Invalid parameter");
1240 return NOTI_EX_ERROR_INVALID_PARAMETER;
1243 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1244 new (std::nothrow) Padding(left, top, right, bottom));
1245 if (ptr == nullptr || ptr->get() == nullptr) {
1246 LOGE("Out-of-memory");
1247 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1252 return NOTI_EX_ERROR_NONE;
1255 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1256 if (handle == nullptr) {
1257 LOGE("Invalid parameter");
1258 return NOTI_EX_ERROR_INVALID_PARAMETER;
1261 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1264 return NOTI_EX_ERROR_NONE;
1267 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1269 if (handle == nullptr || val == nullptr) {
1270 LOGE("Invalid parameter");
1271 return NOTI_EX_ERROR_INVALID_PARAMETER;
1274 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1275 *val = (*p)->GetLeft();
1277 return NOTI_EX_ERROR_NONE;
1280 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1282 if (handle == nullptr || val == nullptr) {
1283 LOGE("Invalid parameter");
1284 return NOTI_EX_ERROR_INVALID_PARAMETER;
1287 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1288 *val = (*p)->GetTop();
1290 return NOTI_EX_ERROR_NONE;
1293 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1295 if (handle == nullptr || val == nullptr) {
1296 LOGE("Invalid parameter");
1297 return NOTI_EX_ERROR_INVALID_PARAMETER;
1300 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1301 *val = (*p)->GetRight();
1303 return NOTI_EX_ERROR_NONE;
1306 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1308 if (handle == nullptr || val == nullptr) {
1309 LOGE("Invalid parameter");
1310 return NOTI_EX_ERROR_INVALID_PARAMETER;
1313 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1314 *val = (*p)->GetBottom();
1316 return NOTI_EX_ERROR_NONE;
1319 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1320 int x, int y, int w, int h) {
1321 if (handle == nullptr) {
1322 LOGE("Invalid parameter");
1323 return NOTI_EX_ERROR_INVALID_PARAMETER;
1326 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1327 new (std::nothrow) Geometry(x, y, w, h));
1328 if (ptr == nullptr || ptr->get() == nullptr) {
1329 LOGE("Out-of-memory");
1330 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1335 return NOTI_EX_ERROR_NONE;
1338 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1339 if (handle == nullptr) {
1340 LOGE("Invalid parameter");
1341 return NOTI_EX_ERROR_INVALID_PARAMETER;
1344 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1347 return NOTI_EX_ERROR_NONE;
1350 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1352 if (handle == nullptr || val == nullptr) {
1353 LOGE("Invalid parameter");
1354 return NOTI_EX_ERROR_INVALID_PARAMETER;
1357 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1358 *val = (*p)->GetX();
1360 return NOTI_EX_ERROR_NONE;
1363 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1365 if (handle == nullptr || val == nullptr) {
1366 LOGE("Invalid parameter");
1367 return NOTI_EX_ERROR_INVALID_PARAMETER;
1370 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1371 *val = (*p)->GetY();
1373 return NOTI_EX_ERROR_NONE;
1376 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1378 if (handle == nullptr || val == nullptr) {
1379 LOGE("Invalid parameter");
1380 return NOTI_EX_ERROR_INVALID_PARAMETER;
1383 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1384 *val = (*p)->GetWidth();
1386 return NOTI_EX_ERROR_NONE;
1389 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1391 if (handle == nullptr || val == nullptr) {
1392 LOGE("Invalid parameter");
1393 return NOTI_EX_ERROR_INVALID_PARAMETER;
1396 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1397 *val = (*p)->GetHeight();
1399 return NOTI_EX_ERROR_NONE;
1402 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1403 noti_ex_color_h color,
1404 noti_ex_padding_h padding,
1405 noti_ex_geometry_h geometry) {
1406 if (handle == nullptr) {
1407 LOGE("Invalid parameter");
1408 return NOTI_EX_ERROR_INVALID_PARAMETER;
1411 shared_ptr<Color> col = (color == nullptr) ?
1412 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1413 shared_ptr<Padding> padd = (padding == nullptr) ?
1414 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1415 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1416 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1418 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1419 new (std::nothrow) Style(col, padd, geo));
1420 if (ptr == nullptr || ptr->get() == nullptr) {
1421 LOGE("Out-of-memory");
1422 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1427 return NOTI_EX_ERROR_NONE;
1430 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1431 if (handle == nullptr) {
1432 LOGE("Invalid parameter");
1433 return NOTI_EX_ERROR_INVALID_PARAMETER;
1436 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1439 return NOTI_EX_ERROR_NONE;
1442 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1443 noti_ex_padding_h *padding) {
1444 if (handle == nullptr || padding == nullptr) {
1445 LOGE("Invalid parameter");
1446 return NOTI_EX_ERROR_INVALID_PARAMETER;
1449 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1450 if ((*p)->GetPadding() == nullptr) {
1451 LOGW("Padding info is null");
1452 return NOTI_EX_ERROR_INVALID_PARAMETER;
1455 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1456 new (std::nothrow) Padding(*((*p)->GetPadding())));
1457 if (padd == nullptr || padd->get() == nullptr) {
1458 LOGE("Out-of-memory");
1459 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1464 return NOTI_EX_ERROR_NONE;
1467 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1468 noti_ex_color_h *color) {
1469 if (handle == nullptr || color == nullptr) {
1470 LOGE("Invalid parameter");
1471 return NOTI_EX_ERROR_INVALID_PARAMETER;
1474 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1475 if ((*p)->GetColor() == nullptr) {
1476 LOGW("Color info is null");
1477 return NOTI_EX_ERROR_INVALID_PARAMETER;
1480 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1481 new (std::nothrow) Color(*((*p)->GetColor())));
1482 if (col == nullptr || col->get() == nullptr) {
1483 LOGE("Out-of-memory");
1484 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1489 return NOTI_EX_ERROR_NONE;
1492 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1493 noti_ex_geometry_h *geometry) {
1494 if (handle == nullptr || geometry == nullptr) {
1495 LOGE("Invalid parameter");
1496 return NOTI_EX_ERROR_INVALID_PARAMETER;
1499 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1500 if ((*p)->GetGeometry() == nullptr) {
1501 LOGW("Geometry info is null");
1502 return NOTI_EX_ERROR_INVALID_PARAMETER;
1505 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1506 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1507 if (geo == nullptr || geo->get() == nullptr) {
1508 LOGE("Out-of-memory");
1509 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1514 return NOTI_EX_ERROR_NONE;
1517 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1518 noti_ex_style_h handle, char** background_image) {
1519 if (handle == nullptr || background_image == nullptr) {
1520 LOGE("Invalid parameter");
1521 return NOTI_EX_ERROR_INVALID_PARAMETER;
1524 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1525 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1527 return NOTI_EX_ERROR_NONE;
1530 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1531 noti_ex_style_h handle, char* background_image) {
1532 if (handle == nullptr || background_image == nullptr) {
1533 LOGE("Invalid parameter");
1534 return NOTI_EX_ERROR_INVALID_PARAMETER;
1537 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1538 (*p)->SetBackgroundImage(background_image);
1540 return NOTI_EX_ERROR_NONE;
1543 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1544 noti_ex_style_h handle, noti_ex_color_h* color) {
1545 if (handle == nullptr || color == 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)->GetBackgroundColor() == nullptr) {
1552 LOGW("Color info is null");
1553 return NOTI_EX_ERROR_INVALID_PARAMETER;
1556 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1557 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1558 if (col == nullptr || col->get() == nullptr) {
1559 LOGE("Out-of-memory");
1560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1565 return NOTI_EX_ERROR_NONE;
1568 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1569 noti_ex_style_h handle, noti_ex_color_h color) {
1570 if (handle == nullptr || color == nullptr) {
1571 LOGE("Invalid parameter");
1572 return NOTI_EX_ERROR_INVALID_PARAMETER;
1575 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1576 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1577 (*p)->SetBackgroundColor(*col);
1579 return NOTI_EX_ERROR_NONE;
1582 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1583 noti_ex_color_h color) {
1584 if (handle == nullptr) {
1585 LOGE("Invalid parameter");
1586 return NOTI_EX_ERROR_INVALID_PARAMETER;
1589 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1590 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1591 new (std::nothrow) LEDInfo(*color_ptr));
1593 LOGE("Out-of-memory");
1594 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1599 return NOTI_EX_ERROR_NONE;
1602 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1603 if (handle == nullptr) {
1604 LOGE("Invalid parameter");
1605 return NOTI_EX_ERROR_INVALID_PARAMETER;
1608 shared_ptr<LEDInfo>* led_ptr =
1609 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1611 return NOTI_EX_ERROR_NONE;
1614 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1615 noti_ex_led_info_h handle, int ms) {
1616 if (handle == nullptr) {
1617 LOGE("Invalid parameter");
1618 return NOTI_EX_ERROR_INVALID_PARAMETER;
1621 shared_ptr<LEDInfo>* led_ptr =
1622 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1623 (*led_ptr)->SetOnPeriod(ms);
1625 return NOTI_EX_ERROR_NONE;
1628 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1629 noti_ex_led_info_h handle, int *ms) {
1630 if (handle == nullptr || ms == nullptr) {
1631 LOGE("Invalid parameter");
1632 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 shared_ptr<LEDInfo>* led_ptr =
1636 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1637 *ms = (*led_ptr)->GetOnPeriod();
1639 return NOTI_EX_ERROR_NONE;
1642 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1643 noti_ex_led_info_h handle, int ms) {
1644 if (handle == nullptr) {
1645 LOGE("Invalid parameter");
1646 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 shared_ptr<LEDInfo>* led_ptr =
1650 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1651 (*led_ptr)->SetOffPeriod(ms);
1653 return NOTI_EX_ERROR_NONE;
1656 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1657 noti_ex_led_info_h handle, int *ms) {
1658 if (handle == nullptr) {
1659 LOGE("Invalid parameter");
1660 return NOTI_EX_ERROR_INVALID_PARAMETER;
1663 shared_ptr<LEDInfo>* led_ptr =
1664 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1665 *ms = (*led_ptr)->GetOffPeriod();
1667 return NOTI_EX_ERROR_NONE;
1670 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1671 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1672 if (handle == nullptr) {
1673 LOGE("Invalid parameter");
1674 return NOTI_EX_ERROR_INVALID_PARAMETER;
1677 shared_ptr<LEDInfo>* led_ptr =
1678 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1679 if ((*led_ptr)->GetColor() == nullptr) {
1680 LOGE("Color is null");
1681 return NOTI_EX_ERROR_INVALID_PARAMETER;
1684 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1685 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1686 if (col == nullptr || col->get() == nullptr) {
1687 LOGE("Out-of-memory");
1688 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1693 return NOTI_EX_ERROR_NONE;
1696 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1697 if (handle == nullptr) {
1698 LOGE("Invalid parameter");
1699 return NOTI_EX_ERROR_INVALID_PARAMETER;
1702 shared_ptr<AbstractAction>* ptr =
1703 static_cast<shared_ptr<AbstractAction>*>(handle);
1706 return NOTI_EX_ERROR_NONE;
1709 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1711 if (handle == nullptr || type == nullptr) {
1712 LOGE("Invalid parameter");
1713 return NOTI_EX_ERROR_INVALID_PARAMETER;
1716 shared_ptr<AbstractAction>* ptr =
1717 static_cast<shared_ptr<AbstractAction>*>(handle);
1718 *type = (*ptr)->GetType();
1720 return NOTI_EX_ERROR_NONE;
1723 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1725 if (handle == nullptr || local == nullptr) {
1726 LOGE("Invalid parameter");
1727 return NOTI_EX_ERROR_INVALID_PARAMETER;
1730 shared_ptr<AbstractAction>* ptr =
1731 static_cast<shared_ptr<AbstractAction>*>(handle);
1732 *local = (*ptr)->IsLocal();
1734 return NOTI_EX_ERROR_NONE;
1737 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1738 noti_ex_item_h item) {
1739 if (handle == nullptr || item == nullptr) {
1740 LOGE("Invalid parameter");
1741 return NOTI_EX_ERROR_INVALID_PARAMETER;
1743 shared_ptr<AbstractAction>* ptr =
1744 static_cast<shared_ptr<AbstractAction>*>(handle);
1745 Handle* ih = static_cast<Handle*>(item);
1746 (*ptr)->Execute(ih->GetPtr());
1748 return NOTI_EX_ERROR_NONE;
1751 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1753 if (handle == nullptr || extra == nullptr) {
1754 LOGE("Invalid parameter");
1755 return NOTI_EX_ERROR_INVALID_PARAMETER;
1758 shared_ptr<AbstractAction>* ptr =
1759 static_cast<shared_ptr<AbstractAction>*>(handle);
1760 if (!(*ptr)->GetExtra().empty()) {
1761 *extra = strdup((*ptr)->GetExtra().c_str());
1762 if (*extra == nullptr) {
1763 LOGE("Out-of-memory");
1764 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1768 return NOTI_EX_ERROR_NONE;
1771 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1772 noti_ex_item_info_h handle, int *hide_time) {
1773 if (handle == nullptr || hide_time == nullptr) {
1774 LOGE("Invalid parameter");
1775 return NOTI_EX_ERROR_INVALID_PARAMETER;
1777 IItemInfo* p = static_cast<IItemInfo*>(handle);
1778 *hide_time = p->GetHideTime();
1779 return NOTI_EX_ERROR_NONE;
1782 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1783 noti_ex_item_info_h handle, int hide_time) {
1784 if (handle == nullptr) {
1785 LOGE("Invalid parameter");
1786 return NOTI_EX_ERROR_INVALID_PARAMETER;
1788 IItemInfo* p = static_cast<IItemInfo*>(handle);
1789 p->SetHideTime(hide_time);
1790 return NOTI_EX_ERROR_NONE;
1793 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1794 noti_ex_item_info_h handle, int *delete_time) {
1795 if (handle == nullptr || delete_time == nullptr) {
1796 LOGE("Invalid parameter");
1797 return NOTI_EX_ERROR_INVALID_PARAMETER;
1799 IItemInfo* p = static_cast<IItemInfo*>(handle);
1800 *delete_time = p->GetDeleteTime();
1801 return NOTI_EX_ERROR_NONE;
1804 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1805 noti_ex_item_info_h handle, int delete_time) {
1806 if (handle == nullptr) {
1807 LOGE("Invalid parameter");
1808 return NOTI_EX_ERROR_INVALID_PARAMETER;
1810 IItemInfo* p = static_cast<IItemInfo*>(handle);
1811 p->SetDeleteTime(delete_time);
1812 return NOTI_EX_ERROR_NONE;
1815 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1816 noti_ex_item_info_h handle, time_t *time) {
1817 if (handle == nullptr || time == nullptr) {
1818 LOGE("Invalid parameter");
1819 return NOTI_EX_ERROR_INVALID_PARAMETER;
1822 IItemInfo* p = static_cast<IItemInfo*>(handle);
1823 *time = p->GetTime();
1824 return NOTI_EX_ERROR_NONE;
1827 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1828 if (handle == nullptr) {
1829 LOGE("Invalid parameter");
1830 return NOTI_EX_ERROR_INVALID_PARAMETER;
1833 Handle* h = static_cast<Handle*>(handle);
1835 return NOTI_EX_ERROR_NONE;
1838 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1839 const char *id, noti_ex_item_h *item) {
1840 if (handle == nullptr) {
1841 LOGE("Invalid parameter");
1842 return NOTI_EX_ERROR_INVALID_PARAMETER;
1845 Handle* p = static_cast<Handle*>(handle);
1846 AbstractItem& find_item = p->Get()->FindByID(string(id));
1847 *item = new Handle(&find_item);
1848 return NOTI_EX_ERROR_NONE;
1851 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1853 if (handle == nullptr || type == nullptr) {
1854 LOGE("Invalid parameter");
1855 return NOTI_EX_ERROR_INVALID_PARAMETER;
1858 Handle* h = static_cast<Handle*>(handle);
1859 AbstractItem* p = h->Get();
1860 *type = p->GetType();
1861 return NOTI_EX_ERROR_NONE;
1864 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1865 char ***path, int *count) {
1866 if (handle == nullptr || path == nullptr || count == nullptr) {
1867 LOGE("Invalid parameter");
1868 return NOTI_EX_ERROR_INVALID_PARAMETER;
1870 Handle* p = static_cast<Handle*>(handle);
1871 list<string> shared_path = p->Get()->GetSharedPath();
1872 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1873 if (tmp_path == nullptr) {
1874 LOGE("Fail to create items");
1875 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1879 for (auto& i : shared_path) {
1880 tmp_path[idx] = strdup(i.c_str());
1881 if (tmp_path[idx] == nullptr) {
1882 __noti_ex_free_str_array(tmp_path, idx);
1883 LOGE("Out of memory");
1884 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1890 *count = shared_path.size();
1891 return NOTI_EX_ERROR_NONE;
1894 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1896 if (handle == nullptr || id == nullptr) {
1897 LOGE("Invalid parameter");
1898 return NOTI_EX_ERROR_INVALID_PARAMETER;
1900 Handle* h = static_cast<Handle*>(handle);
1901 AbstractItem* p = h->Get();
1902 *id = strdup(p->GetId().c_str());
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1908 if (handle == nullptr || id == nullptr) {
1909 LOGE("Invalid parameter");
1910 return NOTI_EX_ERROR_INVALID_PARAMETER;
1912 Handle* p = static_cast<Handle*>(handle);
1913 p->Get()->SetId(id);
1914 return NOTI_EX_ERROR_NONE;
1917 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1918 noti_ex_action_h *action) {
1919 if (handle == nullptr || action == nullptr) {
1920 LOGE("Invalid parameter");
1921 return NOTI_EX_ERROR_INVALID_PARAMETER;
1923 Handle* p = static_cast<Handle*>(handle);
1924 if (p->Get()->GetAction() == nullptr) {
1926 return NOTI_EX_ERROR_NONE;
1928 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1929 p->Get()->GetAction()));
1931 return NOTI_EX_ERROR_NONE;
1934 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1935 noti_ex_action_h action) {
1936 if (handle == nullptr || action == nullptr) {
1937 LOGE("Invalid parameter");
1938 return NOTI_EX_ERROR_INVALID_PARAMETER;
1941 Handle* p = static_cast<Handle*>(handle);
1943 shared_ptr<AbstractAction>* ptr =
1944 static_cast<shared_ptr<AbstractAction>*>(action);
1945 p->Get()->SetAction(*ptr);
1946 return NOTI_EX_ERROR_NONE;
1949 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1950 noti_ex_style_h *style) {
1951 if (handle == nullptr || style == nullptr) {
1952 LOGE("Invalid parameter");
1953 return NOTI_EX_ERROR_INVALID_PARAMETER;
1956 Handle* p = static_cast<Handle*>(handle);
1957 shared_ptr<Style> s = p->Get()->GetStyle();
1958 if (s.get() == nullptr) {
1959 LOGE("Style is null");
1960 return NOTI_EX_ERROR_INVALID_PARAMETER;
1963 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1964 if (ptr == nullptr || ptr->get() == nullptr) {
1965 LOGE("Out of memory");
1966 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1970 return NOTI_EX_ERROR_NONE;
1973 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1974 noti_ex_style_h style) {
1975 if (handle == nullptr || style == nullptr) {
1976 LOGE("Invalid parameter");
1977 return NOTI_EX_ERROR_INVALID_PARAMETER;
1980 Handle* p = static_cast<Handle*>(handle);
1981 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1982 p->Get()->SetStyle(*s);
1983 return NOTI_EX_ERROR_NONE;
1986 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1988 if (handle == nullptr) {
1989 LOGE("Invalid parameter");
1990 return NOTI_EX_ERROR_INVALID_PARAMETER;
1993 Handle* p = static_cast<Handle*>(handle);
1994 p->Get()->SetVisible(visible);
1995 return NOTI_EX_ERROR_NONE;
1998 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2000 if (handle == nullptr || visible == nullptr) {
2001 LOGE("Invalid parameter");
2002 return NOTI_EX_ERROR_INVALID_PARAMETER;
2005 Handle* p = static_cast<Handle*>(handle);
2006 *visible = p->Get()->GetVisible();
2007 return NOTI_EX_ERROR_NONE;
2010 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2012 if (handle == nullptr) {
2013 LOGE("Invalid parameter");
2014 return NOTI_EX_ERROR_INVALID_PARAMETER;
2017 Handle* p = static_cast<Handle*>(handle);
2018 p->Get()->SetEnable(enable);
2019 return NOTI_EX_ERROR_NONE;
2022 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2024 if (handle == nullptr || enable == nullptr) {
2025 LOGE("Invalid parameter");
2026 return NOTI_EX_ERROR_INVALID_PARAMETER;
2029 Handle* p = static_cast<Handle*>(handle);
2030 *enable = p->Get()->GetEnable();
2031 return NOTI_EX_ERROR_NONE;
2034 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2035 const char *receiver_group) {
2036 if (handle == nullptr || receiver_group == nullptr) {
2037 LOGE("Invalid parameter");
2038 return NOTI_EX_ERROR_INVALID_PARAMETER;
2041 Handle* p = static_cast<Handle*>(handle);
2042 p->Get()->AddReceiver(receiver_group);
2043 return NOTI_EX_ERROR_NONE;
2046 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2047 const char *receiver_group) {
2048 if (handle == nullptr || receiver_group == nullptr) {
2049 LOGE("Invalid parameter");
2050 return NOTI_EX_ERROR_INVALID_PARAMETER;
2053 Handle* p = static_cast<Handle*>(handle);
2054 p->Get()->RemoveReceiver(receiver_group);
2055 return NOTI_EX_ERROR_NONE;
2058 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2059 char ***receiver_list, int *count) {
2060 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2061 LOGE("Invalid parameter");
2062 return NOTI_EX_ERROR_INVALID_PARAMETER;
2065 Handle* p = static_cast<Handle*>(handle);
2066 list<string> receivers = p->Get()->GetReceiverList();
2067 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2068 if (tmp_list == nullptr) {
2069 LOGE("Out of memory");
2070 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2074 for (auto& i : receivers) {
2075 tmp_list[idx] = strdup(i.c_str());
2076 if (tmp_list[idx] == nullptr) {
2077 __noti_ex_free_str_array(tmp_list, idx);
2078 LOGE("Out of memory");
2079 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2084 *receiver_list = tmp_list;
2085 *count = receivers.size();
2086 return NOTI_EX_ERROR_NONE;
2089 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2091 if (handle == nullptr) {
2092 LOGE("Invalid parameter");
2093 return NOTI_EX_ERROR_INVALID_PARAMETER;
2096 Handle* p = static_cast<Handle*>(handle);
2097 p->Get()->SetPolicy(policy);
2098 return NOTI_EX_ERROR_NONE;
2101 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2103 if (handle == nullptr || policy == nullptr) {
2104 LOGE("Invalid parameter");
2105 return NOTI_EX_ERROR_INVALID_PARAMETER;
2108 Handle* p = static_cast<Handle*>(handle);
2109 *policy = p->Get()->GetPolicy();
2110 return NOTI_EX_ERROR_NONE;
2113 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2115 if (handle == nullptr || channel == nullptr) {
2116 LOGE("Invalid parameter");
2117 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 Handle* p = static_cast<Handle*>(handle);
2121 if (!p->Get()->GetChannel().empty())
2122 *channel = strdup(p->Get()->GetChannel().c_str());
2126 return NOTI_EX_ERROR_NONE;
2129 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2130 const char *channel) {
2131 if (handle == nullptr) {
2132 LOGE("Invalid parameter");
2133 return NOTI_EX_ERROR_INVALID_PARAMETER;
2136 Handle* p = static_cast<Handle*>(handle);
2137 p->Get()->SetChannel(channel);
2138 return NOTI_EX_ERROR_NONE;
2141 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2142 noti_ex_led_info_h led) {
2143 if (handle == nullptr) {
2144 LOGE("Invalid parameter");
2145 return NOTI_EX_ERROR_INVALID_PARAMETER;
2148 Handle* p = static_cast<Handle*>(handle);
2149 shared_ptr<LEDInfo>* led_ptr =
2150 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2151 p->Get()->SetLEDInfo(*led_ptr);
2152 return NOTI_EX_ERROR_NONE;
2155 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2156 noti_ex_led_info_h *led) {
2157 if (handle == nullptr) {
2158 LOGE("Invalid parameter");
2159 return NOTI_EX_ERROR_INVALID_PARAMETER;
2162 Handle* p = static_cast<Handle*>(handle);
2163 if (p->Get()->GetLEDInfo() != nullptr)
2164 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2167 return NOTI_EX_ERROR_NONE;
2170 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2172 if (handle == nullptr) {
2173 LOGE("Invalid parameter");
2174 return NOTI_EX_ERROR_INVALID_PARAMETER;
2177 Handle* p = static_cast<Handle*>(handle);
2178 if (path == nullptr)
2179 p->Get()->SetSoundPath("");
2181 p->Get()->SetSoundPath(path);
2182 return NOTI_EX_ERROR_NONE;
2185 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2187 if (handle == nullptr) {
2188 LOGE("Invalid parameter");
2189 return NOTI_EX_ERROR_INVALID_PARAMETER;
2192 Handle* p = static_cast<Handle*>(handle);
2193 if (path == nullptr)
2194 p->Get()->SetVibrationPath("");
2196 p->Get()->SetVibrationPath(path);
2197 return NOTI_EX_ERROR_NONE;
2200 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2202 if (handle == nullptr || path == nullptr) {
2203 LOGE("Invalid parameter");
2204 return NOTI_EX_ERROR_INVALID_PARAMETER;
2207 Handle* p = static_cast<Handle*>(handle);
2208 if (p->Get()->GetSoundPath().empty())
2211 *path = strdup(p->Get()->GetSoundPath().c_str());
2212 return NOTI_EX_ERROR_NONE;
2215 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2217 if (handle == nullptr || path == nullptr) {
2218 LOGE("Invalid parameter");
2219 return NOTI_EX_ERROR_INVALID_PARAMETER;
2222 Handle* p = static_cast<Handle*>(handle);
2223 if (p->Get()->GetVibrationPath().empty())
2226 *path = strdup(p->Get()->GetVibrationPath().c_str());
2227 return NOTI_EX_ERROR_NONE;
2230 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2231 noti_ex_item_info_h *info) {
2232 if (handle == nullptr || info == nullptr) {
2233 LOGE("Invalid parameter");
2234 return NOTI_EX_ERROR_INVALID_PARAMETER;
2237 Handle* p = static_cast<Handle*>(handle);
2238 if (p->Get()->GetInfo() == nullptr)
2241 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2242 return NOTI_EX_ERROR_NONE;
2245 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2247 if (handle == nullptr || id == nullptr) {
2248 LOGE("Invalid parameter");
2249 return NOTI_EX_ERROR_INVALID_PARAMETER;
2252 Handle* p = static_cast<Handle*>(handle);
2253 if (p->Get()->GetSenderAppId().empty())
2256 *id = strdup(p->Get()->GetSenderAppId().c_str());
2257 return NOTI_EX_ERROR_NONE;
2260 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2262 if (handle == nullptr || tag == nullptr) {
2263 LOGE("Invalid parameter");
2264 return NOTI_EX_ERROR_INVALID_PARAMETER;
2267 Handle* p = static_cast<Handle*>(handle);
2268 if (p->Get()->GetTag().empty())
2271 *tag = strdup(p->Get()->GetTag().c_str());
2272 return NOTI_EX_ERROR_NONE;
2275 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2277 if (handle == nullptr) {
2278 LOGE("Invalid parameter");
2279 return NOTI_EX_ERROR_INVALID_PARAMETER;
2282 Handle* p = static_cast<Handle*>(handle);
2284 p->Get()->SetTag("");
2286 p->Get()->SetTag(tag);
2287 return NOTI_EX_ERROR_NONE;
2290 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2292 if (handle == nullptr || ongoing == nullptr) {
2293 LOGE("Invalid parameter");
2294 return NOTI_EX_ERROR_INVALID_PARAMETER;
2297 Handle* p = static_cast<Handle*>(handle);
2298 *ongoing = p->Get()->GetOnGoingState();
2300 return NOTI_EX_ERROR_NONE;
2303 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2305 if (handle == nullptr) {
2306 LOGE("Invalid parameter");
2307 return NOTI_EX_ERROR_INVALID_PARAMETER;
2310 Handle* p = static_cast<Handle*>(handle);
2311 p->Get()->SetOnGoingState(ongoing);
2313 return NOTI_EX_ERROR_NONE;
2316 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2317 int type, bool* exist) {
2318 if (handle == nullptr || exist == nullptr) {
2319 LOGE("Invalid parameter");
2320 return NOTI_EX_ERROR_INVALID_PARAMETER;
2323 Handle* p = static_cast<Handle*>(handle);
2324 *exist = p->Get()->IsItemTypeExist(type);
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2331 if (handle == nullptr || type == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 Handle* p = static_cast<Handle*>(handle);
2337 *type = p->Get()->GetMainType();
2339 return NOTI_EX_ERROR_NONE;
2342 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2343 const char* id, int type) {
2344 if (handle == nullptr || id == nullptr) {
2345 LOGE("Invalid parameter");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2349 Handle* p = static_cast<Handle*>(handle);
2350 if (!(p->Get()->SetMainType(string(id),
2351 static_cast<AbstractItem::MainType>(type))))
2352 return NOTI_EX_ERROR_INVALID_PARAMETER;
2354 return NOTI_EX_ERROR_NONE;
2357 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2358 int type, noti_ex_item_h* item) {
2359 if (handle == nullptr || item == nullptr) {
2360 LOGE("Invalid parameter");
2361 return NOTI_EX_ERROR_INVALID_PARAMETER;
2364 Handle* h = static_cast<Handle*>(handle);
2365 if (!h->IsValidType(AbstractItem::Group)) {
2366 LOGE("Invalid handle type");
2367 return NOTI_EX_ERROR_INVALID_PARAMETER;
2370 GroupItem* p = static_cast<GroupItem*>(h->Get());
2371 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2372 *item = new Handle(&find_item);
2374 return NOTI_EX_ERROR_NONE;
2377 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2378 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2380 if (handle == nullptr) {
2381 LOGE("Invalid parameter");
2382 return NOTI_EX_ERROR_INVALID_PARAMETER;
2385 string receiver_group_str = "";
2387 receiver_group_str = string(receiver_group);
2389 ManagerStub* stub = new (std::nothrow) ManagerStub(
2390 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2391 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2392 receiver_group_str);
2393 if (stub == nullptr) {
2394 LOGE("Fail to create manager");
2395 return NOTI_EX_ERROR_IO_ERROR;
2397 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2398 new ManagerCallbackInfo(event_callbacks, data)));
2399 *handle = static_cast<noti_ex_manager_h>(stub);
2401 return NOTI_EX_ERROR_NONE;
2404 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2405 if (handle == nullptr) {
2406 LOGE("Invalid parameter");
2407 return NOTI_EX_ERROR_INVALID_PARAMETER;
2409 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2411 return NOTI_EX_ERROR_NONE;
2414 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2415 noti_ex_item_h **items, int *count) {
2416 if (handle == nullptr || items == nullptr || count == nullptr) {
2417 LOGE("Invalid parameter");
2418 return NOTI_EX_ERROR_INVALID_PARAMETER;
2422 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2423 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2424 if (item_list.size() == 0) {
2427 return NOTI_EX_ERROR_NONE;
2429 noti_ex_item_h* added_item =
2430 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2431 if (added_item == nullptr) {
2432 LOGE("Fail to create items");
2433 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2437 for (auto& i : item_list) {
2438 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2440 *items = added_item;
2441 *count = item_list.size();
2442 } catch (Exception &ex) {
2443 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2444 return NOTI_EX_ERROR_IO_ERROR;
2446 return NOTI_EX_ERROR_NONE;
2449 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2450 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2451 if (handle == nullptr || channel == nullptr ||
2452 items == nullptr || count == nullptr) {
2453 LOGE("Invalid parameter");
2454 return NOTI_EX_ERROR_INVALID_PARAMETER;
2458 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2459 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2460 if (item_list.size() == 0) {
2463 return NOTI_EX_ERROR_NONE;
2465 noti_ex_item_h* added_item =
2466 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2467 if (added_item == nullptr) {
2468 LOGE("Fail to create items");
2469 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2473 for (auto& i : item_list) {
2474 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2476 *items = added_item;
2477 *count = item_list.size();
2478 } catch (Exception &ex) {
2479 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2480 return NOTI_EX_ERROR_IO_ERROR;
2483 return NOTI_EX_ERROR_NONE;
2486 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2487 noti_ex_item_h noti, int *request_id) {
2488 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2489 LOGE("Invalid parameter");
2490 return NOTI_EX_ERROR_INVALID_PARAMETER;
2493 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2494 Handle* sp = static_cast<Handle*>(noti);
2495 if (sp->GetPtr().get() == nullptr) {
2496 LOGE("Invalid noti reference can not be sended");
2497 return NOTI_EX_ERROR_INVALID_PARAMETER;
2499 *request_id = stub->Update(sp->GetPtr());
2501 } catch (Exception &ex) {
2502 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2503 return NOTI_EX_ERROR_IO_ERROR;
2505 return NOTI_EX_ERROR_NONE;
2508 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2509 noti_ex_item_h noti, int *request_id) {
2510 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2511 LOGE("Invalid parameter");
2512 return NOTI_EX_ERROR_INVALID_PARAMETER;
2515 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2516 Handle* item = static_cast<Handle*>(noti);
2517 if (item->GetPtr().get() == nullptr) {
2518 LOGE("Invalid noti reference can not be sended");
2519 return NOTI_EX_ERROR_INVALID_PARAMETER;
2521 *request_id = stub->Delete(item->GetPtr());
2523 } catch (Exception &ex) {
2524 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2525 return NOTI_EX_ERROR_IO_ERROR;
2527 return NOTI_EX_ERROR_NONE;
2530 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2532 if (handle == nullptr || request_id == nullptr) {
2533 LOGE("Invalid parameter");
2534 return NOTI_EX_ERROR_INVALID_PARAMETER;
2537 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2538 *request_id = stub->DeleteAll();
2539 } catch (Exception &ex) {
2540 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2541 return NOTI_EX_ERROR_IO_ERROR;
2543 return NOTI_EX_ERROR_NONE;
2546 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2547 noti_ex_item_h noti, int *request_id) {
2548 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2549 LOGE("Invalid parameter");
2550 return NOTI_EX_ERROR_INVALID_PARAMETER;
2553 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2554 Handle* item = static_cast<Handle*>(noti);
2555 if (item->GetPtr().get() == nullptr) {
2556 LOGE("Invalid noti reference can not be sended");
2557 return NOTI_EX_ERROR_INVALID_PARAMETER;
2559 *request_id = stub->Hide(item->GetPtr());
2561 } catch (Exception &ex) {
2562 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2563 return NOTI_EX_ERROR_IO_ERROR;
2565 return NOTI_EX_ERROR_NONE;
2568 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2569 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2570 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2571 LOGE("Invalid parameter");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2575 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2576 *item = new Handle(stub->FindByRootID(root_id));
2577 } catch (Exception &ex) {
2578 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2579 return NOTI_EX_ERROR_IO_ERROR;
2581 return NOTI_EX_ERROR_NONE;
2584 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2585 noti_ex_event_info_h info, noti_ex_error_e error) {
2586 if (handle == nullptr || info == nullptr) {
2587 LOGE("Invalid parameter");
2588 return NOTI_EX_ERROR_INVALID_PARAMETER;
2591 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2592 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2593 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2594 static_cast<NotificationError>(error));
2595 } catch (Exception &ex) {
2596 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2597 return NOTI_EX_ERROR_IO_ERROR;
2599 return NOTI_EX_ERROR_NONE;
2602 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2603 noti_ex_manager_h handle, int *cnt) {
2605 if (handle == nullptr || cnt == nullptr) {
2606 LOGE("Invalid parameter");
2607 return NOTI_EX_ERROR_INVALID_PARAMETER;
2610 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2611 *cnt = stub->GetCount();
2612 } catch (Exception &ex) {
2613 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2614 return NOTI_EX_ERROR_IO_ERROR;
2616 return NOTI_EX_ERROR_NONE;
2619 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2620 const char *id, float min, float current, float max) {
2623 if (handle == nullptr) {
2624 LOGE("Invalid parameter");
2625 return NOTI_EX_ERROR_INVALID_PARAMETER;
2629 p = new (std::nothrow) ProgressItem(id, min, current, max);
2631 p = new (std::nothrow) ProgressItem(min, current, max);
2634 LOGE("Out-of-memory");
2635 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2638 *handle = new Handle(shared_ptr<AbstractItem>(p));
2640 return NOTI_EX_ERROR_NONE;
2643 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2644 noti_ex_item_h handle, float *current) {
2645 if (handle == nullptr || current == nullptr) {
2646 LOGE("Invalid parameter");
2647 return NOTI_EX_ERROR_INVALID_PARAMETER;
2650 Handle *h = static_cast<Handle*>(handle);
2651 if (!h->IsValidType(AbstractItem::Progress)) {
2652 LOGE("Invalid handle type");
2653 return NOTI_EX_ERROR_INVALID_PARAMETER;
2655 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2656 *current = p->GetCurrent();
2658 return NOTI_EX_ERROR_NONE;
2661 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2662 noti_ex_item_h handle, float current) {
2663 if (handle == nullptr) {
2664 LOGE("Invalid parameter");
2665 return NOTI_EX_ERROR_INVALID_PARAMETER;
2668 Handle *h = static_cast<Handle*>(handle);
2669 if (!h->IsValidType(AbstractItem::Progress)) {
2670 LOGE("Invalid handle type");
2671 return NOTI_EX_ERROR_INVALID_PARAMETER;
2673 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2674 p->SetCurrent(current);
2676 return NOTI_EX_ERROR_NONE;
2679 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2681 if (handle == nullptr || min == nullptr) {
2682 LOGE("Invalid parameter");
2683 return NOTI_EX_ERROR_INVALID_PARAMETER;
2686 Handle *h = static_cast<Handle*>(handle);
2687 if (!h->IsValidType(AbstractItem::Progress)) {
2688 LOGE("Invalid handle type");
2689 return NOTI_EX_ERROR_INVALID_PARAMETER;
2691 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2694 return NOTI_EX_ERROR_NONE;
2697 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2699 if (handle == nullptr || max == nullptr) {
2700 LOGE("Invalid parameter");
2701 return NOTI_EX_ERROR_INVALID_PARAMETER;
2704 Handle *h = static_cast<Handle*>(handle);
2705 if (!h->IsValidType(AbstractItem::Progress)) {
2706 LOGE("Invalid handle type");
2707 return NOTI_EX_ERROR_INVALID_PARAMETER;
2709 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2712 return NOTI_EX_ERROR_NONE;
2715 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2717 if (handle == nullptr || type == nullptr) {
2718 LOGE("Invalid parameter");
2719 return NOTI_EX_ERROR_INVALID_PARAMETER;
2722 Handle *h = static_cast<Handle*>(handle);
2723 if (!h->IsValidType(AbstractItem::Progress)) {
2724 LOGE("Invalid handle type");
2725 return NOTI_EX_ERROR_INVALID_PARAMETER;
2727 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2728 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2730 return NOTI_EX_ERROR_NONE;
2733 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2735 if (handle == nullptr) {
2736 LOGE("Invalid parameter");
2737 return NOTI_EX_ERROR_INVALID_PARAMETER;
2740 Handle *h = static_cast<Handle*>(handle);
2741 if (!h->IsValidType(AbstractItem::Progress)) {
2742 LOGE("Invalid handle type");
2743 return NOTI_EX_ERROR_INVALID_PARAMETER;
2745 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2746 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2748 return NOTI_EX_ERROR_NONE;
2751 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2752 noti_ex_reporter_events_s event_callbacks, void *data) {
2753 if (handle == nullptr) {
2754 LOGE("Invalid parameter");
2755 return NOTI_EX_ERROR_INVALID_PARAMETER;
2758 ReporterStub* stub = new (std::nothrow) ReporterStub(
2759 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2760 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2761 if (stub == nullptr) {
2762 LOGE("Fail to create manager");
2763 return NOTI_EX_ERROR_IO_ERROR;
2765 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2766 new ReporterCallbackInfo(event_callbacks, data)));
2768 *handle = static_cast<noti_ex_reporter_h>(stub);
2770 return NOTI_EX_ERROR_NONE;
2773 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2774 if (handle == nullptr) {
2775 LOGE("Invalid parameter");
2776 return NOTI_EX_ERROR_INVALID_PARAMETER;
2778 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2780 return NOTI_EX_ERROR_NONE;
2783 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2784 noti_ex_event_info_h info, noti_ex_error_e error) {
2785 if (handle == nullptr || info == nullptr) {
2786 LOGE("Invalid parameter");
2787 return NOTI_EX_ERROR_INVALID_PARAMETER;
2790 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2791 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2792 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2793 static_cast<NotificationError>(error));
2794 } catch (Exception &ex) {
2795 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2796 return NOTI_EX_ERROR_IO_ERROR;
2798 return NOTI_EX_ERROR_NONE;
2801 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2802 noti_ex_item_h noti, int *request_id) {
2803 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2804 LOGE("Invalid parameter");
2805 return NOTI_EX_ERROR_INVALID_PARAMETER;
2808 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2809 Handle* h = static_cast<Handle*>(noti);
2810 if (h->GetPtr().get() == nullptr) {
2811 LOGE("Invalid noti reference can not be sended");
2812 return NOTI_EX_ERROR_INVALID_PARAMETER;
2814 *request_id = stub->Post(h->GetPtr());
2816 } catch (Exception &ex) {
2817 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2818 return NOTI_EX_ERROR_IO_ERROR;
2820 return NOTI_EX_ERROR_NONE;
2823 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2824 noti_ex_item_h *noti_list, int count, int *request_id) {
2826 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2827 LOGE("Invalid parameter");
2828 return NOTI_EX_ERROR_INVALID_PARAMETER;
2831 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2832 list<shared_ptr<item::AbstractItem>> notiList;
2833 for (int i = 0; i < count; i++) {
2834 Handle* item = static_cast<Handle*>(noti_list[i]);
2835 notiList.push_back(item->GetPtr());
2837 *request_id = stub->Post(notiList);
2838 } catch (Exception &ex) {
2839 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2840 return NOTI_EX_ERROR_IO_ERROR;
2842 return NOTI_EX_ERROR_NONE;
2845 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2846 noti_ex_item_h noti, int *request_id) {
2847 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2848 LOGE("Invalid parameter");
2849 return NOTI_EX_ERROR_INVALID_PARAMETER;
2852 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2853 Handle* item = static_cast<Handle*>(noti);
2854 if (item->GetPtr().get() == nullptr) {
2855 LOGE("Invalid noti reference can not be sended");
2856 return NOTI_EX_ERROR_INVALID_PARAMETER;
2858 *request_id = stub->Update(item->GetPtr());
2860 } catch (Exception &ex) {
2861 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2862 return NOTI_EX_ERROR_IO_ERROR;
2864 return NOTI_EX_ERROR_NONE;
2867 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2868 noti_ex_item_h noti, int *request_id) {
2869 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2870 LOGE("Invalid parameter");
2871 return NOTI_EX_ERROR_INVALID_PARAMETER;
2874 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2875 Handle* item = static_cast<Handle*>(noti);
2876 if (item->GetPtr().get() == nullptr) {
2877 LOGE("Invalid noti reference can not be sended");
2878 return NOTI_EX_ERROR_INVALID_PARAMETER;
2880 *request_id = stub->Delete(item->GetPtr());
2882 } catch (Exception &ex) {
2883 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2884 return NOTI_EX_ERROR_IO_ERROR;
2886 return NOTI_EX_ERROR_NONE;
2889 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2890 noti_ex_reporter_h handle, int *request_id) {
2891 if (handle == nullptr || request_id == nullptr) {
2892 LOGE("Invalid parameter");
2893 return NOTI_EX_ERROR_INVALID_PARAMETER;
2896 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2897 *request_id = stub->DeleteAll();
2898 } catch (Exception &ex) {
2899 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2900 return NOTI_EX_ERROR_IO_ERROR;
2902 return NOTI_EX_ERROR_NONE;
2905 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2906 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2907 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2908 LOGE("Invalid parameter");
2909 return NOTI_EX_ERROR_INVALID_PARAMETER;
2912 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2913 *item = new Handle(stub->FindByRootID(root_id));
2914 } catch (Exception &ex) {
2915 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2916 return NOTI_EX_ERROR_IO_ERROR;
2918 return NOTI_EX_ERROR_NONE;
2921 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2922 const char *id, const char *text, const char *hyperlink) {
2923 if (handle == nullptr || text == nullptr) {
2924 LOGE("Invalid parameter");
2925 return NOTI_EX_ERROR_INVALID_PARAMETER;
2931 p = new (std::nothrow) TextItem(id, std::string(text),
2932 std::string(hyperlink));
2934 p = new (std::nothrow) TextItem(id, std::string(text));
2937 LOGE("Out-of-memory");
2938 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2941 *handle = new Handle(shared_ptr<AbstractItem>(p));
2943 return NOTI_EX_ERROR_NONE;
2946 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2947 const char *contents) {
2948 if (handle == nullptr || contents == nullptr) {
2949 LOGE("Invalid parameter");
2950 return NOTI_EX_ERROR_INVALID_PARAMETER;
2953 Handle* p = static_cast<Handle*>(handle);
2954 if (!p->IsValidType(AbstractItem::Text)) {
2955 LOGE("Invalid handle type");
2956 return NOTI_EX_ERROR_INVALID_PARAMETER;
2958 TextItem* ti = static_cast<TextItem*>(p->Get());
2959 ti->SetContents(std::string(contents));
2961 return NOTI_EX_ERROR_NONE;
2964 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2966 if (handle == nullptr || contents == nullptr) {
2967 LOGE("Invalid parameter");
2968 return NOTI_EX_ERROR_INVALID_PARAMETER;
2971 Handle* p = static_cast<Handle*>(handle);
2972 if (!p->IsValidType(AbstractItem::Text)) {
2973 LOGE("Invalid handle type");
2974 return NOTI_EX_ERROR_INVALID_PARAMETER;
2977 TextItem* ti = static_cast<TextItem*>(p->Get());
2979 if (ti->GetMultiLanguage() != nullptr &&
2980 !ti->GetMultiLanguage()->GetTranslatedString().empty())
2981 str = ti->GetMultiLanguage()->GetTranslatedString();
2982 else if (!ti->GetContents().empty())
2983 str = ti->GetContents();
2985 *contents = strdup(str.c_str());
2986 if (*contents == nullptr) {
2987 LOGE("Out-of-memory");
2988 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2991 return NOTI_EX_ERROR_NONE;
2994 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2995 noti_ex_item_h handle, char **hyper_link) {
2996 if (handle == nullptr || hyper_link == nullptr) {
2997 LOGE("Invalid parameter");
2998 return NOTI_EX_ERROR_INVALID_PARAMETER;
3001 Handle* p = static_cast<Handle*>(handle);
3002 if (!p->IsValidType(AbstractItem::Text)) {
3003 LOGE("Invalid handle type");
3004 return NOTI_EX_ERROR_INVALID_PARAMETER;
3006 TextItem* ti = static_cast<TextItem*>(p->Get());
3007 if (!ti->GetHyperLink().empty()) {
3008 *hyper_link = strdup(ti->GetHyperLink().c_str());
3009 if (*hyper_link == nullptr) {
3010 LOGE("Out-of-memory");
3011 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3015 return NOTI_EX_ERROR_NONE;
3018 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3019 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3020 if (handle == nullptr) {
3021 LOGE("Invalid parameter");
3022 return NOTI_EX_ERROR_INVALID_PARAMETER;
3025 Handle* p = static_cast<Handle*>(handle);
3026 if (!p->IsValidType(AbstractItem::Text)) {
3027 LOGE("Invalid handle type");
3028 return NOTI_EX_ERROR_INVALID_PARAMETER;
3031 TextItem* ti = static_cast<TextItem*>(p->Get());
3032 if (multi == nullptr) {
3033 ti->SetMultiLanguage(nullptr);
3034 return NOTI_EX_ERROR_NONE;
3037 shared_ptr<MultiLanguage> mul_ptr =
3038 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3039 ti->SetMultiLanguage(mul_ptr);
3040 ti->GetMultiLanguage()->UpdateString();
3042 return NOTI_EX_ERROR_NONE;
3045 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3046 const char *id, time_t time) {
3049 if (handle == nullptr) {
3050 LOGE("Invalid parameter");
3051 return NOTI_EX_ERROR_INVALID_PARAMETER;
3056 p = new (std::nothrow) TimeItem(id, time);
3058 p = new (std::nothrow) TimeItem(time);
3060 p = new (std::nothrow) TimeItem();
3064 LOGE("Out-of-memory");
3065 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3068 *handle = new Handle(shared_ptr<AbstractItem>(p));
3070 return NOTI_EX_ERROR_NONE;
3073 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3075 if (handle == nullptr || time == nullptr) {
3076 LOGE("Invalid parameter");
3077 return NOTI_EX_ERROR_INVALID_PARAMETER;
3079 Handle* h = static_cast<Handle*>(handle);
3080 if (!h->IsValidType(AbstractItem::Time)) {
3081 LOGE("Invalid handle type");
3082 return NOTI_EX_ERROR_INVALID_PARAMETER;
3084 TimeItem* p = static_cast<TimeItem*>(h->Get());
3085 *time = p->GetTime();
3087 return NOTI_EX_ERROR_NONE;
3090 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3091 noti_ex_action_h *handle, const char *extra) {
3092 if (handle == nullptr) {
3093 LOGE("Invalid parameter");
3094 return NOTI_EX_ERROR_INVALID_PARAMETER;
3097 string extra_str = "";
3099 extra_str = string(extra);
3101 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3102 new (std::nothrow) VisibilityAction(extra_str));
3103 if (ptr == nullptr) {
3104 LOGE("Out-of-memory");
3105 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3110 return NOTI_EX_ERROR_NONE;
3113 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3114 const char *id, bool visible) {
3115 if (handle == nullptr || id == nullptr) {
3116 LOGE("Invalid parameter");
3117 return NOTI_EX_ERROR_INVALID_PARAMETER;
3120 shared_ptr<AbstractAction>* ptr =
3121 static_cast<shared_ptr<AbstractAction>*>(handle);
3122 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3123 action->SetVisibility(id, visible);
3125 return NOTI_EX_ERROR_NONE;
3128 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3129 const char* msgid, const char* format, ...) {
3130 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3131 LOGE("Invalid parameter");
3132 return NOTI_EX_ERROR_INVALID_PARAMETER;
3135 const char* format_idx = format;
3138 va_start(args, format);
3139 while (*format_idx != '\0') {
3140 char* arg = nullptr;
3143 stringstream stream;
3144 if (*format_idx == '%') {
3145 switch (*(format_idx + 1)) {
3147 arg = va_arg(args, char *);
3148 arr.push_back(string(arg));
3151 arg_i = va_arg(args, int);
3152 arr.push_back(to_string(arg_i));
3155 arg_f = va_arg(args, double);
3156 stream << std::fixed << std::setprecision(2) << arg_f;
3157 arr.push_back(stream.str());
3165 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3167 LOGE("Out-of-memory");
3168 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3170 *handle = new shared_ptr<MultiLanguage>(p);
3172 return NOTI_EX_ERROR_NONE;
3175 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3176 if (handle == nullptr) {
3177 LOGE("Invalid parameter");
3178 return NOTI_EX_ERROR_INVALID_PARAMETER;
3181 shared_ptr<MultiLanguage>* mul_ptr =
3182 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3184 return NOTI_EX_ERROR_NONE;
3187 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3188 noti_ex_item_h item, int64_t* private_id) {
3189 if (item == nullptr || private_id == nullptr) {
3190 LOGE("Invalid parameter");
3191 return NOTI_EX_ERROR_INVALID_PARAMETER;
3194 Handle* h = static_cast<Handle*>(item);
3195 *private_id = static_pointer_cast<IItemInfoInternal>(
3196 h->Get()->GetInfo())->GetPrivateId();
3198 return NOTI_EX_ERROR_NONE;
3201 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3202 noti_ex_item_h item, int64_t priv_id) {
3203 if (item == nullptr) {
3204 LOGE("Invalid parameter");
3205 return NOTI_EX_ERROR_INVALID_PARAMETER;
3208 Handle* h = static_cast<Handle*>(item);
3209 static_pointer_cast<IItemInfoInternal>(
3210 h->Get()->GetInfo())->SetPrivateId(priv_id);
3212 return NOTI_EX_ERROR_NONE;