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 string receiver_group_str = "";
1956 receiver_group_str = string(receiver_group);
1958 ManagerStub* stub = new (std::nothrow) ManagerStub(
1959 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1960 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1961 receiver_group_str);
1962 if (stub == nullptr) {
1963 LOGE("Fail to create manager");
1964 return NOTI_EX_ERROR_IO_ERROR;
1966 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1967 new ManagerCallbackInfo(event_callbacks, data)));
1968 *handle = static_cast<noti_ex_manager_h>(stub);
1970 return NOTI_EX_ERROR_NONE;
1973 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1974 if (handle == nullptr) {
1975 LOGE("Invalid parameter");
1976 return NOTI_EX_ERROR_INVALID_PARAMETER;
1978 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1980 return NOTI_EX_ERROR_NONE;
1983 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1984 noti_ex_item_h **items, int *count) {
1985 if (handle == nullptr || items == nullptr || count == nullptr) {
1986 LOGE("Invalid parameter");
1987 return NOTI_EX_ERROR_INVALID_PARAMETER;
1991 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1992 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1993 if (item_list.size() == 0) {
1996 return NOTI_EX_ERROR_NONE;
1998 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1999 if (*items == nullptr) {
2000 LOGE("Fail to create items");
2001 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2005 for (auto& i : item_list) {
2006 *items[idx++] = new Handle(move(i));
2008 *count = item_list.size();
2009 } catch (Exception &ex) {
2010 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2011 return NOTI_EX_ERROR_IO_ERROR;
2013 return NOTI_EX_ERROR_NONE;
2016 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2017 noti_ex_item_h noti, int *request_id) {
2018 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2019 LOGE("Invalid parameter");
2020 return NOTI_EX_ERROR_INVALID_PARAMETER;
2023 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2024 Handle* sp = static_cast<Handle*>(noti);
2025 if (sp->GetPtr().get() == nullptr) {
2026 LOGE("Invalid noti reference can not be sended");
2027 return NOTI_EX_ERROR_INVALID_PARAMETER;
2029 *request_id = stub->Update(sp->GetPtr());
2031 } catch (Exception &ex) {
2032 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2033 return NOTI_EX_ERROR_IO_ERROR;
2035 return NOTI_EX_ERROR_NONE;
2038 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2039 noti_ex_item_h noti, int *request_id) {
2040 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2041 LOGE("Invalid parameter");
2042 return NOTI_EX_ERROR_INVALID_PARAMETER;
2045 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2046 Handle* item = static_cast<Handle*>(noti);
2047 if (item->GetPtr().get() == nullptr) {
2048 LOGE("Invalid noti reference can not be sended");
2049 return NOTI_EX_ERROR_INVALID_PARAMETER;
2051 *request_id = stub->Delete(item->GetPtr());
2053 } catch (Exception &ex) {
2054 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2055 return NOTI_EX_ERROR_IO_ERROR;
2057 return NOTI_EX_ERROR_NONE;
2060 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2062 if (handle == nullptr || request_id == nullptr) {
2063 LOGE("Invalid parameter");
2064 return NOTI_EX_ERROR_INVALID_PARAMETER;
2067 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2068 *request_id = stub->DeleteAll();
2069 } catch (Exception &ex) {
2070 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2071 return NOTI_EX_ERROR_IO_ERROR;
2073 return NOTI_EX_ERROR_NONE;
2076 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2077 noti_ex_item_h noti, int *request_id) {
2078 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2079 LOGE("Invalid parameter");
2080 return NOTI_EX_ERROR_INVALID_PARAMETER;
2083 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2084 Handle* item = static_cast<Handle*>(noti);
2085 if (item->GetPtr().get() == nullptr) {
2086 LOGE("Invalid noti reference can not be sended");
2087 return NOTI_EX_ERROR_INVALID_PARAMETER;
2089 *request_id = stub->Hide(item->GetPtr());
2091 } catch (Exception &ex) {
2092 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2093 return NOTI_EX_ERROR_IO_ERROR;
2095 return NOTI_EX_ERROR_NONE;
2098 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2099 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2100 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2101 LOGE("Invalid parameter");
2102 return NOTI_EX_ERROR_INVALID_PARAMETER;
2105 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2106 *item = new Handle(stub->FindByRootID(root_id));
2107 } catch (Exception &ex) {
2108 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2109 return NOTI_EX_ERROR_IO_ERROR;
2111 return NOTI_EX_ERROR_NONE;
2114 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2115 noti_ex_event_info_h info, noti_ex_error_e error) {
2116 if (handle == nullptr || info == nullptr) {
2117 LOGE("Invalid parameter");
2118 return NOTI_EX_ERROR_INVALID_PARAMETER;
2121 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2122 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2123 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2124 static_cast<NotificationError>(error));
2125 } catch (Exception &ex) {
2126 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2127 return NOTI_EX_ERROR_IO_ERROR;
2129 return NOTI_EX_ERROR_NONE;
2132 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2135 if (handle == nullptr || cnt == nullptr) {
2136 LOGE("Invalid parameter");
2137 return NOTI_EX_ERROR_INVALID_PARAMETER;
2140 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2141 *cnt = stub->GetCount();
2142 } catch (Exception &ex) {
2143 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2144 return NOTI_EX_ERROR_IO_ERROR;
2146 return NOTI_EX_ERROR_NONE;
2149 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2150 const char *id, float min, float current, float max) {
2153 if (handle == nullptr) {
2154 LOGE("Invalid parameter");
2155 return NOTI_EX_ERROR_INVALID_PARAMETER;
2159 p = new (std::nothrow) ProgressItem(id, min, current, max);
2161 p = new (std::nothrow) ProgressItem(min, current, max);
2164 LOGE("Out-of-memory");
2165 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2168 *handle = new Handle(p);
2170 return NOTI_EX_ERROR_NONE;
2173 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2174 noti_ex_item_h handle, float *current) {
2175 if (handle == nullptr || current == nullptr) {
2176 LOGE("Invalid parameter");
2177 return NOTI_EX_ERROR_INVALID_PARAMETER;
2180 Handle *h = static_cast<Handle*>(handle);
2181 if (!h->IsValidType(AbstractItem::Progress)) {
2182 LOGE("Invalid handle type");
2183 return NOTI_EX_ERROR_INVALID_PARAMETER;
2185 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2186 *current = p->GetCurrent();
2188 return NOTI_EX_ERROR_NONE;
2191 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2192 noti_ex_item_h handle, float current) {
2193 if (handle == nullptr) {
2194 LOGE("Invalid parameter");
2195 return NOTI_EX_ERROR_INVALID_PARAMETER;
2198 Handle *h = static_cast<Handle*>(handle);
2199 if (!h->IsValidType(AbstractItem::Progress)) {
2200 LOGE("Invalid handle type");
2201 return NOTI_EX_ERROR_INVALID_PARAMETER;
2203 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2204 p->SetCurrent(current);
2206 return NOTI_EX_ERROR_NONE;
2209 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2211 if (handle == nullptr || min == nullptr) {
2212 LOGE("Invalid parameter");
2213 return NOTI_EX_ERROR_INVALID_PARAMETER;
2216 Handle *h = static_cast<Handle*>(handle);
2217 if (!h->IsValidType(AbstractItem::Progress)) {
2218 LOGE("Invalid handle type");
2219 return NOTI_EX_ERROR_INVALID_PARAMETER;
2221 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2224 return NOTI_EX_ERROR_NONE;
2227 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2229 if (handle == nullptr || max == nullptr) {
2230 LOGE("Invalid parameter");
2231 return NOTI_EX_ERROR_INVALID_PARAMETER;
2234 Handle *h = static_cast<Handle*>(handle);
2235 if (!h->IsValidType(AbstractItem::Progress)) {
2236 LOGE("Invalid handle type");
2237 return NOTI_EX_ERROR_INVALID_PARAMETER;
2239 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2242 return NOTI_EX_ERROR_NONE;
2245 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2246 noti_ex_reporter_events_s event_callbacks, void *data) {
2247 if (handle == nullptr) {
2248 LOGE("Invalid parameter");
2249 return NOTI_EX_ERROR_INVALID_PARAMETER;
2252 ReporterStub* stub = new (std::nothrow) ReporterStub(
2253 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2254 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2255 if (stub == nullptr) {
2256 LOGE("Fail to create manager");
2257 return NOTI_EX_ERROR_IO_ERROR;
2259 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2260 new ReporterCallbackInfo(event_callbacks, data)));
2262 *handle = static_cast<noti_ex_reporter_h>(stub);
2264 return NOTI_EX_ERROR_NONE;
2267 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2268 if (handle == nullptr) {
2269 LOGE("Invalid parameter");
2270 return NOTI_EX_ERROR_INVALID_PARAMETER;
2272 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2274 return NOTI_EX_ERROR_NONE;
2277 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2278 noti_ex_event_info_h info, noti_ex_error_e error) {
2279 if (handle == nullptr || info == nullptr) {
2280 LOGE("Invalid parameter");
2281 return NOTI_EX_ERROR_INVALID_PARAMETER;
2284 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2285 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2286 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2287 static_cast<NotificationError>(error));
2288 } catch (Exception &ex) {
2289 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2290 return NOTI_EX_ERROR_IO_ERROR;
2292 return NOTI_EX_ERROR_NONE;
2295 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2296 noti_ex_item_h noti, int *request_id) {
2297 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2298 LOGE("Invalid parameter");
2299 return NOTI_EX_ERROR_INVALID_PARAMETER;
2302 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2303 Handle* h = static_cast<Handle*>(noti);
2304 if (h->GetPtr().get() == nullptr) {
2305 LOGE("Invalid noti reference can not be sended");
2306 return NOTI_EX_ERROR_INVALID_PARAMETER;
2308 *request_id = stub->Post(h->GetPtr());
2310 } catch (Exception &ex) {
2311 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2312 return NOTI_EX_ERROR_IO_ERROR;
2314 return NOTI_EX_ERROR_NONE;
2317 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2318 noti_ex_item_h *noti_list, int count, int *request_id) {
2320 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2321 LOGE("Invalid parameter");
2322 return NOTI_EX_ERROR_INVALID_PARAMETER;
2325 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2326 list<shared_ptr<item::AbstractItem>> notiList;
2327 for (int i = 0; i < count; i++) {
2328 Handle* item = static_cast<Handle*>(noti_list[i]);
2329 notiList.push_back(item->GetPtr());
2331 *request_id = stub->Post(notiList);
2332 } catch (Exception &ex) {
2333 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2334 return NOTI_EX_ERROR_IO_ERROR;
2336 return NOTI_EX_ERROR_NONE;
2339 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2340 noti_ex_item_h noti, int *request_id) {
2341 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2342 LOGE("Invalid parameter");
2343 return NOTI_EX_ERROR_INVALID_PARAMETER;
2346 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2347 Handle* item = static_cast<Handle*>(noti);
2348 if (item->GetPtr().get() == nullptr) {
2349 LOGE("Invalid noti reference can not be sended");
2350 return NOTI_EX_ERROR_INVALID_PARAMETER;
2352 *request_id = stub->Update(item->GetPtr());
2354 } catch (Exception &ex) {
2355 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2356 return NOTI_EX_ERROR_IO_ERROR;
2358 return NOTI_EX_ERROR_NONE;
2361 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2362 noti_ex_item_h noti, int *request_id) {
2363 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2364 LOGE("Invalid parameter");
2365 return NOTI_EX_ERROR_INVALID_PARAMETER;
2368 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2369 Handle* item = static_cast<Handle*>(noti);
2370 if (item->GetPtr().get() == nullptr) {
2371 LOGE("Invalid noti reference can not be sended");
2372 return NOTI_EX_ERROR_INVALID_PARAMETER;
2374 *request_id = stub->Delete(item->GetPtr());
2376 } catch (Exception &ex) {
2377 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2378 return NOTI_EX_ERROR_IO_ERROR;
2380 return NOTI_EX_ERROR_NONE;
2383 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2384 noti_ex_reporter_h handle, int *request_id) {
2385 if (handle == nullptr || request_id == nullptr) {
2386 LOGE("Invalid parameter");
2387 return NOTI_EX_ERROR_INVALID_PARAMETER;
2390 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2391 *request_id = stub->DeleteAll();
2392 } catch (Exception &ex) {
2393 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2394 return NOTI_EX_ERROR_IO_ERROR;
2396 return NOTI_EX_ERROR_NONE;
2399 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2400 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2401 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2402 LOGE("Invalid parameter");
2403 return NOTI_EX_ERROR_INVALID_PARAMETER;
2406 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2407 *item = new Handle(stub->FindByRootID(root_id));
2408 } catch (Exception &ex) {
2409 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2410 return NOTI_EX_ERROR_IO_ERROR;
2412 return NOTI_EX_ERROR_NONE;
2415 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2416 const char *id, const char *text, const char *hyper_link) {
2417 if (handle == nullptr) {
2418 LOGE("Invalid parameter");
2419 return NOTI_EX_ERROR_INVALID_PARAMETER;
2422 auto* p = new (std::nothrow) TextItem(id, std::string(text),
2423 std::string(hyper_link));
2425 LOGE("Out-of-memory");
2426 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2429 *handle = new Handle(p);
2431 return NOTI_EX_ERROR_NONE;
2434 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2435 const char *contents) {
2436 if (handle == nullptr) {
2437 LOGE("Invalid parameter");
2438 return NOTI_EX_ERROR_INVALID_PARAMETER;
2441 Handle* p = static_cast<Handle*>(handle);
2442 if (!p->IsValidType(AbstractItem::Text)) {
2443 LOGE("Invalid handle type");
2444 return NOTI_EX_ERROR_INVALID_PARAMETER;
2446 TextItem* ti = static_cast<TextItem*>(p->Get());
2447 ti->SetContents(std::string(contents));
2449 return NOTI_EX_ERROR_NONE;
2452 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2454 if (handle == nullptr || contents == nullptr) {
2455 LOGE("Invalid parameter");
2456 return NOTI_EX_ERROR_INVALID_PARAMETER;
2459 Handle* p = static_cast<Handle*>(handle);
2460 if (!p->IsValidType(AbstractItem::Text)) {
2461 LOGE("Invalid handle type");
2462 return NOTI_EX_ERROR_INVALID_PARAMETER;
2464 TextItem* ti = static_cast<TextItem*>(p->Get());
2465 if (!ti->GetContents().empty()) {
2466 *contents = strdup(ti->GetContents().c_str());
2467 if (*contents == nullptr) {
2468 LOGE("Out-of-memory");
2469 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2473 return NOTI_EX_ERROR_NONE;
2476 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2477 noti_ex_item_h handle, char **hyper_link) {
2478 if (handle == nullptr || hyper_link == nullptr) {
2479 LOGE("Invalid parameter");
2480 return NOTI_EX_ERROR_INVALID_PARAMETER;
2483 Handle* p = static_cast<Handle*>(handle);
2484 if (!p->IsValidType(AbstractItem::Text)) {
2485 LOGE("Invalid handle type");
2486 return NOTI_EX_ERROR_INVALID_PARAMETER;
2488 TextItem* ti = static_cast<TextItem*>(p->Get());
2489 if (!ti->GetHyperLink().empty()) {
2490 *hyper_link = strdup(ti->GetHyperLink().c_str());
2491 if (*hyper_link == nullptr) {
2492 LOGE("Out-of-memory");
2493 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2497 return NOTI_EX_ERROR_NONE;
2500 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2501 const char *id, time_t time) {
2504 if (handle == nullptr) {
2505 LOGE("Invalid parameter");
2506 return NOTI_EX_ERROR_INVALID_PARAMETER;
2511 p = new (std::nothrow) TimeItem(id, time);
2513 p = new (std::nothrow) TimeItem(time);
2515 p = new (std::nothrow) TimeItem();
2519 LOGE("Out-of-memory");
2520 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2523 *handle = new Handle(p);
2525 return NOTI_EX_ERROR_NONE;
2528 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2530 if (handle == nullptr || time == nullptr) {
2531 LOGE("Invalid parameter");
2532 return NOTI_EX_ERROR_INVALID_PARAMETER;
2534 Handle* h = static_cast<Handle*>(handle);
2535 if (!h->IsValidType(AbstractItem::Time)) {
2536 LOGE("Invalid handle type");
2537 return NOTI_EX_ERROR_INVALID_PARAMETER;
2539 TimeItem* p = static_cast<TimeItem*>(h->Get());
2540 *time = p->GetTime();
2542 return NOTI_EX_ERROR_NONE;
2545 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2546 noti_ex_action_h *handle, const char *extra) {
2547 if (handle == nullptr) {
2548 LOGE("Invalid parameter");
2549 return NOTI_EX_ERROR_INVALID_PARAMETER;
2552 string extra_str = "";
2554 extra_str = string(extra);
2556 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2558 LOGE("Out-of-memory");
2559 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2564 return NOTI_EX_ERROR_NONE;
2567 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2568 const char *id, bool visible) {
2569 if (handle == nullptr || id == nullptr) {
2570 LOGE("Invalid parameter");
2571 return NOTI_EX_ERROR_INVALID_PARAMETER;
2574 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2575 p->SetVisibility(id, visible);
2577 return NOTI_EX_ERROR_NONE;