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 == nullptr || s.get() == nullptr) {
2038 LOGW("Style is null");
2040 return NOTI_EX_ERROR_NONE;
2043 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2044 if (ptr == nullptr || ptr->get() == nullptr) {
2045 LOGE("Out of memory");
2046 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2050 return NOTI_EX_ERROR_NONE;
2053 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2054 noti_ex_style_h style) {
2055 if (handle == nullptr || style == nullptr) {
2056 LOGE("Invalid parameter");
2057 return NOTI_EX_ERROR_INVALID_PARAMETER;
2060 Handle* p = static_cast<Handle*>(handle);
2061 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2062 p->Get()->SetStyle(*s);
2063 return NOTI_EX_ERROR_NONE;
2066 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2068 if (handle == nullptr) {
2069 LOGE("Invalid parameter");
2070 return NOTI_EX_ERROR_INVALID_PARAMETER;
2073 Handle* p = static_cast<Handle*>(handle);
2074 p->Get()->SetVisible(visible);
2075 return NOTI_EX_ERROR_NONE;
2078 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2080 if (handle == nullptr || visible == nullptr) {
2081 LOGE("Invalid parameter");
2082 return NOTI_EX_ERROR_INVALID_PARAMETER;
2085 Handle* p = static_cast<Handle*>(handle);
2086 *visible = p->Get()->GetVisible();
2087 return NOTI_EX_ERROR_NONE;
2090 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2092 if (handle == nullptr) {
2093 LOGE("Invalid parameter");
2094 return NOTI_EX_ERROR_INVALID_PARAMETER;
2097 Handle* p = static_cast<Handle*>(handle);
2098 p->Get()->SetEnable(enable);
2099 return NOTI_EX_ERROR_NONE;
2102 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2104 if (handle == nullptr || enable == nullptr) {
2105 LOGE("Invalid parameter");
2106 return NOTI_EX_ERROR_INVALID_PARAMETER;
2109 Handle* p = static_cast<Handle*>(handle);
2110 *enable = p->Get()->GetEnable();
2111 return NOTI_EX_ERROR_NONE;
2114 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2115 const char *receiver_group) {
2116 if (handle == nullptr || receiver_group == nullptr) {
2117 LOGE("Invalid parameter");
2118 return NOTI_EX_ERROR_INVALID_PARAMETER;
2121 Handle* p = static_cast<Handle*>(handle);
2122 p->Get()->AddReceiver(receiver_group);
2123 return NOTI_EX_ERROR_NONE;
2126 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2127 const char *receiver_group) {
2128 if (handle == nullptr || receiver_group == nullptr) {
2129 LOGE("Invalid parameter");
2130 return NOTI_EX_ERROR_INVALID_PARAMETER;
2133 Handle* p = static_cast<Handle*>(handle);
2134 p->Get()->RemoveReceiver(receiver_group);
2135 return NOTI_EX_ERROR_NONE;
2138 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2139 char ***receiver_list, int *count) {
2140 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2141 LOGE("Invalid parameter");
2142 return NOTI_EX_ERROR_INVALID_PARAMETER;
2145 Handle* p = static_cast<Handle*>(handle);
2146 list<string> receivers = p->Get()->GetReceiverList();
2147 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2148 if (tmp_list == nullptr) {
2149 LOGE("Out of memory");
2150 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2154 for (auto& i : receivers) {
2155 tmp_list[idx] = strdup(i.c_str());
2156 if (tmp_list[idx] == nullptr) {
2157 __noti_ex_free_str_array(tmp_list, idx);
2158 LOGE("Out of memory");
2159 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2164 *receiver_list = tmp_list;
2165 *count = receivers.size();
2166 return NOTI_EX_ERROR_NONE;
2169 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2171 if (handle == nullptr) {
2172 LOGE("Invalid parameter");
2173 return NOTI_EX_ERROR_INVALID_PARAMETER;
2176 Handle* p = static_cast<Handle*>(handle);
2177 p->Get()->SetPolicy(policy);
2178 return NOTI_EX_ERROR_NONE;
2181 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2183 if (handle == nullptr || policy == nullptr) {
2184 LOGE("Invalid parameter");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2188 Handle* p = static_cast<Handle*>(handle);
2189 *policy = p->Get()->GetPolicy();
2190 return NOTI_EX_ERROR_NONE;
2193 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2195 if (handle == nullptr || channel == nullptr) {
2196 LOGE("Invalid parameter");
2197 return NOTI_EX_ERROR_INVALID_PARAMETER;
2200 Handle* p = static_cast<Handle*>(handle);
2201 if (!p->Get()->GetChannel().empty())
2202 *channel = strdup(p->Get()->GetChannel().c_str());
2206 return NOTI_EX_ERROR_NONE;
2209 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2210 const char *channel) {
2211 if (handle == nullptr) {
2212 LOGE("Invalid parameter");
2213 return NOTI_EX_ERROR_INVALID_PARAMETER;
2216 Handle* p = static_cast<Handle*>(handle);
2217 p->Get()->SetChannel(channel);
2218 return NOTI_EX_ERROR_NONE;
2221 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2222 noti_ex_led_info_h led) {
2223 if (handle == nullptr) {
2224 LOGE("Invalid parameter");
2225 return NOTI_EX_ERROR_INVALID_PARAMETER;
2228 Handle* p = static_cast<Handle*>(handle);
2229 if (led == nullptr) {
2230 p->Get()->SetLEDInfo(nullptr);
2231 return NOTI_EX_ERROR_NONE;
2233 shared_ptr<LEDInfo>* led_ptr =
2234 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2235 p->Get()->SetLEDInfo(*led_ptr);
2236 return NOTI_EX_ERROR_NONE;
2239 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2240 noti_ex_led_info_h *led) {
2241 if (handle == nullptr) {
2242 LOGE("Invalid parameter");
2243 return NOTI_EX_ERROR_INVALID_PARAMETER;
2246 Handle* p = static_cast<Handle*>(handle);
2247 if (p->Get()->GetLEDInfo() != nullptr)
2248 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2251 return NOTI_EX_ERROR_NONE;
2254 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2256 if (handle == nullptr) {
2257 LOGE("Invalid parameter");
2258 return NOTI_EX_ERROR_INVALID_PARAMETER;
2261 Handle* p = static_cast<Handle*>(handle);
2262 if (path == nullptr)
2263 p->Get()->SetSoundPath("");
2265 p->Get()->SetSoundPath(path);
2266 return NOTI_EX_ERROR_NONE;
2269 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2271 if (handle == nullptr) {
2272 LOGE("Invalid parameter");
2273 return NOTI_EX_ERROR_INVALID_PARAMETER;
2276 Handle* p = static_cast<Handle*>(handle);
2277 if (path == nullptr)
2278 p->Get()->SetVibrationPath("");
2280 p->Get()->SetVibrationPath(path);
2281 return NOTI_EX_ERROR_NONE;
2284 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2286 if (handle == nullptr || path == nullptr) {
2287 LOGE("Invalid parameter");
2288 return NOTI_EX_ERROR_INVALID_PARAMETER;
2291 Handle* p = static_cast<Handle*>(handle);
2292 if (p->Get()->GetSoundPath().empty())
2295 *path = strdup(p->Get()->GetSoundPath().c_str());
2296 return NOTI_EX_ERROR_NONE;
2299 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2301 if (handle == nullptr || path == nullptr) {
2302 LOGE("Invalid parameter");
2303 return NOTI_EX_ERROR_INVALID_PARAMETER;
2306 Handle* p = static_cast<Handle*>(handle);
2307 if (p->Get()->GetVibrationPath().empty())
2310 *path = strdup(p->Get()->GetVibrationPath().c_str());
2311 return NOTI_EX_ERROR_NONE;
2314 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2315 noti_ex_item_info_h *info) {
2316 if (handle == nullptr || info == nullptr) {
2317 LOGE("Invalid parameter");
2318 return NOTI_EX_ERROR_INVALID_PARAMETER;
2321 Handle* p = static_cast<Handle*>(handle);
2322 if (p->Get()->GetInfo() == nullptr)
2325 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2331 if (handle == nullptr || id == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 Handle* p = static_cast<Handle*>(handle);
2337 if (p->Get()->GetSenderAppId().empty())
2340 *id = strdup(p->Get()->GetSenderAppId().c_str());
2341 return NOTI_EX_ERROR_NONE;
2344 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2346 if (handle == nullptr || tag == nullptr) {
2347 LOGE("Invalid parameter");
2348 return NOTI_EX_ERROR_INVALID_PARAMETER;
2351 Handle* p = static_cast<Handle*>(handle);
2352 if (p->Get()->GetTag().empty())
2355 *tag = strdup(p->Get()->GetTag().c_str());
2356 return NOTI_EX_ERROR_NONE;
2359 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2361 if (handle == nullptr) {
2362 LOGE("Invalid parameter");
2363 return NOTI_EX_ERROR_INVALID_PARAMETER;
2366 Handle* p = static_cast<Handle*>(handle);
2368 p->Get()->SetTag("");
2370 p->Get()->SetTag(tag);
2371 return NOTI_EX_ERROR_NONE;
2374 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2376 if (handle == nullptr || ongoing == nullptr) {
2377 LOGE("Invalid parameter");
2378 return NOTI_EX_ERROR_INVALID_PARAMETER;
2381 Handle* p = static_cast<Handle*>(handle);
2382 *ongoing = p->Get()->GetOnGoingState();
2384 return NOTI_EX_ERROR_NONE;
2387 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2389 if (handle == nullptr) {
2390 LOGE("Invalid parameter");
2391 return NOTI_EX_ERROR_INVALID_PARAMETER;
2394 Handle* p = static_cast<Handle*>(handle);
2395 p->Get()->SetOnGoingState(ongoing);
2397 return NOTI_EX_ERROR_NONE;
2400 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2401 int type, bool* exist) {
2402 if (handle == nullptr || exist == nullptr) {
2403 LOGE("Invalid parameter");
2404 return NOTI_EX_ERROR_INVALID_PARAMETER;
2407 Handle* p = static_cast<Handle*>(handle);
2408 *exist = p->Get()->IsItemTypeExist(type);
2410 return NOTI_EX_ERROR_NONE;
2413 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2415 if (handle == nullptr || type == nullptr) {
2416 LOGE("Invalid parameter");
2417 return NOTI_EX_ERROR_INVALID_PARAMETER;
2420 Handle* p = static_cast<Handle*>(handle);
2421 *type = p->Get()->GetMainType();
2423 return NOTI_EX_ERROR_NONE;
2426 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2427 const char* id, int type) {
2428 if (handle == nullptr || id == nullptr) {
2429 LOGE("Invalid parameter");
2430 return NOTI_EX_ERROR_INVALID_PARAMETER;
2433 Handle* p = static_cast<Handle*>(handle);
2434 if (!(p->Get()->SetMainType(string(id),
2435 static_cast<AbstractItem::MainType>(type))))
2436 return NOTI_EX_ERROR_INVALID_PARAMETER;
2438 return NOTI_EX_ERROR_NONE;
2441 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2442 int type, noti_ex_item_h* item) {
2443 if (handle == nullptr || item == nullptr) {
2444 LOGE("Invalid parameter");
2445 return NOTI_EX_ERROR_INVALID_PARAMETER;
2448 Handle* h = static_cast<Handle*>(handle);
2449 if (!h->IsValidType(AbstractItem::Group)) {
2450 LOGE("Invalid handle type");
2451 return NOTI_EX_ERROR_INVALID_PARAMETER;
2454 GroupItem* p = static_cast<GroupItem*>(h->Get());
2455 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2456 *item = new Handle(&find_item);
2458 return NOTI_EX_ERROR_NONE;
2461 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2462 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2464 if (handle == nullptr) {
2465 LOGE("Invalid parameter");
2466 return NOTI_EX_ERROR_INVALID_PARAMETER;
2469 string receiver_group_str = "";
2471 receiver_group_str = string(receiver_group);
2473 ManagerStub* stub = new (std::nothrow) ManagerStub(
2474 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2475 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2476 receiver_group_str);
2477 if (stub == nullptr) {
2478 LOGE("Fail to create manager");
2479 return NOTI_EX_ERROR_IO_ERROR;
2481 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2482 new ManagerCallbackInfo(event_callbacks, data)));
2483 *handle = static_cast<noti_ex_manager_h>(stub);
2485 return NOTI_EX_ERROR_NONE;
2488 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2489 if (handle == nullptr) {
2490 LOGE("Invalid parameter");
2491 return NOTI_EX_ERROR_INVALID_PARAMETER;
2493 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2495 return NOTI_EX_ERROR_NONE;
2498 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2499 noti_ex_item_h **items, int *count) {
2500 if (handle == nullptr || items == nullptr || count == nullptr) {
2501 LOGE("Invalid parameter");
2502 return NOTI_EX_ERROR_INVALID_PARAMETER;
2506 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2507 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2508 if (item_list.size() == 0) {
2511 return NOTI_EX_ERROR_NONE;
2513 noti_ex_item_h* added_item =
2514 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2515 if (added_item == nullptr) {
2516 LOGE("Fail to create items");
2517 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2521 for (auto& i : item_list) {
2522 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2524 *items = added_item;
2525 *count = item_list.size();
2526 } catch (Exception &ex) {
2527 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2528 return NOTI_EX_ERROR_IO_ERROR;
2530 return NOTI_EX_ERROR_NONE;
2533 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2534 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2535 if (handle == nullptr || channel == nullptr ||
2536 items == nullptr || count == nullptr) {
2537 LOGE("Invalid parameter");
2538 return NOTI_EX_ERROR_INVALID_PARAMETER;
2542 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2543 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2544 if (item_list.size() == 0) {
2547 return NOTI_EX_ERROR_NONE;
2549 noti_ex_item_h* added_item =
2550 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2551 if (added_item == nullptr) {
2552 LOGE("Fail to create items");
2553 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2557 for (auto& i : item_list) {
2558 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2560 *items = added_item;
2561 *count = item_list.size();
2562 } catch (Exception &ex) {
2563 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2564 return NOTI_EX_ERROR_IO_ERROR;
2567 return NOTI_EX_ERROR_NONE;
2570 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2571 noti_ex_item_h noti, int *request_id) {
2572 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2573 LOGE("Invalid parameter");
2574 return NOTI_EX_ERROR_INVALID_PARAMETER;
2577 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2578 Handle* sp = static_cast<Handle*>(noti);
2579 if (sp->GetPtr().get() == nullptr) {
2580 LOGE("Invalid noti reference can not be sended");
2581 return NOTI_EX_ERROR_INVALID_PARAMETER;
2583 *request_id = stub->Update(sp->GetPtr());
2585 } catch (Exception &ex) {
2586 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2587 return NOTI_EX_ERROR_IO_ERROR;
2589 return NOTI_EX_ERROR_NONE;
2592 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2593 noti_ex_item_h noti, int *request_id) {
2594 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2595 LOGE("Invalid parameter");
2596 return NOTI_EX_ERROR_INVALID_PARAMETER;
2599 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2600 Handle* item = static_cast<Handle*>(noti);
2601 if (item->GetPtr().get() == nullptr) {
2602 LOGE("Invalid noti reference can not be sended");
2603 return NOTI_EX_ERROR_INVALID_PARAMETER;
2605 *request_id = stub->Delete(item->GetPtr());
2607 } catch (Exception &ex) {
2608 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2609 return NOTI_EX_ERROR_IO_ERROR;
2611 return NOTI_EX_ERROR_NONE;
2614 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2616 if (handle == nullptr || request_id == nullptr) {
2617 LOGE("Invalid parameter");
2618 return NOTI_EX_ERROR_INVALID_PARAMETER;
2621 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2622 *request_id = stub->DeleteAll();
2623 } catch (Exception &ex) {
2624 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2625 return NOTI_EX_ERROR_IO_ERROR;
2627 return NOTI_EX_ERROR_NONE;
2630 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2631 noti_ex_item_h noti, int *request_id) {
2632 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2633 LOGE("Invalid parameter");
2634 return NOTI_EX_ERROR_INVALID_PARAMETER;
2637 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2638 Handle* item = static_cast<Handle*>(noti);
2639 if (item->GetPtr().get() == nullptr) {
2640 LOGE("Invalid noti reference can not be sended");
2641 return NOTI_EX_ERROR_INVALID_PARAMETER;
2643 *request_id = stub->Hide(item->GetPtr());
2645 } catch (Exception &ex) {
2646 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2647 return NOTI_EX_ERROR_IO_ERROR;
2649 return NOTI_EX_ERROR_NONE;
2652 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2653 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2654 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2655 LOGE("Invalid parameter");
2656 return NOTI_EX_ERROR_INVALID_PARAMETER;
2659 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2660 *item = new Handle(stub->FindByRootID(root_id));
2661 } catch (Exception &ex) {
2662 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2663 return NOTI_EX_ERROR_IO_ERROR;
2665 return NOTI_EX_ERROR_NONE;
2668 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2669 noti_ex_event_info_h info, noti_ex_error_e error) {
2670 if (handle == nullptr || info == nullptr) {
2671 LOGE("Invalid parameter");
2672 return NOTI_EX_ERROR_INVALID_PARAMETER;
2675 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2676 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2677 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2678 static_cast<NotificationError>(error));
2679 } catch (Exception &ex) {
2680 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2681 return NOTI_EX_ERROR_IO_ERROR;
2683 return NOTI_EX_ERROR_NONE;
2686 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2687 noti_ex_manager_h handle, int *cnt) {
2689 if (handle == nullptr || cnt == nullptr) {
2690 LOGE("Invalid parameter");
2691 return NOTI_EX_ERROR_INVALID_PARAMETER;
2694 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2695 *cnt = stub->GetCount();
2696 } catch (Exception &ex) {
2697 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2698 return NOTI_EX_ERROR_IO_ERROR;
2700 return NOTI_EX_ERROR_NONE;
2703 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2704 const char *id, float min, float current, float max) {
2707 if (handle == nullptr) {
2708 LOGE("Invalid parameter");
2709 return NOTI_EX_ERROR_INVALID_PARAMETER;
2713 p = new (std::nothrow) ProgressItem(id, min, current, max);
2715 p = new (std::nothrow) ProgressItem(min, current, max);
2718 LOGE("Out-of-memory");
2719 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2722 *handle = new Handle(shared_ptr<AbstractItem>(p));
2724 return NOTI_EX_ERROR_NONE;
2727 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2728 noti_ex_item_h handle, float *current) {
2729 if (handle == nullptr || current == nullptr) {
2730 LOGE("Invalid parameter");
2731 return NOTI_EX_ERROR_INVALID_PARAMETER;
2734 Handle *h = static_cast<Handle*>(handle);
2735 if (!h->IsValidType(AbstractItem::Progress)) {
2736 LOGE("Invalid handle type");
2737 return NOTI_EX_ERROR_INVALID_PARAMETER;
2739 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2740 *current = p->GetCurrent();
2742 return NOTI_EX_ERROR_NONE;
2745 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2746 noti_ex_item_h handle, float current) {
2747 if (handle == nullptr) {
2748 LOGE("Invalid parameter");
2749 return NOTI_EX_ERROR_INVALID_PARAMETER;
2752 Handle *h = static_cast<Handle*>(handle);
2753 if (!h->IsValidType(AbstractItem::Progress)) {
2754 LOGE("Invalid handle type");
2755 return NOTI_EX_ERROR_INVALID_PARAMETER;
2757 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2758 p->SetCurrent(current);
2760 return NOTI_EX_ERROR_NONE;
2763 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2765 if (handle == nullptr || min == nullptr) {
2766 LOGE("Invalid parameter");
2767 return NOTI_EX_ERROR_INVALID_PARAMETER;
2770 Handle *h = static_cast<Handle*>(handle);
2771 if (!h->IsValidType(AbstractItem::Progress)) {
2772 LOGE("Invalid handle type");
2773 return NOTI_EX_ERROR_INVALID_PARAMETER;
2775 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2778 return NOTI_EX_ERROR_NONE;
2781 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2783 if (handle == nullptr || max == nullptr) {
2784 LOGE("Invalid parameter");
2785 return NOTI_EX_ERROR_INVALID_PARAMETER;
2788 Handle *h = static_cast<Handle*>(handle);
2789 if (!h->IsValidType(AbstractItem::Progress)) {
2790 LOGE("Invalid handle type");
2791 return NOTI_EX_ERROR_INVALID_PARAMETER;
2793 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2796 return NOTI_EX_ERROR_NONE;
2799 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2801 if (handle == nullptr || type == nullptr) {
2802 LOGE("Invalid parameter");
2803 return NOTI_EX_ERROR_INVALID_PARAMETER;
2806 Handle *h = static_cast<Handle*>(handle);
2807 if (!h->IsValidType(AbstractItem::Progress)) {
2808 LOGE("Invalid handle type");
2809 return NOTI_EX_ERROR_INVALID_PARAMETER;
2811 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2812 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2814 return NOTI_EX_ERROR_NONE;
2817 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2819 if (handle == nullptr) {
2820 LOGE("Invalid parameter");
2821 return NOTI_EX_ERROR_INVALID_PARAMETER;
2824 Handle *h = static_cast<Handle*>(handle);
2825 if (!h->IsValidType(AbstractItem::Progress)) {
2826 LOGE("Invalid handle type");
2827 return NOTI_EX_ERROR_INVALID_PARAMETER;
2829 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2830 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2832 return NOTI_EX_ERROR_NONE;
2835 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2836 noti_ex_reporter_events_s event_callbacks, void *data) {
2837 if (handle == nullptr) {
2838 LOGE("Invalid parameter");
2839 return NOTI_EX_ERROR_INVALID_PARAMETER;
2842 ReporterStub* stub = new (std::nothrow) ReporterStub(
2843 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2844 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2845 if (stub == nullptr) {
2846 LOGE("Fail to create manager");
2847 return NOTI_EX_ERROR_IO_ERROR;
2849 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2850 new ReporterCallbackInfo(event_callbacks, data)));
2852 *handle = static_cast<noti_ex_reporter_h>(stub);
2854 return NOTI_EX_ERROR_NONE;
2857 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2858 if (handle == nullptr) {
2859 LOGE("Invalid parameter");
2860 return NOTI_EX_ERROR_INVALID_PARAMETER;
2862 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2864 return NOTI_EX_ERROR_NONE;
2867 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2868 noti_ex_event_info_h info, noti_ex_error_e error) {
2869 if (handle == nullptr || info == nullptr) {
2870 LOGE("Invalid parameter");
2871 return NOTI_EX_ERROR_INVALID_PARAMETER;
2874 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2875 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2876 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2877 static_cast<NotificationError>(error));
2878 } catch (Exception &ex) {
2879 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2880 return NOTI_EX_ERROR_IO_ERROR;
2882 return NOTI_EX_ERROR_NONE;
2885 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2886 noti_ex_item_h noti, int *request_id) {
2887 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2888 LOGE("Invalid parameter");
2889 return NOTI_EX_ERROR_INVALID_PARAMETER;
2892 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2893 Handle* h = static_cast<Handle*>(noti);
2894 if (h->GetPtr().get() == nullptr) {
2895 LOGE("Invalid noti reference can not be sended");
2896 return NOTI_EX_ERROR_INVALID_PARAMETER;
2898 *request_id = stub->Post(h->GetPtr());
2900 } catch (Exception &ex) {
2901 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2902 return NOTI_EX_ERROR_IO_ERROR;
2904 return NOTI_EX_ERROR_NONE;
2907 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2908 noti_ex_item_h *noti_list, int count, int *request_id) {
2910 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2911 LOGE("Invalid parameter");
2912 return NOTI_EX_ERROR_INVALID_PARAMETER;
2915 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2916 list<shared_ptr<item::AbstractItem>> notiList;
2917 for (int i = 0; i < count; i++) {
2918 Handle* item = static_cast<Handle*>(noti_list[i]);
2919 notiList.push_back(item->GetPtr());
2921 *request_id = stub->Post(notiList);
2922 } catch (Exception &ex) {
2923 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2924 return NOTI_EX_ERROR_IO_ERROR;
2926 return NOTI_EX_ERROR_NONE;
2929 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2930 noti_ex_item_h noti, int *request_id) {
2931 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2932 LOGE("Invalid parameter");
2933 return NOTI_EX_ERROR_INVALID_PARAMETER;
2936 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2937 Handle* item = static_cast<Handle*>(noti);
2938 if (item->GetPtr().get() == nullptr) {
2939 LOGE("Invalid noti reference can not be sended");
2940 return NOTI_EX_ERROR_INVALID_PARAMETER;
2942 *request_id = stub->Update(item->GetPtr());
2944 } catch (Exception &ex) {
2945 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2946 return NOTI_EX_ERROR_IO_ERROR;
2948 return NOTI_EX_ERROR_NONE;
2951 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2952 noti_ex_item_h noti, int *request_id) {
2953 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2954 LOGE("Invalid parameter");
2955 return NOTI_EX_ERROR_INVALID_PARAMETER;
2958 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2959 Handle* item = static_cast<Handle*>(noti);
2960 if (item->GetPtr().get() == nullptr) {
2961 LOGE("Invalid noti reference can not be sended");
2962 return NOTI_EX_ERROR_INVALID_PARAMETER;
2964 *request_id = stub->Delete(item->GetPtr());
2966 } catch (Exception &ex) {
2967 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2968 return NOTI_EX_ERROR_IO_ERROR;
2970 return NOTI_EX_ERROR_NONE;
2973 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2974 noti_ex_reporter_h handle, int *request_id) {
2975 if (handle == nullptr || request_id == nullptr) {
2976 LOGE("Invalid parameter");
2977 return NOTI_EX_ERROR_INVALID_PARAMETER;
2980 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2981 *request_id = stub->DeleteAll();
2982 } catch (Exception &ex) {
2983 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2984 return NOTI_EX_ERROR_IO_ERROR;
2986 return NOTI_EX_ERROR_NONE;
2989 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2990 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2991 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2992 LOGE("Invalid parameter");
2993 return NOTI_EX_ERROR_INVALID_PARAMETER;
2996 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2997 *item = new Handle(stub->FindByRootID(root_id));
2998 } catch (Exception &ex) {
2999 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3000 return NOTI_EX_ERROR_IO_ERROR;
3002 return NOTI_EX_ERROR_NONE;
3005 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3006 const char *id, const char *text, const char *hyperlink) {
3007 if (handle == nullptr || text == nullptr) {
3008 LOGE("Invalid parameter");
3009 return NOTI_EX_ERROR_INVALID_PARAMETER;
3015 p = new (std::nothrow) TextItem(id, std::string(text),
3016 std::string(hyperlink));
3018 p = new (std::nothrow) TextItem(id, std::string(text));
3021 LOGE("Out-of-memory");
3022 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3025 *handle = new Handle(shared_ptr<AbstractItem>(p));
3027 return NOTI_EX_ERROR_NONE;
3030 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3031 const char *contents) {
3032 if (handle == nullptr || contents == nullptr) {
3033 LOGE("Invalid parameter");
3034 return NOTI_EX_ERROR_INVALID_PARAMETER;
3037 Handle* p = static_cast<Handle*>(handle);
3038 if (!p->IsValidType(AbstractItem::Text)) {
3039 LOGE("Invalid handle type");
3040 return NOTI_EX_ERROR_INVALID_PARAMETER;
3042 TextItem* ti = static_cast<TextItem*>(p->Get());
3043 ti->SetContents(std::string(contents));
3045 return NOTI_EX_ERROR_NONE;
3048 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3050 if (handle == nullptr || contents == nullptr) {
3051 LOGE("Invalid parameter");
3052 return NOTI_EX_ERROR_INVALID_PARAMETER;
3055 Handle* p = static_cast<Handle*>(handle);
3056 if (!p->IsValidType(AbstractItem::Text)) {
3057 LOGE("Invalid handle type");
3058 return NOTI_EX_ERROR_INVALID_PARAMETER;
3061 TextItem* ti = static_cast<TextItem*>(p->Get());
3063 if (ti->GetMultiLanguage() != nullptr &&
3064 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3065 str = ti->GetMultiLanguage()->GetTranslatedString();
3066 else if (!ti->GetContents().empty())
3067 str = ti->GetContents();
3069 *contents = strdup(str.c_str());
3070 if (*contents == nullptr) {
3071 LOGE("Out-of-memory");
3072 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3075 return NOTI_EX_ERROR_NONE;
3078 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3079 noti_ex_item_h handle, char **hyper_link) {
3080 if (handle == nullptr || hyper_link == nullptr) {
3081 LOGE("Invalid parameter");
3082 return NOTI_EX_ERROR_INVALID_PARAMETER;
3085 Handle* p = static_cast<Handle*>(handle);
3086 if (!p->IsValidType(AbstractItem::Text)) {
3087 LOGE("Invalid handle type");
3088 return NOTI_EX_ERROR_INVALID_PARAMETER;
3090 TextItem* ti = static_cast<TextItem*>(p->Get());
3091 if (!ti->GetHyperLink().empty()) {
3092 *hyper_link = strdup(ti->GetHyperLink().c_str());
3093 if (*hyper_link == nullptr) {
3094 LOGE("Out-of-memory");
3095 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3099 return NOTI_EX_ERROR_NONE;
3102 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3103 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3104 if (handle == nullptr) {
3105 LOGE("Invalid parameter");
3106 return NOTI_EX_ERROR_INVALID_PARAMETER;
3109 Handle* p = static_cast<Handle*>(handle);
3110 if (!p->IsValidType(AbstractItem::Text)) {
3111 LOGE("Invalid handle type");
3112 return NOTI_EX_ERROR_INVALID_PARAMETER;
3115 TextItem* ti = static_cast<TextItem*>(p->Get());
3116 if (multi == nullptr) {
3117 ti->SetMultiLanguage(nullptr);
3118 return NOTI_EX_ERROR_NONE;
3121 shared_ptr<MultiLanguage> mul_ptr =
3122 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3123 ti->SetMultiLanguage(mul_ptr);
3124 ti->GetMultiLanguage()->UpdateString();
3126 return NOTI_EX_ERROR_NONE;
3129 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3130 const char *id, time_t time) {
3133 if (handle == nullptr) {
3134 LOGE("Invalid parameter");
3135 return NOTI_EX_ERROR_INVALID_PARAMETER;
3140 p = new (std::nothrow) TimeItem(id, time);
3142 p = new (std::nothrow) TimeItem(time);
3144 p = new (std::nothrow) TimeItem();
3148 LOGE("Out-of-memory");
3149 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3152 *handle = new Handle(shared_ptr<AbstractItem>(p));
3154 return NOTI_EX_ERROR_NONE;
3157 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3159 if (handle == nullptr || time == nullptr) {
3160 LOGE("Invalid parameter");
3161 return NOTI_EX_ERROR_INVALID_PARAMETER;
3163 Handle* h = static_cast<Handle*>(handle);
3164 if (!h->IsValidType(AbstractItem::Time)) {
3165 LOGE("Invalid handle type");
3166 return NOTI_EX_ERROR_INVALID_PARAMETER;
3168 TimeItem* p = static_cast<TimeItem*>(h->Get());
3169 *time = p->GetTime();
3171 return NOTI_EX_ERROR_NONE;
3174 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3176 if (handle == nullptr) {
3177 LOGE("Invalid parameter");
3178 return NOTI_EX_ERROR_INVALID_PARAMETER;
3180 Handle* h = static_cast<Handle*>(handle);
3181 if (!h->IsValidType(AbstractItem::Time)) {
3182 LOGE("Invalid handle type");
3183 return NOTI_EX_ERROR_INVALID_PARAMETER;
3185 TimeItem* p = static_cast<TimeItem*>(h->Get());
3188 return NOTI_EX_ERROR_NONE;
3191 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3192 noti_ex_action_h *handle, const char *extra) {
3193 if (handle == nullptr) {
3194 LOGE("Invalid parameter");
3195 return NOTI_EX_ERROR_INVALID_PARAMETER;
3198 string extra_str = "";
3200 extra_str = string(extra);
3202 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3203 new (std::nothrow) VisibilityAction(extra_str));
3204 if (ptr == nullptr) {
3205 LOGE("Out-of-memory");
3206 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3211 return NOTI_EX_ERROR_NONE;
3214 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3215 const char *id, bool visible) {
3216 if (handle == nullptr || id == nullptr) {
3217 LOGE("Invalid parameter");
3218 return NOTI_EX_ERROR_INVALID_PARAMETER;
3221 shared_ptr<AbstractAction>* ptr =
3222 static_cast<shared_ptr<AbstractAction>*>(handle);
3223 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3224 action->SetVisibility(id, visible);
3226 return NOTI_EX_ERROR_NONE;
3229 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3230 const char* msgid, const char* format, ...) {
3231 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3232 LOGE("Invalid parameter");
3233 return NOTI_EX_ERROR_INVALID_PARAMETER;
3236 const char* format_idx = format;
3239 va_start(args, format);
3240 while (*format_idx != '\0') {
3241 char* arg = nullptr;
3244 stringstream stream;
3245 if (*format_idx == '%') {
3246 switch (*(format_idx + 1)) {
3248 arg = va_arg(args, char *);
3249 arr.push_back(string(arg));
3252 arg_i = va_arg(args, int);
3253 arr.push_back(to_string(arg_i));
3256 arg_f = va_arg(args, double);
3257 stream << std::fixed << std::setprecision(2) << arg_f;
3258 arr.push_back(stream.str());
3266 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3268 LOGE("Out-of-memory");
3269 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3271 *handle = new shared_ptr<MultiLanguage>(p);
3273 return NOTI_EX_ERROR_NONE;
3276 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3277 if (handle == nullptr) {
3278 LOGE("Invalid parameter");
3279 return NOTI_EX_ERROR_INVALID_PARAMETER;
3282 shared_ptr<MultiLanguage>* mul_ptr =
3283 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3285 return NOTI_EX_ERROR_NONE;
3288 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3289 noti_ex_item_h item, int64_t* private_id) {
3290 if (item == nullptr || private_id == nullptr) {
3291 LOGE("Invalid parameter");
3292 return NOTI_EX_ERROR_INVALID_PARAMETER;
3295 Handle* h = static_cast<Handle*>(item);
3296 *private_id = static_pointer_cast<IItemInfoInternal>(
3297 h->Get()->GetInfo())->GetPrivateId();
3299 return NOTI_EX_ERROR_NONE;
3302 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3303 noti_ex_item_h item, int64_t priv_id) {
3304 if (item == nullptr) {
3305 LOGE("Invalid parameter");
3306 return NOTI_EX_ERROR_INVALID_PARAMETER;
3309 Handle* h = static_cast<Handle*>(item);
3310 static_pointer_cast<IItemInfoInternal>(
3311 h->Get()->GetInfo())->SetPrivateId(priv_id);
3313 return NOTI_EX_ERROR_NONE;
3316 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3317 if (list == nullptr) {
3318 LOGE("Invalid parameter");
3319 return NOTI_EX_ERROR_INVALID_PARAMETER;
3322 LOGI("Free strings (%d)", count);
3323 for (int i = 0; i < count; i++)
3327 return NOTI_EX_ERROR_NONE;
3330 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3331 if (handle == nullptr) {
3332 LOGE("Invalid parameter");
3333 return NOTI_EX_ERROR_INVALID_PARAMETER;
3335 Handle* h = static_cast<Handle*>(handle);
3336 if (!h->IsValidType(AbstractItem::Group)) {
3337 LOGE("Invalid handle type");
3338 return NOTI_EX_ERROR_INVALID_PARAMETER;
3340 GroupItem* p = static_cast<GroupItem*>(h->Get());
3341 p->RemoveChildren();
3343 return NOTI_EX_ERROR_NONE;