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;
287 p = new (std::nothrow) AppControlAction(app_control, extra);
289 p = new (std::nothrow) AppControlAction(app_control);
292 LOGE("Out-of-memory");
293 return NOTI_EX_ERROR_OUT_OF_MEMORY;
298 return NOTI_EX_ERROR_NONE;
301 extern "C" EXPORT_API int noti_ex_action_app_control_set(
302 noti_ex_action_h handle, app_control_h app_control) {
303 if (handle == nullptr || app_control == nullptr) {
304 LOGE("Invalid parameter");
305 return NOTI_EX_ERROR_INVALID_PARAMETER;
308 AppControlAction* p = static_cast<AppControlAction*>(handle);
309 p->SetAppControl(app_control);
311 return NOTI_EX_ERROR_NONE;
314 extern "C" EXPORT_API int noti_ex_action_app_control_get(
315 noti_ex_action_h handle, app_control_h *app_control) {
316 if (handle == nullptr || app_control == nullptr) {
317 LOGE("Invalid parameter");
318 return NOTI_EX_ERROR_INVALID_PARAMETER;
321 AppControlAction* p = static_cast<AppControlAction*>(handle);
322 *app_control = p->GetAppControl();
324 return NOTI_EX_ERROR_NONE;
327 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
328 const char *id, const char *title) {
331 if (handle == nullptr || title == nullptr) {
332 LOGE("Invalid parameter");
333 return NOTI_EX_ERROR_INVALID_PARAMETER;
337 p = new (std::nothrow) ButtonItem(id, title);
339 p = new (std::nothrow) ButtonItem(title);
342 LOGE("Out-of-memory");
343 return NOTI_EX_ERROR_OUT_OF_MEMORY;
345 *handle = new Handle(shared_ptr<AbstractItem>(p));
347 return NOTI_EX_ERROR_NONE;
350 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
352 if (handle == nullptr || title == nullptr) {
353 LOGE("Invalid parameter");
354 return NOTI_EX_ERROR_INVALID_PARAMETER;
357 Handle* sp = static_cast<Handle*>(handle);
358 if (!sp->IsValidType(AbstractItem::Button)) {
359 LOGE("Invalid handle type");
360 return NOTI_EX_ERROR_INVALID_PARAMETER;
362 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
363 if (!p->GetTitle().empty()) {
364 *title = strdup(p->GetTitle().c_str());
365 if (*title == nullptr) {
366 LOGE("Out-of-memory");
367 return NOTI_EX_ERROR_OUT_OF_MEMORY;
371 return NOTI_EX_ERROR_NONE;
374 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
375 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
376 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
377 noti_ex_item_chat_message_type_e message_type) {
378 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
379 LOGE("Invalid parameter");
380 return NOTI_EX_ERROR_INVALID_PARAMETER;
383 auto* p = new (std::nothrow) ChatMessageItem(id,
384 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
385 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
386 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
387 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
388 static_cast<ChatMessageItem::Type>((int)message_type));
390 LOGE("Out-of-memory");
391 return NOTI_EX_ERROR_OUT_OF_MEMORY;
394 *handle = new Handle(shared_ptr<AbstractItem>(p));
396 return NOTI_EX_ERROR_NONE;
399 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
400 noti_ex_item_h handle, noti_ex_item_h *name) {
401 if (handle == nullptr || name == nullptr) {
402 LOGE("Invalid parameter");
403 return NOTI_EX_ERROR_INVALID_PARAMETER;
405 Handle* h = static_cast<Handle*>(handle);
406 if (!h->IsValidType(AbstractItem::ChatMessage)) {
407 LOGE("Invalid handle type");
408 return NOTI_EX_ERROR_INVALID_PARAMETER;
410 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
411 *name = new Handle(&(p->GetNameItem()));
413 return NOTI_EX_ERROR_NONE;
416 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
417 noti_ex_item_h handle, noti_ex_item_h *text) {
418 if (handle == nullptr || text == nullptr) {
419 LOGE("Invalid parameter");
420 return NOTI_EX_ERROR_INVALID_PARAMETER;
423 Handle* h = static_cast<Handle*>(handle);
424 if (!h->IsValidType(AbstractItem::ChatMessage)) {
425 LOGE("Invalid handle type");
426 return NOTI_EX_ERROR_INVALID_PARAMETER;
428 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
429 *text = new Handle(&(p->GetTextItem()));
431 return NOTI_EX_ERROR_NONE;
434 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
435 noti_ex_item_h handle, noti_ex_item_h *image) {
436 if (handle == nullptr || image == nullptr) {
437 LOGE("Invalid parameter");
438 return NOTI_EX_ERROR_INVALID_PARAMETER;
441 Handle* h = static_cast<Handle*>(handle);
442 if (!h->IsValidType(AbstractItem::ChatMessage)) {
443 LOGE("Invalid handle type");
444 return NOTI_EX_ERROR_INVALID_PARAMETER;
446 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
447 *image = new Handle(&(p->GetImageItem()));
449 return NOTI_EX_ERROR_NONE;
452 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
453 noti_ex_item_h handle, noti_ex_item_h *time) {
454 if (handle == nullptr || time == nullptr) {
455 LOGE("Invalid parameter");
456 return NOTI_EX_ERROR_INVALID_PARAMETER;
459 Handle* h = static_cast<Handle*>(handle);
460 if (!h->IsValidType(AbstractItem::ChatMessage)) {
461 LOGE("Invalid handle type");
462 return NOTI_EX_ERROR_INVALID_PARAMETER;
464 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
465 *time = new Handle(&(p->GetTimeItem()));
467 return NOTI_EX_ERROR_NONE;
470 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
471 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
472 if (handle == nullptr || message_type == nullptr) {
473 LOGE("Invalid parameter");
474 return NOTI_EX_ERROR_INVALID_PARAMETER;
477 Handle* h = static_cast<Handle*>(handle);
478 if (!h->IsValidType(AbstractItem::ChatMessage)) {
479 LOGE("Invalid handle type");
480 return NOTI_EX_ERROR_INVALID_PARAMETER;
482 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
483 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
485 return NOTI_EX_ERROR_NONE;
488 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
489 const char *id, const char *title, bool checked) {
492 if (handle == nullptr || title == nullptr) {
493 LOGE("Invalid parameter");
494 return NOTI_EX_ERROR_INVALID_PARAMETER;
497 p = new (std::nothrow) CheckBoxItem(id, title, checked);
499 LOGE("Out-of-memory");
500 return NOTI_EX_ERROR_OUT_OF_MEMORY;
503 *handle = new Handle(p);
505 return NOTI_EX_ERROR_NONE;
508 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
510 if (handle == nullptr || title == nullptr) {
511 LOGE("Invalid parameter");
512 return NOTI_EX_ERROR_INVALID_PARAMETER;
514 Handle* h = static_cast<Handle*>(handle);
515 if (!h->IsValidType(AbstractItem::CheckBox)) {
516 LOGE("Invalid handle type");
517 return NOTI_EX_ERROR_INVALID_PARAMETER;
519 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
520 if (!p->GetTitle().empty()) {
521 *title = strdup(p->GetTitle().c_str());
522 if (*title == nullptr) {
523 LOGE("Out-of-memory");
524 return NOTI_EX_ERROR_OUT_OF_MEMORY;
528 return NOTI_EX_ERROR_NONE;
531 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
533 if (handle == nullptr || checked == nullptr) {
534 LOGE("Invalid parameter");
535 return NOTI_EX_ERROR_INVALID_PARAMETER;
537 Handle* h = static_cast<Handle*>(handle);
538 if (!h->IsValidType(AbstractItem::CheckBox)) {
539 LOGE("Invalid handle type");
540 return NOTI_EX_ERROR_INVALID_PARAMETER;
542 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
543 *checked = p->IsChecked();
545 return NOTI_EX_ERROR_NONE;
548 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
552 if (handle == nullptr) {
553 LOGE("Invalid parameter");
554 return NOTI_EX_ERROR_INVALID_PARAMETER;
557 p = new (std::nothrow) EntryItem(id);
559 LOGE("Out-of-memory");
560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
563 *handle = new Handle(p);
565 return NOTI_EX_ERROR_NONE;
568 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
570 if (handle == nullptr || text == nullptr) {
571 LOGE("Invalid parameter");
572 return NOTI_EX_ERROR_INVALID_PARAMETER;
575 Handle* h = static_cast<Handle*>(handle);
576 if (!h->IsValidType(AbstractItem::Entry)) {
577 LOGE("Invalid handle type");
578 return NOTI_EX_ERROR_INVALID_PARAMETER;
580 EntryItem* p = static_cast<EntryItem*>(h->Get());
581 if (!p->GetText().empty()) {
582 *text = strdup(p->GetText().c_str());
583 if (*text == nullptr) {
584 LOGE("Out-of-memory");
585 return NOTI_EX_ERROR_OUT_OF_MEMORY;
589 return NOTI_EX_ERROR_NONE;
592 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
594 if (handle == nullptr || text == nullptr) {
595 LOGE("Invalid parameter");
596 return NOTI_EX_ERROR_INVALID_PARAMETER;
598 Handle* h = static_cast<Handle*>(handle);
599 if (!h->IsValidType(AbstractItem::Entry)) {
600 LOGE("Invalid handle type");
601 return NOTI_EX_ERROR_INVALID_PARAMETER;
603 EntryItem* p = static_cast<EntryItem*>(h->Get());
604 p->SetText(std::string(text));
606 return NOTI_EX_ERROR_NONE;
609 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
610 noti_ex_event_info_h* cloned_handle) {
611 if (handle == nullptr || cloned_handle == nullptr) {
612 LOGE("Invalid parameter");
613 return NOTI_EX_ERROR_INVALID_PARAMETER;
616 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
617 EventInfo* info = new EventInfo(cloned);
618 *cloned_handle = info;
619 return NOTI_EX_ERROR_NONE;
622 extern "C" EXPORT_API int noti_ex_event_info_destroy(
623 noti_ex_event_info_h handle) {
624 if (handle == nullptr) {
625 LOGE("Invalid parameter");
626 return NOTI_EX_ERROR_INVALID_PARAMETER;
628 EventInfo* info = static_cast<EventInfo*>(handle);
630 return NOTI_EX_ERROR_NONE;
633 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
634 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
635 if (handle == nullptr || event_type == nullptr) {
636 LOGE("Invalid parameter");
637 return NOTI_EX_ERROR_INVALID_PARAMETER;
639 EventInfo* info = static_cast<EventInfo*>(handle);
640 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
642 return NOTI_EX_ERROR_NONE;
645 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
646 noti_ex_event_info_h handle, char **owner) {
647 if (handle == nullptr || owner == nullptr) {
648 LOGE("Invalid parameter");
649 return NOTI_EX_ERROR_INVALID_PARAMETER;
651 EventInfo* info = static_cast<EventInfo*>(handle);
652 *owner = strdup(info->GetOwner().c_str());
653 return NOTI_EX_ERROR_NONE;
656 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
657 noti_ex_event_info_h handle, char **channel) {
658 if (handle == nullptr || channel == nullptr) {
659 LOGE("Invalid parameter");
660 return NOTI_EX_ERROR_INVALID_PARAMETER;
662 EventInfo* info = static_cast<EventInfo*>(handle);
663 *channel = strdup(info->GetChannel().c_str());
664 return NOTI_EX_ERROR_NONE;
667 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
668 noti_ex_event_info_h handle, char **item_id) {
669 if (handle == nullptr || item_id == nullptr) {
670 LOGE("Invalid parameter");
671 return NOTI_EX_ERROR_INVALID_PARAMETER;
673 EventInfo* info = static_cast<EventInfo*>(handle);
674 *item_id = strdup(info->GetItemId().c_str());
675 return NOTI_EX_ERROR_NONE;
678 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
679 noti_ex_event_info_h handle, int *req_id) {
680 if (handle == nullptr || req_id == nullptr) {
681 LOGE("Invalid parameter");
682 return NOTI_EX_ERROR_INVALID_PARAMETER;
684 EventInfo* info = static_cast<EventInfo*>(handle);
685 *req_id = info->GetRequestId();
686 return NOTI_EX_ERROR_NONE;
689 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
693 if (handle == nullptr) {
694 LOGE("Invalid parameter");
695 return NOTI_EX_ERROR_INVALID_PARAMETER;
699 p = new (std::nothrow) GroupItem(id);
701 p = new (std::nothrow) GroupItem();
704 LOGE("Out-of-memory");
705 return NOTI_EX_ERROR_OUT_OF_MEMORY;
708 *handle = new Handle(shared_ptr<AbstractItem>(p));
710 return NOTI_EX_ERROR_NONE;
713 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
715 if (handle == nullptr) {
716 LOGE("Invalid parameter");
717 return NOTI_EX_ERROR_INVALID_PARAMETER;
719 Handle* h = static_cast<Handle*>(handle);
720 if (!h->IsValidType(AbstractItem::Group)) {
721 LOGE("Invalid handle type");
722 return NOTI_EX_ERROR_INVALID_PARAMETER;
724 GroupItem* p = static_cast<GroupItem*>(h->Get());
725 p->SetDirection(vertical);
727 return NOTI_EX_ERROR_NONE;
730 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
732 if (handle == nullptr) {
733 LOGE("Invalid parameter");
734 return NOTI_EX_ERROR_INVALID_PARAMETER;
736 Handle* h = static_cast<Handle*>(handle);
737 if (!h->IsValidType(AbstractItem::Group)) {
738 LOGE("Invalid handle type");
739 return NOTI_EX_ERROR_INVALID_PARAMETER;
741 GroupItem* p = static_cast<GroupItem*>(h->Get());
742 *vertical = p->IsVertical();
744 return NOTI_EX_ERROR_NONE;
747 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
749 if (handle == nullptr) {
750 LOGE("Invalid parameter");
751 return NOTI_EX_ERROR_INVALID_PARAMETER;
753 Handle* h = static_cast<Handle*>(handle);
754 if (!h->IsValidType(AbstractItem::Group)) {
755 LOGE("Invalid handle type");
756 return NOTI_EX_ERROR_INVALID_PARAMETER;
758 GroupItem* p = static_cast<GroupItem*>(h->Get());
759 if (!p->GetAppLabel().empty()) {
760 *label = strdup(p->GetAppLabel().c_str());
761 if (*label == nullptr) {
762 LOGE("Out-of-memory");
763 return NOTI_EX_ERROR_OUT_OF_MEMORY;
767 return NOTI_EX_ERROR_NONE;
770 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
771 noti_ex_item_h child) {
772 if (handle == nullptr || child == nullptr) {
773 LOGE("Invalid parameter");
774 return NOTI_EX_ERROR_INVALID_PARAMETER;
776 Handle* h = static_cast<Handle*>(handle);
777 if (!h->IsValidType(AbstractItem::Group)) {
778 LOGE("Invalid handle type");
779 return NOTI_EX_ERROR_INVALID_PARAMETER;
781 auto p = static_cast<GroupItem*>(h->Get());
782 p->AddChild((static_cast<Handle*>(child))->GetPtr());
784 return NOTI_EX_ERROR_NONE;
787 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
788 const char *item_id) {
789 if (handle == nullptr || item_id == nullptr) {
790 LOGE("Invalid parameter");
791 return NOTI_EX_ERROR_INVALID_PARAMETER;
793 Handle* h = static_cast<Handle*>(handle);
794 if (!h->IsValidType(AbstractItem::Group)) {
795 LOGE("Invalid handle type");
796 return NOTI_EX_ERROR_INVALID_PARAMETER;
798 GroupItem* p = static_cast<GroupItem*>(h->Get());
799 p->RemoveChild(std::string(item_id));
801 return NOTI_EX_ERROR_NONE;
804 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
805 noti_ex_item_group_foreach_child_cb callback, void *data) {
806 if (handle == nullptr || callback == nullptr) {
807 LOGE("Invalid parameter");
808 return NOTI_EX_ERROR_INVALID_PARAMETER;
811 Handle* h = static_cast<Handle*>(handle);
812 if (!h->IsValidType(AbstractItem::Group)) {
813 LOGE("Invalid handle type");
814 return NOTI_EX_ERROR_INVALID_PARAMETER;
816 GroupItem* p = static_cast<GroupItem*>(h->Get());
817 list<shared_ptr<AbstractItem>> children = p->GetChildren();
818 LOGI("Retrive (%zd)", children.size());
819 for (auto i : children) {
821 static_cast<noti_ex_item_h>(new Handle(i)), data);
822 if (ret != NOTI_EX_ERROR_NONE) {
823 LOGW("callback return (%d) stop foreach", ret);
828 return NOTI_EX_ERROR_NONE;
831 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
832 const char *id, const char *image_path) {
835 if (handle == nullptr || image_path == nullptr) {
836 LOGE("Invalid parameter");
837 return NOTI_EX_ERROR_INVALID_PARAMETER;
841 p = new (std::nothrow) ImageItem(id, image_path);
843 p = new (std::nothrow) ImageItem(image_path);
846 LOGE("Out-of-memory");
847 return NOTI_EX_ERROR_OUT_OF_MEMORY;
850 *handle = new Handle(shared_ptr<AbstractItem>(p));
852 return NOTI_EX_ERROR_NONE;
855 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
856 noti_ex_item_h handle, char **image_path) {
857 if (handle == nullptr || image_path == nullptr) {
858 LOGE("Invalid parameter");
859 return NOTI_EX_ERROR_INVALID_PARAMETER;
861 Handle* h = static_cast<Handle*>(handle);
862 if (!h->IsValidType(AbstractItem::Image)) {
863 LOGE("Invalid handle type");
864 return NOTI_EX_ERROR_INVALID_PARAMETER;
866 ImageItem* p = static_cast<ImageItem*>(h->Get());
867 if (!p->GetImagePath().empty()) {
868 *image_path = strdup(p->GetImagePath().c_str());
869 if (*image_path == nullptr) {
870 LOGE("Out-of-memory");
871 return NOTI_EX_ERROR_OUT_OF_MEMORY;
875 return NOTI_EX_ERROR_NONE;
878 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
879 noti_ex_item_h *handle, const char *id) {
880 InputSelectorItem* p;
882 if (handle == nullptr) {
883 LOGE("Invalid parameter");
884 return NOTI_EX_ERROR_INVALID_PARAMETER;
888 p = new (std::nothrow) InputSelectorItem(id);
890 p = new (std::nothrow) InputSelectorItem();
893 LOGE("Out-of-memory");
894 return NOTI_EX_ERROR_OUT_OF_MEMORY;
897 *handle = new Handle(p);
899 return NOTI_EX_ERROR_NONE;
902 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
903 noti_ex_item_h handle, char ***contents_list, int *count) {
904 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
905 LOGE("Invalid parameter");
906 return NOTI_EX_ERROR_INVALID_PARAMETER;
909 Handle* h = static_cast<Handle*>(handle);
910 if (!h->IsValidType(AbstractItem::InputSelector)) {
911 LOGE("Invalid handle type");
912 return NOTI_EX_ERROR_INVALID_PARAMETER;
914 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
915 list<string> contents = p->GetContents();
916 char **list = (char**)calloc(contents.size(), sizeof(char*));
918 for (auto& i : contents) {
919 list[idx++] = strdup(i.c_str());
921 *count = contents.size();
922 *contents_list = list;
924 return NOTI_EX_ERROR_NONE;
927 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
928 noti_ex_item_h handle, const char **contents, int count) {
929 if (handle == nullptr || contents == nullptr) {
930 LOGE("Invalid parameter");
931 return NOTI_EX_ERROR_INVALID_PARAMETER;
934 list<string> new_contents;
935 Handle* h = static_cast<Handle*>(handle);
936 if (!h->IsValidType(AbstractItem::InputSelector)) {
937 LOGE("Invalid handle type");
938 return NOTI_EX_ERROR_INVALID_PARAMETER;
940 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
941 for (int i = 0; i < count; i++) {
942 new_contents.push_back(contents[i]);
944 p->SetContents(move(new_contents));
946 return NOTI_EX_ERROR_NONE;
949 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
950 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
951 if (handle == nullptr) {
952 LOGE("Invalid parameter");
953 return NOTI_EX_ERROR_INVALID_PARAMETER;
956 auto* p = new (std::nothrow) Color(a, r, g, b);
958 LOGE("Out-of-memory");
959 return NOTI_EX_ERROR_OUT_OF_MEMORY;
964 return NOTI_EX_ERROR_NONE;
967 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
968 if (handle == nullptr) {
969 LOGE("Invalid parameter");
970 return NOTI_EX_ERROR_INVALID_PARAMETER;
973 Color* p = static_cast<Color*>(handle);
976 return NOTI_EX_ERROR_NONE;
979 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
980 unsigned char *val) {
981 if (handle == nullptr || val == nullptr) {
982 LOGE("Invalid parameter");
983 return NOTI_EX_ERROR_INVALID_PARAMETER;
986 Color* p = static_cast<Color*>(handle);
989 return NOTI_EX_ERROR_NONE;
992 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
993 unsigned char *val) {
994 if (handle == nullptr || val == nullptr) {
995 LOGE("Invalid parameter");
996 return NOTI_EX_ERROR_INVALID_PARAMETER;
999 Color* p = static_cast<Color*>(handle);
1000 *val = p->GetRVal();
1002 return NOTI_EX_ERROR_NONE;
1005 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1006 unsigned char *val) {
1007 if (handle == nullptr || val == nullptr) {
1008 LOGE("Invalid parameter");
1009 return NOTI_EX_ERROR_INVALID_PARAMETER;
1012 Color* p = static_cast<Color*>(handle);
1013 *val = p->GetGVal();
1015 return NOTI_EX_ERROR_NONE;
1018 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1019 unsigned char *val) {
1020 if (handle == nullptr || val == nullptr) {
1021 LOGE("Invalid parameter");
1022 return NOTI_EX_ERROR_INVALID_PARAMETER;
1025 Color* p = static_cast<Color*>(handle);
1026 *val = p->GetBVal();
1028 return NOTI_EX_ERROR_NONE;
1031 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1032 int left, int top, int right, int bottom) {
1033 if (handle == nullptr) {
1034 LOGE("Invalid parameter");
1035 return NOTI_EX_ERROR_INVALID_PARAMETER;
1038 auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1040 LOGE("Out-of-memory");
1041 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1046 return NOTI_EX_ERROR_NONE;
1049 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1050 if (handle == nullptr) {
1051 LOGE("Invalid parameter");
1052 return NOTI_EX_ERROR_INVALID_PARAMETER;
1055 Padding* p = static_cast<Padding*>(handle);
1058 return NOTI_EX_ERROR_NONE;
1061 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1063 if (handle == nullptr || val == nullptr) {
1064 LOGE("Invalid parameter");
1065 return NOTI_EX_ERROR_INVALID_PARAMETER;
1068 Padding* p = static_cast<Padding*>(handle);
1069 *val = p->GetLeft();
1071 return NOTI_EX_ERROR_NONE;
1074 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1076 if (handle == nullptr || val == nullptr) {
1077 LOGE("Invalid parameter");
1078 return NOTI_EX_ERROR_INVALID_PARAMETER;
1081 Padding* p = static_cast<Padding*>(handle);
1084 return NOTI_EX_ERROR_NONE;
1087 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1089 if (handle == nullptr || val == nullptr) {
1090 LOGE("Invalid parameter");
1091 return NOTI_EX_ERROR_INVALID_PARAMETER;
1094 Padding* p = static_cast<Padding*>(handle);
1095 *val = p->GetRight();
1097 return NOTI_EX_ERROR_NONE;
1100 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1102 if (handle == nullptr || val == nullptr) {
1103 LOGE("Invalid parameter");
1104 return NOTI_EX_ERROR_INVALID_PARAMETER;
1107 Padding* p = static_cast<Padding*>(handle);
1108 *val = p->GetBottom();
1110 return NOTI_EX_ERROR_NONE;
1113 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1114 int x, int y, int w, int h) {
1115 if (handle == nullptr) {
1116 LOGE("Invalid parameter");
1117 return NOTI_EX_ERROR_INVALID_PARAMETER;
1120 auto* p = new (std::nothrow) Geometry(x, y, w, h);
1122 LOGE("Out-of-memory");
1123 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1128 return NOTI_EX_ERROR_NONE;
1131 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1132 if (handle == nullptr) {
1133 LOGE("Invalid parameter");
1134 return NOTI_EX_ERROR_INVALID_PARAMETER;
1137 Geometry* p = static_cast<Geometry*>(handle);
1140 return NOTI_EX_ERROR_NONE;
1143 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1145 if (handle == nullptr || val == nullptr) {
1146 LOGE("Invalid parameter");
1147 return NOTI_EX_ERROR_INVALID_PARAMETER;
1150 Geometry* p = static_cast<Geometry*>(handle);
1153 return NOTI_EX_ERROR_NONE;
1156 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1158 if (handle == nullptr || val == nullptr) {
1159 LOGE("Invalid parameter");
1160 return NOTI_EX_ERROR_INVALID_PARAMETER;
1163 Geometry* p = static_cast<Geometry*>(handle);
1166 return NOTI_EX_ERROR_NONE;
1169 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1171 if (handle == nullptr || val == nullptr) {
1172 LOGE("Invalid parameter");
1173 return NOTI_EX_ERROR_INVALID_PARAMETER;
1176 Geometry* p = static_cast<Geometry*>(handle);
1177 *val = p->GetWidth();
1179 return NOTI_EX_ERROR_NONE;
1182 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1184 if (handle == nullptr || val == nullptr) {
1185 LOGE("Invalid parameter");
1186 return NOTI_EX_ERROR_INVALID_PARAMETER;
1189 Geometry* p = static_cast<Geometry*>(handle);
1190 *val = p->GetHeight();
1192 return NOTI_EX_ERROR_NONE;
1195 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1196 noti_ex_color_h color,
1197 noti_ex_padding_h padding,
1198 noti_ex_geometry_h geometry) {
1199 if (handle == nullptr) {
1200 LOGE("Invalid parameter");
1201 return NOTI_EX_ERROR_INVALID_PARAMETER;
1204 Color* color_ = static_cast<Color*>(color);
1205 Padding* padding_ = static_cast<Padding*>(padding);
1206 Geometry* geo_ = static_cast<Geometry*>(geometry);
1208 auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1210 LOGE("Out-of-memory");
1211 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1216 return NOTI_EX_ERROR_NONE;
1219 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1220 if (handle == nullptr) {
1221 LOGE("Invalid parameter");
1222 return NOTI_EX_ERROR_INVALID_PARAMETER;
1225 Style* p = static_cast<Style*>(handle);
1228 return NOTI_EX_ERROR_NONE;
1231 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1232 noti_ex_padding_h *padding) {
1233 if (handle == nullptr || padding == nullptr) {
1234 LOGE("Invalid parameter");
1235 return NOTI_EX_ERROR_INVALID_PARAMETER;
1238 Style* p = static_cast<Style*>(handle);
1239 Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1240 if (padding_ == nullptr) {
1241 LOGE("Out-of-memory");
1242 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1245 *padding = padding_;
1247 return NOTI_EX_ERROR_NONE;
1250 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1251 noti_ex_color_h *color) {
1252 if (handle == nullptr || color == nullptr) {
1253 LOGE("Invalid parameter");
1254 return NOTI_EX_ERROR_INVALID_PARAMETER;
1257 Style* p = static_cast<Style*>(handle);
1258 Color* color_ = new (std::nothrow) Color(p->GetColor());
1259 if (color_ == nullptr) {
1260 LOGE("Out-of-memory");
1261 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1266 return NOTI_EX_ERROR_NONE;
1269 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1270 noti_ex_geometry_h *geometry) {
1271 if (handle == nullptr || geometry == nullptr) {
1272 LOGE("Invalid parameter");
1273 return NOTI_EX_ERROR_INVALID_PARAMETER;
1276 Style* p = static_cast<Style*>(handle);
1277 Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1278 if (geo_ == nullptr) {
1279 LOGE("Out-of-memory");
1280 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1285 return NOTI_EX_ERROR_NONE;
1288 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1289 noti_ex_color_h color) {
1290 if (handle == nullptr) {
1291 LOGE("Invalid parameter");
1292 return NOTI_EX_ERROR_INVALID_PARAMETER;
1295 Color* color_ = static_cast<Color*>(color);
1296 auto* p = new (std::nothrow) LEDInfo(*color_);
1298 LOGE("Out-of-memory");
1299 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1304 return NOTI_EX_ERROR_NONE;
1307 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1308 if (handle == nullptr) {
1309 LOGE("Invalid parameter");
1310 return NOTI_EX_ERROR_INVALID_PARAMETER;
1313 LEDInfo* p = static_cast<LEDInfo*>(handle);
1316 return NOTI_EX_ERROR_NONE;
1319 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1320 noti_ex_led_info_h handle, int ms) {
1321 if (handle == nullptr) {
1322 LOGE("Invalid parameter");
1323 return NOTI_EX_ERROR_INVALID_PARAMETER;
1326 LEDInfo* p = static_cast<LEDInfo*>(handle);
1329 return NOTI_EX_ERROR_NONE;
1332 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1333 noti_ex_led_info_h handle, int *ms) {
1334 if (handle == nullptr || ms == nullptr) {
1335 LOGE("Invalid parameter");
1336 return NOTI_EX_ERROR_INVALID_PARAMETER;
1339 LEDInfo* p = static_cast<LEDInfo*>(handle);
1340 *ms = p->GetOnPeriod();
1342 return NOTI_EX_ERROR_NONE;
1345 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1346 noti_ex_led_info_h handle, int ms) {
1347 if (handle == nullptr) {
1348 LOGE("Invalid parameter");
1349 return NOTI_EX_ERROR_INVALID_PARAMETER;
1352 LEDInfo* p = static_cast<LEDInfo*>(handle);
1353 p->SetOffPeriod(ms);
1355 return NOTI_EX_ERROR_NONE;
1358 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1359 noti_ex_led_info_h handle, int *ms) {
1360 if (handle == nullptr) {
1361 LOGE("Invalid parameter");
1362 return NOTI_EX_ERROR_INVALID_PARAMETER;
1365 LEDInfo* p = static_cast<LEDInfo*>(handle);
1366 *ms = p->GetOffPeriod();
1368 return NOTI_EX_ERROR_NONE;
1371 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1372 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1373 if (handle == nullptr) {
1374 LOGE("Invalid parameter");
1375 return NOTI_EX_ERROR_INVALID_PARAMETER;
1378 LEDInfo* p = static_cast<LEDInfo*>(handle);
1379 Color* color_ = new (std::nothrow) Color(p->GetColor());
1380 if (color_ == nullptr) {
1381 LOGE("Out-of-memory");
1382 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1387 return NOTI_EX_ERROR_NONE;
1390 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1391 if (handle == nullptr) {
1392 LOGE("Invalid parameter");
1393 return NOTI_EX_ERROR_INVALID_PARAMETER;
1396 AbstractAction* p = static_cast<AbstractAction*>(handle);
1397 p->~AbstractAction();
1399 return NOTI_EX_ERROR_NONE;
1402 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1404 if (handle == nullptr || type == nullptr) {
1405 LOGE("Invalid parameter");
1406 return NOTI_EX_ERROR_INVALID_PARAMETER;
1409 AbstractAction* p = static_cast<AbstractAction*>(handle);
1410 *type = p->GetType();
1412 return NOTI_EX_ERROR_NONE;
1415 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1417 if (handle == nullptr || local == nullptr) {
1418 LOGE("Invalid parameter");
1419 return NOTI_EX_ERROR_INVALID_PARAMETER;
1422 AbstractAction* p = static_cast<AbstractAction*>(handle);
1423 *local = p->IsLocal();
1425 return NOTI_EX_ERROR_NONE;
1428 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1429 noti_ex_item_h item) {
1430 if (handle == nullptr || item==nullptr) {
1431 LOGE("Invalid parameter");
1432 return NOTI_EX_ERROR_INVALID_PARAMETER;
1434 AbstractAction* p = static_cast<AbstractAction*>(handle);
1435 Handle* ih = static_cast<Handle*>(item);
1436 p->Execute(ih->GetPtr());
1438 return NOTI_EX_ERROR_NONE;
1441 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1443 if (handle == nullptr || extra == nullptr) {
1444 LOGE("Invalid parameter");
1445 return NOTI_EX_ERROR_INVALID_PARAMETER;
1448 AbstractAction* p = static_cast<AbstractAction*>(handle);
1449 if (!p->GetExtra().empty()) {
1450 *extra = strdup(p->GetExtra().c_str());
1451 if (*extra == nullptr) {
1452 LOGE("Out-of-memory");
1453 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1457 return NOTI_EX_ERROR_NONE;
1460 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1461 noti_ex_item_info_h handle, int *hide_time) {
1462 if (handle == nullptr || hide_time == nullptr) {
1463 LOGE("Invalid parameter");
1464 return NOTI_EX_ERROR_INVALID_PARAMETER;
1466 IItemInfo* p = static_cast<IItemInfo*>(handle);
1467 *hide_time = p->GetHideTime();
1468 return NOTI_EX_ERROR_NONE;
1471 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1472 noti_ex_item_info_h handle, int hide_time) {
1473 if (handle == nullptr) {
1474 LOGE("Invalid parameter");
1475 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 IItemInfo* p = static_cast<IItemInfo*>(handle);
1478 p->SetHideTime(hide_time);
1479 return NOTI_EX_ERROR_NONE;
1482 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1483 noti_ex_item_info_h handle, int *delete_time) {
1484 if (handle == nullptr || delete_time == nullptr) {
1485 LOGE("Invalid parameter");
1486 return NOTI_EX_ERROR_INVALID_PARAMETER;
1488 IItemInfo* p = static_cast<IItemInfo*>(handle);
1489 *delete_time = p->GetDeleteTime();
1490 return NOTI_EX_ERROR_NONE;
1493 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1494 noti_ex_item_info_h handle, int delete_time) {
1495 if (handle == nullptr) {
1496 LOGE("Invalid parameter");
1497 return NOTI_EX_ERROR_INVALID_PARAMETER;
1499 IItemInfo* p = static_cast<IItemInfo*>(handle);
1500 p->SetDeleteTime(delete_time);
1501 return NOTI_EX_ERROR_NONE;
1504 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1505 noti_ex_item_info_h handle, time_t *time) {
1506 if (handle == nullptr || time == nullptr) {
1507 LOGE("Invalid parameter");
1508 return NOTI_EX_ERROR_INVALID_PARAMETER;
1511 IItemInfo* p = static_cast<IItemInfo*>(handle);
1512 *time = p->GetTime();
1513 return NOTI_EX_ERROR_NONE;
1516 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1517 if (handle == nullptr) {
1518 LOGE("Invalid parameter");
1519 return NOTI_EX_ERROR_INVALID_PARAMETER;
1522 Handle* h = static_cast<Handle*>(handle);
1524 return NOTI_EX_ERROR_NONE;
1527 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1528 const char *id, noti_ex_item_h *item) {
1529 if (handle == nullptr) {
1530 LOGE("Invalid parameter");
1531 return NOTI_EX_ERROR_INVALID_PARAMETER;
1534 Handle* p = static_cast<Handle*>(handle);
1535 AbstractItem& find_item = p->Get()->FindByID(string(id));
1536 *item = new Handle(&find_item);
1537 return NOTI_EX_ERROR_NONE;
1540 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1542 if (handle == nullptr || type == nullptr) {
1543 LOGE("Invalid parameter");
1544 return NOTI_EX_ERROR_INVALID_PARAMETER;
1547 Handle* h = static_cast<Handle*>(handle);
1548 AbstractItem* p = h->Get();
1549 *type = p->GetType();
1550 return NOTI_EX_ERROR_NONE;
1553 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1554 char ***path, int *count) {
1555 if (handle == nullptr || path == nullptr || count == nullptr) {
1556 LOGE("Invalid parameter");
1557 return NOTI_EX_ERROR_INVALID_PARAMETER;
1559 Handle* p = static_cast<Handle*>(handle);
1560 list<string> shared_path = p->Get()->GetSharedPath();
1561 *path = (char**)calloc(shared_path.size(), sizeof(char*));
1563 for (auto& i : shared_path) {
1564 *path[idx++] = strdup(i.c_str());
1566 *count = shared_path.size();
1567 return NOTI_EX_ERROR_NONE;
1570 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1572 if (handle == nullptr || id == nullptr) {
1573 LOGE("Invalid parameter");
1574 return NOTI_EX_ERROR_INVALID_PARAMETER;
1576 Handle* h = static_cast<Handle*>(handle);
1577 AbstractItem* p = h->Get();
1578 *id = strdup(p->GetId().c_str());
1579 return NOTI_EX_ERROR_NONE;
1582 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1584 if (handle == nullptr || id == nullptr) {
1585 LOGE("Invalid parameter");
1586 return NOTI_EX_ERROR_INVALID_PARAMETER;
1588 Handle* p = static_cast<Handle*>(handle);
1589 p->Get()->SetId(id);
1590 return NOTI_EX_ERROR_NONE;
1593 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1594 noti_ex_action_h *action) {
1595 if (handle == nullptr || action == nullptr) {
1596 LOGE("Invalid parameter");
1597 return NOTI_EX_ERROR_INVALID_PARAMETER;
1599 Handle* p = static_cast<Handle*>(handle);
1600 if (p->Get()->GetAction() == nullptr) {
1602 return NOTI_EX_ERROR_NONE;
1604 *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1606 return NOTI_EX_ERROR_NONE;
1609 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1610 noti_ex_action_h action) {
1611 if (handle == nullptr || action == nullptr) {
1612 LOGE("Invalid parameter");
1613 return NOTI_EX_ERROR_INVALID_PARAMETER;
1616 Handle* p = static_cast<Handle*>(handle);
1617 AbstractAction* a = static_cast<AbstractAction*>(action);
1618 p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1619 return NOTI_EX_ERROR_NONE;
1622 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1623 noti_ex_style_h *style) {
1624 if (handle == nullptr || style == nullptr) {
1625 LOGE("Invalid parameter");
1626 return NOTI_EX_ERROR_INVALID_PARAMETER;
1629 Handle* p = static_cast<Handle*>(handle);
1630 shared_ptr<Style> s = p->Get()->GetStyle();
1631 *style = static_cast<noti_ex_style_h>(s.get());
1632 return NOTI_EX_ERROR_NONE;
1635 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1636 noti_ex_style_h style) {
1637 if (handle == nullptr || style == nullptr) {
1638 LOGE("Invalid parameter");
1639 return NOTI_EX_ERROR_INVALID_PARAMETER;
1642 Handle* p = static_cast<Handle*>(handle);
1643 Style* s = static_cast<Style*>(style);
1644 p->Get()->SetStyle(shared_ptr<Style>(s));
1645 return NOTI_EX_ERROR_NONE;
1648 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1650 if (handle == nullptr) {
1651 LOGE("Invalid parameter");
1652 return NOTI_EX_ERROR_INVALID_PARAMETER;
1655 Handle* p = static_cast<Handle*>(handle);
1656 p->Get()->SetVisible(visible);
1657 return NOTI_EX_ERROR_NONE;
1660 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1662 if (handle == nullptr || visible == nullptr) {
1663 LOGE("Invalid parameter");
1664 return NOTI_EX_ERROR_INVALID_PARAMETER;
1667 Handle* p = static_cast<Handle*>(handle);
1668 *visible = p->Get()->GetVisible();
1669 return NOTI_EX_ERROR_NONE;
1672 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1674 if (handle == nullptr) {
1675 LOGE("Invalid parameter");
1676 return NOTI_EX_ERROR_INVALID_PARAMETER;
1679 Handle* p = static_cast<Handle*>(handle);
1680 p->Get()->SetEnable(enable);
1681 return NOTI_EX_ERROR_NONE;
1684 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1686 if (handle == nullptr || enable == nullptr) {
1687 LOGE("Invalid parameter");
1688 return NOTI_EX_ERROR_INVALID_PARAMETER;
1691 Handle* p = static_cast<Handle*>(handle);
1692 *enable = p->Get()->GetEnable();
1693 return NOTI_EX_ERROR_NONE;
1696 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1697 const char *receiver_group) {
1698 if (handle == nullptr || receiver_group == nullptr) {
1699 LOGE("Invalid parameter");
1700 return NOTI_EX_ERROR_INVALID_PARAMETER;
1703 Handle* p = static_cast<Handle*>(handle);
1704 p->Get()->AddReceiver(receiver_group);
1705 return NOTI_EX_ERROR_NONE;
1708 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1709 const char *receiver_group) {
1710 if (handle == nullptr || receiver_group == nullptr) {
1711 LOGE("Invalid parameter");
1712 return NOTI_EX_ERROR_INVALID_PARAMETER;
1715 Handle* p = static_cast<Handle*>(handle);
1716 p->Get()->RemoveReceiver(receiver_group);
1717 return NOTI_EX_ERROR_NONE;
1720 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1721 char ***receiver_list, int *count) {
1722 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1723 LOGE("Invalid parameter");
1724 return NOTI_EX_ERROR_INVALID_PARAMETER;
1727 Handle* p = static_cast<Handle*>(handle);
1728 list<string> receivers = p->Get()->GetReceiverList();
1729 *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1731 for (auto& i : receivers) {
1732 *receiver_list[idx++] = strdup(i.c_str());
1734 *count = receivers.size();
1735 return NOTI_EX_ERROR_NONE;
1738 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1740 if (handle == nullptr) {
1741 LOGE("Invalid parameter");
1742 return NOTI_EX_ERROR_INVALID_PARAMETER;
1745 Handle* p = static_cast<Handle*>(handle);
1746 p->Get()->SetPolicy(policy);
1747 return NOTI_EX_ERROR_NONE;
1750 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1752 if (handle == nullptr || policy == nullptr) {
1753 LOGE("Invalid parameter");
1754 return NOTI_EX_ERROR_INVALID_PARAMETER;
1757 Handle* p = static_cast<Handle*>(handle);
1758 *policy = p->Get()->GetPolicy();
1759 return NOTI_EX_ERROR_NONE;
1762 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1764 if (handle == nullptr || channel == nullptr) {
1765 LOGE("Invalid parameter");
1766 return NOTI_EX_ERROR_INVALID_PARAMETER;
1769 Handle* p = static_cast<Handle*>(handle);
1770 if (!p->Get()->GetChannel().empty())
1771 *channel = strdup(p->Get()->GetChannel().c_str());
1775 return NOTI_EX_ERROR_NONE;
1778 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1779 const char *channel) {
1780 if (handle == nullptr) {
1781 LOGE("Invalid parameter");
1782 return NOTI_EX_ERROR_INVALID_PARAMETER;
1785 Handle* p = static_cast<Handle*>(handle);
1786 p->Get()->SetChannel(channel);
1787 return NOTI_EX_ERROR_NONE;
1790 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1791 noti_ex_led_info_h led) {
1792 if (handle == nullptr) {
1793 LOGE("Invalid parameter");
1794 return NOTI_EX_ERROR_INVALID_PARAMETER;
1797 Handle* p = static_cast<Handle*>(handle);
1798 LEDInfo* led_info = static_cast<LEDInfo*>(led);
1799 p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1800 return NOTI_EX_ERROR_NONE;
1803 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1804 noti_ex_led_info_h *led) {
1805 if (handle == nullptr) {
1806 LOGE("Invalid parameter");
1807 return NOTI_EX_ERROR_INVALID_PARAMETER;
1810 Handle* p = static_cast<Handle*>(handle);
1811 if (p->Get()->GetLEDInfo() != nullptr)
1812 *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1815 return NOTI_EX_ERROR_NONE;
1818 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1820 if (handle == nullptr) {
1821 LOGE("Invalid parameter");
1822 return NOTI_EX_ERROR_INVALID_PARAMETER;
1825 Handle* p = static_cast<Handle*>(handle);
1826 if (path == nullptr)
1827 p->Get()->SetSoundPath("");
1829 p->Get()->SetSoundPath(path);
1830 return NOTI_EX_ERROR_NONE;
1833 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1835 if (handle == nullptr) {
1836 LOGE("Invalid parameter");
1837 return NOTI_EX_ERROR_INVALID_PARAMETER;
1840 Handle* p = static_cast<Handle*>(handle);
1841 if (path == nullptr)
1842 p->Get()->SetVibrationPath("");
1844 p->Get()->SetVibrationPath(path);
1845 return NOTI_EX_ERROR_NONE;
1848 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1850 if (handle == nullptr || path == nullptr) {
1851 LOGE("Invalid parameter");
1852 return NOTI_EX_ERROR_INVALID_PARAMETER;
1855 Handle* p = static_cast<Handle*>(handle);
1856 if (p->Get()->GetSoundPath().empty())
1859 *path = strdup(p->Get()->GetSoundPath().c_str());
1860 return NOTI_EX_ERROR_NONE;
1863 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1865 if (handle == nullptr || path == nullptr) {
1866 LOGE("Invalid parameter");
1867 return NOTI_EX_ERROR_INVALID_PARAMETER;
1870 Handle* p = static_cast<Handle*>(handle);
1871 if (p->Get()->GetVibrationPath().empty())
1874 *path = strdup(p->Get()->GetVibrationPath().c_str());
1875 return NOTI_EX_ERROR_NONE;
1878 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1879 noti_ex_item_info_h *info) {
1880 if (handle == nullptr || info == nullptr) {
1881 LOGE("Invalid parameter");
1882 return NOTI_EX_ERROR_INVALID_PARAMETER;
1885 Handle* p = static_cast<Handle*>(handle);
1886 if (p->Get()->GetInfo() == nullptr)
1889 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1890 return NOTI_EX_ERROR_NONE;
1893 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1895 if (handle == nullptr || id == nullptr) {
1896 LOGE("Invalid parameter");
1897 return NOTI_EX_ERROR_INVALID_PARAMETER;
1900 Handle* p = static_cast<Handle*>(handle);
1901 if (p->Get()->GetSenderAppId().empty())
1904 *id = strdup(p->Get()->GetSenderAppId().c_str());
1905 return NOTI_EX_ERROR_NONE;
1908 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1910 if (handle == nullptr || tag == nullptr) {
1911 LOGE("Invalid parameter");
1912 return NOTI_EX_ERROR_INVALID_PARAMETER;
1915 Handle* p = static_cast<Handle*>(handle);
1916 if (p->Get()->GetTag().empty())
1919 *tag = strdup(p->Get()->GetTag().c_str());
1920 return NOTI_EX_ERROR_NONE;
1923 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1925 if (handle == nullptr) {
1926 LOGE("Invalid parameter");
1927 return NOTI_EX_ERROR_INVALID_PARAMETER;
1930 Handle* p = static_cast<Handle*>(handle);
1932 p->Get()->SetTag("");
1934 p->Get()->SetTag(tag);
1935 return NOTI_EX_ERROR_NONE;
1938 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1939 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1941 if (handle == nullptr) {
1942 LOGE("Invalid parameter");
1943 return NOTI_EX_ERROR_INVALID_PARAMETER;
1946 string receiver_group_str = "";
1948 receiver_group_str = string(receiver_group);
1950 ManagerStub* stub = new (std::nothrow) ManagerStub(
1951 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1952 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1953 receiver_group_str);
1954 if (stub == nullptr) {
1955 LOGE("Fail to create manager");
1956 return NOTI_EX_ERROR_IO_ERROR;
1958 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1959 new ManagerCallbackInfo(event_callbacks, data)));
1960 *handle = static_cast<noti_ex_manager_h>(stub);
1962 return NOTI_EX_ERROR_NONE;
1965 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1966 if (handle == nullptr) {
1967 LOGE("Invalid parameter");
1968 return NOTI_EX_ERROR_INVALID_PARAMETER;
1970 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1972 return NOTI_EX_ERROR_NONE;
1975 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1976 noti_ex_item_h **items, int *count) {
1977 if (handle == nullptr || items == nullptr || count == nullptr) {
1978 LOGE("Invalid parameter");
1979 return NOTI_EX_ERROR_INVALID_PARAMETER;
1983 ManagerStub* stub = static_cast<ManagerStub*>(handle);
1984 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1985 if (item_list.size() == 0) {
1988 return NOTI_EX_ERROR_NONE;
1990 *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1991 if (*items == nullptr) {
1992 LOGE("Fail to create items");
1993 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1997 for (auto& i : item_list) {
1998 *items[idx++] = new Handle(move(i));
2000 *count = item_list.size();
2001 } catch (Exception &ex) {
2002 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2003 return NOTI_EX_ERROR_IO_ERROR;
2005 return NOTI_EX_ERROR_NONE;
2008 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2009 noti_ex_item_h noti, int *request_id) {
2010 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2011 LOGE("Invalid parameter");
2012 return NOTI_EX_ERROR_INVALID_PARAMETER;
2015 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2016 Handle* sp = static_cast<Handle*>(noti);
2017 if (sp->GetPtr().get() == nullptr) {
2018 LOGE("Invalid noti reference can not be sended");
2019 return NOTI_EX_ERROR_INVALID_PARAMETER;
2021 *request_id = stub->Update(sp->GetPtr());
2023 } catch (Exception &ex) {
2024 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2025 return NOTI_EX_ERROR_IO_ERROR;
2027 return NOTI_EX_ERROR_NONE;
2030 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2031 noti_ex_item_h noti, int *request_id) {
2032 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2033 LOGE("Invalid parameter");
2034 return NOTI_EX_ERROR_INVALID_PARAMETER;
2037 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2038 Handle* item = static_cast<Handle*>(noti);
2039 if (item->GetPtr().get() == nullptr) {
2040 LOGE("Invalid noti reference can not be sended");
2041 return NOTI_EX_ERROR_INVALID_PARAMETER;
2043 *request_id = stub->Delete(item->GetPtr());
2045 } catch (Exception &ex) {
2046 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2047 return NOTI_EX_ERROR_IO_ERROR;
2049 return NOTI_EX_ERROR_NONE;
2052 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2054 if (handle == nullptr || request_id == nullptr) {
2055 LOGE("Invalid parameter");
2056 return NOTI_EX_ERROR_INVALID_PARAMETER;
2059 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2060 *request_id = stub->DeleteAll();
2061 } catch (Exception &ex) {
2062 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2063 return NOTI_EX_ERROR_IO_ERROR;
2065 return NOTI_EX_ERROR_NONE;
2068 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2069 noti_ex_item_h noti, int *request_id) {
2070 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2071 LOGE("Invalid parameter");
2072 return NOTI_EX_ERROR_INVALID_PARAMETER;
2075 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2076 Handle* item = static_cast<Handle*>(noti);
2077 if (item->GetPtr().get() == nullptr) {
2078 LOGE("Invalid noti reference can not be sended");
2079 return NOTI_EX_ERROR_INVALID_PARAMETER;
2081 *request_id = stub->Hide(item->GetPtr());
2083 } catch (Exception &ex) {
2084 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2085 return NOTI_EX_ERROR_IO_ERROR;
2087 return NOTI_EX_ERROR_NONE;
2090 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2091 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2092 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2093 LOGE("Invalid parameter");
2094 return NOTI_EX_ERROR_INVALID_PARAMETER;
2097 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2098 *item = new Handle(stub->FindByRootID(root_id));
2099 } catch (Exception &ex) {
2100 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2101 return NOTI_EX_ERROR_IO_ERROR;
2103 return NOTI_EX_ERROR_NONE;
2106 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2107 noti_ex_event_info_h info, noti_ex_error_e error) {
2108 if (handle == nullptr || info == nullptr) {
2109 LOGE("Invalid parameter");
2110 return NOTI_EX_ERROR_INVALID_PARAMETER;
2113 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2114 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2115 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2116 static_cast<NotificationError>(error));
2117 } catch (Exception &ex) {
2118 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2119 return NOTI_EX_ERROR_IO_ERROR;
2121 return NOTI_EX_ERROR_NONE;
2124 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2125 noti_ex_manager_h handle, int *cnt) {
2127 if (handle == nullptr || cnt == nullptr) {
2128 LOGE("Invalid parameter");
2129 return NOTI_EX_ERROR_INVALID_PARAMETER;
2132 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2133 *cnt = stub->GetCount();
2134 } catch (Exception &ex) {
2135 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2136 return NOTI_EX_ERROR_IO_ERROR;
2138 return NOTI_EX_ERROR_NONE;
2141 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2142 const char *id, float min, float current, float max) {
2145 if (handle == nullptr) {
2146 LOGE("Invalid parameter");
2147 return NOTI_EX_ERROR_INVALID_PARAMETER;
2151 p = new (std::nothrow) ProgressItem(id, min, current, max);
2153 p = new (std::nothrow) ProgressItem(min, current, max);
2156 LOGE("Out-of-memory");
2157 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2160 *handle = new Handle(p);
2162 return NOTI_EX_ERROR_NONE;
2165 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2166 noti_ex_item_h handle, float *current) {
2167 if (handle == nullptr || current == nullptr) {
2168 LOGE("Invalid parameter");
2169 return NOTI_EX_ERROR_INVALID_PARAMETER;
2172 Handle *h = static_cast<Handle*>(handle);
2173 if (!h->IsValidType(AbstractItem::Progress)) {
2174 LOGE("Invalid handle type");
2175 return NOTI_EX_ERROR_INVALID_PARAMETER;
2177 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2178 *current = p->GetCurrent();
2180 return NOTI_EX_ERROR_NONE;
2183 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2184 noti_ex_item_h handle, float current) {
2185 if (handle == nullptr) {
2186 LOGE("Invalid parameter");
2187 return NOTI_EX_ERROR_INVALID_PARAMETER;
2190 Handle *h = static_cast<Handle*>(handle);
2191 if (!h->IsValidType(AbstractItem::Progress)) {
2192 LOGE("Invalid handle type");
2193 return NOTI_EX_ERROR_INVALID_PARAMETER;
2195 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2196 p->SetCurrent(current);
2198 return NOTI_EX_ERROR_NONE;
2201 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2203 if (handle == nullptr || min == nullptr) {
2204 LOGE("Invalid parameter");
2205 return NOTI_EX_ERROR_INVALID_PARAMETER;
2208 Handle *h = static_cast<Handle*>(handle);
2209 if (!h->IsValidType(AbstractItem::Progress)) {
2210 LOGE("Invalid handle type");
2211 return NOTI_EX_ERROR_INVALID_PARAMETER;
2213 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2216 return NOTI_EX_ERROR_NONE;
2219 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2221 if (handle == nullptr || max == nullptr) {
2222 LOGE("Invalid parameter");
2223 return NOTI_EX_ERROR_INVALID_PARAMETER;
2226 Handle *h = static_cast<Handle*>(handle);
2227 if (!h->IsValidType(AbstractItem::Progress)) {
2228 LOGE("Invalid handle type");
2229 return NOTI_EX_ERROR_INVALID_PARAMETER;
2231 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2234 return NOTI_EX_ERROR_NONE;
2237 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2238 noti_ex_reporter_events_s event_callbacks, void *data) {
2239 if (handle == nullptr) {
2240 LOGE("Invalid parameter");
2241 return NOTI_EX_ERROR_INVALID_PARAMETER;
2244 ReporterStub* stub = new (std::nothrow) ReporterStub(
2245 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2246 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2247 if (stub == nullptr) {
2248 LOGE("Fail to create manager");
2249 return NOTI_EX_ERROR_IO_ERROR;
2251 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2252 new ReporterCallbackInfo(event_callbacks, data)));
2254 *handle = static_cast<noti_ex_reporter_h>(stub);
2256 return NOTI_EX_ERROR_NONE;
2259 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2260 if (handle == nullptr) {
2261 LOGE("Invalid parameter");
2262 return NOTI_EX_ERROR_INVALID_PARAMETER;
2264 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2266 return NOTI_EX_ERROR_NONE;
2269 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2270 noti_ex_event_info_h info, noti_ex_error_e error) {
2271 if (handle == nullptr || info == nullptr) {
2272 LOGE("Invalid parameter");
2273 return NOTI_EX_ERROR_INVALID_PARAMETER;
2276 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2277 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2278 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2279 static_cast<NotificationError>(error));
2280 } catch (Exception &ex) {
2281 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2282 return NOTI_EX_ERROR_IO_ERROR;
2284 return NOTI_EX_ERROR_NONE;
2287 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2288 noti_ex_item_h noti, int *request_id) {
2289 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2290 LOGE("Invalid parameter");
2291 return NOTI_EX_ERROR_INVALID_PARAMETER;
2294 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2295 Handle* h = static_cast<Handle*>(noti);
2296 if (h->GetPtr().get() == nullptr) {
2297 LOGE("Invalid noti reference can not be sended");
2298 return NOTI_EX_ERROR_INVALID_PARAMETER;
2300 *request_id = stub->Post(h->GetPtr());
2302 } catch (Exception &ex) {
2303 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2304 return NOTI_EX_ERROR_IO_ERROR;
2306 return NOTI_EX_ERROR_NONE;
2309 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2310 noti_ex_item_h *noti_list, int count, int *request_id) {
2312 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2313 LOGE("Invalid parameter");
2314 return NOTI_EX_ERROR_INVALID_PARAMETER;
2317 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2318 list<shared_ptr<item::AbstractItem>> notiList;
2319 for (int i = 0; i < count; i++) {
2320 Handle* item = static_cast<Handle*>(noti_list[i]);
2321 notiList.push_back(item->GetPtr());
2323 *request_id = stub->Post(notiList);
2324 } catch (Exception &ex) {
2325 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2326 return NOTI_EX_ERROR_IO_ERROR;
2328 return NOTI_EX_ERROR_NONE;
2331 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2332 noti_ex_item_h noti, int *request_id) {
2333 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2334 LOGE("Invalid parameter");
2335 return NOTI_EX_ERROR_INVALID_PARAMETER;
2338 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2339 Handle* item = static_cast<Handle*>(noti);
2340 if (item->GetPtr().get() == nullptr) {
2341 LOGE("Invalid noti reference can not be sended");
2342 return NOTI_EX_ERROR_INVALID_PARAMETER;
2344 *request_id = stub->Update(item->GetPtr());
2346 } catch (Exception &ex) {
2347 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2348 return NOTI_EX_ERROR_IO_ERROR;
2350 return NOTI_EX_ERROR_NONE;
2353 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2354 noti_ex_item_h noti, int *request_id) {
2355 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2356 LOGE("Invalid parameter");
2357 return NOTI_EX_ERROR_INVALID_PARAMETER;
2360 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2361 Handle* item = static_cast<Handle*>(noti);
2362 if (item->GetPtr().get() == nullptr) {
2363 LOGE("Invalid noti reference can not be sended");
2364 return NOTI_EX_ERROR_INVALID_PARAMETER;
2366 *request_id = stub->Delete(item->GetPtr());
2368 } catch (Exception &ex) {
2369 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2370 return NOTI_EX_ERROR_IO_ERROR;
2372 return NOTI_EX_ERROR_NONE;
2375 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2376 noti_ex_reporter_h handle, int *request_id) {
2377 if (handle == nullptr || request_id == nullptr) {
2378 LOGE("Invalid parameter");
2379 return NOTI_EX_ERROR_INVALID_PARAMETER;
2382 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2383 *request_id = stub->DeleteAll();
2384 } catch (Exception &ex) {
2385 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2386 return NOTI_EX_ERROR_IO_ERROR;
2388 return NOTI_EX_ERROR_NONE;
2391 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2392 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2393 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2394 LOGE("Invalid parameter");
2395 return NOTI_EX_ERROR_INVALID_PARAMETER;
2398 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2399 *item = new Handle(stub->FindByRootID(root_id));
2400 } catch (Exception &ex) {
2401 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2402 return NOTI_EX_ERROR_IO_ERROR;
2404 return NOTI_EX_ERROR_NONE;
2407 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2408 const char *id, const char *text, const char *hyperlink) {
2409 if (handle == nullptr) {
2410 LOGE("Invalid parameter");
2411 return NOTI_EX_ERROR_INVALID_PARAMETER;
2417 p = new (std::nothrow) TextItem(id, std::string(text),
2418 std::string(hyperlink));
2420 p = new (std::nothrow) TextItem(id, std::string(text));
2423 LOGE("Out-of-memory");
2424 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2427 *handle = new Handle(shared_ptr<AbstractItem>(p));
2429 return NOTI_EX_ERROR_NONE;
2432 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2433 const char *contents) {
2434 if (handle == nullptr) {
2435 LOGE("Invalid parameter");
2436 return NOTI_EX_ERROR_INVALID_PARAMETER;
2439 Handle* p = static_cast<Handle*>(handle);
2440 if (!p->IsValidType(AbstractItem::Text)) {
2441 LOGE("Invalid handle type");
2442 return NOTI_EX_ERROR_INVALID_PARAMETER;
2444 TextItem* ti = static_cast<TextItem*>(p->Get());
2445 ti->SetContents(std::string(contents));
2447 return NOTI_EX_ERROR_NONE;
2450 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2452 if (handle == nullptr || contents == nullptr) {
2453 LOGE("Invalid parameter");
2454 return NOTI_EX_ERROR_INVALID_PARAMETER;
2457 Handle* p = static_cast<Handle*>(handle);
2458 if (!p->IsValidType(AbstractItem::Text)) {
2459 LOGE("Invalid handle type");
2460 return NOTI_EX_ERROR_INVALID_PARAMETER;
2462 TextItem* ti = static_cast<TextItem*>(p->Get());
2463 if (!ti->GetContents().empty()) {
2464 *contents = strdup(ti->GetContents().c_str());
2465 if (*contents == nullptr) {
2466 LOGE("Out-of-memory");
2467 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2471 return NOTI_EX_ERROR_NONE;
2474 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2475 noti_ex_item_h handle, char **hyper_link) {
2476 if (handle == nullptr || hyper_link == nullptr) {
2477 LOGE("Invalid parameter");
2478 return NOTI_EX_ERROR_INVALID_PARAMETER;
2481 Handle* p = static_cast<Handle*>(handle);
2482 if (!p->IsValidType(AbstractItem::Text)) {
2483 LOGE("Invalid handle type");
2484 return NOTI_EX_ERROR_INVALID_PARAMETER;
2486 TextItem* ti = static_cast<TextItem*>(p->Get());
2487 if (!ti->GetHyperLink().empty()) {
2488 *hyper_link = strdup(ti->GetHyperLink().c_str());
2489 if (*hyper_link == nullptr) {
2490 LOGE("Out-of-memory");
2491 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2495 return NOTI_EX_ERROR_NONE;
2498 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2499 const char *id, time_t time) {
2502 if (handle == nullptr) {
2503 LOGE("Invalid parameter");
2504 return NOTI_EX_ERROR_INVALID_PARAMETER;
2509 p = new (std::nothrow) TimeItem(id, time);
2511 p = new (std::nothrow) TimeItem(time);
2513 p = new (std::nothrow) TimeItem();
2517 LOGE("Out-of-memory");
2518 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2521 *handle = new Handle(shared_ptr<AbstractItem>(p));
2523 return NOTI_EX_ERROR_NONE;
2526 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2528 if (handle == nullptr || time == nullptr) {
2529 LOGE("Invalid parameter");
2530 return NOTI_EX_ERROR_INVALID_PARAMETER;
2532 Handle* h = static_cast<Handle*>(handle);
2533 if (!h->IsValidType(AbstractItem::Time)) {
2534 LOGE("Invalid handle type");
2535 return NOTI_EX_ERROR_INVALID_PARAMETER;
2537 TimeItem* p = static_cast<TimeItem*>(h->Get());
2538 *time = p->GetTime();
2540 return NOTI_EX_ERROR_NONE;
2543 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2544 noti_ex_action_h *handle, const char *extra) {
2545 if (handle == nullptr) {
2546 LOGE("Invalid parameter");
2547 return NOTI_EX_ERROR_INVALID_PARAMETER;
2550 string extra_str = "";
2552 extra_str = string(extra);
2554 auto* p = new (std::nothrow) VisibilityAction(extra_str);
2556 LOGE("Out-of-memory");
2557 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2562 return NOTI_EX_ERROR_NONE;
2565 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2566 const char *id, bool visible) {
2567 if (handle == nullptr || id == nullptr) {
2568 LOGE("Invalid parameter");
2569 return NOTI_EX_ERROR_INVALID_PARAMETER;
2572 VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2573 p->SetVisibility(id, visible);
2575 return NOTI_EX_ERROR_NONE;