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.
25 #include "api/notification_ex_app_control_action.h"
26 #include "api/notification_ex_button.h"
27 #include "api/notification_ex_chat_message.h"
28 #include "api/notification_ex_checkbox.h"
29 #include "api/notification_ex_entry.h"
30 #include "api/notification_ex_event_info.h"
31 #include "api/notification_ex_group.h"
32 #include "api/notification_ex_image.h"
33 #include "api/notification_ex_input_selector.h"
34 #include "api/notification_ex_item.h"
35 #include "api/notification_ex_manager.h"
36 #include "api/notification_ex_progress.h"
37 #include "api/notification_ex_reporter.h"
38 #include "api/notification_ex_text.h"
39 #include "api/notification_ex_time.h"
40 #include "api/notification_ex_visibility_action.h"
41 #include "api/notification_ex_visibility_action.h"
42 #include "api/notification_ex_internal.h"
43 #include "notification-ex/reporter.h"
44 #include "notification-ex/app_control_action.h"
45 #include "notification-ex/button_item.h"
46 #include "notification-ex/chat_message_item.h"
47 #include "notification-ex/checkbox_item.h"
48 #include "notification-ex/entry_item.h"
49 #include "notification-ex/group_item.h"
50 #include "notification-ex/input_selector_item.h"
51 #include "notification-ex/abstract_item.h"
52 #include "notification-ex/progress_item.h"
53 #include "notification-ex/time_item.h"
54 #include "notification-ex/visibility_action.h"
55 #include "notification-ex/event_info_internal.h"
56 #include "notification-ex/manager.h"
57 #include "notification-ex/dbus_sender.h"
58 #include "notification-ex/dbus_event_listener.h"
59 #include "notification-ex/exception.h"
60 #include "notification-ex/iitem_info_internal.h"
65 #define LOG_TAG "NOTIFICATION_EX"
70 #define EXPORT_API __attribute__((visibility("default")))
73 using namespace tizen_base;
74 using namespace notification::item;
75 using namespace notification;
81 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
82 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
83 : ref_(nullptr), ptr_(move(ptr)) { }
84 virtual ~Handle() = default;
85 item::AbstractItem* Get() const {
91 bool IsValidType(int type) const {
92 return (Get()->GetType() == type
93 || Get()->GetType() >= AbstractItem::Custom);
96 std::shared_ptr<item::AbstractItem> GetPtr() const {
98 return std::shared_ptr<item::AbstractItem>({});
103 item::AbstractItem* ref_;
104 std::shared_ptr<item::AbstractItem> ptr_;
107 class ManagerCallbackInfo {
109 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
110 : user_data_(user_data) {
111 cb_.added = cb.added;
112 cb_.updated = cb.updated;
113 cb_.deleted = cb.deleted;
114 cb_.error = cb.error;
117 void InvokeAdded(Manager* manager, const IEventInfo& info,
118 list<shared_ptr<AbstractItem>> addedItem) {
119 if (cb_.added == nullptr)
121 noti_ex_item_h* added_item =
122 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
123 if (added_item == nullptr) {
124 LOGE("Out of memory");
129 for (auto& i : addedItem) {
131 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
134 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
135 cb_.added(static_cast<noti_ex_manager_h>(manager),
136 static_cast<noti_ex_event_info_h>(c_info), added_item,
137 addedItem.size(), user_data_);
140 void InvokeUpdated(Manager* manager, const IEventInfo& info,
141 shared_ptr<item::AbstractItem> updatedItem) {
142 if (cb_.updated == nullptr)
144 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
145 cb_.updated(static_cast<noti_ex_manager_h>(manager),
146 static_cast<noti_ex_event_info_h>(c_info),
147 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
150 void InvokeDeleted(Manager* manager, const IEventInfo& info,
151 shared_ptr<item::AbstractItem> deletedItem) {
152 if (cb_.deleted == nullptr)
154 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
155 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
156 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
157 static_cast<noti_ex_event_info_h>(c_info),
158 nullptr, user_data_);
160 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
161 static_cast<noti_ex_event_info_h>(c_info),
162 static_cast<noti_ex_item_h>(
163 new Handle(deletedItem)), user_data_);
167 void InvokeError(Manager* manager, NotificationError error, int requestId) {
168 if (cb_.error == nullptr)
170 cb_.error(static_cast<noti_ex_manager_h>(manager),
171 static_cast<noti_ex_error_e>(error), requestId, user_data_);
175 noti_ex_manager_events_s cb_;
179 class ManagerStub : public Manager {
181 ManagerStub(std::unique_ptr<IEventSender> sender,
182 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
183 : Manager(move(sender), move(listener), receiver_group) {
186 void OnAdd(const IEventInfo& info,
187 list<shared_ptr<AbstractItem>> addedItem) override {
188 cb_->InvokeAdded(this, info, addedItem);
191 void OnUpdate(const IEventInfo& info,
192 std::shared_ptr<item::AbstractItem> updatedItem) override {
193 cb_->InvokeUpdated(this, info, updatedItem);
196 void OnDelete(const IEventInfo& info,
197 shared_ptr<item::AbstractItem> deletedItem) override {
198 cb_->InvokeDeleted(this, info, deletedItem);
201 void OnError(NotificationError error, int requestId) override {
202 cb_->InvokeError(this, error, requestId);
205 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
207 return NOTI_EX_ERROR_NONE;
210 int ClearManagerCallbackInfo() {
212 return NOTI_EX_ERROR_NONE;
216 unique_ptr<ManagerCallbackInfo> cb_;
220 class ReporterCallbackInfo {
222 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
223 : user_data_(user_data) {
224 cb_.event = cb.event;
225 cb_.error = cb.error;
228 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
229 list<shared_ptr<AbstractItem>> notiList) {
230 if (cb_.event == nullptr)
232 noti_ex_item_h* noti_list =
233 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
234 if (noti_list == nullptr) {
235 LOGE("Out of memory");
240 for (auto& i : notiList) {
242 static_cast<noti_ex_item_h>(new Handle(i));
245 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
246 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
247 static_cast<noti_ex_event_info_h>(c_info), noti_list,
248 notiList.size(), user_data_);
252 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
253 if (cb_.error == nullptr)
255 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
256 static_cast<noti_ex_error_e>(error), requestId, user_data_);
260 noti_ex_reporter_events_s cb_;
264 class ReporterStub : public Reporter {
266 ReporterStub(std::unique_ptr<IEventSender> sender,
267 std::unique_ptr<IEventListener> listener)
268 : Reporter(move(sender), move(listener)) {
271 void OnEvent(const IEventInfo& info,
272 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
273 cb_->InvokeEvent(this, info, notiList);
276 void OnError(NotificationError error, int requestId) override {
277 cb_->InvokeError(this, error, requestId);
280 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
282 return NOTI_EX_ERROR_NONE;
285 int ClearReporterCallbackInfo() {
287 return NOTI_EX_ERROR_NONE;
291 unique_ptr<ReporterCallbackInfo> cb_;
296 void __noti_ex_free_str_array(char** val, int length) {
298 for (i = 0; i < length ; i++)
303 extern "C" EXPORT_API int noti_ex_action_app_control_create(
304 noti_ex_action_h *handle, app_control_h app_control,
306 if (handle == nullptr || app_control == nullptr) {
307 LOGE("Invalid parameter");
308 return NOTI_EX_ERROR_INVALID_PARAMETER;
311 shared_ptr<AbstractAction>* p;
314 p = new (std::nothrow) shared_ptr<AbstractAction>(
315 new (std::nothrow) AppControlAction(app_control, extra));
317 p = new (std::nothrow) shared_ptr<AbstractAction>(
318 new (std::nothrow) AppControlAction(app_control));
322 LOGE("Out-of-memory");
323 return NOTI_EX_ERROR_OUT_OF_MEMORY;
328 return NOTI_EX_ERROR_NONE;
331 extern "C" EXPORT_API int noti_ex_action_app_control_set(
332 noti_ex_action_h handle, app_control_h app_control) {
333 if (handle == nullptr || app_control == nullptr) {
334 LOGE("Invalid parameter");
335 return NOTI_EX_ERROR_INVALID_PARAMETER;
338 shared_ptr<AbstractAction>* ptr =
339 static_cast<shared_ptr<AbstractAction>*>(handle);
340 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
341 action->SetAppControl(app_control);
343 return NOTI_EX_ERROR_NONE;
346 extern "C" EXPORT_API int noti_ex_action_app_control_get(
347 noti_ex_action_h handle, app_control_h *app_control) {
348 if (handle == nullptr || app_control == nullptr) {
349 LOGE("Invalid parameter");
350 return NOTI_EX_ERROR_INVALID_PARAMETER;
353 shared_ptr<AbstractAction>* ptr =
354 static_cast<shared_ptr<AbstractAction>*>(handle);
355 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
356 *app_control = action->GetAppControl();
358 return NOTI_EX_ERROR_NONE;
361 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
362 const char *id, const char *title) {
365 if (handle == nullptr || title == nullptr) {
366 LOGE("Invalid parameter");
367 return NOTI_EX_ERROR_INVALID_PARAMETER;
371 p = new (std::nothrow) ButtonItem(id, title);
373 p = new (std::nothrow) ButtonItem(title);
376 LOGE("Out-of-memory");
377 return NOTI_EX_ERROR_OUT_OF_MEMORY;
379 *handle = new Handle(shared_ptr<AbstractItem>(p));
381 return NOTI_EX_ERROR_NONE;
384 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
386 if (handle == nullptr || title == nullptr) {
387 LOGE("Invalid parameter");
388 return NOTI_EX_ERROR_INVALID_PARAMETER;
391 Handle* sp = static_cast<Handle*>(handle);
392 if (!sp->IsValidType(AbstractItem::Button)) {
393 LOGE("Invalid handle type");
394 return NOTI_EX_ERROR_INVALID_PARAMETER;
397 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
399 if (p->GetMultiLanguage() != nullptr &&
400 !p->GetMultiLanguage()->GetTranslatedString().empty())
401 str = p->GetMultiLanguage()->GetTranslatedString();
402 else if (!p->GetTitle().empty())
405 *title = strdup(str.c_str());
406 if (*title == nullptr) {
407 LOGE("Out-of-memory");
408 return NOTI_EX_ERROR_OUT_OF_MEMORY;
411 return NOTI_EX_ERROR_NONE;
414 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
415 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
416 if (handle == nullptr) {
417 LOGE("Invalid parameter");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
421 Handle* p = static_cast<Handle*>(handle);
422 if (!p->IsValidType(AbstractItem::Button)) {
423 LOGE("Invalid handle type");
424 return NOTI_EX_ERROR_INVALID_PARAMETER;
427 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
428 if (multi == nullptr) {
429 bi->SetMultiLanguage(nullptr);
430 return NOTI_EX_ERROR_NONE;
433 shared_ptr<MultiLanguage> mul_ptr =
434 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
436 mul_ptr->UpdateString();
437 bi->SetMultiLanguage(mul_ptr);
439 return NOTI_EX_ERROR_NONE;
442 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
443 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
444 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
445 noti_ex_item_chat_message_type_e message_type) {
446 if (handle == nullptr || (text == nullptr && image == nullptr)
447 || name == nullptr || time == nullptr
448 || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
449 LOGE("Invalid parameter");
450 return NOTI_EX_ERROR_INVALID_PARAMETER;
453 auto* p = new (std::nothrow) ChatMessageItem(id,
454 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
455 text == nullptr ? nullptr
456 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
457 image == nullptr ? nullptr
458 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
459 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
460 static_cast<ChatMessageItem::Type>(message_type));
462 LOGE("Out-of-memory");
463 return NOTI_EX_ERROR_OUT_OF_MEMORY;
466 *handle = new Handle(shared_ptr<AbstractItem>(p));
468 return NOTI_EX_ERROR_NONE;
471 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
472 noti_ex_item_h handle, noti_ex_item_h *name) {
473 if (handle == nullptr || name == nullptr) {
474 LOGE("Invalid parameter");
475 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 *name = new Handle(&(p->GetNameItem()));
485 return NOTI_EX_ERROR_NONE;
488 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
489 noti_ex_item_h handle, noti_ex_item_h *text) {
490 if (handle == nullptr || text == nullptr) {
491 LOGE("Invalid parameter");
492 return NOTI_EX_ERROR_INVALID_PARAMETER;
495 Handle* h = static_cast<Handle*>(handle);
496 if (!h->IsValidType(AbstractItem::ChatMessage)) {
497 LOGE("Invalid handle type");
498 return NOTI_EX_ERROR_INVALID_PARAMETER;
500 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
501 *text = new Handle(&(p->GetTextItem()));
503 return NOTI_EX_ERROR_NONE;
506 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
507 noti_ex_item_h handle, noti_ex_item_h *image) {
508 if (handle == nullptr || image == nullptr) {
509 LOGE("Invalid parameter");
510 return NOTI_EX_ERROR_INVALID_PARAMETER;
513 Handle* h = static_cast<Handle*>(handle);
514 if (!h->IsValidType(AbstractItem::ChatMessage)) {
515 LOGE("Invalid handle type");
516 return NOTI_EX_ERROR_INVALID_PARAMETER;
518 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
519 *image = new Handle(&(p->GetImageItem()));
521 return NOTI_EX_ERROR_NONE;
524 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
525 noti_ex_item_h handle, noti_ex_item_h *time) {
526 if (handle == nullptr || time == nullptr) {
527 LOGE("Invalid parameter");
528 return NOTI_EX_ERROR_INVALID_PARAMETER;
531 Handle* h = static_cast<Handle*>(handle);
532 if (!h->IsValidType(AbstractItem::ChatMessage)) {
533 LOGE("Invalid handle type");
534 return NOTI_EX_ERROR_INVALID_PARAMETER;
536 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
537 *time = new Handle(&(p->GetTimeItem()));
539 return NOTI_EX_ERROR_NONE;
542 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
543 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
544 if (handle == nullptr || message_type == nullptr) {
545 LOGE("Invalid parameter");
546 return NOTI_EX_ERROR_INVALID_PARAMETER;
549 Handle* h = static_cast<Handle*>(handle);
550 if (!h->IsValidType(AbstractItem::ChatMessage)) {
551 LOGE("Invalid handle type");
552 return NOTI_EX_ERROR_INVALID_PARAMETER;
554 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
555 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
557 return NOTI_EX_ERROR_NONE;
560 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
561 const char *id, const char *title, bool checked) {
564 if (handle == nullptr || title == nullptr) {
565 LOGE("Invalid parameter");
566 return NOTI_EX_ERROR_INVALID_PARAMETER;
569 p = new (std::nothrow) CheckBoxItem(id, title, checked);
571 LOGE("Out-of-memory");
572 return NOTI_EX_ERROR_OUT_OF_MEMORY;
575 *handle = new Handle(shared_ptr<AbstractItem>(p));
577 return NOTI_EX_ERROR_NONE;
580 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
582 if (handle == nullptr || title == nullptr) {
583 LOGE("Invalid parameter");
584 return NOTI_EX_ERROR_INVALID_PARAMETER;
586 Handle* h = static_cast<Handle*>(handle);
587 if (!h->IsValidType(AbstractItem::CheckBox)) {
588 LOGE("Invalid handle type");
589 return NOTI_EX_ERROR_INVALID_PARAMETER;
592 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
594 if (p->GetMultiLanguage() != nullptr &&
595 !p->GetMultiLanguage()->GetTranslatedString().empty())
596 str = p->GetMultiLanguage()->GetTranslatedString();
597 else if (!p->GetTitle().empty())
600 *title = strdup(str.c_str());
601 if (*title == nullptr) {
602 LOGE("Out-of-memory");
603 return NOTI_EX_ERROR_OUT_OF_MEMORY;
606 return NOTI_EX_ERROR_NONE;
609 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
610 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
611 if (handle == nullptr) {
612 LOGE("Invalid parameter");
613 return NOTI_EX_ERROR_INVALID_PARAMETER;
616 Handle* p = static_cast<Handle*>(handle);
617 if (!p->IsValidType(AbstractItem::CheckBox)) {
618 LOGE("Invalid handle type");
619 return NOTI_EX_ERROR_INVALID_PARAMETER;
622 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
623 if (multi == nullptr) {
624 ci->SetMultiLanguage(nullptr);
625 return NOTI_EX_ERROR_NONE;
628 shared_ptr<MultiLanguage> mul_ptr =
629 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
630 mul_ptr->UpdateString();
631 ci->SetMultiLanguage(mul_ptr);
633 return NOTI_EX_ERROR_NONE;
636 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
637 noti_ex_item_h handle, bool *checked) {
638 if (handle == nullptr || checked == nullptr) {
639 LOGE("Invalid parameter");
640 return NOTI_EX_ERROR_INVALID_PARAMETER;
642 Handle* h = static_cast<Handle*>(handle);
643 if (!h->IsValidType(AbstractItem::CheckBox)) {
644 LOGE("Invalid handle type");
645 return NOTI_EX_ERROR_INVALID_PARAMETER;
647 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
648 *checked = p->IsChecked();
650 return NOTI_EX_ERROR_NONE;
653 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
654 noti_ex_item_h handle, bool checked) {
655 if (handle == nullptr) {
656 LOGE("Invalid parameter");
657 return NOTI_EX_ERROR_INVALID_PARAMETER;
660 Handle* h = static_cast<Handle*>(handle);
661 if (!h->IsValidType(AbstractItem::CheckBox)) {
662 LOGE("Invalid handle type");
663 return NOTI_EX_ERROR_INVALID_PARAMETER;
666 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
667 p->SetChecked(checked);
669 return NOTI_EX_ERROR_NONE;
672 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
676 if (handle == nullptr) {
677 LOGE("Invalid parameter");
678 return NOTI_EX_ERROR_INVALID_PARAMETER;
681 p = new (std::nothrow) EntryItem(id);
683 LOGE("Out-of-memory");
684 return NOTI_EX_ERROR_OUT_OF_MEMORY;
687 *handle = new Handle(shared_ptr<AbstractItem>(p));
689 return NOTI_EX_ERROR_NONE;
692 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
694 if (handle == nullptr || text == nullptr) {
695 LOGE("Invalid parameter");
696 return NOTI_EX_ERROR_INVALID_PARAMETER;
699 Handle* h = static_cast<Handle*>(handle);
700 if (!h->IsValidType(AbstractItem::Entry)) {
701 LOGE("Invalid handle type");
702 return NOTI_EX_ERROR_INVALID_PARAMETER;
705 EntryItem* p = static_cast<EntryItem*>(h->Get());
707 if (p->GetMultiLanguage() != nullptr &&
708 !p->GetMultiLanguage()->GetTranslatedString().empty())
709 str = p->GetMultiLanguage()->GetTranslatedString();
710 else if (!p->GetText().empty())
713 *text = strdup(str.c_str());
714 if (*text == nullptr) {
715 LOGE("Out-of-memory");
716 return NOTI_EX_ERROR_OUT_OF_MEMORY;
719 return NOTI_EX_ERROR_NONE;
722 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
724 if (handle == nullptr || text == nullptr) {
725 LOGE("Invalid parameter");
726 return NOTI_EX_ERROR_INVALID_PARAMETER;
728 Handle* h = static_cast<Handle*>(handle);
729 if (!h->IsValidType(AbstractItem::Entry)) {
730 LOGE("Invalid handle type");
731 return NOTI_EX_ERROR_INVALID_PARAMETER;
733 EntryItem* p = static_cast<EntryItem*>(h->Get());
734 p->SetText(std::string(text));
736 return NOTI_EX_ERROR_NONE;
739 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
740 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
741 if (handle == nullptr) {
742 LOGE("Invalid parameter");
743 return NOTI_EX_ERROR_INVALID_PARAMETER;
746 Handle* p = static_cast<Handle*>(handle);
747 if (!p->IsValidType(AbstractItem::Entry)) {
748 LOGE("Invalid handle type");
749 return NOTI_EX_ERROR_INVALID_PARAMETER;
752 EntryItem* ei = static_cast<EntryItem*>(p->Get());
753 if (multi == nullptr) {
754 ei->SetMultiLanguage(nullptr);
755 return NOTI_EX_ERROR_NONE;
758 shared_ptr<MultiLanguage> mul_ptr =
759 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
760 ei->SetMultiLanguage(mul_ptr);
761 ei->GetMultiLanguage()->UpdateString();
763 return NOTI_EX_ERROR_NONE;
766 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
767 noti_ex_event_info_h* cloned_handle) {
768 if (handle == nullptr || cloned_handle == nullptr) {
769 LOGE("Invalid parameter");
770 return NOTI_EX_ERROR_INVALID_PARAMETER;
773 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
774 EventInfo* info = new EventInfo(cloned);
775 *cloned_handle = info;
776 return NOTI_EX_ERROR_NONE;
779 extern "C" EXPORT_API int noti_ex_event_info_destroy(
780 noti_ex_event_info_h handle) {
781 if (handle == nullptr) {
782 LOGE("Invalid parameter");
783 return NOTI_EX_ERROR_INVALID_PARAMETER;
785 EventInfo* info = static_cast<EventInfo*>(handle);
787 return NOTI_EX_ERROR_NONE;
790 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
791 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
792 if (handle == nullptr || event_type == nullptr) {
793 LOGE("Invalid parameter");
794 return NOTI_EX_ERROR_INVALID_PARAMETER;
796 EventInfo* info = static_cast<EventInfo*>(handle);
797 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
799 return NOTI_EX_ERROR_NONE;
802 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
803 noti_ex_event_info_h handle, char **owner) {
804 if (handle == nullptr || owner == nullptr) {
805 LOGE("Invalid parameter");
806 return NOTI_EX_ERROR_INVALID_PARAMETER;
808 EventInfo* info = static_cast<EventInfo*>(handle);
809 *owner = strdup(info->GetOwner().c_str());
810 return NOTI_EX_ERROR_NONE;
813 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
814 noti_ex_event_info_h handle, char **channel) {
815 if (handle == nullptr || channel == nullptr) {
816 LOGE("Invalid parameter");
817 return NOTI_EX_ERROR_INVALID_PARAMETER;
819 EventInfo* info = static_cast<EventInfo*>(handle);
820 *channel = strdup(info->GetChannel().c_str());
821 return NOTI_EX_ERROR_NONE;
824 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
825 noti_ex_event_info_h handle, char **item_id) {
826 if (handle == nullptr || item_id == nullptr) {
827 LOGE("Invalid parameter");
828 return NOTI_EX_ERROR_INVALID_PARAMETER;
830 EventInfo* info = static_cast<EventInfo*>(handle);
831 *item_id = strdup(info->GetItemId().c_str());
832 return NOTI_EX_ERROR_NONE;
835 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
836 noti_ex_event_info_h handle, int *req_id) {
837 if (handle == nullptr || req_id == nullptr) {
838 LOGE("Invalid parameter");
839 return NOTI_EX_ERROR_INVALID_PARAMETER;
841 EventInfo* info = static_cast<EventInfo*>(handle);
842 *req_id = info->GetRequestId();
843 return NOTI_EX_ERROR_NONE;
846 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
850 if (handle == nullptr) {
851 LOGE("Invalid parameter");
852 return NOTI_EX_ERROR_INVALID_PARAMETER;
856 p = new (std::nothrow) GroupItem(id);
858 p = new (std::nothrow) GroupItem();
861 LOGE("Out-of-memory");
862 return NOTI_EX_ERROR_OUT_OF_MEMORY;
865 *handle = new Handle(shared_ptr<AbstractItem>(p));
867 return NOTI_EX_ERROR_NONE;
870 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
872 if (handle == nullptr) {
873 LOGE("Invalid parameter");
874 return NOTI_EX_ERROR_INVALID_PARAMETER;
876 Handle* h = static_cast<Handle*>(handle);
877 if (!h->IsValidType(AbstractItem::Group)) {
878 LOGE("Invalid handle type");
879 return NOTI_EX_ERROR_INVALID_PARAMETER;
881 GroupItem* p = static_cast<GroupItem*>(h->Get());
882 p->SetDirection(vertical);
884 return NOTI_EX_ERROR_NONE;
887 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
889 if (handle == nullptr) {
890 LOGE("Invalid parameter");
891 return NOTI_EX_ERROR_INVALID_PARAMETER;
893 Handle* h = static_cast<Handle*>(handle);
894 if (!h->IsValidType(AbstractItem::Group)) {
895 LOGE("Invalid handle type");
896 return NOTI_EX_ERROR_INVALID_PARAMETER;
898 GroupItem* p = static_cast<GroupItem*>(h->Get());
899 *vertical = p->IsVertical();
901 return NOTI_EX_ERROR_NONE;
904 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
906 if (handle == nullptr) {
907 LOGE("Invalid parameter");
908 return NOTI_EX_ERROR_INVALID_PARAMETER;
910 Handle* h = static_cast<Handle*>(handle);
911 if (!h->IsValidType(AbstractItem::Group)) {
912 LOGE("Invalid handle type");
913 return NOTI_EX_ERROR_INVALID_PARAMETER;
915 GroupItem* p = static_cast<GroupItem*>(h->Get());
916 if (!p->GetAppLabel().empty()) {
917 *label = strdup(p->GetAppLabel().c_str());
918 if (*label == nullptr) {
919 LOGE("Out-of-memory");
920 return NOTI_EX_ERROR_OUT_OF_MEMORY;
924 return NOTI_EX_ERROR_NONE;
927 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
928 noti_ex_item_h child) {
929 if (handle == nullptr || child == nullptr) {
930 LOGE("Invalid parameter");
931 return NOTI_EX_ERROR_INVALID_PARAMETER;
933 Handle* h = static_cast<Handle*>(handle);
934 if (!h->IsValidType(AbstractItem::Group)) {
935 LOGE("Invalid handle type");
936 return NOTI_EX_ERROR_INVALID_PARAMETER;
938 auto p = static_cast<GroupItem*>(h->Get());
939 p->AddChild((static_cast<Handle*>(child))->GetPtr());
941 return NOTI_EX_ERROR_NONE;
944 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
945 const char *item_id) {
946 if (handle == nullptr || item_id == nullptr) {
947 LOGE("Invalid parameter");
948 return NOTI_EX_ERROR_INVALID_PARAMETER;
950 Handle* h = static_cast<Handle*>(handle);
951 if (!h->IsValidType(AbstractItem::Group)) {
952 LOGE("Invalid handle type");
953 return NOTI_EX_ERROR_INVALID_PARAMETER;
955 GroupItem* p = static_cast<GroupItem*>(h->Get());
956 p->RemoveChild(std::string(item_id));
958 return NOTI_EX_ERROR_NONE;
961 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
962 noti_ex_item_group_foreach_child_cb callback, void *data) {
963 if (handle == nullptr || callback == nullptr) {
964 LOGE("Invalid parameter");
965 return NOTI_EX_ERROR_INVALID_PARAMETER;
968 Handle* h = static_cast<Handle*>(handle);
969 if (!h->IsValidType(AbstractItem::Group)) {
970 LOGE("Invalid handle type");
971 return NOTI_EX_ERROR_INVALID_PARAMETER;
973 GroupItem* p = static_cast<GroupItem*>(h->Get());
974 list<shared_ptr<AbstractItem>> children = p->GetChildren();
975 LOGI("Retrive (%zd)", children.size());
976 for (auto i : children) {
978 static_cast<noti_ex_item_h>(new Handle(i)), data);
979 if (ret != NOTI_EX_ERROR_NONE) {
980 LOGW("callback return (%d) stop foreach", ret);
985 return NOTI_EX_ERROR_NONE;
988 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
989 const char *id, const char *image_path) {
992 if (handle == nullptr || image_path == nullptr) {
993 LOGE("Invalid parameter");
994 return NOTI_EX_ERROR_INVALID_PARAMETER;
998 p = new (std::nothrow) ImageItem(id, image_path);
1000 p = new (std::nothrow) ImageItem(image_path);
1003 LOGE("Out-of-memory");
1004 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1007 *handle = new Handle(shared_ptr<AbstractItem>(p));
1009 return NOTI_EX_ERROR_NONE;
1012 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1013 noti_ex_item_h handle, char **image_path) {
1014 if (handle == nullptr || image_path == nullptr) {
1015 LOGE("Invalid parameter");
1016 return NOTI_EX_ERROR_INVALID_PARAMETER;
1018 Handle* h = static_cast<Handle*>(handle);
1019 if (!h->IsValidType(AbstractItem::Image)) {
1020 LOGE("Invalid handle type");
1021 return NOTI_EX_ERROR_INVALID_PARAMETER;
1023 ImageItem* p = static_cast<ImageItem*>(h->Get());
1024 if (!p->GetImagePath().empty()) {
1025 *image_path = strdup(p->GetImagePath().c_str());
1026 if (*image_path == nullptr) {
1027 LOGE("Out-of-memory");
1028 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1032 return NOTI_EX_ERROR_NONE;
1035 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1036 noti_ex_item_h *handle, const char *id) {
1037 InputSelectorItem* p;
1039 if (handle == nullptr) {
1040 LOGE("Invalid parameter");
1041 return NOTI_EX_ERROR_INVALID_PARAMETER;
1045 p = new (std::nothrow) InputSelectorItem(id);
1047 p = new (std::nothrow) InputSelectorItem();
1050 LOGE("Out-of-memory");
1051 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1054 *handle = new Handle(shared_ptr<AbstractItem>(p));
1056 return NOTI_EX_ERROR_NONE;
1059 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1060 noti_ex_item_h handle, char ***contents_list, int *count) {
1061 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1062 LOGE("Invalid parameter");
1063 return NOTI_EX_ERROR_INVALID_PARAMETER;
1066 Handle* h = static_cast<Handle*>(handle);
1067 if (!h->IsValidType(AbstractItem::InputSelector)) {
1068 LOGE("Invalid handle type");
1069 return NOTI_EX_ERROR_INVALID_PARAMETER;
1072 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1073 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1074 list<string> contents;
1075 if (arr.size() == 0) {
1076 contents = p->GetContents();
1078 for (auto& i : arr) {
1079 contents.push_back(i->GetTranslatedString());
1083 char **list = (char**)calloc(contents.size(), sizeof(char*));
1084 if (list == nullptr) {
1085 LOGE("Out of memory");
1086 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1090 for (auto& i : contents) {
1091 list[idx] = strdup(i.c_str());
1092 if (list[idx] == nullptr) {
1093 __noti_ex_free_str_array(list, idx);
1094 LOGE("Out of memory");
1095 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1100 *count = contents.size();
1101 *contents_list = list;
1103 return NOTI_EX_ERROR_NONE;
1106 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1107 noti_ex_item_h handle, const char **contents, int count) {
1108 if (handle == nullptr || contents == nullptr) {
1109 LOGE("Invalid parameter");
1110 return NOTI_EX_ERROR_INVALID_PARAMETER;
1113 list<string> new_contents;
1114 Handle* h = static_cast<Handle*>(handle);
1115 if (!h->IsValidType(AbstractItem::InputSelector)) {
1116 LOGE("Invalid handle type");
1117 return NOTI_EX_ERROR_INVALID_PARAMETER;
1119 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1120 for (int i = 0; i < count; i++) {
1121 new_contents.push_back(contents[i]);
1123 p->SetContents(move(new_contents));
1125 return NOTI_EX_ERROR_NONE;
1128 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1129 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1130 if (handle == nullptr) {
1131 LOGE("Invalid parameter");
1132 return NOTI_EX_ERROR_INVALID_PARAMETER;
1135 Handle* p = static_cast<Handle*>(handle);
1136 if (!p->IsValidType(AbstractItem::InputSelector)) {
1137 LOGE("Invalid handle type");
1138 return NOTI_EX_ERROR_INVALID_PARAMETER;
1141 vector<shared_ptr<MultiLanguage>> m_list;
1142 for (int i = 0; i < count; i++) {
1143 shared_ptr<MultiLanguage> mul_ptr =
1144 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1145 mul_ptr->UpdateString();
1146 m_list.push_back(mul_ptr);
1149 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1150 input->SetMultiLanguage(m_list);
1152 return NOTI_EX_ERROR_NONE;
1155 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1156 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1157 if (handle == nullptr) {
1158 LOGE("Invalid parameter");
1159 return NOTI_EX_ERROR_INVALID_PARAMETER;
1162 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1163 new (std::nothrow) Color(a, r, g, b));
1164 if (ptr == nullptr || ptr->get() == nullptr) {
1165 LOGE("Out-of-memory");
1166 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1171 return NOTI_EX_ERROR_NONE;
1174 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1175 if (handle == nullptr) {
1176 LOGE("Invalid parameter");
1177 return NOTI_EX_ERROR_INVALID_PARAMETER;
1180 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1183 return NOTI_EX_ERROR_NONE;
1186 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1187 unsigned char *val) {
1188 if (handle == nullptr || val == nullptr) {
1189 LOGE("Invalid parameter");
1190 return NOTI_EX_ERROR_INVALID_PARAMETER;
1193 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1194 *val = (*p)->GetAVal();
1196 return NOTI_EX_ERROR_NONE;
1199 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1200 unsigned char *val) {
1201 if (handle == nullptr || val == nullptr) {
1202 LOGE("Invalid parameter");
1203 return NOTI_EX_ERROR_INVALID_PARAMETER;
1206 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1207 *val = (*p)->GetRVal();
1209 return NOTI_EX_ERROR_NONE;
1212 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1213 unsigned char *val) {
1214 if (handle == nullptr || val == nullptr) {
1215 LOGE("Invalid parameter");
1216 return NOTI_EX_ERROR_INVALID_PARAMETER;
1219 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1220 *val = (*p)->GetGVal();
1222 return NOTI_EX_ERROR_NONE;
1225 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1226 unsigned char *val) {
1227 if (handle == nullptr || val == nullptr) {
1228 LOGE("Invalid parameter");
1229 return NOTI_EX_ERROR_INVALID_PARAMETER;
1232 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1233 *val = (*p)->GetBVal();
1235 return NOTI_EX_ERROR_NONE;
1238 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1239 int left, int top, int right, int bottom) {
1240 if (handle == nullptr) {
1241 LOGE("Invalid parameter");
1242 return NOTI_EX_ERROR_INVALID_PARAMETER;
1245 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1246 new (std::nothrow) Padding(left, top, right, bottom));
1247 if (ptr == nullptr || ptr->get() == nullptr) {
1248 LOGE("Out-of-memory");
1249 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1254 return NOTI_EX_ERROR_NONE;
1257 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1258 if (handle == nullptr) {
1259 LOGE("Invalid parameter");
1260 return NOTI_EX_ERROR_INVALID_PARAMETER;
1263 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1266 return NOTI_EX_ERROR_NONE;
1269 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1271 if (handle == nullptr || val == nullptr) {
1272 LOGE("Invalid parameter");
1273 return NOTI_EX_ERROR_INVALID_PARAMETER;
1276 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1277 *val = (*p)->GetLeft();
1279 return NOTI_EX_ERROR_NONE;
1282 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1284 if (handle == nullptr || val == nullptr) {
1285 LOGE("Invalid parameter");
1286 return NOTI_EX_ERROR_INVALID_PARAMETER;
1289 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1290 *val = (*p)->GetTop();
1292 return NOTI_EX_ERROR_NONE;
1295 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1297 if (handle == nullptr || val == nullptr) {
1298 LOGE("Invalid parameter");
1299 return NOTI_EX_ERROR_INVALID_PARAMETER;
1302 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1303 *val = (*p)->GetRight();
1305 return NOTI_EX_ERROR_NONE;
1308 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1310 if (handle == nullptr || val == nullptr) {
1311 LOGE("Invalid parameter");
1312 return NOTI_EX_ERROR_INVALID_PARAMETER;
1315 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1316 *val = (*p)->GetBottom();
1318 return NOTI_EX_ERROR_NONE;
1321 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1322 int x, int y, int w, int h) {
1323 if (handle == nullptr) {
1324 LOGE("Invalid parameter");
1325 return NOTI_EX_ERROR_INVALID_PARAMETER;
1328 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1329 new (std::nothrow) Geometry(x, y, w, h));
1330 if (ptr == nullptr || ptr->get() == nullptr) {
1331 LOGE("Out-of-memory");
1332 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1337 return NOTI_EX_ERROR_NONE;
1340 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1341 if (handle == nullptr) {
1342 LOGE("Invalid parameter");
1343 return NOTI_EX_ERROR_INVALID_PARAMETER;
1346 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1349 return NOTI_EX_ERROR_NONE;
1352 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1354 if (handle == nullptr || val == nullptr) {
1355 LOGE("Invalid parameter");
1356 return NOTI_EX_ERROR_INVALID_PARAMETER;
1359 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1360 *val = (*p)->GetX();
1362 return NOTI_EX_ERROR_NONE;
1365 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1367 if (handle == nullptr || val == nullptr) {
1368 LOGE("Invalid parameter");
1369 return NOTI_EX_ERROR_INVALID_PARAMETER;
1372 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1373 *val = (*p)->GetY();
1375 return NOTI_EX_ERROR_NONE;
1378 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1380 if (handle == nullptr || val == nullptr) {
1381 LOGE("Invalid parameter");
1382 return NOTI_EX_ERROR_INVALID_PARAMETER;
1385 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1386 *val = (*p)->GetWidth();
1388 return NOTI_EX_ERROR_NONE;
1391 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1393 if (handle == nullptr || val == nullptr) {
1394 LOGE("Invalid parameter");
1395 return NOTI_EX_ERROR_INVALID_PARAMETER;
1398 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1399 *val = (*p)->GetHeight();
1401 return NOTI_EX_ERROR_NONE;
1404 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1405 noti_ex_color_h color,
1406 noti_ex_padding_h padding,
1407 noti_ex_geometry_h geometry) {
1408 if (handle == nullptr) {
1409 LOGE("Invalid parameter");
1410 return NOTI_EX_ERROR_INVALID_PARAMETER;
1413 shared_ptr<Color> col = (color == nullptr) ?
1414 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1415 shared_ptr<Padding> padd = (padding == nullptr) ?
1416 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1417 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1418 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1420 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1421 new (std::nothrow) Style(col, padd, geo));
1422 if (ptr == nullptr || ptr->get() == nullptr) {
1423 LOGE("Out-of-memory");
1424 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1429 return NOTI_EX_ERROR_NONE;
1432 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1433 if (handle == nullptr) {
1434 LOGE("Invalid parameter");
1435 return NOTI_EX_ERROR_INVALID_PARAMETER;
1438 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1441 return NOTI_EX_ERROR_NONE;
1444 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1445 noti_ex_padding_h *padding) {
1446 if (handle == nullptr || padding == nullptr) {
1447 LOGE("Invalid parameter");
1448 return NOTI_EX_ERROR_INVALID_PARAMETER;
1451 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1452 if ((*p)->GetPadding() == nullptr) {
1453 LOGW("Padding info is null");
1454 return NOTI_EX_ERROR_INVALID_PARAMETER;
1457 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1458 new (std::nothrow) Padding(*((*p)->GetPadding())));
1459 if (padd == nullptr || padd->get() == nullptr) {
1460 LOGE("Out-of-memory");
1461 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1466 return NOTI_EX_ERROR_NONE;
1470 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1471 noti_ex_padding_h padding) {
1472 if (handle == nullptr) {
1473 LOGE("Invalid parameter");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1478 if (padding == nullptr) {
1479 (*p)->SetPadding(nullptr);
1480 return NOTI_EX_ERROR_NONE;
1483 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1484 (*p)->SetPadding(*padd);
1486 return NOTI_EX_ERROR_NONE;
1489 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1490 noti_ex_color_h *color) {
1491 if (handle == nullptr || color == nullptr) {
1492 LOGE("Invalid parameter");
1493 return NOTI_EX_ERROR_INVALID_PARAMETER;
1496 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1497 if ((*p)->GetColor() == nullptr) {
1498 LOGW("Color info is null");
1499 return NOTI_EX_ERROR_INVALID_PARAMETER;
1502 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1503 new (std::nothrow) Color(*((*p)->GetColor())));
1504 if (col == nullptr || col->get() == nullptr) {
1505 LOGE("Out-of-memory");
1506 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1511 return NOTI_EX_ERROR_NONE;
1514 extern "C" EXPORT_API int noti_ex_style_set_color(
1515 noti_ex_style_h handle, noti_ex_color_h color) {
1516 if (handle == nullptr) {
1517 LOGE("Invalid parameter");
1518 return NOTI_EX_ERROR_INVALID_PARAMETER;
1521 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1522 if (color == nullptr) {
1523 (*p)->SetColor(nullptr);
1524 return NOTI_EX_ERROR_NONE;
1527 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1528 (*p)->SetColor(*col);
1530 return NOTI_EX_ERROR_NONE;
1533 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1534 noti_ex_geometry_h *geometry) {
1535 if (handle == nullptr || geometry == nullptr) {
1536 LOGE("Invalid parameter");
1537 return NOTI_EX_ERROR_INVALID_PARAMETER;
1540 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1541 if ((*p)->GetGeometry() == nullptr) {
1542 LOGW("Geometry info is null");
1543 return NOTI_EX_ERROR_INVALID_PARAMETER;
1546 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1547 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1548 if (geo == nullptr || geo->get() == nullptr) {
1549 LOGE("Out-of-memory");
1550 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1555 return NOTI_EX_ERROR_NONE;
1558 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1559 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1560 if (handle == nullptr) {
1561 LOGE("Invalid parameter");
1562 return NOTI_EX_ERROR_INVALID_PARAMETER;
1565 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1566 if (geometry == nullptr) {
1567 (*p)->SetGeometry(nullptr);
1568 return NOTI_EX_ERROR_NONE;
1571 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1572 (*p)->SetGeometry(*geo);
1574 return NOTI_EX_ERROR_NONE;
1577 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1578 noti_ex_style_h handle, char** background_image) {
1579 if (handle == nullptr || background_image == nullptr) {
1580 LOGE("Invalid parameter");
1581 return NOTI_EX_ERROR_INVALID_PARAMETER;
1584 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1585 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1587 return NOTI_EX_ERROR_NONE;
1590 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1591 noti_ex_style_h handle, char* background_image) {
1592 if (handle == nullptr || background_image == nullptr) {
1593 LOGE("Invalid parameter");
1594 return NOTI_EX_ERROR_INVALID_PARAMETER;
1597 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1598 (*p)->SetBackgroundImage(background_image);
1600 return NOTI_EX_ERROR_NONE;
1603 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1604 noti_ex_style_h handle, noti_ex_color_h* color) {
1605 if (handle == nullptr || color == nullptr) {
1606 LOGE("Invalid parameter");
1607 return NOTI_EX_ERROR_INVALID_PARAMETER;
1610 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1611 if ((*p)->GetBackgroundColor() == nullptr) {
1612 LOGW("Color info is null");
1613 return NOTI_EX_ERROR_INVALID_PARAMETER;
1616 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1617 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1618 if (col == nullptr || col->get() == nullptr) {
1619 LOGE("Out-of-memory");
1620 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1625 return NOTI_EX_ERROR_NONE;
1628 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1629 noti_ex_style_h handle, noti_ex_color_h color) {
1630 if (handle == nullptr || color == nullptr) {
1631 LOGE("Invalid parameter");
1632 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1636 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1637 (*p)->SetBackgroundColor(*col);
1639 return NOTI_EX_ERROR_NONE;
1642 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1643 noti_ex_color_h color) {
1644 if (handle == nullptr) {
1645 LOGE("Invalid parameter");
1646 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1650 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1651 new (std::nothrow) LEDInfo(*color_ptr));
1653 LOGE("Out-of-memory");
1654 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1659 return NOTI_EX_ERROR_NONE;
1662 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1663 if (handle == nullptr) {
1664 LOGE("Invalid parameter");
1665 return NOTI_EX_ERROR_INVALID_PARAMETER;
1668 shared_ptr<LEDInfo>* led_ptr =
1669 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1671 return NOTI_EX_ERROR_NONE;
1674 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1675 noti_ex_led_info_h handle, int ms) {
1676 if (handle == nullptr) {
1677 LOGE("Invalid parameter");
1678 return NOTI_EX_ERROR_INVALID_PARAMETER;
1681 shared_ptr<LEDInfo>* led_ptr =
1682 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1683 (*led_ptr)->SetOnPeriod(ms);
1685 return NOTI_EX_ERROR_NONE;
1688 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1689 noti_ex_led_info_h handle, int *ms) {
1690 if (handle == nullptr || ms == nullptr) {
1691 LOGE("Invalid parameter");
1692 return NOTI_EX_ERROR_INVALID_PARAMETER;
1695 shared_ptr<LEDInfo>* led_ptr =
1696 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1697 *ms = (*led_ptr)->GetOnPeriod();
1699 return NOTI_EX_ERROR_NONE;
1702 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1703 noti_ex_led_info_h handle, int ms) {
1704 if (handle == nullptr) {
1705 LOGE("Invalid parameter");
1706 return NOTI_EX_ERROR_INVALID_PARAMETER;
1709 shared_ptr<LEDInfo>* led_ptr =
1710 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1711 (*led_ptr)->SetOffPeriod(ms);
1713 return NOTI_EX_ERROR_NONE;
1716 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1717 noti_ex_led_info_h handle, int *ms) {
1718 if (handle == nullptr) {
1719 LOGE("Invalid parameter");
1720 return NOTI_EX_ERROR_INVALID_PARAMETER;
1723 shared_ptr<LEDInfo>* led_ptr =
1724 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1725 *ms = (*led_ptr)->GetOffPeriod();
1727 return NOTI_EX_ERROR_NONE;
1730 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1731 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1732 if (handle == nullptr) {
1733 LOGE("Invalid parameter");
1734 return NOTI_EX_ERROR_INVALID_PARAMETER;
1737 shared_ptr<LEDInfo>* led_ptr =
1738 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1739 if ((*led_ptr)->GetColor() == nullptr) {
1740 LOGE("Color is null");
1741 return NOTI_EX_ERROR_INVALID_PARAMETER;
1744 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1745 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1746 if (col == nullptr || col->get() == nullptr) {
1747 LOGE("Out-of-memory");
1748 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1753 return NOTI_EX_ERROR_NONE;
1756 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1757 noti_ex_led_info_h handle, noti_ex_color_h color) {
1758 if (handle == nullptr) {
1759 LOGE("Invalid parameter");
1760 return NOTI_EX_ERROR_INVALID_PARAMETER;
1763 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1764 if (color == nullptr) {
1765 (*p)->SetColor(nullptr);
1766 return NOTI_EX_ERROR_NONE;
1769 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1770 (*p)->SetColor(*col);
1772 return NOTI_EX_ERROR_NONE;
1775 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1776 if (handle == nullptr) {
1777 LOGE("Invalid parameter");
1778 return NOTI_EX_ERROR_INVALID_PARAMETER;
1781 shared_ptr<AbstractAction>* ptr =
1782 static_cast<shared_ptr<AbstractAction>*>(handle);
1785 return NOTI_EX_ERROR_NONE;
1788 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1790 if (handle == nullptr || type == nullptr) {
1791 LOGE("Invalid parameter");
1792 return NOTI_EX_ERROR_INVALID_PARAMETER;
1795 shared_ptr<AbstractAction>* ptr =
1796 static_cast<shared_ptr<AbstractAction>*>(handle);
1797 *type = (*ptr)->GetType();
1799 return NOTI_EX_ERROR_NONE;
1802 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1804 if (handle == nullptr || local == nullptr) {
1805 LOGE("Invalid parameter");
1806 return NOTI_EX_ERROR_INVALID_PARAMETER;
1809 shared_ptr<AbstractAction>* ptr =
1810 static_cast<shared_ptr<AbstractAction>*>(handle);
1811 *local = (*ptr)->IsLocal();
1813 return NOTI_EX_ERROR_NONE;
1816 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1817 noti_ex_item_h item) {
1818 if (handle == nullptr || item == nullptr) {
1819 LOGE("Invalid parameter");
1820 return NOTI_EX_ERROR_INVALID_PARAMETER;
1822 shared_ptr<AbstractAction>* ptr =
1823 static_cast<shared_ptr<AbstractAction>*>(handle);
1824 Handle* ih = static_cast<Handle*>(item);
1825 (*ptr)->Execute(ih->GetPtr());
1827 return NOTI_EX_ERROR_NONE;
1830 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1832 if (handle == nullptr || extra == nullptr) {
1833 LOGE("Invalid parameter");
1834 return NOTI_EX_ERROR_INVALID_PARAMETER;
1837 shared_ptr<AbstractAction>* ptr =
1838 static_cast<shared_ptr<AbstractAction>*>(handle);
1839 if (!(*ptr)->GetExtra().empty()) {
1840 *extra = strdup((*ptr)->GetExtra().c_str());
1841 if (*extra == nullptr) {
1842 LOGE("Out-of-memory");
1843 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1847 return NOTI_EX_ERROR_NONE;
1850 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1851 noti_ex_item_info_h handle, int *hide_time) {
1852 if (handle == nullptr || hide_time == nullptr) {
1853 LOGE("Invalid parameter");
1854 return NOTI_EX_ERROR_INVALID_PARAMETER;
1856 IItemInfo* p = static_cast<IItemInfo*>(handle);
1857 *hide_time = p->GetHideTime();
1858 return NOTI_EX_ERROR_NONE;
1861 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1862 noti_ex_item_info_h handle, int hide_time) {
1863 if (handle == nullptr) {
1864 LOGE("Invalid parameter");
1865 return NOTI_EX_ERROR_INVALID_PARAMETER;
1867 IItemInfo* p = static_cast<IItemInfo*>(handle);
1868 p->SetHideTime(hide_time);
1869 return NOTI_EX_ERROR_NONE;
1872 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1873 noti_ex_item_info_h handle, int *delete_time) {
1874 if (handle == nullptr || delete_time == nullptr) {
1875 LOGE("Invalid parameter");
1876 return NOTI_EX_ERROR_INVALID_PARAMETER;
1878 IItemInfo* p = static_cast<IItemInfo*>(handle);
1879 *delete_time = p->GetDeleteTime();
1880 return NOTI_EX_ERROR_NONE;
1883 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1884 noti_ex_item_info_h handle, int delete_time) {
1885 if (handle == nullptr) {
1886 LOGE("Invalid parameter");
1887 return NOTI_EX_ERROR_INVALID_PARAMETER;
1889 IItemInfo* p = static_cast<IItemInfo*>(handle);
1890 p->SetDeleteTime(delete_time);
1891 return NOTI_EX_ERROR_NONE;
1894 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1895 noti_ex_item_info_h handle, time_t *time) {
1896 if (handle == nullptr || time == nullptr) {
1897 LOGE("Invalid parameter");
1898 return NOTI_EX_ERROR_INVALID_PARAMETER;
1901 IItemInfo* p = static_cast<IItemInfo*>(handle);
1902 *time = p->GetTime();
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1907 if (handle == nullptr) {
1908 LOGE("Invalid parameter");
1909 return NOTI_EX_ERROR_INVALID_PARAMETER;
1912 Handle* h = static_cast<Handle*>(handle);
1914 return NOTI_EX_ERROR_NONE;
1917 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1918 const char *id, noti_ex_item_h *item) {
1919 if (handle == nullptr) {
1920 LOGE("Invalid parameter");
1921 return NOTI_EX_ERROR_INVALID_PARAMETER;
1924 Handle* p = static_cast<Handle*>(handle);
1925 AbstractItem& find_item = p->Get()->FindByID(string(id));
1926 *item = new Handle(&find_item);
1927 return NOTI_EX_ERROR_NONE;
1930 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1932 if (handle == nullptr || type == nullptr) {
1933 LOGE("Invalid parameter");
1934 return NOTI_EX_ERROR_INVALID_PARAMETER;
1937 Handle* h = static_cast<Handle*>(handle);
1938 AbstractItem* p = h->Get();
1939 *type = p->GetType();
1940 return NOTI_EX_ERROR_NONE;
1943 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1944 char ***path, int *count) {
1945 if (handle == nullptr || path == nullptr || count == nullptr) {
1946 LOGE("Invalid parameter");
1947 return NOTI_EX_ERROR_INVALID_PARAMETER;
1949 Handle* p = static_cast<Handle*>(handle);
1950 list<string> shared_path = p->Get()->GetSharedPath();
1951 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1952 if (tmp_path == nullptr) {
1953 LOGE("Fail to create items");
1954 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1958 for (auto& i : shared_path) {
1959 tmp_path[idx] = strdup(i.c_str());
1960 if (tmp_path[idx] == nullptr) {
1961 __noti_ex_free_str_array(tmp_path, idx);
1962 LOGE("Out of memory");
1963 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1969 *count = shared_path.size();
1970 return NOTI_EX_ERROR_NONE;
1973 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1975 if (handle == nullptr || id == nullptr) {
1976 LOGE("Invalid parameter");
1977 return NOTI_EX_ERROR_INVALID_PARAMETER;
1979 Handle* h = static_cast<Handle*>(handle);
1980 AbstractItem* p = h->Get();
1981 *id = strdup(p->GetId().c_str());
1982 return NOTI_EX_ERROR_NONE;
1985 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1987 if (handle == nullptr || id == nullptr) {
1988 LOGE("Invalid parameter");
1989 return NOTI_EX_ERROR_INVALID_PARAMETER;
1991 Handle* p = static_cast<Handle*>(handle);
1992 p->Get()->SetId(id);
1993 return NOTI_EX_ERROR_NONE;
1996 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1997 noti_ex_action_h *action) {
1998 if (handle == nullptr || action == nullptr) {
1999 LOGE("Invalid parameter");
2000 return NOTI_EX_ERROR_INVALID_PARAMETER;
2002 Handle* p = static_cast<Handle*>(handle);
2003 if (p->Get()->GetAction() == nullptr) {
2005 return NOTI_EX_ERROR_NONE;
2007 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2008 p->Get()->GetAction()));
2010 return NOTI_EX_ERROR_NONE;
2013 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2014 noti_ex_action_h action) {
2015 if (handle == nullptr || action == nullptr) {
2016 LOGE("Invalid parameter");
2017 return NOTI_EX_ERROR_INVALID_PARAMETER;
2020 Handle* p = static_cast<Handle*>(handle);
2022 shared_ptr<AbstractAction>* ptr =
2023 static_cast<shared_ptr<AbstractAction>*>(action);
2024 p->Get()->SetAction(*ptr);
2025 return NOTI_EX_ERROR_NONE;
2028 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2029 noti_ex_style_h *style) {
2030 if (handle == nullptr || style == nullptr) {
2031 LOGE("Invalid parameter");
2032 return NOTI_EX_ERROR_INVALID_PARAMETER;
2035 Handle* p = static_cast<Handle*>(handle);
2036 shared_ptr<Style> s = p->Get()->GetStyle();
2037 if (s.get() == nullptr) {
2038 LOGE("Style is null");
2039 return NOTI_EX_ERROR_INVALID_PARAMETER;
2042 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2043 if (ptr == nullptr || ptr->get() == nullptr) {
2044 LOGE("Out of memory");
2045 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2049 return NOTI_EX_ERROR_NONE;
2052 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2053 noti_ex_style_h style) {
2054 if (handle == nullptr || style == nullptr) {
2055 LOGE("Invalid parameter");
2056 return NOTI_EX_ERROR_INVALID_PARAMETER;
2059 Handle* p = static_cast<Handle*>(handle);
2060 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2061 p->Get()->SetStyle(*s);
2062 return NOTI_EX_ERROR_NONE;
2065 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2067 if (handle == nullptr) {
2068 LOGE("Invalid parameter");
2069 return NOTI_EX_ERROR_INVALID_PARAMETER;
2072 Handle* p = static_cast<Handle*>(handle);
2073 p->Get()->SetVisible(visible);
2074 return NOTI_EX_ERROR_NONE;
2077 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2079 if (handle == nullptr || visible == nullptr) {
2080 LOGE("Invalid parameter");
2081 return NOTI_EX_ERROR_INVALID_PARAMETER;
2084 Handle* p = static_cast<Handle*>(handle);
2085 *visible = p->Get()->GetVisible();
2086 return NOTI_EX_ERROR_NONE;
2089 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2091 if (handle == nullptr) {
2092 LOGE("Invalid parameter");
2093 return NOTI_EX_ERROR_INVALID_PARAMETER;
2096 Handle* p = static_cast<Handle*>(handle);
2097 p->Get()->SetEnable(enable);
2098 return NOTI_EX_ERROR_NONE;
2101 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2103 if (handle == nullptr || enable == nullptr) {
2104 LOGE("Invalid parameter");
2105 return NOTI_EX_ERROR_INVALID_PARAMETER;
2108 Handle* p = static_cast<Handle*>(handle);
2109 *enable = p->Get()->GetEnable();
2110 return NOTI_EX_ERROR_NONE;
2113 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2114 const char *receiver_group) {
2115 if (handle == nullptr || receiver_group == nullptr) {
2116 LOGE("Invalid parameter");
2117 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 Handle* p = static_cast<Handle*>(handle);
2121 p->Get()->AddReceiver(receiver_group);
2122 return NOTI_EX_ERROR_NONE;
2125 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2126 const char *receiver_group) {
2127 if (handle == nullptr || receiver_group == nullptr) {
2128 LOGE("Invalid parameter");
2129 return NOTI_EX_ERROR_INVALID_PARAMETER;
2132 Handle* p = static_cast<Handle*>(handle);
2133 p->Get()->RemoveReceiver(receiver_group);
2134 return NOTI_EX_ERROR_NONE;
2137 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2138 char ***receiver_list, int *count) {
2139 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2140 LOGE("Invalid parameter");
2141 return NOTI_EX_ERROR_INVALID_PARAMETER;
2144 Handle* p = static_cast<Handle*>(handle);
2145 list<string> receivers = p->Get()->GetReceiverList();
2146 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2147 if (tmp_list == nullptr) {
2148 LOGE("Out of memory");
2149 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2153 for (auto& i : receivers) {
2154 tmp_list[idx] = strdup(i.c_str());
2155 if (tmp_list[idx] == nullptr) {
2156 __noti_ex_free_str_array(tmp_list, idx);
2157 LOGE("Out of memory");
2158 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2163 *receiver_list = tmp_list;
2164 *count = receivers.size();
2165 return NOTI_EX_ERROR_NONE;
2168 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2170 if (handle == nullptr) {
2171 LOGE("Invalid parameter");
2172 return NOTI_EX_ERROR_INVALID_PARAMETER;
2175 Handle* p = static_cast<Handle*>(handle);
2176 p->Get()->SetPolicy(policy);
2177 return NOTI_EX_ERROR_NONE;
2180 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2182 if (handle == nullptr || policy == nullptr) {
2183 LOGE("Invalid parameter");
2184 return NOTI_EX_ERROR_INVALID_PARAMETER;
2187 Handle* p = static_cast<Handle*>(handle);
2188 *policy = p->Get()->GetPolicy();
2189 return NOTI_EX_ERROR_NONE;
2192 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2194 if (handle == nullptr || channel == nullptr) {
2195 LOGE("Invalid parameter");
2196 return NOTI_EX_ERROR_INVALID_PARAMETER;
2199 Handle* p = static_cast<Handle*>(handle);
2200 if (!p->Get()->GetChannel().empty())
2201 *channel = strdup(p->Get()->GetChannel().c_str());
2205 return NOTI_EX_ERROR_NONE;
2208 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2209 const char *channel) {
2210 if (handle == nullptr) {
2211 LOGE("Invalid parameter");
2212 return NOTI_EX_ERROR_INVALID_PARAMETER;
2215 Handle* p = static_cast<Handle*>(handle);
2216 p->Get()->SetChannel(channel);
2217 return NOTI_EX_ERROR_NONE;
2220 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2221 noti_ex_led_info_h led) {
2222 if (handle == nullptr) {
2223 LOGE("Invalid parameter");
2224 return NOTI_EX_ERROR_INVALID_PARAMETER;
2227 Handle* p = static_cast<Handle*>(handle);
2228 if (led == nullptr) {
2229 p->Get()->SetLEDInfo(nullptr);
2230 return NOTI_EX_ERROR_NONE;
2232 shared_ptr<LEDInfo>* led_ptr =
2233 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2234 p->Get()->SetLEDInfo(*led_ptr);
2235 return NOTI_EX_ERROR_NONE;
2238 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2239 noti_ex_led_info_h *led) {
2240 if (handle == nullptr) {
2241 LOGE("Invalid parameter");
2242 return NOTI_EX_ERROR_INVALID_PARAMETER;
2245 Handle* p = static_cast<Handle*>(handle);
2246 if (p->Get()->GetLEDInfo() != nullptr)
2247 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2250 return NOTI_EX_ERROR_NONE;
2253 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2255 if (handle == nullptr) {
2256 LOGE("Invalid parameter");
2257 return NOTI_EX_ERROR_INVALID_PARAMETER;
2260 Handle* p = static_cast<Handle*>(handle);
2261 if (path == nullptr)
2262 p->Get()->SetSoundPath("");
2264 p->Get()->SetSoundPath(path);
2265 return NOTI_EX_ERROR_NONE;
2268 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2270 if (handle == nullptr) {
2271 LOGE("Invalid parameter");
2272 return NOTI_EX_ERROR_INVALID_PARAMETER;
2275 Handle* p = static_cast<Handle*>(handle);
2276 if (path == nullptr)
2277 p->Get()->SetVibrationPath("");
2279 p->Get()->SetVibrationPath(path);
2280 return NOTI_EX_ERROR_NONE;
2283 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2285 if (handle == nullptr || path == nullptr) {
2286 LOGE("Invalid parameter");
2287 return NOTI_EX_ERROR_INVALID_PARAMETER;
2290 Handle* p = static_cast<Handle*>(handle);
2291 if (p->Get()->GetSoundPath().empty())
2294 *path = strdup(p->Get()->GetSoundPath().c_str());
2295 return NOTI_EX_ERROR_NONE;
2298 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2300 if (handle == nullptr || path == nullptr) {
2301 LOGE("Invalid parameter");
2302 return NOTI_EX_ERROR_INVALID_PARAMETER;
2305 Handle* p = static_cast<Handle*>(handle);
2306 if (p->Get()->GetVibrationPath().empty())
2309 *path = strdup(p->Get()->GetVibrationPath().c_str());
2310 return NOTI_EX_ERROR_NONE;
2313 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2314 noti_ex_item_info_h *info) {
2315 if (handle == nullptr || info == nullptr) {
2316 LOGE("Invalid parameter");
2317 return NOTI_EX_ERROR_INVALID_PARAMETER;
2320 Handle* p = static_cast<Handle*>(handle);
2321 if (p->Get()->GetInfo() == nullptr)
2324 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2325 return NOTI_EX_ERROR_NONE;
2328 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2330 if (handle == nullptr || id == nullptr) {
2331 LOGE("Invalid parameter");
2332 return NOTI_EX_ERROR_INVALID_PARAMETER;
2335 Handle* p = static_cast<Handle*>(handle);
2336 if (p->Get()->GetSenderAppId().empty())
2339 *id = strdup(p->Get()->GetSenderAppId().c_str());
2340 return NOTI_EX_ERROR_NONE;
2343 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2345 if (handle == nullptr || tag == nullptr) {
2346 LOGE("Invalid parameter");
2347 return NOTI_EX_ERROR_INVALID_PARAMETER;
2350 Handle* p = static_cast<Handle*>(handle);
2351 if (p->Get()->GetTag().empty())
2354 *tag = strdup(p->Get()->GetTag().c_str());
2355 return NOTI_EX_ERROR_NONE;
2358 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2360 if (handle == nullptr) {
2361 LOGE("Invalid parameter");
2362 return NOTI_EX_ERROR_INVALID_PARAMETER;
2365 Handle* p = static_cast<Handle*>(handle);
2367 p->Get()->SetTag("");
2369 p->Get()->SetTag(tag);
2370 return NOTI_EX_ERROR_NONE;
2373 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2375 if (handle == nullptr || ongoing == nullptr) {
2376 LOGE("Invalid parameter");
2377 return NOTI_EX_ERROR_INVALID_PARAMETER;
2380 Handle* p = static_cast<Handle*>(handle);
2381 *ongoing = p->Get()->GetOnGoingState();
2383 return NOTI_EX_ERROR_NONE;
2386 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2388 if (handle == nullptr) {
2389 LOGE("Invalid parameter");
2390 return NOTI_EX_ERROR_INVALID_PARAMETER;
2393 Handle* p = static_cast<Handle*>(handle);
2394 p->Get()->SetOnGoingState(ongoing);
2396 return NOTI_EX_ERROR_NONE;
2399 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2400 int type, bool* exist) {
2401 if (handle == nullptr || exist == nullptr) {
2402 LOGE("Invalid parameter");
2403 return NOTI_EX_ERROR_INVALID_PARAMETER;
2406 Handle* p = static_cast<Handle*>(handle);
2407 *exist = p->Get()->IsItemTypeExist(type);
2409 return NOTI_EX_ERROR_NONE;
2412 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2414 if (handle == nullptr || type == nullptr) {
2415 LOGE("Invalid parameter");
2416 return NOTI_EX_ERROR_INVALID_PARAMETER;
2419 Handle* p = static_cast<Handle*>(handle);
2420 *type = p->Get()->GetMainType();
2422 return NOTI_EX_ERROR_NONE;
2425 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2426 const char* id, int type) {
2427 if (handle == nullptr || id == nullptr) {
2428 LOGE("Invalid parameter");
2429 return NOTI_EX_ERROR_INVALID_PARAMETER;
2432 Handle* p = static_cast<Handle*>(handle);
2433 if (!(p->Get()->SetMainType(string(id),
2434 static_cast<AbstractItem::MainType>(type))))
2435 return NOTI_EX_ERROR_INVALID_PARAMETER;
2437 return NOTI_EX_ERROR_NONE;
2440 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2441 int type, noti_ex_item_h* item) {
2442 if (handle == nullptr || item == nullptr) {
2443 LOGE("Invalid parameter");
2444 return NOTI_EX_ERROR_INVALID_PARAMETER;
2447 Handle* h = static_cast<Handle*>(handle);
2448 if (!h->IsValidType(AbstractItem::Group)) {
2449 LOGE("Invalid handle type");
2450 return NOTI_EX_ERROR_INVALID_PARAMETER;
2453 GroupItem* p = static_cast<GroupItem*>(h->Get());
2454 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2455 *item = new Handle(&find_item);
2457 return NOTI_EX_ERROR_NONE;
2460 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2461 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2463 if (handle == nullptr) {
2464 LOGE("Invalid parameter");
2465 return NOTI_EX_ERROR_INVALID_PARAMETER;
2468 string receiver_group_str = "";
2470 receiver_group_str = string(receiver_group);
2472 ManagerStub* stub = new (std::nothrow) ManagerStub(
2473 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2474 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2475 receiver_group_str);
2476 if (stub == nullptr) {
2477 LOGE("Fail to create manager");
2478 return NOTI_EX_ERROR_IO_ERROR;
2480 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2481 new ManagerCallbackInfo(event_callbacks, data)));
2482 *handle = static_cast<noti_ex_manager_h>(stub);
2484 return NOTI_EX_ERROR_NONE;
2487 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2488 if (handle == nullptr) {
2489 LOGE("Invalid parameter");
2490 return NOTI_EX_ERROR_INVALID_PARAMETER;
2492 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2494 return NOTI_EX_ERROR_NONE;
2497 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2498 noti_ex_item_h **items, int *count) {
2499 if (handle == nullptr || items == nullptr || count == nullptr) {
2500 LOGE("Invalid parameter");
2501 return NOTI_EX_ERROR_INVALID_PARAMETER;
2505 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2506 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2507 if (item_list.size() == 0) {
2510 return NOTI_EX_ERROR_NONE;
2512 noti_ex_item_h* added_item =
2513 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2514 if (added_item == nullptr) {
2515 LOGE("Fail to create items");
2516 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2520 for (auto& i : item_list) {
2521 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2523 *items = added_item;
2524 *count = item_list.size();
2525 } catch (Exception &ex) {
2526 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2527 return NOTI_EX_ERROR_IO_ERROR;
2529 return NOTI_EX_ERROR_NONE;
2532 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2533 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2534 if (handle == nullptr || channel == nullptr ||
2535 items == nullptr || count == nullptr) {
2536 LOGE("Invalid parameter");
2537 return NOTI_EX_ERROR_INVALID_PARAMETER;
2541 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2542 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2543 if (item_list.size() == 0) {
2546 return NOTI_EX_ERROR_NONE;
2548 noti_ex_item_h* added_item =
2549 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2550 if (added_item == nullptr) {
2551 LOGE("Fail to create items");
2552 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2556 for (auto& i : item_list) {
2557 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2559 *items = added_item;
2560 *count = item_list.size();
2561 } catch (Exception &ex) {
2562 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2563 return NOTI_EX_ERROR_IO_ERROR;
2566 return NOTI_EX_ERROR_NONE;
2569 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2570 noti_ex_item_h noti, int *request_id) {
2571 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2572 LOGE("Invalid parameter");
2573 return NOTI_EX_ERROR_INVALID_PARAMETER;
2576 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2577 Handle* sp = static_cast<Handle*>(noti);
2578 if (sp->GetPtr().get() == nullptr) {
2579 LOGE("Invalid noti reference can not be sended");
2580 return NOTI_EX_ERROR_INVALID_PARAMETER;
2582 *request_id = stub->Update(sp->GetPtr());
2584 } catch (Exception &ex) {
2585 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2586 return NOTI_EX_ERROR_IO_ERROR;
2588 return NOTI_EX_ERROR_NONE;
2591 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2592 noti_ex_item_h noti, int *request_id) {
2593 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2594 LOGE("Invalid parameter");
2595 return NOTI_EX_ERROR_INVALID_PARAMETER;
2598 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2599 Handle* item = static_cast<Handle*>(noti);
2600 if (item->GetPtr().get() == nullptr) {
2601 LOGE("Invalid noti reference can not be sended");
2602 return NOTI_EX_ERROR_INVALID_PARAMETER;
2604 *request_id = stub->Delete(item->GetPtr());
2606 } catch (Exception &ex) {
2607 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2608 return NOTI_EX_ERROR_IO_ERROR;
2610 return NOTI_EX_ERROR_NONE;
2613 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2615 if (handle == nullptr || request_id == nullptr) {
2616 LOGE("Invalid parameter");
2617 return NOTI_EX_ERROR_INVALID_PARAMETER;
2620 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2621 *request_id = stub->DeleteAll();
2622 } catch (Exception &ex) {
2623 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2624 return NOTI_EX_ERROR_IO_ERROR;
2626 return NOTI_EX_ERROR_NONE;
2629 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2630 noti_ex_item_h noti, int *request_id) {
2631 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2632 LOGE("Invalid parameter");
2633 return NOTI_EX_ERROR_INVALID_PARAMETER;
2636 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2637 Handle* item = static_cast<Handle*>(noti);
2638 if (item->GetPtr().get() == nullptr) {
2639 LOGE("Invalid noti reference can not be sended");
2640 return NOTI_EX_ERROR_INVALID_PARAMETER;
2642 *request_id = stub->Hide(item->GetPtr());
2644 } catch (Exception &ex) {
2645 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2646 return NOTI_EX_ERROR_IO_ERROR;
2648 return NOTI_EX_ERROR_NONE;
2651 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2652 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2653 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2654 LOGE("Invalid parameter");
2655 return NOTI_EX_ERROR_INVALID_PARAMETER;
2658 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2659 *item = new Handle(stub->FindByRootID(root_id));
2660 } catch (Exception &ex) {
2661 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2662 return NOTI_EX_ERROR_IO_ERROR;
2664 return NOTI_EX_ERROR_NONE;
2667 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2668 noti_ex_event_info_h info, noti_ex_error_e error) {
2669 if (handle == nullptr || info == nullptr) {
2670 LOGE("Invalid parameter");
2671 return NOTI_EX_ERROR_INVALID_PARAMETER;
2674 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2675 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2676 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2677 static_cast<NotificationError>(error));
2678 } catch (Exception &ex) {
2679 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2680 return NOTI_EX_ERROR_IO_ERROR;
2682 return NOTI_EX_ERROR_NONE;
2685 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2686 noti_ex_manager_h handle, int *cnt) {
2688 if (handle == nullptr || cnt == nullptr) {
2689 LOGE("Invalid parameter");
2690 return NOTI_EX_ERROR_INVALID_PARAMETER;
2693 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2694 *cnt = stub->GetCount();
2695 } catch (Exception &ex) {
2696 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2697 return NOTI_EX_ERROR_IO_ERROR;
2699 return NOTI_EX_ERROR_NONE;
2702 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2703 const char *id, float min, float current, float max) {
2706 if (handle == nullptr) {
2707 LOGE("Invalid parameter");
2708 return NOTI_EX_ERROR_INVALID_PARAMETER;
2712 p = new (std::nothrow) ProgressItem(id, min, current, max);
2714 p = new (std::nothrow) ProgressItem(min, current, max);
2717 LOGE("Out-of-memory");
2718 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2721 *handle = new Handle(shared_ptr<AbstractItem>(p));
2723 return NOTI_EX_ERROR_NONE;
2726 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2727 noti_ex_item_h handle, float *current) {
2728 if (handle == nullptr || current == nullptr) {
2729 LOGE("Invalid parameter");
2730 return NOTI_EX_ERROR_INVALID_PARAMETER;
2733 Handle *h = static_cast<Handle*>(handle);
2734 if (!h->IsValidType(AbstractItem::Progress)) {
2735 LOGE("Invalid handle type");
2736 return NOTI_EX_ERROR_INVALID_PARAMETER;
2738 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2739 *current = p->GetCurrent();
2741 return NOTI_EX_ERROR_NONE;
2744 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2745 noti_ex_item_h handle, float current) {
2746 if (handle == nullptr) {
2747 LOGE("Invalid parameter");
2748 return NOTI_EX_ERROR_INVALID_PARAMETER;
2751 Handle *h = static_cast<Handle*>(handle);
2752 if (!h->IsValidType(AbstractItem::Progress)) {
2753 LOGE("Invalid handle type");
2754 return NOTI_EX_ERROR_INVALID_PARAMETER;
2756 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2757 p->SetCurrent(current);
2759 return NOTI_EX_ERROR_NONE;
2762 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2764 if (handle == nullptr || min == nullptr) {
2765 LOGE("Invalid parameter");
2766 return NOTI_EX_ERROR_INVALID_PARAMETER;
2769 Handle *h = static_cast<Handle*>(handle);
2770 if (!h->IsValidType(AbstractItem::Progress)) {
2771 LOGE("Invalid handle type");
2772 return NOTI_EX_ERROR_INVALID_PARAMETER;
2774 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2777 return NOTI_EX_ERROR_NONE;
2780 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2782 if (handle == nullptr || max == nullptr) {
2783 LOGE("Invalid parameter");
2784 return NOTI_EX_ERROR_INVALID_PARAMETER;
2787 Handle *h = static_cast<Handle*>(handle);
2788 if (!h->IsValidType(AbstractItem::Progress)) {
2789 LOGE("Invalid handle type");
2790 return NOTI_EX_ERROR_INVALID_PARAMETER;
2792 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2795 return NOTI_EX_ERROR_NONE;
2798 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2800 if (handle == nullptr || type == nullptr) {
2801 LOGE("Invalid parameter");
2802 return NOTI_EX_ERROR_INVALID_PARAMETER;
2805 Handle *h = static_cast<Handle*>(handle);
2806 if (!h->IsValidType(AbstractItem::Progress)) {
2807 LOGE("Invalid handle type");
2808 return NOTI_EX_ERROR_INVALID_PARAMETER;
2810 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2811 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2813 return NOTI_EX_ERROR_NONE;
2816 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2818 if (handle == nullptr) {
2819 LOGE("Invalid parameter");
2820 return NOTI_EX_ERROR_INVALID_PARAMETER;
2823 Handle *h = static_cast<Handle*>(handle);
2824 if (!h->IsValidType(AbstractItem::Progress)) {
2825 LOGE("Invalid handle type");
2826 return NOTI_EX_ERROR_INVALID_PARAMETER;
2828 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2829 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2831 return NOTI_EX_ERROR_NONE;
2834 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2835 noti_ex_reporter_events_s event_callbacks, void *data) {
2836 if (handle == nullptr) {
2837 LOGE("Invalid parameter");
2838 return NOTI_EX_ERROR_INVALID_PARAMETER;
2841 ReporterStub* stub = new (std::nothrow) ReporterStub(
2842 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2843 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2844 if (stub == nullptr) {
2845 LOGE("Fail to create manager");
2846 return NOTI_EX_ERROR_IO_ERROR;
2848 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2849 new ReporterCallbackInfo(event_callbacks, data)));
2851 *handle = static_cast<noti_ex_reporter_h>(stub);
2853 return NOTI_EX_ERROR_NONE;
2856 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2857 if (handle == nullptr) {
2858 LOGE("Invalid parameter");
2859 return NOTI_EX_ERROR_INVALID_PARAMETER;
2861 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2863 return NOTI_EX_ERROR_NONE;
2866 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2867 noti_ex_event_info_h info, noti_ex_error_e error) {
2868 if (handle == nullptr || info == nullptr) {
2869 LOGE("Invalid parameter");
2870 return NOTI_EX_ERROR_INVALID_PARAMETER;
2873 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2874 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2875 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2876 static_cast<NotificationError>(error));
2877 } catch (Exception &ex) {
2878 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2879 return NOTI_EX_ERROR_IO_ERROR;
2881 return NOTI_EX_ERROR_NONE;
2884 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2885 noti_ex_item_h noti, int *request_id) {
2886 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2887 LOGE("Invalid parameter");
2888 return NOTI_EX_ERROR_INVALID_PARAMETER;
2891 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2892 Handle* h = static_cast<Handle*>(noti);
2893 if (h->GetPtr().get() == nullptr) {
2894 LOGE("Invalid noti reference can not be sended");
2895 return NOTI_EX_ERROR_INVALID_PARAMETER;
2897 *request_id = stub->Post(h->GetPtr());
2899 } catch (Exception &ex) {
2900 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2901 return NOTI_EX_ERROR_IO_ERROR;
2903 return NOTI_EX_ERROR_NONE;
2906 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2907 noti_ex_item_h *noti_list, int count, int *request_id) {
2909 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2910 LOGE("Invalid parameter");
2911 return NOTI_EX_ERROR_INVALID_PARAMETER;
2914 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2915 list<shared_ptr<item::AbstractItem>> notiList;
2916 for (int i = 0; i < count; i++) {
2917 Handle* item = static_cast<Handle*>(noti_list[i]);
2918 notiList.push_back(item->GetPtr());
2920 *request_id = stub->Post(notiList);
2921 } catch (Exception &ex) {
2922 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2923 return NOTI_EX_ERROR_IO_ERROR;
2925 return NOTI_EX_ERROR_NONE;
2928 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2929 noti_ex_item_h noti, int *request_id) {
2930 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2931 LOGE("Invalid parameter");
2932 return NOTI_EX_ERROR_INVALID_PARAMETER;
2935 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2936 Handle* item = static_cast<Handle*>(noti);
2937 if (item->GetPtr().get() == nullptr) {
2938 LOGE("Invalid noti reference can not be sended");
2939 return NOTI_EX_ERROR_INVALID_PARAMETER;
2941 *request_id = stub->Update(item->GetPtr());
2943 } catch (Exception &ex) {
2944 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2945 return NOTI_EX_ERROR_IO_ERROR;
2947 return NOTI_EX_ERROR_NONE;
2950 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2951 noti_ex_item_h noti, int *request_id) {
2952 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2953 LOGE("Invalid parameter");
2954 return NOTI_EX_ERROR_INVALID_PARAMETER;
2957 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2958 Handle* item = static_cast<Handle*>(noti);
2959 if (item->GetPtr().get() == nullptr) {
2960 LOGE("Invalid noti reference can not be sended");
2961 return NOTI_EX_ERROR_INVALID_PARAMETER;
2963 *request_id = stub->Delete(item->GetPtr());
2965 } catch (Exception &ex) {
2966 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2967 return NOTI_EX_ERROR_IO_ERROR;
2969 return NOTI_EX_ERROR_NONE;
2972 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2973 noti_ex_reporter_h handle, int *request_id) {
2974 if (handle == nullptr || request_id == nullptr) {
2975 LOGE("Invalid parameter");
2976 return NOTI_EX_ERROR_INVALID_PARAMETER;
2979 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2980 *request_id = stub->DeleteAll();
2981 } catch (Exception &ex) {
2982 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2983 return NOTI_EX_ERROR_IO_ERROR;
2985 return NOTI_EX_ERROR_NONE;
2988 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2989 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2990 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2991 LOGE("Invalid parameter");
2992 return NOTI_EX_ERROR_INVALID_PARAMETER;
2995 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2996 *item = new Handle(stub->FindByRootID(root_id));
2997 } catch (Exception &ex) {
2998 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2999 return NOTI_EX_ERROR_IO_ERROR;
3001 return NOTI_EX_ERROR_NONE;
3004 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3005 const char *id, const char *text, const char *hyperlink) {
3006 if (handle == nullptr || text == nullptr) {
3007 LOGE("Invalid parameter");
3008 return NOTI_EX_ERROR_INVALID_PARAMETER;
3014 p = new (std::nothrow) TextItem(id, std::string(text),
3015 std::string(hyperlink));
3017 p = new (std::nothrow) TextItem(id, std::string(text));
3020 LOGE("Out-of-memory");
3021 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3024 *handle = new Handle(shared_ptr<AbstractItem>(p));
3026 return NOTI_EX_ERROR_NONE;
3029 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3030 const char *contents) {
3031 if (handle == nullptr || contents == nullptr) {
3032 LOGE("Invalid parameter");
3033 return NOTI_EX_ERROR_INVALID_PARAMETER;
3036 Handle* p = static_cast<Handle*>(handle);
3037 if (!p->IsValidType(AbstractItem::Text)) {
3038 LOGE("Invalid handle type");
3039 return NOTI_EX_ERROR_INVALID_PARAMETER;
3041 TextItem* ti = static_cast<TextItem*>(p->Get());
3042 ti->SetContents(std::string(contents));
3044 return NOTI_EX_ERROR_NONE;
3047 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3049 if (handle == nullptr || contents == nullptr) {
3050 LOGE("Invalid parameter");
3051 return NOTI_EX_ERROR_INVALID_PARAMETER;
3054 Handle* p = static_cast<Handle*>(handle);
3055 if (!p->IsValidType(AbstractItem::Text)) {
3056 LOGE("Invalid handle type");
3057 return NOTI_EX_ERROR_INVALID_PARAMETER;
3060 TextItem* ti = static_cast<TextItem*>(p->Get());
3062 if (ti->GetMultiLanguage() != nullptr &&
3063 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3064 str = ti->GetMultiLanguage()->GetTranslatedString();
3065 else if (!ti->GetContents().empty())
3066 str = ti->GetContents();
3068 *contents = strdup(str.c_str());
3069 if (*contents == nullptr) {
3070 LOGE("Out-of-memory");
3071 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3074 return NOTI_EX_ERROR_NONE;
3077 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3078 noti_ex_item_h handle, char **hyper_link) {
3079 if (handle == nullptr || hyper_link == nullptr) {
3080 LOGE("Invalid parameter");
3081 return NOTI_EX_ERROR_INVALID_PARAMETER;
3084 Handle* p = static_cast<Handle*>(handle);
3085 if (!p->IsValidType(AbstractItem::Text)) {
3086 LOGE("Invalid handle type");
3087 return NOTI_EX_ERROR_INVALID_PARAMETER;
3089 TextItem* ti = static_cast<TextItem*>(p->Get());
3090 if (!ti->GetHyperLink().empty()) {
3091 *hyper_link = strdup(ti->GetHyperLink().c_str());
3092 if (*hyper_link == nullptr) {
3093 LOGE("Out-of-memory");
3094 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3098 return NOTI_EX_ERROR_NONE;
3101 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3102 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3103 if (handle == nullptr) {
3104 LOGE("Invalid parameter");
3105 return NOTI_EX_ERROR_INVALID_PARAMETER;
3108 Handle* p = static_cast<Handle*>(handle);
3109 if (!p->IsValidType(AbstractItem::Text)) {
3110 LOGE("Invalid handle type");
3111 return NOTI_EX_ERROR_INVALID_PARAMETER;
3114 TextItem* ti = static_cast<TextItem*>(p->Get());
3115 if (multi == nullptr) {
3116 ti->SetMultiLanguage(nullptr);
3117 return NOTI_EX_ERROR_NONE;
3120 shared_ptr<MultiLanguage> mul_ptr =
3121 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3122 ti->SetMultiLanguage(mul_ptr);
3123 ti->GetMultiLanguage()->UpdateString();
3125 return NOTI_EX_ERROR_NONE;
3128 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3129 const char *id, time_t time) {
3132 if (handle == nullptr) {
3133 LOGE("Invalid parameter");
3134 return NOTI_EX_ERROR_INVALID_PARAMETER;
3139 p = new (std::nothrow) TimeItem(id, time);
3141 p = new (std::nothrow) TimeItem(time);
3143 p = new (std::nothrow) TimeItem();
3147 LOGE("Out-of-memory");
3148 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3151 *handle = new Handle(shared_ptr<AbstractItem>(p));
3153 return NOTI_EX_ERROR_NONE;
3156 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3158 if (handle == nullptr || time == nullptr) {
3159 LOGE("Invalid parameter");
3160 return NOTI_EX_ERROR_INVALID_PARAMETER;
3162 Handle* h = static_cast<Handle*>(handle);
3163 if (!h->IsValidType(AbstractItem::Time)) {
3164 LOGE("Invalid handle type");
3165 return NOTI_EX_ERROR_INVALID_PARAMETER;
3167 TimeItem* p = static_cast<TimeItem*>(h->Get());
3168 *time = p->GetTime();
3170 return NOTI_EX_ERROR_NONE;
3173 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3175 if (handle == nullptr) {
3176 LOGE("Invalid parameter");
3177 return NOTI_EX_ERROR_INVALID_PARAMETER;
3179 Handle* h = static_cast<Handle*>(handle);
3180 if (!h->IsValidType(AbstractItem::Time)) {
3181 LOGE("Invalid handle type");
3182 return NOTI_EX_ERROR_INVALID_PARAMETER;
3184 TimeItem* p = static_cast<TimeItem*>(h->Get());
3187 return NOTI_EX_ERROR_NONE;
3190 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3191 noti_ex_action_h *handle, const char *extra) {
3192 if (handle == nullptr) {
3193 LOGE("Invalid parameter");
3194 return NOTI_EX_ERROR_INVALID_PARAMETER;
3197 string extra_str = "";
3199 extra_str = string(extra);
3201 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3202 new (std::nothrow) VisibilityAction(extra_str));
3203 if (ptr == nullptr) {
3204 LOGE("Out-of-memory");
3205 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3210 return NOTI_EX_ERROR_NONE;
3213 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3214 const char *id, bool visible) {
3215 if (handle == nullptr || id == nullptr) {
3216 LOGE("Invalid parameter");
3217 return NOTI_EX_ERROR_INVALID_PARAMETER;
3220 shared_ptr<AbstractAction>* ptr =
3221 static_cast<shared_ptr<AbstractAction>*>(handle);
3222 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3223 action->SetVisibility(id, visible);
3225 return NOTI_EX_ERROR_NONE;
3228 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3229 const char* msgid, const char* format, ...) {
3230 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3231 LOGE("Invalid parameter");
3232 return NOTI_EX_ERROR_INVALID_PARAMETER;
3235 const char* format_idx = format;
3238 va_start(args, format);
3239 while (*format_idx != '\0') {
3240 char* arg = nullptr;
3243 stringstream stream;
3244 if (*format_idx == '%') {
3245 switch (*(format_idx + 1)) {
3247 arg = va_arg(args, char *);
3248 arr.push_back(string(arg));
3251 arg_i = va_arg(args, int);
3252 arr.push_back(to_string(arg_i));
3255 arg_f = va_arg(args, double);
3256 stream << std::fixed << std::setprecision(2) << arg_f;
3257 arr.push_back(stream.str());
3265 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3267 LOGE("Out-of-memory");
3268 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3270 *handle = new shared_ptr<MultiLanguage>(p);
3272 return NOTI_EX_ERROR_NONE;
3275 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3276 if (handle == nullptr) {
3277 LOGE("Invalid parameter");
3278 return NOTI_EX_ERROR_INVALID_PARAMETER;
3281 shared_ptr<MultiLanguage>* mul_ptr =
3282 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3284 return NOTI_EX_ERROR_NONE;
3287 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3288 noti_ex_item_h item, int64_t* private_id) {
3289 if (item == nullptr || private_id == nullptr) {
3290 LOGE("Invalid parameter");
3291 return NOTI_EX_ERROR_INVALID_PARAMETER;
3294 Handle* h = static_cast<Handle*>(item);
3295 *private_id = static_pointer_cast<IItemInfoInternal>(
3296 h->Get()->GetInfo())->GetPrivateId();
3298 return NOTI_EX_ERROR_NONE;
3301 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3302 noti_ex_item_h item, int64_t priv_id) {
3303 if (item == nullptr) {
3304 LOGE("Invalid parameter");
3305 return NOTI_EX_ERROR_INVALID_PARAMETER;
3308 Handle* h = static_cast<Handle*>(item);
3309 static_pointer_cast<IItemInfoInternal>(
3310 h->Get()->GetInfo())->SetPrivateId(priv_id);
3312 return NOTI_EX_ERROR_NONE;
3315 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3316 if (list == nullptr) {
3317 LOGE("Invalid parameter");
3318 return NOTI_EX_ERROR_INVALID_PARAMETER;
3321 LOGI("Free strings (%d)", count);
3322 for (int i = 0; i < count; i++)
3326 return NOTI_EX_ERROR_NONE;
3329 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3330 if (handle == nullptr) {
3331 LOGE("Invalid parameter");
3332 return NOTI_EX_ERROR_INVALID_PARAMETER;
3334 Handle* h = static_cast<Handle*>(handle);
3335 if (!h->IsValidType(AbstractItem::Group)) {
3336 LOGE("Invalid handle type");
3337 return NOTI_EX_ERROR_INVALID_PARAMETER;
3339 GroupItem* p = static_cast<GroupItem*>(h->Get());
3340 p->RemoveChildren();
3342 return NOTI_EX_ERROR_NONE;