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_get_check_state(
631 noti_ex_item_h handle, bool *checked) {
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_set_check_state(
648 noti_ex_item_h handle, bool checked) {
649 if (handle == nullptr) {
650 LOGE("Invalid parameter");
651 return NOTI_EX_ERROR_INVALID_PARAMETER;
654 Handle* h = static_cast<Handle*>(handle);
655 if (!h->IsValidType(AbstractItem::CheckBox)) {
656 LOGE("Invalid handle type");
657 return NOTI_EX_ERROR_INVALID_PARAMETER;
660 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
661 p->SetChecked(checked);
663 return NOTI_EX_ERROR_NONE;
666 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
670 if (handle == nullptr) {
671 LOGE("Invalid parameter");
672 return NOTI_EX_ERROR_INVALID_PARAMETER;
675 p = new (std::nothrow) EntryItem(id);
677 LOGE("Out-of-memory");
678 return NOTI_EX_ERROR_OUT_OF_MEMORY;
681 *handle = new Handle(shared_ptr<AbstractItem>(p));
683 return NOTI_EX_ERROR_NONE;
686 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
688 if (handle == nullptr || text == nullptr) {
689 LOGE("Invalid parameter");
690 return NOTI_EX_ERROR_INVALID_PARAMETER;
693 Handle* h = static_cast<Handle*>(handle);
694 if (!h->IsValidType(AbstractItem::Entry)) {
695 LOGE("Invalid handle type");
696 return NOTI_EX_ERROR_INVALID_PARAMETER;
699 EntryItem* p = static_cast<EntryItem*>(h->Get());
701 if (p->GetMultiLanguage() != nullptr &&
702 !p->GetMultiLanguage()->GetTranslatedString().empty())
703 str = p->GetMultiLanguage()->GetTranslatedString();
704 else if (!p->GetText().empty())
707 *text = strdup(str.c_str());
708 if (*text == nullptr) {
709 LOGE("Out-of-memory");
710 return NOTI_EX_ERROR_OUT_OF_MEMORY;
713 return NOTI_EX_ERROR_NONE;
716 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
718 if (handle == nullptr || text == nullptr) {
719 LOGE("Invalid parameter");
720 return NOTI_EX_ERROR_INVALID_PARAMETER;
722 Handle* h = static_cast<Handle*>(handle);
723 if (!h->IsValidType(AbstractItem::Entry)) {
724 LOGE("Invalid handle type");
725 return NOTI_EX_ERROR_INVALID_PARAMETER;
727 EntryItem* p = static_cast<EntryItem*>(h->Get());
728 p->SetText(std::string(text));
730 return NOTI_EX_ERROR_NONE;
733 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
734 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
735 if (handle == nullptr) {
736 LOGE("Invalid parameter");
737 return NOTI_EX_ERROR_INVALID_PARAMETER;
740 Handle* p = static_cast<Handle*>(handle);
741 if (!p->IsValidType(AbstractItem::Entry)) {
742 LOGE("Invalid handle type");
743 return NOTI_EX_ERROR_INVALID_PARAMETER;
746 EntryItem* ei = static_cast<EntryItem*>(p->Get());
747 if (multi == nullptr) {
748 ei->SetMultiLanguage(nullptr);
749 return NOTI_EX_ERROR_NONE;
752 shared_ptr<MultiLanguage> mul_ptr =
753 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
754 ei->SetMultiLanguage(mul_ptr);
755 ei->GetMultiLanguage()->UpdateString();
757 return NOTI_EX_ERROR_NONE;
760 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
761 noti_ex_event_info_h* cloned_handle) {
762 if (handle == nullptr || cloned_handle == nullptr) {
763 LOGE("Invalid parameter");
764 return NOTI_EX_ERROR_INVALID_PARAMETER;
767 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
768 EventInfo* info = new EventInfo(cloned);
769 *cloned_handle = info;
770 return NOTI_EX_ERROR_NONE;
773 extern "C" EXPORT_API int noti_ex_event_info_destroy(
774 noti_ex_event_info_h handle) {
775 if (handle == nullptr) {
776 LOGE("Invalid parameter");
777 return NOTI_EX_ERROR_INVALID_PARAMETER;
779 EventInfo* info = static_cast<EventInfo*>(handle);
781 return NOTI_EX_ERROR_NONE;
784 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
785 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
786 if (handle == nullptr || event_type == nullptr) {
787 LOGE("Invalid parameter");
788 return NOTI_EX_ERROR_INVALID_PARAMETER;
790 EventInfo* info = static_cast<EventInfo*>(handle);
791 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
793 return NOTI_EX_ERROR_NONE;
796 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
797 noti_ex_event_info_h handle, char **owner) {
798 if (handle == nullptr || owner == nullptr) {
799 LOGE("Invalid parameter");
800 return NOTI_EX_ERROR_INVALID_PARAMETER;
802 EventInfo* info = static_cast<EventInfo*>(handle);
803 *owner = strdup(info->GetOwner().c_str());
804 return NOTI_EX_ERROR_NONE;
807 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
808 noti_ex_event_info_h handle, char **channel) {
809 if (handle == nullptr || channel == nullptr) {
810 LOGE("Invalid parameter");
811 return NOTI_EX_ERROR_INVALID_PARAMETER;
813 EventInfo* info = static_cast<EventInfo*>(handle);
814 *channel = strdup(info->GetChannel().c_str());
815 return NOTI_EX_ERROR_NONE;
818 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
819 noti_ex_event_info_h handle, char **item_id) {
820 if (handle == nullptr || item_id == nullptr) {
821 LOGE("Invalid parameter");
822 return NOTI_EX_ERROR_INVALID_PARAMETER;
824 EventInfo* info = static_cast<EventInfo*>(handle);
825 *item_id = strdup(info->GetItemId().c_str());
826 return NOTI_EX_ERROR_NONE;
829 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
830 noti_ex_event_info_h handle, int *req_id) {
831 if (handle == nullptr || req_id == nullptr) {
832 LOGE("Invalid parameter");
833 return NOTI_EX_ERROR_INVALID_PARAMETER;
835 EventInfo* info = static_cast<EventInfo*>(handle);
836 *req_id = info->GetRequestId();
837 return NOTI_EX_ERROR_NONE;
840 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
844 if (handle == nullptr) {
845 LOGE("Invalid parameter");
846 return NOTI_EX_ERROR_INVALID_PARAMETER;
850 p = new (std::nothrow) GroupItem(id);
852 p = new (std::nothrow) GroupItem();
855 LOGE("Out-of-memory");
856 return NOTI_EX_ERROR_OUT_OF_MEMORY;
859 *handle = new Handle(shared_ptr<AbstractItem>(p));
861 return NOTI_EX_ERROR_NONE;
864 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
866 if (handle == nullptr) {
867 LOGE("Invalid parameter");
868 return NOTI_EX_ERROR_INVALID_PARAMETER;
870 Handle* h = static_cast<Handle*>(handle);
871 if (!h->IsValidType(AbstractItem::Group)) {
872 LOGE("Invalid handle type");
873 return NOTI_EX_ERROR_INVALID_PARAMETER;
875 GroupItem* p = static_cast<GroupItem*>(h->Get());
876 p->SetDirection(vertical);
878 return NOTI_EX_ERROR_NONE;
881 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(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 *vertical = p->IsVertical();
895 return NOTI_EX_ERROR_NONE;
898 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(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 if (!p->GetAppLabel().empty()) {
911 *label = strdup(p->GetAppLabel().c_str());
912 if (*label == nullptr) {
913 LOGE("Out-of-memory");
914 return NOTI_EX_ERROR_OUT_OF_MEMORY;
918 return NOTI_EX_ERROR_NONE;
921 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
922 noti_ex_item_h child) {
923 if (handle == nullptr || child == nullptr) {
924 LOGE("Invalid parameter");
925 return NOTI_EX_ERROR_INVALID_PARAMETER;
927 Handle* h = static_cast<Handle*>(handle);
928 if (!h->IsValidType(AbstractItem::Group)) {
929 LOGE("Invalid handle type");
930 return NOTI_EX_ERROR_INVALID_PARAMETER;
932 auto p = static_cast<GroupItem*>(h->Get());
933 p->AddChild((static_cast<Handle*>(child))->GetPtr());
935 return NOTI_EX_ERROR_NONE;
938 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
939 const char *item_id) {
940 if (handle == nullptr || item_id == 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 GroupItem* p = static_cast<GroupItem*>(h->Get());
950 p->RemoveChild(std::string(item_id));
952 return NOTI_EX_ERROR_NONE;
955 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
956 noti_ex_item_group_foreach_child_cb callback, void *data) {
957 if (handle == nullptr || callback == nullptr) {
958 LOGE("Invalid parameter");
959 return NOTI_EX_ERROR_INVALID_PARAMETER;
962 Handle* h = static_cast<Handle*>(handle);
963 if (!h->IsValidType(AbstractItem::Group)) {
964 LOGE("Invalid handle type");
965 return NOTI_EX_ERROR_INVALID_PARAMETER;
967 GroupItem* p = static_cast<GroupItem*>(h->Get());
968 list<shared_ptr<AbstractItem>> children = p->GetChildren();
969 LOGI("Retrive (%zd)", children.size());
970 for (auto i : children) {
972 static_cast<noti_ex_item_h>(new Handle(i)), data);
973 if (ret != NOTI_EX_ERROR_NONE) {
974 LOGW("callback return (%d) stop foreach", ret);
979 return NOTI_EX_ERROR_NONE;
982 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
983 const char *id, const char *image_path) {
986 if (handle == nullptr || image_path == nullptr) {
987 LOGE("Invalid parameter");
988 return NOTI_EX_ERROR_INVALID_PARAMETER;
992 p = new (std::nothrow) ImageItem(id, image_path);
994 p = new (std::nothrow) ImageItem(image_path);
997 LOGE("Out-of-memory");
998 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1001 *handle = new Handle(shared_ptr<AbstractItem>(p));
1003 return NOTI_EX_ERROR_NONE;
1006 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1007 noti_ex_item_h handle, char **image_path) {
1008 if (handle == nullptr || image_path == nullptr) {
1009 LOGE("Invalid parameter");
1010 return NOTI_EX_ERROR_INVALID_PARAMETER;
1012 Handle* h = static_cast<Handle*>(handle);
1013 if (!h->IsValidType(AbstractItem::Image)) {
1014 LOGE("Invalid handle type");
1015 return NOTI_EX_ERROR_INVALID_PARAMETER;
1017 ImageItem* p = static_cast<ImageItem*>(h->Get());
1018 if (!p->GetImagePath().empty()) {
1019 *image_path = strdup(p->GetImagePath().c_str());
1020 if (*image_path == nullptr) {
1021 LOGE("Out-of-memory");
1022 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1026 return NOTI_EX_ERROR_NONE;
1029 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1030 noti_ex_item_h *handle, const char *id) {
1031 InputSelectorItem* p;
1033 if (handle == nullptr) {
1034 LOGE("Invalid parameter");
1035 return NOTI_EX_ERROR_INVALID_PARAMETER;
1039 p = new (std::nothrow) InputSelectorItem(id);
1041 p = new (std::nothrow) InputSelectorItem();
1044 LOGE("Out-of-memory");
1045 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1048 *handle = new Handle(shared_ptr<AbstractItem>(p));
1050 return NOTI_EX_ERROR_NONE;
1053 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1054 noti_ex_item_h handle, char ***contents_list, int *count) {
1055 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1056 LOGE("Invalid parameter");
1057 return NOTI_EX_ERROR_INVALID_PARAMETER;
1060 Handle* h = static_cast<Handle*>(handle);
1061 if (!h->IsValidType(AbstractItem::InputSelector)) {
1062 LOGE("Invalid handle type");
1063 return NOTI_EX_ERROR_INVALID_PARAMETER;
1066 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1067 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1068 list<string> contents;
1069 if (arr.size() == 0) {
1070 contents = p->GetContents();
1072 for (auto& i : arr) {
1073 contents.push_back(i->GetTranslatedString());
1077 char **list = (char**)calloc(contents.size(), sizeof(char*));
1078 if (list == nullptr) {
1079 LOGE("Out of memory");
1080 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1084 for (auto& i : contents) {
1085 list[idx] = strdup(i.c_str());
1086 if (list[idx] == nullptr) {
1087 __noti_ex_free_str_array(list, idx);
1088 LOGE("Out of memory");
1089 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1094 *count = contents.size();
1095 *contents_list = list;
1097 return NOTI_EX_ERROR_NONE;
1100 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1101 noti_ex_item_h handle, const char **contents, int count) {
1102 if (handle == nullptr || contents == nullptr) {
1103 LOGE("Invalid parameter");
1104 return NOTI_EX_ERROR_INVALID_PARAMETER;
1107 list<string> new_contents;
1108 Handle* h = static_cast<Handle*>(handle);
1109 if (!h->IsValidType(AbstractItem::InputSelector)) {
1110 LOGE("Invalid handle type");
1111 return NOTI_EX_ERROR_INVALID_PARAMETER;
1113 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1114 for (int i = 0; i < count; i++) {
1115 new_contents.push_back(contents[i]);
1117 p->SetContents(move(new_contents));
1119 return NOTI_EX_ERROR_NONE;
1122 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1123 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1124 if (handle == nullptr) {
1125 LOGE("Invalid parameter");
1126 return NOTI_EX_ERROR_INVALID_PARAMETER;
1129 Handle* p = static_cast<Handle*>(handle);
1130 if (!p->IsValidType(AbstractItem::InputSelector)) {
1131 LOGE("Invalid handle type");
1132 return NOTI_EX_ERROR_INVALID_PARAMETER;
1135 vector<shared_ptr<MultiLanguage>> m_list;
1136 for (int i = 0; i < count; i++) {
1137 shared_ptr<MultiLanguage> mul_ptr =
1138 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1139 mul_ptr->UpdateString();
1140 m_list.push_back(mul_ptr);
1143 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1144 input->SetMultiLanguage(m_list);
1146 return NOTI_EX_ERROR_NONE;
1149 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1150 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1151 if (handle == nullptr) {
1152 LOGE("Invalid parameter");
1153 return NOTI_EX_ERROR_INVALID_PARAMETER;
1156 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1157 new (std::nothrow) Color(a, r, g, b));
1158 if (ptr == nullptr || ptr->get() == nullptr) {
1159 LOGE("Out-of-memory");
1160 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1165 return NOTI_EX_ERROR_NONE;
1168 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1169 if (handle == nullptr) {
1170 LOGE("Invalid parameter");
1171 return NOTI_EX_ERROR_INVALID_PARAMETER;
1174 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1177 return NOTI_EX_ERROR_NONE;
1180 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1181 unsigned char *val) {
1182 if (handle == nullptr || val == nullptr) {
1183 LOGE("Invalid parameter");
1184 return NOTI_EX_ERROR_INVALID_PARAMETER;
1187 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1188 *val = (*p)->GetAVal();
1190 return NOTI_EX_ERROR_NONE;
1193 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1194 unsigned char *val) {
1195 if (handle == nullptr || val == nullptr) {
1196 LOGE("Invalid parameter");
1197 return NOTI_EX_ERROR_INVALID_PARAMETER;
1200 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1201 *val = (*p)->GetRVal();
1203 return NOTI_EX_ERROR_NONE;
1206 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1207 unsigned char *val) {
1208 if (handle == nullptr || val == nullptr) {
1209 LOGE("Invalid parameter");
1210 return NOTI_EX_ERROR_INVALID_PARAMETER;
1213 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1214 *val = (*p)->GetGVal();
1216 return NOTI_EX_ERROR_NONE;
1219 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1220 unsigned char *val) {
1221 if (handle == nullptr || val == nullptr) {
1222 LOGE("Invalid parameter");
1223 return NOTI_EX_ERROR_INVALID_PARAMETER;
1226 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1227 *val = (*p)->GetBVal();
1229 return NOTI_EX_ERROR_NONE;
1232 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1233 int left, int top, int right, int bottom) {
1234 if (handle == nullptr) {
1235 LOGE("Invalid parameter");
1236 return NOTI_EX_ERROR_INVALID_PARAMETER;
1239 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1240 new (std::nothrow) Padding(left, top, right, bottom));
1241 if (ptr == nullptr || ptr->get() == nullptr) {
1242 LOGE("Out-of-memory");
1243 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1248 return NOTI_EX_ERROR_NONE;
1251 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1252 if (handle == nullptr) {
1253 LOGE("Invalid parameter");
1254 return NOTI_EX_ERROR_INVALID_PARAMETER;
1257 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1260 return NOTI_EX_ERROR_NONE;
1263 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1265 if (handle == nullptr || val == nullptr) {
1266 LOGE("Invalid parameter");
1267 return NOTI_EX_ERROR_INVALID_PARAMETER;
1270 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1271 *val = (*p)->GetLeft();
1273 return NOTI_EX_ERROR_NONE;
1276 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1278 if (handle == nullptr || val == nullptr) {
1279 LOGE("Invalid parameter");
1280 return NOTI_EX_ERROR_INVALID_PARAMETER;
1283 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1284 *val = (*p)->GetTop();
1286 return NOTI_EX_ERROR_NONE;
1289 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1291 if (handle == nullptr || val == nullptr) {
1292 LOGE("Invalid parameter");
1293 return NOTI_EX_ERROR_INVALID_PARAMETER;
1296 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1297 *val = (*p)->GetRight();
1299 return NOTI_EX_ERROR_NONE;
1302 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1304 if (handle == nullptr || val == nullptr) {
1305 LOGE("Invalid parameter");
1306 return NOTI_EX_ERROR_INVALID_PARAMETER;
1309 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1310 *val = (*p)->GetBottom();
1312 return NOTI_EX_ERROR_NONE;
1315 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1316 int x, int y, int w, int h) {
1317 if (handle == nullptr) {
1318 LOGE("Invalid parameter");
1319 return NOTI_EX_ERROR_INVALID_PARAMETER;
1322 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1323 new (std::nothrow) Geometry(x, y, w, h));
1324 if (ptr == nullptr || ptr->get() == nullptr) {
1325 LOGE("Out-of-memory");
1326 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1331 return NOTI_EX_ERROR_NONE;
1334 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1335 if (handle == nullptr) {
1336 LOGE("Invalid parameter");
1337 return NOTI_EX_ERROR_INVALID_PARAMETER;
1340 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1343 return NOTI_EX_ERROR_NONE;
1346 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1348 if (handle == nullptr || val == nullptr) {
1349 LOGE("Invalid parameter");
1350 return NOTI_EX_ERROR_INVALID_PARAMETER;
1353 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1354 *val = (*p)->GetX();
1356 return NOTI_EX_ERROR_NONE;
1359 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1361 if (handle == nullptr || val == nullptr) {
1362 LOGE("Invalid parameter");
1363 return NOTI_EX_ERROR_INVALID_PARAMETER;
1366 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1367 *val = (*p)->GetY();
1369 return NOTI_EX_ERROR_NONE;
1372 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1374 if (handle == nullptr || val == nullptr) {
1375 LOGE("Invalid parameter");
1376 return NOTI_EX_ERROR_INVALID_PARAMETER;
1379 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1380 *val = (*p)->GetWidth();
1382 return NOTI_EX_ERROR_NONE;
1385 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1387 if (handle == nullptr || val == nullptr) {
1388 LOGE("Invalid parameter");
1389 return NOTI_EX_ERROR_INVALID_PARAMETER;
1392 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1393 *val = (*p)->GetHeight();
1395 return NOTI_EX_ERROR_NONE;
1398 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1399 noti_ex_color_h color,
1400 noti_ex_padding_h padding,
1401 noti_ex_geometry_h geometry) {
1402 if (handle == nullptr) {
1403 LOGE("Invalid parameter");
1404 return NOTI_EX_ERROR_INVALID_PARAMETER;
1407 shared_ptr<Color> col = (color == nullptr) ?
1408 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1409 shared_ptr<Padding> padd = (padding == nullptr) ?
1410 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1411 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1412 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1414 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1415 new (std::nothrow) Style(col, padd, geo));
1416 if (ptr == nullptr || ptr->get() == nullptr) {
1417 LOGE("Out-of-memory");
1418 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1423 return NOTI_EX_ERROR_NONE;
1426 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1427 if (handle == nullptr) {
1428 LOGE("Invalid parameter");
1429 return NOTI_EX_ERROR_INVALID_PARAMETER;
1432 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1435 return NOTI_EX_ERROR_NONE;
1438 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1439 noti_ex_padding_h *padding) {
1440 if (handle == nullptr || padding == nullptr) {
1441 LOGE("Invalid parameter");
1442 return NOTI_EX_ERROR_INVALID_PARAMETER;
1445 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1446 if ((*p)->GetPadding() == nullptr) {
1447 LOGW("Padding info is null");
1448 return NOTI_EX_ERROR_INVALID_PARAMETER;
1451 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1452 new (std::nothrow) Padding(*((*p)->GetPadding())));
1453 if (padd == nullptr || padd->get() == nullptr) {
1454 LOGE("Out-of-memory");
1455 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1460 return NOTI_EX_ERROR_NONE;
1463 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1464 noti_ex_color_h *color) {
1465 if (handle == nullptr || color == nullptr) {
1466 LOGE("Invalid parameter");
1467 return NOTI_EX_ERROR_INVALID_PARAMETER;
1470 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1471 if ((*p)->GetColor() == nullptr) {
1472 LOGW("Color info is null");
1473 return NOTI_EX_ERROR_INVALID_PARAMETER;
1476 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1477 new (std::nothrow) Color(*((*p)->GetColor())));
1478 if (col == nullptr || col->get() == nullptr) {
1479 LOGE("Out-of-memory");
1480 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1485 return NOTI_EX_ERROR_NONE;
1488 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1489 noti_ex_geometry_h *geometry) {
1490 if (handle == nullptr || geometry == nullptr) {
1491 LOGE("Invalid parameter");
1492 return NOTI_EX_ERROR_INVALID_PARAMETER;
1495 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1496 if ((*p)->GetGeometry() == nullptr) {
1497 LOGW("Geometry info is null");
1498 return NOTI_EX_ERROR_INVALID_PARAMETER;
1501 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1502 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1503 if (geo == nullptr || geo->get() == nullptr) {
1504 LOGE("Out-of-memory");
1505 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1510 return NOTI_EX_ERROR_NONE;
1513 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1514 noti_ex_style_h handle, char** background_image) {
1515 if (handle == nullptr || background_image == nullptr) {
1516 LOGE("Invalid parameter");
1517 return NOTI_EX_ERROR_INVALID_PARAMETER;
1520 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1521 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1523 return NOTI_EX_ERROR_NONE;
1526 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1527 noti_ex_style_h handle, char* background_image) {
1528 if (handle == nullptr || background_image == nullptr) {
1529 LOGE("Invalid parameter");
1530 return NOTI_EX_ERROR_INVALID_PARAMETER;
1533 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1534 (*p)->SetBackgroundImage(background_image);
1536 return NOTI_EX_ERROR_NONE;
1539 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1540 noti_ex_style_h handle, noti_ex_color_h* color) {
1541 if (handle == nullptr || color == nullptr) {
1542 LOGE("Invalid parameter");
1543 return NOTI_EX_ERROR_INVALID_PARAMETER;
1546 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1547 if ((*p)->GetBackgroundColor() == nullptr) {
1548 LOGW("Color info is null");
1549 return NOTI_EX_ERROR_INVALID_PARAMETER;
1552 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1553 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1554 if (col == nullptr || col->get() == nullptr) {
1555 LOGE("Out-of-memory");
1556 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1561 return NOTI_EX_ERROR_NONE;
1564 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1565 noti_ex_style_h handle, noti_ex_color_h color) {
1566 if (handle == nullptr || color == nullptr) {
1567 LOGE("Invalid parameter");
1568 return NOTI_EX_ERROR_INVALID_PARAMETER;
1571 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1572 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1573 (*p)->SetBackgroundColor(*col);
1575 return NOTI_EX_ERROR_NONE;
1578 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1579 noti_ex_color_h color) {
1580 if (handle == nullptr) {
1581 LOGE("Invalid parameter");
1582 return NOTI_EX_ERROR_INVALID_PARAMETER;
1585 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1586 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1587 new (std::nothrow) LEDInfo(*color_ptr));
1589 LOGE("Out-of-memory");
1590 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1595 return NOTI_EX_ERROR_NONE;
1598 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1599 if (handle == nullptr) {
1600 LOGE("Invalid parameter");
1601 return NOTI_EX_ERROR_INVALID_PARAMETER;
1604 shared_ptr<LEDInfo>* led_ptr =
1605 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1607 return NOTI_EX_ERROR_NONE;
1610 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1611 noti_ex_led_info_h handle, int ms) {
1612 if (handle == nullptr) {
1613 LOGE("Invalid parameter");
1614 return NOTI_EX_ERROR_INVALID_PARAMETER;
1617 shared_ptr<LEDInfo>* led_ptr =
1618 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1619 (*led_ptr)->SetOnPeriod(ms);
1621 return NOTI_EX_ERROR_NONE;
1624 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1625 noti_ex_led_info_h handle, int *ms) {
1626 if (handle == nullptr || ms == nullptr) {
1627 LOGE("Invalid parameter");
1628 return NOTI_EX_ERROR_INVALID_PARAMETER;
1631 shared_ptr<LEDInfo>* led_ptr =
1632 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1633 *ms = (*led_ptr)->GetOnPeriod();
1635 return NOTI_EX_ERROR_NONE;
1638 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1639 noti_ex_led_info_h handle, int ms) {
1640 if (handle == nullptr) {
1641 LOGE("Invalid parameter");
1642 return NOTI_EX_ERROR_INVALID_PARAMETER;
1645 shared_ptr<LEDInfo>* led_ptr =
1646 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1647 (*led_ptr)->SetOffPeriod(ms);
1649 return NOTI_EX_ERROR_NONE;
1652 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1653 noti_ex_led_info_h handle, int *ms) {
1654 if (handle == nullptr) {
1655 LOGE("Invalid parameter");
1656 return NOTI_EX_ERROR_INVALID_PARAMETER;
1659 shared_ptr<LEDInfo>* led_ptr =
1660 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1661 *ms = (*led_ptr)->GetOffPeriod();
1663 return NOTI_EX_ERROR_NONE;
1666 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1667 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1668 if (handle == nullptr) {
1669 LOGE("Invalid parameter");
1670 return NOTI_EX_ERROR_INVALID_PARAMETER;
1673 shared_ptr<LEDInfo>* led_ptr =
1674 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1675 if ((*led_ptr)->GetColor() == nullptr) {
1676 LOGE("Color is null");
1677 return NOTI_EX_ERROR_INVALID_PARAMETER;
1680 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1681 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1682 if (col == nullptr || col->get() == nullptr) {
1683 LOGE("Out-of-memory");
1684 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1689 return NOTI_EX_ERROR_NONE;
1692 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1693 if (handle == nullptr) {
1694 LOGE("Invalid parameter");
1695 return NOTI_EX_ERROR_INVALID_PARAMETER;
1698 shared_ptr<AbstractAction>* ptr =
1699 static_cast<shared_ptr<AbstractAction>*>(handle);
1702 return NOTI_EX_ERROR_NONE;
1705 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1707 if (handle == nullptr || type == nullptr) {
1708 LOGE("Invalid parameter");
1709 return NOTI_EX_ERROR_INVALID_PARAMETER;
1712 shared_ptr<AbstractAction>* ptr =
1713 static_cast<shared_ptr<AbstractAction>*>(handle);
1714 *type = (*ptr)->GetType();
1716 return NOTI_EX_ERROR_NONE;
1719 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1721 if (handle == nullptr || local == nullptr) {
1722 LOGE("Invalid parameter");
1723 return NOTI_EX_ERROR_INVALID_PARAMETER;
1726 shared_ptr<AbstractAction>* ptr =
1727 static_cast<shared_ptr<AbstractAction>*>(handle);
1728 *local = (*ptr)->IsLocal();
1730 return NOTI_EX_ERROR_NONE;
1733 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1734 noti_ex_item_h item) {
1735 if (handle == nullptr || item == nullptr) {
1736 LOGE("Invalid parameter");
1737 return NOTI_EX_ERROR_INVALID_PARAMETER;
1739 shared_ptr<AbstractAction>* ptr =
1740 static_cast<shared_ptr<AbstractAction>*>(handle);
1741 Handle* ih = static_cast<Handle*>(item);
1742 (*ptr)->Execute(ih->GetPtr());
1744 return NOTI_EX_ERROR_NONE;
1747 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1749 if (handle == nullptr || extra == nullptr) {
1750 LOGE("Invalid parameter");
1751 return NOTI_EX_ERROR_INVALID_PARAMETER;
1754 shared_ptr<AbstractAction>* ptr =
1755 static_cast<shared_ptr<AbstractAction>*>(handle);
1756 if (!(*ptr)->GetExtra().empty()) {
1757 *extra = strdup((*ptr)->GetExtra().c_str());
1758 if (*extra == nullptr) {
1759 LOGE("Out-of-memory");
1760 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1764 return NOTI_EX_ERROR_NONE;
1767 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1768 noti_ex_item_info_h handle, int *hide_time) {
1769 if (handle == nullptr || hide_time == nullptr) {
1770 LOGE("Invalid parameter");
1771 return NOTI_EX_ERROR_INVALID_PARAMETER;
1773 IItemInfo* p = static_cast<IItemInfo*>(handle);
1774 *hide_time = p->GetHideTime();
1775 return NOTI_EX_ERROR_NONE;
1778 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1779 noti_ex_item_info_h handle, int hide_time) {
1780 if (handle == nullptr) {
1781 LOGE("Invalid parameter");
1782 return NOTI_EX_ERROR_INVALID_PARAMETER;
1784 IItemInfo* p = static_cast<IItemInfo*>(handle);
1785 p->SetHideTime(hide_time);
1786 return NOTI_EX_ERROR_NONE;
1789 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1790 noti_ex_item_info_h handle, int *delete_time) {
1791 if (handle == nullptr || delete_time == nullptr) {
1792 LOGE("Invalid parameter");
1793 return NOTI_EX_ERROR_INVALID_PARAMETER;
1795 IItemInfo* p = static_cast<IItemInfo*>(handle);
1796 *delete_time = p->GetDeleteTime();
1797 return NOTI_EX_ERROR_NONE;
1800 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1801 noti_ex_item_info_h handle, int delete_time) {
1802 if (handle == nullptr) {
1803 LOGE("Invalid parameter");
1804 return NOTI_EX_ERROR_INVALID_PARAMETER;
1806 IItemInfo* p = static_cast<IItemInfo*>(handle);
1807 p->SetDeleteTime(delete_time);
1808 return NOTI_EX_ERROR_NONE;
1811 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1812 noti_ex_item_info_h handle, time_t *time) {
1813 if (handle == nullptr || time == nullptr) {
1814 LOGE("Invalid parameter");
1815 return NOTI_EX_ERROR_INVALID_PARAMETER;
1818 IItemInfo* p = static_cast<IItemInfo*>(handle);
1819 *time = p->GetTime();
1820 return NOTI_EX_ERROR_NONE;
1823 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1824 if (handle == nullptr) {
1825 LOGE("Invalid parameter");
1826 return NOTI_EX_ERROR_INVALID_PARAMETER;
1829 Handle* h = static_cast<Handle*>(handle);
1831 return NOTI_EX_ERROR_NONE;
1834 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1835 const char *id, noti_ex_item_h *item) {
1836 if (handle == nullptr) {
1837 LOGE("Invalid parameter");
1838 return NOTI_EX_ERROR_INVALID_PARAMETER;
1841 Handle* p = static_cast<Handle*>(handle);
1842 AbstractItem& find_item = p->Get()->FindByID(string(id));
1843 *item = new Handle(&find_item);
1844 return NOTI_EX_ERROR_NONE;
1847 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1849 if (handle == nullptr || type == nullptr) {
1850 LOGE("Invalid parameter");
1851 return NOTI_EX_ERROR_INVALID_PARAMETER;
1854 Handle* h = static_cast<Handle*>(handle);
1855 AbstractItem* p = h->Get();
1856 *type = p->GetType();
1857 return NOTI_EX_ERROR_NONE;
1860 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1861 char ***path, int *count) {
1862 if (handle == nullptr || path == nullptr || count == nullptr) {
1863 LOGE("Invalid parameter");
1864 return NOTI_EX_ERROR_INVALID_PARAMETER;
1866 Handle* p = static_cast<Handle*>(handle);
1867 list<string> shared_path = p->Get()->GetSharedPath();
1868 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1869 if (tmp_path == nullptr) {
1870 LOGE("Fail to create items");
1871 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1875 for (auto& i : shared_path) {
1876 tmp_path[idx] = strdup(i.c_str());
1877 if (tmp_path[idx] == nullptr) {
1878 __noti_ex_free_str_array(tmp_path, idx);
1879 LOGE("Out of memory");
1880 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1886 *count = shared_path.size();
1887 return NOTI_EX_ERROR_NONE;
1890 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1892 if (handle == nullptr || id == nullptr) {
1893 LOGE("Invalid parameter");
1894 return NOTI_EX_ERROR_INVALID_PARAMETER;
1896 Handle* h = static_cast<Handle*>(handle);
1897 AbstractItem* p = h->Get();
1898 *id = strdup(p->GetId().c_str());
1899 return NOTI_EX_ERROR_NONE;
1902 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1904 if (handle == nullptr || id == nullptr) {
1905 LOGE("Invalid parameter");
1906 return NOTI_EX_ERROR_INVALID_PARAMETER;
1908 Handle* p = static_cast<Handle*>(handle);
1909 p->Get()->SetId(id);
1910 return NOTI_EX_ERROR_NONE;
1913 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1914 noti_ex_action_h *action) {
1915 if (handle == nullptr || action == nullptr) {
1916 LOGE("Invalid parameter");
1917 return NOTI_EX_ERROR_INVALID_PARAMETER;
1919 Handle* p = static_cast<Handle*>(handle);
1920 if (p->Get()->GetAction() == nullptr) {
1922 return NOTI_EX_ERROR_NONE;
1924 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1925 p->Get()->GetAction()));
1927 return NOTI_EX_ERROR_NONE;
1930 extern "C" EXPORT_API int noti_ex_item_set_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;
1937 Handle* p = static_cast<Handle*>(handle);
1939 shared_ptr<AbstractAction>* ptr =
1940 static_cast<shared_ptr<AbstractAction>*>(action);
1941 p->Get()->SetAction(*ptr);
1942 return NOTI_EX_ERROR_NONE;
1945 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1946 noti_ex_style_h *style) {
1947 if (handle == nullptr || style == nullptr) {
1948 LOGE("Invalid parameter");
1949 return NOTI_EX_ERROR_INVALID_PARAMETER;
1952 Handle* p = static_cast<Handle*>(handle);
1953 shared_ptr<Style> s = p->Get()->GetStyle();
1954 if (s.get() == nullptr) {
1955 LOGE("Style is null");
1956 return NOTI_EX_ERROR_INVALID_PARAMETER;
1959 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1960 if (ptr == nullptr || ptr->get() == nullptr) {
1961 LOGE("Out of memory");
1962 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1970 noti_ex_style_h style) {
1971 if (handle == nullptr || style == nullptr) {
1972 LOGE("Invalid parameter");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1976 Handle* p = static_cast<Handle*>(handle);
1977 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1978 p->Get()->SetStyle(*s);
1979 return NOTI_EX_ERROR_NONE;
1982 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1984 if (handle == nullptr) {
1985 LOGE("Invalid parameter");
1986 return NOTI_EX_ERROR_INVALID_PARAMETER;
1989 Handle* p = static_cast<Handle*>(handle);
1990 p->Get()->SetVisible(visible);
1991 return NOTI_EX_ERROR_NONE;
1994 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1996 if (handle == nullptr || visible == nullptr) {
1997 LOGE("Invalid parameter");
1998 return NOTI_EX_ERROR_INVALID_PARAMETER;
2001 Handle* p = static_cast<Handle*>(handle);
2002 *visible = p->Get()->GetVisible();
2003 return NOTI_EX_ERROR_NONE;
2006 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2008 if (handle == nullptr) {
2009 LOGE("Invalid parameter");
2010 return NOTI_EX_ERROR_INVALID_PARAMETER;
2013 Handle* p = static_cast<Handle*>(handle);
2014 p->Get()->SetEnable(enable);
2015 return NOTI_EX_ERROR_NONE;
2018 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2020 if (handle == nullptr || enable == nullptr) {
2021 LOGE("Invalid parameter");
2022 return NOTI_EX_ERROR_INVALID_PARAMETER;
2025 Handle* p = static_cast<Handle*>(handle);
2026 *enable = p->Get()->GetEnable();
2027 return NOTI_EX_ERROR_NONE;
2030 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2031 const char *receiver_group) {
2032 if (handle == nullptr || receiver_group == nullptr) {
2033 LOGE("Invalid parameter");
2034 return NOTI_EX_ERROR_INVALID_PARAMETER;
2037 Handle* p = static_cast<Handle*>(handle);
2038 p->Get()->AddReceiver(receiver_group);
2039 return NOTI_EX_ERROR_NONE;
2042 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2043 const char *receiver_group) {
2044 if (handle == nullptr || receiver_group == nullptr) {
2045 LOGE("Invalid parameter");
2046 return NOTI_EX_ERROR_INVALID_PARAMETER;
2049 Handle* p = static_cast<Handle*>(handle);
2050 p->Get()->RemoveReceiver(receiver_group);
2051 return NOTI_EX_ERROR_NONE;
2054 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2055 char ***receiver_list, int *count) {
2056 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2057 LOGE("Invalid parameter");
2058 return NOTI_EX_ERROR_INVALID_PARAMETER;
2061 Handle* p = static_cast<Handle*>(handle);
2062 list<string> receivers = p->Get()->GetReceiverList();
2063 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2064 if (tmp_list == nullptr) {
2065 LOGE("Out of memory");
2066 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2070 for (auto& i : receivers) {
2071 tmp_list[idx] = strdup(i.c_str());
2072 if (tmp_list[idx] == nullptr) {
2073 __noti_ex_free_str_array(tmp_list, idx);
2074 LOGE("Out of memory");
2075 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2080 *receiver_list = tmp_list;
2081 *count = receivers.size();
2082 return NOTI_EX_ERROR_NONE;
2085 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2087 if (handle == nullptr) {
2088 LOGE("Invalid parameter");
2089 return NOTI_EX_ERROR_INVALID_PARAMETER;
2092 Handle* p = static_cast<Handle*>(handle);
2093 p->Get()->SetPolicy(policy);
2094 return NOTI_EX_ERROR_NONE;
2097 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2099 if (handle == nullptr || policy == nullptr) {
2100 LOGE("Invalid parameter");
2101 return NOTI_EX_ERROR_INVALID_PARAMETER;
2104 Handle* p = static_cast<Handle*>(handle);
2105 *policy = p->Get()->GetPolicy();
2106 return NOTI_EX_ERROR_NONE;
2109 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2111 if (handle == nullptr || channel == nullptr) {
2112 LOGE("Invalid parameter");
2113 return NOTI_EX_ERROR_INVALID_PARAMETER;
2116 Handle* p = static_cast<Handle*>(handle);
2117 if (!p->Get()->GetChannel().empty())
2118 *channel = strdup(p->Get()->GetChannel().c_str());
2122 return NOTI_EX_ERROR_NONE;
2125 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2126 const char *channel) {
2127 if (handle == nullptr) {
2128 LOGE("Invalid parameter");
2129 return NOTI_EX_ERROR_INVALID_PARAMETER;
2132 Handle* p = static_cast<Handle*>(handle);
2133 p->Get()->SetChannel(channel);
2134 return NOTI_EX_ERROR_NONE;
2137 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2138 noti_ex_led_info_h led) {
2139 if (handle == nullptr) {
2140 LOGE("Invalid parameter");
2141 return NOTI_EX_ERROR_INVALID_PARAMETER;
2144 Handle* p = static_cast<Handle*>(handle);
2145 shared_ptr<LEDInfo>* led_ptr =
2146 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2147 p->Get()->SetLEDInfo(*led_ptr);
2148 return NOTI_EX_ERROR_NONE;
2151 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2152 noti_ex_led_info_h *led) {
2153 if (handle == nullptr) {
2154 LOGE("Invalid parameter");
2155 return NOTI_EX_ERROR_INVALID_PARAMETER;
2158 Handle* p = static_cast<Handle*>(handle);
2159 if (p->Get()->GetLEDInfo() != nullptr)
2160 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2163 return NOTI_EX_ERROR_NONE;
2166 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2168 if (handle == nullptr) {
2169 LOGE("Invalid parameter");
2170 return NOTI_EX_ERROR_INVALID_PARAMETER;
2173 Handle* p = static_cast<Handle*>(handle);
2174 if (path == nullptr)
2175 p->Get()->SetSoundPath("");
2177 p->Get()->SetSoundPath(path);
2178 return NOTI_EX_ERROR_NONE;
2181 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2183 if (handle == nullptr) {
2184 LOGE("Invalid parameter");
2185 return NOTI_EX_ERROR_INVALID_PARAMETER;
2188 Handle* p = static_cast<Handle*>(handle);
2189 if (path == nullptr)
2190 p->Get()->SetVibrationPath("");
2192 p->Get()->SetVibrationPath(path);
2193 return NOTI_EX_ERROR_NONE;
2196 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2198 if (handle == nullptr || path == nullptr) {
2199 LOGE("Invalid parameter");
2200 return NOTI_EX_ERROR_INVALID_PARAMETER;
2203 Handle* p = static_cast<Handle*>(handle);
2204 if (p->Get()->GetSoundPath().empty())
2207 *path = strdup(p->Get()->GetSoundPath().c_str());
2208 return NOTI_EX_ERROR_NONE;
2211 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2213 if (handle == nullptr || path == nullptr) {
2214 LOGE("Invalid parameter");
2215 return NOTI_EX_ERROR_INVALID_PARAMETER;
2218 Handle* p = static_cast<Handle*>(handle);
2219 if (p->Get()->GetVibrationPath().empty())
2222 *path = strdup(p->Get()->GetVibrationPath().c_str());
2223 return NOTI_EX_ERROR_NONE;
2226 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2227 noti_ex_item_info_h *info) {
2228 if (handle == nullptr || info == nullptr) {
2229 LOGE("Invalid parameter");
2230 return NOTI_EX_ERROR_INVALID_PARAMETER;
2233 Handle* p = static_cast<Handle*>(handle);
2234 if (p->Get()->GetInfo() == nullptr)
2237 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2238 return NOTI_EX_ERROR_NONE;
2241 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2243 if (handle == nullptr || id == nullptr) {
2244 LOGE("Invalid parameter");
2245 return NOTI_EX_ERROR_INVALID_PARAMETER;
2248 Handle* p = static_cast<Handle*>(handle);
2249 if (p->Get()->GetSenderAppId().empty())
2252 *id = strdup(p->Get()->GetSenderAppId().c_str());
2253 return NOTI_EX_ERROR_NONE;
2256 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2258 if (handle == nullptr || tag == nullptr) {
2259 LOGE("Invalid parameter");
2260 return NOTI_EX_ERROR_INVALID_PARAMETER;
2263 Handle* p = static_cast<Handle*>(handle);
2264 if (p->Get()->GetTag().empty())
2267 *tag = strdup(p->Get()->GetTag().c_str());
2268 return NOTI_EX_ERROR_NONE;
2271 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2273 if (handle == nullptr) {
2274 LOGE("Invalid parameter");
2275 return NOTI_EX_ERROR_INVALID_PARAMETER;
2278 Handle* p = static_cast<Handle*>(handle);
2280 p->Get()->SetTag("");
2282 p->Get()->SetTag(tag);
2283 return NOTI_EX_ERROR_NONE;
2286 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2288 if (handle == nullptr || ongoing == nullptr) {
2289 LOGE("Invalid parameter");
2290 return NOTI_EX_ERROR_INVALID_PARAMETER;
2293 Handle* p = static_cast<Handle*>(handle);
2294 *ongoing = p->Get()->GetOnGoingState();
2296 return NOTI_EX_ERROR_NONE;
2299 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2301 if (handle == nullptr) {
2302 LOGE("Invalid parameter");
2303 return NOTI_EX_ERROR_INVALID_PARAMETER;
2306 Handle* p = static_cast<Handle*>(handle);
2307 p->Get()->SetOnGoingState(ongoing);
2309 return NOTI_EX_ERROR_NONE;
2312 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2313 int type, bool* exist) {
2314 if (handle == nullptr || exist == nullptr) {
2315 LOGE("Invalid parameter");
2316 return NOTI_EX_ERROR_INVALID_PARAMETER;
2319 Handle* p = static_cast<Handle*>(handle);
2320 *exist = p->Get()->IsItemTypeExist(type);
2322 return NOTI_EX_ERROR_NONE;
2325 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2327 if (handle == nullptr || type == nullptr) {
2328 LOGE("Invalid parameter");
2329 return NOTI_EX_ERROR_INVALID_PARAMETER;
2332 Handle* p = static_cast<Handle*>(handle);
2333 *type = p->Get()->GetMainType();
2335 return NOTI_EX_ERROR_NONE;
2338 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2339 const char* id, int type) {
2340 if (handle == nullptr || id == nullptr) {
2341 LOGE("Invalid parameter");
2342 return NOTI_EX_ERROR_INVALID_PARAMETER;
2345 Handle* p = static_cast<Handle*>(handle);
2346 if (!(p->Get()->SetMainType(string(id),
2347 static_cast<AbstractItem::MainType>(type))))
2348 return NOTI_EX_ERROR_INVALID_PARAMETER;
2350 return NOTI_EX_ERROR_NONE;
2353 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2354 int type, noti_ex_item_h* item) {
2355 if (handle == nullptr || item == nullptr) {
2356 LOGE("Invalid parameter");
2357 return NOTI_EX_ERROR_INVALID_PARAMETER;
2360 Handle* h = static_cast<Handle*>(handle);
2361 if (!h->IsValidType(AbstractItem::Group)) {
2362 LOGE("Invalid handle type");
2363 return NOTI_EX_ERROR_INVALID_PARAMETER;
2366 GroupItem* p = static_cast<GroupItem*>(h->Get());
2367 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2368 *item = new Handle(&find_item);
2370 return NOTI_EX_ERROR_NONE;
2373 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2374 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2376 if (handle == nullptr) {
2377 LOGE("Invalid parameter");
2378 return NOTI_EX_ERROR_INVALID_PARAMETER;
2381 string receiver_group_str = "";
2383 receiver_group_str = string(receiver_group);
2385 ManagerStub* stub = new (std::nothrow) ManagerStub(
2386 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2387 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2388 receiver_group_str);
2389 if (stub == nullptr) {
2390 LOGE("Fail to create manager");
2391 return NOTI_EX_ERROR_IO_ERROR;
2393 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2394 new ManagerCallbackInfo(event_callbacks, data)));
2395 *handle = static_cast<noti_ex_manager_h>(stub);
2397 return NOTI_EX_ERROR_NONE;
2400 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2401 if (handle == nullptr) {
2402 LOGE("Invalid parameter");
2403 return NOTI_EX_ERROR_INVALID_PARAMETER;
2405 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2407 return NOTI_EX_ERROR_NONE;
2410 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2411 noti_ex_item_h **items, int *count) {
2412 if (handle == nullptr || items == nullptr || count == nullptr) {
2413 LOGE("Invalid parameter");
2414 return NOTI_EX_ERROR_INVALID_PARAMETER;
2418 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2419 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2420 if (item_list.size() == 0) {
2423 return NOTI_EX_ERROR_NONE;
2425 noti_ex_item_h* added_item =
2426 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2427 if (added_item == nullptr) {
2428 LOGE("Fail to create items");
2429 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2433 for (auto& i : item_list) {
2434 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2436 *items = added_item;
2437 *count = item_list.size();
2438 } catch (Exception &ex) {
2439 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2440 return NOTI_EX_ERROR_IO_ERROR;
2442 return NOTI_EX_ERROR_NONE;
2445 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2446 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2447 if (handle == nullptr || channel == nullptr ||
2448 items == nullptr || count == nullptr) {
2449 LOGE("Invalid parameter");
2450 return NOTI_EX_ERROR_INVALID_PARAMETER;
2454 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2455 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2456 if (item_list.size() == 0) {
2459 return NOTI_EX_ERROR_NONE;
2461 noti_ex_item_h* added_item =
2462 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2463 if (added_item == nullptr) {
2464 LOGE("Fail to create items");
2465 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2469 for (auto& i : item_list) {
2470 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2472 *items = added_item;
2473 *count = item_list.size();
2474 } catch (Exception &ex) {
2475 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2476 return NOTI_EX_ERROR_IO_ERROR;
2479 return NOTI_EX_ERROR_NONE;
2482 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2483 noti_ex_item_h noti, int *request_id) {
2484 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2485 LOGE("Invalid parameter");
2486 return NOTI_EX_ERROR_INVALID_PARAMETER;
2489 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2490 Handle* sp = static_cast<Handle*>(noti);
2491 if (sp->GetPtr().get() == nullptr) {
2492 LOGE("Invalid noti reference can not be sended");
2493 return NOTI_EX_ERROR_INVALID_PARAMETER;
2495 *request_id = stub->Update(sp->GetPtr());
2497 } catch (Exception &ex) {
2498 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2499 return NOTI_EX_ERROR_IO_ERROR;
2501 return NOTI_EX_ERROR_NONE;
2504 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2505 noti_ex_item_h noti, int *request_id) {
2506 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2507 LOGE("Invalid parameter");
2508 return NOTI_EX_ERROR_INVALID_PARAMETER;
2511 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2512 Handle* item = static_cast<Handle*>(noti);
2513 if (item->GetPtr().get() == nullptr) {
2514 LOGE("Invalid noti reference can not be sended");
2515 return NOTI_EX_ERROR_INVALID_PARAMETER;
2517 *request_id = stub->Delete(item->GetPtr());
2519 } catch (Exception &ex) {
2520 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2521 return NOTI_EX_ERROR_IO_ERROR;
2523 return NOTI_EX_ERROR_NONE;
2526 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2528 if (handle == nullptr || request_id == nullptr) {
2529 LOGE("Invalid parameter");
2530 return NOTI_EX_ERROR_INVALID_PARAMETER;
2533 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2534 *request_id = stub->DeleteAll();
2535 } catch (Exception &ex) {
2536 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2537 return NOTI_EX_ERROR_IO_ERROR;
2539 return NOTI_EX_ERROR_NONE;
2542 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2543 noti_ex_item_h noti, int *request_id) {
2544 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2545 LOGE("Invalid parameter");
2546 return NOTI_EX_ERROR_INVALID_PARAMETER;
2549 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2550 Handle* item = static_cast<Handle*>(noti);
2551 if (item->GetPtr().get() == nullptr) {
2552 LOGE("Invalid noti reference can not be sended");
2553 return NOTI_EX_ERROR_INVALID_PARAMETER;
2555 *request_id = stub->Hide(item->GetPtr());
2557 } catch (Exception &ex) {
2558 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2559 return NOTI_EX_ERROR_IO_ERROR;
2561 return NOTI_EX_ERROR_NONE;
2564 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2565 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2566 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2567 LOGE("Invalid parameter");
2568 return NOTI_EX_ERROR_INVALID_PARAMETER;
2571 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2572 *item = new Handle(stub->FindByRootID(root_id));
2573 } catch (Exception &ex) {
2574 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2575 return NOTI_EX_ERROR_IO_ERROR;
2577 return NOTI_EX_ERROR_NONE;
2580 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2581 noti_ex_event_info_h info, noti_ex_error_e error) {
2582 if (handle == nullptr || info == nullptr) {
2583 LOGE("Invalid parameter");
2584 return NOTI_EX_ERROR_INVALID_PARAMETER;
2587 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2588 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2589 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2590 static_cast<NotificationError>(error));
2591 } catch (Exception &ex) {
2592 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2593 return NOTI_EX_ERROR_IO_ERROR;
2595 return NOTI_EX_ERROR_NONE;
2598 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2599 noti_ex_manager_h handle, int *cnt) {
2601 if (handle == nullptr || cnt == nullptr) {
2602 LOGE("Invalid parameter");
2603 return NOTI_EX_ERROR_INVALID_PARAMETER;
2606 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2607 *cnt = stub->GetCount();
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_item_progress_create(noti_ex_item_h *handle,
2616 const char *id, float min, float current, float max) {
2619 if (handle == nullptr) {
2620 LOGE("Invalid parameter");
2621 return NOTI_EX_ERROR_INVALID_PARAMETER;
2625 p = new (std::nothrow) ProgressItem(id, min, current, max);
2627 p = new (std::nothrow) ProgressItem(min, current, max);
2630 LOGE("Out-of-memory");
2631 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2634 *handle = new Handle(shared_ptr<AbstractItem>(p));
2636 return NOTI_EX_ERROR_NONE;
2639 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2640 noti_ex_item_h handle, float *current) {
2641 if (handle == nullptr || current == nullptr) {
2642 LOGE("Invalid parameter");
2643 return NOTI_EX_ERROR_INVALID_PARAMETER;
2646 Handle *h = static_cast<Handle*>(handle);
2647 if (!h->IsValidType(AbstractItem::Progress)) {
2648 LOGE("Invalid handle type");
2649 return NOTI_EX_ERROR_INVALID_PARAMETER;
2651 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2652 *current = p->GetCurrent();
2654 return NOTI_EX_ERROR_NONE;
2657 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2658 noti_ex_item_h handle, float current) {
2659 if (handle == nullptr) {
2660 LOGE("Invalid parameter");
2661 return NOTI_EX_ERROR_INVALID_PARAMETER;
2664 Handle *h = static_cast<Handle*>(handle);
2665 if (!h->IsValidType(AbstractItem::Progress)) {
2666 LOGE("Invalid handle type");
2667 return NOTI_EX_ERROR_INVALID_PARAMETER;
2669 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2670 p->SetCurrent(current);
2672 return NOTI_EX_ERROR_NONE;
2675 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2677 if (handle == nullptr || min == nullptr) {
2678 LOGE("Invalid parameter");
2679 return NOTI_EX_ERROR_INVALID_PARAMETER;
2682 Handle *h = static_cast<Handle*>(handle);
2683 if (!h->IsValidType(AbstractItem::Progress)) {
2684 LOGE("Invalid handle type");
2685 return NOTI_EX_ERROR_INVALID_PARAMETER;
2687 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2690 return NOTI_EX_ERROR_NONE;
2693 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2695 if (handle == nullptr || max == nullptr) {
2696 LOGE("Invalid parameter");
2697 return NOTI_EX_ERROR_INVALID_PARAMETER;
2700 Handle *h = static_cast<Handle*>(handle);
2701 if (!h->IsValidType(AbstractItem::Progress)) {
2702 LOGE("Invalid handle type");
2703 return NOTI_EX_ERROR_INVALID_PARAMETER;
2705 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2708 return NOTI_EX_ERROR_NONE;
2711 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2713 if (handle == nullptr || type == nullptr) {
2714 LOGE("Invalid parameter");
2715 return NOTI_EX_ERROR_INVALID_PARAMETER;
2718 Handle *h = static_cast<Handle*>(handle);
2719 if (!h->IsValidType(AbstractItem::Progress)) {
2720 LOGE("Invalid handle type");
2721 return NOTI_EX_ERROR_INVALID_PARAMETER;
2723 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2724 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2726 return NOTI_EX_ERROR_NONE;
2729 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2731 if (handle == nullptr) {
2732 LOGE("Invalid parameter");
2733 return NOTI_EX_ERROR_INVALID_PARAMETER;
2736 Handle *h = static_cast<Handle*>(handle);
2737 if (!h->IsValidType(AbstractItem::Progress)) {
2738 LOGE("Invalid handle type");
2739 return NOTI_EX_ERROR_INVALID_PARAMETER;
2741 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2742 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2744 return NOTI_EX_ERROR_NONE;
2747 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2748 noti_ex_reporter_events_s event_callbacks, void *data) {
2749 if (handle == nullptr) {
2750 LOGE("Invalid parameter");
2751 return NOTI_EX_ERROR_INVALID_PARAMETER;
2754 ReporterStub* stub = new (std::nothrow) ReporterStub(
2755 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2756 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2757 if (stub == nullptr) {
2758 LOGE("Fail to create manager");
2759 return NOTI_EX_ERROR_IO_ERROR;
2761 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2762 new ReporterCallbackInfo(event_callbacks, data)));
2764 *handle = static_cast<noti_ex_reporter_h>(stub);
2766 return NOTI_EX_ERROR_NONE;
2769 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2770 if (handle == nullptr) {
2771 LOGE("Invalid parameter");
2772 return NOTI_EX_ERROR_INVALID_PARAMETER;
2774 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2776 return NOTI_EX_ERROR_NONE;
2779 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2780 noti_ex_event_info_h info, noti_ex_error_e error) {
2781 if (handle == nullptr || info == nullptr) {
2782 LOGE("Invalid parameter");
2783 return NOTI_EX_ERROR_INVALID_PARAMETER;
2786 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2787 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2788 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2789 static_cast<NotificationError>(error));
2790 } catch (Exception &ex) {
2791 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2792 return NOTI_EX_ERROR_IO_ERROR;
2794 return NOTI_EX_ERROR_NONE;
2797 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2798 noti_ex_item_h noti, int *request_id) {
2799 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2800 LOGE("Invalid parameter");
2801 return NOTI_EX_ERROR_INVALID_PARAMETER;
2804 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2805 Handle* h = static_cast<Handle*>(noti);
2806 if (h->GetPtr().get() == nullptr) {
2807 LOGE("Invalid noti reference can not be sended");
2808 return NOTI_EX_ERROR_INVALID_PARAMETER;
2810 *request_id = stub->Post(h->GetPtr());
2812 } catch (Exception &ex) {
2813 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2814 return NOTI_EX_ERROR_IO_ERROR;
2816 return NOTI_EX_ERROR_NONE;
2819 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2820 noti_ex_item_h *noti_list, int count, int *request_id) {
2822 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2823 LOGE("Invalid parameter");
2824 return NOTI_EX_ERROR_INVALID_PARAMETER;
2827 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2828 list<shared_ptr<item::AbstractItem>> notiList;
2829 for (int i = 0; i < count; i++) {
2830 Handle* item = static_cast<Handle*>(noti_list[i]);
2831 notiList.push_back(item->GetPtr());
2833 *request_id = stub->Post(notiList);
2834 } catch (Exception &ex) {
2835 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2836 return NOTI_EX_ERROR_IO_ERROR;
2838 return NOTI_EX_ERROR_NONE;
2841 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2842 noti_ex_item_h noti, int *request_id) {
2843 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2844 LOGE("Invalid parameter");
2845 return NOTI_EX_ERROR_INVALID_PARAMETER;
2848 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2849 Handle* item = static_cast<Handle*>(noti);
2850 if (item->GetPtr().get() == nullptr) {
2851 LOGE("Invalid noti reference can not be sended");
2852 return NOTI_EX_ERROR_INVALID_PARAMETER;
2854 *request_id = stub->Update(item->GetPtr());
2856 } catch (Exception &ex) {
2857 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2858 return NOTI_EX_ERROR_IO_ERROR;
2860 return NOTI_EX_ERROR_NONE;
2863 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2864 noti_ex_item_h noti, int *request_id) {
2865 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2866 LOGE("Invalid parameter");
2867 return NOTI_EX_ERROR_INVALID_PARAMETER;
2870 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2871 Handle* item = static_cast<Handle*>(noti);
2872 if (item->GetPtr().get() == nullptr) {
2873 LOGE("Invalid noti reference can not be sended");
2874 return NOTI_EX_ERROR_INVALID_PARAMETER;
2876 *request_id = stub->Delete(item->GetPtr());
2878 } catch (Exception &ex) {
2879 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2880 return NOTI_EX_ERROR_IO_ERROR;
2882 return NOTI_EX_ERROR_NONE;
2885 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2886 noti_ex_reporter_h handle, int *request_id) {
2887 if (handle == nullptr || request_id == nullptr) {
2888 LOGE("Invalid parameter");
2889 return NOTI_EX_ERROR_INVALID_PARAMETER;
2892 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2893 *request_id = stub->DeleteAll();
2894 } catch (Exception &ex) {
2895 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2896 return NOTI_EX_ERROR_IO_ERROR;
2898 return NOTI_EX_ERROR_NONE;
2901 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2902 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2903 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2904 LOGE("Invalid parameter");
2905 return NOTI_EX_ERROR_INVALID_PARAMETER;
2908 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2909 *item = new Handle(stub->FindByRootID(root_id));
2910 } catch (Exception &ex) {
2911 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2912 return NOTI_EX_ERROR_IO_ERROR;
2914 return NOTI_EX_ERROR_NONE;
2917 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2918 const char *id, const char *text, const char *hyperlink) {
2919 if (handle == nullptr || text == nullptr) {
2920 LOGE("Invalid parameter");
2921 return NOTI_EX_ERROR_INVALID_PARAMETER;
2927 p = new (std::nothrow) TextItem(id, std::string(text),
2928 std::string(hyperlink));
2930 p = new (std::nothrow) TextItem(id, std::string(text));
2933 LOGE("Out-of-memory");
2934 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2937 *handle = new Handle(shared_ptr<AbstractItem>(p));
2939 return NOTI_EX_ERROR_NONE;
2942 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2943 const char *contents) {
2944 if (handle == nullptr || contents == nullptr) {
2945 LOGE("Invalid parameter");
2946 return NOTI_EX_ERROR_INVALID_PARAMETER;
2949 Handle* p = static_cast<Handle*>(handle);
2950 if (!p->IsValidType(AbstractItem::Text)) {
2951 LOGE("Invalid handle type");
2952 return NOTI_EX_ERROR_INVALID_PARAMETER;
2954 TextItem* ti = static_cast<TextItem*>(p->Get());
2955 ti->SetContents(std::string(contents));
2957 return NOTI_EX_ERROR_NONE;
2960 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2962 if (handle == nullptr || contents == nullptr) {
2963 LOGE("Invalid parameter");
2964 return NOTI_EX_ERROR_INVALID_PARAMETER;
2967 Handle* p = static_cast<Handle*>(handle);
2968 if (!p->IsValidType(AbstractItem::Text)) {
2969 LOGE("Invalid handle type");
2970 return NOTI_EX_ERROR_INVALID_PARAMETER;
2973 TextItem* ti = static_cast<TextItem*>(p->Get());
2975 if (ti->GetMultiLanguage() != nullptr &&
2976 !ti->GetMultiLanguage()->GetTranslatedString().empty())
2977 str = ti->GetMultiLanguage()->GetTranslatedString();
2978 else if (!ti->GetContents().empty())
2979 str = ti->GetContents();
2981 *contents = strdup(str.c_str());
2982 if (*contents == nullptr) {
2983 LOGE("Out-of-memory");
2984 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2987 return NOTI_EX_ERROR_NONE;
2990 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2991 noti_ex_item_h handle, char **hyper_link) {
2992 if (handle == nullptr || hyper_link == nullptr) {
2993 LOGE("Invalid parameter");
2994 return NOTI_EX_ERROR_INVALID_PARAMETER;
2997 Handle* p = static_cast<Handle*>(handle);
2998 if (!p->IsValidType(AbstractItem::Text)) {
2999 LOGE("Invalid handle type");
3000 return NOTI_EX_ERROR_INVALID_PARAMETER;
3002 TextItem* ti = static_cast<TextItem*>(p->Get());
3003 if (!ti->GetHyperLink().empty()) {
3004 *hyper_link = strdup(ti->GetHyperLink().c_str());
3005 if (*hyper_link == nullptr) {
3006 LOGE("Out-of-memory");
3007 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3011 return NOTI_EX_ERROR_NONE;
3014 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3015 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3016 if (handle == nullptr) {
3017 LOGE("Invalid parameter");
3018 return NOTI_EX_ERROR_INVALID_PARAMETER;
3021 Handle* p = static_cast<Handle*>(handle);
3022 if (!p->IsValidType(AbstractItem::Text)) {
3023 LOGE("Invalid handle type");
3024 return NOTI_EX_ERROR_INVALID_PARAMETER;
3027 TextItem* ti = static_cast<TextItem*>(p->Get());
3028 if (multi == nullptr) {
3029 ti->SetMultiLanguage(nullptr);
3030 return NOTI_EX_ERROR_NONE;
3033 shared_ptr<MultiLanguage> mul_ptr =
3034 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3035 ti->SetMultiLanguage(mul_ptr);
3036 ti->GetMultiLanguage()->UpdateString();
3038 return NOTI_EX_ERROR_NONE;
3041 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3042 const char *id, time_t time) {
3045 if (handle == nullptr) {
3046 LOGE("Invalid parameter");
3047 return NOTI_EX_ERROR_INVALID_PARAMETER;
3052 p = new (std::nothrow) TimeItem(id, time);
3054 p = new (std::nothrow) TimeItem(time);
3056 p = new (std::nothrow) TimeItem();
3060 LOGE("Out-of-memory");
3061 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3064 *handle = new Handle(shared_ptr<AbstractItem>(p));
3066 return NOTI_EX_ERROR_NONE;
3069 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3071 if (handle == nullptr || time == nullptr) {
3072 LOGE("Invalid parameter");
3073 return NOTI_EX_ERROR_INVALID_PARAMETER;
3075 Handle* h = static_cast<Handle*>(handle);
3076 if (!h->IsValidType(AbstractItem::Time)) {
3077 LOGE("Invalid handle type");
3078 return NOTI_EX_ERROR_INVALID_PARAMETER;
3080 TimeItem* p = static_cast<TimeItem*>(h->Get());
3081 *time = p->GetTime();
3083 return NOTI_EX_ERROR_NONE;
3086 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3087 noti_ex_action_h *handle, const char *extra) {
3088 if (handle == nullptr) {
3089 LOGE("Invalid parameter");
3090 return NOTI_EX_ERROR_INVALID_PARAMETER;
3093 string extra_str = "";
3095 extra_str = string(extra);
3097 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3098 new (std::nothrow) VisibilityAction(extra_str));
3099 if (ptr == nullptr) {
3100 LOGE("Out-of-memory");
3101 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3106 return NOTI_EX_ERROR_NONE;
3109 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3110 const char *id, bool visible) {
3111 if (handle == nullptr || id == nullptr) {
3112 LOGE("Invalid parameter");
3113 return NOTI_EX_ERROR_INVALID_PARAMETER;
3116 shared_ptr<AbstractAction>* ptr =
3117 static_cast<shared_ptr<AbstractAction>*>(handle);
3118 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3119 action->SetVisibility(id, visible);
3121 return NOTI_EX_ERROR_NONE;
3124 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3125 const char* msgid, const char* format, ...) {
3126 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3127 LOGE("Invalid parameter");
3128 return NOTI_EX_ERROR_INVALID_PARAMETER;
3131 const char* format_idx = format;
3134 va_start(args, format);
3135 while (*format_idx != '\0') {
3136 char* arg = nullptr;
3139 stringstream stream;
3140 if (*format_idx == '%') {
3141 switch (*(format_idx + 1)) {
3143 arg = va_arg(args, char *);
3144 arr.push_back(string(arg));
3147 arg_i = va_arg(args, int);
3148 arr.push_back(to_string(arg_i));
3151 arg_f = va_arg(args, double);
3152 stream << std::fixed << std::setprecision(2) << arg_f;
3153 arr.push_back(stream.str());
3161 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3163 LOGE("Out-of-memory");
3164 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3166 *handle = new shared_ptr<MultiLanguage>(p);
3168 return NOTI_EX_ERROR_NONE;
3171 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3172 if (handle == nullptr) {
3173 LOGE("Invalid parameter");
3174 return NOTI_EX_ERROR_INVALID_PARAMETER;
3177 shared_ptr<MultiLanguage>* mul_ptr =
3178 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3180 return NOTI_EX_ERROR_NONE;