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"
58 #include "notification-ex/iitem_info_internal.h"
63 #define LOG_TAG "NOTIFICATION_EX"
68 #define EXPORT_API __attribute__((visibility("default")))
71 using namespace tizen_base;
72 using namespace notification::item;
73 using namespace notification;
79 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
80 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
81 : ref_(nullptr), ptr_(move(ptr)) { }
82 virtual ~Handle() = default;
83 item::AbstractItem* Get() const {
89 bool IsValidType(int type) const {
90 return (Get()->GetType() == type
91 || Get()->GetType() >= AbstractItem::Custom);
94 std::shared_ptr<item::AbstractItem> GetPtr() const {
96 return std::shared_ptr<item::AbstractItem>({});
101 item::AbstractItem* ref_;
102 std::shared_ptr<item::AbstractItem> ptr_;
105 class ManagerCallbackInfo {
107 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
108 : user_data_(user_data) {
109 cb_.added = cb.added;
110 cb_.updated = cb.updated;
111 cb_.deleted = cb.deleted;
112 cb_.error = cb.error;
115 void InvokeAdded(Manager* manager, const IEventInfo& info,
116 list<shared_ptr<AbstractItem>> addedItem) {
117 if (cb_.added == nullptr)
119 noti_ex_item_h* added_item =
120 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
121 if (added_item == nullptr) {
122 LOGE("Out of memory");
127 for (auto& i : addedItem) {
129 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
132 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
133 cb_.added(static_cast<noti_ex_manager_h>(manager),
134 static_cast<noti_ex_event_info_h>(c_info), added_item,
135 addedItem.size(), user_data_);
139 void InvokeUpdated(Manager* manager, const IEventInfo& info,
140 shared_ptr<item::AbstractItem> updatedItem) {
141 if (cb_.updated == nullptr)
143 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
144 cb_.updated(static_cast<noti_ex_manager_h>(manager),
145 static_cast<noti_ex_event_info_h>(c_info),
146 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
149 void InvokeDeleted(Manager* manager, const IEventInfo& info,
150 shared_ptr<item::AbstractItem> deletedItem) {
151 if (cb_.deleted == nullptr)
153 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
154 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
155 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
156 static_cast<noti_ex_event_info_h>(c_info),
157 nullptr, user_data_);
159 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
160 static_cast<noti_ex_event_info_h>(c_info),
161 static_cast<noti_ex_item_h>(
162 new Handle(deletedItem)), user_data_);
166 void InvokeError(Manager* manager, NotificationError error, int requestId) {
167 if (cb_.error == nullptr)
169 cb_.error(static_cast<noti_ex_manager_h>(manager),
170 static_cast<noti_ex_error_e>(error), requestId, user_data_);
174 noti_ex_manager_events_s cb_;
178 class ManagerStub : public Manager {
180 ManagerStub(std::unique_ptr<IEventSender> sender,
181 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
182 : Manager(move(sender), move(listener), receiver_group) {
185 void OnAdd(const IEventInfo& info,
186 list<shared_ptr<AbstractItem>> addedItem) override {
187 cb_->InvokeAdded(this, info, addedItem);
190 void OnUpdate(const IEventInfo& info,
191 std::shared_ptr<item::AbstractItem> updatedItem) override {
192 cb_->InvokeUpdated(this, info, updatedItem);
195 void OnDelete(const IEventInfo& info,
196 shared_ptr<item::AbstractItem> deletedItem) override {
197 cb_->InvokeDeleted(this, info, deletedItem);
200 void OnError(NotificationError error, int requestId) override {
201 cb_->InvokeError(this, error, requestId);
204 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
206 return NOTI_EX_ERROR_NONE;
209 int ClearManagerCallbackInfo() {
211 return NOTI_EX_ERROR_NONE;
215 unique_ptr<ManagerCallbackInfo> cb_;
219 class ReporterCallbackInfo {
221 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
222 : user_data_(user_data) {
223 cb_.event = cb.event;
224 cb_.error = cb.error;
227 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
228 list<shared_ptr<AbstractItem>> notiList) {
229 if (cb_.event == nullptr)
231 noti_ex_item_h* noti_list =
232 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
233 if (noti_list == nullptr) {
234 LOGE("Out of memory");
239 for (auto& i : notiList) {
241 static_cast<noti_ex_item_h>(new Handle(i));
244 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
245 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
246 static_cast<noti_ex_event_info_h>(c_info), noti_list,
247 notiList.size(), user_data_);
251 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
252 if (cb_.error == nullptr)
254 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
255 static_cast<noti_ex_error_e>(error), requestId, user_data_);
259 noti_ex_reporter_events_s cb_;
263 class ReporterStub : public Reporter {
265 ReporterStub(std::unique_ptr<IEventSender> sender,
266 std::unique_ptr<IEventListener> listener)
267 : Reporter(move(sender), move(listener)) {
270 void OnEvent(const IEventInfo& info,
271 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
272 cb_->InvokeEvent(this, info, notiList);
275 void OnError(NotificationError error, int requestId) override {
276 cb_->InvokeError(this, error, requestId);
279 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
281 return NOTI_EX_ERROR_NONE;
284 int ClearReporterCallbackInfo() {
286 return NOTI_EX_ERROR_NONE;
290 unique_ptr<ReporterCallbackInfo> cb_;
295 void __noti_ex_free_str_array(char** val, int length) {
297 for (i = 0; i < length ; i++)
302 extern "C" EXPORT_API int noti_ex_action_app_control_create(
303 noti_ex_action_h *handle, app_control_h app_control,
305 if (handle == nullptr || app_control == nullptr) {
306 LOGE("Invalid parameter");
307 return NOTI_EX_ERROR_INVALID_PARAMETER;
310 shared_ptr<AbstractAction>* p;
313 p = new (std::nothrow) shared_ptr<AbstractAction>(
314 new (std::nothrow) AppControlAction(app_control, extra));
316 p = new (std::nothrow) shared_ptr<AbstractAction>(
317 new (std::nothrow) AppControlAction(app_control));
321 LOGE("Out-of-memory");
322 return NOTI_EX_ERROR_OUT_OF_MEMORY;
327 return NOTI_EX_ERROR_NONE;
330 extern "C" EXPORT_API int noti_ex_action_app_control_set(
331 noti_ex_action_h handle, app_control_h app_control) {
332 if (handle == nullptr || app_control == nullptr) {
333 LOGE("Invalid parameter");
334 return NOTI_EX_ERROR_INVALID_PARAMETER;
337 shared_ptr<AbstractAction>* ptr =
338 static_cast<shared_ptr<AbstractAction>*>(handle);
339 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
340 action->SetAppControl(app_control);
342 return NOTI_EX_ERROR_NONE;
345 extern "C" EXPORT_API int noti_ex_action_app_control_get(
346 noti_ex_action_h handle, app_control_h *app_control) {
347 if (handle == nullptr || app_control == nullptr) {
348 LOGE("Invalid parameter");
349 return NOTI_EX_ERROR_INVALID_PARAMETER;
352 shared_ptr<AbstractAction>* ptr =
353 static_cast<shared_ptr<AbstractAction>*>(handle);
354 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
355 *app_control = action->GetAppControl();
357 return NOTI_EX_ERROR_NONE;
360 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
361 const char *id, const char *title) {
364 if (handle == nullptr || title == nullptr) {
365 LOGE("Invalid parameter");
366 return NOTI_EX_ERROR_INVALID_PARAMETER;
370 p = new (std::nothrow) ButtonItem(id, title);
372 p = new (std::nothrow) ButtonItem(title);
375 LOGE("Out-of-memory");
376 return NOTI_EX_ERROR_OUT_OF_MEMORY;
378 *handle = new Handle(shared_ptr<AbstractItem>(p));
380 return NOTI_EX_ERROR_NONE;
383 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
385 if (handle == nullptr || title == nullptr) {
386 LOGE("Invalid parameter");
387 return NOTI_EX_ERROR_INVALID_PARAMETER;
390 Handle* sp = static_cast<Handle*>(handle);
391 if (!sp->IsValidType(AbstractItem::Button)) {
392 LOGE("Invalid handle type");
393 return NOTI_EX_ERROR_INVALID_PARAMETER;
396 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
398 if (p->GetMultiLanguage() != nullptr &&
399 !p->GetMultiLanguage()->GetTranslatedString().empty())
400 str = p->GetMultiLanguage()->GetTranslatedString();
401 else if (!p->GetTitle().empty())
404 *title = strdup(str.c_str());
405 if (*title == nullptr) {
406 LOGE("Out-of-memory");
407 return NOTI_EX_ERROR_OUT_OF_MEMORY;
410 return NOTI_EX_ERROR_NONE;
413 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
414 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
415 if (handle == nullptr) {
416 LOGE("Invalid parameter");
417 return NOTI_EX_ERROR_INVALID_PARAMETER;
420 Handle* p = static_cast<Handle*>(handle);
421 if (!p->IsValidType(AbstractItem::Button)) {
422 LOGE("Invalid handle type");
423 return NOTI_EX_ERROR_INVALID_PARAMETER;
426 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
427 if (multi == nullptr) {
428 bi->SetMultiLanguage(nullptr);
429 return NOTI_EX_ERROR_NONE;
432 shared_ptr<MultiLanguage> mul_ptr =
433 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
435 mul_ptr->UpdateString();
436 bi->SetMultiLanguage(mul_ptr);
438 return NOTI_EX_ERROR_NONE;
441 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
442 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
443 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
444 noti_ex_item_chat_message_type_e message_type) {
445 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
446 LOGE("Invalid parameter");
447 return NOTI_EX_ERROR_INVALID_PARAMETER;
450 auto* p = new (std::nothrow) ChatMessageItem(id,
451 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
452 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
453 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
454 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
455 static_cast<ChatMessageItem::Type>(message_type));
457 LOGE("Out-of-memory");
458 return NOTI_EX_ERROR_OUT_OF_MEMORY;
461 *handle = new Handle(shared_ptr<AbstractItem>(p));
463 return NOTI_EX_ERROR_NONE;
466 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
467 noti_ex_item_h handle, noti_ex_item_h *name) {
468 if (handle == nullptr || name == nullptr) {
469 LOGE("Invalid parameter");
470 return NOTI_EX_ERROR_INVALID_PARAMETER;
472 Handle* h = static_cast<Handle*>(handle);
473 if (!h->IsValidType(AbstractItem::ChatMessage)) {
474 LOGE("Invalid handle type");
475 return NOTI_EX_ERROR_INVALID_PARAMETER;
477 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
478 *name = new Handle(&(p->GetNameItem()));
480 return NOTI_EX_ERROR_NONE;
483 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
484 noti_ex_item_h handle, noti_ex_item_h *text) {
485 if (handle == nullptr || text == nullptr) {
486 LOGE("Invalid parameter");
487 return NOTI_EX_ERROR_INVALID_PARAMETER;
490 Handle* h = static_cast<Handle*>(handle);
491 if (!h->IsValidType(AbstractItem::ChatMessage)) {
492 LOGE("Invalid handle type");
493 return NOTI_EX_ERROR_INVALID_PARAMETER;
495 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
496 *text = new Handle(&(p->GetTextItem()));
498 return NOTI_EX_ERROR_NONE;
501 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
502 noti_ex_item_h handle, noti_ex_item_h *image) {
503 if (handle == nullptr || image == nullptr) {
504 LOGE("Invalid parameter");
505 return NOTI_EX_ERROR_INVALID_PARAMETER;
508 Handle* h = static_cast<Handle*>(handle);
509 if (!h->IsValidType(AbstractItem::ChatMessage)) {
510 LOGE("Invalid handle type");
511 return NOTI_EX_ERROR_INVALID_PARAMETER;
513 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
514 *image = new Handle(&(p->GetImageItem()));
516 return NOTI_EX_ERROR_NONE;
519 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
520 noti_ex_item_h handle, noti_ex_item_h *time) {
521 if (handle == nullptr || time == nullptr) {
522 LOGE("Invalid parameter");
523 return NOTI_EX_ERROR_INVALID_PARAMETER;
526 Handle* h = static_cast<Handle*>(handle);
527 if (!h->IsValidType(AbstractItem::ChatMessage)) {
528 LOGE("Invalid handle type");
529 return NOTI_EX_ERROR_INVALID_PARAMETER;
531 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
532 *time = new Handle(&(p->GetTimeItem()));
534 return NOTI_EX_ERROR_NONE;
537 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
538 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
539 if (handle == nullptr || message_type == nullptr) {
540 LOGE("Invalid parameter");
541 return NOTI_EX_ERROR_INVALID_PARAMETER;
544 Handle* h = static_cast<Handle*>(handle);
545 if (!h->IsValidType(AbstractItem::ChatMessage)) {
546 LOGE("Invalid handle type");
547 return NOTI_EX_ERROR_INVALID_PARAMETER;
549 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
550 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
552 return NOTI_EX_ERROR_NONE;
555 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
556 const char *id, const char *title, bool checked) {
559 if (handle == nullptr || title == nullptr) {
560 LOGE("Invalid parameter");
561 return NOTI_EX_ERROR_INVALID_PARAMETER;
564 p = new (std::nothrow) CheckBoxItem(id, title, checked);
566 LOGE("Out-of-memory");
567 return NOTI_EX_ERROR_OUT_OF_MEMORY;
570 *handle = new Handle(shared_ptr<AbstractItem>(p));
572 return NOTI_EX_ERROR_NONE;
575 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
577 if (handle == nullptr || title == nullptr) {
578 LOGE("Invalid parameter");
579 return NOTI_EX_ERROR_INVALID_PARAMETER;
581 Handle* h = static_cast<Handle*>(handle);
582 if (!h->IsValidType(AbstractItem::CheckBox)) {
583 LOGE("Invalid handle type");
584 return NOTI_EX_ERROR_INVALID_PARAMETER;
587 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
589 if (p->GetMultiLanguage() != nullptr &&
590 !p->GetMultiLanguage()->GetTranslatedString().empty())
591 str = p->GetMultiLanguage()->GetTranslatedString();
592 else if (!p->GetTitle().empty())
595 *title = strdup(str.c_str());
596 if (*title == nullptr) {
597 LOGE("Out-of-memory");
598 return NOTI_EX_ERROR_OUT_OF_MEMORY;
601 return NOTI_EX_ERROR_NONE;
604 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
605 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
606 if (handle == nullptr) {
607 LOGE("Invalid parameter");
608 return NOTI_EX_ERROR_INVALID_PARAMETER;
611 Handle* p = static_cast<Handle*>(handle);
612 if (!p->IsValidType(AbstractItem::CheckBox)) {
613 LOGE("Invalid handle type");
614 return NOTI_EX_ERROR_INVALID_PARAMETER;
617 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
618 if (multi == nullptr) {
619 ci->SetMultiLanguage(nullptr);
620 return NOTI_EX_ERROR_NONE;
623 shared_ptr<MultiLanguage> mul_ptr =
624 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
625 mul_ptr->UpdateString();
626 ci->SetMultiLanguage(mul_ptr);
628 return NOTI_EX_ERROR_NONE;
631 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
632 noti_ex_item_h handle, bool *checked) {
633 if (handle == nullptr || checked == nullptr) {
634 LOGE("Invalid parameter");
635 return NOTI_EX_ERROR_INVALID_PARAMETER;
637 Handle* h = static_cast<Handle*>(handle);
638 if (!h->IsValidType(AbstractItem::CheckBox)) {
639 LOGE("Invalid handle type");
640 return NOTI_EX_ERROR_INVALID_PARAMETER;
642 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
643 *checked = p->IsChecked();
645 return NOTI_EX_ERROR_NONE;
648 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
649 noti_ex_item_h handle, bool checked) {
650 if (handle == nullptr) {
651 LOGE("Invalid parameter");
652 return NOTI_EX_ERROR_INVALID_PARAMETER;
655 Handle* h = static_cast<Handle*>(handle);
656 if (!h->IsValidType(AbstractItem::CheckBox)) {
657 LOGE("Invalid handle type");
658 return NOTI_EX_ERROR_INVALID_PARAMETER;
661 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
662 p->SetChecked(checked);
664 return NOTI_EX_ERROR_NONE;
667 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
671 if (handle == nullptr) {
672 LOGE("Invalid parameter");
673 return NOTI_EX_ERROR_INVALID_PARAMETER;
676 p = new (std::nothrow) EntryItem(id);
678 LOGE("Out-of-memory");
679 return NOTI_EX_ERROR_OUT_OF_MEMORY;
682 *handle = new Handle(shared_ptr<AbstractItem>(p));
684 return NOTI_EX_ERROR_NONE;
687 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
689 if (handle == nullptr || text == nullptr) {
690 LOGE("Invalid parameter");
691 return NOTI_EX_ERROR_INVALID_PARAMETER;
694 Handle* h = static_cast<Handle*>(handle);
695 if (!h->IsValidType(AbstractItem::Entry)) {
696 LOGE("Invalid handle type");
697 return NOTI_EX_ERROR_INVALID_PARAMETER;
700 EntryItem* p = static_cast<EntryItem*>(h->Get());
702 if (p->GetMultiLanguage() != nullptr &&
703 !p->GetMultiLanguage()->GetTranslatedString().empty())
704 str = p->GetMultiLanguage()->GetTranslatedString();
705 else if (!p->GetText().empty())
708 *text = strdup(str.c_str());
709 if (*text == nullptr) {
710 LOGE("Out-of-memory");
711 return NOTI_EX_ERROR_OUT_OF_MEMORY;
714 return NOTI_EX_ERROR_NONE;
717 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
719 if (handle == nullptr || text == nullptr) {
720 LOGE("Invalid parameter");
721 return NOTI_EX_ERROR_INVALID_PARAMETER;
723 Handle* h = static_cast<Handle*>(handle);
724 if (!h->IsValidType(AbstractItem::Entry)) {
725 LOGE("Invalid handle type");
726 return NOTI_EX_ERROR_INVALID_PARAMETER;
728 EntryItem* p = static_cast<EntryItem*>(h->Get());
729 p->SetText(std::string(text));
731 return NOTI_EX_ERROR_NONE;
734 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
735 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
736 if (handle == nullptr) {
737 LOGE("Invalid parameter");
738 return NOTI_EX_ERROR_INVALID_PARAMETER;
741 Handle* p = static_cast<Handle*>(handle);
742 if (!p->IsValidType(AbstractItem::Entry)) {
743 LOGE("Invalid handle type");
744 return NOTI_EX_ERROR_INVALID_PARAMETER;
747 EntryItem* ei = static_cast<EntryItem*>(p->Get());
748 if (multi == nullptr) {
749 ei->SetMultiLanguage(nullptr);
750 return NOTI_EX_ERROR_NONE;
753 shared_ptr<MultiLanguage> mul_ptr =
754 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
755 ei->SetMultiLanguage(mul_ptr);
756 ei->GetMultiLanguage()->UpdateString();
758 return NOTI_EX_ERROR_NONE;
761 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
762 noti_ex_event_info_h* cloned_handle) {
763 if (handle == nullptr || cloned_handle == nullptr) {
764 LOGE("Invalid parameter");
765 return NOTI_EX_ERROR_INVALID_PARAMETER;
768 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
769 EventInfo* info = new EventInfo(cloned);
770 *cloned_handle = info;
771 return NOTI_EX_ERROR_NONE;
774 extern "C" EXPORT_API int noti_ex_event_info_destroy(
775 noti_ex_event_info_h handle) {
776 if (handle == nullptr) {
777 LOGE("Invalid parameter");
778 return NOTI_EX_ERROR_INVALID_PARAMETER;
780 EventInfo* info = static_cast<EventInfo*>(handle);
782 return NOTI_EX_ERROR_NONE;
785 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
786 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
787 if (handle == nullptr || event_type == nullptr) {
788 LOGE("Invalid parameter");
789 return NOTI_EX_ERROR_INVALID_PARAMETER;
791 EventInfo* info = static_cast<EventInfo*>(handle);
792 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
794 return NOTI_EX_ERROR_NONE;
797 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
798 noti_ex_event_info_h handle, char **owner) {
799 if (handle == nullptr || owner == nullptr) {
800 LOGE("Invalid parameter");
801 return NOTI_EX_ERROR_INVALID_PARAMETER;
803 EventInfo* info = static_cast<EventInfo*>(handle);
804 *owner = strdup(info->GetOwner().c_str());
805 return NOTI_EX_ERROR_NONE;
808 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
809 noti_ex_event_info_h handle, char **channel) {
810 if (handle == nullptr || channel == nullptr) {
811 LOGE("Invalid parameter");
812 return NOTI_EX_ERROR_INVALID_PARAMETER;
814 EventInfo* info = static_cast<EventInfo*>(handle);
815 *channel = strdup(info->GetChannel().c_str());
816 return NOTI_EX_ERROR_NONE;
819 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
820 noti_ex_event_info_h handle, char **item_id) {
821 if (handle == nullptr || item_id == nullptr) {
822 LOGE("Invalid parameter");
823 return NOTI_EX_ERROR_INVALID_PARAMETER;
825 EventInfo* info = static_cast<EventInfo*>(handle);
826 *item_id = strdup(info->GetItemId().c_str());
827 return NOTI_EX_ERROR_NONE;
830 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
831 noti_ex_event_info_h handle, int *req_id) {
832 if (handle == nullptr || req_id == nullptr) {
833 LOGE("Invalid parameter");
834 return NOTI_EX_ERROR_INVALID_PARAMETER;
836 EventInfo* info = static_cast<EventInfo*>(handle);
837 *req_id = info->GetRequestId();
838 return NOTI_EX_ERROR_NONE;
841 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
845 if (handle == nullptr) {
846 LOGE("Invalid parameter");
847 return NOTI_EX_ERROR_INVALID_PARAMETER;
851 p = new (std::nothrow) GroupItem(id);
853 p = new (std::nothrow) GroupItem();
856 LOGE("Out-of-memory");
857 return NOTI_EX_ERROR_OUT_OF_MEMORY;
860 *handle = new Handle(shared_ptr<AbstractItem>(p));
862 return NOTI_EX_ERROR_NONE;
865 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
867 if (handle == nullptr) {
868 LOGE("Invalid parameter");
869 return NOTI_EX_ERROR_INVALID_PARAMETER;
871 Handle* h = static_cast<Handle*>(handle);
872 if (!h->IsValidType(AbstractItem::Group)) {
873 LOGE("Invalid handle type");
874 return NOTI_EX_ERROR_INVALID_PARAMETER;
876 GroupItem* p = static_cast<GroupItem*>(h->Get());
877 p->SetDirection(vertical);
879 return NOTI_EX_ERROR_NONE;
882 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
884 if (handle == nullptr) {
885 LOGE("Invalid parameter");
886 return NOTI_EX_ERROR_INVALID_PARAMETER;
888 Handle* h = static_cast<Handle*>(handle);
889 if (!h->IsValidType(AbstractItem::Group)) {
890 LOGE("Invalid handle type");
891 return NOTI_EX_ERROR_INVALID_PARAMETER;
893 GroupItem* p = static_cast<GroupItem*>(h->Get());
894 *vertical = p->IsVertical();
896 return NOTI_EX_ERROR_NONE;
899 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
901 if (handle == nullptr) {
902 LOGE("Invalid parameter");
903 return NOTI_EX_ERROR_INVALID_PARAMETER;
905 Handle* h = static_cast<Handle*>(handle);
906 if (!h->IsValidType(AbstractItem::Group)) {
907 LOGE("Invalid handle type");
908 return NOTI_EX_ERROR_INVALID_PARAMETER;
910 GroupItem* p = static_cast<GroupItem*>(h->Get());
911 if (!p->GetAppLabel().empty()) {
912 *label = strdup(p->GetAppLabel().c_str());
913 if (*label == nullptr) {
914 LOGE("Out-of-memory");
915 return NOTI_EX_ERROR_OUT_OF_MEMORY;
919 return NOTI_EX_ERROR_NONE;
922 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
923 noti_ex_item_h child) {
924 if (handle == nullptr || child == nullptr) {
925 LOGE("Invalid parameter");
926 return NOTI_EX_ERROR_INVALID_PARAMETER;
928 Handle* h = static_cast<Handle*>(handle);
929 if (!h->IsValidType(AbstractItem::Group)) {
930 LOGE("Invalid handle type");
931 return NOTI_EX_ERROR_INVALID_PARAMETER;
933 auto p = static_cast<GroupItem*>(h->Get());
934 p->AddChild((static_cast<Handle*>(child))->GetPtr());
936 return NOTI_EX_ERROR_NONE;
939 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
940 const char *item_id) {
941 if (handle == nullptr || item_id == nullptr) {
942 LOGE("Invalid parameter");
943 return NOTI_EX_ERROR_INVALID_PARAMETER;
945 Handle* h = static_cast<Handle*>(handle);
946 if (!h->IsValidType(AbstractItem::Group)) {
947 LOGE("Invalid handle type");
948 return NOTI_EX_ERROR_INVALID_PARAMETER;
950 GroupItem* p = static_cast<GroupItem*>(h->Get());
951 p->RemoveChild(std::string(item_id));
953 return NOTI_EX_ERROR_NONE;
956 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
957 noti_ex_item_group_foreach_child_cb callback, void *data) {
958 if (handle == nullptr || callback == nullptr) {
959 LOGE("Invalid parameter");
960 return NOTI_EX_ERROR_INVALID_PARAMETER;
963 Handle* h = static_cast<Handle*>(handle);
964 if (!h->IsValidType(AbstractItem::Group)) {
965 LOGE("Invalid handle type");
966 return NOTI_EX_ERROR_INVALID_PARAMETER;
968 GroupItem* p = static_cast<GroupItem*>(h->Get());
969 list<shared_ptr<AbstractItem>> children = p->GetChildren();
970 LOGI("Retrive (%zd)", children.size());
971 for (auto i : children) {
973 static_cast<noti_ex_item_h>(new Handle(i)), data);
974 if (ret != NOTI_EX_ERROR_NONE) {
975 LOGW("callback return (%d) stop foreach", ret);
980 return NOTI_EX_ERROR_NONE;
983 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
984 const char *id, const char *image_path) {
987 if (handle == nullptr || image_path == nullptr) {
988 LOGE("Invalid parameter");
989 return NOTI_EX_ERROR_INVALID_PARAMETER;
993 p = new (std::nothrow) ImageItem(id, image_path);
995 p = new (std::nothrow) ImageItem(image_path);
998 LOGE("Out-of-memory");
999 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1002 *handle = new Handle(shared_ptr<AbstractItem>(p));
1004 return NOTI_EX_ERROR_NONE;
1007 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1008 noti_ex_item_h handle, char **image_path) {
1009 if (handle == nullptr || image_path == nullptr) {
1010 LOGE("Invalid parameter");
1011 return NOTI_EX_ERROR_INVALID_PARAMETER;
1013 Handle* h = static_cast<Handle*>(handle);
1014 if (!h->IsValidType(AbstractItem::Image)) {
1015 LOGE("Invalid handle type");
1016 return NOTI_EX_ERROR_INVALID_PARAMETER;
1018 ImageItem* p = static_cast<ImageItem*>(h->Get());
1019 if (!p->GetImagePath().empty()) {
1020 *image_path = strdup(p->GetImagePath().c_str());
1021 if (*image_path == nullptr) {
1022 LOGE("Out-of-memory");
1023 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1027 return NOTI_EX_ERROR_NONE;
1030 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1031 noti_ex_item_h *handle, const char *id) {
1032 InputSelectorItem* p;
1034 if (handle == nullptr) {
1035 LOGE("Invalid parameter");
1036 return NOTI_EX_ERROR_INVALID_PARAMETER;
1040 p = new (std::nothrow) InputSelectorItem(id);
1042 p = new (std::nothrow) InputSelectorItem();
1045 LOGE("Out-of-memory");
1046 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1049 *handle = new Handle(shared_ptr<AbstractItem>(p));
1051 return NOTI_EX_ERROR_NONE;
1054 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1055 noti_ex_item_h handle, char ***contents_list, int *count) {
1056 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1057 LOGE("Invalid parameter");
1058 return NOTI_EX_ERROR_INVALID_PARAMETER;
1061 Handle* h = static_cast<Handle*>(handle);
1062 if (!h->IsValidType(AbstractItem::InputSelector)) {
1063 LOGE("Invalid handle type");
1064 return NOTI_EX_ERROR_INVALID_PARAMETER;
1067 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1068 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1069 list<string> contents;
1070 if (arr.size() == 0) {
1071 contents = p->GetContents();
1073 for (auto& i : arr) {
1074 contents.push_back(i->GetTranslatedString());
1078 char **list = (char**)calloc(contents.size(), sizeof(char*));
1079 if (list == nullptr) {
1080 LOGE("Out of memory");
1081 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1085 for (auto& i : contents) {
1086 list[idx] = strdup(i.c_str());
1087 if (list[idx] == nullptr) {
1088 __noti_ex_free_str_array(list, idx);
1089 LOGE("Out of memory");
1090 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1095 *count = contents.size();
1096 *contents_list = list;
1098 return NOTI_EX_ERROR_NONE;
1101 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1102 noti_ex_item_h handle, const char **contents, int count) {
1103 if (handle == nullptr || contents == nullptr) {
1104 LOGE("Invalid parameter");
1105 return NOTI_EX_ERROR_INVALID_PARAMETER;
1108 list<string> new_contents;
1109 Handle* h = static_cast<Handle*>(handle);
1110 if (!h->IsValidType(AbstractItem::InputSelector)) {
1111 LOGE("Invalid handle type");
1112 return NOTI_EX_ERROR_INVALID_PARAMETER;
1114 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1115 for (int i = 0; i < count; i++) {
1116 new_contents.push_back(contents[i]);
1118 p->SetContents(move(new_contents));
1120 return NOTI_EX_ERROR_NONE;
1123 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1124 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1125 if (handle == nullptr) {
1126 LOGE("Invalid parameter");
1127 return NOTI_EX_ERROR_INVALID_PARAMETER;
1130 Handle* p = static_cast<Handle*>(handle);
1131 if (!p->IsValidType(AbstractItem::InputSelector)) {
1132 LOGE("Invalid handle type");
1133 return NOTI_EX_ERROR_INVALID_PARAMETER;
1136 vector<shared_ptr<MultiLanguage>> m_list;
1137 for (int i = 0; i < count; i++) {
1138 shared_ptr<MultiLanguage> mul_ptr =
1139 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1140 mul_ptr->UpdateString();
1141 m_list.push_back(mul_ptr);
1144 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1145 input->SetMultiLanguage(m_list);
1147 return NOTI_EX_ERROR_NONE;
1150 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1151 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1152 if (handle == nullptr) {
1153 LOGE("Invalid parameter");
1154 return NOTI_EX_ERROR_INVALID_PARAMETER;
1157 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1158 new (std::nothrow) Color(a, r, g, b));
1159 if (ptr == nullptr || ptr->get() == nullptr) {
1160 LOGE("Out-of-memory");
1161 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1166 return NOTI_EX_ERROR_NONE;
1169 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1170 if (handle == nullptr) {
1171 LOGE("Invalid parameter");
1172 return NOTI_EX_ERROR_INVALID_PARAMETER;
1175 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1178 return NOTI_EX_ERROR_NONE;
1181 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1182 unsigned char *val) {
1183 if (handle == nullptr || val == nullptr) {
1184 LOGE("Invalid parameter");
1185 return NOTI_EX_ERROR_INVALID_PARAMETER;
1188 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1189 *val = (*p)->GetAVal();
1191 return NOTI_EX_ERROR_NONE;
1194 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1195 unsigned char *val) {
1196 if (handle == nullptr || val == nullptr) {
1197 LOGE("Invalid parameter");
1198 return NOTI_EX_ERROR_INVALID_PARAMETER;
1201 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1202 *val = (*p)->GetRVal();
1204 return NOTI_EX_ERROR_NONE;
1207 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1208 unsigned char *val) {
1209 if (handle == nullptr || val == nullptr) {
1210 LOGE("Invalid parameter");
1211 return NOTI_EX_ERROR_INVALID_PARAMETER;
1214 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1215 *val = (*p)->GetGVal();
1217 return NOTI_EX_ERROR_NONE;
1220 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1221 unsigned char *val) {
1222 if (handle == nullptr || val == nullptr) {
1223 LOGE("Invalid parameter");
1224 return NOTI_EX_ERROR_INVALID_PARAMETER;
1227 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1228 *val = (*p)->GetBVal();
1230 return NOTI_EX_ERROR_NONE;
1233 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1234 int left, int top, int right, int bottom) {
1235 if (handle == nullptr) {
1236 LOGE("Invalid parameter");
1237 return NOTI_EX_ERROR_INVALID_PARAMETER;
1240 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1241 new (std::nothrow) Padding(left, top, right, bottom));
1242 if (ptr == nullptr || ptr->get() == nullptr) {
1243 LOGE("Out-of-memory");
1244 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1249 return NOTI_EX_ERROR_NONE;
1252 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1253 if (handle == nullptr) {
1254 LOGE("Invalid parameter");
1255 return NOTI_EX_ERROR_INVALID_PARAMETER;
1258 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1261 return NOTI_EX_ERROR_NONE;
1264 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1266 if (handle == nullptr || val == nullptr) {
1267 LOGE("Invalid parameter");
1268 return NOTI_EX_ERROR_INVALID_PARAMETER;
1271 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1272 *val = (*p)->GetLeft();
1274 return NOTI_EX_ERROR_NONE;
1277 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1279 if (handle == nullptr || val == nullptr) {
1280 LOGE("Invalid parameter");
1281 return NOTI_EX_ERROR_INVALID_PARAMETER;
1284 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1285 *val = (*p)->GetTop();
1287 return NOTI_EX_ERROR_NONE;
1290 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1292 if (handle == nullptr || val == nullptr) {
1293 LOGE("Invalid parameter");
1294 return NOTI_EX_ERROR_INVALID_PARAMETER;
1297 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1298 *val = (*p)->GetRight();
1300 return NOTI_EX_ERROR_NONE;
1303 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1305 if (handle == nullptr || val == nullptr) {
1306 LOGE("Invalid parameter");
1307 return NOTI_EX_ERROR_INVALID_PARAMETER;
1310 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1311 *val = (*p)->GetBottom();
1313 return NOTI_EX_ERROR_NONE;
1316 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1317 int x, int y, int w, int h) {
1318 if (handle == nullptr) {
1319 LOGE("Invalid parameter");
1320 return NOTI_EX_ERROR_INVALID_PARAMETER;
1323 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1324 new (std::nothrow) Geometry(x, y, w, h));
1325 if (ptr == nullptr || ptr->get() == nullptr) {
1326 LOGE("Out-of-memory");
1327 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1332 return NOTI_EX_ERROR_NONE;
1335 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1336 if (handle == nullptr) {
1337 LOGE("Invalid parameter");
1338 return NOTI_EX_ERROR_INVALID_PARAMETER;
1341 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1344 return NOTI_EX_ERROR_NONE;
1347 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1349 if (handle == nullptr || val == nullptr) {
1350 LOGE("Invalid parameter");
1351 return NOTI_EX_ERROR_INVALID_PARAMETER;
1354 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1355 *val = (*p)->GetX();
1357 return NOTI_EX_ERROR_NONE;
1360 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1362 if (handle == nullptr || val == nullptr) {
1363 LOGE("Invalid parameter");
1364 return NOTI_EX_ERROR_INVALID_PARAMETER;
1367 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1368 *val = (*p)->GetY();
1370 return NOTI_EX_ERROR_NONE;
1373 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1375 if (handle == nullptr || val == nullptr) {
1376 LOGE("Invalid parameter");
1377 return NOTI_EX_ERROR_INVALID_PARAMETER;
1380 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1381 *val = (*p)->GetWidth();
1383 return NOTI_EX_ERROR_NONE;
1386 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1388 if (handle == nullptr || val == nullptr) {
1389 LOGE("Invalid parameter");
1390 return NOTI_EX_ERROR_INVALID_PARAMETER;
1393 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1394 *val = (*p)->GetHeight();
1396 return NOTI_EX_ERROR_NONE;
1399 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1400 noti_ex_color_h color,
1401 noti_ex_padding_h padding,
1402 noti_ex_geometry_h geometry) {
1403 if (handle == nullptr) {
1404 LOGE("Invalid parameter");
1405 return NOTI_EX_ERROR_INVALID_PARAMETER;
1408 shared_ptr<Color> col = (color == nullptr) ?
1409 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1410 shared_ptr<Padding> padd = (padding == nullptr) ?
1411 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1412 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1413 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1415 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1416 new (std::nothrow) Style(col, padd, geo));
1417 if (ptr == nullptr || ptr->get() == nullptr) {
1418 LOGE("Out-of-memory");
1419 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1424 return NOTI_EX_ERROR_NONE;
1427 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1428 if (handle == nullptr) {
1429 LOGE("Invalid parameter");
1430 return NOTI_EX_ERROR_INVALID_PARAMETER;
1433 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1436 return NOTI_EX_ERROR_NONE;
1439 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1440 noti_ex_padding_h *padding) {
1441 if (handle == nullptr || padding == 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)->GetPadding() == nullptr) {
1448 LOGW("Padding info is null");
1449 return NOTI_EX_ERROR_INVALID_PARAMETER;
1452 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1453 new (std::nothrow) Padding(*((*p)->GetPadding())));
1454 if (padd == nullptr || padd->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_color(noti_ex_style_h handle,
1465 noti_ex_color_h *color) {
1466 if (handle == nullptr || color == 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)->GetColor() == nullptr) {
1473 LOGW("Color info is null");
1474 return NOTI_EX_ERROR_INVALID_PARAMETER;
1477 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1478 new (std::nothrow) Color(*((*p)->GetColor())));
1479 if (col == nullptr || col->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_geometry(noti_ex_style_h handle,
1490 noti_ex_geometry_h *geometry) {
1491 if (handle == nullptr || geometry == nullptr) {
1492 LOGE("Invalid parameter");
1493 return NOTI_EX_ERROR_INVALID_PARAMETER;
1496 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1497 if ((*p)->GetGeometry() == nullptr) {
1498 LOGW("Geometry info is null");
1499 return NOTI_EX_ERROR_INVALID_PARAMETER;
1502 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1503 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1504 if (geo == nullptr || geo->get() == nullptr) {
1505 LOGE("Out-of-memory");
1506 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1511 return NOTI_EX_ERROR_NONE;
1514 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1515 noti_ex_style_h handle, char** background_image) {
1516 if (handle == nullptr || background_image == nullptr) {
1517 LOGE("Invalid parameter");
1518 return NOTI_EX_ERROR_INVALID_PARAMETER;
1521 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1522 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1524 return NOTI_EX_ERROR_NONE;
1527 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1528 noti_ex_style_h handle, char* background_image) {
1529 if (handle == nullptr || background_image == nullptr) {
1530 LOGE("Invalid parameter");
1531 return NOTI_EX_ERROR_INVALID_PARAMETER;
1534 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1535 (*p)->SetBackgroundImage(background_image);
1537 return NOTI_EX_ERROR_NONE;
1540 extern "C" EXPORT_API int noti_ex_style_get_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 if ((*p)->GetBackgroundColor() == nullptr) {
1549 LOGW("Color info is null");
1550 return NOTI_EX_ERROR_INVALID_PARAMETER;
1553 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1554 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1555 if (col == nullptr || col->get() == nullptr) {
1556 LOGE("Out-of-memory");
1557 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1562 return NOTI_EX_ERROR_NONE;
1565 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1566 noti_ex_style_h handle, noti_ex_color_h color) {
1567 if (handle == nullptr || color == nullptr) {
1568 LOGE("Invalid parameter");
1569 return NOTI_EX_ERROR_INVALID_PARAMETER;
1572 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1573 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1574 (*p)->SetBackgroundColor(*col);
1576 return NOTI_EX_ERROR_NONE;
1579 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1580 noti_ex_color_h color) {
1581 if (handle == nullptr) {
1582 LOGE("Invalid parameter");
1583 return NOTI_EX_ERROR_INVALID_PARAMETER;
1586 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1587 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1588 new (std::nothrow) LEDInfo(*color_ptr));
1590 LOGE("Out-of-memory");
1591 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1596 return NOTI_EX_ERROR_NONE;
1599 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1600 if (handle == nullptr) {
1601 LOGE("Invalid parameter");
1602 return NOTI_EX_ERROR_INVALID_PARAMETER;
1605 shared_ptr<LEDInfo>* led_ptr =
1606 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1608 return NOTI_EX_ERROR_NONE;
1611 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1612 noti_ex_led_info_h handle, int ms) {
1613 if (handle == nullptr) {
1614 LOGE("Invalid parameter");
1615 return NOTI_EX_ERROR_INVALID_PARAMETER;
1618 shared_ptr<LEDInfo>* led_ptr =
1619 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1620 (*led_ptr)->SetOnPeriod(ms);
1622 return NOTI_EX_ERROR_NONE;
1625 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1626 noti_ex_led_info_h handle, int *ms) {
1627 if (handle == nullptr || ms == nullptr) {
1628 LOGE("Invalid parameter");
1629 return NOTI_EX_ERROR_INVALID_PARAMETER;
1632 shared_ptr<LEDInfo>* led_ptr =
1633 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1634 *ms = (*led_ptr)->GetOnPeriod();
1636 return NOTI_EX_ERROR_NONE;
1639 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1640 noti_ex_led_info_h handle, int ms) {
1641 if (handle == nullptr) {
1642 LOGE("Invalid parameter");
1643 return NOTI_EX_ERROR_INVALID_PARAMETER;
1646 shared_ptr<LEDInfo>* led_ptr =
1647 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1648 (*led_ptr)->SetOffPeriod(ms);
1650 return NOTI_EX_ERROR_NONE;
1653 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1654 noti_ex_led_info_h handle, int *ms) {
1655 if (handle == nullptr) {
1656 LOGE("Invalid parameter");
1657 return NOTI_EX_ERROR_INVALID_PARAMETER;
1660 shared_ptr<LEDInfo>* led_ptr =
1661 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1662 *ms = (*led_ptr)->GetOffPeriod();
1664 return NOTI_EX_ERROR_NONE;
1667 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1668 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1669 if (handle == nullptr) {
1670 LOGE("Invalid parameter");
1671 return NOTI_EX_ERROR_INVALID_PARAMETER;
1674 shared_ptr<LEDInfo>* led_ptr =
1675 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1676 if ((*led_ptr)->GetColor() == nullptr) {
1677 LOGE("Color is null");
1678 return NOTI_EX_ERROR_INVALID_PARAMETER;
1681 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1682 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1683 if (col == nullptr || col->get() == nullptr) {
1684 LOGE("Out-of-memory");
1685 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1690 return NOTI_EX_ERROR_NONE;
1693 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1694 if (handle == nullptr) {
1695 LOGE("Invalid parameter");
1696 return NOTI_EX_ERROR_INVALID_PARAMETER;
1699 shared_ptr<AbstractAction>* ptr =
1700 static_cast<shared_ptr<AbstractAction>*>(handle);
1703 return NOTI_EX_ERROR_NONE;
1706 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1708 if (handle == nullptr || type == nullptr) {
1709 LOGE("Invalid parameter");
1710 return NOTI_EX_ERROR_INVALID_PARAMETER;
1713 shared_ptr<AbstractAction>* ptr =
1714 static_cast<shared_ptr<AbstractAction>*>(handle);
1715 *type = (*ptr)->GetType();
1717 return NOTI_EX_ERROR_NONE;
1720 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1722 if (handle == nullptr || local == nullptr) {
1723 LOGE("Invalid parameter");
1724 return NOTI_EX_ERROR_INVALID_PARAMETER;
1727 shared_ptr<AbstractAction>* ptr =
1728 static_cast<shared_ptr<AbstractAction>*>(handle);
1729 *local = (*ptr)->IsLocal();
1731 return NOTI_EX_ERROR_NONE;
1734 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1735 noti_ex_item_h item) {
1736 if (handle == nullptr || item == nullptr) {
1737 LOGE("Invalid parameter");
1738 return NOTI_EX_ERROR_INVALID_PARAMETER;
1740 shared_ptr<AbstractAction>* ptr =
1741 static_cast<shared_ptr<AbstractAction>*>(handle);
1742 Handle* ih = static_cast<Handle*>(item);
1743 (*ptr)->Execute(ih->GetPtr());
1745 return NOTI_EX_ERROR_NONE;
1748 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1750 if (handle == nullptr || extra == nullptr) {
1751 LOGE("Invalid parameter");
1752 return NOTI_EX_ERROR_INVALID_PARAMETER;
1755 shared_ptr<AbstractAction>* ptr =
1756 static_cast<shared_ptr<AbstractAction>*>(handle);
1757 if (!(*ptr)->GetExtra().empty()) {
1758 *extra = strdup((*ptr)->GetExtra().c_str());
1759 if (*extra == nullptr) {
1760 LOGE("Out-of-memory");
1761 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1765 return NOTI_EX_ERROR_NONE;
1768 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1769 noti_ex_item_info_h handle, int *hide_time) {
1770 if (handle == nullptr || hide_time == nullptr) {
1771 LOGE("Invalid parameter");
1772 return NOTI_EX_ERROR_INVALID_PARAMETER;
1774 IItemInfo* p = static_cast<IItemInfo*>(handle);
1775 *hide_time = p->GetHideTime();
1776 return NOTI_EX_ERROR_NONE;
1779 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1780 noti_ex_item_info_h handle, int hide_time) {
1781 if (handle == nullptr) {
1782 LOGE("Invalid parameter");
1783 return NOTI_EX_ERROR_INVALID_PARAMETER;
1785 IItemInfo* p = static_cast<IItemInfo*>(handle);
1786 p->SetHideTime(hide_time);
1787 return NOTI_EX_ERROR_NONE;
1790 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1791 noti_ex_item_info_h handle, int *delete_time) {
1792 if (handle == nullptr || delete_time == nullptr) {
1793 LOGE("Invalid parameter");
1794 return NOTI_EX_ERROR_INVALID_PARAMETER;
1796 IItemInfo* p = static_cast<IItemInfo*>(handle);
1797 *delete_time = p->GetDeleteTime();
1798 return NOTI_EX_ERROR_NONE;
1801 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1802 noti_ex_item_info_h handle, int delete_time) {
1803 if (handle == nullptr) {
1804 LOGE("Invalid parameter");
1805 return NOTI_EX_ERROR_INVALID_PARAMETER;
1807 IItemInfo* p = static_cast<IItemInfo*>(handle);
1808 p->SetDeleteTime(delete_time);
1809 return NOTI_EX_ERROR_NONE;
1812 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1813 noti_ex_item_info_h handle, time_t *time) {
1814 if (handle == nullptr || time == nullptr) {
1815 LOGE("Invalid parameter");
1816 return NOTI_EX_ERROR_INVALID_PARAMETER;
1819 IItemInfo* p = static_cast<IItemInfo*>(handle);
1820 *time = p->GetTime();
1821 return NOTI_EX_ERROR_NONE;
1824 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1825 if (handle == nullptr) {
1826 LOGE("Invalid parameter");
1827 return NOTI_EX_ERROR_INVALID_PARAMETER;
1830 Handle* h = static_cast<Handle*>(handle);
1832 return NOTI_EX_ERROR_NONE;
1835 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1836 const char *id, noti_ex_item_h *item) {
1837 if (handle == nullptr) {
1838 LOGE("Invalid parameter");
1839 return NOTI_EX_ERROR_INVALID_PARAMETER;
1842 Handle* p = static_cast<Handle*>(handle);
1843 AbstractItem& find_item = p->Get()->FindByID(string(id));
1844 *item = new Handle(&find_item);
1845 return NOTI_EX_ERROR_NONE;
1848 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1850 if (handle == nullptr || type == nullptr) {
1851 LOGE("Invalid parameter");
1852 return NOTI_EX_ERROR_INVALID_PARAMETER;
1855 Handle* h = static_cast<Handle*>(handle);
1856 AbstractItem* p = h->Get();
1857 *type = p->GetType();
1858 return NOTI_EX_ERROR_NONE;
1861 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1862 char ***path, int *count) {
1863 if (handle == nullptr || path == nullptr || count == nullptr) {
1864 LOGE("Invalid parameter");
1865 return NOTI_EX_ERROR_INVALID_PARAMETER;
1867 Handle* p = static_cast<Handle*>(handle);
1868 list<string> shared_path = p->Get()->GetSharedPath();
1869 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1870 if (tmp_path == nullptr) {
1871 LOGE("Fail to create items");
1872 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1876 for (auto& i : shared_path) {
1877 tmp_path[idx] = strdup(i.c_str());
1878 if (tmp_path[idx] == nullptr) {
1879 __noti_ex_free_str_array(tmp_path, idx);
1880 LOGE("Out of memory");
1881 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1887 *count = shared_path.size();
1888 return NOTI_EX_ERROR_NONE;
1891 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1893 if (handle == nullptr || id == nullptr) {
1894 LOGE("Invalid parameter");
1895 return NOTI_EX_ERROR_INVALID_PARAMETER;
1897 Handle* h = static_cast<Handle*>(handle);
1898 AbstractItem* p = h->Get();
1899 *id = strdup(p->GetId().c_str());
1900 return NOTI_EX_ERROR_NONE;
1903 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1905 if (handle == nullptr || id == nullptr) {
1906 LOGE("Invalid parameter");
1907 return NOTI_EX_ERROR_INVALID_PARAMETER;
1909 Handle* p = static_cast<Handle*>(handle);
1910 p->Get()->SetId(id);
1911 return NOTI_EX_ERROR_NONE;
1914 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1915 noti_ex_action_h *action) {
1916 if (handle == nullptr || action == nullptr) {
1917 LOGE("Invalid parameter");
1918 return NOTI_EX_ERROR_INVALID_PARAMETER;
1920 Handle* p = static_cast<Handle*>(handle);
1921 if (p->Get()->GetAction() == nullptr) {
1923 return NOTI_EX_ERROR_NONE;
1925 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1926 p->Get()->GetAction()));
1928 return NOTI_EX_ERROR_NONE;
1931 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1932 noti_ex_action_h action) {
1933 if (handle == nullptr || action == nullptr) {
1934 LOGE("Invalid parameter");
1935 return NOTI_EX_ERROR_INVALID_PARAMETER;
1938 Handle* p = static_cast<Handle*>(handle);
1940 shared_ptr<AbstractAction>* ptr =
1941 static_cast<shared_ptr<AbstractAction>*>(action);
1942 p->Get()->SetAction(*ptr);
1943 return NOTI_EX_ERROR_NONE;
1946 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1947 noti_ex_style_h *style) {
1948 if (handle == nullptr || style == nullptr) {
1949 LOGE("Invalid parameter");
1950 return NOTI_EX_ERROR_INVALID_PARAMETER;
1953 Handle* p = static_cast<Handle*>(handle);
1954 shared_ptr<Style> s = p->Get()->GetStyle();
1955 if (s.get() == nullptr) {
1956 LOGE("Style is null");
1957 return NOTI_EX_ERROR_INVALID_PARAMETER;
1960 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1961 if (ptr == nullptr || ptr->get() == nullptr) {
1962 LOGE("Out of memory");
1963 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1967 return NOTI_EX_ERROR_NONE;
1970 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1971 noti_ex_style_h style) {
1972 if (handle == nullptr || style == nullptr) {
1973 LOGE("Invalid parameter");
1974 return NOTI_EX_ERROR_INVALID_PARAMETER;
1977 Handle* p = static_cast<Handle*>(handle);
1978 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1979 p->Get()->SetStyle(*s);
1980 return NOTI_EX_ERROR_NONE;
1983 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1985 if (handle == nullptr) {
1986 LOGE("Invalid parameter");
1987 return NOTI_EX_ERROR_INVALID_PARAMETER;
1990 Handle* p = static_cast<Handle*>(handle);
1991 p->Get()->SetVisible(visible);
1992 return NOTI_EX_ERROR_NONE;
1995 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1997 if (handle == nullptr || visible == nullptr) {
1998 LOGE("Invalid parameter");
1999 return NOTI_EX_ERROR_INVALID_PARAMETER;
2002 Handle* p = static_cast<Handle*>(handle);
2003 *visible = p->Get()->GetVisible();
2004 return NOTI_EX_ERROR_NONE;
2007 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2009 if (handle == nullptr) {
2010 LOGE("Invalid parameter");
2011 return NOTI_EX_ERROR_INVALID_PARAMETER;
2014 Handle* p = static_cast<Handle*>(handle);
2015 p->Get()->SetEnable(enable);
2016 return NOTI_EX_ERROR_NONE;
2019 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2021 if (handle == nullptr || enable == nullptr) {
2022 LOGE("Invalid parameter");
2023 return NOTI_EX_ERROR_INVALID_PARAMETER;
2026 Handle* p = static_cast<Handle*>(handle);
2027 *enable = p->Get()->GetEnable();
2028 return NOTI_EX_ERROR_NONE;
2031 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2032 const char *receiver_group) {
2033 if (handle == nullptr || receiver_group == nullptr) {
2034 LOGE("Invalid parameter");
2035 return NOTI_EX_ERROR_INVALID_PARAMETER;
2038 Handle* p = static_cast<Handle*>(handle);
2039 p->Get()->AddReceiver(receiver_group);
2040 return NOTI_EX_ERROR_NONE;
2043 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2044 const char *receiver_group) {
2045 if (handle == nullptr || receiver_group == nullptr) {
2046 LOGE("Invalid parameter");
2047 return NOTI_EX_ERROR_INVALID_PARAMETER;
2050 Handle* p = static_cast<Handle*>(handle);
2051 p->Get()->RemoveReceiver(receiver_group);
2052 return NOTI_EX_ERROR_NONE;
2055 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2056 char ***receiver_list, int *count) {
2057 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2058 LOGE("Invalid parameter");
2059 return NOTI_EX_ERROR_INVALID_PARAMETER;
2062 Handle* p = static_cast<Handle*>(handle);
2063 list<string> receivers = p->Get()->GetReceiverList();
2064 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2065 if (tmp_list == nullptr) {
2066 LOGE("Out of memory");
2067 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2071 for (auto& i : receivers) {
2072 tmp_list[idx] = strdup(i.c_str());
2073 if (tmp_list[idx] == nullptr) {
2074 __noti_ex_free_str_array(tmp_list, idx);
2075 LOGE("Out of memory");
2076 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2081 *receiver_list = tmp_list;
2082 *count = receivers.size();
2083 return NOTI_EX_ERROR_NONE;
2086 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2088 if (handle == nullptr) {
2089 LOGE("Invalid parameter");
2090 return NOTI_EX_ERROR_INVALID_PARAMETER;
2093 Handle* p = static_cast<Handle*>(handle);
2094 p->Get()->SetPolicy(policy);
2095 return NOTI_EX_ERROR_NONE;
2098 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2100 if (handle == nullptr || policy == nullptr) {
2101 LOGE("Invalid parameter");
2102 return NOTI_EX_ERROR_INVALID_PARAMETER;
2105 Handle* p = static_cast<Handle*>(handle);
2106 *policy = p->Get()->GetPolicy();
2107 return NOTI_EX_ERROR_NONE;
2110 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2112 if (handle == nullptr || channel == nullptr) {
2113 LOGE("Invalid parameter");
2114 return NOTI_EX_ERROR_INVALID_PARAMETER;
2117 Handle* p = static_cast<Handle*>(handle);
2118 if (!p->Get()->GetChannel().empty())
2119 *channel = strdup(p->Get()->GetChannel().c_str());
2123 return NOTI_EX_ERROR_NONE;
2126 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2127 const char *channel) {
2128 if (handle == nullptr) {
2129 LOGE("Invalid parameter");
2130 return NOTI_EX_ERROR_INVALID_PARAMETER;
2133 Handle* p = static_cast<Handle*>(handle);
2134 p->Get()->SetChannel(channel);
2135 return NOTI_EX_ERROR_NONE;
2138 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2139 noti_ex_led_info_h led) {
2140 if (handle == nullptr) {
2141 LOGE("Invalid parameter");
2142 return NOTI_EX_ERROR_INVALID_PARAMETER;
2145 Handle* p = static_cast<Handle*>(handle);
2146 shared_ptr<LEDInfo>* led_ptr =
2147 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2148 p->Get()->SetLEDInfo(*led_ptr);
2149 return NOTI_EX_ERROR_NONE;
2152 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2153 noti_ex_led_info_h *led) {
2154 if (handle == nullptr) {
2155 LOGE("Invalid parameter");
2156 return NOTI_EX_ERROR_INVALID_PARAMETER;
2159 Handle* p = static_cast<Handle*>(handle);
2160 if (p->Get()->GetLEDInfo() != nullptr)
2161 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2164 return NOTI_EX_ERROR_NONE;
2167 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2169 if (handle == nullptr) {
2170 LOGE("Invalid parameter");
2171 return NOTI_EX_ERROR_INVALID_PARAMETER;
2174 Handle* p = static_cast<Handle*>(handle);
2175 if (path == nullptr)
2176 p->Get()->SetSoundPath("");
2178 p->Get()->SetSoundPath(path);
2179 return NOTI_EX_ERROR_NONE;
2182 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2184 if (handle == nullptr) {
2185 LOGE("Invalid parameter");
2186 return NOTI_EX_ERROR_INVALID_PARAMETER;
2189 Handle* p = static_cast<Handle*>(handle);
2190 if (path == nullptr)
2191 p->Get()->SetVibrationPath("");
2193 p->Get()->SetVibrationPath(path);
2194 return NOTI_EX_ERROR_NONE;
2197 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2199 if (handle == nullptr || path == nullptr) {
2200 LOGE("Invalid parameter");
2201 return NOTI_EX_ERROR_INVALID_PARAMETER;
2204 Handle* p = static_cast<Handle*>(handle);
2205 if (p->Get()->GetSoundPath().empty())
2208 *path = strdup(p->Get()->GetSoundPath().c_str());
2209 return NOTI_EX_ERROR_NONE;
2212 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2214 if (handle == nullptr || path == nullptr) {
2215 LOGE("Invalid parameter");
2216 return NOTI_EX_ERROR_INVALID_PARAMETER;
2219 Handle* p = static_cast<Handle*>(handle);
2220 if (p->Get()->GetVibrationPath().empty())
2223 *path = strdup(p->Get()->GetVibrationPath().c_str());
2224 return NOTI_EX_ERROR_NONE;
2227 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2228 noti_ex_item_info_h *info) {
2229 if (handle == nullptr || info == nullptr) {
2230 LOGE("Invalid parameter");
2231 return NOTI_EX_ERROR_INVALID_PARAMETER;
2234 Handle* p = static_cast<Handle*>(handle);
2235 if (p->Get()->GetInfo() == nullptr)
2238 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2239 return NOTI_EX_ERROR_NONE;
2242 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2244 if (handle == nullptr || id == nullptr) {
2245 LOGE("Invalid parameter");
2246 return NOTI_EX_ERROR_INVALID_PARAMETER;
2249 Handle* p = static_cast<Handle*>(handle);
2250 if (p->Get()->GetSenderAppId().empty())
2253 *id = strdup(p->Get()->GetSenderAppId().c_str());
2254 return NOTI_EX_ERROR_NONE;
2257 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2259 if (handle == nullptr || tag == nullptr) {
2260 LOGE("Invalid parameter");
2261 return NOTI_EX_ERROR_INVALID_PARAMETER;
2264 Handle* p = static_cast<Handle*>(handle);
2265 if (p->Get()->GetTag().empty())
2268 *tag = strdup(p->Get()->GetTag().c_str());
2269 return NOTI_EX_ERROR_NONE;
2272 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2274 if (handle == nullptr) {
2275 LOGE("Invalid parameter");
2276 return NOTI_EX_ERROR_INVALID_PARAMETER;
2279 Handle* p = static_cast<Handle*>(handle);
2281 p->Get()->SetTag("");
2283 p->Get()->SetTag(tag);
2284 return NOTI_EX_ERROR_NONE;
2287 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2289 if (handle == nullptr || ongoing == nullptr) {
2290 LOGE("Invalid parameter");
2291 return NOTI_EX_ERROR_INVALID_PARAMETER;
2294 Handle* p = static_cast<Handle*>(handle);
2295 *ongoing = p->Get()->GetOnGoingState();
2297 return NOTI_EX_ERROR_NONE;
2300 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2302 if (handle == nullptr) {
2303 LOGE("Invalid parameter");
2304 return NOTI_EX_ERROR_INVALID_PARAMETER;
2307 Handle* p = static_cast<Handle*>(handle);
2308 p->Get()->SetOnGoingState(ongoing);
2310 return NOTI_EX_ERROR_NONE;
2313 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2314 int type, bool* exist) {
2315 if (handle == nullptr || exist == nullptr) {
2316 LOGE("Invalid parameter");
2317 return NOTI_EX_ERROR_INVALID_PARAMETER;
2320 Handle* p = static_cast<Handle*>(handle);
2321 *exist = p->Get()->IsItemTypeExist(type);
2323 return NOTI_EX_ERROR_NONE;
2326 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2328 if (handle == nullptr || type == nullptr) {
2329 LOGE("Invalid parameter");
2330 return NOTI_EX_ERROR_INVALID_PARAMETER;
2333 Handle* p = static_cast<Handle*>(handle);
2334 *type = p->Get()->GetMainType();
2336 return NOTI_EX_ERROR_NONE;
2339 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2340 const char* id, int type) {
2341 if (handle == nullptr || id == nullptr) {
2342 LOGE("Invalid parameter");
2343 return NOTI_EX_ERROR_INVALID_PARAMETER;
2346 Handle* p = static_cast<Handle*>(handle);
2347 if (!(p->Get()->SetMainType(string(id),
2348 static_cast<AbstractItem::MainType>(type))))
2349 return NOTI_EX_ERROR_INVALID_PARAMETER;
2351 return NOTI_EX_ERROR_NONE;
2354 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2355 int type, noti_ex_item_h* item) {
2356 if (handle == nullptr || item == nullptr) {
2357 LOGE("Invalid parameter");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2361 Handle* h = static_cast<Handle*>(handle);
2362 if (!h->IsValidType(AbstractItem::Group)) {
2363 LOGE("Invalid handle type");
2364 return NOTI_EX_ERROR_INVALID_PARAMETER;
2367 GroupItem* p = static_cast<GroupItem*>(h->Get());
2368 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2369 *item = new Handle(&find_item);
2371 return NOTI_EX_ERROR_NONE;
2374 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2375 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2377 if (handle == nullptr) {
2378 LOGE("Invalid parameter");
2379 return NOTI_EX_ERROR_INVALID_PARAMETER;
2382 string receiver_group_str = "";
2384 receiver_group_str = string(receiver_group);
2386 ManagerStub* stub = new (std::nothrow) ManagerStub(
2387 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2388 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2389 receiver_group_str);
2390 if (stub == nullptr) {
2391 LOGE("Fail to create manager");
2392 return NOTI_EX_ERROR_IO_ERROR;
2394 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2395 new ManagerCallbackInfo(event_callbacks, data)));
2396 *handle = static_cast<noti_ex_manager_h>(stub);
2398 return NOTI_EX_ERROR_NONE;
2401 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2402 if (handle == nullptr) {
2403 LOGE("Invalid parameter");
2404 return NOTI_EX_ERROR_INVALID_PARAMETER;
2406 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2408 return NOTI_EX_ERROR_NONE;
2411 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2412 noti_ex_item_h **items, int *count) {
2413 if (handle == nullptr || items == nullptr || count == nullptr) {
2414 LOGE("Invalid parameter");
2415 return NOTI_EX_ERROR_INVALID_PARAMETER;
2419 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2420 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2421 if (item_list.size() == 0) {
2424 return NOTI_EX_ERROR_NONE;
2426 noti_ex_item_h* added_item =
2427 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2428 if (added_item == nullptr) {
2429 LOGE("Fail to create items");
2430 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2434 for (auto& i : item_list) {
2435 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2437 *items = added_item;
2438 *count = item_list.size();
2439 } catch (Exception &ex) {
2440 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2441 return NOTI_EX_ERROR_IO_ERROR;
2443 return NOTI_EX_ERROR_NONE;
2446 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2447 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2448 if (handle == nullptr || channel == nullptr ||
2449 items == nullptr || count == nullptr) {
2450 LOGE("Invalid parameter");
2451 return NOTI_EX_ERROR_INVALID_PARAMETER;
2455 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2456 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2457 if (item_list.size() == 0) {
2460 return NOTI_EX_ERROR_NONE;
2462 noti_ex_item_h* added_item =
2463 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2464 if (added_item == nullptr) {
2465 LOGE("Fail to create items");
2466 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2470 for (auto& i : item_list) {
2471 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2473 *items = added_item;
2474 *count = item_list.size();
2475 } catch (Exception &ex) {
2476 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2477 return NOTI_EX_ERROR_IO_ERROR;
2480 return NOTI_EX_ERROR_NONE;
2483 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2484 noti_ex_item_h noti, int *request_id) {
2485 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2486 LOGE("Invalid parameter");
2487 return NOTI_EX_ERROR_INVALID_PARAMETER;
2490 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2491 Handle* sp = static_cast<Handle*>(noti);
2492 if (sp->GetPtr().get() == nullptr) {
2493 LOGE("Invalid noti reference can not be sended");
2494 return NOTI_EX_ERROR_INVALID_PARAMETER;
2496 *request_id = stub->Update(sp->GetPtr());
2498 } catch (Exception &ex) {
2499 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2500 return NOTI_EX_ERROR_IO_ERROR;
2502 return NOTI_EX_ERROR_NONE;
2505 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2506 noti_ex_item_h noti, int *request_id) {
2507 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2508 LOGE("Invalid parameter");
2509 return NOTI_EX_ERROR_INVALID_PARAMETER;
2512 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2513 Handle* item = static_cast<Handle*>(noti);
2514 if (item->GetPtr().get() == nullptr) {
2515 LOGE("Invalid noti reference can not be sended");
2516 return NOTI_EX_ERROR_INVALID_PARAMETER;
2518 *request_id = stub->Delete(item->GetPtr());
2520 } catch (Exception &ex) {
2521 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2522 return NOTI_EX_ERROR_IO_ERROR;
2524 return NOTI_EX_ERROR_NONE;
2527 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2529 if (handle == nullptr || request_id == nullptr) {
2530 LOGE("Invalid parameter");
2531 return NOTI_EX_ERROR_INVALID_PARAMETER;
2534 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2535 *request_id = stub->DeleteAll();
2536 } catch (Exception &ex) {
2537 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2538 return NOTI_EX_ERROR_IO_ERROR;
2540 return NOTI_EX_ERROR_NONE;
2543 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2544 noti_ex_item_h noti, int *request_id) {
2545 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2546 LOGE("Invalid parameter");
2547 return NOTI_EX_ERROR_INVALID_PARAMETER;
2550 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2551 Handle* item = static_cast<Handle*>(noti);
2552 if (item->GetPtr().get() == nullptr) {
2553 LOGE("Invalid noti reference can not be sended");
2554 return NOTI_EX_ERROR_INVALID_PARAMETER;
2556 *request_id = stub->Hide(item->GetPtr());
2558 } catch (Exception &ex) {
2559 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2560 return NOTI_EX_ERROR_IO_ERROR;
2562 return NOTI_EX_ERROR_NONE;
2565 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2566 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2567 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2568 LOGE("Invalid parameter");
2569 return NOTI_EX_ERROR_INVALID_PARAMETER;
2572 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2573 *item = new Handle(stub->FindByRootID(root_id));
2574 } catch (Exception &ex) {
2575 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2576 return NOTI_EX_ERROR_IO_ERROR;
2578 return NOTI_EX_ERROR_NONE;
2581 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2582 noti_ex_event_info_h info, noti_ex_error_e error) {
2583 if (handle == nullptr || info == nullptr) {
2584 LOGE("Invalid parameter");
2585 return NOTI_EX_ERROR_INVALID_PARAMETER;
2588 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2589 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2590 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2591 static_cast<NotificationError>(error));
2592 } catch (Exception &ex) {
2593 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2594 return NOTI_EX_ERROR_IO_ERROR;
2596 return NOTI_EX_ERROR_NONE;
2599 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2600 noti_ex_manager_h handle, int *cnt) {
2602 if (handle == nullptr || cnt == nullptr) {
2603 LOGE("Invalid parameter");
2604 return NOTI_EX_ERROR_INVALID_PARAMETER;
2607 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2608 *cnt = stub->GetCount();
2609 } catch (Exception &ex) {
2610 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2611 return NOTI_EX_ERROR_IO_ERROR;
2613 return NOTI_EX_ERROR_NONE;
2616 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2617 const char *id, float min, float current, float max) {
2620 if (handle == nullptr) {
2621 LOGE("Invalid parameter");
2622 return NOTI_EX_ERROR_INVALID_PARAMETER;
2626 p = new (std::nothrow) ProgressItem(id, min, current, max);
2628 p = new (std::nothrow) ProgressItem(min, current, max);
2631 LOGE("Out-of-memory");
2632 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2635 *handle = new Handle(shared_ptr<AbstractItem>(p));
2637 return NOTI_EX_ERROR_NONE;
2640 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2641 noti_ex_item_h handle, float *current) {
2642 if (handle == nullptr || current == nullptr) {
2643 LOGE("Invalid parameter");
2644 return NOTI_EX_ERROR_INVALID_PARAMETER;
2647 Handle *h = static_cast<Handle*>(handle);
2648 if (!h->IsValidType(AbstractItem::Progress)) {
2649 LOGE("Invalid handle type");
2650 return NOTI_EX_ERROR_INVALID_PARAMETER;
2652 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2653 *current = p->GetCurrent();
2655 return NOTI_EX_ERROR_NONE;
2658 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2659 noti_ex_item_h handle, float current) {
2660 if (handle == nullptr) {
2661 LOGE("Invalid parameter");
2662 return NOTI_EX_ERROR_INVALID_PARAMETER;
2665 Handle *h = static_cast<Handle*>(handle);
2666 if (!h->IsValidType(AbstractItem::Progress)) {
2667 LOGE("Invalid handle type");
2668 return NOTI_EX_ERROR_INVALID_PARAMETER;
2670 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2671 p->SetCurrent(current);
2673 return NOTI_EX_ERROR_NONE;
2676 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2678 if (handle == nullptr || min == nullptr) {
2679 LOGE("Invalid parameter");
2680 return NOTI_EX_ERROR_INVALID_PARAMETER;
2683 Handle *h = static_cast<Handle*>(handle);
2684 if (!h->IsValidType(AbstractItem::Progress)) {
2685 LOGE("Invalid handle type");
2686 return NOTI_EX_ERROR_INVALID_PARAMETER;
2688 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2691 return NOTI_EX_ERROR_NONE;
2694 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2696 if (handle == nullptr || max == nullptr) {
2697 LOGE("Invalid parameter");
2698 return NOTI_EX_ERROR_INVALID_PARAMETER;
2701 Handle *h = static_cast<Handle*>(handle);
2702 if (!h->IsValidType(AbstractItem::Progress)) {
2703 LOGE("Invalid handle type");
2704 return NOTI_EX_ERROR_INVALID_PARAMETER;
2706 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2709 return NOTI_EX_ERROR_NONE;
2712 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2714 if (handle == nullptr || type == nullptr) {
2715 LOGE("Invalid parameter");
2716 return NOTI_EX_ERROR_INVALID_PARAMETER;
2719 Handle *h = static_cast<Handle*>(handle);
2720 if (!h->IsValidType(AbstractItem::Progress)) {
2721 LOGE("Invalid handle type");
2722 return NOTI_EX_ERROR_INVALID_PARAMETER;
2724 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2725 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2727 return NOTI_EX_ERROR_NONE;
2730 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2732 if (handle == nullptr) {
2733 LOGE("Invalid parameter");
2734 return NOTI_EX_ERROR_INVALID_PARAMETER;
2737 Handle *h = static_cast<Handle*>(handle);
2738 if (!h->IsValidType(AbstractItem::Progress)) {
2739 LOGE("Invalid handle type");
2740 return NOTI_EX_ERROR_INVALID_PARAMETER;
2742 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2743 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2745 return NOTI_EX_ERROR_NONE;
2748 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2749 noti_ex_reporter_events_s event_callbacks, void *data) {
2750 if (handle == nullptr) {
2751 LOGE("Invalid parameter");
2752 return NOTI_EX_ERROR_INVALID_PARAMETER;
2755 ReporterStub* stub = new (std::nothrow) ReporterStub(
2756 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2757 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2758 if (stub == nullptr) {
2759 LOGE("Fail to create manager");
2760 return NOTI_EX_ERROR_IO_ERROR;
2762 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2763 new ReporterCallbackInfo(event_callbacks, data)));
2765 *handle = static_cast<noti_ex_reporter_h>(stub);
2767 return NOTI_EX_ERROR_NONE;
2770 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2771 if (handle == nullptr) {
2772 LOGE("Invalid parameter");
2773 return NOTI_EX_ERROR_INVALID_PARAMETER;
2775 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2777 return NOTI_EX_ERROR_NONE;
2780 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2781 noti_ex_event_info_h info, noti_ex_error_e error) {
2782 if (handle == nullptr || info == nullptr) {
2783 LOGE("Invalid parameter");
2784 return NOTI_EX_ERROR_INVALID_PARAMETER;
2787 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2788 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2789 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2790 static_cast<NotificationError>(error));
2791 } catch (Exception &ex) {
2792 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2793 return NOTI_EX_ERROR_IO_ERROR;
2795 return NOTI_EX_ERROR_NONE;
2798 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2799 noti_ex_item_h noti, int *request_id) {
2800 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2801 LOGE("Invalid parameter");
2802 return NOTI_EX_ERROR_INVALID_PARAMETER;
2805 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2806 Handle* h = static_cast<Handle*>(noti);
2807 if (h->GetPtr().get() == nullptr) {
2808 LOGE("Invalid noti reference can not be sended");
2809 return NOTI_EX_ERROR_INVALID_PARAMETER;
2811 *request_id = stub->Post(h->GetPtr());
2813 } catch (Exception &ex) {
2814 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2815 return NOTI_EX_ERROR_IO_ERROR;
2817 return NOTI_EX_ERROR_NONE;
2820 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2821 noti_ex_item_h *noti_list, int count, int *request_id) {
2823 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2824 LOGE("Invalid parameter");
2825 return NOTI_EX_ERROR_INVALID_PARAMETER;
2828 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2829 list<shared_ptr<item::AbstractItem>> notiList;
2830 for (int i = 0; i < count; i++) {
2831 Handle* item = static_cast<Handle*>(noti_list[i]);
2832 notiList.push_back(item->GetPtr());
2834 *request_id = stub->Post(notiList);
2835 } catch (Exception &ex) {
2836 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2837 return NOTI_EX_ERROR_IO_ERROR;
2839 return NOTI_EX_ERROR_NONE;
2842 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2843 noti_ex_item_h noti, int *request_id) {
2844 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2845 LOGE("Invalid parameter");
2846 return NOTI_EX_ERROR_INVALID_PARAMETER;
2849 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2850 Handle* item = static_cast<Handle*>(noti);
2851 if (item->GetPtr().get() == nullptr) {
2852 LOGE("Invalid noti reference can not be sended");
2853 return NOTI_EX_ERROR_INVALID_PARAMETER;
2855 *request_id = stub->Update(item->GetPtr());
2857 } catch (Exception &ex) {
2858 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2859 return NOTI_EX_ERROR_IO_ERROR;
2861 return NOTI_EX_ERROR_NONE;
2864 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2865 noti_ex_item_h noti, int *request_id) {
2866 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2867 LOGE("Invalid parameter");
2868 return NOTI_EX_ERROR_INVALID_PARAMETER;
2871 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2872 Handle* item = static_cast<Handle*>(noti);
2873 if (item->GetPtr().get() == nullptr) {
2874 LOGE("Invalid noti reference can not be sended");
2875 return NOTI_EX_ERROR_INVALID_PARAMETER;
2877 *request_id = stub->Delete(item->GetPtr());
2879 } catch (Exception &ex) {
2880 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2881 return NOTI_EX_ERROR_IO_ERROR;
2883 return NOTI_EX_ERROR_NONE;
2886 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2887 noti_ex_reporter_h handle, int *request_id) {
2888 if (handle == nullptr || request_id == nullptr) {
2889 LOGE("Invalid parameter");
2890 return NOTI_EX_ERROR_INVALID_PARAMETER;
2893 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2894 *request_id = stub->DeleteAll();
2895 } catch (Exception &ex) {
2896 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2897 return NOTI_EX_ERROR_IO_ERROR;
2899 return NOTI_EX_ERROR_NONE;
2902 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2903 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2904 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2905 LOGE("Invalid parameter");
2906 return NOTI_EX_ERROR_INVALID_PARAMETER;
2909 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2910 *item = new Handle(stub->FindByRootID(root_id));
2911 } catch (Exception &ex) {
2912 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2913 return NOTI_EX_ERROR_IO_ERROR;
2915 return NOTI_EX_ERROR_NONE;
2918 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2919 const char *id, const char *text, const char *hyperlink) {
2920 if (handle == nullptr || text == nullptr) {
2921 LOGE("Invalid parameter");
2922 return NOTI_EX_ERROR_INVALID_PARAMETER;
2928 p = new (std::nothrow) TextItem(id, std::string(text),
2929 std::string(hyperlink));
2931 p = new (std::nothrow) TextItem(id, std::string(text));
2934 LOGE("Out-of-memory");
2935 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2938 *handle = new Handle(shared_ptr<AbstractItem>(p));
2940 return NOTI_EX_ERROR_NONE;
2943 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2944 const char *contents) {
2945 if (handle == nullptr || contents == nullptr) {
2946 LOGE("Invalid parameter");
2947 return NOTI_EX_ERROR_INVALID_PARAMETER;
2950 Handle* p = static_cast<Handle*>(handle);
2951 if (!p->IsValidType(AbstractItem::Text)) {
2952 LOGE("Invalid handle type");
2953 return NOTI_EX_ERROR_INVALID_PARAMETER;
2955 TextItem* ti = static_cast<TextItem*>(p->Get());
2956 ti->SetContents(std::string(contents));
2958 return NOTI_EX_ERROR_NONE;
2961 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2963 if (handle == nullptr || contents == nullptr) {
2964 LOGE("Invalid parameter");
2965 return NOTI_EX_ERROR_INVALID_PARAMETER;
2968 Handle* p = static_cast<Handle*>(handle);
2969 if (!p->IsValidType(AbstractItem::Text)) {
2970 LOGE("Invalid handle type");
2971 return NOTI_EX_ERROR_INVALID_PARAMETER;
2974 TextItem* ti = static_cast<TextItem*>(p->Get());
2976 if (ti->GetMultiLanguage() != nullptr &&
2977 !ti->GetMultiLanguage()->GetTranslatedString().empty())
2978 str = ti->GetMultiLanguage()->GetTranslatedString();
2979 else if (!ti->GetContents().empty())
2980 str = ti->GetContents();
2982 *contents = strdup(str.c_str());
2983 if (*contents == nullptr) {
2984 LOGE("Out-of-memory");
2985 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2988 return NOTI_EX_ERROR_NONE;
2991 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2992 noti_ex_item_h handle, char **hyper_link) {
2993 if (handle == nullptr || hyper_link == nullptr) {
2994 LOGE("Invalid parameter");
2995 return NOTI_EX_ERROR_INVALID_PARAMETER;
2998 Handle* p = static_cast<Handle*>(handle);
2999 if (!p->IsValidType(AbstractItem::Text)) {
3000 LOGE("Invalid handle type");
3001 return NOTI_EX_ERROR_INVALID_PARAMETER;
3003 TextItem* ti = static_cast<TextItem*>(p->Get());
3004 if (!ti->GetHyperLink().empty()) {
3005 *hyper_link = strdup(ti->GetHyperLink().c_str());
3006 if (*hyper_link == nullptr) {
3007 LOGE("Out-of-memory");
3008 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3012 return NOTI_EX_ERROR_NONE;
3015 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3016 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3017 if (handle == nullptr) {
3018 LOGE("Invalid parameter");
3019 return NOTI_EX_ERROR_INVALID_PARAMETER;
3022 Handle* p = static_cast<Handle*>(handle);
3023 if (!p->IsValidType(AbstractItem::Text)) {
3024 LOGE("Invalid handle type");
3025 return NOTI_EX_ERROR_INVALID_PARAMETER;
3028 TextItem* ti = static_cast<TextItem*>(p->Get());
3029 if (multi == nullptr) {
3030 ti->SetMultiLanguage(nullptr);
3031 return NOTI_EX_ERROR_NONE;
3034 shared_ptr<MultiLanguage> mul_ptr =
3035 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3036 ti->SetMultiLanguage(mul_ptr);
3037 ti->GetMultiLanguage()->UpdateString();
3039 return NOTI_EX_ERROR_NONE;
3042 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3043 const char *id, time_t time) {
3046 if (handle == nullptr) {
3047 LOGE("Invalid parameter");
3048 return NOTI_EX_ERROR_INVALID_PARAMETER;
3053 p = new (std::nothrow) TimeItem(id, time);
3055 p = new (std::nothrow) TimeItem(time);
3057 p = new (std::nothrow) TimeItem();
3061 LOGE("Out-of-memory");
3062 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3065 *handle = new Handle(shared_ptr<AbstractItem>(p));
3067 return NOTI_EX_ERROR_NONE;
3070 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3072 if (handle == nullptr || time == nullptr) {
3073 LOGE("Invalid parameter");
3074 return NOTI_EX_ERROR_INVALID_PARAMETER;
3076 Handle* h = static_cast<Handle*>(handle);
3077 if (!h->IsValidType(AbstractItem::Time)) {
3078 LOGE("Invalid handle type");
3079 return NOTI_EX_ERROR_INVALID_PARAMETER;
3081 TimeItem* p = static_cast<TimeItem*>(h->Get());
3082 *time = p->GetTime();
3084 return NOTI_EX_ERROR_NONE;
3087 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3088 noti_ex_action_h *handle, const char *extra) {
3089 if (handle == nullptr) {
3090 LOGE("Invalid parameter");
3091 return NOTI_EX_ERROR_INVALID_PARAMETER;
3094 string extra_str = "";
3096 extra_str = string(extra);
3098 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3099 new (std::nothrow) VisibilityAction(extra_str));
3100 if (ptr == nullptr) {
3101 LOGE("Out-of-memory");
3102 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3107 return NOTI_EX_ERROR_NONE;
3110 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3111 const char *id, bool visible) {
3112 if (handle == nullptr || id == nullptr) {
3113 LOGE("Invalid parameter");
3114 return NOTI_EX_ERROR_INVALID_PARAMETER;
3117 shared_ptr<AbstractAction>* ptr =
3118 static_cast<shared_ptr<AbstractAction>*>(handle);
3119 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3120 action->SetVisibility(id, visible);
3122 return NOTI_EX_ERROR_NONE;
3125 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3126 const char* msgid, const char* format, ...) {
3127 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3128 LOGE("Invalid parameter");
3129 return NOTI_EX_ERROR_INVALID_PARAMETER;
3132 const char* format_idx = format;
3135 va_start(args, format);
3136 while (*format_idx != '\0') {
3137 char* arg = nullptr;
3140 stringstream stream;
3141 if (*format_idx == '%') {
3142 switch (*(format_idx + 1)) {
3144 arg = va_arg(args, char *);
3145 arr.push_back(string(arg));
3148 arg_i = va_arg(args, int);
3149 arr.push_back(to_string(arg_i));
3152 arg_f = va_arg(args, double);
3153 stream << std::fixed << std::setprecision(2) << arg_f;
3154 arr.push_back(stream.str());
3162 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3164 LOGE("Out-of-memory");
3165 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3167 *handle = new shared_ptr<MultiLanguage>(p);
3169 return NOTI_EX_ERROR_NONE;
3172 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3173 if (handle == nullptr) {
3174 LOGE("Invalid parameter");
3175 return NOTI_EX_ERROR_INVALID_PARAMETER;
3178 shared_ptr<MultiLanguage>* mul_ptr =
3179 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3181 return NOTI_EX_ERROR_NONE;
3184 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3185 noti_ex_item_h item, int64_t* private_id) {
3186 if (item == nullptr || private_id == nullptr) {
3187 LOGE("Invalid parameter");
3188 return NOTI_EX_ERROR_INVALID_PARAMETER;
3191 Handle* h = static_cast<Handle*>(item);
3192 *private_id = static_pointer_cast<IItemInfoInternal>(
3193 h->Get()->GetInfo())->GetPrivateId();
3195 return NOTI_EX_ERROR_NONE;
3198 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3199 noti_ex_item_h item, int64_t priv_id) {
3200 if (item == nullptr) {
3201 LOGE("Invalid parameter");
3202 return NOTI_EX_ERROR_INVALID_PARAMETER;
3205 Handle* h = static_cast<Handle*>(item);
3206 static_pointer_cast<IItemInfoInternal>(
3207 h->Get()->GetInfo())->SetPrivateId(priv_id);
3209 return NOTI_EX_ERROR_NONE;