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_is_checked(
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_get_check_state(
566 noti_ex_item_h handle, bool *checked) {
567 if (handle == nullptr || checked == nullptr) {
568 LOGE("Invalid parameter");
569 return NOTI_EX_ERROR_INVALID_PARAMETER;
571 Handle* h = static_cast<Handle*>(handle);
572 if (!h->IsValidType(AbstractItem::CheckBox)) {
573 LOGE("Invalid handle type");
574 return NOTI_EX_ERROR_INVALID_PARAMETER;
576 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
577 *checked = p->IsChecked();
579 return NOTI_EX_ERROR_NONE;
582 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
583 noti_ex_item_h handle, bool checked) {
584 if (handle == nullptr) {
585 LOGE("Invalid parameter");
586 return NOTI_EX_ERROR_INVALID_PARAMETER;
589 Handle* h = static_cast<Handle*>(handle);
590 if (!h->IsValidType(AbstractItem::CheckBox)) {
591 LOGE("Invalid handle type");
592 return NOTI_EX_ERROR_INVALID_PARAMETER;
595 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
596 p->SetChecked(checked);
598 return NOTI_EX_ERROR_NONE;
601 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
605 if (handle == nullptr) {
606 LOGE("Invalid parameter");
607 return NOTI_EX_ERROR_INVALID_PARAMETER;
610 p = new (std::nothrow) EntryItem(id);
612 LOGE("Out-of-memory");
613 return NOTI_EX_ERROR_OUT_OF_MEMORY;
616 *handle = new Handle(shared_ptr<AbstractItem>(p));
618 return NOTI_EX_ERROR_NONE;
621 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
623 if (handle == nullptr || text == nullptr) {
624 LOGE("Invalid parameter");
625 return NOTI_EX_ERROR_INVALID_PARAMETER;
628 Handle* h = static_cast<Handle*>(handle);
629 if (!h->IsValidType(AbstractItem::Entry)) {
630 LOGE("Invalid handle type");
631 return NOTI_EX_ERROR_INVALID_PARAMETER;
633 EntryItem* p = static_cast<EntryItem*>(h->Get());
634 if (!p->GetText().empty()) {
635 *text = strdup(p->GetText().c_str());
636 if (*text == nullptr) {
637 LOGE("Out-of-memory");
638 return NOTI_EX_ERROR_OUT_OF_MEMORY;
642 return NOTI_EX_ERROR_NONE;
645 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
647 if (handle == nullptr || text == nullptr) {
648 LOGE("Invalid parameter");
649 return NOTI_EX_ERROR_INVALID_PARAMETER;
651 Handle* h = static_cast<Handle*>(handle);
652 if (!h->IsValidType(AbstractItem::Entry)) {
653 LOGE("Invalid handle type");
654 return NOTI_EX_ERROR_INVALID_PARAMETER;
656 EntryItem* p = static_cast<EntryItem*>(h->Get());
657 p->SetText(std::string(text));
659 return NOTI_EX_ERROR_NONE;
662 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
663 noti_ex_event_info_h* cloned_handle) {
664 if (handle == nullptr || cloned_handle == nullptr) {
665 LOGE("Invalid parameter");
666 return NOTI_EX_ERROR_INVALID_PARAMETER;
669 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
670 EventInfo* info = new EventInfo(cloned);
671 *cloned_handle = info;
672 return NOTI_EX_ERROR_NONE;
675 extern "C" EXPORT_API int noti_ex_event_info_destroy(
676 noti_ex_event_info_h handle) {
677 if (handle == nullptr) {
678 LOGE("Invalid parameter");
679 return NOTI_EX_ERROR_INVALID_PARAMETER;
681 EventInfo* info = static_cast<EventInfo*>(handle);
683 return NOTI_EX_ERROR_NONE;
686 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
687 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
688 if (handle == nullptr || event_type == nullptr) {
689 LOGE("Invalid parameter");
690 return NOTI_EX_ERROR_INVALID_PARAMETER;
692 EventInfo* info = static_cast<EventInfo*>(handle);
693 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
695 return NOTI_EX_ERROR_NONE;
698 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
699 noti_ex_event_info_h handle, char **owner) {
700 if (handle == nullptr || owner == nullptr) {
701 LOGE("Invalid parameter");
702 return NOTI_EX_ERROR_INVALID_PARAMETER;
704 EventInfo* info = static_cast<EventInfo*>(handle);
705 *owner = strdup(info->GetOwner().c_str());
706 return NOTI_EX_ERROR_NONE;
709 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
710 noti_ex_event_info_h handle, char **channel) {
711 if (handle == nullptr || channel == nullptr) {
712 LOGE("Invalid parameter");
713 return NOTI_EX_ERROR_INVALID_PARAMETER;
715 EventInfo* info = static_cast<EventInfo*>(handle);
716 *channel = strdup(info->GetChannel().c_str());
717 return NOTI_EX_ERROR_NONE;
720 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
721 noti_ex_event_info_h handle, char **item_id) {
722 if (handle == nullptr || item_id == nullptr) {
723 LOGE("Invalid parameter");
724 return NOTI_EX_ERROR_INVALID_PARAMETER;
726 EventInfo* info = static_cast<EventInfo*>(handle);
727 *item_id = strdup(info->GetItemId().c_str());
728 return NOTI_EX_ERROR_NONE;
731 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
732 noti_ex_event_info_h handle, int *req_id) {
733 if (handle == nullptr || req_id == nullptr) {
734 LOGE("Invalid parameter");
735 return NOTI_EX_ERROR_INVALID_PARAMETER;
737 EventInfo* info = static_cast<EventInfo*>(handle);
738 *req_id = info->GetRequestId();
739 return NOTI_EX_ERROR_NONE;
742 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
746 if (handle == nullptr) {
747 LOGE("Invalid parameter");
748 return NOTI_EX_ERROR_INVALID_PARAMETER;
752 p = new (std::nothrow) GroupItem(id);
754 p = new (std::nothrow) GroupItem();
757 LOGE("Out-of-memory");
758 return NOTI_EX_ERROR_OUT_OF_MEMORY;
761 *handle = new Handle(shared_ptr<AbstractItem>(p));
763 return NOTI_EX_ERROR_NONE;
766 extern "C" EXPORT_API int noti_ex_item_group_set_direction(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 p->SetDirection(vertical);
780 return NOTI_EX_ERROR_NONE;
783 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(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 *vertical = p->IsVertical();
797 return NOTI_EX_ERROR_NONE;
800 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
802 if (handle == nullptr) {
803 LOGE("Invalid parameter");
804 return NOTI_EX_ERROR_INVALID_PARAMETER;
806 Handle* h = static_cast<Handle*>(handle);
807 if (!h->IsValidType(AbstractItem::Group)) {
808 LOGE("Invalid handle type");
809 return NOTI_EX_ERROR_INVALID_PARAMETER;
811 GroupItem* p = static_cast<GroupItem*>(h->Get());
812 if (!p->GetAppLabel().empty()) {
813 *label = strdup(p->GetAppLabel().c_str());
814 if (*label == nullptr) {
815 LOGE("Out-of-memory");
816 return NOTI_EX_ERROR_OUT_OF_MEMORY;
820 return NOTI_EX_ERROR_NONE;
823 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
824 noti_ex_item_h child) {
825 if (handle == nullptr || child == 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 auto p = static_cast<GroupItem*>(h->Get());
835 p->AddChild((static_cast<Handle*>(child))->GetPtr());
837 return NOTI_EX_ERROR_NONE;
840 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
841 const char *item_id) {
842 if (handle == nullptr || item_id == nullptr) {
843 LOGE("Invalid parameter");
844 return NOTI_EX_ERROR_INVALID_PARAMETER;
846 Handle* h = static_cast<Handle*>(handle);
847 if (!h->IsValidType(AbstractItem::Group)) {
848 LOGE("Invalid handle type");
849 return NOTI_EX_ERROR_INVALID_PARAMETER;
851 GroupItem* p = static_cast<GroupItem*>(h->Get());
852 p->RemoveChild(std::string(item_id));
854 return NOTI_EX_ERROR_NONE;
857 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
858 noti_ex_item_group_foreach_child_cb callback, void *data) {
859 if (handle == nullptr || callback == nullptr) {
860 LOGE("Invalid parameter");
861 return NOTI_EX_ERROR_INVALID_PARAMETER;
864 Handle* h = static_cast<Handle*>(handle);
865 if (!h->IsValidType(AbstractItem::Group)) {
866 LOGE("Invalid handle type");
867 return NOTI_EX_ERROR_INVALID_PARAMETER;
869 GroupItem* p = static_cast<GroupItem*>(h->Get());
870 list<shared_ptr<AbstractItem>> children = p->GetChildren();
871 LOGI("Retrive (%zd)", children.size());
872 for (auto i : children) {
874 static_cast<noti_ex_item_h>(new Handle(i)), data);
875 if (ret != NOTI_EX_ERROR_NONE) {
876 LOGW("callback return (%d) stop foreach", ret);
881 return NOTI_EX_ERROR_NONE;
884 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
885 const char *id, const char *image_path) {
888 if (handle == nullptr || image_path == nullptr) {
889 LOGE("Invalid parameter");
890 return NOTI_EX_ERROR_INVALID_PARAMETER;
894 p = new (std::nothrow) ImageItem(id, image_path);
896 p = new (std::nothrow) ImageItem(image_path);
899 LOGE("Out-of-memory");
900 return NOTI_EX_ERROR_OUT_OF_MEMORY;
903 *handle = new Handle(shared_ptr<AbstractItem>(p));
905 return NOTI_EX_ERROR_NONE;
908 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
909 noti_ex_item_h handle, char **image_path) {
910 if (handle == nullptr || image_path == nullptr) {
911 LOGE("Invalid parameter");
912 return NOTI_EX_ERROR_INVALID_PARAMETER;
914 Handle* h = static_cast<Handle*>(handle);
915 if (!h->IsValidType(AbstractItem::Image)) {
916 LOGE("Invalid handle type");
917 return NOTI_EX_ERROR_INVALID_PARAMETER;
919 ImageItem* p = static_cast<ImageItem*>(h->Get());
920 if (!p->GetImagePath().empty()) {
921 *image_path = strdup(p->GetImagePath().c_str());
922 if (*image_path == nullptr) {
923 LOGE("Out-of-memory");
924 return NOTI_EX_ERROR_OUT_OF_MEMORY;
928 return NOTI_EX_ERROR_NONE;
931 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
932 noti_ex_item_h *handle, const char *id) {
933 InputSelectorItem* p;
935 if (handle == nullptr) {
936 LOGE("Invalid parameter");
937 return NOTI_EX_ERROR_INVALID_PARAMETER;
941 p = new (std::nothrow) InputSelectorItem(id);
943 p = new (std::nothrow) InputSelectorItem();
946 LOGE("Out-of-memory");
947 return NOTI_EX_ERROR_OUT_OF_MEMORY;
950 *handle = new Handle(shared_ptr<AbstractItem>(p));
952 return NOTI_EX_ERROR_NONE;
955 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
956 noti_ex_item_h handle, char ***contents_list, int *count) {
957 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
958 LOGE("Invalid parameter");
959 return NOTI_EX_ERROR_INVALID_PARAMETER;
962 Handle* h = static_cast<Handle*>(handle);
963 if (!h->IsValidType(AbstractItem::InputSelector)) {
964 LOGE("Invalid handle type");
965 return NOTI_EX_ERROR_INVALID_PARAMETER;
967 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
968 list<string> contents = p->GetContents();
969 char **list = (char**)calloc(contents.size(), sizeof(char*));
970 if (list == nullptr) {
971 LOGE("Out of memory");
972 return NOTI_EX_ERROR_OUT_OF_MEMORY;
976 for (auto& i : contents) {
977 list[idx] = strdup(i.c_str());
978 if (list[idx] == nullptr) {
979 __noti_ex_free_str_array(list, idx);
980 LOGE("Out of memory");
981 return NOTI_EX_ERROR_OUT_OF_MEMORY;
986 *count = contents.size();
987 *contents_list = list;
989 return NOTI_EX_ERROR_NONE;
992 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
993 noti_ex_item_h handle, const char **contents, int count) {
994 if (handle == nullptr || contents == nullptr) {
995 LOGE("Invalid parameter");
996 return NOTI_EX_ERROR_INVALID_PARAMETER;
999 list<string> new_contents;
1000 Handle* h = static_cast<Handle*>(handle);
1001 if (!h->IsValidType(AbstractItem::InputSelector)) {
1002 LOGE("Invalid handle type");
1003 return NOTI_EX_ERROR_INVALID_PARAMETER;
1005 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1006 for (int i = 0; i < count; i++) {
1007 new_contents.push_back(contents[i]);
1009 p->SetContents(move(new_contents));
1011 return NOTI_EX_ERROR_NONE;
1014 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1015 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1016 if (handle == nullptr) {
1017 LOGE("Invalid parameter");
1018 return NOTI_EX_ERROR_INVALID_PARAMETER;
1021 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1022 new (std::nothrow) Color(a, r, g, b));
1023 if (ptr == nullptr || ptr->get() == nullptr) {
1024 LOGE("Out-of-memory");
1025 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1030 return NOTI_EX_ERROR_NONE;
1033 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1034 if (handle == nullptr) {
1035 LOGE("Invalid parameter");
1036 return NOTI_EX_ERROR_INVALID_PARAMETER;
1039 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1042 return NOTI_EX_ERROR_NONE;
1045 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1046 unsigned char *val) {
1047 if (handle == nullptr || val == nullptr) {
1048 LOGE("Invalid parameter");
1049 return NOTI_EX_ERROR_INVALID_PARAMETER;
1052 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1053 *val = (*p)->GetAVal();
1055 return NOTI_EX_ERROR_NONE;
1058 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1059 unsigned char *val) {
1060 if (handle == nullptr || val == nullptr) {
1061 LOGE("Invalid parameter");
1062 return NOTI_EX_ERROR_INVALID_PARAMETER;
1065 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1066 *val = (*p)->GetRVal();
1068 return NOTI_EX_ERROR_NONE;
1071 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1072 unsigned char *val) {
1073 if (handle == nullptr || val == nullptr) {
1074 LOGE("Invalid parameter");
1075 return NOTI_EX_ERROR_INVALID_PARAMETER;
1078 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1079 *val = (*p)->GetGVal();
1081 return NOTI_EX_ERROR_NONE;
1084 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1085 unsigned char *val) {
1086 if (handle == nullptr || val == nullptr) {
1087 LOGE("Invalid parameter");
1088 return NOTI_EX_ERROR_INVALID_PARAMETER;
1091 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1092 *val = (*p)->GetBVal();
1094 return NOTI_EX_ERROR_NONE;
1097 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1098 int left, int top, int right, int bottom) {
1099 if (handle == nullptr) {
1100 LOGE("Invalid parameter");
1101 return NOTI_EX_ERROR_INVALID_PARAMETER;
1104 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1105 new (std::nothrow) Padding(left, top, right, bottom));
1106 if (ptr == nullptr || ptr->get() == nullptr) {
1107 LOGE("Out-of-memory");
1108 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1113 return NOTI_EX_ERROR_NONE;
1116 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1117 if (handle == nullptr) {
1118 LOGE("Invalid parameter");
1119 return NOTI_EX_ERROR_INVALID_PARAMETER;
1122 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1125 return NOTI_EX_ERROR_NONE;
1128 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1130 if (handle == nullptr || val == nullptr) {
1131 LOGE("Invalid parameter");
1132 return NOTI_EX_ERROR_INVALID_PARAMETER;
1135 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1136 *val = (*p)->GetLeft();
1138 return NOTI_EX_ERROR_NONE;
1141 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1143 if (handle == nullptr || val == nullptr) {
1144 LOGE("Invalid parameter");
1145 return NOTI_EX_ERROR_INVALID_PARAMETER;
1148 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1149 *val = (*p)->GetTop();
1151 return NOTI_EX_ERROR_NONE;
1154 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1156 if (handle == nullptr || val == nullptr) {
1157 LOGE("Invalid parameter");
1158 return NOTI_EX_ERROR_INVALID_PARAMETER;
1161 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1162 *val = (*p)->GetRight();
1164 return NOTI_EX_ERROR_NONE;
1167 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1169 if (handle == nullptr || val == nullptr) {
1170 LOGE("Invalid parameter");
1171 return NOTI_EX_ERROR_INVALID_PARAMETER;
1174 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1175 *val = (*p)->GetBottom();
1177 return NOTI_EX_ERROR_NONE;
1180 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1181 int x, int y, int w, int h) {
1182 if (handle == nullptr) {
1183 LOGE("Invalid parameter");
1184 return NOTI_EX_ERROR_INVALID_PARAMETER;
1187 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1188 new (std::nothrow) Geometry(x, y, w, h));
1189 if (ptr == nullptr || ptr->get() == nullptr) {
1190 LOGE("Out-of-memory");
1191 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1196 return NOTI_EX_ERROR_NONE;
1199 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1200 if (handle == nullptr) {
1201 LOGE("Invalid parameter");
1202 return NOTI_EX_ERROR_INVALID_PARAMETER;
1205 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1208 return NOTI_EX_ERROR_NONE;
1211 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1213 if (handle == nullptr || val == nullptr) {
1214 LOGE("Invalid parameter");
1215 return NOTI_EX_ERROR_INVALID_PARAMETER;
1218 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1219 *val = (*p)->GetX();
1221 return NOTI_EX_ERROR_NONE;
1224 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1226 if (handle == nullptr || val == nullptr) {
1227 LOGE("Invalid parameter");
1228 return NOTI_EX_ERROR_INVALID_PARAMETER;
1231 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1232 *val = (*p)->GetY();
1234 return NOTI_EX_ERROR_NONE;
1237 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1239 if (handle == nullptr || val == nullptr) {
1240 LOGE("Invalid parameter");
1241 return NOTI_EX_ERROR_INVALID_PARAMETER;
1244 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1245 *val = (*p)->GetWidth();
1247 return NOTI_EX_ERROR_NONE;
1250 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1252 if (handle == nullptr || val == nullptr) {
1253 LOGE("Invalid parameter");
1254 return NOTI_EX_ERROR_INVALID_PARAMETER;
1257 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1258 *val = (*p)->GetHeight();
1260 return NOTI_EX_ERROR_NONE;
1263 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1264 noti_ex_color_h color,
1265 noti_ex_padding_h padding,
1266 noti_ex_geometry_h geometry) {
1267 if (handle == nullptr) {
1268 LOGE("Invalid parameter");
1269 return NOTI_EX_ERROR_INVALID_PARAMETER;
1272 shared_ptr<Color> col = (color == nullptr) ?
1273 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1274 shared_ptr<Padding> padd = (padding == nullptr) ?
1275 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1276 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1277 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1279 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1280 new (std::nothrow) Style(col, padd, geo));
1281 if (ptr == nullptr || ptr->get() == nullptr) {
1282 LOGE("Out-of-memory");
1283 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1288 return NOTI_EX_ERROR_NONE;
1291 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1292 if (handle == nullptr) {
1293 LOGE("Invalid parameter");
1294 return NOTI_EX_ERROR_INVALID_PARAMETER;
1297 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1300 return NOTI_EX_ERROR_NONE;
1303 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1304 noti_ex_padding_h *padding) {
1305 if (handle == nullptr || padding == nullptr) {
1306 LOGE("Invalid parameter");
1307 return NOTI_EX_ERROR_INVALID_PARAMETER;
1310 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1311 if ((*p)->GetPadding() == nullptr) {
1312 LOGW("Padding info is null");
1313 return NOTI_EX_ERROR_INVALID_PARAMETER;
1316 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1317 new (std::nothrow) Padding(*((*p)->GetPadding())));
1318 if (padd == nullptr || padd->get() == nullptr) {
1319 LOGE("Out-of-memory");
1320 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1325 return NOTI_EX_ERROR_NONE;
1328 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1329 noti_ex_color_h *color) {
1330 if (handle == nullptr || color == nullptr) {
1331 LOGE("Invalid parameter");
1332 return NOTI_EX_ERROR_INVALID_PARAMETER;
1335 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1336 if ((*p)->GetColor() == nullptr) {
1337 LOGW("Color info is null");
1338 return NOTI_EX_ERROR_INVALID_PARAMETER;
1341 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1342 new (std::nothrow) Color(*((*p)->GetColor())));
1343 if (col == nullptr || col->get() == nullptr) {
1344 LOGE("Out-of-memory");
1345 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1350 return NOTI_EX_ERROR_NONE;
1353 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1354 noti_ex_geometry_h *geometry) {
1355 if (handle == nullptr || geometry == nullptr) {
1356 LOGE("Invalid parameter");
1357 return NOTI_EX_ERROR_INVALID_PARAMETER;
1360 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1361 if ((*p)->GetGeometry() == nullptr) {
1362 LOGW("Geometry info is null");
1363 return NOTI_EX_ERROR_INVALID_PARAMETER;
1366 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1367 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1368 if (geo == nullptr || geo->get() == nullptr) {
1369 LOGE("Out-of-memory");
1370 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1375 return NOTI_EX_ERROR_NONE;
1378 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1379 noti_ex_style_h handle, char** background_image) {
1380 if (handle == nullptr || background_image == nullptr) {
1381 LOGE("Invalid parameter");
1382 return NOTI_EX_ERROR_INVALID_PARAMETER;
1385 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1386 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1388 return NOTI_EX_ERROR_NONE;
1391 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1392 noti_ex_style_h handle, char* background_image) {
1393 if (handle == nullptr || background_image == nullptr) {
1394 LOGE("Invalid parameter");
1395 return NOTI_EX_ERROR_INVALID_PARAMETER;
1398 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1399 (*p)->SetBackgroundImage(background_image);
1401 return NOTI_EX_ERROR_NONE;
1404 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1405 noti_ex_style_h handle, noti_ex_color_h* color) {
1406 if (handle == nullptr || color == nullptr) {
1407 LOGE("Invalid parameter");
1408 return NOTI_EX_ERROR_INVALID_PARAMETER;
1411 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1412 if ((*p)->GetBackgroundColor() == nullptr) {
1413 LOGW("Color info is null");
1414 return NOTI_EX_ERROR_INVALID_PARAMETER;
1417 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1418 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1419 if (col == nullptr || col->get() == nullptr) {
1420 LOGE("Out-of-memory");
1421 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1426 return NOTI_EX_ERROR_NONE;
1429 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1430 noti_ex_style_h handle, noti_ex_color_h color) {
1431 if (handle == nullptr || color == nullptr) {
1432 LOGE("Invalid parameter");
1433 return NOTI_EX_ERROR_INVALID_PARAMETER;
1436 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1437 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1438 (*p)->SetBackgroundColor(*col);
1440 return NOTI_EX_ERROR_NONE;
1443 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1444 noti_ex_color_h color) {
1445 if (handle == nullptr) {
1446 LOGE("Invalid parameter");
1447 return NOTI_EX_ERROR_INVALID_PARAMETER;
1450 shared_ptr<Color>* color_ = static_cast<shared_ptr<Color>*>(color);
1451 auto* p = new (std::nothrow) LEDInfo(*color_);
1453 LOGE("Out-of-memory");
1454 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1459 return NOTI_EX_ERROR_NONE;
1462 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1463 if (handle == nullptr) {
1464 LOGE("Invalid parameter");
1465 return NOTI_EX_ERROR_INVALID_PARAMETER;
1468 LEDInfo* p = static_cast<LEDInfo*>(handle);
1471 return NOTI_EX_ERROR_NONE;
1474 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1475 noti_ex_led_info_h handle, int ms) {
1476 if (handle == nullptr) {
1477 LOGE("Invalid parameter");
1478 return NOTI_EX_ERROR_INVALID_PARAMETER;
1481 LEDInfo* p = static_cast<LEDInfo*>(handle);
1484 return NOTI_EX_ERROR_NONE;
1487 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1488 noti_ex_led_info_h handle, int *ms) {
1489 if (handle == nullptr || ms == nullptr) {
1490 LOGE("Invalid parameter");
1491 return NOTI_EX_ERROR_INVALID_PARAMETER;
1494 LEDInfo* p = static_cast<LEDInfo*>(handle);
1495 *ms = p->GetOnPeriod();
1497 return NOTI_EX_ERROR_NONE;
1500 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1501 noti_ex_led_info_h handle, int ms) {
1502 if (handle == nullptr) {
1503 LOGE("Invalid parameter");
1504 return NOTI_EX_ERROR_INVALID_PARAMETER;
1507 LEDInfo* p = static_cast<LEDInfo*>(handle);
1508 p->SetOffPeriod(ms);
1510 return NOTI_EX_ERROR_NONE;
1513 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1514 noti_ex_led_info_h handle, int *ms) {
1515 if (handle == nullptr) {
1516 LOGE("Invalid parameter");
1517 return NOTI_EX_ERROR_INVALID_PARAMETER;
1520 LEDInfo* p = static_cast<LEDInfo*>(handle);
1521 *ms = p->GetOffPeriod();
1523 return NOTI_EX_ERROR_NONE;
1526 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1527 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1528 if (handle == nullptr) {
1529 LOGE("Invalid parameter");
1530 return NOTI_EX_ERROR_INVALID_PARAMETER;
1533 LEDInfo* p = static_cast<LEDInfo*>(handle);
1534 if (p->GetColor() == nullptr) {
1535 LOGE("Color is null");
1536 return NOTI_EX_ERROR_INVALID_PARAMETER;
1539 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1540 new (std::nothrow) Color(*(p->GetColor())));
1541 if (col == nullptr || col->get() == nullptr) {
1542 LOGE("Out-of-memory");
1543 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1548 return NOTI_EX_ERROR_NONE;
1551 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1552 if (handle == nullptr) {
1553 LOGE("Invalid parameter");
1554 return NOTI_EX_ERROR_INVALID_PARAMETER;
1557 AbstractAction* p = static_cast<AbstractAction*>(handle);
1558 p->~AbstractAction();
1560 return NOTI_EX_ERROR_NONE;
1563 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1565 if (handle == nullptr || type == nullptr) {
1566 LOGE("Invalid parameter");
1567 return NOTI_EX_ERROR_INVALID_PARAMETER;
1570 AbstractAction* p = static_cast<AbstractAction*>(handle);
1571 *type = p->GetType();
1573 return NOTI_EX_ERROR_NONE;
1576 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1578 if (handle == nullptr || local == nullptr) {
1579 LOGE("Invalid parameter");
1580 return NOTI_EX_ERROR_INVALID_PARAMETER;
1583 AbstractAction* p = static_cast<AbstractAction*>(handle);
1584 *local = p->IsLocal();
1586 return NOTI_EX_ERROR_NONE;
1589 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1590 noti_ex_item_h item) {
1591 if (handle == nullptr || item == nullptr) {
1592 LOGE("Invalid parameter");
1593 return NOTI_EX_ERROR_INVALID_PARAMETER;
1595 AbstractAction* p = static_cast<AbstractAction*>(handle);
1596 Handle* ih = static_cast<Handle*>(item);
1597 p->Execute(ih->GetPtr());
1599 return NOTI_EX_ERROR_NONE;
1602 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1604 if (handle == nullptr || extra == nullptr) {
1605 LOGE("Invalid parameter");
1606 return NOTI_EX_ERROR_INVALID_PARAMETER;
1609 AbstractAction* p = static_cast<AbstractAction*>(handle);
1610 if (!p->GetExtra().empty()) {
1611 *extra = strdup(p->GetExtra().c_str());
1612 if (*extra == nullptr) {
1613 LOGE("Out-of-memory");
1614 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1618 return NOTI_EX_ERROR_NONE;
1621 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1622 noti_ex_item_info_h handle, int *hide_time) {
1623 if (handle == nullptr || hide_time == nullptr) {
1624 LOGE("Invalid parameter");
1625 return NOTI_EX_ERROR_INVALID_PARAMETER;
1627 IItemInfo* p = static_cast<IItemInfo*>(handle);
1628 *hide_time = p->GetHideTime();
1629 return NOTI_EX_ERROR_NONE;
1632 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1633 noti_ex_item_info_h handle, int hide_time) {
1634 if (handle == nullptr) {
1635 LOGE("Invalid parameter");
1636 return NOTI_EX_ERROR_INVALID_PARAMETER;
1638 IItemInfo* p = static_cast<IItemInfo*>(handle);
1639 p->SetHideTime(hide_time);
1640 return NOTI_EX_ERROR_NONE;
1643 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1644 noti_ex_item_info_h handle, int *delete_time) {
1645 if (handle == nullptr || delete_time == nullptr) {
1646 LOGE("Invalid parameter");
1647 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 IItemInfo* p = static_cast<IItemInfo*>(handle);
1650 *delete_time = p->GetDeleteTime();
1651 return NOTI_EX_ERROR_NONE;
1654 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1655 noti_ex_item_info_h handle, int delete_time) {
1656 if (handle == nullptr) {
1657 LOGE("Invalid parameter");
1658 return NOTI_EX_ERROR_INVALID_PARAMETER;
1660 IItemInfo* p = static_cast<IItemInfo*>(handle);
1661 p->SetDeleteTime(delete_time);
1662 return NOTI_EX_ERROR_NONE;
1665 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1666 noti_ex_item_info_h handle, time_t *time) {
1667 if (handle == nullptr || time == nullptr) {
1668 LOGE("Invalid parameter");
1669 return NOTI_EX_ERROR_INVALID_PARAMETER;
1672 IItemInfo* p = static_cast<IItemInfo*>(handle);
1673 *time = p->GetTime();
1674 return NOTI_EX_ERROR_NONE;
1677 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1678 if (handle == nullptr) {
1679 LOGE("Invalid parameter");
1680 return NOTI_EX_ERROR_INVALID_PARAMETER;
1683 Handle* h = static_cast<Handle*>(handle);
1685 return NOTI_EX_ERROR_NONE;
1688 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1689 const char *id, noti_ex_item_h *item) {
1690 if (handle == nullptr) {
1691 LOGE("Invalid parameter");
1692 return NOTI_EX_ERROR_INVALID_PARAMETER;
1695 Handle* p = static_cast<Handle*>(handle);
1696 AbstractItem& find_item = p->Get()->FindByID(string(id));
1697 *item = new Handle(&find_item);
1698 return NOTI_EX_ERROR_NONE;
1701 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1703 if (handle == nullptr || type == nullptr) {
1704 LOGE("Invalid parameter");
1705 return NOTI_EX_ERROR_INVALID_PARAMETER;
1708 Handle* h = static_cast<Handle*>(handle);
1709 AbstractItem* p = h->Get();
1710 *type = p->GetType();
1711 return NOTI_EX_ERROR_NONE;
1714 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1715 char ***path, int *count) {
1716 if (handle == nullptr || path == nullptr || count == nullptr) {
1717 LOGE("Invalid parameter");
1718 return NOTI_EX_ERROR_INVALID_PARAMETER;
1720 Handle* p = static_cast<Handle*>(handle);
1721 list<string> shared_path = p->Get()->GetSharedPath();
1722 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1723 if (tmp_path == nullptr) {
1724 LOGE("Fail to create items");
1725 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1729 for (auto& i : shared_path) {
1730 tmp_path[idx] = strdup(i.c_str());
1731 if (tmp_path[idx] == nullptr) {
1732 __noti_ex_free_str_array(tmp_path, idx);
1733 LOGE("Out of memory");
1734 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1740 *count = shared_path.size();
1741 return NOTI_EX_ERROR_NONE;
1744 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1746 if (handle == nullptr || id == nullptr) {
1747 LOGE("Invalid parameter");
1748 return NOTI_EX_ERROR_INVALID_PARAMETER;
1750 Handle* h = static_cast<Handle*>(handle);
1751 AbstractItem* p = h->Get();
1752 *id = strdup(p->GetId().c_str());
1753 return NOTI_EX_ERROR_NONE;
1756 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1758 if (handle == nullptr || id == nullptr) {
1759 LOGE("Invalid parameter");
1760 return NOTI_EX_ERROR_INVALID_PARAMETER;
1762 Handle* p = static_cast<Handle*>(handle);
1763 p->Get()->SetId(id);
1764 return NOTI_EX_ERROR_NONE;
1767 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1768 noti_ex_action_h *action) {
1769 if (handle == nullptr || action == nullptr) {
1770 LOGE("Invalid parameter");
1771 return NOTI_EX_ERROR_INVALID_PARAMETER;
1773 Handle* p = static_cast<Handle*>(handle);
1774 if (p->Get()->GetAction() == nullptr) {
1776 return NOTI_EX_ERROR_NONE;
1778 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1780 return NOTI_EX_ERROR_NONE;
1783 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1784 noti_ex_action_h action) {
1785 if (handle == nullptr || action == nullptr) {
1786 LOGE("Invalid parameter");
1787 return NOTI_EX_ERROR_INVALID_PARAMETER;
1790 Handle* p = static_cast<Handle*>(handle);
1791 AbstractAction* a = static_cast<AbstractAction*>(action);
1792 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1793 return NOTI_EX_ERROR_NONE;
1796 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1797 noti_ex_style_h *style) {
1798 if (handle == nullptr || style == nullptr) {
1799 LOGE("Invalid parameter");
1800 return NOTI_EX_ERROR_INVALID_PARAMETER;
1803 Handle* p = static_cast<Handle*>(handle);
1804 shared_ptr<Style> s = p->Get()->GetStyle();
1805 if (s.get() == nullptr) {
1806 LOGE("Style is null");
1807 return NOTI_EX_ERROR_INVALID_PARAMETER;
1810 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1811 if (ptr == nullptr || ptr->get() == nullptr) {
1812 LOGE("Out of memory");
1813 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1817 return NOTI_EX_ERROR_NONE;
1820 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1821 noti_ex_style_h style) {
1822 if (handle == nullptr || style == nullptr) {
1823 LOGE("Invalid parameter");
1824 return NOTI_EX_ERROR_INVALID_PARAMETER;
1827 Handle* p = static_cast<Handle*>(handle);
1828 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1829 p->Get()->SetStyle(*s);
1830 return NOTI_EX_ERROR_NONE;
1833 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1835 if (handle == nullptr) {
1836 LOGE("Invalid parameter");
1837 return NOTI_EX_ERROR_INVALID_PARAMETER;
1840 Handle* p = static_cast<Handle*>(handle);
1841 p->Get()->SetVisible(visible);
1842 return NOTI_EX_ERROR_NONE;
1845 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1847 if (handle == nullptr || visible == nullptr) {
1848 LOGE("Invalid parameter");
1849 return NOTI_EX_ERROR_INVALID_PARAMETER;
1852 Handle* p = static_cast<Handle*>(handle);
1853 *visible = p->Get()->GetVisible();
1854 return NOTI_EX_ERROR_NONE;
1857 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1859 if (handle == nullptr) {
1860 LOGE("Invalid parameter");
1861 return NOTI_EX_ERROR_INVALID_PARAMETER;
1864 Handle* p = static_cast<Handle*>(handle);
1865 p->Get()->SetEnable(enable);
1866 return NOTI_EX_ERROR_NONE;
1869 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1871 if (handle == nullptr || enable == nullptr) {
1872 LOGE("Invalid parameter");
1873 return NOTI_EX_ERROR_INVALID_PARAMETER;
1876 Handle* p = static_cast<Handle*>(handle);
1877 *enable = p->Get()->GetEnable();
1878 return NOTI_EX_ERROR_NONE;
1881 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1882 const char *receiver_group) {
1883 if (handle == nullptr || receiver_group == nullptr) {
1884 LOGE("Invalid parameter");
1885 return NOTI_EX_ERROR_INVALID_PARAMETER;
1888 Handle* p = static_cast<Handle*>(handle);
1889 p->Get()->AddReceiver(receiver_group);
1890 return NOTI_EX_ERROR_NONE;
1893 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1894 const char *receiver_group) {
1895 if (handle == nullptr || receiver_group == nullptr) {
1896 LOGE("Invalid parameter");
1897 return NOTI_EX_ERROR_INVALID_PARAMETER;
1900 Handle* p = static_cast<Handle*>(handle);
1901 p->Get()->RemoveReceiver(receiver_group);
1902 return NOTI_EX_ERROR_NONE;
1905 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1906 char ***receiver_list, int *count) {
1907 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1908 LOGE("Invalid parameter");
1909 return NOTI_EX_ERROR_INVALID_PARAMETER;
1912 Handle* p = static_cast<Handle*>(handle);
1913 list<string> receivers = p->Get()->GetReceiverList();
1914 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
1915 if (tmp_list == nullptr) {
1916 LOGE("Out of memory");
1917 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1921 for (auto& i : receivers) {
1922 tmp_list[idx] = strdup(i.c_str());
1923 if (tmp_list[idx] == nullptr) {
1924 __noti_ex_free_str_array(tmp_list, idx);
1925 LOGE("Out of memory");
1926 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1931 *receiver_list = tmp_list;
1932 *count = receivers.size();
1933 return NOTI_EX_ERROR_NONE;
1936 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1938 if (handle == nullptr) {
1939 LOGE("Invalid parameter");
1940 return NOTI_EX_ERROR_INVALID_PARAMETER;
1943 Handle* p = static_cast<Handle*>(handle);
1944 p->Get()->SetPolicy(policy);
1945 return NOTI_EX_ERROR_NONE;
1948 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1950 if (handle == nullptr || policy == nullptr) {
1951 LOGE("Invalid parameter");
1952 return NOTI_EX_ERROR_INVALID_PARAMETER;
1955 Handle* p = static_cast<Handle*>(handle);
1956 *policy = p->Get()->GetPolicy();
1957 return NOTI_EX_ERROR_NONE;
1960 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1962 if (handle == nullptr || channel == nullptr) {
1963 LOGE("Invalid parameter");
1964 return NOTI_EX_ERROR_INVALID_PARAMETER;
1967 Handle* p = static_cast<Handle*>(handle);
1968 if (!p->Get()->GetChannel().empty())
1969 *channel = strdup(p->Get()->GetChannel().c_str());
1973 return NOTI_EX_ERROR_NONE;
1976 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1977 const char *channel) {
1978 if (handle == nullptr) {
1979 LOGE("Invalid parameter");
1980 return NOTI_EX_ERROR_INVALID_PARAMETER;
1983 Handle* p = static_cast<Handle*>(handle);
1984 p->Get()->SetChannel(channel);
1985 return NOTI_EX_ERROR_NONE;
1988 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1989 noti_ex_led_info_h led) {
1990 if (handle == nullptr) {
1991 LOGE("Invalid parameter");
1992 return NOTI_EX_ERROR_INVALID_PARAMETER;
1995 Handle* p = static_cast<Handle*>(handle);
1996 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1997 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1998 return NOTI_EX_ERROR_NONE;
2001 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2002 noti_ex_led_info_h *led) {
2003 if (handle == nullptr) {
2004 LOGE("Invalid parameter");
2005 return NOTI_EX_ERROR_INVALID_PARAMETER;
2008 Handle* p = static_cast<Handle*>(handle);
2009 if (p->Get()->GetLEDInfo() != nullptr)
2010 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
2013 return NOTI_EX_ERROR_NONE;
2016 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2018 if (handle == nullptr) {
2019 LOGE("Invalid parameter");
2020 return NOTI_EX_ERROR_INVALID_PARAMETER;
2023 Handle* p = static_cast<Handle*>(handle);
2024 if (path == nullptr)
2025 p->Get()->SetSoundPath("");
2027 p->Get()->SetSoundPath(path);
2028 return NOTI_EX_ERROR_NONE;
2031 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2033 if (handle == nullptr) {
2034 LOGE("Invalid parameter");
2035 return NOTI_EX_ERROR_INVALID_PARAMETER;
2038 Handle* p = static_cast<Handle*>(handle);
2039 if (path == nullptr)
2040 p->Get()->SetVibrationPath("");
2042 p->Get()->SetVibrationPath(path);
2043 return NOTI_EX_ERROR_NONE;
2046 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2048 if (handle == nullptr || path == nullptr) {
2049 LOGE("Invalid parameter");
2050 return NOTI_EX_ERROR_INVALID_PARAMETER;
2053 Handle* p = static_cast<Handle*>(handle);
2054 if (p->Get()->GetSoundPath().empty())
2057 *path = strdup(p->Get()->GetSoundPath().c_str());
2058 return NOTI_EX_ERROR_NONE;
2061 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2063 if (handle == nullptr || path == nullptr) {
2064 LOGE("Invalid parameter");
2065 return NOTI_EX_ERROR_INVALID_PARAMETER;
2068 Handle* p = static_cast<Handle*>(handle);
2069 if (p->Get()->GetVibrationPath().empty())
2072 *path = strdup(p->Get()->GetVibrationPath().c_str());
2073 return NOTI_EX_ERROR_NONE;
2076 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2077 noti_ex_item_info_h *info) {
2078 if (handle == nullptr || info == nullptr) {
2079 LOGE("Invalid parameter");
2080 return NOTI_EX_ERROR_INVALID_PARAMETER;
2083 Handle* p = static_cast<Handle*>(handle);
2084 if (p->Get()->GetInfo() == nullptr)
2087 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2088 return NOTI_EX_ERROR_NONE;
2091 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2093 if (handle == nullptr || id == nullptr) {
2094 LOGE("Invalid parameter");
2095 return NOTI_EX_ERROR_INVALID_PARAMETER;
2098 Handle* p = static_cast<Handle*>(handle);
2099 if (p->Get()->GetSenderAppId().empty())
2102 *id = strdup(p->Get()->GetSenderAppId().c_str());
2103 return NOTI_EX_ERROR_NONE;
2106 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2108 if (handle == nullptr || tag == nullptr) {
2109 LOGE("Invalid parameter");
2110 return NOTI_EX_ERROR_INVALID_PARAMETER;
2113 Handle* p = static_cast<Handle*>(handle);
2114 if (p->Get()->GetTag().empty())
2117 *tag = strdup(p->Get()->GetTag().c_str());
2118 return NOTI_EX_ERROR_NONE;
2121 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2123 if (handle == nullptr) {
2124 LOGE("Invalid parameter");
2125 return NOTI_EX_ERROR_INVALID_PARAMETER;
2128 Handle* p = static_cast<Handle*>(handle);
2130 p->Get()->SetTag("");
2132 p->Get()->SetTag(tag);
2133 return NOTI_EX_ERROR_NONE;
2136 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2138 if (handle == nullptr || ongoing == nullptr) {
2139 LOGE("Invalid parameter");
2140 return NOTI_EX_ERROR_INVALID_PARAMETER;
2143 Handle* p = static_cast<Handle*>(handle);
2144 *ongoing = p->Get()->GetOnGoingState();
2146 return NOTI_EX_ERROR_NONE;
2149 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2151 if (handle == nullptr) {
2152 LOGE("Invalid parameter");
2153 return NOTI_EX_ERROR_INVALID_PARAMETER;
2156 Handle* p = static_cast<Handle*>(handle);
2157 p->Get()->SetOnGoingState(ongoing);
2159 return NOTI_EX_ERROR_NONE;
2162 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2163 int type, bool* exist) {
2164 if (handle == nullptr || exist == nullptr) {
2165 LOGE("Invalid parameter");
2166 return NOTI_EX_ERROR_INVALID_PARAMETER;
2169 Handle* p = static_cast<Handle*>(handle);
2170 *exist = p->Get()->IsItemTypeExist(type);
2172 return NOTI_EX_ERROR_NONE;
2175 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2177 if (handle == nullptr || type == nullptr) {
2178 LOGE("Invalid parameter");
2179 return NOTI_EX_ERROR_INVALID_PARAMETER;
2182 Handle* p = static_cast<Handle*>(handle);
2183 *type = p->Get()->GetMainType();
2185 return NOTI_EX_ERROR_NONE;
2188 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2189 const char* id, int type) {
2190 if (handle == nullptr || id == nullptr) {
2191 LOGE("Invalid parameter");
2192 return NOTI_EX_ERROR_INVALID_PARAMETER;
2195 Handle* p = static_cast<Handle*>(handle);
2196 if (!(p->Get()->SetMainType(string(id),
2197 static_cast<AbstractItem::MainType>(type))))
2198 return NOTI_EX_ERROR_INVALID_PARAMETER;
2200 return NOTI_EX_ERROR_NONE;
2203 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2204 int type, noti_ex_item_h* item) {
2205 if (handle == nullptr || item == nullptr) {
2206 LOGE("Invalid parameter");
2207 return NOTI_EX_ERROR_INVALID_PARAMETER;
2210 Handle* h = static_cast<Handle*>(handle);
2211 if (!h->IsValidType(AbstractItem::Group)) {
2212 LOGE("Invalid handle type");
2213 return NOTI_EX_ERROR_INVALID_PARAMETER;
2216 GroupItem* p = static_cast<GroupItem*>(h->Get());
2217 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2218 *item = new Handle(&find_item);
2220 return NOTI_EX_ERROR_NONE;
2223 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2224 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2226 if (handle == nullptr) {
2227 LOGE("Invalid parameter");
2228 return NOTI_EX_ERROR_INVALID_PARAMETER;
2231 string receiver_group_str = "";
2233 receiver_group_str = string(receiver_group);
2235 ManagerStub* stub = new (std::nothrow) ManagerStub(
2236 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2237 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2238 receiver_group_str);
2239 if (stub == nullptr) {
2240 LOGE("Fail to create manager");
2241 return NOTI_EX_ERROR_IO_ERROR;
2243 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2244 new ManagerCallbackInfo(event_callbacks, data)));
2245 *handle = static_cast<noti_ex_manager_h>(stub);
2247 return NOTI_EX_ERROR_NONE;
2250 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2251 if (handle == nullptr) {
2252 LOGE("Invalid parameter");
2253 return NOTI_EX_ERROR_INVALID_PARAMETER;
2255 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2257 return NOTI_EX_ERROR_NONE;
2260 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2261 noti_ex_item_h **items, int *count) {
2262 if (handle == nullptr || items == nullptr || count == nullptr) {
2263 LOGE("Invalid parameter");
2264 return NOTI_EX_ERROR_INVALID_PARAMETER;
2268 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2269 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2270 if (item_list.size() == 0) {
2273 return NOTI_EX_ERROR_NONE;
2275 noti_ex_item_h* added_item =
2276 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2277 if (added_item == nullptr) {
2278 LOGE("Fail to create items");
2279 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2283 for (auto& i : item_list) {
2284 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2286 *items = added_item;
2287 *count = item_list.size();
2288 } catch (Exception &ex) {
2289 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2290 return NOTI_EX_ERROR_IO_ERROR;
2292 return NOTI_EX_ERROR_NONE;
2295 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2296 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2297 if (handle == nullptr || channel == nullptr ||
2298 items == nullptr || count == nullptr) {
2299 LOGE("Invalid parameter");
2300 return NOTI_EX_ERROR_INVALID_PARAMETER;
2304 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2305 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2306 if (item_list.size() == 0) {
2309 return NOTI_EX_ERROR_NONE;
2311 noti_ex_item_h* added_item =
2312 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2313 if (added_item == nullptr) {
2314 LOGE("Fail to create items");
2315 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2319 for (auto& i : item_list) {
2320 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2322 *items = added_item;
2323 *count = item_list.size();
2324 } catch (Exception &ex) {
2325 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2326 return NOTI_EX_ERROR_IO_ERROR;
2329 return NOTI_EX_ERROR_NONE;
2332 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2333 noti_ex_item_h noti, int *request_id) {
2334 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2335 LOGE("Invalid parameter");
2336 return NOTI_EX_ERROR_INVALID_PARAMETER;
2339 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2340 Handle* sp = static_cast<Handle*>(noti);
2341 if (sp->GetPtr().get() == nullptr) {
2342 LOGE("Invalid noti reference can not be sended");
2343 return NOTI_EX_ERROR_INVALID_PARAMETER;
2345 *request_id = stub->Update(sp->GetPtr());
2347 } catch (Exception &ex) {
2348 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2349 return NOTI_EX_ERROR_IO_ERROR;
2351 return NOTI_EX_ERROR_NONE;
2354 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2355 noti_ex_item_h noti, int *request_id) {
2356 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2357 LOGE("Invalid parameter");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2361 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2362 Handle* item = static_cast<Handle*>(noti);
2363 if (item->GetPtr().get() == nullptr) {
2364 LOGE("Invalid noti reference can not be sended");
2365 return NOTI_EX_ERROR_INVALID_PARAMETER;
2367 *request_id = stub->Delete(item->GetPtr());
2369 } catch (Exception &ex) {
2370 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2371 return NOTI_EX_ERROR_IO_ERROR;
2373 return NOTI_EX_ERROR_NONE;
2376 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2378 if (handle == nullptr || request_id == nullptr) {
2379 LOGE("Invalid parameter");
2380 return NOTI_EX_ERROR_INVALID_PARAMETER;
2383 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2384 *request_id = stub->DeleteAll();
2385 } catch (Exception &ex) {
2386 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2387 return NOTI_EX_ERROR_IO_ERROR;
2389 return NOTI_EX_ERROR_NONE;
2392 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2393 noti_ex_item_h noti, int *request_id) {
2394 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2395 LOGE("Invalid parameter");
2396 return NOTI_EX_ERROR_INVALID_PARAMETER;
2399 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2400 Handle* item = static_cast<Handle*>(noti);
2401 if (item->GetPtr().get() == nullptr) {
2402 LOGE("Invalid noti reference can not be sended");
2403 return NOTI_EX_ERROR_INVALID_PARAMETER;
2405 *request_id = stub->Hide(item->GetPtr());
2407 } catch (Exception &ex) {
2408 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2409 return NOTI_EX_ERROR_IO_ERROR;
2411 return NOTI_EX_ERROR_NONE;
2414 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2415 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2416 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2417 LOGE("Invalid parameter");
2418 return NOTI_EX_ERROR_INVALID_PARAMETER;
2421 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2422 *item = new Handle(stub->FindByRootID(root_id));
2423 } catch (Exception &ex) {
2424 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2425 return NOTI_EX_ERROR_IO_ERROR;
2427 return NOTI_EX_ERROR_NONE;
2430 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2431 noti_ex_event_info_h info, noti_ex_error_e error) {
2432 if (handle == nullptr || info == nullptr) {
2433 LOGE("Invalid parameter");
2434 return NOTI_EX_ERROR_INVALID_PARAMETER;
2437 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2438 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2439 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2440 static_cast<NotificationError>(error));
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_manager_get_notification_count(
2449 noti_ex_manager_h handle, int *cnt) {
2451 if (handle == nullptr || cnt == nullptr) {
2452 LOGE("Invalid parameter");
2453 return NOTI_EX_ERROR_INVALID_PARAMETER;
2456 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2457 *cnt = stub->GetCount();
2458 } catch (Exception &ex) {
2459 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2460 return NOTI_EX_ERROR_IO_ERROR;
2462 return NOTI_EX_ERROR_NONE;
2465 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2466 const char *id, float min, float current, float max) {
2469 if (handle == nullptr) {
2470 LOGE("Invalid parameter");
2471 return NOTI_EX_ERROR_INVALID_PARAMETER;
2475 p = new (std::nothrow) ProgressItem(id, min, current, max);
2477 p = new (std::nothrow) ProgressItem(min, current, max);
2480 LOGE("Out-of-memory");
2481 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2484 *handle = new Handle(shared_ptr<AbstractItem>(p));
2486 return NOTI_EX_ERROR_NONE;
2489 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2490 noti_ex_item_h handle, float *current) {
2491 if (handle == nullptr || current == nullptr) {
2492 LOGE("Invalid parameter");
2493 return NOTI_EX_ERROR_INVALID_PARAMETER;
2496 Handle *h = static_cast<Handle*>(handle);
2497 if (!h->IsValidType(AbstractItem::Progress)) {
2498 LOGE("Invalid handle type");
2499 return NOTI_EX_ERROR_INVALID_PARAMETER;
2501 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2502 *current = p->GetCurrent();
2504 return NOTI_EX_ERROR_NONE;
2507 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2508 noti_ex_item_h handle, float current) {
2509 if (handle == nullptr) {
2510 LOGE("Invalid parameter");
2511 return NOTI_EX_ERROR_INVALID_PARAMETER;
2514 Handle *h = static_cast<Handle*>(handle);
2515 if (!h->IsValidType(AbstractItem::Progress)) {
2516 LOGE("Invalid handle type");
2517 return NOTI_EX_ERROR_INVALID_PARAMETER;
2519 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2520 p->SetCurrent(current);
2522 return NOTI_EX_ERROR_NONE;
2525 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2527 if (handle == nullptr || min == nullptr) {
2528 LOGE("Invalid parameter");
2529 return NOTI_EX_ERROR_INVALID_PARAMETER;
2532 Handle *h = static_cast<Handle*>(handle);
2533 if (!h->IsValidType(AbstractItem::Progress)) {
2534 LOGE("Invalid handle type");
2535 return NOTI_EX_ERROR_INVALID_PARAMETER;
2537 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2540 return NOTI_EX_ERROR_NONE;
2543 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2545 if (handle == nullptr || max == nullptr) {
2546 LOGE("Invalid parameter");
2547 return NOTI_EX_ERROR_INVALID_PARAMETER;
2550 Handle *h = static_cast<Handle*>(handle);
2551 if (!h->IsValidType(AbstractItem::Progress)) {
2552 LOGE("Invalid handle type");
2553 return NOTI_EX_ERROR_INVALID_PARAMETER;
2555 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2558 return NOTI_EX_ERROR_NONE;
2561 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2563 if (handle == nullptr || type == nullptr) {
2564 LOGE("Invalid parameter");
2565 return NOTI_EX_ERROR_INVALID_PARAMETER;
2568 Handle *h = static_cast<Handle*>(handle);
2569 if (!h->IsValidType(AbstractItem::Progress)) {
2570 LOGE("Invalid handle type");
2571 return NOTI_EX_ERROR_INVALID_PARAMETER;
2573 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2574 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2576 return NOTI_EX_ERROR_NONE;
2579 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2581 if (handle == nullptr) {
2582 LOGE("Invalid parameter");
2583 return NOTI_EX_ERROR_INVALID_PARAMETER;
2586 Handle *h = static_cast<Handle*>(handle);
2587 if (!h->IsValidType(AbstractItem::Progress)) {
2588 LOGE("Invalid handle type");
2589 return NOTI_EX_ERROR_INVALID_PARAMETER;
2591 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2592 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2594 return NOTI_EX_ERROR_NONE;
2597 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2598 noti_ex_reporter_events_s event_callbacks, void *data) {
2599 if (handle == nullptr) {
2600 LOGE("Invalid parameter");
2601 return NOTI_EX_ERROR_INVALID_PARAMETER;
2604 ReporterStub* stub = new (std::nothrow) ReporterStub(
2605 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2606 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2607 if (stub == nullptr) {
2608 LOGE("Fail to create manager");
2609 return NOTI_EX_ERROR_IO_ERROR;
2611 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2612 new ReporterCallbackInfo(event_callbacks, data)));
2614 *handle = static_cast<noti_ex_reporter_h>(stub);
2616 return NOTI_EX_ERROR_NONE;
2619 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2620 if (handle == nullptr) {
2621 LOGE("Invalid parameter");
2622 return NOTI_EX_ERROR_INVALID_PARAMETER;
2624 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2626 return NOTI_EX_ERROR_NONE;
2629 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2630 noti_ex_event_info_h info, noti_ex_error_e error) {
2631 if (handle == nullptr || info == nullptr) {
2632 LOGE("Invalid parameter");
2633 return NOTI_EX_ERROR_INVALID_PARAMETER;
2636 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2637 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2638 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2639 static_cast<NotificationError>(error));
2640 } catch (Exception &ex) {
2641 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2642 return NOTI_EX_ERROR_IO_ERROR;
2644 return NOTI_EX_ERROR_NONE;
2647 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2648 noti_ex_item_h noti, int *request_id) {
2649 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2650 LOGE("Invalid parameter");
2651 return NOTI_EX_ERROR_INVALID_PARAMETER;
2654 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2655 Handle* h = static_cast<Handle*>(noti);
2656 if (h->GetPtr().get() == nullptr) {
2657 LOGE("Invalid noti reference can not be sended");
2658 return NOTI_EX_ERROR_INVALID_PARAMETER;
2660 *request_id = stub->Post(h->GetPtr());
2662 } catch (Exception &ex) {
2663 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2664 return NOTI_EX_ERROR_IO_ERROR;
2666 return NOTI_EX_ERROR_NONE;
2669 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2670 noti_ex_item_h *noti_list, int count, int *request_id) {
2672 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2673 LOGE("Invalid parameter");
2674 return NOTI_EX_ERROR_INVALID_PARAMETER;
2677 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2678 list<shared_ptr<item::AbstractItem>> notiList;
2679 for (int i = 0; i < count; i++) {
2680 Handle* item = static_cast<Handle*>(noti_list[i]);
2681 notiList.push_back(item->GetPtr());
2683 *request_id = stub->Post(notiList);
2684 } catch (Exception &ex) {
2685 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2686 return NOTI_EX_ERROR_IO_ERROR;
2688 return NOTI_EX_ERROR_NONE;
2691 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2692 noti_ex_item_h noti, int *request_id) {
2693 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2694 LOGE("Invalid parameter");
2695 return NOTI_EX_ERROR_INVALID_PARAMETER;
2698 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2699 Handle* item = static_cast<Handle*>(noti);
2700 if (item->GetPtr().get() == nullptr) {
2701 LOGE("Invalid noti reference can not be sended");
2702 return NOTI_EX_ERROR_INVALID_PARAMETER;
2704 *request_id = stub->Update(item->GetPtr());
2706 } catch (Exception &ex) {
2707 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2708 return NOTI_EX_ERROR_IO_ERROR;
2710 return NOTI_EX_ERROR_NONE;
2713 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2714 noti_ex_item_h noti, int *request_id) {
2715 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2716 LOGE("Invalid parameter");
2717 return NOTI_EX_ERROR_INVALID_PARAMETER;
2720 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2721 Handle* item = static_cast<Handle*>(noti);
2722 if (item->GetPtr().get() == nullptr) {
2723 LOGE("Invalid noti reference can not be sended");
2724 return NOTI_EX_ERROR_INVALID_PARAMETER;
2726 *request_id = stub->Delete(item->GetPtr());
2728 } catch (Exception &ex) {
2729 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2730 return NOTI_EX_ERROR_IO_ERROR;
2732 return NOTI_EX_ERROR_NONE;
2735 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2736 noti_ex_reporter_h handle, int *request_id) {
2737 if (handle == nullptr || request_id == nullptr) {
2738 LOGE("Invalid parameter");
2739 return NOTI_EX_ERROR_INVALID_PARAMETER;
2742 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2743 *request_id = stub->DeleteAll();
2744 } catch (Exception &ex) {
2745 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2746 return NOTI_EX_ERROR_IO_ERROR;
2748 return NOTI_EX_ERROR_NONE;
2751 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2752 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2753 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2754 LOGE("Invalid parameter");
2755 return NOTI_EX_ERROR_INVALID_PARAMETER;
2758 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2759 *item = new Handle(stub->FindByRootID(root_id));
2760 } catch (Exception &ex) {
2761 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2762 return NOTI_EX_ERROR_IO_ERROR;
2764 return NOTI_EX_ERROR_NONE;
2767 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2768 const char *id, const char *text, const char *hyperlink) {
2769 if (handle == nullptr || text == nullptr) {
2770 LOGE("Invalid parameter");
2771 return NOTI_EX_ERROR_INVALID_PARAMETER;
2777 p = new (std::nothrow) TextItem(id, std::string(text),
2778 std::string(hyperlink));
2780 p = new (std::nothrow) TextItem(id, std::string(text));
2783 LOGE("Out-of-memory");
2784 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2787 *handle = new Handle(shared_ptr<AbstractItem>(p));
2789 return NOTI_EX_ERROR_NONE;
2792 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2793 const char *contents) {
2794 if (handle == nullptr || contents == nullptr) {
2795 LOGE("Invalid parameter");
2796 return NOTI_EX_ERROR_INVALID_PARAMETER;
2799 Handle* p = static_cast<Handle*>(handle);
2800 if (!p->IsValidType(AbstractItem::Text)) {
2801 LOGE("Invalid handle type");
2802 return NOTI_EX_ERROR_INVALID_PARAMETER;
2804 TextItem* ti = static_cast<TextItem*>(p->Get());
2805 ti->SetContents(std::string(contents));
2807 return NOTI_EX_ERROR_NONE;
2810 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2812 if (handle == nullptr || contents == nullptr) {
2813 LOGE("Invalid parameter");
2814 return NOTI_EX_ERROR_INVALID_PARAMETER;
2817 Handle* p = static_cast<Handle*>(handle);
2818 if (!p->IsValidType(AbstractItem::Text)) {
2819 LOGE("Invalid handle type");
2820 return NOTI_EX_ERROR_INVALID_PARAMETER;
2822 TextItem* ti = static_cast<TextItem*>(p->Get());
2823 if (!ti->GetContents().empty()) {
2824 *contents = strdup(ti->GetContents().c_str());
2825 if (*contents == nullptr) {
2826 LOGE("Out-of-memory");
2827 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2831 return NOTI_EX_ERROR_NONE;
2834 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2835 noti_ex_item_h handle, char **hyper_link) {
2836 if (handle == nullptr || hyper_link == nullptr) {
2837 LOGE("Invalid parameter");
2838 return NOTI_EX_ERROR_INVALID_PARAMETER;
2841 Handle* p = static_cast<Handle*>(handle);
2842 if (!p->IsValidType(AbstractItem::Text)) {
2843 LOGE("Invalid handle type");
2844 return NOTI_EX_ERROR_INVALID_PARAMETER;
2846 TextItem* ti = static_cast<TextItem*>(p->Get());
2847 if (!ti->GetHyperLink().empty()) {
2848 *hyper_link = strdup(ti->GetHyperLink().c_str());
2849 if (*hyper_link == nullptr) {
2850 LOGE("Out-of-memory");
2851 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2855 return NOTI_EX_ERROR_NONE;
2858 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2859 const char *id, time_t time) {
2862 if (handle == nullptr) {
2863 LOGE("Invalid parameter");
2864 return NOTI_EX_ERROR_INVALID_PARAMETER;
2869 p = new (std::nothrow) TimeItem(id, time);
2871 p = new (std::nothrow) TimeItem(time);
2873 p = new (std::nothrow) TimeItem();
2877 LOGE("Out-of-memory");
2878 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2881 *handle = new Handle(shared_ptr<AbstractItem>(p));
2883 return NOTI_EX_ERROR_NONE;
2886 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2888 if (handle == nullptr || time == nullptr) {
2889 LOGE("Invalid parameter");
2890 return NOTI_EX_ERROR_INVALID_PARAMETER;
2892 Handle* h = static_cast<Handle*>(handle);
2893 if (!h->IsValidType(AbstractItem::Time)) {
2894 LOGE("Invalid handle type");
2895 return NOTI_EX_ERROR_INVALID_PARAMETER;
2897 TimeItem* p = static_cast<TimeItem*>(h->Get());
2898 *time = p->GetTime();
2900 return NOTI_EX_ERROR_NONE;
2903 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2904 noti_ex_action_h *handle, const char *extra) {
2905 if (handle == nullptr) {
2906 LOGE("Invalid parameter");
2907 return NOTI_EX_ERROR_INVALID_PARAMETER;
2910 string extra_str = "";
2912 extra_str = string(extra);
2914 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2916 LOGE("Out-of-memory");
2917 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2922 return NOTI_EX_ERROR_NONE;
2925 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2926 const char *id, bool visible) {
2927 if (handle == nullptr || id == nullptr) {
2928 LOGE("Invalid parameter");
2929 return NOTI_EX_ERROR_INVALID_PARAMETER;
2932 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2933 p->SetVisibility(id, visible);
2935 return NOTI_EX_ERROR_NONE;