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 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_path(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_set_sender_app_id(noti_ex_item_h handle,
1904 if (handle == nullptr) {
1905 LOGE("Invalid parameter");
1906 return NOTI_EX_ERROR_INVALID_PARAMETER;
1909 Handle* p = static_cast<Handle*>(handle);
1911 p->Get()->SetSenderAppId("");
1913 p->Get()->SetSenderAppId(id);
1914 return NOTI_EX_ERROR_NONE;
1917 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1919 if (handle == nullptr || tag == nullptr) {
1920 LOGE("Invalid parameter");
1921 return NOTI_EX_ERROR_INVALID_PARAMETER;
1924 Handle* p = static_cast<Handle*>(handle);
1925 if (p->Get()->GetTag().empty())
1928 *tag = strdup(p->Get()->GetTag().c_str());
1929 return NOTI_EX_ERROR_NONE;
1932 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1934 if (handle == nullptr) {
1935 LOGE("Invalid parameter");
1936 return NOTI_EX_ERROR_INVALID_PARAMETER;
1939 Handle* p = static_cast<Handle*>(handle);
1941 p->Get()->SetTag("");
1943 p->Get()->SetTag(tag);
1944 return NOTI_EX_ERROR_NONE;
1947 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1948 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1950 if (handle == nullptr) {
1951 LOGE("Invalid parameter");
1952 return NOTI_EX_ERROR_INVALID_PARAMETER;
1955 string receiver_group_str = "";
1957 receiver_group_str = string(receiver_group);
1959 ManagerStub* stub = new (std::nothrow) ManagerStub(
1960 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1961 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1962 receiver_group_str);
1963 if (stub == nullptr) {
1964 LOGE("Fail to create manager");
1965 return NOTI_EX_ERROR_IO_ERROR;
1967 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1968 new ManagerCallbackInfo(event_callbacks, data)));
1969 *handle = static_cast<noti_ex_manager_h>(stub);
1971 return NOTI_EX_ERROR_NONE;
1974 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1975 if (handle == nullptr) {
1976 LOGE("Invalid parameter");
1977 return NOTI_EX_ERROR_INVALID_PARAMETER;
1979 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1981 return NOTI_EX_ERROR_NONE;
1984 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1985 noti_ex_item_h **items, int *count) {
1986 if (handle == nullptr || items == nullptr || count == nullptr) {
1987 LOGE("Invalid parameter");
1988 return NOTI_EX_ERROR_INVALID_PARAMETER;
1992 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1993 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1994 if (item_list.size() == 0) {
1997 return NOTI_EX_ERROR_NONE;
1999 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2000 if (*items == nullptr) {
2001 LOGE("Fail to create items");
2002 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2006 for (auto& i : item_list) {
2007 *items[idx++] = new Handle(move(i));
2009 *count = item_list.size();
2010 } catch (Exception &ex) {
2011 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2012 return NOTI_EX_ERROR_IO_ERROR;
2014 return NOTI_EX_ERROR_NONE;
2017 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2018 noti_ex_item_h noti, int *request_id) {
2019 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2020 LOGE("Invalid parameter");
2021 return NOTI_EX_ERROR_INVALID_PARAMETER;
2024 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2025 Handle* sp = static_cast<Handle*>(noti);
2026 if (sp->GetPtr().get() == nullptr) {
2027 LOGE("Invalid noti reference can not be sended");
2028 return NOTI_EX_ERROR_INVALID_PARAMETER;
2030 *request_id = stub->Update(sp->GetPtr());
2032 } catch (Exception &ex) {
2033 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2034 return NOTI_EX_ERROR_IO_ERROR;
2036 return NOTI_EX_ERROR_NONE;
2039 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2040 noti_ex_item_h noti, int *request_id) {
2041 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2042 LOGE("Invalid parameter");
2043 return NOTI_EX_ERROR_INVALID_PARAMETER;
2046 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2047 Handle* item = static_cast<Handle*>(noti);
2048 if (item->GetPtr().get() == nullptr) {
2049 LOGE("Invalid noti reference can not be sended");
2050 return NOTI_EX_ERROR_INVALID_PARAMETER;
2052 *request_id = stub->Delete(item->GetPtr());
2054 } catch (Exception &ex) {
2055 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2056 return NOTI_EX_ERROR_IO_ERROR;
2058 return NOTI_EX_ERROR_NONE;
2061 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2063 if (handle == nullptr || request_id == nullptr) {
2064 LOGE("Invalid parameter");
2065 return NOTI_EX_ERROR_INVALID_PARAMETER;
2068 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2069 *request_id = stub->DeleteAll();
2070 } catch (Exception &ex) {
2071 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2072 return NOTI_EX_ERROR_IO_ERROR;
2074 return NOTI_EX_ERROR_NONE;
2077 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2078 noti_ex_item_h noti, int *request_id) {
2079 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2080 LOGE("Invalid parameter");
2081 return NOTI_EX_ERROR_INVALID_PARAMETER;
2084 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2085 Handle* item = static_cast<Handle*>(noti);
2086 if (item->GetPtr().get() == nullptr) {
2087 LOGE("Invalid noti reference can not be sended");
2088 return NOTI_EX_ERROR_INVALID_PARAMETER;
2090 *request_id = stub->Hide(item->GetPtr());
2092 } catch (Exception &ex) {
2093 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2094 return NOTI_EX_ERROR_IO_ERROR;
2096 return NOTI_EX_ERROR_NONE;
2099 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2100 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2101 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2102 LOGE("Invalid parameter");
2103 return NOTI_EX_ERROR_INVALID_PARAMETER;
2106 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2107 *item = new Handle(stub->FindByRootID(root_id));
2108 } catch (Exception &ex) {
2109 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2110 return NOTI_EX_ERROR_IO_ERROR;
2112 return NOTI_EX_ERROR_NONE;
2115 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2116 noti_ex_event_info_h info, noti_ex_error_e error) {
2117 if (handle == nullptr || info == nullptr) {
2118 LOGE("Invalid parameter");
2119 return NOTI_EX_ERROR_INVALID_PARAMETER;
2122 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2123 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2124 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2125 static_cast<NotificationError>(error));
2126 } catch (Exception &ex) {
2127 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2128 return NOTI_EX_ERROR_IO_ERROR;
2130 return NOTI_EX_ERROR_NONE;
2133 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2136 if (handle == nullptr || cnt == nullptr) {
2137 LOGE("Invalid parameter");
2138 return NOTI_EX_ERROR_INVALID_PARAMETER;
2141 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2142 *cnt = stub->GetCount();
2143 } catch (Exception &ex) {
2144 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2145 return NOTI_EX_ERROR_IO_ERROR;
2147 return NOTI_EX_ERROR_NONE;
2150 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2151 const char *id, float min, float current, float max) {
2154 if (handle == nullptr) {
2155 LOGE("Invalid parameter");
2156 return NOTI_EX_ERROR_INVALID_PARAMETER;
2160 p = new (std::nothrow) ProgressItem(id, min, current, max);
2162 p = new (std::nothrow) ProgressItem(min, current, max);
2165 LOGE("Out-of-memory");
2166 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2169 *handle = new Handle(p);
2171 return NOTI_EX_ERROR_NONE;
2174 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2175 noti_ex_item_h handle, float *current) {
2176 if (handle == nullptr || current == nullptr) {
2177 LOGE("Invalid parameter");
2178 return NOTI_EX_ERROR_INVALID_PARAMETER;
2181 Handle *h = static_cast<Handle*>(handle);
2182 if (!h->IsValidType(AbstractItem::Progress)) {
2183 LOGE("Invalid handle type");
2184 return NOTI_EX_ERROR_INVALID_PARAMETER;
2186 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2187 *current = p->GetCurrent();
2189 return NOTI_EX_ERROR_NONE;
2192 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2193 noti_ex_item_h handle, float current) {
2194 if (handle == nullptr) {
2195 LOGE("Invalid parameter");
2196 return NOTI_EX_ERROR_INVALID_PARAMETER;
2199 Handle *h = static_cast<Handle*>(handle);
2200 if (!h->IsValidType(AbstractItem::Progress)) {
2201 LOGE("Invalid handle type");
2202 return NOTI_EX_ERROR_INVALID_PARAMETER;
2204 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2205 p->SetCurrent(current);
2207 return NOTI_EX_ERROR_NONE;
2210 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2212 if (handle == nullptr || min == nullptr) {
2213 LOGE("Invalid parameter");
2214 return NOTI_EX_ERROR_INVALID_PARAMETER;
2217 Handle *h = static_cast<Handle*>(handle);
2218 if (!h->IsValidType(AbstractItem::Progress)) {
2219 LOGE("Invalid handle type");
2220 return NOTI_EX_ERROR_INVALID_PARAMETER;
2222 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2225 return NOTI_EX_ERROR_NONE;
2228 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2230 if (handle == nullptr || max == nullptr) {
2231 LOGE("Invalid parameter");
2232 return NOTI_EX_ERROR_INVALID_PARAMETER;
2235 Handle *h = static_cast<Handle*>(handle);
2236 if (!h->IsValidType(AbstractItem::Progress)) {
2237 LOGE("Invalid handle type");
2238 return NOTI_EX_ERROR_INVALID_PARAMETER;
2240 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2243 return NOTI_EX_ERROR_NONE;
2246 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2247 noti_ex_reporter_events_s event_callbacks, void *data) {
2248 if (handle == nullptr) {
2249 LOGE("Invalid parameter");
2250 return NOTI_EX_ERROR_INVALID_PARAMETER;
2253 ReporterStub* stub = new (std::nothrow) ReporterStub(
2254 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2255 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2256 if (stub == nullptr) {
2257 LOGE("Fail to create manager");
2258 return NOTI_EX_ERROR_IO_ERROR;
2260 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2261 new ReporterCallbackInfo(event_callbacks, data)));
2263 *handle = static_cast<noti_ex_reporter_h>(stub);
2265 return NOTI_EX_ERROR_NONE;
2268 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2269 if (handle == nullptr) {
2270 LOGE("Invalid parameter");
2271 return NOTI_EX_ERROR_INVALID_PARAMETER;
2273 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2275 return NOTI_EX_ERROR_NONE;
2278 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2279 noti_ex_event_info_h info, noti_ex_error_e error) {
2280 if (handle == nullptr || info == nullptr) {
2281 LOGE("Invalid parameter");
2282 return NOTI_EX_ERROR_INVALID_PARAMETER;
2285 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2286 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2287 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2288 static_cast<NotificationError>(error));
2289 } catch (Exception &ex) {
2290 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2291 return NOTI_EX_ERROR_IO_ERROR;
2293 return NOTI_EX_ERROR_NONE;
2296 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2297 noti_ex_item_h noti, int *request_id) {
2298 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2299 LOGE("Invalid parameter");
2300 return NOTI_EX_ERROR_INVALID_PARAMETER;
2303 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2304 Handle* h = static_cast<Handle*>(noti);
2305 if (h->GetPtr().get() == nullptr) {
2306 LOGE("Invalid noti reference can not be sended");
2307 return NOTI_EX_ERROR_INVALID_PARAMETER;
2309 *request_id = stub->Post(h->GetPtr());
2311 } catch (Exception &ex) {
2312 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2313 return NOTI_EX_ERROR_IO_ERROR;
2315 return NOTI_EX_ERROR_NONE;
2318 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2319 noti_ex_item_h *noti_list, int count, int *request_id) {
2321 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2322 LOGE("Invalid parameter");
2323 return NOTI_EX_ERROR_INVALID_PARAMETER;
2326 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2327 list<shared_ptr<item::AbstractItem>> notiList;
2328 for (int i = 0; i < count; i++) {
2329 Handle* item = static_cast<Handle*>(noti_list[i]);
2330 notiList.push_back(item->GetPtr());
2332 *request_id = stub->Post(notiList);
2333 } catch (Exception &ex) {
2334 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2335 return NOTI_EX_ERROR_IO_ERROR;
2337 return NOTI_EX_ERROR_NONE;
2340 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2341 noti_ex_item_h noti, int *request_id) {
2342 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2343 LOGE("Invalid parameter");
2344 return NOTI_EX_ERROR_INVALID_PARAMETER;
2347 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2348 Handle* item = static_cast<Handle*>(noti);
2349 if (item->GetPtr().get() == nullptr) {
2350 LOGE("Invalid noti reference can not be sended");
2351 return NOTI_EX_ERROR_INVALID_PARAMETER;
2353 *request_id = stub->Update(item->GetPtr());
2355 } catch (Exception &ex) {
2356 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2357 return NOTI_EX_ERROR_IO_ERROR;
2359 return NOTI_EX_ERROR_NONE;
2362 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2363 noti_ex_item_h noti, int *request_id) {
2364 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2365 LOGE("Invalid parameter");
2366 return NOTI_EX_ERROR_INVALID_PARAMETER;
2369 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2370 Handle* item = static_cast<Handle*>(noti);
2371 if (item->GetPtr().get() == nullptr) {
2372 LOGE("Invalid noti reference can not be sended");
2373 return NOTI_EX_ERROR_INVALID_PARAMETER;
2375 *request_id = stub->Delete(item->GetPtr());
2377 } catch (Exception &ex) {
2378 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2379 return NOTI_EX_ERROR_IO_ERROR;
2381 return NOTI_EX_ERROR_NONE;
2384 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2385 noti_ex_reporter_h handle, int *request_id) {
2386 if (handle == nullptr || request_id == nullptr) {
2387 LOGE("Invalid parameter");
2388 return NOTI_EX_ERROR_INVALID_PARAMETER;
2391 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2392 *request_id = stub->DeleteAll();
2393 } catch (Exception &ex) {
2394 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2395 return NOTI_EX_ERROR_IO_ERROR;
2397 return NOTI_EX_ERROR_NONE;
2400 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2401 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2402 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2403 LOGE("Invalid parameter");
2404 return NOTI_EX_ERROR_INVALID_PARAMETER;
2407 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2408 *item = new Handle(stub->FindByRootID(root_id));
2409 } catch (Exception &ex) {
2410 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2411 return NOTI_EX_ERROR_IO_ERROR;
2413 return NOTI_EX_ERROR_NONE;
2416 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2417 const char *id, const char *text, const char *hyper_link) {
2418 if (handle == nullptr) {
2419 LOGE("Invalid parameter");
2420 return NOTI_EX_ERROR_INVALID_PARAMETER;
2423 auto* p = new (std::nothrow) TextItem(id, std::string(text),
2424 std::string(hyper_link));
2426 LOGE("Out-of-memory");
2427 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2430 *handle = new Handle(p);
2432 return NOTI_EX_ERROR_NONE;
2435 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2436 const char *contents) {
2437 if (handle == nullptr) {
2438 LOGE("Invalid parameter");
2439 return NOTI_EX_ERROR_INVALID_PARAMETER;
2442 Handle* p = static_cast<Handle*>(handle);
2443 if (!p->IsValidType(AbstractItem::Text)) {
2444 LOGE("Invalid handle type");
2445 return NOTI_EX_ERROR_INVALID_PARAMETER;
2447 TextItem* ti = static_cast<TextItem*>(p->Get());
2448 ti->SetContents(std::string(contents));
2450 return NOTI_EX_ERROR_NONE;
2453 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2455 if (handle == nullptr || contents == nullptr) {
2456 LOGE("Invalid parameter");
2457 return NOTI_EX_ERROR_INVALID_PARAMETER;
2460 Handle* p = static_cast<Handle*>(handle);
2461 if (!p->IsValidType(AbstractItem::Text)) {
2462 LOGE("Invalid handle type");
2463 return NOTI_EX_ERROR_INVALID_PARAMETER;
2465 TextItem* ti = static_cast<TextItem*>(p->Get());
2466 if (!ti->GetContents().empty()) {
2467 *contents = strdup(ti->GetContents().c_str());
2468 if (*contents == nullptr) {
2469 LOGE("Out-of-memory");
2470 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2474 return NOTI_EX_ERROR_NONE;
2477 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2478 noti_ex_item_h handle, char **hyper_link) {
2479 if (handle == nullptr || hyper_link == nullptr) {
2480 LOGE("Invalid parameter");
2481 return NOTI_EX_ERROR_INVALID_PARAMETER;
2484 Handle* p = static_cast<Handle*>(handle);
2485 if (!p->IsValidType(AbstractItem::Text)) {
2486 LOGE("Invalid handle type");
2487 return NOTI_EX_ERROR_INVALID_PARAMETER;
2489 TextItem* ti = static_cast<TextItem*>(p->Get());
2490 if (!ti->GetHyperLink().empty()) {
2491 *hyper_link = strdup(ti->GetHyperLink().c_str());
2492 if (*hyper_link == nullptr) {
2493 LOGE("Out-of-memory");
2494 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2498 return NOTI_EX_ERROR_NONE;
2501 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2502 const char *id, time_t time) {
2505 if (handle == nullptr) {
2506 LOGE("Invalid parameter");
2507 return NOTI_EX_ERROR_INVALID_PARAMETER;
2512 p = new (std::nothrow) TimeItem(id, time);
2514 p = new (std::nothrow) TimeItem(time);
2516 p = new (std::nothrow) TimeItem();
2520 LOGE("Out-of-memory");
2521 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2524 *handle = new Handle(p);
2526 return NOTI_EX_ERROR_NONE;
2529 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2531 if (handle == nullptr || time == nullptr) {
2532 LOGE("Invalid parameter");
2533 return NOTI_EX_ERROR_INVALID_PARAMETER;
2535 Handle* h = static_cast<Handle*>(handle);
2536 if (!h->IsValidType(AbstractItem::Time)) {
2537 LOGE("Invalid handle type");
2538 return NOTI_EX_ERROR_INVALID_PARAMETER;
2540 TimeItem* p = static_cast<TimeItem*>(h->Get());
2541 *time = p->GetTime();
2543 return NOTI_EX_ERROR_NONE;
2546 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2547 noti_ex_action_h *handle, const char *extra) {
2548 if (handle == nullptr) {
2549 LOGE("Invalid parameter");
2550 return NOTI_EX_ERROR_INVALID_PARAMETER;
2553 string extra_str = "";
2555 extra_str = string(extra);
2557 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2559 LOGE("Out-of-memory");
2560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2565 return NOTI_EX_ERROR_NONE;
2568 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2569 const char *id, bool visible) {
2570 if (handle == nullptr || id == nullptr) {
2571 LOGE("Invalid parameter");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2575 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2576 p->SetVisibility(id, visible);
2578 return NOTI_EX_ERROR_NONE;