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/ex_bundle.h"
52 #include "notification-ex/event_info_internal.h"
53 #include "notification-ex/manager.h"
54 #include "notification-ex/dbus_sender.h"
55 #include "notification-ex/dbus_event_listener.h"
56 #include "notification-ex/exception.h"
61 #define LOG_TAG "NOTIFICATION_EX"
66 #define EXPORT_API __attribute__((visibility("default")))
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 extern "C" EXPORT_API int noti_ex_action_app_control_create(
287 noti_ex_action_h *handle, app_control_h app_control,
289 if (handle == nullptr || app_control == nullptr) {
290 LOGE("Invalid parameter");
291 return NOTI_EX_ERROR_INVALID_PARAMETER;
297 p = new (std::nothrow) AppControlAction(app_control, extra);
299 p = new (std::nothrow) AppControlAction(app_control);
302 LOGE("Out-of-memory");
303 return NOTI_EX_ERROR_OUT_OF_MEMORY;
308 return NOTI_EX_ERROR_NONE;
311 extern "C" EXPORT_API int noti_ex_action_app_control_set(
312 noti_ex_action_h handle, app_control_h app_control) {
313 if (handle == nullptr || app_control == nullptr) {
314 LOGE("Invalid parameter");
315 return NOTI_EX_ERROR_INVALID_PARAMETER;
318 AppControlAction* p = static_cast<AppControlAction*>(handle);
319 p->SetAppControl(app_control);
321 return NOTI_EX_ERROR_NONE;
324 extern "C" EXPORT_API int noti_ex_action_app_control_get(
325 noti_ex_action_h handle, app_control_h *app_control) {
326 if (handle == nullptr || app_control == nullptr) {
327 LOGE("Invalid parameter");
328 return NOTI_EX_ERROR_INVALID_PARAMETER;
331 AppControlAction* p = static_cast<AppControlAction*>(handle);
332 *app_control = p->GetAppControl();
334 return NOTI_EX_ERROR_NONE;
337 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
338 const char *id, const char *title) {
341 if (handle == nullptr || title == nullptr) {
342 LOGE("Invalid parameter");
343 return NOTI_EX_ERROR_INVALID_PARAMETER;
347 p = new (std::nothrow) ButtonItem(id, title);
349 p = new (std::nothrow) ButtonItem(title);
352 LOGE("Out-of-memory");
353 return NOTI_EX_ERROR_OUT_OF_MEMORY;
355 *handle = new Handle(shared_ptr<AbstractItem>(p));
357 return NOTI_EX_ERROR_NONE;
360 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
362 if (handle == nullptr || title == nullptr) {
363 LOGE("Invalid parameter");
364 return NOTI_EX_ERROR_INVALID_PARAMETER;
367 Handle* sp = static_cast<Handle*>(handle);
368 if (!sp->IsValidType(AbstractItem::Button)) {
369 LOGE("Invalid handle type");
370 return NOTI_EX_ERROR_INVALID_PARAMETER;
372 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
373 if (!p->GetTitle().empty()) {
374 *title = strdup(p->GetTitle().c_str());
375 if (*title == nullptr) {
376 LOGE("Out-of-memory");
377 return NOTI_EX_ERROR_OUT_OF_MEMORY;
381 return NOTI_EX_ERROR_NONE;
384 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
385 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
386 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
387 noti_ex_item_chat_message_type_e message_type) {
388 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
389 LOGE("Invalid parameter");
390 return NOTI_EX_ERROR_INVALID_PARAMETER;
393 auto* p = new (std::nothrow) ChatMessageItem(id,
394 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
395 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
396 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
397 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
398 static_cast<ChatMessageItem::Type>(message_type));
400 LOGE("Out-of-memory");
401 return NOTI_EX_ERROR_OUT_OF_MEMORY;
404 *handle = new Handle(shared_ptr<AbstractItem>(p));
406 return NOTI_EX_ERROR_NONE;
409 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
410 noti_ex_item_h handle, noti_ex_item_h *name) {
411 if (handle == nullptr || name == nullptr) {
412 LOGE("Invalid parameter");
413 return NOTI_EX_ERROR_INVALID_PARAMETER;
415 Handle* h = static_cast<Handle*>(handle);
416 if (!h->IsValidType(AbstractItem::ChatMessage)) {
417 LOGE("Invalid handle type");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
420 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
421 *name = new Handle(&(p->GetNameItem()));
423 return NOTI_EX_ERROR_NONE;
426 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
427 noti_ex_item_h handle, noti_ex_item_h *text) {
428 if (handle == nullptr || text == nullptr) {
429 LOGE("Invalid parameter");
430 return NOTI_EX_ERROR_INVALID_PARAMETER;
433 Handle* h = static_cast<Handle*>(handle);
434 if (!h->IsValidType(AbstractItem::ChatMessage)) {
435 LOGE("Invalid handle type");
436 return NOTI_EX_ERROR_INVALID_PARAMETER;
438 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
439 *text = new Handle(&(p->GetTextItem()));
441 return NOTI_EX_ERROR_NONE;
444 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
445 noti_ex_item_h handle, noti_ex_item_h *image) {
446 if (handle == nullptr || image == nullptr) {
447 LOGE("Invalid parameter");
448 return NOTI_EX_ERROR_INVALID_PARAMETER;
451 Handle* h = static_cast<Handle*>(handle);
452 if (!h->IsValidType(AbstractItem::ChatMessage)) {
453 LOGE("Invalid handle type");
454 return NOTI_EX_ERROR_INVALID_PARAMETER;
456 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
457 *image = new Handle(&(p->GetImageItem()));
459 return NOTI_EX_ERROR_NONE;
462 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
463 noti_ex_item_h handle, noti_ex_item_h *time) {
464 if (handle == nullptr || time == nullptr) {
465 LOGE("Invalid parameter");
466 return NOTI_EX_ERROR_INVALID_PARAMETER;
469 Handle* h = static_cast<Handle*>(handle);
470 if (!h->IsValidType(AbstractItem::ChatMessage)) {
471 LOGE("Invalid handle type");
472 return NOTI_EX_ERROR_INVALID_PARAMETER;
474 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
475 *time = new Handle(&(p->GetTimeItem()));
477 return NOTI_EX_ERROR_NONE;
480 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
481 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
482 if (handle == nullptr || message_type == nullptr) {
483 LOGE("Invalid parameter");
484 return NOTI_EX_ERROR_INVALID_PARAMETER;
487 Handle* h = static_cast<Handle*>(handle);
488 if (!h->IsValidType(AbstractItem::ChatMessage)) {
489 LOGE("Invalid handle type");
490 return NOTI_EX_ERROR_INVALID_PARAMETER;
492 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
493 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
495 return NOTI_EX_ERROR_NONE;
498 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
499 const char *id, const char *title, bool checked) {
502 if (handle == nullptr || title == nullptr) {
503 LOGE("Invalid parameter");
504 return NOTI_EX_ERROR_INVALID_PARAMETER;
507 p = new (std::nothrow) CheckBoxItem(id, title, checked);
509 LOGE("Out-of-memory");
510 return NOTI_EX_ERROR_OUT_OF_MEMORY;
513 *handle = new Handle(p);
515 return NOTI_EX_ERROR_NONE;
518 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
520 if (handle == nullptr || title == nullptr) {
521 LOGE("Invalid parameter");
522 return NOTI_EX_ERROR_INVALID_PARAMETER;
524 Handle* h = static_cast<Handle*>(handle);
525 if (!h->IsValidType(AbstractItem::CheckBox)) {
526 LOGE("Invalid handle type");
527 return NOTI_EX_ERROR_INVALID_PARAMETER;
529 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
530 if (!p->GetTitle().empty()) {
531 *title = strdup(p->GetTitle().c_str());
532 if (*title == nullptr) {
533 LOGE("Out-of-memory");
534 return NOTI_EX_ERROR_OUT_OF_MEMORY;
538 return NOTI_EX_ERROR_NONE;
541 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
543 if (handle == nullptr || checked == nullptr) {
544 LOGE("Invalid parameter");
545 return NOTI_EX_ERROR_INVALID_PARAMETER;
547 Handle* h = static_cast<Handle*>(handle);
548 if (!h->IsValidType(AbstractItem::CheckBox)) {
549 LOGE("Invalid handle type");
550 return NOTI_EX_ERROR_INVALID_PARAMETER;
552 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
553 *checked = p->IsChecked();
555 return NOTI_EX_ERROR_NONE;
558 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
562 if (handle == nullptr) {
563 LOGE("Invalid parameter");
564 return NOTI_EX_ERROR_INVALID_PARAMETER;
567 p = new (std::nothrow) EntryItem(id);
569 LOGE("Out-of-memory");
570 return NOTI_EX_ERROR_OUT_OF_MEMORY;
573 *handle = new Handle(p);
575 return NOTI_EX_ERROR_NONE;
578 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
580 if (handle == nullptr || text == nullptr) {
581 LOGE("Invalid parameter");
582 return NOTI_EX_ERROR_INVALID_PARAMETER;
585 Handle* h = static_cast<Handle*>(handle);
586 if (!h->IsValidType(AbstractItem::Entry)) {
587 LOGE("Invalid handle type");
588 return NOTI_EX_ERROR_INVALID_PARAMETER;
590 EntryItem* p = static_cast<EntryItem*>(h->Get());
591 if (!p->GetText().empty()) {
592 *text = strdup(p->GetText().c_str());
593 if (*text == nullptr) {
594 LOGE("Out-of-memory");
595 return NOTI_EX_ERROR_OUT_OF_MEMORY;
599 return NOTI_EX_ERROR_NONE;
602 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
604 if (handle == nullptr || text == nullptr) {
605 LOGE("Invalid parameter");
606 return NOTI_EX_ERROR_INVALID_PARAMETER;
608 Handle* h = static_cast<Handle*>(handle);
609 if (!h->IsValidType(AbstractItem::Entry)) {
610 LOGE("Invalid handle type");
611 return NOTI_EX_ERROR_INVALID_PARAMETER;
613 EntryItem* p = static_cast<EntryItem*>(h->Get());
614 p->SetText(std::string(text));
616 return NOTI_EX_ERROR_NONE;
619 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
620 noti_ex_event_info_h* cloned_handle) {
621 if (handle == nullptr || cloned_handle == nullptr) {
622 LOGE("Invalid parameter");
623 return NOTI_EX_ERROR_INVALID_PARAMETER;
626 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
627 EventInfo* info = new EventInfo(cloned);
628 *cloned_handle = info;
629 return NOTI_EX_ERROR_NONE;
632 extern "C" EXPORT_API int noti_ex_event_info_destroy(
633 noti_ex_event_info_h handle) {
634 if (handle == nullptr) {
635 LOGE("Invalid parameter");
636 return NOTI_EX_ERROR_INVALID_PARAMETER;
638 EventInfo* info = static_cast<EventInfo*>(handle);
640 return NOTI_EX_ERROR_NONE;
643 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
644 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
645 if (handle == nullptr || event_type == nullptr) {
646 LOGE("Invalid parameter");
647 return NOTI_EX_ERROR_INVALID_PARAMETER;
649 EventInfo* info = static_cast<EventInfo*>(handle);
650 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
652 return NOTI_EX_ERROR_NONE;
655 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
656 noti_ex_event_info_h handle, char **owner) {
657 if (handle == nullptr || owner == nullptr) {
658 LOGE("Invalid parameter");
659 return NOTI_EX_ERROR_INVALID_PARAMETER;
661 EventInfo* info = static_cast<EventInfo*>(handle);
662 *owner = strdup(info->GetOwner().c_str());
663 return NOTI_EX_ERROR_NONE;
666 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
667 noti_ex_event_info_h handle, char **channel) {
668 if (handle == nullptr || channel == nullptr) {
669 LOGE("Invalid parameter");
670 return NOTI_EX_ERROR_INVALID_PARAMETER;
672 EventInfo* info = static_cast<EventInfo*>(handle);
673 *channel = strdup(info->GetChannel().c_str());
674 return NOTI_EX_ERROR_NONE;
677 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
678 noti_ex_event_info_h handle, char **item_id) {
679 if (handle == nullptr || item_id == nullptr) {
680 LOGE("Invalid parameter");
681 return NOTI_EX_ERROR_INVALID_PARAMETER;
683 EventInfo* info = static_cast<EventInfo*>(handle);
684 *item_id = strdup(info->GetItemId().c_str());
685 return NOTI_EX_ERROR_NONE;
688 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
689 noti_ex_event_info_h handle, int *req_id) {
690 if (handle == nullptr || req_id == nullptr) {
691 LOGE("Invalid parameter");
692 return NOTI_EX_ERROR_INVALID_PARAMETER;
694 EventInfo* info = static_cast<EventInfo*>(handle);
695 *req_id = info->GetRequestId();
696 return NOTI_EX_ERROR_NONE;
699 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
703 if (handle == nullptr) {
704 LOGE("Invalid parameter");
705 return NOTI_EX_ERROR_INVALID_PARAMETER;
709 p = new (std::nothrow) GroupItem(id);
711 p = new (std::nothrow) GroupItem();
714 LOGE("Out-of-memory");
715 return NOTI_EX_ERROR_OUT_OF_MEMORY;
718 *handle = new Handle(shared_ptr<AbstractItem>(p));
720 return NOTI_EX_ERROR_NONE;
723 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
725 if (handle == nullptr) {
726 LOGE("Invalid parameter");
727 return NOTI_EX_ERROR_INVALID_PARAMETER;
729 Handle* h = static_cast<Handle*>(handle);
730 if (!h->IsValidType(AbstractItem::Group)) {
731 LOGE("Invalid handle type");
732 return NOTI_EX_ERROR_INVALID_PARAMETER;
734 GroupItem* p = static_cast<GroupItem*>(h->Get());
735 p->SetDirection(vertical);
737 return NOTI_EX_ERROR_NONE;
740 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
742 if (handle == nullptr) {
743 LOGE("Invalid parameter");
744 return NOTI_EX_ERROR_INVALID_PARAMETER;
746 Handle* h = static_cast<Handle*>(handle);
747 if (!h->IsValidType(AbstractItem::Group)) {
748 LOGE("Invalid handle type");
749 return NOTI_EX_ERROR_INVALID_PARAMETER;
751 GroupItem* p = static_cast<GroupItem*>(h->Get());
752 *vertical = p->IsVertical();
754 return NOTI_EX_ERROR_NONE;
757 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
759 if (handle == nullptr) {
760 LOGE("Invalid parameter");
761 return NOTI_EX_ERROR_INVALID_PARAMETER;
763 Handle* h = static_cast<Handle*>(handle);
764 if (!h->IsValidType(AbstractItem::Group)) {
765 LOGE("Invalid handle type");
766 return NOTI_EX_ERROR_INVALID_PARAMETER;
768 GroupItem* p = static_cast<GroupItem*>(h->Get());
769 if (!p->GetAppLabel().empty()) {
770 *label = strdup(p->GetAppLabel().c_str());
771 if (*label == nullptr) {
772 LOGE("Out-of-memory");
773 return NOTI_EX_ERROR_OUT_OF_MEMORY;
777 return NOTI_EX_ERROR_NONE;
780 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
781 noti_ex_item_h child) {
782 if (handle == nullptr || child == nullptr) {
783 LOGE("Invalid parameter");
784 return NOTI_EX_ERROR_INVALID_PARAMETER;
786 Handle* h = static_cast<Handle*>(handle);
787 if (!h->IsValidType(AbstractItem::Group)) {
788 LOGE("Invalid handle type");
789 return NOTI_EX_ERROR_INVALID_PARAMETER;
791 auto p = static_cast<GroupItem*>(h->Get());
792 p->AddChild((static_cast<Handle*>(child))->GetPtr());
794 return NOTI_EX_ERROR_NONE;
797 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
798 const char *item_id) {
799 if (handle == nullptr || item_id == nullptr) {
800 LOGE("Invalid parameter");
801 return NOTI_EX_ERROR_INVALID_PARAMETER;
803 Handle* h = static_cast<Handle*>(handle);
804 if (!h->IsValidType(AbstractItem::Group)) {
805 LOGE("Invalid handle type");
806 return NOTI_EX_ERROR_INVALID_PARAMETER;
808 GroupItem* p = static_cast<GroupItem*>(h->Get());
809 p->RemoveChild(std::string(item_id));
811 return NOTI_EX_ERROR_NONE;
814 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
815 noti_ex_item_group_foreach_child_cb callback, void *data) {
816 if (handle == nullptr || callback == nullptr) {
817 LOGE("Invalid parameter");
818 return NOTI_EX_ERROR_INVALID_PARAMETER;
821 Handle* h = static_cast<Handle*>(handle);
822 if (!h->IsValidType(AbstractItem::Group)) {
823 LOGE("Invalid handle type");
824 return NOTI_EX_ERROR_INVALID_PARAMETER;
826 GroupItem* p = static_cast<GroupItem*>(h->Get());
827 list<shared_ptr<AbstractItem>> children = p->GetChildren();
828 LOGI("Retrive (%zd)", children.size());
829 for (auto i : children) {
831 static_cast<noti_ex_item_h>(new Handle(i)), data);
832 if (ret != NOTI_EX_ERROR_NONE) {
833 LOGW("callback return (%d) stop foreach", ret);
838 return NOTI_EX_ERROR_NONE;
841 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
842 const char *id, const char *image_path) {
845 if (handle == nullptr || image_path == nullptr) {
846 LOGE("Invalid parameter");
847 return NOTI_EX_ERROR_INVALID_PARAMETER;
851 p = new (std::nothrow) ImageItem(id, image_path);
853 p = new (std::nothrow) ImageItem(image_path);
856 LOGE("Out-of-memory");
857 return NOTI_EX_ERROR_OUT_OF_MEMORY;
860 *handle = new Handle(shared_ptr<AbstractItem>(p));
862 return NOTI_EX_ERROR_NONE;
865 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
866 noti_ex_item_h handle, char **image_path) {
867 if (handle == nullptr || image_path == nullptr) {
868 LOGE("Invalid parameter");
869 return NOTI_EX_ERROR_INVALID_PARAMETER;
871 Handle* h = static_cast<Handle*>(handle);
872 if (!h->IsValidType(AbstractItem::Image)) {
873 LOGE("Invalid handle type");
874 return NOTI_EX_ERROR_INVALID_PARAMETER;
876 ImageItem* p = static_cast<ImageItem*>(h->Get());
877 if (!p->GetImagePath().empty()) {
878 *image_path = strdup(p->GetImagePath().c_str());
879 if (*image_path == nullptr) {
880 LOGE("Out-of-memory");
881 return NOTI_EX_ERROR_OUT_OF_MEMORY;
885 return NOTI_EX_ERROR_NONE;
888 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
889 noti_ex_item_h *handle, const char *id) {
890 InputSelectorItem* p;
892 if (handle == nullptr) {
893 LOGE("Invalid parameter");
894 return NOTI_EX_ERROR_INVALID_PARAMETER;
898 p = new (std::nothrow) InputSelectorItem(id);
900 p = new (std::nothrow) InputSelectorItem();
903 LOGE("Out-of-memory");
904 return NOTI_EX_ERROR_OUT_OF_MEMORY;
907 *handle = new Handle(p);
909 return NOTI_EX_ERROR_NONE;
912 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
913 noti_ex_item_h handle, char ***contents_list, int *count) {
914 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
915 LOGE("Invalid parameter");
916 return NOTI_EX_ERROR_INVALID_PARAMETER;
919 Handle* h = static_cast<Handle*>(handle);
920 if (!h->IsValidType(AbstractItem::InputSelector)) {
921 LOGE("Invalid handle type");
922 return NOTI_EX_ERROR_INVALID_PARAMETER;
924 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
925 list<string> contents = p->GetContents();
926 char **list = (char**)calloc(contents.size(), sizeof(char*));
928 for (auto& i : contents) {
929 list[idx++] = strdup(i.c_str());
931 *count = contents.size();
932 *contents_list = list;
934 return NOTI_EX_ERROR_NONE;
937 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
938 noti_ex_item_h handle, const char **contents, int count) {
939 if (handle == nullptr || contents == nullptr) {
940 LOGE("Invalid parameter");
941 return NOTI_EX_ERROR_INVALID_PARAMETER;
944 list<string> new_contents;
945 Handle* h = static_cast<Handle*>(handle);
946 if (!h->IsValidType(AbstractItem::InputSelector)) {
947 LOGE("Invalid handle type");
948 return NOTI_EX_ERROR_INVALID_PARAMETER;
950 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
951 for (int i = 0; i < count; i++) {
952 new_contents.push_back(contents[i]);
954 p->SetContents(move(new_contents));
956 return NOTI_EX_ERROR_NONE;
959 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
960 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
961 if (handle == nullptr) {
962 LOGE("Invalid parameter");
963 return NOTI_EX_ERROR_INVALID_PARAMETER;
966 auto* ptr = new (std::nothrow) shared_ptr<Color>(
967 new (std::nothrow) Color(a, r, g, b));
968 if (ptr == nullptr || ptr->get() == nullptr) {
969 LOGE("Out-of-memory");
970 return NOTI_EX_ERROR_OUT_OF_MEMORY;
975 return NOTI_EX_ERROR_NONE;
978 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
979 if (handle == nullptr) {
980 LOGE("Invalid parameter");
981 return NOTI_EX_ERROR_INVALID_PARAMETER;
984 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
987 return NOTI_EX_ERROR_NONE;
990 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
991 unsigned char *val) {
992 if (handle == nullptr || val == nullptr) {
993 LOGE("Invalid parameter");
994 return NOTI_EX_ERROR_INVALID_PARAMETER;
997 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
998 *val = (*p)->GetAVal();
1000 return NOTI_EX_ERROR_NONE;
1003 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1004 unsigned char *val) {
1005 if (handle == nullptr || val == nullptr) {
1006 LOGE("Invalid parameter");
1007 return NOTI_EX_ERROR_INVALID_PARAMETER;
1010 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1011 *val = (*p)->GetRVal();
1013 return NOTI_EX_ERROR_NONE;
1016 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1017 unsigned char *val) {
1018 if (handle == nullptr || val == nullptr) {
1019 LOGE("Invalid parameter");
1020 return NOTI_EX_ERROR_INVALID_PARAMETER;
1023 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1024 *val = (*p)->GetGVal();
1026 return NOTI_EX_ERROR_NONE;
1029 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1030 unsigned char *val) {
1031 if (handle == nullptr || val == nullptr) {
1032 LOGE("Invalid parameter");
1033 return NOTI_EX_ERROR_INVALID_PARAMETER;
1036 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1037 *val = (*p)->GetBVal();
1039 return NOTI_EX_ERROR_NONE;
1042 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1043 int left, int top, int right, int bottom) {
1044 if (handle == nullptr) {
1045 LOGE("Invalid parameter");
1046 return NOTI_EX_ERROR_INVALID_PARAMETER;
1049 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1051 LOGE("Out-of-memory");
1052 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1055 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1056 new (std::nothrow) Padding(left, top, right, bottom));
1057 if (ptr == nullptr || ptr->get() == nullptr) {
1058 LOGE("Out-of-memory");
1059 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1064 return NOTI_EX_ERROR_NONE;
1067 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1068 if (handle == nullptr) {
1069 LOGE("Invalid parameter");
1070 return NOTI_EX_ERROR_INVALID_PARAMETER;
1073 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1076 return NOTI_EX_ERROR_NONE;
1079 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1081 if (handle == nullptr || val == nullptr) {
1082 LOGE("Invalid parameter");
1083 return NOTI_EX_ERROR_INVALID_PARAMETER;
1086 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1087 *val = (*p)->GetLeft();
1089 return NOTI_EX_ERROR_NONE;
1092 extern "C" EXPORT_API int noti_ex_padding_get_top(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)->GetTop();
1102 return NOTI_EX_ERROR_NONE;
1105 extern "C" EXPORT_API int noti_ex_padding_get_right(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)->GetRight();
1115 return NOTI_EX_ERROR_NONE;
1118 extern "C" EXPORT_API int noti_ex_padding_get_bottom(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)->GetBottom();
1128 return NOTI_EX_ERROR_NONE;
1131 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1132 int x, int y, int w, int h) {
1133 if (handle == nullptr) {
1134 LOGE("Invalid parameter");
1135 return NOTI_EX_ERROR_INVALID_PARAMETER;
1138 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1139 new (std::nothrow) Geometry(x, y, w, h));
1140 if (ptr == nullptr || ptr->get() == nullptr) {
1141 LOGE("Out-of-memory");
1142 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1151 if (handle == nullptr) {
1152 LOGE("Invalid parameter");
1153 return NOTI_EX_ERROR_INVALID_PARAMETER;
1156 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1159 return NOTI_EX_ERROR_NONE;
1162 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1164 if (handle == nullptr || val == nullptr) {
1165 LOGE("Invalid parameter");
1166 return NOTI_EX_ERROR_INVALID_PARAMETER;
1169 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1170 *val = (*p)->GetX();
1172 return NOTI_EX_ERROR_NONE;
1175 extern "C" EXPORT_API int noti_ex_geometry_get_y(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)->GetY();
1185 return NOTI_EX_ERROR_NONE;
1188 extern "C" EXPORT_API int noti_ex_geometry_get_width(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)->GetWidth();
1198 return NOTI_EX_ERROR_NONE;
1201 extern "C" EXPORT_API int noti_ex_geometry_get_height(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)->GetHeight();
1211 return NOTI_EX_ERROR_NONE;
1214 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1215 noti_ex_color_h color,
1216 noti_ex_padding_h padding,
1217 noti_ex_geometry_h geometry) {
1218 if (handle == nullptr) {
1219 LOGE("Invalid parameter");
1220 return NOTI_EX_ERROR_INVALID_PARAMETER;
1223 shared_ptr<Color> col = (color == nullptr) ?
1224 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1225 shared_ptr<Padding> padd = (padding == nullptr) ?
1226 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1227 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1228 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1230 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1231 new (std::nothrow) Style(col, padd, geo));
1232 if (ptr == nullptr || ptr->get() == nullptr) {
1233 LOGE("Out-of-memory");
1234 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1239 return NOTI_EX_ERROR_NONE;
1242 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1243 if (handle == nullptr) {
1244 LOGE("Invalid parameter");
1245 return NOTI_EX_ERROR_INVALID_PARAMETER;
1248 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1251 return NOTI_EX_ERROR_NONE;
1254 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1255 noti_ex_padding_h *padding) {
1256 if (handle == nullptr || padding == nullptr) {
1257 LOGE("Invalid parameter");
1258 return NOTI_EX_ERROR_INVALID_PARAMETER;
1261 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1262 if ((*p)->GetPadding() == nullptr) {
1263 LOGW("Padding info is null");
1264 return NOTI_EX_ERROR_INVALID_PARAMETER;
1267 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1268 new (std::nothrow) Padding(*((*p)->GetPadding())));
1269 if (padd == nullptr || padd->get() == nullptr) {
1270 LOGE("Out-of-memory");
1271 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1276 return NOTI_EX_ERROR_NONE;
1279 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1280 noti_ex_color_h *color) {
1281 if (handle == nullptr || color == nullptr) {
1282 LOGE("Invalid parameter");
1283 return NOTI_EX_ERROR_INVALID_PARAMETER;
1286 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1287 if ((*p)->GetColor() == nullptr) {
1288 LOGW("Color info is null");
1289 return NOTI_EX_ERROR_INVALID_PARAMETER;
1292 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1293 new (std::nothrow) Color(*((*p)->GetColor())));
1294 if (col == nullptr || col->get() == nullptr) {
1295 LOGE("Out-of-memory");
1296 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1301 return NOTI_EX_ERROR_NONE;
1304 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1305 noti_ex_geometry_h *geometry) {
1306 if (handle == nullptr || geometry == nullptr) {
1307 LOGE("Invalid parameter");
1308 return NOTI_EX_ERROR_INVALID_PARAMETER;
1311 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1312 if ((*p)->GetGeometry() == nullptr) {
1313 LOGW("Geometry info is null");
1314 return NOTI_EX_ERROR_INVALID_PARAMETER;
1317 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1318 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1319 if (geo == nullptr || geo->get() == nullptr) {
1320 LOGE("Out-of-memory");
1321 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1326 return NOTI_EX_ERROR_NONE;
1329 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1330 noti_ex_color_h color) {
1331 if (handle == nullptr) {
1332 LOGE("Invalid parameter");
1333 return NOTI_EX_ERROR_INVALID_PARAMETER;
1336 shared_ptr<Color>* color_ = static_cast<shared_ptr<Color>*>(color);
1337 auto* p = new (std::nothrow) LEDInfo(*color_);
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_destroy(noti_ex_led_info_h handle) {
1349 if (handle == nullptr) {
1350 LOGE("Invalid parameter");
1351 return NOTI_EX_ERROR_INVALID_PARAMETER;
1354 LEDInfo* p = static_cast<LEDInfo*>(handle);
1357 return NOTI_EX_ERROR_NONE;
1360 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1361 noti_ex_led_info_h handle, int ms) {
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_get_on_period(
1374 noti_ex_led_info_h handle, int *ms) {
1375 if (handle == nullptr || ms == nullptr) {
1376 LOGE("Invalid parameter");
1377 return NOTI_EX_ERROR_INVALID_PARAMETER;
1380 LEDInfo* p = static_cast<LEDInfo*>(handle);
1381 *ms = p->GetOnPeriod();
1383 return NOTI_EX_ERROR_NONE;
1386 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1387 noti_ex_led_info_h handle, int ms) {
1388 if (handle == nullptr) {
1389 LOGE("Invalid parameter");
1390 return NOTI_EX_ERROR_INVALID_PARAMETER;
1393 LEDInfo* p = static_cast<LEDInfo*>(handle);
1394 p->SetOffPeriod(ms);
1396 return NOTI_EX_ERROR_NONE;
1399 extern "C" EXPORT_API int noti_ex_led_info_get_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 *ms = p->GetOffPeriod();
1409 return NOTI_EX_ERROR_NONE;
1412 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1413 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1414 if (handle == nullptr) {
1415 LOGE("Invalid parameter");
1416 return NOTI_EX_ERROR_INVALID_PARAMETER;
1419 LEDInfo* p = static_cast<LEDInfo*>(handle);
1420 if (p->GetColor() == nullptr) {
1421 LOGE("Color is null");
1422 return NOTI_EX_ERROR_INVALID_PARAMETER;
1425 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1426 new (std::nothrow) Color(*(p->GetColor())));
1427 if (col == nullptr || col->get() == nullptr) {
1428 LOGE("Out-of-memory");
1429 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1434 return NOTI_EX_ERROR_NONE;
1437 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1438 if (handle == nullptr) {
1439 LOGE("Invalid parameter");
1440 return NOTI_EX_ERROR_INVALID_PARAMETER;
1443 AbstractAction* p = static_cast<AbstractAction*>(handle);
1444 p->~AbstractAction();
1446 return NOTI_EX_ERROR_NONE;
1449 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1451 if (handle == nullptr || type == nullptr) {
1452 LOGE("Invalid parameter");
1453 return NOTI_EX_ERROR_INVALID_PARAMETER;
1456 AbstractAction* p = static_cast<AbstractAction*>(handle);
1457 *type = p->GetType();
1459 return NOTI_EX_ERROR_NONE;
1462 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1464 if (handle == nullptr || local == nullptr) {
1465 LOGE("Invalid parameter");
1466 return NOTI_EX_ERROR_INVALID_PARAMETER;
1469 AbstractAction* p = static_cast<AbstractAction*>(handle);
1470 *local = p->IsLocal();
1472 return NOTI_EX_ERROR_NONE;
1475 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1476 noti_ex_item_h item) {
1477 if (handle == nullptr || item == nullptr) {
1478 LOGE("Invalid parameter");
1479 return NOTI_EX_ERROR_INVALID_PARAMETER;
1481 AbstractAction* p = static_cast<AbstractAction*>(handle);
1482 Handle* ih = static_cast<Handle*>(item);
1483 p->Execute(ih->GetPtr());
1485 return NOTI_EX_ERROR_NONE;
1488 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1490 if (handle == nullptr || extra == nullptr) {
1491 LOGE("Invalid parameter");
1492 return NOTI_EX_ERROR_INVALID_PARAMETER;
1495 AbstractAction* p = static_cast<AbstractAction*>(handle);
1496 if (!p->GetExtra().empty()) {
1497 *extra = strdup(p->GetExtra().c_str());
1498 if (*extra == nullptr) {
1499 LOGE("Out-of-memory");
1500 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1504 return NOTI_EX_ERROR_NONE;
1507 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1508 noti_ex_item_info_h handle, int *hide_time) {
1509 if (handle == nullptr || hide_time == nullptr) {
1510 LOGE("Invalid parameter");
1511 return NOTI_EX_ERROR_INVALID_PARAMETER;
1513 IItemInfo* p = static_cast<IItemInfo*>(handle);
1514 *hide_time = p->GetHideTime();
1515 return NOTI_EX_ERROR_NONE;
1518 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1519 noti_ex_item_info_h handle, int hide_time) {
1520 if (handle == nullptr) {
1521 LOGE("Invalid parameter");
1522 return NOTI_EX_ERROR_INVALID_PARAMETER;
1524 IItemInfo* p = static_cast<IItemInfo*>(handle);
1525 p->SetHideTime(hide_time);
1526 return NOTI_EX_ERROR_NONE;
1529 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1530 noti_ex_item_info_h handle, int *delete_time) {
1531 if (handle == nullptr || delete_time == nullptr) {
1532 LOGE("Invalid parameter");
1533 return NOTI_EX_ERROR_INVALID_PARAMETER;
1535 IItemInfo* p = static_cast<IItemInfo*>(handle);
1536 *delete_time = p->GetDeleteTime();
1537 return NOTI_EX_ERROR_NONE;
1540 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1541 noti_ex_item_info_h handle, int delete_time) {
1542 if (handle == nullptr) {
1543 LOGE("Invalid parameter");
1544 return NOTI_EX_ERROR_INVALID_PARAMETER;
1546 IItemInfo* p = static_cast<IItemInfo*>(handle);
1547 p->SetDeleteTime(delete_time);
1548 return NOTI_EX_ERROR_NONE;
1551 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1552 noti_ex_item_info_h handle, time_t *time) {
1553 if (handle == nullptr || time == nullptr) {
1554 LOGE("Invalid parameter");
1555 return NOTI_EX_ERROR_INVALID_PARAMETER;
1558 IItemInfo* p = static_cast<IItemInfo*>(handle);
1559 *time = p->GetTime();
1560 return NOTI_EX_ERROR_NONE;
1563 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1564 if (handle == nullptr) {
1565 LOGE("Invalid parameter");
1566 return NOTI_EX_ERROR_INVALID_PARAMETER;
1569 Handle* h = static_cast<Handle*>(handle);
1571 return NOTI_EX_ERROR_NONE;
1574 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1575 const char *id, noti_ex_item_h *item) {
1576 if (handle == nullptr) {
1577 LOGE("Invalid parameter");
1578 return NOTI_EX_ERROR_INVALID_PARAMETER;
1581 Handle* p = static_cast<Handle*>(handle);
1582 AbstractItem& find_item = p->Get()->FindByID(string(id));
1583 *item = new Handle(&find_item);
1584 return NOTI_EX_ERROR_NONE;
1587 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1589 if (handle == nullptr || type == nullptr) {
1590 LOGE("Invalid parameter");
1591 return NOTI_EX_ERROR_INVALID_PARAMETER;
1594 Handle* h = static_cast<Handle*>(handle);
1595 AbstractItem* p = h->Get();
1596 *type = p->GetType();
1597 return NOTI_EX_ERROR_NONE;
1600 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1601 char ***path, int *count) {
1602 if (handle == nullptr || path == nullptr || count == nullptr) {
1603 LOGE("Invalid parameter");
1604 return NOTI_EX_ERROR_INVALID_PARAMETER;
1606 Handle* p = static_cast<Handle*>(handle);
1607 list<string> shared_path = p->Get()->GetSharedPath();
1608 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1610 for (auto& i : shared_path) {
1611 *path[idx++] = strdup(i.c_str());
1613 *count = shared_path.size();
1614 return NOTI_EX_ERROR_NONE;
1617 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1619 if (handle == nullptr || id == nullptr) {
1620 LOGE("Invalid parameter");
1621 return NOTI_EX_ERROR_INVALID_PARAMETER;
1623 Handle* h = static_cast<Handle*>(handle);
1624 AbstractItem* p = h->Get();
1625 *id = strdup(p->GetId().c_str());
1626 return NOTI_EX_ERROR_NONE;
1629 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1631 if (handle == nullptr || id == nullptr) {
1632 LOGE("Invalid parameter");
1633 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 Handle* p = static_cast<Handle*>(handle);
1636 p->Get()->SetId(id);
1637 return NOTI_EX_ERROR_NONE;
1640 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1641 noti_ex_action_h *action) {
1642 if (handle == nullptr || action == nullptr) {
1643 LOGE("Invalid parameter");
1644 return NOTI_EX_ERROR_INVALID_PARAMETER;
1646 Handle* p = static_cast<Handle*>(handle);
1647 if (p->Get()->GetAction() == nullptr) {
1649 return NOTI_EX_ERROR_NONE;
1651 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1653 return NOTI_EX_ERROR_NONE;
1656 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1657 noti_ex_action_h action) {
1658 if (handle == nullptr || action == nullptr) {
1659 LOGE("Invalid parameter");
1660 return NOTI_EX_ERROR_INVALID_PARAMETER;
1663 Handle* p = static_cast<Handle*>(handle);
1664 AbstractAction* a = static_cast<AbstractAction*>(action);
1665 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1666 return NOTI_EX_ERROR_NONE;
1669 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1670 noti_ex_style_h *style) {
1671 if (handle == nullptr || style == nullptr) {
1672 LOGE("Invalid parameter");
1673 return NOTI_EX_ERROR_INVALID_PARAMETER;
1676 Handle* p = static_cast<Handle*>(handle);
1677 shared_ptr<Style> s = p->Get()->GetStyle();
1678 if (s.get() == nullptr) {
1679 LOGE("Style is null");
1680 return NOTI_EX_ERROR_INVALID_PARAMETER;
1683 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1684 if (ptr == nullptr || ptr->get() == nullptr) {
1685 LOGE("Out of memory");
1686 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1690 return NOTI_EX_ERROR_NONE;
1693 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1694 noti_ex_style_h style) {
1695 if (handle == nullptr || style == nullptr) {
1696 LOGE("Invalid parameter");
1697 return NOTI_EX_ERROR_INVALID_PARAMETER;
1700 Handle* p = static_cast<Handle*>(handle);
1701 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1702 p->Get()->SetStyle(*s);
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1708 if (handle == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 Handle* p = static_cast<Handle*>(handle);
1714 p->Get()->SetVisible(visible);
1715 return NOTI_EX_ERROR_NONE;
1718 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1720 if (handle == nullptr || visible == nullptr) {
1721 LOGE("Invalid parameter");
1722 return NOTI_EX_ERROR_INVALID_PARAMETER;
1725 Handle* p = static_cast<Handle*>(handle);
1726 *visible = p->Get()->GetVisible();
1727 return NOTI_EX_ERROR_NONE;
1730 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1732 if (handle == nullptr) {
1733 LOGE("Invalid parameter");
1734 return NOTI_EX_ERROR_INVALID_PARAMETER;
1737 Handle* p = static_cast<Handle*>(handle);
1738 p->Get()->SetEnable(enable);
1739 return NOTI_EX_ERROR_NONE;
1742 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1744 if (handle == nullptr || enable == nullptr) {
1745 LOGE("Invalid parameter");
1746 return NOTI_EX_ERROR_INVALID_PARAMETER;
1749 Handle* p = static_cast<Handle*>(handle);
1750 *enable = p->Get()->GetEnable();
1751 return NOTI_EX_ERROR_NONE;
1754 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1755 const char *receiver_group) {
1756 if (handle == nullptr || receiver_group == nullptr) {
1757 LOGE("Invalid parameter");
1758 return NOTI_EX_ERROR_INVALID_PARAMETER;
1761 Handle* p = static_cast<Handle*>(handle);
1762 p->Get()->AddReceiver(receiver_group);
1763 return NOTI_EX_ERROR_NONE;
1766 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1767 const char *receiver_group) {
1768 if (handle == nullptr || receiver_group == nullptr) {
1769 LOGE("Invalid parameter");
1770 return NOTI_EX_ERROR_INVALID_PARAMETER;
1773 Handle* p = static_cast<Handle*>(handle);
1774 p->Get()->RemoveReceiver(receiver_group);
1775 return NOTI_EX_ERROR_NONE;
1778 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1779 char ***receiver_list, int *count) {
1780 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1781 LOGE("Invalid parameter");
1782 return NOTI_EX_ERROR_INVALID_PARAMETER;
1785 Handle* p = static_cast<Handle*>(handle);
1786 list<string> receivers = p->Get()->GetReceiverList();
1787 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1789 for (auto& i : receivers) {
1790 *receiver_list[idx++] = strdup(i.c_str());
1792 *count = receivers.size();
1793 return NOTI_EX_ERROR_NONE;
1796 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1798 if (handle == nullptr) {
1799 LOGE("Invalid parameter");
1800 return NOTI_EX_ERROR_INVALID_PARAMETER;
1803 Handle* p = static_cast<Handle*>(handle);
1804 p->Get()->SetPolicy(policy);
1805 return NOTI_EX_ERROR_NONE;
1808 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1810 if (handle == nullptr || policy == nullptr) {
1811 LOGE("Invalid parameter");
1812 return NOTI_EX_ERROR_INVALID_PARAMETER;
1815 Handle* p = static_cast<Handle*>(handle);
1816 *policy = p->Get()->GetPolicy();
1817 return NOTI_EX_ERROR_NONE;
1820 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1822 if (handle == nullptr || channel == nullptr) {
1823 LOGE("Invalid parameter");
1824 return NOTI_EX_ERROR_INVALID_PARAMETER;
1827 Handle* p = static_cast<Handle*>(handle);
1828 if (!p->Get()->GetChannel().empty())
1829 *channel = strdup(p->Get()->GetChannel().c_str());
1833 return NOTI_EX_ERROR_NONE;
1836 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1837 const char *channel) {
1838 if (handle == nullptr) {
1839 LOGE("Invalid parameter");
1840 return NOTI_EX_ERROR_INVALID_PARAMETER;
1843 Handle* p = static_cast<Handle*>(handle);
1844 p->Get()->SetChannel(channel);
1845 return NOTI_EX_ERROR_NONE;
1848 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1849 noti_ex_led_info_h led) {
1850 if (handle == nullptr) {
1851 LOGE("Invalid parameter");
1852 return NOTI_EX_ERROR_INVALID_PARAMETER;
1855 Handle* p = static_cast<Handle*>(handle);
1856 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1857 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1858 return NOTI_EX_ERROR_NONE;
1861 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1862 noti_ex_led_info_h *led) {
1863 if (handle == nullptr) {
1864 LOGE("Invalid parameter");
1865 return NOTI_EX_ERROR_INVALID_PARAMETER;
1868 Handle* p = static_cast<Handle*>(handle);
1869 if (p->Get()->GetLEDInfo() != nullptr)
1870 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1873 return NOTI_EX_ERROR_NONE;
1876 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1878 if (handle == nullptr) {
1879 LOGE("Invalid parameter");
1880 return NOTI_EX_ERROR_INVALID_PARAMETER;
1883 Handle* p = static_cast<Handle*>(handle);
1884 if (path == nullptr)
1885 p->Get()->SetSoundPath("");
1887 p->Get()->SetSoundPath(path);
1888 return NOTI_EX_ERROR_NONE;
1891 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1893 if (handle == nullptr) {
1894 LOGE("Invalid parameter");
1895 return NOTI_EX_ERROR_INVALID_PARAMETER;
1898 Handle* p = static_cast<Handle*>(handle);
1899 if (path == nullptr)
1900 p->Get()->SetVibrationPath("");
1902 p->Get()->SetVibrationPath(path);
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1908 if (handle == nullptr || path == nullptr) {
1909 LOGE("Invalid parameter");
1910 return NOTI_EX_ERROR_INVALID_PARAMETER;
1913 Handle* p = static_cast<Handle*>(handle);
1914 if (p->Get()->GetSoundPath().empty())
1917 *path = strdup(p->Get()->GetSoundPath().c_str());
1918 return NOTI_EX_ERROR_NONE;
1921 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1923 if (handle == nullptr || path == nullptr) {
1924 LOGE("Invalid parameter");
1925 return NOTI_EX_ERROR_INVALID_PARAMETER;
1928 Handle* p = static_cast<Handle*>(handle);
1929 if (p->Get()->GetVibrationPath().empty())
1932 *path = strdup(p->Get()->GetVibrationPath().c_str());
1933 return NOTI_EX_ERROR_NONE;
1936 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1937 noti_ex_item_info_h *info) {
1938 if (handle == nullptr || info == nullptr) {
1939 LOGE("Invalid parameter");
1940 return NOTI_EX_ERROR_INVALID_PARAMETER;
1943 Handle* p = static_cast<Handle*>(handle);
1944 if (p->Get()->GetInfo() == nullptr)
1947 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1948 return NOTI_EX_ERROR_NONE;
1951 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1953 if (handle == nullptr || id == nullptr) {
1954 LOGE("Invalid parameter");
1955 return NOTI_EX_ERROR_INVALID_PARAMETER;
1958 Handle* p = static_cast<Handle*>(handle);
1959 if (p->Get()->GetSenderAppId().empty())
1962 *id = strdup(p->Get()->GetSenderAppId().c_str());
1963 return NOTI_EX_ERROR_NONE;
1966 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1968 if (handle == nullptr || tag == nullptr) {
1969 LOGE("Invalid parameter");
1970 return NOTI_EX_ERROR_INVALID_PARAMETER;
1973 Handle* p = static_cast<Handle*>(handle);
1974 if (p->Get()->GetTag().empty())
1977 *tag = strdup(p->Get()->GetTag().c_str());
1978 return NOTI_EX_ERROR_NONE;
1981 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1983 if (handle == nullptr) {
1984 LOGE("Invalid parameter");
1985 return NOTI_EX_ERROR_INVALID_PARAMETER;
1988 Handle* p = static_cast<Handle*>(handle);
1990 p->Get()->SetTag("");
1992 p->Get()->SetTag(tag);
1993 return NOTI_EX_ERROR_NONE;
1996 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1997 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1999 if (handle == nullptr) {
2000 LOGE("Invalid parameter");
2001 return NOTI_EX_ERROR_INVALID_PARAMETER;
2004 string receiver_group_str = "";
2006 receiver_group_str = string(receiver_group);
2008 ManagerStub* stub = new (std::nothrow) ManagerStub(
2009 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2010 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2011 receiver_group_str);
2012 if (stub == nullptr) {
2013 LOGE("Fail to create manager");
2014 return NOTI_EX_ERROR_IO_ERROR;
2016 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2017 new ManagerCallbackInfo(event_callbacks, data)));
2018 *handle = static_cast<noti_ex_manager_h>(stub);
2020 return NOTI_EX_ERROR_NONE;
2023 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2024 if (handle == nullptr) {
2025 LOGE("Invalid parameter");
2026 return NOTI_EX_ERROR_INVALID_PARAMETER;
2028 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2030 return NOTI_EX_ERROR_NONE;
2033 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2034 noti_ex_item_h **items, int *count) {
2035 if (handle == nullptr || items == nullptr || count == nullptr) {
2036 LOGE("Invalid parameter");
2037 return NOTI_EX_ERROR_INVALID_PARAMETER;
2041 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2042 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2043 if (item_list.size() == 0) {
2046 return NOTI_EX_ERROR_NONE;
2048 noti_ex_item_h* added_item =
2049 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2050 if (added_item == nullptr) {
2051 LOGE("Fail to create items");
2052 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2056 for (auto& i : item_list) {
2057 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2059 *items = added_item;
2060 *count = item_list.size();
2061 } catch (Exception &ex) {
2062 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2063 return NOTI_EX_ERROR_IO_ERROR;
2065 return NOTI_EX_ERROR_NONE;
2068 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2069 noti_ex_item_h noti, int *request_id) {
2070 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2071 LOGE("Invalid parameter");
2072 return NOTI_EX_ERROR_INVALID_PARAMETER;
2075 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2076 Handle* sp = static_cast<Handle*>(noti);
2077 if (sp->GetPtr().get() == nullptr) {
2078 LOGE("Invalid noti reference can not be sended");
2079 return NOTI_EX_ERROR_INVALID_PARAMETER;
2081 *request_id = stub->Update(sp->GetPtr());
2083 } catch (Exception &ex) {
2084 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2085 return NOTI_EX_ERROR_IO_ERROR;
2087 return NOTI_EX_ERROR_NONE;
2090 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2091 noti_ex_item_h noti, int *request_id) {
2092 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2093 LOGE("Invalid parameter");
2094 return NOTI_EX_ERROR_INVALID_PARAMETER;
2097 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2098 Handle* item = static_cast<Handle*>(noti);
2099 if (item->GetPtr().get() == nullptr) {
2100 LOGE("Invalid noti reference can not be sended");
2101 return NOTI_EX_ERROR_INVALID_PARAMETER;
2103 *request_id = stub->Delete(item->GetPtr());
2105 } catch (Exception &ex) {
2106 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2107 return NOTI_EX_ERROR_IO_ERROR;
2109 return NOTI_EX_ERROR_NONE;
2112 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2114 if (handle == nullptr || request_id == nullptr) {
2115 LOGE("Invalid parameter");
2116 return NOTI_EX_ERROR_INVALID_PARAMETER;
2119 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2120 *request_id = stub->DeleteAll();
2121 } catch (Exception &ex) {
2122 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2123 return NOTI_EX_ERROR_IO_ERROR;
2125 return NOTI_EX_ERROR_NONE;
2128 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2129 noti_ex_item_h noti, int *request_id) {
2130 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2131 LOGE("Invalid parameter");
2132 return NOTI_EX_ERROR_INVALID_PARAMETER;
2135 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2136 Handle* item = static_cast<Handle*>(noti);
2137 if (item->GetPtr().get() == nullptr) {
2138 LOGE("Invalid noti reference can not be sended");
2139 return NOTI_EX_ERROR_INVALID_PARAMETER;
2141 *request_id = stub->Hide(item->GetPtr());
2143 } catch (Exception &ex) {
2144 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2145 return NOTI_EX_ERROR_IO_ERROR;
2147 return NOTI_EX_ERROR_NONE;
2150 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2151 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2152 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2153 LOGE("Invalid parameter");
2154 return NOTI_EX_ERROR_INVALID_PARAMETER;
2157 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2158 *item = new Handle(stub->FindByRootID(root_id));
2159 } catch (Exception &ex) {
2160 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2161 return NOTI_EX_ERROR_IO_ERROR;
2163 return NOTI_EX_ERROR_NONE;
2166 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2167 noti_ex_event_info_h info, noti_ex_error_e error) {
2168 if (handle == nullptr || info == nullptr) {
2169 LOGE("Invalid parameter");
2170 return NOTI_EX_ERROR_INVALID_PARAMETER;
2173 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2174 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2175 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2176 static_cast<NotificationError>(error));
2177 } catch (Exception &ex) {
2178 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2179 return NOTI_EX_ERROR_IO_ERROR;
2181 return NOTI_EX_ERROR_NONE;
2184 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2185 noti_ex_manager_h handle, int *cnt) {
2187 if (handle == nullptr || cnt == nullptr) {
2188 LOGE("Invalid parameter");
2189 return NOTI_EX_ERROR_INVALID_PARAMETER;
2192 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2193 *cnt = stub->GetCount();
2194 } catch (Exception &ex) {
2195 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2196 return NOTI_EX_ERROR_IO_ERROR;
2198 return NOTI_EX_ERROR_NONE;
2201 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2202 const char *id, float min, float current, float max) {
2205 if (handle == nullptr) {
2206 LOGE("Invalid parameter");
2207 return NOTI_EX_ERROR_INVALID_PARAMETER;
2211 p = new (std::nothrow) ProgressItem(id, min, current, max);
2213 p = new (std::nothrow) ProgressItem(min, current, max);
2216 LOGE("Out-of-memory");
2217 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2220 *handle = new Handle(shared_ptr<AbstractItem>(p));
2222 return NOTI_EX_ERROR_NONE;
2225 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2226 noti_ex_item_h handle, float *current) {
2227 if (handle == nullptr || current == nullptr) {
2228 LOGE("Invalid parameter");
2229 return NOTI_EX_ERROR_INVALID_PARAMETER;
2232 Handle *h = static_cast<Handle*>(handle);
2233 if (!h->IsValidType(AbstractItem::Progress)) {
2234 LOGE("Invalid handle type");
2235 return NOTI_EX_ERROR_INVALID_PARAMETER;
2237 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2238 *current = p->GetCurrent();
2240 return NOTI_EX_ERROR_NONE;
2243 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2244 noti_ex_item_h handle, float current) {
2245 if (handle == nullptr) {
2246 LOGE("Invalid parameter");
2247 return NOTI_EX_ERROR_INVALID_PARAMETER;
2250 Handle *h = static_cast<Handle*>(handle);
2251 if (!h->IsValidType(AbstractItem::Progress)) {
2252 LOGE("Invalid handle type");
2253 return NOTI_EX_ERROR_INVALID_PARAMETER;
2255 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2256 p->SetCurrent(current);
2258 return NOTI_EX_ERROR_NONE;
2261 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2263 if (handle == nullptr || min == nullptr) {
2264 LOGE("Invalid parameter");
2265 return NOTI_EX_ERROR_INVALID_PARAMETER;
2268 Handle *h = static_cast<Handle*>(handle);
2269 if (!h->IsValidType(AbstractItem::Progress)) {
2270 LOGE("Invalid handle type");
2271 return NOTI_EX_ERROR_INVALID_PARAMETER;
2273 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2276 return NOTI_EX_ERROR_NONE;
2279 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2281 if (handle == nullptr || max == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2286 Handle *h = static_cast<Handle*>(handle);
2287 if (!h->IsValidType(AbstractItem::Progress)) {
2288 LOGE("Invalid handle type");
2289 return NOTI_EX_ERROR_INVALID_PARAMETER;
2291 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2294 return NOTI_EX_ERROR_NONE;
2297 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2298 noti_ex_reporter_events_s event_callbacks, void *data) {
2299 if (handle == nullptr) {
2300 LOGE("Invalid parameter");
2301 return NOTI_EX_ERROR_INVALID_PARAMETER;
2304 ReporterStub* stub = new (std::nothrow) ReporterStub(
2305 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2306 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2307 if (stub == nullptr) {
2308 LOGE("Fail to create manager");
2309 return NOTI_EX_ERROR_IO_ERROR;
2311 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2312 new ReporterCallbackInfo(event_callbacks, data)));
2314 *handle = static_cast<noti_ex_reporter_h>(stub);
2316 return NOTI_EX_ERROR_NONE;
2319 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2320 if (handle == nullptr) {
2321 LOGE("Invalid parameter");
2322 return NOTI_EX_ERROR_INVALID_PARAMETER;
2324 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2330 noti_ex_event_info_h info, noti_ex_error_e error) {
2331 if (handle == nullptr || info == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2337 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2338 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2339 static_cast<NotificationError>(error));
2340 } catch (Exception &ex) {
2341 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2342 return NOTI_EX_ERROR_IO_ERROR;
2344 return NOTI_EX_ERROR_NONE;
2347 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2348 noti_ex_item_h noti, int *request_id) {
2349 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2350 LOGE("Invalid parameter");
2351 return NOTI_EX_ERROR_INVALID_PARAMETER;
2354 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2355 Handle* h = static_cast<Handle*>(noti);
2356 if (h->GetPtr().get() == nullptr) {
2357 LOGE("Invalid noti reference can not be sended");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2360 *request_id = stub->Post(h->GetPtr());
2362 } catch (Exception &ex) {
2363 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2364 return NOTI_EX_ERROR_IO_ERROR;
2366 return NOTI_EX_ERROR_NONE;
2369 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2370 noti_ex_item_h *noti_list, int count, int *request_id) {
2372 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2373 LOGE("Invalid parameter");
2374 return NOTI_EX_ERROR_INVALID_PARAMETER;
2377 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2378 list<shared_ptr<item::AbstractItem>> notiList;
2379 for (int i = 0; i < count; i++) {
2380 Handle* item = static_cast<Handle*>(noti_list[i]);
2381 notiList.push_back(item->GetPtr());
2383 *request_id = stub->Post(notiList);
2384 } catch (Exception &ex) {
2385 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2386 return NOTI_EX_ERROR_IO_ERROR;
2388 return NOTI_EX_ERROR_NONE;
2391 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2392 noti_ex_item_h noti, int *request_id) {
2393 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2394 LOGE("Invalid parameter");
2395 return NOTI_EX_ERROR_INVALID_PARAMETER;
2398 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2399 Handle* item = static_cast<Handle*>(noti);
2400 if (item->GetPtr().get() == nullptr) {
2401 LOGE("Invalid noti reference can not be sended");
2402 return NOTI_EX_ERROR_INVALID_PARAMETER;
2404 *request_id = stub->Update(item->GetPtr());
2406 } catch (Exception &ex) {
2407 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2408 return NOTI_EX_ERROR_IO_ERROR;
2410 return NOTI_EX_ERROR_NONE;
2413 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2414 noti_ex_item_h noti, int *request_id) {
2415 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2416 LOGE("Invalid parameter");
2417 return NOTI_EX_ERROR_INVALID_PARAMETER;
2420 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2421 Handle* item = static_cast<Handle*>(noti);
2422 if (item->GetPtr().get() == nullptr) {
2423 LOGE("Invalid noti reference can not be sended");
2424 return NOTI_EX_ERROR_INVALID_PARAMETER;
2426 *request_id = stub->Delete(item->GetPtr());
2428 } catch (Exception &ex) {
2429 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2430 return NOTI_EX_ERROR_IO_ERROR;
2432 return NOTI_EX_ERROR_NONE;
2435 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2436 noti_ex_reporter_h handle, int *request_id) {
2437 if (handle == nullptr || request_id == nullptr) {
2438 LOGE("Invalid parameter");
2439 return NOTI_EX_ERROR_INVALID_PARAMETER;
2442 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2443 *request_id = stub->DeleteAll();
2444 } catch (Exception &ex) {
2445 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2446 return NOTI_EX_ERROR_IO_ERROR;
2448 return NOTI_EX_ERROR_NONE;
2451 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2452 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2453 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2454 LOGE("Invalid parameter");
2455 return NOTI_EX_ERROR_INVALID_PARAMETER;
2458 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2459 *item = new Handle(stub->FindByRootID(root_id));
2460 } catch (Exception &ex) {
2461 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2462 return NOTI_EX_ERROR_IO_ERROR;
2464 return NOTI_EX_ERROR_NONE;
2467 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2468 const char *id, const char *text, const char *hyperlink) {
2469 if (handle == nullptr || text == nullptr) {
2470 LOGE("Invalid parameter");
2471 return NOTI_EX_ERROR_INVALID_PARAMETER;
2477 p = new (std::nothrow) TextItem(id, std::string(text),
2478 std::string(hyperlink));
2480 p = new (std::nothrow) TextItem(id, std::string(text));
2483 LOGE("Out-of-memory");
2484 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2487 *handle = new Handle(shared_ptr<AbstractItem>(p));
2489 return NOTI_EX_ERROR_NONE;
2492 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2493 const char *contents) {
2494 if (handle == nullptr || contents == nullptr) {
2495 LOGE("Invalid parameter");
2496 return NOTI_EX_ERROR_INVALID_PARAMETER;
2499 Handle* p = static_cast<Handle*>(handle);
2500 if (!p->IsValidType(AbstractItem::Text)) {
2501 LOGE("Invalid handle type");
2502 return NOTI_EX_ERROR_INVALID_PARAMETER;
2504 TextItem* ti = static_cast<TextItem*>(p->Get());
2505 ti->SetContents(std::string(contents));
2507 return NOTI_EX_ERROR_NONE;
2510 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2512 if (handle == nullptr || contents == nullptr) {
2513 LOGE("Invalid parameter");
2514 return NOTI_EX_ERROR_INVALID_PARAMETER;
2517 Handle* p = static_cast<Handle*>(handle);
2518 if (!p->IsValidType(AbstractItem::Text)) {
2519 LOGE("Invalid handle type");
2520 return NOTI_EX_ERROR_INVALID_PARAMETER;
2522 TextItem* ti = static_cast<TextItem*>(p->Get());
2523 if (!ti->GetContents().empty()) {
2524 *contents = strdup(ti->GetContents().c_str());
2525 if (*contents == nullptr) {
2526 LOGE("Out-of-memory");
2527 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2531 return NOTI_EX_ERROR_NONE;
2534 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2535 noti_ex_item_h handle, char **hyper_link) {
2536 if (handle == nullptr || hyper_link == nullptr) {
2537 LOGE("Invalid parameter");
2538 return NOTI_EX_ERROR_INVALID_PARAMETER;
2541 Handle* p = static_cast<Handle*>(handle);
2542 if (!p->IsValidType(AbstractItem::Text)) {
2543 LOGE("Invalid handle type");
2544 return NOTI_EX_ERROR_INVALID_PARAMETER;
2546 TextItem* ti = static_cast<TextItem*>(p->Get());
2547 if (!ti->GetHyperLink().empty()) {
2548 *hyper_link = strdup(ti->GetHyperLink().c_str());
2549 if (*hyper_link == nullptr) {
2550 LOGE("Out-of-memory");
2551 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2555 return NOTI_EX_ERROR_NONE;
2558 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2559 const char *id, time_t time) {
2562 if (handle == nullptr) {
2563 LOGE("Invalid parameter");
2564 return NOTI_EX_ERROR_INVALID_PARAMETER;
2569 p = new (std::nothrow) TimeItem(id, time);
2571 p = new (std::nothrow) TimeItem(time);
2573 p = new (std::nothrow) TimeItem();
2577 LOGE("Out-of-memory");
2578 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2581 *handle = new Handle(shared_ptr<AbstractItem>(p));
2583 return NOTI_EX_ERROR_NONE;
2586 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2588 if (handle == nullptr || time == nullptr) {
2589 LOGE("Invalid parameter");
2590 return NOTI_EX_ERROR_INVALID_PARAMETER;
2592 Handle* h = static_cast<Handle*>(handle);
2593 if (!h->IsValidType(AbstractItem::Time)) {
2594 LOGE("Invalid handle type");
2595 return NOTI_EX_ERROR_INVALID_PARAMETER;
2597 TimeItem* p = static_cast<TimeItem*>(h->Get());
2598 *time = p->GetTime();
2600 return NOTI_EX_ERROR_NONE;
2603 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2604 noti_ex_action_h *handle, const char *extra) {
2605 if (handle == nullptr) {
2606 LOGE("Invalid parameter");
2607 return NOTI_EX_ERROR_INVALID_PARAMETER;
2610 string extra_str = "";
2612 extra_str = string(extra);
2614 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2616 LOGE("Out-of-memory");
2617 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2622 return NOTI_EX_ERROR_NONE;
2625 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2626 const char *id, bool visible) {
2627 if (handle == nullptr || id == nullptr) {
2628 LOGE("Invalid parameter");
2629 return NOTI_EX_ERROR_INVALID_PARAMETER;
2632 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2633 p->SetVisibility(id, visible);
2635 return NOTI_EX_ERROR_NONE;