2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include "api/notification_ex_app_control_action.h"
26 #include "api/notification_ex_button.h"
27 #include "api/notification_ex_chat_message.h"
28 #include "api/notification_ex_checkbox.h"
29 #include "api/notification_ex_entry.h"
30 #include "api/notification_ex_event_info.h"
31 #include "api/notification_ex_group.h"
32 #include "api/notification_ex_image.h"
33 #include "api/notification_ex_input_selector.h"
34 #include "api/notification_ex_item.h"
35 #include "api/notification_ex_manager.h"
36 #include "api/notification_ex_progress.h"
37 #include "api/notification_ex_reporter.h"
38 #include "api/notification_ex_text.h"
39 #include "api/notification_ex_time.h"
40 #include "api/notification_ex_visibility_action.h"
41 #include "notification-ex/reporter.h"
42 #include "notification-ex/app_control_action.h"
43 #include "notification-ex/button_item.h"
44 #include "notification-ex/chat_message_item.h"
45 #include "notification-ex/checkbox_item.h"
46 #include "notification-ex/entry_item.h"
47 #include "notification-ex/group_item.h"
48 #include "notification-ex/input_selector_item.h"
49 #include "notification-ex/abstract_item.h"
50 #include "notification-ex/progress_item.h"
51 #include "notification-ex/time_item.h"
52 #include "notification-ex/visibility_action.h"
53 #include "notification-ex/event_info_internal.h"
54 #include "notification-ex/manager.h"
55 #include "notification-ex/dbus_sender.h"
56 #include "notification-ex/dbus_event_listener.h"
57 #include "notification-ex/exception.h"
62 #define LOG_TAG "NOTIFICATION_EX"
67 #define EXPORT_API __attribute__((visibility("default")))
70 using namespace tizen_base;
71 using namespace notification::item;
72 using namespace notification;
78 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
79 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
80 : ref_(nullptr), ptr_(move(ptr)) { }
81 virtual ~Handle() = default;
82 item::AbstractItem* Get() const {
88 bool IsValidType(int type) const {
89 return (Get()->GetType() == type
90 || Get()->GetType() >= AbstractItem::Custom);
93 std::shared_ptr<item::AbstractItem> GetPtr() const {
95 return std::shared_ptr<item::AbstractItem>({});
100 item::AbstractItem* ref_;
101 std::shared_ptr<item::AbstractItem> ptr_;
104 class ManagerCallbackInfo {
106 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
107 : user_data_(user_data) {
108 cb_.added = cb.added;
109 cb_.updated = cb.updated;
110 cb_.deleted = cb.deleted;
111 cb_.error = cb.error;
114 void InvokeAdded(Manager* manager, const IEventInfo& info,
115 list<shared_ptr<AbstractItem>> addedItem) {
116 if (cb_.added == nullptr)
118 noti_ex_item_h* added_item =
119 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
120 if (added_item == nullptr) {
121 LOGE("Out of memory");
126 for (auto& i : addedItem) {
128 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
131 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
132 cb_.added(static_cast<noti_ex_manager_h>(manager),
133 static_cast<noti_ex_event_info_h>(c_info), added_item,
134 addedItem.size(), user_data_);
138 void InvokeUpdated(Manager* manager, const IEventInfo& info,
139 shared_ptr<item::AbstractItem> updatedItem) {
140 if (cb_.updated == nullptr)
142 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
143 cb_.updated(static_cast<noti_ex_manager_h>(manager),
144 static_cast<noti_ex_event_info_h>(c_info),
145 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
148 void InvokeDeleted(Manager* manager, const IEventInfo& info,
149 shared_ptr<item::AbstractItem> deletedItem) {
150 if (cb_.deleted == nullptr)
152 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
153 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
154 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
155 static_cast<noti_ex_event_info_h>(c_info),
156 nullptr, user_data_);
158 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
159 static_cast<noti_ex_event_info_h>(c_info),
160 static_cast<noti_ex_item_h>(
161 new Handle(deletedItem)), user_data_);
165 void InvokeError(Manager* manager, NotificationError error, int requestId) {
166 if (cb_.error == nullptr)
168 cb_.error(static_cast<noti_ex_manager_h>(manager),
169 static_cast<noti_ex_error_e>(error), requestId, user_data_);
173 noti_ex_manager_events_s cb_;
177 class ManagerStub : public Manager {
179 ManagerStub(std::unique_ptr<IEventSender> sender,
180 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
181 : Manager(move(sender), move(listener), receiver_group) {
184 void OnAdd(const IEventInfo& info,
185 list<shared_ptr<AbstractItem>> addedItem) override {
186 cb_->InvokeAdded(this, info, addedItem);
189 void OnUpdate(const IEventInfo& info,
190 std::shared_ptr<item::AbstractItem> updatedItem) override {
191 cb_->InvokeUpdated(this, info, updatedItem);
194 void OnDelete(const IEventInfo& info,
195 shared_ptr<item::AbstractItem> deletedItem) override {
196 cb_->InvokeDeleted(this, info, deletedItem);
199 void OnError(NotificationError error, int requestId) override {
200 cb_->InvokeError(this, error, requestId);
203 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
205 return NOTI_EX_ERROR_NONE;
208 int ClearManagerCallbackInfo() {
210 return NOTI_EX_ERROR_NONE;
214 unique_ptr<ManagerCallbackInfo> cb_;
218 class ReporterCallbackInfo {
220 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
221 : user_data_(user_data) {
222 cb_.event = cb.event;
223 cb_.error = cb.error;
226 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
227 list<shared_ptr<AbstractItem>> notiList) {
228 if (cb_.event == nullptr)
230 noti_ex_item_h* noti_list =
231 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
232 if (noti_list == nullptr) {
233 LOGE("Out of memory");
238 for (auto& i : notiList) {
240 static_cast<noti_ex_item_h>(new Handle(i));
243 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
244 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
245 static_cast<noti_ex_event_info_h>(c_info), noti_list,
246 notiList.size(), user_data_);
250 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
251 if (cb_.error == nullptr)
253 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
254 static_cast<noti_ex_error_e>(error), requestId, user_data_);
258 noti_ex_reporter_events_s cb_;
262 class ReporterStub : public Reporter {
264 ReporterStub(std::unique_ptr<IEventSender> sender,
265 std::unique_ptr<IEventListener> listener)
266 : Reporter(move(sender), move(listener)) {
269 void OnEvent(const IEventInfo& info,
270 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
271 cb_->InvokeEvent(this, info, notiList);
274 void OnError(NotificationError error, int requestId) override {
275 cb_->InvokeError(this, error, requestId);
278 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
280 return NOTI_EX_ERROR_NONE;
283 int ClearReporterCallbackInfo() {
285 return NOTI_EX_ERROR_NONE;
289 unique_ptr<ReporterCallbackInfo> cb_;
294 void __noti_ex_free_str_array(char** val, int length) {
296 for (i = 0; i < length ; i++)
301 extern "C" EXPORT_API int noti_ex_action_app_control_create(
302 noti_ex_action_h *handle, app_control_h app_control,
304 if (handle == nullptr || app_control == nullptr) {
305 LOGE("Invalid parameter");
306 return NOTI_EX_ERROR_INVALID_PARAMETER;
309 shared_ptr<AbstractAction>* p;
312 p = new (std::nothrow) shared_ptr<AbstractAction>(
313 new (std::nothrow) AppControlAction(app_control, extra));
315 p = new (std::nothrow) shared_ptr<AbstractAction>(
316 new (std::nothrow) AppControlAction(app_control));
320 LOGE("Out-of-memory");
321 return NOTI_EX_ERROR_OUT_OF_MEMORY;
326 return NOTI_EX_ERROR_NONE;
329 extern "C" EXPORT_API int noti_ex_action_app_control_set(
330 noti_ex_action_h handle, app_control_h app_control) {
331 if (handle == nullptr || app_control == nullptr) {
332 LOGE("Invalid parameter");
333 return NOTI_EX_ERROR_INVALID_PARAMETER;
336 shared_ptr<AbstractAction>* ptr =
337 static_cast<shared_ptr<AbstractAction>*>(handle);
338 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
339 action->SetAppControl(app_control);
341 return NOTI_EX_ERROR_NONE;
344 extern "C" EXPORT_API int noti_ex_action_app_control_get(
345 noti_ex_action_h handle, app_control_h *app_control) {
346 if (handle == nullptr || app_control == nullptr) {
347 LOGE("Invalid parameter");
348 return NOTI_EX_ERROR_INVALID_PARAMETER;
351 shared_ptr<AbstractAction>* ptr =
352 static_cast<shared_ptr<AbstractAction>*>(handle);
353 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
354 *app_control = action->GetAppControl();
356 return NOTI_EX_ERROR_NONE;
359 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
360 const char *id, const char *title) {
363 if (handle == nullptr || title == nullptr) {
364 LOGE("Invalid parameter");
365 return NOTI_EX_ERROR_INVALID_PARAMETER;
369 p = new (std::nothrow) ButtonItem(id, title);
371 p = new (std::nothrow) ButtonItem(title);
374 LOGE("Out-of-memory");
375 return NOTI_EX_ERROR_OUT_OF_MEMORY;
377 *handle = new Handle(shared_ptr<AbstractItem>(p));
379 return NOTI_EX_ERROR_NONE;
382 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
384 if (handle == nullptr || title == nullptr) {
385 LOGE("Invalid parameter");
386 return NOTI_EX_ERROR_INVALID_PARAMETER;
389 Handle* sp = static_cast<Handle*>(handle);
390 if (!sp->IsValidType(AbstractItem::Button)) {
391 LOGE("Invalid handle type");
392 return NOTI_EX_ERROR_INVALID_PARAMETER;
395 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
397 if (p->GetMultiLanguage() != nullptr &&
398 !p->GetMultiLanguage()->GetTranslatedString().empty())
399 str = p->GetMultiLanguage()->GetTranslatedString();
400 else if (!p->GetTitle().empty())
403 *title = strdup(str.c_str());
404 if (*title == nullptr) {
405 LOGE("Out-of-memory");
406 return NOTI_EX_ERROR_OUT_OF_MEMORY;
409 return NOTI_EX_ERROR_NONE;
412 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
413 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
414 if (handle == nullptr) {
415 LOGE("Invalid parameter");
416 return NOTI_EX_ERROR_INVALID_PARAMETER;
419 Handle* p = static_cast<Handle*>(handle);
420 if (!p->IsValidType(AbstractItem::Button)) {
421 LOGE("Invalid handle type");
422 return NOTI_EX_ERROR_INVALID_PARAMETER;
425 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
426 if (multi == nullptr) {
427 bi->SetMultiLanguage(nullptr);
428 return NOTI_EX_ERROR_NONE;
431 shared_ptr<MultiLanguage> mul_ptr =
432 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
434 mul_ptr->UpdateString();
435 bi->SetMultiLanguage(mul_ptr);
437 return NOTI_EX_ERROR_NONE;
440 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
441 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
442 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
443 noti_ex_item_chat_message_type_e message_type) {
444 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
445 LOGE("Invalid parameter");
446 return NOTI_EX_ERROR_INVALID_PARAMETER;
449 auto* p = new (std::nothrow) ChatMessageItem(id,
450 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
451 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
452 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
453 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
454 static_cast<ChatMessageItem::Type>(message_type));
456 LOGE("Out-of-memory");
457 return NOTI_EX_ERROR_OUT_OF_MEMORY;
460 *handle = new Handle(shared_ptr<AbstractItem>(p));
462 return NOTI_EX_ERROR_NONE;
465 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
466 noti_ex_item_h handle, noti_ex_item_h *name) {
467 if (handle == nullptr || name == nullptr) {
468 LOGE("Invalid parameter");
469 return NOTI_EX_ERROR_INVALID_PARAMETER;
471 Handle* h = static_cast<Handle*>(handle);
472 if (!h->IsValidType(AbstractItem::ChatMessage)) {
473 LOGE("Invalid handle type");
474 return NOTI_EX_ERROR_INVALID_PARAMETER;
476 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
477 *name = new Handle(&(p->GetNameItem()));
479 return NOTI_EX_ERROR_NONE;
482 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
483 noti_ex_item_h handle, noti_ex_item_h *text) {
484 if (handle == nullptr || text == nullptr) {
485 LOGE("Invalid parameter");
486 return NOTI_EX_ERROR_INVALID_PARAMETER;
489 Handle* h = static_cast<Handle*>(handle);
490 if (!h->IsValidType(AbstractItem::ChatMessage)) {
491 LOGE("Invalid handle type");
492 return NOTI_EX_ERROR_INVALID_PARAMETER;
494 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
495 *text = new Handle(&(p->GetTextItem()));
497 return NOTI_EX_ERROR_NONE;
500 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
501 noti_ex_item_h handle, noti_ex_item_h *image) {
502 if (handle == nullptr || image == nullptr) {
503 LOGE("Invalid parameter");
504 return NOTI_EX_ERROR_INVALID_PARAMETER;
507 Handle* h = static_cast<Handle*>(handle);
508 if (!h->IsValidType(AbstractItem::ChatMessage)) {
509 LOGE("Invalid handle type");
510 return NOTI_EX_ERROR_INVALID_PARAMETER;
512 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
513 *image = new Handle(&(p->GetImageItem()));
515 return NOTI_EX_ERROR_NONE;
518 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
519 noti_ex_item_h handle, noti_ex_item_h *time) {
520 if (handle == nullptr || time == nullptr) {
521 LOGE("Invalid parameter");
522 return NOTI_EX_ERROR_INVALID_PARAMETER;
525 Handle* h = static_cast<Handle*>(handle);
526 if (!h->IsValidType(AbstractItem::ChatMessage)) {
527 LOGE("Invalid handle type");
528 return NOTI_EX_ERROR_INVALID_PARAMETER;
530 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
531 *time = new Handle(&(p->GetTimeItem()));
533 return NOTI_EX_ERROR_NONE;
536 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
537 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
538 if (handle == nullptr || message_type == nullptr) {
539 LOGE("Invalid parameter");
540 return NOTI_EX_ERROR_INVALID_PARAMETER;
543 Handle* h = static_cast<Handle*>(handle);
544 if (!h->IsValidType(AbstractItem::ChatMessage)) {
545 LOGE("Invalid handle type");
546 return NOTI_EX_ERROR_INVALID_PARAMETER;
548 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
549 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
551 return NOTI_EX_ERROR_NONE;
554 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
555 const char *id, const char *title, bool checked) {
558 if (handle == nullptr || title == nullptr) {
559 LOGE("Invalid parameter");
560 return NOTI_EX_ERROR_INVALID_PARAMETER;
563 p = new (std::nothrow) CheckBoxItem(id, title, checked);
565 LOGE("Out-of-memory");
566 return NOTI_EX_ERROR_OUT_OF_MEMORY;
569 *handle = new Handle(shared_ptr<AbstractItem>(p));
571 return NOTI_EX_ERROR_NONE;
574 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
576 if (handle == nullptr || title == nullptr) {
577 LOGE("Invalid parameter");
578 return NOTI_EX_ERROR_INVALID_PARAMETER;
580 Handle* h = static_cast<Handle*>(handle);
581 if (!h->IsValidType(AbstractItem::CheckBox)) {
582 LOGE("Invalid handle type");
583 return NOTI_EX_ERROR_INVALID_PARAMETER;
586 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
588 if (p->GetMultiLanguage() != nullptr &&
589 !p->GetMultiLanguage()->GetTranslatedString().empty())
590 str = p->GetMultiLanguage()->GetTranslatedString();
591 else if (!p->GetTitle().empty())
594 *title = strdup(str.c_str());
595 if (*title == nullptr) {
596 LOGE("Out-of-memory");
597 return NOTI_EX_ERROR_OUT_OF_MEMORY;
600 return NOTI_EX_ERROR_NONE;
603 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
604 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
605 if (handle == nullptr) {
606 LOGE("Invalid parameter");
607 return NOTI_EX_ERROR_INVALID_PARAMETER;
610 Handle* p = static_cast<Handle*>(handle);
611 if (!p->IsValidType(AbstractItem::CheckBox)) {
612 LOGE("Invalid handle type");
613 return NOTI_EX_ERROR_INVALID_PARAMETER;
616 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
617 if (multi == nullptr) {
618 ci->SetMultiLanguage(nullptr);
619 return NOTI_EX_ERROR_NONE;
622 shared_ptr<MultiLanguage> mul_ptr =
623 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
624 mul_ptr->UpdateString();
625 ci->SetMultiLanguage(mul_ptr);
627 return NOTI_EX_ERROR_NONE;
630 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
632 if (handle == nullptr || checked == nullptr) {
633 LOGE("Invalid parameter");
634 return NOTI_EX_ERROR_INVALID_PARAMETER;
636 Handle* h = static_cast<Handle*>(handle);
637 if (!h->IsValidType(AbstractItem::CheckBox)) {
638 LOGE("Invalid handle type");
639 return NOTI_EX_ERROR_INVALID_PARAMETER;
641 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
642 *checked = p->IsChecked();
644 return NOTI_EX_ERROR_NONE;
647 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
648 noti_ex_item_h handle, bool *checked) {
649 if (handle == nullptr || checked == nullptr) {
650 LOGE("Invalid parameter");
651 return NOTI_EX_ERROR_INVALID_PARAMETER;
653 Handle* h = static_cast<Handle*>(handle);
654 if (!h->IsValidType(AbstractItem::CheckBox)) {
655 LOGE("Invalid handle type");
656 return NOTI_EX_ERROR_INVALID_PARAMETER;
658 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
659 *checked = p->IsChecked();
661 return NOTI_EX_ERROR_NONE;
664 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
665 noti_ex_item_h handle, bool checked) {
666 if (handle == nullptr) {
667 LOGE("Invalid parameter");
668 return NOTI_EX_ERROR_INVALID_PARAMETER;
671 Handle* h = static_cast<Handle*>(handle);
672 if (!h->IsValidType(AbstractItem::CheckBox)) {
673 LOGE("Invalid handle type");
674 return NOTI_EX_ERROR_INVALID_PARAMETER;
677 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
678 p->SetChecked(checked);
680 return NOTI_EX_ERROR_NONE;
683 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
687 if (handle == nullptr) {
688 LOGE("Invalid parameter");
689 return NOTI_EX_ERROR_INVALID_PARAMETER;
692 p = new (std::nothrow) EntryItem(id);
694 LOGE("Out-of-memory");
695 return NOTI_EX_ERROR_OUT_OF_MEMORY;
698 *handle = new Handle(shared_ptr<AbstractItem>(p));
700 return NOTI_EX_ERROR_NONE;
703 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
705 if (handle == nullptr || text == nullptr) {
706 LOGE("Invalid parameter");
707 return NOTI_EX_ERROR_INVALID_PARAMETER;
710 Handle* h = static_cast<Handle*>(handle);
711 if (!h->IsValidType(AbstractItem::Entry)) {
712 LOGE("Invalid handle type");
713 return NOTI_EX_ERROR_INVALID_PARAMETER;
716 EntryItem* p = static_cast<EntryItem*>(h->Get());
718 if (p->GetMultiLanguage() != nullptr &&
719 !p->GetMultiLanguage()->GetTranslatedString().empty())
720 str = p->GetMultiLanguage()->GetTranslatedString();
721 else if (!p->GetText().empty())
724 *text = strdup(str.c_str());
725 if (*text == nullptr) {
726 LOGE("Out-of-memory");
727 return NOTI_EX_ERROR_OUT_OF_MEMORY;
730 return NOTI_EX_ERROR_NONE;
733 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
735 if (handle == nullptr || text == nullptr) {
736 LOGE("Invalid parameter");
737 return NOTI_EX_ERROR_INVALID_PARAMETER;
739 Handle* h = static_cast<Handle*>(handle);
740 if (!h->IsValidType(AbstractItem::Entry)) {
741 LOGE("Invalid handle type");
742 return NOTI_EX_ERROR_INVALID_PARAMETER;
744 EntryItem* p = static_cast<EntryItem*>(h->Get());
745 p->SetText(std::string(text));
747 return NOTI_EX_ERROR_NONE;
750 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
751 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
752 if (handle == nullptr) {
753 LOGE("Invalid parameter");
754 return NOTI_EX_ERROR_INVALID_PARAMETER;
757 Handle* p = static_cast<Handle*>(handle);
758 if (!p->IsValidType(AbstractItem::Entry)) {
759 LOGE("Invalid handle type");
760 return NOTI_EX_ERROR_INVALID_PARAMETER;
763 EntryItem* ei = static_cast<EntryItem*>(p->Get());
764 if (multi == nullptr) {
765 ei->SetMultiLanguage(nullptr);
766 return NOTI_EX_ERROR_NONE;
769 shared_ptr<MultiLanguage> mul_ptr =
770 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
771 ei->SetMultiLanguage(mul_ptr);
772 ei->GetMultiLanguage()->UpdateString();
774 return NOTI_EX_ERROR_NONE;
777 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
778 noti_ex_event_info_h* cloned_handle) {
779 if (handle == nullptr || cloned_handle == nullptr) {
780 LOGE("Invalid parameter");
781 return NOTI_EX_ERROR_INVALID_PARAMETER;
784 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
785 EventInfo* info = new EventInfo(cloned);
786 *cloned_handle = info;
787 return NOTI_EX_ERROR_NONE;
790 extern "C" EXPORT_API int noti_ex_event_info_destroy(
791 noti_ex_event_info_h handle) {
792 if (handle == nullptr) {
793 LOGE("Invalid parameter");
794 return NOTI_EX_ERROR_INVALID_PARAMETER;
796 EventInfo* info = static_cast<EventInfo*>(handle);
798 return NOTI_EX_ERROR_NONE;
801 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
802 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
803 if (handle == nullptr || event_type == nullptr) {
804 LOGE("Invalid parameter");
805 return NOTI_EX_ERROR_INVALID_PARAMETER;
807 EventInfo* info = static_cast<EventInfo*>(handle);
808 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
810 return NOTI_EX_ERROR_NONE;
813 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
814 noti_ex_event_info_h handle, char **owner) {
815 if (handle == nullptr || owner == nullptr) {
816 LOGE("Invalid parameter");
817 return NOTI_EX_ERROR_INVALID_PARAMETER;
819 EventInfo* info = static_cast<EventInfo*>(handle);
820 *owner = strdup(info->GetOwner().c_str());
821 return NOTI_EX_ERROR_NONE;
824 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
825 noti_ex_event_info_h handle, char **channel) {
826 if (handle == nullptr || channel == nullptr) {
827 LOGE("Invalid parameter");
828 return NOTI_EX_ERROR_INVALID_PARAMETER;
830 EventInfo* info = static_cast<EventInfo*>(handle);
831 *channel = strdup(info->GetChannel().c_str());
832 return NOTI_EX_ERROR_NONE;
835 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
836 noti_ex_event_info_h handle, char **item_id) {
837 if (handle == nullptr || item_id == nullptr) {
838 LOGE("Invalid parameter");
839 return NOTI_EX_ERROR_INVALID_PARAMETER;
841 EventInfo* info = static_cast<EventInfo*>(handle);
842 *item_id = strdup(info->GetItemId().c_str());
843 return NOTI_EX_ERROR_NONE;
846 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
847 noti_ex_event_info_h handle, int *req_id) {
848 if (handle == nullptr || req_id == nullptr) {
849 LOGE("Invalid parameter");
850 return NOTI_EX_ERROR_INVALID_PARAMETER;
852 EventInfo* info = static_cast<EventInfo*>(handle);
853 *req_id = info->GetRequestId();
854 return NOTI_EX_ERROR_NONE;
857 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
861 if (handle == nullptr) {
862 LOGE("Invalid parameter");
863 return NOTI_EX_ERROR_INVALID_PARAMETER;
867 p = new (std::nothrow) GroupItem(id);
869 p = new (std::nothrow) GroupItem();
872 LOGE("Out-of-memory");
873 return NOTI_EX_ERROR_OUT_OF_MEMORY;
876 *handle = new Handle(shared_ptr<AbstractItem>(p));
878 return NOTI_EX_ERROR_NONE;
881 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
883 if (handle == nullptr) {
884 LOGE("Invalid parameter");
885 return NOTI_EX_ERROR_INVALID_PARAMETER;
887 Handle* h = static_cast<Handle*>(handle);
888 if (!h->IsValidType(AbstractItem::Group)) {
889 LOGE("Invalid handle type");
890 return NOTI_EX_ERROR_INVALID_PARAMETER;
892 GroupItem* p = static_cast<GroupItem*>(h->Get());
893 p->SetDirection(vertical);
895 return NOTI_EX_ERROR_NONE;
898 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
900 if (handle == nullptr) {
901 LOGE("Invalid parameter");
902 return NOTI_EX_ERROR_INVALID_PARAMETER;
904 Handle* h = static_cast<Handle*>(handle);
905 if (!h->IsValidType(AbstractItem::Group)) {
906 LOGE("Invalid handle type");
907 return NOTI_EX_ERROR_INVALID_PARAMETER;
909 GroupItem* p = static_cast<GroupItem*>(h->Get());
910 *vertical = p->IsVertical();
912 return NOTI_EX_ERROR_NONE;
915 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
917 if (handle == nullptr) {
918 LOGE("Invalid parameter");
919 return NOTI_EX_ERROR_INVALID_PARAMETER;
921 Handle* h = static_cast<Handle*>(handle);
922 if (!h->IsValidType(AbstractItem::Group)) {
923 LOGE("Invalid handle type");
924 return NOTI_EX_ERROR_INVALID_PARAMETER;
926 GroupItem* p = static_cast<GroupItem*>(h->Get());
927 if (!p->GetAppLabel().empty()) {
928 *label = strdup(p->GetAppLabel().c_str());
929 if (*label == nullptr) {
930 LOGE("Out-of-memory");
931 return NOTI_EX_ERROR_OUT_OF_MEMORY;
935 return NOTI_EX_ERROR_NONE;
938 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
939 noti_ex_item_h child) {
940 if (handle == nullptr || child == nullptr) {
941 LOGE("Invalid parameter");
942 return NOTI_EX_ERROR_INVALID_PARAMETER;
944 Handle* h = static_cast<Handle*>(handle);
945 if (!h->IsValidType(AbstractItem::Group)) {
946 LOGE("Invalid handle type");
947 return NOTI_EX_ERROR_INVALID_PARAMETER;
949 auto p = static_cast<GroupItem*>(h->Get());
950 p->AddChild((static_cast<Handle*>(child))->GetPtr());
952 return NOTI_EX_ERROR_NONE;
955 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
956 const char *item_id) {
957 if (handle == nullptr || item_id == nullptr) {
958 LOGE("Invalid parameter");
959 return NOTI_EX_ERROR_INVALID_PARAMETER;
961 Handle* h = static_cast<Handle*>(handle);
962 if (!h->IsValidType(AbstractItem::Group)) {
963 LOGE("Invalid handle type");
964 return NOTI_EX_ERROR_INVALID_PARAMETER;
966 GroupItem* p = static_cast<GroupItem*>(h->Get());
967 p->RemoveChild(std::string(item_id));
969 return NOTI_EX_ERROR_NONE;
972 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
973 noti_ex_item_group_foreach_child_cb callback, void *data) {
974 if (handle == nullptr || callback == nullptr) {
975 LOGE("Invalid parameter");
976 return NOTI_EX_ERROR_INVALID_PARAMETER;
979 Handle* h = static_cast<Handle*>(handle);
980 if (!h->IsValidType(AbstractItem::Group)) {
981 LOGE("Invalid handle type");
982 return NOTI_EX_ERROR_INVALID_PARAMETER;
984 GroupItem* p = static_cast<GroupItem*>(h->Get());
985 list<shared_ptr<AbstractItem>> children = p->GetChildren();
986 LOGI("Retrive (%zd)", children.size());
987 for (auto i : children) {
989 static_cast<noti_ex_item_h>(new Handle(i)), data);
990 if (ret != NOTI_EX_ERROR_NONE) {
991 LOGW("callback return (%d) stop foreach", ret);
996 return NOTI_EX_ERROR_NONE;
999 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1000 const char *id, const char *image_path) {
1003 if (handle == nullptr || image_path == nullptr) {
1004 LOGE("Invalid parameter");
1005 return NOTI_EX_ERROR_INVALID_PARAMETER;
1009 p = new (std::nothrow) ImageItem(id, image_path);
1011 p = new (std::nothrow) ImageItem(image_path);
1014 LOGE("Out-of-memory");
1015 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1018 *handle = new Handle(shared_ptr<AbstractItem>(p));
1020 return NOTI_EX_ERROR_NONE;
1023 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1024 noti_ex_item_h handle, char **image_path) {
1025 if (handle == nullptr || image_path == nullptr) {
1026 LOGE("Invalid parameter");
1027 return NOTI_EX_ERROR_INVALID_PARAMETER;
1029 Handle* h = static_cast<Handle*>(handle);
1030 if (!h->IsValidType(AbstractItem::Image)) {
1031 LOGE("Invalid handle type");
1032 return NOTI_EX_ERROR_INVALID_PARAMETER;
1034 ImageItem* p = static_cast<ImageItem*>(h->Get());
1035 if (!p->GetImagePath().empty()) {
1036 *image_path = strdup(p->GetImagePath().c_str());
1037 if (*image_path == nullptr) {
1038 LOGE("Out-of-memory");
1039 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1043 return NOTI_EX_ERROR_NONE;
1046 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1047 noti_ex_item_h *handle, const char *id) {
1048 InputSelectorItem* p;
1050 if (handle == nullptr) {
1051 LOGE("Invalid parameter");
1052 return NOTI_EX_ERROR_INVALID_PARAMETER;
1056 p = new (std::nothrow) InputSelectorItem(id);
1058 p = new (std::nothrow) InputSelectorItem();
1061 LOGE("Out-of-memory");
1062 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1065 *handle = new Handle(shared_ptr<AbstractItem>(p));
1067 return NOTI_EX_ERROR_NONE;
1070 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1071 noti_ex_item_h handle, char ***contents_list, int *count) {
1072 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1073 LOGE("Invalid parameter");
1074 return NOTI_EX_ERROR_INVALID_PARAMETER;
1077 Handle* h = static_cast<Handle*>(handle);
1078 if (!h->IsValidType(AbstractItem::InputSelector)) {
1079 LOGE("Invalid handle type");
1080 return NOTI_EX_ERROR_INVALID_PARAMETER;
1083 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1084 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1085 list<string> contents;
1086 if (arr.size() == 0) {
1087 contents = p->GetContents();
1089 for (auto& i : arr) {
1090 contents.push_back(i->GetTranslatedString());
1094 char **list = (char**)calloc(contents.size(), sizeof(char*));
1095 if (list == nullptr) {
1096 LOGE("Out of memory");
1097 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1101 for (auto& i : contents) {
1102 list[idx] = strdup(i.c_str());
1103 if (list[idx] == nullptr) {
1104 __noti_ex_free_str_array(list, idx);
1105 LOGE("Out of memory");
1106 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1111 *count = contents.size();
1112 *contents_list = list;
1114 return NOTI_EX_ERROR_NONE;
1117 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1118 noti_ex_item_h handle, const char **contents, int count) {
1119 if (handle == nullptr || contents == nullptr) {
1120 LOGE("Invalid parameter");
1121 return NOTI_EX_ERROR_INVALID_PARAMETER;
1124 list<string> new_contents;
1125 Handle* h = static_cast<Handle*>(handle);
1126 if (!h->IsValidType(AbstractItem::InputSelector)) {
1127 LOGE("Invalid handle type");
1128 return NOTI_EX_ERROR_INVALID_PARAMETER;
1130 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1131 for (int i = 0; i < count; i++) {
1132 new_contents.push_back(contents[i]);
1134 p->SetContents(move(new_contents));
1136 return NOTI_EX_ERROR_NONE;
1139 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1140 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1141 if (handle == nullptr) {
1142 LOGE("Invalid parameter");
1143 return NOTI_EX_ERROR_INVALID_PARAMETER;
1146 Handle* p = static_cast<Handle*>(handle);
1147 if (!p->IsValidType(AbstractItem::InputSelector)) {
1148 LOGE("Invalid handle type");
1149 return NOTI_EX_ERROR_INVALID_PARAMETER;
1152 vector<shared_ptr<MultiLanguage>> m_list;
1153 for (int i = 0; i < count; i++) {
1154 shared_ptr<MultiLanguage> mul_ptr =
1155 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1156 mul_ptr->UpdateString();
1157 m_list.push_back(mul_ptr);
1160 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1161 input->SetMultiLanguage(m_list);
1163 return NOTI_EX_ERROR_NONE;
1166 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1167 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1168 if (handle == nullptr) {
1169 LOGE("Invalid parameter");
1170 return NOTI_EX_ERROR_INVALID_PARAMETER;
1173 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1174 new (std::nothrow) Color(a, r, g, b));
1175 if (ptr == nullptr || ptr->get() == nullptr) {
1176 LOGE("Out-of-memory");
1177 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1182 return NOTI_EX_ERROR_NONE;
1185 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1186 if (handle == nullptr) {
1187 LOGE("Invalid parameter");
1188 return NOTI_EX_ERROR_INVALID_PARAMETER;
1191 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1194 return NOTI_EX_ERROR_NONE;
1197 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1198 unsigned char *val) {
1199 if (handle == nullptr || val == nullptr) {
1200 LOGE("Invalid parameter");
1201 return NOTI_EX_ERROR_INVALID_PARAMETER;
1204 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1205 *val = (*p)->GetAVal();
1207 return NOTI_EX_ERROR_NONE;
1210 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1211 unsigned char *val) {
1212 if (handle == nullptr || val == nullptr) {
1213 LOGE("Invalid parameter");
1214 return NOTI_EX_ERROR_INVALID_PARAMETER;
1217 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1218 *val = (*p)->GetRVal();
1220 return NOTI_EX_ERROR_NONE;
1223 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1224 unsigned char *val) {
1225 if (handle == nullptr || val == nullptr) {
1226 LOGE("Invalid parameter");
1227 return NOTI_EX_ERROR_INVALID_PARAMETER;
1230 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1231 *val = (*p)->GetGVal();
1233 return NOTI_EX_ERROR_NONE;
1236 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1237 unsigned char *val) {
1238 if (handle == nullptr || val == nullptr) {
1239 LOGE("Invalid parameter");
1240 return NOTI_EX_ERROR_INVALID_PARAMETER;
1243 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1244 *val = (*p)->GetBVal();
1246 return NOTI_EX_ERROR_NONE;
1249 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1250 int left, int top, int right, int bottom) {
1251 if (handle == nullptr) {
1252 LOGE("Invalid parameter");
1253 return NOTI_EX_ERROR_INVALID_PARAMETER;
1256 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1257 new (std::nothrow) Padding(left, top, right, bottom));
1258 if (ptr == nullptr || ptr->get() == nullptr) {
1259 LOGE("Out-of-memory");
1260 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1265 return NOTI_EX_ERROR_NONE;
1268 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1269 if (handle == nullptr) {
1270 LOGE("Invalid parameter");
1271 return NOTI_EX_ERROR_INVALID_PARAMETER;
1274 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1277 return NOTI_EX_ERROR_NONE;
1280 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1282 if (handle == nullptr || val == nullptr) {
1283 LOGE("Invalid parameter");
1284 return NOTI_EX_ERROR_INVALID_PARAMETER;
1287 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1288 *val = (*p)->GetLeft();
1290 return NOTI_EX_ERROR_NONE;
1293 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1295 if (handle == nullptr || val == nullptr) {
1296 LOGE("Invalid parameter");
1297 return NOTI_EX_ERROR_INVALID_PARAMETER;
1300 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1301 *val = (*p)->GetTop();
1303 return NOTI_EX_ERROR_NONE;
1306 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1308 if (handle == nullptr || val == nullptr) {
1309 LOGE("Invalid parameter");
1310 return NOTI_EX_ERROR_INVALID_PARAMETER;
1313 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1314 *val = (*p)->GetRight();
1316 return NOTI_EX_ERROR_NONE;
1319 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1321 if (handle == nullptr || val == nullptr) {
1322 LOGE("Invalid parameter");
1323 return NOTI_EX_ERROR_INVALID_PARAMETER;
1326 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1327 *val = (*p)->GetBottom();
1329 return NOTI_EX_ERROR_NONE;
1332 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1333 int x, int y, int w, int h) {
1334 if (handle == nullptr) {
1335 LOGE("Invalid parameter");
1336 return NOTI_EX_ERROR_INVALID_PARAMETER;
1339 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1340 new (std::nothrow) Geometry(x, y, w, h));
1341 if (ptr == nullptr || ptr->get() == nullptr) {
1342 LOGE("Out-of-memory");
1343 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1348 return NOTI_EX_ERROR_NONE;
1351 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1352 if (handle == nullptr) {
1353 LOGE("Invalid parameter");
1354 return NOTI_EX_ERROR_INVALID_PARAMETER;
1357 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1360 return NOTI_EX_ERROR_NONE;
1363 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1365 if (handle == nullptr || val == nullptr) {
1366 LOGE("Invalid parameter");
1367 return NOTI_EX_ERROR_INVALID_PARAMETER;
1370 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1371 *val = (*p)->GetX();
1373 return NOTI_EX_ERROR_NONE;
1376 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1378 if (handle == nullptr || val == nullptr) {
1379 LOGE("Invalid parameter");
1380 return NOTI_EX_ERROR_INVALID_PARAMETER;
1383 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1384 *val = (*p)->GetY();
1386 return NOTI_EX_ERROR_NONE;
1389 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1391 if (handle == nullptr || val == nullptr) {
1392 LOGE("Invalid parameter");
1393 return NOTI_EX_ERROR_INVALID_PARAMETER;
1396 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1397 *val = (*p)->GetWidth();
1399 return NOTI_EX_ERROR_NONE;
1402 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1404 if (handle == nullptr || val == nullptr) {
1405 LOGE("Invalid parameter");
1406 return NOTI_EX_ERROR_INVALID_PARAMETER;
1409 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1410 *val = (*p)->GetHeight();
1412 return NOTI_EX_ERROR_NONE;
1415 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1416 noti_ex_color_h color,
1417 noti_ex_padding_h padding,
1418 noti_ex_geometry_h geometry) {
1419 if (handle == nullptr) {
1420 LOGE("Invalid parameter");
1421 return NOTI_EX_ERROR_INVALID_PARAMETER;
1424 shared_ptr<Color> col = (color == nullptr) ?
1425 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1426 shared_ptr<Padding> padd = (padding == nullptr) ?
1427 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1428 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1429 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1431 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1432 new (std::nothrow) Style(col, padd, geo));
1433 if (ptr == nullptr || ptr->get() == nullptr) {
1434 LOGE("Out-of-memory");
1435 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1440 return NOTI_EX_ERROR_NONE;
1443 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1444 if (handle == nullptr) {
1445 LOGE("Invalid parameter");
1446 return NOTI_EX_ERROR_INVALID_PARAMETER;
1449 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1452 return NOTI_EX_ERROR_NONE;
1455 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1456 noti_ex_padding_h *padding) {
1457 if (handle == nullptr || padding == nullptr) {
1458 LOGE("Invalid parameter");
1459 return NOTI_EX_ERROR_INVALID_PARAMETER;
1462 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1463 if ((*p)->GetPadding() == nullptr) {
1464 LOGW("Padding info is null");
1465 return NOTI_EX_ERROR_INVALID_PARAMETER;
1468 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1469 new (std::nothrow) Padding(*((*p)->GetPadding())));
1470 if (padd == nullptr || padd->get() == nullptr) {
1471 LOGE("Out-of-memory");
1472 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1477 return NOTI_EX_ERROR_NONE;
1480 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1481 noti_ex_color_h *color) {
1482 if (handle == nullptr || color == nullptr) {
1483 LOGE("Invalid parameter");
1484 return NOTI_EX_ERROR_INVALID_PARAMETER;
1487 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1488 if ((*p)->GetColor() == nullptr) {
1489 LOGW("Color info is null");
1490 return NOTI_EX_ERROR_INVALID_PARAMETER;
1493 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1494 new (std::nothrow) Color(*((*p)->GetColor())));
1495 if (col == nullptr || col->get() == nullptr) {
1496 LOGE("Out-of-memory");
1497 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1502 return NOTI_EX_ERROR_NONE;
1505 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1506 noti_ex_geometry_h *geometry) {
1507 if (handle == nullptr || geometry == nullptr) {
1508 LOGE("Invalid parameter");
1509 return NOTI_EX_ERROR_INVALID_PARAMETER;
1512 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1513 if ((*p)->GetGeometry() == nullptr) {
1514 LOGW("Geometry info is null");
1515 return NOTI_EX_ERROR_INVALID_PARAMETER;
1518 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1519 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1520 if (geo == nullptr || geo->get() == nullptr) {
1521 LOGE("Out-of-memory");
1522 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1527 return NOTI_EX_ERROR_NONE;
1530 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1531 noti_ex_style_h handle, char** background_image) {
1532 if (handle == nullptr || background_image == nullptr) {
1533 LOGE("Invalid parameter");
1534 return NOTI_EX_ERROR_INVALID_PARAMETER;
1537 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1538 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1540 return NOTI_EX_ERROR_NONE;
1543 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1544 noti_ex_style_h handle, char* background_image) {
1545 if (handle == nullptr || background_image == nullptr) {
1546 LOGE("Invalid parameter");
1547 return NOTI_EX_ERROR_INVALID_PARAMETER;
1550 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1551 (*p)->SetBackgroundImage(background_image);
1553 return NOTI_EX_ERROR_NONE;
1556 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1557 noti_ex_style_h handle, noti_ex_color_h* color) {
1558 if (handle == nullptr || color == nullptr) {
1559 LOGE("Invalid parameter");
1560 return NOTI_EX_ERROR_INVALID_PARAMETER;
1563 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1564 if ((*p)->GetBackgroundColor() == nullptr) {
1565 LOGW("Color info is null");
1566 return NOTI_EX_ERROR_INVALID_PARAMETER;
1569 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1570 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1571 if (col == nullptr || col->get() == nullptr) {
1572 LOGE("Out-of-memory");
1573 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1578 return NOTI_EX_ERROR_NONE;
1581 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1582 noti_ex_style_h handle, noti_ex_color_h color) {
1583 if (handle == nullptr || color == nullptr) {
1584 LOGE("Invalid parameter");
1585 return NOTI_EX_ERROR_INVALID_PARAMETER;
1588 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1589 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1590 (*p)->SetBackgroundColor(*col);
1592 return NOTI_EX_ERROR_NONE;
1595 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1596 noti_ex_color_h color) {
1597 if (handle == nullptr) {
1598 LOGE("Invalid parameter");
1599 return NOTI_EX_ERROR_INVALID_PARAMETER;
1602 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1603 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1604 new (std::nothrow) LEDInfo(*color_ptr));
1606 LOGE("Out-of-memory");
1607 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1612 return NOTI_EX_ERROR_NONE;
1615 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1616 if (handle == nullptr) {
1617 LOGE("Invalid parameter");
1618 return NOTI_EX_ERROR_INVALID_PARAMETER;
1621 shared_ptr<LEDInfo>* led_ptr =
1622 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1624 return NOTI_EX_ERROR_NONE;
1627 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1628 noti_ex_led_info_h handle, int ms) {
1629 if (handle == nullptr) {
1630 LOGE("Invalid parameter");
1631 return NOTI_EX_ERROR_INVALID_PARAMETER;
1634 shared_ptr<LEDInfo>* led_ptr =
1635 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1636 (*led_ptr)->SetOnPeriod(ms);
1638 return NOTI_EX_ERROR_NONE;
1641 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1642 noti_ex_led_info_h handle, int *ms) {
1643 if (handle == nullptr || ms == nullptr) {
1644 LOGE("Invalid parameter");
1645 return NOTI_EX_ERROR_INVALID_PARAMETER;
1648 shared_ptr<LEDInfo>* led_ptr =
1649 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1650 *ms = (*led_ptr)->GetOnPeriod();
1652 return NOTI_EX_ERROR_NONE;
1655 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1656 noti_ex_led_info_h handle, int ms) {
1657 if (handle == nullptr) {
1658 LOGE("Invalid parameter");
1659 return NOTI_EX_ERROR_INVALID_PARAMETER;
1662 shared_ptr<LEDInfo>* led_ptr =
1663 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1664 (*led_ptr)->SetOffPeriod(ms);
1666 return NOTI_EX_ERROR_NONE;
1669 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1670 noti_ex_led_info_h handle, int *ms) {
1671 if (handle == nullptr) {
1672 LOGE("Invalid parameter");
1673 return NOTI_EX_ERROR_INVALID_PARAMETER;
1676 shared_ptr<LEDInfo>* led_ptr =
1677 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1678 *ms = (*led_ptr)->GetOffPeriod();
1680 return NOTI_EX_ERROR_NONE;
1683 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1684 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1685 if (handle == nullptr) {
1686 LOGE("Invalid parameter");
1687 return NOTI_EX_ERROR_INVALID_PARAMETER;
1690 shared_ptr<LEDInfo>* led_ptr =
1691 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1692 if ((*led_ptr)->GetColor() == nullptr) {
1693 LOGE("Color is null");
1694 return NOTI_EX_ERROR_INVALID_PARAMETER;
1697 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1698 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1699 if (col == nullptr || col->get() == nullptr) {
1700 LOGE("Out-of-memory");
1701 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1706 return NOTI_EX_ERROR_NONE;
1709 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1710 if (handle == nullptr) {
1711 LOGE("Invalid parameter");
1712 return NOTI_EX_ERROR_INVALID_PARAMETER;
1715 shared_ptr<AbstractAction>* ptr =
1716 static_cast<shared_ptr<AbstractAction>*>(handle);
1719 return NOTI_EX_ERROR_NONE;
1722 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1724 if (handle == nullptr || type == nullptr) {
1725 LOGE("Invalid parameter");
1726 return NOTI_EX_ERROR_INVALID_PARAMETER;
1729 shared_ptr<AbstractAction>* ptr =
1730 static_cast<shared_ptr<AbstractAction>*>(handle);
1731 *type = (*ptr)->GetType();
1733 return NOTI_EX_ERROR_NONE;
1736 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1738 if (handle == nullptr || local == nullptr) {
1739 LOGE("Invalid parameter");
1740 return NOTI_EX_ERROR_INVALID_PARAMETER;
1743 shared_ptr<AbstractAction>* ptr =
1744 static_cast<shared_ptr<AbstractAction>*>(handle);
1745 *local = (*ptr)->IsLocal();
1747 return NOTI_EX_ERROR_NONE;
1750 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1751 noti_ex_item_h item) {
1752 if (handle == nullptr || item == nullptr) {
1753 LOGE("Invalid parameter");
1754 return NOTI_EX_ERROR_INVALID_PARAMETER;
1756 shared_ptr<AbstractAction>* ptr =
1757 static_cast<shared_ptr<AbstractAction>*>(handle);
1758 Handle* ih = static_cast<Handle*>(item);
1759 (*ptr)->Execute(ih->GetPtr());
1761 return NOTI_EX_ERROR_NONE;
1764 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1766 if (handle == nullptr || extra == nullptr) {
1767 LOGE("Invalid parameter");
1768 return NOTI_EX_ERROR_INVALID_PARAMETER;
1771 shared_ptr<AbstractAction>* ptr =
1772 static_cast<shared_ptr<AbstractAction>*>(handle);
1773 if (!(*ptr)->GetExtra().empty()) {
1774 *extra = strdup((*ptr)->GetExtra().c_str());
1775 if (*extra == nullptr) {
1776 LOGE("Out-of-memory");
1777 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1781 return NOTI_EX_ERROR_NONE;
1784 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1785 noti_ex_item_info_h handle, int *hide_time) {
1786 if (handle == nullptr || hide_time == nullptr) {
1787 LOGE("Invalid parameter");
1788 return NOTI_EX_ERROR_INVALID_PARAMETER;
1790 IItemInfo* p = static_cast<IItemInfo*>(handle);
1791 *hide_time = p->GetHideTime();
1792 return NOTI_EX_ERROR_NONE;
1795 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1796 noti_ex_item_info_h handle, int hide_time) {
1797 if (handle == nullptr) {
1798 LOGE("Invalid parameter");
1799 return NOTI_EX_ERROR_INVALID_PARAMETER;
1801 IItemInfo* p = static_cast<IItemInfo*>(handle);
1802 p->SetHideTime(hide_time);
1803 return NOTI_EX_ERROR_NONE;
1806 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1807 noti_ex_item_info_h handle, int *delete_time) {
1808 if (handle == nullptr || delete_time == nullptr) {
1809 LOGE("Invalid parameter");
1810 return NOTI_EX_ERROR_INVALID_PARAMETER;
1812 IItemInfo* p = static_cast<IItemInfo*>(handle);
1813 *delete_time = p->GetDeleteTime();
1814 return NOTI_EX_ERROR_NONE;
1817 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1818 noti_ex_item_info_h handle, int delete_time) {
1819 if (handle == nullptr) {
1820 LOGE("Invalid parameter");
1821 return NOTI_EX_ERROR_INVALID_PARAMETER;
1823 IItemInfo* p = static_cast<IItemInfo*>(handle);
1824 p->SetDeleteTime(delete_time);
1825 return NOTI_EX_ERROR_NONE;
1828 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1829 noti_ex_item_info_h handle, time_t *time) {
1830 if (handle == nullptr || time == nullptr) {
1831 LOGE("Invalid parameter");
1832 return NOTI_EX_ERROR_INVALID_PARAMETER;
1835 IItemInfo* p = static_cast<IItemInfo*>(handle);
1836 *time = p->GetTime();
1837 return NOTI_EX_ERROR_NONE;
1840 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1841 if (handle == nullptr) {
1842 LOGE("Invalid parameter");
1843 return NOTI_EX_ERROR_INVALID_PARAMETER;
1846 Handle* h = static_cast<Handle*>(handle);
1848 return NOTI_EX_ERROR_NONE;
1851 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1852 const char *id, noti_ex_item_h *item) {
1853 if (handle == nullptr) {
1854 LOGE("Invalid parameter");
1855 return NOTI_EX_ERROR_INVALID_PARAMETER;
1858 Handle* p = static_cast<Handle*>(handle);
1859 AbstractItem& find_item = p->Get()->FindByID(string(id));
1860 *item = new Handle(&find_item);
1861 return NOTI_EX_ERROR_NONE;
1864 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1866 if (handle == nullptr || type == nullptr) {
1867 LOGE("Invalid parameter");
1868 return NOTI_EX_ERROR_INVALID_PARAMETER;
1871 Handle* h = static_cast<Handle*>(handle);
1872 AbstractItem* p = h->Get();
1873 *type = p->GetType();
1874 return NOTI_EX_ERROR_NONE;
1877 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1878 char ***path, int *count) {
1879 if (handle == nullptr || path == nullptr || count == nullptr) {
1880 LOGE("Invalid parameter");
1881 return NOTI_EX_ERROR_INVALID_PARAMETER;
1883 Handle* p = static_cast<Handle*>(handle);
1884 list<string> shared_path = p->Get()->GetSharedPath();
1885 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1886 if (tmp_path == nullptr) {
1887 LOGE("Fail to create items");
1888 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1892 for (auto& i : shared_path) {
1893 tmp_path[idx] = strdup(i.c_str());
1894 if (tmp_path[idx] == nullptr) {
1895 __noti_ex_free_str_array(tmp_path, idx);
1896 LOGE("Out of memory");
1897 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1903 *count = shared_path.size();
1904 return NOTI_EX_ERROR_NONE;
1907 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1909 if (handle == nullptr || id == nullptr) {
1910 LOGE("Invalid parameter");
1911 return NOTI_EX_ERROR_INVALID_PARAMETER;
1913 Handle* h = static_cast<Handle*>(handle);
1914 AbstractItem* p = h->Get();
1915 *id = strdup(p->GetId().c_str());
1916 return NOTI_EX_ERROR_NONE;
1919 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1921 if (handle == nullptr || id == nullptr) {
1922 LOGE("Invalid parameter");
1923 return NOTI_EX_ERROR_INVALID_PARAMETER;
1925 Handle* p = static_cast<Handle*>(handle);
1926 p->Get()->SetId(id);
1927 return NOTI_EX_ERROR_NONE;
1930 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1931 noti_ex_action_h *action) {
1932 if (handle == nullptr || action == nullptr) {
1933 LOGE("Invalid parameter");
1934 return NOTI_EX_ERROR_INVALID_PARAMETER;
1936 Handle* p = static_cast<Handle*>(handle);
1937 if (p->Get()->GetAction() == nullptr) {
1939 return NOTI_EX_ERROR_NONE;
1941 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1942 p->Get()->GetAction()));
1944 return NOTI_EX_ERROR_NONE;
1947 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1948 noti_ex_action_h action) {
1949 if (handle == nullptr || action == nullptr) {
1950 LOGE("Invalid parameter");
1951 return NOTI_EX_ERROR_INVALID_PARAMETER;
1954 Handle* p = static_cast<Handle*>(handle);
1956 shared_ptr<AbstractAction>* ptr =
1957 static_cast<shared_ptr<AbstractAction>*>(action);
1958 p->Get()->SetAction(*ptr);
1959 return NOTI_EX_ERROR_NONE;
1962 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1963 noti_ex_style_h *style) {
1964 if (handle == nullptr || style == nullptr) {
1965 LOGE("Invalid parameter");
1966 return NOTI_EX_ERROR_INVALID_PARAMETER;
1969 Handle* p = static_cast<Handle*>(handle);
1970 shared_ptr<Style> s = p->Get()->GetStyle();
1971 if (s.get() == nullptr) {
1972 LOGE("Style is null");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1976 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1977 if (ptr == nullptr || ptr->get() == nullptr) {
1978 LOGE("Out of memory");
1979 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1983 return NOTI_EX_ERROR_NONE;
1986 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1987 noti_ex_style_h style) {
1988 if (handle == nullptr || style == nullptr) {
1989 LOGE("Invalid parameter");
1990 return NOTI_EX_ERROR_INVALID_PARAMETER;
1993 Handle* p = static_cast<Handle*>(handle);
1994 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1995 p->Get()->SetStyle(*s);
1996 return NOTI_EX_ERROR_NONE;
1999 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2001 if (handle == nullptr) {
2002 LOGE("Invalid parameter");
2003 return NOTI_EX_ERROR_INVALID_PARAMETER;
2006 Handle* p = static_cast<Handle*>(handle);
2007 p->Get()->SetVisible(visible);
2008 return NOTI_EX_ERROR_NONE;
2011 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2013 if (handle == nullptr || visible == nullptr) {
2014 LOGE("Invalid parameter");
2015 return NOTI_EX_ERROR_INVALID_PARAMETER;
2018 Handle* p = static_cast<Handle*>(handle);
2019 *visible = p->Get()->GetVisible();
2020 return NOTI_EX_ERROR_NONE;
2023 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2025 if (handle == nullptr) {
2026 LOGE("Invalid parameter");
2027 return NOTI_EX_ERROR_INVALID_PARAMETER;
2030 Handle* p = static_cast<Handle*>(handle);
2031 p->Get()->SetEnable(enable);
2032 return NOTI_EX_ERROR_NONE;
2035 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2037 if (handle == nullptr || enable == nullptr) {
2038 LOGE("Invalid parameter");
2039 return NOTI_EX_ERROR_INVALID_PARAMETER;
2042 Handle* p = static_cast<Handle*>(handle);
2043 *enable = p->Get()->GetEnable();
2044 return NOTI_EX_ERROR_NONE;
2047 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2048 const char *receiver_group) {
2049 if (handle == nullptr || receiver_group == nullptr) {
2050 LOGE("Invalid parameter");
2051 return NOTI_EX_ERROR_INVALID_PARAMETER;
2054 Handle* p = static_cast<Handle*>(handle);
2055 p->Get()->AddReceiver(receiver_group);
2056 return NOTI_EX_ERROR_NONE;
2059 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2060 const char *receiver_group) {
2061 if (handle == nullptr || receiver_group == nullptr) {
2062 LOGE("Invalid parameter");
2063 return NOTI_EX_ERROR_INVALID_PARAMETER;
2066 Handle* p = static_cast<Handle*>(handle);
2067 p->Get()->RemoveReceiver(receiver_group);
2068 return NOTI_EX_ERROR_NONE;
2071 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2072 char ***receiver_list, int *count) {
2073 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2074 LOGE("Invalid parameter");
2075 return NOTI_EX_ERROR_INVALID_PARAMETER;
2078 Handle* p = static_cast<Handle*>(handle);
2079 list<string> receivers = p->Get()->GetReceiverList();
2080 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2081 if (tmp_list == nullptr) {
2082 LOGE("Out of memory");
2083 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2087 for (auto& i : receivers) {
2088 tmp_list[idx] = strdup(i.c_str());
2089 if (tmp_list[idx] == nullptr) {
2090 __noti_ex_free_str_array(tmp_list, idx);
2091 LOGE("Out of memory");
2092 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2097 *receiver_list = tmp_list;
2098 *count = receivers.size();
2099 return NOTI_EX_ERROR_NONE;
2102 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2104 if (handle == nullptr) {
2105 LOGE("Invalid parameter");
2106 return NOTI_EX_ERROR_INVALID_PARAMETER;
2109 Handle* p = static_cast<Handle*>(handle);
2110 p->Get()->SetPolicy(policy);
2111 return NOTI_EX_ERROR_NONE;
2114 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2116 if (handle == nullptr || policy == nullptr) {
2117 LOGE("Invalid parameter");
2118 return NOTI_EX_ERROR_INVALID_PARAMETER;
2121 Handle* p = static_cast<Handle*>(handle);
2122 *policy = p->Get()->GetPolicy();
2123 return NOTI_EX_ERROR_NONE;
2126 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2128 if (handle == nullptr || channel == nullptr) {
2129 LOGE("Invalid parameter");
2130 return NOTI_EX_ERROR_INVALID_PARAMETER;
2133 Handle* p = static_cast<Handle*>(handle);
2134 if (!p->Get()->GetChannel().empty())
2135 *channel = strdup(p->Get()->GetChannel().c_str());
2139 return NOTI_EX_ERROR_NONE;
2142 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2143 const char *channel) {
2144 if (handle == nullptr) {
2145 LOGE("Invalid parameter");
2146 return NOTI_EX_ERROR_INVALID_PARAMETER;
2149 Handle* p = static_cast<Handle*>(handle);
2150 p->Get()->SetChannel(channel);
2151 return NOTI_EX_ERROR_NONE;
2154 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2155 noti_ex_led_info_h led) {
2156 if (handle == nullptr) {
2157 LOGE("Invalid parameter");
2158 return NOTI_EX_ERROR_INVALID_PARAMETER;
2161 Handle* p = static_cast<Handle*>(handle);
2162 shared_ptr<LEDInfo>* led_ptr =
2163 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2164 p->Get()->SetLEDInfo(*led_ptr);
2165 return NOTI_EX_ERROR_NONE;
2168 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2169 noti_ex_led_info_h *led) {
2170 if (handle == nullptr) {
2171 LOGE("Invalid parameter");
2172 return NOTI_EX_ERROR_INVALID_PARAMETER;
2175 Handle* p = static_cast<Handle*>(handle);
2176 if (p->Get()->GetLEDInfo() != nullptr)
2177 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2180 return NOTI_EX_ERROR_NONE;
2183 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2185 if (handle == nullptr) {
2186 LOGE("Invalid parameter");
2187 return NOTI_EX_ERROR_INVALID_PARAMETER;
2190 Handle* p = static_cast<Handle*>(handle);
2191 if (path == nullptr)
2192 p->Get()->SetSoundPath("");
2194 p->Get()->SetSoundPath(path);
2195 return NOTI_EX_ERROR_NONE;
2198 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2200 if (handle == nullptr) {
2201 LOGE("Invalid parameter");
2202 return NOTI_EX_ERROR_INVALID_PARAMETER;
2205 Handle* p = static_cast<Handle*>(handle);
2206 if (path == nullptr)
2207 p->Get()->SetVibrationPath("");
2209 p->Get()->SetVibrationPath(path);
2210 return NOTI_EX_ERROR_NONE;
2213 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2215 if (handle == nullptr || path == nullptr) {
2216 LOGE("Invalid parameter");
2217 return NOTI_EX_ERROR_INVALID_PARAMETER;
2220 Handle* p = static_cast<Handle*>(handle);
2221 if (p->Get()->GetSoundPath().empty())
2224 *path = strdup(p->Get()->GetSoundPath().c_str());
2225 return NOTI_EX_ERROR_NONE;
2228 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2230 if (handle == nullptr || path == nullptr) {
2231 LOGE("Invalid parameter");
2232 return NOTI_EX_ERROR_INVALID_PARAMETER;
2235 Handle* p = static_cast<Handle*>(handle);
2236 if (p->Get()->GetVibrationPath().empty())
2239 *path = strdup(p->Get()->GetVibrationPath().c_str());
2240 return NOTI_EX_ERROR_NONE;
2243 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2244 noti_ex_item_info_h *info) {
2245 if (handle == nullptr || info == nullptr) {
2246 LOGE("Invalid parameter");
2247 return NOTI_EX_ERROR_INVALID_PARAMETER;
2250 Handle* p = static_cast<Handle*>(handle);
2251 if (p->Get()->GetInfo() == nullptr)
2254 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2255 return NOTI_EX_ERROR_NONE;
2258 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2260 if (handle == nullptr || id == nullptr) {
2261 LOGE("Invalid parameter");
2262 return NOTI_EX_ERROR_INVALID_PARAMETER;
2265 Handle* p = static_cast<Handle*>(handle);
2266 if (p->Get()->GetSenderAppId().empty())
2269 *id = strdup(p->Get()->GetSenderAppId().c_str());
2270 return NOTI_EX_ERROR_NONE;
2273 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2275 if (handle == nullptr || tag == nullptr) {
2276 LOGE("Invalid parameter");
2277 return NOTI_EX_ERROR_INVALID_PARAMETER;
2280 Handle* p = static_cast<Handle*>(handle);
2281 if (p->Get()->GetTag().empty())
2284 *tag = strdup(p->Get()->GetTag().c_str());
2285 return NOTI_EX_ERROR_NONE;
2288 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2290 if (handle == nullptr) {
2291 LOGE("Invalid parameter");
2292 return NOTI_EX_ERROR_INVALID_PARAMETER;
2295 Handle* p = static_cast<Handle*>(handle);
2297 p->Get()->SetTag("");
2299 p->Get()->SetTag(tag);
2300 return NOTI_EX_ERROR_NONE;
2303 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2305 if (handle == nullptr || ongoing == nullptr) {
2306 LOGE("Invalid parameter");
2307 return NOTI_EX_ERROR_INVALID_PARAMETER;
2310 Handle* p = static_cast<Handle*>(handle);
2311 *ongoing = p->Get()->GetOnGoingState();
2313 return NOTI_EX_ERROR_NONE;
2316 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2318 if (handle == nullptr) {
2319 LOGE("Invalid parameter");
2320 return NOTI_EX_ERROR_INVALID_PARAMETER;
2323 Handle* p = static_cast<Handle*>(handle);
2324 p->Get()->SetOnGoingState(ongoing);
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2330 int type, bool* exist) {
2331 if (handle == nullptr || exist == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 Handle* p = static_cast<Handle*>(handle);
2337 *exist = p->Get()->IsItemTypeExist(type);
2339 return NOTI_EX_ERROR_NONE;
2342 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2344 if (handle == nullptr || type == nullptr) {
2345 LOGE("Invalid parameter");
2346 return NOTI_EX_ERROR_INVALID_PARAMETER;
2349 Handle* p = static_cast<Handle*>(handle);
2350 *type = p->Get()->GetMainType();
2352 return NOTI_EX_ERROR_NONE;
2355 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2356 const char* id, int type) {
2357 if (handle == nullptr || id == nullptr) {
2358 LOGE("Invalid parameter");
2359 return NOTI_EX_ERROR_INVALID_PARAMETER;
2362 Handle* p = static_cast<Handle*>(handle);
2363 if (!(p->Get()->SetMainType(string(id),
2364 static_cast<AbstractItem::MainType>(type))))
2365 return NOTI_EX_ERROR_INVALID_PARAMETER;
2367 return NOTI_EX_ERROR_NONE;
2370 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2371 int type, noti_ex_item_h* item) {
2372 if (handle == nullptr || item == nullptr) {
2373 LOGE("Invalid parameter");
2374 return NOTI_EX_ERROR_INVALID_PARAMETER;
2377 Handle* h = static_cast<Handle*>(handle);
2378 if (!h->IsValidType(AbstractItem::Group)) {
2379 LOGE("Invalid handle type");
2380 return NOTI_EX_ERROR_INVALID_PARAMETER;
2383 GroupItem* p = static_cast<GroupItem*>(h->Get());
2384 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2385 *item = new Handle(&find_item);
2387 return NOTI_EX_ERROR_NONE;
2390 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2391 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2393 if (handle == nullptr) {
2394 LOGE("Invalid parameter");
2395 return NOTI_EX_ERROR_INVALID_PARAMETER;
2398 string receiver_group_str = "";
2400 receiver_group_str = string(receiver_group);
2402 ManagerStub* stub = new (std::nothrow) ManagerStub(
2403 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2404 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2405 receiver_group_str);
2406 if (stub == nullptr) {
2407 LOGE("Fail to create manager");
2408 return NOTI_EX_ERROR_IO_ERROR;
2410 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2411 new ManagerCallbackInfo(event_callbacks, data)));
2412 *handle = static_cast<noti_ex_manager_h>(stub);
2414 return NOTI_EX_ERROR_NONE;
2417 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2418 if (handle == nullptr) {
2419 LOGE("Invalid parameter");
2420 return NOTI_EX_ERROR_INVALID_PARAMETER;
2422 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2424 return NOTI_EX_ERROR_NONE;
2427 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2428 noti_ex_item_h **items, int *count) {
2429 if (handle == nullptr || items == nullptr || count == nullptr) {
2430 LOGE("Invalid parameter");
2431 return NOTI_EX_ERROR_INVALID_PARAMETER;
2435 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2436 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2437 if (item_list.size() == 0) {
2440 return NOTI_EX_ERROR_NONE;
2442 noti_ex_item_h* added_item =
2443 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2444 if (added_item == nullptr) {
2445 LOGE("Fail to create items");
2446 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2450 for (auto& i : item_list) {
2451 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2453 *items = added_item;
2454 *count = item_list.size();
2455 } catch (Exception &ex) {
2456 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2457 return NOTI_EX_ERROR_IO_ERROR;
2459 return NOTI_EX_ERROR_NONE;
2462 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2463 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2464 if (handle == nullptr || channel == nullptr ||
2465 items == nullptr || count == nullptr) {
2466 LOGE("Invalid parameter");
2467 return NOTI_EX_ERROR_INVALID_PARAMETER;
2471 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2472 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2473 if (item_list.size() == 0) {
2476 return NOTI_EX_ERROR_NONE;
2478 noti_ex_item_h* added_item =
2479 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2480 if (added_item == nullptr) {
2481 LOGE("Fail to create items");
2482 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2486 for (auto& i : item_list) {
2487 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2489 *items = added_item;
2490 *count = item_list.size();
2491 } catch (Exception &ex) {
2492 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2493 return NOTI_EX_ERROR_IO_ERROR;
2496 return NOTI_EX_ERROR_NONE;
2499 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2500 noti_ex_item_h noti, int *request_id) {
2501 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2502 LOGE("Invalid parameter");
2503 return NOTI_EX_ERROR_INVALID_PARAMETER;
2506 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2507 Handle* sp = static_cast<Handle*>(noti);
2508 if (sp->GetPtr().get() == nullptr) {
2509 LOGE("Invalid noti reference can not be sended");
2510 return NOTI_EX_ERROR_INVALID_PARAMETER;
2512 *request_id = stub->Update(sp->GetPtr());
2514 } catch (Exception &ex) {
2515 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2516 return NOTI_EX_ERROR_IO_ERROR;
2518 return NOTI_EX_ERROR_NONE;
2521 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2522 noti_ex_item_h noti, int *request_id) {
2523 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2524 LOGE("Invalid parameter");
2525 return NOTI_EX_ERROR_INVALID_PARAMETER;
2528 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2529 Handle* item = static_cast<Handle*>(noti);
2530 if (item->GetPtr().get() == nullptr) {
2531 LOGE("Invalid noti reference can not be sended");
2532 return NOTI_EX_ERROR_INVALID_PARAMETER;
2534 *request_id = stub->Delete(item->GetPtr());
2536 } catch (Exception &ex) {
2537 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2538 return NOTI_EX_ERROR_IO_ERROR;
2540 return NOTI_EX_ERROR_NONE;
2543 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2545 if (handle == nullptr || request_id == nullptr) {
2546 LOGE("Invalid parameter");
2547 return NOTI_EX_ERROR_INVALID_PARAMETER;
2550 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2551 *request_id = stub->DeleteAll();
2552 } catch (Exception &ex) {
2553 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2554 return NOTI_EX_ERROR_IO_ERROR;
2556 return NOTI_EX_ERROR_NONE;
2559 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2560 noti_ex_item_h noti, int *request_id) {
2561 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2562 LOGE("Invalid parameter");
2563 return NOTI_EX_ERROR_INVALID_PARAMETER;
2566 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2567 Handle* item = static_cast<Handle*>(noti);
2568 if (item->GetPtr().get() == nullptr) {
2569 LOGE("Invalid noti reference can not be sended");
2570 return NOTI_EX_ERROR_INVALID_PARAMETER;
2572 *request_id = stub->Hide(item->GetPtr());
2574 } catch (Exception &ex) {
2575 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2576 return NOTI_EX_ERROR_IO_ERROR;
2578 return NOTI_EX_ERROR_NONE;
2581 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2582 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2583 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2584 LOGE("Invalid parameter");
2585 return NOTI_EX_ERROR_INVALID_PARAMETER;
2588 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2589 *item = new Handle(stub->FindByRootID(root_id));
2590 } catch (Exception &ex) {
2591 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2592 return NOTI_EX_ERROR_IO_ERROR;
2594 return NOTI_EX_ERROR_NONE;
2597 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2598 noti_ex_event_info_h info, noti_ex_error_e error) {
2599 if (handle == nullptr || info == nullptr) {
2600 LOGE("Invalid parameter");
2601 return NOTI_EX_ERROR_INVALID_PARAMETER;
2604 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2605 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2606 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2607 static_cast<NotificationError>(error));
2608 } catch (Exception &ex) {
2609 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2610 return NOTI_EX_ERROR_IO_ERROR;
2612 return NOTI_EX_ERROR_NONE;
2615 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2616 noti_ex_manager_h handle, int *cnt) {
2618 if (handle == nullptr || cnt == nullptr) {
2619 LOGE("Invalid parameter");
2620 return NOTI_EX_ERROR_INVALID_PARAMETER;
2623 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2624 *cnt = stub->GetCount();
2625 } catch (Exception &ex) {
2626 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2627 return NOTI_EX_ERROR_IO_ERROR;
2629 return NOTI_EX_ERROR_NONE;
2632 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2633 const char *id, float min, float current, float max) {
2636 if (handle == nullptr) {
2637 LOGE("Invalid parameter");
2638 return NOTI_EX_ERROR_INVALID_PARAMETER;
2642 p = new (std::nothrow) ProgressItem(id, min, current, max);
2644 p = new (std::nothrow) ProgressItem(min, current, max);
2647 LOGE("Out-of-memory");
2648 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2651 *handle = new Handle(shared_ptr<AbstractItem>(p));
2653 return NOTI_EX_ERROR_NONE;
2656 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2657 noti_ex_item_h handle, float *current) {
2658 if (handle == nullptr || current == nullptr) {
2659 LOGE("Invalid parameter");
2660 return NOTI_EX_ERROR_INVALID_PARAMETER;
2663 Handle *h = static_cast<Handle*>(handle);
2664 if (!h->IsValidType(AbstractItem::Progress)) {
2665 LOGE("Invalid handle type");
2666 return NOTI_EX_ERROR_INVALID_PARAMETER;
2668 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2669 *current = p->GetCurrent();
2671 return NOTI_EX_ERROR_NONE;
2674 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2675 noti_ex_item_h handle, float current) {
2676 if (handle == nullptr) {
2677 LOGE("Invalid parameter");
2678 return NOTI_EX_ERROR_INVALID_PARAMETER;
2681 Handle *h = static_cast<Handle*>(handle);
2682 if (!h->IsValidType(AbstractItem::Progress)) {
2683 LOGE("Invalid handle type");
2684 return NOTI_EX_ERROR_INVALID_PARAMETER;
2686 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2687 p->SetCurrent(current);
2689 return NOTI_EX_ERROR_NONE;
2692 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2694 if (handle == nullptr || min == nullptr) {
2695 LOGE("Invalid parameter");
2696 return NOTI_EX_ERROR_INVALID_PARAMETER;
2699 Handle *h = static_cast<Handle*>(handle);
2700 if (!h->IsValidType(AbstractItem::Progress)) {
2701 LOGE("Invalid handle type");
2702 return NOTI_EX_ERROR_INVALID_PARAMETER;
2704 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2707 return NOTI_EX_ERROR_NONE;
2710 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2712 if (handle == nullptr || max == nullptr) {
2713 LOGE("Invalid parameter");
2714 return NOTI_EX_ERROR_INVALID_PARAMETER;
2717 Handle *h = static_cast<Handle*>(handle);
2718 if (!h->IsValidType(AbstractItem::Progress)) {
2719 LOGE("Invalid handle type");
2720 return NOTI_EX_ERROR_INVALID_PARAMETER;
2722 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2725 return NOTI_EX_ERROR_NONE;
2728 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2730 if (handle == nullptr || type == nullptr) {
2731 LOGE("Invalid parameter");
2732 return NOTI_EX_ERROR_INVALID_PARAMETER;
2735 Handle *h = static_cast<Handle*>(handle);
2736 if (!h->IsValidType(AbstractItem::Progress)) {
2737 LOGE("Invalid handle type");
2738 return NOTI_EX_ERROR_INVALID_PARAMETER;
2740 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2741 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2743 return NOTI_EX_ERROR_NONE;
2746 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2748 if (handle == nullptr) {
2749 LOGE("Invalid parameter");
2750 return NOTI_EX_ERROR_INVALID_PARAMETER;
2753 Handle *h = static_cast<Handle*>(handle);
2754 if (!h->IsValidType(AbstractItem::Progress)) {
2755 LOGE("Invalid handle type");
2756 return NOTI_EX_ERROR_INVALID_PARAMETER;
2758 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2759 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2761 return NOTI_EX_ERROR_NONE;
2764 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2765 noti_ex_reporter_events_s event_callbacks, void *data) {
2766 if (handle == nullptr) {
2767 LOGE("Invalid parameter");
2768 return NOTI_EX_ERROR_INVALID_PARAMETER;
2771 ReporterStub* stub = new (std::nothrow) ReporterStub(
2772 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2773 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2774 if (stub == nullptr) {
2775 LOGE("Fail to create manager");
2776 return NOTI_EX_ERROR_IO_ERROR;
2778 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2779 new ReporterCallbackInfo(event_callbacks, data)));
2781 *handle = static_cast<noti_ex_reporter_h>(stub);
2783 return NOTI_EX_ERROR_NONE;
2786 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2787 if (handle == nullptr) {
2788 LOGE("Invalid parameter");
2789 return NOTI_EX_ERROR_INVALID_PARAMETER;
2791 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2793 return NOTI_EX_ERROR_NONE;
2796 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2797 noti_ex_event_info_h info, noti_ex_error_e error) {
2798 if (handle == nullptr || info == nullptr) {
2799 LOGE("Invalid parameter");
2800 return NOTI_EX_ERROR_INVALID_PARAMETER;
2803 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2804 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2805 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2806 static_cast<NotificationError>(error));
2807 } catch (Exception &ex) {
2808 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2809 return NOTI_EX_ERROR_IO_ERROR;
2811 return NOTI_EX_ERROR_NONE;
2814 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_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 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2822 Handle* h = static_cast<Handle*>(noti);
2823 if (h->GetPtr().get() == nullptr) {
2824 LOGE("Invalid noti reference can not be sended");
2825 return NOTI_EX_ERROR_INVALID_PARAMETER;
2827 *request_id = stub->Post(h->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_reporter_post_list(noti_ex_reporter_h handle,
2837 noti_ex_item_h *noti_list, int count, int *request_id) {
2839 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2840 LOGE("Invalid parameter");
2841 return NOTI_EX_ERROR_INVALID_PARAMETER;
2844 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2845 list<shared_ptr<item::AbstractItem>> notiList;
2846 for (int i = 0; i < count; i++) {
2847 Handle* item = static_cast<Handle*>(noti_list[i]);
2848 notiList.push_back(item->GetPtr());
2850 *request_id = stub->Post(notiList);
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_reporter_update(noti_ex_reporter_h handle,
2859 noti_ex_item_h noti, int *request_id) {
2860 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2861 LOGE("Invalid parameter");
2862 return NOTI_EX_ERROR_INVALID_PARAMETER;
2865 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2866 Handle* item = static_cast<Handle*>(noti);
2867 if (item->GetPtr().get() == nullptr) {
2868 LOGE("Invalid noti reference can not be sended");
2869 return NOTI_EX_ERROR_INVALID_PARAMETER;
2871 *request_id = stub->Update(item->GetPtr());
2873 } catch (Exception &ex) {
2874 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2875 return NOTI_EX_ERROR_IO_ERROR;
2877 return NOTI_EX_ERROR_NONE;
2880 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2881 noti_ex_item_h noti, int *request_id) {
2882 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2883 LOGE("Invalid parameter");
2884 return NOTI_EX_ERROR_INVALID_PARAMETER;
2887 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2888 Handle* item = static_cast<Handle*>(noti);
2889 if (item->GetPtr().get() == nullptr) {
2890 LOGE("Invalid noti reference can not be sended");
2891 return NOTI_EX_ERROR_INVALID_PARAMETER;
2893 *request_id = stub->Delete(item->GetPtr());
2895 } catch (Exception &ex) {
2896 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2897 return NOTI_EX_ERROR_IO_ERROR;
2899 return NOTI_EX_ERROR_NONE;
2902 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2903 noti_ex_reporter_h handle, int *request_id) {
2904 if (handle == nullptr || request_id == nullptr) {
2905 LOGE("Invalid parameter");
2906 return NOTI_EX_ERROR_INVALID_PARAMETER;
2909 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2910 *request_id = stub->DeleteAll();
2911 } catch (Exception &ex) {
2912 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2913 return NOTI_EX_ERROR_IO_ERROR;
2915 return NOTI_EX_ERROR_NONE;
2918 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2919 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2920 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2921 LOGE("Invalid parameter");
2922 return NOTI_EX_ERROR_INVALID_PARAMETER;
2925 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2926 *item = new Handle(stub->FindByRootID(root_id));
2927 } catch (Exception &ex) {
2928 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2929 return NOTI_EX_ERROR_IO_ERROR;
2931 return NOTI_EX_ERROR_NONE;
2934 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2935 const char *id, const char *text, const char *hyperlink) {
2936 if (handle == nullptr || text == nullptr) {
2937 LOGE("Invalid parameter");
2938 return NOTI_EX_ERROR_INVALID_PARAMETER;
2944 p = new (std::nothrow) TextItem(id, std::string(text),
2945 std::string(hyperlink));
2947 p = new (std::nothrow) TextItem(id, std::string(text));
2950 LOGE("Out-of-memory");
2951 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2954 *handle = new Handle(shared_ptr<AbstractItem>(p));
2956 return NOTI_EX_ERROR_NONE;
2959 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2960 const char *contents) {
2961 if (handle == nullptr || contents == nullptr) {
2962 LOGE("Invalid parameter");
2963 return NOTI_EX_ERROR_INVALID_PARAMETER;
2966 Handle* p = static_cast<Handle*>(handle);
2967 if (!p->IsValidType(AbstractItem::Text)) {
2968 LOGE("Invalid handle type");
2969 return NOTI_EX_ERROR_INVALID_PARAMETER;
2971 TextItem* ti = static_cast<TextItem*>(p->Get());
2972 ti->SetContents(std::string(contents));
2974 return NOTI_EX_ERROR_NONE;
2977 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2979 if (handle == nullptr || contents == nullptr) {
2980 LOGE("Invalid parameter");
2981 return NOTI_EX_ERROR_INVALID_PARAMETER;
2984 Handle* p = static_cast<Handle*>(handle);
2985 if (!p->IsValidType(AbstractItem::Text)) {
2986 LOGE("Invalid handle type");
2987 return NOTI_EX_ERROR_INVALID_PARAMETER;
2990 TextItem* ti = static_cast<TextItem*>(p->Get());
2992 if (ti->GetMultiLanguage() != nullptr &&
2993 !ti->GetMultiLanguage()->GetTranslatedString().empty())
2994 str = ti->GetMultiLanguage()->GetTranslatedString();
2995 else if (!ti->GetContents().empty())
2996 str = ti->GetContents();
2998 *contents = strdup(str.c_str());
2999 if (*contents == nullptr) {
3000 LOGE("Out-of-memory");
3001 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3004 return NOTI_EX_ERROR_NONE;
3007 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3008 noti_ex_item_h handle, char **hyper_link) {
3009 if (handle == nullptr || hyper_link == nullptr) {
3010 LOGE("Invalid parameter");
3011 return NOTI_EX_ERROR_INVALID_PARAMETER;
3014 Handle* p = static_cast<Handle*>(handle);
3015 if (!p->IsValidType(AbstractItem::Text)) {
3016 LOGE("Invalid handle type");
3017 return NOTI_EX_ERROR_INVALID_PARAMETER;
3019 TextItem* ti = static_cast<TextItem*>(p->Get());
3020 if (!ti->GetHyperLink().empty()) {
3021 *hyper_link = strdup(ti->GetHyperLink().c_str());
3022 if (*hyper_link == nullptr) {
3023 LOGE("Out-of-memory");
3024 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3028 return NOTI_EX_ERROR_NONE;
3031 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3032 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3033 if (handle == nullptr) {
3034 LOGE("Invalid parameter");
3035 return NOTI_EX_ERROR_INVALID_PARAMETER;
3038 Handle* p = static_cast<Handle*>(handle);
3039 if (!p->IsValidType(AbstractItem::Text)) {
3040 LOGE("Invalid handle type");
3041 return NOTI_EX_ERROR_INVALID_PARAMETER;
3044 TextItem* ti = static_cast<TextItem*>(p->Get());
3045 if (multi == nullptr) {
3046 ti->SetMultiLanguage(nullptr);
3047 return NOTI_EX_ERROR_NONE;
3050 shared_ptr<MultiLanguage> mul_ptr =
3051 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3052 ti->SetMultiLanguage(mul_ptr);
3053 ti->GetMultiLanguage()->UpdateString();
3055 return NOTI_EX_ERROR_NONE;
3058 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3059 const char *id, time_t time) {
3062 if (handle == nullptr) {
3063 LOGE("Invalid parameter");
3064 return NOTI_EX_ERROR_INVALID_PARAMETER;
3069 p = new (std::nothrow) TimeItem(id, time);
3071 p = new (std::nothrow) TimeItem(time);
3073 p = new (std::nothrow) TimeItem();
3077 LOGE("Out-of-memory");
3078 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3081 *handle = new Handle(shared_ptr<AbstractItem>(p));
3083 return NOTI_EX_ERROR_NONE;
3086 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3088 if (handle == nullptr || time == nullptr) {
3089 LOGE("Invalid parameter");
3090 return NOTI_EX_ERROR_INVALID_PARAMETER;
3092 Handle* h = static_cast<Handle*>(handle);
3093 if (!h->IsValidType(AbstractItem::Time)) {
3094 LOGE("Invalid handle type");
3095 return NOTI_EX_ERROR_INVALID_PARAMETER;
3097 TimeItem* p = static_cast<TimeItem*>(h->Get());
3098 *time = p->GetTime();
3100 return NOTI_EX_ERROR_NONE;
3103 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3104 noti_ex_action_h *handle, const char *extra) {
3105 if (handle == nullptr) {
3106 LOGE("Invalid parameter");
3107 return NOTI_EX_ERROR_INVALID_PARAMETER;
3110 string extra_str = "";
3112 extra_str = string(extra);
3114 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3115 new (std::nothrow) VisibilityAction(extra_str));
3116 if (ptr == nullptr) {
3117 LOGE("Out-of-memory");
3118 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3123 return NOTI_EX_ERROR_NONE;
3126 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3127 const char *id, bool visible) {
3128 if (handle == nullptr || id == nullptr) {
3129 LOGE("Invalid parameter");
3130 return NOTI_EX_ERROR_INVALID_PARAMETER;
3133 shared_ptr<AbstractAction>* ptr =
3134 static_cast<shared_ptr<AbstractAction>*>(handle);
3135 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3136 action->SetVisibility(id, visible);
3138 return NOTI_EX_ERROR_NONE;
3141 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3142 const char* msgid, const char* format, ...) {
3143 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3144 LOGE("Invalid parameter");
3145 return NOTI_EX_ERROR_INVALID_PARAMETER;
3148 const char* format_idx = format;
3151 va_start(args, format);
3152 while (*format_idx != '\0') {
3153 char* arg = nullptr;
3156 stringstream stream;
3157 if (*format_idx == '%') {
3158 switch (*(format_idx + 1)) {
3160 arg = va_arg(args, char *);
3161 arr.push_back(string(arg));
3164 arg_i = va_arg(args, int);
3165 arr.push_back(to_string(arg_i));
3168 arg_f = va_arg(args, double);
3169 stream << std::fixed << std::setprecision(2) << arg_f;
3170 arr.push_back(stream.str());
3178 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3180 LOGE("Out-of-memory");
3181 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3183 *handle = new shared_ptr<MultiLanguage>(p);
3185 return NOTI_EX_ERROR_NONE;
3188 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3189 if (handle == nullptr) {
3190 LOGE("Invalid parameter");
3191 return NOTI_EX_ERROR_INVALID_PARAMETER;
3194 shared_ptr<MultiLanguage>* mul_ptr =
3195 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3197 return NOTI_EX_ERROR_NONE;