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.
23 #include "api/notification_ex_app_control_action.h"
24 #include "api/notification_ex_button.h"
25 #include "api/notification_ex_chat_message.h"
26 #include "api/notification_ex_checkbox.h"
27 #include "api/notification_ex_entry.h"
28 #include "api/notification_ex_event_info.h"
29 #include "api/notification_ex_group.h"
30 #include "api/notification_ex_image.h"
31 #include "api/notification_ex_input_selector.h"
32 #include "api/notification_ex_item.h"
33 #include "api/notification_ex_manager.h"
34 #include "api/notification_ex_progress.h"
35 #include "api/notification_ex_reporter.h"
36 #include "api/notification_ex_text.h"
37 #include "api/notification_ex_time.h"
38 #include "api/notification_ex_visibility_action.h"
39 #include "notification-ex/reporter.h"
40 #include "notification-ex/app_control_action.h"
41 #include "notification-ex/button_item.h"
42 #include "notification-ex/chat_message_item.h"
43 #include "notification-ex/checkbox_item.h"
44 #include "notification-ex/entry_item.h"
45 #include "notification-ex/group_item.h"
46 #include "notification-ex/input_selector_item.h"
47 #include "notification-ex/abstract_item.h"
48 #include "notification-ex/progress_item.h"
49 #include "notification-ex/time_item.h"
50 #include "notification-ex/visibility_action.h"
51 #include "notification-ex/event_info_internal.h"
52 #include "notification-ex/manager.h"
53 #include "notification-ex/dbus_sender.h"
54 #include "notification-ex/dbus_event_listener.h"
55 #include "notification-ex/exception.h"
60 #define LOG_TAG "NOTIFICATION_EX"
65 #define EXPORT_API __attribute__((visibility("default")))
68 using namespace tizen_base;
69 using namespace notification::item;
70 using namespace notification;
76 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
77 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
78 : ref_(nullptr), ptr_(move(ptr)) { }
79 virtual ~Handle() = default;
80 item::AbstractItem* Get() const {
86 bool IsValidType(int type) const {
87 return (Get()->GetType() == type
88 || Get()->GetType() >= AbstractItem::Custom);
91 std::shared_ptr<item::AbstractItem> GetPtr() const {
93 return std::shared_ptr<item::AbstractItem>({});
98 item::AbstractItem* ref_;
99 std::shared_ptr<item::AbstractItem> ptr_;
102 class ManagerCallbackInfo {
104 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
105 : user_data_(user_data) {
106 cb_.added = cb.added;
107 cb_.updated = cb.updated;
108 cb_.deleted = cb.deleted;
109 cb_.error = cb.error;
112 void InvokeAdded(Manager* manager, const IEventInfo& info,
113 list<shared_ptr<AbstractItem>> addedItem) {
114 if (cb_.added == nullptr)
116 noti_ex_item_h* added_item =
117 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
118 if (added_item == nullptr) {
119 LOGE("Out of memory");
124 for (auto& i : addedItem) {
126 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
129 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
130 cb_.added(static_cast<noti_ex_manager_h>(manager),
131 static_cast<noti_ex_event_info_h>(c_info), added_item,
132 addedItem.size(), user_data_);
136 void InvokeUpdated(Manager* manager, const IEventInfo& info,
137 shared_ptr<item::AbstractItem> updatedItem) {
138 if (cb_.updated == nullptr)
140 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
141 cb_.updated(static_cast<noti_ex_manager_h>(manager),
142 static_cast<noti_ex_event_info_h>(c_info),
143 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
146 void InvokeDeleted(Manager* manager, const IEventInfo& info,
147 shared_ptr<item::AbstractItem> deletedItem) {
148 if (cb_.deleted == nullptr)
150 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
151 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
152 static_cast<noti_ex_event_info_h>(c_info),
153 static_cast<noti_ex_item_h>(
154 new Handle(deletedItem)), user_data_);
157 void InvokeError(Manager* manager, NotificationError error, int requestId) {
158 if (cb_.error == nullptr)
160 cb_.error(static_cast<noti_ex_manager_h>(manager),
161 static_cast<noti_ex_error_e>(error), requestId, user_data_);
165 noti_ex_manager_events_s cb_;
169 class ManagerStub : public Manager {
171 ManagerStub(std::unique_ptr<IEventSender> sender,
172 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
173 : Manager(move(sender), move(listener), receiver_group) {
176 void OnAdd(const IEventInfo& info,
177 list<shared_ptr<AbstractItem>> addedItem) override {
178 cb_->InvokeAdded(this, info, addedItem);
181 void OnUpdate(const IEventInfo& info,
182 std::shared_ptr<item::AbstractItem> updatedItem) override {
183 cb_->InvokeUpdated(this, info, updatedItem);
186 void OnDelete(const IEventInfo& info,
187 shared_ptr<item::AbstractItem> deletedItem) override {
188 cb_->InvokeDeleted(this, info, deletedItem);
191 void OnError(NotificationError error, int requestId) override {
192 cb_->InvokeError(this, error, requestId);
195 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
197 return NOTI_EX_ERROR_NONE;
200 int ClearManagerCallbackInfo() {
202 return NOTI_EX_ERROR_NONE;
206 unique_ptr<ManagerCallbackInfo> cb_;
210 class ReporterCallbackInfo {
212 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
213 : user_data_(user_data) {
214 cb_.event = cb.event;
215 cb_.error = cb.error;
218 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
219 list<shared_ptr<AbstractItem>> notiList) {
220 if (cb_.event == nullptr)
222 noti_ex_item_h* noti_list =
223 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
224 if (noti_list == nullptr) {
225 LOGE("Out of memory");
230 for (auto& i : notiList) {
232 static_cast<noti_ex_item_h>(new Handle(i));
235 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
236 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
237 static_cast<noti_ex_event_info_h>(c_info), noti_list,
238 notiList.size(), user_data_);
242 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
243 if (cb_.error == nullptr)
245 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
246 static_cast<noti_ex_error_e>(error), requestId, user_data_);
250 noti_ex_reporter_events_s cb_;
254 class ReporterStub : public Reporter {
256 ReporterStub(std::unique_ptr<IEventSender> sender,
257 std::unique_ptr<IEventListener> listener)
258 : Reporter(move(sender), move(listener)) {
261 void OnEvent(const IEventInfo& info,
262 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
263 cb_->InvokeEvent(this, info, notiList);
266 void OnError(NotificationError error, int requestId) override {
267 cb_->InvokeError(this, error, requestId);
270 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
272 return NOTI_EX_ERROR_NONE;
275 int ClearReporterCallbackInfo() {
277 return NOTI_EX_ERROR_NONE;
281 unique_ptr<ReporterCallbackInfo> cb_;
286 void __noti_ex_free_str_array(char** val, int length) {
288 for (i = 0; i < length ; i++)
293 extern "C" EXPORT_API int noti_ex_action_app_control_create(
294 noti_ex_action_h *handle, app_control_h app_control,
296 if (handle == nullptr || app_control == nullptr) {
297 LOGE("Invalid parameter");
298 return NOTI_EX_ERROR_INVALID_PARAMETER;
304 p = new (std::nothrow) AppControlAction(app_control, extra);
306 p = new (std::nothrow) AppControlAction(app_control);
309 LOGE("Out-of-memory");
310 return NOTI_EX_ERROR_OUT_OF_MEMORY;
315 return NOTI_EX_ERROR_NONE;
318 extern "C" EXPORT_API int noti_ex_action_app_control_set(
319 noti_ex_action_h handle, app_control_h app_control) {
320 if (handle == nullptr || app_control == nullptr) {
321 LOGE("Invalid parameter");
322 return NOTI_EX_ERROR_INVALID_PARAMETER;
325 AppControlAction* p = static_cast<AppControlAction*>(handle);
326 p->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 AppControlAction* p = static_cast<AppControlAction*>(handle);
339 *app_control = p->GetAppControl();
341 return NOTI_EX_ERROR_NONE;
344 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
345 const char *id, const char *title) {
348 if (handle == nullptr || title == nullptr) {
349 LOGE("Invalid parameter");
350 return NOTI_EX_ERROR_INVALID_PARAMETER;
354 p = new (std::nothrow) ButtonItem(id, title);
356 p = new (std::nothrow) ButtonItem(title);
359 LOGE("Out-of-memory");
360 return NOTI_EX_ERROR_OUT_OF_MEMORY;
362 *handle = new Handle(shared_ptr<AbstractItem>(p));
364 return NOTI_EX_ERROR_NONE;
367 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
369 if (handle == nullptr || title == nullptr) {
370 LOGE("Invalid parameter");
371 return NOTI_EX_ERROR_INVALID_PARAMETER;
374 Handle* sp = static_cast<Handle*>(handle);
375 if (!sp->IsValidType(AbstractItem::Button)) {
376 LOGE("Invalid handle type");
377 return NOTI_EX_ERROR_INVALID_PARAMETER;
379 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
380 if (!p->GetTitle().empty()) {
381 *title = strdup(p->GetTitle().c_str());
382 if (*title == nullptr) {
383 LOGE("Out-of-memory");
384 return NOTI_EX_ERROR_OUT_OF_MEMORY;
388 return NOTI_EX_ERROR_NONE;
391 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
392 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
393 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
394 noti_ex_item_chat_message_type_e message_type) {
395 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
396 LOGE("Invalid parameter");
397 return NOTI_EX_ERROR_INVALID_PARAMETER;
400 auto* p = new (std::nothrow) ChatMessageItem(id,
401 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
402 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
403 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
404 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
405 static_cast<ChatMessageItem::Type>(message_type));
407 LOGE("Out-of-memory");
408 return NOTI_EX_ERROR_OUT_OF_MEMORY;
411 *handle = new Handle(shared_ptr<AbstractItem>(p));
413 return NOTI_EX_ERROR_NONE;
416 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
417 noti_ex_item_h handle, noti_ex_item_h *name) {
418 if (handle == nullptr || name == nullptr) {
419 LOGE("Invalid parameter");
420 return NOTI_EX_ERROR_INVALID_PARAMETER;
422 Handle* h = static_cast<Handle*>(handle);
423 if (!h->IsValidType(AbstractItem::ChatMessage)) {
424 LOGE("Invalid handle type");
425 return NOTI_EX_ERROR_INVALID_PARAMETER;
427 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
428 *name = new Handle(&(p->GetNameItem()));
430 return NOTI_EX_ERROR_NONE;
433 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
434 noti_ex_item_h handle, noti_ex_item_h *text) {
435 if (handle == nullptr || text == nullptr) {
436 LOGE("Invalid parameter");
437 return NOTI_EX_ERROR_INVALID_PARAMETER;
440 Handle* h = static_cast<Handle*>(handle);
441 if (!h->IsValidType(AbstractItem::ChatMessage)) {
442 LOGE("Invalid handle type");
443 return NOTI_EX_ERROR_INVALID_PARAMETER;
445 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
446 *text = new Handle(&(p->GetTextItem()));
448 return NOTI_EX_ERROR_NONE;
451 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
452 noti_ex_item_h handle, noti_ex_item_h *image) {
453 if (handle == nullptr || image == nullptr) {
454 LOGE("Invalid parameter");
455 return NOTI_EX_ERROR_INVALID_PARAMETER;
458 Handle* h = static_cast<Handle*>(handle);
459 if (!h->IsValidType(AbstractItem::ChatMessage)) {
460 LOGE("Invalid handle type");
461 return NOTI_EX_ERROR_INVALID_PARAMETER;
463 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
464 *image = new Handle(&(p->GetImageItem()));
466 return NOTI_EX_ERROR_NONE;
469 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
470 noti_ex_item_h handle, noti_ex_item_h *time) {
471 if (handle == nullptr || time == nullptr) {
472 LOGE("Invalid parameter");
473 return NOTI_EX_ERROR_INVALID_PARAMETER;
476 Handle* h = static_cast<Handle*>(handle);
477 if (!h->IsValidType(AbstractItem::ChatMessage)) {
478 LOGE("Invalid handle type");
479 return NOTI_EX_ERROR_INVALID_PARAMETER;
481 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
482 *time = new Handle(&(p->GetTimeItem()));
484 return NOTI_EX_ERROR_NONE;
487 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
488 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
489 if (handle == nullptr || message_type == nullptr) {
490 LOGE("Invalid parameter");
491 return NOTI_EX_ERROR_INVALID_PARAMETER;
494 Handle* h = static_cast<Handle*>(handle);
495 if (!h->IsValidType(AbstractItem::ChatMessage)) {
496 LOGE("Invalid handle type");
497 return NOTI_EX_ERROR_INVALID_PARAMETER;
499 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
500 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
502 return NOTI_EX_ERROR_NONE;
505 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
506 const char *id, const char *title, bool checked) {
509 if (handle == nullptr || title == nullptr) {
510 LOGE("Invalid parameter");
511 return NOTI_EX_ERROR_INVALID_PARAMETER;
514 p = new (std::nothrow) CheckBoxItem(id, title, checked);
516 LOGE("Out-of-memory");
517 return NOTI_EX_ERROR_OUT_OF_MEMORY;
520 *handle = new Handle(shared_ptr<AbstractItem>(p));
522 return NOTI_EX_ERROR_NONE;
525 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
527 if (handle == nullptr || title == nullptr) {
528 LOGE("Invalid parameter");
529 return NOTI_EX_ERROR_INVALID_PARAMETER;
531 Handle* h = static_cast<Handle*>(handle);
532 if (!h->IsValidType(AbstractItem::CheckBox)) {
533 LOGE("Invalid handle type");
534 return NOTI_EX_ERROR_INVALID_PARAMETER;
536 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
537 if (!p->GetTitle().empty()) {
538 *title = strdup(p->GetTitle().c_str());
539 if (*title == nullptr) {
540 LOGE("Out-of-memory");
541 return NOTI_EX_ERROR_OUT_OF_MEMORY;
545 return NOTI_EX_ERROR_NONE;
548 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
549 noti_ex_item_h handle, bool *checked) {
550 if (handle == nullptr || checked == nullptr) {
551 LOGE("Invalid parameter");
552 return NOTI_EX_ERROR_INVALID_PARAMETER;
554 Handle* h = static_cast<Handle*>(handle);
555 if (!h->IsValidType(AbstractItem::CheckBox)) {
556 LOGE("Invalid handle type");
557 return NOTI_EX_ERROR_INVALID_PARAMETER;
559 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
560 *checked = p->IsChecked();
562 return NOTI_EX_ERROR_NONE;
565 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
566 noti_ex_item_h handle, bool checked) {
567 if (handle == nullptr) {
568 LOGE("Invalid parameter");
569 return NOTI_EX_ERROR_INVALID_PARAMETER;
572 Handle* h = static_cast<Handle*>(handle);
573 if (!h->IsValidType(AbstractItem::CheckBox)) {
574 LOGE("Invalid handle type");
575 return NOTI_EX_ERROR_INVALID_PARAMETER;
578 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
579 p->SetChecked(checked);
581 return NOTI_EX_ERROR_NONE;
584 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
588 if (handle == nullptr) {
589 LOGE("Invalid parameter");
590 return NOTI_EX_ERROR_INVALID_PARAMETER;
593 p = new (std::nothrow) EntryItem(id);
595 LOGE("Out-of-memory");
596 return NOTI_EX_ERROR_OUT_OF_MEMORY;
599 *handle = new Handle(shared_ptr<AbstractItem>(p));
601 return NOTI_EX_ERROR_NONE;
604 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
606 if (handle == nullptr || text == nullptr) {
607 LOGE("Invalid parameter");
608 return NOTI_EX_ERROR_INVALID_PARAMETER;
611 Handle* h = static_cast<Handle*>(handle);
612 if (!h->IsValidType(AbstractItem::Entry)) {
613 LOGE("Invalid handle type");
614 return NOTI_EX_ERROR_INVALID_PARAMETER;
616 EntryItem* p = static_cast<EntryItem*>(h->Get());
617 if (!p->GetText().empty()) {
618 *text = strdup(p->GetText().c_str());
619 if (*text == nullptr) {
620 LOGE("Out-of-memory");
621 return NOTI_EX_ERROR_OUT_OF_MEMORY;
625 return NOTI_EX_ERROR_NONE;
628 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
630 if (handle == nullptr || text == nullptr) {
631 LOGE("Invalid parameter");
632 return NOTI_EX_ERROR_INVALID_PARAMETER;
634 Handle* h = static_cast<Handle*>(handle);
635 if (!h->IsValidType(AbstractItem::Entry)) {
636 LOGE("Invalid handle type");
637 return NOTI_EX_ERROR_INVALID_PARAMETER;
639 EntryItem* p = static_cast<EntryItem*>(h->Get());
640 p->SetText(std::string(text));
642 return NOTI_EX_ERROR_NONE;
645 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
646 noti_ex_event_info_h* cloned_handle) {
647 if (handle == nullptr || cloned_handle == nullptr) {
648 LOGE("Invalid parameter");
649 return NOTI_EX_ERROR_INVALID_PARAMETER;
652 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
653 EventInfo* info = new EventInfo(cloned);
654 *cloned_handle = info;
655 return NOTI_EX_ERROR_NONE;
658 extern "C" EXPORT_API int noti_ex_event_info_destroy(
659 noti_ex_event_info_h handle) {
660 if (handle == nullptr) {
661 LOGE("Invalid parameter");
662 return NOTI_EX_ERROR_INVALID_PARAMETER;
664 EventInfo* info = static_cast<EventInfo*>(handle);
666 return NOTI_EX_ERROR_NONE;
669 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
670 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
671 if (handle == nullptr || event_type == nullptr) {
672 LOGE("Invalid parameter");
673 return NOTI_EX_ERROR_INVALID_PARAMETER;
675 EventInfo* info = static_cast<EventInfo*>(handle);
676 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
678 return NOTI_EX_ERROR_NONE;
681 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
682 noti_ex_event_info_h handle, char **owner) {
683 if (handle == nullptr || owner == nullptr) {
684 LOGE("Invalid parameter");
685 return NOTI_EX_ERROR_INVALID_PARAMETER;
687 EventInfo* info = static_cast<EventInfo*>(handle);
688 *owner = strdup(info->GetOwner().c_str());
689 return NOTI_EX_ERROR_NONE;
692 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
693 noti_ex_event_info_h handle, char **channel) {
694 if (handle == nullptr || channel == nullptr) {
695 LOGE("Invalid parameter");
696 return NOTI_EX_ERROR_INVALID_PARAMETER;
698 EventInfo* info = static_cast<EventInfo*>(handle);
699 *channel = strdup(info->GetChannel().c_str());
700 return NOTI_EX_ERROR_NONE;
703 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
704 noti_ex_event_info_h handle, char **item_id) {
705 if (handle == nullptr || item_id == nullptr) {
706 LOGE("Invalid parameter");
707 return NOTI_EX_ERROR_INVALID_PARAMETER;
709 EventInfo* info = static_cast<EventInfo*>(handle);
710 *item_id = strdup(info->GetItemId().c_str());
711 return NOTI_EX_ERROR_NONE;
714 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
715 noti_ex_event_info_h handle, int *req_id) {
716 if (handle == nullptr || req_id == nullptr) {
717 LOGE("Invalid parameter");
718 return NOTI_EX_ERROR_INVALID_PARAMETER;
720 EventInfo* info = static_cast<EventInfo*>(handle);
721 *req_id = info->GetRequestId();
722 return NOTI_EX_ERROR_NONE;
725 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
729 if (handle == nullptr) {
730 LOGE("Invalid parameter");
731 return NOTI_EX_ERROR_INVALID_PARAMETER;
735 p = new (std::nothrow) GroupItem(id);
737 p = new (std::nothrow) GroupItem();
740 LOGE("Out-of-memory");
741 return NOTI_EX_ERROR_OUT_OF_MEMORY;
744 *handle = new Handle(shared_ptr<AbstractItem>(p));
746 return NOTI_EX_ERROR_NONE;
749 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
751 if (handle == nullptr) {
752 LOGE("Invalid parameter");
753 return NOTI_EX_ERROR_INVALID_PARAMETER;
755 Handle* h = static_cast<Handle*>(handle);
756 if (!h->IsValidType(AbstractItem::Group)) {
757 LOGE("Invalid handle type");
758 return NOTI_EX_ERROR_INVALID_PARAMETER;
760 GroupItem* p = static_cast<GroupItem*>(h->Get());
761 p->SetDirection(vertical);
763 return NOTI_EX_ERROR_NONE;
766 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
768 if (handle == nullptr) {
769 LOGE("Invalid parameter");
770 return NOTI_EX_ERROR_INVALID_PARAMETER;
772 Handle* h = static_cast<Handle*>(handle);
773 if (!h->IsValidType(AbstractItem::Group)) {
774 LOGE("Invalid handle type");
775 return NOTI_EX_ERROR_INVALID_PARAMETER;
777 GroupItem* p = static_cast<GroupItem*>(h->Get());
778 *vertical = p->IsVertical();
780 return NOTI_EX_ERROR_NONE;
783 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
785 if (handle == nullptr) {
786 LOGE("Invalid parameter");
787 return NOTI_EX_ERROR_INVALID_PARAMETER;
789 Handle* h = static_cast<Handle*>(handle);
790 if (!h->IsValidType(AbstractItem::Group)) {
791 LOGE("Invalid handle type");
792 return NOTI_EX_ERROR_INVALID_PARAMETER;
794 GroupItem* p = static_cast<GroupItem*>(h->Get());
795 if (!p->GetAppLabel().empty()) {
796 *label = strdup(p->GetAppLabel().c_str());
797 if (*label == nullptr) {
798 LOGE("Out-of-memory");
799 return NOTI_EX_ERROR_OUT_OF_MEMORY;
803 return NOTI_EX_ERROR_NONE;
806 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
807 noti_ex_item_h child) {
808 if (handle == nullptr || child == nullptr) {
809 LOGE("Invalid parameter");
810 return NOTI_EX_ERROR_INVALID_PARAMETER;
812 Handle* h = static_cast<Handle*>(handle);
813 if (!h->IsValidType(AbstractItem::Group)) {
814 LOGE("Invalid handle type");
815 return NOTI_EX_ERROR_INVALID_PARAMETER;
817 auto p = static_cast<GroupItem*>(h->Get());
818 p->AddChild((static_cast<Handle*>(child))->GetPtr());
820 return NOTI_EX_ERROR_NONE;
823 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
824 const char *item_id) {
825 if (handle == nullptr || item_id == nullptr) {
826 LOGE("Invalid parameter");
827 return NOTI_EX_ERROR_INVALID_PARAMETER;
829 Handle* h = static_cast<Handle*>(handle);
830 if (!h->IsValidType(AbstractItem::Group)) {
831 LOGE("Invalid handle type");
832 return NOTI_EX_ERROR_INVALID_PARAMETER;
834 GroupItem* p = static_cast<GroupItem*>(h->Get());
835 p->RemoveChild(std::string(item_id));
837 return NOTI_EX_ERROR_NONE;
840 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
841 noti_ex_item_group_foreach_child_cb callback, void *data) {
842 if (handle == nullptr || callback == nullptr) {
843 LOGE("Invalid parameter");
844 return NOTI_EX_ERROR_INVALID_PARAMETER;
847 Handle* h = static_cast<Handle*>(handle);
848 if (!h->IsValidType(AbstractItem::Group)) {
849 LOGE("Invalid handle type");
850 return NOTI_EX_ERROR_INVALID_PARAMETER;
852 GroupItem* p = static_cast<GroupItem*>(h->Get());
853 list<shared_ptr<AbstractItem>> children = p->GetChildren();
854 LOGI("Retrive (%zd)", children.size());
855 for (auto i : children) {
857 static_cast<noti_ex_item_h>(new Handle(i)), data);
858 if (ret != NOTI_EX_ERROR_NONE) {
859 LOGW("callback return (%d) stop foreach", ret);
864 return NOTI_EX_ERROR_NONE;
867 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
868 const char *id, const char *image_path) {
871 if (handle == nullptr || image_path == nullptr) {
872 LOGE("Invalid parameter");
873 return NOTI_EX_ERROR_INVALID_PARAMETER;
877 p = new (std::nothrow) ImageItem(id, image_path);
879 p = new (std::nothrow) ImageItem(image_path);
882 LOGE("Out-of-memory");
883 return NOTI_EX_ERROR_OUT_OF_MEMORY;
886 *handle = new Handle(shared_ptr<AbstractItem>(p));
888 return NOTI_EX_ERROR_NONE;
891 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
892 noti_ex_item_h handle, char **image_path) {
893 if (handle == nullptr || image_path == nullptr) {
894 LOGE("Invalid parameter");
895 return NOTI_EX_ERROR_INVALID_PARAMETER;
897 Handle* h = static_cast<Handle*>(handle);
898 if (!h->IsValidType(AbstractItem::Image)) {
899 LOGE("Invalid handle type");
900 return NOTI_EX_ERROR_INVALID_PARAMETER;
902 ImageItem* p = static_cast<ImageItem*>(h->Get());
903 if (!p->GetImagePath().empty()) {
904 *image_path = strdup(p->GetImagePath().c_str());
905 if (*image_path == nullptr) {
906 LOGE("Out-of-memory");
907 return NOTI_EX_ERROR_OUT_OF_MEMORY;
911 return NOTI_EX_ERROR_NONE;
914 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
915 noti_ex_item_h *handle, const char *id) {
916 InputSelectorItem* p;
918 if (handle == nullptr) {
919 LOGE("Invalid parameter");
920 return NOTI_EX_ERROR_INVALID_PARAMETER;
924 p = new (std::nothrow) InputSelectorItem(id);
926 p = new (std::nothrow) InputSelectorItem();
929 LOGE("Out-of-memory");
930 return NOTI_EX_ERROR_OUT_OF_MEMORY;
933 *handle = new Handle(shared_ptr<AbstractItem>(p));
935 return NOTI_EX_ERROR_NONE;
938 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
939 noti_ex_item_h handle, char ***contents_list, int *count) {
940 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
941 LOGE("Invalid parameter");
942 return NOTI_EX_ERROR_INVALID_PARAMETER;
945 Handle* h = static_cast<Handle*>(handle);
946 if (!h->IsValidType(AbstractItem::InputSelector)) {
947 LOGE("Invalid handle type");
948 return NOTI_EX_ERROR_INVALID_PARAMETER;
950 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
951 list<string> contents = p->GetContents();
952 char **list = (char**)calloc(contents.size(), sizeof(char*));
953 if (list == nullptr) {
954 LOGE("Out of memory");
955 return NOTI_EX_ERROR_OUT_OF_MEMORY;
959 for (auto& i : contents) {
960 list[idx] = strdup(i.c_str());
961 if (list[idx] == nullptr) {
962 __noti_ex_free_str_array(list, idx);
963 LOGE("Out of memory");
964 return NOTI_EX_ERROR_OUT_OF_MEMORY;
969 *count = contents.size();
970 *contents_list = list;
972 return NOTI_EX_ERROR_NONE;
975 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
976 noti_ex_item_h handle, const char **contents, int count) {
977 if (handle == nullptr || contents == nullptr) {
978 LOGE("Invalid parameter");
979 return NOTI_EX_ERROR_INVALID_PARAMETER;
982 list<string> new_contents;
983 Handle* h = static_cast<Handle*>(handle);
984 if (!h->IsValidType(AbstractItem::InputSelector)) {
985 LOGE("Invalid handle type");
986 return NOTI_EX_ERROR_INVALID_PARAMETER;
988 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
989 for (int i = 0; i < count; i++) {
990 new_contents.push_back(contents[i]);
992 p->SetContents(move(new_contents));
994 return NOTI_EX_ERROR_NONE;
997 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
998 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
999 if (handle == nullptr) {
1000 LOGE("Invalid parameter");
1001 return NOTI_EX_ERROR_INVALID_PARAMETER;
1004 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1005 new (std::nothrow) Color(a, r, g, b));
1006 if (ptr == nullptr || ptr->get() == nullptr) {
1007 LOGE("Out-of-memory");
1008 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1013 return NOTI_EX_ERROR_NONE;
1016 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1017 if (handle == nullptr) {
1018 LOGE("Invalid parameter");
1019 return NOTI_EX_ERROR_INVALID_PARAMETER;
1022 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1025 return NOTI_EX_ERROR_NONE;
1028 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1029 unsigned char *val) {
1030 if (handle == nullptr || val == nullptr) {
1031 LOGE("Invalid parameter");
1032 return NOTI_EX_ERROR_INVALID_PARAMETER;
1035 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1036 *val = (*p)->GetAVal();
1038 return NOTI_EX_ERROR_NONE;
1041 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1042 unsigned char *val) {
1043 if (handle == nullptr || val == nullptr) {
1044 LOGE("Invalid parameter");
1045 return NOTI_EX_ERROR_INVALID_PARAMETER;
1048 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1049 *val = (*p)->GetRVal();
1051 return NOTI_EX_ERROR_NONE;
1054 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1055 unsigned char *val) {
1056 if (handle == nullptr || val == nullptr) {
1057 LOGE("Invalid parameter");
1058 return NOTI_EX_ERROR_INVALID_PARAMETER;
1061 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1062 *val = (*p)->GetGVal();
1064 return NOTI_EX_ERROR_NONE;
1067 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1068 unsigned char *val) {
1069 if (handle == nullptr || val == nullptr) {
1070 LOGE("Invalid parameter");
1071 return NOTI_EX_ERROR_INVALID_PARAMETER;
1074 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1075 *val = (*p)->GetBVal();
1077 return NOTI_EX_ERROR_NONE;
1080 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1081 int left, int top, int right, int bottom) {
1082 if (handle == nullptr) {
1083 LOGE("Invalid parameter");
1084 return NOTI_EX_ERROR_INVALID_PARAMETER;
1087 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1088 new (std::nothrow) Padding(left, top, right, bottom));
1089 if (ptr == nullptr || ptr->get() == nullptr) {
1090 LOGE("Out-of-memory");
1091 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1096 return NOTI_EX_ERROR_NONE;
1099 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1100 if (handle == nullptr) {
1101 LOGE("Invalid parameter");
1102 return NOTI_EX_ERROR_INVALID_PARAMETER;
1105 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1108 return NOTI_EX_ERROR_NONE;
1111 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1113 if (handle == nullptr || val == nullptr) {
1114 LOGE("Invalid parameter");
1115 return NOTI_EX_ERROR_INVALID_PARAMETER;
1118 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1119 *val = (*p)->GetLeft();
1121 return NOTI_EX_ERROR_NONE;
1124 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1126 if (handle == nullptr || val == nullptr) {
1127 LOGE("Invalid parameter");
1128 return NOTI_EX_ERROR_INVALID_PARAMETER;
1131 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1132 *val = (*p)->GetTop();
1134 return NOTI_EX_ERROR_NONE;
1137 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1139 if (handle == nullptr || val == nullptr) {
1140 LOGE("Invalid parameter");
1141 return NOTI_EX_ERROR_INVALID_PARAMETER;
1144 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1145 *val = (*p)->GetRight();
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1152 if (handle == nullptr || val == nullptr) {
1153 LOGE("Invalid parameter");
1154 return NOTI_EX_ERROR_INVALID_PARAMETER;
1157 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1158 *val = (*p)->GetBottom();
1160 return NOTI_EX_ERROR_NONE;
1163 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1164 int x, int y, int w, int h) {
1165 if (handle == nullptr) {
1166 LOGE("Invalid parameter");
1167 return NOTI_EX_ERROR_INVALID_PARAMETER;
1170 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1171 new (std::nothrow) Geometry(x, y, w, h));
1172 if (ptr == nullptr || ptr->get() == nullptr) {
1173 LOGE("Out-of-memory");
1174 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1179 return NOTI_EX_ERROR_NONE;
1182 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1183 if (handle == nullptr) {
1184 LOGE("Invalid parameter");
1185 return NOTI_EX_ERROR_INVALID_PARAMETER;
1188 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1191 return NOTI_EX_ERROR_NONE;
1194 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1196 if (handle == nullptr || val == nullptr) {
1197 LOGE("Invalid parameter");
1198 return NOTI_EX_ERROR_INVALID_PARAMETER;
1201 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1202 *val = (*p)->GetX();
1204 return NOTI_EX_ERROR_NONE;
1207 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1209 if (handle == nullptr || val == nullptr) {
1210 LOGE("Invalid parameter");
1211 return NOTI_EX_ERROR_INVALID_PARAMETER;
1214 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1215 *val = (*p)->GetY();
1217 return NOTI_EX_ERROR_NONE;
1220 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1222 if (handle == nullptr || val == nullptr) {
1223 LOGE("Invalid parameter");
1224 return NOTI_EX_ERROR_INVALID_PARAMETER;
1227 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1228 *val = (*p)->GetWidth();
1230 return NOTI_EX_ERROR_NONE;
1233 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1235 if (handle == nullptr || val == nullptr) {
1236 LOGE("Invalid parameter");
1237 return NOTI_EX_ERROR_INVALID_PARAMETER;
1240 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1241 *val = (*p)->GetHeight();
1243 return NOTI_EX_ERROR_NONE;
1246 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1247 noti_ex_color_h color,
1248 noti_ex_padding_h padding,
1249 noti_ex_geometry_h geometry) {
1250 if (handle == nullptr) {
1251 LOGE("Invalid parameter");
1252 return NOTI_EX_ERROR_INVALID_PARAMETER;
1255 shared_ptr<Color> col = (color == nullptr) ?
1256 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1257 shared_ptr<Padding> padd = (padding == nullptr) ?
1258 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1259 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1260 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1262 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1263 new (std::nothrow) Style(col, padd, geo));
1264 if (ptr == nullptr || ptr->get() == nullptr) {
1265 LOGE("Out-of-memory");
1266 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1271 return NOTI_EX_ERROR_NONE;
1274 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1275 if (handle == nullptr) {
1276 LOGE("Invalid parameter");
1277 return NOTI_EX_ERROR_INVALID_PARAMETER;
1280 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1283 return NOTI_EX_ERROR_NONE;
1286 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1287 noti_ex_padding_h *padding) {
1288 if (handle == nullptr || padding == nullptr) {
1289 LOGE("Invalid parameter");
1290 return NOTI_EX_ERROR_INVALID_PARAMETER;
1293 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1294 if ((*p)->GetPadding() == nullptr) {
1295 LOGW("Padding info is null");
1296 return NOTI_EX_ERROR_INVALID_PARAMETER;
1299 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1300 new (std::nothrow) Padding(*((*p)->GetPadding())));
1301 if (padd == nullptr || padd->get() == nullptr) {
1302 LOGE("Out-of-memory");
1303 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1308 return NOTI_EX_ERROR_NONE;
1311 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1312 noti_ex_color_h *color) {
1313 if (handle == nullptr || color == nullptr) {
1314 LOGE("Invalid parameter");
1315 return NOTI_EX_ERROR_INVALID_PARAMETER;
1318 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1319 if ((*p)->GetColor() == nullptr) {
1320 LOGW("Color info is null");
1321 return NOTI_EX_ERROR_INVALID_PARAMETER;
1324 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1325 new (std::nothrow) Color(*((*p)->GetColor())));
1326 if (col == nullptr || col->get() == nullptr) {
1327 LOGE("Out-of-memory");
1328 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1333 return NOTI_EX_ERROR_NONE;
1336 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1337 noti_ex_geometry_h *geometry) {
1338 if (handle == nullptr || geometry == nullptr) {
1339 LOGE("Invalid parameter");
1340 return NOTI_EX_ERROR_INVALID_PARAMETER;
1343 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1344 if ((*p)->GetGeometry() == nullptr) {
1345 LOGW("Geometry info is null");
1346 return NOTI_EX_ERROR_INVALID_PARAMETER;
1349 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1350 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1351 if (geo == nullptr || geo->get() == nullptr) {
1352 LOGE("Out-of-memory");
1353 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1358 return NOTI_EX_ERROR_NONE;
1361 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1362 noti_ex_style_h handle, char** background_image) {
1363 if (handle == nullptr || background_image == nullptr) {
1364 LOGE("Invalid parameter");
1365 return NOTI_EX_ERROR_INVALID_PARAMETER;
1368 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1369 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1371 return NOTI_EX_ERROR_NONE;
1374 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1375 noti_ex_style_h handle, char* background_image) {
1376 if (handle == nullptr || background_image == nullptr) {
1377 LOGE("Invalid parameter");
1378 return NOTI_EX_ERROR_INVALID_PARAMETER;
1381 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1382 (*p)->SetBackgroundImage(background_image);
1384 return NOTI_EX_ERROR_NONE;
1387 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1388 noti_ex_style_h handle, noti_ex_color_h* color) {
1389 if (handle == nullptr || color == nullptr) {
1390 LOGE("Invalid parameter");
1391 return NOTI_EX_ERROR_INVALID_PARAMETER;
1394 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1395 if ((*p)->GetBackgroundColor() == nullptr) {
1396 LOGW("Color info is null");
1397 return NOTI_EX_ERROR_INVALID_PARAMETER;
1400 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1401 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1402 if (col == nullptr || col->get() == nullptr) {
1403 LOGE("Out-of-memory");
1404 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1409 return NOTI_EX_ERROR_NONE;
1412 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1413 noti_ex_style_h handle, noti_ex_color_h color) {
1414 if (handle == nullptr || color == nullptr) {
1415 LOGE("Invalid parameter");
1416 return NOTI_EX_ERROR_INVALID_PARAMETER;
1419 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1420 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1421 (*p)->SetBackgroundColor(*col);
1423 return NOTI_EX_ERROR_NONE;
1426 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1427 noti_ex_color_h color) {
1428 if (handle == nullptr) {
1429 LOGE("Invalid parameter");
1430 return NOTI_EX_ERROR_INVALID_PARAMETER;
1433 shared_ptr<Color>* color_ = static_cast<shared_ptr<Color>*>(color);
1434 auto* p = new (std::nothrow) LEDInfo(*color_);
1436 LOGE("Out-of-memory");
1437 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1442 return NOTI_EX_ERROR_NONE;
1445 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1446 if (handle == nullptr) {
1447 LOGE("Invalid parameter");
1448 return NOTI_EX_ERROR_INVALID_PARAMETER;
1451 LEDInfo* p = static_cast<LEDInfo*>(handle);
1454 return NOTI_EX_ERROR_NONE;
1457 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1458 noti_ex_led_info_h handle, int ms) {
1459 if (handle == nullptr) {
1460 LOGE("Invalid parameter");
1461 return NOTI_EX_ERROR_INVALID_PARAMETER;
1464 LEDInfo* p = static_cast<LEDInfo*>(handle);
1467 return NOTI_EX_ERROR_NONE;
1470 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1471 noti_ex_led_info_h handle, int *ms) {
1472 if (handle == nullptr || ms == nullptr) {
1473 LOGE("Invalid parameter");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 LEDInfo* p = static_cast<LEDInfo*>(handle);
1478 *ms = p->GetOnPeriod();
1480 return NOTI_EX_ERROR_NONE;
1483 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1484 noti_ex_led_info_h handle, int ms) {
1485 if (handle == nullptr) {
1486 LOGE("Invalid parameter");
1487 return NOTI_EX_ERROR_INVALID_PARAMETER;
1490 LEDInfo* p = static_cast<LEDInfo*>(handle);
1491 p->SetOffPeriod(ms);
1493 return NOTI_EX_ERROR_NONE;
1496 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1497 noti_ex_led_info_h handle, int *ms) {
1498 if (handle == nullptr) {
1499 LOGE("Invalid parameter");
1500 return NOTI_EX_ERROR_INVALID_PARAMETER;
1503 LEDInfo* p = static_cast<LEDInfo*>(handle);
1504 *ms = p->GetOffPeriod();
1506 return NOTI_EX_ERROR_NONE;
1509 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1510 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1511 if (handle == nullptr) {
1512 LOGE("Invalid parameter");
1513 return NOTI_EX_ERROR_INVALID_PARAMETER;
1516 LEDInfo* p = static_cast<LEDInfo*>(handle);
1517 if (p->GetColor() == nullptr) {
1518 LOGE("Color is null");
1519 return NOTI_EX_ERROR_INVALID_PARAMETER;
1522 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1523 new (std::nothrow) Color(*(p->GetColor())));
1524 if (col == nullptr || col->get() == nullptr) {
1525 LOGE("Out-of-memory");
1526 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1531 return NOTI_EX_ERROR_NONE;
1534 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1535 if (handle == nullptr) {
1536 LOGE("Invalid parameter");
1537 return NOTI_EX_ERROR_INVALID_PARAMETER;
1540 AbstractAction* p = static_cast<AbstractAction*>(handle);
1541 p->~AbstractAction();
1543 return NOTI_EX_ERROR_NONE;
1546 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1548 if (handle == nullptr || type == nullptr) {
1549 LOGE("Invalid parameter");
1550 return NOTI_EX_ERROR_INVALID_PARAMETER;
1553 AbstractAction* p = static_cast<AbstractAction*>(handle);
1554 *type = p->GetType();
1556 return NOTI_EX_ERROR_NONE;
1559 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1561 if (handle == nullptr || local == nullptr) {
1562 LOGE("Invalid parameter");
1563 return NOTI_EX_ERROR_INVALID_PARAMETER;
1566 AbstractAction* p = static_cast<AbstractAction*>(handle);
1567 *local = p->IsLocal();
1569 return NOTI_EX_ERROR_NONE;
1572 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1573 noti_ex_item_h item) {
1574 if (handle == nullptr || item == nullptr) {
1575 LOGE("Invalid parameter");
1576 return NOTI_EX_ERROR_INVALID_PARAMETER;
1578 AbstractAction* p = static_cast<AbstractAction*>(handle);
1579 Handle* ih = static_cast<Handle*>(item);
1580 p->Execute(ih->GetPtr());
1582 return NOTI_EX_ERROR_NONE;
1585 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1587 if (handle == nullptr || extra == nullptr) {
1588 LOGE("Invalid parameter");
1589 return NOTI_EX_ERROR_INVALID_PARAMETER;
1592 AbstractAction* p = static_cast<AbstractAction*>(handle);
1593 if (!p->GetExtra().empty()) {
1594 *extra = strdup(p->GetExtra().c_str());
1595 if (*extra == nullptr) {
1596 LOGE("Out-of-memory");
1597 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1601 return NOTI_EX_ERROR_NONE;
1604 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1605 noti_ex_item_info_h handle, int *hide_time) {
1606 if (handle == nullptr || hide_time == nullptr) {
1607 LOGE("Invalid parameter");
1608 return NOTI_EX_ERROR_INVALID_PARAMETER;
1610 IItemInfo* p = static_cast<IItemInfo*>(handle);
1611 *hide_time = p->GetHideTime();
1612 return NOTI_EX_ERROR_NONE;
1615 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1616 noti_ex_item_info_h handle, int hide_time) {
1617 if (handle == nullptr) {
1618 LOGE("Invalid parameter");
1619 return NOTI_EX_ERROR_INVALID_PARAMETER;
1621 IItemInfo* p = static_cast<IItemInfo*>(handle);
1622 p->SetHideTime(hide_time);
1623 return NOTI_EX_ERROR_NONE;
1626 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1627 noti_ex_item_info_h handle, int *delete_time) {
1628 if (handle == nullptr || delete_time == nullptr) {
1629 LOGE("Invalid parameter");
1630 return NOTI_EX_ERROR_INVALID_PARAMETER;
1632 IItemInfo* p = static_cast<IItemInfo*>(handle);
1633 *delete_time = p->GetDeleteTime();
1634 return NOTI_EX_ERROR_NONE;
1637 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1638 noti_ex_item_info_h handle, int delete_time) {
1639 if (handle == nullptr) {
1640 LOGE("Invalid parameter");
1641 return NOTI_EX_ERROR_INVALID_PARAMETER;
1643 IItemInfo* p = static_cast<IItemInfo*>(handle);
1644 p->SetDeleteTime(delete_time);
1645 return NOTI_EX_ERROR_NONE;
1648 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1649 noti_ex_item_info_h handle, time_t *time) {
1650 if (handle == nullptr || time == nullptr) {
1651 LOGE("Invalid parameter");
1652 return NOTI_EX_ERROR_INVALID_PARAMETER;
1655 IItemInfo* p = static_cast<IItemInfo*>(handle);
1656 *time = p->GetTime();
1657 return NOTI_EX_ERROR_NONE;
1660 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1661 if (handle == nullptr) {
1662 LOGE("Invalid parameter");
1663 return NOTI_EX_ERROR_INVALID_PARAMETER;
1666 Handle* h = static_cast<Handle*>(handle);
1668 return NOTI_EX_ERROR_NONE;
1671 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1672 const char *id, noti_ex_item_h *item) {
1673 if (handle == nullptr) {
1674 LOGE("Invalid parameter");
1675 return NOTI_EX_ERROR_INVALID_PARAMETER;
1678 Handle* p = static_cast<Handle*>(handle);
1679 AbstractItem& find_item = p->Get()->FindByID(string(id));
1680 *item = new Handle(&find_item);
1681 return NOTI_EX_ERROR_NONE;
1684 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1686 if (handle == nullptr || type == nullptr) {
1687 LOGE("Invalid parameter");
1688 return NOTI_EX_ERROR_INVALID_PARAMETER;
1691 Handle* h = static_cast<Handle*>(handle);
1692 AbstractItem* p = h->Get();
1693 *type = p->GetType();
1694 return NOTI_EX_ERROR_NONE;
1697 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1698 char ***path, int *count) {
1699 if (handle == nullptr || path == nullptr || count == nullptr) {
1700 LOGE("Invalid parameter");
1701 return NOTI_EX_ERROR_INVALID_PARAMETER;
1703 Handle* p = static_cast<Handle*>(handle);
1704 list<string> shared_path = p->Get()->GetSharedPath();
1705 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1706 if (tmp_path == nullptr) {
1707 LOGE("Fail to create items");
1708 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1712 for (auto& i : shared_path) {
1713 tmp_path[idx] = strdup(i.c_str());
1714 if (tmp_path[idx] == nullptr) {
1715 __noti_ex_free_str_array(tmp_path, idx);
1716 LOGE("Out of memory");
1717 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1723 *count = shared_path.size();
1724 return NOTI_EX_ERROR_NONE;
1727 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1729 if (handle == nullptr || id == nullptr) {
1730 LOGE("Invalid parameter");
1731 return NOTI_EX_ERROR_INVALID_PARAMETER;
1733 Handle* h = static_cast<Handle*>(handle);
1734 AbstractItem* p = h->Get();
1735 *id = strdup(p->GetId().c_str());
1736 return NOTI_EX_ERROR_NONE;
1739 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1741 if (handle == nullptr || id == nullptr) {
1742 LOGE("Invalid parameter");
1743 return NOTI_EX_ERROR_INVALID_PARAMETER;
1745 Handle* p = static_cast<Handle*>(handle);
1746 p->Get()->SetId(id);
1747 return NOTI_EX_ERROR_NONE;
1750 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1751 noti_ex_action_h *action) {
1752 if (handle == nullptr || action == nullptr) {
1753 LOGE("Invalid parameter");
1754 return NOTI_EX_ERROR_INVALID_PARAMETER;
1756 Handle* p = static_cast<Handle*>(handle);
1757 if (p->Get()->GetAction() == nullptr) {
1759 return NOTI_EX_ERROR_NONE;
1761 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1763 return NOTI_EX_ERROR_NONE;
1766 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1767 noti_ex_action_h action) {
1768 if (handle == nullptr || action == nullptr) {
1769 LOGE("Invalid parameter");
1770 return NOTI_EX_ERROR_INVALID_PARAMETER;
1773 Handle* p = static_cast<Handle*>(handle);
1774 AbstractAction* a = static_cast<AbstractAction*>(action);
1775 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1776 return NOTI_EX_ERROR_NONE;
1779 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1780 noti_ex_style_h *style) {
1781 if (handle == nullptr || style == nullptr) {
1782 LOGE("Invalid parameter");
1783 return NOTI_EX_ERROR_INVALID_PARAMETER;
1786 Handle* p = static_cast<Handle*>(handle);
1787 shared_ptr<Style> s = p->Get()->GetStyle();
1788 if (s.get() == nullptr) {
1789 LOGE("Style is null");
1790 return NOTI_EX_ERROR_INVALID_PARAMETER;
1793 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1794 if (ptr == nullptr || ptr->get() == nullptr) {
1795 LOGE("Out of memory");
1796 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1800 return NOTI_EX_ERROR_NONE;
1803 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1804 noti_ex_style_h style) {
1805 if (handle == nullptr || style == nullptr) {
1806 LOGE("Invalid parameter");
1807 return NOTI_EX_ERROR_INVALID_PARAMETER;
1810 Handle* p = static_cast<Handle*>(handle);
1811 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1812 p->Get()->SetStyle(*s);
1813 return NOTI_EX_ERROR_NONE;
1816 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1818 if (handle == nullptr) {
1819 LOGE("Invalid parameter");
1820 return NOTI_EX_ERROR_INVALID_PARAMETER;
1823 Handle* p = static_cast<Handle*>(handle);
1824 p->Get()->SetVisible(visible);
1825 return NOTI_EX_ERROR_NONE;
1828 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1830 if (handle == nullptr || visible == nullptr) {
1831 LOGE("Invalid parameter");
1832 return NOTI_EX_ERROR_INVALID_PARAMETER;
1835 Handle* p = static_cast<Handle*>(handle);
1836 *visible = p->Get()->GetVisible();
1837 return NOTI_EX_ERROR_NONE;
1840 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1842 if (handle == nullptr) {
1843 LOGE("Invalid parameter");
1844 return NOTI_EX_ERROR_INVALID_PARAMETER;
1847 Handle* p = static_cast<Handle*>(handle);
1848 p->Get()->SetEnable(enable);
1849 return NOTI_EX_ERROR_NONE;
1852 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1854 if (handle == nullptr || enable == nullptr) {
1855 LOGE("Invalid parameter");
1856 return NOTI_EX_ERROR_INVALID_PARAMETER;
1859 Handle* p = static_cast<Handle*>(handle);
1860 *enable = p->Get()->GetEnable();
1861 return NOTI_EX_ERROR_NONE;
1864 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1865 const char *receiver_group) {
1866 if (handle == nullptr || receiver_group == nullptr) {
1867 LOGE("Invalid parameter");
1868 return NOTI_EX_ERROR_INVALID_PARAMETER;
1871 Handle* p = static_cast<Handle*>(handle);
1872 p->Get()->AddReceiver(receiver_group);
1873 return NOTI_EX_ERROR_NONE;
1876 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1877 const char *receiver_group) {
1878 if (handle == nullptr || receiver_group == nullptr) {
1879 LOGE("Invalid parameter");
1880 return NOTI_EX_ERROR_INVALID_PARAMETER;
1883 Handle* p = static_cast<Handle*>(handle);
1884 p->Get()->RemoveReceiver(receiver_group);
1885 return NOTI_EX_ERROR_NONE;
1888 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1889 char ***receiver_list, int *count) {
1890 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1891 LOGE("Invalid parameter");
1892 return NOTI_EX_ERROR_INVALID_PARAMETER;
1895 Handle* p = static_cast<Handle*>(handle);
1896 list<string> receivers = p->Get()->GetReceiverList();
1897 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
1898 if (tmp_list == nullptr) {
1899 LOGE("Out of memory");
1900 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1904 for (auto& i : receivers) {
1905 tmp_list[idx] = strdup(i.c_str());
1906 if (tmp_list[idx] == nullptr) {
1907 __noti_ex_free_str_array(tmp_list, idx);
1908 LOGE("Out of memory");
1909 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1914 *receiver_list = tmp_list;
1915 *count = receivers.size();
1916 return NOTI_EX_ERROR_NONE;
1919 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1921 if (handle == nullptr) {
1922 LOGE("Invalid parameter");
1923 return NOTI_EX_ERROR_INVALID_PARAMETER;
1926 Handle* p = static_cast<Handle*>(handle);
1927 p->Get()->SetPolicy(policy);
1928 return NOTI_EX_ERROR_NONE;
1931 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1933 if (handle == nullptr || policy == nullptr) {
1934 LOGE("Invalid parameter");
1935 return NOTI_EX_ERROR_INVALID_PARAMETER;
1938 Handle* p = static_cast<Handle*>(handle);
1939 *policy = p->Get()->GetPolicy();
1940 return NOTI_EX_ERROR_NONE;
1943 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1945 if (handle == nullptr || channel == nullptr) {
1946 LOGE("Invalid parameter");
1947 return NOTI_EX_ERROR_INVALID_PARAMETER;
1950 Handle* p = static_cast<Handle*>(handle);
1951 if (!p->Get()->GetChannel().empty())
1952 *channel = strdup(p->Get()->GetChannel().c_str());
1956 return NOTI_EX_ERROR_NONE;
1959 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1960 const char *channel) {
1961 if (handle == nullptr) {
1962 LOGE("Invalid parameter");
1963 return NOTI_EX_ERROR_INVALID_PARAMETER;
1966 Handle* p = static_cast<Handle*>(handle);
1967 p->Get()->SetChannel(channel);
1968 return NOTI_EX_ERROR_NONE;
1971 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1972 noti_ex_led_info_h led) {
1973 if (handle == nullptr) {
1974 LOGE("Invalid parameter");
1975 return NOTI_EX_ERROR_INVALID_PARAMETER;
1978 Handle* p = static_cast<Handle*>(handle);
1979 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1980 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1981 return NOTI_EX_ERROR_NONE;
1984 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1985 noti_ex_led_info_h *led) {
1986 if (handle == nullptr) {
1987 LOGE("Invalid parameter");
1988 return NOTI_EX_ERROR_INVALID_PARAMETER;
1991 Handle* p = static_cast<Handle*>(handle);
1992 if (p->Get()->GetLEDInfo() != nullptr)
1993 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1996 return NOTI_EX_ERROR_NONE;
1999 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2001 if (handle == nullptr) {
2002 LOGE("Invalid parameter");
2003 return NOTI_EX_ERROR_INVALID_PARAMETER;
2006 Handle* p = static_cast<Handle*>(handle);
2007 if (path == nullptr)
2008 p->Get()->SetSoundPath("");
2010 p->Get()->SetSoundPath(path);
2011 return NOTI_EX_ERROR_NONE;
2014 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2016 if (handle == nullptr) {
2017 LOGE("Invalid parameter");
2018 return NOTI_EX_ERROR_INVALID_PARAMETER;
2021 Handle* p = static_cast<Handle*>(handle);
2022 if (path == nullptr)
2023 p->Get()->SetVibrationPath("");
2025 p->Get()->SetVibrationPath(path);
2026 return NOTI_EX_ERROR_NONE;
2029 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2031 if (handle == nullptr || path == nullptr) {
2032 LOGE("Invalid parameter");
2033 return NOTI_EX_ERROR_INVALID_PARAMETER;
2036 Handle* p = static_cast<Handle*>(handle);
2037 if (p->Get()->GetSoundPath().empty())
2040 *path = strdup(p->Get()->GetSoundPath().c_str());
2041 return NOTI_EX_ERROR_NONE;
2044 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2046 if (handle == nullptr || path == nullptr) {
2047 LOGE("Invalid parameter");
2048 return NOTI_EX_ERROR_INVALID_PARAMETER;
2051 Handle* p = static_cast<Handle*>(handle);
2052 if (p->Get()->GetVibrationPath().empty())
2055 *path = strdup(p->Get()->GetVibrationPath().c_str());
2056 return NOTI_EX_ERROR_NONE;
2059 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2060 noti_ex_item_info_h *info) {
2061 if (handle == nullptr || info == nullptr) {
2062 LOGE("Invalid parameter");
2063 return NOTI_EX_ERROR_INVALID_PARAMETER;
2066 Handle* p = static_cast<Handle*>(handle);
2067 if (p->Get()->GetInfo() == nullptr)
2070 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2071 return NOTI_EX_ERROR_NONE;
2074 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2076 if (handle == nullptr || id == nullptr) {
2077 LOGE("Invalid parameter");
2078 return NOTI_EX_ERROR_INVALID_PARAMETER;
2081 Handle* p = static_cast<Handle*>(handle);
2082 if (p->Get()->GetSenderAppId().empty())
2085 *id = strdup(p->Get()->GetSenderAppId().c_str());
2086 return NOTI_EX_ERROR_NONE;
2089 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2091 if (handle == nullptr || tag == nullptr) {
2092 LOGE("Invalid parameter");
2093 return NOTI_EX_ERROR_INVALID_PARAMETER;
2096 Handle* p = static_cast<Handle*>(handle);
2097 if (p->Get()->GetTag().empty())
2100 *tag = strdup(p->Get()->GetTag().c_str());
2101 return NOTI_EX_ERROR_NONE;
2104 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2106 if (handle == nullptr) {
2107 LOGE("Invalid parameter");
2108 return NOTI_EX_ERROR_INVALID_PARAMETER;
2111 Handle* p = static_cast<Handle*>(handle);
2113 p->Get()->SetTag("");
2115 p->Get()->SetTag(tag);
2116 return NOTI_EX_ERROR_NONE;
2119 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2121 if (handle == nullptr || ongoing == nullptr) {
2122 LOGE("Invalid parameter");
2123 return NOTI_EX_ERROR_INVALID_PARAMETER;
2126 Handle* p = static_cast<Handle*>(handle);
2127 *ongoing = p->Get()->GetOnGoingState();
2129 return NOTI_EX_ERROR_NONE;
2132 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2134 if (handle == nullptr) {
2135 LOGE("Invalid parameter");
2136 return NOTI_EX_ERROR_INVALID_PARAMETER;
2139 Handle* p = static_cast<Handle*>(handle);
2140 p->Get()->SetOnGoingState(ongoing);
2142 return NOTI_EX_ERROR_NONE;
2145 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2146 int type, bool* exist) {
2147 if (handle == nullptr || exist == nullptr) {
2148 LOGE("Invalid parameter");
2149 return NOTI_EX_ERROR_INVALID_PARAMETER;
2152 Handle* p = static_cast<Handle*>(handle);
2153 *exist = p->Get()->IsItemTypeExist(type);
2155 return NOTI_EX_ERROR_NONE;
2158 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2160 if (handle == nullptr || type == nullptr) {
2161 LOGE("Invalid parameter");
2162 return NOTI_EX_ERROR_INVALID_PARAMETER;
2165 Handle* p = static_cast<Handle*>(handle);
2166 *type = p->Get()->GetMainType();
2168 return NOTI_EX_ERROR_NONE;
2171 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2172 const char* id, int type) {
2173 if (handle == nullptr || id == nullptr) {
2174 LOGE("Invalid parameter");
2175 return NOTI_EX_ERROR_INVALID_PARAMETER;
2178 Handle* p = static_cast<Handle*>(handle);
2179 if (!(p->Get()->SetMainType(string(id),
2180 static_cast<AbstractItem::MainType>(type))))
2181 return NOTI_EX_ERROR_INVALID_PARAMETER;
2183 return NOTI_EX_ERROR_NONE;
2186 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2187 int type, noti_ex_item_h* item) {
2188 if (handle == nullptr || item == nullptr) {
2189 LOGE("Invalid parameter");
2190 return NOTI_EX_ERROR_INVALID_PARAMETER;
2193 Handle* h = static_cast<Handle*>(handle);
2194 if (!h->IsValidType(AbstractItem::Group)) {
2195 LOGE("Invalid handle type");
2196 return NOTI_EX_ERROR_INVALID_PARAMETER;
2199 GroupItem* p = static_cast<GroupItem*>(h->Get());
2200 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2201 *item = new Handle(&find_item);
2203 return NOTI_EX_ERROR_NONE;
2206 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2207 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2209 if (handle == nullptr) {
2210 LOGE("Invalid parameter");
2211 return NOTI_EX_ERROR_INVALID_PARAMETER;
2214 string receiver_group_str = "";
2216 receiver_group_str = string(receiver_group);
2218 ManagerStub* stub = new (std::nothrow) ManagerStub(
2219 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2220 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2221 receiver_group_str);
2222 if (stub == nullptr) {
2223 LOGE("Fail to create manager");
2224 return NOTI_EX_ERROR_IO_ERROR;
2226 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2227 new ManagerCallbackInfo(event_callbacks, data)));
2228 *handle = static_cast<noti_ex_manager_h>(stub);
2230 return NOTI_EX_ERROR_NONE;
2233 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2234 if (handle == nullptr) {
2235 LOGE("Invalid parameter");
2236 return NOTI_EX_ERROR_INVALID_PARAMETER;
2238 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2240 return NOTI_EX_ERROR_NONE;
2243 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2244 noti_ex_item_h **items, int *count) {
2245 if (handle == nullptr || items == nullptr || count == nullptr) {
2246 LOGE("Invalid parameter");
2247 return NOTI_EX_ERROR_INVALID_PARAMETER;
2251 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2252 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2253 if (item_list.size() == 0) {
2256 return NOTI_EX_ERROR_NONE;
2258 noti_ex_item_h* added_item =
2259 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2260 if (added_item == nullptr) {
2261 LOGE("Fail to create items");
2262 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2266 for (auto& i : item_list) {
2267 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2269 *items = added_item;
2270 *count = item_list.size();
2271 } catch (Exception &ex) {
2272 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2273 return NOTI_EX_ERROR_IO_ERROR;
2275 return NOTI_EX_ERROR_NONE;
2278 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2279 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2280 if (handle == nullptr || channel == nullptr ||
2281 items == nullptr || count == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2287 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2288 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2289 if (item_list.size() == 0) {
2292 return NOTI_EX_ERROR_NONE;
2294 noti_ex_item_h* added_item =
2295 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2296 if (added_item == nullptr) {
2297 LOGE("Fail to create items");
2298 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2302 for (auto& i : item_list) {
2303 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2305 *items = added_item;
2306 *count = item_list.size();
2307 } catch (Exception &ex) {
2308 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2309 return NOTI_EX_ERROR_IO_ERROR;
2312 return NOTI_EX_ERROR_NONE;
2315 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2316 noti_ex_item_h noti, int *request_id) {
2317 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2318 LOGE("Invalid parameter");
2319 return NOTI_EX_ERROR_INVALID_PARAMETER;
2322 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2323 Handle* sp = static_cast<Handle*>(noti);
2324 if (sp->GetPtr().get() == nullptr) {
2325 LOGE("Invalid noti reference can not be sended");
2326 return NOTI_EX_ERROR_INVALID_PARAMETER;
2328 *request_id = stub->Update(sp->GetPtr());
2330 } catch (Exception &ex) {
2331 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2332 return NOTI_EX_ERROR_IO_ERROR;
2334 return NOTI_EX_ERROR_NONE;
2337 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2338 noti_ex_item_h noti, int *request_id) {
2339 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2340 LOGE("Invalid parameter");
2341 return NOTI_EX_ERROR_INVALID_PARAMETER;
2344 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2345 Handle* item = static_cast<Handle*>(noti);
2346 if (item->GetPtr().get() == nullptr) {
2347 LOGE("Invalid noti reference can not be sended");
2348 return NOTI_EX_ERROR_INVALID_PARAMETER;
2350 *request_id = stub->Delete(item->GetPtr());
2352 } catch (Exception &ex) {
2353 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2354 return NOTI_EX_ERROR_IO_ERROR;
2356 return NOTI_EX_ERROR_NONE;
2359 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2361 if (handle == nullptr || request_id == nullptr) {
2362 LOGE("Invalid parameter");
2363 return NOTI_EX_ERROR_INVALID_PARAMETER;
2366 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2367 *request_id = stub->DeleteAll();
2368 } catch (Exception &ex) {
2369 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2370 return NOTI_EX_ERROR_IO_ERROR;
2372 return NOTI_EX_ERROR_NONE;
2375 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2376 noti_ex_item_h noti, int *request_id) {
2377 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2378 LOGE("Invalid parameter");
2379 return NOTI_EX_ERROR_INVALID_PARAMETER;
2382 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2383 Handle* item = static_cast<Handle*>(noti);
2384 if (item->GetPtr().get() == nullptr) {
2385 LOGE("Invalid noti reference can not be sended");
2386 return NOTI_EX_ERROR_INVALID_PARAMETER;
2388 *request_id = stub->Hide(item->GetPtr());
2390 } catch (Exception &ex) {
2391 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2392 return NOTI_EX_ERROR_IO_ERROR;
2394 return NOTI_EX_ERROR_NONE;
2397 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2398 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2399 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2400 LOGE("Invalid parameter");
2401 return NOTI_EX_ERROR_INVALID_PARAMETER;
2404 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2405 *item = new Handle(stub->FindByRootID(root_id));
2406 } catch (Exception &ex) {
2407 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2408 return NOTI_EX_ERROR_IO_ERROR;
2410 return NOTI_EX_ERROR_NONE;
2413 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2414 noti_ex_event_info_h info, noti_ex_error_e error) {
2415 if (handle == nullptr || info == nullptr) {
2416 LOGE("Invalid parameter");
2417 return NOTI_EX_ERROR_INVALID_PARAMETER;
2420 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2421 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2422 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2423 static_cast<NotificationError>(error));
2424 } catch (Exception &ex) {
2425 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2426 return NOTI_EX_ERROR_IO_ERROR;
2428 return NOTI_EX_ERROR_NONE;
2431 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2432 noti_ex_manager_h handle, int *cnt) {
2434 if (handle == nullptr || cnt == nullptr) {
2435 LOGE("Invalid parameter");
2436 return NOTI_EX_ERROR_INVALID_PARAMETER;
2439 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2440 *cnt = stub->GetCount();
2441 } catch (Exception &ex) {
2442 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2443 return NOTI_EX_ERROR_IO_ERROR;
2445 return NOTI_EX_ERROR_NONE;
2448 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2449 const char *id, float min, float current, float max) {
2452 if (handle == nullptr) {
2453 LOGE("Invalid parameter");
2454 return NOTI_EX_ERROR_INVALID_PARAMETER;
2458 p = new (std::nothrow) ProgressItem(id, min, current, max);
2460 p = new (std::nothrow) ProgressItem(min, current, max);
2463 LOGE("Out-of-memory");
2464 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2467 *handle = new Handle(shared_ptr<AbstractItem>(p));
2469 return NOTI_EX_ERROR_NONE;
2472 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2473 noti_ex_item_h handle, float *current) {
2474 if (handle == nullptr || current == nullptr) {
2475 LOGE("Invalid parameter");
2476 return NOTI_EX_ERROR_INVALID_PARAMETER;
2479 Handle *h = static_cast<Handle*>(handle);
2480 if (!h->IsValidType(AbstractItem::Progress)) {
2481 LOGE("Invalid handle type");
2482 return NOTI_EX_ERROR_INVALID_PARAMETER;
2484 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2485 *current = p->GetCurrent();
2487 return NOTI_EX_ERROR_NONE;
2490 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2491 noti_ex_item_h handle, float current) {
2492 if (handle == nullptr) {
2493 LOGE("Invalid parameter");
2494 return NOTI_EX_ERROR_INVALID_PARAMETER;
2497 Handle *h = static_cast<Handle*>(handle);
2498 if (!h->IsValidType(AbstractItem::Progress)) {
2499 LOGE("Invalid handle type");
2500 return NOTI_EX_ERROR_INVALID_PARAMETER;
2502 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2503 p->SetCurrent(current);
2505 return NOTI_EX_ERROR_NONE;
2508 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2510 if (handle == nullptr || min == nullptr) {
2511 LOGE("Invalid parameter");
2512 return NOTI_EX_ERROR_INVALID_PARAMETER;
2515 Handle *h = static_cast<Handle*>(handle);
2516 if (!h->IsValidType(AbstractItem::Progress)) {
2517 LOGE("Invalid handle type");
2518 return NOTI_EX_ERROR_INVALID_PARAMETER;
2520 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2523 return NOTI_EX_ERROR_NONE;
2526 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2528 if (handle == nullptr || max == nullptr) {
2529 LOGE("Invalid parameter");
2530 return NOTI_EX_ERROR_INVALID_PARAMETER;
2533 Handle *h = static_cast<Handle*>(handle);
2534 if (!h->IsValidType(AbstractItem::Progress)) {
2535 LOGE("Invalid handle type");
2536 return NOTI_EX_ERROR_INVALID_PARAMETER;
2538 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2541 return NOTI_EX_ERROR_NONE;
2544 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2546 if (handle == nullptr || type == nullptr) {
2547 LOGE("Invalid parameter");
2548 return NOTI_EX_ERROR_INVALID_PARAMETER;
2551 Handle *h = static_cast<Handle*>(handle);
2552 if (!h->IsValidType(AbstractItem::Progress)) {
2553 LOGE("Invalid handle type");
2554 return NOTI_EX_ERROR_INVALID_PARAMETER;
2556 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2557 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2559 return NOTI_EX_ERROR_NONE;
2562 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2564 if (handle == nullptr) {
2565 LOGE("Invalid parameter");
2566 return NOTI_EX_ERROR_INVALID_PARAMETER;
2569 Handle *h = static_cast<Handle*>(handle);
2570 if (!h->IsValidType(AbstractItem::Progress)) {
2571 LOGE("Invalid handle type");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2574 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2575 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2577 return NOTI_EX_ERROR_NONE;
2580 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2581 noti_ex_reporter_events_s event_callbacks, void *data) {
2582 if (handle == nullptr) {
2583 LOGE("Invalid parameter");
2584 return NOTI_EX_ERROR_INVALID_PARAMETER;
2587 ReporterStub* stub = new (std::nothrow) ReporterStub(
2588 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2589 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2590 if (stub == nullptr) {
2591 LOGE("Fail to create manager");
2592 return NOTI_EX_ERROR_IO_ERROR;
2594 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2595 new ReporterCallbackInfo(event_callbacks, data)));
2597 *handle = static_cast<noti_ex_reporter_h>(stub);
2599 return NOTI_EX_ERROR_NONE;
2602 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2603 if (handle == nullptr) {
2604 LOGE("Invalid parameter");
2605 return NOTI_EX_ERROR_INVALID_PARAMETER;
2607 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2609 return NOTI_EX_ERROR_NONE;
2612 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2613 noti_ex_event_info_h info, noti_ex_error_e error) {
2614 if (handle == nullptr || info == nullptr) {
2615 LOGE("Invalid parameter");
2616 return NOTI_EX_ERROR_INVALID_PARAMETER;
2619 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2620 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2621 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2622 static_cast<NotificationError>(error));
2623 } catch (Exception &ex) {
2624 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2625 return NOTI_EX_ERROR_IO_ERROR;
2627 return NOTI_EX_ERROR_NONE;
2630 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2631 noti_ex_item_h noti, int *request_id) {
2632 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2633 LOGE("Invalid parameter");
2634 return NOTI_EX_ERROR_INVALID_PARAMETER;
2637 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2638 Handle* h = static_cast<Handle*>(noti);
2639 if (h->GetPtr().get() == nullptr) {
2640 LOGE("Invalid noti reference can not be sended");
2641 return NOTI_EX_ERROR_INVALID_PARAMETER;
2643 *request_id = stub->Post(h->GetPtr());
2645 } catch (Exception &ex) {
2646 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2647 return NOTI_EX_ERROR_IO_ERROR;
2649 return NOTI_EX_ERROR_NONE;
2652 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2653 noti_ex_item_h *noti_list, int count, int *request_id) {
2655 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2656 LOGE("Invalid parameter");
2657 return NOTI_EX_ERROR_INVALID_PARAMETER;
2660 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2661 list<shared_ptr<item::AbstractItem>> notiList;
2662 for (int i = 0; i < count; i++) {
2663 Handle* item = static_cast<Handle*>(noti_list[i]);
2664 notiList.push_back(item->GetPtr());
2666 *request_id = stub->Post(notiList);
2667 } catch (Exception &ex) {
2668 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2669 return NOTI_EX_ERROR_IO_ERROR;
2671 return NOTI_EX_ERROR_NONE;
2674 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2675 noti_ex_item_h noti, int *request_id) {
2676 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2677 LOGE("Invalid parameter");
2678 return NOTI_EX_ERROR_INVALID_PARAMETER;
2681 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2682 Handle* item = static_cast<Handle*>(noti);
2683 if (item->GetPtr().get() == nullptr) {
2684 LOGE("Invalid noti reference can not be sended");
2685 return NOTI_EX_ERROR_INVALID_PARAMETER;
2687 *request_id = stub->Update(item->GetPtr());
2689 } catch (Exception &ex) {
2690 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2691 return NOTI_EX_ERROR_IO_ERROR;
2693 return NOTI_EX_ERROR_NONE;
2696 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2697 noti_ex_item_h noti, int *request_id) {
2698 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2699 LOGE("Invalid parameter");
2700 return NOTI_EX_ERROR_INVALID_PARAMETER;
2703 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2704 Handle* item = static_cast<Handle*>(noti);
2705 if (item->GetPtr().get() == nullptr) {
2706 LOGE("Invalid noti reference can not be sended");
2707 return NOTI_EX_ERROR_INVALID_PARAMETER;
2709 *request_id = stub->Delete(item->GetPtr());
2711 } catch (Exception &ex) {
2712 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2713 return NOTI_EX_ERROR_IO_ERROR;
2715 return NOTI_EX_ERROR_NONE;
2718 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2719 noti_ex_reporter_h handle, int *request_id) {
2720 if (handle == nullptr || request_id == nullptr) {
2721 LOGE("Invalid parameter");
2722 return NOTI_EX_ERROR_INVALID_PARAMETER;
2725 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2726 *request_id = stub->DeleteAll();
2727 } catch (Exception &ex) {
2728 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2729 return NOTI_EX_ERROR_IO_ERROR;
2731 return NOTI_EX_ERROR_NONE;
2734 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2735 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2736 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2737 LOGE("Invalid parameter");
2738 return NOTI_EX_ERROR_INVALID_PARAMETER;
2741 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2742 *item = new Handle(stub->FindByRootID(root_id));
2743 } catch (Exception &ex) {
2744 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2745 return NOTI_EX_ERROR_IO_ERROR;
2747 return NOTI_EX_ERROR_NONE;
2750 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2751 const char *id, const char *text, const char *hyperlink) {
2752 if (handle == nullptr || text == nullptr) {
2753 LOGE("Invalid parameter");
2754 return NOTI_EX_ERROR_INVALID_PARAMETER;
2760 p = new (std::nothrow) TextItem(id, std::string(text),
2761 std::string(hyperlink));
2763 p = new (std::nothrow) TextItem(id, std::string(text));
2766 LOGE("Out-of-memory");
2767 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2770 *handle = new Handle(shared_ptr<AbstractItem>(p));
2772 return NOTI_EX_ERROR_NONE;
2775 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2776 const char *contents) {
2777 if (handle == nullptr || contents == nullptr) {
2778 LOGE("Invalid parameter");
2779 return NOTI_EX_ERROR_INVALID_PARAMETER;
2782 Handle* p = static_cast<Handle*>(handle);
2783 if (!p->IsValidType(AbstractItem::Text)) {
2784 LOGE("Invalid handle type");
2785 return NOTI_EX_ERROR_INVALID_PARAMETER;
2787 TextItem* ti = static_cast<TextItem*>(p->Get());
2788 ti->SetContents(std::string(contents));
2790 return NOTI_EX_ERROR_NONE;
2793 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2795 if (handle == nullptr || contents == nullptr) {
2796 LOGE("Invalid parameter");
2797 return NOTI_EX_ERROR_INVALID_PARAMETER;
2800 Handle* p = static_cast<Handle*>(handle);
2801 if (!p->IsValidType(AbstractItem::Text)) {
2802 LOGE("Invalid handle type");
2803 return NOTI_EX_ERROR_INVALID_PARAMETER;
2805 TextItem* ti = static_cast<TextItem*>(p->Get());
2806 if (!ti->GetContents().empty()) {
2807 *contents = strdup(ti->GetContents().c_str());
2808 if (*contents == nullptr) {
2809 LOGE("Out-of-memory");
2810 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2814 return NOTI_EX_ERROR_NONE;
2817 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2818 noti_ex_item_h handle, char **hyper_link) {
2819 if (handle == nullptr || hyper_link == nullptr) {
2820 LOGE("Invalid parameter");
2821 return NOTI_EX_ERROR_INVALID_PARAMETER;
2824 Handle* p = static_cast<Handle*>(handle);
2825 if (!p->IsValidType(AbstractItem::Text)) {
2826 LOGE("Invalid handle type");
2827 return NOTI_EX_ERROR_INVALID_PARAMETER;
2829 TextItem* ti = static_cast<TextItem*>(p->Get());
2830 if (!ti->GetHyperLink().empty()) {
2831 *hyper_link = strdup(ti->GetHyperLink().c_str());
2832 if (*hyper_link == nullptr) {
2833 LOGE("Out-of-memory");
2834 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2838 return NOTI_EX_ERROR_NONE;
2841 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2842 const char *id, time_t time) {
2845 if (handle == nullptr) {
2846 LOGE("Invalid parameter");
2847 return NOTI_EX_ERROR_INVALID_PARAMETER;
2852 p = new (std::nothrow) TimeItem(id, time);
2854 p = new (std::nothrow) TimeItem(time);
2856 p = new (std::nothrow) TimeItem();
2860 LOGE("Out-of-memory");
2861 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2864 *handle = new Handle(shared_ptr<AbstractItem>(p));
2866 return NOTI_EX_ERROR_NONE;
2869 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2871 if (handle == nullptr || time == nullptr) {
2872 LOGE("Invalid parameter");
2873 return NOTI_EX_ERROR_INVALID_PARAMETER;
2875 Handle* h = static_cast<Handle*>(handle);
2876 if (!h->IsValidType(AbstractItem::Time)) {
2877 LOGE("Invalid handle type");
2878 return NOTI_EX_ERROR_INVALID_PARAMETER;
2880 TimeItem* p = static_cast<TimeItem*>(h->Get());
2881 *time = p->GetTime();
2883 return NOTI_EX_ERROR_NONE;
2886 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2887 noti_ex_action_h *handle, const char *extra) {
2888 if (handle == nullptr) {
2889 LOGE("Invalid parameter");
2890 return NOTI_EX_ERROR_INVALID_PARAMETER;
2893 string extra_str = "";
2895 extra_str = string(extra);
2897 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2899 LOGE("Out-of-memory");
2900 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2905 return NOTI_EX_ERROR_NONE;
2908 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2909 const char *id, bool visible) {
2910 if (handle == nullptr || id == nullptr) {
2911 LOGE("Invalid parameter");
2912 return NOTI_EX_ERROR_INVALID_PARAMETER;
2915 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2916 p->SetVisibility(id, visible);
2918 return NOTI_EX_ERROR_NONE;