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* p = new (std::nothrow) Color(a, r, g, b);
968 LOGE("Out-of-memory");
969 return NOTI_EX_ERROR_OUT_OF_MEMORY;
974 return NOTI_EX_ERROR_NONE;
977 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
978 if (handle == nullptr) {
979 LOGE("Invalid parameter");
980 return NOTI_EX_ERROR_INVALID_PARAMETER;
983 Color* p = static_cast<Color*>(handle);
986 return NOTI_EX_ERROR_NONE;
989 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
990 unsigned char *val) {
991 if (handle == nullptr || val == nullptr) {
992 LOGE("Invalid parameter");
993 return NOTI_EX_ERROR_INVALID_PARAMETER;
996 Color* p = static_cast<Color*>(handle);
999 return NOTI_EX_ERROR_NONE;
1002 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1003 unsigned char *val) {
1004 if (handle == nullptr || val == nullptr) {
1005 LOGE("Invalid parameter");
1006 return NOTI_EX_ERROR_INVALID_PARAMETER;
1009 Color* p = static_cast<Color*>(handle);
1010 *val = p->GetRVal();
1012 return NOTI_EX_ERROR_NONE;
1015 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1016 unsigned char *val) {
1017 if (handle == nullptr || val == nullptr) {
1018 LOGE("Invalid parameter");
1019 return NOTI_EX_ERROR_INVALID_PARAMETER;
1022 Color* p = static_cast<Color*>(handle);
1023 *val = p->GetGVal();
1025 return NOTI_EX_ERROR_NONE;
1028 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1029 unsigned char *val) {
1030 if (handle == nullptr || val == nullptr) {
1031 LOGE("Invalid parameter");
1032 return NOTI_EX_ERROR_INVALID_PARAMETER;
1035 Color* p = static_cast<Color*>(handle);
1036 *val = p->GetBVal();
1038 return NOTI_EX_ERROR_NONE;
1041 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1042 int left, int top, int right, int bottom) {
1043 if (handle == nullptr) {
1044 LOGE("Invalid parameter");
1045 return NOTI_EX_ERROR_INVALID_PARAMETER;
1048 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1050 LOGE("Out-of-memory");
1051 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1056 return NOTI_EX_ERROR_NONE;
1059 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1060 if (handle == nullptr) {
1061 LOGE("Invalid parameter");
1062 return NOTI_EX_ERROR_INVALID_PARAMETER;
1065 Padding* p = static_cast<Padding*>(handle);
1068 return NOTI_EX_ERROR_NONE;
1071 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1073 if (handle == nullptr || val == nullptr) {
1074 LOGE("Invalid parameter");
1075 return NOTI_EX_ERROR_INVALID_PARAMETER;
1078 Padding* p = static_cast<Padding*>(handle);
1079 *val = p->GetLeft();
1081 return NOTI_EX_ERROR_NONE;
1084 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1086 if (handle == nullptr || val == nullptr) {
1087 LOGE("Invalid parameter");
1088 return NOTI_EX_ERROR_INVALID_PARAMETER;
1091 Padding* p = static_cast<Padding*>(handle);
1094 return NOTI_EX_ERROR_NONE;
1097 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1099 if (handle == nullptr || val == nullptr) {
1100 LOGE("Invalid parameter");
1101 return NOTI_EX_ERROR_INVALID_PARAMETER;
1104 Padding* p = static_cast<Padding*>(handle);
1105 *val = p->GetRight();
1107 return NOTI_EX_ERROR_NONE;
1110 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1112 if (handle == nullptr || val == nullptr) {
1113 LOGE("Invalid parameter");
1114 return NOTI_EX_ERROR_INVALID_PARAMETER;
1117 Padding* p = static_cast<Padding*>(handle);
1118 *val = p->GetBottom();
1120 return NOTI_EX_ERROR_NONE;
1123 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1124 int x, int y, int w, int h) {
1125 if (handle == nullptr) {
1126 LOGE("Invalid parameter");
1127 return NOTI_EX_ERROR_INVALID_PARAMETER;
1130 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1132 LOGE("Out-of-memory");
1133 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1138 return NOTI_EX_ERROR_NONE;
1141 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1142 if (handle == nullptr) {
1143 LOGE("Invalid parameter");
1144 return NOTI_EX_ERROR_INVALID_PARAMETER;
1147 Geometry* p = static_cast<Geometry*>(handle);
1150 return NOTI_EX_ERROR_NONE;
1153 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1155 if (handle == nullptr || val == nullptr) {
1156 LOGE("Invalid parameter");
1157 return NOTI_EX_ERROR_INVALID_PARAMETER;
1160 Geometry* p = static_cast<Geometry*>(handle);
1163 return NOTI_EX_ERROR_NONE;
1166 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1168 if (handle == nullptr || val == nullptr) {
1169 LOGE("Invalid parameter");
1170 return NOTI_EX_ERROR_INVALID_PARAMETER;
1173 Geometry* p = static_cast<Geometry*>(handle);
1176 return NOTI_EX_ERROR_NONE;
1179 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1181 if (handle == nullptr || val == nullptr) {
1182 LOGE("Invalid parameter");
1183 return NOTI_EX_ERROR_INVALID_PARAMETER;
1186 Geometry* p = static_cast<Geometry*>(handle);
1187 *val = p->GetWidth();
1189 return NOTI_EX_ERROR_NONE;
1192 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1194 if (handle == nullptr || val == nullptr) {
1195 LOGE("Invalid parameter");
1196 return NOTI_EX_ERROR_INVALID_PARAMETER;
1199 Geometry* p = static_cast<Geometry*>(handle);
1200 *val = p->GetHeight();
1202 return NOTI_EX_ERROR_NONE;
1205 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1206 noti_ex_color_h color,
1207 noti_ex_padding_h padding,
1208 noti_ex_geometry_h geometry) {
1209 if (handle == nullptr) {
1210 LOGE("Invalid parameter");
1211 return NOTI_EX_ERROR_INVALID_PARAMETER;
1214 Color* color_ = static_cast<Color*>(color);
1215 Padding* padding_ = static_cast<Padding*>(padding);
1216 Geometry* geo_ = static_cast<Geometry*>(geometry);
1218 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1220 LOGE("Out-of-memory");
1221 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1226 return NOTI_EX_ERROR_NONE;
1229 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1230 if (handle == nullptr) {
1231 LOGE("Invalid parameter");
1232 return NOTI_EX_ERROR_INVALID_PARAMETER;
1235 Style* p = static_cast<Style*>(handle);
1238 return NOTI_EX_ERROR_NONE;
1241 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1242 noti_ex_padding_h *padding) {
1243 if (handle == nullptr || padding == nullptr) {
1244 LOGE("Invalid parameter");
1245 return NOTI_EX_ERROR_INVALID_PARAMETER;
1248 Style* p = static_cast<Style*>(handle);
1249 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1250 if (padding_ == nullptr) {
1251 LOGE("Out-of-memory");
1252 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1255 *padding = padding_;
1257 return NOTI_EX_ERROR_NONE;
1260 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1261 noti_ex_color_h *color) {
1262 if (handle == nullptr || color == nullptr) {
1263 LOGE("Invalid parameter");
1264 return NOTI_EX_ERROR_INVALID_PARAMETER;
1267 Style* p = static_cast<Style*>(handle);
1268 Color* color_ = new (std::nothrow) Color(p->GetColor());
1269 if (color_ == 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_geometry(noti_ex_style_h handle,
1280 noti_ex_geometry_h *geometry) {
1281 if (handle == nullptr || geometry == nullptr) {
1282 LOGE("Invalid parameter");
1283 return NOTI_EX_ERROR_INVALID_PARAMETER;
1286 Style* p = static_cast<Style*>(handle);
1287 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1288 if (geo_ == nullptr) {
1289 LOGE("Out-of-memory");
1290 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1295 return NOTI_EX_ERROR_NONE;
1298 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1299 noti_ex_color_h color) {
1300 if (handle == nullptr) {
1301 LOGE("Invalid parameter");
1302 return NOTI_EX_ERROR_INVALID_PARAMETER;
1305 Color* color_ = static_cast<Color*>(color);
1306 auto* p = new (std::nothrow) LEDInfo(*color_);
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_led_info_destroy(noti_ex_led_info_h handle) {
1318 if (handle == nullptr) {
1319 LOGE("Invalid parameter");
1320 return NOTI_EX_ERROR_INVALID_PARAMETER;
1323 LEDInfo* p = static_cast<LEDInfo*>(handle);
1326 return NOTI_EX_ERROR_NONE;
1329 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1330 noti_ex_led_info_h handle, int ms) {
1331 if (handle == nullptr) {
1332 LOGE("Invalid parameter");
1333 return NOTI_EX_ERROR_INVALID_PARAMETER;
1336 LEDInfo* p = static_cast<LEDInfo*>(handle);
1339 return NOTI_EX_ERROR_NONE;
1342 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1343 noti_ex_led_info_h handle, int *ms) {
1344 if (handle == nullptr || ms == nullptr) {
1345 LOGE("Invalid parameter");
1346 return NOTI_EX_ERROR_INVALID_PARAMETER;
1349 LEDInfo* p = static_cast<LEDInfo*>(handle);
1350 *ms = p->GetOnPeriod();
1352 return NOTI_EX_ERROR_NONE;
1355 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1356 noti_ex_led_info_h handle, int ms) {
1357 if (handle == nullptr) {
1358 LOGE("Invalid parameter");
1359 return NOTI_EX_ERROR_INVALID_PARAMETER;
1362 LEDInfo* p = static_cast<LEDInfo*>(handle);
1363 p->SetOffPeriod(ms);
1365 return NOTI_EX_ERROR_NONE;
1368 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1369 noti_ex_led_info_h handle, int *ms) {
1370 if (handle == nullptr) {
1371 LOGE("Invalid parameter");
1372 return NOTI_EX_ERROR_INVALID_PARAMETER;
1375 LEDInfo* p = static_cast<LEDInfo*>(handle);
1376 *ms = p->GetOffPeriod();
1378 return NOTI_EX_ERROR_NONE;
1381 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1382 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1383 if (handle == nullptr) {
1384 LOGE("Invalid parameter");
1385 return NOTI_EX_ERROR_INVALID_PARAMETER;
1388 LEDInfo* p = static_cast<LEDInfo*>(handle);
1389 Color* color_ = new (std::nothrow) Color(p->GetColor());
1390 if (color_ == nullptr) {
1391 LOGE("Out-of-memory");
1392 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1397 return NOTI_EX_ERROR_NONE;
1400 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1401 if (handle == nullptr) {
1402 LOGE("Invalid parameter");
1403 return NOTI_EX_ERROR_INVALID_PARAMETER;
1406 AbstractAction* p = static_cast<AbstractAction*>(handle);
1407 p->~AbstractAction();
1409 return NOTI_EX_ERROR_NONE;
1412 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1414 if (handle == nullptr || type == nullptr) {
1415 LOGE("Invalid parameter");
1416 return NOTI_EX_ERROR_INVALID_PARAMETER;
1419 AbstractAction* p = static_cast<AbstractAction*>(handle);
1420 *type = p->GetType();
1422 return NOTI_EX_ERROR_NONE;
1425 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1427 if (handle == nullptr || local == nullptr) {
1428 LOGE("Invalid parameter");
1429 return NOTI_EX_ERROR_INVALID_PARAMETER;
1432 AbstractAction* p = static_cast<AbstractAction*>(handle);
1433 *local = p->IsLocal();
1435 return NOTI_EX_ERROR_NONE;
1438 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1439 noti_ex_item_h item) {
1440 if (handle == nullptr || item == nullptr) {
1441 LOGE("Invalid parameter");
1442 return NOTI_EX_ERROR_INVALID_PARAMETER;
1444 AbstractAction* p = static_cast<AbstractAction*>(handle);
1445 Handle* ih = static_cast<Handle*>(item);
1446 p->Execute(ih->GetPtr());
1448 return NOTI_EX_ERROR_NONE;
1451 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1453 if (handle == nullptr || extra == nullptr) {
1454 LOGE("Invalid parameter");
1455 return NOTI_EX_ERROR_INVALID_PARAMETER;
1458 AbstractAction* p = static_cast<AbstractAction*>(handle);
1459 if (!p->GetExtra().empty()) {
1460 *extra = strdup(p->GetExtra().c_str());
1461 if (*extra == nullptr) {
1462 LOGE("Out-of-memory");
1463 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1467 return NOTI_EX_ERROR_NONE;
1470 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1471 noti_ex_item_info_h handle, int *hide_time) {
1472 if (handle == nullptr || hide_time == nullptr) {
1473 LOGE("Invalid parameter");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1476 IItemInfo* p = static_cast<IItemInfo*>(handle);
1477 *hide_time = p->GetHideTime();
1478 return NOTI_EX_ERROR_NONE;
1481 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1482 noti_ex_item_info_h handle, int hide_time) {
1483 if (handle == nullptr) {
1484 LOGE("Invalid parameter");
1485 return NOTI_EX_ERROR_INVALID_PARAMETER;
1487 IItemInfo* p = static_cast<IItemInfo*>(handle);
1488 p->SetHideTime(hide_time);
1489 return NOTI_EX_ERROR_NONE;
1492 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1493 noti_ex_item_info_h handle, int *delete_time) {
1494 if (handle == nullptr || delete_time == nullptr) {
1495 LOGE("Invalid parameter");
1496 return NOTI_EX_ERROR_INVALID_PARAMETER;
1498 IItemInfo* p = static_cast<IItemInfo*>(handle);
1499 *delete_time = p->GetDeleteTime();
1500 return NOTI_EX_ERROR_NONE;
1503 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1504 noti_ex_item_info_h handle, int delete_time) {
1505 if (handle == nullptr) {
1506 LOGE("Invalid parameter");
1507 return NOTI_EX_ERROR_INVALID_PARAMETER;
1509 IItemInfo* p = static_cast<IItemInfo*>(handle);
1510 p->SetDeleteTime(delete_time);
1511 return NOTI_EX_ERROR_NONE;
1514 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1515 noti_ex_item_info_h handle, time_t *time) {
1516 if (handle == nullptr || time == nullptr) {
1517 LOGE("Invalid parameter");
1518 return NOTI_EX_ERROR_INVALID_PARAMETER;
1521 IItemInfo* p = static_cast<IItemInfo*>(handle);
1522 *time = p->GetTime();
1523 return NOTI_EX_ERROR_NONE;
1526 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1527 if (handle == nullptr) {
1528 LOGE("Invalid parameter");
1529 return NOTI_EX_ERROR_INVALID_PARAMETER;
1532 Handle* h = static_cast<Handle*>(handle);
1534 return NOTI_EX_ERROR_NONE;
1537 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1538 const char *id, noti_ex_item_h *item) {
1539 if (handle == nullptr) {
1540 LOGE("Invalid parameter");
1541 return NOTI_EX_ERROR_INVALID_PARAMETER;
1544 Handle* p = static_cast<Handle*>(handle);
1545 AbstractItem& find_item = p->Get()->FindByID(string(id));
1546 *item = new Handle(&find_item);
1547 return NOTI_EX_ERROR_NONE;
1550 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1552 if (handle == nullptr || type == nullptr) {
1553 LOGE("Invalid parameter");
1554 return NOTI_EX_ERROR_INVALID_PARAMETER;
1557 Handle* h = static_cast<Handle*>(handle);
1558 AbstractItem* p = h->Get();
1559 *type = p->GetType();
1560 return NOTI_EX_ERROR_NONE;
1563 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1564 char ***path, int *count) {
1565 if (handle == nullptr || path == nullptr || count == nullptr) {
1566 LOGE("Invalid parameter");
1567 return NOTI_EX_ERROR_INVALID_PARAMETER;
1569 Handle* p = static_cast<Handle*>(handle);
1570 list<string> shared_path = p->Get()->GetSharedPath();
1571 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1573 for (auto& i : shared_path) {
1574 *path[idx++] = strdup(i.c_str());
1576 *count = shared_path.size();
1577 return NOTI_EX_ERROR_NONE;
1580 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1582 if (handle == nullptr || id == nullptr) {
1583 LOGE("Invalid parameter");
1584 return NOTI_EX_ERROR_INVALID_PARAMETER;
1586 Handle* h = static_cast<Handle*>(handle);
1587 AbstractItem* p = h->Get();
1588 *id = strdup(p->GetId().c_str());
1589 return NOTI_EX_ERROR_NONE;
1592 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1594 if (handle == nullptr || id == nullptr) {
1595 LOGE("Invalid parameter");
1596 return NOTI_EX_ERROR_INVALID_PARAMETER;
1598 Handle* p = static_cast<Handle*>(handle);
1599 p->Get()->SetId(id);
1600 return NOTI_EX_ERROR_NONE;
1603 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1604 noti_ex_action_h *action) {
1605 if (handle == nullptr || action == nullptr) {
1606 LOGE("Invalid parameter");
1607 return NOTI_EX_ERROR_INVALID_PARAMETER;
1609 Handle* p = static_cast<Handle*>(handle);
1610 if (p->Get()->GetAction() == nullptr) {
1612 return NOTI_EX_ERROR_NONE;
1614 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1616 return NOTI_EX_ERROR_NONE;
1619 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1620 noti_ex_action_h action) {
1621 if (handle == nullptr || action == nullptr) {
1622 LOGE("Invalid parameter");
1623 return NOTI_EX_ERROR_INVALID_PARAMETER;
1626 Handle* p = static_cast<Handle*>(handle);
1627 AbstractAction* a = static_cast<AbstractAction*>(action);
1628 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1629 return NOTI_EX_ERROR_NONE;
1632 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1633 noti_ex_style_h *style) {
1634 if (handle == nullptr || style == nullptr) {
1635 LOGE("Invalid parameter");
1636 return NOTI_EX_ERROR_INVALID_PARAMETER;
1639 Handle* p = static_cast<Handle*>(handle);
1640 shared_ptr<Style> s = p->Get()->GetStyle();
1641 *style = static_cast<noti_ex_style_h>(s.get());
1642 return NOTI_EX_ERROR_NONE;
1645 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1646 noti_ex_style_h style) {
1647 if (handle == nullptr || style == nullptr) {
1648 LOGE("Invalid parameter");
1649 return NOTI_EX_ERROR_INVALID_PARAMETER;
1652 Handle* p = static_cast<Handle*>(handle);
1653 Style* s = static_cast<Style*>(style);
1654 p->Get()->SetStyle(shared_ptr<Style>(s));
1655 return NOTI_EX_ERROR_NONE;
1658 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1660 if (handle == nullptr) {
1661 LOGE("Invalid parameter");
1662 return NOTI_EX_ERROR_INVALID_PARAMETER;
1665 Handle* p = static_cast<Handle*>(handle);
1666 p->Get()->SetVisible(visible);
1667 return NOTI_EX_ERROR_NONE;
1670 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1672 if (handle == nullptr || visible == nullptr) {
1673 LOGE("Invalid parameter");
1674 return NOTI_EX_ERROR_INVALID_PARAMETER;
1677 Handle* p = static_cast<Handle*>(handle);
1678 *visible = p->Get()->GetVisible();
1679 return NOTI_EX_ERROR_NONE;
1682 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1684 if (handle == nullptr) {
1685 LOGE("Invalid parameter");
1686 return NOTI_EX_ERROR_INVALID_PARAMETER;
1689 Handle* p = static_cast<Handle*>(handle);
1690 p->Get()->SetEnable(enable);
1691 return NOTI_EX_ERROR_NONE;
1694 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1696 if (handle == nullptr || enable == nullptr) {
1697 LOGE("Invalid parameter");
1698 return NOTI_EX_ERROR_INVALID_PARAMETER;
1701 Handle* p = static_cast<Handle*>(handle);
1702 *enable = p->Get()->GetEnable();
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1707 const char *receiver_group) {
1708 if (handle == nullptr || receiver_group == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 Handle* p = static_cast<Handle*>(handle);
1714 p->Get()->AddReceiver(receiver_group);
1715 return NOTI_EX_ERROR_NONE;
1718 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1719 const char *receiver_group) {
1720 if (handle == nullptr || receiver_group == nullptr) {
1721 LOGE("Invalid parameter");
1722 return NOTI_EX_ERROR_INVALID_PARAMETER;
1725 Handle* p = static_cast<Handle*>(handle);
1726 p->Get()->RemoveReceiver(receiver_group);
1727 return NOTI_EX_ERROR_NONE;
1730 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1731 char ***receiver_list, int *count) {
1732 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1733 LOGE("Invalid parameter");
1734 return NOTI_EX_ERROR_INVALID_PARAMETER;
1737 Handle* p = static_cast<Handle*>(handle);
1738 list<string> receivers = p->Get()->GetReceiverList();
1739 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1741 for (auto& i : receivers) {
1742 *receiver_list[idx++] = strdup(i.c_str());
1744 *count = receivers.size();
1745 return NOTI_EX_ERROR_NONE;
1748 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1750 if (handle == nullptr) {
1751 LOGE("Invalid parameter");
1752 return NOTI_EX_ERROR_INVALID_PARAMETER;
1755 Handle* p = static_cast<Handle*>(handle);
1756 p->Get()->SetPolicy(policy);
1757 return NOTI_EX_ERROR_NONE;
1760 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1762 if (handle == nullptr || policy == nullptr) {
1763 LOGE("Invalid parameter");
1764 return NOTI_EX_ERROR_INVALID_PARAMETER;
1767 Handle* p = static_cast<Handle*>(handle);
1768 *policy = p->Get()->GetPolicy();
1769 return NOTI_EX_ERROR_NONE;
1772 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1774 if (handle == nullptr || channel == nullptr) {
1775 LOGE("Invalid parameter");
1776 return NOTI_EX_ERROR_INVALID_PARAMETER;
1779 Handle* p = static_cast<Handle*>(handle);
1780 if (!p->Get()->GetChannel().empty())
1781 *channel = strdup(p->Get()->GetChannel().c_str());
1785 return NOTI_EX_ERROR_NONE;
1788 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1789 const char *channel) {
1790 if (handle == nullptr) {
1791 LOGE("Invalid parameter");
1792 return NOTI_EX_ERROR_INVALID_PARAMETER;
1795 Handle* p = static_cast<Handle*>(handle);
1796 p->Get()->SetChannel(channel);
1797 return NOTI_EX_ERROR_NONE;
1800 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1801 noti_ex_led_info_h led) {
1802 if (handle == nullptr) {
1803 LOGE("Invalid parameter");
1804 return NOTI_EX_ERROR_INVALID_PARAMETER;
1807 Handle* p = static_cast<Handle*>(handle);
1808 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1809 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1810 return NOTI_EX_ERROR_NONE;
1813 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1814 noti_ex_led_info_h *led) {
1815 if (handle == nullptr) {
1816 LOGE("Invalid parameter");
1817 return NOTI_EX_ERROR_INVALID_PARAMETER;
1820 Handle* p = static_cast<Handle*>(handle);
1821 if (p->Get()->GetLEDInfo() != nullptr)
1822 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1825 return NOTI_EX_ERROR_NONE;
1828 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1830 if (handle == nullptr) {
1831 LOGE("Invalid parameter");
1832 return NOTI_EX_ERROR_INVALID_PARAMETER;
1835 Handle* p = static_cast<Handle*>(handle);
1836 if (path == nullptr)
1837 p->Get()->SetSoundPath("");
1839 p->Get()->SetSoundPath(path);
1840 return NOTI_EX_ERROR_NONE;
1843 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1845 if (handle == nullptr) {
1846 LOGE("Invalid parameter");
1847 return NOTI_EX_ERROR_INVALID_PARAMETER;
1850 Handle* p = static_cast<Handle*>(handle);
1851 if (path == nullptr)
1852 p->Get()->SetVibrationPath("");
1854 p->Get()->SetVibrationPath(path);
1855 return NOTI_EX_ERROR_NONE;
1858 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1860 if (handle == nullptr || path == nullptr) {
1861 LOGE("Invalid parameter");
1862 return NOTI_EX_ERROR_INVALID_PARAMETER;
1865 Handle* p = static_cast<Handle*>(handle);
1866 if (p->Get()->GetSoundPath().empty())
1869 *path = strdup(p->Get()->GetSoundPath().c_str());
1870 return NOTI_EX_ERROR_NONE;
1873 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1875 if (handle == nullptr || path == nullptr) {
1876 LOGE("Invalid parameter");
1877 return NOTI_EX_ERROR_INVALID_PARAMETER;
1880 Handle* p = static_cast<Handle*>(handle);
1881 if (p->Get()->GetVibrationPath().empty())
1884 *path = strdup(p->Get()->GetVibrationPath().c_str());
1885 return NOTI_EX_ERROR_NONE;
1888 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1889 noti_ex_item_info_h *info) {
1890 if (handle == nullptr || info == nullptr) {
1891 LOGE("Invalid parameter");
1892 return NOTI_EX_ERROR_INVALID_PARAMETER;
1895 Handle* p = static_cast<Handle*>(handle);
1896 if (p->Get()->GetInfo() == nullptr)
1899 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1900 return NOTI_EX_ERROR_NONE;
1903 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1905 if (handle == nullptr || id == nullptr) {
1906 LOGE("Invalid parameter");
1907 return NOTI_EX_ERROR_INVALID_PARAMETER;
1910 Handle* p = static_cast<Handle*>(handle);
1911 if (p->Get()->GetSenderAppId().empty())
1914 *id = strdup(p->Get()->GetSenderAppId().c_str());
1915 return NOTI_EX_ERROR_NONE;
1918 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1920 if (handle == nullptr || tag == nullptr) {
1921 LOGE("Invalid parameter");
1922 return NOTI_EX_ERROR_INVALID_PARAMETER;
1925 Handle* p = static_cast<Handle*>(handle);
1926 if (p->Get()->GetTag().empty())
1929 *tag = strdup(p->Get()->GetTag().c_str());
1930 return NOTI_EX_ERROR_NONE;
1933 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1935 if (handle == nullptr) {
1936 LOGE("Invalid parameter");
1937 return NOTI_EX_ERROR_INVALID_PARAMETER;
1940 Handle* p = static_cast<Handle*>(handle);
1942 p->Get()->SetTag("");
1944 p->Get()->SetTag(tag);
1945 return NOTI_EX_ERROR_NONE;
1948 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1949 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1951 if (handle == nullptr) {
1952 LOGE("Invalid parameter");
1953 return NOTI_EX_ERROR_INVALID_PARAMETER;
1956 string receiver_group_str = "";
1958 receiver_group_str = string(receiver_group);
1960 ManagerStub* stub = new (std::nothrow) ManagerStub(
1961 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1962 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1963 receiver_group_str);
1964 if (stub == nullptr) {
1965 LOGE("Fail to create manager");
1966 return NOTI_EX_ERROR_IO_ERROR;
1968 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1969 new ManagerCallbackInfo(event_callbacks, data)));
1970 *handle = static_cast<noti_ex_manager_h>(stub);
1972 return NOTI_EX_ERROR_NONE;
1975 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1976 if (handle == nullptr) {
1977 LOGE("Invalid parameter");
1978 return NOTI_EX_ERROR_INVALID_PARAMETER;
1980 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1982 return NOTI_EX_ERROR_NONE;
1985 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1986 noti_ex_item_h **items, int *count) {
1987 if (handle == nullptr || items == nullptr || count == nullptr) {
1988 LOGE("Invalid parameter");
1989 return NOTI_EX_ERROR_INVALID_PARAMETER;
1993 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1994 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1995 if (item_list.size() == 0) {
1998 return NOTI_EX_ERROR_NONE;
2000 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2001 if (*items == nullptr) {
2002 LOGE("Fail to create items");
2003 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2007 for (auto& i : item_list) {
2008 *items[idx++] = new Handle(move(i));
2010 *count = item_list.size();
2011 } catch (Exception &ex) {
2012 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2013 return NOTI_EX_ERROR_IO_ERROR;
2015 return NOTI_EX_ERROR_NONE;
2018 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2019 noti_ex_item_h noti, int *request_id) {
2020 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2021 LOGE("Invalid parameter");
2022 return NOTI_EX_ERROR_INVALID_PARAMETER;
2025 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2026 Handle* sp = static_cast<Handle*>(noti);
2027 if (sp->GetPtr().get() == nullptr) {
2028 LOGE("Invalid noti reference can not be sended");
2029 return NOTI_EX_ERROR_INVALID_PARAMETER;
2031 *request_id = stub->Update(sp->GetPtr());
2033 } catch (Exception &ex) {
2034 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2035 return NOTI_EX_ERROR_IO_ERROR;
2037 return NOTI_EX_ERROR_NONE;
2040 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2041 noti_ex_item_h noti, int *request_id) {
2042 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2043 LOGE("Invalid parameter");
2044 return NOTI_EX_ERROR_INVALID_PARAMETER;
2047 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2048 Handle* item = static_cast<Handle*>(noti);
2049 if (item->GetPtr().get() == nullptr) {
2050 LOGE("Invalid noti reference can not be sended");
2051 return NOTI_EX_ERROR_INVALID_PARAMETER;
2053 *request_id = stub->Delete(item->GetPtr());
2055 } catch (Exception &ex) {
2056 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2057 return NOTI_EX_ERROR_IO_ERROR;
2059 return NOTI_EX_ERROR_NONE;
2062 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2064 if (handle == nullptr || request_id == nullptr) {
2065 LOGE("Invalid parameter");
2066 return NOTI_EX_ERROR_INVALID_PARAMETER;
2069 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2070 *request_id = stub->DeleteAll();
2071 } catch (Exception &ex) {
2072 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2073 return NOTI_EX_ERROR_IO_ERROR;
2075 return NOTI_EX_ERROR_NONE;
2078 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2079 noti_ex_item_h noti, int *request_id) {
2080 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2081 LOGE("Invalid parameter");
2082 return NOTI_EX_ERROR_INVALID_PARAMETER;
2085 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2086 Handle* item = static_cast<Handle*>(noti);
2087 if (item->GetPtr().get() == nullptr) {
2088 LOGE("Invalid noti reference can not be sended");
2089 return NOTI_EX_ERROR_INVALID_PARAMETER;
2091 *request_id = stub->Hide(item->GetPtr());
2093 } catch (Exception &ex) {
2094 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2095 return NOTI_EX_ERROR_IO_ERROR;
2097 return NOTI_EX_ERROR_NONE;
2100 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2101 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2102 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2103 LOGE("Invalid parameter");
2104 return NOTI_EX_ERROR_INVALID_PARAMETER;
2107 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2108 *item = new Handle(stub->FindByRootID(root_id));
2109 } catch (Exception &ex) {
2110 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2111 return NOTI_EX_ERROR_IO_ERROR;
2113 return NOTI_EX_ERROR_NONE;
2116 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2117 noti_ex_event_info_h info, noti_ex_error_e error) {
2118 if (handle == nullptr || info == nullptr) {
2119 LOGE("Invalid parameter");
2120 return NOTI_EX_ERROR_INVALID_PARAMETER;
2123 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2124 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2125 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2126 static_cast<NotificationError>(error));
2127 } catch (Exception &ex) {
2128 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2129 return NOTI_EX_ERROR_IO_ERROR;
2131 return NOTI_EX_ERROR_NONE;
2134 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2135 noti_ex_manager_h handle, int *cnt) {
2137 if (handle == nullptr || cnt == nullptr) {
2138 LOGE("Invalid parameter");
2139 return NOTI_EX_ERROR_INVALID_PARAMETER;
2142 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2143 *cnt = stub->GetCount();
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_item_progress_create(noti_ex_item_h *handle,
2152 const char *id, float min, float current, float max) {
2155 if (handle == nullptr) {
2156 LOGE("Invalid parameter");
2157 return NOTI_EX_ERROR_INVALID_PARAMETER;
2161 p = new (std::nothrow) ProgressItem(id, min, current, max);
2163 p = new (std::nothrow) ProgressItem(min, current, max);
2166 LOGE("Out-of-memory");
2167 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2170 *handle = new Handle(shared_ptr<AbstractItem>(p));
2172 return NOTI_EX_ERROR_NONE;
2175 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2176 noti_ex_item_h handle, float *current) {
2177 if (handle == nullptr || current == nullptr) {
2178 LOGE("Invalid parameter");
2179 return NOTI_EX_ERROR_INVALID_PARAMETER;
2182 Handle *h = static_cast<Handle*>(handle);
2183 if (!h->IsValidType(AbstractItem::Progress)) {
2184 LOGE("Invalid handle type");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2187 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2188 *current = p->GetCurrent();
2190 return NOTI_EX_ERROR_NONE;
2193 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2194 noti_ex_item_h handle, float current) {
2195 if (handle == nullptr) {
2196 LOGE("Invalid parameter");
2197 return NOTI_EX_ERROR_INVALID_PARAMETER;
2200 Handle *h = static_cast<Handle*>(handle);
2201 if (!h->IsValidType(AbstractItem::Progress)) {
2202 LOGE("Invalid handle type");
2203 return NOTI_EX_ERROR_INVALID_PARAMETER;
2205 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2206 p->SetCurrent(current);
2208 return NOTI_EX_ERROR_NONE;
2211 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2213 if (handle == nullptr || min == nullptr) {
2214 LOGE("Invalid parameter");
2215 return NOTI_EX_ERROR_INVALID_PARAMETER;
2218 Handle *h = static_cast<Handle*>(handle);
2219 if (!h->IsValidType(AbstractItem::Progress)) {
2220 LOGE("Invalid handle type");
2221 return NOTI_EX_ERROR_INVALID_PARAMETER;
2223 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2226 return NOTI_EX_ERROR_NONE;
2229 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2231 if (handle == nullptr || max == nullptr) {
2232 LOGE("Invalid parameter");
2233 return NOTI_EX_ERROR_INVALID_PARAMETER;
2236 Handle *h = static_cast<Handle*>(handle);
2237 if (!h->IsValidType(AbstractItem::Progress)) {
2238 LOGE("Invalid handle type");
2239 return NOTI_EX_ERROR_INVALID_PARAMETER;
2241 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2244 return NOTI_EX_ERROR_NONE;
2247 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2248 noti_ex_reporter_events_s event_callbacks, void *data) {
2249 if (handle == nullptr) {
2250 LOGE("Invalid parameter");
2251 return NOTI_EX_ERROR_INVALID_PARAMETER;
2254 ReporterStub* stub = new (std::nothrow) ReporterStub(
2255 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2256 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2257 if (stub == nullptr) {
2258 LOGE("Fail to create manager");
2259 return NOTI_EX_ERROR_IO_ERROR;
2261 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2262 new ReporterCallbackInfo(event_callbacks, data)));
2264 *handle = static_cast<noti_ex_reporter_h>(stub);
2266 return NOTI_EX_ERROR_NONE;
2269 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2270 if (handle == nullptr) {
2271 LOGE("Invalid parameter");
2272 return NOTI_EX_ERROR_INVALID_PARAMETER;
2274 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2276 return NOTI_EX_ERROR_NONE;
2279 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2280 noti_ex_event_info_h info, noti_ex_error_e error) {
2281 if (handle == nullptr || info == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2286 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2287 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2288 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2289 static_cast<NotificationError>(error));
2290 } catch (Exception &ex) {
2291 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2292 return NOTI_EX_ERROR_IO_ERROR;
2294 return NOTI_EX_ERROR_NONE;
2297 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2298 noti_ex_item_h noti, int *request_id) {
2299 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2300 LOGE("Invalid parameter");
2301 return NOTI_EX_ERROR_INVALID_PARAMETER;
2304 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2305 Handle* h = static_cast<Handle*>(noti);
2306 if (h->GetPtr().get() == nullptr) {
2307 LOGE("Invalid noti reference can not be sended");
2308 return NOTI_EX_ERROR_INVALID_PARAMETER;
2310 *request_id = stub->Post(h->GetPtr());
2312 } catch (Exception &ex) {
2313 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2314 return NOTI_EX_ERROR_IO_ERROR;
2316 return NOTI_EX_ERROR_NONE;
2319 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2320 noti_ex_item_h *noti_list, int count, int *request_id) {
2322 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2323 LOGE("Invalid parameter");
2324 return NOTI_EX_ERROR_INVALID_PARAMETER;
2327 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2328 list<shared_ptr<item::AbstractItem>> notiList;
2329 for (int i = 0; i < count; i++) {
2330 Handle* item = static_cast<Handle*>(noti_list[i]);
2331 notiList.push_back(item->GetPtr());
2333 *request_id = stub->Post(notiList);
2334 } catch (Exception &ex) {
2335 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2336 return NOTI_EX_ERROR_IO_ERROR;
2338 return NOTI_EX_ERROR_NONE;
2341 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2342 noti_ex_item_h noti, int *request_id) {
2343 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2344 LOGE("Invalid parameter");
2345 return NOTI_EX_ERROR_INVALID_PARAMETER;
2348 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2349 Handle* item = static_cast<Handle*>(noti);
2350 if (item->GetPtr().get() == nullptr) {
2351 LOGE("Invalid noti reference can not be sended");
2352 return NOTI_EX_ERROR_INVALID_PARAMETER;
2354 *request_id = stub->Update(item->GetPtr());
2356 } catch (Exception &ex) {
2357 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2358 return NOTI_EX_ERROR_IO_ERROR;
2360 return NOTI_EX_ERROR_NONE;
2363 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2364 noti_ex_item_h noti, int *request_id) {
2365 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2366 LOGE("Invalid parameter");
2367 return NOTI_EX_ERROR_INVALID_PARAMETER;
2370 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2371 Handle* item = static_cast<Handle*>(noti);
2372 if (item->GetPtr().get() == nullptr) {
2373 LOGE("Invalid noti reference can not be sended");
2374 return NOTI_EX_ERROR_INVALID_PARAMETER;
2376 *request_id = stub->Delete(item->GetPtr());
2378 } catch (Exception &ex) {
2379 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2380 return NOTI_EX_ERROR_IO_ERROR;
2382 return NOTI_EX_ERROR_NONE;
2385 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2386 noti_ex_reporter_h handle, int *request_id) {
2387 if (handle == nullptr || request_id == nullptr) {
2388 LOGE("Invalid parameter");
2389 return NOTI_EX_ERROR_INVALID_PARAMETER;
2392 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2393 *request_id = stub->DeleteAll();
2394 } catch (Exception &ex) {
2395 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2396 return NOTI_EX_ERROR_IO_ERROR;
2398 return NOTI_EX_ERROR_NONE;
2401 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2402 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2403 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2404 LOGE("Invalid parameter");
2405 return NOTI_EX_ERROR_INVALID_PARAMETER;
2408 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2409 *item = new Handle(stub->FindByRootID(root_id));
2410 } catch (Exception &ex) {
2411 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2412 return NOTI_EX_ERROR_IO_ERROR;
2414 return NOTI_EX_ERROR_NONE;
2417 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2418 const char *id, const char *text, const char *hyperlink) {
2419 if (handle == nullptr || text == nullptr) {
2420 LOGE("Invalid parameter");
2421 return NOTI_EX_ERROR_INVALID_PARAMETER;
2427 p = new (std::nothrow) TextItem(id, std::string(text),
2428 std::string(hyperlink));
2430 p = new (std::nothrow) TextItem(id, std::string(text));
2433 LOGE("Out-of-memory");
2434 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2437 *handle = new Handle(shared_ptr<AbstractItem>(p));
2439 return NOTI_EX_ERROR_NONE;
2442 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2443 const char *contents) {
2444 if (handle == nullptr || contents == nullptr) {
2445 LOGE("Invalid parameter");
2446 return NOTI_EX_ERROR_INVALID_PARAMETER;
2449 Handle* p = static_cast<Handle*>(handle);
2450 if (!p->IsValidType(AbstractItem::Text)) {
2451 LOGE("Invalid handle type");
2452 return NOTI_EX_ERROR_INVALID_PARAMETER;
2454 TextItem* ti = static_cast<TextItem*>(p->Get());
2455 ti->SetContents(std::string(contents));
2457 return NOTI_EX_ERROR_NONE;
2460 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2462 if (handle == nullptr || contents == nullptr) {
2463 LOGE("Invalid parameter");
2464 return NOTI_EX_ERROR_INVALID_PARAMETER;
2467 Handle* p = static_cast<Handle*>(handle);
2468 if (!p->IsValidType(AbstractItem::Text)) {
2469 LOGE("Invalid handle type");
2470 return NOTI_EX_ERROR_INVALID_PARAMETER;
2472 TextItem* ti = static_cast<TextItem*>(p->Get());
2473 if (!ti->GetContents().empty()) {
2474 *contents = strdup(ti->GetContents().c_str());
2475 if (*contents == nullptr) {
2476 LOGE("Out-of-memory");
2477 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2481 return NOTI_EX_ERROR_NONE;
2484 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2485 noti_ex_item_h handle, char **hyper_link) {
2486 if (handle == nullptr || hyper_link == nullptr) {
2487 LOGE("Invalid parameter");
2488 return NOTI_EX_ERROR_INVALID_PARAMETER;
2491 Handle* p = static_cast<Handle*>(handle);
2492 if (!p->IsValidType(AbstractItem::Text)) {
2493 LOGE("Invalid handle type");
2494 return NOTI_EX_ERROR_INVALID_PARAMETER;
2496 TextItem* ti = static_cast<TextItem*>(p->Get());
2497 if (!ti->GetHyperLink().empty()) {
2498 *hyper_link = strdup(ti->GetHyperLink().c_str());
2499 if (*hyper_link == nullptr) {
2500 LOGE("Out-of-memory");
2501 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2505 return NOTI_EX_ERROR_NONE;
2508 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2509 const char *id, time_t time) {
2512 if (handle == nullptr) {
2513 LOGE("Invalid parameter");
2514 return NOTI_EX_ERROR_INVALID_PARAMETER;
2519 p = new (std::nothrow) TimeItem(id, time);
2521 p = new (std::nothrow) TimeItem(time);
2523 p = new (std::nothrow) TimeItem();
2527 LOGE("Out-of-memory");
2528 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2531 *handle = new Handle(shared_ptr<AbstractItem>(p));
2533 return NOTI_EX_ERROR_NONE;
2536 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2538 if (handle == nullptr || time == nullptr) {
2539 LOGE("Invalid parameter");
2540 return NOTI_EX_ERROR_INVALID_PARAMETER;
2542 Handle* h = static_cast<Handle*>(handle);
2543 if (!h->IsValidType(AbstractItem::Time)) {
2544 LOGE("Invalid handle type");
2545 return NOTI_EX_ERROR_INVALID_PARAMETER;
2547 TimeItem* p = static_cast<TimeItem*>(h->Get());
2548 *time = p->GetTime();
2550 return NOTI_EX_ERROR_NONE;
2553 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2554 noti_ex_action_h *handle, const char *extra) {
2555 if (handle == nullptr) {
2556 LOGE("Invalid parameter");
2557 return NOTI_EX_ERROR_INVALID_PARAMETER;
2560 string extra_str = "";
2562 extra_str = string(extra);
2564 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2566 LOGE("Out-of-memory");
2567 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2572 return NOTI_EX_ERROR_NONE;
2575 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2576 const char *id, bool visible) {
2577 if (handle == nullptr || id == nullptr) {
2578 LOGE("Invalid parameter");
2579 return NOTI_EX_ERROR_INVALID_PARAMETER;
2582 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2583 p->SetVisibility(id, visible);
2585 return NOTI_EX_ERROR_NONE;