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;
112 void InvokeAdded(Manager* manager, const IEventInfo& info,
113 list<shared_ptr<AbstractItem>> addedItem) {
115 noti_ex_item_h* added_item =
116 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
117 if (added_item == nullptr) {
118 LOGE("Out of memory");
123 for (auto& i : addedItem) {
125 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
128 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
129 cb_.added(static_cast<noti_ex_manager_h>(manager),
130 static_cast<noti_ex_event_info_h>(c_info), added_item,
131 addedItem.size(), user_data_);
135 void InvokeUpdated(Manager* manager, const IEventInfo& info,
136 shared_ptr<item::AbstractItem> updatedItem) {
137 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
138 cb_.updated(static_cast<noti_ex_manager_h>(manager),
139 static_cast<noti_ex_event_info_h>(c_info),
140 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
143 void InvokeDeleted(Manager* manager, const IEventInfo& info,
144 shared_ptr<item::AbstractItem> deletedItem) {
145 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
146 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
147 static_cast<noti_ex_event_info_h>(c_info),
148 static_cast<noti_ex_item_h>(
149 new Handle(deletedItem)), user_data_);
152 void InvokeError(Manager* manager, NotificationError error, int requestId) {
153 cb_.error(static_cast<noti_ex_manager_h>(manager),
154 static_cast<noti_ex_error_e>(error), requestId, user_data_);
158 noti_ex_manager_events_s cb_;
162 class ManagerStub : public Manager {
164 ManagerStub(std::unique_ptr<IEventSender> sender,
165 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
166 : Manager(move(sender), move(listener), receiver_group) {
169 void OnAdd(const IEventInfo& info,
170 list<shared_ptr<AbstractItem>> addedItem) override {
171 cb_->InvokeAdded(this, info, addedItem);
175 void OnUpdate(const IEventInfo& info,
176 std::shared_ptr<item::AbstractItem> updatedItem) override {
177 cb_->InvokeUpdated(this, info, updatedItem);
180 void OnDelete(const IEventInfo& info,
181 shared_ptr<item::AbstractItem> deletedItem) override {
182 cb_->InvokeDeleted(this, info, deletedItem);
185 void OnError(NotificationError error, int requestId) override {
186 cb_->InvokeError(this, error, requestId);
189 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
191 return NOTI_EX_ERROR_NONE;
194 int ClearManagerCallbackInfo() {
196 return NOTI_EX_ERROR_NONE;
200 unique_ptr<ManagerCallbackInfo> cb_;
204 class ReporterCallbackInfo {
206 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
207 : user_data_(user_data) {
208 cb_.event = cb.event;
209 cb_.error = cb.error;
212 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
213 list<shared_ptr<AbstractItem>> notiList) {
215 noti_ex_item_h* noti_list =
216 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
217 if (noti_list == nullptr) {
218 LOGE("Out of memory");
223 for (auto& i : notiList) {
225 static_cast<noti_ex_item_h>(new Handle(i));
228 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
229 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
230 static_cast<noti_ex_event_info_h>(c_info), noti_list,
231 notiList.size(), user_data_);
235 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
236 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
237 static_cast<noti_ex_error_e>(error), requestId, user_data_);
241 noti_ex_reporter_events_s cb_;
245 class ReporterStub : public Reporter {
247 ReporterStub(std::unique_ptr<IEventSender> sender,
248 std::unique_ptr<IEventListener> listener)
249 : Reporter(move(sender), move(listener)) {
252 void OnEvent(const IEventInfo& info,
253 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
254 cb_->InvokeEvent(this, info, notiList);
257 void OnError(NotificationError error, int requestId) override {
258 cb_->InvokeError(this, error, requestId);
261 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
263 return NOTI_EX_ERROR_NONE;
266 int ClearReporterCallbackInfo() {
268 return NOTI_EX_ERROR_NONE;
272 unique_ptr<ReporterCallbackInfo> cb_;
276 extern "C" EXPORT_API int noti_ex_action_app_control_create(
277 noti_ex_action_h *handle, app_control_h app_control,
279 if (handle == nullptr || app_control == nullptr) {
280 LOGE("Invalid parameter");
281 return NOTI_EX_ERROR_INVALID_PARAMETER;
284 auto* p = new (std::nothrow) AppControlAction(app_control, extra);
286 LOGE("Out-of-memory");
287 return NOTI_EX_ERROR_OUT_OF_MEMORY;
292 return NOTI_EX_ERROR_NONE;
295 extern "C" EXPORT_API int noti_ex_action_app_control_set(
296 noti_ex_action_h handle, app_control_h app_control) {
297 if (handle == nullptr || app_control == nullptr) {
298 LOGE("Invalid parameter");
299 return NOTI_EX_ERROR_INVALID_PARAMETER;
302 AppControlAction* p = static_cast<AppControlAction*>(handle);
303 p->SetAppControl(app_control);
305 return NOTI_EX_ERROR_NONE;
308 extern "C" EXPORT_API int noti_ex_action_app_control_get(
309 noti_ex_action_h handle, app_control_h *app_control) {
310 if (handle == nullptr || app_control == nullptr) {
311 LOGE("Invalid parameter");
312 return NOTI_EX_ERROR_INVALID_PARAMETER;
315 AppControlAction* p = static_cast<AppControlAction*>(handle);
316 *app_control = p->GetAppControl();
318 return NOTI_EX_ERROR_NONE;
321 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
322 const char *id, const char *title) {
325 if (handle == nullptr || title == nullptr) {
326 LOGE("Invalid parameter");
327 return NOTI_EX_ERROR_INVALID_PARAMETER;
331 p = new (std::nothrow) ButtonItem(id, title);
333 p = new (std::nothrow) ButtonItem(title);
336 LOGE("Out-of-memory");
337 return NOTI_EX_ERROR_OUT_OF_MEMORY;
339 *handle = new Handle(shared_ptr<AbstractItem>(p));
341 return NOTI_EX_ERROR_NONE;
344 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
346 if (handle == nullptr || title == nullptr) {
347 LOGE("Invalid parameter");
348 return NOTI_EX_ERROR_INVALID_PARAMETER;
351 Handle* sp = static_cast<Handle*>(handle);
352 if (!sp->IsValidType(AbstractItem::Button)) {
353 LOGE("Invalid handle type");
354 return NOTI_EX_ERROR_INVALID_PARAMETER;
356 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
357 if (!p->GetTitle().empty()) {
358 *title = strdup(p->GetTitle().c_str());
359 if (*title == nullptr) {
360 LOGE("Out-of-memory");
361 return NOTI_EX_ERROR_OUT_OF_MEMORY;
365 return NOTI_EX_ERROR_NONE;
368 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
369 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
370 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
371 noti_ex_item_chat_message_type_e message_type) {
372 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
373 LOGE("Invalid parameter");
374 return NOTI_EX_ERROR_INVALID_PARAMETER;
377 auto* p = new (std::nothrow) ChatMessageItem(id,
378 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
379 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
380 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
381 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
382 static_cast<ChatMessageItem::Type>((int)message_type));
384 LOGE("Out-of-memory");
385 return NOTI_EX_ERROR_OUT_OF_MEMORY;
388 *handle = new Handle(shared_ptr<AbstractItem>(p));
390 return NOTI_EX_ERROR_NONE;
393 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
394 noti_ex_item_h handle, noti_ex_item_h *name) {
395 if (handle == nullptr || name == nullptr) {
396 LOGE("Invalid parameter");
397 return NOTI_EX_ERROR_INVALID_PARAMETER;
399 Handle* h = static_cast<Handle*>(handle);
400 if (!h->IsValidType(AbstractItem::ChatMessage)) {
401 LOGE("Invalid handle type");
402 return NOTI_EX_ERROR_INVALID_PARAMETER;
404 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
405 *name = new Handle(&(p->GetNameItem()));
407 return NOTI_EX_ERROR_NONE;
410 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
411 noti_ex_item_h handle, noti_ex_item_h *text) {
412 if (handle == nullptr || text == nullptr) {
413 LOGE("Invalid parameter");
414 return NOTI_EX_ERROR_INVALID_PARAMETER;
417 Handle* h = static_cast<Handle*>(handle);
418 if (!h->IsValidType(AbstractItem::ChatMessage)) {
419 LOGE("Invalid handle type");
420 return NOTI_EX_ERROR_INVALID_PARAMETER;
422 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
423 *text = new Handle(&(p->GetTextItem()));
425 return NOTI_EX_ERROR_NONE;
428 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
429 noti_ex_item_h handle, noti_ex_item_h *image) {
430 if (handle == nullptr || image == nullptr) {
431 LOGE("Invalid parameter");
432 return NOTI_EX_ERROR_INVALID_PARAMETER;
435 Handle* h = static_cast<Handle*>(handle);
436 if (!h->IsValidType(AbstractItem::ChatMessage)) {
437 LOGE("Invalid handle type");
438 return NOTI_EX_ERROR_INVALID_PARAMETER;
440 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
441 *image = new Handle(&(p->GetImageItem()));
443 return NOTI_EX_ERROR_NONE;
446 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
447 noti_ex_item_h handle, noti_ex_item_h *time) {
448 if (handle == nullptr || time == nullptr) {
449 LOGE("Invalid parameter");
450 return NOTI_EX_ERROR_INVALID_PARAMETER;
453 Handle* h = static_cast<Handle*>(handle);
454 if (!h->IsValidType(AbstractItem::ChatMessage)) {
455 LOGE("Invalid handle type");
456 return NOTI_EX_ERROR_INVALID_PARAMETER;
458 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
459 *time = new Handle(&(p->GetTimeItem()));
461 return NOTI_EX_ERROR_NONE;
464 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
465 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
466 if (handle == nullptr || message_type == nullptr) {
467 LOGE("Invalid parameter");
468 return NOTI_EX_ERROR_INVALID_PARAMETER;
471 Handle* h = static_cast<Handle*>(handle);
472 if (!h->IsValidType(AbstractItem::ChatMessage)) {
473 LOGE("Invalid handle type");
474 return NOTI_EX_ERROR_INVALID_PARAMETER;
476 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
477 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
479 return NOTI_EX_ERROR_NONE;
482 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
483 const char *id, const char *title, bool checked) {
486 if (handle == nullptr || title == nullptr) {
487 LOGE("Invalid parameter");
488 return NOTI_EX_ERROR_INVALID_PARAMETER;
491 p = new (std::nothrow) CheckBoxItem(id, title, checked);
493 LOGE("Out-of-memory");
494 return NOTI_EX_ERROR_OUT_OF_MEMORY;
497 *handle = new Handle(p);
499 return NOTI_EX_ERROR_NONE;
502 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
504 if (handle == nullptr || title == nullptr) {
505 LOGE("Invalid parameter");
506 return NOTI_EX_ERROR_INVALID_PARAMETER;
508 Handle* h = static_cast<Handle*>(handle);
509 if (!h->IsValidType(AbstractItem::CheckBox)) {
510 LOGE("Invalid handle type");
511 return NOTI_EX_ERROR_INVALID_PARAMETER;
513 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
514 if (!p->GetTitle().empty()) {
515 *title = strdup(p->GetTitle().c_str());
516 if (*title == nullptr) {
517 LOGE("Out-of-memory");
518 return NOTI_EX_ERROR_OUT_OF_MEMORY;
522 return NOTI_EX_ERROR_NONE;
525 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
527 if (handle == nullptr || checked == nullptr) {
528 LOGE("Invalid parameter");
529 return NOTI_EX_ERROR_INVALID_PARAMETER;
531 Handle* h = static_cast<Handle*>(handle);
532 if (!h->IsValidType(AbstractItem::CheckBox)) {
533 LOGE("Invalid handle type");
534 return NOTI_EX_ERROR_INVALID_PARAMETER;
536 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
537 *checked = p->IsChecked();
539 return NOTI_EX_ERROR_NONE;
542 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
546 if (handle == nullptr) {
547 LOGE("Invalid parameter");
548 return NOTI_EX_ERROR_INVALID_PARAMETER;
551 p = new (std::nothrow) EntryItem(id);
553 LOGE("Out-of-memory");
554 return NOTI_EX_ERROR_OUT_OF_MEMORY;
557 *handle = new Handle(p);
559 return NOTI_EX_ERROR_NONE;
562 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
564 if (handle == nullptr || text == nullptr) {
565 LOGE("Invalid parameter");
566 return NOTI_EX_ERROR_INVALID_PARAMETER;
569 Handle* h = static_cast<Handle*>(handle);
570 if (!h->IsValidType(AbstractItem::Entry)) {
571 LOGE("Invalid handle type");
572 return NOTI_EX_ERROR_INVALID_PARAMETER;
574 EntryItem* p = static_cast<EntryItem*>(h->Get());
575 if (!p->GetText().empty()) {
576 *text = strdup(p->GetText().c_str());
577 if (*text == nullptr) {
578 LOGE("Out-of-memory");
579 return NOTI_EX_ERROR_OUT_OF_MEMORY;
583 return NOTI_EX_ERROR_NONE;
586 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
588 if (handle == nullptr || text == nullptr) {
589 LOGE("Invalid parameter");
590 return NOTI_EX_ERROR_INVALID_PARAMETER;
592 Handle* h = static_cast<Handle*>(handle);
593 if (!h->IsValidType(AbstractItem::Entry)) {
594 LOGE("Invalid handle type");
595 return NOTI_EX_ERROR_INVALID_PARAMETER;
597 EntryItem* p = static_cast<EntryItem*>(h->Get());
598 p->SetText(std::string(text));
600 return NOTI_EX_ERROR_NONE;
603 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
604 noti_ex_event_info_h* cloned_handle) {
605 if (handle == nullptr || cloned_handle == nullptr) {
606 LOGE("Invalid parameter");
607 return NOTI_EX_ERROR_INVALID_PARAMETER;
610 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
611 EventInfo* info = new EventInfo(cloned);
612 *cloned_handle = info;
613 return NOTI_EX_ERROR_NONE;
616 extern "C" EXPORT_API int noti_ex_event_info_destroy(
617 noti_ex_event_info_h handle) {
618 if (handle == nullptr) {
619 LOGE("Invalid parameter");
620 return NOTI_EX_ERROR_INVALID_PARAMETER;
622 EventInfo* info = static_cast<EventInfo*>(handle);
624 return NOTI_EX_ERROR_NONE;
627 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
628 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
629 if (handle == nullptr || event_type == nullptr) {
630 LOGE("Invalid parameter");
631 return NOTI_EX_ERROR_INVALID_PARAMETER;
633 EventInfo* info = static_cast<EventInfo*>(handle);
634 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
636 return NOTI_EX_ERROR_NONE;
639 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
640 noti_ex_event_info_h handle, char **owner) {
641 if (handle == nullptr || owner == nullptr) {
642 LOGE("Invalid parameter");
643 return NOTI_EX_ERROR_INVALID_PARAMETER;
645 EventInfo* info = static_cast<EventInfo*>(handle);
646 *owner = strdup(info->GetOwner().c_str());
647 return NOTI_EX_ERROR_NONE;
650 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
651 noti_ex_event_info_h handle, char **channel) {
652 if (handle == nullptr || channel == nullptr) {
653 LOGE("Invalid parameter");
654 return NOTI_EX_ERROR_INVALID_PARAMETER;
656 EventInfo* info = static_cast<EventInfo*>(handle);
657 *channel = strdup(info->GetChannel().c_str());
658 return NOTI_EX_ERROR_NONE;
661 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
662 noti_ex_event_info_h handle, char **item_id) {
663 if (handle == nullptr || item_id == nullptr) {
664 LOGE("Invalid parameter");
665 return NOTI_EX_ERROR_INVALID_PARAMETER;
667 EventInfo* info = static_cast<EventInfo*>(handle);
668 *item_id = strdup(info->GetItemId().c_str());
669 return NOTI_EX_ERROR_NONE;
672 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
673 noti_ex_event_info_h handle, int *req_id) {
674 if (handle == nullptr || req_id == nullptr) {
675 LOGE("Invalid parameter");
676 return NOTI_EX_ERROR_INVALID_PARAMETER;
678 EventInfo* info = static_cast<EventInfo*>(handle);
679 *req_id = info->GetRequestId();
680 return NOTI_EX_ERROR_NONE;
683 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
687 if (handle == nullptr) {
688 LOGE("Invalid parameter");
689 return NOTI_EX_ERROR_INVALID_PARAMETER;
693 p = new (std::nothrow) GroupItem(id);
695 p = new (std::nothrow) GroupItem();
698 LOGE("Out-of-memory");
699 return NOTI_EX_ERROR_OUT_OF_MEMORY;
702 *handle = new Handle(shared_ptr<AbstractItem>(p));
704 return NOTI_EX_ERROR_NONE;
707 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
709 if (handle == nullptr) {
710 LOGE("Invalid parameter");
711 return NOTI_EX_ERROR_INVALID_PARAMETER;
713 Handle* h = static_cast<Handle*>(handle);
714 if (!h->IsValidType(AbstractItem::Group)) {
715 LOGE("Invalid handle type");
716 return NOTI_EX_ERROR_INVALID_PARAMETER;
718 GroupItem* p = static_cast<GroupItem*>(h->Get());
719 p->SetDirection(vertical);
721 return NOTI_EX_ERROR_NONE;
724 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
726 if (handle == nullptr) {
727 LOGE("Invalid parameter");
728 return NOTI_EX_ERROR_INVALID_PARAMETER;
730 Handle* h = static_cast<Handle*>(handle);
731 if (!h->IsValidType(AbstractItem::Group)) {
732 LOGE("Invalid handle type");
733 return NOTI_EX_ERROR_INVALID_PARAMETER;
735 GroupItem* p = static_cast<GroupItem*>(h->Get());
736 *vertical = p->IsVertical();
738 return NOTI_EX_ERROR_NONE;
741 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
743 if (handle == nullptr) {
744 LOGE("Invalid parameter");
745 return NOTI_EX_ERROR_INVALID_PARAMETER;
747 Handle* h = static_cast<Handle*>(handle);
748 if (!h->IsValidType(AbstractItem::Group)) {
749 LOGE("Invalid handle type");
750 return NOTI_EX_ERROR_INVALID_PARAMETER;
752 GroupItem* p = static_cast<GroupItem*>(h->Get());
753 if (!p->GetAppLabel().empty()) {
754 *label = strdup(p->GetAppLabel().c_str());
755 if (*label == nullptr) {
756 LOGE("Out-of-memory");
757 return NOTI_EX_ERROR_OUT_OF_MEMORY;
761 return NOTI_EX_ERROR_NONE;
764 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
765 noti_ex_item_h child) {
766 if (handle == nullptr || child == nullptr) {
767 LOGE("Invalid parameter");
768 return NOTI_EX_ERROR_INVALID_PARAMETER;
770 Handle* h = static_cast<Handle*>(handle);
771 if (!h->IsValidType(AbstractItem::Group)) {
772 LOGE("Invalid handle type");
773 return NOTI_EX_ERROR_INVALID_PARAMETER;
775 auto p = static_cast<GroupItem*>(h->Get());
776 p->AddChild((static_cast<Handle*>(child))->GetPtr());
778 return NOTI_EX_ERROR_NONE;
781 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
782 const char *item_id) {
783 if (handle == nullptr || item_id == nullptr) {
784 LOGE("Invalid parameter");
785 return NOTI_EX_ERROR_INVALID_PARAMETER;
787 Handle* h = static_cast<Handle*>(handle);
788 if (!h->IsValidType(AbstractItem::Group)) {
789 LOGE("Invalid handle type");
790 return NOTI_EX_ERROR_INVALID_PARAMETER;
792 GroupItem* p = static_cast<GroupItem*>(h->Get());
793 p->RemoveChild(std::string(item_id));
795 return NOTI_EX_ERROR_NONE;
798 extern "C" EXPORT_API int noti_ex_item_group_foreach(noti_ex_item_h handle,
799 noti_ex_item_group_foreach_cb callback, void *data) {
800 if (handle == nullptr || callback == nullptr) {
801 LOGE("Invalid parameter");
802 return NOTI_EX_ERROR_INVALID_PARAMETER;
805 Handle* h = static_cast<Handle*>(handle);
806 if (!h->IsValidType(AbstractItem::Group)) {
807 LOGE("Invalid handle type");
808 return NOTI_EX_ERROR_INVALID_PARAMETER;
810 GroupItem* p = static_cast<GroupItem*>(h->Get());
811 list<shared_ptr<AbstractItem>> children = p->GetChildren();
812 LOGI("Retrive (%zd)", children.size());
813 for (auto i : children) {
815 static_cast<noti_ex_item_h>(new Handle(i)), data);
816 if (ret != NOTI_EX_ERROR_NONE) {
817 LOGW("callback return (%d) stop foreach", ret);
822 return NOTI_EX_ERROR_NONE;
825 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
826 const char *id, const char *image_path) {
829 if (handle == nullptr || image_path == nullptr) {
830 LOGE("Invalid parameter");
831 return NOTI_EX_ERROR_INVALID_PARAMETER;
835 p = new (std::nothrow) ImageItem(id, image_path);
837 p = new (std::nothrow) ImageItem(image_path);
840 LOGE("Out-of-memory");
841 return NOTI_EX_ERROR_OUT_OF_MEMORY;
844 *handle = new Handle(p);
846 return NOTI_EX_ERROR_NONE;
849 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
850 noti_ex_item_h handle, char **image_path) {
851 if (handle == nullptr || image_path == nullptr) {
852 LOGE("Invalid parameter");
853 return NOTI_EX_ERROR_INVALID_PARAMETER;
855 Handle* h = static_cast<Handle*>(handle);
856 if (!h->IsValidType(AbstractItem::Image)) {
857 LOGE("Invalid handle type");
858 return NOTI_EX_ERROR_INVALID_PARAMETER;
860 ImageItem* p = static_cast<ImageItem*>(h->Get());
861 if (!p->GetImagePath().empty()) {
862 *image_path = strdup(p->GetImagePath().c_str());
863 if (*image_path == nullptr) {
864 LOGE("Out-of-memory");
865 return NOTI_EX_ERROR_OUT_OF_MEMORY;
869 return NOTI_EX_ERROR_NONE;
872 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
873 noti_ex_item_h *handle, const char *id) {
874 InputSelectorItem* p;
876 if (handle == nullptr) {
877 LOGE("Invalid parameter");
878 return NOTI_EX_ERROR_INVALID_PARAMETER;
882 p = new (std::nothrow) InputSelectorItem(id);
884 p = new (std::nothrow) InputSelectorItem();
887 LOGE("Out-of-memory");
888 return NOTI_EX_ERROR_OUT_OF_MEMORY;
891 *handle = new Handle(p);
893 return NOTI_EX_ERROR_NONE;
896 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
897 noti_ex_item_h handle, char ***contents_list, int *count) {
898 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
899 LOGE("Invalid parameter");
900 return NOTI_EX_ERROR_INVALID_PARAMETER;
903 Handle* h = static_cast<Handle*>(handle);
904 if (!h->IsValidType(AbstractItem::InputSelector)) {
905 LOGE("Invalid handle type");
906 return NOTI_EX_ERROR_INVALID_PARAMETER;
908 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
909 list<string> contents = p->GetContents();
910 *contents_list = (char**)calloc(contents.size(), sizeof(char*));
912 for (auto& i : contents) {
913 *contents_list[idx++] = strdup(i.c_str());
915 *count = contents.size();
917 return NOTI_EX_ERROR_NONE;
920 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
921 noti_ex_item_h handle, const char **contents, int count) {
922 if (handle == nullptr || contents == nullptr) {
923 LOGE("Invalid parameter");
924 return NOTI_EX_ERROR_INVALID_PARAMETER;
927 list<string> new_contents;
928 Handle* h = static_cast<Handle*>(handle);
929 if (!h->IsValidType(AbstractItem::InputSelector)) {
930 LOGE("Invalid handle type");
931 return NOTI_EX_ERROR_INVALID_PARAMETER;
933 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
934 for (int i = 0; i < count; i++) {
935 new_contents.push_back(contents[i]);
937 p->SetContents(move(new_contents));
939 return NOTI_EX_ERROR_NONE;
942 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
943 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
944 if (handle == nullptr) {
945 LOGE("Invalid parameter");
946 return NOTI_EX_ERROR_INVALID_PARAMETER;
949 auto* p = new (std::nothrow) Color(a, r, g, b);
951 LOGE("Out-of-memory");
952 return NOTI_EX_ERROR_OUT_OF_MEMORY;
957 return NOTI_EX_ERROR_NONE;
960 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
961 if (handle == nullptr) {
962 LOGE("Invalid parameter");
963 return NOTI_EX_ERROR_INVALID_PARAMETER;
966 Color* p = static_cast<Color*>(handle);
969 return NOTI_EX_ERROR_NONE;
972 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
973 unsigned char *val) {
974 if (handle == nullptr || val == nullptr) {
975 LOGE("Invalid parameter");
976 return NOTI_EX_ERROR_INVALID_PARAMETER;
979 Color* p = static_cast<Color*>(handle);
982 return NOTI_EX_ERROR_NONE;
985 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
986 unsigned char *val) {
987 if (handle == nullptr || val == nullptr) {
988 LOGE("Invalid parameter");
989 return NOTI_EX_ERROR_INVALID_PARAMETER;
992 Color* p = static_cast<Color*>(handle);
995 return NOTI_EX_ERROR_NONE;
998 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
999 unsigned char *val) {
1000 if (handle == nullptr || val == nullptr) {
1001 LOGE("Invalid parameter");
1002 return NOTI_EX_ERROR_INVALID_PARAMETER;
1005 Color* p = static_cast<Color*>(handle);
1006 *val = p->GetGVal();
1008 return NOTI_EX_ERROR_NONE;
1011 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1012 unsigned char *val) {
1013 if (handle == nullptr || val == nullptr) {
1014 LOGE("Invalid parameter");
1015 return NOTI_EX_ERROR_INVALID_PARAMETER;
1018 Color* p = static_cast<Color*>(handle);
1019 *val = p->GetBVal();
1021 return NOTI_EX_ERROR_NONE;
1024 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1025 int left, int top, int right, int bottom) {
1026 if (handle == nullptr) {
1027 LOGE("Invalid parameter");
1028 return NOTI_EX_ERROR_INVALID_PARAMETER;
1031 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1033 LOGE("Out-of-memory");
1034 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1039 return NOTI_EX_ERROR_NONE;
1042 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1043 if (handle == nullptr) {
1044 LOGE("Invalid parameter");
1045 return NOTI_EX_ERROR_INVALID_PARAMETER;
1048 Padding* p = static_cast<Padding*>(handle);
1051 return NOTI_EX_ERROR_NONE;
1054 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1056 if (handle == nullptr || val == nullptr) {
1057 LOGE("Invalid parameter");
1058 return NOTI_EX_ERROR_INVALID_PARAMETER;
1061 Padding* p = static_cast<Padding*>(handle);
1062 *val = p->GetLeft();
1064 return NOTI_EX_ERROR_NONE;
1067 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1069 if (handle == nullptr || val == nullptr) {
1070 LOGE("Invalid parameter");
1071 return NOTI_EX_ERROR_INVALID_PARAMETER;
1074 Padding* p = static_cast<Padding*>(handle);
1077 return NOTI_EX_ERROR_NONE;
1080 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1082 if (handle == nullptr || val == nullptr) {
1083 LOGE("Invalid parameter");
1084 return NOTI_EX_ERROR_INVALID_PARAMETER;
1087 Padding* p = static_cast<Padding*>(handle);
1088 *val = p->GetRight();
1090 return NOTI_EX_ERROR_NONE;
1093 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1095 if (handle == nullptr || val == nullptr) {
1096 LOGE("Invalid parameter");
1097 return NOTI_EX_ERROR_INVALID_PARAMETER;
1100 Padding* p = static_cast<Padding*>(handle);
1101 *val = p->GetBottom();
1103 return NOTI_EX_ERROR_NONE;
1106 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1107 int x, int y, int w, int h) {
1108 if (handle == nullptr) {
1109 LOGE("Invalid parameter");
1110 return NOTI_EX_ERROR_INVALID_PARAMETER;
1113 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1115 LOGE("Out-of-memory");
1116 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1121 return NOTI_EX_ERROR_NONE;
1124 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1125 if (handle == nullptr) {
1126 LOGE("Invalid parameter");
1127 return NOTI_EX_ERROR_INVALID_PARAMETER;
1130 Geometry* p = static_cast<Geometry*>(handle);
1133 return NOTI_EX_ERROR_NONE;
1136 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1138 if (handle == nullptr || val == nullptr) {
1139 LOGE("Invalid parameter");
1140 return NOTI_EX_ERROR_INVALID_PARAMETER;
1143 Geometry* p = static_cast<Geometry*>(handle);
1146 return NOTI_EX_ERROR_NONE;
1149 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1151 if (handle == nullptr || val == nullptr) {
1152 LOGE("Invalid parameter");
1153 return NOTI_EX_ERROR_INVALID_PARAMETER;
1156 Geometry* p = static_cast<Geometry*>(handle);
1159 return NOTI_EX_ERROR_NONE;
1162 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1164 if (handle == nullptr || val == nullptr) {
1165 LOGE("Invalid parameter");
1166 return NOTI_EX_ERROR_INVALID_PARAMETER;
1169 Geometry* p = static_cast<Geometry*>(handle);
1170 *val = p->GetWidth();
1172 return NOTI_EX_ERROR_NONE;
1175 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1177 if (handle == nullptr || val == nullptr) {
1178 LOGE("Invalid parameter");
1179 return NOTI_EX_ERROR_INVALID_PARAMETER;
1182 Geometry* p = static_cast<Geometry*>(handle);
1183 *val = p->GetHeight();
1185 return NOTI_EX_ERROR_NONE;
1188 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1189 noti_ex_color_h color,
1190 noti_ex_padding_h padding,
1191 noti_ex_geometry_h geometry) {
1192 if (handle == nullptr) {
1193 LOGE("Invalid parameter");
1194 return NOTI_EX_ERROR_INVALID_PARAMETER;
1197 Color* color_ = static_cast<Color*>(color);
1198 Padding* padding_ = static_cast<Padding*>(padding);
1199 Geometry* geo_ = static_cast<Geometry*>(geometry);
1201 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1203 LOGE("Out-of-memory");
1204 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1209 return NOTI_EX_ERROR_NONE;
1212 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1213 if (handle == nullptr) {
1214 LOGE("Invalid parameter");
1215 return NOTI_EX_ERROR_INVALID_PARAMETER;
1218 Style* p = static_cast<Style*>(handle);
1221 return NOTI_EX_ERROR_NONE;
1224 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1225 noti_ex_padding_h *padding) {
1226 if (handle == nullptr || padding == nullptr) {
1227 LOGE("Invalid parameter");
1228 return NOTI_EX_ERROR_INVALID_PARAMETER;
1231 Style* p = static_cast<Style*>(handle);
1232 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1233 if (padding_ == nullptr) {
1234 LOGE("Out-of-memory");
1235 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1238 *padding = padding_;
1240 return NOTI_EX_ERROR_NONE;
1243 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1244 noti_ex_color_h *color) {
1245 if (handle == nullptr || color == nullptr) {
1246 LOGE("Invalid parameter");
1247 return NOTI_EX_ERROR_INVALID_PARAMETER;
1250 Style* p = static_cast<Style*>(handle);
1251 Color* color_ = new (std::nothrow) Color(p->GetColor());
1252 if (color_ == nullptr) {
1253 LOGE("Out-of-memory");
1254 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1259 return NOTI_EX_ERROR_NONE;
1262 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1263 noti_ex_geometry_h *geometry) {
1264 if (handle == nullptr || geometry == nullptr) {
1265 LOGE("Invalid parameter");
1266 return NOTI_EX_ERROR_INVALID_PARAMETER;
1269 Style* p = static_cast<Style*>(handle);
1270 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1271 if (geo_ == nullptr) {
1272 LOGE("Out-of-memory");
1273 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1278 return NOTI_EX_ERROR_NONE;
1281 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1282 noti_ex_color_h color) {
1283 if (handle == nullptr) {
1284 LOGE("Invalid parameter");
1285 return NOTI_EX_ERROR_INVALID_PARAMETER;
1288 Color* color_ = static_cast<Color*>(color);
1289 auto* p = new (std::nothrow) LEDInfo(*color_);
1291 LOGE("Out-of-memory");
1292 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1297 return NOTI_EX_ERROR_NONE;
1300 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1301 if (handle == nullptr) {
1302 LOGE("Invalid parameter");
1303 return NOTI_EX_ERROR_INVALID_PARAMETER;
1306 LEDInfo* p = static_cast<LEDInfo*>(handle);
1309 return NOTI_EX_ERROR_NONE;
1312 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1313 noti_ex_led_info_h handle, int ms) {
1314 if (handle == nullptr) {
1315 LOGE("Invalid parameter");
1316 return NOTI_EX_ERROR_INVALID_PARAMETER;
1319 LEDInfo* p = static_cast<LEDInfo*>(handle);
1322 return NOTI_EX_ERROR_NONE;
1325 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1326 noti_ex_led_info_h handle, int *ms) {
1327 if (handle == nullptr || ms == nullptr) {
1328 LOGE("Invalid parameter");
1329 return NOTI_EX_ERROR_INVALID_PARAMETER;
1332 LEDInfo* p = static_cast<LEDInfo*>(handle);
1333 *ms = p->GetOnPeriod();
1335 return NOTI_EX_ERROR_NONE;
1338 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1339 noti_ex_led_info_h handle, int ms) {
1340 if (handle == nullptr) {
1341 LOGE("Invalid parameter");
1342 return NOTI_EX_ERROR_INVALID_PARAMETER;
1345 LEDInfo* p = static_cast<LEDInfo*>(handle);
1346 p->SetOffPeriod(ms);
1348 return NOTI_EX_ERROR_NONE;
1351 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1352 noti_ex_led_info_h handle, int *ms) {
1353 if (handle == nullptr) {
1354 LOGE("Invalid parameter");
1355 return NOTI_EX_ERROR_INVALID_PARAMETER;
1358 LEDInfo* p = static_cast<LEDInfo*>(handle);
1359 *ms = p->GetOffPeriod();
1361 return NOTI_EX_ERROR_NONE;
1364 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1365 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1366 if (handle == nullptr) {
1367 LOGE("Invalid parameter");
1368 return NOTI_EX_ERROR_INVALID_PARAMETER;
1371 LEDInfo* p = static_cast<LEDInfo*>(handle);
1372 Color* color_ = new (std::nothrow) Color(p->GetColor());
1373 if (color_ == nullptr) {
1374 LOGE("Out-of-memory");
1375 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1380 return NOTI_EX_ERROR_NONE;
1383 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1384 if (handle == nullptr) {
1385 LOGE("Invalid parameter");
1386 return NOTI_EX_ERROR_INVALID_PARAMETER;
1389 AbstractAction* p = static_cast<AbstractAction*>(handle);
1390 p->~AbstractAction();
1392 return NOTI_EX_ERROR_NONE;
1395 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1397 if (handle == nullptr || type == nullptr) {
1398 LOGE("Invalid parameter");
1399 return NOTI_EX_ERROR_INVALID_PARAMETER;
1402 AbstractAction* p = static_cast<AbstractAction*>(handle);
1403 *type = p->GetType();
1405 return NOTI_EX_ERROR_NONE;
1408 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1410 if (handle == nullptr || local == nullptr) {
1411 LOGE("Invalid parameter");
1412 return NOTI_EX_ERROR_INVALID_PARAMETER;
1415 AbstractAction* p = static_cast<AbstractAction*>(handle);
1416 *local = p->IsLocal();
1418 return NOTI_EX_ERROR_NONE;
1421 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1422 noti_ex_item_h item) {
1423 if (handle == nullptr || item==nullptr) {
1424 LOGE("Invalid parameter");
1425 return NOTI_EX_ERROR_INVALID_PARAMETER;
1427 AbstractAction* p = static_cast<AbstractAction*>(handle);
1428 Handle* ih = static_cast<Handle*>(item);
1429 p->Execute(ih->GetPtr());
1431 return NOTI_EX_ERROR_NONE;
1434 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1436 if (handle == nullptr || extra == nullptr) {
1437 LOGE("Invalid parameter");
1438 return NOTI_EX_ERROR_INVALID_PARAMETER;
1441 AbstractAction* p = static_cast<AbstractAction*>(handle);
1442 if (!p->GetExtra().empty()) {
1443 *extra = strdup(p->GetExtra().c_str());
1444 if (*extra == nullptr) {
1445 LOGE("Out-of-memory");
1446 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1450 return NOTI_EX_ERROR_NONE;
1453 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1454 noti_ex_item_info_h handle, int *hide_time) {
1455 if (handle == nullptr || hide_time == nullptr) {
1456 LOGE("Invalid parameter");
1457 return NOTI_EX_ERROR_INVALID_PARAMETER;
1459 IItemInfo* p = static_cast<IItemInfo*>(handle);
1460 *hide_time = p->GetHideTime();
1461 return NOTI_EX_ERROR_NONE;
1464 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1465 noti_ex_item_info_h handle, int hide_time) {
1466 if (handle == nullptr) {
1467 LOGE("Invalid parameter");
1468 return NOTI_EX_ERROR_INVALID_PARAMETER;
1470 IItemInfo* p = static_cast<IItemInfo*>(handle);
1471 p->SetHideTime(hide_time);
1472 return NOTI_EX_ERROR_NONE;
1475 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1476 noti_ex_item_info_h handle, int *delete_time) {
1477 if (handle == nullptr || delete_time == nullptr) {
1478 LOGE("Invalid parameter");
1479 return NOTI_EX_ERROR_INVALID_PARAMETER;
1481 IItemInfo* p = static_cast<IItemInfo*>(handle);
1482 *delete_time = p->GetDeleteTime();
1483 return NOTI_EX_ERROR_NONE;
1486 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1487 noti_ex_item_info_h handle, int delete_time) {
1488 if (handle == nullptr) {
1489 LOGE("Invalid parameter");
1490 return NOTI_EX_ERROR_INVALID_PARAMETER;
1492 IItemInfo* p = static_cast<IItemInfo*>(handle);
1493 p->SetDeleteTime(delete_time);
1494 return NOTI_EX_ERROR_NONE;
1497 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1498 noti_ex_item_info_h handle, time_t *time) {
1499 if (handle == nullptr || time == nullptr) {
1500 LOGE("Invalid parameter");
1501 return NOTI_EX_ERROR_INVALID_PARAMETER;
1504 IItemInfo* p = static_cast<IItemInfo*>(handle);
1505 *time = p->GetTime();
1506 return NOTI_EX_ERROR_NONE;
1509 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1510 if (handle == nullptr) {
1511 LOGE("Invalid parameter");
1512 return NOTI_EX_ERROR_INVALID_PARAMETER;
1515 Handle* h = static_cast<Handle*>(handle);
1517 return NOTI_EX_ERROR_NONE;
1520 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1521 const char *id, noti_ex_item_h *item) {
1522 if (handle == nullptr) {
1523 LOGE("Invalid parameter");
1524 return NOTI_EX_ERROR_INVALID_PARAMETER;
1527 Handle* p = static_cast<Handle*>(handle);
1528 AbstractItem& find_item = p->Get()->FindByID(string(id));
1529 *item = new Handle(&find_item);
1530 return NOTI_EX_ERROR_NONE;
1533 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1535 if (handle == nullptr || type == nullptr) {
1536 LOGE("Invalid parameter");
1537 return NOTI_EX_ERROR_INVALID_PARAMETER;
1540 Handle* h = static_cast<Handle*>(handle);
1541 AbstractItem* p = h->Get();
1542 *type = p->GetType();
1543 return NOTI_EX_ERROR_NONE;
1546 extern "C" EXPORT_API int noti_ex_item_get_shared_path(noti_ex_item_h handle,
1547 char ***path, int *count) {
1548 if (handle == nullptr || path == nullptr || count == nullptr) {
1549 LOGE("Invalid parameter");
1550 return NOTI_EX_ERROR_INVALID_PARAMETER;
1552 Handle* p = static_cast<Handle*>(handle);
1553 list<string> shared_path = p->Get()->GetSharedPath();
1554 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1556 for (auto& i : shared_path) {
1557 *path[idx++] = strdup(i.c_str());
1559 *count = shared_path.size();
1560 return NOTI_EX_ERROR_NONE;
1563 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1565 if (handle == nullptr || id == nullptr) {
1566 LOGE("Invalid parameter");
1567 return NOTI_EX_ERROR_INVALID_PARAMETER;
1569 Handle* h = static_cast<Handle*>(handle);
1570 AbstractItem* p = h->Get();
1571 *id = strdup(p->GetId().c_str());
1572 return NOTI_EX_ERROR_NONE;
1575 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1577 if (handle == nullptr || id == nullptr) {
1578 LOGE("Invalid parameter");
1579 return NOTI_EX_ERROR_INVALID_PARAMETER;
1581 Handle* p = static_cast<Handle*>(handle);
1582 p->Get()->SetId(id);
1583 return NOTI_EX_ERROR_NONE;
1586 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1587 noti_ex_action_h *action) {
1588 if (handle == nullptr || action == nullptr) {
1589 LOGE("Invalid parameter");
1590 return NOTI_EX_ERROR_INVALID_PARAMETER;
1592 Handle* p = static_cast<Handle*>(handle);
1593 if (p->Get()->GetAction() == nullptr) {
1595 return NOTI_EX_ERROR_NONE;
1597 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1599 return NOTI_EX_ERROR_NONE;
1602 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1603 noti_ex_action_h action) {
1604 if (handle == nullptr || action == nullptr) {
1605 LOGE("Invalid parameter");
1606 return NOTI_EX_ERROR_INVALID_PARAMETER;
1609 Handle* p = static_cast<Handle*>(handle);
1610 AbstractAction* a = static_cast<AbstractAction*>(action);
1611 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1612 return NOTI_EX_ERROR_NONE;
1615 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1616 noti_ex_style_h *style) {
1617 if (handle == nullptr || style == nullptr) {
1618 LOGE("Invalid parameter");
1619 return NOTI_EX_ERROR_INVALID_PARAMETER;
1622 Handle* p = static_cast<Handle*>(handle);
1623 shared_ptr<Style> s = p->Get()->GetStyle();
1624 *style = static_cast<noti_ex_style_h>(s.get());
1625 return NOTI_EX_ERROR_NONE;
1628 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1629 noti_ex_style_h style) {
1630 if (handle == nullptr || style == nullptr) {
1631 LOGE("Invalid parameter");
1632 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 Handle* p = static_cast<Handle*>(handle);
1636 Style* s = static_cast<Style*>(style);
1637 p->Get()->SetStyle(shared_ptr<Style>(s));
1638 return NOTI_EX_ERROR_NONE;
1641 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1643 if (handle == nullptr) {
1644 LOGE("Invalid parameter");
1645 return NOTI_EX_ERROR_INVALID_PARAMETER;
1648 Handle* p = static_cast<Handle*>(handle);
1649 p->Get()->SetVisible(visible);
1650 return NOTI_EX_ERROR_NONE;
1653 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1655 if (handle == nullptr || visible == nullptr) {
1656 LOGE("Invalid parameter");
1657 return NOTI_EX_ERROR_INVALID_PARAMETER;
1660 Handle* p = static_cast<Handle*>(handle);
1661 *visible = p->Get()->GetVisible();
1662 return NOTI_EX_ERROR_NONE;
1665 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1667 if (handle == nullptr) {
1668 LOGE("Invalid parameter");
1669 return NOTI_EX_ERROR_INVALID_PARAMETER;
1672 Handle* p = static_cast<Handle*>(handle);
1673 p->Get()->SetEnable(enable);
1674 return NOTI_EX_ERROR_NONE;
1677 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1679 if (handle == nullptr || enable == nullptr) {
1680 LOGE("Invalid parameter");
1681 return NOTI_EX_ERROR_INVALID_PARAMETER;
1684 Handle* p = static_cast<Handle*>(handle);
1685 *enable = p->Get()->GetEnable();
1686 return NOTI_EX_ERROR_NONE;
1689 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1690 const char *receiver_group) {
1691 if (handle == nullptr || receiver_group == nullptr) {
1692 LOGE("Invalid parameter");
1693 return NOTI_EX_ERROR_INVALID_PARAMETER;
1696 Handle* p = static_cast<Handle*>(handle);
1697 p->Get()->AddReceiver(receiver_group);
1698 return NOTI_EX_ERROR_NONE;
1701 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1702 const char *receiver_group) {
1703 if (handle == nullptr || receiver_group == nullptr) {
1704 LOGE("Invalid parameter");
1705 return NOTI_EX_ERROR_INVALID_PARAMETER;
1708 Handle* p = static_cast<Handle*>(handle);
1709 p->Get()->RemoveReceiver(receiver_group);
1710 return NOTI_EX_ERROR_NONE;
1713 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1714 char ***receiver_list, int *count) {
1715 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1716 LOGE("Invalid parameter");
1717 return NOTI_EX_ERROR_INVALID_PARAMETER;
1720 Handle* p = static_cast<Handle*>(handle);
1721 list<string> receivers = p->Get()->GetReceiverList();
1722 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1724 for (auto& i : receivers) {
1725 *receiver_list[idx++] = strdup(i.c_str());
1727 *count = receivers.size();
1728 return NOTI_EX_ERROR_NONE;
1731 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1733 if (handle == nullptr) {
1734 LOGE("Invalid parameter");
1735 return NOTI_EX_ERROR_INVALID_PARAMETER;
1738 Handle* p = static_cast<Handle*>(handle);
1739 p->Get()->SetPolicy(policy);
1740 return NOTI_EX_ERROR_NONE;
1743 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1745 if (handle == nullptr || policy == nullptr) {
1746 LOGE("Invalid parameter");
1747 return NOTI_EX_ERROR_INVALID_PARAMETER;
1750 Handle* p = static_cast<Handle*>(handle);
1751 *policy = p->Get()->GetPolicy();
1752 return NOTI_EX_ERROR_NONE;
1755 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1757 if (handle == nullptr || channel == nullptr) {
1758 LOGE("Invalid parameter");
1759 return NOTI_EX_ERROR_INVALID_PARAMETER;
1762 Handle* p = static_cast<Handle*>(handle);
1763 if (!p->Get()->GetChannel().empty())
1764 *channel = strdup(p->Get()->GetChannel().c_str());
1768 return NOTI_EX_ERROR_NONE;
1771 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1772 const char *channel) {
1773 if (handle == nullptr) {
1774 LOGE("Invalid parameter");
1775 return NOTI_EX_ERROR_INVALID_PARAMETER;
1778 Handle* p = static_cast<Handle*>(handle);
1779 p->Get()->SetChannel(channel);
1780 return NOTI_EX_ERROR_NONE;
1783 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1784 noti_ex_led_info_h led) {
1785 if (handle == nullptr) {
1786 LOGE("Invalid parameter");
1787 return NOTI_EX_ERROR_INVALID_PARAMETER;
1790 Handle* p = static_cast<Handle*>(handle);
1791 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1792 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1793 return NOTI_EX_ERROR_NONE;
1796 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1797 noti_ex_led_info_h *led) {
1798 if (handle == nullptr) {
1799 LOGE("Invalid parameter");
1800 return NOTI_EX_ERROR_INVALID_PARAMETER;
1803 Handle* p = static_cast<Handle*>(handle);
1804 if (p->Get()->GetLEDInfo() != nullptr)
1805 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1808 return NOTI_EX_ERROR_NONE;
1811 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1813 if (handle == nullptr) {
1814 LOGE("Invalid parameter");
1815 return NOTI_EX_ERROR_INVALID_PARAMETER;
1818 Handle* p = static_cast<Handle*>(handle);
1819 if (path == nullptr)
1820 p->Get()->SetSoundPath("");
1822 p->Get()->SetSoundPath(path);
1823 return NOTI_EX_ERROR_NONE;
1826 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1828 if (handle == nullptr) {
1829 LOGE("Invalid parameter");
1830 return NOTI_EX_ERROR_INVALID_PARAMETER;
1833 Handle* p = static_cast<Handle*>(handle);
1834 if (path == nullptr)
1835 p->Get()->SetVibrationPath("");
1837 p->Get()->SetVibrationPath(path);
1838 return NOTI_EX_ERROR_NONE;
1841 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1843 if (handle == nullptr || path == nullptr) {
1844 LOGE("Invalid parameter");
1845 return NOTI_EX_ERROR_INVALID_PARAMETER;
1848 Handle* p = static_cast<Handle*>(handle);
1849 if (p->Get()->GetSoundPath().empty())
1852 *path = strdup(p->Get()->GetSoundPath().c_str());
1853 return NOTI_EX_ERROR_NONE;
1856 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1858 if (handle == nullptr || path == nullptr) {
1859 LOGE("Invalid parameter");
1860 return NOTI_EX_ERROR_INVALID_PARAMETER;
1863 Handle* p = static_cast<Handle*>(handle);
1864 if (p->Get()->GetVibrationPath().empty())
1867 *path = strdup(p->Get()->GetVibrationPath().c_str());
1868 return NOTI_EX_ERROR_NONE;
1871 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1872 noti_ex_item_info_h *info) {
1873 if (handle == nullptr || info == nullptr) {
1874 LOGE("Invalid parameter");
1875 return NOTI_EX_ERROR_INVALID_PARAMETER;
1878 Handle* p = static_cast<Handle*>(handle);
1879 if (p->Get()->GetInfo() == nullptr)
1882 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1883 return NOTI_EX_ERROR_NONE;
1886 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1888 if (handle == nullptr || id == nullptr) {
1889 LOGE("Invalid parameter");
1890 return NOTI_EX_ERROR_INVALID_PARAMETER;
1893 Handle* p = static_cast<Handle*>(handle);
1894 if (p->Get()->GetSenderAppId().empty())
1897 *id = strdup(p->Get()->GetSenderAppId().c_str());
1898 return NOTI_EX_ERROR_NONE;
1901 extern "C" EXPORT_API int noti_ex_item_set_sender_app_id(noti_ex_item_h handle,
1903 if (handle == nullptr) {
1904 LOGE("Invalid parameter");
1905 return NOTI_EX_ERROR_INVALID_PARAMETER;
1908 Handle* p = static_cast<Handle*>(handle);
1910 p->Get()->SetSenderAppId("");
1912 p->Get()->SetSenderAppId(id);
1913 return NOTI_EX_ERROR_NONE;
1916 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1918 if (handle == nullptr || tag == nullptr) {
1919 LOGE("Invalid parameter");
1920 return NOTI_EX_ERROR_INVALID_PARAMETER;
1923 Handle* p = static_cast<Handle*>(handle);
1924 if (p->Get()->GetTag().empty())
1927 *tag = strdup(p->Get()->GetTag().c_str());
1928 return NOTI_EX_ERROR_NONE;
1931 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1933 if (handle == nullptr) {
1934 LOGE("Invalid parameter");
1935 return NOTI_EX_ERROR_INVALID_PARAMETER;
1938 Handle* p = static_cast<Handle*>(handle);
1940 p->Get()->SetTag("");
1942 p->Get()->SetTag(tag);
1943 return NOTI_EX_ERROR_NONE;
1946 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1947 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1949 if (handle == nullptr) {
1950 LOGE("Invalid parameter");
1951 return NOTI_EX_ERROR_INVALID_PARAMETER;
1954 ManagerStub* stub = new (std::nothrow) ManagerStub(
1955 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1956 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1958 if (stub == nullptr) {
1959 LOGE("Fail to create manager");
1960 return NOTI_EX_ERROR_IO_ERROR;
1962 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1963 new ManagerCallbackInfo(event_callbacks, data)));
1964 *handle = static_cast<noti_ex_manager_h>(stub);
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1970 if (handle == nullptr) {
1971 LOGE("Invalid parameter");
1972 return NOTI_EX_ERROR_INVALID_PARAMETER;
1974 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1976 return NOTI_EX_ERROR_NONE;
1979 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1980 noti_ex_item_h **items, int *count) {
1981 if (handle == nullptr || items == nullptr || count == nullptr) {
1982 LOGE("Invalid parameter");
1983 return NOTI_EX_ERROR_INVALID_PARAMETER;
1987 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1988 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1989 if (item_list.size() == 0) {
1992 return NOTI_EX_ERROR_NONE;
1994 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1995 if (*items == nullptr) {
1996 LOGE("Fail to create items");
1997 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2001 for (auto& i : item_list) {
2002 *items[idx++] = new Handle(move(i));
2004 *count = item_list.size();
2005 } catch (Exception &ex) {
2006 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2007 return NOTI_EX_ERROR_IO_ERROR;
2009 return NOTI_EX_ERROR_NONE;
2012 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2013 noti_ex_item_h noti, int *request_id) {
2014 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2015 LOGE("Invalid parameter");
2016 return NOTI_EX_ERROR_INVALID_PARAMETER;
2019 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2020 Handle* sp = static_cast<Handle*>(noti);
2021 if (sp->GetPtr().get() == nullptr) {
2022 LOGE("Invalid noti reference can not be sended");
2023 return NOTI_EX_ERROR_INVALID_PARAMETER;
2025 *request_id = stub->Update(sp->GetPtr());
2027 } catch (Exception &ex) {
2028 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2029 return NOTI_EX_ERROR_IO_ERROR;
2031 return NOTI_EX_ERROR_NONE;
2034 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2035 noti_ex_item_h noti, int *request_id) {
2036 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2037 LOGE("Invalid parameter");
2038 return NOTI_EX_ERROR_INVALID_PARAMETER;
2041 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2042 Handle* item = static_cast<Handle*>(noti);
2043 if (item->GetPtr().get() == nullptr) {
2044 LOGE("Invalid noti reference can not be sended");
2045 return NOTI_EX_ERROR_INVALID_PARAMETER;
2047 *request_id = stub->Delete(item->GetPtr());
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_delete_all(noti_ex_manager_h handle,
2058 if (handle == nullptr || request_id == nullptr) {
2059 LOGE("Invalid parameter");
2060 return NOTI_EX_ERROR_INVALID_PARAMETER;
2063 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2064 *request_id = stub->DeleteAll();
2065 } catch (Exception &ex) {
2066 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2067 return NOTI_EX_ERROR_IO_ERROR;
2069 return NOTI_EX_ERROR_NONE;
2072 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2073 noti_ex_item_h noti, int *request_id) {
2074 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2075 LOGE("Invalid parameter");
2076 return NOTI_EX_ERROR_INVALID_PARAMETER;
2079 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2080 Handle* item = static_cast<Handle*>(noti);
2081 if (item->GetPtr().get() == nullptr) {
2082 LOGE("Invalid noti reference can not be sended");
2083 return NOTI_EX_ERROR_INVALID_PARAMETER;
2085 *request_id = stub->Hide(item->GetPtr());
2087 } catch (Exception &ex) {
2088 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2089 return NOTI_EX_ERROR_IO_ERROR;
2091 return NOTI_EX_ERROR_NONE;
2094 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2095 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2096 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2097 LOGE("Invalid parameter");
2098 return NOTI_EX_ERROR_INVALID_PARAMETER;
2101 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2102 *item = new Handle(stub->FindByRootID(root_id));
2103 } catch (Exception &ex) {
2104 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2105 return NOTI_EX_ERROR_IO_ERROR;
2107 return NOTI_EX_ERROR_NONE;
2110 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2111 noti_ex_event_info_h info, noti_ex_error_e error) {
2112 if (handle == nullptr || info == nullptr) {
2113 LOGE("Invalid parameter");
2114 return NOTI_EX_ERROR_INVALID_PARAMETER;
2117 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2118 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2119 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2120 static_cast<NotificationError>(error));
2121 } catch (Exception &ex) {
2122 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2123 return NOTI_EX_ERROR_IO_ERROR;
2125 return NOTI_EX_ERROR_NONE;
2128 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2131 if (handle == nullptr || cnt == nullptr) {
2132 LOGE("Invalid parameter");
2133 return NOTI_EX_ERROR_INVALID_PARAMETER;
2136 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2137 *cnt = stub->GetCount();
2138 } catch (Exception &ex) {
2139 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2140 return NOTI_EX_ERROR_IO_ERROR;
2142 return NOTI_EX_ERROR_NONE;
2145 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2146 const char *id, float min, float current, float max) {
2149 if (handle == nullptr) {
2150 LOGE("Invalid parameter");
2151 return NOTI_EX_ERROR_INVALID_PARAMETER;
2155 p = new (std::nothrow) ProgressItem(id, min, current, max);
2157 p = new (std::nothrow) ProgressItem(min, current, max);
2160 LOGE("Out-of-memory");
2161 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2164 *handle = new Handle(p);
2166 return NOTI_EX_ERROR_NONE;
2169 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2170 noti_ex_item_h handle, float *current) {
2171 if (handle == nullptr || current == nullptr) {
2172 LOGE("Invalid parameter");
2173 return NOTI_EX_ERROR_INVALID_PARAMETER;
2176 Handle *h = static_cast<Handle*>(handle);
2177 if (!h->IsValidType(AbstractItem::Progress)) {
2178 LOGE("Invalid handle type");
2179 return NOTI_EX_ERROR_INVALID_PARAMETER;
2181 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2182 *current = p->GetCurrent();
2184 return NOTI_EX_ERROR_NONE;
2187 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2188 noti_ex_item_h handle, float current) {
2189 if (handle == nullptr) {
2190 LOGE("Invalid parameter");
2191 return NOTI_EX_ERROR_INVALID_PARAMETER;
2194 Handle *h = static_cast<Handle*>(handle);
2195 if (!h->IsValidType(AbstractItem::Progress)) {
2196 LOGE("Invalid handle type");
2197 return NOTI_EX_ERROR_INVALID_PARAMETER;
2199 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2200 p->SetCurrent(current);
2202 return NOTI_EX_ERROR_NONE;
2205 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2207 if (handle == nullptr || min == nullptr) {
2208 LOGE("Invalid parameter");
2209 return NOTI_EX_ERROR_INVALID_PARAMETER;
2212 Handle *h = static_cast<Handle*>(handle);
2213 if (!h->IsValidType(AbstractItem::Progress)) {
2214 LOGE("Invalid handle type");
2215 return NOTI_EX_ERROR_INVALID_PARAMETER;
2217 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2220 return NOTI_EX_ERROR_NONE;
2223 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2225 if (handle == nullptr || max == nullptr) {
2226 LOGE("Invalid parameter");
2227 return NOTI_EX_ERROR_INVALID_PARAMETER;
2230 Handle *h = static_cast<Handle*>(handle);
2231 if (!h->IsValidType(AbstractItem::Progress)) {
2232 LOGE("Invalid handle type");
2233 return NOTI_EX_ERROR_INVALID_PARAMETER;
2235 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2238 return NOTI_EX_ERROR_NONE;
2241 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2242 noti_ex_reporter_events_s event_callbacks, void *data) {
2243 if (handle == nullptr) {
2244 LOGE("Invalid parameter");
2245 return NOTI_EX_ERROR_INVALID_PARAMETER;
2248 ReporterStub* stub = new (std::nothrow) ReporterStub(
2249 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2250 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2251 if (stub == nullptr) {
2252 LOGE("Fail to create manager");
2253 return NOTI_EX_ERROR_IO_ERROR;
2255 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2256 new ReporterCallbackInfo(event_callbacks, data)));
2258 *handle = static_cast<noti_ex_reporter_h>(stub);
2260 return NOTI_EX_ERROR_NONE;
2263 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2264 if (handle == nullptr) {
2265 LOGE("Invalid parameter");
2266 return NOTI_EX_ERROR_INVALID_PARAMETER;
2268 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2270 return NOTI_EX_ERROR_NONE;
2273 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2274 noti_ex_event_info_h info, noti_ex_error_e error) {
2275 if (handle == nullptr || info == nullptr) {
2276 LOGE("Invalid parameter");
2277 return NOTI_EX_ERROR_INVALID_PARAMETER;
2280 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2281 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2282 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2283 static_cast<NotificationError>(error));
2284 } catch (Exception &ex) {
2285 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2286 return NOTI_EX_ERROR_IO_ERROR;
2288 return NOTI_EX_ERROR_NONE;
2291 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2292 noti_ex_item_h noti, int *request_id) {
2293 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2294 LOGE("Invalid parameter");
2295 return NOTI_EX_ERROR_INVALID_PARAMETER;
2298 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2299 Handle* h = static_cast<Handle*>(noti);
2300 if (h->GetPtr().get() == nullptr) {
2301 LOGE("Invalid noti reference can not be sended");
2302 return NOTI_EX_ERROR_INVALID_PARAMETER;
2304 *request_id = stub->Post(h->GetPtr());
2306 } catch (Exception &ex) {
2307 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2308 return NOTI_EX_ERROR_IO_ERROR;
2310 return NOTI_EX_ERROR_NONE;
2313 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2314 noti_ex_item_h *noti_list, int count, int *request_id) {
2316 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2317 LOGE("Invalid parameter");
2318 return NOTI_EX_ERROR_INVALID_PARAMETER;
2321 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2322 list<shared_ptr<item::AbstractItem>> notiList;
2323 for (int i = 0; i < count; i++) {
2324 Handle* item = static_cast<Handle*>(noti_list[i]);
2325 notiList.emplace_back(item->GetPtr());
2327 *request_id = stub->Post(notiList);
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_update(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* item = static_cast<Handle*>(noti);
2344 if (item->GetPtr().get() == nullptr) {
2345 LOGE("Invalid noti reference can not be sended");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2348 *request_id = stub->Update(item->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_delete(noti_ex_reporter_h handle,
2358 noti_ex_item_h noti, int *request_id) {
2359 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2360 LOGE("Invalid parameter");
2361 return NOTI_EX_ERROR_INVALID_PARAMETER;
2364 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2365 Handle* item = static_cast<Handle*>(noti);
2366 if (item->GetPtr().get() == nullptr) {
2367 LOGE("Invalid noti reference can not be sended");
2368 return NOTI_EX_ERROR_INVALID_PARAMETER;
2370 *request_id = stub->Delete(item->GetPtr());
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_delete_all(
2380 noti_ex_reporter_h handle, int *request_id) {
2381 if (handle == nullptr || request_id == nullptr) {
2382 LOGE("Invalid parameter");
2383 return NOTI_EX_ERROR_INVALID_PARAMETER;
2386 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2387 *request_id = stub->DeleteAll();
2388 } catch (Exception &ex) {
2389 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2390 return NOTI_EX_ERROR_IO_ERROR;
2392 return NOTI_EX_ERROR_NONE;
2395 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2396 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2397 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2398 LOGE("Invalid parameter");
2399 return NOTI_EX_ERROR_INVALID_PARAMETER;
2402 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2403 *item = new Handle(stub->FindByRootID(root_id));
2404 } catch (Exception &ex) {
2405 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2406 return NOTI_EX_ERROR_IO_ERROR;
2408 return NOTI_EX_ERROR_NONE;
2411 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2412 const char *id, const char *text, const char *hyper_link) {
2413 if (handle == nullptr) {
2414 LOGE("Invalid parameter");
2415 return NOTI_EX_ERROR_INVALID_PARAMETER;
2418 auto* p = new (std::nothrow) TextItem(id, std::string(text),
2419 std::string(hyper_link));
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 auto* p = new (std::nothrow) VisibilityAction(extra);
2550 LOGE("Out-of-memory");
2551 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2556 return NOTI_EX_ERROR_NONE;
2559 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2560 const char *id, bool visible) {
2561 if (handle == nullptr || id == nullptr) {
2562 LOGE("Invalid parameter");
2563 return NOTI_EX_ERROR_INVALID_PARAMETER;
2566 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2567 p->SetVisibility(id, visible);
2569 return NOTI_EX_ERROR_NONE;