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;
75 Handle(item::AbstractItem* ref) : ref_(ref) { }
76 Handle(std::shared_ptr<item::AbstractItem> ptr)
77 : ref_(nullptr), ptr_(move(ptr)) { }
78 virtual ~Handle() = default;
79 item::AbstractItem* Get() const {
85 bool IsValidType(int type) const {
86 return (Get()->GetType() == type
87 || Get()->GetType() >= AbstractItem::Custom);
90 std::shared_ptr<item::AbstractItem> GetPtr() const {
92 return std::shared_ptr<item::AbstractItem>({});
97 item::AbstractItem* ref_;
98 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;
110 cb_.requested = cb.requested;
113 void InvokeAdded(Manager* manager, const IEventInfo& info,
114 list<shared_ptr<AbstractItem>> addedItem) {
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 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
139 cb_.updated(static_cast<noti_ex_manager_h>(manager),
140 static_cast<noti_ex_event_info_h>(c_info),
141 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
144 void InvokeDeleted(Manager* manager, const IEventInfo& info,
145 shared_ptr<item::AbstractItem> deletedItem) {
146 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
147 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
148 static_cast<noti_ex_event_info_h>(c_info),
149 static_cast<noti_ex_item_h>(
150 new Handle(deletedItem)), user_data_);
153 void InvokeError(Manager* manager, NotificationError error, int requestId) {
154 cb_.error(static_cast<noti_ex_manager_h>(manager),
155 static_cast<noti_ex_error_e>(error), requestId, user_data_);
158 list<shared_ptr<item::AbstractItem>> InvokeRequested(
159 Manager* manager, const IEventInfo& info) {
160 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
161 noti_ex_item_h* items = nullptr;
163 cb_.requested(static_cast<noti_ex_manager_h>(manager),
164 static_cast<noti_ex_event_info_h>(c_info),
165 &items, &cnt, user_data_);
166 list<shared_ptr<item::AbstractItem>> ret_list;
167 for (int i = 0; i < cnt; i++) {
168 Handle* item = static_cast<Handle*>(items[i]);
169 ret_list.emplace_back(item->GetPtr());
175 noti_ex_manager_events_s cb_;
179 class ManagerStub : public Manager {
181 ManagerStub(std::unique_ptr<IEventSender> sender,
182 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
183 : Manager(move(sender), move(listener), receiver_group) {
186 void OnAdd(const IEventInfo& info,
187 list<shared_ptr<AbstractItem>> addedItem) override {
188 cb_->InvokeAdded(this, info, addedItem);
192 void OnUpdate(const IEventInfo& info,
193 std::shared_ptr<item::AbstractItem> updatedItem) override {
194 cb_->InvokeUpdated(this, info, updatedItem);
197 void OnDelete(const IEventInfo& info,
198 shared_ptr<item::AbstractItem> deletedItem) override {
199 cb_->InvokeDeleted(this, info, deletedItem);
202 void OnError(NotificationError error, int requestId) override {
203 cb_->InvokeError(this, error, requestId);
206 list<shared_ptr<item::AbstractItem>> OnRequestEvent(
207 const IEventInfo& info) override {
208 return cb_->InvokeRequested(this, info);
211 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
213 return NOTI_EX_ERROR_NONE;
216 int ClearManagerCallbackInfo() {
218 return NOTI_EX_ERROR_NONE;
222 unique_ptr<ManagerCallbackInfo> cb_;
226 class ReporterCallbackInfo {
228 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
229 : user_data_(user_data) {
230 cb_.event = cb.event;
231 cb_.error = cb.error;
232 cb_.requested = cb.requested;
235 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
236 list<shared_ptr<AbstractItem>> notiList) {
238 noti_ex_item_h* noti_list =
239 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
240 if (noti_list == nullptr) {
241 LOGE("Out of memory");
246 for (auto& i : notiList) {
248 static_cast<noti_ex_item_h>(new Handle(i));
251 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
252 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
253 static_cast<noti_ex_event_info_h>(c_info), noti_list,
254 notiList.size(), user_data_);
258 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
259 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
260 static_cast<noti_ex_error_e>(error), requestId, user_data_);
263 list<shared_ptr<item::AbstractItem>> InvokeRequested(Reporter* reporter,
264 const IEventInfo& info) {
265 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
266 noti_ex_item_h* items = nullptr;
268 cb_.requested(static_cast<noti_ex_reporter_h>(reporter),
269 static_cast<noti_ex_event_info_h>(c_info),
270 &items, &cnt, user_data_);
271 list<shared_ptr<item::AbstractItem>> ret_list;
272 for (int i = 0; i < cnt; i++) {
273 Handle* item = static_cast<Handle*>(items[i]);
274 ret_list.emplace_back(item->GetPtr());
280 noti_ex_reporter_events_s cb_;
284 class ReporterStub : public Reporter {
286 ReporterStub(std::unique_ptr<IEventSender> sender,
287 std::unique_ptr<IEventListener> listener)
288 : Reporter(move(sender), move(listener)) {
291 void OnEvent(const IEventInfo& info,
292 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
293 cb_->InvokeEvent(this, info, notiList);
296 list<shared_ptr<item::AbstractItem>> OnRequestEvent(
297 const IEventInfo& info) override {
298 return cb_->InvokeRequested(this, info);
301 void OnError(NotificationError error, int requestId) override {
302 cb_->InvokeError(this, error, requestId);
305 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
307 return NOTI_EX_ERROR_NONE;
310 int ClearReporterCallbackInfo() {
312 return NOTI_EX_ERROR_NONE;
316 unique_ptr<ReporterCallbackInfo> cb_;
320 extern "C" EXPORT_API int noti_ex_action_app_control_create(
321 noti_ex_action_h *handle, app_control_h app_control,
323 if (handle == nullptr || app_control == nullptr) {
324 LOGE("Invalid parameter");
325 return NOTI_EX_ERROR_INVALID_PARAMETER;
328 auto* p = new (std::nothrow) AppControlAction(app_control, extra);
330 LOGE("Out-of-memory");
331 return NOTI_EX_ERROR_OUT_OF_MEMORY;
336 return NOTI_EX_ERROR_NONE;
339 extern "C" EXPORT_API int noti_ex_action_app_control_set(
340 noti_ex_action_h handle, app_control_h app_control) {
341 if (handle == nullptr || app_control == nullptr) {
342 LOGE("Invalid parameter");
343 return NOTI_EX_ERROR_INVALID_PARAMETER;
346 AppControlAction* p = static_cast<AppControlAction*>(handle);
347 p->SetAppControl(app_control);
349 return NOTI_EX_ERROR_NONE;
352 extern "C" EXPORT_API int noti_ex_action_app_control_get(
353 noti_ex_action_h handle, app_control_h *app_control) {
354 if (handle == nullptr || app_control == nullptr) {
355 LOGE("Invalid parameter");
356 return NOTI_EX_ERROR_INVALID_PARAMETER;
359 AppControlAction* p = static_cast<AppControlAction*>(handle);
360 *app_control = p->GetAppControl();
362 return NOTI_EX_ERROR_NONE;
365 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
366 const char *id, const char *title) {
369 if (handle == nullptr || title == nullptr) {
370 LOGE("Invalid parameter");
371 return NOTI_EX_ERROR_INVALID_PARAMETER;
375 p = new (std::nothrow) ButtonItem(id, title);
377 p = new (std::nothrow) ButtonItem(title);
380 LOGE("Out-of-memory");
381 return NOTI_EX_ERROR_OUT_OF_MEMORY;
383 *handle = new Handle(shared_ptr<AbstractItem>(p));
385 return NOTI_EX_ERROR_NONE;
388 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
390 if (handle == nullptr || title == nullptr) {
391 LOGE("Invalid parameter");
392 return NOTI_EX_ERROR_INVALID_PARAMETER;
395 Handle* sp = static_cast<Handle*>(handle);
396 if (!sp->IsValidType(AbstractItem::Button)) {
397 LOGE("Invalid handle type");
398 return NOTI_EX_ERROR_INVALID_PARAMETER;
400 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
401 if (!p->GetTitle().empty()) {
402 *title = strdup(p->GetTitle().c_str());
403 if (*title == nullptr) {
404 LOGE("Out-of-memory");
405 return NOTI_EX_ERROR_OUT_OF_MEMORY;
409 return NOTI_EX_ERROR_NONE;
412 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
413 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
414 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
415 noti_ex_item_chat_message_type_e message_type) {
416 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
417 LOGE("Invalid parameter");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
421 auto* p = new (std::nothrow) ChatMessageItem(id,
422 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
423 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
424 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
425 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
426 static_cast<ChatMessageItem::Type>((int)message_type));
428 LOGE("Out-of-memory");
429 return NOTI_EX_ERROR_OUT_OF_MEMORY;
432 *handle = new Handle(shared_ptr<AbstractItem>(p));
434 return NOTI_EX_ERROR_NONE;
437 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
438 noti_ex_item_h handle, noti_ex_item_h *name) {
439 if (handle == nullptr || name == nullptr) {
440 LOGE("Invalid parameter");
441 return NOTI_EX_ERROR_INVALID_PARAMETER;
443 Handle* h = static_cast<Handle*>(handle);
444 if (!h->IsValidType(AbstractItem::ChatMessage)) {
445 LOGE("Invalid handle type");
446 return NOTI_EX_ERROR_INVALID_PARAMETER;
448 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
449 *name = new Handle(&(p->GetNameItem()));
451 return NOTI_EX_ERROR_NONE;
454 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
455 noti_ex_item_h handle, noti_ex_item_h *text) {
456 if (handle == nullptr || text == nullptr) {
457 LOGE("Invalid parameter");
458 return NOTI_EX_ERROR_INVALID_PARAMETER;
461 Handle* h = static_cast<Handle*>(handle);
462 if (!h->IsValidType(AbstractItem::ChatMessage)) {
463 LOGE("Invalid handle type");
464 return NOTI_EX_ERROR_INVALID_PARAMETER;
466 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
467 *text = new Handle(&(p->GetTextItem()));
469 return NOTI_EX_ERROR_NONE;
472 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
473 noti_ex_item_h handle, noti_ex_item_h *image) {
474 if (handle == nullptr || image == nullptr) {
475 LOGE("Invalid parameter");
476 return NOTI_EX_ERROR_INVALID_PARAMETER;
479 Handle* h = static_cast<Handle*>(handle);
480 if (!h->IsValidType(AbstractItem::ChatMessage)) {
481 LOGE("Invalid handle type");
482 return NOTI_EX_ERROR_INVALID_PARAMETER;
484 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
485 *image = new Handle(&(p->GetImageItem()));
487 return NOTI_EX_ERROR_NONE;
490 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
491 noti_ex_item_h handle, noti_ex_item_h *time) {
492 if (handle == nullptr || time == nullptr) {
493 LOGE("Invalid parameter");
494 return NOTI_EX_ERROR_INVALID_PARAMETER;
497 Handle* h = static_cast<Handle*>(handle);
498 if (!h->IsValidType(AbstractItem::ChatMessage)) {
499 LOGE("Invalid handle type");
500 return NOTI_EX_ERROR_INVALID_PARAMETER;
502 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
503 *time = new Handle(&(p->GetTimeItem()));
505 return NOTI_EX_ERROR_NONE;
508 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
509 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
510 if (handle == nullptr || message_type == nullptr) {
511 LOGE("Invalid parameter");
512 return NOTI_EX_ERROR_INVALID_PARAMETER;
515 Handle* h = static_cast<Handle*>(handle);
516 if (!h->IsValidType(AbstractItem::ChatMessage)) {
517 LOGE("Invalid handle type");
518 return NOTI_EX_ERROR_INVALID_PARAMETER;
520 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
521 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
523 return NOTI_EX_ERROR_NONE;
526 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
527 const char *id, const char *title, bool checked) {
530 if (handle == nullptr || title == nullptr) {
531 LOGE("Invalid parameter");
532 return NOTI_EX_ERROR_INVALID_PARAMETER;
535 p = new (std::nothrow) CheckBoxItem(id, title, checked);
537 LOGE("Out-of-memory");
538 return NOTI_EX_ERROR_OUT_OF_MEMORY;
541 *handle = new Handle(p);
543 return NOTI_EX_ERROR_NONE;
546 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
548 if (handle == nullptr || title == nullptr) {
549 LOGE("Invalid parameter");
550 return NOTI_EX_ERROR_INVALID_PARAMETER;
552 Handle* h = static_cast<Handle*>(handle);
553 if (!h->IsValidType(AbstractItem::CheckBox)) {
554 LOGE("Invalid handle type");
555 return NOTI_EX_ERROR_INVALID_PARAMETER;
557 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
558 if (!p->GetTitle().empty()) {
559 *title = strdup(p->GetTitle().c_str());
560 if (*title == nullptr) {
561 LOGE("Out-of-memory");
562 return NOTI_EX_ERROR_OUT_OF_MEMORY;
566 return NOTI_EX_ERROR_NONE;
569 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
571 if (handle == nullptr || checked == nullptr) {
572 LOGE("Invalid parameter");
573 return NOTI_EX_ERROR_INVALID_PARAMETER;
575 Handle* h = static_cast<Handle*>(handle);
576 if (!h->IsValidType(AbstractItem::CheckBox)) {
577 LOGE("Invalid handle type");
578 return NOTI_EX_ERROR_INVALID_PARAMETER;
580 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
581 *checked = p->IsChecked();
583 return NOTI_EX_ERROR_NONE;
586 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
590 if (handle == nullptr) {
591 LOGE("Invalid parameter");
592 return NOTI_EX_ERROR_INVALID_PARAMETER;
595 p = new (std::nothrow) EntryItem(id);
597 LOGE("Out-of-memory");
598 return NOTI_EX_ERROR_OUT_OF_MEMORY;
601 *handle = new Handle(p);
603 return NOTI_EX_ERROR_NONE;
606 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
608 if (handle == nullptr || text == nullptr) {
609 LOGE("Invalid parameter");
610 return NOTI_EX_ERROR_INVALID_PARAMETER;
613 Handle* h = static_cast<Handle*>(handle);
614 if (!h->IsValidType(AbstractItem::Entry)) {
615 LOGE("Invalid handle type");
616 return NOTI_EX_ERROR_INVALID_PARAMETER;
618 EntryItem* p = static_cast<EntryItem*>(h->Get());
619 if (!p->GetText().empty()) {
620 *text = strdup(p->GetText().c_str());
621 if (*text == nullptr) {
622 LOGE("Out-of-memory");
623 return NOTI_EX_ERROR_OUT_OF_MEMORY;
627 return NOTI_EX_ERROR_NONE;
630 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
632 if (handle == nullptr || text == nullptr) {
633 LOGE("Invalid parameter");
634 return NOTI_EX_ERROR_INVALID_PARAMETER;
636 Handle* h = static_cast<Handle*>(handle);
637 if (!h->IsValidType(AbstractItem::Entry)) {
638 LOGE("Invalid handle type");
639 return NOTI_EX_ERROR_INVALID_PARAMETER;
641 EntryItem* p = static_cast<EntryItem*>(h->Get());
642 p->SetText(std::string(text));
644 return NOTI_EX_ERROR_NONE;
647 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
648 noti_ex_event_info_h* cloned_handle) {
649 if (handle == nullptr || cloned_handle == nullptr) {
650 LOGE("Invalid parameter");
651 return NOTI_EX_ERROR_INVALID_PARAMETER;
654 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
655 EventInfo* info = new EventInfo(cloned);
656 *cloned_handle = info;
657 return NOTI_EX_ERROR_NONE;
660 extern "C" EXPORT_API int noti_ex_event_info_destroy(
661 noti_ex_event_info_h handle) {
662 if (handle == nullptr) {
663 LOGE("Invalid parameter");
664 return NOTI_EX_ERROR_INVALID_PARAMETER;
666 EventInfo* info = static_cast<EventInfo*>(handle);
668 return NOTI_EX_ERROR_NONE;
671 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
672 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
673 if (handle == nullptr || event_type == nullptr) {
674 LOGE("Invalid parameter");
675 return NOTI_EX_ERROR_INVALID_PARAMETER;
677 EventInfo* info = static_cast<EventInfo*>(handle);
678 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
680 return NOTI_EX_ERROR_NONE;
683 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
684 noti_ex_event_info_h handle, char **owner) {
685 if (handle == nullptr || owner == nullptr) {
686 LOGE("Invalid parameter");
687 return NOTI_EX_ERROR_INVALID_PARAMETER;
689 EventInfo* info = static_cast<EventInfo*>(handle);
690 *owner = strdup(info->GetOwner().c_str());
691 return NOTI_EX_ERROR_NONE;
694 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
695 noti_ex_event_info_h handle, char **channel) {
696 if (handle == nullptr || channel == nullptr) {
697 LOGE("Invalid parameter");
698 return NOTI_EX_ERROR_INVALID_PARAMETER;
700 EventInfo* info = static_cast<EventInfo*>(handle);
701 *channel = strdup(info->GetChannel().c_str());
702 return NOTI_EX_ERROR_NONE;
705 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
706 noti_ex_event_info_h handle, char **item_id) {
707 if (handle == nullptr || item_id == nullptr) {
708 LOGE("Invalid parameter");
709 return NOTI_EX_ERROR_INVALID_PARAMETER;
711 EventInfo* info = static_cast<EventInfo*>(handle);
712 *item_id = strdup(info->GetItemId().c_str());
713 return NOTI_EX_ERROR_NONE;
716 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
717 noti_ex_event_info_h handle, int *req_id) {
718 if (handle == nullptr || req_id == nullptr) {
719 LOGE("Invalid parameter");
720 return NOTI_EX_ERROR_INVALID_PARAMETER;
722 EventInfo* info = static_cast<EventInfo*>(handle);
723 *req_id = info->GetRequestId();
724 return NOTI_EX_ERROR_NONE;
727 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
731 if (handle == nullptr) {
732 LOGE("Invalid parameter");
733 return NOTI_EX_ERROR_INVALID_PARAMETER;
737 p = new (std::nothrow) GroupItem(id);
739 p = new (std::nothrow) GroupItem();
742 LOGE("Out-of-memory");
743 return NOTI_EX_ERROR_OUT_OF_MEMORY;
746 *handle = new Handle(shared_ptr<AbstractItem>(p));
748 return NOTI_EX_ERROR_NONE;
751 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
753 if (handle == nullptr) {
754 LOGE("Invalid parameter");
755 return NOTI_EX_ERROR_INVALID_PARAMETER;
757 Handle* h = static_cast<Handle*>(handle);
758 if (!h->IsValidType(AbstractItem::Group)) {
759 LOGE("Invalid handle type");
760 return NOTI_EX_ERROR_INVALID_PARAMETER;
762 GroupItem* p = static_cast<GroupItem*>(h->Get());
763 p->SetDirection(vertical);
765 return NOTI_EX_ERROR_NONE;
768 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
770 if (handle == 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 GroupItem* p = static_cast<GroupItem*>(h->Get());
780 *vertical = p->IsVertical();
782 return NOTI_EX_ERROR_NONE;
785 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
787 if (handle == 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 if (!p->GetAppLabel().empty()) {
798 *label = strdup(p->GetAppLabel().c_str());
799 if (*label == nullptr) {
800 LOGE("Out-of-memory");
801 return NOTI_EX_ERROR_OUT_OF_MEMORY;
805 return NOTI_EX_ERROR_NONE;
808 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
809 noti_ex_item_h child) {
810 if (handle == nullptr || child == nullptr) {
811 LOGE("Invalid parameter");
812 return NOTI_EX_ERROR_INVALID_PARAMETER;
814 Handle* h = static_cast<Handle*>(handle);
815 if (!h->IsValidType(AbstractItem::Group)) {
816 LOGE("Invalid handle type");
817 return NOTI_EX_ERROR_INVALID_PARAMETER;
819 auto p = static_cast<GroupItem*>(h->Get());
820 p->AddChild((static_cast<Handle*>(child))->GetPtr());
822 return NOTI_EX_ERROR_NONE;
825 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
826 const char *item_id) {
827 if (handle == nullptr || item_id == nullptr) {
828 LOGE("Invalid parameter");
829 return NOTI_EX_ERROR_INVALID_PARAMETER;
831 Handle* h = static_cast<Handle*>(handle);
832 if (!h->IsValidType(AbstractItem::Group)) {
833 LOGE("Invalid handle type");
834 return NOTI_EX_ERROR_INVALID_PARAMETER;
836 GroupItem* p = static_cast<GroupItem*>(h->Get());
837 p->RemoveChild(std::string(item_id));
839 return NOTI_EX_ERROR_NONE;
842 extern "C" EXPORT_API int noti_ex_item_group_foreach(noti_ex_item_h handle,
843 noti_ex_item_group_foreach_cb callback, void *data) {
844 if (handle == nullptr || callback == nullptr) {
845 LOGE("Invalid parameter");
846 return NOTI_EX_ERROR_INVALID_PARAMETER;
849 Handle* h = static_cast<Handle*>(handle);
850 if (!h->IsValidType(AbstractItem::Group)) {
851 LOGE("Invalid handle type");
852 return NOTI_EX_ERROR_INVALID_PARAMETER;
854 GroupItem* p = static_cast<GroupItem*>(h->Get());
855 list<shared_ptr<AbstractItem>> children = p->GetChildren();
856 LOGI("Retrive (%zd)", children.size());
857 for (auto i : children) {
859 static_cast<noti_ex_item_h>(new Handle(i)), data);
860 if (ret != NOTI_EX_ERROR_NONE) {
861 LOGW("callback return (%d) stop foreach", ret);
866 return NOTI_EX_ERROR_NONE;
869 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
870 const char *id, const char *image_path) {
873 if (handle == nullptr || image_path == nullptr) {
874 LOGE("Invalid parameter");
875 return NOTI_EX_ERROR_INVALID_PARAMETER;
879 p = new (std::nothrow) ImageItem(id, image_path);
881 p = new (std::nothrow) ImageItem(image_path);
884 LOGE("Out-of-memory");
885 return NOTI_EX_ERROR_OUT_OF_MEMORY;
888 *handle = new Handle(p);
890 return NOTI_EX_ERROR_NONE;
893 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
894 noti_ex_item_h handle, char **image_path) {
895 if (handle == nullptr || image_path == nullptr) {
896 LOGE("Invalid parameter");
897 return NOTI_EX_ERROR_INVALID_PARAMETER;
899 Handle* h = static_cast<Handle*>(handle);
900 if (!h->IsValidType(AbstractItem::Image)) {
901 LOGE("Invalid handle type");
902 return NOTI_EX_ERROR_INVALID_PARAMETER;
904 ImageItem* p = static_cast<ImageItem*>(h->Get());
905 if (!p->GetImagePath().empty()) {
906 *image_path = strdup(p->GetImagePath().c_str());
907 if (*image_path == nullptr) {
908 LOGE("Out-of-memory");
909 return NOTI_EX_ERROR_OUT_OF_MEMORY;
913 return NOTI_EX_ERROR_NONE;
916 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
917 noti_ex_item_h *handle, const char *id) {
918 InputSelectorItem* p;
920 if (handle == nullptr) {
921 LOGE("Invalid parameter");
922 return NOTI_EX_ERROR_INVALID_PARAMETER;
926 p = new (std::nothrow) InputSelectorItem(id);
928 p = new (std::nothrow) InputSelectorItem();
931 LOGE("Out-of-memory");
932 return NOTI_EX_ERROR_OUT_OF_MEMORY;
935 *handle = new Handle(p);
937 return NOTI_EX_ERROR_NONE;
940 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
941 noti_ex_item_h handle, char ***contents_list, int *count) {
942 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
943 LOGE("Invalid parameter");
944 return NOTI_EX_ERROR_INVALID_PARAMETER;
947 Handle* h = static_cast<Handle*>(handle);
948 if (!h->IsValidType(AbstractItem::InputSelector)) {
949 LOGE("Invalid handle type");
950 return NOTI_EX_ERROR_INVALID_PARAMETER;
952 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
953 list<string> contents = p->GetContents();
954 *contents_list = (char**)calloc(contents.size(), sizeof(char*));
956 for (auto& i : contents) {
957 *contents_list[idx++] = strdup(i.c_str());
959 *count = contents.size();
961 return NOTI_EX_ERROR_NONE;
964 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
965 noti_ex_item_h handle, const char **contents, int count) {
966 if (handle == nullptr || contents == nullptr) {
967 LOGE("Invalid parameter");
968 return NOTI_EX_ERROR_INVALID_PARAMETER;
971 list<string> new_contents;
972 Handle* h = static_cast<Handle*>(handle);
973 if (!h->IsValidType(AbstractItem::InputSelector)) {
974 LOGE("Invalid handle type");
975 return NOTI_EX_ERROR_INVALID_PARAMETER;
977 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
978 for (int i = 0; i < count; i++) {
979 new_contents.push_back(contents[i]);
981 p->SetContents(move(new_contents));
983 return NOTI_EX_ERROR_NONE;
986 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
987 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
988 if (handle == nullptr) {
989 LOGE("Invalid parameter");
990 return NOTI_EX_ERROR_INVALID_PARAMETER;
993 auto* p = new (std::nothrow) Color(a, r, g, b);
995 LOGE("Out-of-memory");
996 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1001 return NOTI_EX_ERROR_NONE;
1004 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1005 if (handle == nullptr) {
1006 LOGE("Invalid parameter");
1007 return NOTI_EX_ERROR_INVALID_PARAMETER;
1010 Color* p = static_cast<Color*>(handle);
1013 return NOTI_EX_ERROR_NONE;
1016 extern "C" EXPORT_API int noti_ex_color_get_alpha(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->GetAVal();
1026 return NOTI_EX_ERROR_NONE;
1029 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1030 unsigned char *val) {
1031 if (handle == nullptr || val == nullptr) {
1032 LOGE("Invalid parameter");
1033 return NOTI_EX_ERROR_INVALID_PARAMETER;
1036 Color* p = static_cast<Color*>(handle);
1037 *val = p->GetRVal();
1039 return NOTI_EX_ERROR_NONE;
1042 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1043 unsigned char *val) {
1044 if (handle == nullptr || val == nullptr) {
1045 LOGE("Invalid parameter");
1046 return NOTI_EX_ERROR_INVALID_PARAMETER;
1049 Color* p = static_cast<Color*>(handle);
1050 *val = p->GetGVal();
1052 return NOTI_EX_ERROR_NONE;
1055 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1056 unsigned char *val) {
1057 if (handle == nullptr || val == nullptr) {
1058 LOGE("Invalid parameter");
1059 return NOTI_EX_ERROR_INVALID_PARAMETER;
1062 Color* p = static_cast<Color*>(handle);
1063 *val = p->GetBVal();
1065 return NOTI_EX_ERROR_NONE;
1068 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1069 int left, int top, int right, int bottom) {
1070 if (handle == nullptr) {
1071 LOGE("Invalid parameter");
1072 return NOTI_EX_ERROR_INVALID_PARAMETER;
1075 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1077 LOGE("Out-of-memory");
1078 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1083 return NOTI_EX_ERROR_NONE;
1086 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1087 if (handle == nullptr) {
1088 LOGE("Invalid parameter");
1089 return NOTI_EX_ERROR_INVALID_PARAMETER;
1092 Padding* p = static_cast<Padding*>(handle);
1095 return NOTI_EX_ERROR_NONE;
1098 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1100 if (handle == nullptr || val == nullptr) {
1101 LOGE("Invalid parameter");
1102 return NOTI_EX_ERROR_INVALID_PARAMETER;
1105 Padding* p = static_cast<Padding*>(handle);
1106 *val = p->GetLeft();
1108 return NOTI_EX_ERROR_NONE;
1111 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1113 if (handle == nullptr || val == nullptr) {
1114 LOGE("Invalid parameter");
1115 return NOTI_EX_ERROR_INVALID_PARAMETER;
1118 Padding* p = static_cast<Padding*>(handle);
1121 return NOTI_EX_ERROR_NONE;
1124 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1126 if (handle == nullptr || val == nullptr) {
1127 LOGE("Invalid parameter");
1128 return NOTI_EX_ERROR_INVALID_PARAMETER;
1131 Padding* p = static_cast<Padding*>(handle);
1132 *val = p->GetRight();
1134 return NOTI_EX_ERROR_NONE;
1137 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1139 if (handle == nullptr || val == nullptr) {
1140 LOGE("Invalid parameter");
1141 return NOTI_EX_ERROR_INVALID_PARAMETER;
1144 Padding* p = static_cast<Padding*>(handle);
1145 *val = p->GetBottom();
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1151 int x, int y, int w, int h) {
1152 if (handle == nullptr) {
1153 LOGE("Invalid parameter");
1154 return NOTI_EX_ERROR_INVALID_PARAMETER;
1157 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1159 LOGE("Out-of-memory");
1160 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1165 return NOTI_EX_ERROR_NONE;
1168 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1169 if (handle == nullptr) {
1170 LOGE("Invalid parameter");
1171 return NOTI_EX_ERROR_INVALID_PARAMETER;
1174 Geometry* p = static_cast<Geometry*>(handle);
1177 return NOTI_EX_ERROR_NONE;
1180 extern "C" EXPORT_API int noti_ex_geometry_get_x(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);
1190 return NOTI_EX_ERROR_NONE;
1193 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1195 if (handle == nullptr || val == nullptr) {
1196 LOGE("Invalid parameter");
1197 return NOTI_EX_ERROR_INVALID_PARAMETER;
1200 Geometry* p = static_cast<Geometry*>(handle);
1203 return NOTI_EX_ERROR_NONE;
1206 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1208 if (handle == nullptr || val == nullptr) {
1209 LOGE("Invalid parameter");
1210 return NOTI_EX_ERROR_INVALID_PARAMETER;
1213 Geometry* p = static_cast<Geometry*>(handle);
1214 *val = p->GetWidth();
1216 return NOTI_EX_ERROR_NONE;
1219 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1221 if (handle == nullptr || val == nullptr) {
1222 LOGE("Invalid parameter");
1223 return NOTI_EX_ERROR_INVALID_PARAMETER;
1226 Geometry* p = static_cast<Geometry*>(handle);
1227 *val = p->GetHeight();
1229 return NOTI_EX_ERROR_NONE;
1232 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1233 noti_ex_color_h color,
1234 noti_ex_padding_h padding,
1235 noti_ex_geometry_h geometry) {
1236 if (handle == nullptr) {
1237 LOGE("Invalid parameter");
1238 return NOTI_EX_ERROR_INVALID_PARAMETER;
1241 Color* color_ = static_cast<Color*>(color);
1242 Padding* padding_ = static_cast<Padding*>(padding);
1243 Geometry* geo_ = static_cast<Geometry*>(geometry);
1245 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1247 LOGE("Out-of-memory");
1248 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1253 return NOTI_EX_ERROR_NONE;
1256 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1257 if (handle == nullptr) {
1258 LOGE("Invalid parameter");
1259 return NOTI_EX_ERROR_INVALID_PARAMETER;
1262 Style* p = static_cast<Style*>(handle);
1265 return NOTI_EX_ERROR_NONE;
1268 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1269 noti_ex_padding_h *padding) {
1270 if (handle == nullptr || padding == nullptr) {
1271 LOGE("Invalid parameter");
1272 return NOTI_EX_ERROR_INVALID_PARAMETER;
1275 Style* p = static_cast<Style*>(handle);
1276 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1277 if (padding_ == nullptr) {
1278 LOGE("Out-of-memory");
1279 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1282 *padding = padding_;
1284 return NOTI_EX_ERROR_NONE;
1287 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1288 noti_ex_color_h *color) {
1289 if (handle == nullptr || color == nullptr) {
1290 LOGE("Invalid parameter");
1291 return NOTI_EX_ERROR_INVALID_PARAMETER;
1294 Style* p = static_cast<Style*>(handle);
1295 Color* color_ = new (std::nothrow) Color(p->GetColor());
1296 if (color_ == nullptr) {
1297 LOGE("Out-of-memory");
1298 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1303 return NOTI_EX_ERROR_NONE;
1306 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1307 noti_ex_geometry_h *geometry) {
1308 if (handle == nullptr || geometry == nullptr) {
1309 LOGE("Invalid parameter");
1310 return NOTI_EX_ERROR_INVALID_PARAMETER;
1313 Style* p = static_cast<Style*>(handle);
1314 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1315 if (geo_ == nullptr) {
1316 LOGE("Out-of-memory");
1317 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1322 return NOTI_EX_ERROR_NONE;
1325 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1326 noti_ex_color_h color) {
1327 if (handle == nullptr) {
1328 LOGE("Invalid parameter");
1329 return NOTI_EX_ERROR_INVALID_PARAMETER;
1332 Color* color_ = static_cast<Color*>(color);
1333 auto* p = new (std::nothrow) LEDInfo(*color_);
1335 LOGE("Out-of-memory");
1336 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1341 return NOTI_EX_ERROR_NONE;
1344 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1345 if (handle == nullptr) {
1346 LOGE("Invalid parameter");
1347 return NOTI_EX_ERROR_INVALID_PARAMETER;
1350 LEDInfo* p = static_cast<LEDInfo*>(handle);
1353 return NOTI_EX_ERROR_NONE;
1356 extern "C" EXPORT_API int noti_ex_led_info_set_on_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);
1366 return NOTI_EX_ERROR_NONE;
1369 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1370 noti_ex_led_info_h handle, int *ms) {
1371 if (handle == nullptr || ms == nullptr) {
1372 LOGE("Invalid parameter");
1373 return NOTI_EX_ERROR_INVALID_PARAMETER;
1376 LEDInfo* p = static_cast<LEDInfo*>(handle);
1377 *ms = p->GetOnPeriod();
1379 return NOTI_EX_ERROR_NONE;
1382 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1383 noti_ex_led_info_h handle, int ms) {
1384 if (handle == nullptr) {
1385 LOGE("Invalid parameter");
1386 return NOTI_EX_ERROR_INVALID_PARAMETER;
1389 LEDInfo* p = static_cast<LEDInfo*>(handle);
1390 p->SetOffPeriod(ms);
1392 return NOTI_EX_ERROR_NONE;
1395 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1396 noti_ex_led_info_h handle, int *ms) {
1397 if (handle == nullptr) {
1398 LOGE("Invalid parameter");
1399 return NOTI_EX_ERROR_INVALID_PARAMETER;
1402 LEDInfo* p = static_cast<LEDInfo*>(handle);
1403 *ms = p->GetOffPeriod();
1405 return NOTI_EX_ERROR_NONE;
1408 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1409 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1410 if (handle == nullptr) {
1411 LOGE("Invalid parameter");
1412 return NOTI_EX_ERROR_INVALID_PARAMETER;
1415 LEDInfo* p = static_cast<LEDInfo*>(handle);
1416 Color* color_ = new (std::nothrow) Color(p->GetColor());
1417 if (color_ == nullptr) {
1418 LOGE("Out-of-memory");
1419 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1424 return NOTI_EX_ERROR_NONE;
1427 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1428 if (handle == nullptr) {
1429 LOGE("Invalid parameter");
1430 return NOTI_EX_ERROR_INVALID_PARAMETER;
1433 AbstractAction* p = static_cast<AbstractAction*>(handle);
1434 p->~AbstractAction();
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1441 if (handle == nullptr || type == nullptr) {
1442 LOGE("Invalid parameter");
1443 return NOTI_EX_ERROR_INVALID_PARAMETER;
1446 AbstractAction* p = static_cast<AbstractAction*>(handle);
1447 *type = p->GetType();
1449 return NOTI_EX_ERROR_NONE;
1452 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1454 if (handle == nullptr || local == nullptr) {
1455 LOGE("Invalid parameter");
1456 return NOTI_EX_ERROR_INVALID_PARAMETER;
1459 AbstractAction* p = static_cast<AbstractAction*>(handle);
1460 *local = p->IsLocal();
1462 return NOTI_EX_ERROR_NONE;
1465 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1466 noti_ex_item_h item) {
1467 if (handle == nullptr || item==nullptr) {
1468 LOGE("Invalid parameter");
1469 return NOTI_EX_ERROR_INVALID_PARAMETER;
1471 AbstractAction* p = static_cast<AbstractAction*>(handle);
1472 Handle* ih = static_cast<Handle*>(item);
1473 p->Execute(ih->GetPtr());
1475 return NOTI_EX_ERROR_NONE;
1478 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1480 if (handle == nullptr || extra == nullptr) {
1481 LOGE("Invalid parameter");
1482 return NOTI_EX_ERROR_INVALID_PARAMETER;
1485 AbstractAction* p = static_cast<AbstractAction*>(handle);
1486 if (!p->GetExtra().empty()) {
1487 *extra = strdup(p->GetExtra().c_str());
1488 if (*extra == nullptr) {
1489 LOGE("Out-of-memory");
1490 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1494 return NOTI_EX_ERROR_NONE;
1497 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1498 noti_ex_item_info_h handle, int *hide_time) {
1499 if (handle == nullptr || hide_time == nullptr) {
1500 LOGE("Invalid parameter");
1501 return NOTI_EX_ERROR_INVALID_PARAMETER;
1503 IItemInfo* p = static_cast<IItemInfo*>(handle);
1504 *hide_time = p->GetHideTime();
1505 return NOTI_EX_ERROR_NONE;
1508 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1509 noti_ex_item_info_h handle, int hide_time) {
1510 if (handle == nullptr) {
1511 LOGE("Invalid parameter");
1512 return NOTI_EX_ERROR_INVALID_PARAMETER;
1514 IItemInfo* p = static_cast<IItemInfo*>(handle);
1515 p->SetHideTime(hide_time);
1516 return NOTI_EX_ERROR_NONE;
1519 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1520 noti_ex_item_info_h handle, int *delete_time) {
1521 if (handle == nullptr || delete_time == nullptr) {
1522 LOGE("Invalid parameter");
1523 return NOTI_EX_ERROR_INVALID_PARAMETER;
1525 IItemInfo* p = static_cast<IItemInfo*>(handle);
1526 *delete_time = p->GetDeleteTime();
1527 return NOTI_EX_ERROR_NONE;
1530 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1531 noti_ex_item_info_h handle, int delete_time) {
1532 if (handle == nullptr) {
1533 LOGE("Invalid parameter");
1534 return NOTI_EX_ERROR_INVALID_PARAMETER;
1536 IItemInfo* p = static_cast<IItemInfo*>(handle);
1537 p->SetDeleteTime(delete_time);
1538 return NOTI_EX_ERROR_NONE;
1541 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1542 noti_ex_item_info_h handle, time_t *time) {
1543 if (handle == nullptr || time == nullptr) {
1544 LOGE("Invalid parameter");
1545 return NOTI_EX_ERROR_INVALID_PARAMETER;
1548 IItemInfo* p = static_cast<IItemInfo*>(handle);
1549 *time = p->GetTime();
1550 return NOTI_EX_ERROR_NONE;
1553 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1554 if (handle == nullptr) {
1555 LOGE("Invalid parameter");
1556 return NOTI_EX_ERROR_INVALID_PARAMETER;
1559 Handle* h = static_cast<Handle*>(handle);
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1565 const char *id, noti_ex_item_h *item) {
1566 if (handle == nullptr) {
1567 LOGE("Invalid parameter");
1568 return NOTI_EX_ERROR_INVALID_PARAMETER;
1571 Handle* p = static_cast<Handle*>(handle);
1572 AbstractItem& find_item = p->Get()->FindByID(string(id));
1573 *item = new Handle(&find_item);
1574 return NOTI_EX_ERROR_NONE;
1577 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1579 if (handle == nullptr || type == nullptr) {
1580 LOGE("Invalid parameter");
1581 return NOTI_EX_ERROR_INVALID_PARAMETER;
1584 Handle* h = static_cast<Handle*>(handle);
1585 AbstractItem* p = h->Get();
1586 *type = p->GetType();
1587 return NOTI_EX_ERROR_NONE;
1590 extern "C" EXPORT_API int noti_ex_item_get_shared_path(noti_ex_item_h handle,
1591 char ***path, int *count) {
1592 if (handle == nullptr || path == nullptr || count == nullptr) {
1593 LOGE("Invalid parameter");
1594 return NOTI_EX_ERROR_INVALID_PARAMETER;
1596 Handle* p = static_cast<Handle*>(handle);
1597 list<string> shared_path = p->Get()->GetSharedPath();
1598 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1600 for (auto& i : shared_path) {
1601 *path[idx++] = strdup(i.c_str());
1603 *count = shared_path.size();
1604 return NOTI_EX_ERROR_NONE;
1607 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1609 if (handle == nullptr || id == nullptr) {
1610 LOGE("Invalid parameter");
1611 return NOTI_EX_ERROR_INVALID_PARAMETER;
1613 Handle* h = static_cast<Handle*>(handle);
1614 AbstractItem* p = h->Get();
1615 *id = strdup(p->GetId().c_str());
1616 return NOTI_EX_ERROR_NONE;
1619 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1621 if (handle == nullptr || id == nullptr) {
1622 LOGE("Invalid parameter");
1623 return NOTI_EX_ERROR_INVALID_PARAMETER;
1625 Handle* p = static_cast<Handle*>(handle);
1626 p->Get()->SetId(id);
1627 return NOTI_EX_ERROR_NONE;
1630 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1631 noti_ex_action_h *action) {
1632 if (handle == nullptr || action == nullptr) {
1633 LOGE("Invalid parameter");
1634 return NOTI_EX_ERROR_INVALID_PARAMETER;
1636 Handle* p = static_cast<Handle*>(handle);
1637 if (p->Get()->GetAction() == nullptr) {
1639 return NOTI_EX_ERROR_NONE;
1641 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1643 return NOTI_EX_ERROR_NONE;
1646 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1647 noti_ex_action_h action) {
1648 if (handle == nullptr || action == nullptr) {
1649 LOGE("Invalid parameter");
1650 return NOTI_EX_ERROR_INVALID_PARAMETER;
1653 Handle* p = static_cast<Handle*>(handle);
1654 AbstractAction* a = static_cast<AbstractAction*>(action);
1655 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1656 return NOTI_EX_ERROR_NONE;
1659 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1660 noti_ex_style_h *style) {
1661 if (handle == nullptr || style == nullptr) {
1662 LOGE("Invalid parameter");
1663 return NOTI_EX_ERROR_INVALID_PARAMETER;
1666 Handle* p = static_cast<Handle*>(handle);
1667 shared_ptr<Style> s = p->Get()->GetStyle();
1668 *style = static_cast<noti_ex_style_h>(s.get());
1669 return NOTI_EX_ERROR_NONE;
1672 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1673 noti_ex_style_h style) {
1674 if (handle == nullptr || style == nullptr) {
1675 LOGE("Invalid parameter");
1676 return NOTI_EX_ERROR_INVALID_PARAMETER;
1679 Handle* p = static_cast<Handle*>(handle);
1680 Style* s = static_cast<Style*>(style);
1681 p->Get()->SetStyle(shared_ptr<Style>(s));
1682 return NOTI_EX_ERROR_NONE;
1685 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1687 if (handle == nullptr) {
1688 LOGE("Invalid parameter");
1689 return NOTI_EX_ERROR_INVALID_PARAMETER;
1692 Handle* p = static_cast<Handle*>(handle);
1693 p->Get()->SetVisible(visible);
1694 return NOTI_EX_ERROR_NONE;
1697 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1699 if (handle == nullptr || visible == nullptr) {
1700 LOGE("Invalid parameter");
1701 return NOTI_EX_ERROR_INVALID_PARAMETER;
1704 Handle* p = static_cast<Handle*>(handle);
1705 *visible = p->Get()->GetVisible();
1706 return NOTI_EX_ERROR_NONE;
1709 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1711 if (handle == nullptr) {
1712 LOGE("Invalid parameter");
1713 return NOTI_EX_ERROR_INVALID_PARAMETER;
1716 Handle* p = static_cast<Handle*>(handle);
1717 p->Get()->SetEnable(enable);
1718 return NOTI_EX_ERROR_NONE;
1721 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1723 if (handle == nullptr || enable == nullptr) {
1724 LOGE("Invalid parameter");
1725 return NOTI_EX_ERROR_INVALID_PARAMETER;
1728 Handle* p = static_cast<Handle*>(handle);
1729 *enable = p->Get()->GetEnable();
1730 return NOTI_EX_ERROR_NONE;
1733 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1734 const char *receiver_group) {
1735 if (handle == nullptr || receiver_group == nullptr) {
1736 LOGE("Invalid parameter");
1737 return NOTI_EX_ERROR_INVALID_PARAMETER;
1740 Handle* p = static_cast<Handle*>(handle);
1741 p->Get()->AddReceiver(receiver_group);
1742 return NOTI_EX_ERROR_NONE;
1745 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1746 const char *receiver_group) {
1747 if (handle == nullptr || receiver_group == nullptr) {
1748 LOGE("Invalid parameter");
1749 return NOTI_EX_ERROR_INVALID_PARAMETER;
1752 Handle* p = static_cast<Handle*>(handle);
1753 p->Get()->RemoveReceiver(receiver_group);
1754 return NOTI_EX_ERROR_NONE;
1757 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1758 char ***receiver_list, int *count) {
1759 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1760 LOGE("Invalid parameter");
1761 return NOTI_EX_ERROR_INVALID_PARAMETER;
1764 Handle* p = static_cast<Handle*>(handle);
1765 list<string> receivers = p->Get()->GetReceiverList();
1766 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1768 for (auto& i : receivers) {
1769 *receiver_list[idx++] = strdup(i.c_str());
1771 *count = receivers.size();
1772 return NOTI_EX_ERROR_NONE;
1775 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1777 if (handle == nullptr) {
1778 LOGE("Invalid parameter");
1779 return NOTI_EX_ERROR_INVALID_PARAMETER;
1782 Handle* p = static_cast<Handle*>(handle);
1783 p->Get()->SetPolicy(policy);
1784 return NOTI_EX_ERROR_NONE;
1787 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1789 if (handle == nullptr || policy == nullptr) {
1790 LOGE("Invalid parameter");
1791 return NOTI_EX_ERROR_INVALID_PARAMETER;
1794 Handle* p = static_cast<Handle*>(handle);
1795 *policy = p->Get()->GetPolicy();
1796 return NOTI_EX_ERROR_NONE;
1799 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1801 if (handle == nullptr || channel == nullptr) {
1802 LOGE("Invalid parameter");
1803 return NOTI_EX_ERROR_INVALID_PARAMETER;
1806 Handle* p = static_cast<Handle*>(handle);
1807 if (!p->Get()->GetChannel().empty())
1808 *channel = strdup(p->Get()->GetChannel().c_str());
1812 return NOTI_EX_ERROR_NONE;
1815 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1816 const char *channel) {
1817 if (handle == nullptr) {
1818 LOGE("Invalid parameter");
1819 return NOTI_EX_ERROR_INVALID_PARAMETER;
1822 Handle* p = static_cast<Handle*>(handle);
1823 p->Get()->SetChannel(channel);
1824 return NOTI_EX_ERROR_NONE;
1827 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1828 noti_ex_led_info_h led) {
1829 if (handle == nullptr) {
1830 LOGE("Invalid parameter");
1831 return NOTI_EX_ERROR_INVALID_PARAMETER;
1834 Handle* p = static_cast<Handle*>(handle);
1835 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1836 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1837 return NOTI_EX_ERROR_NONE;
1840 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1841 noti_ex_led_info_h *led) {
1842 if (handle == nullptr) {
1843 LOGE("Invalid parameter");
1844 return NOTI_EX_ERROR_INVALID_PARAMETER;
1847 Handle* p = static_cast<Handle*>(handle);
1848 if (p->Get()->GetLEDInfo() != nullptr)
1849 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1852 return NOTI_EX_ERROR_NONE;
1855 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1857 if (handle == nullptr) {
1858 LOGE("Invalid parameter");
1859 return NOTI_EX_ERROR_INVALID_PARAMETER;
1862 Handle* p = static_cast<Handle*>(handle);
1863 if (path == nullptr)
1864 p->Get()->SetSoundPath("");
1866 p->Get()->SetSoundPath(path);
1867 return NOTI_EX_ERROR_NONE;
1870 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1872 if (handle == nullptr) {
1873 LOGE("Invalid parameter");
1874 return NOTI_EX_ERROR_INVALID_PARAMETER;
1877 Handle* p = static_cast<Handle*>(handle);
1878 if (path == nullptr)
1879 p->Get()->SetVibrationPath("");
1881 p->Get()->SetVibrationPath(path);
1882 return NOTI_EX_ERROR_NONE;
1885 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1887 if (handle == nullptr || path == nullptr) {
1888 LOGE("Invalid parameter");
1889 return NOTI_EX_ERROR_INVALID_PARAMETER;
1892 Handle* p = static_cast<Handle*>(handle);
1893 if (p->Get()->GetSoundPath().empty())
1896 *path = strdup(p->Get()->GetSoundPath().c_str());
1897 return NOTI_EX_ERROR_NONE;
1900 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1902 if (handle == nullptr || path == nullptr) {
1903 LOGE("Invalid parameter");
1904 return NOTI_EX_ERROR_INVALID_PARAMETER;
1907 Handle* p = static_cast<Handle*>(handle);
1908 if (p->Get()->GetVibrationPath().empty())
1911 *path = strdup(p->Get()->GetVibrationPath().c_str());
1912 return NOTI_EX_ERROR_NONE;
1915 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1916 noti_ex_item_info_h *info) {
1917 if (handle == nullptr || info == nullptr) {
1918 LOGE("Invalid parameter");
1919 return NOTI_EX_ERROR_INVALID_PARAMETER;
1922 Handle* p = static_cast<Handle*>(handle);
1923 if (p->Get()->GetInfo() == nullptr)
1926 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1927 return NOTI_EX_ERROR_NONE;
1930 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1932 if (handle == nullptr || id == nullptr) {
1933 LOGE("Invalid parameter");
1934 return NOTI_EX_ERROR_INVALID_PARAMETER;
1937 Handle* p = static_cast<Handle*>(handle);
1938 if (p->Get()->GetSenderAppId().empty())
1941 *id = strdup(p->Get()->GetSenderAppId().c_str());
1942 return NOTI_EX_ERROR_NONE;
1945 extern "C" EXPORT_API int noti_ex_item_set_sender_app_id(noti_ex_item_h handle,
1947 if (handle == nullptr) {
1948 LOGE("Invalid parameter");
1949 return NOTI_EX_ERROR_INVALID_PARAMETER;
1952 Handle* p = static_cast<Handle*>(handle);
1954 p->Get()->SetSenderAppId("");
1956 p->Get()->SetSenderAppId(id);
1957 return NOTI_EX_ERROR_NONE;
1960 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1962 if (handle == nullptr || tag == nullptr) {
1963 LOGE("Invalid parameter");
1964 return NOTI_EX_ERROR_INVALID_PARAMETER;
1967 Handle* p = static_cast<Handle*>(handle);
1968 if (p->Get()->GetTag().empty())
1971 *tag = strdup(p->Get()->GetTag().c_str());
1972 return NOTI_EX_ERROR_NONE;
1975 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1977 if (handle == nullptr) {
1978 LOGE("Invalid parameter");
1979 return NOTI_EX_ERROR_INVALID_PARAMETER;
1982 Handle* p = static_cast<Handle*>(handle);
1984 p->Get()->SetTag("");
1986 p->Get()->SetTag(tag);
1987 return NOTI_EX_ERROR_NONE;
1990 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1991 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1993 if (handle == nullptr) {
1994 LOGE("Invalid parameter");
1995 return NOTI_EX_ERROR_INVALID_PARAMETER;
1998 ManagerStub* stub = new (std::nothrow) ManagerStub(
1999 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2000 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2002 if (stub == nullptr) {
2003 LOGE("Fail to create manager");
2004 return NOTI_EX_ERROR_IO_ERROR;
2006 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2007 new ManagerCallbackInfo(event_callbacks, data)));
2008 *handle = static_cast<noti_ex_manager_h>(stub);
2010 return NOTI_EX_ERROR_NONE;
2013 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2014 if (handle == nullptr) {
2015 LOGE("Invalid parameter");
2016 return NOTI_EX_ERROR_INVALID_PARAMETER;
2018 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2020 return NOTI_EX_ERROR_NONE;
2023 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2024 noti_ex_item_h **items, int *count) {
2025 if (handle == nullptr || items == nullptr || count == nullptr) {
2026 LOGE("Invalid parameter");
2027 return NOTI_EX_ERROR_INVALID_PARAMETER;
2031 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2032 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2033 if (item_list.size() == 0) {
2036 return NOTI_EX_ERROR_NONE;
2038 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2039 if (*items == nullptr) {
2040 LOGE("Fail to create items");
2041 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2045 for (auto& i : item_list) {
2046 *items[idx++] = new Handle(move(i));
2048 *count = item_list.size();
2049 } catch (Exception &ex) {
2050 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2051 return NOTI_EX_ERROR_IO_ERROR;
2053 return NOTI_EX_ERROR_NONE;
2056 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2057 noti_ex_item_h noti, int *request_id) {
2058 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2059 LOGE("Invalid parameter");
2060 return NOTI_EX_ERROR_INVALID_PARAMETER;
2063 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2064 Handle* sp = static_cast<Handle*>(noti);
2065 if (sp->GetPtr().get() == nullptr) {
2066 LOGE("Invalid noti reference can not be sended");
2067 return NOTI_EX_ERROR_INVALID_PARAMETER;
2069 *request_id = stub->Update(sp->GetPtr());
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_delete(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->Delete(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_delete_all(noti_ex_manager_h handle,
2102 if (handle == nullptr || request_id == nullptr) {
2103 LOGE("Invalid parameter");
2104 return NOTI_EX_ERROR_INVALID_PARAMETER;
2107 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2108 *request_id = stub->DeleteAll();
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_hide(noti_ex_manager_h handle,
2117 noti_ex_item_h noti, int *request_id) {
2118 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2119 LOGE("Invalid parameter");
2120 return NOTI_EX_ERROR_INVALID_PARAMETER;
2123 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2124 Handle* item = static_cast<Handle*>(noti);
2125 if (item->GetPtr().get() == nullptr) {
2126 LOGE("Invalid noti reference can not be sended");
2127 return NOTI_EX_ERROR_INVALID_PARAMETER;
2129 *request_id = stub->Hide(item->GetPtr());
2131 } catch (Exception &ex) {
2132 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2133 return NOTI_EX_ERROR_IO_ERROR;
2135 return NOTI_EX_ERROR_NONE;
2138 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2139 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2140 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2141 LOGE("Invalid parameter");
2142 return NOTI_EX_ERROR_INVALID_PARAMETER;
2145 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2146 *item = new Handle(stub->FindByRootID(root_id));
2147 } catch (Exception &ex) {
2148 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2149 return NOTI_EX_ERROR_IO_ERROR;
2151 return NOTI_EX_ERROR_NONE;
2154 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2155 noti_ex_event_info_h info, noti_ex_error_e error) {
2156 if (handle == nullptr || info == nullptr) {
2157 LOGE("Invalid parameter");
2158 return NOTI_EX_ERROR_INVALID_PARAMETER;
2161 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2162 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2163 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2164 static_cast<NotificationError>(error));
2165 } catch (Exception &ex) {
2166 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2167 return NOTI_EX_ERROR_IO_ERROR;
2169 return NOTI_EX_ERROR_NONE;
2172 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2175 if (handle == nullptr || cnt == nullptr) {
2176 LOGE("Invalid parameter");
2177 return NOTI_EX_ERROR_INVALID_PARAMETER;
2180 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2181 *cnt = stub->GetCount();
2182 } catch (Exception &ex) {
2183 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2184 return NOTI_EX_ERROR_IO_ERROR;
2186 return NOTI_EX_ERROR_NONE;
2189 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2190 const char *id, float min, float current, float max) {
2193 if (handle == nullptr) {
2194 LOGE("Invalid parameter");
2195 return NOTI_EX_ERROR_INVALID_PARAMETER;
2199 p = new (std::nothrow) ProgressItem(id, min, current, max);
2201 p = new (std::nothrow) ProgressItem(min, current, max);
2204 LOGE("Out-of-memory");
2205 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2208 *handle = new Handle(p);
2210 return NOTI_EX_ERROR_NONE;
2213 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2214 noti_ex_item_h handle, float *current) {
2215 if (handle == nullptr || current == nullptr) {
2216 LOGE("Invalid parameter");
2217 return NOTI_EX_ERROR_INVALID_PARAMETER;
2220 Handle *h = static_cast<Handle*>(handle);
2221 if (!h->IsValidType(AbstractItem::Progress)) {
2222 LOGE("Invalid handle type");
2223 return NOTI_EX_ERROR_INVALID_PARAMETER;
2225 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2226 *current = p->GetCurrent();
2228 return NOTI_EX_ERROR_NONE;
2231 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2232 noti_ex_item_h handle, float current) {
2233 if (handle == nullptr) {
2234 LOGE("Invalid parameter");
2235 return NOTI_EX_ERROR_INVALID_PARAMETER;
2238 Handle *h = static_cast<Handle*>(handle);
2239 if (!h->IsValidType(AbstractItem::Progress)) {
2240 LOGE("Invalid handle type");
2241 return NOTI_EX_ERROR_INVALID_PARAMETER;
2243 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2244 p->SetCurrent(current);
2246 return NOTI_EX_ERROR_NONE;
2249 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2251 if (handle == nullptr || min == nullptr) {
2252 LOGE("Invalid parameter");
2253 return NOTI_EX_ERROR_INVALID_PARAMETER;
2256 Handle *h = static_cast<Handle*>(handle);
2257 if (!h->IsValidType(AbstractItem::Progress)) {
2258 LOGE("Invalid handle type");
2259 return NOTI_EX_ERROR_INVALID_PARAMETER;
2261 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2264 return NOTI_EX_ERROR_NONE;
2267 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2269 if (handle == nullptr || max == nullptr) {
2270 LOGE("Invalid parameter");
2271 return NOTI_EX_ERROR_INVALID_PARAMETER;
2274 Handle *h = static_cast<Handle*>(handle);
2275 if (!h->IsValidType(AbstractItem::Progress)) {
2276 LOGE("Invalid handle type");
2277 return NOTI_EX_ERROR_INVALID_PARAMETER;
2279 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2282 return NOTI_EX_ERROR_NONE;
2285 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2286 noti_ex_reporter_events_s event_callbacks, void *data) {
2287 if (handle == nullptr) {
2288 LOGE("Invalid parameter");
2289 return NOTI_EX_ERROR_INVALID_PARAMETER;
2292 ReporterStub* stub = new (std::nothrow) ReporterStub(
2293 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2294 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2295 if (stub == nullptr) {
2296 LOGE("Fail to create manager");
2297 return NOTI_EX_ERROR_IO_ERROR;
2299 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2300 new ReporterCallbackInfo(event_callbacks, data)));
2302 *handle = static_cast<noti_ex_reporter_h>(stub);
2304 return NOTI_EX_ERROR_NONE;
2307 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2308 if (handle == nullptr) {
2309 LOGE("Invalid parameter");
2310 return NOTI_EX_ERROR_INVALID_PARAMETER;
2312 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2314 return NOTI_EX_ERROR_NONE;
2317 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2318 noti_ex_event_info_h info, noti_ex_error_e error) {
2319 if (handle == nullptr || info == nullptr) {
2320 LOGE("Invalid parameter");
2321 return NOTI_EX_ERROR_INVALID_PARAMETER;
2324 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2325 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2326 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2327 static_cast<NotificationError>(error));
2328 } catch (Exception &ex) {
2329 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2330 return NOTI_EX_ERROR_IO_ERROR;
2332 return NOTI_EX_ERROR_NONE;
2335 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2336 noti_ex_item_h noti, int *request_id) {
2337 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2338 LOGE("Invalid parameter");
2339 return NOTI_EX_ERROR_INVALID_PARAMETER;
2342 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2343 Handle* h = static_cast<Handle*>(noti);
2344 if (h->GetPtr().get() == nullptr) {
2345 LOGE("Invalid noti reference can not be sended");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2348 *request_id = stub->Post(h->GetPtr());
2350 } catch (Exception &ex) {
2351 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2352 return NOTI_EX_ERROR_IO_ERROR;
2354 return NOTI_EX_ERROR_NONE;
2357 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2358 noti_ex_item_h *noti_list, int count, int *request_id) {
2360 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2361 LOGE("Invalid parameter");
2362 return NOTI_EX_ERROR_INVALID_PARAMETER;
2365 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2366 list<shared_ptr<item::AbstractItem>> notiList;
2367 for (int i = 0; i < count; i++) {
2368 Handle* item = static_cast<Handle*>(noti_list[i]);
2369 notiList.emplace_back(item->GetPtr());
2371 *request_id = stub->Post(notiList);
2372 } catch (Exception &ex) {
2373 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2374 return NOTI_EX_ERROR_IO_ERROR;
2376 return NOTI_EX_ERROR_NONE;
2379 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2380 noti_ex_item_h noti, int *request_id) {
2381 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2382 LOGE("Invalid parameter");
2383 return NOTI_EX_ERROR_INVALID_PARAMETER;
2386 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2387 Handle* item = static_cast<Handle*>(noti);
2388 if (item->GetPtr().get() == nullptr) {
2389 LOGE("Invalid noti reference can not be sended");
2390 return NOTI_EX_ERROR_INVALID_PARAMETER;
2392 *request_id = stub->Update(item->GetPtr());
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_delete(noti_ex_reporter_h handle,
2402 noti_ex_item_h noti, int *request_id) {
2403 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2404 LOGE("Invalid parameter");
2405 return NOTI_EX_ERROR_INVALID_PARAMETER;
2408 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2409 Handle* item = static_cast<Handle*>(noti);
2410 if (item->GetPtr().get() == nullptr) {
2411 LOGE("Invalid noti reference can not be sended");
2412 return NOTI_EX_ERROR_INVALID_PARAMETER;
2414 *request_id = stub->Delete(item->GetPtr());
2416 } catch (Exception &ex) {
2417 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2418 return NOTI_EX_ERROR_IO_ERROR;
2420 return NOTI_EX_ERROR_NONE;
2423 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2424 noti_ex_reporter_h handle, int *request_id) {
2425 if (handle == nullptr || request_id == nullptr) {
2426 LOGE("Invalid parameter");
2427 return NOTI_EX_ERROR_INVALID_PARAMETER;
2430 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2431 *request_id = stub->DeleteAll();
2432 } catch (Exception &ex) {
2433 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2434 return NOTI_EX_ERROR_IO_ERROR;
2436 return NOTI_EX_ERROR_NONE;
2439 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2440 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2441 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2442 LOGE("Invalid parameter");
2443 return NOTI_EX_ERROR_INVALID_PARAMETER;
2446 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2447 *item = new Handle(stub->FindByRootID(root_id));
2448 } catch (Exception &ex) {
2449 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2450 return NOTI_EX_ERROR_IO_ERROR;
2452 return NOTI_EX_ERROR_NONE;
2455 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2456 const char *id, const char *text, const char *hyper_link) {
2457 if (handle == nullptr) {
2458 LOGE("Invalid parameter");
2459 return NOTI_EX_ERROR_INVALID_PARAMETER;
2462 auto* p = new (std::nothrow) TextItem(id, std::string(text),
2463 std::string(hyper_link));
2465 LOGE("Out-of-memory");
2466 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2469 *handle = new Handle(p);
2471 return NOTI_EX_ERROR_NONE;
2474 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2475 const char *contents) {
2476 if (handle == nullptr) {
2477 LOGE("Invalid parameter");
2478 return NOTI_EX_ERROR_INVALID_PARAMETER;
2481 Handle* p = static_cast<Handle*>(handle);
2482 if (!p->IsValidType(AbstractItem::Text)) {
2483 LOGE("Invalid handle type");
2484 return NOTI_EX_ERROR_INVALID_PARAMETER;
2486 TextItem* ti = static_cast<TextItem*>(p->Get());
2487 ti->SetContents(std::string(contents));
2489 return NOTI_EX_ERROR_NONE;
2492 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2494 if (handle == nullptr || contents == nullptr) {
2495 LOGE("Invalid parameter");
2496 return NOTI_EX_ERROR_INVALID_PARAMETER;
2499 Handle* p = static_cast<Handle*>(handle);
2500 if (!p->IsValidType(AbstractItem::Text)) {
2501 LOGE("Invalid handle type");
2502 return NOTI_EX_ERROR_INVALID_PARAMETER;
2504 TextItem* ti = static_cast<TextItem*>(p->Get());
2505 if (!ti->GetContents().empty()) {
2506 *contents = strdup(ti->GetContents().c_str());
2507 if (*contents == nullptr) {
2508 LOGE("Out-of-memory");
2509 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2513 return NOTI_EX_ERROR_NONE;
2516 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2517 noti_ex_item_h handle, char **hyper_link) {
2518 if (handle == nullptr || hyper_link == nullptr) {
2519 LOGE("Invalid parameter");
2520 return NOTI_EX_ERROR_INVALID_PARAMETER;
2523 Handle* p = static_cast<Handle*>(handle);
2524 if (!p->IsValidType(AbstractItem::Text)) {
2525 LOGE("Invalid handle type");
2526 return NOTI_EX_ERROR_INVALID_PARAMETER;
2528 TextItem* ti = static_cast<TextItem*>(p->Get());
2529 if (!ti->GetHyperLink().empty()) {
2530 *hyper_link = strdup(ti->GetHyperLink().c_str());
2531 if (*hyper_link == nullptr) {
2532 LOGE("Out-of-memory");
2533 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2537 return NOTI_EX_ERROR_NONE;
2540 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2541 const char *id, time_t time) {
2544 if (handle == nullptr) {
2545 LOGE("Invalid parameter");
2546 return NOTI_EX_ERROR_INVALID_PARAMETER;
2551 p = new (std::nothrow) TimeItem(id, time);
2553 p = new (std::nothrow) TimeItem(time);
2555 p = new (std::nothrow) TimeItem();
2559 LOGE("Out-of-memory");
2560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2563 *handle = new Handle(p);
2565 return NOTI_EX_ERROR_NONE;
2568 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2570 if (handle == nullptr || time == nullptr) {
2571 LOGE("Invalid parameter");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2574 Handle* h = static_cast<Handle*>(handle);
2575 if (!h->IsValidType(AbstractItem::Time)) {
2576 LOGE("Invalid handle type");
2577 return NOTI_EX_ERROR_INVALID_PARAMETER;
2579 TimeItem* p = static_cast<TimeItem*>(h->Get());
2580 *time = p->GetTime();
2582 return NOTI_EX_ERROR_NONE;
2585 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2586 noti_ex_action_h *handle, const char *extra) {
2587 if (handle == nullptr) {
2588 LOGE("Invalid parameter");
2589 return NOTI_EX_ERROR_INVALID_PARAMETER;
2592 auto* p = new (std::nothrow) VisibilityAction(extra);
2594 LOGE("Out-of-memory");
2595 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2600 return NOTI_EX_ERROR_NONE;
2603 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2604 const char *id, bool visible) {
2605 if (handle == nullptr || id == nullptr) {
2606 LOGE("Invalid parameter");
2607 return NOTI_EX_ERROR_INVALID_PARAMETER;
2610 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2611 p->SetVisibility(id, visible);
2613 return NOTI_EX_ERROR_NONE;