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) {
1076 static_cast<noti_ex_item_h>(new Handle(i)), data);
1077 if (ret != NOTI_EX_ERROR_NONE) {
1078 LOGW("callback return (%d) stop foreach", ret);
1083 return NOTI_EX_ERROR_NONE;
1086 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1087 const char *id, const char *image_path) {
1090 if (handle == nullptr || image_path == nullptr) {
1091 LOGE("Invalid parameter");
1092 return NOTI_EX_ERROR_INVALID_PARAMETER;
1096 p = new (std::nothrow) ImageItem(id, image_path);
1098 p = new (std::nothrow) ImageItem(image_path);
1101 LOGE("Out-of-memory");
1102 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1105 *handle = new Handle(shared_ptr<AbstractItem>(p));
1107 return NOTI_EX_ERROR_NONE;
1110 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1111 noti_ex_item_h handle, char **image_path) {
1112 if (handle == nullptr || image_path == nullptr) {
1113 LOGE("Invalid parameter");
1114 return NOTI_EX_ERROR_INVALID_PARAMETER;
1116 Handle* h = static_cast<Handle*>(handle);
1117 if (!h->IsValidType(AbstractItem::Image)) {
1118 LOGE("Invalid handle type");
1119 return NOTI_EX_ERROR_INVALID_PARAMETER;
1121 ImageItem* p = static_cast<ImageItem*>(h->Get());
1122 if (!p->GetImagePath().empty()) {
1123 *image_path = strdup(p->GetImagePath().c_str());
1124 if (*image_path == nullptr) {
1125 LOGE("Out-of-memory");
1126 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1129 *image_path = nullptr;
1132 return NOTI_EX_ERROR_NONE;
1135 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1136 noti_ex_item_h *handle, const char *id) {
1137 InputSelectorItem* p;
1139 if (handle == nullptr) {
1140 LOGE("Invalid parameter");
1141 return NOTI_EX_ERROR_INVALID_PARAMETER;
1145 p = new (std::nothrow) InputSelectorItem(id);
1147 p = new (std::nothrow) InputSelectorItem();
1150 LOGE("Out-of-memory");
1151 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1154 *handle = new Handle(shared_ptr<AbstractItem>(p));
1156 return NOTI_EX_ERROR_NONE;
1159 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1160 noti_ex_item_h handle, char ***contents_list, int *count) {
1161 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1162 LOGE("Invalid parameter");
1163 return NOTI_EX_ERROR_INVALID_PARAMETER;
1166 Handle* h = static_cast<Handle*>(handle);
1167 if (!h->IsValidType(AbstractItem::InputSelector)) {
1168 LOGE("Invalid handle type");
1169 return NOTI_EX_ERROR_INVALID_PARAMETER;
1172 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1173 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1174 list<string> contents;
1175 if (arr.size() == 0) {
1176 contents = p->GetContents();
1178 for (auto& i : arr) {
1179 contents.push_back(i->GetTranslatedString());
1183 char **list = (char**)calloc(contents.size(), sizeof(char*));
1184 if (list == nullptr) {
1185 LOGE("Out of memory");
1186 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1190 for (auto& i : contents) {
1191 list[idx] = strdup(i.c_str());
1192 if (list[idx] == nullptr) {
1193 __noti_ex_free_str_array(list, idx);
1194 LOGE("Out of memory");
1195 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1200 *count = contents.size();
1201 *contents_list = list;
1203 return NOTI_EX_ERROR_NONE;
1206 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1207 noti_ex_item_h handle, const char **contents, int count) {
1208 if (handle == nullptr || contents == nullptr) {
1209 LOGE("Invalid parameter");
1210 return NOTI_EX_ERROR_INVALID_PARAMETER;
1213 list<string> new_contents;
1214 Handle* h = static_cast<Handle*>(handle);
1215 if (!h->IsValidType(AbstractItem::InputSelector)) {
1216 LOGE("Invalid handle type");
1217 return NOTI_EX_ERROR_INVALID_PARAMETER;
1219 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1220 for (int i = 0; i < count; i++) {
1221 new_contents.push_back(contents[i]);
1223 p->SetContents(move(new_contents));
1225 return NOTI_EX_ERROR_NONE;
1228 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1229 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1230 if (handle == nullptr) {
1231 LOGE("Invalid parameter");
1232 return NOTI_EX_ERROR_INVALID_PARAMETER;
1235 Handle* p = static_cast<Handle*>(handle);
1236 if (!p->IsValidType(AbstractItem::InputSelector)) {
1237 LOGE("Invalid handle type");
1238 return NOTI_EX_ERROR_INVALID_PARAMETER;
1241 vector<shared_ptr<MultiLanguage>> m_list;
1242 for (int i = 0; i < count; i++) {
1243 shared_ptr<MultiLanguage> mul_ptr =
1244 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1245 mul_ptr->UpdateString();
1246 m_list.push_back(mul_ptr);
1249 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1250 input->SetMultiLanguage(m_list);
1252 return NOTI_EX_ERROR_NONE;
1255 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1256 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1257 if (handle == nullptr) {
1258 LOGE("Invalid parameter");
1259 return NOTI_EX_ERROR_INVALID_PARAMETER;
1262 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1263 new (std::nothrow) Color(a, r, g, b));
1264 if (ptr == nullptr || ptr->get() == nullptr) {
1265 LOGE("Out-of-memory");
1266 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1271 return NOTI_EX_ERROR_NONE;
1274 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1275 if (handle == nullptr) {
1276 LOGE("Invalid parameter");
1277 return NOTI_EX_ERROR_INVALID_PARAMETER;
1280 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1283 return NOTI_EX_ERROR_NONE;
1286 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1287 unsigned char *val) {
1288 if (handle == nullptr || val == nullptr) {
1289 LOGE("Invalid parameter");
1290 return NOTI_EX_ERROR_INVALID_PARAMETER;
1293 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1294 *val = (*p)->GetAVal();
1296 return NOTI_EX_ERROR_NONE;
1299 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1300 unsigned char *val) {
1301 if (handle == nullptr || val == nullptr) {
1302 LOGE("Invalid parameter");
1303 return NOTI_EX_ERROR_INVALID_PARAMETER;
1306 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1307 *val = (*p)->GetRVal();
1309 return NOTI_EX_ERROR_NONE;
1312 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1313 unsigned char *val) {
1314 if (handle == nullptr || val == nullptr) {
1315 LOGE("Invalid parameter");
1316 return NOTI_EX_ERROR_INVALID_PARAMETER;
1319 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1320 *val = (*p)->GetGVal();
1322 return NOTI_EX_ERROR_NONE;
1325 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1326 unsigned char *val) {
1327 if (handle == nullptr || val == nullptr) {
1328 LOGE("Invalid parameter");
1329 return NOTI_EX_ERROR_INVALID_PARAMETER;
1332 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1333 *val = (*p)->GetBVal();
1335 return NOTI_EX_ERROR_NONE;
1338 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1339 int left, int top, int right, int bottom) {
1340 if (handle == nullptr) {
1341 LOGE("Invalid parameter");
1342 return NOTI_EX_ERROR_INVALID_PARAMETER;
1345 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1346 new (std::nothrow) Padding(left, top, right, bottom));
1347 if (ptr == nullptr || ptr->get() == nullptr) {
1348 LOGE("Out-of-memory");
1349 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1354 return NOTI_EX_ERROR_NONE;
1357 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1358 if (handle == nullptr) {
1359 LOGE("Invalid parameter");
1360 return NOTI_EX_ERROR_INVALID_PARAMETER;
1363 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1366 return NOTI_EX_ERROR_NONE;
1369 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1371 if (handle == nullptr || val == nullptr) {
1372 LOGE("Invalid parameter");
1373 return NOTI_EX_ERROR_INVALID_PARAMETER;
1376 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1377 *val = (*p)->GetLeft();
1379 return NOTI_EX_ERROR_NONE;
1382 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1384 if (handle == nullptr || val == nullptr) {
1385 LOGE("Invalid parameter");
1386 return NOTI_EX_ERROR_INVALID_PARAMETER;
1389 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1390 *val = (*p)->GetTop();
1392 return NOTI_EX_ERROR_NONE;
1395 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1397 if (handle == nullptr || val == nullptr) {
1398 LOGE("Invalid parameter");
1399 return NOTI_EX_ERROR_INVALID_PARAMETER;
1402 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1403 *val = (*p)->GetRight();
1405 return NOTI_EX_ERROR_NONE;
1408 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1410 if (handle == nullptr || val == nullptr) {
1411 LOGE("Invalid parameter");
1412 return NOTI_EX_ERROR_INVALID_PARAMETER;
1415 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1416 *val = (*p)->GetBottom();
1418 return NOTI_EX_ERROR_NONE;
1421 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1422 int x, int y, int w, int h) {
1423 if (handle == nullptr) {
1424 LOGE("Invalid parameter");
1425 return NOTI_EX_ERROR_INVALID_PARAMETER;
1428 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1429 new (std::nothrow) Geometry(x, y, w, h));
1430 if (ptr == nullptr || ptr->get() == nullptr) {
1431 LOGE("Out-of-memory");
1432 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1437 return NOTI_EX_ERROR_NONE;
1440 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1441 if (handle == nullptr) {
1442 LOGE("Invalid parameter");
1443 return NOTI_EX_ERROR_INVALID_PARAMETER;
1446 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1449 return NOTI_EX_ERROR_NONE;
1452 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1454 if (handle == nullptr || val == nullptr) {
1455 LOGE("Invalid parameter");
1456 return NOTI_EX_ERROR_INVALID_PARAMETER;
1459 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1460 *val = (*p)->GetX();
1462 return NOTI_EX_ERROR_NONE;
1465 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1467 if (handle == nullptr || val == nullptr) {
1468 LOGE("Invalid parameter");
1469 return NOTI_EX_ERROR_INVALID_PARAMETER;
1472 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1473 *val = (*p)->GetY();
1475 return NOTI_EX_ERROR_NONE;
1478 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1480 if (handle == nullptr || val == nullptr) {
1481 LOGE("Invalid parameter");
1482 return NOTI_EX_ERROR_INVALID_PARAMETER;
1485 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1486 *val = (*p)->GetWidth();
1488 return NOTI_EX_ERROR_NONE;
1491 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1493 if (handle == nullptr || val == nullptr) {
1494 LOGE("Invalid parameter");
1495 return NOTI_EX_ERROR_INVALID_PARAMETER;
1498 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1499 *val = (*p)->GetHeight();
1501 return NOTI_EX_ERROR_NONE;
1504 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1505 noti_ex_color_h color,
1506 noti_ex_padding_h padding,
1507 noti_ex_geometry_h geometry) {
1508 if (handle == nullptr) {
1509 LOGE("Invalid parameter");
1510 return NOTI_EX_ERROR_INVALID_PARAMETER;
1513 shared_ptr<Color> col = (color == nullptr) ?
1514 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1515 shared_ptr<Padding> padd = (padding == nullptr) ?
1516 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1517 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1518 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1520 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1521 new (std::nothrow) Style(col, padd, geo));
1522 if (ptr == nullptr || ptr->get() == nullptr) {
1523 LOGE("Out-of-memory");
1524 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1529 return NOTI_EX_ERROR_NONE;
1532 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1533 if (handle == nullptr) {
1534 LOGE("Invalid parameter");
1535 return NOTI_EX_ERROR_INVALID_PARAMETER;
1538 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1541 return NOTI_EX_ERROR_NONE;
1544 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1545 noti_ex_padding_h *padding) {
1546 if (handle == nullptr || padding == nullptr) {
1547 LOGE("Invalid parameter");
1548 return NOTI_EX_ERROR_INVALID_PARAMETER;
1551 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1552 if ((*p)->GetPadding() == nullptr) {
1553 LOGW("Padding info is null");
1554 return NOTI_EX_ERROR_INVALID_PARAMETER;
1557 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1558 new (std::nothrow) Padding(*((*p)->GetPadding())));
1559 if (padd == nullptr || padd->get() == nullptr) {
1560 LOGE("Out-of-memory");
1562 return NOTI_EX_ERROR_NONE;
1567 return NOTI_EX_ERROR_NONE;
1571 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1572 noti_ex_padding_h padding) {
1573 if (handle == nullptr) {
1574 LOGE("Invalid parameter");
1575 return NOTI_EX_ERROR_INVALID_PARAMETER;
1578 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1579 if (padding == nullptr) {
1580 (*p)->SetPadding(nullptr);
1581 return NOTI_EX_ERROR_NONE;
1584 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1585 (*p)->SetPadding(*padd);
1587 return NOTI_EX_ERROR_NONE;
1590 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1591 noti_ex_color_h *color) {
1592 if (handle == nullptr || color == nullptr) {
1593 LOGE("Invalid parameter");
1594 return NOTI_EX_ERROR_INVALID_PARAMETER;
1597 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1598 if ((*p)->GetColor() == nullptr) {
1599 LOGW("Color info is null");
1601 return NOTI_EX_ERROR_NONE;
1604 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1605 new (std::nothrow) Color(*((*p)->GetColor())));
1606 if (col == nullptr || col->get() == nullptr) {
1607 LOGE("Out-of-memory");
1608 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1613 return NOTI_EX_ERROR_NONE;
1616 extern "C" EXPORT_API int noti_ex_style_set_color(
1617 noti_ex_style_h handle, noti_ex_color_h color) {
1618 if (handle == nullptr) {
1619 LOGE("Invalid parameter");
1620 return NOTI_EX_ERROR_INVALID_PARAMETER;
1623 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1624 if (color == nullptr) {
1625 (*p)->SetColor(nullptr);
1626 return NOTI_EX_ERROR_NONE;
1629 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1630 (*p)->SetColor(*col);
1632 return NOTI_EX_ERROR_NONE;
1635 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1636 noti_ex_geometry_h *geometry) {
1637 if (handle == nullptr || geometry == nullptr) {
1638 LOGE("Invalid parameter");
1639 return NOTI_EX_ERROR_INVALID_PARAMETER;
1642 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1643 if ((*p)->GetGeometry() == nullptr) {
1644 LOGW("Geometry info is null");
1645 *geometry = nullptr;
1646 return NOTI_EX_ERROR_NONE;
1649 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1650 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1651 if (geo == nullptr || geo->get() == nullptr) {
1652 LOGE("Out-of-memory");
1653 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1658 return NOTI_EX_ERROR_NONE;
1661 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1662 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1663 if (handle == nullptr) {
1664 LOGE("Invalid parameter");
1665 return NOTI_EX_ERROR_INVALID_PARAMETER;
1668 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1669 if (geometry == nullptr) {
1670 (*p)->SetGeometry(nullptr);
1671 return NOTI_EX_ERROR_NONE;
1674 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1675 (*p)->SetGeometry(*geo);
1677 return NOTI_EX_ERROR_NONE;
1680 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1681 noti_ex_style_h handle, char** background_image) {
1682 if (handle == nullptr || background_image == nullptr) {
1683 LOGE("Invalid parameter");
1684 return NOTI_EX_ERROR_INVALID_PARAMETER;
1687 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1689 if ((*p)->GetBackgroundImage().empty())
1690 *background_image = nullptr;
1692 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1694 return NOTI_EX_ERROR_NONE;
1697 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1698 noti_ex_style_h handle, char* background_image) {
1699 if (handle == nullptr) {
1700 LOGE("Invalid parameter");
1701 return NOTI_EX_ERROR_INVALID_PARAMETER;
1704 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1705 if (background_image == nullptr)
1706 (*p)->SetBackgroundImage("");
1708 (*p)->SetBackgroundImage(background_image);
1710 return NOTI_EX_ERROR_NONE;
1713 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1714 noti_ex_style_h handle, noti_ex_color_h* color) {
1715 if (handle == nullptr || color == nullptr) {
1716 LOGE("Invalid parameter");
1717 return NOTI_EX_ERROR_INVALID_PARAMETER;
1720 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1721 if ((*p)->GetBackgroundColor() == nullptr) {
1722 LOGW("Color info is null");
1724 return NOTI_EX_ERROR_NONE;
1727 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1728 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1729 if (col == nullptr || col->get() == nullptr) {
1730 LOGE("Out-of-memory");
1731 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1736 return NOTI_EX_ERROR_NONE;
1739 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1740 noti_ex_style_h handle, noti_ex_color_h color) {
1741 if (handle == nullptr) {
1742 LOGE("Invalid parameter");
1743 return NOTI_EX_ERROR_INVALID_PARAMETER;
1746 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1747 if (color == nullptr) {
1748 (*p)->SetBackgroundColor(nullptr);
1749 return NOTI_EX_ERROR_NONE;
1752 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1753 (*p)->SetBackgroundColor(*col);
1755 return NOTI_EX_ERROR_NONE;
1758 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1759 noti_ex_color_h color) {
1760 if (handle == nullptr || color == nullptr) {
1761 LOGE("Invalid parameter");
1762 return NOTI_EX_ERROR_INVALID_PARAMETER;
1765 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1766 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1767 new (std::nothrow) LEDInfo(*color_ptr));
1769 LOGE("Out-of-memory");
1770 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1775 return NOTI_EX_ERROR_NONE;
1778 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1779 if (handle == nullptr) {
1780 LOGE("Invalid parameter");
1781 return NOTI_EX_ERROR_INVALID_PARAMETER;
1784 shared_ptr<LEDInfo>* led_ptr =
1785 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1787 return NOTI_EX_ERROR_NONE;
1790 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1791 noti_ex_led_info_h handle, int ms) {
1792 if (handle == nullptr) {
1793 LOGE("Invalid parameter");
1794 return NOTI_EX_ERROR_INVALID_PARAMETER;
1797 shared_ptr<LEDInfo>* led_ptr =
1798 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1799 (*led_ptr)->SetOnPeriod(ms);
1801 return NOTI_EX_ERROR_NONE;
1804 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1805 noti_ex_led_info_h handle, int *ms) {
1806 if (handle == nullptr || ms == nullptr) {
1807 LOGE("Invalid parameter");
1808 return NOTI_EX_ERROR_INVALID_PARAMETER;
1811 shared_ptr<LEDInfo>* led_ptr =
1812 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1813 *ms = (*led_ptr)->GetOnPeriod();
1815 return NOTI_EX_ERROR_NONE;
1818 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1819 noti_ex_led_info_h handle, int ms) {
1820 if (handle == nullptr) {
1821 LOGE("Invalid parameter");
1822 return NOTI_EX_ERROR_INVALID_PARAMETER;
1825 shared_ptr<LEDInfo>* led_ptr =
1826 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1827 (*led_ptr)->SetOffPeriod(ms);
1829 return NOTI_EX_ERROR_NONE;
1832 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1833 noti_ex_led_info_h handle, int *ms) {
1834 if (handle == nullptr) {
1835 LOGE("Invalid parameter");
1836 return NOTI_EX_ERROR_INVALID_PARAMETER;
1839 shared_ptr<LEDInfo>* led_ptr =
1840 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1841 *ms = (*led_ptr)->GetOffPeriod();
1843 return NOTI_EX_ERROR_NONE;
1846 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1847 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1848 if (handle == nullptr) {
1849 LOGE("Invalid parameter");
1850 return NOTI_EX_ERROR_INVALID_PARAMETER;
1853 shared_ptr<LEDInfo>* led_ptr =
1854 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1855 if ((*led_ptr)->GetColor() == nullptr) {
1856 LOGW("Color is null");
1858 return NOTI_EX_ERROR_NONE;
1861 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1862 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1863 if (col == nullptr || col->get() == nullptr) {
1864 LOGE("Out-of-memory");
1865 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1870 return NOTI_EX_ERROR_NONE;
1873 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1874 noti_ex_led_info_h handle, noti_ex_color_h color) {
1875 if (handle == nullptr) {
1876 LOGE("Invalid parameter");
1877 return NOTI_EX_ERROR_INVALID_PARAMETER;
1880 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1881 if (color == nullptr) {
1882 (*p)->SetColor(nullptr);
1883 return NOTI_EX_ERROR_NONE;
1886 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1887 (*p)->SetColor(*col);
1889 return NOTI_EX_ERROR_NONE;
1892 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1893 if (handle == nullptr) {
1894 LOGE("Invalid parameter");
1895 return NOTI_EX_ERROR_INVALID_PARAMETER;
1898 shared_ptr<AbstractAction>* ptr =
1899 static_cast<shared_ptr<AbstractAction>*>(handle);
1902 return NOTI_EX_ERROR_NONE;
1905 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1907 if (handle == nullptr || type == nullptr) {
1908 LOGE("Invalid parameter");
1909 return NOTI_EX_ERROR_INVALID_PARAMETER;
1912 shared_ptr<AbstractAction>* ptr =
1913 static_cast<shared_ptr<AbstractAction>*>(handle);
1914 *type = (*ptr)->GetType();
1916 return NOTI_EX_ERROR_NONE;
1919 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1921 if (handle == nullptr || local == nullptr) {
1922 LOGE("Invalid parameter");
1923 return NOTI_EX_ERROR_INVALID_PARAMETER;
1926 shared_ptr<AbstractAction>* ptr =
1927 static_cast<shared_ptr<AbstractAction>*>(handle);
1928 *local = (*ptr)->IsLocal();
1930 return NOTI_EX_ERROR_NONE;
1933 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1934 noti_ex_item_h item) {
1935 if (handle == nullptr || item == nullptr) {
1936 LOGE("Invalid parameter");
1937 return NOTI_EX_ERROR_INVALID_PARAMETER;
1939 shared_ptr<AbstractAction>* ptr =
1940 static_cast<shared_ptr<AbstractAction>*>(handle);
1941 Handle* ih = static_cast<Handle*>(item);
1942 (*ptr)->Execute(ih->GetPtr());
1944 return NOTI_EX_ERROR_NONE;
1947 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1949 if (handle == nullptr || extra == nullptr) {
1950 LOGE("Invalid parameter");
1951 return NOTI_EX_ERROR_INVALID_PARAMETER;
1954 shared_ptr<AbstractAction>* ptr =
1955 static_cast<shared_ptr<AbstractAction>*>(handle);
1956 if (!(*ptr)->GetExtra().empty()) {
1957 *extra = strdup((*ptr)->GetExtra().c_str());
1958 if (*extra == nullptr) {
1959 LOGE("Out-of-memory");
1960 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1970 noti_ex_item_info_h handle, int *hide_time) {
1971 if (handle == nullptr || hide_time == nullptr) {
1972 LOGE("Invalid parameter");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1975 IItemInfo* p = static_cast<IItemInfo*>(handle);
1976 *hide_time = p->GetHideTime();
1977 return NOTI_EX_ERROR_NONE;
1980 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1981 noti_ex_item_info_h handle, int hide_time) {
1982 if (handle == nullptr) {
1983 LOGE("Invalid parameter");
1984 return NOTI_EX_ERROR_INVALID_PARAMETER;
1986 IItemInfo* p = static_cast<IItemInfo*>(handle);
1987 p->SetHideTime(hide_time);
1988 return NOTI_EX_ERROR_NONE;
1991 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1992 noti_ex_item_info_h handle, int *delete_time) {
1993 if (handle == nullptr || delete_time == nullptr) {
1994 LOGE("Invalid parameter");
1995 return NOTI_EX_ERROR_INVALID_PARAMETER;
1997 IItemInfo* p = static_cast<IItemInfo*>(handle);
1998 *delete_time = p->GetDeleteTime();
1999 return NOTI_EX_ERROR_NONE;
2002 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
2003 noti_ex_item_info_h handle, int delete_time) {
2004 if (handle == nullptr) {
2005 LOGE("Invalid parameter");
2006 return NOTI_EX_ERROR_INVALID_PARAMETER;
2008 IItemInfo* p = static_cast<IItemInfo*>(handle);
2009 p->SetDeleteTime(delete_time);
2010 return NOTI_EX_ERROR_NONE;
2013 extern "C" EXPORT_API int noti_ex_item_info_get_time(
2014 noti_ex_item_info_h handle, time_t *time) {
2015 if (handle == nullptr || time == nullptr) {
2016 LOGE("Invalid parameter");
2017 return NOTI_EX_ERROR_INVALID_PARAMETER;
2020 IItemInfo* p = static_cast<IItemInfo*>(handle);
2021 *time = p->GetTime();
2022 return NOTI_EX_ERROR_NONE;
2025 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
2026 if (handle == nullptr) {
2027 LOGE("Invalid parameter");
2028 return NOTI_EX_ERROR_INVALID_PARAMETER;
2031 Handle* h = static_cast<Handle*>(handle);
2033 return NOTI_EX_ERROR_NONE;
2036 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
2037 const char *id, noti_ex_item_h *item) {
2038 if (handle == nullptr) {
2039 LOGE("Invalid parameter");
2040 return NOTI_EX_ERROR_INVALID_PARAMETER;
2043 Handle* p = static_cast<Handle*>(handle);
2044 AbstractItem& find_item = p->Get()->FindByID(string(id));
2045 if (find_item.GetType() == AbstractItem::NullObject) {
2046 LOGW("Not exist ID");
2048 return NOTI_EX_ERROR_NONE;
2051 *item = new Handle(&find_item);
2052 return NOTI_EX_ERROR_NONE;
2055 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2057 if (handle == nullptr || type == nullptr) {
2058 LOGE("Invalid parameter");
2059 return NOTI_EX_ERROR_INVALID_PARAMETER;
2062 Handle* h = static_cast<Handle*>(handle);
2063 AbstractItem* p = h->Get();
2064 *type = p->GetType();
2065 return NOTI_EX_ERROR_NONE;
2068 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2070 if (handle == nullptr || id == nullptr) {
2071 LOGE("Invalid parameter");
2072 return NOTI_EX_ERROR_INVALID_PARAMETER;
2074 Handle* h = static_cast<Handle*>(handle);
2075 AbstractItem* p = h->Get();
2076 *id = strdup(p->GetId().c_str());
2077 return NOTI_EX_ERROR_NONE;
2080 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2082 if (handle == nullptr || id == nullptr) {
2083 LOGE("Invalid parameter");
2084 return NOTI_EX_ERROR_INVALID_PARAMETER;
2086 Handle* p = static_cast<Handle*>(handle);
2087 p->Get()->SetId(id);
2088 return NOTI_EX_ERROR_NONE;
2091 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2092 noti_ex_action_h *action) {
2093 if (handle == nullptr || action == nullptr) {
2094 LOGE("Invalid parameter");
2095 return NOTI_EX_ERROR_INVALID_PARAMETER;
2097 Handle* p = static_cast<Handle*>(handle);
2098 if (p->Get()->GetAction() == nullptr) {
2100 return NOTI_EX_ERROR_NONE;
2102 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2103 p->Get()->GetAction()));
2105 return NOTI_EX_ERROR_NONE;
2108 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2109 noti_ex_action_h action) {
2110 if (handle == nullptr) {
2111 LOGE("Invalid parameter");
2112 return NOTI_EX_ERROR_INVALID_PARAMETER;
2115 Handle* p = static_cast<Handle*>(handle);
2116 if (action == nullptr) {
2117 p->Get()->SetAction(nullptr);
2118 return NOTI_EX_ERROR_NONE;
2121 shared_ptr<AbstractAction>* ptr =
2122 static_cast<shared_ptr<AbstractAction>*>(action);
2123 p->Get()->SetAction(*ptr);
2124 return NOTI_EX_ERROR_NONE;
2127 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2128 noti_ex_style_h *style) {
2129 if (handle == nullptr || style == nullptr) {
2130 LOGE("Invalid parameter");
2131 return NOTI_EX_ERROR_INVALID_PARAMETER;
2134 Handle* p = static_cast<Handle*>(handle);
2135 shared_ptr<Style> s = p->Get()->GetStyle();
2136 if (s.get() == nullptr) {
2137 LOGW("Style is null");
2139 return NOTI_EX_ERROR_NONE;
2142 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2143 if (ptr == nullptr || ptr->get() == nullptr) {
2144 LOGE("Out of memory");
2145 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2149 return NOTI_EX_ERROR_NONE;
2152 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2153 noti_ex_style_h style) {
2154 if (handle == nullptr) {
2155 LOGE("Invalid parameter");
2156 return NOTI_EX_ERROR_INVALID_PARAMETER;
2159 Handle* p = static_cast<Handle*>(handle);
2160 if (style == nullptr) {
2161 p->Get()->SetStyle(nullptr);
2162 return NOTI_EX_ERROR_NONE;
2165 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2166 p->Get()->SetStyle(*s);
2167 return NOTI_EX_ERROR_NONE;
2170 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2172 if (handle == nullptr) {
2173 LOGE("Invalid parameter");
2174 return NOTI_EX_ERROR_INVALID_PARAMETER;
2177 Handle* p = static_cast<Handle*>(handle);
2178 p->Get()->SetVisible(visible);
2179 return NOTI_EX_ERROR_NONE;
2182 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2184 if (handle == nullptr || visible == nullptr) {
2185 LOGE("Invalid parameter");
2186 return NOTI_EX_ERROR_INVALID_PARAMETER;
2189 Handle* p = static_cast<Handle*>(handle);
2190 *visible = p->Get()->GetVisible();
2191 return NOTI_EX_ERROR_NONE;
2194 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2196 if (handle == nullptr) {
2197 LOGE("Invalid parameter");
2198 return NOTI_EX_ERROR_INVALID_PARAMETER;
2201 Handle* p = static_cast<Handle*>(handle);
2202 p->Get()->SetEnable(enable);
2203 return NOTI_EX_ERROR_NONE;
2206 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2208 if (handle == nullptr || enable == nullptr) {
2209 LOGE("Invalid parameter");
2210 return NOTI_EX_ERROR_INVALID_PARAMETER;
2213 Handle* p = static_cast<Handle*>(handle);
2214 *enable = p->Get()->GetEnable();
2215 return NOTI_EX_ERROR_NONE;
2218 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2219 const char *receiver_group) {
2220 if (handle == nullptr || receiver_group == nullptr) {
2221 LOGE("Invalid parameter");
2222 return NOTI_EX_ERROR_INVALID_PARAMETER;
2225 Handle* p = static_cast<Handle*>(handle);
2226 p->Get()->AddReceiver(receiver_group);
2227 return NOTI_EX_ERROR_NONE;
2230 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2231 const char *receiver_group) {
2232 if (handle == nullptr || receiver_group == nullptr) {
2233 LOGE("Invalid parameter");
2234 return NOTI_EX_ERROR_INVALID_PARAMETER;
2237 Handle* p = static_cast<Handle*>(handle);
2238 p->Get()->RemoveReceiver(receiver_group);
2239 return NOTI_EX_ERROR_NONE;
2242 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2243 char ***receiver_list, int *count) {
2244 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2245 LOGE("Invalid parameter");
2246 return NOTI_EX_ERROR_INVALID_PARAMETER;
2249 Handle* p = static_cast<Handle*>(handle);
2250 list<string> receivers = p->Get()->GetReceiverList();
2251 if (receivers.size() == 0) {
2252 *receiver_list = nullptr;
2254 return NOTI_EX_ERROR_NONE;
2257 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2258 if (tmp_list == nullptr) {
2259 LOGE("Out of memory");
2260 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2264 for (auto& i : receivers) {
2265 tmp_list[idx] = strdup(i.c_str());
2266 if (tmp_list[idx] == nullptr) {
2267 __noti_ex_free_str_array(tmp_list, idx);
2268 LOGE("Out of memory");
2269 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2274 *receiver_list = tmp_list;
2275 *count = receivers.size();
2276 return NOTI_EX_ERROR_NONE;
2279 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2281 if (handle == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2286 Handle* p = static_cast<Handle*>(handle);
2287 p->Get()->SetPolicy(policy);
2288 return NOTI_EX_ERROR_NONE;
2291 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2293 if (handle == nullptr || policy == nullptr) {
2294 LOGE("Invalid parameter");
2295 return NOTI_EX_ERROR_INVALID_PARAMETER;
2298 Handle* p = static_cast<Handle*>(handle);
2299 *policy = p->Get()->GetPolicy();
2300 return NOTI_EX_ERROR_NONE;
2303 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2305 if (handle == nullptr || channel == nullptr) {
2306 LOGE("Invalid parameter");
2307 return NOTI_EX_ERROR_INVALID_PARAMETER;
2310 Handle* p = static_cast<Handle*>(handle);
2311 if (!p->Get()->GetChannel().empty())
2312 *channel = strdup(p->Get()->GetChannel().c_str());
2316 return NOTI_EX_ERROR_NONE;
2319 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2320 const char *channel) {
2321 if (handle == nullptr) {
2322 LOGE("Invalid parameter");
2323 return NOTI_EX_ERROR_INVALID_PARAMETER;
2326 Handle* p = static_cast<Handle*>(handle);
2327 p->Get()->SetChannel(channel);
2328 return NOTI_EX_ERROR_NONE;
2331 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2332 noti_ex_led_info_h led) {
2333 if (handle == nullptr) {
2334 LOGE("Invalid parameter");
2335 return NOTI_EX_ERROR_INVALID_PARAMETER;
2338 Handle* p = static_cast<Handle*>(handle);
2339 if (led == nullptr) {
2340 p->Get()->SetLEDInfo(nullptr);
2341 return NOTI_EX_ERROR_NONE;
2343 shared_ptr<LEDInfo>* led_ptr =
2344 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2345 p->Get()->SetLEDInfo(*led_ptr);
2346 return NOTI_EX_ERROR_NONE;
2349 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2350 noti_ex_led_info_h *led) {
2351 if (handle == nullptr) {
2352 LOGE("Invalid parameter");
2353 return NOTI_EX_ERROR_INVALID_PARAMETER;
2356 Handle* p = static_cast<Handle*>(handle);
2357 if (p->Get()->GetLEDInfo() != nullptr)
2358 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2361 return NOTI_EX_ERROR_NONE;
2364 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2366 if (handle == nullptr) {
2367 LOGE("Invalid parameter");
2368 return NOTI_EX_ERROR_INVALID_PARAMETER;
2371 Handle* p = static_cast<Handle*>(handle);
2372 if (path == nullptr)
2373 p->Get()->SetSoundPath("");
2375 p->Get()->SetSoundPath(path);
2376 return NOTI_EX_ERROR_NONE;
2379 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2381 if (handle == nullptr) {
2382 LOGE("Invalid parameter");
2383 return NOTI_EX_ERROR_INVALID_PARAMETER;
2386 Handle* p = static_cast<Handle*>(handle);
2387 if (path == nullptr)
2388 p->Get()->SetVibrationPath("");
2390 p->Get()->SetVibrationPath(path);
2391 return NOTI_EX_ERROR_NONE;
2394 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2396 if (handle == nullptr || path == nullptr) {
2397 LOGE("Invalid parameter");
2398 return NOTI_EX_ERROR_INVALID_PARAMETER;
2401 Handle* p = static_cast<Handle*>(handle);
2402 if (p->Get()->GetSoundPath().empty())
2405 *path = strdup(p->Get()->GetSoundPath().c_str());
2406 return NOTI_EX_ERROR_NONE;
2409 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2411 if (handle == nullptr || path == nullptr) {
2412 LOGE("Invalid parameter");
2413 return NOTI_EX_ERROR_INVALID_PARAMETER;
2416 Handle* p = static_cast<Handle*>(handle);
2417 if (p->Get()->GetVibrationPath().empty())
2420 *path = strdup(p->Get()->GetVibrationPath().c_str());
2421 return NOTI_EX_ERROR_NONE;
2424 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2425 noti_ex_item_info_h *info) {
2426 if (handle == nullptr || info == nullptr) {
2427 LOGE("Invalid parameter");
2428 return NOTI_EX_ERROR_INVALID_PARAMETER;
2431 Handle* p = static_cast<Handle*>(handle);
2432 if (p->Get()->GetInfo() == nullptr)
2435 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2436 return NOTI_EX_ERROR_NONE;
2439 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2441 if (handle == nullptr || id == nullptr) {
2442 LOGE("Invalid parameter");
2443 return NOTI_EX_ERROR_INVALID_PARAMETER;
2446 Handle* p = static_cast<Handle*>(handle);
2447 if (p->Get()->GetSenderAppId().empty())
2450 *id = strdup(p->Get()->GetSenderAppId().c_str());
2451 return NOTI_EX_ERROR_NONE;
2454 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2456 if (handle == nullptr || tag == nullptr) {
2457 LOGE("Invalid parameter");
2458 return NOTI_EX_ERROR_INVALID_PARAMETER;
2461 Handle* p = static_cast<Handle*>(handle);
2462 if (p->Get()->GetTag().empty())
2465 *tag = strdup(p->Get()->GetTag().c_str());
2466 return NOTI_EX_ERROR_NONE;
2469 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2471 if (handle == nullptr) {
2472 LOGE("Invalid parameter");
2473 return NOTI_EX_ERROR_INVALID_PARAMETER;
2476 Handle* p = static_cast<Handle*>(handle);
2478 p->Get()->SetTag("");
2480 p->Get()->SetTag(tag);
2481 return NOTI_EX_ERROR_NONE;
2484 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2486 if (handle == nullptr || ongoing == nullptr) {
2487 LOGE("Invalid parameter");
2488 return NOTI_EX_ERROR_INVALID_PARAMETER;
2491 Handle* p = static_cast<Handle*>(handle);
2492 *ongoing = p->Get()->GetOnGoingState();
2494 return NOTI_EX_ERROR_NONE;
2497 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2499 if (handle == nullptr) {
2500 LOGE("Invalid parameter");
2501 return NOTI_EX_ERROR_INVALID_PARAMETER;
2504 Handle* p = static_cast<Handle*>(handle);
2505 p->Get()->SetOnGoingState(ongoing);
2507 return NOTI_EX_ERROR_NONE;
2510 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2511 int type, bool* exist) {
2512 if (handle == nullptr || exist == nullptr) {
2513 LOGE("Invalid parameter");
2514 return NOTI_EX_ERROR_INVALID_PARAMETER;
2517 Handle* p = static_cast<Handle*>(handle);
2518 *exist = p->Get()->IsItemTypeExist(type);
2520 return NOTI_EX_ERROR_NONE;
2523 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2525 if (handle == nullptr || type == nullptr) {
2526 LOGE("Invalid parameter");
2527 return NOTI_EX_ERROR_INVALID_PARAMETER;
2530 Handle* p = static_cast<Handle*>(handle);
2531 *type = p->Get()->GetMainType();
2533 return NOTI_EX_ERROR_NONE;
2536 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2537 const char* id, int type) {
2538 if (handle == nullptr || id == nullptr) {
2539 LOGE("Invalid parameter");
2540 return NOTI_EX_ERROR_INVALID_PARAMETER;
2543 Handle* p = static_cast<Handle*>(handle);
2544 if (!(p->Get()->SetMainType(string(id),
2545 static_cast<AbstractItem::MainType>(type))))
2546 return NOTI_EX_ERROR_INVALID_PARAMETER;
2548 return NOTI_EX_ERROR_NONE;
2551 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2552 int type, noti_ex_item_h* item) {
2553 if (handle == nullptr || item == nullptr) {
2554 LOGE("Invalid parameter");
2555 return NOTI_EX_ERROR_INVALID_PARAMETER;
2558 Handle* h = static_cast<Handle*>(handle);
2559 if (!h->IsValidType(AbstractItem::Group)) {
2560 LOGE("Invalid handle type");
2561 return NOTI_EX_ERROR_INVALID_PARAMETER;
2564 GroupItem* p = static_cast<GroupItem*>(h->Get());
2565 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2566 if (find_item.GetType() == AbstractItem::NullObject) {
2567 LOGW("Not exist ID");
2569 return NOTI_EX_ERROR_NONE;
2571 *item = new Handle(&find_item);
2573 return NOTI_EX_ERROR_NONE;
2576 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2577 const char *key, bundle **value) {
2578 if (handle == nullptr || key == nullptr || value == nullptr) {
2579 LOGE("Invalid handle type");
2580 return NOTI_EX_ERROR_INVALID_PARAMETER;
2583 Handle* p = static_cast<Handle*>(handle);
2585 Bundle b = p->Get()->GetExtensionData(key);
2586 if (b.GetCount() == 0)
2589 *value = bundle_dup(b.GetHandle());
2591 return NOTI_EX_ERROR_NONE;
2594 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2595 const char *key, bundle *value) {
2596 if (handle == nullptr || key == nullptr || value == nullptr) {
2597 LOGE("Invalid handle type");
2598 return NOTI_EX_ERROR_INVALID_PARAMETER;
2601 Bundle b = Bundle(value);
2603 Handle* p = static_cast<Handle*>(handle);
2604 p->Get()->SetExtensionData(key, b);
2606 return NOTI_EX_ERROR_NONE;
2609 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2610 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2612 if (handle == nullptr) {
2613 LOGE("Invalid parameter");
2614 return NOTI_EX_ERROR_INVALID_PARAMETER;
2617 string receiver_group_str = "";
2619 receiver_group_str = string(receiver_group);
2621 ManagerStub* stub = new (std::nothrow) ManagerStub(
2622 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2623 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2624 receiver_group_str);
2625 if (stub == nullptr) {
2626 LOGE("Fail to create manager");
2627 return NOTI_EX_ERROR_IO_ERROR;
2629 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2630 new ManagerCallbackInfo(event_callbacks, data)));
2631 *handle = static_cast<noti_ex_manager_h>(stub);
2633 return NOTI_EX_ERROR_NONE;
2636 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2637 if (handle == nullptr) {
2638 LOGE("Invalid parameter");
2639 return NOTI_EX_ERROR_INVALID_PARAMETER;
2641 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2643 return NOTI_EX_ERROR_NONE;
2646 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2647 noti_ex_item_h **items, int *count) {
2648 if (handle == nullptr || items == nullptr || count == nullptr) {
2649 LOGE("Invalid parameter");
2650 return NOTI_EX_ERROR_INVALID_PARAMETER;
2654 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2655 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2656 if (item_list.size() == 0) {
2659 return NOTI_EX_ERROR_NONE;
2661 noti_ex_item_h* added_item =
2662 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2663 if (added_item == nullptr) {
2664 LOGE("Fail to create items");
2665 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2669 for (auto& i : item_list) {
2670 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2672 *items = added_item;
2673 *count = item_list.size();
2674 } catch (Exception &ex) {
2675 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2676 return NOTI_EX_ERROR_IO_ERROR;
2678 return NOTI_EX_ERROR_NONE;
2681 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2682 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2683 if (handle == nullptr || channel == nullptr ||
2684 items == nullptr || count == nullptr) {
2685 LOGE("Invalid parameter");
2686 return NOTI_EX_ERROR_INVALID_PARAMETER;
2690 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2691 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2692 if (item_list.size() == 0) {
2695 return NOTI_EX_ERROR_NONE;
2697 noti_ex_item_h* added_item =
2698 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2699 if (added_item == nullptr) {
2700 LOGE("Fail to create items");
2701 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2705 for (auto& i : item_list) {
2706 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2708 *items = added_item;
2709 *count = item_list.size();
2710 } catch (Exception &ex) {
2711 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2712 return NOTI_EX_ERROR_IO_ERROR;
2715 return NOTI_EX_ERROR_NONE;
2718 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2719 noti_ex_item_h noti, int *request_id) {
2720 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2721 LOGE("Invalid parameter");
2722 return NOTI_EX_ERROR_INVALID_PARAMETER;
2725 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2726 Handle* sp = static_cast<Handle*>(noti);
2727 if (sp->GetPtr().get() == nullptr) {
2728 LOGE("Invalid noti reference can not be sended");
2729 return NOTI_EX_ERROR_INVALID_PARAMETER;
2731 *request_id = stub->Update(sp->GetPtr());
2733 } catch (Exception &ex) {
2734 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2735 return NOTI_EX_ERROR_IO_ERROR;
2737 return NOTI_EX_ERROR_NONE;
2740 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2741 noti_ex_item_h noti, int *request_id) {
2742 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2743 LOGE("Invalid parameter");
2744 return NOTI_EX_ERROR_INVALID_PARAMETER;
2747 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2748 Handle* item = static_cast<Handle*>(noti);
2749 if (item->GetPtr().get() == nullptr) {
2750 LOGE("Invalid noti reference can not be sended");
2751 return NOTI_EX_ERROR_INVALID_PARAMETER;
2753 *request_id = stub->Delete(item->GetPtr());
2755 } catch (Exception &ex) {
2756 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2757 return NOTI_EX_ERROR_IO_ERROR;
2759 return NOTI_EX_ERROR_NONE;
2762 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2764 if (handle == nullptr || request_id == nullptr) {
2765 LOGE("Invalid parameter");
2766 return NOTI_EX_ERROR_INVALID_PARAMETER;
2769 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2770 *request_id = stub->DeleteAll();
2771 } catch (Exception &ex) {
2772 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2773 return NOTI_EX_ERROR_IO_ERROR;
2775 return NOTI_EX_ERROR_NONE;
2778 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2779 noti_ex_manager_h handle, const char* channel, int* request_id) {
2780 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2781 LOGE("Invalid parameter");
2782 return NOTI_EX_ERROR_INVALID_PARAMETER;
2786 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2787 *request_id = stub->DeleteByChannel(channel);
2788 } catch (Exception &ex) {
2789 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2790 return NOTI_EX_ERROR_IO_ERROR;
2793 return NOTI_EX_ERROR_NONE;
2796 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2797 noti_ex_manager_h handle, const char* app_id, int* request_id) {
2798 if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2799 LOGE("Invalid parameter");
2800 return NOTI_EX_ERROR_INVALID_PARAMETER;
2804 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2805 *request_id = stub->DeleteByAppId(app_id);
2806 } catch (Exception &ex) {
2807 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2808 return NOTI_EX_ERROR_IO_ERROR;
2811 return NOTI_EX_ERROR_NONE;
2814 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2815 noti_ex_item_h noti, int *request_id) {
2816 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2817 LOGE("Invalid parameter");
2818 return NOTI_EX_ERROR_INVALID_PARAMETER;
2821 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2822 Handle* item = static_cast<Handle*>(noti);
2823 if (item->GetPtr().get() == nullptr) {
2824 LOGE("Invalid noti reference can not be sended");
2825 return NOTI_EX_ERROR_INVALID_PARAMETER;
2827 *request_id = stub->Hide(item->GetPtr());
2829 } catch (Exception &ex) {
2830 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2831 return NOTI_EX_ERROR_IO_ERROR;
2833 return NOTI_EX_ERROR_NONE;
2836 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2837 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2838 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2839 LOGE("Invalid parameter");
2840 return NOTI_EX_ERROR_INVALID_PARAMETER;
2843 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2844 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2845 if (ptr == nullptr) {
2846 LOGW("Not exist ID");
2848 return NOTI_EX_ERROR_NONE;
2850 *item = new Handle(ptr);
2851 } catch (Exception &ex) {
2852 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2853 return NOTI_EX_ERROR_IO_ERROR;
2855 return NOTI_EX_ERROR_NONE;
2858 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2859 noti_ex_event_info_h info, noti_ex_error_e error) {
2860 if (handle == nullptr || info == nullptr) {
2861 LOGE("Invalid parameter");
2862 return NOTI_EX_ERROR_INVALID_PARAMETER;
2865 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2866 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2867 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2868 static_cast<NotificationError>(error));
2869 } catch (Exception &ex) {
2870 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2871 return NOTI_EX_ERROR_IO_ERROR;
2873 return NOTI_EX_ERROR_NONE;
2876 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2877 noti_ex_manager_h handle, int *count) {
2878 if (handle == nullptr || count == nullptr) {
2879 LOGE("Invalid parameter");
2880 return NOTI_EX_ERROR_INVALID_PARAMETER;
2883 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2884 *count = stub->GetCount();
2885 } catch (Exception &ex) {
2886 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2887 return NOTI_EX_ERROR_IO_ERROR;
2889 return NOTI_EX_ERROR_NONE;
2892 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2893 const char *id, float min, float current, float max) {
2896 if (handle == nullptr) {
2897 LOGE("Invalid parameter");
2898 return NOTI_EX_ERROR_INVALID_PARAMETER;
2902 p = new (std::nothrow) ProgressItem(id, min, current, max);
2904 p = new (std::nothrow) ProgressItem(min, current, max);
2907 LOGE("Out-of-memory");
2908 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2911 *handle = new Handle(shared_ptr<AbstractItem>(p));
2913 return NOTI_EX_ERROR_NONE;
2916 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2917 noti_ex_item_h handle, float *current) {
2918 if (handle == nullptr || current == nullptr) {
2919 LOGE("Invalid parameter");
2920 return NOTI_EX_ERROR_INVALID_PARAMETER;
2923 Handle *h = static_cast<Handle*>(handle);
2924 if (!h->IsValidType(AbstractItem::Progress)) {
2925 LOGE("Invalid handle type");
2926 return NOTI_EX_ERROR_INVALID_PARAMETER;
2928 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2929 *current = p->GetCurrent();
2931 return NOTI_EX_ERROR_NONE;
2934 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2935 noti_ex_item_h handle, float current) {
2936 if (handle == nullptr) {
2937 LOGE("Invalid parameter");
2938 return NOTI_EX_ERROR_INVALID_PARAMETER;
2941 Handle *h = static_cast<Handle*>(handle);
2942 if (!h->IsValidType(AbstractItem::Progress)) {
2943 LOGE("Invalid handle type");
2944 return NOTI_EX_ERROR_INVALID_PARAMETER;
2946 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2947 p->SetCurrent(current);
2949 return NOTI_EX_ERROR_NONE;
2952 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2954 if (handle == nullptr || min == nullptr) {
2955 LOGE("Invalid parameter");
2956 return NOTI_EX_ERROR_INVALID_PARAMETER;
2959 Handle *h = static_cast<Handle*>(handle);
2960 if (!h->IsValidType(AbstractItem::Progress)) {
2961 LOGE("Invalid handle type");
2962 return NOTI_EX_ERROR_INVALID_PARAMETER;
2964 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2967 return NOTI_EX_ERROR_NONE;
2970 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2972 if (handle == nullptr || max == nullptr) {
2973 LOGE("Invalid parameter");
2974 return NOTI_EX_ERROR_INVALID_PARAMETER;
2977 Handle *h = static_cast<Handle*>(handle);
2978 if (!h->IsValidType(AbstractItem::Progress)) {
2979 LOGE("Invalid handle type");
2980 return NOTI_EX_ERROR_INVALID_PARAMETER;
2982 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2985 return NOTI_EX_ERROR_NONE;
2988 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2990 if (handle == nullptr || type == nullptr) {
2991 LOGE("Invalid parameter");
2992 return NOTI_EX_ERROR_INVALID_PARAMETER;
2995 Handle *h = static_cast<Handle*>(handle);
2996 if (!h->IsValidType(AbstractItem::Progress)) {
2997 LOGE("Invalid handle type");
2998 return NOTI_EX_ERROR_INVALID_PARAMETER;
3000 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3001 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
3003 return NOTI_EX_ERROR_NONE;
3006 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
3008 if (handle == nullptr) {
3009 LOGE("Invalid parameter");
3010 return NOTI_EX_ERROR_INVALID_PARAMETER;
3013 Handle *h = static_cast<Handle*>(handle);
3014 if (!h->IsValidType(AbstractItem::Progress)) {
3015 LOGE("Invalid handle type");
3016 return NOTI_EX_ERROR_INVALID_PARAMETER;
3018 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3019 p->SetProgressType(static_cast<ProgressItem::Type>(type));
3021 return NOTI_EX_ERROR_NONE;
3024 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
3025 noti_ex_reporter_events_s event_callbacks, void *data) {
3026 if (handle == nullptr) {
3027 LOGE("Invalid parameter");
3028 return NOTI_EX_ERROR_INVALID_PARAMETER;
3031 ReporterStub* stub = new (std::nothrow) ReporterStub(
3032 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
3033 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
3034 if (stub == nullptr) {
3035 LOGE("Fail to create manager");
3036 return NOTI_EX_ERROR_IO_ERROR;
3038 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
3039 new ReporterCallbackInfo(event_callbacks, data)));
3041 *handle = static_cast<noti_ex_reporter_h>(stub);
3043 return NOTI_EX_ERROR_NONE;
3046 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3047 if (handle == nullptr) {
3048 LOGE("Invalid parameter");
3049 return NOTI_EX_ERROR_INVALID_PARAMETER;
3051 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3053 return NOTI_EX_ERROR_NONE;
3056 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3057 noti_ex_event_info_h info, noti_ex_error_e error) {
3058 if (handle == nullptr || info == nullptr) {
3059 LOGE("Invalid parameter");
3060 return NOTI_EX_ERROR_INVALID_PARAMETER;
3063 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3064 IEventInfo* c_info = static_cast<IEventInfo*>(info);
3065 stub->SendError(static_cast<const IEventInfo&>(*c_info),
3066 static_cast<NotificationError>(error));
3067 } catch (Exception &ex) {
3068 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3069 return NOTI_EX_ERROR_IO_ERROR;
3071 return NOTI_EX_ERROR_NONE;
3074 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3075 noti_ex_item_h noti, int *request_id) {
3076 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3077 LOGE("Invalid parameter");
3078 return NOTI_EX_ERROR_INVALID_PARAMETER;
3081 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3082 Handle* h = static_cast<Handle*>(noti);
3083 if (h->GetPtr().get() == nullptr) {
3084 LOGE("Invalid noti reference can not be sended");
3085 return NOTI_EX_ERROR_INVALID_PARAMETER;
3087 *request_id = stub->Post(h->GetPtr());
3089 } catch (Exception &ex) {
3090 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3091 return NOTI_EX_ERROR_IO_ERROR;
3093 return NOTI_EX_ERROR_NONE;
3096 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3097 noti_ex_item_h *noti_list, int count, int *request_id) {
3099 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3100 LOGE("Invalid parameter");
3101 return NOTI_EX_ERROR_INVALID_PARAMETER;
3104 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3105 list<shared_ptr<item::AbstractItem>> notiList;
3106 for (int i = 0; i < count; i++) {
3107 Handle* item = static_cast<Handle*>(noti_list[i]);
3108 notiList.push_back(item->GetPtr());
3110 *request_id = stub->Post(notiList);
3111 } catch (Exception &ex) {
3112 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3113 return NOTI_EX_ERROR_IO_ERROR;
3115 return NOTI_EX_ERROR_NONE;
3118 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3119 noti_ex_item_h noti, int *request_id) {
3120 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3121 LOGE("Invalid parameter");
3122 return NOTI_EX_ERROR_INVALID_PARAMETER;
3125 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3126 Handle* item = static_cast<Handle*>(noti);
3127 if (item->GetPtr().get() == nullptr) {
3128 LOGE("Invalid noti reference can not be sended");
3129 return NOTI_EX_ERROR_INVALID_PARAMETER;
3131 *request_id = stub->Update(item->GetPtr());
3133 } catch (Exception &ex) {
3134 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3135 return NOTI_EX_ERROR_IO_ERROR;
3137 return NOTI_EX_ERROR_NONE;
3140 extern "C" EXPORT_API int noti_ex_reporter_update_list(
3141 noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3143 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3144 LOGE("Invalid parameter");
3145 return NOTI_EX_ERROR_INVALID_PARAMETER;
3148 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3149 list<shared_ptr<item::AbstractItem>> notiList;
3150 for (int i = 0; i < count; i++) {
3151 Handle* item = static_cast<Handle*>(noti_list[i]);
3152 notiList.push_back(item->GetPtr());
3154 *request_id = stub->Update(notiList);
3155 } catch (Exception &ex) {
3156 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3157 return NOTI_EX_ERROR_IO_ERROR;
3159 return NOTI_EX_ERROR_NONE;
3162 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3163 noti_ex_item_h noti, int *request_id) {
3164 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3165 LOGE("Invalid parameter");
3166 return NOTI_EX_ERROR_INVALID_PARAMETER;
3169 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3170 Handle* item = static_cast<Handle*>(noti);
3171 if (item->GetPtr().get() == nullptr) {
3172 LOGE("Invalid noti reference can not be sended");
3173 return NOTI_EX_ERROR_INVALID_PARAMETER;
3175 *request_id = stub->Delete(item->GetPtr());
3177 } catch (Exception &ex) {
3178 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3179 return NOTI_EX_ERROR_IO_ERROR;
3181 return NOTI_EX_ERROR_NONE;
3184 extern "C" EXPORT_API int noti_ex_reporter_delete_list(
3185 noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3187 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3188 LOGE("Invalid parameter");
3189 return NOTI_EX_ERROR_INVALID_PARAMETER;
3192 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3193 list<shared_ptr<item::AbstractItem>> notiList;
3194 for (int i = 0; i < count; i++) {
3195 Handle* item = static_cast<Handle*>(noti_list[i]);
3196 notiList.push_back(item->GetPtr());
3198 *request_id = stub->Delete(notiList);
3199 } catch (Exception &ex) {
3200 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3201 return NOTI_EX_ERROR_IO_ERROR;
3203 return NOTI_EX_ERROR_NONE;
3206 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3207 noti_ex_reporter_h handle, int *request_id) {
3208 if (handle == nullptr || request_id == nullptr) {
3209 LOGE("Invalid parameter");
3210 return NOTI_EX_ERROR_INVALID_PARAMETER;
3213 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3214 *request_id = stub->DeleteAll();
3215 } catch (Exception &ex) {
3216 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3217 return NOTI_EX_ERROR_IO_ERROR;
3219 return NOTI_EX_ERROR_NONE;
3222 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3223 noti_ex_reporter_h handle, const char* channel, int* request_id) {
3224 if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3225 LOGE("Invalid parameter");
3226 return NOTI_EX_ERROR_INVALID_PARAMETER;
3230 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3231 *request_id = stub->DeleteByChannel(channel);
3232 } catch (Exception &ex) {
3233 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3234 return NOTI_EX_ERROR_IO_ERROR;
3237 return NOTI_EX_ERROR_NONE;
3240 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3241 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3242 if (handle == nullptr || root_id == nullptr || item == nullptr) {
3243 LOGE("Invalid parameter");
3244 return NOTI_EX_ERROR_INVALID_PARAMETER;
3247 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3248 shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3249 if (ptr == nullptr) {
3250 LOGW("Not exist ID");
3252 return NOTI_EX_ERROR_NONE;
3254 *item = new Handle(ptr);
3255 } catch (Exception &ex) {
3256 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3257 return NOTI_EX_ERROR_IO_ERROR;
3259 return NOTI_EX_ERROR_NONE;
3262 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3263 const char *channel, noti_ex_item_h **noti_list, int *count) {
3264 if (handle == nullptr || channel == nullptr || noti_list == nullptr
3265 || count == nullptr) {
3266 LOGE("Invalid parameter");
3267 return NOTI_EX_ERROR_INVALID_PARAMETER;
3270 Handle** list_item = nullptr;
3273 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3274 list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3275 if (list_ptr.empty()) {
3276 LOGW("Not exist ID");
3277 *noti_list = nullptr;
3279 return NOTI_EX_ERROR_NONE;
3282 int size = list_ptr.size();
3285 list_item = (Handle**)calloc(size, sizeof(Handle*));
3286 for (auto& ptr : list_ptr)
3287 list_item[i++] = new Handle(std::move(ptr));
3289 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3291 } catch (Exception &ex) {
3292 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3294 return NOTI_EX_ERROR_IO_ERROR;
3297 return NOTI_EX_ERROR_NONE;
3300 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3301 noti_ex_item_h **noti_list, int *count) {
3302 if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3303 LOGE("Invalid parameter");
3304 return NOTI_EX_ERROR_INVALID_PARAMETER;
3307 Handle** list_item = nullptr;
3310 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3311 list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3312 if (list_ptr.empty()) {
3313 LOGW("Not exist ID");
3314 *noti_list = nullptr;
3315 return NOTI_EX_ERROR_NONE;
3318 int size = list_ptr.size();
3321 list_item = (Handle**)calloc(size, sizeof(Handle*));
3322 for (auto& ptr : list_ptr)
3323 list_item[i++] = new Handle(std::move(ptr));
3325 *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3327 } catch (Exception &ex) {
3328 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3330 return NOTI_EX_ERROR_IO_ERROR;
3333 return NOTI_EX_ERROR_NONE;
3336 extern "C" EXPORT_API int noti_ex_reporter_get_count_by_channel(
3337 noti_ex_reporter_h handle, const char *channel, int *count) {
3338 if (handle == nullptr || channel == nullptr || count == nullptr) {
3339 LOGE("Invalid parameter");
3340 return NOTI_EX_ERROR_INVALID_PARAMETER;
3344 ReporterStub* stub = static_cast<ReporterStub*>(handle);
3345 *count = stub->GetCount(channel);
3346 } catch (Exception &ex) {
3347 LOGE("%s %d", ex.what(), ex.GetErrorCode());
3348 return NOTI_EX_ERROR_IO_ERROR;
3351 return NOTI_EX_ERROR_NONE;
3354 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3355 const char *id, const char *text, const char *hyperlink) {
3356 if (handle == nullptr || text == nullptr) {
3357 LOGE("Invalid parameter");
3358 return NOTI_EX_ERROR_INVALID_PARAMETER;
3367 p = new (std::nothrow) TextItem(id, std::string(text),
3368 std::string(hyperlink));
3370 p = new (std::nothrow) TextItem(id, std::string(text));
3373 LOGE("Out-of-memory");
3374 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3377 *handle = new Handle(shared_ptr<AbstractItem>(p));
3379 return NOTI_EX_ERROR_NONE;
3382 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3383 const char *contents) {
3384 if (handle == nullptr || contents == nullptr) {
3385 LOGE("Invalid parameter");
3386 return NOTI_EX_ERROR_INVALID_PARAMETER;
3389 Handle* p = static_cast<Handle*>(handle);
3390 if (!p->IsValidType(AbstractItem::Text)) {
3391 LOGE("Invalid handle type");
3392 return NOTI_EX_ERROR_INVALID_PARAMETER;
3394 TextItem* ti = static_cast<TextItem*>(p->Get());
3395 ti->SetContents(std::string(contents));
3397 return NOTI_EX_ERROR_NONE;
3400 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3402 if (handle == nullptr || contents == nullptr) {
3403 LOGE("Invalid parameter");
3404 return NOTI_EX_ERROR_INVALID_PARAMETER;
3407 Handle* p = static_cast<Handle*>(handle);
3408 if (!p->IsValidType(AbstractItem::Text)) {
3409 LOGE("Invalid handle type");
3410 return NOTI_EX_ERROR_INVALID_PARAMETER;
3413 TextItem* ti = static_cast<TextItem*>(p->Get());
3415 if (ti->GetMultiLanguage() != nullptr &&
3416 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3417 str = ti->GetMultiLanguage()->GetTranslatedString();
3418 else if (!ti->GetContents().empty())
3419 str = ti->GetContents();
3421 *contents = strdup(str.c_str());
3422 if (*contents == nullptr) {
3423 LOGE("Out-of-memory");
3424 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3427 return NOTI_EX_ERROR_NONE;
3430 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3431 noti_ex_item_h handle, char **hyper_link) {
3432 if (handle == nullptr || hyper_link == nullptr) {
3433 LOGE("Invalid parameter");
3434 return NOTI_EX_ERROR_INVALID_PARAMETER;
3437 Handle* p = static_cast<Handle*>(handle);
3438 if (!p->IsValidType(AbstractItem::Text)) {
3439 LOGE("Invalid handle type");
3440 return NOTI_EX_ERROR_INVALID_PARAMETER;
3442 TextItem* ti = static_cast<TextItem*>(p->Get());
3443 if (!ti->GetHyperLink().empty()) {
3444 *hyper_link = strdup(ti->GetHyperLink().c_str());
3445 if (*hyper_link == nullptr) {
3446 LOGE("Out-of-memory");
3447 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3450 *hyper_link = nullptr;
3453 return NOTI_EX_ERROR_NONE;
3456 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3457 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3458 if (handle == nullptr) {
3459 LOGE("Invalid parameter");
3460 return NOTI_EX_ERROR_INVALID_PARAMETER;
3463 Handle* p = static_cast<Handle*>(handle);
3464 if (!p->IsValidType(AbstractItem::Text)) {
3465 LOGE("Invalid handle type");
3466 return NOTI_EX_ERROR_INVALID_PARAMETER;
3469 TextItem* ti = static_cast<TextItem*>(p->Get());
3470 if (multi == nullptr) {
3471 ti->SetMultiLanguage(nullptr);
3472 return NOTI_EX_ERROR_NONE;
3475 shared_ptr<MultiLanguage> mul_ptr =
3476 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3477 ti->SetMultiLanguage(mul_ptr);
3478 ti->GetMultiLanguage()->UpdateString();
3480 return NOTI_EX_ERROR_NONE;
3483 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3484 const char *id, time_t time) {
3487 if (handle == nullptr) {
3488 LOGE("Invalid parameter");
3489 return NOTI_EX_ERROR_INVALID_PARAMETER;
3494 p = new (std::nothrow) TimeItem(id, time);
3496 p = new (std::nothrow) TimeItem(time);
3498 p = new (std::nothrow) TimeItem();
3502 LOGE("Out-of-memory");
3503 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3506 *handle = new Handle(shared_ptr<AbstractItem>(p));
3508 return NOTI_EX_ERROR_NONE;
3511 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3513 if (handle == nullptr || time == nullptr) {
3514 LOGE("Invalid parameter");
3515 return NOTI_EX_ERROR_INVALID_PARAMETER;
3517 Handle* h = static_cast<Handle*>(handle);
3518 if (!h->IsValidType(AbstractItem::Time)) {
3519 LOGE("Invalid handle type");
3520 return NOTI_EX_ERROR_INVALID_PARAMETER;
3522 TimeItem* p = static_cast<TimeItem*>(h->Get());
3523 *time = p->GetTime();
3525 return NOTI_EX_ERROR_NONE;
3528 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3530 if (handle == nullptr) {
3531 LOGE("Invalid parameter");
3532 return NOTI_EX_ERROR_INVALID_PARAMETER;
3534 Handle* h = static_cast<Handle*>(handle);
3535 if (!h->IsValidType(AbstractItem::Time)) {
3536 LOGE("Invalid handle type");
3537 return NOTI_EX_ERROR_INVALID_PARAMETER;
3539 TimeItem* p = static_cast<TimeItem*>(h->Get());
3542 return NOTI_EX_ERROR_NONE;
3545 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3546 noti_ex_action_h *handle, const char *extra) {
3547 if (handle == nullptr) {
3548 LOGE("Invalid parameter");
3549 return NOTI_EX_ERROR_INVALID_PARAMETER;
3552 string extra_str = "";
3554 extra_str = string(extra);
3556 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3557 new (std::nothrow) VisibilityAction(extra_str));
3558 if (ptr == nullptr) {
3559 LOGE("Out-of-memory");
3560 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3565 return NOTI_EX_ERROR_NONE;
3568 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3569 const char *id, bool visible) {
3570 if (handle == nullptr || id == nullptr) {
3571 LOGE("Invalid parameter");
3572 return NOTI_EX_ERROR_INVALID_PARAMETER;
3575 shared_ptr<AbstractAction>* ptr =
3576 static_cast<shared_ptr<AbstractAction>*>(handle);
3577 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3578 action->SetVisibility(id, visible);
3580 return NOTI_EX_ERROR_NONE;
3583 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3584 const char* msgid, const char* format, ...) {
3585 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3586 LOGE("Invalid parameter");
3587 return NOTI_EX_ERROR_INVALID_PARAMETER;
3590 const char* format_idx = format;
3593 va_start(args, format);
3594 while (*format_idx != '\0') {
3595 char* arg = nullptr;
3598 stringstream stream;
3599 if (*format_idx == '%') {
3600 switch (*(format_idx + 1)) {
3602 arg = va_arg(args, char *);
3603 arr.push_back(string(arg));
3606 arg_i = va_arg(args, int);
3607 arr.push_back(to_string(arg_i));
3610 arg_f = va_arg(args, double);
3611 stream << std::fixed << std::setprecision(2) << arg_f;
3612 arr.push_back(stream.str());
3620 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3622 LOGE("Out-of-memory");
3623 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3625 *handle = new shared_ptr<MultiLanguage>(p);
3627 return NOTI_EX_ERROR_NONE;
3630 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3631 if (handle == nullptr) {
3632 LOGE("Invalid parameter");
3633 return NOTI_EX_ERROR_INVALID_PARAMETER;
3636 shared_ptr<MultiLanguage>* mul_ptr =
3637 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3639 return NOTI_EX_ERROR_NONE;
3642 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3643 noti_ex_item_h handle, int64_t* private_id) {
3644 if (handle == nullptr || private_id == nullptr) {
3645 LOGE("Invalid parameter");
3646 return NOTI_EX_ERROR_INVALID_PARAMETER;
3649 Handle* h = static_cast<Handle*>(handle);
3650 *private_id = static_pointer_cast<IItemInfoInternal>(
3651 h->Get()->GetInfo())->GetPrivateId();
3653 return NOTI_EX_ERROR_NONE;
3656 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3657 if (list == nullptr) {
3658 LOGE("Invalid parameter");
3659 return NOTI_EX_ERROR_INVALID_PARAMETER;
3662 LOGI("Free strings (%d)", count);
3663 for (int i = 0; i < count; i++)
3667 return NOTI_EX_ERROR_NONE;
3670 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3671 if (handle == nullptr) {
3672 LOGE("Invalid parameter");
3673 return NOTI_EX_ERROR_INVALID_PARAMETER;
3675 Handle* h = static_cast<Handle*>(handle);
3676 if (!h->IsValidType(AbstractItem::Group)) {
3677 LOGE("Invalid handle type");
3678 return NOTI_EX_ERROR_INVALID_PARAMETER;
3680 GroupItem* p = static_cast<GroupItem*>(h->Get());
3681 p->RemoveChildren();
3683 return NOTI_EX_ERROR_NONE;
3686 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3687 const char *id, const char *icon_path) {
3688 if (handle == nullptr || icon_path == nullptr) {
3689 LOGE("Invalid parameter");
3690 return NOTI_EX_ERROR_INVALID_PARAMETER;
3695 p = new (std::nothrow) IconItem(id, icon_path);
3697 p = new (std::nothrow) IconItem(icon_path);
3700 LOGE("Out-of-memory");
3701 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3704 *handle = new Handle(shared_ptr<AbstractItem>(p));
3706 return NOTI_EX_ERROR_NONE;
3709 extern "C" EXPORT_API int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3710 if (handle == nullptr || icon_path == nullptr) {
3711 LOGE("Invalid parameter");
3712 return NOTI_EX_ERROR_INVALID_PARAMETER;
3715 Handle* h = static_cast<Handle*>(handle);
3716 if (!h->IsValidType(AbstractItem::Icon)) {
3717 LOGE("Invalid handle type");
3718 return NOTI_EX_ERROR_INVALID_PARAMETER;
3721 IconItem* p = static_cast<IconItem*>(h->Get());
3722 if (!p->GetImagePath().empty()) {
3723 *icon_path = strdup(p->GetImagePath().c_str());
3724 if (*icon_path == nullptr) {
3725 LOGE("Out-of-memory");
3726 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3729 *icon_path = nullptr;
3732 return NOTI_EX_ERROR_NONE;