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* ptr = new (std::nothrow) shared_ptr<Padding>(
1069 new (std::nothrow) Padding(left, top, right, bottom));
1070 if (ptr == nullptr || ptr->get() == nullptr) {
1071 LOGE("Out-of-memory");
1072 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1077 return NOTI_EX_ERROR_NONE;
1080 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1081 if (handle == nullptr) {
1082 LOGE("Invalid parameter");
1083 return NOTI_EX_ERROR_INVALID_PARAMETER;
1086 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1089 return NOTI_EX_ERROR_NONE;
1092 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1094 if (handle == nullptr || val == nullptr) {
1095 LOGE("Invalid parameter");
1096 return NOTI_EX_ERROR_INVALID_PARAMETER;
1099 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1100 *val = (*p)->GetLeft();
1102 return NOTI_EX_ERROR_NONE;
1105 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1107 if (handle == nullptr || val == nullptr) {
1108 LOGE("Invalid parameter");
1109 return NOTI_EX_ERROR_INVALID_PARAMETER;
1112 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1113 *val = (*p)->GetTop();
1115 return NOTI_EX_ERROR_NONE;
1118 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1120 if (handle == nullptr || val == nullptr) {
1121 LOGE("Invalid parameter");
1122 return NOTI_EX_ERROR_INVALID_PARAMETER;
1125 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1126 *val = (*p)->GetRight();
1128 return NOTI_EX_ERROR_NONE;
1131 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1133 if (handle == nullptr || val == nullptr) {
1134 LOGE("Invalid parameter");
1135 return NOTI_EX_ERROR_INVALID_PARAMETER;
1138 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1139 *val = (*p)->GetBottom();
1141 return NOTI_EX_ERROR_NONE;
1144 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1145 int x, int y, int w, int h) {
1146 if (handle == nullptr) {
1147 LOGE("Invalid parameter");
1148 return NOTI_EX_ERROR_INVALID_PARAMETER;
1151 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1152 new (std::nothrow) Geometry(x, y, w, h));
1153 if (ptr == nullptr || ptr->get() == nullptr) {
1154 LOGE("Out-of-memory");
1155 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1160 return NOTI_EX_ERROR_NONE;
1163 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1164 if (handle == nullptr) {
1165 LOGE("Invalid parameter");
1166 return NOTI_EX_ERROR_INVALID_PARAMETER;
1169 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1172 return NOTI_EX_ERROR_NONE;
1175 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1177 if (handle == nullptr || val == nullptr) {
1178 LOGE("Invalid parameter");
1179 return NOTI_EX_ERROR_INVALID_PARAMETER;
1182 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1183 *val = (*p)->GetX();
1185 return NOTI_EX_ERROR_NONE;
1188 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1190 if (handle == nullptr || val == nullptr) {
1191 LOGE("Invalid parameter");
1192 return NOTI_EX_ERROR_INVALID_PARAMETER;
1195 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1196 *val = (*p)->GetY();
1198 return NOTI_EX_ERROR_NONE;
1201 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1203 if (handle == nullptr || val == nullptr) {
1204 LOGE("Invalid parameter");
1205 return NOTI_EX_ERROR_INVALID_PARAMETER;
1208 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1209 *val = (*p)->GetWidth();
1211 return NOTI_EX_ERROR_NONE;
1214 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1216 if (handle == nullptr || val == nullptr) {
1217 LOGE("Invalid parameter");
1218 return NOTI_EX_ERROR_INVALID_PARAMETER;
1221 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1222 *val = (*p)->GetHeight();
1224 return NOTI_EX_ERROR_NONE;
1227 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1228 noti_ex_color_h color,
1229 noti_ex_padding_h padding,
1230 noti_ex_geometry_h geometry) {
1231 if (handle == nullptr) {
1232 LOGE("Invalid parameter");
1233 return NOTI_EX_ERROR_INVALID_PARAMETER;
1236 shared_ptr<Color> col = (color == nullptr) ?
1237 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1238 shared_ptr<Padding> padd = (padding == nullptr) ?
1239 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1240 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1241 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1243 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1244 new (std::nothrow) Style(col, padd, geo));
1245 if (ptr == nullptr || ptr->get() == nullptr) {
1246 LOGE("Out-of-memory");
1247 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1252 return NOTI_EX_ERROR_NONE;
1255 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1256 if (handle == nullptr) {
1257 LOGE("Invalid parameter");
1258 return NOTI_EX_ERROR_INVALID_PARAMETER;
1261 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1264 return NOTI_EX_ERROR_NONE;
1267 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1268 noti_ex_padding_h *padding) {
1269 if (handle == nullptr || padding == nullptr) {
1270 LOGE("Invalid parameter");
1271 return NOTI_EX_ERROR_INVALID_PARAMETER;
1274 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1275 if ((*p)->GetPadding() == nullptr) {
1276 LOGW("Padding info is null");
1277 return NOTI_EX_ERROR_INVALID_PARAMETER;
1280 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1281 new (std::nothrow) Padding(*((*p)->GetPadding())));
1282 if (padd == nullptr || padd->get() == nullptr) {
1283 LOGE("Out-of-memory");
1284 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1289 return NOTI_EX_ERROR_NONE;
1292 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1293 noti_ex_color_h *color) {
1294 if (handle == nullptr || color == nullptr) {
1295 LOGE("Invalid parameter");
1296 return NOTI_EX_ERROR_INVALID_PARAMETER;
1299 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1300 if ((*p)->GetColor() == nullptr) {
1301 LOGW("Color info is null");
1302 return NOTI_EX_ERROR_INVALID_PARAMETER;
1305 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1306 new (std::nothrow) Color(*((*p)->GetColor())));
1307 if (col == nullptr || col->get() == nullptr) {
1308 LOGE("Out-of-memory");
1309 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1314 return NOTI_EX_ERROR_NONE;
1317 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1318 noti_ex_geometry_h *geometry) {
1319 if (handle == nullptr || geometry == nullptr) {
1320 LOGE("Invalid parameter");
1321 return NOTI_EX_ERROR_INVALID_PARAMETER;
1324 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1325 if ((*p)->GetGeometry() == nullptr) {
1326 LOGW("Geometry info is null");
1327 return NOTI_EX_ERROR_INVALID_PARAMETER;
1330 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1331 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1332 if (geo == nullptr || geo->get() == nullptr) {
1333 LOGE("Out-of-memory");
1334 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1339 return NOTI_EX_ERROR_NONE;
1342 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1343 noti_ex_color_h color) {
1344 if (handle == nullptr) {
1345 LOGE("Invalid parameter");
1346 return NOTI_EX_ERROR_INVALID_PARAMETER;
1349 shared_ptr<Color>* color_ = static_cast<shared_ptr<Color>*>(color);
1350 auto* p = new (std::nothrow) LEDInfo(*color_);
1352 LOGE("Out-of-memory");
1353 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1358 return NOTI_EX_ERROR_NONE;
1361 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1362 if (handle == nullptr) {
1363 LOGE("Invalid parameter");
1364 return NOTI_EX_ERROR_INVALID_PARAMETER;
1367 LEDInfo* p = static_cast<LEDInfo*>(handle);
1370 return NOTI_EX_ERROR_NONE;
1373 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1374 noti_ex_led_info_h handle, int ms) {
1375 if (handle == nullptr) {
1376 LOGE("Invalid parameter");
1377 return NOTI_EX_ERROR_INVALID_PARAMETER;
1380 LEDInfo* p = static_cast<LEDInfo*>(handle);
1383 return NOTI_EX_ERROR_NONE;
1386 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1387 noti_ex_led_info_h handle, int *ms) {
1388 if (handle == nullptr || ms == nullptr) {
1389 LOGE("Invalid parameter");
1390 return NOTI_EX_ERROR_INVALID_PARAMETER;
1393 LEDInfo* p = static_cast<LEDInfo*>(handle);
1394 *ms = p->GetOnPeriod();
1396 return NOTI_EX_ERROR_NONE;
1399 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1400 noti_ex_led_info_h handle, int ms) {
1401 if (handle == nullptr) {
1402 LOGE("Invalid parameter");
1403 return NOTI_EX_ERROR_INVALID_PARAMETER;
1406 LEDInfo* p = static_cast<LEDInfo*>(handle);
1407 p->SetOffPeriod(ms);
1409 return NOTI_EX_ERROR_NONE;
1412 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1413 noti_ex_led_info_h handle, int *ms) {
1414 if (handle == nullptr) {
1415 LOGE("Invalid parameter");
1416 return NOTI_EX_ERROR_INVALID_PARAMETER;
1419 LEDInfo* p = static_cast<LEDInfo*>(handle);
1420 *ms = p->GetOffPeriod();
1422 return NOTI_EX_ERROR_NONE;
1425 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1426 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1427 if (handle == nullptr) {
1428 LOGE("Invalid parameter");
1429 return NOTI_EX_ERROR_INVALID_PARAMETER;
1432 LEDInfo* p = static_cast<LEDInfo*>(handle);
1433 if (p->GetColor() == nullptr) {
1434 LOGE("Color is null");
1435 return NOTI_EX_ERROR_INVALID_PARAMETER;
1438 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1439 new (std::nothrow) Color(*(p->GetColor())));
1440 if (col == nullptr || col->get() == nullptr) {
1441 LOGE("Out-of-memory");
1442 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1447 return NOTI_EX_ERROR_NONE;
1450 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1451 if (handle == nullptr) {
1452 LOGE("Invalid parameter");
1453 return NOTI_EX_ERROR_INVALID_PARAMETER;
1456 AbstractAction* p = static_cast<AbstractAction*>(handle);
1457 p->~AbstractAction();
1459 return NOTI_EX_ERROR_NONE;
1462 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1464 if (handle == nullptr || type == nullptr) {
1465 LOGE("Invalid parameter");
1466 return NOTI_EX_ERROR_INVALID_PARAMETER;
1469 AbstractAction* p = static_cast<AbstractAction*>(handle);
1470 *type = p->GetType();
1472 return NOTI_EX_ERROR_NONE;
1475 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1477 if (handle == nullptr || local == nullptr) {
1478 LOGE("Invalid parameter");
1479 return NOTI_EX_ERROR_INVALID_PARAMETER;
1482 AbstractAction* p = static_cast<AbstractAction*>(handle);
1483 *local = p->IsLocal();
1485 return NOTI_EX_ERROR_NONE;
1488 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1489 noti_ex_item_h item) {
1490 if (handle == nullptr || item == nullptr) {
1491 LOGE("Invalid parameter");
1492 return NOTI_EX_ERROR_INVALID_PARAMETER;
1494 AbstractAction* p = static_cast<AbstractAction*>(handle);
1495 Handle* ih = static_cast<Handle*>(item);
1496 p->Execute(ih->GetPtr());
1498 return NOTI_EX_ERROR_NONE;
1501 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1503 if (handle == nullptr || extra == nullptr) {
1504 LOGE("Invalid parameter");
1505 return NOTI_EX_ERROR_INVALID_PARAMETER;
1508 AbstractAction* p = static_cast<AbstractAction*>(handle);
1509 if (!p->GetExtra().empty()) {
1510 *extra = strdup(p->GetExtra().c_str());
1511 if (*extra == nullptr) {
1512 LOGE("Out-of-memory");
1513 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1517 return NOTI_EX_ERROR_NONE;
1520 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1521 noti_ex_item_info_h handle, int *hide_time) {
1522 if (handle == nullptr || hide_time == nullptr) {
1523 LOGE("Invalid parameter");
1524 return NOTI_EX_ERROR_INVALID_PARAMETER;
1526 IItemInfo* p = static_cast<IItemInfo*>(handle);
1527 *hide_time = p->GetHideTime();
1528 return NOTI_EX_ERROR_NONE;
1531 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1532 noti_ex_item_info_h handle, int hide_time) {
1533 if (handle == nullptr) {
1534 LOGE("Invalid parameter");
1535 return NOTI_EX_ERROR_INVALID_PARAMETER;
1537 IItemInfo* p = static_cast<IItemInfo*>(handle);
1538 p->SetHideTime(hide_time);
1539 return NOTI_EX_ERROR_NONE;
1542 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1543 noti_ex_item_info_h handle, int *delete_time) {
1544 if (handle == nullptr || delete_time == nullptr) {
1545 LOGE("Invalid parameter");
1546 return NOTI_EX_ERROR_INVALID_PARAMETER;
1548 IItemInfo* p = static_cast<IItemInfo*>(handle);
1549 *delete_time = p->GetDeleteTime();
1550 return NOTI_EX_ERROR_NONE;
1553 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1554 noti_ex_item_info_h handle, int delete_time) {
1555 if (handle == nullptr) {
1556 LOGE("Invalid parameter");
1557 return NOTI_EX_ERROR_INVALID_PARAMETER;
1559 IItemInfo* p = static_cast<IItemInfo*>(handle);
1560 p->SetDeleteTime(delete_time);
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1565 noti_ex_item_info_h handle, time_t *time) {
1566 if (handle == nullptr || time == nullptr) {
1567 LOGE("Invalid parameter");
1568 return NOTI_EX_ERROR_INVALID_PARAMETER;
1571 IItemInfo* p = static_cast<IItemInfo*>(handle);
1572 *time = p->GetTime();
1573 return NOTI_EX_ERROR_NONE;
1576 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1577 if (handle == nullptr) {
1578 LOGE("Invalid parameter");
1579 return NOTI_EX_ERROR_INVALID_PARAMETER;
1582 Handle* h = static_cast<Handle*>(handle);
1584 return NOTI_EX_ERROR_NONE;
1587 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1588 const char *id, noti_ex_item_h *item) {
1589 if (handle == nullptr) {
1590 LOGE("Invalid parameter");
1591 return NOTI_EX_ERROR_INVALID_PARAMETER;
1594 Handle* p = static_cast<Handle*>(handle);
1595 AbstractItem& find_item = p->Get()->FindByID(string(id));
1596 *item = new Handle(&find_item);
1597 return NOTI_EX_ERROR_NONE;
1600 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1602 if (handle == nullptr || type == nullptr) {
1603 LOGE("Invalid parameter");
1604 return NOTI_EX_ERROR_INVALID_PARAMETER;
1607 Handle* h = static_cast<Handle*>(handle);
1608 AbstractItem* p = h->Get();
1609 *type = p->GetType();
1610 return NOTI_EX_ERROR_NONE;
1613 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1614 char ***path, int *count) {
1615 if (handle == nullptr || path == nullptr || count == nullptr) {
1616 LOGE("Invalid parameter");
1617 return NOTI_EX_ERROR_INVALID_PARAMETER;
1619 Handle* p = static_cast<Handle*>(handle);
1620 list<string> shared_path = p->Get()->GetSharedPath();
1621 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1622 if (tmp_path == nullptr) {
1623 LOGE("Fail to create items");
1624 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1628 for (auto& i : shared_path) {
1629 tmp_path[idx] = strdup(i.c_str());
1630 if (tmp_path[idx] == nullptr) {
1631 __noti_ex_free_str_array(tmp_path, idx);
1632 LOGE("Out of memory");
1633 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1639 *count = shared_path.size();
1640 return NOTI_EX_ERROR_NONE;
1643 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1645 if (handle == nullptr || id == nullptr) {
1646 LOGE("Invalid parameter");
1647 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 Handle* h = static_cast<Handle*>(handle);
1650 AbstractItem* p = h->Get();
1651 *id = strdup(p->GetId().c_str());
1652 return NOTI_EX_ERROR_NONE;
1655 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1657 if (handle == nullptr || id == nullptr) {
1658 LOGE("Invalid parameter");
1659 return NOTI_EX_ERROR_INVALID_PARAMETER;
1661 Handle* p = static_cast<Handle*>(handle);
1662 p->Get()->SetId(id);
1663 return NOTI_EX_ERROR_NONE;
1666 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1667 noti_ex_action_h *action) {
1668 if (handle == nullptr || action == nullptr) {
1669 LOGE("Invalid parameter");
1670 return NOTI_EX_ERROR_INVALID_PARAMETER;
1672 Handle* p = static_cast<Handle*>(handle);
1673 if (p->Get()->GetAction() == nullptr) {
1675 return NOTI_EX_ERROR_NONE;
1677 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1679 return NOTI_EX_ERROR_NONE;
1682 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1683 noti_ex_action_h action) {
1684 if (handle == nullptr || action == nullptr) {
1685 LOGE("Invalid parameter");
1686 return NOTI_EX_ERROR_INVALID_PARAMETER;
1689 Handle* p = static_cast<Handle*>(handle);
1690 AbstractAction* a = static_cast<AbstractAction*>(action);
1691 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1692 return NOTI_EX_ERROR_NONE;
1695 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1696 noti_ex_style_h *style) {
1697 if (handle == nullptr || style == nullptr) {
1698 LOGE("Invalid parameter");
1699 return NOTI_EX_ERROR_INVALID_PARAMETER;
1702 Handle* p = static_cast<Handle*>(handle);
1703 shared_ptr<Style> s = p->Get()->GetStyle();
1704 if (s.get() == nullptr) {
1705 LOGE("Style is null");
1706 return NOTI_EX_ERROR_INVALID_PARAMETER;
1709 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1710 if (ptr == nullptr || ptr->get() == nullptr) {
1711 LOGE("Out of memory");
1712 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1716 return NOTI_EX_ERROR_NONE;
1719 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1720 noti_ex_style_h style) {
1721 if (handle == nullptr || style == nullptr) {
1722 LOGE("Invalid parameter");
1723 return NOTI_EX_ERROR_INVALID_PARAMETER;
1726 Handle* p = static_cast<Handle*>(handle);
1727 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1728 p->Get()->SetStyle(*s);
1729 return NOTI_EX_ERROR_NONE;
1732 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1734 if (handle == nullptr) {
1735 LOGE("Invalid parameter");
1736 return NOTI_EX_ERROR_INVALID_PARAMETER;
1739 Handle* p = static_cast<Handle*>(handle);
1740 p->Get()->SetVisible(visible);
1741 return NOTI_EX_ERROR_NONE;
1744 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1746 if (handle == nullptr || visible == nullptr) {
1747 LOGE("Invalid parameter");
1748 return NOTI_EX_ERROR_INVALID_PARAMETER;
1751 Handle* p = static_cast<Handle*>(handle);
1752 *visible = p->Get()->GetVisible();
1753 return NOTI_EX_ERROR_NONE;
1756 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1758 if (handle == nullptr) {
1759 LOGE("Invalid parameter");
1760 return NOTI_EX_ERROR_INVALID_PARAMETER;
1763 Handle* p = static_cast<Handle*>(handle);
1764 p->Get()->SetEnable(enable);
1765 return NOTI_EX_ERROR_NONE;
1768 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1770 if (handle == nullptr || enable == nullptr) {
1771 LOGE("Invalid parameter");
1772 return NOTI_EX_ERROR_INVALID_PARAMETER;
1775 Handle* p = static_cast<Handle*>(handle);
1776 *enable = p->Get()->GetEnable();
1777 return NOTI_EX_ERROR_NONE;
1780 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1781 const char *receiver_group) {
1782 if (handle == nullptr || receiver_group == nullptr) {
1783 LOGE("Invalid parameter");
1784 return NOTI_EX_ERROR_INVALID_PARAMETER;
1787 Handle* p = static_cast<Handle*>(handle);
1788 p->Get()->AddReceiver(receiver_group);
1789 return NOTI_EX_ERROR_NONE;
1792 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1793 const char *receiver_group) {
1794 if (handle == nullptr || receiver_group == nullptr) {
1795 LOGE("Invalid parameter");
1796 return NOTI_EX_ERROR_INVALID_PARAMETER;
1799 Handle* p = static_cast<Handle*>(handle);
1800 p->Get()->RemoveReceiver(receiver_group);
1801 return NOTI_EX_ERROR_NONE;
1804 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1805 char ***receiver_list, int *count) {
1806 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1807 LOGE("Invalid parameter");
1808 return NOTI_EX_ERROR_INVALID_PARAMETER;
1811 Handle* p = static_cast<Handle*>(handle);
1812 list<string> receivers = p->Get()->GetReceiverList();
1813 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
1814 if (tmp_list == nullptr) {
1815 LOGE("Out of memory");
1816 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1820 for (auto& i : receivers) {
1821 tmp_list[idx] = strdup(i.c_str());
1822 if (tmp_list[idx] == nullptr) {
1823 __noti_ex_free_str_array(tmp_list, idx);
1824 LOGE("Out of memory");
1825 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1830 *receiver_list = tmp_list;
1831 *count = receivers.size();
1832 return NOTI_EX_ERROR_NONE;
1835 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1837 if (handle == nullptr) {
1838 LOGE("Invalid parameter");
1839 return NOTI_EX_ERROR_INVALID_PARAMETER;
1842 Handle* p = static_cast<Handle*>(handle);
1843 p->Get()->SetPolicy(policy);
1844 return NOTI_EX_ERROR_NONE;
1847 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1849 if (handle == nullptr || policy == nullptr) {
1850 LOGE("Invalid parameter");
1851 return NOTI_EX_ERROR_INVALID_PARAMETER;
1854 Handle* p = static_cast<Handle*>(handle);
1855 *policy = p->Get()->GetPolicy();
1856 return NOTI_EX_ERROR_NONE;
1859 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1861 if (handle == nullptr || channel == nullptr) {
1862 LOGE("Invalid parameter");
1863 return NOTI_EX_ERROR_INVALID_PARAMETER;
1866 Handle* p = static_cast<Handle*>(handle);
1867 if (!p->Get()->GetChannel().empty())
1868 *channel = strdup(p->Get()->GetChannel().c_str());
1872 return NOTI_EX_ERROR_NONE;
1875 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1876 const char *channel) {
1877 if (handle == nullptr) {
1878 LOGE("Invalid parameter");
1879 return NOTI_EX_ERROR_INVALID_PARAMETER;
1882 Handle* p = static_cast<Handle*>(handle);
1883 p->Get()->SetChannel(channel);
1884 return NOTI_EX_ERROR_NONE;
1887 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1888 noti_ex_led_info_h led) {
1889 if (handle == nullptr) {
1890 LOGE("Invalid parameter");
1891 return NOTI_EX_ERROR_INVALID_PARAMETER;
1894 Handle* p = static_cast<Handle*>(handle);
1895 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1896 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1897 return NOTI_EX_ERROR_NONE;
1900 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1901 noti_ex_led_info_h *led) {
1902 if (handle == nullptr) {
1903 LOGE("Invalid parameter");
1904 return NOTI_EX_ERROR_INVALID_PARAMETER;
1907 Handle* p = static_cast<Handle*>(handle);
1908 if (p->Get()->GetLEDInfo() != nullptr)
1909 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1912 return NOTI_EX_ERROR_NONE;
1915 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1917 if (handle == nullptr) {
1918 LOGE("Invalid parameter");
1919 return NOTI_EX_ERROR_INVALID_PARAMETER;
1922 Handle* p = static_cast<Handle*>(handle);
1923 if (path == nullptr)
1924 p->Get()->SetSoundPath("");
1926 p->Get()->SetSoundPath(path);
1927 return NOTI_EX_ERROR_NONE;
1930 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1932 if (handle == nullptr) {
1933 LOGE("Invalid parameter");
1934 return NOTI_EX_ERROR_INVALID_PARAMETER;
1937 Handle* p = static_cast<Handle*>(handle);
1938 if (path == nullptr)
1939 p->Get()->SetVibrationPath("");
1941 p->Get()->SetVibrationPath(path);
1942 return NOTI_EX_ERROR_NONE;
1945 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1947 if (handle == nullptr || path == nullptr) {
1948 LOGE("Invalid parameter");
1949 return NOTI_EX_ERROR_INVALID_PARAMETER;
1952 Handle* p = static_cast<Handle*>(handle);
1953 if (p->Get()->GetSoundPath().empty())
1956 *path = strdup(p->Get()->GetSoundPath().c_str());
1957 return NOTI_EX_ERROR_NONE;
1960 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1962 if (handle == nullptr || path == nullptr) {
1963 LOGE("Invalid parameter");
1964 return NOTI_EX_ERROR_INVALID_PARAMETER;
1967 Handle* p = static_cast<Handle*>(handle);
1968 if (p->Get()->GetVibrationPath().empty())
1971 *path = strdup(p->Get()->GetVibrationPath().c_str());
1972 return NOTI_EX_ERROR_NONE;
1975 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1976 noti_ex_item_info_h *info) {
1977 if (handle == nullptr || info == nullptr) {
1978 LOGE("Invalid parameter");
1979 return NOTI_EX_ERROR_INVALID_PARAMETER;
1982 Handle* p = static_cast<Handle*>(handle);
1983 if (p->Get()->GetInfo() == nullptr)
1986 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1987 return NOTI_EX_ERROR_NONE;
1990 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1992 if (handle == nullptr || id == nullptr) {
1993 LOGE("Invalid parameter");
1994 return NOTI_EX_ERROR_INVALID_PARAMETER;
1997 Handle* p = static_cast<Handle*>(handle);
1998 if (p->Get()->GetSenderAppId().empty())
2001 *id = strdup(p->Get()->GetSenderAppId().c_str());
2002 return NOTI_EX_ERROR_NONE;
2005 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2007 if (handle == nullptr || tag == nullptr) {
2008 LOGE("Invalid parameter");
2009 return NOTI_EX_ERROR_INVALID_PARAMETER;
2012 Handle* p = static_cast<Handle*>(handle);
2013 if (p->Get()->GetTag().empty())
2016 *tag = strdup(p->Get()->GetTag().c_str());
2017 return NOTI_EX_ERROR_NONE;
2020 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2022 if (handle == nullptr) {
2023 LOGE("Invalid parameter");
2024 return NOTI_EX_ERROR_INVALID_PARAMETER;
2027 Handle* p = static_cast<Handle*>(handle);
2029 p->Get()->SetTag("");
2031 p->Get()->SetTag(tag);
2032 return NOTI_EX_ERROR_NONE;
2035 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2036 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2038 if (handle == nullptr) {
2039 LOGE("Invalid parameter");
2040 return NOTI_EX_ERROR_INVALID_PARAMETER;
2043 string receiver_group_str = "";
2045 receiver_group_str = string(receiver_group);
2047 ManagerStub* stub = new (std::nothrow) ManagerStub(
2048 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2049 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2050 receiver_group_str);
2051 if (stub == nullptr) {
2052 LOGE("Fail to create manager");
2053 return NOTI_EX_ERROR_IO_ERROR;
2055 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2056 new ManagerCallbackInfo(event_callbacks, data)));
2057 *handle = static_cast<noti_ex_manager_h>(stub);
2059 return NOTI_EX_ERROR_NONE;
2062 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2063 if (handle == nullptr) {
2064 LOGE("Invalid parameter");
2065 return NOTI_EX_ERROR_INVALID_PARAMETER;
2067 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2069 return NOTI_EX_ERROR_NONE;
2072 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2073 noti_ex_item_h **items, int *count) {
2074 if (handle == nullptr || items == nullptr || count == nullptr) {
2075 LOGE("Invalid parameter");
2076 return NOTI_EX_ERROR_INVALID_PARAMETER;
2080 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2081 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2082 if (item_list.size() == 0) {
2085 return NOTI_EX_ERROR_NONE;
2087 noti_ex_item_h* added_item =
2088 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2089 if (added_item == nullptr) {
2090 LOGE("Fail to create items");
2091 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2095 for (auto& i : item_list) {
2096 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2098 *items = added_item;
2099 *count = item_list.size();
2100 } catch (Exception &ex) {
2101 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2102 return NOTI_EX_ERROR_IO_ERROR;
2104 return NOTI_EX_ERROR_NONE;
2107 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2108 noti_ex_item_h noti, int *request_id) {
2109 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2110 LOGE("Invalid parameter");
2111 return NOTI_EX_ERROR_INVALID_PARAMETER;
2114 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2115 Handle* sp = static_cast<Handle*>(noti);
2116 if (sp->GetPtr().get() == nullptr) {
2117 LOGE("Invalid noti reference can not be sended");
2118 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 *request_id = stub->Update(sp->GetPtr());
2122 } catch (Exception &ex) {
2123 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2124 return NOTI_EX_ERROR_IO_ERROR;
2126 return NOTI_EX_ERROR_NONE;
2129 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2130 noti_ex_item_h noti, int *request_id) {
2131 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2132 LOGE("Invalid parameter");
2133 return NOTI_EX_ERROR_INVALID_PARAMETER;
2136 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2137 Handle* item = static_cast<Handle*>(noti);
2138 if (item->GetPtr().get() == nullptr) {
2139 LOGE("Invalid noti reference can not be sended");
2140 return NOTI_EX_ERROR_INVALID_PARAMETER;
2142 *request_id = stub->Delete(item->GetPtr());
2144 } catch (Exception &ex) {
2145 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2146 return NOTI_EX_ERROR_IO_ERROR;
2148 return NOTI_EX_ERROR_NONE;
2151 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2153 if (handle == nullptr || request_id == nullptr) {
2154 LOGE("Invalid parameter");
2155 return NOTI_EX_ERROR_INVALID_PARAMETER;
2158 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2159 *request_id = stub->DeleteAll();
2160 } catch (Exception &ex) {
2161 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2162 return NOTI_EX_ERROR_IO_ERROR;
2164 return NOTI_EX_ERROR_NONE;
2167 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2168 noti_ex_item_h noti, int *request_id) {
2169 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2170 LOGE("Invalid parameter");
2171 return NOTI_EX_ERROR_INVALID_PARAMETER;
2174 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2175 Handle* item = static_cast<Handle*>(noti);
2176 if (item->GetPtr().get() == nullptr) {
2177 LOGE("Invalid noti reference can not be sended");
2178 return NOTI_EX_ERROR_INVALID_PARAMETER;
2180 *request_id = stub->Hide(item->GetPtr());
2182 } catch (Exception &ex) {
2183 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2184 return NOTI_EX_ERROR_IO_ERROR;
2186 return NOTI_EX_ERROR_NONE;
2189 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2190 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2191 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2192 LOGE("Invalid parameter");
2193 return NOTI_EX_ERROR_INVALID_PARAMETER;
2196 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2197 *item = new Handle(stub->FindByRootID(root_id));
2198 } catch (Exception &ex) {
2199 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2200 return NOTI_EX_ERROR_IO_ERROR;
2202 return NOTI_EX_ERROR_NONE;
2205 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2206 noti_ex_event_info_h info, noti_ex_error_e error) {
2207 if (handle == nullptr || info == nullptr) {
2208 LOGE("Invalid parameter");
2209 return NOTI_EX_ERROR_INVALID_PARAMETER;
2212 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2213 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2214 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2215 static_cast<NotificationError>(error));
2216 } catch (Exception &ex) {
2217 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2218 return NOTI_EX_ERROR_IO_ERROR;
2220 return NOTI_EX_ERROR_NONE;
2223 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2224 noti_ex_manager_h handle, int *cnt) {
2226 if (handle == nullptr || cnt == nullptr) {
2227 LOGE("Invalid parameter");
2228 return NOTI_EX_ERROR_INVALID_PARAMETER;
2231 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2232 *cnt = stub->GetCount();
2233 } catch (Exception &ex) {
2234 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2235 return NOTI_EX_ERROR_IO_ERROR;
2237 return NOTI_EX_ERROR_NONE;
2240 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2241 const char *id, float min, float current, float max) {
2244 if (handle == nullptr) {
2245 LOGE("Invalid parameter");
2246 return NOTI_EX_ERROR_INVALID_PARAMETER;
2250 p = new (std::nothrow) ProgressItem(id, min, current, max);
2252 p = new (std::nothrow) ProgressItem(min, current, max);
2255 LOGE("Out-of-memory");
2256 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2259 *handle = new Handle(shared_ptr<AbstractItem>(p));
2261 return NOTI_EX_ERROR_NONE;
2264 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2265 noti_ex_item_h handle, float *current) {
2266 if (handle == nullptr || current == nullptr) {
2267 LOGE("Invalid parameter");
2268 return NOTI_EX_ERROR_INVALID_PARAMETER;
2271 Handle *h = static_cast<Handle*>(handle);
2272 if (!h->IsValidType(AbstractItem::Progress)) {
2273 LOGE("Invalid handle type");
2274 return NOTI_EX_ERROR_INVALID_PARAMETER;
2276 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2277 *current = p->GetCurrent();
2279 return NOTI_EX_ERROR_NONE;
2282 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2283 noti_ex_item_h handle, float current) {
2284 if (handle == nullptr) {
2285 LOGE("Invalid parameter");
2286 return NOTI_EX_ERROR_INVALID_PARAMETER;
2289 Handle *h = static_cast<Handle*>(handle);
2290 if (!h->IsValidType(AbstractItem::Progress)) {
2291 LOGE("Invalid handle type");
2292 return NOTI_EX_ERROR_INVALID_PARAMETER;
2294 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2295 p->SetCurrent(current);
2297 return NOTI_EX_ERROR_NONE;
2300 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2302 if (handle == nullptr || min == nullptr) {
2303 LOGE("Invalid parameter");
2304 return NOTI_EX_ERROR_INVALID_PARAMETER;
2307 Handle *h = static_cast<Handle*>(handle);
2308 if (!h->IsValidType(AbstractItem::Progress)) {
2309 LOGE("Invalid handle type");
2310 return NOTI_EX_ERROR_INVALID_PARAMETER;
2312 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2315 return NOTI_EX_ERROR_NONE;
2318 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2320 if (handle == nullptr || max == nullptr) {
2321 LOGE("Invalid parameter");
2322 return NOTI_EX_ERROR_INVALID_PARAMETER;
2325 Handle *h = static_cast<Handle*>(handle);
2326 if (!h->IsValidType(AbstractItem::Progress)) {
2327 LOGE("Invalid handle type");
2328 return NOTI_EX_ERROR_INVALID_PARAMETER;
2330 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2333 return NOTI_EX_ERROR_NONE;
2336 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2337 noti_ex_reporter_events_s event_callbacks, void *data) {
2338 if (handle == nullptr) {
2339 LOGE("Invalid parameter");
2340 return NOTI_EX_ERROR_INVALID_PARAMETER;
2343 ReporterStub* stub = new (std::nothrow) ReporterStub(
2344 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2345 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2346 if (stub == nullptr) {
2347 LOGE("Fail to create manager");
2348 return NOTI_EX_ERROR_IO_ERROR;
2350 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2351 new ReporterCallbackInfo(event_callbacks, data)));
2353 *handle = static_cast<noti_ex_reporter_h>(stub);
2355 return NOTI_EX_ERROR_NONE;
2358 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2359 if (handle == nullptr) {
2360 LOGE("Invalid parameter");
2361 return NOTI_EX_ERROR_INVALID_PARAMETER;
2363 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2365 return NOTI_EX_ERROR_NONE;
2368 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2369 noti_ex_event_info_h info, noti_ex_error_e error) {
2370 if (handle == nullptr || info == nullptr) {
2371 LOGE("Invalid parameter");
2372 return NOTI_EX_ERROR_INVALID_PARAMETER;
2375 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2376 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2377 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2378 static_cast<NotificationError>(error));
2379 } catch (Exception &ex) {
2380 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2381 return NOTI_EX_ERROR_IO_ERROR;
2383 return NOTI_EX_ERROR_NONE;
2386 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2387 noti_ex_item_h noti, int *request_id) {
2388 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2389 LOGE("Invalid parameter");
2390 return NOTI_EX_ERROR_INVALID_PARAMETER;
2393 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2394 Handle* h = static_cast<Handle*>(noti);
2395 if (h->GetPtr().get() == nullptr) {
2396 LOGE("Invalid noti reference can not be sended");
2397 return NOTI_EX_ERROR_INVALID_PARAMETER;
2399 *request_id = stub->Post(h->GetPtr());
2401 } catch (Exception &ex) {
2402 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2403 return NOTI_EX_ERROR_IO_ERROR;
2405 return NOTI_EX_ERROR_NONE;
2408 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2409 noti_ex_item_h *noti_list, int count, int *request_id) {
2411 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2412 LOGE("Invalid parameter");
2413 return NOTI_EX_ERROR_INVALID_PARAMETER;
2416 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2417 list<shared_ptr<item::AbstractItem>> notiList;
2418 for (int i = 0; i < count; i++) {
2419 Handle* item = static_cast<Handle*>(noti_list[i]);
2420 notiList.push_back(item->GetPtr());
2422 *request_id = stub->Post(notiList);
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_reporter_update(noti_ex_reporter_h handle,
2431 noti_ex_item_h noti, int *request_id) {
2432 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2433 LOGE("Invalid parameter");
2434 return NOTI_EX_ERROR_INVALID_PARAMETER;
2437 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2438 Handle* item = static_cast<Handle*>(noti);
2439 if (item->GetPtr().get() == nullptr) {
2440 LOGE("Invalid noti reference can not be sended");
2441 return NOTI_EX_ERROR_INVALID_PARAMETER;
2443 *request_id = stub->Update(item->GetPtr());
2445 } catch (Exception &ex) {
2446 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2447 return NOTI_EX_ERROR_IO_ERROR;
2449 return NOTI_EX_ERROR_NONE;
2452 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2453 noti_ex_item_h noti, int *request_id) {
2454 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2455 LOGE("Invalid parameter");
2456 return NOTI_EX_ERROR_INVALID_PARAMETER;
2459 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2460 Handle* item = static_cast<Handle*>(noti);
2461 if (item->GetPtr().get() == nullptr) {
2462 LOGE("Invalid noti reference can not be sended");
2463 return NOTI_EX_ERROR_INVALID_PARAMETER;
2465 *request_id = stub->Delete(item->GetPtr());
2467 } catch (Exception &ex) {
2468 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2469 return NOTI_EX_ERROR_IO_ERROR;
2471 return NOTI_EX_ERROR_NONE;
2474 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2475 noti_ex_reporter_h handle, int *request_id) {
2476 if (handle == nullptr || request_id == nullptr) {
2477 LOGE("Invalid parameter");
2478 return NOTI_EX_ERROR_INVALID_PARAMETER;
2481 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2482 *request_id = stub->DeleteAll();
2483 } catch (Exception &ex) {
2484 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2485 return NOTI_EX_ERROR_IO_ERROR;
2487 return NOTI_EX_ERROR_NONE;
2490 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2491 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2492 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2493 LOGE("Invalid parameter");
2494 return NOTI_EX_ERROR_INVALID_PARAMETER;
2497 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2498 *item = new Handle(stub->FindByRootID(root_id));
2499 } catch (Exception &ex) {
2500 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2501 return NOTI_EX_ERROR_IO_ERROR;
2503 return NOTI_EX_ERROR_NONE;
2506 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2507 const char *id, const char *text, const char *hyperlink) {
2508 if (handle == nullptr || text == nullptr) {
2509 LOGE("Invalid parameter");
2510 return NOTI_EX_ERROR_INVALID_PARAMETER;
2516 p = new (std::nothrow) TextItem(id, std::string(text),
2517 std::string(hyperlink));
2519 p = new (std::nothrow) TextItem(id, std::string(text));
2522 LOGE("Out-of-memory");
2523 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2526 *handle = new Handle(shared_ptr<AbstractItem>(p));
2528 return NOTI_EX_ERROR_NONE;
2531 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2532 const char *contents) {
2533 if (handle == nullptr || contents == nullptr) {
2534 LOGE("Invalid parameter");
2535 return NOTI_EX_ERROR_INVALID_PARAMETER;
2538 Handle* p = static_cast<Handle*>(handle);
2539 if (!p->IsValidType(AbstractItem::Text)) {
2540 LOGE("Invalid handle type");
2541 return NOTI_EX_ERROR_INVALID_PARAMETER;
2543 TextItem* ti = static_cast<TextItem*>(p->Get());
2544 ti->SetContents(std::string(contents));
2546 return NOTI_EX_ERROR_NONE;
2549 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2551 if (handle == nullptr || contents == nullptr) {
2552 LOGE("Invalid parameter");
2553 return NOTI_EX_ERROR_INVALID_PARAMETER;
2556 Handle* p = static_cast<Handle*>(handle);
2557 if (!p->IsValidType(AbstractItem::Text)) {
2558 LOGE("Invalid handle type");
2559 return NOTI_EX_ERROR_INVALID_PARAMETER;
2561 TextItem* ti = static_cast<TextItem*>(p->Get());
2562 if (!ti->GetContents().empty()) {
2563 *contents = strdup(ti->GetContents().c_str());
2564 if (*contents == nullptr) {
2565 LOGE("Out-of-memory");
2566 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2570 return NOTI_EX_ERROR_NONE;
2573 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2574 noti_ex_item_h handle, char **hyper_link) {
2575 if (handle == nullptr || hyper_link == nullptr) {
2576 LOGE("Invalid parameter");
2577 return NOTI_EX_ERROR_INVALID_PARAMETER;
2580 Handle* p = static_cast<Handle*>(handle);
2581 if (!p->IsValidType(AbstractItem::Text)) {
2582 LOGE("Invalid handle type");
2583 return NOTI_EX_ERROR_INVALID_PARAMETER;
2585 TextItem* ti = static_cast<TextItem*>(p->Get());
2586 if (!ti->GetHyperLink().empty()) {
2587 *hyper_link = strdup(ti->GetHyperLink().c_str());
2588 if (*hyper_link == nullptr) {
2589 LOGE("Out-of-memory");
2590 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2594 return NOTI_EX_ERROR_NONE;
2597 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2598 const char *id, time_t time) {
2601 if (handle == nullptr) {
2602 LOGE("Invalid parameter");
2603 return NOTI_EX_ERROR_INVALID_PARAMETER;
2608 p = new (std::nothrow) TimeItem(id, time);
2610 p = new (std::nothrow) TimeItem(time);
2612 p = new (std::nothrow) TimeItem();
2616 LOGE("Out-of-memory");
2617 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2620 *handle = new Handle(shared_ptr<AbstractItem>(p));
2622 return NOTI_EX_ERROR_NONE;
2625 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2627 if (handle == nullptr || time == nullptr) {
2628 LOGE("Invalid parameter");
2629 return NOTI_EX_ERROR_INVALID_PARAMETER;
2631 Handle* h = static_cast<Handle*>(handle);
2632 if (!h->IsValidType(AbstractItem::Time)) {
2633 LOGE("Invalid handle type");
2634 return NOTI_EX_ERROR_INVALID_PARAMETER;
2636 TimeItem* p = static_cast<TimeItem*>(h->Get());
2637 *time = p->GetTime();
2639 return NOTI_EX_ERROR_NONE;
2642 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2643 noti_ex_action_h *handle, const char *extra) {
2644 if (handle == nullptr) {
2645 LOGE("Invalid parameter");
2646 return NOTI_EX_ERROR_INVALID_PARAMETER;
2649 string extra_str = "";
2651 extra_str = string(extra);
2653 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2655 LOGE("Out-of-memory");
2656 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2661 return NOTI_EX_ERROR_NONE;
2664 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2665 const char *id, bool visible) {
2666 if (handle == nullptr || id == nullptr) {
2667 LOGE("Invalid parameter");
2668 return NOTI_EX_ERROR_INVALID_PARAMETER;
2671 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2672 p->SetVisibility(id, visible);
2674 return NOTI_EX_ERROR_NONE;