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 noti_ex_item_h* added_item =
115 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
116 if (added_item == nullptr) {
117 LOGE("Out of memory");
122 for (auto& i : addedItem) {
124 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
127 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
128 cb_.added(static_cast<noti_ex_manager_h>(manager),
129 static_cast<noti_ex_event_info_h>(c_info), added_item,
130 addedItem.size(), user_data_);
134 void InvokeUpdated(Manager* manager, const IEventInfo& info,
135 shared_ptr<item::AbstractItem> updatedItem) {
136 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
137 cb_.updated(static_cast<noti_ex_manager_h>(manager),
138 static_cast<noti_ex_event_info_h>(c_info),
139 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
142 void InvokeDeleted(Manager* manager, const IEventInfo& info,
143 shared_ptr<item::AbstractItem> deletedItem) {
144 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
145 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
146 static_cast<noti_ex_event_info_h>(c_info),
147 static_cast<noti_ex_item_h>(
148 new Handle(deletedItem)), user_data_);
151 void InvokeError(Manager* manager, NotificationError error, int requestId) {
152 cb_.error(static_cast<noti_ex_manager_h>(manager),
153 static_cast<noti_ex_error_e>(error), requestId, user_data_);
157 noti_ex_manager_events_s cb_;
161 class ManagerStub : public Manager {
163 ManagerStub(std::unique_ptr<IEventSender> sender,
164 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
165 : Manager(move(sender), move(listener), receiver_group) {
168 void OnAdd(const IEventInfo& info,
169 list<shared_ptr<AbstractItem>> addedItem) override {
170 cb_->InvokeAdded(this, info, addedItem);
173 void OnUpdate(const IEventInfo& info,
174 std::shared_ptr<item::AbstractItem> updatedItem) override {
175 cb_->InvokeUpdated(this, info, updatedItem);
178 void OnDelete(const IEventInfo& info,
179 shared_ptr<item::AbstractItem> deletedItem) override {
180 cb_->InvokeDeleted(this, info, deletedItem);
183 void OnError(NotificationError error, int requestId) override {
184 cb_->InvokeError(this, error, requestId);
187 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
189 return NOTI_EX_ERROR_NONE;
192 int ClearManagerCallbackInfo() {
194 return NOTI_EX_ERROR_NONE;
198 unique_ptr<ManagerCallbackInfo> cb_;
202 class ReporterCallbackInfo {
204 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
205 : user_data_(user_data) {
206 cb_.event = cb.event;
207 cb_.error = cb.error;
210 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
211 list<shared_ptr<AbstractItem>> notiList) {
212 noti_ex_item_h* noti_list =
213 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
214 if (noti_list == nullptr) {
215 LOGE("Out of memory");
220 for (auto& i : notiList) {
222 static_cast<noti_ex_item_h>(new Handle(i));
225 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
226 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
227 static_cast<noti_ex_event_info_h>(c_info), noti_list,
228 notiList.size(), user_data_);
232 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
233 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
234 static_cast<noti_ex_error_e>(error), requestId, user_data_);
238 noti_ex_reporter_events_s cb_;
242 class ReporterStub : public Reporter {
244 ReporterStub(std::unique_ptr<IEventSender> sender,
245 std::unique_ptr<IEventListener> listener)
246 : Reporter(move(sender), move(listener)) {
249 void OnEvent(const IEventInfo& info,
250 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
251 cb_->InvokeEvent(this, info, notiList);
254 void OnError(NotificationError error, int requestId) override {
255 cb_->InvokeError(this, error, requestId);
258 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
260 return NOTI_EX_ERROR_NONE;
263 int ClearReporterCallbackInfo() {
265 return NOTI_EX_ERROR_NONE;
269 unique_ptr<ReporterCallbackInfo> cb_;
274 extern "C" EXPORT_API int noti_ex_action_app_control_create(
275 noti_ex_action_h *handle, app_control_h app_control,
277 if (handle == nullptr || app_control == nullptr) {
278 LOGE("Invalid parameter");
279 return NOTI_EX_ERROR_INVALID_PARAMETER;
285 p = new (std::nothrow) AppControlAction(app_control, extra);
287 p = new (std::nothrow) AppControlAction(app_control);
290 LOGE("Out-of-memory");
291 return NOTI_EX_ERROR_OUT_OF_MEMORY;
296 return NOTI_EX_ERROR_NONE;
299 extern "C" EXPORT_API int noti_ex_action_app_control_set(
300 noti_ex_action_h handle, app_control_h app_control) {
301 if (handle == nullptr || app_control == nullptr) {
302 LOGE("Invalid parameter");
303 return NOTI_EX_ERROR_INVALID_PARAMETER;
306 AppControlAction* p = static_cast<AppControlAction*>(handle);
307 p->SetAppControl(app_control);
309 return NOTI_EX_ERROR_NONE;
312 extern "C" EXPORT_API int noti_ex_action_app_control_get(
313 noti_ex_action_h handle, app_control_h *app_control) {
314 if (handle == nullptr || app_control == nullptr) {
315 LOGE("Invalid parameter");
316 return NOTI_EX_ERROR_INVALID_PARAMETER;
319 AppControlAction* p = static_cast<AppControlAction*>(handle);
320 *app_control = p->GetAppControl();
322 return NOTI_EX_ERROR_NONE;
325 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
326 const char *id, const char *title) {
329 if (handle == nullptr || title == nullptr) {
330 LOGE("Invalid parameter");
331 return NOTI_EX_ERROR_INVALID_PARAMETER;
335 p = new (std::nothrow) ButtonItem(id, title);
337 p = new (std::nothrow) ButtonItem(title);
340 LOGE("Out-of-memory");
341 return NOTI_EX_ERROR_OUT_OF_MEMORY;
343 *handle = new Handle(shared_ptr<AbstractItem>(p));
345 return NOTI_EX_ERROR_NONE;
348 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
350 if (handle == nullptr || title == nullptr) {
351 LOGE("Invalid parameter");
352 return NOTI_EX_ERROR_INVALID_PARAMETER;
355 Handle* sp = static_cast<Handle*>(handle);
356 if (!sp->IsValidType(AbstractItem::Button)) {
357 LOGE("Invalid handle type");
358 return NOTI_EX_ERROR_INVALID_PARAMETER;
360 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
361 if (!p->GetTitle().empty()) {
362 *title = strdup(p->GetTitle().c_str());
363 if (*title == nullptr) {
364 LOGE("Out-of-memory");
365 return NOTI_EX_ERROR_OUT_OF_MEMORY;
369 return NOTI_EX_ERROR_NONE;
372 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
373 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
374 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
375 noti_ex_item_chat_message_type_e message_type) {
376 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
377 LOGE("Invalid parameter");
378 return NOTI_EX_ERROR_INVALID_PARAMETER;
381 auto* p = new (std::nothrow) ChatMessageItem(id,
382 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
383 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
384 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
385 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
386 static_cast<ChatMessageItem::Type>(message_type));
388 LOGE("Out-of-memory");
389 return NOTI_EX_ERROR_OUT_OF_MEMORY;
392 *handle = new Handle(shared_ptr<AbstractItem>(p));
394 return NOTI_EX_ERROR_NONE;
397 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
398 noti_ex_item_h handle, noti_ex_item_h *name) {
399 if (handle == nullptr || name == nullptr) {
400 LOGE("Invalid parameter");
401 return NOTI_EX_ERROR_INVALID_PARAMETER;
403 Handle* h = static_cast<Handle*>(handle);
404 if (!h->IsValidType(AbstractItem::ChatMessage)) {
405 LOGE("Invalid handle type");
406 return NOTI_EX_ERROR_INVALID_PARAMETER;
408 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
409 *name = new Handle(&(p->GetNameItem()));
411 return NOTI_EX_ERROR_NONE;
414 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
415 noti_ex_item_h handle, noti_ex_item_h *text) {
416 if (handle == nullptr || text == nullptr) {
417 LOGE("Invalid parameter");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
421 Handle* h = static_cast<Handle*>(handle);
422 if (!h->IsValidType(AbstractItem::ChatMessage)) {
423 LOGE("Invalid handle type");
424 return NOTI_EX_ERROR_INVALID_PARAMETER;
426 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
427 *text = new Handle(&(p->GetTextItem()));
429 return NOTI_EX_ERROR_NONE;
432 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
433 noti_ex_item_h handle, noti_ex_item_h *image) {
434 if (handle == nullptr || image == nullptr) {
435 LOGE("Invalid parameter");
436 return NOTI_EX_ERROR_INVALID_PARAMETER;
439 Handle* h = static_cast<Handle*>(handle);
440 if (!h->IsValidType(AbstractItem::ChatMessage)) {
441 LOGE("Invalid handle type");
442 return NOTI_EX_ERROR_INVALID_PARAMETER;
444 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
445 *image = new Handle(&(p->GetImageItem()));
447 return NOTI_EX_ERROR_NONE;
450 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
451 noti_ex_item_h handle, noti_ex_item_h *time) {
452 if (handle == nullptr || time == nullptr) {
453 LOGE("Invalid parameter");
454 return NOTI_EX_ERROR_INVALID_PARAMETER;
457 Handle* h = static_cast<Handle*>(handle);
458 if (!h->IsValidType(AbstractItem::ChatMessage)) {
459 LOGE("Invalid handle type");
460 return NOTI_EX_ERROR_INVALID_PARAMETER;
462 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
463 *time = new Handle(&(p->GetTimeItem()));
465 return NOTI_EX_ERROR_NONE;
468 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
469 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
470 if (handle == nullptr || message_type == nullptr) {
471 LOGE("Invalid parameter");
472 return NOTI_EX_ERROR_INVALID_PARAMETER;
475 Handle* h = static_cast<Handle*>(handle);
476 if (!h->IsValidType(AbstractItem::ChatMessage)) {
477 LOGE("Invalid handle type");
478 return NOTI_EX_ERROR_INVALID_PARAMETER;
480 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
481 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
483 return NOTI_EX_ERROR_NONE;
486 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
487 const char *id, const char *title, bool checked) {
490 if (handle == nullptr || title == nullptr) {
491 LOGE("Invalid parameter");
492 return NOTI_EX_ERROR_INVALID_PARAMETER;
495 p = new (std::nothrow) CheckBoxItem(id, title, checked);
497 LOGE("Out-of-memory");
498 return NOTI_EX_ERROR_OUT_OF_MEMORY;
501 *handle = new Handle(p);
503 return NOTI_EX_ERROR_NONE;
506 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
508 if (handle == nullptr || title == nullptr) {
509 LOGE("Invalid parameter");
510 return NOTI_EX_ERROR_INVALID_PARAMETER;
512 Handle* h = static_cast<Handle*>(handle);
513 if (!h->IsValidType(AbstractItem::CheckBox)) {
514 LOGE("Invalid handle type");
515 return NOTI_EX_ERROR_INVALID_PARAMETER;
517 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
518 if (!p->GetTitle().empty()) {
519 *title = strdup(p->GetTitle().c_str());
520 if (*title == nullptr) {
521 LOGE("Out-of-memory");
522 return NOTI_EX_ERROR_OUT_OF_MEMORY;
526 return NOTI_EX_ERROR_NONE;
529 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
531 if (handle == nullptr || checked == nullptr) {
532 LOGE("Invalid parameter");
533 return NOTI_EX_ERROR_INVALID_PARAMETER;
535 Handle* h = static_cast<Handle*>(handle);
536 if (!h->IsValidType(AbstractItem::CheckBox)) {
537 LOGE("Invalid handle type");
538 return NOTI_EX_ERROR_INVALID_PARAMETER;
540 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
541 *checked = p->IsChecked();
543 return NOTI_EX_ERROR_NONE;
546 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
550 if (handle == nullptr) {
551 LOGE("Invalid parameter");
552 return NOTI_EX_ERROR_INVALID_PARAMETER;
555 p = new (std::nothrow) EntryItem(id);
557 LOGE("Out-of-memory");
558 return NOTI_EX_ERROR_OUT_OF_MEMORY;
561 *handle = new Handle(p);
563 return NOTI_EX_ERROR_NONE;
566 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
568 if (handle == nullptr || text == nullptr) {
569 LOGE("Invalid parameter");
570 return NOTI_EX_ERROR_INVALID_PARAMETER;
573 Handle* h = static_cast<Handle*>(handle);
574 if (!h->IsValidType(AbstractItem::Entry)) {
575 LOGE("Invalid handle type");
576 return NOTI_EX_ERROR_INVALID_PARAMETER;
578 EntryItem* p = static_cast<EntryItem*>(h->Get());
579 if (!p->GetText().empty()) {
580 *text = strdup(p->GetText().c_str());
581 if (*text == nullptr) {
582 LOGE("Out-of-memory");
583 return NOTI_EX_ERROR_OUT_OF_MEMORY;
587 return NOTI_EX_ERROR_NONE;
590 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
592 if (handle == nullptr || text == nullptr) {
593 LOGE("Invalid parameter");
594 return NOTI_EX_ERROR_INVALID_PARAMETER;
596 Handle* h = static_cast<Handle*>(handle);
597 if (!h->IsValidType(AbstractItem::Entry)) {
598 LOGE("Invalid handle type");
599 return NOTI_EX_ERROR_INVALID_PARAMETER;
601 EntryItem* p = static_cast<EntryItem*>(h->Get());
602 p->SetText(std::string(text));
604 return NOTI_EX_ERROR_NONE;
607 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
608 noti_ex_event_info_h* cloned_handle) {
609 if (handle == nullptr || cloned_handle == nullptr) {
610 LOGE("Invalid parameter");
611 return NOTI_EX_ERROR_INVALID_PARAMETER;
614 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
615 EventInfo* info = new EventInfo(cloned);
616 *cloned_handle = info;
617 return NOTI_EX_ERROR_NONE;
620 extern "C" EXPORT_API int noti_ex_event_info_destroy(
621 noti_ex_event_info_h handle) {
622 if (handle == nullptr) {
623 LOGE("Invalid parameter");
624 return NOTI_EX_ERROR_INVALID_PARAMETER;
626 EventInfo* info = static_cast<EventInfo*>(handle);
628 return NOTI_EX_ERROR_NONE;
631 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
632 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
633 if (handle == nullptr || event_type == nullptr) {
634 LOGE("Invalid parameter");
635 return NOTI_EX_ERROR_INVALID_PARAMETER;
637 EventInfo* info = static_cast<EventInfo*>(handle);
638 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
640 return NOTI_EX_ERROR_NONE;
643 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
644 noti_ex_event_info_h handle, char **owner) {
645 if (handle == nullptr || owner == nullptr) {
646 LOGE("Invalid parameter");
647 return NOTI_EX_ERROR_INVALID_PARAMETER;
649 EventInfo* info = static_cast<EventInfo*>(handle);
650 *owner = strdup(info->GetOwner().c_str());
651 return NOTI_EX_ERROR_NONE;
654 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
655 noti_ex_event_info_h handle, char **channel) {
656 if (handle == nullptr || channel == nullptr) {
657 LOGE("Invalid parameter");
658 return NOTI_EX_ERROR_INVALID_PARAMETER;
660 EventInfo* info = static_cast<EventInfo*>(handle);
661 *channel = strdup(info->GetChannel().c_str());
662 return NOTI_EX_ERROR_NONE;
665 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
666 noti_ex_event_info_h handle, char **item_id) {
667 if (handle == nullptr || item_id == nullptr) {
668 LOGE("Invalid parameter");
669 return NOTI_EX_ERROR_INVALID_PARAMETER;
671 EventInfo* info = static_cast<EventInfo*>(handle);
672 *item_id = strdup(info->GetItemId().c_str());
673 return NOTI_EX_ERROR_NONE;
676 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
677 noti_ex_event_info_h handle, int *req_id) {
678 if (handle == nullptr || req_id == nullptr) {
679 LOGE("Invalid parameter");
680 return NOTI_EX_ERROR_INVALID_PARAMETER;
682 EventInfo* info = static_cast<EventInfo*>(handle);
683 *req_id = info->GetRequestId();
684 return NOTI_EX_ERROR_NONE;
687 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
691 if (handle == nullptr) {
692 LOGE("Invalid parameter");
693 return NOTI_EX_ERROR_INVALID_PARAMETER;
697 p = new (std::nothrow) GroupItem(id);
699 p = new (std::nothrow) GroupItem();
702 LOGE("Out-of-memory");
703 return NOTI_EX_ERROR_OUT_OF_MEMORY;
706 *handle = new Handle(shared_ptr<AbstractItem>(p));
708 return NOTI_EX_ERROR_NONE;
711 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
713 if (handle == nullptr) {
714 LOGE("Invalid parameter");
715 return NOTI_EX_ERROR_INVALID_PARAMETER;
717 Handle* h = static_cast<Handle*>(handle);
718 if (!h->IsValidType(AbstractItem::Group)) {
719 LOGE("Invalid handle type");
720 return NOTI_EX_ERROR_INVALID_PARAMETER;
722 GroupItem* p = static_cast<GroupItem*>(h->Get());
723 p->SetDirection(vertical);
725 return NOTI_EX_ERROR_NONE;
728 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
730 if (handle == nullptr) {
731 LOGE("Invalid parameter");
732 return NOTI_EX_ERROR_INVALID_PARAMETER;
734 Handle* h = static_cast<Handle*>(handle);
735 if (!h->IsValidType(AbstractItem::Group)) {
736 LOGE("Invalid handle type");
737 return NOTI_EX_ERROR_INVALID_PARAMETER;
739 GroupItem* p = static_cast<GroupItem*>(h->Get());
740 *vertical = p->IsVertical();
742 return NOTI_EX_ERROR_NONE;
745 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
747 if (handle == nullptr) {
748 LOGE("Invalid parameter");
749 return NOTI_EX_ERROR_INVALID_PARAMETER;
751 Handle* h = static_cast<Handle*>(handle);
752 if (!h->IsValidType(AbstractItem::Group)) {
753 LOGE("Invalid handle type");
754 return NOTI_EX_ERROR_INVALID_PARAMETER;
756 GroupItem* p = static_cast<GroupItem*>(h->Get());
757 if (!p->GetAppLabel().empty()) {
758 *label = strdup(p->GetAppLabel().c_str());
759 if (*label == nullptr) {
760 LOGE("Out-of-memory");
761 return NOTI_EX_ERROR_OUT_OF_MEMORY;
765 return NOTI_EX_ERROR_NONE;
768 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
769 noti_ex_item_h child) {
770 if (handle == nullptr || child == nullptr) {
771 LOGE("Invalid parameter");
772 return NOTI_EX_ERROR_INVALID_PARAMETER;
774 Handle* h = static_cast<Handle*>(handle);
775 if (!h->IsValidType(AbstractItem::Group)) {
776 LOGE("Invalid handle type");
777 return NOTI_EX_ERROR_INVALID_PARAMETER;
779 auto p = static_cast<GroupItem*>(h->Get());
780 p->AddChild((static_cast<Handle*>(child))->GetPtr());
782 return NOTI_EX_ERROR_NONE;
785 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
786 const char *item_id) {
787 if (handle == nullptr || item_id == nullptr) {
788 LOGE("Invalid parameter");
789 return NOTI_EX_ERROR_INVALID_PARAMETER;
791 Handle* h = static_cast<Handle*>(handle);
792 if (!h->IsValidType(AbstractItem::Group)) {
793 LOGE("Invalid handle type");
794 return NOTI_EX_ERROR_INVALID_PARAMETER;
796 GroupItem* p = static_cast<GroupItem*>(h->Get());
797 p->RemoveChild(std::string(item_id));
799 return NOTI_EX_ERROR_NONE;
802 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
803 noti_ex_item_group_foreach_child_cb callback, void *data) {
804 if (handle == nullptr || callback == nullptr) {
805 LOGE("Invalid parameter");
806 return NOTI_EX_ERROR_INVALID_PARAMETER;
809 Handle* h = static_cast<Handle*>(handle);
810 if (!h->IsValidType(AbstractItem::Group)) {
811 LOGE("Invalid handle type");
812 return NOTI_EX_ERROR_INVALID_PARAMETER;
814 GroupItem* p = static_cast<GroupItem*>(h->Get());
815 list<shared_ptr<AbstractItem>> children = p->GetChildren();
816 LOGI("Retrive (%zd)", children.size());
817 for (auto i : children) {
819 static_cast<noti_ex_item_h>(new Handle(i)), data);
820 if (ret != NOTI_EX_ERROR_NONE) {
821 LOGW("callback return (%d) stop foreach", ret);
826 return NOTI_EX_ERROR_NONE;
829 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
830 const char *id, const char *image_path) {
833 if (handle == nullptr || image_path == nullptr) {
834 LOGE("Invalid parameter");
835 return NOTI_EX_ERROR_INVALID_PARAMETER;
839 p = new (std::nothrow) ImageItem(id, image_path);
841 p = new (std::nothrow) ImageItem(image_path);
844 LOGE("Out-of-memory");
845 return NOTI_EX_ERROR_OUT_OF_MEMORY;
848 *handle = new Handle(p);
850 return NOTI_EX_ERROR_NONE;
853 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
854 noti_ex_item_h handle, char **image_path) {
855 if (handle == nullptr || image_path == nullptr) {
856 LOGE("Invalid parameter");
857 return NOTI_EX_ERROR_INVALID_PARAMETER;
859 Handle* h = static_cast<Handle*>(handle);
860 if (!h->IsValidType(AbstractItem::Image)) {
861 LOGE("Invalid handle type");
862 return NOTI_EX_ERROR_INVALID_PARAMETER;
864 ImageItem* p = static_cast<ImageItem*>(h->Get());
865 if (!p->GetImagePath().empty()) {
866 *image_path = strdup(p->GetImagePath().c_str());
867 if (*image_path == nullptr) {
868 LOGE("Out-of-memory");
869 return NOTI_EX_ERROR_OUT_OF_MEMORY;
873 return NOTI_EX_ERROR_NONE;
876 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
877 noti_ex_item_h *handle, const char *id) {
878 InputSelectorItem* p;
880 if (handle == nullptr) {
881 LOGE("Invalid parameter");
882 return NOTI_EX_ERROR_INVALID_PARAMETER;
886 p = new (std::nothrow) InputSelectorItem(id);
888 p = new (std::nothrow) InputSelectorItem();
891 LOGE("Out-of-memory");
892 return NOTI_EX_ERROR_OUT_OF_MEMORY;
895 *handle = new Handle(p);
897 return NOTI_EX_ERROR_NONE;
900 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
901 noti_ex_item_h handle, char ***contents_list, int *count) {
902 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
903 LOGE("Invalid parameter");
904 return NOTI_EX_ERROR_INVALID_PARAMETER;
907 Handle* h = static_cast<Handle*>(handle);
908 if (!h->IsValidType(AbstractItem::InputSelector)) {
909 LOGE("Invalid handle type");
910 return NOTI_EX_ERROR_INVALID_PARAMETER;
912 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
913 list<string> contents = p->GetContents();
914 char **list = (char**)calloc(contents.size(), sizeof(char*));
916 for (auto& i : contents) {
917 list[idx++] = strdup(i.c_str());
919 *count = contents.size();
920 *contents_list = list;
922 return NOTI_EX_ERROR_NONE;
925 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
926 noti_ex_item_h handle, const char **contents, int count) {
927 if (handle == nullptr || contents == nullptr) {
928 LOGE("Invalid parameter");
929 return NOTI_EX_ERROR_INVALID_PARAMETER;
932 list<string> new_contents;
933 Handle* h = static_cast<Handle*>(handle);
934 if (!h->IsValidType(AbstractItem::InputSelector)) {
935 LOGE("Invalid handle type");
936 return NOTI_EX_ERROR_INVALID_PARAMETER;
938 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
939 for (int i = 0; i < count; i++) {
940 new_contents.push_back(contents[i]);
942 p->SetContents(move(new_contents));
944 return NOTI_EX_ERROR_NONE;
947 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
948 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
949 if (handle == nullptr) {
950 LOGE("Invalid parameter");
951 return NOTI_EX_ERROR_INVALID_PARAMETER;
954 auto* p = new (std::nothrow) Color(a, r, g, b);
956 LOGE("Out-of-memory");
957 return NOTI_EX_ERROR_OUT_OF_MEMORY;
962 return NOTI_EX_ERROR_NONE;
965 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
966 if (handle == nullptr) {
967 LOGE("Invalid parameter");
968 return NOTI_EX_ERROR_INVALID_PARAMETER;
971 Color* p = static_cast<Color*>(handle);
974 return NOTI_EX_ERROR_NONE;
977 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
978 unsigned char *val) {
979 if (handle == nullptr || val == nullptr) {
980 LOGE("Invalid parameter");
981 return NOTI_EX_ERROR_INVALID_PARAMETER;
984 Color* p = static_cast<Color*>(handle);
987 return NOTI_EX_ERROR_NONE;
990 extern "C" EXPORT_API int noti_ex_color_get_red(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 Color* p = static_cast<Color*>(handle);
1000 return NOTI_EX_ERROR_NONE;
1003 extern "C" EXPORT_API int noti_ex_color_get_green(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 Color* p = static_cast<Color*>(handle);
1011 *val = p->GetGVal();
1013 return NOTI_EX_ERROR_NONE;
1016 extern "C" EXPORT_API int noti_ex_color_get_blue(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 Color* p = static_cast<Color*>(handle);
1024 *val = p->GetBVal();
1026 return NOTI_EX_ERROR_NONE;
1029 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1030 int left, int top, int right, int bottom) {
1031 if (handle == nullptr) {
1032 LOGE("Invalid parameter");
1033 return NOTI_EX_ERROR_INVALID_PARAMETER;
1036 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1038 LOGE("Out-of-memory");
1039 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1044 return NOTI_EX_ERROR_NONE;
1047 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1048 if (handle == nullptr) {
1049 LOGE("Invalid parameter");
1050 return NOTI_EX_ERROR_INVALID_PARAMETER;
1053 Padding* p = static_cast<Padding*>(handle);
1056 return NOTI_EX_ERROR_NONE;
1059 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1061 if (handle == nullptr || val == nullptr) {
1062 LOGE("Invalid parameter");
1063 return NOTI_EX_ERROR_INVALID_PARAMETER;
1066 Padding* p = static_cast<Padding*>(handle);
1067 *val = p->GetLeft();
1069 return NOTI_EX_ERROR_NONE;
1072 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1074 if (handle == nullptr || val == nullptr) {
1075 LOGE("Invalid parameter");
1076 return NOTI_EX_ERROR_INVALID_PARAMETER;
1079 Padding* p = static_cast<Padding*>(handle);
1082 return NOTI_EX_ERROR_NONE;
1085 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1087 if (handle == nullptr || val == nullptr) {
1088 LOGE("Invalid parameter");
1089 return NOTI_EX_ERROR_INVALID_PARAMETER;
1092 Padding* p = static_cast<Padding*>(handle);
1093 *val = p->GetRight();
1095 return NOTI_EX_ERROR_NONE;
1098 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1100 if (handle == nullptr || val == nullptr) {
1101 LOGE("Invalid parameter");
1102 return NOTI_EX_ERROR_INVALID_PARAMETER;
1105 Padding* p = static_cast<Padding*>(handle);
1106 *val = p->GetBottom();
1108 return NOTI_EX_ERROR_NONE;
1111 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1112 int x, int y, int w, int h) {
1113 if (handle == nullptr) {
1114 LOGE("Invalid parameter");
1115 return NOTI_EX_ERROR_INVALID_PARAMETER;
1118 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1120 LOGE("Out-of-memory");
1121 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1126 return NOTI_EX_ERROR_NONE;
1129 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1130 if (handle == nullptr) {
1131 LOGE("Invalid parameter");
1132 return NOTI_EX_ERROR_INVALID_PARAMETER;
1135 Geometry* p = static_cast<Geometry*>(handle);
1138 return NOTI_EX_ERROR_NONE;
1141 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1143 if (handle == nullptr || val == nullptr) {
1144 LOGE("Invalid parameter");
1145 return NOTI_EX_ERROR_INVALID_PARAMETER;
1148 Geometry* p = static_cast<Geometry*>(handle);
1151 return NOTI_EX_ERROR_NONE;
1154 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1156 if (handle == nullptr || val == nullptr) {
1157 LOGE("Invalid parameter");
1158 return NOTI_EX_ERROR_INVALID_PARAMETER;
1161 Geometry* p = static_cast<Geometry*>(handle);
1164 return NOTI_EX_ERROR_NONE;
1167 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1169 if (handle == nullptr || val == nullptr) {
1170 LOGE("Invalid parameter");
1171 return NOTI_EX_ERROR_INVALID_PARAMETER;
1174 Geometry* p = static_cast<Geometry*>(handle);
1175 *val = p->GetWidth();
1177 return NOTI_EX_ERROR_NONE;
1180 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1182 if (handle == nullptr || val == nullptr) {
1183 LOGE("Invalid parameter");
1184 return NOTI_EX_ERROR_INVALID_PARAMETER;
1187 Geometry* p = static_cast<Geometry*>(handle);
1188 *val = p->GetHeight();
1190 return NOTI_EX_ERROR_NONE;
1193 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1194 noti_ex_color_h color,
1195 noti_ex_padding_h padding,
1196 noti_ex_geometry_h geometry) {
1197 if (handle == nullptr) {
1198 LOGE("Invalid parameter");
1199 return NOTI_EX_ERROR_INVALID_PARAMETER;
1202 Color* color_ = static_cast<Color*>(color);
1203 Padding* padding_ = static_cast<Padding*>(padding);
1204 Geometry* geo_ = static_cast<Geometry*>(geometry);
1206 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1208 LOGE("Out-of-memory");
1209 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1214 return NOTI_EX_ERROR_NONE;
1217 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1218 if (handle == nullptr) {
1219 LOGE("Invalid parameter");
1220 return NOTI_EX_ERROR_INVALID_PARAMETER;
1223 Style* p = static_cast<Style*>(handle);
1226 return NOTI_EX_ERROR_NONE;
1229 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1230 noti_ex_padding_h *padding) {
1231 if (handle == nullptr || padding == nullptr) {
1232 LOGE("Invalid parameter");
1233 return NOTI_EX_ERROR_INVALID_PARAMETER;
1236 Style* p = static_cast<Style*>(handle);
1237 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1238 if (padding_ == nullptr) {
1239 LOGE("Out-of-memory");
1240 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1243 *padding = padding_;
1245 return NOTI_EX_ERROR_NONE;
1248 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1249 noti_ex_color_h *color) {
1250 if (handle == nullptr || color == nullptr) {
1251 LOGE("Invalid parameter");
1252 return NOTI_EX_ERROR_INVALID_PARAMETER;
1255 Style* p = static_cast<Style*>(handle);
1256 Color* color_ = new (std::nothrow) Color(p->GetColor());
1257 if (color_ == nullptr) {
1258 LOGE("Out-of-memory");
1259 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1264 return NOTI_EX_ERROR_NONE;
1267 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1268 noti_ex_geometry_h *geometry) {
1269 if (handle == nullptr || geometry == nullptr) {
1270 LOGE("Invalid parameter");
1271 return NOTI_EX_ERROR_INVALID_PARAMETER;
1274 Style* p = static_cast<Style*>(handle);
1275 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1276 if (geo_ == nullptr) {
1277 LOGE("Out-of-memory");
1278 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1283 return NOTI_EX_ERROR_NONE;
1286 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1287 noti_ex_color_h color) {
1288 if (handle == nullptr) {
1289 LOGE("Invalid parameter");
1290 return NOTI_EX_ERROR_INVALID_PARAMETER;
1293 Color* color_ = static_cast<Color*>(color);
1294 auto* p = new (std::nothrow) LEDInfo(*color_);
1296 LOGE("Out-of-memory");
1297 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1302 return NOTI_EX_ERROR_NONE;
1305 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1306 if (handle == nullptr) {
1307 LOGE("Invalid parameter");
1308 return NOTI_EX_ERROR_INVALID_PARAMETER;
1311 LEDInfo* p = static_cast<LEDInfo*>(handle);
1314 return NOTI_EX_ERROR_NONE;
1317 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1318 noti_ex_led_info_h handle, int ms) {
1319 if (handle == nullptr) {
1320 LOGE("Invalid parameter");
1321 return NOTI_EX_ERROR_INVALID_PARAMETER;
1324 LEDInfo* p = static_cast<LEDInfo*>(handle);
1327 return NOTI_EX_ERROR_NONE;
1330 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1331 noti_ex_led_info_h handle, int *ms) {
1332 if (handle == nullptr || ms == nullptr) {
1333 LOGE("Invalid parameter");
1334 return NOTI_EX_ERROR_INVALID_PARAMETER;
1337 LEDInfo* p = static_cast<LEDInfo*>(handle);
1338 *ms = p->GetOnPeriod();
1340 return NOTI_EX_ERROR_NONE;
1343 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1344 noti_ex_led_info_h handle, int ms) {
1345 if (handle == nullptr) {
1346 LOGE("Invalid parameter");
1347 return NOTI_EX_ERROR_INVALID_PARAMETER;
1350 LEDInfo* p = static_cast<LEDInfo*>(handle);
1351 p->SetOffPeriod(ms);
1353 return NOTI_EX_ERROR_NONE;
1356 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1357 noti_ex_led_info_h handle, int *ms) {
1358 if (handle == nullptr) {
1359 LOGE("Invalid parameter");
1360 return NOTI_EX_ERROR_INVALID_PARAMETER;
1363 LEDInfo* p = static_cast<LEDInfo*>(handle);
1364 *ms = p->GetOffPeriod();
1366 return NOTI_EX_ERROR_NONE;
1369 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1370 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1371 if (handle == nullptr) {
1372 LOGE("Invalid parameter");
1373 return NOTI_EX_ERROR_INVALID_PARAMETER;
1376 LEDInfo* p = static_cast<LEDInfo*>(handle);
1377 Color* color_ = new (std::nothrow) Color(p->GetColor());
1378 if (color_ == nullptr) {
1379 LOGE("Out-of-memory");
1380 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1385 return NOTI_EX_ERROR_NONE;
1388 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1389 if (handle == nullptr) {
1390 LOGE("Invalid parameter");
1391 return NOTI_EX_ERROR_INVALID_PARAMETER;
1394 AbstractAction* p = static_cast<AbstractAction*>(handle);
1395 p->~AbstractAction();
1397 return NOTI_EX_ERROR_NONE;
1400 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1402 if (handle == nullptr || type == nullptr) {
1403 LOGE("Invalid parameter");
1404 return NOTI_EX_ERROR_INVALID_PARAMETER;
1407 AbstractAction* p = static_cast<AbstractAction*>(handle);
1408 *type = p->GetType();
1410 return NOTI_EX_ERROR_NONE;
1413 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1415 if (handle == nullptr || local == nullptr) {
1416 LOGE("Invalid parameter");
1417 return NOTI_EX_ERROR_INVALID_PARAMETER;
1420 AbstractAction* p = static_cast<AbstractAction*>(handle);
1421 *local = p->IsLocal();
1423 return NOTI_EX_ERROR_NONE;
1426 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1427 noti_ex_item_h item) {
1428 if (handle == nullptr || item == nullptr) {
1429 LOGE("Invalid parameter");
1430 return NOTI_EX_ERROR_INVALID_PARAMETER;
1432 AbstractAction* p = static_cast<AbstractAction*>(handle);
1433 Handle* ih = static_cast<Handle*>(item);
1434 p->Execute(ih->GetPtr());
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1441 if (handle == nullptr || extra == nullptr) {
1442 LOGE("Invalid parameter");
1443 return NOTI_EX_ERROR_INVALID_PARAMETER;
1446 AbstractAction* p = static_cast<AbstractAction*>(handle);
1447 if (!p->GetExtra().empty()) {
1448 *extra = strdup(p->GetExtra().c_str());
1449 if (*extra == nullptr) {
1450 LOGE("Out-of-memory");
1451 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1455 return NOTI_EX_ERROR_NONE;
1458 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1459 noti_ex_item_info_h handle, int *hide_time) {
1460 if (handle == nullptr || hide_time == nullptr) {
1461 LOGE("Invalid parameter");
1462 return NOTI_EX_ERROR_INVALID_PARAMETER;
1464 IItemInfo* p = static_cast<IItemInfo*>(handle);
1465 *hide_time = p->GetHideTime();
1466 return NOTI_EX_ERROR_NONE;
1469 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1470 noti_ex_item_info_h handle, int hide_time) {
1471 if (handle == nullptr) {
1472 LOGE("Invalid parameter");
1473 return NOTI_EX_ERROR_INVALID_PARAMETER;
1475 IItemInfo* p = static_cast<IItemInfo*>(handle);
1476 p->SetHideTime(hide_time);
1477 return NOTI_EX_ERROR_NONE;
1480 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1481 noti_ex_item_info_h handle, int *delete_time) {
1482 if (handle == nullptr || delete_time == nullptr) {
1483 LOGE("Invalid parameter");
1484 return NOTI_EX_ERROR_INVALID_PARAMETER;
1486 IItemInfo* p = static_cast<IItemInfo*>(handle);
1487 *delete_time = p->GetDeleteTime();
1488 return NOTI_EX_ERROR_NONE;
1491 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1492 noti_ex_item_info_h handle, int delete_time) {
1493 if (handle == nullptr) {
1494 LOGE("Invalid parameter");
1495 return NOTI_EX_ERROR_INVALID_PARAMETER;
1497 IItemInfo* p = static_cast<IItemInfo*>(handle);
1498 p->SetDeleteTime(delete_time);
1499 return NOTI_EX_ERROR_NONE;
1502 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1503 noti_ex_item_info_h handle, time_t *time) {
1504 if (handle == nullptr || time == nullptr) {
1505 LOGE("Invalid parameter");
1506 return NOTI_EX_ERROR_INVALID_PARAMETER;
1509 IItemInfo* p = static_cast<IItemInfo*>(handle);
1510 *time = p->GetTime();
1511 return NOTI_EX_ERROR_NONE;
1514 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1515 if (handle == nullptr) {
1516 LOGE("Invalid parameter");
1517 return NOTI_EX_ERROR_INVALID_PARAMETER;
1520 Handle* h = static_cast<Handle*>(handle);
1522 return NOTI_EX_ERROR_NONE;
1525 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1526 const char *id, noti_ex_item_h *item) {
1527 if (handle == nullptr) {
1528 LOGE("Invalid parameter");
1529 return NOTI_EX_ERROR_INVALID_PARAMETER;
1532 Handle* p = static_cast<Handle*>(handle);
1533 AbstractItem& find_item = p->Get()->FindByID(string(id));
1534 *item = new Handle(&find_item);
1535 return NOTI_EX_ERROR_NONE;
1538 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1540 if (handle == nullptr || type == nullptr) {
1541 LOGE("Invalid parameter");
1542 return NOTI_EX_ERROR_INVALID_PARAMETER;
1545 Handle* h = static_cast<Handle*>(handle);
1546 AbstractItem* p = h->Get();
1547 *type = p->GetType();
1548 return NOTI_EX_ERROR_NONE;
1551 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1552 char ***path, int *count) {
1553 if (handle == nullptr || path == nullptr || count == nullptr) {
1554 LOGE("Invalid parameter");
1555 return NOTI_EX_ERROR_INVALID_PARAMETER;
1557 Handle* p = static_cast<Handle*>(handle);
1558 list<string> shared_path = p->Get()->GetSharedPath();
1559 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1561 for (auto& i : shared_path) {
1562 *path[idx++] = strdup(i.c_str());
1564 *count = shared_path.size();
1565 return NOTI_EX_ERROR_NONE;
1568 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1570 if (handle == nullptr || id == nullptr) {
1571 LOGE("Invalid parameter");
1572 return NOTI_EX_ERROR_INVALID_PARAMETER;
1574 Handle* h = static_cast<Handle*>(handle);
1575 AbstractItem* p = h->Get();
1576 *id = strdup(p->GetId().c_str());
1577 return NOTI_EX_ERROR_NONE;
1580 extern "C" EXPORT_API int noti_ex_item_set_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* p = static_cast<Handle*>(handle);
1587 p->Get()->SetId(id);
1588 return NOTI_EX_ERROR_NONE;
1591 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1592 noti_ex_action_h *action) {
1593 if (handle == nullptr || action == nullptr) {
1594 LOGE("Invalid parameter");
1595 return NOTI_EX_ERROR_INVALID_PARAMETER;
1597 Handle* p = static_cast<Handle*>(handle);
1598 if (p->Get()->GetAction() == nullptr) {
1600 return NOTI_EX_ERROR_NONE;
1602 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1604 return NOTI_EX_ERROR_NONE;
1607 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1608 noti_ex_action_h action) {
1609 if (handle == nullptr || action == nullptr) {
1610 LOGE("Invalid parameter");
1611 return NOTI_EX_ERROR_INVALID_PARAMETER;
1614 Handle* p = static_cast<Handle*>(handle);
1615 AbstractAction* a = static_cast<AbstractAction*>(action);
1616 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1617 return NOTI_EX_ERROR_NONE;
1620 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1621 noti_ex_style_h *style) {
1622 if (handle == nullptr || style == nullptr) {
1623 LOGE("Invalid parameter");
1624 return NOTI_EX_ERROR_INVALID_PARAMETER;
1627 Handle* p = static_cast<Handle*>(handle);
1628 shared_ptr<Style> s = p->Get()->GetStyle();
1629 *style = static_cast<noti_ex_style_h>(s.get());
1630 return NOTI_EX_ERROR_NONE;
1633 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1634 noti_ex_style_h style) {
1635 if (handle == nullptr || style == nullptr) {
1636 LOGE("Invalid parameter");
1637 return NOTI_EX_ERROR_INVALID_PARAMETER;
1640 Handle* p = static_cast<Handle*>(handle);
1641 Style* s = static_cast<Style*>(style);
1642 p->Get()->SetStyle(shared_ptr<Style>(s));
1643 return NOTI_EX_ERROR_NONE;
1646 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1648 if (handle == nullptr) {
1649 LOGE("Invalid parameter");
1650 return NOTI_EX_ERROR_INVALID_PARAMETER;
1653 Handle* p = static_cast<Handle*>(handle);
1654 p->Get()->SetVisible(visible);
1655 return NOTI_EX_ERROR_NONE;
1658 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1660 if (handle == nullptr || visible == nullptr) {
1661 LOGE("Invalid parameter");
1662 return NOTI_EX_ERROR_INVALID_PARAMETER;
1665 Handle* p = static_cast<Handle*>(handle);
1666 *visible = p->Get()->GetVisible();
1667 return NOTI_EX_ERROR_NONE;
1670 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1672 if (handle == nullptr) {
1673 LOGE("Invalid parameter");
1674 return NOTI_EX_ERROR_INVALID_PARAMETER;
1677 Handle* p = static_cast<Handle*>(handle);
1678 p->Get()->SetEnable(enable);
1679 return NOTI_EX_ERROR_NONE;
1682 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1684 if (handle == nullptr || enable == nullptr) {
1685 LOGE("Invalid parameter");
1686 return NOTI_EX_ERROR_INVALID_PARAMETER;
1689 Handle* p = static_cast<Handle*>(handle);
1690 *enable = p->Get()->GetEnable();
1691 return NOTI_EX_ERROR_NONE;
1694 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1695 const char *receiver_group) {
1696 if (handle == nullptr || receiver_group == nullptr) {
1697 LOGE("Invalid parameter");
1698 return NOTI_EX_ERROR_INVALID_PARAMETER;
1701 Handle* p = static_cast<Handle*>(handle);
1702 p->Get()->AddReceiver(receiver_group);
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_item_remove_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()->RemoveReceiver(receiver_group);
1715 return NOTI_EX_ERROR_NONE;
1718 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1719 char ***receiver_list, int *count) {
1720 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1721 LOGE("Invalid parameter");
1722 return NOTI_EX_ERROR_INVALID_PARAMETER;
1725 Handle* p = static_cast<Handle*>(handle);
1726 list<string> receivers = p->Get()->GetReceiverList();
1727 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1729 for (auto& i : receivers) {
1730 *receiver_list[idx++] = strdup(i.c_str());
1732 *count = receivers.size();
1733 return NOTI_EX_ERROR_NONE;
1736 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1738 if (handle == nullptr) {
1739 LOGE("Invalid parameter");
1740 return NOTI_EX_ERROR_INVALID_PARAMETER;
1743 Handle* p = static_cast<Handle*>(handle);
1744 p->Get()->SetPolicy(policy);
1745 return NOTI_EX_ERROR_NONE;
1748 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1750 if (handle == nullptr || policy == nullptr) {
1751 LOGE("Invalid parameter");
1752 return NOTI_EX_ERROR_INVALID_PARAMETER;
1755 Handle* p = static_cast<Handle*>(handle);
1756 *policy = p->Get()->GetPolicy();
1757 return NOTI_EX_ERROR_NONE;
1760 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1762 if (handle == nullptr || channel == nullptr) {
1763 LOGE("Invalid parameter");
1764 return NOTI_EX_ERROR_INVALID_PARAMETER;
1767 Handle* p = static_cast<Handle*>(handle);
1768 if (!p->Get()->GetChannel().empty())
1769 *channel = strdup(p->Get()->GetChannel().c_str());
1773 return NOTI_EX_ERROR_NONE;
1776 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1777 const char *channel) {
1778 if (handle == nullptr) {
1779 LOGE("Invalid parameter");
1780 return NOTI_EX_ERROR_INVALID_PARAMETER;
1783 Handle* p = static_cast<Handle*>(handle);
1784 p->Get()->SetChannel(channel);
1785 return NOTI_EX_ERROR_NONE;
1788 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1789 noti_ex_led_info_h led) {
1790 if (handle == nullptr) {
1791 LOGE("Invalid parameter");
1792 return NOTI_EX_ERROR_INVALID_PARAMETER;
1795 Handle* p = static_cast<Handle*>(handle);
1796 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1797 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1798 return NOTI_EX_ERROR_NONE;
1801 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1802 noti_ex_led_info_h *led) {
1803 if (handle == nullptr) {
1804 LOGE("Invalid parameter");
1805 return NOTI_EX_ERROR_INVALID_PARAMETER;
1808 Handle* p = static_cast<Handle*>(handle);
1809 if (p->Get()->GetLEDInfo() != nullptr)
1810 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1813 return NOTI_EX_ERROR_NONE;
1816 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1818 if (handle == nullptr) {
1819 LOGE("Invalid parameter");
1820 return NOTI_EX_ERROR_INVALID_PARAMETER;
1823 Handle* p = static_cast<Handle*>(handle);
1824 if (path == nullptr)
1825 p->Get()->SetSoundPath("");
1827 p->Get()->SetSoundPath(path);
1828 return NOTI_EX_ERROR_NONE;
1831 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1833 if (handle == nullptr) {
1834 LOGE("Invalid parameter");
1835 return NOTI_EX_ERROR_INVALID_PARAMETER;
1838 Handle* p = static_cast<Handle*>(handle);
1839 if (path == nullptr)
1840 p->Get()->SetVibrationPath("");
1842 p->Get()->SetVibrationPath(path);
1843 return NOTI_EX_ERROR_NONE;
1846 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1848 if (handle == nullptr || path == nullptr) {
1849 LOGE("Invalid parameter");
1850 return NOTI_EX_ERROR_INVALID_PARAMETER;
1853 Handle* p = static_cast<Handle*>(handle);
1854 if (p->Get()->GetSoundPath().empty())
1857 *path = strdup(p->Get()->GetSoundPath().c_str());
1858 return NOTI_EX_ERROR_NONE;
1861 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1863 if (handle == nullptr || path == nullptr) {
1864 LOGE("Invalid parameter");
1865 return NOTI_EX_ERROR_INVALID_PARAMETER;
1868 Handle* p = static_cast<Handle*>(handle);
1869 if (p->Get()->GetVibrationPath().empty())
1872 *path = strdup(p->Get()->GetVibrationPath().c_str());
1873 return NOTI_EX_ERROR_NONE;
1876 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1877 noti_ex_item_info_h *info) {
1878 if (handle == nullptr || info == nullptr) {
1879 LOGE("Invalid parameter");
1880 return NOTI_EX_ERROR_INVALID_PARAMETER;
1883 Handle* p = static_cast<Handle*>(handle);
1884 if (p->Get()->GetInfo() == nullptr)
1887 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1888 return NOTI_EX_ERROR_NONE;
1891 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1893 if (handle == nullptr || id == nullptr) {
1894 LOGE("Invalid parameter");
1895 return NOTI_EX_ERROR_INVALID_PARAMETER;
1898 Handle* p = static_cast<Handle*>(handle);
1899 if (p->Get()->GetSenderAppId().empty())
1902 *id = strdup(p->Get()->GetSenderAppId().c_str());
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1908 if (handle == nullptr || tag == nullptr) {
1909 LOGE("Invalid parameter");
1910 return NOTI_EX_ERROR_INVALID_PARAMETER;
1913 Handle* p = static_cast<Handle*>(handle);
1914 if (p->Get()->GetTag().empty())
1917 *tag = strdup(p->Get()->GetTag().c_str());
1918 return NOTI_EX_ERROR_NONE;
1921 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1923 if (handle == nullptr) {
1924 LOGE("Invalid parameter");
1925 return NOTI_EX_ERROR_INVALID_PARAMETER;
1928 Handle* p = static_cast<Handle*>(handle);
1930 p->Get()->SetTag("");
1932 p->Get()->SetTag(tag);
1933 return NOTI_EX_ERROR_NONE;
1936 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1937 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1939 if (handle == nullptr) {
1940 LOGE("Invalid parameter");
1941 return NOTI_EX_ERROR_INVALID_PARAMETER;
1944 string receiver_group_str = "";
1946 receiver_group_str = string(receiver_group);
1948 ManagerStub* stub = new (std::nothrow) ManagerStub(
1949 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1950 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1951 receiver_group_str);
1952 if (stub == nullptr) {
1953 LOGE("Fail to create manager");
1954 return NOTI_EX_ERROR_IO_ERROR;
1956 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1957 new ManagerCallbackInfo(event_callbacks, data)));
1958 *handle = static_cast<noti_ex_manager_h>(stub);
1960 return NOTI_EX_ERROR_NONE;
1963 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1964 if (handle == nullptr) {
1965 LOGE("Invalid parameter");
1966 return NOTI_EX_ERROR_INVALID_PARAMETER;
1968 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1970 return NOTI_EX_ERROR_NONE;
1973 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1974 noti_ex_item_h **items, int *count) {
1975 if (handle == nullptr || items == nullptr || count == nullptr) {
1976 LOGE("Invalid parameter");
1977 return NOTI_EX_ERROR_INVALID_PARAMETER;
1981 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1982 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1983 if (item_list.size() == 0) {
1986 return NOTI_EX_ERROR_NONE;
1988 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1989 if (*items == nullptr) {
1990 LOGE("Fail to create items");
1991 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1995 for (auto& i : item_list) {
1996 *items[idx++] = new Handle(move(i));
1998 *count = item_list.size();
1999 } catch (Exception &ex) {
2000 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2001 return NOTI_EX_ERROR_IO_ERROR;
2003 return NOTI_EX_ERROR_NONE;
2006 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2007 noti_ex_item_h noti, int *request_id) {
2008 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2009 LOGE("Invalid parameter");
2010 return NOTI_EX_ERROR_INVALID_PARAMETER;
2013 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2014 Handle* sp = static_cast<Handle*>(noti);
2015 if (sp->GetPtr().get() == nullptr) {
2016 LOGE("Invalid noti reference can not be sended");
2017 return NOTI_EX_ERROR_INVALID_PARAMETER;
2019 *request_id = stub->Update(sp->GetPtr());
2021 } catch (Exception &ex) {
2022 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2023 return NOTI_EX_ERROR_IO_ERROR;
2025 return NOTI_EX_ERROR_NONE;
2028 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2029 noti_ex_item_h noti, int *request_id) {
2030 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2031 LOGE("Invalid parameter");
2032 return NOTI_EX_ERROR_INVALID_PARAMETER;
2035 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2036 Handle* item = static_cast<Handle*>(noti);
2037 if (item->GetPtr().get() == nullptr) {
2038 LOGE("Invalid noti reference can not be sended");
2039 return NOTI_EX_ERROR_INVALID_PARAMETER;
2041 *request_id = stub->Delete(item->GetPtr());
2043 } catch (Exception &ex) {
2044 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2045 return NOTI_EX_ERROR_IO_ERROR;
2047 return NOTI_EX_ERROR_NONE;
2050 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2052 if (handle == nullptr || request_id == nullptr) {
2053 LOGE("Invalid parameter");
2054 return NOTI_EX_ERROR_INVALID_PARAMETER;
2057 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2058 *request_id = stub->DeleteAll();
2059 } catch (Exception &ex) {
2060 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2061 return NOTI_EX_ERROR_IO_ERROR;
2063 return NOTI_EX_ERROR_NONE;
2066 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2067 noti_ex_item_h noti, int *request_id) {
2068 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2069 LOGE("Invalid parameter");
2070 return NOTI_EX_ERROR_INVALID_PARAMETER;
2073 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2074 Handle* item = static_cast<Handle*>(noti);
2075 if (item->GetPtr().get() == nullptr) {
2076 LOGE("Invalid noti reference can not be sended");
2077 return NOTI_EX_ERROR_INVALID_PARAMETER;
2079 *request_id = stub->Hide(item->GetPtr());
2081 } catch (Exception &ex) {
2082 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2083 return NOTI_EX_ERROR_IO_ERROR;
2085 return NOTI_EX_ERROR_NONE;
2088 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2089 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2090 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2091 LOGE("Invalid parameter");
2092 return NOTI_EX_ERROR_INVALID_PARAMETER;
2095 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2096 *item = new Handle(stub->FindByRootID(root_id));
2097 } catch (Exception &ex) {
2098 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2099 return NOTI_EX_ERROR_IO_ERROR;
2101 return NOTI_EX_ERROR_NONE;
2104 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2105 noti_ex_event_info_h info, noti_ex_error_e error) {
2106 if (handle == nullptr || info == nullptr) {
2107 LOGE("Invalid parameter");
2108 return NOTI_EX_ERROR_INVALID_PARAMETER;
2111 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2112 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2113 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2114 static_cast<NotificationError>(error));
2115 } catch (Exception &ex) {
2116 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2117 return NOTI_EX_ERROR_IO_ERROR;
2119 return NOTI_EX_ERROR_NONE;
2122 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2123 noti_ex_manager_h handle, int *cnt) {
2125 if (handle == nullptr || cnt == nullptr) {
2126 LOGE("Invalid parameter");
2127 return NOTI_EX_ERROR_INVALID_PARAMETER;
2130 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2131 *cnt = stub->GetCount();
2132 } catch (Exception &ex) {
2133 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2134 return NOTI_EX_ERROR_IO_ERROR;
2136 return NOTI_EX_ERROR_NONE;
2139 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2140 const char *id, float min, float current, float max) {
2143 if (handle == nullptr) {
2144 LOGE("Invalid parameter");
2145 return NOTI_EX_ERROR_INVALID_PARAMETER;
2149 p = new (std::nothrow) ProgressItem(id, min, current, max);
2151 p = new (std::nothrow) ProgressItem(min, current, max);
2154 LOGE("Out-of-memory");
2155 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2158 *handle = new Handle(p);
2160 return NOTI_EX_ERROR_NONE;
2163 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2164 noti_ex_item_h handle, float *current) {
2165 if (handle == nullptr || current == nullptr) {
2166 LOGE("Invalid parameter");
2167 return NOTI_EX_ERROR_INVALID_PARAMETER;
2170 Handle *h = static_cast<Handle*>(handle);
2171 if (!h->IsValidType(AbstractItem::Progress)) {
2172 LOGE("Invalid handle type");
2173 return NOTI_EX_ERROR_INVALID_PARAMETER;
2175 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2176 *current = p->GetCurrent();
2178 return NOTI_EX_ERROR_NONE;
2181 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2182 noti_ex_item_h handle, float current) {
2183 if (handle == nullptr) {
2184 LOGE("Invalid parameter");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2188 Handle *h = static_cast<Handle*>(handle);
2189 if (!h->IsValidType(AbstractItem::Progress)) {
2190 LOGE("Invalid handle type");
2191 return NOTI_EX_ERROR_INVALID_PARAMETER;
2193 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2194 p->SetCurrent(current);
2196 return NOTI_EX_ERROR_NONE;
2199 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2201 if (handle == nullptr || min == nullptr) {
2202 LOGE("Invalid parameter");
2203 return NOTI_EX_ERROR_INVALID_PARAMETER;
2206 Handle *h = static_cast<Handle*>(handle);
2207 if (!h->IsValidType(AbstractItem::Progress)) {
2208 LOGE("Invalid handle type");
2209 return NOTI_EX_ERROR_INVALID_PARAMETER;
2211 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2214 return NOTI_EX_ERROR_NONE;
2217 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2219 if (handle == nullptr || max == nullptr) {
2220 LOGE("Invalid parameter");
2221 return NOTI_EX_ERROR_INVALID_PARAMETER;
2224 Handle *h = static_cast<Handle*>(handle);
2225 if (!h->IsValidType(AbstractItem::Progress)) {
2226 LOGE("Invalid handle type");
2227 return NOTI_EX_ERROR_INVALID_PARAMETER;
2229 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2232 return NOTI_EX_ERROR_NONE;
2235 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2236 noti_ex_reporter_events_s event_callbacks, void *data) {
2237 if (handle == nullptr) {
2238 LOGE("Invalid parameter");
2239 return NOTI_EX_ERROR_INVALID_PARAMETER;
2242 ReporterStub* stub = new (std::nothrow) ReporterStub(
2243 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2244 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2245 if (stub == nullptr) {
2246 LOGE("Fail to create manager");
2247 return NOTI_EX_ERROR_IO_ERROR;
2249 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2250 new ReporterCallbackInfo(event_callbacks, data)));
2252 *handle = static_cast<noti_ex_reporter_h>(stub);
2254 return NOTI_EX_ERROR_NONE;
2257 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2258 if (handle == nullptr) {
2259 LOGE("Invalid parameter");
2260 return NOTI_EX_ERROR_INVALID_PARAMETER;
2262 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2264 return NOTI_EX_ERROR_NONE;
2267 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2268 noti_ex_event_info_h info, noti_ex_error_e error) {
2269 if (handle == nullptr || info == nullptr) {
2270 LOGE("Invalid parameter");
2271 return NOTI_EX_ERROR_INVALID_PARAMETER;
2274 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2275 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2276 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2277 static_cast<NotificationError>(error));
2278 } catch (Exception &ex) {
2279 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2280 return NOTI_EX_ERROR_IO_ERROR;
2282 return NOTI_EX_ERROR_NONE;
2285 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2286 noti_ex_item_h noti, int *request_id) {
2287 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2288 LOGE("Invalid parameter");
2289 return NOTI_EX_ERROR_INVALID_PARAMETER;
2292 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2293 Handle* h = static_cast<Handle*>(noti);
2294 if (h->GetPtr().get() == nullptr) {
2295 LOGE("Invalid noti reference can not be sended");
2296 return NOTI_EX_ERROR_INVALID_PARAMETER;
2298 *request_id = stub->Post(h->GetPtr());
2300 } catch (Exception &ex) {
2301 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2302 return NOTI_EX_ERROR_IO_ERROR;
2304 return NOTI_EX_ERROR_NONE;
2307 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2308 noti_ex_item_h *noti_list, int count, int *request_id) {
2310 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2311 LOGE("Invalid parameter");
2312 return NOTI_EX_ERROR_INVALID_PARAMETER;
2315 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2316 list<shared_ptr<item::AbstractItem>> notiList;
2317 for (int i = 0; i < count; i++) {
2318 Handle* item = static_cast<Handle*>(noti_list[i]);
2319 notiList.push_back(item->GetPtr());
2321 *request_id = stub->Post(notiList);
2322 } catch (Exception &ex) {
2323 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2324 return NOTI_EX_ERROR_IO_ERROR;
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2330 noti_ex_item_h noti, int *request_id) {
2331 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2337 Handle* item = static_cast<Handle*>(noti);
2338 if (item->GetPtr().get() == nullptr) {
2339 LOGE("Invalid noti reference can not be sended");
2340 return NOTI_EX_ERROR_INVALID_PARAMETER;
2342 *request_id = stub->Update(item->GetPtr());
2344 } catch (Exception &ex) {
2345 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2346 return NOTI_EX_ERROR_IO_ERROR;
2348 return NOTI_EX_ERROR_NONE;
2351 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2352 noti_ex_item_h noti, int *request_id) {
2353 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2354 LOGE("Invalid parameter");
2355 return NOTI_EX_ERROR_INVALID_PARAMETER;
2358 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2359 Handle* item = static_cast<Handle*>(noti);
2360 if (item->GetPtr().get() == nullptr) {
2361 LOGE("Invalid noti reference can not be sended");
2362 return NOTI_EX_ERROR_INVALID_PARAMETER;
2364 *request_id = stub->Delete(item->GetPtr());
2366 } catch (Exception &ex) {
2367 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2368 return NOTI_EX_ERROR_IO_ERROR;
2370 return NOTI_EX_ERROR_NONE;
2373 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2374 noti_ex_reporter_h handle, int *request_id) {
2375 if (handle == nullptr || request_id == nullptr) {
2376 LOGE("Invalid parameter");
2377 return NOTI_EX_ERROR_INVALID_PARAMETER;
2380 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2381 *request_id = stub->DeleteAll();
2382 } catch (Exception &ex) {
2383 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2384 return NOTI_EX_ERROR_IO_ERROR;
2386 return NOTI_EX_ERROR_NONE;
2389 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2390 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2391 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2392 LOGE("Invalid parameter");
2393 return NOTI_EX_ERROR_INVALID_PARAMETER;
2396 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2397 *item = new Handle(stub->FindByRootID(root_id));
2398 } catch (Exception &ex) {
2399 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2400 return NOTI_EX_ERROR_IO_ERROR;
2402 return NOTI_EX_ERROR_NONE;
2405 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2406 const char *id, const char *text, const char *hyperlink) {
2407 if (handle == nullptr) {
2408 LOGE("Invalid parameter");
2409 return NOTI_EX_ERROR_INVALID_PARAMETER;
2415 p = new (std::nothrow) TextItem(id, std::string(text),
2416 std::string(hyperlink));
2418 p = new (std::nothrow) TextItem(id, std::string(text));
2421 LOGE("Out-of-memory");
2422 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2425 *handle = new Handle(p);
2427 return NOTI_EX_ERROR_NONE;
2430 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2431 const char *contents) {
2432 if (handle == nullptr) {
2433 LOGE("Invalid parameter");
2434 return NOTI_EX_ERROR_INVALID_PARAMETER;
2437 Handle* p = static_cast<Handle*>(handle);
2438 if (!p->IsValidType(AbstractItem::Text)) {
2439 LOGE("Invalid handle type");
2440 return NOTI_EX_ERROR_INVALID_PARAMETER;
2442 TextItem* ti = static_cast<TextItem*>(p->Get());
2443 ti->SetContents(std::string(contents));
2445 return NOTI_EX_ERROR_NONE;
2448 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2450 if (handle == nullptr || contents == nullptr) {
2451 LOGE("Invalid parameter");
2452 return NOTI_EX_ERROR_INVALID_PARAMETER;
2455 Handle* p = static_cast<Handle*>(handle);
2456 if (!p->IsValidType(AbstractItem::Text)) {
2457 LOGE("Invalid handle type");
2458 return NOTI_EX_ERROR_INVALID_PARAMETER;
2460 TextItem* ti = static_cast<TextItem*>(p->Get());
2461 if (!ti->GetContents().empty()) {
2462 *contents = strdup(ti->GetContents().c_str());
2463 if (*contents == nullptr) {
2464 LOGE("Out-of-memory");
2465 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2469 return NOTI_EX_ERROR_NONE;
2472 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2473 noti_ex_item_h handle, char **hyper_link) {
2474 if (handle == nullptr || hyper_link == nullptr) {
2475 LOGE("Invalid parameter");
2476 return NOTI_EX_ERROR_INVALID_PARAMETER;
2479 Handle* p = static_cast<Handle*>(handle);
2480 if (!p->IsValidType(AbstractItem::Text)) {
2481 LOGE("Invalid handle type");
2482 return NOTI_EX_ERROR_INVALID_PARAMETER;
2484 TextItem* ti = static_cast<TextItem*>(p->Get());
2485 if (!ti->GetHyperLink().empty()) {
2486 *hyper_link = strdup(ti->GetHyperLink().c_str());
2487 if (*hyper_link == nullptr) {
2488 LOGE("Out-of-memory");
2489 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2493 return NOTI_EX_ERROR_NONE;
2496 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2497 const char *id, time_t time) {
2500 if (handle == nullptr) {
2501 LOGE("Invalid parameter");
2502 return NOTI_EX_ERROR_INVALID_PARAMETER;
2507 p = new (std::nothrow) TimeItem(id, time);
2509 p = new (std::nothrow) TimeItem(time);
2511 p = new (std::nothrow) TimeItem();
2515 LOGE("Out-of-memory");
2516 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2519 *handle = new Handle(p);
2521 return NOTI_EX_ERROR_NONE;
2524 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2526 if (handle == nullptr || time == nullptr) {
2527 LOGE("Invalid parameter");
2528 return NOTI_EX_ERROR_INVALID_PARAMETER;
2530 Handle* h = static_cast<Handle*>(handle);
2531 if (!h->IsValidType(AbstractItem::Time)) {
2532 LOGE("Invalid handle type");
2533 return NOTI_EX_ERROR_INVALID_PARAMETER;
2535 TimeItem* p = static_cast<TimeItem*>(h->Get());
2536 *time = p->GetTime();
2538 return NOTI_EX_ERROR_NONE;
2541 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2542 noti_ex_action_h *handle, const char *extra) {
2543 if (handle == nullptr) {
2544 LOGE("Invalid parameter");
2545 return NOTI_EX_ERROR_INVALID_PARAMETER;
2548 string extra_str = "";
2550 extra_str = string(extra);
2552 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2554 LOGE("Out-of-memory");
2555 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2560 return NOTI_EX_ERROR_NONE;
2563 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2564 const char *id, bool visible) {
2565 if (handle == nullptr || id == nullptr) {
2566 LOGE("Invalid parameter");
2567 return NOTI_EX_ERROR_INVALID_PARAMETER;
2570 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2571 p->SetVisibility(id, visible);
2573 return NOTI_EX_ERROR_NONE;