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.h"
26 #include "api/notification_ex_internal.h"
27 #include "notification-ex/reporter.h"
28 #include "notification-ex/app_control_action.h"
29 #include "notification-ex/button_item.h"
30 #include "notification-ex/chat_message_item.h"
31 #include "notification-ex/checkbox_item.h"
32 #include "notification-ex/entry_item.h"
33 #include "notification-ex/group_item.h"
34 #include "notification-ex/input_selector_item.h"
35 #include "notification-ex/abstract_item.h"
36 #include "notification-ex/progress_item.h"
37 #include "notification-ex/time_item.h"
38 #include "notification-ex/visibility_action.h"
39 #include "notification-ex/event_info_internal.h"
40 #include "notification-ex/manager.h"
41 #include "notification-ex/dbus_sender.h"
42 #include "notification-ex/dbus_event_listener.h"
43 #include "notification-ex/exception.h"
44 #include "notification-ex/iitem_info_internal.h"
45 #include "notification-ex/icon_item.h"
50 #define LOG_TAG "NOTIFICATION_EX"
55 #define EXPORT_API __attribute__((visibility("default")))
58 using namespace tizen_base;
59 using namespace notification::item;
60 using namespace notification;
66 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
67 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
68 : ref_(nullptr), ptr_(move(ptr)) { }
69 virtual ~Handle() = default;
70 item::AbstractItem* Get() const {
76 bool IsValidType(int type) const {
77 return (Get()->GetType() == type
78 || Get()->GetType() >= AbstractItem::Custom);
81 std::shared_ptr<item::AbstractItem> GetPtr() const {
83 return std::shared_ptr<item::AbstractItem>({});
88 item::AbstractItem* ref_;
89 std::shared_ptr<item::AbstractItem> ptr_;
92 class ManagerCallbackInfo {
94 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
95 : user_data_(user_data) {
97 cb_.updated = cb.updated;
98 cb_.deleted = cb.deleted;
102 void InvokeAdded(Manager* manager, const IEventInfo& info,
103 list<shared_ptr<AbstractItem>> addedList) {
104 if (cb_.added == nullptr)
106 noti_ex_item_h* added_item =
107 (noti_ex_item_h*)calloc(addedList.size(), sizeof(noti_ex_item_h));
108 if (added_item == nullptr) {
109 LOGE("Out of memory");
114 for (auto& i : addedList) {
116 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
119 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
120 cb_.added(static_cast<noti_ex_manager_h>(manager),
121 static_cast<noti_ex_event_info_h>(c_info), added_item,
122 addedList.size(), user_data_);
125 void InvokeUpdated(Manager* manager, const IEventInfo& info,
126 list<shared_ptr<AbstractItem>> updatedList) {
127 if (cb_.updated == nullptr)
130 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
131 for (auto& i : updatedList) {
132 cb_.updated(static_cast<noti_ex_manager_h>(manager),
133 static_cast<noti_ex_event_info_h>(c_info),
134 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i))),
139 void InvokeDeleted(Manager* manager, const IEventInfo& info,
140 list<shared_ptr<AbstractItem>> deletedList) {
141 if (cb_.deleted == nullptr)
144 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
145 for (auto& i : deletedList) {
146 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
147 static_cast<noti_ex_event_info_h>(c_info),
148 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i))),
153 void InvokeError(Manager* manager, NotificationError error, int requestId) {
154 if (cb_.error == nullptr)
156 cb_.error(static_cast<noti_ex_manager_h>(manager),
157 static_cast<noti_ex_error_e>(error), requestId, user_data_);
161 noti_ex_manager_events_s cb_;
165 class ManagerStub : public Manager {
167 ManagerStub(std::unique_ptr<IEventSender> sender,
168 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
169 : Manager(move(sender), move(listener), receiver_group) {
172 void OnAdd(const IEventInfo& info,
173 list<shared_ptr<AbstractItem>> addedList) override {
174 cb_->InvokeAdded(this, info, addedList);
177 void OnUpdate(const IEventInfo& info,
178 list<shared_ptr<AbstractItem>> updatedList) override {
179 cb_->InvokeUpdated(this, info, updatedList);
182 void OnDelete(const IEventInfo& info,
183 list<shared_ptr<AbstractItem>> deletedList) override {
184 cb_->InvokeDeleted(this, info, deletedList);
187 void OnError(NotificationError error, int requestId) override {
188 cb_->InvokeError(this, error, requestId);
191 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
193 return NOTI_EX_ERROR_NONE;
196 int ClearManagerCallbackInfo() {
198 return NOTI_EX_ERROR_NONE;
202 unique_ptr<ManagerCallbackInfo> cb_;
206 class ReporterCallbackInfo {
208 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
209 : user_data_(user_data) {
210 cb_.event = cb.event;
211 cb_.error = cb.error;
214 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
215 list<shared_ptr<AbstractItem>> notiList) {
216 if (cb_.event == nullptr)
218 noti_ex_item_h* noti_list =
219 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
220 if (noti_list == nullptr) {
221 LOGE("Out of memory");
226 for (auto& i : notiList) {
228 static_cast<noti_ex_item_h>(new Handle(i));
231 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
232 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
233 static_cast<noti_ex_event_info_h>(c_info), noti_list,
234 notiList.size(), user_data_);
238 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
239 if (cb_.error == nullptr)
241 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
242 static_cast<noti_ex_error_e>(error), requestId, user_data_);
246 noti_ex_reporter_events_s cb_;
250 class ReporterStub : public Reporter {
252 ReporterStub(std::unique_ptr<IEventSender> sender,
253 std::unique_ptr<IEventListener> listener)
254 : Reporter(move(sender), move(listener)) {
257 void OnEvent(const IEventInfo& info,
258 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
259 cb_->InvokeEvent(this, info, notiList);
262 void OnError(NotificationError error, int requestId) override {
263 cb_->InvokeError(this, error, requestId);
266 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
268 return NOTI_EX_ERROR_NONE;
271 int ClearReporterCallbackInfo() {
273 return NOTI_EX_ERROR_NONE;
277 unique_ptr<ReporterCallbackInfo> cb_;
282 void __noti_ex_free_str_array(char** val, int length) {
284 for (i = 0; i < length ; i++)
289 extern "C" EXPORT_API int noti_ex_action_app_control_create(
290 noti_ex_action_h *handle, app_control_h app_control,
292 if (handle == nullptr || app_control == nullptr) {
293 LOGE("Invalid parameter");
294 return NOTI_EX_ERROR_INVALID_PARAMETER;
297 shared_ptr<AbstractAction>* p;
300 p = new (std::nothrow) shared_ptr<AbstractAction>(
301 new (std::nothrow) AppControlAction(app_control, extra));
303 p = new (std::nothrow) shared_ptr<AbstractAction>(
304 new (std::nothrow) AppControlAction(app_control));
308 LOGE("Out-of-memory");
309 return NOTI_EX_ERROR_OUT_OF_MEMORY;
314 return NOTI_EX_ERROR_NONE;
317 extern "C" EXPORT_API int noti_ex_action_app_control_set(
318 noti_ex_action_h handle, app_control_h app_control) {
319 if (handle == nullptr || app_control == nullptr) {
320 LOGE("Invalid parameter");
321 return NOTI_EX_ERROR_INVALID_PARAMETER;
324 shared_ptr<AbstractAction>* ptr =
325 static_cast<shared_ptr<AbstractAction>*>(handle);
326 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
327 action->SetAppControl(app_control);
329 return NOTI_EX_ERROR_NONE;
332 extern "C" EXPORT_API int noti_ex_action_app_control_get(
333 noti_ex_action_h handle, app_control_h *app_control) {
334 if (handle == nullptr || app_control == nullptr) {
335 LOGE("Invalid parameter");
336 return NOTI_EX_ERROR_INVALID_PARAMETER;
339 shared_ptr<AbstractAction>* ptr =
340 static_cast<shared_ptr<AbstractAction>*>(handle);
341 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
344 int r = app_control_clone(&clone, action->GetAppControl());
345 if (r != APP_CONTROL_ERROR_NONE) {
346 LOGE("failed to create a app_control handle : %d", r);
347 return NOTI_EX_ERROR_INVALID_PARAMETER;
350 *app_control = clone;
352 return NOTI_EX_ERROR_NONE;
355 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
356 const char *id, const char *title) {
359 if (handle == nullptr || title == nullptr) {
360 LOGE("Invalid parameter");
361 return NOTI_EX_ERROR_INVALID_PARAMETER;
365 p = new (std::nothrow) ButtonItem(id, title);
367 p = new (std::nothrow) ButtonItem(title);
370 LOGE("Out-of-memory");
371 return NOTI_EX_ERROR_OUT_OF_MEMORY;
373 *handle = new Handle(shared_ptr<AbstractItem>(p));
375 return NOTI_EX_ERROR_NONE;
378 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
380 if (handle == nullptr || title == nullptr) {
381 LOGE("Invalid parameter");
382 return NOTI_EX_ERROR_INVALID_PARAMETER;
385 Handle* sp = static_cast<Handle*>(handle);
386 if (!sp->IsValidType(AbstractItem::Button)) {
387 LOGE("Invalid handle type");
388 return NOTI_EX_ERROR_INVALID_PARAMETER;
391 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
393 if (p->GetMultiLanguage() != nullptr &&
394 !p->GetMultiLanguage()->GetTranslatedString().empty())
395 str = p->GetMultiLanguage()->GetTranslatedString();
396 else if (!p->GetTitle().empty())
399 *title = strdup(str.c_str());
400 if (*title == nullptr) {
401 LOGE("Out-of-memory");
402 return NOTI_EX_ERROR_OUT_OF_MEMORY;
405 return NOTI_EX_ERROR_NONE;
408 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
409 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
410 if (handle == nullptr) {
411 LOGE("Invalid parameter");
412 return NOTI_EX_ERROR_INVALID_PARAMETER;
415 Handle* p = static_cast<Handle*>(handle);
416 if (!p->IsValidType(AbstractItem::Button)) {
417 LOGE("Invalid handle type");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
421 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
422 if (multi == nullptr) {
423 bi->SetMultiLanguage(nullptr);
424 return NOTI_EX_ERROR_NONE;
427 shared_ptr<MultiLanguage> mul_ptr =
428 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
430 mul_ptr->UpdateString();
431 bi->SetMultiLanguage(mul_ptr);
433 return NOTI_EX_ERROR_NONE;
436 extern "C" EXPORT_API int noti_ex_item_button_set_image(
437 noti_ex_item_h handle, const char *path) {
438 if (handle == nullptr || path == nullptr) {
439 LOGE("Invalid parameter");
440 return NOTI_EX_ERROR_INVALID_PARAMETER;
443 Handle* h = static_cast<Handle*>(handle);
444 if (!h->IsValidType(AbstractItem::Button)) {
445 LOGE("Invalid handle type");
446 return NOTI_EX_ERROR_INVALID_PARAMETER;
449 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
452 return NOTI_EX_ERROR_NONE;
455 extern "C" EXPORT_API int noti_ex_item_button_get_image(
456 noti_ex_item_h handle, char **path) {
457 if (handle == nullptr || path == nullptr) {
458 LOGE("Invalid parameter");
459 return NOTI_EX_ERROR_INVALID_PARAMETER;
462 Handle* h = static_cast<Handle*>(handle);
463 if (!h->IsValidType(AbstractItem::Button)) {
464 LOGE("Invalid handle type");
465 return NOTI_EX_ERROR_INVALID_PARAMETER;
468 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
469 if (!p->GetImgPath().empty())
470 *path = strdup(p->GetImgPath().c_str());
474 return NOTI_EX_ERROR_NONE;
477 extern "C" EXPORT_API int noti_ex_item_button_set_contents(
478 noti_ex_item_h handle, const char *contents) {
479 if (handle == nullptr || contents == nullptr) {
480 LOGE("Invalid parameter");
481 return NOTI_EX_ERROR_INVALID_PARAMETER;
484 Handle* h = static_cast<Handle*>(handle);
485 if (!h->IsValidType(AbstractItem::Button)) {
486 LOGE("Invalid handle type");
487 return NOTI_EX_ERROR_INVALID_PARAMETER;
490 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
491 p->SetContents(std::string(contents));
493 return NOTI_EX_ERROR_NONE;
496 extern "C" EXPORT_API int noti_ex_item_button_get_contents(
497 noti_ex_item_h handle, char **contents) {
498 if (handle == nullptr || contents == nullptr) {
499 LOGE("Invalid parameter");
500 return NOTI_EX_ERROR_INVALID_PARAMETER;
503 Handle* h = static_cast<Handle*>(handle);
504 if (!h->IsValidType(AbstractItem::Button)) {
505 LOGE("Invalid handle type");
506 return NOTI_EX_ERROR_INVALID_PARAMETER;
509 ButtonItem* p = static_cast<ButtonItem*>(h->Get());
510 if (!p->GetContents().empty())
511 *contents = strdup(p->GetContents().c_str());
515 return NOTI_EX_ERROR_NONE;
518 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
519 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
520 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
521 noti_ex_item_chat_message_type_e message_type) {
522 if (handle == nullptr || (text == nullptr && image == nullptr)
523 || name == nullptr || time == nullptr
524 || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
525 LOGE("Invalid parameter");
526 return NOTI_EX_ERROR_INVALID_PARAMETER;
532 auto* p = new (std::nothrow) ChatMessageItem(id,
533 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
534 text == nullptr ? nullptr
535 : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
536 image == nullptr ? nullptr
537 : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
538 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
539 static_cast<ChatMessageItem::Type>(message_type));
541 LOGE("Out-of-memory");
542 return NOTI_EX_ERROR_OUT_OF_MEMORY;
545 *handle = new Handle(shared_ptr<AbstractItem>(p));
547 return NOTI_EX_ERROR_NONE;
550 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
551 noti_ex_item_h handle, noti_ex_item_h *name) {
552 if (handle == nullptr || name == nullptr) {
553 LOGE("Invalid parameter");
554 return NOTI_EX_ERROR_INVALID_PARAMETER;
556 Handle* h = static_cast<Handle*>(handle);
557 if (!h->IsValidType(AbstractItem::ChatMessage)) {
558 LOGE("Invalid handle type");
559 return NOTI_EX_ERROR_INVALID_PARAMETER;
561 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
562 if (p->GetNameItem().GetType() == AbstractItem::NullObject)
565 *name = new Handle(&(p->GetNameItem()));
567 return NOTI_EX_ERROR_NONE;
570 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
571 noti_ex_item_h handle, noti_ex_item_h *text) {
572 if (handle == nullptr || text == nullptr) {
573 LOGE("Invalid parameter");
574 return NOTI_EX_ERROR_INVALID_PARAMETER;
577 Handle* h = static_cast<Handle*>(handle);
578 if (!h->IsValidType(AbstractItem::ChatMessage)) {
579 LOGE("Invalid handle type");
580 return NOTI_EX_ERROR_INVALID_PARAMETER;
582 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
583 if (p->GetTextItem().GetType() == AbstractItem::NullObject)
586 *text = new Handle(&(p->GetTextItem()));
588 return NOTI_EX_ERROR_NONE;
591 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
592 noti_ex_item_h handle, noti_ex_item_h *image) {
593 if (handle == nullptr || image == nullptr) {
594 LOGE("Invalid parameter");
595 return NOTI_EX_ERROR_INVALID_PARAMETER;
598 Handle* h = static_cast<Handle*>(handle);
599 if (!h->IsValidType(AbstractItem::ChatMessage)) {
600 LOGE("Invalid handle type");
601 return NOTI_EX_ERROR_INVALID_PARAMETER;
603 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
604 if (p->GetImageItem().GetType() == AbstractItem::NullObject)
607 *image = new Handle(&(p->GetImageItem()));
609 return NOTI_EX_ERROR_NONE;
612 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
613 noti_ex_item_h handle, noti_ex_item_h *time) {
614 if (handle == nullptr || time == nullptr) {
615 LOGE("Invalid parameter");
616 return NOTI_EX_ERROR_INVALID_PARAMETER;
619 Handle* h = static_cast<Handle*>(handle);
620 if (!h->IsValidType(AbstractItem::ChatMessage)) {
621 LOGE("Invalid handle type");
622 return NOTI_EX_ERROR_INVALID_PARAMETER;
624 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
625 if (p->GetTimeItem().GetType() == AbstractItem::NullObject)
628 *time = new Handle(&(p->GetTimeItem()));
630 return NOTI_EX_ERROR_NONE;
633 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
634 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
635 if (handle == nullptr || message_type == nullptr) {
636 LOGE("Invalid parameter");
637 return NOTI_EX_ERROR_INVALID_PARAMETER;
640 Handle* h = static_cast<Handle*>(handle);
641 if (!h->IsValidType(AbstractItem::ChatMessage)) {
642 LOGE("Invalid handle type");
643 return NOTI_EX_ERROR_INVALID_PARAMETER;
645 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
646 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
648 return NOTI_EX_ERROR_NONE;
651 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
652 const char *id, const char *title, bool checked) {
655 if (handle == nullptr || title == nullptr) {
656 LOGE("Invalid parameter");
657 return NOTI_EX_ERROR_INVALID_PARAMETER;
663 p = new (std::nothrow) CheckBoxItem(id, title, checked);
665 LOGE("Out-of-memory");
666 return NOTI_EX_ERROR_OUT_OF_MEMORY;
669 *handle = new Handle(shared_ptr<AbstractItem>(p));
671 return NOTI_EX_ERROR_NONE;
674 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
676 if (handle == nullptr || title == nullptr) {
677 LOGE("Invalid parameter");
678 return NOTI_EX_ERROR_INVALID_PARAMETER;
680 Handle* h = static_cast<Handle*>(handle);
681 if (!h->IsValidType(AbstractItem::CheckBox)) {
682 LOGE("Invalid handle type");
683 return NOTI_EX_ERROR_INVALID_PARAMETER;
686 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
688 if (p->GetMultiLanguage() != nullptr &&
689 !p->GetMultiLanguage()->GetTranslatedString().empty())
690 str = p->GetMultiLanguage()->GetTranslatedString();
691 else if (!p->GetTitle().empty())
694 *title = strdup(str.c_str());
695 if (*title == nullptr) {
696 LOGE("Out-of-memory");
697 return NOTI_EX_ERROR_OUT_OF_MEMORY;
700 return NOTI_EX_ERROR_NONE;
703 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
704 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
705 if (handle == nullptr) {
706 LOGE("Invalid parameter");
707 return NOTI_EX_ERROR_INVALID_PARAMETER;
710 Handle* p = static_cast<Handle*>(handle);
711 if (!p->IsValidType(AbstractItem::CheckBox)) {
712 LOGE("Invalid handle type");
713 return NOTI_EX_ERROR_INVALID_PARAMETER;
716 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
717 if (multi == nullptr) {
718 ci->SetMultiLanguage(nullptr);
719 return NOTI_EX_ERROR_NONE;
722 shared_ptr<MultiLanguage> mul_ptr =
723 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
724 mul_ptr->UpdateString();
725 ci->SetMultiLanguage(mul_ptr);
727 return NOTI_EX_ERROR_NONE;
730 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
731 noti_ex_item_h handle, bool *checked) {
732 if (handle == nullptr || checked == nullptr) {
733 LOGE("Invalid parameter");
734 return NOTI_EX_ERROR_INVALID_PARAMETER;
736 Handle* h = static_cast<Handle*>(handle);
737 if (!h->IsValidType(AbstractItem::CheckBox)) {
738 LOGE("Invalid handle type");
739 return NOTI_EX_ERROR_INVALID_PARAMETER;
741 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
742 *checked = p->IsChecked();
744 return NOTI_EX_ERROR_NONE;
747 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
748 noti_ex_item_h handle, bool checked) {
749 if (handle == nullptr) {
750 LOGE("Invalid parameter");
751 return NOTI_EX_ERROR_INVALID_PARAMETER;
754 Handle* h = static_cast<Handle*>(handle);
755 if (!h->IsValidType(AbstractItem::CheckBox)) {
756 LOGE("Invalid handle type");
757 return NOTI_EX_ERROR_INVALID_PARAMETER;
760 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
761 p->SetChecked(checked);
763 return NOTI_EX_ERROR_NONE;
766 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
770 if (handle == nullptr) {
771 LOGE("Invalid parameter");
772 return NOTI_EX_ERROR_INVALID_PARAMETER;
776 p = new (std::nothrow) EntryItem(id);
778 p = new (std::nothrow) EntryItem();
781 LOGE("Out-of-memory");
782 return NOTI_EX_ERROR_OUT_OF_MEMORY;
785 *handle = new Handle(shared_ptr<AbstractItem>(p));
787 return NOTI_EX_ERROR_NONE;
790 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
792 if (handle == nullptr || text == nullptr) {
793 LOGE("Invalid parameter");
794 return NOTI_EX_ERROR_INVALID_PARAMETER;
797 Handle* h = static_cast<Handle*>(handle);
798 if (!h->IsValidType(AbstractItem::Entry)) {
799 LOGE("Invalid handle type");
800 return NOTI_EX_ERROR_INVALID_PARAMETER;
803 EntryItem* p = static_cast<EntryItem*>(h->Get());
805 if (p->GetMultiLanguage() != nullptr &&
806 !p->GetMultiLanguage()->GetTranslatedString().empty())
807 str = p->GetMultiLanguage()->GetTranslatedString();
808 else if (!p->GetText().empty())
811 *text = strdup(str.c_str());
812 if (*text == nullptr) {
813 LOGE("Out-of-memory");
814 return NOTI_EX_ERROR_OUT_OF_MEMORY;
817 return NOTI_EX_ERROR_NONE;
820 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
822 if (handle == nullptr || text == nullptr) {
823 LOGE("Invalid parameter");
824 return NOTI_EX_ERROR_INVALID_PARAMETER;
826 Handle* h = static_cast<Handle*>(handle);
827 if (!h->IsValidType(AbstractItem::Entry)) {
828 LOGE("Invalid handle type");
829 return NOTI_EX_ERROR_INVALID_PARAMETER;
831 EntryItem* p = static_cast<EntryItem*>(h->Get());
832 p->SetText(std::string(text));
834 return NOTI_EX_ERROR_NONE;
837 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
838 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
839 if (handle == nullptr) {
840 LOGE("Invalid parameter");
841 return NOTI_EX_ERROR_INVALID_PARAMETER;
844 Handle* p = static_cast<Handle*>(handle);
845 if (!p->IsValidType(AbstractItem::Entry)) {
846 LOGE("Invalid handle type");
847 return NOTI_EX_ERROR_INVALID_PARAMETER;
850 EntryItem* ei = static_cast<EntryItem*>(p->Get());
851 if (multi == nullptr) {
852 ei->SetMultiLanguage(nullptr);
853 return NOTI_EX_ERROR_NONE;
856 shared_ptr<MultiLanguage> mul_ptr =
857 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
858 ei->SetMultiLanguage(mul_ptr);
859 ei->GetMultiLanguage()->UpdateString();
861 return NOTI_EX_ERROR_NONE;
864 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
865 noti_ex_event_info_h* cloned_handle) {
866 if (handle == nullptr || cloned_handle == nullptr) {
867 LOGE("Invalid parameter");
868 return NOTI_EX_ERROR_INVALID_PARAMETER;
871 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
872 EventInfo* info = new EventInfo(cloned);
873 *cloned_handle = info;
874 return NOTI_EX_ERROR_NONE;
877 extern "C" EXPORT_API int noti_ex_event_info_destroy(
878 noti_ex_event_info_h handle) {
879 if (handle == nullptr) {
880 LOGE("Invalid parameter");
881 return NOTI_EX_ERROR_INVALID_PARAMETER;
883 EventInfo* info = static_cast<EventInfo*>(handle);
885 return NOTI_EX_ERROR_NONE;
888 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
889 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
890 if (handle == nullptr || event_type == nullptr) {
891 LOGE("Invalid parameter");
892 return NOTI_EX_ERROR_INVALID_PARAMETER;
894 EventInfo* info = static_cast<EventInfo*>(handle);
895 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
897 return NOTI_EX_ERROR_NONE;
900 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
901 noti_ex_event_info_h handle, char **owner) {
902 if (handle == nullptr || owner == nullptr) {
903 LOGE("Invalid parameter");
904 return NOTI_EX_ERROR_INVALID_PARAMETER;
906 EventInfo* info = static_cast<EventInfo*>(handle);
907 *owner = strdup(info->GetOwner().c_str());
908 return NOTI_EX_ERROR_NONE;
911 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
912 noti_ex_event_info_h handle, char **channel) {
913 if (handle == nullptr || channel == nullptr) {
914 LOGE("Invalid parameter");
915 return NOTI_EX_ERROR_INVALID_PARAMETER;
917 EventInfo* info = static_cast<EventInfo*>(handle);
918 *channel = strdup(info->GetChannel().c_str());
919 return NOTI_EX_ERROR_NONE;
922 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
923 noti_ex_event_info_h handle, char **item_id) {
924 if (handle == nullptr || item_id == nullptr) {
925 LOGE("Invalid parameter");
926 return NOTI_EX_ERROR_INVALID_PARAMETER;
928 EventInfo* info = static_cast<EventInfo*>(handle);
929 *item_id = strdup(info->GetItemId().c_str());
930 return NOTI_EX_ERROR_NONE;
933 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
934 noti_ex_event_info_h handle, int *req_id) {
935 if (handle == nullptr || req_id == nullptr) {
936 LOGE("Invalid parameter");
937 return NOTI_EX_ERROR_INVALID_PARAMETER;
939 EventInfo* info = static_cast<EventInfo*>(handle);
940 *req_id = info->GetRequestId();
941 return NOTI_EX_ERROR_NONE;
944 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
948 if (handle == nullptr) {
949 LOGE("Invalid parameter");
950 return NOTI_EX_ERROR_INVALID_PARAMETER;
954 p = new (std::nothrow) GroupItem(id);
956 p = new (std::nothrow) GroupItem();
959 LOGE("Out-of-memory");
960 return NOTI_EX_ERROR_OUT_OF_MEMORY;
963 *handle = new Handle(shared_ptr<AbstractItem>(p));
965 return NOTI_EX_ERROR_NONE;
968 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
970 if (handle == nullptr) {
971 LOGE("Invalid parameter");
972 return NOTI_EX_ERROR_INVALID_PARAMETER;
974 Handle* h = static_cast<Handle*>(handle);
975 if (!h->IsValidType(AbstractItem::Group)) {
976 LOGE("Invalid handle type");
977 return NOTI_EX_ERROR_INVALID_PARAMETER;
979 GroupItem* p = static_cast<GroupItem*>(h->Get());
980 p->SetDirection(vertical);
982 return NOTI_EX_ERROR_NONE;
985 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
987 if (handle == nullptr) {
988 LOGE("Invalid parameter");
989 return NOTI_EX_ERROR_INVALID_PARAMETER;
991 Handle* h = static_cast<Handle*>(handle);
992 if (!h->IsValidType(AbstractItem::Group)) {
993 LOGE("Invalid handle type");
994 return NOTI_EX_ERROR_INVALID_PARAMETER;
996 GroupItem* p = static_cast<GroupItem*>(h->Get());
997 *vertical = p->IsVertical();
999 return NOTI_EX_ERROR_NONE;
1002 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
1004 if (handle == nullptr) {
1005 LOGE("Invalid parameter");
1006 return NOTI_EX_ERROR_INVALID_PARAMETER;
1008 Handle* h = static_cast<Handle*>(handle);
1009 if (!h->IsValidType(AbstractItem::Group)) {
1010 LOGE("Invalid handle type");
1011 return NOTI_EX_ERROR_INVALID_PARAMETER;
1013 GroupItem* p = static_cast<GroupItem*>(h->Get());
1014 if (!p->GetAppLabel().empty()) {
1015 *label = strdup(p->GetAppLabel().c_str());
1016 if (*label == nullptr) {
1017 LOGE("Out-of-memory");
1018 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1022 return NOTI_EX_ERROR_NONE;
1025 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
1026 noti_ex_item_h child) {
1027 if (handle == nullptr || child == nullptr) {
1028 LOGE("Invalid parameter");
1029 return NOTI_EX_ERROR_INVALID_PARAMETER;
1031 Handle* h = static_cast<Handle*>(handle);
1032 if (!h->IsValidType(AbstractItem::Group)) {
1033 LOGE("Invalid handle type");
1034 return NOTI_EX_ERROR_INVALID_PARAMETER;
1036 auto p = static_cast<GroupItem*>(h->Get());
1037 p->AddChild((static_cast<Handle*>(child))->GetPtr());
1039 return NOTI_EX_ERROR_NONE;
1042 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
1043 const char *item_id) {
1044 if (handle == nullptr || item_id == nullptr) {
1045 LOGE("Invalid parameter");
1046 return NOTI_EX_ERROR_INVALID_PARAMETER;
1048 Handle* h = static_cast<Handle*>(handle);
1049 if (!h->IsValidType(AbstractItem::Group)) {
1050 LOGE("Invalid handle type");
1051 return NOTI_EX_ERROR_INVALID_PARAMETER;
1053 GroupItem* p = static_cast<GroupItem*>(h->Get());
1054 p->RemoveChild(std::string(item_id));
1056 return NOTI_EX_ERROR_NONE;
1059 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
1060 noti_ex_item_group_foreach_child_cb callback, void *data) {
1061 if (handle == nullptr || callback == nullptr) {
1062 LOGE("Invalid parameter");
1063 return NOTI_EX_ERROR_INVALID_PARAMETER;
1066 Handle* h = static_cast<Handle*>(handle);
1067 if (!h->IsValidType(AbstractItem::Group)) {
1068 LOGE("Invalid handle type");
1069 return NOTI_EX_ERROR_INVALID_PARAMETER;
1071 GroupItem* p = static_cast<GroupItem*>(h->Get());
1072 list<shared_ptr<AbstractItem>> children = p->GetChildren();
1073 LOGI("Retrive (%zd)", children.size());
1074 for (auto i : children) {
1077 static_cast<noti_ex_item_h>(&handle), data);
1078 if (ret != NOTI_EX_ERROR_NONE) {
1079 LOGW("callback return (%d) stop foreach", ret);
1084 return NOTI_EX_ERROR_NONE;
1087 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1088 const char *id, const char *image_path) {
1091 if (handle == nullptr || image_path == nullptr) {
1092 LOGE("Invalid parameter");
1093 return NOTI_EX_ERROR_INVALID_PARAMETER;
1097 p = new (std::nothrow) ImageItem(id, image_path);
1099 p = new (std::nothrow) ImageItem(image_path);
1102 LOGE("Out-of-memory");
1103 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1106 *handle = new Handle(shared_ptr<AbstractItem>(p));
1108 return NOTI_EX_ERROR_NONE;
1111 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1112 noti_ex_item_h handle, char **image_path) {
1113 if (handle == nullptr || image_path == nullptr) {
1114 LOGE("Invalid parameter");
1115 return NOTI_EX_ERROR_INVALID_PARAMETER;
1117 Handle* h = static_cast<Handle*>(handle);
1118 if (!h->IsValidType(AbstractItem::Image)) {
1119 LOGE("Invalid handle type");
1120 return NOTI_EX_ERROR_INVALID_PARAMETER;
1122 ImageItem* p = static_cast<ImageItem*>(h->Get());
1123 if (!p->GetImagePath().empty()) {
1124 *image_path = strdup(p->GetImagePath().c_str());
1125 if (*image_path == nullptr) {
1126 LOGE("Out-of-memory");
1127 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1130 *image_path = nullptr;
1133 return NOTI_EX_ERROR_NONE;
1136 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1137 noti_ex_item_h *handle, const char *id) {
1138 InputSelectorItem* p;
1140 if (handle == nullptr) {
1141 LOGE("Invalid parameter");
1142 return NOTI_EX_ERROR_INVALID_PARAMETER;
1146 p = new (std::nothrow) InputSelectorItem(id);
1148 p = new (std::nothrow) InputSelectorItem();
1151 LOGE("Out-of-memory");
1152 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1155 *handle = new Handle(shared_ptr<AbstractItem>(p));
1157 return NOTI_EX_ERROR_NONE;
1160 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1161 noti_ex_item_h handle, char ***contents_list, int *count) {
1162 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1163 LOGE("Invalid parameter");
1164 return NOTI_EX_ERROR_INVALID_PARAMETER;
1167 Handle* h = static_cast<Handle*>(handle);
1168 if (!h->IsValidType(AbstractItem::InputSelector)) {
1169 LOGE("Invalid handle type");
1170 return NOTI_EX_ERROR_INVALID_PARAMETER;
1173 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1174 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1175 list<string> contents;
1176 if (arr.size() == 0) {
1177 contents = p->GetContents();
1179 for (auto& i : arr) {
1180 contents.push_back(i->GetTranslatedString());
1184 char **list = (char**)calloc(contents.size(), sizeof(char*));
1185 if (list == nullptr) {
1186 LOGE("Out of memory");
1187 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1191 for (auto& i : contents) {
1192 list[idx] = strdup(i.c_str());
1193 if (list[idx] == nullptr) {
1194 __noti_ex_free_str_array(list, idx);
1195 LOGE("Out of memory");
1196 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1201 *count = contents.size();
1202 *contents_list = list;
1204 return NOTI_EX_ERROR_NONE;
1207 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1208 noti_ex_item_h handle, const char **contents, int count) {
1209 if (handle == nullptr || contents == nullptr) {
1210 LOGE("Invalid parameter");
1211 return NOTI_EX_ERROR_INVALID_PARAMETER;
1214 list<string> new_contents;
1215 Handle* h = static_cast<Handle*>(handle);
1216 if (!h->IsValidType(AbstractItem::InputSelector)) {
1217 LOGE("Invalid handle type");
1218 return NOTI_EX_ERROR_INVALID_PARAMETER;
1220 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1221 for (int i = 0; i < count; i++) {
1222 new_contents.push_back(contents[i]);
1224 p->SetContents(move(new_contents));
1226 return NOTI_EX_ERROR_NONE;
1229 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1230 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1231 if (handle == nullptr) {
1232 LOGE("Invalid parameter");
1233 return NOTI_EX_ERROR_INVALID_PARAMETER;
1236 Handle* p = static_cast<Handle*>(handle);
1237 if (!p->IsValidType(AbstractItem::InputSelector)) {
1238 LOGE("Invalid handle type");
1239 return NOTI_EX_ERROR_INVALID_PARAMETER;
1242 vector<shared_ptr<MultiLanguage>> m_list;
1243 for (int i = 0; i < count; i++) {
1244 shared_ptr<MultiLanguage> mul_ptr =
1245 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1246 mul_ptr->UpdateString();
1247 m_list.push_back(mul_ptr);
1250 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1251 input->SetMultiLanguage(m_list);
1253 return NOTI_EX_ERROR_NONE;
1256 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1257 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1258 if (handle == nullptr) {
1259 LOGE("Invalid parameter");
1260 return NOTI_EX_ERROR_INVALID_PARAMETER;
1263 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1264 new (std::nothrow) Color(a, r, g, b));
1265 if (ptr == nullptr || ptr->get() == nullptr) {
1266 LOGE("Out-of-memory");
1267 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1272 return NOTI_EX_ERROR_NONE;
1275 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1276 if (handle == nullptr) {
1277 LOGE("Invalid parameter");
1278 return NOTI_EX_ERROR_INVALID_PARAMETER;
1281 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1284 return NOTI_EX_ERROR_NONE;
1287 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1288 unsigned char *val) {
1289 if (handle == nullptr || val == nullptr) {
1290 LOGE("Invalid parameter");
1291 return NOTI_EX_ERROR_INVALID_PARAMETER;
1294 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1295 *val = (*p)->GetAVal();
1297 return NOTI_EX_ERROR_NONE;
1300 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1301 unsigned char *val) {
1302 if (handle == nullptr || val == nullptr) {
1303 LOGE("Invalid parameter");
1304 return NOTI_EX_ERROR_INVALID_PARAMETER;
1307 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1308 *val = (*p)->GetRVal();
1310 return NOTI_EX_ERROR_NONE;
1313 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1314 unsigned char *val) {
1315 if (handle == nullptr || val == nullptr) {
1316 LOGE("Invalid parameter");
1317 return NOTI_EX_ERROR_INVALID_PARAMETER;
1320 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1321 *val = (*p)->GetGVal();
1323 return NOTI_EX_ERROR_NONE;
1326 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1327 unsigned char *val) {
1328 if (handle == nullptr || val == nullptr) {
1329 LOGE("Invalid parameter");
1330 return NOTI_EX_ERROR_INVALID_PARAMETER;
1333 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1334 *val = (*p)->GetBVal();
1336 return NOTI_EX_ERROR_NONE;
1339 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1340 int left, int top, int right, int bottom) {
1341 if (handle == nullptr) {
1342 LOGE("Invalid parameter");
1343 return NOTI_EX_ERROR_INVALID_PARAMETER;
1346 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1347 new (std::nothrow) Padding(left, top, right, bottom));
1348 if (ptr == nullptr || ptr->get() == nullptr) {
1349 LOGE("Out-of-memory");
1352 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1357 return NOTI_EX_ERROR_NONE;
1360 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1361 if (handle == nullptr) {
1362 LOGE("Invalid parameter");
1363 return NOTI_EX_ERROR_INVALID_PARAMETER;
1366 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1369 return NOTI_EX_ERROR_NONE;
1372 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1374 if (handle == nullptr || val == nullptr) {
1375 LOGE("Invalid parameter");
1376 return NOTI_EX_ERROR_INVALID_PARAMETER;
1379 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1380 *val = (*p)->GetLeft();
1382 return NOTI_EX_ERROR_NONE;
1385 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1387 if (handle == nullptr || val == nullptr) {
1388 LOGE("Invalid parameter");
1389 return NOTI_EX_ERROR_INVALID_PARAMETER;
1392 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1393 *val = (*p)->GetTop();
1395 return NOTI_EX_ERROR_NONE;
1398 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1400 if (handle == nullptr || val == nullptr) {
1401 LOGE("Invalid parameter");
1402 return NOTI_EX_ERROR_INVALID_PARAMETER;
1405 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1406 *val = (*p)->GetRight();
1408 return NOTI_EX_ERROR_NONE;
1411 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1413 if (handle == nullptr || val == nullptr) {
1414 LOGE("Invalid parameter");
1415 return NOTI_EX_ERROR_INVALID_PARAMETER;
1418 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1419 *val = (*p)->GetBottom();
1421 return NOTI_EX_ERROR_NONE;
1424 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1425 int x, int y, int w, int h) {
1426 if (handle == nullptr) {
1427 LOGE("Invalid parameter");
1428 return NOTI_EX_ERROR_INVALID_PARAMETER;
1431 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1432 new (std::nothrow) Geometry(x, y, w, h));
1433 if (ptr == nullptr || ptr->get() == nullptr) {
1434 LOGE("Out-of-memory");
1437 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1442 return NOTI_EX_ERROR_NONE;
1445 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1446 if (handle == nullptr) {
1447 LOGE("Invalid parameter");
1448 return NOTI_EX_ERROR_INVALID_PARAMETER;
1451 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1454 return NOTI_EX_ERROR_NONE;
1457 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1459 if (handle == nullptr || val == nullptr) {
1460 LOGE("Invalid parameter");
1461 return NOTI_EX_ERROR_INVALID_PARAMETER;
1464 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1465 *val = (*p)->GetX();
1467 return NOTI_EX_ERROR_NONE;
1470 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1472 if (handle == nullptr || val == nullptr) {
1473 LOGE("Invalid parameter");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1478 *val = (*p)->GetY();
1480 return NOTI_EX_ERROR_NONE;
1483 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1485 if (handle == nullptr || val == nullptr) {
1486 LOGE("Invalid parameter");
1487 return NOTI_EX_ERROR_INVALID_PARAMETER;
1490 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1491 *val = (*p)->GetWidth();
1493 return NOTI_EX_ERROR_NONE;
1496 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1498 if (handle == nullptr || val == nullptr) {
1499 LOGE("Invalid parameter");
1500 return NOTI_EX_ERROR_INVALID_PARAMETER;
1503 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1504 *val = (*p)->GetHeight();
1506 return NOTI_EX_ERROR_NONE;
1509 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1510 noti_ex_color_h color,
1511 noti_ex_padding_h padding,
1512 noti_ex_geometry_h geometry) {
1513 if (handle == nullptr) {
1514 LOGE("Invalid parameter");
1515 return NOTI_EX_ERROR_INVALID_PARAMETER;
1518 shared_ptr<Color> col = (color == nullptr) ?
1519 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1520 shared_ptr<Padding> padd = (padding == nullptr) ?
1521 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1522 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1523 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1525 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1526 new (std::nothrow) Style(col, padd, geo));
1527 if (ptr == nullptr || ptr->get() == nullptr) {
1528 LOGE("Out-of-memory");
1531 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1536 return NOTI_EX_ERROR_NONE;
1539 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1540 if (handle == nullptr) {
1541 LOGE("Invalid parameter");
1542 return NOTI_EX_ERROR_INVALID_PARAMETER;
1545 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1548 return NOTI_EX_ERROR_NONE;
1551 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1552 noti_ex_padding_h *padding) {
1553 if (handle == nullptr || padding == nullptr) {
1554 LOGE("Invalid parameter");
1555 return NOTI_EX_ERROR_INVALID_PARAMETER;
1558 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1559 if ((*p)->GetPadding() == nullptr) {
1560 LOGW("Padding info is null");
1561 return NOTI_EX_ERROR_INVALID_PARAMETER;
1564 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1565 new (std::nothrow) Padding(*((*p)->GetPadding())));
1566 if (padd == nullptr || padd->get() == nullptr) {
1567 LOGE("Out-of-memory");
1569 return NOTI_EX_ERROR_NONE;
1574 return NOTI_EX_ERROR_NONE;
1578 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1579 noti_ex_padding_h padding) {
1580 if (handle == nullptr) {
1581 LOGE("Invalid parameter");
1582 return NOTI_EX_ERROR_INVALID_PARAMETER;
1585 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1586 if (padding == nullptr) {
1587 (*p)->SetPadding(nullptr);
1588 return NOTI_EX_ERROR_NONE;
1591 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1592 (*p)->SetPadding(*padd);
1594 return NOTI_EX_ERROR_NONE;
1597 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1598 noti_ex_color_h *color) {
1599 if (handle == nullptr || color == nullptr) {
1600 LOGE("Invalid parameter");
1601 return NOTI_EX_ERROR_INVALID_PARAMETER;
1604 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1605 if ((*p)->GetColor() == nullptr) {
1606 LOGW("Color info is null");
1608 return NOTI_EX_ERROR_NONE;
1611 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1612 new (std::nothrow) Color(*((*p)->GetColor())));
1613 if (col == nullptr || col->get() == nullptr) {
1614 LOGE("Out-of-memory");
1615 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1620 return NOTI_EX_ERROR_NONE;
1623 extern "C" EXPORT_API int noti_ex_style_set_color(
1624 noti_ex_style_h handle, noti_ex_color_h color) {
1625 if (handle == nullptr) {
1626 LOGE("Invalid parameter");
1627 return NOTI_EX_ERROR_INVALID_PARAMETER;
1630 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1631 if (color == nullptr) {
1632 (*p)->SetColor(nullptr);
1633 return NOTI_EX_ERROR_NONE;
1636 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1637 (*p)->SetColor(*col);
1639 return NOTI_EX_ERROR_NONE;
1642 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1643 noti_ex_geometry_h *geometry) {
1644 if (handle == nullptr || geometry == nullptr) {
1645 LOGE("Invalid parameter");
1646 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1650 if ((*p)->GetGeometry() == nullptr) {
1651 LOGW("Geometry info is null");
1652 *geometry = nullptr;
1653 return NOTI_EX_ERROR_NONE;
1656 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1657 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1658 if (geo == nullptr || geo->get() == nullptr) {
1659 LOGE("Out-of-memory");
1662 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1667 return NOTI_EX_ERROR_NONE;
1670 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1671 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1672 if (handle == nullptr) {
1673 LOGE("Invalid parameter");
1674 return NOTI_EX_ERROR_INVALID_PARAMETER;
1677 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1678 if (geometry == nullptr) {
1679 (*p)->SetGeometry(nullptr);
1680 return NOTI_EX_ERROR_NONE;
1683 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1684 (*p)->SetGeometry(*geo);
1686 return NOTI_EX_ERROR_NONE;
1689 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1690 noti_ex_style_h handle, char** background_image) {
1691 if (handle == nullptr || background_image == nullptr) {
1692 LOGE("Invalid parameter");
1693 return NOTI_EX_ERROR_INVALID_PARAMETER;
1696 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1698 if ((*p)->GetBackgroundImage().empty())
1699 *background_image = nullptr;
1701 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1707 noti_ex_style_h handle, char* background_image) {
1708 if (handle == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1714 if (background_image == nullptr)
1715 (*p)->SetBackgroundImage("");
1717 (*p)->SetBackgroundImage(background_image);
1719 return NOTI_EX_ERROR_NONE;
1722 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1723 noti_ex_style_h handle, noti_ex_color_h* color) {
1724 if (handle == nullptr || color == nullptr) {
1725 LOGE("Invalid parameter");
1726 return NOTI_EX_ERROR_INVALID_PARAMETER;
1729 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1730 if ((*p)->GetBackgroundColor() == nullptr) {
1731 LOGW("Color info is null");
1733 return NOTI_EX_ERROR_NONE;
1736 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1737 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1738 if (col == nullptr || col->get() == nullptr) {
1739 LOGE("Out-of-memory");
1740 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1745 return NOTI_EX_ERROR_NONE;
1748 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1749 noti_ex_style_h handle, noti_ex_color_h color) {
1750 if (handle == nullptr) {
1751 LOGE("Invalid parameter");
1752 return NOTI_EX_ERROR_INVALID_PARAMETER;
1755 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1756 if (color == nullptr) {
1757 (*p)->SetBackgroundColor(nullptr);
1758 return NOTI_EX_ERROR_NONE;
1761 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1762 (*p)->SetBackgroundColor(*col);
1764 return NOTI_EX_ERROR_NONE;
1767 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1768 noti_ex_color_h color) {
1769 if (handle == nullptr || color == nullptr) {
1770 LOGE("Invalid parameter");
1771 return NOTI_EX_ERROR_INVALID_PARAMETER;
1774 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1775 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1776 new (std::nothrow) LEDInfo(*color_ptr));
1778 LOGE("Out-of-memory");
1779 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1784 return NOTI_EX_ERROR_NONE;
1787 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1788 if (handle == nullptr) {
1789 LOGE("Invalid parameter");
1790 return NOTI_EX_ERROR_INVALID_PARAMETER;
1793 shared_ptr<LEDInfo>* led_ptr =
1794 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1796 return NOTI_EX_ERROR_NONE;
1799 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1800 noti_ex_led_info_h handle, int ms) {
1801 if (handle == nullptr) {
1802 LOGE("Invalid parameter");
1803 return NOTI_EX_ERROR_INVALID_PARAMETER;
1806 shared_ptr<LEDInfo>* led_ptr =
1807 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1808 (*led_ptr)->SetOnPeriod(ms);
1810 return NOTI_EX_ERROR_NONE;
1813 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1814 noti_ex_led_info_h handle, int *ms) {
1815 if (handle == nullptr || ms == nullptr) {
1816 LOGE("Invalid parameter");
1817 return NOTI_EX_ERROR_INVALID_PARAMETER;
1820 shared_ptr<LEDInfo>* led_ptr =
1821 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1822 *ms = (*led_ptr)->GetOnPeriod();
1824 return NOTI_EX_ERROR_NONE;
1827 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1828 noti_ex_led_info_h handle, int ms) {
1829 if (handle == nullptr) {
1830 LOGE("Invalid parameter");
1831 return NOTI_EX_ERROR_INVALID_PARAMETER;
1834 shared_ptr<LEDInfo>* led_ptr =
1835 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1836 (*led_ptr)->SetOffPeriod(ms);
1838 return NOTI_EX_ERROR_NONE;
1841 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1842 noti_ex_led_info_h handle, int *ms) {
1843 if (handle == nullptr) {
1844 LOGE("Invalid parameter");
1845 return NOTI_EX_ERROR_INVALID_PARAMETER;
1848 shared_ptr<LEDInfo>* led_ptr =
1849 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1850 *ms = (*led_ptr)->GetOffPeriod();
1852 return NOTI_EX_ERROR_NONE;
1855 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1856 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1857 if (handle == nullptr) {
1858 LOGE("Invalid parameter");
1859 return NOTI_EX_ERROR_INVALID_PARAMETER;
1862 shared_ptr<LEDInfo>* led_ptr =
1863 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1864 if ((*led_ptr)->GetColor() == nullptr) {
1865 LOGW("Color is null");
1867 return NOTI_EX_ERROR_NONE;
1870 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1871 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1872 if (col == nullptr || col->get() == nullptr) {
1873 LOGE("Out-of-memory");
1874 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1879 return NOTI_EX_ERROR_NONE;
1882 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1883 noti_ex_led_info_h handle, noti_ex_color_h color) {
1884 if (handle == nullptr) {
1885 LOGE("Invalid parameter");
1886 return NOTI_EX_ERROR_INVALID_PARAMETER;
1889 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1890 if (color == nullptr) {
1891 (*p)->SetColor(nullptr);
1892 return NOTI_EX_ERROR_NONE;
1895 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1896 (*p)->SetColor(*col);
1898 return NOTI_EX_ERROR_NONE;
1901 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1902 if (handle == nullptr) {
1903 LOGE("Invalid parameter");
1904 return NOTI_EX_ERROR_INVALID_PARAMETER;
1907 shared_ptr<AbstractAction>* ptr =
1908 static_cast<shared_ptr<AbstractAction>*>(handle);
1911 return NOTI_EX_ERROR_NONE;
1914 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1916 if (handle == nullptr || type == nullptr) {
1917 LOGE("Invalid parameter");
1918 return NOTI_EX_ERROR_INVALID_PARAMETER;
1921 shared_ptr<AbstractAction>* ptr =
1922 static_cast<shared_ptr<AbstractAction>*>(handle);
1923 *type = (*ptr)->GetType();
1925 return NOTI_EX_ERROR_NONE;
1928 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1930 if (handle == nullptr || local == nullptr) {
1931 LOGE("Invalid parameter");
1932 return NOTI_EX_ERROR_INVALID_PARAMETER;
1935 shared_ptr<AbstractAction>* ptr =
1936 static_cast<shared_ptr<AbstractAction>*>(handle);
1937 *local = (*ptr)->IsLocal();
1939 return NOTI_EX_ERROR_NONE;
1942 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1943 noti_ex_item_h item) {
1944 if (handle == nullptr || item == nullptr) {
1945 LOGE("Invalid parameter");
1946 return NOTI_EX_ERROR_INVALID_PARAMETER;
1948 shared_ptr<AbstractAction>* ptr =
1949 static_cast<shared_ptr<AbstractAction>*>(handle);
1950 Handle* ih = static_cast<Handle*>(item);
1951 (*ptr)->Execute(ih->GetPtr());
1953 return NOTI_EX_ERROR_NONE;
1956 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1958 if (handle == nullptr || extra == nullptr) {
1959 LOGE("Invalid parameter");
1960 return NOTI_EX_ERROR_INVALID_PARAMETER;
1963 shared_ptr<AbstractAction>* ptr =
1964 static_cast<shared_ptr<AbstractAction>*>(handle);
1965 if (!(*ptr)->GetExtra().empty()) {
1966 *extra = strdup((*ptr)->GetExtra().c_str());
1967 if (*extra == nullptr) {
1968 LOGE("Out-of-memory");
1969 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1975 return NOTI_EX_ERROR_NONE;
1978 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1979 noti_ex_item_info_h handle, int *hide_time) {
1980 if (handle == nullptr || hide_time == nullptr) {
1981 LOGE("Invalid parameter");
1982 return NOTI_EX_ERROR_INVALID_PARAMETER;
1984 IItemInfo* p = static_cast<IItemInfo*>(handle);
1985 *hide_time = p->GetHideTime();
1986 return NOTI_EX_ERROR_NONE;
1989 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1990 noti_ex_item_info_h handle, int hide_time) {
1991 if (handle == nullptr) {
1992 LOGE("Invalid parameter");
1993 return NOTI_EX_ERROR_INVALID_PARAMETER;
1995 IItemInfo* p = static_cast<IItemInfo*>(handle);
1996 p->SetHideTime(hide_time);
1997 return NOTI_EX_ERROR_NONE;
2000 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
2001 noti_ex_item_info_h handle, int *delete_time) {
2002 if (handle == nullptr || delete_time == nullptr) {
2003 LOGE("Invalid parameter");
2004 return NOTI_EX_ERROR_INVALID_PARAMETER;
2006 IItemInfo* p = static_cast<IItemInfo*>(handle);
2007 *delete_time = p->GetDeleteTime();
2008 return NOTI_EX_ERROR_NONE;
2011 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
2012 noti_ex_item_info_h handle, int delete_time) {
2013 if (handle == nullptr) {
2014 LOGE("Invalid parameter");
2015 return NOTI_EX_ERROR_INVALID_PARAMETER;
2017 IItemInfo* p = static_cast<IItemInfo*>(handle);
2018 p->SetDeleteTime(delete_time);
2019 return NOTI_EX_ERROR_NONE;
2022 extern "C" EXPORT_API int noti_ex_item_info_get_time(
2023 noti_ex_item_info_h handle, time_t *time) {
2024 if (handle == nullptr || time == nullptr) {
2025 LOGE("Invalid parameter");
2026 return NOTI_EX_ERROR_INVALID_PARAMETER;
2029 IItemInfo* p = static_cast<IItemInfo*>(handle);
2030 *time = p->GetTime();
2031 return NOTI_EX_ERROR_NONE;
2034 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
2035 if (handle == nullptr) {
2036 LOGE("Invalid parameter");
2037 return NOTI_EX_ERROR_INVALID_PARAMETER;
2040 Handle* h = static_cast<Handle*>(handle);
2042 return NOTI_EX_ERROR_NONE;
2045 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
2046 const char *id, noti_ex_item_h *item) {
2047 if (handle == nullptr) {
2048 LOGE("Invalid parameter");
2049 return NOTI_EX_ERROR_INVALID_PARAMETER;
2052 Handle* p = static_cast<Handle*>(handle);
2053 AbstractItem& find_item = p->Get()->FindByID(string(id));
2054 if (find_item.GetType() == AbstractItem::NullObject) {
2055 LOGW("Not exist ID");
2057 return NOTI_EX_ERROR_NONE;
2060 *item = new Handle(&find_item);
2061 return NOTI_EX_ERROR_NONE;
2064 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2066 if (handle == nullptr || type == nullptr) {
2067 LOGE("Invalid parameter");
2068 return NOTI_EX_ERROR_INVALID_PARAMETER;
2071 Handle* h = static_cast<Handle*>(handle);
2072 AbstractItem* p = h->Get();
2073 *type = p->GetType();
2074 return NOTI_EX_ERROR_NONE;
2077 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2079 if (handle == nullptr || id == nullptr) {
2080 LOGE("Invalid parameter");
2081 return NOTI_EX_ERROR_INVALID_PARAMETER;
2083 Handle* h = static_cast<Handle*>(handle);
2084 AbstractItem* p = h->Get();
2085 *id = strdup(p->GetId().c_str());
2086 return NOTI_EX_ERROR_NONE;
2089 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2091 if (handle == nullptr || id == nullptr) {
2092 LOGE("Invalid parameter");
2093 return NOTI_EX_ERROR_INVALID_PARAMETER;
2095 Handle* p = static_cast<Handle*>(handle);
2096 p->Get()->SetId(id);
2097 return NOTI_EX_ERROR_NONE;
2100 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2101 noti_ex_action_h *action) {
2102 if (handle == nullptr || action == nullptr) {
2103 LOGE("Invalid parameter");
2104 return NOTI_EX_ERROR_INVALID_PARAMETER;
2106 Handle* p = static_cast<Handle*>(handle);
2107 if (p->Get()->GetAction() == nullptr) {
2109 return NOTI_EX_ERROR_NONE;
2111 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2112 p->Get()->GetAction()));
2114 return NOTI_EX_ERROR_NONE;
2117 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2118 noti_ex_action_h action) {
2119 if (handle == nullptr) {
2120 LOGE("Invalid parameter");
2121 return NOTI_EX_ERROR_INVALID_PARAMETER;
2124 Handle* p = static_cast<Handle*>(handle);
2125 if (action == nullptr) {
2126 p->Get()->SetAction(nullptr);
2127 return NOTI_EX_ERROR_NONE;
2130 shared_ptr<AbstractAction>* ptr =
2131 static_cast<shared_ptr<AbstractAction>*>(action);
2132 p->Get()->SetAction(*ptr);
2133 return NOTI_EX_ERROR_NONE;
2136 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2137 noti_ex_style_h *style) {
2138 if (handle == nullptr || style == nullptr) {
2139 LOGE("Invalid parameter");
2140 return NOTI_EX_ERROR_INVALID_PARAMETER;
2143 Handle* p = static_cast<Handle*>(handle);
2144 shared_ptr<Style> s = p->Get()->GetStyle();
2145 if (s.get() == nullptr) {
2146 LOGW("Style is null");
2148 return NOTI_EX_ERROR_NONE;
2151 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2152 if (ptr == nullptr || ptr->get() == nullptr) {
2153 LOGE("Out of memory");
2156 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2160 return NOTI_EX_ERROR_NONE;
2163 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2164 noti_ex_style_h style) {
2165 if (handle == nullptr) {
2166 LOGE("Invalid parameter");
2167 return NOTI_EX_ERROR_INVALID_PARAMETER;
2170 Handle* p = static_cast<Handle*>(handle);
2171 if (style == nullptr) {
2172 p->Get()->SetStyle(nullptr);
2173 return NOTI_EX_ERROR_NONE;
2176 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2177 p->Get()->SetStyle(*s);
2178 return NOTI_EX_ERROR_NONE;
2181 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2183 if (handle == nullptr) {
2184 LOGE("Invalid parameter");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2188 Handle* p = static_cast<Handle*>(handle);
2189 p->Get()->SetVisible(visible);
2190 return NOTI_EX_ERROR_NONE;
2193 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2195 if (handle == nullptr || visible == nullptr) {
2196 LOGE("Invalid parameter");
2197 return NOTI_EX_ERROR_INVALID_PARAMETER;
2200 Handle* p = static_cast<Handle*>(handle);
2201 *visible = p->Get()->GetVisible();
2202 return NOTI_EX_ERROR_NONE;
2205 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2207 if (handle == nullptr) {
2208 LOGE("Invalid parameter");
2209 return NOTI_EX_ERROR_INVALID_PARAMETER;
2212 Handle* p = static_cast<Handle*>(handle);
2213 p->Get()->SetEnable(enable);
2214 return NOTI_EX_ERROR_NONE;
2217 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2219 if (handle == nullptr || enable == nullptr) {
2220 LOGE("Invalid parameter");
2221 return NOTI_EX_ERROR_INVALID_PARAMETER;
2224 Handle* p = static_cast<Handle*>(handle);
2225 *enable = p->Get()->GetEnable();
2226 return NOTI_EX_ERROR_NONE;
2229 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2230 const char *receiver_group) {
2231 if (handle == nullptr || receiver_group == nullptr) {
2232 LOGE("Invalid parameter");
2233 return NOTI_EX_ERROR_INVALID_PARAMETER;
2236 Handle* p = static_cast<Handle*>(handle);
2237 p->Get()->AddReceiver(receiver_group);
2238 return NOTI_EX_ERROR_NONE;
2241 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2242 const char *receiver_group) {
2243 if (handle == nullptr || receiver_group == nullptr) {
2244 LOGE("Invalid parameter");
2245 return NOTI_EX_ERROR_INVALID_PARAMETER;
2248 Handle* p = static_cast<Handle*>(handle);
2249 p->Get()->RemoveReceiver(receiver_group);
2250 return NOTI_EX_ERROR_NONE;
2253 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2254 char ***receiver_list, int *count) {
2255 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2256 LOGE("Invalid parameter");
2257 return NOTI_EX_ERROR_INVALID_PARAMETER;
2260 Handle* p = static_cast<Handle*>(handle);
2261 list<string> receivers = p->Get()->GetReceiverList();
2262 if (receivers.size() == 0) {
2263 *receiver_list = nullptr;
2265 return NOTI_EX_ERROR_NONE;
2268 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2269 if (tmp_list == nullptr) {
2270 LOGE("Out of memory");
2271 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2275 for (auto& i : receivers) {
2276 tmp_list[idx] = strdup(i.c_str());
2277 if (tmp_list[idx] == nullptr) {
2278 __noti_ex_free_str_array(tmp_list, idx);
2279 LOGE("Out of memory");
2280 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2285 *receiver_list = tmp_list;
2286 *count = receivers.size();
2287 return NOTI_EX_ERROR_NONE;
2290 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2292 if (handle == nullptr) {
2293 LOGE("Invalid parameter");
2294 return NOTI_EX_ERROR_INVALID_PARAMETER;
2297 Handle* p = static_cast<Handle*>(handle);
2298 p->Get()->SetPolicy(policy);
2299 return NOTI_EX_ERROR_NONE;
2302 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2304 if (handle == nullptr || policy == nullptr) {
2305 LOGE("Invalid parameter");
2306 return NOTI_EX_ERROR_INVALID_PARAMETER;
2309 Handle* p = static_cast<Handle*>(handle);
2310 *policy = p->Get()->GetPolicy();
2311 return NOTI_EX_ERROR_NONE;
2314 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2316 if (handle == nullptr || channel == nullptr) {
2317 LOGE("Invalid parameter");
2318 return NOTI_EX_ERROR_INVALID_PARAMETER;
2321 Handle* p = static_cast<Handle*>(handle);
2322 if (!p->Get()->GetChannel().empty())
2323 *channel = strdup(p->Get()->GetChannel().c_str());
2327 return NOTI_EX_ERROR_NONE;
2330 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2331 const char *channel) {
2332 if (handle == nullptr) {
2333 LOGE("Invalid parameter");
2334 return NOTI_EX_ERROR_INVALID_PARAMETER;
2337 Handle* p = static_cast<Handle*>(handle);
2338 p->Get()->SetChannel(channel);
2339 return NOTI_EX_ERROR_NONE;
2342 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2343 noti_ex_led_info_h led) {
2344 if (handle == nullptr) {
2345 LOGE("Invalid parameter");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2349 Handle* p = static_cast<Handle*>(handle);
2350 if (led == nullptr) {
2351 p->Get()->SetLEDInfo(nullptr);
2352 return NOTI_EX_ERROR_NONE;
2354 shared_ptr<LEDInfo>* led_ptr =
2355 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2356 p->Get()->SetLEDInfo(*led_ptr);
2357 return NOTI_EX_ERROR_NONE;
2360 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2361 noti_ex_led_info_h *led) {
2362 if (handle == nullptr) {
2363 LOGE("Invalid parameter");
2364 return NOTI_EX_ERROR_INVALID_PARAMETER;
2367 Handle* p = static_cast<Handle*>(handle);
2368 if (p->Get()->GetLEDInfo() != nullptr)
2369 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2372 return NOTI_EX_ERROR_NONE;
2375 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2377 if (handle == nullptr) {
2378 LOGE("Invalid parameter");
2379 return NOTI_EX_ERROR_INVALID_PARAMETER;
2382 Handle* p = static_cast<Handle*>(handle);
2383 if (path == nullptr)
2384 p->Get()->SetSoundPath("");
2386 p->Get()->SetSoundPath(path);
2387 return NOTI_EX_ERROR_NONE;
2390 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2392 if (handle == nullptr) {
2393 LOGE("Invalid parameter");
2394 return NOTI_EX_ERROR_INVALID_PARAMETER;
2397 Handle* p = static_cast<Handle*>(handle);
2398 if (path == nullptr)
2399 p->Get()->SetVibrationPath("");
2401 p->Get()->SetVibrationPath(path);
2402 return NOTI_EX_ERROR_NONE;
2405 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2407 if (handle == nullptr || path == nullptr) {
2408 LOGE("Invalid parameter");
2409 return NOTI_EX_ERROR_INVALID_PARAMETER;
2412 Handle* p = static_cast<Handle*>(handle);
2413 if (p->Get()->GetSoundPath().empty())
2416 *path = strdup(p->Get()->GetSoundPath().c_str());
2417 return NOTI_EX_ERROR_NONE;
2420 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2422 if (handle == nullptr || path == nullptr) {
2423 LOGE("Invalid parameter");
2424 return NOTI_EX_ERROR_INVALID_PARAMETER;
2427 Handle* p = static_cast<Handle*>(handle);
2428 if (p->Get()->GetVibrationPath().empty())
2431 *path = strdup(p->Get()->GetVibrationPath().c_str());
2432 return NOTI_EX_ERROR_NONE;
2435 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2436 noti_ex_item_info_h *info) {
2437 if (handle == nullptr || info == nullptr) {
2438 LOGE("Invalid parameter");
2439 return NOTI_EX_ERROR_INVALID_PARAMETER;
2442 Handle* p = static_cast<Handle*>(handle);
2443 if (p->Get()->GetInfo() == nullptr)
2446 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2447 return NOTI_EX_ERROR_NONE;
2450 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2452 if (handle == nullptr || id == nullptr) {
2453 LOGE("Invalid parameter");
2454 return NOTI_EX_ERROR_INVALID_PARAMETER;
2457 Handle* p = static_cast<Handle*>(handle);
2458 if (p->Get()->GetSenderAppId().empty())
2461 *id = strdup(p->Get()->GetSenderAppId().c_str());
2462 return NOTI_EX_ERROR_NONE;
2465 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2467 if (handle == nullptr || tag == nullptr) {
2468 LOGE("Invalid parameter");
2469 return NOTI_EX_ERROR_INVALID_PARAMETER;
2472 Handle* p = static_cast<Handle*>(handle);
2473 if (p->Get()->GetTag().empty())
2476 *tag = strdup(p->Get()->GetTag().c_str());
2477 return NOTI_EX_ERROR_NONE;
2480 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2482 if (handle == nullptr) {
2483 LOGE("Invalid parameter");
2484 return NOTI_EX_ERROR_INVALID_PARAMETER;
2487 Handle* p = static_cast<Handle*>(handle);
2489 p->Get()->SetTag("");
2491 p->Get()->SetTag(tag);
2492 return NOTI_EX_ERROR_NONE;
2495 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2497 if (handle == nullptr || ongoing == nullptr) {
2498 LOGE("Invalid parameter");
2499 return NOTI_EX_ERROR_INVALID_PARAMETER;
2502 Handle* p = static_cast<Handle*>(handle);
2503 *ongoing = p->Get()->GetOnGoingState();
2505 return NOTI_EX_ERROR_NONE;
2508 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2510 if (handle == nullptr) {
2511 LOGE("Invalid parameter");
2512 return NOTI_EX_ERROR_INVALID_PARAMETER;
2515 Handle* p = static_cast<Handle*>(handle);
2516 p->Get()->SetOnGoingState(ongoing);
2518 return NOTI_EX_ERROR_NONE;
2521 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2522 int type, bool* exist) {
2523 if (handle == nullptr || exist == nullptr) {
2524 LOGE("Invalid parameter");
2525 return NOTI_EX_ERROR_INVALID_PARAMETER;
2528 Handle* p = static_cast<Handle*>(handle);
2529 *exist = p->Get()->IsItemTypeExist(type);
2531 return NOTI_EX_ERROR_NONE;
2534 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2536 if (handle == nullptr || type == nullptr) {
2537 LOGE("Invalid parameter");
2538 return NOTI_EX_ERROR_INVALID_PARAMETER;
2541 Handle* p = static_cast<Handle*>(handle);
2542 *type = p->Get()->GetMainType();
2544 return NOTI_EX_ERROR_NONE;
2547 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2548 const char* id, int type) {
2549 if (handle == nullptr || id == nullptr) {
2550 LOGE("Invalid parameter");
2551 return NOTI_EX_ERROR_INVALID_PARAMETER;
2554 Handle* p = static_cast<Handle*>(handle);
2555 if (!(p->Get()->SetMainType(string(id),
2556 static_cast<AbstractItem::MainType>(type))))
2557 return NOTI_EX_ERROR_INVALID_PARAMETER;
2559 return NOTI_EX_ERROR_NONE;
2562 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2563 int type, noti_ex_item_h* item) {
2564 if (handle == nullptr || item == nullptr) {
2565 LOGE("Invalid parameter");
2566 return NOTI_EX_ERROR_INVALID_PARAMETER;
2569 Handle* h = static_cast<Handle*>(handle);
2570 if (!h->IsValidType(AbstractItem::Group)) {
2571 LOGE("Invalid handle type");
2572 return NOTI_EX_ERROR_INVALID_PARAMETER;
2575 GroupItem* p = static_cast<GroupItem*>(h->Get());
2576 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2577 if (find_item.GetType() == AbstractItem::NullObject) {
2578 LOGW("Not exist ID");
2580 return NOTI_EX_ERROR_NONE;
2582 *item = new Handle(&find_item);
2584 return NOTI_EX_ERROR_NONE;
2587 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2588 const char *key, bundle **value) {
2589 if (handle == nullptr || key == nullptr || value == nullptr) {
2590 LOGE("Invalid handle type");
2591 return NOTI_EX_ERROR_INVALID_PARAMETER;
2594 Handle* p = static_cast<Handle*>(handle);
2596 Bundle b = p->Get()->GetExtensionData(key);
2597 if (b.GetCount() == 0)
2600 *value = bundle_dup(b.GetHandle());
2602 return NOTI_EX_ERROR_NONE;
2605 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2606 const char *key, bundle *value) {
2607 if (handle == nullptr || key == nullptr || value == nullptr) {
2608 LOGE("Invalid handle type");
2609 return NOTI_EX_ERROR_INVALID_PARAMETER;
2612 Bundle b = Bundle(value);
2614 Handle* p = static_cast<Handle*>(handle);
2615 p->Get()->SetExtensionData(key, b);
2617 return NOTI_EX_ERROR_NONE;
2620 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2621 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2623 if (handle == nullptr) {
2624 LOGE("Invalid parameter");
2625 return NOTI_EX_ERROR_INVALID_PARAMETER;
2628 string receiver_group_str = "";
2630 receiver_group_str = string(receiver_group);
2632 ManagerStub* stub = new (std::nothrow) ManagerStub(
2633 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2634 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2635 receiver_group_str);
2636 if (stub == nullptr) {
2637 LOGE("Fail to create manager");
2638 return NOTI_EX_ERROR_IO_ERROR;
2641 int ret = get_last_result();
2642 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2643 LOGE("error(%d)", ret);
2647 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2648 new ManagerCallbackInfo(event_callbacks, data)));
2649 *handle = static_cast<noti_ex_manager_h>(stub);
2651 return NOTI_EX_ERROR_NONE;
2654 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2655 if (handle == nullptr) {
2656 LOGE("Invalid parameter");
2657 return NOTI_EX_ERROR_INVALID_PARAMETER;
2659 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2661 return NOTI_EX_ERROR_NONE;
2664 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2665 noti_ex_item_h **items, int *count) {
2666 if (handle == nullptr || items == nullptr || count == nullptr) {
2667 LOGE("Invalid parameter");
2668 return NOTI_EX_ERROR_INVALID_PARAMETER;
2672 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2673 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2674 int ret = get_last_result();
2675 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2676 LOGE("error(%d)", ret);
2682 if (item_list.size() == 0) {
2685 return NOTI_EX_ERROR_NONE;
2688 noti_ex_item_h* added_item =
2689 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2690 if (added_item == nullptr) {
2691 LOGE("Fail to create items");
2692 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2696 for (auto& i : item_list) {
2697 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2699 *items = added_item;
2700 *count = item_list.size();
2701 } catch (Exception &ex) {
2702 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2703 return NOTI_EX_ERROR_IO_ERROR;
2705 return NOTI_EX_ERROR_NONE;
2708 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2709 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2710 if (handle == nullptr || channel == nullptr ||
2711 items == nullptr || count == nullptr) {
2712 LOGE("Invalid parameter");
2713 return NOTI_EX_ERROR_INVALID_PARAMETER;
2717 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2718 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2719 int ret = get_last_result();
2720 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2721 LOGE("error(%d)", ret);
2727 if (item_list.size() == 0) {
2730 return NOTI_EX_ERROR_NONE;
2732 noti_ex_item_h* added_item =
2733 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2734 if (added_item == nullptr) {
2735 LOGE("Fail to create items");
2736 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2740 for (auto& i : item_list) {
2741 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2743 *items = added_item;
2744 *count = item_list.size();
2745 } catch (Exception &ex) {
2746 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2747 return NOTI_EX_ERROR_IO_ERROR;
2750 return NOTI_EX_ERROR_NONE;
2753 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2754 noti_ex_item_h noti, int *request_id) {
2755 int ret = ERROR_NONE;
2757 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2758 LOGE("Invalid parameter");
2759 return NOTI_EX_ERROR_INVALID_PARAMETER;
2762 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2763 Handle* sp = static_cast<Handle*>(noti);
2764 if (sp->GetPtr().get() == nullptr) {
2765 LOGE("Invalid noti reference can not be sended");
2766 return NOTI_EX_ERROR_INVALID_PARAMETER;
2768 ret = stub->Update(sp->GetPtr(), *request_id);
2770 } catch (Exception &ex) {
2771 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2772 return NOTI_EX_ERROR_IO_ERROR;
2777 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2778 noti_ex_item_h noti, int *request_id) {
2779 int ret = ERROR_NONE;
2781 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2782 LOGE("Invalid parameter");
2783 return NOTI_EX_ERROR_INVALID_PARAMETER;
2787 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2788 Handle* item = static_cast<Handle*>(noti);
2789 if (item->GetPtr().get() == nullptr) {
2790 LOGE("Invalid noti reference can not be sended");
2791 return NOTI_EX_ERROR_INVALID_PARAMETER;
2793 ret = stub->Delete(item->GetPtr(), *request_id);
2795 } catch (Exception &ex) {
2796 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2797 return NOTI_EX_ERROR_IO_ERROR;
2803 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2805 int ret = ERROR_NONE;
2807 if (handle == nullptr || request_id == nullptr) {
2808 LOGE("Invalid parameter");
2809 return NOTI_EX_ERROR_INVALID_PARAMETER;
2812 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2813 ret = stub->DeleteAll(*request_id);
2814 } catch (Exception &ex) {
2815 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2816 return NOTI_EX_ERROR_IO_ERROR;
2821 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2822 noti_ex_manager_h handle, const char* channel, int* request_id) {
2823 int ret = ERROR_NONE;
2825 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2826 LOGE("Invalid parameter");
2827 return NOTI_EX_ERROR_INVALID_PARAMETER;
2831 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2832 ret = stub->DeleteByChannel(channel, *request_id);
2833 } catch (Exception &ex) {
2834 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2835 return NOTI_EX_ERROR_IO_ERROR;
2841 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2842 noti_ex_manager_h handle, const char* app_id, int* request_id) {
2843 int ret = ERROR_NONE;
2845 if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2846 LOGE("Invalid parameter");
2847 return NOTI_EX_ERROR_INVALID_PARAMETER;
2851 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2852 ret = stub->DeleteByAppId(app_id, *request_id);
2853 } catch (Exception &ex) {
2854 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2855 return NOTI_EX_ERROR_IO_ERROR;
2861 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2862 noti_ex_item_h noti, int *request_id) {
2863 int ret = ERROR_NONE;
2865 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2866 LOGE("Invalid parameter");
2867 return NOTI_EX_ERROR_INVALID_PARAMETER;
2870 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2871 Handle* item = static_cast<Handle*>(noti);
2872 if (item->GetPtr().get() == nullptr) {
2873 LOGE("Invalid noti reference can not be sended");
2874 return NOTI_EX_ERROR_INVALID_PARAMETER;
2876 ret = stub->Hide(item->GetPtr(), *request_id);
2878 } catch (Exception &ex) {
2879 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2880 return NOTI_EX_ERROR_IO_ERROR;
2885 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2886 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2887 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2888 LOGE("Invalid parameter");
2889 return NOTI_EX_ERROR_INVALID_PARAMETER;
2892 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2893 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2894 int ret = get_last_result();
2895 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2896 LOGE("error(%d)", ret);
2900 if (ptr == nullptr) {
2901 LOGW("Not exist ID");
2903 return NOTI_EX_ERROR_NONE;
2905 *item = new Handle(ptr);
2906 } catch (Exception &ex) {
2907 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2908 return NOTI_EX_ERROR_IO_ERROR;
2910 return NOTI_EX_ERROR_NONE;
2913 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2914 noti_ex_event_info_h info, noti_ex_error_e error) {
2915 if (handle == nullptr || info == nullptr) {
2916 LOGE("Invalid parameter");
2917 return NOTI_EX_ERROR_INVALID_PARAMETER;
2920 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2921 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2922 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2923 static_cast<NotificationError>(error));
2925 int ret = get_last_result();
2926 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2927 LOGE("error(%d)", ret);
2930 } catch (Exception &ex) {
2931 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2932 return NOTI_EX_ERROR_IO_ERROR;
2934 return NOTI_EX_ERROR_NONE;
2937 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2938 noti_ex_manager_h handle, int *count) {
2939 if (handle == nullptr || count == nullptr) {
2940 LOGE("Invalid parameter");
2941 return NOTI_EX_ERROR_INVALID_PARAMETER;
2944 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2945 *count = stub->GetCount();
2947 int ret = get_last_result();
2948 if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2949 LOGE("error(%d)", ret);
2952 } catch (Exception &ex) {
2953 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2954 return NOTI_EX_ERROR_IO_ERROR;
2956 return NOTI_EX_ERROR_NONE;
2959 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2960 const char *id, float min, float current, float max) {
2963 if (handle == nullptr) {
2964 LOGE("Invalid parameter");
2965 return NOTI_EX_ERROR_INVALID_PARAMETER;
2969 p = new (std::nothrow) ProgressItem(id, min, current, max);
2971 p = new (std::nothrow) ProgressItem(min, current, max);
2974 LOGE("Out-of-memory");
2975 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2978 *handle = new Handle(shared_ptr<AbstractItem>(p));
2980 return NOTI_EX_ERROR_NONE;
2983 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2984 noti_ex_item_h handle, float *current) {
2985 if (handle == nullptr || current == nullptr) {
2986 LOGE("Invalid parameter");
2987 return NOTI_EX_ERROR_INVALID_PARAMETER;
2990 Handle *h = static_cast<Handle*>(handle);
2991 if (!h->IsValidType(AbstractItem::Progress)) {
2992 LOGE("Invalid handle type");
2993 return NOTI_EX_ERROR_INVALID_PARAMETER;
2995 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2996 *current = p->GetCurrent();
2998 return NOTI_EX_ERROR_NONE;
3001 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
3002 noti_ex_item_h handle, float current) {
3003 if (handle == nullptr) {
3004 LOGE("Invalid parameter");
3005 return NOTI_EX_ERROR_INVALID_PARAMETER;
3008 Handle *h = static_cast<Handle*>(handle);
3009 if (!h->IsValidType(AbstractItem::Progress)) {
3010 LOGE("Invalid handle type");
3011 return NOTI_EX_ERROR_INVALID_PARAMETER;
3013 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3014 p->SetCurrent(current);
3016 return NOTI_EX_ERROR_NONE;
3019 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
3021 if (handle == nullptr || min == nullptr) {
3022 LOGE("Invalid parameter");
3023 return NOTI_EX_ERROR_INVALID_PARAMETER;
3026 Handle *h = static_cast<Handle*>(handle);
3027 if (!h->IsValidType(AbstractItem::Progress)) {
3028 LOGE("Invalid handle type");
3029 return NOTI_EX_ERROR_INVALID_PARAMETER;
3031 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3034 return NOTI_EX_ERROR_NONE;
3037 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
3039 if (handle == nullptr || max == nullptr) {
3040 LOGE("Invalid parameter");
3041 return NOTI_EX_ERROR_INVALID_PARAMETER;
3044 Handle *h = static_cast<Handle*>(handle);
3045 if (!h->IsValidType(AbstractItem::Progress)) {
3046 LOGE("Invalid handle type");
3047 return NOTI_EX_ERROR_INVALID_PARAMETER;
3049 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3052 return NOTI_EX_ERROR_NONE;
3055 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
3057 if (handle == nullptr || type == nullptr) {
3058 LOGE("Invalid parameter");
3059 return NOTI_EX_ERROR_INVALID_PARAMETER;
3062 Handle *h = static_cast<Handle*>(handle);
3063 if (!h->IsValidType(AbstractItem::Progress)) {
3064 LOGE("Invalid handle type");
3065 return NOTI_EX_ERROR_INVALID_PARAMETER;
3067 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3068 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
3070 return NOTI_EX_ERROR_NONE;
3073 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
3075 if (handle == nullptr) {
3076 LOGE("Invalid parameter");
3077 return NOTI_EX_ERROR_INVALID_PARAMETER;
3080 Handle *h = static_cast<Handle*>(handle);
3081 if (!h->IsValidType(AbstractItem::Progress)) {
3082 LOGE("Invalid handle type");
3083 return NOTI_EX_ERROR_INVALID_PARAMETER;
3085 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3086 p->SetProgressType(static_cast<ProgressItem::Type>(type));
3088 return NOTI_EX_ERROR_NONE;
3091 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
3092 noti_ex_reporter_events_s event_callbacks, void *data) {
3093 if (handle == nullptr) {
3094 LOGE("Invalid parameter");
3095 return NOTI_EX_ERROR_INVALID_PARAMETER;
3098 ReporterStub* stub = new (std::nothrow) ReporterStub(
3099 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
3100 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
3101 if (stub == nullptr) {
3102 LOGE("Fail to create manager");
3103 return NOTI_EX_ERROR_IO_ERROR;
3105 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
3106 new ReporterCallbackInfo(event_callbacks, data)));
3108 *handle = static_cast<noti_ex_reporter_h>(stub);
3110 return NOTI_EX_ERROR_NONE;
3113 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3114 if (handle == nullptr) {
3115 LOGE("Invalid parameter");
3116 return NOTI_EX_ERROR_INVALID_PARAMETER;
3118 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3120 return NOTI_EX_ERROR_NONE;
3123 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3124 noti_ex_event_info_h info, noti_ex_error_e error) {
3125 if (handle == nullptr || info == nullptr) {
3126 LOGE("Invalid parameter");
3127 return NOTI_EX_ERROR_INVALID_PARAMETER;
3130 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3131 IEventInfo* c_info = static_cast<IEventInfo*>(info);
3132 stub->SendError(static_cast<const IEventInfo&>(*c_info),
3133 static_cast<NotificationError>(error));
3134 } catch (Exception &ex) {
3135 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3136 return NOTI_EX_ERROR_IO_ERROR;
3138 return NOTI_EX_ERROR_NONE;
3141 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3142 noti_ex_item_h noti, int *request_id) {
3143 int ret = NOTI_EX_ERROR_NONE;
3145 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3146 LOGE("Invalid parameter");
3147 return NOTI_EX_ERROR_INVALID_PARAMETER;
3150 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3151 Handle* h = static_cast<Handle*>(noti);
3152 if (h->GetPtr().get() == nullptr) {
3153 LOGE("Invalid noti reference can not be sended");
3154 return NOTI_EX_ERROR_INVALID_PARAMETER;
3156 ret = stub->Post(h->GetPtr(), *request_id);
3158 } catch (Exception &ex) {
3159 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3160 return NOTI_EX_ERROR_IO_ERROR;
3165 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3166 noti_ex_item_h *noti_list, int count, int *request_id) {
3167 int ret = NOTI_EX_ERROR_NONE;
3169 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3170 LOGE("Invalid parameter");
3171 return NOTI_EX_ERROR_INVALID_PARAMETER;
3174 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3175 list<shared_ptr<item::AbstractItem>> notiList;
3176 for (int i = 0; i < count; i++) {
3177 Handle* item = static_cast<Handle*>(noti_list[i]);
3178 notiList.push_back(item->GetPtr());
3180 ret = stub->Post(notiList, *request_id);
3181 } catch (Exception &ex) {
3182 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3183 return NOTI_EX_ERROR_IO_ERROR;
3188 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3189 noti_ex_item_h noti, int *request_id) {
3190 int ret = NOTI_EX_ERROR_NONE;
3192 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3193 LOGE("Invalid parameter");
3194 return NOTI_EX_ERROR_INVALID_PARAMETER;
3197 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3198 Handle* item = static_cast<Handle*>(noti);
3199 if (item->GetPtr().get() == nullptr) {
3200 LOGE("Invalid noti reference can not be sended");
3201 return NOTI_EX_ERROR_INVALID_PARAMETER;
3203 ret = stub->Update(item->GetPtr(), *request_id);
3205 } catch (Exception &ex) {
3206 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3207 return NOTI_EX_ERROR_IO_ERROR;
3212 extern "C" EXPORT_API int noti_ex_reporter_update_list(
3213 noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3215 int ret = NOTI_EX_ERROR_NONE;
3217 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3218 LOGE("Invalid parameter");
3219 return NOTI_EX_ERROR_INVALID_PARAMETER;
3222 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3223 list<shared_ptr<item::AbstractItem>> notiList;
3224 for (int i = 0; i < count; i++) {
3225 Handle* item = static_cast<Handle*>(noti_list[i]);
3226 notiList.push_back(item->GetPtr());
3228 ret = stub->Update(notiList, *request_id);
3229 } catch (Exception &ex) {
3230 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3231 return NOTI_EX_ERROR_IO_ERROR;
3236 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3237 noti_ex_item_h noti, int *request_id) {
3238 int ret = NOTI_EX_ERROR_NONE;
3240 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3241 LOGE("Invalid parameter");
3242 return NOTI_EX_ERROR_INVALID_PARAMETER;
3245 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3246 Handle* item = static_cast<Handle*>(noti);
3247 if (item->GetPtr().get() == nullptr) {
3248 LOGE("Invalid noti reference can not be sended");
3249 return NOTI_EX_ERROR_INVALID_PARAMETER;
3251 ret = stub->Delete(item->GetPtr(), *request_id);
3253 } catch (Exception &ex) {
3254 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3255 return NOTI_EX_ERROR_IO_ERROR;
3260 extern "C" EXPORT_API int noti_ex_reporter_delete_list(
3261 noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3263 int ret = NOTI_EX_ERROR_NONE;
3265 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3266 LOGE("Invalid parameter");
3267 return NOTI_EX_ERROR_INVALID_PARAMETER;
3271 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3272 list<shared_ptr<item::AbstractItem>> notiList;
3273 for (int i = 0; i < count; i++) {
3274 Handle* item = static_cast<Handle*>(noti_list[i]);
3275 notiList.push_back(item->GetPtr());
3277 ret = stub->Delete(notiList, *request_id);
3278 } catch (Exception &ex) {
3279 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3280 return NOTI_EX_ERROR_IO_ERROR;
3286 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3287 noti_ex_reporter_h handle, int *request_id) {
3288 int ret = NOTI_EX_ERROR_NONE;
3290 if (handle == nullptr || request_id == nullptr) {
3291 LOGE("Invalid parameter");
3292 return NOTI_EX_ERROR_INVALID_PARAMETER;
3296 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3297 ret = stub->DeleteAll(*request_id);
3298 } catch (Exception &ex) {
3299 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3300 return NOTI_EX_ERROR_IO_ERROR;
3306 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3307 noti_ex_reporter_h handle, const char* channel, int* request_id) {
3308 int ret = NOTI_EX_ERROR_NONE;
3310 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3311 LOGE("Invalid parameter");
3312 return NOTI_EX_ERROR_INVALID_PARAMETER;
3316 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3317 ret = stub->DeleteByChannel(channel, *request_id);
3318 } catch (Exception &ex) {
3319 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3320 return NOTI_EX_ERROR_IO_ERROR;
3326 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3327 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3328 if (handle == nullptr || root_id == nullptr || item == nullptr) {
3329 LOGE("Invalid parameter");
3330 return NOTI_EX_ERROR_INVALID_PARAMETER;
3333 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3334 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3335 if (ptr == nullptr) {
3336 LOGW("Not exist ID");
3338 return NOTI_EX_ERROR_NONE;
3340 *item = new Handle(ptr);
3341 } catch (Exception &ex) {
3342 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3343 return NOTI_EX_ERROR_IO_ERROR;
3345 return NOTI_EX_ERROR_NONE;
3348 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3349 const char *channel, noti_ex_item_h **noti_list, int *count) {
3350 if (handle == nullptr || channel == nullptr || noti_list == nullptr
3351 || count == nullptr) {
3352 LOGE("Invalid parameter");
3353 return NOTI_EX_ERROR_INVALID_PARAMETER;
3356 Handle** list_item = nullptr;
3359 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3360 list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3361 if (list_ptr.empty()) {
3362 LOGW("Not exist ID");
3363 *noti_list = nullptr;
3365 return NOTI_EX_ERROR_NONE;
3368 int size = list_ptr.size();
3369 list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
3370 if (list_item == nullptr) {
3371 LOGE("Out of memory");
3372 *noti_list = nullptr;
3374 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3378 for (auto& ptr : list_ptr)
3379 list_item[i++] = new Handle(std::move(ptr));
3381 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3383 } catch (Exception &ex) {
3384 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3386 return NOTI_EX_ERROR_IO_ERROR;
3389 return NOTI_EX_ERROR_NONE;
3392 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3393 noti_ex_item_h **noti_list, int *count) {
3394 if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3395 LOGE("Invalid parameter");
3396 return NOTI_EX_ERROR_INVALID_PARAMETER;
3399 Handle** list_item = nullptr;
3402 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3403 list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3404 if (list_ptr.empty()) {
3405 LOGW("Not exist ID");
3406 *noti_list = nullptr;
3407 return NOTI_EX_ERROR_NONE;
3410 int size = list_ptr.size();
3411 list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
3412 if (list_item == nullptr) {
3413 LOGE("Out of memory");
3414 *noti_list = nullptr;
3416 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3420 for (auto& ptr : list_ptr)
3421 list_item[i++] = new Handle(std::move(ptr));
3423 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3425 } catch (Exception &ex) {
3426 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3428 return NOTI_EX_ERROR_IO_ERROR;
3431 return NOTI_EX_ERROR_NONE;
3434 extern "C" EXPORT_API int noti_ex_reporter_get_count_by_channel(
3435 noti_ex_reporter_h handle, const char *channel, int *count) {
3436 if (handle == nullptr || channel == nullptr || count == nullptr) {
3437 LOGE("Invalid parameter");
3438 return NOTI_EX_ERROR_INVALID_PARAMETER;
3442 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3443 *count = stub->GetCount(channel);
3444 } catch (Exception &ex) {
3445 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3446 return NOTI_EX_ERROR_IO_ERROR;
3449 return NOTI_EX_ERROR_NONE;
3452 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3453 const char *id, const char *text, const char *hyperlink) {
3454 if (handle == nullptr || text == nullptr) {
3455 LOGE("Invalid parameter");
3456 return NOTI_EX_ERROR_INVALID_PARAMETER;
3465 p = new (std::nothrow) TextItem(id, std::string(text),
3466 std::string(hyperlink));
3468 p = new (std::nothrow) TextItem(id, std::string(text));
3471 LOGE("Out-of-memory");
3472 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3475 *handle = new Handle(shared_ptr<AbstractItem>(p));
3477 return NOTI_EX_ERROR_NONE;
3480 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3481 const char *contents) {
3482 if (handle == nullptr || contents == nullptr) {
3483 LOGE("Invalid parameter");
3484 return NOTI_EX_ERROR_INVALID_PARAMETER;
3487 Handle* p = static_cast<Handle*>(handle);
3488 if (!p->IsValidType(AbstractItem::Text)) {
3489 LOGE("Invalid handle type");
3490 return NOTI_EX_ERROR_INVALID_PARAMETER;
3492 TextItem* ti = static_cast<TextItem*>(p->Get());
3493 ti->SetContents(std::string(contents));
3495 return NOTI_EX_ERROR_NONE;
3498 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3500 if (handle == nullptr || contents == nullptr) {
3501 LOGE("Invalid parameter");
3502 return NOTI_EX_ERROR_INVALID_PARAMETER;
3505 Handle* p = static_cast<Handle*>(handle);
3506 if (!p->IsValidType(AbstractItem::Text)) {
3507 LOGE("Invalid handle type");
3508 return NOTI_EX_ERROR_INVALID_PARAMETER;
3511 TextItem* ti = static_cast<TextItem*>(p->Get());
3513 if (ti->GetMultiLanguage() != nullptr &&
3514 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3515 str = ti->GetMultiLanguage()->GetTranslatedString();
3516 else if (!ti->GetContents().empty())
3517 str = ti->GetContents();
3519 *contents = strdup(str.c_str());
3520 if (*contents == nullptr) {
3521 LOGE("Out-of-memory");
3522 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3525 return NOTI_EX_ERROR_NONE;
3528 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3529 noti_ex_item_h handle, char **hyper_link) {
3530 if (handle == nullptr || hyper_link == nullptr) {
3531 LOGE("Invalid parameter");
3532 return NOTI_EX_ERROR_INVALID_PARAMETER;
3535 Handle* p = static_cast<Handle*>(handle);
3536 if (!p->IsValidType(AbstractItem::Text)) {
3537 LOGE("Invalid handle type");
3538 return NOTI_EX_ERROR_INVALID_PARAMETER;
3540 TextItem* ti = static_cast<TextItem*>(p->Get());
3541 if (!ti->GetHyperLink().empty()) {
3542 *hyper_link = strdup(ti->GetHyperLink().c_str());
3543 if (*hyper_link == nullptr) {
3544 LOGE("Out-of-memory");
3545 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3548 *hyper_link = nullptr;
3551 return NOTI_EX_ERROR_NONE;
3554 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3555 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3556 if (handle == nullptr) {
3557 LOGE("Invalid parameter");
3558 return NOTI_EX_ERROR_INVALID_PARAMETER;
3561 Handle* p = static_cast<Handle*>(handle);
3562 if (!p->IsValidType(AbstractItem::Text)) {
3563 LOGE("Invalid handle type");
3564 return NOTI_EX_ERROR_INVALID_PARAMETER;
3567 TextItem* ti = static_cast<TextItem*>(p->Get());
3568 if (multi == nullptr) {
3569 ti->SetMultiLanguage(nullptr);
3570 return NOTI_EX_ERROR_NONE;
3573 shared_ptr<MultiLanguage> mul_ptr =
3574 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3575 ti->SetMultiLanguage(mul_ptr);
3576 ti->GetMultiLanguage()->UpdateString();
3578 return NOTI_EX_ERROR_NONE;
3581 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3582 const char *id, time_t time) {
3585 if (handle == nullptr) {
3586 LOGE("Invalid parameter");
3587 return NOTI_EX_ERROR_INVALID_PARAMETER;
3592 p = new (std::nothrow) TimeItem(id, time);
3594 p = new (std::nothrow) TimeItem(time);
3596 p = new (std::nothrow) TimeItem();
3600 LOGE("Out-of-memory");
3601 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3604 *handle = new Handle(shared_ptr<AbstractItem>(p));
3606 return NOTI_EX_ERROR_NONE;
3609 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3611 if (handle == nullptr || time == nullptr) {
3612 LOGE("Invalid parameter");
3613 return NOTI_EX_ERROR_INVALID_PARAMETER;
3615 Handle* h = static_cast<Handle*>(handle);
3616 if (!h->IsValidType(AbstractItem::Time)) {
3617 LOGE("Invalid handle type");
3618 return NOTI_EX_ERROR_INVALID_PARAMETER;
3620 TimeItem* p = static_cast<TimeItem*>(h->Get());
3621 *time = p->GetTime();
3623 return NOTI_EX_ERROR_NONE;
3626 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3628 if (handle == nullptr) {
3629 LOGE("Invalid parameter");
3630 return NOTI_EX_ERROR_INVALID_PARAMETER;
3632 Handle* h = static_cast<Handle*>(handle);
3633 if (!h->IsValidType(AbstractItem::Time)) {
3634 LOGE("Invalid handle type");
3635 return NOTI_EX_ERROR_INVALID_PARAMETER;
3637 TimeItem* p = static_cast<TimeItem*>(h->Get());
3640 return NOTI_EX_ERROR_NONE;
3643 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3644 noti_ex_action_h *handle, const char *extra) {
3645 if (handle == nullptr) {
3646 LOGE("Invalid parameter");
3647 return NOTI_EX_ERROR_INVALID_PARAMETER;
3650 string extra_str = "";
3652 extra_str = string(extra);
3654 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3655 new (std::nothrow) VisibilityAction(extra_str));
3656 if (ptr == nullptr) {
3657 LOGE("Out-of-memory");
3658 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3663 return NOTI_EX_ERROR_NONE;
3666 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3667 const char *id, bool visible) {
3668 if (handle == nullptr || id == nullptr) {
3669 LOGE("Invalid parameter");
3670 return NOTI_EX_ERROR_INVALID_PARAMETER;
3673 shared_ptr<AbstractAction>* ptr =
3674 static_cast<shared_ptr<AbstractAction>*>(handle);
3675 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3676 action->SetVisibility(id, visible);
3678 return NOTI_EX_ERROR_NONE;
3681 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3682 const char* msgid, const char* format, ...) {
3683 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3684 LOGE("Invalid parameter");
3685 return NOTI_EX_ERROR_INVALID_PARAMETER;
3688 const char* format_idx = format;
3691 va_start(args, format);
3692 while (*format_idx != '\0') {
3693 char* arg = nullptr;
3696 stringstream stream;
3697 if (*format_idx == '%') {
3698 switch (*(format_idx + 1)) {
3700 arg = va_arg(args, char *);
3701 arr.push_back(string(arg));
3704 arg_i = va_arg(args, int);
3705 arr.push_back(to_string(arg_i));
3708 arg_f = va_arg(args, double);
3709 stream << std::fixed << std::setprecision(2) << arg_f;
3710 arr.push_back(stream.str());
3718 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3720 LOGE("Out-of-memory");
3721 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3723 *handle = new shared_ptr<MultiLanguage>(p);
3725 return NOTI_EX_ERROR_NONE;
3728 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3729 if (handle == nullptr) {
3730 LOGE("Invalid parameter");
3731 return NOTI_EX_ERROR_INVALID_PARAMETER;
3734 shared_ptr<MultiLanguage>* mul_ptr =
3735 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3737 return NOTI_EX_ERROR_NONE;
3740 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3741 noti_ex_item_h handle, int64_t* private_id) {
3742 if (handle == nullptr || private_id == nullptr) {
3743 LOGE("Invalid parameter");
3744 return NOTI_EX_ERROR_INVALID_PARAMETER;
3747 Handle* h = static_cast<Handle*>(handle);
3748 *private_id = static_pointer_cast<IItemInfoInternal>(
3749 h->Get()->GetInfo())->GetPrivateId();
3751 return NOTI_EX_ERROR_NONE;
3754 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3755 if (list == nullptr) {
3756 LOGE("Invalid parameter");
3757 return NOTI_EX_ERROR_INVALID_PARAMETER;
3760 LOGI("Free strings (%d)", count);
3761 for (int i = 0; i < count; i++)
3765 return NOTI_EX_ERROR_NONE;
3768 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3769 if (handle == nullptr) {
3770 LOGE("Invalid parameter");
3771 return NOTI_EX_ERROR_INVALID_PARAMETER;
3773 Handle* h = static_cast<Handle*>(handle);
3774 if (!h->IsValidType(AbstractItem::Group)) {
3775 LOGE("Invalid handle type");
3776 return NOTI_EX_ERROR_INVALID_PARAMETER;
3778 GroupItem* p = static_cast<GroupItem*>(h->Get());
3779 p->RemoveChildren();
3781 return NOTI_EX_ERROR_NONE;
3784 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3785 const char *id, const char *icon_path) {
3786 if (handle == nullptr || icon_path == nullptr) {
3787 LOGE("Invalid parameter");
3788 return NOTI_EX_ERROR_INVALID_PARAMETER;
3793 p = new (std::nothrow) IconItem(id, icon_path);
3795 p = new (std::nothrow) IconItem(icon_path);
3798 LOGE("Out-of-memory");
3799 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3802 *handle = new Handle(shared_ptr<AbstractItem>(p));
3804 return NOTI_EX_ERROR_NONE;
3807 extern "C" EXPORT_API int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3808 if (handle == nullptr || icon_path == nullptr) {
3809 LOGE("Invalid parameter");
3810 return NOTI_EX_ERROR_INVALID_PARAMETER;
3813 Handle* h = static_cast<Handle*>(handle);
3814 if (!h->IsValidType(AbstractItem::Icon)) {
3815 LOGE("Invalid handle type");
3816 return NOTI_EX_ERROR_INVALID_PARAMETER;
3819 IconItem* p = static_cast<IconItem*>(h->Get());
3820 if (!p->GetImagePath().empty()) {
3821 *icon_path = strdup(p->GetImagePath().c_str());
3822 if (*icon_path == nullptr) {
3823 LOGE("Out-of-memory");
3824 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3827 *icon_path = nullptr;
3830 return NOTI_EX_ERROR_NONE;