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(noti_ex_item_h handle,
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_entry_create(noti_ex_item_h *handle,
569 if (handle == nullptr) {
570 LOGE("Invalid parameter");
571 return NOTI_EX_ERROR_INVALID_PARAMETER;
574 p = new (std::nothrow) EntryItem(id);
576 LOGE("Out-of-memory");
577 return NOTI_EX_ERROR_OUT_OF_MEMORY;
580 *handle = new Handle(shared_ptr<AbstractItem>(p));
582 return NOTI_EX_ERROR_NONE;
585 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
587 if (handle == nullptr || text == nullptr) {
588 LOGE("Invalid parameter");
589 return NOTI_EX_ERROR_INVALID_PARAMETER;
592 Handle* h = static_cast<Handle*>(handle);
593 if (!h->IsValidType(AbstractItem::Entry)) {
594 LOGE("Invalid handle type");
595 return NOTI_EX_ERROR_INVALID_PARAMETER;
597 EntryItem* p = static_cast<EntryItem*>(h->Get());
598 if (!p->GetText().empty()) {
599 *text = strdup(p->GetText().c_str());
600 if (*text == nullptr) {
601 LOGE("Out-of-memory");
602 return NOTI_EX_ERROR_OUT_OF_MEMORY;
606 return NOTI_EX_ERROR_NONE;
609 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
611 if (handle == nullptr || text == nullptr) {
612 LOGE("Invalid parameter");
613 return NOTI_EX_ERROR_INVALID_PARAMETER;
615 Handle* h = static_cast<Handle*>(handle);
616 if (!h->IsValidType(AbstractItem::Entry)) {
617 LOGE("Invalid handle type");
618 return NOTI_EX_ERROR_INVALID_PARAMETER;
620 EntryItem* p = static_cast<EntryItem*>(h->Get());
621 p->SetText(std::string(text));
623 return NOTI_EX_ERROR_NONE;
626 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
627 noti_ex_event_info_h* cloned_handle) {
628 if (handle == nullptr || cloned_handle == nullptr) {
629 LOGE("Invalid parameter");
630 return NOTI_EX_ERROR_INVALID_PARAMETER;
633 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
634 EventInfo* info = new EventInfo(cloned);
635 *cloned_handle = info;
636 return NOTI_EX_ERROR_NONE;
639 extern "C" EXPORT_API int noti_ex_event_info_destroy(
640 noti_ex_event_info_h handle) {
641 if (handle == nullptr) {
642 LOGE("Invalid parameter");
643 return NOTI_EX_ERROR_INVALID_PARAMETER;
645 EventInfo* info = static_cast<EventInfo*>(handle);
647 return NOTI_EX_ERROR_NONE;
650 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
651 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
652 if (handle == nullptr || event_type == nullptr) {
653 LOGE("Invalid parameter");
654 return NOTI_EX_ERROR_INVALID_PARAMETER;
656 EventInfo* info = static_cast<EventInfo*>(handle);
657 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
659 return NOTI_EX_ERROR_NONE;
662 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
663 noti_ex_event_info_h handle, char **owner) {
664 if (handle == nullptr || owner == nullptr) {
665 LOGE("Invalid parameter");
666 return NOTI_EX_ERROR_INVALID_PARAMETER;
668 EventInfo* info = static_cast<EventInfo*>(handle);
669 *owner = strdup(info->GetOwner().c_str());
670 return NOTI_EX_ERROR_NONE;
673 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
674 noti_ex_event_info_h handle, char **channel) {
675 if (handle == nullptr || channel == nullptr) {
676 LOGE("Invalid parameter");
677 return NOTI_EX_ERROR_INVALID_PARAMETER;
679 EventInfo* info = static_cast<EventInfo*>(handle);
680 *channel = strdup(info->GetChannel().c_str());
681 return NOTI_EX_ERROR_NONE;
684 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
685 noti_ex_event_info_h handle, char **item_id) {
686 if (handle == nullptr || item_id == nullptr) {
687 LOGE("Invalid parameter");
688 return NOTI_EX_ERROR_INVALID_PARAMETER;
690 EventInfo* info = static_cast<EventInfo*>(handle);
691 *item_id = strdup(info->GetItemId().c_str());
692 return NOTI_EX_ERROR_NONE;
695 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
696 noti_ex_event_info_h handle, int *req_id) {
697 if (handle == nullptr || req_id == nullptr) {
698 LOGE("Invalid parameter");
699 return NOTI_EX_ERROR_INVALID_PARAMETER;
701 EventInfo* info = static_cast<EventInfo*>(handle);
702 *req_id = info->GetRequestId();
703 return NOTI_EX_ERROR_NONE;
706 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
710 if (handle == nullptr) {
711 LOGE("Invalid parameter");
712 return NOTI_EX_ERROR_INVALID_PARAMETER;
716 p = new (std::nothrow) GroupItem(id);
718 p = new (std::nothrow) GroupItem();
721 LOGE("Out-of-memory");
722 return NOTI_EX_ERROR_OUT_OF_MEMORY;
725 *handle = new Handle(shared_ptr<AbstractItem>(p));
727 return NOTI_EX_ERROR_NONE;
730 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
732 if (handle == nullptr) {
733 LOGE("Invalid parameter");
734 return NOTI_EX_ERROR_INVALID_PARAMETER;
736 Handle* h = static_cast<Handle*>(handle);
737 if (!h->IsValidType(AbstractItem::Group)) {
738 LOGE("Invalid handle type");
739 return NOTI_EX_ERROR_INVALID_PARAMETER;
741 GroupItem* p = static_cast<GroupItem*>(h->Get());
742 p->SetDirection(vertical);
744 return NOTI_EX_ERROR_NONE;
747 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
749 if (handle == nullptr) {
750 LOGE("Invalid parameter");
751 return NOTI_EX_ERROR_INVALID_PARAMETER;
753 Handle* h = static_cast<Handle*>(handle);
754 if (!h->IsValidType(AbstractItem::Group)) {
755 LOGE("Invalid handle type");
756 return NOTI_EX_ERROR_INVALID_PARAMETER;
758 GroupItem* p = static_cast<GroupItem*>(h->Get());
759 *vertical = p->IsVertical();
761 return NOTI_EX_ERROR_NONE;
764 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
766 if (handle == nullptr) {
767 LOGE("Invalid parameter");
768 return NOTI_EX_ERROR_INVALID_PARAMETER;
770 Handle* h = static_cast<Handle*>(handle);
771 if (!h->IsValidType(AbstractItem::Group)) {
772 LOGE("Invalid handle type");
773 return NOTI_EX_ERROR_INVALID_PARAMETER;
775 GroupItem* p = static_cast<GroupItem*>(h->Get());
776 if (!p->GetAppLabel().empty()) {
777 *label = strdup(p->GetAppLabel().c_str());
778 if (*label == nullptr) {
779 LOGE("Out-of-memory");
780 return NOTI_EX_ERROR_OUT_OF_MEMORY;
784 return NOTI_EX_ERROR_NONE;
787 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
788 noti_ex_item_h child) {
789 if (handle == nullptr || child == nullptr) {
790 LOGE("Invalid parameter");
791 return NOTI_EX_ERROR_INVALID_PARAMETER;
793 Handle* h = static_cast<Handle*>(handle);
794 if (!h->IsValidType(AbstractItem::Group)) {
795 LOGE("Invalid handle type");
796 return NOTI_EX_ERROR_INVALID_PARAMETER;
798 auto p = static_cast<GroupItem*>(h->Get());
799 p->AddChild((static_cast<Handle*>(child))->GetPtr());
801 return NOTI_EX_ERROR_NONE;
804 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
805 const char *item_id) {
806 if (handle == nullptr || item_id == nullptr) {
807 LOGE("Invalid parameter");
808 return NOTI_EX_ERROR_INVALID_PARAMETER;
810 Handle* h = static_cast<Handle*>(handle);
811 if (!h->IsValidType(AbstractItem::Group)) {
812 LOGE("Invalid handle type");
813 return NOTI_EX_ERROR_INVALID_PARAMETER;
815 GroupItem* p = static_cast<GroupItem*>(h->Get());
816 p->RemoveChild(std::string(item_id));
818 return NOTI_EX_ERROR_NONE;
821 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
822 noti_ex_item_group_foreach_child_cb callback, void *data) {
823 if (handle == nullptr || callback == nullptr) {
824 LOGE("Invalid parameter");
825 return NOTI_EX_ERROR_INVALID_PARAMETER;
828 Handle* h = static_cast<Handle*>(handle);
829 if (!h->IsValidType(AbstractItem::Group)) {
830 LOGE("Invalid handle type");
831 return NOTI_EX_ERROR_INVALID_PARAMETER;
833 GroupItem* p = static_cast<GroupItem*>(h->Get());
834 list<shared_ptr<AbstractItem>> children = p->GetChildren();
835 LOGI("Retrive (%zd)", children.size());
836 for (auto i : children) {
838 static_cast<noti_ex_item_h>(new Handle(i)), data);
839 if (ret != NOTI_EX_ERROR_NONE) {
840 LOGW("callback return (%d) stop foreach", ret);
845 return NOTI_EX_ERROR_NONE;
848 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
849 const char *id, const char *image_path) {
852 if (handle == nullptr || image_path == nullptr) {
853 LOGE("Invalid parameter");
854 return NOTI_EX_ERROR_INVALID_PARAMETER;
858 p = new (std::nothrow) ImageItem(id, image_path);
860 p = new (std::nothrow) ImageItem(image_path);
863 LOGE("Out-of-memory");
864 return NOTI_EX_ERROR_OUT_OF_MEMORY;
867 *handle = new Handle(shared_ptr<AbstractItem>(p));
869 return NOTI_EX_ERROR_NONE;
872 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
873 noti_ex_item_h handle, char **image_path) {
874 if (handle == nullptr || image_path == nullptr) {
875 LOGE("Invalid parameter");
876 return NOTI_EX_ERROR_INVALID_PARAMETER;
878 Handle* h = static_cast<Handle*>(handle);
879 if (!h->IsValidType(AbstractItem::Image)) {
880 LOGE("Invalid handle type");
881 return NOTI_EX_ERROR_INVALID_PARAMETER;
883 ImageItem* p = static_cast<ImageItem*>(h->Get());
884 if (!p->GetImagePath().empty()) {
885 *image_path = strdup(p->GetImagePath().c_str());
886 if (*image_path == nullptr) {
887 LOGE("Out-of-memory");
888 return NOTI_EX_ERROR_OUT_OF_MEMORY;
892 return NOTI_EX_ERROR_NONE;
895 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
896 noti_ex_item_h *handle, const char *id) {
897 InputSelectorItem* p;
899 if (handle == nullptr) {
900 LOGE("Invalid parameter");
901 return NOTI_EX_ERROR_INVALID_PARAMETER;
905 p = new (std::nothrow) InputSelectorItem(id);
907 p = new (std::nothrow) InputSelectorItem();
910 LOGE("Out-of-memory");
911 return NOTI_EX_ERROR_OUT_OF_MEMORY;
914 *handle = new Handle(shared_ptr<AbstractItem>(p));
916 return NOTI_EX_ERROR_NONE;
919 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
920 noti_ex_item_h handle, char ***contents_list, int *count) {
921 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
922 LOGE("Invalid parameter");
923 return NOTI_EX_ERROR_INVALID_PARAMETER;
926 Handle* h = static_cast<Handle*>(handle);
927 if (!h->IsValidType(AbstractItem::InputSelector)) {
928 LOGE("Invalid handle type");
929 return NOTI_EX_ERROR_INVALID_PARAMETER;
931 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
932 list<string> contents = p->GetContents();
933 char **list = (char**)calloc(contents.size(), sizeof(char*));
934 if (list == nullptr) {
935 LOGE("Out of memory");
936 return NOTI_EX_ERROR_OUT_OF_MEMORY;
940 for (auto& i : contents) {
941 list[idx] = strdup(i.c_str());
942 if (list[idx] == nullptr) {
943 __noti_ex_free_str_array(list, idx);
944 LOGE("Out of memory");
945 return NOTI_EX_ERROR_OUT_OF_MEMORY;
950 *count = contents.size();
951 *contents_list = list;
953 return NOTI_EX_ERROR_NONE;
956 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
957 noti_ex_item_h handle, const char **contents, int count) {
958 if (handle == nullptr || contents == nullptr) {
959 LOGE("Invalid parameter");
960 return NOTI_EX_ERROR_INVALID_PARAMETER;
963 list<string> new_contents;
964 Handle* h = static_cast<Handle*>(handle);
965 if (!h->IsValidType(AbstractItem::InputSelector)) {
966 LOGE("Invalid handle type");
967 return NOTI_EX_ERROR_INVALID_PARAMETER;
969 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
970 for (int i = 0; i < count; i++) {
971 new_contents.push_back(contents[i]);
973 p->SetContents(move(new_contents));
975 return NOTI_EX_ERROR_NONE;
978 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
979 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
980 if (handle == nullptr) {
981 LOGE("Invalid parameter");
982 return NOTI_EX_ERROR_INVALID_PARAMETER;
985 auto* ptr = new (std::nothrow) shared_ptr<Color>(
986 new (std::nothrow) Color(a, r, g, b));
987 if (ptr == nullptr || ptr->get() == nullptr) {
988 LOGE("Out-of-memory");
989 return NOTI_EX_ERROR_OUT_OF_MEMORY;
994 return NOTI_EX_ERROR_NONE;
997 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
998 if (handle == nullptr) {
999 LOGE("Invalid parameter");
1000 return NOTI_EX_ERROR_INVALID_PARAMETER;
1003 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1006 return NOTI_EX_ERROR_NONE;
1009 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1010 unsigned char *val) {
1011 if (handle == nullptr || val == nullptr) {
1012 LOGE("Invalid parameter");
1013 return NOTI_EX_ERROR_INVALID_PARAMETER;
1016 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1017 *val = (*p)->GetAVal();
1019 return NOTI_EX_ERROR_NONE;
1022 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1023 unsigned char *val) {
1024 if (handle == nullptr || val == nullptr) {
1025 LOGE("Invalid parameter");
1026 return NOTI_EX_ERROR_INVALID_PARAMETER;
1029 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1030 *val = (*p)->GetRVal();
1032 return NOTI_EX_ERROR_NONE;
1035 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1036 unsigned char *val) {
1037 if (handle == nullptr || val == nullptr) {
1038 LOGE("Invalid parameter");
1039 return NOTI_EX_ERROR_INVALID_PARAMETER;
1042 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1043 *val = (*p)->GetGVal();
1045 return NOTI_EX_ERROR_NONE;
1048 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1049 unsigned char *val) {
1050 if (handle == nullptr || val == nullptr) {
1051 LOGE("Invalid parameter");
1052 return NOTI_EX_ERROR_INVALID_PARAMETER;
1055 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1056 *val = (*p)->GetBVal();
1058 return NOTI_EX_ERROR_NONE;
1061 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1062 int left, int top, int right, int bottom) {
1063 if (handle == nullptr) {
1064 LOGE("Invalid parameter");
1065 return NOTI_EX_ERROR_INVALID_PARAMETER;
1068 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1070 LOGE("Out-of-memory");
1071 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1074 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1075 new (std::nothrow) Padding(left, top, right, bottom));
1076 if (ptr == nullptr || ptr->get() == nullptr) {
1077 LOGE("Out-of-memory");
1078 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1083 return NOTI_EX_ERROR_NONE;
1086 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1087 if (handle == nullptr) {
1088 LOGE("Invalid parameter");
1089 return NOTI_EX_ERROR_INVALID_PARAMETER;
1092 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1095 return NOTI_EX_ERROR_NONE;
1098 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1100 if (handle == nullptr || val == nullptr) {
1101 LOGE("Invalid parameter");
1102 return NOTI_EX_ERROR_INVALID_PARAMETER;
1105 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1106 *val = (*p)->GetLeft();
1108 return NOTI_EX_ERROR_NONE;
1111 extern "C" EXPORT_API int noti_ex_padding_get_top(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)->GetTop();
1121 return NOTI_EX_ERROR_NONE;
1124 extern "C" EXPORT_API int noti_ex_padding_get_right(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)->GetRight();
1134 return NOTI_EX_ERROR_NONE;
1137 extern "C" EXPORT_API int noti_ex_padding_get_bottom(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)->GetBottom();
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1151 int x, int y, int w, int h) {
1152 if (handle == nullptr) {
1153 LOGE("Invalid parameter");
1154 return NOTI_EX_ERROR_INVALID_PARAMETER;
1157 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1158 new (std::nothrow) Geometry(x, y, w, h));
1159 if (ptr == nullptr || ptr->get() == nullptr) {
1160 LOGE("Out-of-memory");
1161 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1166 return NOTI_EX_ERROR_NONE;
1169 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1170 if (handle == nullptr) {
1171 LOGE("Invalid parameter");
1172 return NOTI_EX_ERROR_INVALID_PARAMETER;
1175 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1178 return NOTI_EX_ERROR_NONE;
1181 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1183 if (handle == nullptr || val == nullptr) {
1184 LOGE("Invalid parameter");
1185 return NOTI_EX_ERROR_INVALID_PARAMETER;
1188 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1189 *val = (*p)->GetX();
1191 return NOTI_EX_ERROR_NONE;
1194 extern "C" EXPORT_API int noti_ex_geometry_get_y(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)->GetY();
1204 return NOTI_EX_ERROR_NONE;
1207 extern "C" EXPORT_API int noti_ex_geometry_get_width(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)->GetWidth();
1217 return NOTI_EX_ERROR_NONE;
1220 extern "C" EXPORT_API int noti_ex_geometry_get_height(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)->GetHeight();
1230 return NOTI_EX_ERROR_NONE;
1233 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1234 noti_ex_color_h color,
1235 noti_ex_padding_h padding,
1236 noti_ex_geometry_h geometry) {
1237 if (handle == nullptr) {
1238 LOGE("Invalid parameter");
1239 return NOTI_EX_ERROR_INVALID_PARAMETER;
1242 shared_ptr<Color> col = (color == nullptr) ?
1243 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1244 shared_ptr<Padding> padd = (padding == nullptr) ?
1245 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1246 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1247 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1249 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1250 new (std::nothrow) Style(col, padd, geo));
1251 if (ptr == nullptr || ptr->get() == nullptr) {
1252 LOGE("Out-of-memory");
1253 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1258 return NOTI_EX_ERROR_NONE;
1261 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1262 if (handle == nullptr) {
1263 LOGE("Invalid parameter");
1264 return NOTI_EX_ERROR_INVALID_PARAMETER;
1267 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1270 return NOTI_EX_ERROR_NONE;
1273 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1274 noti_ex_padding_h *padding) {
1275 if (handle == nullptr || padding == nullptr) {
1276 LOGE("Invalid parameter");
1277 return NOTI_EX_ERROR_INVALID_PARAMETER;
1280 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1281 if ((*p)->GetPadding() == nullptr) {
1282 LOGW("Padding info is null");
1283 return NOTI_EX_ERROR_INVALID_PARAMETER;
1286 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1287 new (std::nothrow) Padding(*((*p)->GetPadding())));
1288 if (padd == nullptr || padd->get() == nullptr) {
1289 LOGE("Out-of-memory");
1290 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1295 return NOTI_EX_ERROR_NONE;
1298 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1299 noti_ex_color_h *color) {
1300 if (handle == nullptr || color == nullptr) {
1301 LOGE("Invalid parameter");
1302 return NOTI_EX_ERROR_INVALID_PARAMETER;
1305 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1306 if ((*p)->GetColor() == nullptr) {
1307 LOGW("Color info is null");
1308 return NOTI_EX_ERROR_INVALID_PARAMETER;
1311 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1312 new (std::nothrow) Color(*((*p)->GetColor())));
1313 if (col == nullptr || col->get() == nullptr) {
1314 LOGE("Out-of-memory");
1315 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1320 return NOTI_EX_ERROR_NONE;
1323 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1324 noti_ex_geometry_h *geometry) {
1325 if (handle == nullptr || geometry == nullptr) {
1326 LOGE("Invalid parameter");
1327 return NOTI_EX_ERROR_INVALID_PARAMETER;
1330 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1331 if ((*p)->GetGeometry() == nullptr) {
1332 LOGW("Geometry info is null");
1333 return NOTI_EX_ERROR_INVALID_PARAMETER;
1336 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1337 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1338 if (geo == nullptr || geo->get() == nullptr) {
1339 LOGE("Out-of-memory");
1340 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1345 return NOTI_EX_ERROR_NONE;
1348 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1349 noti_ex_color_h color) {
1350 if (handle == nullptr) {
1351 LOGE("Invalid parameter");
1352 return NOTI_EX_ERROR_INVALID_PARAMETER;
1355 shared_ptr<Color>* color_ = static_cast<shared_ptr<Color>*>(color);
1356 auto* p = new (std::nothrow) LEDInfo(*color_);
1358 LOGE("Out-of-memory");
1359 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1364 return NOTI_EX_ERROR_NONE;
1367 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1368 if (handle == nullptr) {
1369 LOGE("Invalid parameter");
1370 return NOTI_EX_ERROR_INVALID_PARAMETER;
1373 LEDInfo* p = static_cast<LEDInfo*>(handle);
1376 return NOTI_EX_ERROR_NONE;
1379 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1380 noti_ex_led_info_h handle, int ms) {
1381 if (handle == nullptr) {
1382 LOGE("Invalid parameter");
1383 return NOTI_EX_ERROR_INVALID_PARAMETER;
1386 LEDInfo* p = static_cast<LEDInfo*>(handle);
1389 return NOTI_EX_ERROR_NONE;
1392 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1393 noti_ex_led_info_h handle, int *ms) {
1394 if (handle == nullptr || ms == nullptr) {
1395 LOGE("Invalid parameter");
1396 return NOTI_EX_ERROR_INVALID_PARAMETER;
1399 LEDInfo* p = static_cast<LEDInfo*>(handle);
1400 *ms = p->GetOnPeriod();
1402 return NOTI_EX_ERROR_NONE;
1405 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1406 noti_ex_led_info_h handle, int ms) {
1407 if (handle == nullptr) {
1408 LOGE("Invalid parameter");
1409 return NOTI_EX_ERROR_INVALID_PARAMETER;
1412 LEDInfo* p = static_cast<LEDInfo*>(handle);
1413 p->SetOffPeriod(ms);
1415 return NOTI_EX_ERROR_NONE;
1418 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1419 noti_ex_led_info_h handle, int *ms) {
1420 if (handle == nullptr) {
1421 LOGE("Invalid parameter");
1422 return NOTI_EX_ERROR_INVALID_PARAMETER;
1425 LEDInfo* p = static_cast<LEDInfo*>(handle);
1426 *ms = p->GetOffPeriod();
1428 return NOTI_EX_ERROR_NONE;
1431 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1432 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1433 if (handle == nullptr) {
1434 LOGE("Invalid parameter");
1435 return NOTI_EX_ERROR_INVALID_PARAMETER;
1438 LEDInfo* p = static_cast<LEDInfo*>(handle);
1439 if (p->GetColor() == nullptr) {
1440 LOGE("Color is null");
1441 return NOTI_EX_ERROR_INVALID_PARAMETER;
1444 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1445 new (std::nothrow) Color(*(p->GetColor())));
1446 if (col == nullptr || col->get() == nullptr) {
1447 LOGE("Out-of-memory");
1448 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1453 return NOTI_EX_ERROR_NONE;
1456 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1457 if (handle == nullptr) {
1458 LOGE("Invalid parameter");
1459 return NOTI_EX_ERROR_INVALID_PARAMETER;
1462 AbstractAction* p = static_cast<AbstractAction*>(handle);
1463 p->~AbstractAction();
1465 return NOTI_EX_ERROR_NONE;
1468 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1470 if (handle == nullptr || type == nullptr) {
1471 LOGE("Invalid parameter");
1472 return NOTI_EX_ERROR_INVALID_PARAMETER;
1475 AbstractAction* p = static_cast<AbstractAction*>(handle);
1476 *type = p->GetType();
1478 return NOTI_EX_ERROR_NONE;
1481 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1483 if (handle == nullptr || local == nullptr) {
1484 LOGE("Invalid parameter");
1485 return NOTI_EX_ERROR_INVALID_PARAMETER;
1488 AbstractAction* p = static_cast<AbstractAction*>(handle);
1489 *local = p->IsLocal();
1491 return NOTI_EX_ERROR_NONE;
1494 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1495 noti_ex_item_h item) {
1496 if (handle == nullptr || item == nullptr) {
1497 LOGE("Invalid parameter");
1498 return NOTI_EX_ERROR_INVALID_PARAMETER;
1500 AbstractAction* p = static_cast<AbstractAction*>(handle);
1501 Handle* ih = static_cast<Handle*>(item);
1502 p->Execute(ih->GetPtr());
1504 return NOTI_EX_ERROR_NONE;
1507 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1509 if (handle == nullptr || extra == nullptr) {
1510 LOGE("Invalid parameter");
1511 return NOTI_EX_ERROR_INVALID_PARAMETER;
1514 AbstractAction* p = static_cast<AbstractAction*>(handle);
1515 if (!p->GetExtra().empty()) {
1516 *extra = strdup(p->GetExtra().c_str());
1517 if (*extra == nullptr) {
1518 LOGE("Out-of-memory");
1519 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1523 return NOTI_EX_ERROR_NONE;
1526 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1527 noti_ex_item_info_h handle, int *hide_time) {
1528 if (handle == nullptr || hide_time == nullptr) {
1529 LOGE("Invalid parameter");
1530 return NOTI_EX_ERROR_INVALID_PARAMETER;
1532 IItemInfo* p = static_cast<IItemInfo*>(handle);
1533 *hide_time = p->GetHideTime();
1534 return NOTI_EX_ERROR_NONE;
1537 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1538 noti_ex_item_info_h handle, int hide_time) {
1539 if (handle == nullptr) {
1540 LOGE("Invalid parameter");
1541 return NOTI_EX_ERROR_INVALID_PARAMETER;
1543 IItemInfo* p = static_cast<IItemInfo*>(handle);
1544 p->SetHideTime(hide_time);
1545 return NOTI_EX_ERROR_NONE;
1548 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1549 noti_ex_item_info_h handle, int *delete_time) {
1550 if (handle == nullptr || delete_time == nullptr) {
1551 LOGE("Invalid parameter");
1552 return NOTI_EX_ERROR_INVALID_PARAMETER;
1554 IItemInfo* p = static_cast<IItemInfo*>(handle);
1555 *delete_time = p->GetDeleteTime();
1556 return NOTI_EX_ERROR_NONE;
1559 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1560 noti_ex_item_info_h handle, int delete_time) {
1561 if (handle == nullptr) {
1562 LOGE("Invalid parameter");
1563 return NOTI_EX_ERROR_INVALID_PARAMETER;
1565 IItemInfo* p = static_cast<IItemInfo*>(handle);
1566 p->SetDeleteTime(delete_time);
1567 return NOTI_EX_ERROR_NONE;
1570 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1571 noti_ex_item_info_h handle, time_t *time) {
1572 if (handle == nullptr || time == nullptr) {
1573 LOGE("Invalid parameter");
1574 return NOTI_EX_ERROR_INVALID_PARAMETER;
1577 IItemInfo* p = static_cast<IItemInfo*>(handle);
1578 *time = p->GetTime();
1579 return NOTI_EX_ERROR_NONE;
1582 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1583 if (handle == nullptr) {
1584 LOGE("Invalid parameter");
1585 return NOTI_EX_ERROR_INVALID_PARAMETER;
1588 Handle* h = static_cast<Handle*>(handle);
1590 return NOTI_EX_ERROR_NONE;
1593 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1594 const char *id, noti_ex_item_h *item) {
1595 if (handle == nullptr) {
1596 LOGE("Invalid parameter");
1597 return NOTI_EX_ERROR_INVALID_PARAMETER;
1600 Handle* p = static_cast<Handle*>(handle);
1601 AbstractItem& find_item = p->Get()->FindByID(string(id));
1602 *item = new Handle(&find_item);
1603 return NOTI_EX_ERROR_NONE;
1606 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1608 if (handle == nullptr || type == nullptr) {
1609 LOGE("Invalid parameter");
1610 return NOTI_EX_ERROR_INVALID_PARAMETER;
1613 Handle* h = static_cast<Handle*>(handle);
1614 AbstractItem* p = h->Get();
1615 *type = p->GetType();
1616 return NOTI_EX_ERROR_NONE;
1619 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1620 char ***path, int *count) {
1621 if (handle == nullptr || path == nullptr || count == nullptr) {
1622 LOGE("Invalid parameter");
1623 return NOTI_EX_ERROR_INVALID_PARAMETER;
1625 Handle* p = static_cast<Handle*>(handle);
1626 list<string> shared_path = p->Get()->GetSharedPath();
1627 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1628 if (tmp_path == nullptr) {
1629 LOGE("Fail to create items");
1630 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1634 for (auto& i : shared_path) {
1635 tmp_path[idx] = strdup(i.c_str());
1636 if (tmp_path[idx] == nullptr) {
1637 __noti_ex_free_str_array(tmp_path, idx);
1638 LOGE("Out of memory");
1639 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1645 *count = shared_path.size();
1646 return NOTI_EX_ERROR_NONE;
1649 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1651 if (handle == nullptr || id == nullptr) {
1652 LOGE("Invalid parameter");
1653 return NOTI_EX_ERROR_INVALID_PARAMETER;
1655 Handle* h = static_cast<Handle*>(handle);
1656 AbstractItem* p = h->Get();
1657 *id = strdup(p->GetId().c_str());
1658 return NOTI_EX_ERROR_NONE;
1661 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1663 if (handle == nullptr || id == nullptr) {
1664 LOGE("Invalid parameter");
1665 return NOTI_EX_ERROR_INVALID_PARAMETER;
1667 Handle* p = static_cast<Handle*>(handle);
1668 p->Get()->SetId(id);
1669 return NOTI_EX_ERROR_NONE;
1672 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1673 noti_ex_action_h *action) {
1674 if (handle == nullptr || action == nullptr) {
1675 LOGE("Invalid parameter");
1676 return NOTI_EX_ERROR_INVALID_PARAMETER;
1678 Handle* p = static_cast<Handle*>(handle);
1679 if (p->Get()->GetAction() == nullptr) {
1681 return NOTI_EX_ERROR_NONE;
1683 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1685 return NOTI_EX_ERROR_NONE;
1688 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1689 noti_ex_action_h action) {
1690 if (handle == nullptr || action == nullptr) {
1691 LOGE("Invalid parameter");
1692 return NOTI_EX_ERROR_INVALID_PARAMETER;
1695 Handle* p = static_cast<Handle*>(handle);
1696 AbstractAction* a = static_cast<AbstractAction*>(action);
1697 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1698 return NOTI_EX_ERROR_NONE;
1701 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1702 noti_ex_style_h *style) {
1703 if (handle == nullptr || style == nullptr) {
1704 LOGE("Invalid parameter");
1705 return NOTI_EX_ERROR_INVALID_PARAMETER;
1708 Handle* p = static_cast<Handle*>(handle);
1709 shared_ptr<Style> s = p->Get()->GetStyle();
1710 if (s.get() == nullptr) {
1711 LOGE("Style is null");
1712 return NOTI_EX_ERROR_INVALID_PARAMETER;
1715 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1716 if (ptr == nullptr || ptr->get() == nullptr) {
1717 LOGE("Out of memory");
1718 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1722 return NOTI_EX_ERROR_NONE;
1725 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1726 noti_ex_style_h style) {
1727 if (handle == nullptr || style == nullptr) {
1728 LOGE("Invalid parameter");
1729 return NOTI_EX_ERROR_INVALID_PARAMETER;
1732 Handle* p = static_cast<Handle*>(handle);
1733 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1734 p->Get()->SetStyle(*s);
1735 return NOTI_EX_ERROR_NONE;
1738 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1740 if (handle == nullptr) {
1741 LOGE("Invalid parameter");
1742 return NOTI_EX_ERROR_INVALID_PARAMETER;
1745 Handle* p = static_cast<Handle*>(handle);
1746 p->Get()->SetVisible(visible);
1747 return NOTI_EX_ERROR_NONE;
1750 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1752 if (handle == nullptr || visible == nullptr) {
1753 LOGE("Invalid parameter");
1754 return NOTI_EX_ERROR_INVALID_PARAMETER;
1757 Handle* p = static_cast<Handle*>(handle);
1758 *visible = p->Get()->GetVisible();
1759 return NOTI_EX_ERROR_NONE;
1762 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1764 if (handle == nullptr) {
1765 LOGE("Invalid parameter");
1766 return NOTI_EX_ERROR_INVALID_PARAMETER;
1769 Handle* p = static_cast<Handle*>(handle);
1770 p->Get()->SetEnable(enable);
1771 return NOTI_EX_ERROR_NONE;
1774 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1776 if (handle == nullptr || enable == nullptr) {
1777 LOGE("Invalid parameter");
1778 return NOTI_EX_ERROR_INVALID_PARAMETER;
1781 Handle* p = static_cast<Handle*>(handle);
1782 *enable = p->Get()->GetEnable();
1783 return NOTI_EX_ERROR_NONE;
1786 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1787 const char *receiver_group) {
1788 if (handle == nullptr || receiver_group == nullptr) {
1789 LOGE("Invalid parameter");
1790 return NOTI_EX_ERROR_INVALID_PARAMETER;
1793 Handle* p = static_cast<Handle*>(handle);
1794 p->Get()->AddReceiver(receiver_group);
1795 return NOTI_EX_ERROR_NONE;
1798 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1799 const char *receiver_group) {
1800 if (handle == nullptr || receiver_group == nullptr) {
1801 LOGE("Invalid parameter");
1802 return NOTI_EX_ERROR_INVALID_PARAMETER;
1805 Handle* p = static_cast<Handle*>(handle);
1806 p->Get()->RemoveReceiver(receiver_group);
1807 return NOTI_EX_ERROR_NONE;
1810 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1811 char ***receiver_list, int *count) {
1812 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1813 LOGE("Invalid parameter");
1814 return NOTI_EX_ERROR_INVALID_PARAMETER;
1817 Handle* p = static_cast<Handle*>(handle);
1818 list<string> receivers = p->Get()->GetReceiverList();
1819 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
1820 if (tmp_list == nullptr) {
1821 LOGE("Out of memory");
1822 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1826 for (auto& i : receivers) {
1827 tmp_list[idx] = strdup(i.c_str());
1828 if (tmp_list[idx] == nullptr) {
1829 __noti_ex_free_str_array(tmp_list, idx);
1830 LOGE("Out of memory");
1831 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1836 *receiver_list = tmp_list;
1837 *count = receivers.size();
1838 return NOTI_EX_ERROR_NONE;
1841 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1843 if (handle == nullptr) {
1844 LOGE("Invalid parameter");
1845 return NOTI_EX_ERROR_INVALID_PARAMETER;
1848 Handle* p = static_cast<Handle*>(handle);
1849 p->Get()->SetPolicy(policy);
1850 return NOTI_EX_ERROR_NONE;
1853 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1855 if (handle == nullptr || policy == nullptr) {
1856 LOGE("Invalid parameter");
1857 return NOTI_EX_ERROR_INVALID_PARAMETER;
1860 Handle* p = static_cast<Handle*>(handle);
1861 *policy = p->Get()->GetPolicy();
1862 return NOTI_EX_ERROR_NONE;
1865 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1867 if (handle == nullptr || channel == nullptr) {
1868 LOGE("Invalid parameter");
1869 return NOTI_EX_ERROR_INVALID_PARAMETER;
1872 Handle* p = static_cast<Handle*>(handle);
1873 if (!p->Get()->GetChannel().empty())
1874 *channel = strdup(p->Get()->GetChannel().c_str());
1878 return NOTI_EX_ERROR_NONE;
1881 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1882 const char *channel) {
1883 if (handle == nullptr) {
1884 LOGE("Invalid parameter");
1885 return NOTI_EX_ERROR_INVALID_PARAMETER;
1888 Handle* p = static_cast<Handle*>(handle);
1889 p->Get()->SetChannel(channel);
1890 return NOTI_EX_ERROR_NONE;
1893 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1894 noti_ex_led_info_h led) {
1895 if (handle == nullptr) {
1896 LOGE("Invalid parameter");
1897 return NOTI_EX_ERROR_INVALID_PARAMETER;
1900 Handle* p = static_cast<Handle*>(handle);
1901 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1902 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1907 noti_ex_led_info_h *led) {
1908 if (handle == nullptr) {
1909 LOGE("Invalid parameter");
1910 return NOTI_EX_ERROR_INVALID_PARAMETER;
1913 Handle* p = static_cast<Handle*>(handle);
1914 if (p->Get()->GetLEDInfo() != nullptr)
1915 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1918 return NOTI_EX_ERROR_NONE;
1921 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1923 if (handle == nullptr) {
1924 LOGE("Invalid parameter");
1925 return NOTI_EX_ERROR_INVALID_PARAMETER;
1928 Handle* p = static_cast<Handle*>(handle);
1929 if (path == nullptr)
1930 p->Get()->SetSoundPath("");
1932 p->Get()->SetSoundPath(path);
1933 return NOTI_EX_ERROR_NONE;
1936 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(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 if (path == nullptr)
1945 p->Get()->SetVibrationPath("");
1947 p->Get()->SetVibrationPath(path);
1948 return NOTI_EX_ERROR_NONE;
1951 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1953 if (handle == nullptr || path == nullptr) {
1954 LOGE("Invalid parameter");
1955 return NOTI_EX_ERROR_INVALID_PARAMETER;
1958 Handle* p = static_cast<Handle*>(handle);
1959 if (p->Get()->GetSoundPath().empty())
1962 *path = strdup(p->Get()->GetSoundPath().c_str());
1963 return NOTI_EX_ERROR_NONE;
1966 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1968 if (handle == nullptr || path == nullptr) {
1969 LOGE("Invalid parameter");
1970 return NOTI_EX_ERROR_INVALID_PARAMETER;
1973 Handle* p = static_cast<Handle*>(handle);
1974 if (p->Get()->GetVibrationPath().empty())
1977 *path = strdup(p->Get()->GetVibrationPath().c_str());
1978 return NOTI_EX_ERROR_NONE;
1981 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1982 noti_ex_item_info_h *info) {
1983 if (handle == nullptr || info == nullptr) {
1984 LOGE("Invalid parameter");
1985 return NOTI_EX_ERROR_INVALID_PARAMETER;
1988 Handle* p = static_cast<Handle*>(handle);
1989 if (p->Get()->GetInfo() == nullptr)
1992 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1993 return NOTI_EX_ERROR_NONE;
1996 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1998 if (handle == nullptr || id == nullptr) {
1999 LOGE("Invalid parameter");
2000 return NOTI_EX_ERROR_INVALID_PARAMETER;
2003 Handle* p = static_cast<Handle*>(handle);
2004 if (p->Get()->GetSenderAppId().empty())
2007 *id = strdup(p->Get()->GetSenderAppId().c_str());
2008 return NOTI_EX_ERROR_NONE;
2011 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2013 if (handle == nullptr || tag == nullptr) {
2014 LOGE("Invalid parameter");
2015 return NOTI_EX_ERROR_INVALID_PARAMETER;
2018 Handle* p = static_cast<Handle*>(handle);
2019 if (p->Get()->GetTag().empty())
2022 *tag = strdup(p->Get()->GetTag().c_str());
2023 return NOTI_EX_ERROR_NONE;
2026 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2028 if (handle == nullptr) {
2029 LOGE("Invalid parameter");
2030 return NOTI_EX_ERROR_INVALID_PARAMETER;
2033 Handle* p = static_cast<Handle*>(handle);
2035 p->Get()->SetTag("");
2037 p->Get()->SetTag(tag);
2038 return NOTI_EX_ERROR_NONE;
2041 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2042 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2044 if (handle == nullptr) {
2045 LOGE("Invalid parameter");
2046 return NOTI_EX_ERROR_INVALID_PARAMETER;
2049 string receiver_group_str = "";
2051 receiver_group_str = string(receiver_group);
2053 ManagerStub* stub = new (std::nothrow) ManagerStub(
2054 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2055 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2056 receiver_group_str);
2057 if (stub == nullptr) {
2058 LOGE("Fail to create manager");
2059 return NOTI_EX_ERROR_IO_ERROR;
2061 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2062 new ManagerCallbackInfo(event_callbacks, data)));
2063 *handle = static_cast<noti_ex_manager_h>(stub);
2065 return NOTI_EX_ERROR_NONE;
2068 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2069 if (handle == nullptr) {
2070 LOGE("Invalid parameter");
2071 return NOTI_EX_ERROR_INVALID_PARAMETER;
2073 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2075 return NOTI_EX_ERROR_NONE;
2078 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2079 noti_ex_item_h **items, int *count) {
2080 if (handle == nullptr || items == nullptr || count == nullptr) {
2081 LOGE("Invalid parameter");
2082 return NOTI_EX_ERROR_INVALID_PARAMETER;
2086 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2087 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2088 if (item_list.size() == 0) {
2091 return NOTI_EX_ERROR_NONE;
2093 noti_ex_item_h* added_item =
2094 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2095 if (added_item == nullptr) {
2096 LOGE("Fail to create items");
2097 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2101 for (auto& i : item_list) {
2102 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2104 *items = added_item;
2105 *count = item_list.size();
2106 } catch (Exception &ex) {
2107 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2108 return NOTI_EX_ERROR_IO_ERROR;
2110 return NOTI_EX_ERROR_NONE;
2113 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2114 noti_ex_item_h noti, int *request_id) {
2115 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2116 LOGE("Invalid parameter");
2117 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2121 Handle* sp = static_cast<Handle*>(noti);
2122 if (sp->GetPtr().get() == nullptr) {
2123 LOGE("Invalid noti reference can not be sended");
2124 return NOTI_EX_ERROR_INVALID_PARAMETER;
2126 *request_id = stub->Update(sp->GetPtr());
2128 } catch (Exception &ex) {
2129 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2130 return NOTI_EX_ERROR_IO_ERROR;
2132 return NOTI_EX_ERROR_NONE;
2135 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2136 noti_ex_item_h noti, int *request_id) {
2137 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2138 LOGE("Invalid parameter");
2139 return NOTI_EX_ERROR_INVALID_PARAMETER;
2142 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2143 Handle* item = static_cast<Handle*>(noti);
2144 if (item->GetPtr().get() == nullptr) {
2145 LOGE("Invalid noti reference can not be sended");
2146 return NOTI_EX_ERROR_INVALID_PARAMETER;
2148 *request_id = stub->Delete(item->GetPtr());
2150 } catch (Exception &ex) {
2151 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2152 return NOTI_EX_ERROR_IO_ERROR;
2154 return NOTI_EX_ERROR_NONE;
2157 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2159 if (handle == nullptr || request_id == nullptr) {
2160 LOGE("Invalid parameter");
2161 return NOTI_EX_ERROR_INVALID_PARAMETER;
2164 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2165 *request_id = stub->DeleteAll();
2166 } catch (Exception &ex) {
2167 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2168 return NOTI_EX_ERROR_IO_ERROR;
2170 return NOTI_EX_ERROR_NONE;
2173 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2174 noti_ex_item_h noti, int *request_id) {
2175 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2176 LOGE("Invalid parameter");
2177 return NOTI_EX_ERROR_INVALID_PARAMETER;
2180 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2181 Handle* item = static_cast<Handle*>(noti);
2182 if (item->GetPtr().get() == nullptr) {
2183 LOGE("Invalid noti reference can not be sended");
2184 return NOTI_EX_ERROR_INVALID_PARAMETER;
2186 *request_id = stub->Hide(item->GetPtr());
2188 } catch (Exception &ex) {
2189 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2190 return NOTI_EX_ERROR_IO_ERROR;
2192 return NOTI_EX_ERROR_NONE;
2195 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2196 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2197 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2198 LOGE("Invalid parameter");
2199 return NOTI_EX_ERROR_INVALID_PARAMETER;
2202 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2203 *item = new Handle(stub->FindByRootID(root_id));
2204 } catch (Exception &ex) {
2205 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2206 return NOTI_EX_ERROR_IO_ERROR;
2208 return NOTI_EX_ERROR_NONE;
2211 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2212 noti_ex_event_info_h info, noti_ex_error_e error) {
2213 if (handle == nullptr || info == nullptr) {
2214 LOGE("Invalid parameter");
2215 return NOTI_EX_ERROR_INVALID_PARAMETER;
2218 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2219 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2220 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2221 static_cast<NotificationError>(error));
2222 } catch (Exception &ex) {
2223 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2224 return NOTI_EX_ERROR_IO_ERROR;
2226 return NOTI_EX_ERROR_NONE;
2229 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2230 noti_ex_manager_h handle, int *cnt) {
2232 if (handle == nullptr || cnt == nullptr) {
2233 LOGE("Invalid parameter");
2234 return NOTI_EX_ERROR_INVALID_PARAMETER;
2237 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2238 *cnt = stub->GetCount();
2239 } catch (Exception &ex) {
2240 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2241 return NOTI_EX_ERROR_IO_ERROR;
2243 return NOTI_EX_ERROR_NONE;
2246 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2247 const char *id, float min, float current, float max) {
2250 if (handle == nullptr) {
2251 LOGE("Invalid parameter");
2252 return NOTI_EX_ERROR_INVALID_PARAMETER;
2256 p = new (std::nothrow) ProgressItem(id, min, current, max);
2258 p = new (std::nothrow) ProgressItem(min, current, max);
2261 LOGE("Out-of-memory");
2262 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2265 *handle = new Handle(shared_ptr<AbstractItem>(p));
2267 return NOTI_EX_ERROR_NONE;
2270 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2271 noti_ex_item_h handle, float *current) {
2272 if (handle == nullptr || current == nullptr) {
2273 LOGE("Invalid parameter");
2274 return NOTI_EX_ERROR_INVALID_PARAMETER;
2277 Handle *h = static_cast<Handle*>(handle);
2278 if (!h->IsValidType(AbstractItem::Progress)) {
2279 LOGE("Invalid handle type");
2280 return NOTI_EX_ERROR_INVALID_PARAMETER;
2282 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2283 *current = p->GetCurrent();
2285 return NOTI_EX_ERROR_NONE;
2288 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2289 noti_ex_item_h handle, float current) {
2290 if (handle == nullptr) {
2291 LOGE("Invalid parameter");
2292 return NOTI_EX_ERROR_INVALID_PARAMETER;
2295 Handle *h = static_cast<Handle*>(handle);
2296 if (!h->IsValidType(AbstractItem::Progress)) {
2297 LOGE("Invalid handle type");
2298 return NOTI_EX_ERROR_INVALID_PARAMETER;
2300 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2301 p->SetCurrent(current);
2303 return NOTI_EX_ERROR_NONE;
2306 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2308 if (handle == nullptr || min == nullptr) {
2309 LOGE("Invalid parameter");
2310 return NOTI_EX_ERROR_INVALID_PARAMETER;
2313 Handle *h = static_cast<Handle*>(handle);
2314 if (!h->IsValidType(AbstractItem::Progress)) {
2315 LOGE("Invalid handle type");
2316 return NOTI_EX_ERROR_INVALID_PARAMETER;
2318 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2321 return NOTI_EX_ERROR_NONE;
2324 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2326 if (handle == nullptr || max == nullptr) {
2327 LOGE("Invalid parameter");
2328 return NOTI_EX_ERROR_INVALID_PARAMETER;
2331 Handle *h = static_cast<Handle*>(handle);
2332 if (!h->IsValidType(AbstractItem::Progress)) {
2333 LOGE("Invalid handle type");
2334 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2339 return NOTI_EX_ERROR_NONE;
2342 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2343 noti_ex_reporter_events_s event_callbacks, void *data) {
2344 if (handle == nullptr) {
2345 LOGE("Invalid parameter");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2349 ReporterStub* stub = new (std::nothrow) ReporterStub(
2350 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2351 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2352 if (stub == nullptr) {
2353 LOGE("Fail to create manager");
2354 return NOTI_EX_ERROR_IO_ERROR;
2356 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2357 new ReporterCallbackInfo(event_callbacks, data)));
2359 *handle = static_cast<noti_ex_reporter_h>(stub);
2361 return NOTI_EX_ERROR_NONE;
2364 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2365 if (handle == nullptr) {
2366 LOGE("Invalid parameter");
2367 return NOTI_EX_ERROR_INVALID_PARAMETER;
2369 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2371 return NOTI_EX_ERROR_NONE;
2374 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2375 noti_ex_event_info_h info, noti_ex_error_e error) {
2376 if (handle == nullptr || info == nullptr) {
2377 LOGE("Invalid parameter");
2378 return NOTI_EX_ERROR_INVALID_PARAMETER;
2381 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2382 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2383 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2384 static_cast<NotificationError>(error));
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_reporter_post(noti_ex_reporter_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 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2400 Handle* h = static_cast<Handle*>(noti);
2401 if (h->GetPtr().get() == nullptr) {
2402 LOGE("Invalid noti reference can not be sended");
2403 return NOTI_EX_ERROR_INVALID_PARAMETER;
2405 *request_id = stub->Post(h->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_reporter_post_list(noti_ex_reporter_h handle,
2415 noti_ex_item_h *noti_list, int count, int *request_id) {
2417 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2418 LOGE("Invalid parameter");
2419 return NOTI_EX_ERROR_INVALID_PARAMETER;
2422 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2423 list<shared_ptr<item::AbstractItem>> notiList;
2424 for (int i = 0; i < count; i++) {
2425 Handle* item = static_cast<Handle*>(noti_list[i]);
2426 notiList.push_back(item->GetPtr());
2428 *request_id = stub->Post(notiList);
2429 } catch (Exception &ex) {
2430 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2431 return NOTI_EX_ERROR_IO_ERROR;
2433 return NOTI_EX_ERROR_NONE;
2436 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2437 noti_ex_item_h noti, int *request_id) {
2438 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2439 LOGE("Invalid parameter");
2440 return NOTI_EX_ERROR_INVALID_PARAMETER;
2443 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2444 Handle* item = static_cast<Handle*>(noti);
2445 if (item->GetPtr().get() == nullptr) {
2446 LOGE("Invalid noti reference can not be sended");
2447 return NOTI_EX_ERROR_INVALID_PARAMETER;
2449 *request_id = stub->Update(item->GetPtr());
2451 } catch (Exception &ex) {
2452 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2453 return NOTI_EX_ERROR_IO_ERROR;
2455 return NOTI_EX_ERROR_NONE;
2458 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2459 noti_ex_item_h noti, int *request_id) {
2460 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2461 LOGE("Invalid parameter");
2462 return NOTI_EX_ERROR_INVALID_PARAMETER;
2465 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2466 Handle* item = static_cast<Handle*>(noti);
2467 if (item->GetPtr().get() == nullptr) {
2468 LOGE("Invalid noti reference can not be sended");
2469 return NOTI_EX_ERROR_INVALID_PARAMETER;
2471 *request_id = stub->Delete(item->GetPtr());
2473 } catch (Exception &ex) {
2474 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2475 return NOTI_EX_ERROR_IO_ERROR;
2477 return NOTI_EX_ERROR_NONE;
2480 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2481 noti_ex_reporter_h handle, int *request_id) {
2482 if (handle == nullptr || request_id == nullptr) {
2483 LOGE("Invalid parameter");
2484 return NOTI_EX_ERROR_INVALID_PARAMETER;
2487 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2488 *request_id = stub->DeleteAll();
2489 } catch (Exception &ex) {
2490 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2491 return NOTI_EX_ERROR_IO_ERROR;
2493 return NOTI_EX_ERROR_NONE;
2496 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2497 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2498 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2499 LOGE("Invalid parameter");
2500 return NOTI_EX_ERROR_INVALID_PARAMETER;
2503 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2504 *item = new Handle(stub->FindByRootID(root_id));
2505 } catch (Exception &ex) {
2506 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2507 return NOTI_EX_ERROR_IO_ERROR;
2509 return NOTI_EX_ERROR_NONE;
2512 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2513 const char *id, const char *text, const char *hyperlink) {
2514 if (handle == nullptr || text == nullptr) {
2515 LOGE("Invalid parameter");
2516 return NOTI_EX_ERROR_INVALID_PARAMETER;
2522 p = new (std::nothrow) TextItem(id, std::string(text),
2523 std::string(hyperlink));
2525 p = new (std::nothrow) TextItem(id, std::string(text));
2528 LOGE("Out-of-memory");
2529 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2532 *handle = new Handle(shared_ptr<AbstractItem>(p));
2534 return NOTI_EX_ERROR_NONE;
2537 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2538 const char *contents) {
2539 if (handle == nullptr || contents == nullptr) {
2540 LOGE("Invalid parameter");
2541 return NOTI_EX_ERROR_INVALID_PARAMETER;
2544 Handle* p = static_cast<Handle*>(handle);
2545 if (!p->IsValidType(AbstractItem::Text)) {
2546 LOGE("Invalid handle type");
2547 return NOTI_EX_ERROR_INVALID_PARAMETER;
2549 TextItem* ti = static_cast<TextItem*>(p->Get());
2550 ti->SetContents(std::string(contents));
2552 return NOTI_EX_ERROR_NONE;
2555 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2557 if (handle == nullptr || contents == nullptr) {
2558 LOGE("Invalid parameter");
2559 return NOTI_EX_ERROR_INVALID_PARAMETER;
2562 Handle* p = static_cast<Handle*>(handle);
2563 if (!p->IsValidType(AbstractItem::Text)) {
2564 LOGE("Invalid handle type");
2565 return NOTI_EX_ERROR_INVALID_PARAMETER;
2567 TextItem* ti = static_cast<TextItem*>(p->Get());
2568 if (!ti->GetContents().empty()) {
2569 *contents = strdup(ti->GetContents().c_str());
2570 if (*contents == nullptr) {
2571 LOGE("Out-of-memory");
2572 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2576 return NOTI_EX_ERROR_NONE;
2579 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2580 noti_ex_item_h handle, char **hyper_link) {
2581 if (handle == nullptr || hyper_link == nullptr) {
2582 LOGE("Invalid parameter");
2583 return NOTI_EX_ERROR_INVALID_PARAMETER;
2586 Handle* p = static_cast<Handle*>(handle);
2587 if (!p->IsValidType(AbstractItem::Text)) {
2588 LOGE("Invalid handle type");
2589 return NOTI_EX_ERROR_INVALID_PARAMETER;
2591 TextItem* ti = static_cast<TextItem*>(p->Get());
2592 if (!ti->GetHyperLink().empty()) {
2593 *hyper_link = strdup(ti->GetHyperLink().c_str());
2594 if (*hyper_link == nullptr) {
2595 LOGE("Out-of-memory");
2596 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2600 return NOTI_EX_ERROR_NONE;
2603 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2604 const char *id, time_t time) {
2607 if (handle == nullptr) {
2608 LOGE("Invalid parameter");
2609 return NOTI_EX_ERROR_INVALID_PARAMETER;
2614 p = new (std::nothrow) TimeItem(id, time);
2616 p = new (std::nothrow) TimeItem(time);
2618 p = new (std::nothrow) TimeItem();
2622 LOGE("Out-of-memory");
2623 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2626 *handle = new Handle(shared_ptr<AbstractItem>(p));
2628 return NOTI_EX_ERROR_NONE;
2631 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2633 if (handle == nullptr || time == nullptr) {
2634 LOGE("Invalid parameter");
2635 return NOTI_EX_ERROR_INVALID_PARAMETER;
2637 Handle* h = static_cast<Handle*>(handle);
2638 if (!h->IsValidType(AbstractItem::Time)) {
2639 LOGE("Invalid handle type");
2640 return NOTI_EX_ERROR_INVALID_PARAMETER;
2642 TimeItem* p = static_cast<TimeItem*>(h->Get());
2643 *time = p->GetTime();
2645 return NOTI_EX_ERROR_NONE;
2648 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2649 noti_ex_action_h *handle, const char *extra) {
2650 if (handle == nullptr) {
2651 LOGE("Invalid parameter");
2652 return NOTI_EX_ERROR_INVALID_PARAMETER;
2655 string extra_str = "";
2657 extra_str = string(extra);
2659 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2661 LOGE("Out-of-memory");
2662 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2667 return NOTI_EX_ERROR_NONE;
2670 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2671 const char *id, bool visible) {
2672 if (handle == nullptr || id == nullptr) {
2673 LOGE("Invalid parameter");
2674 return NOTI_EX_ERROR_INVALID_PARAMETER;
2677 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2678 p->SetVisibility(id, visible);
2680 return NOTI_EX_ERROR_NONE;