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 || multi == 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_entry_create(noti_ex_item_h *handle,
651 if (handle == nullptr) {
652 LOGE("Invalid parameter");
653 return NOTI_EX_ERROR_INVALID_PARAMETER;
656 p = new (std::nothrow) EntryItem(id);
658 LOGE("Out-of-memory");
659 return NOTI_EX_ERROR_OUT_OF_MEMORY;
662 *handle = new Handle(shared_ptr<AbstractItem>(p));
664 return NOTI_EX_ERROR_NONE;
667 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
669 if (handle == nullptr || text == nullptr) {
670 LOGE("Invalid parameter");
671 return NOTI_EX_ERROR_INVALID_PARAMETER;
674 Handle* h = static_cast<Handle*>(handle);
675 if (!h->IsValidType(AbstractItem::Entry)) {
676 LOGE("Invalid handle type");
677 return NOTI_EX_ERROR_INVALID_PARAMETER;
680 EntryItem* p = static_cast<EntryItem*>(h->Get());
682 if (p->GetMultiLanguage() != nullptr &&
683 !p->GetMultiLanguage()->GetTranslatedString().empty())
684 str = p->GetMultiLanguage()->GetTranslatedString();
685 else if (!p->GetText().empty())
688 *text = strdup(str.c_str());
689 if (*text == nullptr) {
690 LOGE("Out-of-memory");
691 return NOTI_EX_ERROR_OUT_OF_MEMORY;
694 return NOTI_EX_ERROR_NONE;
697 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
699 if (handle == nullptr || text == nullptr) {
700 LOGE("Invalid parameter");
701 return NOTI_EX_ERROR_INVALID_PARAMETER;
703 Handle* h = static_cast<Handle*>(handle);
704 if (!h->IsValidType(AbstractItem::Entry)) {
705 LOGE("Invalid handle type");
706 return NOTI_EX_ERROR_INVALID_PARAMETER;
708 EntryItem* p = static_cast<EntryItem*>(h->Get());
709 p->SetText(std::string(text));
711 return NOTI_EX_ERROR_NONE;
714 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
715 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
716 if (handle == nullptr || multi == nullptr) {
717 LOGE("Invalid parameter");
718 return NOTI_EX_ERROR_INVALID_PARAMETER;
721 Handle* p = static_cast<Handle*>(handle);
722 if (!p->IsValidType(AbstractItem::Entry)) {
723 LOGE("Invalid handle type");
724 return NOTI_EX_ERROR_INVALID_PARAMETER;
727 shared_ptr<MultiLanguage> mul_ptr =
728 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
729 EntryItem* ei = static_cast<EntryItem*>(p->Get());
730 ei->SetMultiLanguage(mul_ptr);
731 ei->GetMultiLanguage()->UpdateString();
733 return NOTI_EX_ERROR_NONE;
736 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
737 noti_ex_event_info_h* cloned_handle) {
738 if (handle == nullptr || cloned_handle == nullptr) {
739 LOGE("Invalid parameter");
740 return NOTI_EX_ERROR_INVALID_PARAMETER;
743 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
744 EventInfo* info = new EventInfo(cloned);
745 *cloned_handle = info;
746 return NOTI_EX_ERROR_NONE;
749 extern "C" EXPORT_API int noti_ex_event_info_destroy(
750 noti_ex_event_info_h handle) {
751 if (handle == nullptr) {
752 LOGE("Invalid parameter");
753 return NOTI_EX_ERROR_INVALID_PARAMETER;
755 EventInfo* info = static_cast<EventInfo*>(handle);
757 return NOTI_EX_ERROR_NONE;
760 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
761 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
762 if (handle == nullptr || event_type == nullptr) {
763 LOGE("Invalid parameter");
764 return NOTI_EX_ERROR_INVALID_PARAMETER;
766 EventInfo* info = static_cast<EventInfo*>(handle);
767 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
769 return NOTI_EX_ERROR_NONE;
772 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
773 noti_ex_event_info_h handle, char **owner) {
774 if (handle == nullptr || owner == nullptr) {
775 LOGE("Invalid parameter");
776 return NOTI_EX_ERROR_INVALID_PARAMETER;
778 EventInfo* info = static_cast<EventInfo*>(handle);
779 *owner = strdup(info->GetOwner().c_str());
780 return NOTI_EX_ERROR_NONE;
783 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
784 noti_ex_event_info_h handle, char **channel) {
785 if (handle == nullptr || channel == nullptr) {
786 LOGE("Invalid parameter");
787 return NOTI_EX_ERROR_INVALID_PARAMETER;
789 EventInfo* info = static_cast<EventInfo*>(handle);
790 *channel = strdup(info->GetChannel().c_str());
791 return NOTI_EX_ERROR_NONE;
794 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
795 noti_ex_event_info_h handle, char **item_id) {
796 if (handle == nullptr || item_id == nullptr) {
797 LOGE("Invalid parameter");
798 return NOTI_EX_ERROR_INVALID_PARAMETER;
800 EventInfo* info = static_cast<EventInfo*>(handle);
801 *item_id = strdup(info->GetItemId().c_str());
802 return NOTI_EX_ERROR_NONE;
805 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
806 noti_ex_event_info_h handle, int *req_id) {
807 if (handle == nullptr || req_id == nullptr) {
808 LOGE("Invalid parameter");
809 return NOTI_EX_ERROR_INVALID_PARAMETER;
811 EventInfo* info = static_cast<EventInfo*>(handle);
812 *req_id = info->GetRequestId();
813 return NOTI_EX_ERROR_NONE;
816 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
820 if (handle == nullptr) {
821 LOGE("Invalid parameter");
822 return NOTI_EX_ERROR_INVALID_PARAMETER;
826 p = new (std::nothrow) GroupItem(id);
828 p = new (std::nothrow) GroupItem();
831 LOGE("Out-of-memory");
832 return NOTI_EX_ERROR_OUT_OF_MEMORY;
835 *handle = new Handle(shared_ptr<AbstractItem>(p));
837 return NOTI_EX_ERROR_NONE;
840 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
842 if (handle == nullptr) {
843 LOGE("Invalid parameter");
844 return NOTI_EX_ERROR_INVALID_PARAMETER;
846 Handle* h = static_cast<Handle*>(handle);
847 if (!h->IsValidType(AbstractItem::Group)) {
848 LOGE("Invalid handle type");
849 return NOTI_EX_ERROR_INVALID_PARAMETER;
851 GroupItem* p = static_cast<GroupItem*>(h->Get());
852 p->SetDirection(vertical);
854 return NOTI_EX_ERROR_NONE;
857 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
859 if (handle == nullptr) {
860 LOGE("Invalid parameter");
861 return NOTI_EX_ERROR_INVALID_PARAMETER;
863 Handle* h = static_cast<Handle*>(handle);
864 if (!h->IsValidType(AbstractItem::Group)) {
865 LOGE("Invalid handle type");
866 return NOTI_EX_ERROR_INVALID_PARAMETER;
868 GroupItem* p = static_cast<GroupItem*>(h->Get());
869 *vertical = p->IsVertical();
871 return NOTI_EX_ERROR_NONE;
874 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
876 if (handle == nullptr) {
877 LOGE("Invalid parameter");
878 return NOTI_EX_ERROR_INVALID_PARAMETER;
880 Handle* h = static_cast<Handle*>(handle);
881 if (!h->IsValidType(AbstractItem::Group)) {
882 LOGE("Invalid handle type");
883 return NOTI_EX_ERROR_INVALID_PARAMETER;
885 GroupItem* p = static_cast<GroupItem*>(h->Get());
886 if (!p->GetAppLabel().empty()) {
887 *label = strdup(p->GetAppLabel().c_str());
888 if (*label == nullptr) {
889 LOGE("Out-of-memory");
890 return NOTI_EX_ERROR_OUT_OF_MEMORY;
894 return NOTI_EX_ERROR_NONE;
897 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
898 noti_ex_item_h child) {
899 if (handle == nullptr || child == nullptr) {
900 LOGE("Invalid parameter");
901 return NOTI_EX_ERROR_INVALID_PARAMETER;
903 Handle* h = static_cast<Handle*>(handle);
904 if (!h->IsValidType(AbstractItem::Group)) {
905 LOGE("Invalid handle type");
906 return NOTI_EX_ERROR_INVALID_PARAMETER;
908 auto p = static_cast<GroupItem*>(h->Get());
909 p->AddChild((static_cast<Handle*>(child))->GetPtr());
911 return NOTI_EX_ERROR_NONE;
914 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
915 const char *item_id) {
916 if (handle == nullptr || item_id == nullptr) {
917 LOGE("Invalid parameter");
918 return NOTI_EX_ERROR_INVALID_PARAMETER;
920 Handle* h = static_cast<Handle*>(handle);
921 if (!h->IsValidType(AbstractItem::Group)) {
922 LOGE("Invalid handle type");
923 return NOTI_EX_ERROR_INVALID_PARAMETER;
925 GroupItem* p = static_cast<GroupItem*>(h->Get());
926 p->RemoveChild(std::string(item_id));
928 return NOTI_EX_ERROR_NONE;
931 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
932 noti_ex_item_group_foreach_child_cb callback, void *data) {
933 if (handle == nullptr || callback == nullptr) {
934 LOGE("Invalid parameter");
935 return NOTI_EX_ERROR_INVALID_PARAMETER;
938 Handle* h = static_cast<Handle*>(handle);
939 if (!h->IsValidType(AbstractItem::Group)) {
940 LOGE("Invalid handle type");
941 return NOTI_EX_ERROR_INVALID_PARAMETER;
943 GroupItem* p = static_cast<GroupItem*>(h->Get());
944 list<shared_ptr<AbstractItem>> children = p->GetChildren();
945 LOGI("Retrive (%zd)", children.size());
946 for (auto i : children) {
948 static_cast<noti_ex_item_h>(new Handle(i)), data);
949 if (ret != NOTI_EX_ERROR_NONE) {
950 LOGW("callback return (%d) stop foreach", ret);
955 return NOTI_EX_ERROR_NONE;
958 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
959 const char *id, const char *image_path) {
962 if (handle == nullptr || image_path == nullptr) {
963 LOGE("Invalid parameter");
964 return NOTI_EX_ERROR_INVALID_PARAMETER;
968 p = new (std::nothrow) ImageItem(id, image_path);
970 p = new (std::nothrow) ImageItem(image_path);
973 LOGE("Out-of-memory");
974 return NOTI_EX_ERROR_OUT_OF_MEMORY;
977 *handle = new Handle(shared_ptr<AbstractItem>(p));
979 return NOTI_EX_ERROR_NONE;
982 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
983 noti_ex_item_h handle, char **image_path) {
984 if (handle == nullptr || image_path == nullptr) {
985 LOGE("Invalid parameter");
986 return NOTI_EX_ERROR_INVALID_PARAMETER;
988 Handle* h = static_cast<Handle*>(handle);
989 if (!h->IsValidType(AbstractItem::Image)) {
990 LOGE("Invalid handle type");
991 return NOTI_EX_ERROR_INVALID_PARAMETER;
993 ImageItem* p = static_cast<ImageItem*>(h->Get());
994 if (!p->GetImagePath().empty()) {
995 *image_path = strdup(p->GetImagePath().c_str());
996 if (*image_path == nullptr) {
997 LOGE("Out-of-memory");
998 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1002 return NOTI_EX_ERROR_NONE;
1005 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1006 noti_ex_item_h *handle, const char *id) {
1007 InputSelectorItem* p;
1009 if (handle == nullptr) {
1010 LOGE("Invalid parameter");
1011 return NOTI_EX_ERROR_INVALID_PARAMETER;
1015 p = new (std::nothrow) InputSelectorItem(id);
1017 p = new (std::nothrow) InputSelectorItem();
1020 LOGE("Out-of-memory");
1021 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1024 *handle = new Handle(shared_ptr<AbstractItem>(p));
1026 return NOTI_EX_ERROR_NONE;
1029 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1030 noti_ex_item_h handle, char ***contents_list, int *count) {
1031 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1032 LOGE("Invalid parameter");
1033 return NOTI_EX_ERROR_INVALID_PARAMETER;
1036 Handle* h = static_cast<Handle*>(handle);
1037 if (!h->IsValidType(AbstractItem::InputSelector)) {
1038 LOGE("Invalid handle type");
1039 return NOTI_EX_ERROR_INVALID_PARAMETER;
1042 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1043 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1044 list<string> contents;
1045 if (arr.size() == 0) {
1046 contents = p->GetContents();
1048 for (auto& i : arr) {
1049 contents.push_back(i->GetTranslatedString());
1053 char **list = (char**)calloc(contents.size(), sizeof(char*));
1054 if (list == nullptr) {
1055 LOGE("Out of memory");
1056 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1060 for (auto& i : contents) {
1061 list[idx] = strdup(i.c_str());
1062 if (list[idx] == nullptr) {
1063 __noti_ex_free_str_array(list, idx);
1064 LOGE("Out of memory");
1065 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1070 *count = contents.size();
1071 *contents_list = list;
1073 return NOTI_EX_ERROR_NONE;
1076 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1077 noti_ex_item_h handle, const char **contents, int count) {
1078 if (handle == nullptr || contents == nullptr) {
1079 LOGE("Invalid parameter");
1080 return NOTI_EX_ERROR_INVALID_PARAMETER;
1083 list<string> new_contents;
1084 Handle* h = static_cast<Handle*>(handle);
1085 if (!h->IsValidType(AbstractItem::InputSelector)) {
1086 LOGE("Invalid handle type");
1087 return NOTI_EX_ERROR_INVALID_PARAMETER;
1089 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1090 for (int i = 0; i < count; i++) {
1091 new_contents.push_back(contents[i]);
1093 p->SetContents(move(new_contents));
1095 return NOTI_EX_ERROR_NONE;
1098 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1099 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1100 if (handle == nullptr) {
1101 LOGE("Invalid parameter");
1102 return NOTI_EX_ERROR_INVALID_PARAMETER;
1105 Handle* p = static_cast<Handle*>(handle);
1106 if (!p->IsValidType(AbstractItem::InputSelector)) {
1107 LOGE("Invalid handle type");
1108 return NOTI_EX_ERROR_INVALID_PARAMETER;
1111 vector<shared_ptr<MultiLanguage>> m_list;
1112 for (int i = 0; i < count; i++) {
1113 shared_ptr<MultiLanguage> mul_ptr =
1114 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1115 mul_ptr->UpdateString();
1116 m_list.push_back(mul_ptr);
1119 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1120 input->SetMultiLanguage(m_list);
1122 return NOTI_EX_ERROR_NONE;
1125 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1126 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1127 if (handle == nullptr) {
1128 LOGE("Invalid parameter");
1129 return NOTI_EX_ERROR_INVALID_PARAMETER;
1132 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1133 new (std::nothrow) Color(a, r, g, b));
1134 if (ptr == nullptr || ptr->get() == nullptr) {
1135 LOGE("Out-of-memory");
1136 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1141 return NOTI_EX_ERROR_NONE;
1144 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1145 if (handle == nullptr) {
1146 LOGE("Invalid parameter");
1147 return NOTI_EX_ERROR_INVALID_PARAMETER;
1150 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1153 return NOTI_EX_ERROR_NONE;
1156 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1157 unsigned char *val) {
1158 if (handle == nullptr || val == nullptr) {
1159 LOGE("Invalid parameter");
1160 return NOTI_EX_ERROR_INVALID_PARAMETER;
1163 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1164 *val = (*p)->GetAVal();
1166 return NOTI_EX_ERROR_NONE;
1169 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1170 unsigned char *val) {
1171 if (handle == nullptr || val == nullptr) {
1172 LOGE("Invalid parameter");
1173 return NOTI_EX_ERROR_INVALID_PARAMETER;
1176 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1177 *val = (*p)->GetRVal();
1179 return NOTI_EX_ERROR_NONE;
1182 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1183 unsigned char *val) {
1184 if (handle == nullptr || val == nullptr) {
1185 LOGE("Invalid parameter");
1186 return NOTI_EX_ERROR_INVALID_PARAMETER;
1189 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1190 *val = (*p)->GetGVal();
1192 return NOTI_EX_ERROR_NONE;
1195 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1196 unsigned char *val) {
1197 if (handle == nullptr || val == nullptr) {
1198 LOGE("Invalid parameter");
1199 return NOTI_EX_ERROR_INVALID_PARAMETER;
1202 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1203 *val = (*p)->GetBVal();
1205 return NOTI_EX_ERROR_NONE;
1208 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1209 int left, int top, int right, int bottom) {
1210 if (handle == nullptr) {
1211 LOGE("Invalid parameter");
1212 return NOTI_EX_ERROR_INVALID_PARAMETER;
1215 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1216 new (std::nothrow) Padding(left, top, right, bottom));
1217 if (ptr == nullptr || ptr->get() == nullptr) {
1218 LOGE("Out-of-memory");
1219 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1224 return NOTI_EX_ERROR_NONE;
1227 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1228 if (handle == nullptr) {
1229 LOGE("Invalid parameter");
1230 return NOTI_EX_ERROR_INVALID_PARAMETER;
1233 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1236 return NOTI_EX_ERROR_NONE;
1239 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1241 if (handle == nullptr || val == nullptr) {
1242 LOGE("Invalid parameter");
1243 return NOTI_EX_ERROR_INVALID_PARAMETER;
1246 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1247 *val = (*p)->GetLeft();
1249 return NOTI_EX_ERROR_NONE;
1252 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1254 if (handle == nullptr || val == nullptr) {
1255 LOGE("Invalid parameter");
1256 return NOTI_EX_ERROR_INVALID_PARAMETER;
1259 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1260 *val = (*p)->GetTop();
1262 return NOTI_EX_ERROR_NONE;
1265 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1267 if (handle == nullptr || val == nullptr) {
1268 LOGE("Invalid parameter");
1269 return NOTI_EX_ERROR_INVALID_PARAMETER;
1272 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1273 *val = (*p)->GetRight();
1275 return NOTI_EX_ERROR_NONE;
1278 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1280 if (handle == nullptr || val == nullptr) {
1281 LOGE("Invalid parameter");
1282 return NOTI_EX_ERROR_INVALID_PARAMETER;
1285 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1286 *val = (*p)->GetBottom();
1288 return NOTI_EX_ERROR_NONE;
1291 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1292 int x, int y, int w, int h) {
1293 if (handle == nullptr) {
1294 LOGE("Invalid parameter");
1295 return NOTI_EX_ERROR_INVALID_PARAMETER;
1298 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1299 new (std::nothrow) Geometry(x, y, w, h));
1300 if (ptr == nullptr || ptr->get() == nullptr) {
1301 LOGE("Out-of-memory");
1302 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1307 return NOTI_EX_ERROR_NONE;
1310 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1311 if (handle == nullptr) {
1312 LOGE("Invalid parameter");
1313 return NOTI_EX_ERROR_INVALID_PARAMETER;
1316 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1319 return NOTI_EX_ERROR_NONE;
1322 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1324 if (handle == nullptr || val == nullptr) {
1325 LOGE("Invalid parameter");
1326 return NOTI_EX_ERROR_INVALID_PARAMETER;
1329 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1330 *val = (*p)->GetX();
1332 return NOTI_EX_ERROR_NONE;
1335 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1337 if (handle == nullptr || val == nullptr) {
1338 LOGE("Invalid parameter");
1339 return NOTI_EX_ERROR_INVALID_PARAMETER;
1342 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1343 *val = (*p)->GetY();
1345 return NOTI_EX_ERROR_NONE;
1348 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1350 if (handle == nullptr || val == nullptr) {
1351 LOGE("Invalid parameter");
1352 return NOTI_EX_ERROR_INVALID_PARAMETER;
1355 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1356 *val = (*p)->GetWidth();
1358 return NOTI_EX_ERROR_NONE;
1361 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1363 if (handle == nullptr || val == nullptr) {
1364 LOGE("Invalid parameter");
1365 return NOTI_EX_ERROR_INVALID_PARAMETER;
1368 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1369 *val = (*p)->GetHeight();
1371 return NOTI_EX_ERROR_NONE;
1374 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1375 noti_ex_color_h color,
1376 noti_ex_padding_h padding,
1377 noti_ex_geometry_h geometry) {
1378 if (handle == nullptr) {
1379 LOGE("Invalid parameter");
1380 return NOTI_EX_ERROR_INVALID_PARAMETER;
1383 shared_ptr<Color> col = (color == nullptr) ?
1384 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1385 shared_ptr<Padding> padd = (padding == nullptr) ?
1386 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1387 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1388 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1390 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1391 new (std::nothrow) Style(col, padd, geo));
1392 if (ptr == nullptr || ptr->get() == nullptr) {
1393 LOGE("Out-of-memory");
1394 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1399 return NOTI_EX_ERROR_NONE;
1402 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1403 if (handle == nullptr) {
1404 LOGE("Invalid parameter");
1405 return NOTI_EX_ERROR_INVALID_PARAMETER;
1408 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1411 return NOTI_EX_ERROR_NONE;
1414 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1415 noti_ex_padding_h *padding) {
1416 if (handle == nullptr || padding == nullptr) {
1417 LOGE("Invalid parameter");
1418 return NOTI_EX_ERROR_INVALID_PARAMETER;
1421 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1422 if ((*p)->GetPadding() == nullptr) {
1423 LOGW("Padding info is null");
1424 return NOTI_EX_ERROR_INVALID_PARAMETER;
1427 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1428 new (std::nothrow) Padding(*((*p)->GetPadding())));
1429 if (padd == nullptr || padd->get() == nullptr) {
1430 LOGE("Out-of-memory");
1431 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1440 noti_ex_color_h *color) {
1441 if (handle == nullptr || color == nullptr) {
1442 LOGE("Invalid parameter");
1443 return NOTI_EX_ERROR_INVALID_PARAMETER;
1446 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1447 if ((*p)->GetColor() == nullptr) {
1448 LOGW("Color info is null");
1449 return NOTI_EX_ERROR_INVALID_PARAMETER;
1452 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1453 new (std::nothrow) Color(*((*p)->GetColor())));
1454 if (col == nullptr || col->get() == nullptr) {
1455 LOGE("Out-of-memory");
1456 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1461 return NOTI_EX_ERROR_NONE;
1464 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1465 noti_ex_geometry_h *geometry) {
1466 if (handle == nullptr || geometry == nullptr) {
1467 LOGE("Invalid parameter");
1468 return NOTI_EX_ERROR_INVALID_PARAMETER;
1471 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1472 if ((*p)->GetGeometry() == nullptr) {
1473 LOGW("Geometry info is null");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1478 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1479 if (geo == nullptr || geo->get() == nullptr) {
1480 LOGE("Out-of-memory");
1481 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1486 return NOTI_EX_ERROR_NONE;
1489 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1490 noti_ex_style_h handle, char** background_image) {
1491 if (handle == nullptr || background_image == nullptr) {
1492 LOGE("Invalid parameter");
1493 return NOTI_EX_ERROR_INVALID_PARAMETER;
1496 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1497 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1499 return NOTI_EX_ERROR_NONE;
1502 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1503 noti_ex_style_h handle, char* background_image) {
1504 if (handle == nullptr || background_image == nullptr) {
1505 LOGE("Invalid parameter");
1506 return NOTI_EX_ERROR_INVALID_PARAMETER;
1509 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1510 (*p)->SetBackgroundImage(background_image);
1512 return NOTI_EX_ERROR_NONE;
1515 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1516 noti_ex_style_h handle, noti_ex_color_h* color) {
1517 if (handle == nullptr || color == nullptr) {
1518 LOGE("Invalid parameter");
1519 return NOTI_EX_ERROR_INVALID_PARAMETER;
1522 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1523 if ((*p)->GetBackgroundColor() == nullptr) {
1524 LOGW("Color info is null");
1525 return NOTI_EX_ERROR_INVALID_PARAMETER;
1528 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1529 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1530 if (col == nullptr || col->get() == nullptr) {
1531 LOGE("Out-of-memory");
1532 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1537 return NOTI_EX_ERROR_NONE;
1540 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1541 noti_ex_style_h handle, noti_ex_color_h color) {
1542 if (handle == nullptr || color == nullptr) {
1543 LOGE("Invalid parameter");
1544 return NOTI_EX_ERROR_INVALID_PARAMETER;
1547 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1548 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1549 (*p)->SetBackgroundColor(*col);
1551 return NOTI_EX_ERROR_NONE;
1554 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1555 noti_ex_color_h color) {
1556 if (handle == nullptr) {
1557 LOGE("Invalid parameter");
1558 return NOTI_EX_ERROR_INVALID_PARAMETER;
1561 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1562 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1563 new (std::nothrow) LEDInfo(*color_ptr));
1565 LOGE("Out-of-memory");
1566 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1571 return NOTI_EX_ERROR_NONE;
1574 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1575 if (handle == nullptr) {
1576 LOGE("Invalid parameter");
1577 return NOTI_EX_ERROR_INVALID_PARAMETER;
1580 shared_ptr<LEDInfo>* led_ptr =
1581 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1583 return NOTI_EX_ERROR_NONE;
1586 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1587 noti_ex_led_info_h handle, int ms) {
1588 if (handle == nullptr) {
1589 LOGE("Invalid parameter");
1590 return NOTI_EX_ERROR_INVALID_PARAMETER;
1593 shared_ptr<LEDInfo>* led_ptr =
1594 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1595 (*led_ptr)->SetOnPeriod(ms);
1597 return NOTI_EX_ERROR_NONE;
1600 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1601 noti_ex_led_info_h handle, int *ms) {
1602 if (handle == nullptr || ms == nullptr) {
1603 LOGE("Invalid parameter");
1604 return NOTI_EX_ERROR_INVALID_PARAMETER;
1607 shared_ptr<LEDInfo>* led_ptr =
1608 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1609 *ms = (*led_ptr)->GetOnPeriod();
1611 return NOTI_EX_ERROR_NONE;
1614 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1615 noti_ex_led_info_h handle, int ms) {
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);
1623 (*led_ptr)->SetOffPeriod(ms);
1625 return NOTI_EX_ERROR_NONE;
1628 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1629 noti_ex_led_info_h handle, int *ms) {
1630 if (handle == nullptr) {
1631 LOGE("Invalid parameter");
1632 return NOTI_EX_ERROR_INVALID_PARAMETER;
1635 shared_ptr<LEDInfo>* led_ptr =
1636 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1637 *ms = (*led_ptr)->GetOffPeriod();
1639 return NOTI_EX_ERROR_NONE;
1642 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1643 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1644 if (handle == nullptr) {
1645 LOGE("Invalid parameter");
1646 return NOTI_EX_ERROR_INVALID_PARAMETER;
1649 shared_ptr<LEDInfo>* led_ptr =
1650 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1651 if ((*led_ptr)->GetColor() == nullptr) {
1652 LOGE("Color is null");
1653 return NOTI_EX_ERROR_INVALID_PARAMETER;
1656 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1657 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1658 if (col == nullptr || col->get() == nullptr) {
1659 LOGE("Out-of-memory");
1660 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1665 return NOTI_EX_ERROR_NONE;
1668 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1669 if (handle == nullptr) {
1670 LOGE("Invalid parameter");
1671 return NOTI_EX_ERROR_INVALID_PARAMETER;
1674 shared_ptr<AbstractAction>* ptr =
1675 static_cast<shared_ptr<AbstractAction>*>(handle);
1678 return NOTI_EX_ERROR_NONE;
1681 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1683 if (handle == nullptr || type == nullptr) {
1684 LOGE("Invalid parameter");
1685 return NOTI_EX_ERROR_INVALID_PARAMETER;
1688 shared_ptr<AbstractAction>* ptr =
1689 static_cast<shared_ptr<AbstractAction>*>(handle);
1690 *type = (*ptr)->GetType();
1692 return NOTI_EX_ERROR_NONE;
1695 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1697 if (handle == nullptr || local == nullptr) {
1698 LOGE("Invalid parameter");
1699 return NOTI_EX_ERROR_INVALID_PARAMETER;
1702 shared_ptr<AbstractAction>* ptr =
1703 static_cast<shared_ptr<AbstractAction>*>(handle);
1704 *local = (*ptr)->IsLocal();
1706 return NOTI_EX_ERROR_NONE;
1709 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1710 noti_ex_item_h item) {
1711 if (handle == nullptr || item == nullptr) {
1712 LOGE("Invalid parameter");
1713 return NOTI_EX_ERROR_INVALID_PARAMETER;
1715 shared_ptr<AbstractAction>* ptr =
1716 static_cast<shared_ptr<AbstractAction>*>(handle);
1717 Handle* ih = static_cast<Handle*>(item);
1718 (*ptr)->Execute(ih->GetPtr());
1720 return NOTI_EX_ERROR_NONE;
1723 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1725 if (handle == nullptr || extra == nullptr) {
1726 LOGE("Invalid parameter");
1727 return NOTI_EX_ERROR_INVALID_PARAMETER;
1730 shared_ptr<AbstractAction>* ptr =
1731 static_cast<shared_ptr<AbstractAction>*>(handle);
1732 if (!(*ptr)->GetExtra().empty()) {
1733 *extra = strdup((*ptr)->GetExtra().c_str());
1734 if (*extra == nullptr) {
1735 LOGE("Out-of-memory");
1736 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1740 return NOTI_EX_ERROR_NONE;
1743 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1744 noti_ex_item_info_h handle, int *hide_time) {
1745 if (handle == nullptr || hide_time == nullptr) {
1746 LOGE("Invalid parameter");
1747 return NOTI_EX_ERROR_INVALID_PARAMETER;
1749 IItemInfo* p = static_cast<IItemInfo*>(handle);
1750 *hide_time = p->GetHideTime();
1751 return NOTI_EX_ERROR_NONE;
1754 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1755 noti_ex_item_info_h handle, int hide_time) {
1756 if (handle == nullptr) {
1757 LOGE("Invalid parameter");
1758 return NOTI_EX_ERROR_INVALID_PARAMETER;
1760 IItemInfo* p = static_cast<IItemInfo*>(handle);
1761 p->SetHideTime(hide_time);
1762 return NOTI_EX_ERROR_NONE;
1765 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1766 noti_ex_item_info_h handle, int *delete_time) {
1767 if (handle == nullptr || delete_time == nullptr) {
1768 LOGE("Invalid parameter");
1769 return NOTI_EX_ERROR_INVALID_PARAMETER;
1771 IItemInfo* p = static_cast<IItemInfo*>(handle);
1772 *delete_time = p->GetDeleteTime();
1773 return NOTI_EX_ERROR_NONE;
1776 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1777 noti_ex_item_info_h handle, int delete_time) {
1778 if (handle == nullptr) {
1779 LOGE("Invalid parameter");
1780 return NOTI_EX_ERROR_INVALID_PARAMETER;
1782 IItemInfo* p = static_cast<IItemInfo*>(handle);
1783 p->SetDeleteTime(delete_time);
1784 return NOTI_EX_ERROR_NONE;
1787 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1788 noti_ex_item_info_h handle, time_t *time) {
1789 if (handle == nullptr || time == nullptr) {
1790 LOGE("Invalid parameter");
1791 return NOTI_EX_ERROR_INVALID_PARAMETER;
1794 IItemInfo* p = static_cast<IItemInfo*>(handle);
1795 *time = p->GetTime();
1796 return NOTI_EX_ERROR_NONE;
1799 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1800 if (handle == nullptr) {
1801 LOGE("Invalid parameter");
1802 return NOTI_EX_ERROR_INVALID_PARAMETER;
1805 Handle* h = static_cast<Handle*>(handle);
1807 return NOTI_EX_ERROR_NONE;
1810 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1811 const char *id, noti_ex_item_h *item) {
1812 if (handle == nullptr) {
1813 LOGE("Invalid parameter");
1814 return NOTI_EX_ERROR_INVALID_PARAMETER;
1817 Handle* p = static_cast<Handle*>(handle);
1818 AbstractItem& find_item = p->Get()->FindByID(string(id));
1819 *item = new Handle(&find_item);
1820 return NOTI_EX_ERROR_NONE;
1823 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1825 if (handle == nullptr || type == nullptr) {
1826 LOGE("Invalid parameter");
1827 return NOTI_EX_ERROR_INVALID_PARAMETER;
1830 Handle* h = static_cast<Handle*>(handle);
1831 AbstractItem* p = h->Get();
1832 *type = p->GetType();
1833 return NOTI_EX_ERROR_NONE;
1836 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1837 char ***path, int *count) {
1838 if (handle == nullptr || path == nullptr || count == nullptr) {
1839 LOGE("Invalid parameter");
1840 return NOTI_EX_ERROR_INVALID_PARAMETER;
1842 Handle* p = static_cast<Handle*>(handle);
1843 list<string> shared_path = p->Get()->GetSharedPath();
1844 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1845 if (tmp_path == nullptr) {
1846 LOGE("Fail to create items");
1847 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1851 for (auto& i : shared_path) {
1852 tmp_path[idx] = strdup(i.c_str());
1853 if (tmp_path[idx] == nullptr) {
1854 __noti_ex_free_str_array(tmp_path, idx);
1855 LOGE("Out of memory");
1856 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1862 *count = shared_path.size();
1863 return NOTI_EX_ERROR_NONE;
1866 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1868 if (handle == nullptr || id == nullptr) {
1869 LOGE("Invalid parameter");
1870 return NOTI_EX_ERROR_INVALID_PARAMETER;
1872 Handle* h = static_cast<Handle*>(handle);
1873 AbstractItem* p = h->Get();
1874 *id = strdup(p->GetId().c_str());
1875 return NOTI_EX_ERROR_NONE;
1878 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1880 if (handle == nullptr || id == nullptr) {
1881 LOGE("Invalid parameter");
1882 return NOTI_EX_ERROR_INVALID_PARAMETER;
1884 Handle* p = static_cast<Handle*>(handle);
1885 p->Get()->SetId(id);
1886 return NOTI_EX_ERROR_NONE;
1889 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1890 noti_ex_action_h *action) {
1891 if (handle == nullptr || action == nullptr) {
1892 LOGE("Invalid parameter");
1893 return NOTI_EX_ERROR_INVALID_PARAMETER;
1895 Handle* p = static_cast<Handle*>(handle);
1896 if (p->Get()->GetAction() == nullptr) {
1898 return NOTI_EX_ERROR_NONE;
1900 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1901 p->Get()->GetAction()));
1903 return NOTI_EX_ERROR_NONE;
1906 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1907 noti_ex_action_h action) {
1908 if (handle == nullptr || action == nullptr) {
1909 LOGE("Invalid parameter");
1910 return NOTI_EX_ERROR_INVALID_PARAMETER;
1913 Handle* p = static_cast<Handle*>(handle);
1915 shared_ptr<AbstractAction>* ptr =
1916 static_cast<shared_ptr<AbstractAction>*>(action);
1917 p->Get()->SetAction(*ptr);
1918 return NOTI_EX_ERROR_NONE;
1921 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1922 noti_ex_style_h *style) {
1923 if (handle == nullptr || style == nullptr) {
1924 LOGE("Invalid parameter");
1925 return NOTI_EX_ERROR_INVALID_PARAMETER;
1928 Handle* p = static_cast<Handle*>(handle);
1929 shared_ptr<Style> s = p->Get()->GetStyle();
1930 if (s.get() == nullptr) {
1931 LOGE("Style is null");
1932 return NOTI_EX_ERROR_INVALID_PARAMETER;
1935 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1936 if (ptr == nullptr || ptr->get() == nullptr) {
1937 LOGE("Out of memory");
1938 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1942 return NOTI_EX_ERROR_NONE;
1945 extern "C" EXPORT_API int noti_ex_item_set_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 = static_cast<shared_ptr<Style>*>(style);
1954 p->Get()->SetStyle(*s);
1955 return NOTI_EX_ERROR_NONE;
1958 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1960 if (handle == nullptr) {
1961 LOGE("Invalid parameter");
1962 return NOTI_EX_ERROR_INVALID_PARAMETER;
1965 Handle* p = static_cast<Handle*>(handle);
1966 p->Get()->SetVisible(visible);
1967 return NOTI_EX_ERROR_NONE;
1970 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1972 if (handle == nullptr || visible == nullptr) {
1973 LOGE("Invalid parameter");
1974 return NOTI_EX_ERROR_INVALID_PARAMETER;
1977 Handle* p = static_cast<Handle*>(handle);
1978 *visible = p->Get()->GetVisible();
1979 return NOTI_EX_ERROR_NONE;
1982 extern "C" EXPORT_API int noti_ex_item_set_enable(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()->SetEnable(enable);
1991 return NOTI_EX_ERROR_NONE;
1994 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1996 if (handle == nullptr || enable == nullptr) {
1997 LOGE("Invalid parameter");
1998 return NOTI_EX_ERROR_INVALID_PARAMETER;
2001 Handle* p = static_cast<Handle*>(handle);
2002 *enable = p->Get()->GetEnable();
2003 return NOTI_EX_ERROR_NONE;
2006 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2007 const char *receiver_group) {
2008 if (handle == nullptr || receiver_group == nullptr) {
2009 LOGE("Invalid parameter");
2010 return NOTI_EX_ERROR_INVALID_PARAMETER;
2013 Handle* p = static_cast<Handle*>(handle);
2014 p->Get()->AddReceiver(receiver_group);
2015 return NOTI_EX_ERROR_NONE;
2018 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2019 const char *receiver_group) {
2020 if (handle == nullptr || receiver_group == nullptr) {
2021 LOGE("Invalid parameter");
2022 return NOTI_EX_ERROR_INVALID_PARAMETER;
2025 Handle* p = static_cast<Handle*>(handle);
2026 p->Get()->RemoveReceiver(receiver_group);
2027 return NOTI_EX_ERROR_NONE;
2030 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2031 char ***receiver_list, int *count) {
2032 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2033 LOGE("Invalid parameter");
2034 return NOTI_EX_ERROR_INVALID_PARAMETER;
2037 Handle* p = static_cast<Handle*>(handle);
2038 list<string> receivers = p->Get()->GetReceiverList();
2039 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2040 if (tmp_list == nullptr) {
2041 LOGE("Out of memory");
2042 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2046 for (auto& i : receivers) {
2047 tmp_list[idx] = strdup(i.c_str());
2048 if (tmp_list[idx] == nullptr) {
2049 __noti_ex_free_str_array(tmp_list, idx);
2050 LOGE("Out of memory");
2051 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2056 *receiver_list = tmp_list;
2057 *count = receivers.size();
2058 return NOTI_EX_ERROR_NONE;
2061 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2063 if (handle == nullptr) {
2064 LOGE("Invalid parameter");
2065 return NOTI_EX_ERROR_INVALID_PARAMETER;
2068 Handle* p = static_cast<Handle*>(handle);
2069 p->Get()->SetPolicy(policy);
2070 return NOTI_EX_ERROR_NONE;
2073 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2075 if (handle == nullptr || policy == nullptr) {
2076 LOGE("Invalid parameter");
2077 return NOTI_EX_ERROR_INVALID_PARAMETER;
2080 Handle* p = static_cast<Handle*>(handle);
2081 *policy = p->Get()->GetPolicy();
2082 return NOTI_EX_ERROR_NONE;
2085 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2087 if (handle == nullptr || channel == nullptr) {
2088 LOGE("Invalid parameter");
2089 return NOTI_EX_ERROR_INVALID_PARAMETER;
2092 Handle* p = static_cast<Handle*>(handle);
2093 if (!p->Get()->GetChannel().empty())
2094 *channel = strdup(p->Get()->GetChannel().c_str());
2098 return NOTI_EX_ERROR_NONE;
2101 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2102 const char *channel) {
2103 if (handle == nullptr) {
2104 LOGE("Invalid parameter");
2105 return NOTI_EX_ERROR_INVALID_PARAMETER;
2108 Handle* p = static_cast<Handle*>(handle);
2109 p->Get()->SetChannel(channel);
2110 return NOTI_EX_ERROR_NONE;
2113 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2114 noti_ex_led_info_h led) {
2115 if (handle == nullptr) {
2116 LOGE("Invalid parameter");
2117 return NOTI_EX_ERROR_INVALID_PARAMETER;
2120 Handle* p = static_cast<Handle*>(handle);
2121 shared_ptr<LEDInfo>* led_ptr =
2122 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2123 p->Get()->SetLEDInfo(*led_ptr);
2124 return NOTI_EX_ERROR_NONE;
2127 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2128 noti_ex_led_info_h *led) {
2129 if (handle == nullptr) {
2130 LOGE("Invalid parameter");
2131 return NOTI_EX_ERROR_INVALID_PARAMETER;
2134 Handle* p = static_cast<Handle*>(handle);
2135 if (p->Get()->GetLEDInfo() != nullptr)
2136 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2139 return NOTI_EX_ERROR_NONE;
2142 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2144 if (handle == nullptr) {
2145 LOGE("Invalid parameter");
2146 return NOTI_EX_ERROR_INVALID_PARAMETER;
2149 Handle* p = static_cast<Handle*>(handle);
2150 if (path == nullptr)
2151 p->Get()->SetSoundPath("");
2153 p->Get()->SetSoundPath(path);
2154 return NOTI_EX_ERROR_NONE;
2157 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2159 if (handle == nullptr) {
2160 LOGE("Invalid parameter");
2161 return NOTI_EX_ERROR_INVALID_PARAMETER;
2164 Handle* p = static_cast<Handle*>(handle);
2165 if (path == nullptr)
2166 p->Get()->SetVibrationPath("");
2168 p->Get()->SetVibrationPath(path);
2169 return NOTI_EX_ERROR_NONE;
2172 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2174 if (handle == nullptr || path == nullptr) {
2175 LOGE("Invalid parameter");
2176 return NOTI_EX_ERROR_INVALID_PARAMETER;
2179 Handle* p = static_cast<Handle*>(handle);
2180 if (p->Get()->GetSoundPath().empty())
2183 *path = strdup(p->Get()->GetSoundPath().c_str());
2184 return NOTI_EX_ERROR_NONE;
2187 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2189 if (handle == nullptr || path == nullptr) {
2190 LOGE("Invalid parameter");
2191 return NOTI_EX_ERROR_INVALID_PARAMETER;
2194 Handle* p = static_cast<Handle*>(handle);
2195 if (p->Get()->GetVibrationPath().empty())
2198 *path = strdup(p->Get()->GetVibrationPath().c_str());
2199 return NOTI_EX_ERROR_NONE;
2202 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2203 noti_ex_item_info_h *info) {
2204 if (handle == nullptr || info == nullptr) {
2205 LOGE("Invalid parameter");
2206 return NOTI_EX_ERROR_INVALID_PARAMETER;
2209 Handle* p = static_cast<Handle*>(handle);
2210 if (p->Get()->GetInfo() == nullptr)
2213 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2214 return NOTI_EX_ERROR_NONE;
2217 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2219 if (handle == nullptr || id == nullptr) {
2220 LOGE("Invalid parameter");
2221 return NOTI_EX_ERROR_INVALID_PARAMETER;
2224 Handle* p = static_cast<Handle*>(handle);
2225 if (p->Get()->GetSenderAppId().empty())
2228 *id = strdup(p->Get()->GetSenderAppId().c_str());
2229 return NOTI_EX_ERROR_NONE;
2232 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2234 if (handle == nullptr || tag == nullptr) {
2235 LOGE("Invalid parameter");
2236 return NOTI_EX_ERROR_INVALID_PARAMETER;
2239 Handle* p = static_cast<Handle*>(handle);
2240 if (p->Get()->GetTag().empty())
2243 *tag = strdup(p->Get()->GetTag().c_str());
2244 return NOTI_EX_ERROR_NONE;
2247 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2249 if (handle == nullptr) {
2250 LOGE("Invalid parameter");
2251 return NOTI_EX_ERROR_INVALID_PARAMETER;
2254 Handle* p = static_cast<Handle*>(handle);
2256 p->Get()->SetTag("");
2258 p->Get()->SetTag(tag);
2259 return NOTI_EX_ERROR_NONE;
2262 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2264 if (handle == nullptr || ongoing == nullptr) {
2265 LOGE("Invalid parameter");
2266 return NOTI_EX_ERROR_INVALID_PARAMETER;
2269 Handle* p = static_cast<Handle*>(handle);
2270 *ongoing = p->Get()->GetOnGoingState();
2272 return NOTI_EX_ERROR_NONE;
2275 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2277 if (handle == nullptr) {
2278 LOGE("Invalid parameter");
2279 return NOTI_EX_ERROR_INVALID_PARAMETER;
2282 Handle* p = static_cast<Handle*>(handle);
2283 p->Get()->SetOnGoingState(ongoing);
2285 return NOTI_EX_ERROR_NONE;
2288 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2289 int type, bool* exist) {
2290 if (handle == nullptr || exist == nullptr) {
2291 LOGE("Invalid parameter");
2292 return NOTI_EX_ERROR_INVALID_PARAMETER;
2295 Handle* p = static_cast<Handle*>(handle);
2296 *exist = p->Get()->IsItemTypeExist(type);
2298 return NOTI_EX_ERROR_NONE;
2301 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2303 if (handle == nullptr || type == nullptr) {
2304 LOGE("Invalid parameter");
2305 return NOTI_EX_ERROR_INVALID_PARAMETER;
2308 Handle* p = static_cast<Handle*>(handle);
2309 *type = p->Get()->GetMainType();
2311 return NOTI_EX_ERROR_NONE;
2314 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2315 const char* id, int type) {
2316 if (handle == nullptr || id == nullptr) {
2317 LOGE("Invalid parameter");
2318 return NOTI_EX_ERROR_INVALID_PARAMETER;
2321 Handle* p = static_cast<Handle*>(handle);
2322 if (!(p->Get()->SetMainType(string(id),
2323 static_cast<AbstractItem::MainType>(type))))
2324 return NOTI_EX_ERROR_INVALID_PARAMETER;
2326 return NOTI_EX_ERROR_NONE;
2329 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2330 int type, noti_ex_item_h* item) {
2331 if (handle == nullptr || item == nullptr) {
2332 LOGE("Invalid parameter");
2333 return NOTI_EX_ERROR_INVALID_PARAMETER;
2336 Handle* h = static_cast<Handle*>(handle);
2337 if (!h->IsValidType(AbstractItem::Group)) {
2338 LOGE("Invalid handle type");
2339 return NOTI_EX_ERROR_INVALID_PARAMETER;
2342 GroupItem* p = static_cast<GroupItem*>(h->Get());
2343 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2344 *item = new Handle(&find_item);
2346 return NOTI_EX_ERROR_NONE;
2349 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2350 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2352 if (handle == nullptr) {
2353 LOGE("Invalid parameter");
2354 return NOTI_EX_ERROR_INVALID_PARAMETER;
2357 string receiver_group_str = "";
2359 receiver_group_str = string(receiver_group);
2361 ManagerStub* stub = new (std::nothrow) ManagerStub(
2362 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2363 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2364 receiver_group_str);
2365 if (stub == nullptr) {
2366 LOGE("Fail to create manager");
2367 return NOTI_EX_ERROR_IO_ERROR;
2369 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2370 new ManagerCallbackInfo(event_callbacks, data)));
2371 *handle = static_cast<noti_ex_manager_h>(stub);
2373 return NOTI_EX_ERROR_NONE;
2376 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2377 if (handle == nullptr) {
2378 LOGE("Invalid parameter");
2379 return NOTI_EX_ERROR_INVALID_PARAMETER;
2381 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2383 return NOTI_EX_ERROR_NONE;
2386 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2387 noti_ex_item_h **items, int *count) {
2388 if (handle == nullptr || items == nullptr || count == nullptr) {
2389 LOGE("Invalid parameter");
2390 return NOTI_EX_ERROR_INVALID_PARAMETER;
2394 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2395 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2396 if (item_list.size() == 0) {
2399 return NOTI_EX_ERROR_NONE;
2401 noti_ex_item_h* added_item =
2402 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2403 if (added_item == nullptr) {
2404 LOGE("Fail to create items");
2405 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2409 for (auto& i : item_list) {
2410 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2412 *items = added_item;
2413 *count = item_list.size();
2414 } catch (Exception &ex) {
2415 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2416 return NOTI_EX_ERROR_IO_ERROR;
2418 return NOTI_EX_ERROR_NONE;
2421 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2422 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2423 if (handle == nullptr || channel == nullptr ||
2424 items == nullptr || count == nullptr) {
2425 LOGE("Invalid parameter");
2426 return NOTI_EX_ERROR_INVALID_PARAMETER;
2430 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2431 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2432 if (item_list.size() == 0) {
2435 return NOTI_EX_ERROR_NONE;
2437 noti_ex_item_h* added_item =
2438 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2439 if (added_item == nullptr) {
2440 LOGE("Fail to create items");
2441 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2445 for (auto& i : item_list) {
2446 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2448 *items = added_item;
2449 *count = item_list.size();
2450 } catch (Exception &ex) {
2451 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2452 return NOTI_EX_ERROR_IO_ERROR;
2455 return NOTI_EX_ERROR_NONE;
2458 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2459 noti_ex_item_h noti, int *request_id) {
2460 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2461 LOGE("Invalid parameter");
2462 return NOTI_EX_ERROR_INVALID_PARAMETER;
2465 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2466 Handle* sp = static_cast<Handle*>(noti);
2467 if (sp->GetPtr().get() == nullptr) {
2468 LOGE("Invalid noti reference can not be sended");
2469 return NOTI_EX_ERROR_INVALID_PARAMETER;
2471 *request_id = stub->Update(sp->GetPtr());
2473 } catch (Exception &ex) {
2474 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2475 return NOTI_EX_ERROR_IO_ERROR;
2477 return NOTI_EX_ERROR_NONE;
2480 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2481 noti_ex_item_h noti, int *request_id) {
2482 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2483 LOGE("Invalid parameter");
2484 return NOTI_EX_ERROR_INVALID_PARAMETER;
2487 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2488 Handle* item = static_cast<Handle*>(noti);
2489 if (item->GetPtr().get() == nullptr) {
2490 LOGE("Invalid noti reference can not be sended");
2491 return NOTI_EX_ERROR_INVALID_PARAMETER;
2493 *request_id = stub->Delete(item->GetPtr());
2495 } catch (Exception &ex) {
2496 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2497 return NOTI_EX_ERROR_IO_ERROR;
2499 return NOTI_EX_ERROR_NONE;
2502 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2504 if (handle == nullptr || request_id == nullptr) {
2505 LOGE("Invalid parameter");
2506 return NOTI_EX_ERROR_INVALID_PARAMETER;
2509 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2510 *request_id = stub->DeleteAll();
2511 } catch (Exception &ex) {
2512 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2513 return NOTI_EX_ERROR_IO_ERROR;
2515 return NOTI_EX_ERROR_NONE;
2518 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2519 noti_ex_item_h noti, int *request_id) {
2520 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2521 LOGE("Invalid parameter");
2522 return NOTI_EX_ERROR_INVALID_PARAMETER;
2525 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2526 Handle* item = static_cast<Handle*>(noti);
2527 if (item->GetPtr().get() == nullptr) {
2528 LOGE("Invalid noti reference can not be sended");
2529 return NOTI_EX_ERROR_INVALID_PARAMETER;
2531 *request_id = stub->Hide(item->GetPtr());
2533 } catch (Exception &ex) {
2534 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2535 return NOTI_EX_ERROR_IO_ERROR;
2537 return NOTI_EX_ERROR_NONE;
2540 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2541 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2542 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2543 LOGE("Invalid parameter");
2544 return NOTI_EX_ERROR_INVALID_PARAMETER;
2547 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2548 *item = new Handle(stub->FindByRootID(root_id));
2549 } catch (Exception &ex) {
2550 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2551 return NOTI_EX_ERROR_IO_ERROR;
2553 return NOTI_EX_ERROR_NONE;
2556 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2557 noti_ex_event_info_h info, noti_ex_error_e error) {
2558 if (handle == nullptr || info == nullptr) {
2559 LOGE("Invalid parameter");
2560 return NOTI_EX_ERROR_INVALID_PARAMETER;
2563 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2564 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2565 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2566 static_cast<NotificationError>(error));
2567 } catch (Exception &ex) {
2568 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2569 return NOTI_EX_ERROR_IO_ERROR;
2571 return NOTI_EX_ERROR_NONE;
2574 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2575 noti_ex_manager_h handle, int *cnt) {
2577 if (handle == nullptr || cnt == nullptr) {
2578 LOGE("Invalid parameter");
2579 return NOTI_EX_ERROR_INVALID_PARAMETER;
2582 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2583 *cnt = stub->GetCount();
2584 } catch (Exception &ex) {
2585 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2586 return NOTI_EX_ERROR_IO_ERROR;
2588 return NOTI_EX_ERROR_NONE;
2591 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2592 const char *id, float min, float current, float max) {
2595 if (handle == nullptr) {
2596 LOGE("Invalid parameter");
2597 return NOTI_EX_ERROR_INVALID_PARAMETER;
2601 p = new (std::nothrow) ProgressItem(id, min, current, max);
2603 p = new (std::nothrow) ProgressItem(min, current, max);
2606 LOGE("Out-of-memory");
2607 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2610 *handle = new Handle(shared_ptr<AbstractItem>(p));
2612 return NOTI_EX_ERROR_NONE;
2615 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2616 noti_ex_item_h handle, float *current) {
2617 if (handle == nullptr || current == nullptr) {
2618 LOGE("Invalid parameter");
2619 return NOTI_EX_ERROR_INVALID_PARAMETER;
2622 Handle *h = static_cast<Handle*>(handle);
2623 if (!h->IsValidType(AbstractItem::Progress)) {
2624 LOGE("Invalid handle type");
2625 return NOTI_EX_ERROR_INVALID_PARAMETER;
2627 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2628 *current = p->GetCurrent();
2630 return NOTI_EX_ERROR_NONE;
2633 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2634 noti_ex_item_h handle, float current) {
2635 if (handle == nullptr) {
2636 LOGE("Invalid parameter");
2637 return NOTI_EX_ERROR_INVALID_PARAMETER;
2640 Handle *h = static_cast<Handle*>(handle);
2641 if (!h->IsValidType(AbstractItem::Progress)) {
2642 LOGE("Invalid handle type");
2643 return NOTI_EX_ERROR_INVALID_PARAMETER;
2645 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2646 p->SetCurrent(current);
2648 return NOTI_EX_ERROR_NONE;
2651 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2653 if (handle == nullptr || min == nullptr) {
2654 LOGE("Invalid parameter");
2655 return NOTI_EX_ERROR_INVALID_PARAMETER;
2658 Handle *h = static_cast<Handle*>(handle);
2659 if (!h->IsValidType(AbstractItem::Progress)) {
2660 LOGE("Invalid handle type");
2661 return NOTI_EX_ERROR_INVALID_PARAMETER;
2663 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2666 return NOTI_EX_ERROR_NONE;
2669 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2671 if (handle == nullptr || max == nullptr) {
2672 LOGE("Invalid parameter");
2673 return NOTI_EX_ERROR_INVALID_PARAMETER;
2676 Handle *h = static_cast<Handle*>(handle);
2677 if (!h->IsValidType(AbstractItem::Progress)) {
2678 LOGE("Invalid handle type");
2679 return NOTI_EX_ERROR_INVALID_PARAMETER;
2681 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2684 return NOTI_EX_ERROR_NONE;
2687 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2689 if (handle == nullptr || type == nullptr) {
2690 LOGE("Invalid parameter");
2691 return NOTI_EX_ERROR_INVALID_PARAMETER;
2694 Handle *h = static_cast<Handle*>(handle);
2695 if (!h->IsValidType(AbstractItem::Progress)) {
2696 LOGE("Invalid handle type");
2697 return NOTI_EX_ERROR_INVALID_PARAMETER;
2699 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2700 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2702 return NOTI_EX_ERROR_NONE;
2705 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2707 if (handle == nullptr) {
2708 LOGE("Invalid parameter");
2709 return NOTI_EX_ERROR_INVALID_PARAMETER;
2712 Handle *h = static_cast<Handle*>(handle);
2713 if (!h->IsValidType(AbstractItem::Progress)) {
2714 LOGE("Invalid handle type");
2715 return NOTI_EX_ERROR_INVALID_PARAMETER;
2717 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2718 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2720 return NOTI_EX_ERROR_NONE;
2723 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2724 noti_ex_reporter_events_s event_callbacks, void *data) {
2725 if (handle == nullptr) {
2726 LOGE("Invalid parameter");
2727 return NOTI_EX_ERROR_INVALID_PARAMETER;
2730 ReporterStub* stub = new (std::nothrow) ReporterStub(
2731 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2732 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2733 if (stub == nullptr) {
2734 LOGE("Fail to create manager");
2735 return NOTI_EX_ERROR_IO_ERROR;
2737 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2738 new ReporterCallbackInfo(event_callbacks, data)));
2740 *handle = static_cast<noti_ex_reporter_h>(stub);
2742 return NOTI_EX_ERROR_NONE;
2745 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2746 if (handle == nullptr) {
2747 LOGE("Invalid parameter");
2748 return NOTI_EX_ERROR_INVALID_PARAMETER;
2750 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2752 return NOTI_EX_ERROR_NONE;
2755 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2756 noti_ex_event_info_h info, noti_ex_error_e error) {
2757 if (handle == nullptr || info == nullptr) {
2758 LOGE("Invalid parameter");
2759 return NOTI_EX_ERROR_INVALID_PARAMETER;
2762 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2763 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2764 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2765 static_cast<NotificationError>(error));
2766 } catch (Exception &ex) {
2767 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2768 return NOTI_EX_ERROR_IO_ERROR;
2770 return NOTI_EX_ERROR_NONE;
2773 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2774 noti_ex_item_h noti, int *request_id) {
2775 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2776 LOGE("Invalid parameter");
2777 return NOTI_EX_ERROR_INVALID_PARAMETER;
2780 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2781 Handle* h = static_cast<Handle*>(noti);
2782 if (h->GetPtr().get() == nullptr) {
2783 LOGE("Invalid noti reference can not be sended");
2784 return NOTI_EX_ERROR_INVALID_PARAMETER;
2786 *request_id = stub->Post(h->GetPtr());
2788 } catch (Exception &ex) {
2789 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2790 return NOTI_EX_ERROR_IO_ERROR;
2792 return NOTI_EX_ERROR_NONE;
2795 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2796 noti_ex_item_h *noti_list, int count, int *request_id) {
2798 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2799 LOGE("Invalid parameter");
2800 return NOTI_EX_ERROR_INVALID_PARAMETER;
2803 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2804 list<shared_ptr<item::AbstractItem>> notiList;
2805 for (int i = 0; i < count; i++) {
2806 Handle* item = static_cast<Handle*>(noti_list[i]);
2807 notiList.push_back(item->GetPtr());
2809 *request_id = stub->Post(notiList);
2810 } catch (Exception &ex) {
2811 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2812 return NOTI_EX_ERROR_IO_ERROR;
2814 return NOTI_EX_ERROR_NONE;
2817 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2818 noti_ex_item_h noti, int *request_id) {
2819 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2820 LOGE("Invalid parameter");
2821 return NOTI_EX_ERROR_INVALID_PARAMETER;
2824 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2825 Handle* item = static_cast<Handle*>(noti);
2826 if (item->GetPtr().get() == nullptr) {
2827 LOGE("Invalid noti reference can not be sended");
2828 return NOTI_EX_ERROR_INVALID_PARAMETER;
2830 *request_id = stub->Update(item->GetPtr());
2832 } catch (Exception &ex) {
2833 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2834 return NOTI_EX_ERROR_IO_ERROR;
2836 return NOTI_EX_ERROR_NONE;
2839 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2840 noti_ex_item_h noti, int *request_id) {
2841 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2842 LOGE("Invalid parameter");
2843 return NOTI_EX_ERROR_INVALID_PARAMETER;
2846 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2847 Handle* item = static_cast<Handle*>(noti);
2848 if (item->GetPtr().get() == nullptr) {
2849 LOGE("Invalid noti reference can not be sended");
2850 return NOTI_EX_ERROR_INVALID_PARAMETER;
2852 *request_id = stub->Delete(item->GetPtr());
2854 } catch (Exception &ex) {
2855 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2856 return NOTI_EX_ERROR_IO_ERROR;
2858 return NOTI_EX_ERROR_NONE;
2861 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2862 noti_ex_reporter_h handle, int *request_id) {
2863 if (handle == nullptr || request_id == nullptr) {
2864 LOGE("Invalid parameter");
2865 return NOTI_EX_ERROR_INVALID_PARAMETER;
2868 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2869 *request_id = stub->DeleteAll();
2870 } catch (Exception &ex) {
2871 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2872 return NOTI_EX_ERROR_IO_ERROR;
2874 return NOTI_EX_ERROR_NONE;
2877 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2878 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2879 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2880 LOGE("Invalid parameter");
2881 return NOTI_EX_ERROR_INVALID_PARAMETER;
2884 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2885 *item = new Handle(stub->FindByRootID(root_id));
2886 } catch (Exception &ex) {
2887 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2888 return NOTI_EX_ERROR_IO_ERROR;
2890 return NOTI_EX_ERROR_NONE;
2893 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2894 const char *id, const char *text, const char *hyperlink) {
2895 if (handle == nullptr || text == nullptr) {
2896 LOGE("Invalid parameter");
2897 return NOTI_EX_ERROR_INVALID_PARAMETER;
2903 p = new (std::nothrow) TextItem(id, std::string(text),
2904 std::string(hyperlink));
2906 p = new (std::nothrow) TextItem(id, std::string(text));
2909 LOGE("Out-of-memory");
2910 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2913 *handle = new Handle(shared_ptr<AbstractItem>(p));
2915 return NOTI_EX_ERROR_NONE;
2918 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2919 const char *contents) {
2920 if (handle == nullptr || contents == nullptr) {
2921 LOGE("Invalid parameter");
2922 return NOTI_EX_ERROR_INVALID_PARAMETER;
2925 Handle* p = static_cast<Handle*>(handle);
2926 if (!p->IsValidType(AbstractItem::Text)) {
2927 LOGE("Invalid handle type");
2928 return NOTI_EX_ERROR_INVALID_PARAMETER;
2930 TextItem* ti = static_cast<TextItem*>(p->Get());
2931 ti->SetContents(std::string(contents));
2933 return NOTI_EX_ERROR_NONE;
2936 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2938 if (handle == nullptr || contents == nullptr) {
2939 LOGE("Invalid parameter");
2940 return NOTI_EX_ERROR_INVALID_PARAMETER;
2943 Handle* p = static_cast<Handle*>(handle);
2944 if (!p->IsValidType(AbstractItem::Text)) {
2945 LOGE("Invalid handle type");
2946 return NOTI_EX_ERROR_INVALID_PARAMETER;
2949 TextItem* ti = static_cast<TextItem*>(p->Get());
2951 if (ti->GetMultiLanguage() != nullptr &&
2952 !ti->GetMultiLanguage()->GetTranslatedString().empty())
2953 str = ti->GetMultiLanguage()->GetTranslatedString();
2954 else if (!ti->GetContents().empty())
2955 str = ti->GetContents();
2957 *contents = strdup(str.c_str());
2958 if (*contents == nullptr) {
2959 LOGE("Out-of-memory");
2960 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2963 return NOTI_EX_ERROR_NONE;
2966 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2967 noti_ex_item_h handle, char **hyper_link) {
2968 if (handle == nullptr || hyper_link == nullptr) {
2969 LOGE("Invalid parameter");
2970 return NOTI_EX_ERROR_INVALID_PARAMETER;
2973 Handle* p = static_cast<Handle*>(handle);
2974 if (!p->IsValidType(AbstractItem::Text)) {
2975 LOGE("Invalid handle type");
2976 return NOTI_EX_ERROR_INVALID_PARAMETER;
2978 TextItem* ti = static_cast<TextItem*>(p->Get());
2979 if (!ti->GetHyperLink().empty()) {
2980 *hyper_link = strdup(ti->GetHyperLink().c_str());
2981 if (*hyper_link == nullptr) {
2982 LOGE("Out-of-memory");
2983 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2987 return NOTI_EX_ERROR_NONE;
2990 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
2991 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
2992 if (handle == 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;
3003 TextItem* ti = static_cast<TextItem*>(p->Get());
3004 if (multi == nullptr) {
3005 ti->SetMultiLanguage(nullptr);
3006 return NOTI_EX_ERROR_NONE;
3009 shared_ptr<MultiLanguage> mul_ptr =
3010 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3011 ti->SetMultiLanguage(mul_ptr);
3012 ti->GetMultiLanguage()->UpdateString();
3014 return NOTI_EX_ERROR_NONE;
3017 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3018 const char *id, time_t time) {
3021 if (handle == nullptr) {
3022 LOGE("Invalid parameter");
3023 return NOTI_EX_ERROR_INVALID_PARAMETER;
3028 p = new (std::nothrow) TimeItem(id, time);
3030 p = new (std::nothrow) TimeItem(time);
3032 p = new (std::nothrow) TimeItem();
3036 LOGE("Out-of-memory");
3037 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3040 *handle = new Handle(shared_ptr<AbstractItem>(p));
3042 return NOTI_EX_ERROR_NONE;
3045 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3047 if (handle == nullptr || time == nullptr) {
3048 LOGE("Invalid parameter");
3049 return NOTI_EX_ERROR_INVALID_PARAMETER;
3051 Handle* h = static_cast<Handle*>(handle);
3052 if (!h->IsValidType(AbstractItem::Time)) {
3053 LOGE("Invalid handle type");
3054 return NOTI_EX_ERROR_INVALID_PARAMETER;
3056 TimeItem* p = static_cast<TimeItem*>(h->Get());
3057 *time = p->GetTime();
3059 return NOTI_EX_ERROR_NONE;
3062 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3063 noti_ex_action_h *handle, const char *extra) {
3064 if (handle == nullptr) {
3065 LOGE("Invalid parameter");
3066 return NOTI_EX_ERROR_INVALID_PARAMETER;
3069 string extra_str = "";
3071 extra_str = string(extra);
3073 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3074 new (std::nothrow) VisibilityAction(extra_str));
3075 if (ptr == nullptr) {
3076 LOGE("Out-of-memory");
3077 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3082 return NOTI_EX_ERROR_NONE;
3085 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3086 const char *id, bool visible) {
3087 if (handle == nullptr || id == nullptr) {
3088 LOGE("Invalid parameter");
3089 return NOTI_EX_ERROR_INVALID_PARAMETER;
3092 shared_ptr<AbstractAction>* ptr =
3093 static_cast<shared_ptr<AbstractAction>*>(handle);
3094 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3095 action->SetVisibility(id, visible);
3097 return NOTI_EX_ERROR_NONE;
3100 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3101 const char* msgid, const char* format, ...) {
3102 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3103 LOGE("Invalid parameter");
3104 return NOTI_EX_ERROR_INVALID_PARAMETER;
3107 const char* format_idx = format;
3110 va_start(args, format);
3111 while (*format_idx != '\0') {
3112 char* arg = nullptr;
3115 stringstream stream;
3116 if (*format_idx == '%') {
3117 switch (*(format_idx + 1)) {
3119 arg = va_arg(args, char *);
3120 arr.push_back(string(arg));
3123 arg_i = va_arg(args, int);
3124 arr.push_back(to_string(arg_i));
3127 arg_f = va_arg(args, double);
3128 stream << std::fixed << std::setprecision(2) << arg_f;
3129 arr.push_back(stream.str());
3137 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3139 LOGE("Out-of-memory");
3140 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3142 *handle = new shared_ptr<MultiLanguage>(p);
3144 return NOTI_EX_ERROR_NONE;
3147 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3148 if (handle == nullptr) {
3149 LOGE("Invalid parameter");
3150 return NOTI_EX_ERROR_INVALID_PARAMETER;
3153 shared_ptr<MultiLanguage>* mul_ptr =
3154 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3156 return NOTI_EX_ERROR_NONE;