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_child(noti_ex_item_h handle,
799 noti_ex_item_group_foreach_child_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 char **list = (char**)calloc(contents.size(), sizeof(char*));
912 for (auto& i : contents) {
913 list[idx++] = strdup(i.c_str());
915 *count = contents.size();
916 *contents_list = list;
918 return NOTI_EX_ERROR_NONE;
921 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
922 noti_ex_item_h handle, const char **contents, int count) {
923 if (handle == nullptr || contents == nullptr) {
924 LOGE("Invalid parameter");
925 return NOTI_EX_ERROR_INVALID_PARAMETER;
928 list<string> new_contents;
929 Handle* h = static_cast<Handle*>(handle);
930 if (!h->IsValidType(AbstractItem::InputSelector)) {
931 LOGE("Invalid handle type");
932 return NOTI_EX_ERROR_INVALID_PARAMETER;
934 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
935 for (int i = 0; i < count; i++) {
936 new_contents.push_back(contents[i]);
938 p->SetContents(move(new_contents));
940 return NOTI_EX_ERROR_NONE;
943 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
944 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
945 if (handle == nullptr) {
946 LOGE("Invalid parameter");
947 return NOTI_EX_ERROR_INVALID_PARAMETER;
950 auto* p = new (std::nothrow) Color(a, r, g, b);
952 LOGE("Out-of-memory");
953 return NOTI_EX_ERROR_OUT_OF_MEMORY;
958 return NOTI_EX_ERROR_NONE;
961 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
962 if (handle == nullptr) {
963 LOGE("Invalid parameter");
964 return NOTI_EX_ERROR_INVALID_PARAMETER;
967 Color* p = static_cast<Color*>(handle);
970 return NOTI_EX_ERROR_NONE;
973 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
974 unsigned char *val) {
975 if (handle == nullptr || val == nullptr) {
976 LOGE("Invalid parameter");
977 return NOTI_EX_ERROR_INVALID_PARAMETER;
980 Color* p = static_cast<Color*>(handle);
983 return NOTI_EX_ERROR_NONE;
986 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
987 unsigned char *val) {
988 if (handle == nullptr || val == nullptr) {
989 LOGE("Invalid parameter");
990 return NOTI_EX_ERROR_INVALID_PARAMETER;
993 Color* p = static_cast<Color*>(handle);
996 return NOTI_EX_ERROR_NONE;
999 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1000 unsigned char *val) {
1001 if (handle == nullptr || val == nullptr) {
1002 LOGE("Invalid parameter");
1003 return NOTI_EX_ERROR_INVALID_PARAMETER;
1006 Color* p = static_cast<Color*>(handle);
1007 *val = p->GetGVal();
1009 return NOTI_EX_ERROR_NONE;
1012 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1013 unsigned char *val) {
1014 if (handle == nullptr || val == nullptr) {
1015 LOGE("Invalid parameter");
1016 return NOTI_EX_ERROR_INVALID_PARAMETER;
1019 Color* p = static_cast<Color*>(handle);
1020 *val = p->GetBVal();
1022 return NOTI_EX_ERROR_NONE;
1025 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1026 int left, int top, int right, int bottom) {
1027 if (handle == nullptr) {
1028 LOGE("Invalid parameter");
1029 return NOTI_EX_ERROR_INVALID_PARAMETER;
1032 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1034 LOGE("Out-of-memory");
1035 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1040 return NOTI_EX_ERROR_NONE;
1043 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1044 if (handle == nullptr) {
1045 LOGE("Invalid parameter");
1046 return NOTI_EX_ERROR_INVALID_PARAMETER;
1049 Padding* p = static_cast<Padding*>(handle);
1052 return NOTI_EX_ERROR_NONE;
1055 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1057 if (handle == nullptr || val == nullptr) {
1058 LOGE("Invalid parameter");
1059 return NOTI_EX_ERROR_INVALID_PARAMETER;
1062 Padding* p = static_cast<Padding*>(handle);
1063 *val = p->GetLeft();
1065 return NOTI_EX_ERROR_NONE;
1068 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1070 if (handle == nullptr || val == nullptr) {
1071 LOGE("Invalid parameter");
1072 return NOTI_EX_ERROR_INVALID_PARAMETER;
1075 Padding* p = static_cast<Padding*>(handle);
1078 return NOTI_EX_ERROR_NONE;
1081 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1083 if (handle == nullptr || val == nullptr) {
1084 LOGE("Invalid parameter");
1085 return NOTI_EX_ERROR_INVALID_PARAMETER;
1088 Padding* p = static_cast<Padding*>(handle);
1089 *val = p->GetRight();
1091 return NOTI_EX_ERROR_NONE;
1094 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1096 if (handle == nullptr || val == nullptr) {
1097 LOGE("Invalid parameter");
1098 return NOTI_EX_ERROR_INVALID_PARAMETER;
1101 Padding* p = static_cast<Padding*>(handle);
1102 *val = p->GetBottom();
1104 return NOTI_EX_ERROR_NONE;
1107 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1108 int x, int y, int w, int h) {
1109 if (handle == nullptr) {
1110 LOGE("Invalid parameter");
1111 return NOTI_EX_ERROR_INVALID_PARAMETER;
1114 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1116 LOGE("Out-of-memory");
1117 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1122 return NOTI_EX_ERROR_NONE;
1125 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1126 if (handle == nullptr) {
1127 LOGE("Invalid parameter");
1128 return NOTI_EX_ERROR_INVALID_PARAMETER;
1131 Geometry* p = static_cast<Geometry*>(handle);
1134 return NOTI_EX_ERROR_NONE;
1137 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1139 if (handle == nullptr || val == nullptr) {
1140 LOGE("Invalid parameter");
1141 return NOTI_EX_ERROR_INVALID_PARAMETER;
1144 Geometry* p = static_cast<Geometry*>(handle);
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1152 if (handle == nullptr || val == nullptr) {
1153 LOGE("Invalid parameter");
1154 return NOTI_EX_ERROR_INVALID_PARAMETER;
1157 Geometry* p = static_cast<Geometry*>(handle);
1160 return NOTI_EX_ERROR_NONE;
1163 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1165 if (handle == nullptr || val == nullptr) {
1166 LOGE("Invalid parameter");
1167 return NOTI_EX_ERROR_INVALID_PARAMETER;
1170 Geometry* p = static_cast<Geometry*>(handle);
1171 *val = p->GetWidth();
1173 return NOTI_EX_ERROR_NONE;
1176 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1178 if (handle == nullptr || val == nullptr) {
1179 LOGE("Invalid parameter");
1180 return NOTI_EX_ERROR_INVALID_PARAMETER;
1183 Geometry* p = static_cast<Geometry*>(handle);
1184 *val = p->GetHeight();
1186 return NOTI_EX_ERROR_NONE;
1189 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1190 noti_ex_color_h color,
1191 noti_ex_padding_h padding,
1192 noti_ex_geometry_h geometry) {
1193 if (handle == nullptr) {
1194 LOGE("Invalid parameter");
1195 return NOTI_EX_ERROR_INVALID_PARAMETER;
1198 Color* color_ = static_cast<Color*>(color);
1199 Padding* padding_ = static_cast<Padding*>(padding);
1200 Geometry* geo_ = static_cast<Geometry*>(geometry);
1202 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1204 LOGE("Out-of-memory");
1205 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1210 return NOTI_EX_ERROR_NONE;
1213 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1214 if (handle == nullptr) {
1215 LOGE("Invalid parameter");
1216 return NOTI_EX_ERROR_INVALID_PARAMETER;
1219 Style* p = static_cast<Style*>(handle);
1222 return NOTI_EX_ERROR_NONE;
1225 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1226 noti_ex_padding_h *padding) {
1227 if (handle == nullptr || padding == nullptr) {
1228 LOGE("Invalid parameter");
1229 return NOTI_EX_ERROR_INVALID_PARAMETER;
1232 Style* p = static_cast<Style*>(handle);
1233 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1234 if (padding_ == nullptr) {
1235 LOGE("Out-of-memory");
1236 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1239 *padding = padding_;
1241 return NOTI_EX_ERROR_NONE;
1244 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1245 noti_ex_color_h *color) {
1246 if (handle == nullptr || color == nullptr) {
1247 LOGE("Invalid parameter");
1248 return NOTI_EX_ERROR_INVALID_PARAMETER;
1251 Style* p = static_cast<Style*>(handle);
1252 Color* color_ = new (std::nothrow) Color(p->GetColor());
1253 if (color_ == nullptr) {
1254 LOGE("Out-of-memory");
1255 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1260 return NOTI_EX_ERROR_NONE;
1263 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1264 noti_ex_geometry_h *geometry) {
1265 if (handle == nullptr || geometry == nullptr) {
1266 LOGE("Invalid parameter");
1267 return NOTI_EX_ERROR_INVALID_PARAMETER;
1270 Style* p = static_cast<Style*>(handle);
1271 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1272 if (geo_ == nullptr) {
1273 LOGE("Out-of-memory");
1274 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1279 return NOTI_EX_ERROR_NONE;
1282 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1283 noti_ex_color_h color) {
1284 if (handle == nullptr) {
1285 LOGE("Invalid parameter");
1286 return NOTI_EX_ERROR_INVALID_PARAMETER;
1289 Color* color_ = static_cast<Color*>(color);
1290 auto* p = new (std::nothrow) LEDInfo(*color_);
1292 LOGE("Out-of-memory");
1293 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1298 return NOTI_EX_ERROR_NONE;
1301 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1302 if (handle == nullptr) {
1303 LOGE("Invalid parameter");
1304 return NOTI_EX_ERROR_INVALID_PARAMETER;
1307 LEDInfo* p = static_cast<LEDInfo*>(handle);
1310 return NOTI_EX_ERROR_NONE;
1313 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1314 noti_ex_led_info_h handle, int ms) {
1315 if (handle == nullptr) {
1316 LOGE("Invalid parameter");
1317 return NOTI_EX_ERROR_INVALID_PARAMETER;
1320 LEDInfo* p = static_cast<LEDInfo*>(handle);
1323 return NOTI_EX_ERROR_NONE;
1326 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1327 noti_ex_led_info_h handle, int *ms) {
1328 if (handle == nullptr || ms == nullptr) {
1329 LOGE("Invalid parameter");
1330 return NOTI_EX_ERROR_INVALID_PARAMETER;
1333 LEDInfo* p = static_cast<LEDInfo*>(handle);
1334 *ms = p->GetOnPeriod();
1336 return NOTI_EX_ERROR_NONE;
1339 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1340 noti_ex_led_info_h handle, int ms) {
1341 if (handle == nullptr) {
1342 LOGE("Invalid parameter");
1343 return NOTI_EX_ERROR_INVALID_PARAMETER;
1346 LEDInfo* p = static_cast<LEDInfo*>(handle);
1347 p->SetOffPeriod(ms);
1349 return NOTI_EX_ERROR_NONE;
1352 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1353 noti_ex_led_info_h handle, int *ms) {
1354 if (handle == nullptr) {
1355 LOGE("Invalid parameter");
1356 return NOTI_EX_ERROR_INVALID_PARAMETER;
1359 LEDInfo* p = static_cast<LEDInfo*>(handle);
1360 *ms = p->GetOffPeriod();
1362 return NOTI_EX_ERROR_NONE;
1365 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1366 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1367 if (handle == nullptr) {
1368 LOGE("Invalid parameter");
1369 return NOTI_EX_ERROR_INVALID_PARAMETER;
1372 LEDInfo* p = static_cast<LEDInfo*>(handle);
1373 Color* color_ = new (std::nothrow) Color(p->GetColor());
1374 if (color_ == nullptr) {
1375 LOGE("Out-of-memory");
1376 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1381 return NOTI_EX_ERROR_NONE;
1384 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1385 if (handle == nullptr) {
1386 LOGE("Invalid parameter");
1387 return NOTI_EX_ERROR_INVALID_PARAMETER;
1390 AbstractAction* p = static_cast<AbstractAction*>(handle);
1391 p->~AbstractAction();
1393 return NOTI_EX_ERROR_NONE;
1396 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1398 if (handle == nullptr || type == nullptr) {
1399 LOGE("Invalid parameter");
1400 return NOTI_EX_ERROR_INVALID_PARAMETER;
1403 AbstractAction* p = static_cast<AbstractAction*>(handle);
1404 *type = p->GetType();
1406 return NOTI_EX_ERROR_NONE;
1409 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1411 if (handle == nullptr || local == nullptr) {
1412 LOGE("Invalid parameter");
1413 return NOTI_EX_ERROR_INVALID_PARAMETER;
1416 AbstractAction* p = static_cast<AbstractAction*>(handle);
1417 *local = p->IsLocal();
1419 return NOTI_EX_ERROR_NONE;
1422 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1423 noti_ex_item_h item) {
1424 if (handle == nullptr || item==nullptr) {
1425 LOGE("Invalid parameter");
1426 return NOTI_EX_ERROR_INVALID_PARAMETER;
1428 AbstractAction* p = static_cast<AbstractAction*>(handle);
1429 Handle* ih = static_cast<Handle*>(item);
1430 p->Execute(ih->GetPtr());
1432 return NOTI_EX_ERROR_NONE;
1435 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1437 if (handle == nullptr || extra == nullptr) {
1438 LOGE("Invalid parameter");
1439 return NOTI_EX_ERROR_INVALID_PARAMETER;
1442 AbstractAction* p = static_cast<AbstractAction*>(handle);
1443 if (!p->GetExtra().empty()) {
1444 *extra = strdup(p->GetExtra().c_str());
1445 if (*extra == nullptr) {
1446 LOGE("Out-of-memory");
1447 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1451 return NOTI_EX_ERROR_NONE;
1454 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1455 noti_ex_item_info_h handle, int *hide_time) {
1456 if (handle == nullptr || hide_time == nullptr) {
1457 LOGE("Invalid parameter");
1458 return NOTI_EX_ERROR_INVALID_PARAMETER;
1460 IItemInfo* p = static_cast<IItemInfo*>(handle);
1461 *hide_time = p->GetHideTime();
1462 return NOTI_EX_ERROR_NONE;
1465 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1466 noti_ex_item_info_h handle, int hide_time) {
1467 if (handle == nullptr) {
1468 LOGE("Invalid parameter");
1469 return NOTI_EX_ERROR_INVALID_PARAMETER;
1471 IItemInfo* p = static_cast<IItemInfo*>(handle);
1472 p->SetHideTime(hide_time);
1473 return NOTI_EX_ERROR_NONE;
1476 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1477 noti_ex_item_info_h handle, int *delete_time) {
1478 if (handle == nullptr || delete_time == nullptr) {
1479 LOGE("Invalid parameter");
1480 return NOTI_EX_ERROR_INVALID_PARAMETER;
1482 IItemInfo* p = static_cast<IItemInfo*>(handle);
1483 *delete_time = p->GetDeleteTime();
1484 return NOTI_EX_ERROR_NONE;
1487 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1488 noti_ex_item_info_h handle, int delete_time) {
1489 if (handle == nullptr) {
1490 LOGE("Invalid parameter");
1491 return NOTI_EX_ERROR_INVALID_PARAMETER;
1493 IItemInfo* p = static_cast<IItemInfo*>(handle);
1494 p->SetDeleteTime(delete_time);
1495 return NOTI_EX_ERROR_NONE;
1498 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1499 noti_ex_item_info_h handle, time_t *time) {
1500 if (handle == nullptr || time == nullptr) {
1501 LOGE("Invalid parameter");
1502 return NOTI_EX_ERROR_INVALID_PARAMETER;
1505 IItemInfo* p = static_cast<IItemInfo*>(handle);
1506 *time = p->GetTime();
1507 return NOTI_EX_ERROR_NONE;
1510 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1511 if (handle == nullptr) {
1512 LOGE("Invalid parameter");
1513 return NOTI_EX_ERROR_INVALID_PARAMETER;
1516 Handle* h = static_cast<Handle*>(handle);
1518 return NOTI_EX_ERROR_NONE;
1521 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1522 const char *id, noti_ex_item_h *item) {
1523 if (handle == nullptr) {
1524 LOGE("Invalid parameter");
1525 return NOTI_EX_ERROR_INVALID_PARAMETER;
1528 Handle* p = static_cast<Handle*>(handle);
1529 AbstractItem& find_item = p->Get()->FindByID(string(id));
1530 *item = new Handle(&find_item);
1531 return NOTI_EX_ERROR_NONE;
1534 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1536 if (handle == nullptr || type == nullptr) {
1537 LOGE("Invalid parameter");
1538 return NOTI_EX_ERROR_INVALID_PARAMETER;
1541 Handle* h = static_cast<Handle*>(handle);
1542 AbstractItem* p = h->Get();
1543 *type = p->GetType();
1544 return NOTI_EX_ERROR_NONE;
1547 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1548 char ***path, int *count) {
1549 if (handle == nullptr || path == nullptr || count == nullptr) {
1550 LOGE("Invalid parameter");
1551 return NOTI_EX_ERROR_INVALID_PARAMETER;
1553 Handle* p = static_cast<Handle*>(handle);
1554 list<string> shared_path = p->Get()->GetSharedPath();
1555 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1557 for (auto& i : shared_path) {
1558 *path[idx++] = strdup(i.c_str());
1560 *count = shared_path.size();
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1566 if (handle == nullptr || id == nullptr) {
1567 LOGE("Invalid parameter");
1568 return NOTI_EX_ERROR_INVALID_PARAMETER;
1570 Handle* h = static_cast<Handle*>(handle);
1571 AbstractItem* p = h->Get();
1572 *id = strdup(p->GetId().c_str());
1573 return NOTI_EX_ERROR_NONE;
1576 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1578 if (handle == nullptr || id == nullptr) {
1579 LOGE("Invalid parameter");
1580 return NOTI_EX_ERROR_INVALID_PARAMETER;
1582 Handle* p = static_cast<Handle*>(handle);
1583 p->Get()->SetId(id);
1584 return NOTI_EX_ERROR_NONE;
1587 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1588 noti_ex_action_h *action) {
1589 if (handle == nullptr || action == nullptr) {
1590 LOGE("Invalid parameter");
1591 return NOTI_EX_ERROR_INVALID_PARAMETER;
1593 Handle* p = static_cast<Handle*>(handle);
1594 if (p->Get()->GetAction() == nullptr) {
1596 return NOTI_EX_ERROR_NONE;
1598 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1600 return NOTI_EX_ERROR_NONE;
1603 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1604 noti_ex_action_h action) {
1605 if (handle == nullptr || action == nullptr) {
1606 LOGE("Invalid parameter");
1607 return NOTI_EX_ERROR_INVALID_PARAMETER;
1610 Handle* p = static_cast<Handle*>(handle);
1611 AbstractAction* a = static_cast<AbstractAction*>(action);
1612 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1613 return NOTI_EX_ERROR_NONE;
1616 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1617 noti_ex_style_h *style) {
1618 if (handle == nullptr || style == nullptr) {
1619 LOGE("Invalid parameter");
1620 return NOTI_EX_ERROR_INVALID_PARAMETER;
1623 Handle* p = static_cast<Handle*>(handle);
1624 shared_ptr<Style> s = p->Get()->GetStyle();
1625 *style = static_cast<noti_ex_style_h>(s.get());
1626 return NOTI_EX_ERROR_NONE;
1629 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1630 noti_ex_style_h style) {
1631 if (handle == nullptr || style == nullptr) {
1632 LOGE("Invalid parameter");
1633 return NOTI_EX_ERROR_INVALID_PARAMETER;
1636 Handle* p = static_cast<Handle*>(handle);
1637 Style* s = static_cast<Style*>(style);
1638 p->Get()->SetStyle(shared_ptr<Style>(s));
1639 return NOTI_EX_ERROR_NONE;
1642 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1644 if (handle == nullptr) {
1645 LOGE("Invalid parameter");
1646 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 Handle* p = static_cast<Handle*>(handle);
1650 p->Get()->SetVisible(visible);
1651 return NOTI_EX_ERROR_NONE;
1654 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1656 if (handle == nullptr || visible == nullptr) {
1657 LOGE("Invalid parameter");
1658 return NOTI_EX_ERROR_INVALID_PARAMETER;
1661 Handle* p = static_cast<Handle*>(handle);
1662 *visible = p->Get()->GetVisible();
1663 return NOTI_EX_ERROR_NONE;
1666 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1668 if (handle == nullptr) {
1669 LOGE("Invalid parameter");
1670 return NOTI_EX_ERROR_INVALID_PARAMETER;
1673 Handle* p = static_cast<Handle*>(handle);
1674 p->Get()->SetEnable(enable);
1675 return NOTI_EX_ERROR_NONE;
1678 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1680 if (handle == nullptr || enable == nullptr) {
1681 LOGE("Invalid parameter");
1682 return NOTI_EX_ERROR_INVALID_PARAMETER;
1685 Handle* p = static_cast<Handle*>(handle);
1686 *enable = p->Get()->GetEnable();
1687 return NOTI_EX_ERROR_NONE;
1690 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1691 const char *receiver_group) {
1692 if (handle == nullptr || receiver_group == nullptr) {
1693 LOGE("Invalid parameter");
1694 return NOTI_EX_ERROR_INVALID_PARAMETER;
1697 Handle* p = static_cast<Handle*>(handle);
1698 p->Get()->AddReceiver(receiver_group);
1699 return NOTI_EX_ERROR_NONE;
1702 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1703 const char *receiver_group) {
1704 if (handle == nullptr || receiver_group == nullptr) {
1705 LOGE("Invalid parameter");
1706 return NOTI_EX_ERROR_INVALID_PARAMETER;
1709 Handle* p = static_cast<Handle*>(handle);
1710 p->Get()->RemoveReceiver(receiver_group);
1711 return NOTI_EX_ERROR_NONE;
1714 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1715 char ***receiver_list, int *count) {
1716 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1717 LOGE("Invalid parameter");
1718 return NOTI_EX_ERROR_INVALID_PARAMETER;
1721 Handle* p = static_cast<Handle*>(handle);
1722 list<string> receivers = p->Get()->GetReceiverList();
1723 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1725 for (auto& i : receivers) {
1726 *receiver_list[idx++] = strdup(i.c_str());
1728 *count = receivers.size();
1729 return NOTI_EX_ERROR_NONE;
1732 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1734 if (handle == nullptr) {
1735 LOGE("Invalid parameter");
1736 return NOTI_EX_ERROR_INVALID_PARAMETER;
1739 Handle* p = static_cast<Handle*>(handle);
1740 p->Get()->SetPolicy(policy);
1741 return NOTI_EX_ERROR_NONE;
1744 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1746 if (handle == nullptr || policy == nullptr) {
1747 LOGE("Invalid parameter");
1748 return NOTI_EX_ERROR_INVALID_PARAMETER;
1751 Handle* p = static_cast<Handle*>(handle);
1752 *policy = p->Get()->GetPolicy();
1753 return NOTI_EX_ERROR_NONE;
1756 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1758 if (handle == nullptr || channel == nullptr) {
1759 LOGE("Invalid parameter");
1760 return NOTI_EX_ERROR_INVALID_PARAMETER;
1763 Handle* p = static_cast<Handle*>(handle);
1764 if (!p->Get()->GetChannel().empty())
1765 *channel = strdup(p->Get()->GetChannel().c_str());
1769 return NOTI_EX_ERROR_NONE;
1772 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1773 const char *channel) {
1774 if (handle == nullptr) {
1775 LOGE("Invalid parameter");
1776 return NOTI_EX_ERROR_INVALID_PARAMETER;
1779 Handle* p = static_cast<Handle*>(handle);
1780 p->Get()->SetChannel(channel);
1781 return NOTI_EX_ERROR_NONE;
1784 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1785 noti_ex_led_info_h led) {
1786 if (handle == nullptr) {
1787 LOGE("Invalid parameter");
1788 return NOTI_EX_ERROR_INVALID_PARAMETER;
1791 Handle* p = static_cast<Handle*>(handle);
1792 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1793 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1794 return NOTI_EX_ERROR_NONE;
1797 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1798 noti_ex_led_info_h *led) {
1799 if (handle == nullptr) {
1800 LOGE("Invalid parameter");
1801 return NOTI_EX_ERROR_INVALID_PARAMETER;
1804 Handle* p = static_cast<Handle*>(handle);
1805 if (p->Get()->GetLEDInfo() != nullptr)
1806 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1809 return NOTI_EX_ERROR_NONE;
1812 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1814 if (handle == nullptr) {
1815 LOGE("Invalid parameter");
1816 return NOTI_EX_ERROR_INVALID_PARAMETER;
1819 Handle* p = static_cast<Handle*>(handle);
1820 if (path == nullptr)
1821 p->Get()->SetSoundPath("");
1823 p->Get()->SetSoundPath(path);
1824 return NOTI_EX_ERROR_NONE;
1827 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1829 if (handle == nullptr) {
1830 LOGE("Invalid parameter");
1831 return NOTI_EX_ERROR_INVALID_PARAMETER;
1834 Handle* p = static_cast<Handle*>(handle);
1835 if (path == nullptr)
1836 p->Get()->SetVibrationPath("");
1838 p->Get()->SetVibrationPath(path);
1839 return NOTI_EX_ERROR_NONE;
1842 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1844 if (handle == nullptr || path == nullptr) {
1845 LOGE("Invalid parameter");
1846 return NOTI_EX_ERROR_INVALID_PARAMETER;
1849 Handle* p = static_cast<Handle*>(handle);
1850 if (p->Get()->GetSoundPath().empty())
1853 *path = strdup(p->Get()->GetSoundPath().c_str());
1854 return NOTI_EX_ERROR_NONE;
1857 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1859 if (handle == nullptr || path == nullptr) {
1860 LOGE("Invalid parameter");
1861 return NOTI_EX_ERROR_INVALID_PARAMETER;
1864 Handle* p = static_cast<Handle*>(handle);
1865 if (p->Get()->GetVibrationPath().empty())
1868 *path = strdup(p->Get()->GetVibrationPath().c_str());
1869 return NOTI_EX_ERROR_NONE;
1872 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1873 noti_ex_item_info_h *info) {
1874 if (handle == nullptr || info == nullptr) {
1875 LOGE("Invalid parameter");
1876 return NOTI_EX_ERROR_INVALID_PARAMETER;
1879 Handle* p = static_cast<Handle*>(handle);
1880 if (p->Get()->GetInfo() == nullptr)
1883 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1884 return NOTI_EX_ERROR_NONE;
1887 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1889 if (handle == nullptr || id == nullptr) {
1890 LOGE("Invalid parameter");
1891 return NOTI_EX_ERROR_INVALID_PARAMETER;
1894 Handle* p = static_cast<Handle*>(handle);
1895 if (p->Get()->GetSenderAppId().empty())
1898 *id = strdup(p->Get()->GetSenderAppId().c_str());
1899 return NOTI_EX_ERROR_NONE;
1902 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1904 if (handle == nullptr || tag == nullptr) {
1905 LOGE("Invalid parameter");
1906 return NOTI_EX_ERROR_INVALID_PARAMETER;
1909 Handle* p = static_cast<Handle*>(handle);
1910 if (p->Get()->GetTag().empty())
1913 *tag = strdup(p->Get()->GetTag().c_str());
1914 return NOTI_EX_ERROR_NONE;
1917 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1919 if (handle == nullptr) {
1920 LOGE("Invalid parameter");
1921 return NOTI_EX_ERROR_INVALID_PARAMETER;
1924 Handle* p = static_cast<Handle*>(handle);
1926 p->Get()->SetTag("");
1928 p->Get()->SetTag(tag);
1929 return NOTI_EX_ERROR_NONE;
1932 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1933 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1935 if (handle == nullptr) {
1936 LOGE("Invalid parameter");
1937 return NOTI_EX_ERROR_INVALID_PARAMETER;
1940 string receiver_group_str = "";
1942 receiver_group_str = string(receiver_group);
1944 ManagerStub* stub = new (std::nothrow) ManagerStub(
1945 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1946 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1947 receiver_group_str);
1948 if (stub == nullptr) {
1949 LOGE("Fail to create manager");
1950 return NOTI_EX_ERROR_IO_ERROR;
1952 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1953 new ManagerCallbackInfo(event_callbacks, data)));
1954 *handle = static_cast<noti_ex_manager_h>(stub);
1956 return NOTI_EX_ERROR_NONE;
1959 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1960 if (handle == nullptr) {
1961 LOGE("Invalid parameter");
1962 return NOTI_EX_ERROR_INVALID_PARAMETER;
1964 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1970 noti_ex_item_h **items, int *count) {
1971 if (handle == nullptr || items == nullptr || count == nullptr) {
1972 LOGE("Invalid parameter");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1977 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1978 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1979 if (item_list.size() == 0) {
1982 return NOTI_EX_ERROR_NONE;
1984 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1985 if (*items == nullptr) {
1986 LOGE("Fail to create items");
1987 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1991 for (auto& i : item_list) {
1992 *items[idx++] = new Handle(move(i));
1994 *count = item_list.size();
1995 } catch (Exception &ex) {
1996 LOGE("%s %d", ex.what(), ex.GetErrorCode());
1997 return NOTI_EX_ERROR_IO_ERROR;
1999 return NOTI_EX_ERROR_NONE;
2002 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2003 noti_ex_item_h noti, int *request_id) {
2004 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2005 LOGE("Invalid parameter");
2006 return NOTI_EX_ERROR_INVALID_PARAMETER;
2009 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2010 Handle* sp = static_cast<Handle*>(noti);
2011 if (sp->GetPtr().get() == nullptr) {
2012 LOGE("Invalid noti reference can not be sended");
2013 return NOTI_EX_ERROR_INVALID_PARAMETER;
2015 *request_id = stub->Update(sp->GetPtr());
2017 } catch (Exception &ex) {
2018 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2019 return NOTI_EX_ERROR_IO_ERROR;
2021 return NOTI_EX_ERROR_NONE;
2024 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2025 noti_ex_item_h noti, int *request_id) {
2026 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2027 LOGE("Invalid parameter");
2028 return NOTI_EX_ERROR_INVALID_PARAMETER;
2031 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2032 Handle* item = static_cast<Handle*>(noti);
2033 if (item->GetPtr().get() == nullptr) {
2034 LOGE("Invalid noti reference can not be sended");
2035 return NOTI_EX_ERROR_INVALID_PARAMETER;
2037 *request_id = stub->Delete(item->GetPtr());
2039 } catch (Exception &ex) {
2040 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2041 return NOTI_EX_ERROR_IO_ERROR;
2043 return NOTI_EX_ERROR_NONE;
2046 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2048 if (handle == nullptr || request_id == nullptr) {
2049 LOGE("Invalid parameter");
2050 return NOTI_EX_ERROR_INVALID_PARAMETER;
2053 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2054 *request_id = stub->DeleteAll();
2055 } catch (Exception &ex) {
2056 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2057 return NOTI_EX_ERROR_IO_ERROR;
2059 return NOTI_EX_ERROR_NONE;
2062 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2063 noti_ex_item_h noti, int *request_id) {
2064 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2065 LOGE("Invalid parameter");
2066 return NOTI_EX_ERROR_INVALID_PARAMETER;
2069 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2070 Handle* item = static_cast<Handle*>(noti);
2071 if (item->GetPtr().get() == nullptr) {
2072 LOGE("Invalid noti reference can not be sended");
2073 return NOTI_EX_ERROR_INVALID_PARAMETER;
2075 *request_id = stub->Hide(item->GetPtr());
2077 } catch (Exception &ex) {
2078 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2079 return NOTI_EX_ERROR_IO_ERROR;
2081 return NOTI_EX_ERROR_NONE;
2084 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2085 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2086 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2087 LOGE("Invalid parameter");
2088 return NOTI_EX_ERROR_INVALID_PARAMETER;
2091 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2092 *item = new Handle(stub->FindByRootID(root_id));
2093 } catch (Exception &ex) {
2094 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2095 return NOTI_EX_ERROR_IO_ERROR;
2097 return NOTI_EX_ERROR_NONE;
2100 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2101 noti_ex_event_info_h info, noti_ex_error_e error) {
2102 if (handle == nullptr || info == nullptr) {
2103 LOGE("Invalid parameter");
2104 return NOTI_EX_ERROR_INVALID_PARAMETER;
2107 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2108 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2109 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2110 static_cast<NotificationError>(error));
2111 } catch (Exception &ex) {
2112 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2113 return NOTI_EX_ERROR_IO_ERROR;
2115 return NOTI_EX_ERROR_NONE;
2118 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2119 noti_ex_manager_h handle, int *cnt) {
2121 if (handle == nullptr || cnt == nullptr) {
2122 LOGE("Invalid parameter");
2123 return NOTI_EX_ERROR_INVALID_PARAMETER;
2126 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2127 *cnt = stub->GetCount();
2128 } catch (Exception &ex) {
2129 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2130 return NOTI_EX_ERROR_IO_ERROR;
2132 return NOTI_EX_ERROR_NONE;
2135 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2136 const char *id, float min, float current, float max) {
2139 if (handle == nullptr) {
2140 LOGE("Invalid parameter");
2141 return NOTI_EX_ERROR_INVALID_PARAMETER;
2145 p = new (std::nothrow) ProgressItem(id, min, current, max);
2147 p = new (std::nothrow) ProgressItem(min, current, max);
2150 LOGE("Out-of-memory");
2151 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2154 *handle = new Handle(p);
2156 return NOTI_EX_ERROR_NONE;
2159 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2160 noti_ex_item_h handle, float *current) {
2161 if (handle == nullptr || current == nullptr) {
2162 LOGE("Invalid parameter");
2163 return NOTI_EX_ERROR_INVALID_PARAMETER;
2166 Handle *h = static_cast<Handle*>(handle);
2167 if (!h->IsValidType(AbstractItem::Progress)) {
2168 LOGE("Invalid handle type");
2169 return NOTI_EX_ERROR_INVALID_PARAMETER;
2171 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2172 *current = p->GetCurrent();
2174 return NOTI_EX_ERROR_NONE;
2177 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2178 noti_ex_item_h handle, float current) {
2179 if (handle == nullptr) {
2180 LOGE("Invalid parameter");
2181 return NOTI_EX_ERROR_INVALID_PARAMETER;
2184 Handle *h = static_cast<Handle*>(handle);
2185 if (!h->IsValidType(AbstractItem::Progress)) {
2186 LOGE("Invalid handle type");
2187 return NOTI_EX_ERROR_INVALID_PARAMETER;
2189 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2190 p->SetCurrent(current);
2192 return NOTI_EX_ERROR_NONE;
2195 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2197 if (handle == nullptr || min == nullptr) {
2198 LOGE("Invalid parameter");
2199 return NOTI_EX_ERROR_INVALID_PARAMETER;
2202 Handle *h = static_cast<Handle*>(handle);
2203 if (!h->IsValidType(AbstractItem::Progress)) {
2204 LOGE("Invalid handle type");
2205 return NOTI_EX_ERROR_INVALID_PARAMETER;
2207 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2210 return NOTI_EX_ERROR_NONE;
2213 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2215 if (handle == nullptr || max == nullptr) {
2216 LOGE("Invalid parameter");
2217 return NOTI_EX_ERROR_INVALID_PARAMETER;
2220 Handle *h = static_cast<Handle*>(handle);
2221 if (!h->IsValidType(AbstractItem::Progress)) {
2222 LOGE("Invalid handle type");
2223 return NOTI_EX_ERROR_INVALID_PARAMETER;
2225 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2228 return NOTI_EX_ERROR_NONE;
2231 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2232 noti_ex_reporter_events_s event_callbacks, void *data) {
2233 if (handle == nullptr) {
2234 LOGE("Invalid parameter");
2235 return NOTI_EX_ERROR_INVALID_PARAMETER;
2238 ReporterStub* stub = new (std::nothrow) ReporterStub(
2239 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2240 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2241 if (stub == nullptr) {
2242 LOGE("Fail to create manager");
2243 return NOTI_EX_ERROR_IO_ERROR;
2245 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2246 new ReporterCallbackInfo(event_callbacks, data)));
2248 *handle = static_cast<noti_ex_reporter_h>(stub);
2250 return NOTI_EX_ERROR_NONE;
2253 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2254 if (handle == nullptr) {
2255 LOGE("Invalid parameter");
2256 return NOTI_EX_ERROR_INVALID_PARAMETER;
2258 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2260 return NOTI_EX_ERROR_NONE;
2263 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2264 noti_ex_event_info_h info, noti_ex_error_e error) {
2265 if (handle == nullptr || info == nullptr) {
2266 LOGE("Invalid parameter");
2267 return NOTI_EX_ERROR_INVALID_PARAMETER;
2270 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2271 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2272 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2273 static_cast<NotificationError>(error));
2274 } catch (Exception &ex) {
2275 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2276 return NOTI_EX_ERROR_IO_ERROR;
2278 return NOTI_EX_ERROR_NONE;
2281 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2282 noti_ex_item_h noti, int *request_id) {
2283 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2284 LOGE("Invalid parameter");
2285 return NOTI_EX_ERROR_INVALID_PARAMETER;
2288 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2289 Handle* h = static_cast<Handle*>(noti);
2290 if (h->GetPtr().get() == nullptr) {
2291 LOGE("Invalid noti reference can not be sended");
2292 return NOTI_EX_ERROR_INVALID_PARAMETER;
2294 *request_id = stub->Post(h->GetPtr());
2296 } catch (Exception &ex) {
2297 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2298 return NOTI_EX_ERROR_IO_ERROR;
2300 return NOTI_EX_ERROR_NONE;
2303 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2304 noti_ex_item_h *noti_list, int count, int *request_id) {
2306 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2307 LOGE("Invalid parameter");
2308 return NOTI_EX_ERROR_INVALID_PARAMETER;
2311 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2312 list<shared_ptr<item::AbstractItem>> notiList;
2313 for (int i = 0; i < count; i++) {
2314 Handle* item = static_cast<Handle*>(noti_list[i]);
2315 notiList.push_back(item->GetPtr());
2317 *request_id = stub->Post(notiList);
2318 } catch (Exception &ex) {
2319 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2320 return NOTI_EX_ERROR_IO_ERROR;
2322 return NOTI_EX_ERROR_NONE;
2325 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2326 noti_ex_item_h noti, int *request_id) {
2327 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2328 LOGE("Invalid parameter");
2329 return NOTI_EX_ERROR_INVALID_PARAMETER;
2332 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2333 Handle* item = static_cast<Handle*>(noti);
2334 if (item->GetPtr().get() == nullptr) {
2335 LOGE("Invalid noti reference can not be sended");
2336 return NOTI_EX_ERROR_INVALID_PARAMETER;
2338 *request_id = stub->Update(item->GetPtr());
2340 } catch (Exception &ex) {
2341 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2342 return NOTI_EX_ERROR_IO_ERROR;
2344 return NOTI_EX_ERROR_NONE;
2347 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2348 noti_ex_item_h noti, int *request_id) {
2349 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2350 LOGE("Invalid parameter");
2351 return NOTI_EX_ERROR_INVALID_PARAMETER;
2354 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2355 Handle* item = static_cast<Handle*>(noti);
2356 if (item->GetPtr().get() == nullptr) {
2357 LOGE("Invalid noti reference can not be sended");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2360 *request_id = stub->Delete(item->GetPtr());
2362 } catch (Exception &ex) {
2363 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2364 return NOTI_EX_ERROR_IO_ERROR;
2366 return NOTI_EX_ERROR_NONE;
2369 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2370 noti_ex_reporter_h handle, int *request_id) {
2371 if (handle == nullptr || request_id == nullptr) {
2372 LOGE("Invalid parameter");
2373 return NOTI_EX_ERROR_INVALID_PARAMETER;
2376 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2377 *request_id = stub->DeleteAll();
2378 } catch (Exception &ex) {
2379 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2380 return NOTI_EX_ERROR_IO_ERROR;
2382 return NOTI_EX_ERROR_NONE;
2385 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2386 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2387 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2388 LOGE("Invalid parameter");
2389 return NOTI_EX_ERROR_INVALID_PARAMETER;
2392 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2393 *item = new Handle(stub->FindByRootID(root_id));
2394 } catch (Exception &ex) {
2395 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2396 return NOTI_EX_ERROR_IO_ERROR;
2398 return NOTI_EX_ERROR_NONE;
2401 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2402 const char *id, const char *text, const char *hyper_link) {
2403 if (handle == nullptr) {
2404 LOGE("Invalid parameter");
2405 return NOTI_EX_ERROR_INVALID_PARAMETER;
2408 auto* p = new (std::nothrow) TextItem(id, std::string(text),
2409 std::string(hyper_link));
2411 LOGE("Out-of-memory");
2412 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2415 *handle = new Handle(p);
2417 return NOTI_EX_ERROR_NONE;
2420 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2421 const char *contents) {
2422 if (handle == nullptr) {
2423 LOGE("Invalid parameter");
2424 return NOTI_EX_ERROR_INVALID_PARAMETER;
2427 Handle* p = static_cast<Handle*>(handle);
2428 if (!p->IsValidType(AbstractItem::Text)) {
2429 LOGE("Invalid handle type");
2430 return NOTI_EX_ERROR_INVALID_PARAMETER;
2432 TextItem* ti = static_cast<TextItem*>(p->Get());
2433 ti->SetContents(std::string(contents));
2435 return NOTI_EX_ERROR_NONE;
2438 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2440 if (handle == nullptr || contents == nullptr) {
2441 LOGE("Invalid parameter");
2442 return NOTI_EX_ERROR_INVALID_PARAMETER;
2445 Handle* p = static_cast<Handle*>(handle);
2446 if (!p->IsValidType(AbstractItem::Text)) {
2447 LOGE("Invalid handle type");
2448 return NOTI_EX_ERROR_INVALID_PARAMETER;
2450 TextItem* ti = static_cast<TextItem*>(p->Get());
2451 if (!ti->GetContents().empty()) {
2452 *contents = strdup(ti->GetContents().c_str());
2453 if (*contents == nullptr) {
2454 LOGE("Out-of-memory");
2455 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2459 return NOTI_EX_ERROR_NONE;
2462 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2463 noti_ex_item_h handle, char **hyper_link) {
2464 if (handle == nullptr || hyper_link == nullptr) {
2465 LOGE("Invalid parameter");
2466 return NOTI_EX_ERROR_INVALID_PARAMETER;
2469 Handle* p = static_cast<Handle*>(handle);
2470 if (!p->IsValidType(AbstractItem::Text)) {
2471 LOGE("Invalid handle type");
2472 return NOTI_EX_ERROR_INVALID_PARAMETER;
2474 TextItem* ti = static_cast<TextItem*>(p->Get());
2475 if (!ti->GetHyperLink().empty()) {
2476 *hyper_link = strdup(ti->GetHyperLink().c_str());
2477 if (*hyper_link == nullptr) {
2478 LOGE("Out-of-memory");
2479 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2483 return NOTI_EX_ERROR_NONE;
2486 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2487 const char *id, time_t time) {
2490 if (handle == nullptr) {
2491 LOGE("Invalid parameter");
2492 return NOTI_EX_ERROR_INVALID_PARAMETER;
2497 p = new (std::nothrow) TimeItem(id, time);
2499 p = new (std::nothrow) TimeItem(time);
2501 p = new (std::nothrow) TimeItem();
2505 LOGE("Out-of-memory");
2506 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2509 *handle = new Handle(p);
2511 return NOTI_EX_ERROR_NONE;
2514 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2516 if (handle == nullptr || time == nullptr) {
2517 LOGE("Invalid parameter");
2518 return NOTI_EX_ERROR_INVALID_PARAMETER;
2520 Handle* h = static_cast<Handle*>(handle);
2521 if (!h->IsValidType(AbstractItem::Time)) {
2522 LOGE("Invalid handle type");
2523 return NOTI_EX_ERROR_INVALID_PARAMETER;
2525 TimeItem* p = static_cast<TimeItem*>(h->Get());
2526 *time = p->GetTime();
2528 return NOTI_EX_ERROR_NONE;
2531 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2532 noti_ex_action_h *handle, const char *extra) {
2533 if (handle == nullptr) {
2534 LOGE("Invalid parameter");
2535 return NOTI_EX_ERROR_INVALID_PARAMETER;
2538 string extra_str = "";
2540 extra_str = string(extra);
2542 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2544 LOGE("Out-of-memory");
2545 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2550 return NOTI_EX_ERROR_NONE;
2553 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2554 const char *id, bool visible) {
2555 if (handle == nullptr || id == nullptr) {
2556 LOGE("Invalid parameter");
2557 return NOTI_EX_ERROR_INVALID_PARAMETER;
2560 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2561 p->SetVisibility(id, visible);
2563 return NOTI_EX_ERROR_NONE;