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/event_info_internal.h"
52 #include "notification-ex/manager.h"
53 #include "notification-ex/dbus_sender.h"
54 #include "notification-ex/dbus_event_listener.h"
55 #include "notification-ex/exception.h"
60 #define LOG_TAG "NOTIFICATION_EX"
65 #define EXPORT_API __attribute__((visibility("default")))
68 using namespace tizen_base;
69 using namespace notification::item;
70 using namespace notification;
76 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
77 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
78 : ref_(nullptr), ptr_(move(ptr)) { }
79 virtual ~Handle() = default;
80 item::AbstractItem* Get() const {
86 bool IsValidType(int type) const {
87 return (Get()->GetType() == type
88 || Get()->GetType() >= AbstractItem::Custom);
91 std::shared_ptr<item::AbstractItem> GetPtr() const {
93 return std::shared_ptr<item::AbstractItem>({});
98 item::AbstractItem* ref_;
99 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) {
114 if (cb_.added == nullptr)
116 noti_ex_item_h* added_item =
117 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
118 if (added_item == nullptr) {
119 LOGE("Out of memory");
124 for (auto& i : addedItem) {
126 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
129 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
130 cb_.added(static_cast<noti_ex_manager_h>(manager),
131 static_cast<noti_ex_event_info_h>(c_info), added_item,
132 addedItem.size(), user_data_);
136 void InvokeUpdated(Manager* manager, const IEventInfo& info,
137 shared_ptr<item::AbstractItem> updatedItem) {
138 if (cb_.updated == nullptr)
140 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
141 cb_.updated(static_cast<noti_ex_manager_h>(manager),
142 static_cast<noti_ex_event_info_h>(c_info),
143 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
146 void InvokeDeleted(Manager* manager, const IEventInfo& info,
147 shared_ptr<item::AbstractItem> deletedItem) {
148 if (cb_.deleted == nullptr)
150 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
151 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
152 static_cast<noti_ex_event_info_h>(c_info),
153 static_cast<noti_ex_item_h>(
154 new Handle(deletedItem)), user_data_);
157 void InvokeError(Manager* manager, NotificationError error, int requestId) {
158 if (cb_.error == nullptr)
160 cb_.error(static_cast<noti_ex_manager_h>(manager),
161 static_cast<noti_ex_error_e>(error), requestId, user_data_);
165 noti_ex_manager_events_s cb_;
169 class ManagerStub : public Manager {
171 ManagerStub(std::unique_ptr<IEventSender> sender,
172 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
173 : Manager(move(sender), move(listener), receiver_group) {
176 void OnAdd(const IEventInfo& info,
177 list<shared_ptr<AbstractItem>> addedItem) override {
178 cb_->InvokeAdded(this, info, addedItem);
181 void OnUpdate(const IEventInfo& info,
182 std::shared_ptr<item::AbstractItem> updatedItem) override {
183 cb_->InvokeUpdated(this, info, updatedItem);
186 void OnDelete(const IEventInfo& info,
187 shared_ptr<item::AbstractItem> deletedItem) override {
188 cb_->InvokeDeleted(this, info, deletedItem);
191 void OnError(NotificationError error, int requestId) override {
192 cb_->InvokeError(this, error, requestId);
195 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
197 return NOTI_EX_ERROR_NONE;
200 int ClearManagerCallbackInfo() {
202 return NOTI_EX_ERROR_NONE;
206 unique_ptr<ManagerCallbackInfo> cb_;
210 class ReporterCallbackInfo {
212 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
213 : user_data_(user_data) {
214 cb_.event = cb.event;
215 cb_.error = cb.error;
218 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
219 list<shared_ptr<AbstractItem>> notiList) {
220 if (cb_.event == nullptr)
222 noti_ex_item_h* noti_list =
223 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
224 if (noti_list == nullptr) {
225 LOGE("Out of memory");
230 for (auto& i : notiList) {
232 static_cast<noti_ex_item_h>(new Handle(i));
235 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
236 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
237 static_cast<noti_ex_event_info_h>(c_info), noti_list,
238 notiList.size(), user_data_);
242 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
243 if (cb_.error == nullptr)
245 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
246 static_cast<noti_ex_error_e>(error), requestId, user_data_);
250 noti_ex_reporter_events_s cb_;
254 class ReporterStub : public Reporter {
256 ReporterStub(std::unique_ptr<IEventSender> sender,
257 std::unique_ptr<IEventListener> listener)
258 : Reporter(move(sender), move(listener)) {
261 void OnEvent(const IEventInfo& info,
262 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
263 cb_->InvokeEvent(this, info, notiList);
266 void OnError(NotificationError error, int requestId) override {
267 cb_->InvokeError(this, error, requestId);
270 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
272 return NOTI_EX_ERROR_NONE;
275 int ClearReporterCallbackInfo() {
277 return NOTI_EX_ERROR_NONE;
281 unique_ptr<ReporterCallbackInfo> cb_;
286 void __noti_ex_free_str_array(char** val, int length) {
288 for (i = 0; i < length ; i++)
293 extern "C" EXPORT_API int noti_ex_action_app_control_create(
294 noti_ex_action_h *handle, app_control_h app_control,
296 if (handle == nullptr || app_control == nullptr) {
297 LOGE("Invalid parameter");
298 return NOTI_EX_ERROR_INVALID_PARAMETER;
301 shared_ptr<AbstractAction>* p;
304 p = new (std::nothrow) shared_ptr<AbstractAction>(
305 new (std::nothrow) AppControlAction(app_control, extra));
307 p = new (std::nothrow) shared_ptr<AbstractAction>(
308 new (std::nothrow) AppControlAction(app_control));
312 LOGE("Out-of-memory");
313 return NOTI_EX_ERROR_OUT_OF_MEMORY;
318 return NOTI_EX_ERROR_NONE;
321 extern "C" EXPORT_API int noti_ex_action_app_control_set(
322 noti_ex_action_h handle, app_control_h app_control) {
323 if (handle == nullptr || app_control == nullptr) {
324 LOGE("Invalid parameter");
325 return NOTI_EX_ERROR_INVALID_PARAMETER;
328 shared_ptr<AbstractAction>* ptr =
329 static_cast<shared_ptr<AbstractAction>*>(handle);
330 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
331 action->SetAppControl(app_control);
333 return NOTI_EX_ERROR_NONE;
336 extern "C" EXPORT_API int noti_ex_action_app_control_get(
337 noti_ex_action_h handle, app_control_h *app_control) {
338 if (handle == nullptr || app_control == nullptr) {
339 LOGE("Invalid parameter");
340 return NOTI_EX_ERROR_INVALID_PARAMETER;
343 shared_ptr<AbstractAction>* ptr =
344 static_cast<shared_ptr<AbstractAction>*>(handle);
345 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
346 *app_control = action->GetAppControl();
348 return NOTI_EX_ERROR_NONE;
351 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
352 const char *id, const char *title) {
355 if (handle == nullptr || title == nullptr) {
356 LOGE("Invalid parameter");
357 return NOTI_EX_ERROR_INVALID_PARAMETER;
361 p = new (std::nothrow) ButtonItem(id, title);
363 p = new (std::nothrow) ButtonItem(title);
366 LOGE("Out-of-memory");
367 return NOTI_EX_ERROR_OUT_OF_MEMORY;
369 *handle = new Handle(shared_ptr<AbstractItem>(p));
371 return NOTI_EX_ERROR_NONE;
374 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
376 if (handle == nullptr || title == nullptr) {
377 LOGE("Invalid parameter");
378 return NOTI_EX_ERROR_INVALID_PARAMETER;
381 Handle* sp = static_cast<Handle*>(handle);
382 if (!sp->IsValidType(AbstractItem::Button)) {
383 LOGE("Invalid handle type");
384 return NOTI_EX_ERROR_INVALID_PARAMETER;
386 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
387 if (!p->GetTitle().empty()) {
388 *title = strdup(p->GetTitle().c_str());
389 if (*title == nullptr) {
390 LOGE("Out-of-memory");
391 return NOTI_EX_ERROR_OUT_OF_MEMORY;
395 return NOTI_EX_ERROR_NONE;
398 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
399 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
400 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
401 noti_ex_item_chat_message_type_e message_type) {
402 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
403 LOGE("Invalid parameter");
404 return NOTI_EX_ERROR_INVALID_PARAMETER;
407 auto* p = new (std::nothrow) ChatMessageItem(id,
408 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
409 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
410 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
411 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
412 static_cast<ChatMessageItem::Type>(message_type));
414 LOGE("Out-of-memory");
415 return NOTI_EX_ERROR_OUT_OF_MEMORY;
418 *handle = new Handle(shared_ptr<AbstractItem>(p));
420 return NOTI_EX_ERROR_NONE;
423 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
424 noti_ex_item_h handle, noti_ex_item_h *name) {
425 if (handle == nullptr || name == nullptr) {
426 LOGE("Invalid parameter");
427 return NOTI_EX_ERROR_INVALID_PARAMETER;
429 Handle* h = static_cast<Handle*>(handle);
430 if (!h->IsValidType(AbstractItem::ChatMessage)) {
431 LOGE("Invalid handle type");
432 return NOTI_EX_ERROR_INVALID_PARAMETER;
434 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
435 *name = new Handle(&(p->GetNameItem()));
437 return NOTI_EX_ERROR_NONE;
440 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
441 noti_ex_item_h handle, noti_ex_item_h *text) {
442 if (handle == nullptr || text == nullptr) {
443 LOGE("Invalid parameter");
444 return NOTI_EX_ERROR_INVALID_PARAMETER;
447 Handle* h = static_cast<Handle*>(handle);
448 if (!h->IsValidType(AbstractItem::ChatMessage)) {
449 LOGE("Invalid handle type");
450 return NOTI_EX_ERROR_INVALID_PARAMETER;
452 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
453 *text = new Handle(&(p->GetTextItem()));
455 return NOTI_EX_ERROR_NONE;
458 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
459 noti_ex_item_h handle, noti_ex_item_h *image) {
460 if (handle == nullptr || image == nullptr) {
461 LOGE("Invalid parameter");
462 return NOTI_EX_ERROR_INVALID_PARAMETER;
465 Handle* h = static_cast<Handle*>(handle);
466 if (!h->IsValidType(AbstractItem::ChatMessage)) {
467 LOGE("Invalid handle type");
468 return NOTI_EX_ERROR_INVALID_PARAMETER;
470 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
471 *image = new Handle(&(p->GetImageItem()));
473 return NOTI_EX_ERROR_NONE;
476 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
477 noti_ex_item_h handle, noti_ex_item_h *time) {
478 if (handle == nullptr || time == nullptr) {
479 LOGE("Invalid parameter");
480 return NOTI_EX_ERROR_INVALID_PARAMETER;
483 Handle* h = static_cast<Handle*>(handle);
484 if (!h->IsValidType(AbstractItem::ChatMessage)) {
485 LOGE("Invalid handle type");
486 return NOTI_EX_ERROR_INVALID_PARAMETER;
488 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
489 *time = new Handle(&(p->GetTimeItem()));
491 return NOTI_EX_ERROR_NONE;
494 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
495 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
496 if (handle == nullptr || message_type == nullptr) {
497 LOGE("Invalid parameter");
498 return NOTI_EX_ERROR_INVALID_PARAMETER;
501 Handle* h = static_cast<Handle*>(handle);
502 if (!h->IsValidType(AbstractItem::ChatMessage)) {
503 LOGE("Invalid handle type");
504 return NOTI_EX_ERROR_INVALID_PARAMETER;
506 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
507 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
509 return NOTI_EX_ERROR_NONE;
512 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
513 const char *id, const char *title, bool checked) {
516 if (handle == nullptr || title == nullptr) {
517 LOGE("Invalid parameter");
518 return NOTI_EX_ERROR_INVALID_PARAMETER;
521 p = new (std::nothrow) CheckBoxItem(id, title, checked);
523 LOGE("Out-of-memory");
524 return NOTI_EX_ERROR_OUT_OF_MEMORY;
527 *handle = new Handle(shared_ptr<AbstractItem>(p));
529 return NOTI_EX_ERROR_NONE;
532 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
534 if (handle == nullptr || title == nullptr) {
535 LOGE("Invalid parameter");
536 return NOTI_EX_ERROR_INVALID_PARAMETER;
538 Handle* h = static_cast<Handle*>(handle);
539 if (!h->IsValidType(AbstractItem::CheckBox)) {
540 LOGE("Invalid handle type");
541 return NOTI_EX_ERROR_INVALID_PARAMETER;
543 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
544 if (!p->GetTitle().empty()) {
545 *title = strdup(p->GetTitle().c_str());
546 if (*title == nullptr) {
547 LOGE("Out-of-memory");
548 return NOTI_EX_ERROR_OUT_OF_MEMORY;
552 return NOTI_EX_ERROR_NONE;
555 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(
556 noti_ex_item_h handle, bool *checked) {
557 if (handle == nullptr || checked == nullptr) {
558 LOGE("Invalid parameter");
559 return NOTI_EX_ERROR_INVALID_PARAMETER;
561 Handle* h = static_cast<Handle*>(handle);
562 if (!h->IsValidType(AbstractItem::CheckBox)) {
563 LOGE("Invalid handle type");
564 return NOTI_EX_ERROR_INVALID_PARAMETER;
566 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
567 *checked = p->IsChecked();
569 return NOTI_EX_ERROR_NONE;
572 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
573 noti_ex_item_h handle, bool *checked) {
574 if (handle == nullptr || checked == nullptr) {
575 LOGE("Invalid parameter");
576 return NOTI_EX_ERROR_INVALID_PARAMETER;
578 Handle* h = static_cast<Handle*>(handle);
579 if (!h->IsValidType(AbstractItem::CheckBox)) {
580 LOGE("Invalid handle type");
581 return NOTI_EX_ERROR_INVALID_PARAMETER;
583 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
584 *checked = p->IsChecked();
586 return NOTI_EX_ERROR_NONE;
589 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
590 noti_ex_item_h handle, bool checked) {
591 if (handle == nullptr) {
592 LOGE("Invalid parameter");
593 return NOTI_EX_ERROR_INVALID_PARAMETER;
596 Handle* h = static_cast<Handle*>(handle);
597 if (!h->IsValidType(AbstractItem::CheckBox)) {
598 LOGE("Invalid handle type");
599 return NOTI_EX_ERROR_INVALID_PARAMETER;
602 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
603 p->SetChecked(checked);
605 return NOTI_EX_ERROR_NONE;
608 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
612 if (handle == nullptr) {
613 LOGE("Invalid parameter");
614 return NOTI_EX_ERROR_INVALID_PARAMETER;
617 p = new (std::nothrow) EntryItem(id);
619 LOGE("Out-of-memory");
620 return NOTI_EX_ERROR_OUT_OF_MEMORY;
623 *handle = new Handle(shared_ptr<AbstractItem>(p));
625 return NOTI_EX_ERROR_NONE;
628 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
630 if (handle == nullptr || text == nullptr) {
631 LOGE("Invalid parameter");
632 return NOTI_EX_ERROR_INVALID_PARAMETER;
635 Handle* h = static_cast<Handle*>(handle);
636 if (!h->IsValidType(AbstractItem::Entry)) {
637 LOGE("Invalid handle type");
638 return NOTI_EX_ERROR_INVALID_PARAMETER;
640 EntryItem* p = static_cast<EntryItem*>(h->Get());
641 if (!p->GetText().empty()) {
642 *text = strdup(p->GetText().c_str());
643 if (*text == nullptr) {
644 LOGE("Out-of-memory");
645 return NOTI_EX_ERROR_OUT_OF_MEMORY;
649 return NOTI_EX_ERROR_NONE;
652 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
654 if (handle == nullptr || text == nullptr) {
655 LOGE("Invalid parameter");
656 return NOTI_EX_ERROR_INVALID_PARAMETER;
658 Handle* h = static_cast<Handle*>(handle);
659 if (!h->IsValidType(AbstractItem::Entry)) {
660 LOGE("Invalid handle type");
661 return NOTI_EX_ERROR_INVALID_PARAMETER;
663 EntryItem* p = static_cast<EntryItem*>(h->Get());
664 p->SetText(std::string(text));
666 return NOTI_EX_ERROR_NONE;
669 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
670 noti_ex_event_info_h* cloned_handle) {
671 if (handle == nullptr || cloned_handle == nullptr) {
672 LOGE("Invalid parameter");
673 return NOTI_EX_ERROR_INVALID_PARAMETER;
676 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
677 EventInfo* info = new EventInfo(cloned);
678 *cloned_handle = info;
679 return NOTI_EX_ERROR_NONE;
682 extern "C" EXPORT_API int noti_ex_event_info_destroy(
683 noti_ex_event_info_h handle) {
684 if (handle == nullptr) {
685 LOGE("Invalid parameter");
686 return NOTI_EX_ERROR_INVALID_PARAMETER;
688 EventInfo* info = static_cast<EventInfo*>(handle);
690 return NOTI_EX_ERROR_NONE;
693 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
694 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
695 if (handle == nullptr || event_type == nullptr) {
696 LOGE("Invalid parameter");
697 return NOTI_EX_ERROR_INVALID_PARAMETER;
699 EventInfo* info = static_cast<EventInfo*>(handle);
700 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
702 return NOTI_EX_ERROR_NONE;
705 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
706 noti_ex_event_info_h handle, char **owner) {
707 if (handle == nullptr || owner == nullptr) {
708 LOGE("Invalid parameter");
709 return NOTI_EX_ERROR_INVALID_PARAMETER;
711 EventInfo* info = static_cast<EventInfo*>(handle);
712 *owner = strdup(info->GetOwner().c_str());
713 return NOTI_EX_ERROR_NONE;
716 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
717 noti_ex_event_info_h handle, char **channel) {
718 if (handle == nullptr || channel == nullptr) {
719 LOGE("Invalid parameter");
720 return NOTI_EX_ERROR_INVALID_PARAMETER;
722 EventInfo* info = static_cast<EventInfo*>(handle);
723 *channel = strdup(info->GetChannel().c_str());
724 return NOTI_EX_ERROR_NONE;
727 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
728 noti_ex_event_info_h handle, char **item_id) {
729 if (handle == nullptr || item_id == nullptr) {
730 LOGE("Invalid parameter");
731 return NOTI_EX_ERROR_INVALID_PARAMETER;
733 EventInfo* info = static_cast<EventInfo*>(handle);
734 *item_id = strdup(info->GetItemId().c_str());
735 return NOTI_EX_ERROR_NONE;
738 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
739 noti_ex_event_info_h handle, int *req_id) {
740 if (handle == nullptr || req_id == nullptr) {
741 LOGE("Invalid parameter");
742 return NOTI_EX_ERROR_INVALID_PARAMETER;
744 EventInfo* info = static_cast<EventInfo*>(handle);
745 *req_id = info->GetRequestId();
746 return NOTI_EX_ERROR_NONE;
749 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
753 if (handle == nullptr) {
754 LOGE("Invalid parameter");
755 return NOTI_EX_ERROR_INVALID_PARAMETER;
759 p = new (std::nothrow) GroupItem(id);
761 p = new (std::nothrow) GroupItem();
764 LOGE("Out-of-memory");
765 return NOTI_EX_ERROR_OUT_OF_MEMORY;
768 *handle = new Handle(shared_ptr<AbstractItem>(p));
770 return NOTI_EX_ERROR_NONE;
773 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
775 if (handle == nullptr) {
776 LOGE("Invalid parameter");
777 return NOTI_EX_ERROR_INVALID_PARAMETER;
779 Handle* h = static_cast<Handle*>(handle);
780 if (!h->IsValidType(AbstractItem::Group)) {
781 LOGE("Invalid handle type");
782 return NOTI_EX_ERROR_INVALID_PARAMETER;
784 GroupItem* p = static_cast<GroupItem*>(h->Get());
785 p->SetDirection(vertical);
787 return NOTI_EX_ERROR_NONE;
790 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
792 if (handle == nullptr) {
793 LOGE("Invalid parameter");
794 return NOTI_EX_ERROR_INVALID_PARAMETER;
796 Handle* h = static_cast<Handle*>(handle);
797 if (!h->IsValidType(AbstractItem::Group)) {
798 LOGE("Invalid handle type");
799 return NOTI_EX_ERROR_INVALID_PARAMETER;
801 GroupItem* p = static_cast<GroupItem*>(h->Get());
802 *vertical = p->IsVertical();
804 return NOTI_EX_ERROR_NONE;
807 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
809 if (handle == nullptr) {
810 LOGE("Invalid parameter");
811 return NOTI_EX_ERROR_INVALID_PARAMETER;
813 Handle* h = static_cast<Handle*>(handle);
814 if (!h->IsValidType(AbstractItem::Group)) {
815 LOGE("Invalid handle type");
816 return NOTI_EX_ERROR_INVALID_PARAMETER;
818 GroupItem* p = static_cast<GroupItem*>(h->Get());
819 if (!p->GetAppLabel().empty()) {
820 *label = strdup(p->GetAppLabel().c_str());
821 if (*label == nullptr) {
822 LOGE("Out-of-memory");
823 return NOTI_EX_ERROR_OUT_OF_MEMORY;
827 return NOTI_EX_ERROR_NONE;
830 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
831 noti_ex_item_h child) {
832 if (handle == nullptr || child == nullptr) {
833 LOGE("Invalid parameter");
834 return NOTI_EX_ERROR_INVALID_PARAMETER;
836 Handle* h = static_cast<Handle*>(handle);
837 if (!h->IsValidType(AbstractItem::Group)) {
838 LOGE("Invalid handle type");
839 return NOTI_EX_ERROR_INVALID_PARAMETER;
841 auto p = static_cast<GroupItem*>(h->Get());
842 p->AddChild((static_cast<Handle*>(child))->GetPtr());
844 return NOTI_EX_ERROR_NONE;
847 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
848 const char *item_id) {
849 if (handle == nullptr || item_id == nullptr) {
850 LOGE("Invalid parameter");
851 return NOTI_EX_ERROR_INVALID_PARAMETER;
853 Handle* h = static_cast<Handle*>(handle);
854 if (!h->IsValidType(AbstractItem::Group)) {
855 LOGE("Invalid handle type");
856 return NOTI_EX_ERROR_INVALID_PARAMETER;
858 GroupItem* p = static_cast<GroupItem*>(h->Get());
859 p->RemoveChild(std::string(item_id));
861 return NOTI_EX_ERROR_NONE;
864 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
865 noti_ex_item_group_foreach_child_cb callback, void *data) {
866 if (handle == nullptr || callback == nullptr) {
867 LOGE("Invalid parameter");
868 return NOTI_EX_ERROR_INVALID_PARAMETER;
871 Handle* h = static_cast<Handle*>(handle);
872 if (!h->IsValidType(AbstractItem::Group)) {
873 LOGE("Invalid handle type");
874 return NOTI_EX_ERROR_INVALID_PARAMETER;
876 GroupItem* p = static_cast<GroupItem*>(h->Get());
877 list<shared_ptr<AbstractItem>> children = p->GetChildren();
878 LOGI("Retrive (%zd)", children.size());
879 for (auto i : children) {
881 static_cast<noti_ex_item_h>(new Handle(i)), data);
882 if (ret != NOTI_EX_ERROR_NONE) {
883 LOGW("callback return (%d) stop foreach", ret);
888 return NOTI_EX_ERROR_NONE;
891 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
892 const char *id, const char *image_path) {
895 if (handle == nullptr || image_path == nullptr) {
896 LOGE("Invalid parameter");
897 return NOTI_EX_ERROR_INVALID_PARAMETER;
901 p = new (std::nothrow) ImageItem(id, image_path);
903 p = new (std::nothrow) ImageItem(image_path);
906 LOGE("Out-of-memory");
907 return NOTI_EX_ERROR_OUT_OF_MEMORY;
910 *handle = new Handle(shared_ptr<AbstractItem>(p));
912 return NOTI_EX_ERROR_NONE;
915 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
916 noti_ex_item_h handle, char **image_path) {
917 if (handle == nullptr || image_path == nullptr) {
918 LOGE("Invalid parameter");
919 return NOTI_EX_ERROR_INVALID_PARAMETER;
921 Handle* h = static_cast<Handle*>(handle);
922 if (!h->IsValidType(AbstractItem::Image)) {
923 LOGE("Invalid handle type");
924 return NOTI_EX_ERROR_INVALID_PARAMETER;
926 ImageItem* p = static_cast<ImageItem*>(h->Get());
927 if (!p->GetImagePath().empty()) {
928 *image_path = strdup(p->GetImagePath().c_str());
929 if (*image_path == nullptr) {
930 LOGE("Out-of-memory");
931 return NOTI_EX_ERROR_OUT_OF_MEMORY;
935 return NOTI_EX_ERROR_NONE;
938 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
939 noti_ex_item_h *handle, const char *id) {
940 InputSelectorItem* p;
942 if (handle == nullptr) {
943 LOGE("Invalid parameter");
944 return NOTI_EX_ERROR_INVALID_PARAMETER;
948 p = new (std::nothrow) InputSelectorItem(id);
950 p = new (std::nothrow) InputSelectorItem();
953 LOGE("Out-of-memory");
954 return NOTI_EX_ERROR_OUT_OF_MEMORY;
957 *handle = new Handle(shared_ptr<AbstractItem>(p));
959 return NOTI_EX_ERROR_NONE;
962 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
963 noti_ex_item_h handle, char ***contents_list, int *count) {
964 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
965 LOGE("Invalid parameter");
966 return NOTI_EX_ERROR_INVALID_PARAMETER;
969 Handle* h = static_cast<Handle*>(handle);
970 if (!h->IsValidType(AbstractItem::InputSelector)) {
971 LOGE("Invalid handle type");
972 return NOTI_EX_ERROR_INVALID_PARAMETER;
974 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
975 list<string> contents = p->GetContents();
976 char **list = (char**)calloc(contents.size(), sizeof(char*));
977 if (list == nullptr) {
978 LOGE("Out of memory");
979 return NOTI_EX_ERROR_OUT_OF_MEMORY;
983 for (auto& i : contents) {
984 list[idx] = strdup(i.c_str());
985 if (list[idx] == nullptr) {
986 __noti_ex_free_str_array(list, idx);
987 LOGE("Out of memory");
988 return NOTI_EX_ERROR_OUT_OF_MEMORY;
993 *count = contents.size();
994 *contents_list = list;
996 return NOTI_EX_ERROR_NONE;
999 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1000 noti_ex_item_h handle, const char **contents, int count) {
1001 if (handle == nullptr || contents == nullptr) {
1002 LOGE("Invalid parameter");
1003 return NOTI_EX_ERROR_INVALID_PARAMETER;
1006 list<string> new_contents;
1007 Handle* h = static_cast<Handle*>(handle);
1008 if (!h->IsValidType(AbstractItem::InputSelector)) {
1009 LOGE("Invalid handle type");
1010 return NOTI_EX_ERROR_INVALID_PARAMETER;
1012 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1013 for (int i = 0; i < count; i++) {
1014 new_contents.push_back(contents[i]);
1016 p->SetContents(move(new_contents));
1018 return NOTI_EX_ERROR_NONE;
1021 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1022 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1023 if (handle == nullptr) {
1024 LOGE("Invalid parameter");
1025 return NOTI_EX_ERROR_INVALID_PARAMETER;
1028 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1029 new (std::nothrow) Color(a, r, g, b));
1030 if (ptr == nullptr || ptr->get() == nullptr) {
1031 LOGE("Out-of-memory");
1032 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1037 return NOTI_EX_ERROR_NONE;
1040 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1041 if (handle == nullptr) {
1042 LOGE("Invalid parameter");
1043 return NOTI_EX_ERROR_INVALID_PARAMETER;
1046 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1049 return NOTI_EX_ERROR_NONE;
1052 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1053 unsigned char *val) {
1054 if (handle == nullptr || val == nullptr) {
1055 LOGE("Invalid parameter");
1056 return NOTI_EX_ERROR_INVALID_PARAMETER;
1059 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1060 *val = (*p)->GetAVal();
1062 return NOTI_EX_ERROR_NONE;
1065 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1066 unsigned char *val) {
1067 if (handle == nullptr || val == nullptr) {
1068 LOGE("Invalid parameter");
1069 return NOTI_EX_ERROR_INVALID_PARAMETER;
1072 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1073 *val = (*p)->GetRVal();
1075 return NOTI_EX_ERROR_NONE;
1078 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1079 unsigned char *val) {
1080 if (handle == nullptr || val == nullptr) {
1081 LOGE("Invalid parameter");
1082 return NOTI_EX_ERROR_INVALID_PARAMETER;
1085 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1086 *val = (*p)->GetGVal();
1088 return NOTI_EX_ERROR_NONE;
1091 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1092 unsigned char *val) {
1093 if (handle == nullptr || val == nullptr) {
1094 LOGE("Invalid parameter");
1095 return NOTI_EX_ERROR_INVALID_PARAMETER;
1098 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1099 *val = (*p)->GetBVal();
1101 return NOTI_EX_ERROR_NONE;
1104 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1105 int left, int top, int right, int bottom) {
1106 if (handle == nullptr) {
1107 LOGE("Invalid parameter");
1108 return NOTI_EX_ERROR_INVALID_PARAMETER;
1111 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1112 new (std::nothrow) Padding(left, top, right, bottom));
1113 if (ptr == nullptr || ptr->get() == nullptr) {
1114 LOGE("Out-of-memory");
1115 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1120 return NOTI_EX_ERROR_NONE;
1123 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1124 if (handle == nullptr) {
1125 LOGE("Invalid parameter");
1126 return NOTI_EX_ERROR_INVALID_PARAMETER;
1129 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1132 return NOTI_EX_ERROR_NONE;
1135 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1137 if (handle == nullptr || val == nullptr) {
1138 LOGE("Invalid parameter");
1139 return NOTI_EX_ERROR_INVALID_PARAMETER;
1142 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1143 *val = (*p)->GetLeft();
1145 return NOTI_EX_ERROR_NONE;
1148 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1150 if (handle == nullptr || val == nullptr) {
1151 LOGE("Invalid parameter");
1152 return NOTI_EX_ERROR_INVALID_PARAMETER;
1155 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1156 *val = (*p)->GetTop();
1158 return NOTI_EX_ERROR_NONE;
1161 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1163 if (handle == nullptr || val == nullptr) {
1164 LOGE("Invalid parameter");
1165 return NOTI_EX_ERROR_INVALID_PARAMETER;
1168 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1169 *val = (*p)->GetRight();
1171 return NOTI_EX_ERROR_NONE;
1174 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1176 if (handle == nullptr || val == nullptr) {
1177 LOGE("Invalid parameter");
1178 return NOTI_EX_ERROR_INVALID_PARAMETER;
1181 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1182 *val = (*p)->GetBottom();
1184 return NOTI_EX_ERROR_NONE;
1187 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1188 int x, int y, int w, int h) {
1189 if (handle == nullptr) {
1190 LOGE("Invalid parameter");
1191 return NOTI_EX_ERROR_INVALID_PARAMETER;
1194 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1195 new (std::nothrow) Geometry(x, y, w, h));
1196 if (ptr == nullptr || ptr->get() == nullptr) {
1197 LOGE("Out-of-memory");
1198 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1203 return NOTI_EX_ERROR_NONE;
1206 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1207 if (handle == nullptr) {
1208 LOGE("Invalid parameter");
1209 return NOTI_EX_ERROR_INVALID_PARAMETER;
1212 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1215 return NOTI_EX_ERROR_NONE;
1218 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1220 if (handle == nullptr || val == nullptr) {
1221 LOGE("Invalid parameter");
1222 return NOTI_EX_ERROR_INVALID_PARAMETER;
1225 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1226 *val = (*p)->GetX();
1228 return NOTI_EX_ERROR_NONE;
1231 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1233 if (handle == nullptr || val == nullptr) {
1234 LOGE("Invalid parameter");
1235 return NOTI_EX_ERROR_INVALID_PARAMETER;
1238 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1239 *val = (*p)->GetY();
1241 return NOTI_EX_ERROR_NONE;
1244 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1246 if (handle == nullptr || val == nullptr) {
1247 LOGE("Invalid parameter");
1248 return NOTI_EX_ERROR_INVALID_PARAMETER;
1251 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1252 *val = (*p)->GetWidth();
1254 return NOTI_EX_ERROR_NONE;
1257 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1259 if (handle == nullptr || val == nullptr) {
1260 LOGE("Invalid parameter");
1261 return NOTI_EX_ERROR_INVALID_PARAMETER;
1264 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1265 *val = (*p)->GetHeight();
1267 return NOTI_EX_ERROR_NONE;
1270 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1271 noti_ex_color_h color,
1272 noti_ex_padding_h padding,
1273 noti_ex_geometry_h geometry) {
1274 if (handle == nullptr) {
1275 LOGE("Invalid parameter");
1276 return NOTI_EX_ERROR_INVALID_PARAMETER;
1279 shared_ptr<Color> col = (color == nullptr) ?
1280 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1281 shared_ptr<Padding> padd = (padding == nullptr) ?
1282 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1283 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1284 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1286 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1287 new (std::nothrow) Style(col, padd, geo));
1288 if (ptr == nullptr || ptr->get() == nullptr) {
1289 LOGE("Out-of-memory");
1290 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1295 return NOTI_EX_ERROR_NONE;
1298 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1299 if (handle == nullptr) {
1300 LOGE("Invalid parameter");
1301 return NOTI_EX_ERROR_INVALID_PARAMETER;
1304 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1307 return NOTI_EX_ERROR_NONE;
1310 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1311 noti_ex_padding_h *padding) {
1312 if (handle == nullptr || padding == nullptr) {
1313 LOGE("Invalid parameter");
1314 return NOTI_EX_ERROR_INVALID_PARAMETER;
1317 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1318 if ((*p)->GetPadding() == nullptr) {
1319 LOGW("Padding info is null");
1320 return NOTI_EX_ERROR_INVALID_PARAMETER;
1323 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1324 new (std::nothrow) Padding(*((*p)->GetPadding())));
1325 if (padd == nullptr || padd->get() == nullptr) {
1326 LOGE("Out-of-memory");
1327 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1332 return NOTI_EX_ERROR_NONE;
1335 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1336 noti_ex_color_h *color) {
1337 if (handle == nullptr || color == nullptr) {
1338 LOGE("Invalid parameter");
1339 return NOTI_EX_ERROR_INVALID_PARAMETER;
1342 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1343 if ((*p)->GetColor() == nullptr) {
1344 LOGW("Color info is null");
1345 return NOTI_EX_ERROR_INVALID_PARAMETER;
1348 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1349 new (std::nothrow) Color(*((*p)->GetColor())));
1350 if (col == nullptr || col->get() == nullptr) {
1351 LOGE("Out-of-memory");
1352 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1357 return NOTI_EX_ERROR_NONE;
1360 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1361 noti_ex_geometry_h *geometry) {
1362 if (handle == nullptr || geometry == nullptr) {
1363 LOGE("Invalid parameter");
1364 return NOTI_EX_ERROR_INVALID_PARAMETER;
1367 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1368 if ((*p)->GetGeometry() == nullptr) {
1369 LOGW("Geometry info is null");
1370 return NOTI_EX_ERROR_INVALID_PARAMETER;
1373 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1374 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1375 if (geo == nullptr || geo->get() == nullptr) {
1376 LOGE("Out-of-memory");
1377 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1382 return NOTI_EX_ERROR_NONE;
1385 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1386 noti_ex_style_h handle, char** background_image) {
1387 if (handle == nullptr || background_image == nullptr) {
1388 LOGE("Invalid parameter");
1389 return NOTI_EX_ERROR_INVALID_PARAMETER;
1392 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1393 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1395 return NOTI_EX_ERROR_NONE;
1398 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1399 noti_ex_style_h handle, char* background_image) {
1400 if (handle == nullptr || background_image == nullptr) {
1401 LOGE("Invalid parameter");
1402 return NOTI_EX_ERROR_INVALID_PARAMETER;
1405 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1406 (*p)->SetBackgroundImage(background_image);
1408 return NOTI_EX_ERROR_NONE;
1411 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1412 noti_ex_style_h handle, noti_ex_color_h* color) {
1413 if (handle == nullptr || color == nullptr) {
1414 LOGE("Invalid parameter");
1415 return NOTI_EX_ERROR_INVALID_PARAMETER;
1418 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1419 if ((*p)->GetBackgroundColor() == nullptr) {
1420 LOGW("Color info is null");
1421 return NOTI_EX_ERROR_INVALID_PARAMETER;
1424 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1425 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1426 if (col == nullptr || col->get() == nullptr) {
1427 LOGE("Out-of-memory");
1428 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1433 return NOTI_EX_ERROR_NONE;
1436 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1437 noti_ex_style_h handle, noti_ex_color_h color) {
1438 if (handle == nullptr || color == nullptr) {
1439 LOGE("Invalid parameter");
1440 return NOTI_EX_ERROR_INVALID_PARAMETER;
1443 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1444 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1445 (*p)->SetBackgroundColor(*col);
1447 return NOTI_EX_ERROR_NONE;
1450 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1451 noti_ex_color_h color) {
1452 if (handle == nullptr) {
1453 LOGE("Invalid parameter");
1454 return NOTI_EX_ERROR_INVALID_PARAMETER;
1457 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1458 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1459 new (std::nothrow) LEDInfo(*color_ptr));
1461 LOGE("Out-of-memory");
1462 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1467 return NOTI_EX_ERROR_NONE;
1470 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1471 if (handle == nullptr) {
1472 LOGE("Invalid parameter");
1473 return NOTI_EX_ERROR_INVALID_PARAMETER;
1476 shared_ptr<LEDInfo>* led_ptr =
1477 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1479 return NOTI_EX_ERROR_NONE;
1482 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1483 noti_ex_led_info_h handle, int ms) {
1484 if (handle == nullptr) {
1485 LOGE("Invalid parameter");
1486 return NOTI_EX_ERROR_INVALID_PARAMETER;
1489 shared_ptr<LEDInfo>* led_ptr =
1490 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1491 (*led_ptr)->SetOnPeriod(ms);
1493 return NOTI_EX_ERROR_NONE;
1496 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1497 noti_ex_led_info_h handle, int *ms) {
1498 if (handle == nullptr || ms == nullptr) {
1499 LOGE("Invalid parameter");
1500 return NOTI_EX_ERROR_INVALID_PARAMETER;
1503 shared_ptr<LEDInfo>* led_ptr =
1504 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1505 *ms = (*led_ptr)->GetOnPeriod();
1507 return NOTI_EX_ERROR_NONE;
1510 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1511 noti_ex_led_info_h handle, int ms) {
1512 if (handle == nullptr) {
1513 LOGE("Invalid parameter");
1514 return NOTI_EX_ERROR_INVALID_PARAMETER;
1517 shared_ptr<LEDInfo>* led_ptr =
1518 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1519 (*led_ptr)->SetOffPeriod(ms);
1521 return NOTI_EX_ERROR_NONE;
1524 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1525 noti_ex_led_info_h handle, int *ms) {
1526 if (handle == nullptr) {
1527 LOGE("Invalid parameter");
1528 return NOTI_EX_ERROR_INVALID_PARAMETER;
1531 shared_ptr<LEDInfo>* led_ptr =
1532 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1533 *ms = (*led_ptr)->GetOffPeriod();
1535 return NOTI_EX_ERROR_NONE;
1538 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1539 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1540 if (handle == nullptr) {
1541 LOGE("Invalid parameter");
1542 return NOTI_EX_ERROR_INVALID_PARAMETER;
1545 shared_ptr<LEDInfo>* led_ptr =
1546 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1547 if ((*led_ptr)->GetColor() == nullptr) {
1548 LOGE("Color is null");
1549 return NOTI_EX_ERROR_INVALID_PARAMETER;
1552 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1553 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1554 if (col == nullptr || col->get() == nullptr) {
1555 LOGE("Out-of-memory");
1556 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1565 if (handle == nullptr) {
1566 LOGE("Invalid parameter");
1567 return NOTI_EX_ERROR_INVALID_PARAMETER;
1570 shared_ptr<AbstractAction>* ptr =
1571 static_cast<shared_ptr<AbstractAction>*>(handle);
1574 return NOTI_EX_ERROR_NONE;
1577 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1579 if (handle == nullptr || type == nullptr) {
1580 LOGE("Invalid parameter");
1581 return NOTI_EX_ERROR_INVALID_PARAMETER;
1584 shared_ptr<AbstractAction>* ptr =
1585 static_cast<shared_ptr<AbstractAction>*>(handle);
1586 *type = (*ptr)->GetType();
1588 return NOTI_EX_ERROR_NONE;
1591 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1593 if (handle == nullptr || local == nullptr) {
1594 LOGE("Invalid parameter");
1595 return NOTI_EX_ERROR_INVALID_PARAMETER;
1598 shared_ptr<AbstractAction>* ptr =
1599 static_cast<shared_ptr<AbstractAction>*>(handle);
1600 *local = (*ptr)->IsLocal();
1602 return NOTI_EX_ERROR_NONE;
1605 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1606 noti_ex_item_h item) {
1607 if (handle == nullptr || item == nullptr) {
1608 LOGE("Invalid parameter");
1609 return NOTI_EX_ERROR_INVALID_PARAMETER;
1611 shared_ptr<AbstractAction>* ptr =
1612 static_cast<shared_ptr<AbstractAction>*>(handle);
1613 Handle* ih = static_cast<Handle*>(item);
1614 (*ptr)->Execute(ih->GetPtr());
1616 return NOTI_EX_ERROR_NONE;
1619 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1621 if (handle == nullptr || extra == nullptr) {
1622 LOGE("Invalid parameter");
1623 return NOTI_EX_ERROR_INVALID_PARAMETER;
1626 shared_ptr<AbstractAction>* ptr =
1627 static_cast<shared_ptr<AbstractAction>*>(handle);
1628 if (!(*ptr)->GetExtra().empty()) {
1629 *extra = strdup((*ptr)->GetExtra().c_str());
1630 if (*extra == nullptr) {
1631 LOGE("Out-of-memory");
1632 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1636 return NOTI_EX_ERROR_NONE;
1639 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1640 noti_ex_item_info_h handle, int *hide_time) {
1641 if (handle == nullptr || hide_time == nullptr) {
1642 LOGE("Invalid parameter");
1643 return NOTI_EX_ERROR_INVALID_PARAMETER;
1645 IItemInfo* p = static_cast<IItemInfo*>(handle);
1646 *hide_time = p->GetHideTime();
1647 return NOTI_EX_ERROR_NONE;
1650 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1651 noti_ex_item_info_h handle, int hide_time) {
1652 if (handle == nullptr) {
1653 LOGE("Invalid parameter");
1654 return NOTI_EX_ERROR_INVALID_PARAMETER;
1656 IItemInfo* p = static_cast<IItemInfo*>(handle);
1657 p->SetHideTime(hide_time);
1658 return NOTI_EX_ERROR_NONE;
1661 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1662 noti_ex_item_info_h handle, int *delete_time) {
1663 if (handle == nullptr || delete_time == nullptr) {
1664 LOGE("Invalid parameter");
1665 return NOTI_EX_ERROR_INVALID_PARAMETER;
1667 IItemInfo* p = static_cast<IItemInfo*>(handle);
1668 *delete_time = p->GetDeleteTime();
1669 return NOTI_EX_ERROR_NONE;
1672 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1673 noti_ex_item_info_h handle, int delete_time) {
1674 if (handle == nullptr) {
1675 LOGE("Invalid parameter");
1676 return NOTI_EX_ERROR_INVALID_PARAMETER;
1678 IItemInfo* p = static_cast<IItemInfo*>(handle);
1679 p->SetDeleteTime(delete_time);
1680 return NOTI_EX_ERROR_NONE;
1683 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1684 noti_ex_item_info_h handle, time_t *time) {
1685 if (handle == nullptr || time == nullptr) {
1686 LOGE("Invalid parameter");
1687 return NOTI_EX_ERROR_INVALID_PARAMETER;
1690 IItemInfo* p = static_cast<IItemInfo*>(handle);
1691 *time = p->GetTime();
1692 return NOTI_EX_ERROR_NONE;
1695 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1696 if (handle == nullptr) {
1697 LOGE("Invalid parameter");
1698 return NOTI_EX_ERROR_INVALID_PARAMETER;
1701 Handle* h = static_cast<Handle*>(handle);
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1707 const char *id, noti_ex_item_h *item) {
1708 if (handle == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 Handle* p = static_cast<Handle*>(handle);
1714 AbstractItem& find_item = p->Get()->FindByID(string(id));
1715 *item = new Handle(&find_item);
1716 return NOTI_EX_ERROR_NONE;
1719 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1721 if (handle == nullptr || type == nullptr) {
1722 LOGE("Invalid parameter");
1723 return NOTI_EX_ERROR_INVALID_PARAMETER;
1726 Handle* h = static_cast<Handle*>(handle);
1727 AbstractItem* p = h->Get();
1728 *type = p->GetType();
1729 return NOTI_EX_ERROR_NONE;
1732 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1733 char ***path, int *count) {
1734 if (handle == nullptr || path == nullptr || count == nullptr) {
1735 LOGE("Invalid parameter");
1736 return NOTI_EX_ERROR_INVALID_PARAMETER;
1738 Handle* p = static_cast<Handle*>(handle);
1739 list<string> shared_path = p->Get()->GetSharedPath();
1740 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1741 if (tmp_path == nullptr) {
1742 LOGE("Fail to create items");
1743 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1747 for (auto& i : shared_path) {
1748 tmp_path[idx] = strdup(i.c_str());
1749 if (tmp_path[idx] == nullptr) {
1750 __noti_ex_free_str_array(tmp_path, idx);
1751 LOGE("Out of memory");
1752 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1758 *count = shared_path.size();
1759 return NOTI_EX_ERROR_NONE;
1762 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1764 if (handle == nullptr || id == nullptr) {
1765 LOGE("Invalid parameter");
1766 return NOTI_EX_ERROR_INVALID_PARAMETER;
1768 Handle* h = static_cast<Handle*>(handle);
1769 AbstractItem* p = h->Get();
1770 *id = strdup(p->GetId().c_str());
1771 return NOTI_EX_ERROR_NONE;
1774 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1776 if (handle == nullptr || id == nullptr) {
1777 LOGE("Invalid parameter");
1778 return NOTI_EX_ERROR_INVALID_PARAMETER;
1780 Handle* p = static_cast<Handle*>(handle);
1781 p->Get()->SetId(id);
1782 return NOTI_EX_ERROR_NONE;
1785 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1786 noti_ex_action_h *action) {
1787 if (handle == nullptr || action == nullptr) {
1788 LOGE("Invalid parameter");
1789 return NOTI_EX_ERROR_INVALID_PARAMETER;
1791 Handle* p = static_cast<Handle*>(handle);
1792 if (p->Get()->GetAction() == nullptr) {
1794 return NOTI_EX_ERROR_NONE;
1796 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1797 p->Get()->GetAction()));
1799 return NOTI_EX_ERROR_NONE;
1802 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1803 noti_ex_action_h action) {
1804 if (handle == nullptr || action == nullptr) {
1805 LOGE("Invalid parameter");
1806 return NOTI_EX_ERROR_INVALID_PARAMETER;
1809 Handle* p = static_cast<Handle*>(handle);
1811 shared_ptr<AbstractAction>* ptr =
1812 static_cast<shared_ptr<AbstractAction>*>(action);
1813 p->Get()->SetAction(*ptr);
1814 return NOTI_EX_ERROR_NONE;
1817 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1818 noti_ex_style_h *style) {
1819 if (handle == nullptr || style == nullptr) {
1820 LOGE("Invalid parameter");
1821 return NOTI_EX_ERROR_INVALID_PARAMETER;
1824 Handle* p = static_cast<Handle*>(handle);
1825 shared_ptr<Style> s = p->Get()->GetStyle();
1826 if (s.get() == nullptr) {
1827 LOGE("Style is null");
1828 return NOTI_EX_ERROR_INVALID_PARAMETER;
1831 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1832 if (ptr == nullptr || ptr->get() == nullptr) {
1833 LOGE("Out of memory");
1834 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1838 return NOTI_EX_ERROR_NONE;
1841 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1842 noti_ex_style_h style) {
1843 if (handle == nullptr || style == nullptr) {
1844 LOGE("Invalid parameter");
1845 return NOTI_EX_ERROR_INVALID_PARAMETER;
1848 Handle* p = static_cast<Handle*>(handle);
1849 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1850 p->Get()->SetStyle(*s);
1851 return NOTI_EX_ERROR_NONE;
1854 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1856 if (handle == nullptr) {
1857 LOGE("Invalid parameter");
1858 return NOTI_EX_ERROR_INVALID_PARAMETER;
1861 Handle* p = static_cast<Handle*>(handle);
1862 p->Get()->SetVisible(visible);
1863 return NOTI_EX_ERROR_NONE;
1866 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1868 if (handle == nullptr || visible == nullptr) {
1869 LOGE("Invalid parameter");
1870 return NOTI_EX_ERROR_INVALID_PARAMETER;
1873 Handle* p = static_cast<Handle*>(handle);
1874 *visible = p->Get()->GetVisible();
1875 return NOTI_EX_ERROR_NONE;
1878 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1880 if (handle == nullptr) {
1881 LOGE("Invalid parameter");
1882 return NOTI_EX_ERROR_INVALID_PARAMETER;
1885 Handle* p = static_cast<Handle*>(handle);
1886 p->Get()->SetEnable(enable);
1887 return NOTI_EX_ERROR_NONE;
1890 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1892 if (handle == nullptr || enable == nullptr) {
1893 LOGE("Invalid parameter");
1894 return NOTI_EX_ERROR_INVALID_PARAMETER;
1897 Handle* p = static_cast<Handle*>(handle);
1898 *enable = p->Get()->GetEnable();
1899 return NOTI_EX_ERROR_NONE;
1902 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1903 const char *receiver_group) {
1904 if (handle == nullptr || receiver_group == nullptr) {
1905 LOGE("Invalid parameter");
1906 return NOTI_EX_ERROR_INVALID_PARAMETER;
1909 Handle* p = static_cast<Handle*>(handle);
1910 p->Get()->AddReceiver(receiver_group);
1911 return NOTI_EX_ERROR_NONE;
1914 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1915 const char *receiver_group) {
1916 if (handle == nullptr || receiver_group == nullptr) {
1917 LOGE("Invalid parameter");
1918 return NOTI_EX_ERROR_INVALID_PARAMETER;
1921 Handle* p = static_cast<Handle*>(handle);
1922 p->Get()->RemoveReceiver(receiver_group);
1923 return NOTI_EX_ERROR_NONE;
1926 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1927 char ***receiver_list, int *count) {
1928 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1929 LOGE("Invalid parameter");
1930 return NOTI_EX_ERROR_INVALID_PARAMETER;
1933 Handle* p = static_cast<Handle*>(handle);
1934 list<string> receivers = p->Get()->GetReceiverList();
1935 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
1936 if (tmp_list == nullptr) {
1937 LOGE("Out of memory");
1938 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1942 for (auto& i : receivers) {
1943 tmp_list[idx] = strdup(i.c_str());
1944 if (tmp_list[idx] == nullptr) {
1945 __noti_ex_free_str_array(tmp_list, idx);
1946 LOGE("Out of memory");
1947 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1952 *receiver_list = tmp_list;
1953 *count = receivers.size();
1954 return NOTI_EX_ERROR_NONE;
1957 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1959 if (handle == nullptr) {
1960 LOGE("Invalid parameter");
1961 return NOTI_EX_ERROR_INVALID_PARAMETER;
1964 Handle* p = static_cast<Handle*>(handle);
1965 p->Get()->SetPolicy(policy);
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1971 if (handle == nullptr || policy == nullptr) {
1972 LOGE("Invalid parameter");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1976 Handle* p = static_cast<Handle*>(handle);
1977 *policy = p->Get()->GetPolicy();
1978 return NOTI_EX_ERROR_NONE;
1981 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1983 if (handle == nullptr || channel == nullptr) {
1984 LOGE("Invalid parameter");
1985 return NOTI_EX_ERROR_INVALID_PARAMETER;
1988 Handle* p = static_cast<Handle*>(handle);
1989 if (!p->Get()->GetChannel().empty())
1990 *channel = strdup(p->Get()->GetChannel().c_str());
1994 return NOTI_EX_ERROR_NONE;
1997 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1998 const char *channel) {
1999 if (handle == nullptr) {
2000 LOGE("Invalid parameter");
2001 return NOTI_EX_ERROR_INVALID_PARAMETER;
2004 Handle* p = static_cast<Handle*>(handle);
2005 p->Get()->SetChannel(channel);
2006 return NOTI_EX_ERROR_NONE;
2009 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2010 noti_ex_led_info_h led) {
2011 if (handle == nullptr) {
2012 LOGE("Invalid parameter");
2013 return NOTI_EX_ERROR_INVALID_PARAMETER;
2016 Handle* p = static_cast<Handle*>(handle);
2017 shared_ptr<LEDInfo>* led_ptr =
2018 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2019 p->Get()->SetLEDInfo(*led_ptr);
2020 return NOTI_EX_ERROR_NONE;
2023 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2024 noti_ex_led_info_h *led) {
2025 if (handle == nullptr) {
2026 LOGE("Invalid parameter");
2027 return NOTI_EX_ERROR_INVALID_PARAMETER;
2030 Handle* p = static_cast<Handle*>(handle);
2031 if (p->Get()->GetLEDInfo() != nullptr)
2032 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2035 return NOTI_EX_ERROR_NONE;
2038 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2040 if (handle == nullptr) {
2041 LOGE("Invalid parameter");
2042 return NOTI_EX_ERROR_INVALID_PARAMETER;
2045 Handle* p = static_cast<Handle*>(handle);
2046 if (path == nullptr)
2047 p->Get()->SetSoundPath("");
2049 p->Get()->SetSoundPath(path);
2050 return NOTI_EX_ERROR_NONE;
2053 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2055 if (handle == nullptr) {
2056 LOGE("Invalid parameter");
2057 return NOTI_EX_ERROR_INVALID_PARAMETER;
2060 Handle* p = static_cast<Handle*>(handle);
2061 if (path == nullptr)
2062 p->Get()->SetVibrationPath("");
2064 p->Get()->SetVibrationPath(path);
2065 return NOTI_EX_ERROR_NONE;
2068 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2070 if (handle == nullptr || path == nullptr) {
2071 LOGE("Invalid parameter");
2072 return NOTI_EX_ERROR_INVALID_PARAMETER;
2075 Handle* p = static_cast<Handle*>(handle);
2076 if (p->Get()->GetSoundPath().empty())
2079 *path = strdup(p->Get()->GetSoundPath().c_str());
2080 return NOTI_EX_ERROR_NONE;
2083 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2085 if (handle == nullptr || path == nullptr) {
2086 LOGE("Invalid parameter");
2087 return NOTI_EX_ERROR_INVALID_PARAMETER;
2090 Handle* p = static_cast<Handle*>(handle);
2091 if (p->Get()->GetVibrationPath().empty())
2094 *path = strdup(p->Get()->GetVibrationPath().c_str());
2095 return NOTI_EX_ERROR_NONE;
2098 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2099 noti_ex_item_info_h *info) {
2100 if (handle == nullptr || info == nullptr) {
2101 LOGE("Invalid parameter");
2102 return NOTI_EX_ERROR_INVALID_PARAMETER;
2105 Handle* p = static_cast<Handle*>(handle);
2106 if (p->Get()->GetInfo() == nullptr)
2109 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2110 return NOTI_EX_ERROR_NONE;
2113 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2115 if (handle == nullptr || id == nullptr) {
2116 LOGE("Invalid parameter");
2117 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 Handle* p = static_cast<Handle*>(handle);
2121 if (p->Get()->GetSenderAppId().empty())
2124 *id = strdup(p->Get()->GetSenderAppId().c_str());
2125 return NOTI_EX_ERROR_NONE;
2128 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2130 if (handle == nullptr || tag == nullptr) {
2131 LOGE("Invalid parameter");
2132 return NOTI_EX_ERROR_INVALID_PARAMETER;
2135 Handle* p = static_cast<Handle*>(handle);
2136 if (p->Get()->GetTag().empty())
2139 *tag = strdup(p->Get()->GetTag().c_str());
2140 return NOTI_EX_ERROR_NONE;
2143 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2145 if (handle == nullptr) {
2146 LOGE("Invalid parameter");
2147 return NOTI_EX_ERROR_INVALID_PARAMETER;
2150 Handle* p = static_cast<Handle*>(handle);
2152 p->Get()->SetTag("");
2154 p->Get()->SetTag(tag);
2155 return NOTI_EX_ERROR_NONE;
2158 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2160 if (handle == nullptr || ongoing == nullptr) {
2161 LOGE("Invalid parameter");
2162 return NOTI_EX_ERROR_INVALID_PARAMETER;
2165 Handle* p = static_cast<Handle*>(handle);
2166 *ongoing = p->Get()->GetOnGoingState();
2168 return NOTI_EX_ERROR_NONE;
2171 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2173 if (handle == nullptr) {
2174 LOGE("Invalid parameter");
2175 return NOTI_EX_ERROR_INVALID_PARAMETER;
2178 Handle* p = static_cast<Handle*>(handle);
2179 p->Get()->SetOnGoingState(ongoing);
2181 return NOTI_EX_ERROR_NONE;
2184 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2185 int type, bool* exist) {
2186 if (handle == nullptr || exist == nullptr) {
2187 LOGE("Invalid parameter");
2188 return NOTI_EX_ERROR_INVALID_PARAMETER;
2191 Handle* p = static_cast<Handle*>(handle);
2192 *exist = p->Get()->IsItemTypeExist(type);
2194 return NOTI_EX_ERROR_NONE;
2197 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2199 if (handle == nullptr || type == nullptr) {
2200 LOGE("Invalid parameter");
2201 return NOTI_EX_ERROR_INVALID_PARAMETER;
2204 Handle* p = static_cast<Handle*>(handle);
2205 *type = p->Get()->GetMainType();
2207 return NOTI_EX_ERROR_NONE;
2210 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2211 const char* id, int type) {
2212 if (handle == nullptr || id == nullptr) {
2213 LOGE("Invalid parameter");
2214 return NOTI_EX_ERROR_INVALID_PARAMETER;
2217 Handle* p = static_cast<Handle*>(handle);
2218 if (!(p->Get()->SetMainType(string(id),
2219 static_cast<AbstractItem::MainType>(type))))
2220 return NOTI_EX_ERROR_INVALID_PARAMETER;
2222 return NOTI_EX_ERROR_NONE;
2225 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2226 int type, noti_ex_item_h* item) {
2227 if (handle == nullptr || item == nullptr) {
2228 LOGE("Invalid parameter");
2229 return NOTI_EX_ERROR_INVALID_PARAMETER;
2232 Handle* h = static_cast<Handle*>(handle);
2233 if (!h->IsValidType(AbstractItem::Group)) {
2234 LOGE("Invalid handle type");
2235 return NOTI_EX_ERROR_INVALID_PARAMETER;
2238 GroupItem* p = static_cast<GroupItem*>(h->Get());
2239 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2240 *item = new Handle(&find_item);
2242 return NOTI_EX_ERROR_NONE;
2245 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2246 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2248 if (handle == nullptr) {
2249 LOGE("Invalid parameter");
2250 return NOTI_EX_ERROR_INVALID_PARAMETER;
2253 string receiver_group_str = "";
2255 receiver_group_str = string(receiver_group);
2257 ManagerStub* stub = new (std::nothrow) ManagerStub(
2258 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2259 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2260 receiver_group_str);
2261 if (stub == nullptr) {
2262 LOGE("Fail to create manager");
2263 return NOTI_EX_ERROR_IO_ERROR;
2265 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2266 new ManagerCallbackInfo(event_callbacks, data)));
2267 *handle = static_cast<noti_ex_manager_h>(stub);
2269 return NOTI_EX_ERROR_NONE;
2272 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2273 if (handle == nullptr) {
2274 LOGE("Invalid parameter");
2275 return NOTI_EX_ERROR_INVALID_PARAMETER;
2277 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2279 return NOTI_EX_ERROR_NONE;
2282 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2283 noti_ex_item_h **items, int *count) {
2284 if (handle == nullptr || items == nullptr || count == nullptr) {
2285 LOGE("Invalid parameter");
2286 return NOTI_EX_ERROR_INVALID_PARAMETER;
2290 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2291 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2292 if (item_list.size() == 0) {
2295 return NOTI_EX_ERROR_NONE;
2297 noti_ex_item_h* added_item =
2298 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2299 if (added_item == nullptr) {
2300 LOGE("Fail to create items");
2301 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2305 for (auto& i : item_list) {
2306 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2308 *items = added_item;
2309 *count = item_list.size();
2310 } catch (Exception &ex) {
2311 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2312 return NOTI_EX_ERROR_IO_ERROR;
2314 return NOTI_EX_ERROR_NONE;
2317 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2318 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2319 if (handle == nullptr || channel == nullptr ||
2320 items == nullptr || count == nullptr) {
2321 LOGE("Invalid parameter");
2322 return NOTI_EX_ERROR_INVALID_PARAMETER;
2326 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2327 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2328 if (item_list.size() == 0) {
2331 return NOTI_EX_ERROR_NONE;
2333 noti_ex_item_h* added_item =
2334 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2335 if (added_item == nullptr) {
2336 LOGE("Fail to create items");
2337 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2341 for (auto& i : item_list) {
2342 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2344 *items = added_item;
2345 *count = item_list.size();
2346 } catch (Exception &ex) {
2347 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2348 return NOTI_EX_ERROR_IO_ERROR;
2351 return NOTI_EX_ERROR_NONE;
2354 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2355 noti_ex_item_h noti, int *request_id) {
2356 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2357 LOGE("Invalid parameter");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2361 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2362 Handle* sp = static_cast<Handle*>(noti);
2363 if (sp->GetPtr().get() == nullptr) {
2364 LOGE("Invalid noti reference can not be sended");
2365 return NOTI_EX_ERROR_INVALID_PARAMETER;
2367 *request_id = stub->Update(sp->GetPtr());
2369 } catch (Exception &ex) {
2370 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2371 return NOTI_EX_ERROR_IO_ERROR;
2373 return NOTI_EX_ERROR_NONE;
2376 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2377 noti_ex_item_h noti, int *request_id) {
2378 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2379 LOGE("Invalid parameter");
2380 return NOTI_EX_ERROR_INVALID_PARAMETER;
2383 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2384 Handle* item = static_cast<Handle*>(noti);
2385 if (item->GetPtr().get() == nullptr) {
2386 LOGE("Invalid noti reference can not be sended");
2387 return NOTI_EX_ERROR_INVALID_PARAMETER;
2389 *request_id = stub->Delete(item->GetPtr());
2391 } catch (Exception &ex) {
2392 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2393 return NOTI_EX_ERROR_IO_ERROR;
2395 return NOTI_EX_ERROR_NONE;
2398 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2400 if (handle == nullptr || request_id == nullptr) {
2401 LOGE("Invalid parameter");
2402 return NOTI_EX_ERROR_INVALID_PARAMETER;
2405 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2406 *request_id = stub->DeleteAll();
2407 } catch (Exception &ex) {
2408 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2409 return NOTI_EX_ERROR_IO_ERROR;
2411 return NOTI_EX_ERROR_NONE;
2414 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2415 noti_ex_item_h noti, int *request_id) {
2416 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2417 LOGE("Invalid parameter");
2418 return NOTI_EX_ERROR_INVALID_PARAMETER;
2421 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2422 Handle* item = static_cast<Handle*>(noti);
2423 if (item->GetPtr().get() == nullptr) {
2424 LOGE("Invalid noti reference can not be sended");
2425 return NOTI_EX_ERROR_INVALID_PARAMETER;
2427 *request_id = stub->Hide(item->GetPtr());
2429 } catch (Exception &ex) {
2430 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2431 return NOTI_EX_ERROR_IO_ERROR;
2433 return NOTI_EX_ERROR_NONE;
2436 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2437 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2438 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2439 LOGE("Invalid parameter");
2440 return NOTI_EX_ERROR_INVALID_PARAMETER;
2443 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2444 *item = new Handle(stub->FindByRootID(root_id));
2445 } catch (Exception &ex) {
2446 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2447 return NOTI_EX_ERROR_IO_ERROR;
2449 return NOTI_EX_ERROR_NONE;
2452 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2453 noti_ex_event_info_h info, noti_ex_error_e error) {
2454 if (handle == nullptr || info == nullptr) {
2455 LOGE("Invalid parameter");
2456 return NOTI_EX_ERROR_INVALID_PARAMETER;
2459 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2460 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2461 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2462 static_cast<NotificationError>(error));
2463 } catch (Exception &ex) {
2464 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2465 return NOTI_EX_ERROR_IO_ERROR;
2467 return NOTI_EX_ERROR_NONE;
2470 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2471 noti_ex_manager_h handle, int *cnt) {
2473 if (handle == nullptr || cnt == nullptr) {
2474 LOGE("Invalid parameter");
2475 return NOTI_EX_ERROR_INVALID_PARAMETER;
2478 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2479 *cnt = stub->GetCount();
2480 } catch (Exception &ex) {
2481 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2482 return NOTI_EX_ERROR_IO_ERROR;
2484 return NOTI_EX_ERROR_NONE;
2487 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2488 const char *id, float min, float current, float max) {
2491 if (handle == nullptr) {
2492 LOGE("Invalid parameter");
2493 return NOTI_EX_ERROR_INVALID_PARAMETER;
2497 p = new (std::nothrow) ProgressItem(id, min, current, max);
2499 p = new (std::nothrow) ProgressItem(min, current, max);
2502 LOGE("Out-of-memory");
2503 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2506 *handle = new Handle(shared_ptr<AbstractItem>(p));
2508 return NOTI_EX_ERROR_NONE;
2511 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2512 noti_ex_item_h handle, float *current) {
2513 if (handle == nullptr || current == nullptr) {
2514 LOGE("Invalid parameter");
2515 return NOTI_EX_ERROR_INVALID_PARAMETER;
2518 Handle *h = static_cast<Handle*>(handle);
2519 if (!h->IsValidType(AbstractItem::Progress)) {
2520 LOGE("Invalid handle type");
2521 return NOTI_EX_ERROR_INVALID_PARAMETER;
2523 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2524 *current = p->GetCurrent();
2526 return NOTI_EX_ERROR_NONE;
2529 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2530 noti_ex_item_h handle, float current) {
2531 if (handle == nullptr) {
2532 LOGE("Invalid parameter");
2533 return NOTI_EX_ERROR_INVALID_PARAMETER;
2536 Handle *h = static_cast<Handle*>(handle);
2537 if (!h->IsValidType(AbstractItem::Progress)) {
2538 LOGE("Invalid handle type");
2539 return NOTI_EX_ERROR_INVALID_PARAMETER;
2541 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2542 p->SetCurrent(current);
2544 return NOTI_EX_ERROR_NONE;
2547 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2549 if (handle == nullptr || min == nullptr) {
2550 LOGE("Invalid parameter");
2551 return NOTI_EX_ERROR_INVALID_PARAMETER;
2554 Handle *h = static_cast<Handle*>(handle);
2555 if (!h->IsValidType(AbstractItem::Progress)) {
2556 LOGE("Invalid handle type");
2557 return NOTI_EX_ERROR_INVALID_PARAMETER;
2559 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2562 return NOTI_EX_ERROR_NONE;
2565 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2567 if (handle == nullptr || max == nullptr) {
2568 LOGE("Invalid parameter");
2569 return NOTI_EX_ERROR_INVALID_PARAMETER;
2572 Handle *h = static_cast<Handle*>(handle);
2573 if (!h->IsValidType(AbstractItem::Progress)) {
2574 LOGE("Invalid handle type");
2575 return NOTI_EX_ERROR_INVALID_PARAMETER;
2577 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2580 return NOTI_EX_ERROR_NONE;
2583 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2585 if (handle == nullptr || type == nullptr) {
2586 LOGE("Invalid parameter");
2587 return NOTI_EX_ERROR_INVALID_PARAMETER;
2590 Handle *h = static_cast<Handle*>(handle);
2591 if (!h->IsValidType(AbstractItem::Progress)) {
2592 LOGE("Invalid handle type");
2593 return NOTI_EX_ERROR_INVALID_PARAMETER;
2595 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2596 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2598 return NOTI_EX_ERROR_NONE;
2601 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2603 if (handle == nullptr) {
2604 LOGE("Invalid parameter");
2605 return NOTI_EX_ERROR_INVALID_PARAMETER;
2608 Handle *h = static_cast<Handle*>(handle);
2609 if (!h->IsValidType(AbstractItem::Progress)) {
2610 LOGE("Invalid handle type");
2611 return NOTI_EX_ERROR_INVALID_PARAMETER;
2613 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2614 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2616 return NOTI_EX_ERROR_NONE;
2619 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2620 noti_ex_reporter_events_s event_callbacks, void *data) {
2621 if (handle == nullptr) {
2622 LOGE("Invalid parameter");
2623 return NOTI_EX_ERROR_INVALID_PARAMETER;
2626 ReporterStub* stub = new (std::nothrow) ReporterStub(
2627 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2628 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2629 if (stub == nullptr) {
2630 LOGE("Fail to create manager");
2631 return NOTI_EX_ERROR_IO_ERROR;
2633 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2634 new ReporterCallbackInfo(event_callbacks, data)));
2636 *handle = static_cast<noti_ex_reporter_h>(stub);
2638 return NOTI_EX_ERROR_NONE;
2641 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2642 if (handle == nullptr) {
2643 LOGE("Invalid parameter");
2644 return NOTI_EX_ERROR_INVALID_PARAMETER;
2646 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2648 return NOTI_EX_ERROR_NONE;
2651 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2652 noti_ex_event_info_h info, noti_ex_error_e error) {
2653 if (handle == nullptr || info == nullptr) {
2654 LOGE("Invalid parameter");
2655 return NOTI_EX_ERROR_INVALID_PARAMETER;
2658 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2659 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2660 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2661 static_cast<NotificationError>(error));
2662 } catch (Exception &ex) {
2663 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2664 return NOTI_EX_ERROR_IO_ERROR;
2666 return NOTI_EX_ERROR_NONE;
2669 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2670 noti_ex_item_h noti, int *request_id) {
2671 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2672 LOGE("Invalid parameter");
2673 return NOTI_EX_ERROR_INVALID_PARAMETER;
2676 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2677 Handle* h = static_cast<Handle*>(noti);
2678 if (h->GetPtr().get() == nullptr) {
2679 LOGE("Invalid noti reference can not be sended");
2680 return NOTI_EX_ERROR_INVALID_PARAMETER;
2682 *request_id = stub->Post(h->GetPtr());
2684 } catch (Exception &ex) {
2685 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2686 return NOTI_EX_ERROR_IO_ERROR;
2688 return NOTI_EX_ERROR_NONE;
2691 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2692 noti_ex_item_h *noti_list, int count, int *request_id) {
2694 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2695 LOGE("Invalid parameter");
2696 return NOTI_EX_ERROR_INVALID_PARAMETER;
2699 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2700 list<shared_ptr<item::AbstractItem>> notiList;
2701 for (int i = 0; i < count; i++) {
2702 Handle* item = static_cast<Handle*>(noti_list[i]);
2703 notiList.push_back(item->GetPtr());
2705 *request_id = stub->Post(notiList);
2706 } catch (Exception &ex) {
2707 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2708 return NOTI_EX_ERROR_IO_ERROR;
2710 return NOTI_EX_ERROR_NONE;
2713 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2714 noti_ex_item_h noti, int *request_id) {
2715 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2716 LOGE("Invalid parameter");
2717 return NOTI_EX_ERROR_INVALID_PARAMETER;
2720 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2721 Handle* item = static_cast<Handle*>(noti);
2722 if (item->GetPtr().get() == nullptr) {
2723 LOGE("Invalid noti reference can not be sended");
2724 return NOTI_EX_ERROR_INVALID_PARAMETER;
2726 *request_id = stub->Update(item->GetPtr());
2728 } catch (Exception &ex) {
2729 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2730 return NOTI_EX_ERROR_IO_ERROR;
2732 return NOTI_EX_ERROR_NONE;
2735 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2736 noti_ex_item_h noti, int *request_id) {
2737 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2738 LOGE("Invalid parameter");
2739 return NOTI_EX_ERROR_INVALID_PARAMETER;
2742 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2743 Handle* item = static_cast<Handle*>(noti);
2744 if (item->GetPtr().get() == nullptr) {
2745 LOGE("Invalid noti reference can not be sended");
2746 return NOTI_EX_ERROR_INVALID_PARAMETER;
2748 *request_id = stub->Delete(item->GetPtr());
2750 } catch (Exception &ex) {
2751 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2752 return NOTI_EX_ERROR_IO_ERROR;
2754 return NOTI_EX_ERROR_NONE;
2757 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2758 noti_ex_reporter_h handle, int *request_id) {
2759 if (handle == nullptr || request_id == nullptr) {
2760 LOGE("Invalid parameter");
2761 return NOTI_EX_ERROR_INVALID_PARAMETER;
2764 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2765 *request_id = stub->DeleteAll();
2766 } catch (Exception &ex) {
2767 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2768 return NOTI_EX_ERROR_IO_ERROR;
2770 return NOTI_EX_ERROR_NONE;
2773 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2774 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2775 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2776 LOGE("Invalid parameter");
2777 return NOTI_EX_ERROR_INVALID_PARAMETER;
2780 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2781 *item = new Handle(stub->FindByRootID(root_id));
2782 } catch (Exception &ex) {
2783 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2784 return NOTI_EX_ERROR_IO_ERROR;
2786 return NOTI_EX_ERROR_NONE;
2789 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2790 const char *id, const char *text, const char *hyperlink) {
2791 if (handle == nullptr || text == nullptr) {
2792 LOGE("Invalid parameter");
2793 return NOTI_EX_ERROR_INVALID_PARAMETER;
2799 p = new (std::nothrow) TextItem(id, std::string(text),
2800 std::string(hyperlink));
2802 p = new (std::nothrow) TextItem(id, std::string(text));
2805 LOGE("Out-of-memory");
2806 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2809 *handle = new Handle(shared_ptr<AbstractItem>(p));
2811 return NOTI_EX_ERROR_NONE;
2814 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2815 const char *contents) {
2816 if (handle == nullptr || contents == nullptr) {
2817 LOGE("Invalid parameter");
2818 return NOTI_EX_ERROR_INVALID_PARAMETER;
2821 Handle* p = static_cast<Handle*>(handle);
2822 if (!p->IsValidType(AbstractItem::Text)) {
2823 LOGE("Invalid handle type");
2824 return NOTI_EX_ERROR_INVALID_PARAMETER;
2826 TextItem* ti = static_cast<TextItem*>(p->Get());
2827 ti->SetContents(std::string(contents));
2829 return NOTI_EX_ERROR_NONE;
2832 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2834 if (handle == nullptr || contents == nullptr) {
2835 LOGE("Invalid parameter");
2836 return NOTI_EX_ERROR_INVALID_PARAMETER;
2839 Handle* p = static_cast<Handle*>(handle);
2840 if (!p->IsValidType(AbstractItem::Text)) {
2841 LOGE("Invalid handle type");
2842 return NOTI_EX_ERROR_INVALID_PARAMETER;
2844 TextItem* ti = static_cast<TextItem*>(p->Get());
2845 if (!ti->GetContents().empty()) {
2846 *contents = strdup(ti->GetContents().c_str());
2847 if (*contents == nullptr) {
2848 LOGE("Out-of-memory");
2849 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2853 return NOTI_EX_ERROR_NONE;
2856 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2857 noti_ex_item_h handle, char **hyper_link) {
2858 if (handle == nullptr || hyper_link == nullptr) {
2859 LOGE("Invalid parameter");
2860 return NOTI_EX_ERROR_INVALID_PARAMETER;
2863 Handle* p = static_cast<Handle*>(handle);
2864 if (!p->IsValidType(AbstractItem::Text)) {
2865 LOGE("Invalid handle type");
2866 return NOTI_EX_ERROR_INVALID_PARAMETER;
2868 TextItem* ti = static_cast<TextItem*>(p->Get());
2869 if (!ti->GetHyperLink().empty()) {
2870 *hyper_link = strdup(ti->GetHyperLink().c_str());
2871 if (*hyper_link == nullptr) {
2872 LOGE("Out-of-memory");
2873 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2877 return NOTI_EX_ERROR_NONE;
2880 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2881 const char *id, time_t time) {
2884 if (handle == nullptr) {
2885 LOGE("Invalid parameter");
2886 return NOTI_EX_ERROR_INVALID_PARAMETER;
2891 p = new (std::nothrow) TimeItem(id, time);
2893 p = new (std::nothrow) TimeItem(time);
2895 p = new (std::nothrow) TimeItem();
2899 LOGE("Out-of-memory");
2900 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2903 *handle = new Handle(shared_ptr<AbstractItem>(p));
2905 return NOTI_EX_ERROR_NONE;
2908 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2910 if (handle == nullptr || time == nullptr) {
2911 LOGE("Invalid parameter");
2912 return NOTI_EX_ERROR_INVALID_PARAMETER;
2914 Handle* h = static_cast<Handle*>(handle);
2915 if (!h->IsValidType(AbstractItem::Time)) {
2916 LOGE("Invalid handle type");
2917 return NOTI_EX_ERROR_INVALID_PARAMETER;
2919 TimeItem* p = static_cast<TimeItem*>(h->Get());
2920 *time = p->GetTime();
2922 return NOTI_EX_ERROR_NONE;
2925 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2926 noti_ex_action_h *handle, const char *extra) {
2927 if (handle == nullptr) {
2928 LOGE("Invalid parameter");
2929 return NOTI_EX_ERROR_INVALID_PARAMETER;
2932 string extra_str = "";
2934 extra_str = string(extra);
2936 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
2937 new (std::nothrow) VisibilityAction(extra_str));
2938 if (ptr == nullptr) {
2939 LOGE("Out-of-memory");
2940 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2945 return NOTI_EX_ERROR_NONE;
2948 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2949 const char *id, bool visible) {
2950 if (handle == nullptr || id == nullptr) {
2951 LOGE("Invalid parameter");
2952 return NOTI_EX_ERROR_INVALID_PARAMETER;
2955 shared_ptr<AbstractAction>* ptr =
2956 static_cast<shared_ptr<AbstractAction>*>(handle);
2957 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
2958 action->SetVisibility(id, visible);
2960 return NOTI_EX_ERROR_NONE;