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 "api/notification_ex_visibility_action.h"
42 #include "api/notification_ex_internal.h"
43 #include "notification-ex/reporter.h"
44 #include "notification-ex/app_control_action.h"
45 #include "notification-ex/button_item.h"
46 #include "notification-ex/chat_message_item.h"
47 #include "notification-ex/checkbox_item.h"
48 #include "notification-ex/entry_item.h"
49 #include "notification-ex/group_item.h"
50 #include "notification-ex/input_selector_item.h"
51 #include "notification-ex/abstract_item.h"
52 #include "notification-ex/progress_item.h"
53 #include "notification-ex/time_item.h"
54 #include "notification-ex/visibility_action.h"
55 #include "notification-ex/event_info_internal.h"
56 #include "notification-ex/manager.h"
57 #include "notification-ex/dbus_sender.h"
58 #include "notification-ex/dbus_event_listener.h"
59 #include "notification-ex/exception.h"
60 #include "notification-ex/iitem_info_internal.h"
65 #define LOG_TAG "NOTIFICATION_EX"
70 #define EXPORT_API __attribute__((visibility("default")))
73 using namespace tizen_base;
74 using namespace notification::item;
75 using namespace notification;
81 explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
82 explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
83 : ref_(nullptr), ptr_(move(ptr)) { }
84 virtual ~Handle() = default;
85 item::AbstractItem* Get() const {
91 bool IsValidType(int type) const {
92 return (Get()->GetType() == type
93 || Get()->GetType() >= AbstractItem::Custom);
96 std::shared_ptr<item::AbstractItem> GetPtr() const {
98 return std::shared_ptr<item::AbstractItem>({});
103 item::AbstractItem* ref_;
104 std::shared_ptr<item::AbstractItem> ptr_;
107 class ManagerCallbackInfo {
109 ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
110 : user_data_(user_data) {
111 cb_.added = cb.added;
112 cb_.updated = cb.updated;
113 cb_.deleted = cb.deleted;
114 cb_.error = cb.error;
117 void InvokeAdded(Manager* manager, const IEventInfo& info,
118 list<shared_ptr<AbstractItem>> addedItem) {
119 if (cb_.added == nullptr)
121 noti_ex_item_h* added_item =
122 (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
123 if (added_item == nullptr) {
124 LOGE("Out of memory");
129 for (auto& i : addedItem) {
131 static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
134 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
135 cb_.added(static_cast<noti_ex_manager_h>(manager),
136 static_cast<noti_ex_event_info_h>(c_info), added_item,
137 addedItem.size(), user_data_);
140 void InvokeUpdated(Manager* manager, const IEventInfo& info,
141 shared_ptr<item::AbstractItem> updatedItem) {
142 if (cb_.updated == nullptr)
144 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
145 cb_.updated(static_cast<noti_ex_manager_h>(manager),
146 static_cast<noti_ex_event_info_h>(c_info),
147 static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
150 void InvokeDeleted(Manager* manager, const IEventInfo& info,
151 shared_ptr<item::AbstractItem> deletedItem) {
152 if (cb_.deleted == nullptr)
154 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
155 if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
156 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
157 static_cast<noti_ex_event_info_h>(c_info),
158 nullptr, user_data_);
160 cb_.deleted(static_cast<noti_ex_manager_h>(manager),
161 static_cast<noti_ex_event_info_h>(c_info),
162 static_cast<noti_ex_item_h>(
163 new Handle(deletedItem)), user_data_);
167 void InvokeError(Manager* manager, NotificationError error, int requestId) {
168 if (cb_.error == nullptr)
170 cb_.error(static_cast<noti_ex_manager_h>(manager),
171 static_cast<noti_ex_error_e>(error), requestId, user_data_);
175 noti_ex_manager_events_s cb_;
179 class ManagerStub : public Manager {
181 ManagerStub(std::unique_ptr<IEventSender> sender,
182 std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
183 : Manager(move(sender), move(listener), receiver_group) {
186 void OnAdd(const IEventInfo& info,
187 list<shared_ptr<AbstractItem>> addedItem) override {
188 cb_->InvokeAdded(this, info, addedItem);
191 void OnUpdate(const IEventInfo& info,
192 std::shared_ptr<item::AbstractItem> updatedItem) override {
193 cb_->InvokeUpdated(this, info, updatedItem);
196 void OnDelete(const IEventInfo& info,
197 shared_ptr<item::AbstractItem> deletedItem) override {
198 cb_->InvokeDeleted(this, info, deletedItem);
201 void OnError(NotificationError error, int requestId) override {
202 cb_->InvokeError(this, error, requestId);
205 int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
207 return NOTI_EX_ERROR_NONE;
210 int ClearManagerCallbackInfo() {
212 return NOTI_EX_ERROR_NONE;
216 unique_ptr<ManagerCallbackInfo> cb_;
220 class ReporterCallbackInfo {
222 ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
223 : user_data_(user_data) {
224 cb_.event = cb.event;
225 cb_.error = cb.error;
228 void InvokeEvent(Reporter* reporter, const IEventInfo& info,
229 list<shared_ptr<AbstractItem>> notiList) {
230 if (cb_.event == nullptr)
232 noti_ex_item_h* noti_list =
233 (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
234 if (noti_list == nullptr) {
235 LOGE("Out of memory");
240 for (auto& i : notiList) {
242 static_cast<noti_ex_item_h>(new Handle(i));
245 IEventInfo* c_info = const_cast<IEventInfo*>(&info);
246 cb_.event(static_cast<noti_ex_reporter_h>(reporter),
247 static_cast<noti_ex_event_info_h>(c_info), noti_list,
248 notiList.size(), user_data_);
252 void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
253 if (cb_.error == nullptr)
255 cb_.error(static_cast<noti_ex_reporter_h>(reporter),
256 static_cast<noti_ex_error_e>(error), requestId, user_data_);
260 noti_ex_reporter_events_s cb_;
264 class ReporterStub : public Reporter {
266 ReporterStub(std::unique_ptr<IEventSender> sender,
267 std::unique_ptr<IEventListener> listener)
268 : Reporter(move(sender), move(listener)) {
271 void OnEvent(const IEventInfo& info,
272 std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
273 cb_->InvokeEvent(this, info, notiList);
276 void OnError(NotificationError error, int requestId) override {
277 cb_->InvokeError(this, error, requestId);
280 int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
282 return NOTI_EX_ERROR_NONE;
285 int ClearReporterCallbackInfo() {
287 return NOTI_EX_ERROR_NONE;
291 unique_ptr<ReporterCallbackInfo> cb_;
296 void __noti_ex_free_str_array(char** val, int length) {
298 for (i = 0; i < length ; i++)
303 extern "C" EXPORT_API int noti_ex_action_app_control_create(
304 noti_ex_action_h *handle, app_control_h app_control,
306 if (handle == nullptr || app_control == nullptr) {
307 LOGE("Invalid parameter");
308 return NOTI_EX_ERROR_INVALID_PARAMETER;
311 shared_ptr<AbstractAction>* p;
314 p = new (std::nothrow) shared_ptr<AbstractAction>(
315 new (std::nothrow) AppControlAction(app_control, extra));
317 p = new (std::nothrow) shared_ptr<AbstractAction>(
318 new (std::nothrow) AppControlAction(app_control));
322 LOGE("Out-of-memory");
323 return NOTI_EX_ERROR_OUT_OF_MEMORY;
328 return NOTI_EX_ERROR_NONE;
331 extern "C" EXPORT_API int noti_ex_action_app_control_set(
332 noti_ex_action_h handle, app_control_h app_control) {
333 if (handle == nullptr || app_control == nullptr) {
334 LOGE("Invalid parameter");
335 return NOTI_EX_ERROR_INVALID_PARAMETER;
338 shared_ptr<AbstractAction>* ptr =
339 static_cast<shared_ptr<AbstractAction>*>(handle);
340 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
341 action->SetAppControl(app_control);
343 return NOTI_EX_ERROR_NONE;
346 extern "C" EXPORT_API int noti_ex_action_app_control_get(
347 noti_ex_action_h handle, app_control_h *app_control) {
348 if (handle == nullptr || app_control == nullptr) {
349 LOGE("Invalid parameter");
350 return NOTI_EX_ERROR_INVALID_PARAMETER;
353 shared_ptr<AbstractAction>* ptr =
354 static_cast<shared_ptr<AbstractAction>*>(handle);
355 AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
356 *app_control = action->GetAppControl();
358 return NOTI_EX_ERROR_NONE;
361 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
362 const char *id, const char *title) {
365 if (handle == nullptr || title == nullptr) {
366 LOGE("Invalid parameter");
367 return NOTI_EX_ERROR_INVALID_PARAMETER;
371 p = new (std::nothrow) ButtonItem(id, title);
373 p = new (std::nothrow) ButtonItem(title);
376 LOGE("Out-of-memory");
377 return NOTI_EX_ERROR_OUT_OF_MEMORY;
379 *handle = new Handle(shared_ptr<AbstractItem>(p));
381 return NOTI_EX_ERROR_NONE;
384 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
386 if (handle == nullptr || title == nullptr) {
387 LOGE("Invalid parameter");
388 return NOTI_EX_ERROR_INVALID_PARAMETER;
391 Handle* sp = static_cast<Handle*>(handle);
392 if (!sp->IsValidType(AbstractItem::Button)) {
393 LOGE("Invalid handle type");
394 return NOTI_EX_ERROR_INVALID_PARAMETER;
397 ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
399 if (p->GetMultiLanguage() != nullptr &&
400 !p->GetMultiLanguage()->GetTranslatedString().empty())
401 str = p->GetMultiLanguage()->GetTranslatedString();
402 else if (!p->GetTitle().empty())
405 *title = strdup(str.c_str());
406 if (*title == nullptr) {
407 LOGE("Out-of-memory");
408 return NOTI_EX_ERROR_OUT_OF_MEMORY;
411 return NOTI_EX_ERROR_NONE;
414 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
415 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
416 if (handle == nullptr) {
417 LOGE("Invalid parameter");
418 return NOTI_EX_ERROR_INVALID_PARAMETER;
421 Handle* p = static_cast<Handle*>(handle);
422 if (!p->IsValidType(AbstractItem::Button)) {
423 LOGE("Invalid handle type");
424 return NOTI_EX_ERROR_INVALID_PARAMETER;
427 ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
428 if (multi == nullptr) {
429 bi->SetMultiLanguage(nullptr);
430 return NOTI_EX_ERROR_NONE;
433 shared_ptr<MultiLanguage> mul_ptr =
434 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
436 mul_ptr->UpdateString();
437 bi->SetMultiLanguage(mul_ptr);
439 return NOTI_EX_ERROR_NONE;
442 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
443 noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
444 noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
445 noti_ex_item_chat_message_type_e message_type) {
446 if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
447 LOGE("Invalid parameter");
448 return NOTI_EX_ERROR_INVALID_PARAMETER;
451 auto* p = new (std::nothrow) ChatMessageItem(id,
452 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
453 dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
454 dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
455 dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
456 static_cast<ChatMessageItem::Type>(message_type));
458 LOGE("Out-of-memory");
459 return NOTI_EX_ERROR_OUT_OF_MEMORY;
462 *handle = new Handle(shared_ptr<AbstractItem>(p));
464 return NOTI_EX_ERROR_NONE;
467 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
468 noti_ex_item_h handle, noti_ex_item_h *name) {
469 if (handle == nullptr || name == nullptr) {
470 LOGE("Invalid parameter");
471 return NOTI_EX_ERROR_INVALID_PARAMETER;
473 Handle* h = static_cast<Handle*>(handle);
474 if (!h->IsValidType(AbstractItem::ChatMessage)) {
475 LOGE("Invalid handle type");
476 return NOTI_EX_ERROR_INVALID_PARAMETER;
478 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
479 *name = new Handle(&(p->GetNameItem()));
481 return NOTI_EX_ERROR_NONE;
484 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
485 noti_ex_item_h handle, noti_ex_item_h *text) {
486 if (handle == nullptr || text == nullptr) {
487 LOGE("Invalid parameter");
488 return NOTI_EX_ERROR_INVALID_PARAMETER;
491 Handle* h = static_cast<Handle*>(handle);
492 if (!h->IsValidType(AbstractItem::ChatMessage)) {
493 LOGE("Invalid handle type");
494 return NOTI_EX_ERROR_INVALID_PARAMETER;
496 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
497 *text = new Handle(&(p->GetTextItem()));
499 return NOTI_EX_ERROR_NONE;
502 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
503 noti_ex_item_h handle, noti_ex_item_h *image) {
504 if (handle == nullptr || image == nullptr) {
505 LOGE("Invalid parameter");
506 return NOTI_EX_ERROR_INVALID_PARAMETER;
509 Handle* h = static_cast<Handle*>(handle);
510 if (!h->IsValidType(AbstractItem::ChatMessage)) {
511 LOGE("Invalid handle type");
512 return NOTI_EX_ERROR_INVALID_PARAMETER;
514 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
515 *image = new Handle(&(p->GetImageItem()));
517 return NOTI_EX_ERROR_NONE;
520 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
521 noti_ex_item_h handle, noti_ex_item_h *time) {
522 if (handle == nullptr || time == nullptr) {
523 LOGE("Invalid parameter");
524 return NOTI_EX_ERROR_INVALID_PARAMETER;
527 Handle* h = static_cast<Handle*>(handle);
528 if (!h->IsValidType(AbstractItem::ChatMessage)) {
529 LOGE("Invalid handle type");
530 return NOTI_EX_ERROR_INVALID_PARAMETER;
532 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
533 *time = new Handle(&(p->GetTimeItem()));
535 return NOTI_EX_ERROR_NONE;
538 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
539 noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
540 if (handle == nullptr || message_type == nullptr) {
541 LOGE("Invalid parameter");
542 return NOTI_EX_ERROR_INVALID_PARAMETER;
545 Handle* h = static_cast<Handle*>(handle);
546 if (!h->IsValidType(AbstractItem::ChatMessage)) {
547 LOGE("Invalid handle type");
548 return NOTI_EX_ERROR_INVALID_PARAMETER;
550 ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
551 *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
553 return NOTI_EX_ERROR_NONE;
556 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
557 const char *id, const char *title, bool checked) {
560 if (handle == nullptr || title == nullptr) {
561 LOGE("Invalid parameter");
562 return NOTI_EX_ERROR_INVALID_PARAMETER;
565 p = new (std::nothrow) CheckBoxItem(id, title, checked);
567 LOGE("Out-of-memory");
568 return NOTI_EX_ERROR_OUT_OF_MEMORY;
571 *handle = new Handle(shared_ptr<AbstractItem>(p));
573 return NOTI_EX_ERROR_NONE;
576 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
578 if (handle == nullptr || title == nullptr) {
579 LOGE("Invalid parameter");
580 return NOTI_EX_ERROR_INVALID_PARAMETER;
582 Handle* h = static_cast<Handle*>(handle);
583 if (!h->IsValidType(AbstractItem::CheckBox)) {
584 LOGE("Invalid handle type");
585 return NOTI_EX_ERROR_INVALID_PARAMETER;
588 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
590 if (p->GetMultiLanguage() != nullptr &&
591 !p->GetMultiLanguage()->GetTranslatedString().empty())
592 str = p->GetMultiLanguage()->GetTranslatedString();
593 else if (!p->GetTitle().empty())
596 *title = strdup(str.c_str());
597 if (*title == nullptr) {
598 LOGE("Out-of-memory");
599 return NOTI_EX_ERROR_OUT_OF_MEMORY;
602 return NOTI_EX_ERROR_NONE;
605 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
606 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
607 if (handle == nullptr) {
608 LOGE("Invalid parameter");
609 return NOTI_EX_ERROR_INVALID_PARAMETER;
612 Handle* p = static_cast<Handle*>(handle);
613 if (!p->IsValidType(AbstractItem::CheckBox)) {
614 LOGE("Invalid handle type");
615 return NOTI_EX_ERROR_INVALID_PARAMETER;
618 CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
619 if (multi == nullptr) {
620 ci->SetMultiLanguage(nullptr);
621 return NOTI_EX_ERROR_NONE;
624 shared_ptr<MultiLanguage> mul_ptr =
625 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
626 mul_ptr->UpdateString();
627 ci->SetMultiLanguage(mul_ptr);
629 return NOTI_EX_ERROR_NONE;
632 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
633 noti_ex_item_h handle, bool *checked) {
634 if (handle == nullptr || checked == nullptr) {
635 LOGE("Invalid parameter");
636 return NOTI_EX_ERROR_INVALID_PARAMETER;
638 Handle* h = static_cast<Handle*>(handle);
639 if (!h->IsValidType(AbstractItem::CheckBox)) {
640 LOGE("Invalid handle type");
641 return NOTI_EX_ERROR_INVALID_PARAMETER;
643 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
644 *checked = p->IsChecked();
646 return NOTI_EX_ERROR_NONE;
649 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
650 noti_ex_item_h handle, bool checked) {
651 if (handle == nullptr) {
652 LOGE("Invalid parameter");
653 return NOTI_EX_ERROR_INVALID_PARAMETER;
656 Handle* h = static_cast<Handle*>(handle);
657 if (!h->IsValidType(AbstractItem::CheckBox)) {
658 LOGE("Invalid handle type");
659 return NOTI_EX_ERROR_INVALID_PARAMETER;
662 CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
663 p->SetChecked(checked);
665 return NOTI_EX_ERROR_NONE;
668 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
672 if (handle == nullptr) {
673 LOGE("Invalid parameter");
674 return NOTI_EX_ERROR_INVALID_PARAMETER;
677 p = new (std::nothrow) EntryItem(id);
679 LOGE("Out-of-memory");
680 return NOTI_EX_ERROR_OUT_OF_MEMORY;
683 *handle = new Handle(shared_ptr<AbstractItem>(p));
685 return NOTI_EX_ERROR_NONE;
688 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
690 if (handle == nullptr || text == nullptr) {
691 LOGE("Invalid parameter");
692 return NOTI_EX_ERROR_INVALID_PARAMETER;
695 Handle* h = static_cast<Handle*>(handle);
696 if (!h->IsValidType(AbstractItem::Entry)) {
697 LOGE("Invalid handle type");
698 return NOTI_EX_ERROR_INVALID_PARAMETER;
701 EntryItem* p = static_cast<EntryItem*>(h->Get());
703 if (p->GetMultiLanguage() != nullptr &&
704 !p->GetMultiLanguage()->GetTranslatedString().empty())
705 str = p->GetMultiLanguage()->GetTranslatedString();
706 else if (!p->GetText().empty())
709 *text = strdup(str.c_str());
710 if (*text == nullptr) {
711 LOGE("Out-of-memory");
712 return NOTI_EX_ERROR_OUT_OF_MEMORY;
715 return NOTI_EX_ERROR_NONE;
718 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
720 if (handle == nullptr || text == nullptr) {
721 LOGE("Invalid parameter");
722 return NOTI_EX_ERROR_INVALID_PARAMETER;
724 Handle* h = static_cast<Handle*>(handle);
725 if (!h->IsValidType(AbstractItem::Entry)) {
726 LOGE("Invalid handle type");
727 return NOTI_EX_ERROR_INVALID_PARAMETER;
729 EntryItem* p = static_cast<EntryItem*>(h->Get());
730 p->SetText(std::string(text));
732 return NOTI_EX_ERROR_NONE;
735 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
736 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
737 if (handle == nullptr) {
738 LOGE("Invalid parameter");
739 return NOTI_EX_ERROR_INVALID_PARAMETER;
742 Handle* p = static_cast<Handle*>(handle);
743 if (!p->IsValidType(AbstractItem::Entry)) {
744 LOGE("Invalid handle type");
745 return NOTI_EX_ERROR_INVALID_PARAMETER;
748 EntryItem* ei = static_cast<EntryItem*>(p->Get());
749 if (multi == nullptr) {
750 ei->SetMultiLanguage(nullptr);
751 return NOTI_EX_ERROR_NONE;
754 shared_ptr<MultiLanguage> mul_ptr =
755 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
756 ei->SetMultiLanguage(mul_ptr);
757 ei->GetMultiLanguage()->UpdateString();
759 return NOTI_EX_ERROR_NONE;
762 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
763 noti_ex_event_info_h* cloned_handle) {
764 if (handle == nullptr || cloned_handle == nullptr) {
765 LOGE("Invalid parameter");
766 return NOTI_EX_ERROR_INVALID_PARAMETER;
769 Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
770 EventInfo* info = new EventInfo(cloned);
771 *cloned_handle = info;
772 return NOTI_EX_ERROR_NONE;
775 extern "C" EXPORT_API int noti_ex_event_info_destroy(
776 noti_ex_event_info_h handle) {
777 if (handle == nullptr) {
778 LOGE("Invalid parameter");
779 return NOTI_EX_ERROR_INVALID_PARAMETER;
781 EventInfo* info = static_cast<EventInfo*>(handle);
783 return NOTI_EX_ERROR_NONE;
786 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
787 noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
788 if (handle == nullptr || event_type == nullptr) {
789 LOGE("Invalid parameter");
790 return NOTI_EX_ERROR_INVALID_PARAMETER;
792 EventInfo* info = static_cast<EventInfo*>(handle);
793 *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
795 return NOTI_EX_ERROR_NONE;
798 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
799 noti_ex_event_info_h handle, char **owner) {
800 if (handle == nullptr || owner == nullptr) {
801 LOGE("Invalid parameter");
802 return NOTI_EX_ERROR_INVALID_PARAMETER;
804 EventInfo* info = static_cast<EventInfo*>(handle);
805 *owner = strdup(info->GetOwner().c_str());
806 return NOTI_EX_ERROR_NONE;
809 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
810 noti_ex_event_info_h handle, char **channel) {
811 if (handle == nullptr || channel == nullptr) {
812 LOGE("Invalid parameter");
813 return NOTI_EX_ERROR_INVALID_PARAMETER;
815 EventInfo* info = static_cast<EventInfo*>(handle);
816 *channel = strdup(info->GetChannel().c_str());
817 return NOTI_EX_ERROR_NONE;
820 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
821 noti_ex_event_info_h handle, char **item_id) {
822 if (handle == nullptr || item_id == nullptr) {
823 LOGE("Invalid parameter");
824 return NOTI_EX_ERROR_INVALID_PARAMETER;
826 EventInfo* info = static_cast<EventInfo*>(handle);
827 *item_id = strdup(info->GetItemId().c_str());
828 return NOTI_EX_ERROR_NONE;
831 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
832 noti_ex_event_info_h handle, int *req_id) {
833 if (handle == nullptr || req_id == nullptr) {
834 LOGE("Invalid parameter");
835 return NOTI_EX_ERROR_INVALID_PARAMETER;
837 EventInfo* info = static_cast<EventInfo*>(handle);
838 *req_id = info->GetRequestId();
839 return NOTI_EX_ERROR_NONE;
842 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
846 if (handle == nullptr) {
847 LOGE("Invalid parameter");
848 return NOTI_EX_ERROR_INVALID_PARAMETER;
852 p = new (std::nothrow) GroupItem(id);
854 p = new (std::nothrow) GroupItem();
857 LOGE("Out-of-memory");
858 return NOTI_EX_ERROR_OUT_OF_MEMORY;
861 *handle = new Handle(shared_ptr<AbstractItem>(p));
863 return NOTI_EX_ERROR_NONE;
866 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
868 if (handle == nullptr) {
869 LOGE("Invalid parameter");
870 return NOTI_EX_ERROR_INVALID_PARAMETER;
872 Handle* h = static_cast<Handle*>(handle);
873 if (!h->IsValidType(AbstractItem::Group)) {
874 LOGE("Invalid handle type");
875 return NOTI_EX_ERROR_INVALID_PARAMETER;
877 GroupItem* p = static_cast<GroupItem*>(h->Get());
878 p->SetDirection(vertical);
880 return NOTI_EX_ERROR_NONE;
883 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
885 if (handle == nullptr) {
886 LOGE("Invalid parameter");
887 return NOTI_EX_ERROR_INVALID_PARAMETER;
889 Handle* h = static_cast<Handle*>(handle);
890 if (!h->IsValidType(AbstractItem::Group)) {
891 LOGE("Invalid handle type");
892 return NOTI_EX_ERROR_INVALID_PARAMETER;
894 GroupItem* p = static_cast<GroupItem*>(h->Get());
895 *vertical = p->IsVertical();
897 return NOTI_EX_ERROR_NONE;
900 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
902 if (handle == nullptr) {
903 LOGE("Invalid parameter");
904 return NOTI_EX_ERROR_INVALID_PARAMETER;
906 Handle* h = static_cast<Handle*>(handle);
907 if (!h->IsValidType(AbstractItem::Group)) {
908 LOGE("Invalid handle type");
909 return NOTI_EX_ERROR_INVALID_PARAMETER;
911 GroupItem* p = static_cast<GroupItem*>(h->Get());
912 if (!p->GetAppLabel().empty()) {
913 *label = strdup(p->GetAppLabel().c_str());
914 if (*label == nullptr) {
915 LOGE("Out-of-memory");
916 return NOTI_EX_ERROR_OUT_OF_MEMORY;
920 return NOTI_EX_ERROR_NONE;
923 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
924 noti_ex_item_h child) {
925 if (handle == nullptr || child == nullptr) {
926 LOGE("Invalid parameter");
927 return NOTI_EX_ERROR_INVALID_PARAMETER;
929 Handle* h = static_cast<Handle*>(handle);
930 if (!h->IsValidType(AbstractItem::Group)) {
931 LOGE("Invalid handle type");
932 return NOTI_EX_ERROR_INVALID_PARAMETER;
934 auto p = static_cast<GroupItem*>(h->Get());
935 p->AddChild((static_cast<Handle*>(child))->GetPtr());
937 return NOTI_EX_ERROR_NONE;
940 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
941 const char *item_id) {
942 if (handle == nullptr || item_id == nullptr) {
943 LOGE("Invalid parameter");
944 return NOTI_EX_ERROR_INVALID_PARAMETER;
946 Handle* h = static_cast<Handle*>(handle);
947 if (!h->IsValidType(AbstractItem::Group)) {
948 LOGE("Invalid handle type");
949 return NOTI_EX_ERROR_INVALID_PARAMETER;
951 GroupItem* p = static_cast<GroupItem*>(h->Get());
952 p->RemoveChild(std::string(item_id));
954 return NOTI_EX_ERROR_NONE;
957 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
958 noti_ex_item_group_foreach_child_cb callback, void *data) {
959 if (handle == nullptr || callback == nullptr) {
960 LOGE("Invalid parameter");
961 return NOTI_EX_ERROR_INVALID_PARAMETER;
964 Handle* h = static_cast<Handle*>(handle);
965 if (!h->IsValidType(AbstractItem::Group)) {
966 LOGE("Invalid handle type");
967 return NOTI_EX_ERROR_INVALID_PARAMETER;
969 GroupItem* p = static_cast<GroupItem*>(h->Get());
970 list<shared_ptr<AbstractItem>> children = p->GetChildren();
971 LOGI("Retrive (%zd)", children.size());
972 for (auto i : children) {
974 static_cast<noti_ex_item_h>(new Handle(i)), data);
975 if (ret != NOTI_EX_ERROR_NONE) {
976 LOGW("callback return (%d) stop foreach", ret);
981 return NOTI_EX_ERROR_NONE;
984 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
985 const char *id, const char *image_path) {
988 if (handle == nullptr || image_path == nullptr) {
989 LOGE("Invalid parameter");
990 return NOTI_EX_ERROR_INVALID_PARAMETER;
994 p = new (std::nothrow) ImageItem(id, image_path);
996 p = new (std::nothrow) ImageItem(image_path);
999 LOGE("Out-of-memory");
1000 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1003 *handle = new Handle(shared_ptr<AbstractItem>(p));
1005 return NOTI_EX_ERROR_NONE;
1008 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1009 noti_ex_item_h handle, char **image_path) {
1010 if (handle == nullptr || image_path == nullptr) {
1011 LOGE("Invalid parameter");
1012 return NOTI_EX_ERROR_INVALID_PARAMETER;
1014 Handle* h = static_cast<Handle*>(handle);
1015 if (!h->IsValidType(AbstractItem::Image)) {
1016 LOGE("Invalid handle type");
1017 return NOTI_EX_ERROR_INVALID_PARAMETER;
1019 ImageItem* p = static_cast<ImageItem*>(h->Get());
1020 if (!p->GetImagePath().empty()) {
1021 *image_path = strdup(p->GetImagePath().c_str());
1022 if (*image_path == nullptr) {
1023 LOGE("Out-of-memory");
1024 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1028 return NOTI_EX_ERROR_NONE;
1031 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1032 noti_ex_item_h *handle, const char *id) {
1033 InputSelectorItem* p;
1035 if (handle == nullptr) {
1036 LOGE("Invalid parameter");
1037 return NOTI_EX_ERROR_INVALID_PARAMETER;
1041 p = new (std::nothrow) InputSelectorItem(id);
1043 p = new (std::nothrow) InputSelectorItem();
1046 LOGE("Out-of-memory");
1047 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1050 *handle = new Handle(shared_ptr<AbstractItem>(p));
1052 return NOTI_EX_ERROR_NONE;
1055 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1056 noti_ex_item_h handle, char ***contents_list, int *count) {
1057 if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1058 LOGE("Invalid parameter");
1059 return NOTI_EX_ERROR_INVALID_PARAMETER;
1062 Handle* h = static_cast<Handle*>(handle);
1063 if (!h->IsValidType(AbstractItem::InputSelector)) {
1064 LOGE("Invalid handle type");
1065 return NOTI_EX_ERROR_INVALID_PARAMETER;
1068 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1069 vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1070 list<string> contents;
1071 if (arr.size() == 0) {
1072 contents = p->GetContents();
1074 for (auto& i : arr) {
1075 contents.push_back(i->GetTranslatedString());
1079 char **list = (char**)calloc(contents.size(), sizeof(char*));
1080 if (list == nullptr) {
1081 LOGE("Out of memory");
1082 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1086 for (auto& i : contents) {
1087 list[idx] = strdup(i.c_str());
1088 if (list[idx] == nullptr) {
1089 __noti_ex_free_str_array(list, idx);
1090 LOGE("Out of memory");
1091 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1096 *count = contents.size();
1097 *contents_list = list;
1099 return NOTI_EX_ERROR_NONE;
1102 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1103 noti_ex_item_h handle, const char **contents, int count) {
1104 if (handle == nullptr || contents == nullptr) {
1105 LOGE("Invalid parameter");
1106 return NOTI_EX_ERROR_INVALID_PARAMETER;
1109 list<string> new_contents;
1110 Handle* h = static_cast<Handle*>(handle);
1111 if (!h->IsValidType(AbstractItem::InputSelector)) {
1112 LOGE("Invalid handle type");
1113 return NOTI_EX_ERROR_INVALID_PARAMETER;
1115 InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1116 for (int i = 0; i < count; i++) {
1117 new_contents.push_back(contents[i]);
1119 p->SetContents(move(new_contents));
1121 return NOTI_EX_ERROR_NONE;
1124 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1125 noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1126 if (handle == nullptr) {
1127 LOGE("Invalid parameter");
1128 return NOTI_EX_ERROR_INVALID_PARAMETER;
1131 Handle* p = static_cast<Handle*>(handle);
1132 if (!p->IsValidType(AbstractItem::InputSelector)) {
1133 LOGE("Invalid handle type");
1134 return NOTI_EX_ERROR_INVALID_PARAMETER;
1137 vector<shared_ptr<MultiLanguage>> m_list;
1138 for (int i = 0; i < count; i++) {
1139 shared_ptr<MultiLanguage> mul_ptr =
1140 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1141 mul_ptr->UpdateString();
1142 m_list.push_back(mul_ptr);
1145 InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1146 input->SetMultiLanguage(m_list);
1148 return NOTI_EX_ERROR_NONE;
1151 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1152 unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1153 if (handle == nullptr) {
1154 LOGE("Invalid parameter");
1155 return NOTI_EX_ERROR_INVALID_PARAMETER;
1158 auto* ptr = new (std::nothrow) shared_ptr<Color>(
1159 new (std::nothrow) Color(a, r, g, b));
1160 if (ptr == nullptr || ptr->get() == nullptr) {
1161 LOGE("Out-of-memory");
1162 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1167 return NOTI_EX_ERROR_NONE;
1170 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1171 if (handle == nullptr) {
1172 LOGE("Invalid parameter");
1173 return NOTI_EX_ERROR_INVALID_PARAMETER;
1176 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1179 return NOTI_EX_ERROR_NONE;
1182 extern "C" EXPORT_API int noti_ex_color_get_alpha(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)->GetAVal();
1192 return NOTI_EX_ERROR_NONE;
1195 extern "C" EXPORT_API int noti_ex_color_get_red(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)->GetRVal();
1205 return NOTI_EX_ERROR_NONE;
1208 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1209 unsigned char *val) {
1210 if (handle == nullptr || val == nullptr) {
1211 LOGE("Invalid parameter");
1212 return NOTI_EX_ERROR_INVALID_PARAMETER;
1215 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1216 *val = (*p)->GetGVal();
1218 return NOTI_EX_ERROR_NONE;
1221 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1222 unsigned char *val) {
1223 if (handle == nullptr || val == nullptr) {
1224 LOGE("Invalid parameter");
1225 return NOTI_EX_ERROR_INVALID_PARAMETER;
1228 shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1229 *val = (*p)->GetBVal();
1231 return NOTI_EX_ERROR_NONE;
1234 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1235 int left, int top, int right, int bottom) {
1236 if (handle == nullptr) {
1237 LOGE("Invalid parameter");
1238 return NOTI_EX_ERROR_INVALID_PARAMETER;
1241 auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1242 new (std::nothrow) Padding(left, top, right, bottom));
1243 if (ptr == nullptr || ptr->get() == nullptr) {
1244 LOGE("Out-of-memory");
1245 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1250 return NOTI_EX_ERROR_NONE;
1253 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1254 if (handle == nullptr) {
1255 LOGE("Invalid parameter");
1256 return NOTI_EX_ERROR_INVALID_PARAMETER;
1259 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1262 return NOTI_EX_ERROR_NONE;
1265 extern "C" EXPORT_API int noti_ex_padding_get_left(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)->GetLeft();
1275 return NOTI_EX_ERROR_NONE;
1278 extern "C" EXPORT_API int noti_ex_padding_get_top(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)->GetTop();
1288 return NOTI_EX_ERROR_NONE;
1291 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1293 if (handle == nullptr || val == nullptr) {
1294 LOGE("Invalid parameter");
1295 return NOTI_EX_ERROR_INVALID_PARAMETER;
1298 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1299 *val = (*p)->GetRight();
1301 return NOTI_EX_ERROR_NONE;
1304 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1306 if (handle == nullptr || val == nullptr) {
1307 LOGE("Invalid parameter");
1308 return NOTI_EX_ERROR_INVALID_PARAMETER;
1311 shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1312 *val = (*p)->GetBottom();
1314 return NOTI_EX_ERROR_NONE;
1317 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1318 int x, int y, int w, int h) {
1319 if (handle == nullptr) {
1320 LOGE("Invalid parameter");
1321 return NOTI_EX_ERROR_INVALID_PARAMETER;
1324 auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1325 new (std::nothrow) Geometry(x, y, w, h));
1326 if (ptr == nullptr || ptr->get() == nullptr) {
1327 LOGE("Out-of-memory");
1328 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1333 return NOTI_EX_ERROR_NONE;
1336 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1337 if (handle == nullptr) {
1338 LOGE("Invalid parameter");
1339 return NOTI_EX_ERROR_INVALID_PARAMETER;
1342 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1345 return NOTI_EX_ERROR_NONE;
1348 extern "C" EXPORT_API int noti_ex_geometry_get_x(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)->GetX();
1358 return NOTI_EX_ERROR_NONE;
1361 extern "C" EXPORT_API int noti_ex_geometry_get_y(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)->GetY();
1371 return NOTI_EX_ERROR_NONE;
1374 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1376 if (handle == nullptr || val == nullptr) {
1377 LOGE("Invalid parameter");
1378 return NOTI_EX_ERROR_INVALID_PARAMETER;
1381 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1382 *val = (*p)->GetWidth();
1384 return NOTI_EX_ERROR_NONE;
1387 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1389 if (handle == nullptr || val == nullptr) {
1390 LOGE("Invalid parameter");
1391 return NOTI_EX_ERROR_INVALID_PARAMETER;
1394 shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1395 *val = (*p)->GetHeight();
1397 return NOTI_EX_ERROR_NONE;
1400 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1401 noti_ex_color_h color,
1402 noti_ex_padding_h padding,
1403 noti_ex_geometry_h geometry) {
1404 if (handle == nullptr) {
1405 LOGE("Invalid parameter");
1406 return NOTI_EX_ERROR_INVALID_PARAMETER;
1409 shared_ptr<Color> col = (color == nullptr) ?
1410 nullptr : *(static_cast<shared_ptr<Color>*>(color));
1411 shared_ptr<Padding> padd = (padding == nullptr) ?
1412 nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1413 shared_ptr<Geometry> geo = (geometry == nullptr) ?
1414 nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1416 auto* ptr = new (std::nothrow) shared_ptr<Style>(
1417 new (std::nothrow) Style(col, padd, geo));
1418 if (ptr == nullptr || ptr->get() == nullptr) {
1419 LOGE("Out-of-memory");
1420 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1425 return NOTI_EX_ERROR_NONE;
1428 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1429 if (handle == nullptr) {
1430 LOGE("Invalid parameter");
1431 return NOTI_EX_ERROR_INVALID_PARAMETER;
1434 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1437 return NOTI_EX_ERROR_NONE;
1440 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1441 noti_ex_padding_h *padding) {
1442 if (handle == nullptr || padding == nullptr) {
1443 LOGE("Invalid parameter");
1444 return NOTI_EX_ERROR_INVALID_PARAMETER;
1447 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1448 if ((*p)->GetPadding() == nullptr) {
1449 LOGW("Padding info is null");
1450 return NOTI_EX_ERROR_INVALID_PARAMETER;
1453 shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1454 new (std::nothrow) Padding(*((*p)->GetPadding())));
1455 if (padd == nullptr || padd->get() == nullptr) {
1456 LOGE("Out-of-memory");
1457 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1462 return NOTI_EX_ERROR_NONE;
1466 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1467 noti_ex_padding_h padding) {
1468 if (handle == nullptr) {
1469 LOGE("Invalid parameter");
1470 return NOTI_EX_ERROR_INVALID_PARAMETER;
1473 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1474 if (padding == nullptr) {
1475 (*p)->SetPadding(nullptr);
1476 return NOTI_EX_ERROR_NONE;
1479 shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1480 (*p)->SetPadding(*padd);
1482 return NOTI_EX_ERROR_NONE;
1485 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1486 noti_ex_color_h *color) {
1487 if (handle == nullptr || color == nullptr) {
1488 LOGE("Invalid parameter");
1489 return NOTI_EX_ERROR_INVALID_PARAMETER;
1492 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1493 if ((*p)->GetColor() == nullptr) {
1494 LOGW("Color info is null");
1495 return NOTI_EX_ERROR_INVALID_PARAMETER;
1498 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1499 new (std::nothrow) Color(*((*p)->GetColor())));
1500 if (col == nullptr || col->get() == nullptr) {
1501 LOGE("Out-of-memory");
1502 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1507 return NOTI_EX_ERROR_NONE;
1510 extern "C" EXPORT_API int noti_ex_style_set_color(
1511 noti_ex_style_h handle, noti_ex_color_h color) {
1512 if (handle == nullptr) {
1513 LOGE("Invalid parameter");
1514 return NOTI_EX_ERROR_INVALID_PARAMETER;
1517 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1518 if (color == nullptr) {
1519 (*p)->SetColor(nullptr);
1520 return NOTI_EX_ERROR_NONE;
1523 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1524 (*p)->SetColor(*col);
1526 return NOTI_EX_ERROR_NONE;
1529 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1530 noti_ex_geometry_h *geometry) {
1531 if (handle == nullptr || geometry == nullptr) {
1532 LOGE("Invalid parameter");
1533 return NOTI_EX_ERROR_INVALID_PARAMETER;
1536 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1537 if ((*p)->GetGeometry() == nullptr) {
1538 LOGW("Geometry info is null");
1539 return NOTI_EX_ERROR_INVALID_PARAMETER;
1542 shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1543 new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1544 if (geo == nullptr || geo->get() == nullptr) {
1545 LOGE("Out-of-memory");
1546 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1551 return NOTI_EX_ERROR_NONE;
1554 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1555 noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1556 if (handle == nullptr) {
1557 LOGE("Invalid parameter");
1558 return NOTI_EX_ERROR_INVALID_PARAMETER;
1561 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1562 if (geometry == nullptr) {
1563 (*p)->SetGeometry(nullptr);
1564 return NOTI_EX_ERROR_NONE;
1567 shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1568 (*p)->SetGeometry(*geo);
1570 return NOTI_EX_ERROR_NONE;
1573 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1574 noti_ex_style_h handle, char** background_image) {
1575 if (handle == nullptr || background_image == nullptr) {
1576 LOGE("Invalid parameter");
1577 return NOTI_EX_ERROR_INVALID_PARAMETER;
1580 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1581 *background_image = strdup((*p)->GetBackgroundImage().c_str());
1583 return NOTI_EX_ERROR_NONE;
1586 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1587 noti_ex_style_h handle, char* background_image) {
1588 if (handle == nullptr || background_image == nullptr) {
1589 LOGE("Invalid parameter");
1590 return NOTI_EX_ERROR_INVALID_PARAMETER;
1593 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1594 (*p)->SetBackgroundImage(background_image);
1596 return NOTI_EX_ERROR_NONE;
1599 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1600 noti_ex_style_h handle, noti_ex_color_h* color) {
1601 if (handle == nullptr || color == nullptr) {
1602 LOGE("Invalid parameter");
1603 return NOTI_EX_ERROR_INVALID_PARAMETER;
1606 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1607 if ((*p)->GetBackgroundColor() == nullptr) {
1608 LOGW("Color info is null");
1609 return NOTI_EX_ERROR_INVALID_PARAMETER;
1612 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1613 new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1614 if (col == nullptr || col->get() == nullptr) {
1615 LOGE("Out-of-memory");
1616 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1621 return NOTI_EX_ERROR_NONE;
1624 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1625 noti_ex_style_h handle, noti_ex_color_h color) {
1626 if (handle == nullptr || color == nullptr) {
1627 LOGE("Invalid parameter");
1628 return NOTI_EX_ERROR_INVALID_PARAMETER;
1631 shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1632 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1633 (*p)->SetBackgroundColor(*col);
1635 return NOTI_EX_ERROR_NONE;
1638 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1639 noti_ex_color_h color) {
1640 if (handle == nullptr) {
1641 LOGE("Invalid parameter");
1642 return NOTI_EX_ERROR_INVALID_PARAMETER;
1645 shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1646 shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1647 new (std::nothrow) LEDInfo(*color_ptr));
1649 LOGE("Out-of-memory");
1650 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1655 return NOTI_EX_ERROR_NONE;
1658 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1659 if (handle == nullptr) {
1660 LOGE("Invalid parameter");
1661 return NOTI_EX_ERROR_INVALID_PARAMETER;
1664 shared_ptr<LEDInfo>* led_ptr =
1665 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1667 return NOTI_EX_ERROR_NONE;
1670 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1671 noti_ex_led_info_h handle, int ms) {
1672 if (handle == nullptr) {
1673 LOGE("Invalid parameter");
1674 return NOTI_EX_ERROR_INVALID_PARAMETER;
1677 shared_ptr<LEDInfo>* led_ptr =
1678 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1679 (*led_ptr)->SetOnPeriod(ms);
1681 return NOTI_EX_ERROR_NONE;
1684 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1685 noti_ex_led_info_h handle, int *ms) {
1686 if (handle == nullptr || ms == nullptr) {
1687 LOGE("Invalid parameter");
1688 return NOTI_EX_ERROR_INVALID_PARAMETER;
1691 shared_ptr<LEDInfo>* led_ptr =
1692 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1693 *ms = (*led_ptr)->GetOnPeriod();
1695 return NOTI_EX_ERROR_NONE;
1698 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1699 noti_ex_led_info_h handle, int ms) {
1700 if (handle == nullptr) {
1701 LOGE("Invalid parameter");
1702 return NOTI_EX_ERROR_INVALID_PARAMETER;
1705 shared_ptr<LEDInfo>* led_ptr =
1706 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1707 (*led_ptr)->SetOffPeriod(ms);
1709 return NOTI_EX_ERROR_NONE;
1712 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1713 noti_ex_led_info_h handle, int *ms) {
1714 if (handle == nullptr) {
1715 LOGE("Invalid parameter");
1716 return NOTI_EX_ERROR_INVALID_PARAMETER;
1719 shared_ptr<LEDInfo>* led_ptr =
1720 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1721 *ms = (*led_ptr)->GetOffPeriod();
1723 return NOTI_EX_ERROR_NONE;
1726 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1727 noti_ex_led_info_h handle, noti_ex_color_h *color) {
1728 if (handle == nullptr) {
1729 LOGE("Invalid parameter");
1730 return NOTI_EX_ERROR_INVALID_PARAMETER;
1733 shared_ptr<LEDInfo>* led_ptr =
1734 reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1735 if ((*led_ptr)->GetColor() == nullptr) {
1736 LOGE("Color is null");
1737 return NOTI_EX_ERROR_INVALID_PARAMETER;
1740 shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1741 new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1742 if (col == nullptr || col->get() == nullptr) {
1743 LOGE("Out-of-memory");
1744 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1749 return NOTI_EX_ERROR_NONE;
1752 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1753 noti_ex_led_info_h handle, noti_ex_color_h color) {
1754 if (handle == nullptr) {
1755 LOGE("Invalid parameter");
1756 return NOTI_EX_ERROR_INVALID_PARAMETER;
1759 shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1760 if (color == nullptr) {
1761 (*p)->SetColor(nullptr);
1762 return NOTI_EX_ERROR_NONE;
1765 shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1766 (*p)->SetColor(*col);
1768 return NOTI_EX_ERROR_NONE;
1771 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1772 if (handle == nullptr) {
1773 LOGE("Invalid parameter");
1774 return NOTI_EX_ERROR_INVALID_PARAMETER;
1777 shared_ptr<AbstractAction>* ptr =
1778 static_cast<shared_ptr<AbstractAction>*>(handle);
1781 return NOTI_EX_ERROR_NONE;
1784 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1786 if (handle == nullptr || type == nullptr) {
1787 LOGE("Invalid parameter");
1788 return NOTI_EX_ERROR_INVALID_PARAMETER;
1791 shared_ptr<AbstractAction>* ptr =
1792 static_cast<shared_ptr<AbstractAction>*>(handle);
1793 *type = (*ptr)->GetType();
1795 return NOTI_EX_ERROR_NONE;
1798 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1800 if (handle == nullptr || local == nullptr) {
1801 LOGE("Invalid parameter");
1802 return NOTI_EX_ERROR_INVALID_PARAMETER;
1805 shared_ptr<AbstractAction>* ptr =
1806 static_cast<shared_ptr<AbstractAction>*>(handle);
1807 *local = (*ptr)->IsLocal();
1809 return NOTI_EX_ERROR_NONE;
1812 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1813 noti_ex_item_h item) {
1814 if (handle == nullptr || item == nullptr) {
1815 LOGE("Invalid parameter");
1816 return NOTI_EX_ERROR_INVALID_PARAMETER;
1818 shared_ptr<AbstractAction>* ptr =
1819 static_cast<shared_ptr<AbstractAction>*>(handle);
1820 Handle* ih = static_cast<Handle*>(item);
1821 (*ptr)->Execute(ih->GetPtr());
1823 return NOTI_EX_ERROR_NONE;
1826 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1828 if (handle == nullptr || extra == nullptr) {
1829 LOGE("Invalid parameter");
1830 return NOTI_EX_ERROR_INVALID_PARAMETER;
1833 shared_ptr<AbstractAction>* ptr =
1834 static_cast<shared_ptr<AbstractAction>*>(handle);
1835 if (!(*ptr)->GetExtra().empty()) {
1836 *extra = strdup((*ptr)->GetExtra().c_str());
1837 if (*extra == nullptr) {
1838 LOGE("Out-of-memory");
1839 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1843 return NOTI_EX_ERROR_NONE;
1846 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1847 noti_ex_item_info_h handle, int *hide_time) {
1848 if (handle == nullptr || hide_time == nullptr) {
1849 LOGE("Invalid parameter");
1850 return NOTI_EX_ERROR_INVALID_PARAMETER;
1852 IItemInfo* p = static_cast<IItemInfo*>(handle);
1853 *hide_time = p->GetHideTime();
1854 return NOTI_EX_ERROR_NONE;
1857 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1858 noti_ex_item_info_h handle, int hide_time) {
1859 if (handle == nullptr) {
1860 LOGE("Invalid parameter");
1861 return NOTI_EX_ERROR_INVALID_PARAMETER;
1863 IItemInfo* p = static_cast<IItemInfo*>(handle);
1864 p->SetHideTime(hide_time);
1865 return NOTI_EX_ERROR_NONE;
1868 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1869 noti_ex_item_info_h handle, int *delete_time) {
1870 if (handle == nullptr || delete_time == nullptr) {
1871 LOGE("Invalid parameter");
1872 return NOTI_EX_ERROR_INVALID_PARAMETER;
1874 IItemInfo* p = static_cast<IItemInfo*>(handle);
1875 *delete_time = p->GetDeleteTime();
1876 return NOTI_EX_ERROR_NONE;
1879 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1880 noti_ex_item_info_h handle, int delete_time) {
1881 if (handle == nullptr) {
1882 LOGE("Invalid parameter");
1883 return NOTI_EX_ERROR_INVALID_PARAMETER;
1885 IItemInfo* p = static_cast<IItemInfo*>(handle);
1886 p->SetDeleteTime(delete_time);
1887 return NOTI_EX_ERROR_NONE;
1890 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1891 noti_ex_item_info_h handle, time_t *time) {
1892 if (handle == nullptr || time == nullptr) {
1893 LOGE("Invalid parameter");
1894 return NOTI_EX_ERROR_INVALID_PARAMETER;
1897 IItemInfo* p = static_cast<IItemInfo*>(handle);
1898 *time = p->GetTime();
1899 return NOTI_EX_ERROR_NONE;
1902 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1903 if (handle == nullptr) {
1904 LOGE("Invalid parameter");
1905 return NOTI_EX_ERROR_INVALID_PARAMETER;
1908 Handle* h = static_cast<Handle*>(handle);
1910 return NOTI_EX_ERROR_NONE;
1913 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1914 const char *id, noti_ex_item_h *item) {
1915 if (handle == nullptr) {
1916 LOGE("Invalid parameter");
1917 return NOTI_EX_ERROR_INVALID_PARAMETER;
1920 Handle* p = static_cast<Handle*>(handle);
1921 AbstractItem& find_item = p->Get()->FindByID(string(id));
1922 *item = new Handle(&find_item);
1923 return NOTI_EX_ERROR_NONE;
1926 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1928 if (handle == nullptr || type == nullptr) {
1929 LOGE("Invalid parameter");
1930 return NOTI_EX_ERROR_INVALID_PARAMETER;
1933 Handle* h = static_cast<Handle*>(handle);
1934 AbstractItem* p = h->Get();
1935 *type = p->GetType();
1936 return NOTI_EX_ERROR_NONE;
1939 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1940 char ***path, int *count) {
1941 if (handle == nullptr || path == nullptr || count == nullptr) {
1942 LOGE("Invalid parameter");
1943 return NOTI_EX_ERROR_INVALID_PARAMETER;
1945 Handle* p = static_cast<Handle*>(handle);
1946 list<string> shared_path = p->Get()->GetSharedPath();
1947 char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1948 if (tmp_path == nullptr) {
1949 LOGE("Fail to create items");
1950 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1954 for (auto& i : shared_path) {
1955 tmp_path[idx] = strdup(i.c_str());
1956 if (tmp_path[idx] == nullptr) {
1957 __noti_ex_free_str_array(tmp_path, idx);
1958 LOGE("Out of memory");
1959 return NOTI_EX_ERROR_OUT_OF_MEMORY;
1965 *count = shared_path.size();
1966 return NOTI_EX_ERROR_NONE;
1969 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1971 if (handle == nullptr || id == nullptr) {
1972 LOGE("Invalid parameter");
1973 return NOTI_EX_ERROR_INVALID_PARAMETER;
1975 Handle* h = static_cast<Handle*>(handle);
1976 AbstractItem* p = h->Get();
1977 *id = strdup(p->GetId().c_str());
1978 return NOTI_EX_ERROR_NONE;
1981 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1983 if (handle == nullptr || id == nullptr) {
1984 LOGE("Invalid parameter");
1985 return NOTI_EX_ERROR_INVALID_PARAMETER;
1987 Handle* p = static_cast<Handle*>(handle);
1988 p->Get()->SetId(id);
1989 return NOTI_EX_ERROR_NONE;
1992 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1993 noti_ex_action_h *action) {
1994 if (handle == nullptr || action == nullptr) {
1995 LOGE("Invalid parameter");
1996 return NOTI_EX_ERROR_INVALID_PARAMETER;
1998 Handle* p = static_cast<Handle*>(handle);
1999 if (p->Get()->GetAction() == nullptr) {
2001 return NOTI_EX_ERROR_NONE;
2003 *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2004 p->Get()->GetAction()));
2006 return NOTI_EX_ERROR_NONE;
2009 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2010 noti_ex_action_h action) {
2011 if (handle == nullptr || action == nullptr) {
2012 LOGE("Invalid parameter");
2013 return NOTI_EX_ERROR_INVALID_PARAMETER;
2016 Handle* p = static_cast<Handle*>(handle);
2018 shared_ptr<AbstractAction>* ptr =
2019 static_cast<shared_ptr<AbstractAction>*>(action);
2020 p->Get()->SetAction(*ptr);
2021 return NOTI_EX_ERROR_NONE;
2024 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2025 noti_ex_style_h *style) {
2026 if (handle == nullptr || style == nullptr) {
2027 LOGE("Invalid parameter");
2028 return NOTI_EX_ERROR_INVALID_PARAMETER;
2031 Handle* p = static_cast<Handle*>(handle);
2032 shared_ptr<Style> s = p->Get()->GetStyle();
2033 if (s.get() == nullptr) {
2034 LOGE("Style is null");
2035 return NOTI_EX_ERROR_INVALID_PARAMETER;
2038 auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2039 if (ptr == nullptr || ptr->get() == nullptr) {
2040 LOGE("Out of memory");
2041 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2045 return NOTI_EX_ERROR_NONE;
2048 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2049 noti_ex_style_h style) {
2050 if (handle == nullptr || style == nullptr) {
2051 LOGE("Invalid parameter");
2052 return NOTI_EX_ERROR_INVALID_PARAMETER;
2055 Handle* p = static_cast<Handle*>(handle);
2056 shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2057 p->Get()->SetStyle(*s);
2058 return NOTI_EX_ERROR_NONE;
2061 extern "C" EXPORT_API int noti_ex_item_set_visible(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()->SetVisible(visible);
2070 return NOTI_EX_ERROR_NONE;
2073 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2075 if (handle == nullptr || visible == nullptr) {
2076 LOGE("Invalid parameter");
2077 return NOTI_EX_ERROR_INVALID_PARAMETER;
2080 Handle* p = static_cast<Handle*>(handle);
2081 *visible = p->Get()->GetVisible();
2082 return NOTI_EX_ERROR_NONE;
2085 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2087 if (handle == nullptr) {
2088 LOGE("Invalid parameter");
2089 return NOTI_EX_ERROR_INVALID_PARAMETER;
2092 Handle* p = static_cast<Handle*>(handle);
2093 p->Get()->SetEnable(enable);
2094 return NOTI_EX_ERROR_NONE;
2097 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2099 if (handle == nullptr || enable == nullptr) {
2100 LOGE("Invalid parameter");
2101 return NOTI_EX_ERROR_INVALID_PARAMETER;
2104 Handle* p = static_cast<Handle*>(handle);
2105 *enable = p->Get()->GetEnable();
2106 return NOTI_EX_ERROR_NONE;
2109 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2110 const char *receiver_group) {
2111 if (handle == nullptr || receiver_group == nullptr) {
2112 LOGE("Invalid parameter");
2113 return NOTI_EX_ERROR_INVALID_PARAMETER;
2116 Handle* p = static_cast<Handle*>(handle);
2117 p->Get()->AddReceiver(receiver_group);
2118 return NOTI_EX_ERROR_NONE;
2121 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2122 const char *receiver_group) {
2123 if (handle == nullptr || receiver_group == nullptr) {
2124 LOGE("Invalid parameter");
2125 return NOTI_EX_ERROR_INVALID_PARAMETER;
2128 Handle* p = static_cast<Handle*>(handle);
2129 p->Get()->RemoveReceiver(receiver_group);
2130 return NOTI_EX_ERROR_NONE;
2133 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2134 char ***receiver_list, int *count) {
2135 if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2136 LOGE("Invalid parameter");
2137 return NOTI_EX_ERROR_INVALID_PARAMETER;
2140 Handle* p = static_cast<Handle*>(handle);
2141 list<string> receivers = p->Get()->GetReceiverList();
2142 char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2143 if (tmp_list == nullptr) {
2144 LOGE("Out of memory");
2145 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2149 for (auto& i : receivers) {
2150 tmp_list[idx] = strdup(i.c_str());
2151 if (tmp_list[idx] == nullptr) {
2152 __noti_ex_free_str_array(tmp_list, idx);
2153 LOGE("Out of memory");
2154 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2159 *receiver_list = tmp_list;
2160 *count = receivers.size();
2161 return NOTI_EX_ERROR_NONE;
2164 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2166 if (handle == nullptr) {
2167 LOGE("Invalid parameter");
2168 return NOTI_EX_ERROR_INVALID_PARAMETER;
2171 Handle* p = static_cast<Handle*>(handle);
2172 p->Get()->SetPolicy(policy);
2173 return NOTI_EX_ERROR_NONE;
2176 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2178 if (handle == nullptr || policy == nullptr) {
2179 LOGE("Invalid parameter");
2180 return NOTI_EX_ERROR_INVALID_PARAMETER;
2183 Handle* p = static_cast<Handle*>(handle);
2184 *policy = p->Get()->GetPolicy();
2185 return NOTI_EX_ERROR_NONE;
2188 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2190 if (handle == nullptr || channel == nullptr) {
2191 LOGE("Invalid parameter");
2192 return NOTI_EX_ERROR_INVALID_PARAMETER;
2195 Handle* p = static_cast<Handle*>(handle);
2196 if (!p->Get()->GetChannel().empty())
2197 *channel = strdup(p->Get()->GetChannel().c_str());
2201 return NOTI_EX_ERROR_NONE;
2204 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2205 const char *channel) {
2206 if (handle == nullptr) {
2207 LOGE("Invalid parameter");
2208 return NOTI_EX_ERROR_INVALID_PARAMETER;
2211 Handle* p = static_cast<Handle*>(handle);
2212 p->Get()->SetChannel(channel);
2213 return NOTI_EX_ERROR_NONE;
2216 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2217 noti_ex_led_info_h led) {
2218 if (handle == nullptr) {
2219 LOGE("Invalid parameter");
2220 return NOTI_EX_ERROR_INVALID_PARAMETER;
2223 Handle* p = static_cast<Handle*>(handle);
2224 if (led == nullptr) {
2225 p->Get()->SetLEDInfo(nullptr);
2226 return NOTI_EX_ERROR_NONE;
2228 shared_ptr<LEDInfo>* led_ptr =
2229 reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2230 p->Get()->SetLEDInfo(*led_ptr);
2231 return NOTI_EX_ERROR_NONE;
2234 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2235 noti_ex_led_info_h *led) {
2236 if (handle == nullptr) {
2237 LOGE("Invalid parameter");
2238 return NOTI_EX_ERROR_INVALID_PARAMETER;
2241 Handle* p = static_cast<Handle*>(handle);
2242 if (p->Get()->GetLEDInfo() != nullptr)
2243 *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2246 return NOTI_EX_ERROR_NONE;
2249 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2251 if (handle == nullptr) {
2252 LOGE("Invalid parameter");
2253 return NOTI_EX_ERROR_INVALID_PARAMETER;
2256 Handle* p = static_cast<Handle*>(handle);
2257 if (path == nullptr)
2258 p->Get()->SetSoundPath("");
2260 p->Get()->SetSoundPath(path);
2261 return NOTI_EX_ERROR_NONE;
2264 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2266 if (handle == nullptr) {
2267 LOGE("Invalid parameter");
2268 return NOTI_EX_ERROR_INVALID_PARAMETER;
2271 Handle* p = static_cast<Handle*>(handle);
2272 if (path == nullptr)
2273 p->Get()->SetVibrationPath("");
2275 p->Get()->SetVibrationPath(path);
2276 return NOTI_EX_ERROR_NONE;
2279 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2281 if (handle == nullptr || path == nullptr) {
2282 LOGE("Invalid parameter");
2283 return NOTI_EX_ERROR_INVALID_PARAMETER;
2286 Handle* p = static_cast<Handle*>(handle);
2287 if (p->Get()->GetSoundPath().empty())
2290 *path = strdup(p->Get()->GetSoundPath().c_str());
2291 return NOTI_EX_ERROR_NONE;
2294 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2296 if (handle == nullptr || path == nullptr) {
2297 LOGE("Invalid parameter");
2298 return NOTI_EX_ERROR_INVALID_PARAMETER;
2301 Handle* p = static_cast<Handle*>(handle);
2302 if (p->Get()->GetVibrationPath().empty())
2305 *path = strdup(p->Get()->GetVibrationPath().c_str());
2306 return NOTI_EX_ERROR_NONE;
2309 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2310 noti_ex_item_info_h *info) {
2311 if (handle == nullptr || info == nullptr) {
2312 LOGE("Invalid parameter");
2313 return NOTI_EX_ERROR_INVALID_PARAMETER;
2316 Handle* p = static_cast<Handle*>(handle);
2317 if (p->Get()->GetInfo() == nullptr)
2320 *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2321 return NOTI_EX_ERROR_NONE;
2324 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2326 if (handle == nullptr || id == nullptr) {
2327 LOGE("Invalid parameter");
2328 return NOTI_EX_ERROR_INVALID_PARAMETER;
2331 Handle* p = static_cast<Handle*>(handle);
2332 if (p->Get()->GetSenderAppId().empty())
2335 *id = strdup(p->Get()->GetSenderAppId().c_str());
2336 return NOTI_EX_ERROR_NONE;
2339 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2341 if (handle == nullptr || tag == nullptr) {
2342 LOGE("Invalid parameter");
2343 return NOTI_EX_ERROR_INVALID_PARAMETER;
2346 Handle* p = static_cast<Handle*>(handle);
2347 if (p->Get()->GetTag().empty())
2350 *tag = strdup(p->Get()->GetTag().c_str());
2351 return NOTI_EX_ERROR_NONE;
2354 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2356 if (handle == nullptr) {
2357 LOGE("Invalid parameter");
2358 return NOTI_EX_ERROR_INVALID_PARAMETER;
2361 Handle* p = static_cast<Handle*>(handle);
2363 p->Get()->SetTag("");
2365 p->Get()->SetTag(tag);
2366 return NOTI_EX_ERROR_NONE;
2369 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2371 if (handle == nullptr || ongoing == nullptr) {
2372 LOGE("Invalid parameter");
2373 return NOTI_EX_ERROR_INVALID_PARAMETER;
2376 Handle* p = static_cast<Handle*>(handle);
2377 *ongoing = p->Get()->GetOnGoingState();
2379 return NOTI_EX_ERROR_NONE;
2382 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2384 if (handle == nullptr) {
2385 LOGE("Invalid parameter");
2386 return NOTI_EX_ERROR_INVALID_PARAMETER;
2389 Handle* p = static_cast<Handle*>(handle);
2390 p->Get()->SetOnGoingState(ongoing);
2392 return NOTI_EX_ERROR_NONE;
2395 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2396 int type, bool* exist) {
2397 if (handle == nullptr || exist == nullptr) {
2398 LOGE("Invalid parameter");
2399 return NOTI_EX_ERROR_INVALID_PARAMETER;
2402 Handle* p = static_cast<Handle*>(handle);
2403 *exist = p->Get()->IsItemTypeExist(type);
2405 return NOTI_EX_ERROR_NONE;
2408 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2410 if (handle == nullptr || type == nullptr) {
2411 LOGE("Invalid parameter");
2412 return NOTI_EX_ERROR_INVALID_PARAMETER;
2415 Handle* p = static_cast<Handle*>(handle);
2416 *type = p->Get()->GetMainType();
2418 return NOTI_EX_ERROR_NONE;
2421 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2422 const char* id, int type) {
2423 if (handle == nullptr || id == nullptr) {
2424 LOGE("Invalid parameter");
2425 return NOTI_EX_ERROR_INVALID_PARAMETER;
2428 Handle* p = static_cast<Handle*>(handle);
2429 if (!(p->Get()->SetMainType(string(id),
2430 static_cast<AbstractItem::MainType>(type))))
2431 return NOTI_EX_ERROR_INVALID_PARAMETER;
2433 return NOTI_EX_ERROR_NONE;
2436 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2437 int type, noti_ex_item_h* item) {
2438 if (handle == nullptr || item == nullptr) {
2439 LOGE("Invalid parameter");
2440 return NOTI_EX_ERROR_INVALID_PARAMETER;
2443 Handle* h = static_cast<Handle*>(handle);
2444 if (!h->IsValidType(AbstractItem::Group)) {
2445 LOGE("Invalid handle type");
2446 return NOTI_EX_ERROR_INVALID_PARAMETER;
2449 GroupItem* p = static_cast<GroupItem*>(h->Get());
2450 AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2451 *item = new Handle(&find_item);
2453 return NOTI_EX_ERROR_NONE;
2456 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2457 const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2459 if (handle == nullptr) {
2460 LOGE("Invalid parameter");
2461 return NOTI_EX_ERROR_INVALID_PARAMETER;
2464 string receiver_group_str = "";
2466 receiver_group_str = string(receiver_group);
2468 ManagerStub* stub = new (std::nothrow) ManagerStub(
2469 unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2470 unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2471 receiver_group_str);
2472 if (stub == nullptr) {
2473 LOGE("Fail to create manager");
2474 return NOTI_EX_ERROR_IO_ERROR;
2476 stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2477 new ManagerCallbackInfo(event_callbacks, data)));
2478 *handle = static_cast<noti_ex_manager_h>(stub);
2480 return NOTI_EX_ERROR_NONE;
2483 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2484 if (handle == nullptr) {
2485 LOGE("Invalid parameter");
2486 return NOTI_EX_ERROR_INVALID_PARAMETER;
2488 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2490 return NOTI_EX_ERROR_NONE;
2493 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2494 noti_ex_item_h **items, int *count) {
2495 if (handle == nullptr || items == nullptr || count == nullptr) {
2496 LOGE("Invalid parameter");
2497 return NOTI_EX_ERROR_INVALID_PARAMETER;
2501 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2502 list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2503 if (item_list.size() == 0) {
2506 return NOTI_EX_ERROR_NONE;
2508 noti_ex_item_h* added_item =
2509 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2510 if (added_item == nullptr) {
2511 LOGE("Fail to create items");
2512 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2516 for (auto& i : item_list) {
2517 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2519 *items = added_item;
2520 *count = item_list.size();
2521 } catch (Exception &ex) {
2522 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2523 return NOTI_EX_ERROR_IO_ERROR;
2525 return NOTI_EX_ERROR_NONE;
2528 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2529 noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2530 if (handle == nullptr || channel == nullptr ||
2531 items == nullptr || count == nullptr) {
2532 LOGE("Invalid parameter");
2533 return NOTI_EX_ERROR_INVALID_PARAMETER;
2537 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2538 list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2539 if (item_list.size() == 0) {
2542 return NOTI_EX_ERROR_NONE;
2544 noti_ex_item_h* added_item =
2545 (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2546 if (added_item == nullptr) {
2547 LOGE("Fail to create items");
2548 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2552 for (auto& i : item_list) {
2553 added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2555 *items = added_item;
2556 *count = item_list.size();
2557 } catch (Exception &ex) {
2558 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2559 return NOTI_EX_ERROR_IO_ERROR;
2562 return NOTI_EX_ERROR_NONE;
2565 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2566 noti_ex_item_h noti, int *request_id) {
2567 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2568 LOGE("Invalid parameter");
2569 return NOTI_EX_ERROR_INVALID_PARAMETER;
2572 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2573 Handle* sp = static_cast<Handle*>(noti);
2574 if (sp->GetPtr().get() == nullptr) {
2575 LOGE("Invalid noti reference can not be sended");
2576 return NOTI_EX_ERROR_INVALID_PARAMETER;
2578 *request_id = stub->Update(sp->GetPtr());
2580 } catch (Exception &ex) {
2581 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2582 return NOTI_EX_ERROR_IO_ERROR;
2584 return NOTI_EX_ERROR_NONE;
2587 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2588 noti_ex_item_h noti, int *request_id) {
2589 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2590 LOGE("Invalid parameter");
2591 return NOTI_EX_ERROR_INVALID_PARAMETER;
2594 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2595 Handle* item = static_cast<Handle*>(noti);
2596 if (item->GetPtr().get() == nullptr) {
2597 LOGE("Invalid noti reference can not be sended");
2598 return NOTI_EX_ERROR_INVALID_PARAMETER;
2600 *request_id = stub->Delete(item->GetPtr());
2602 } catch (Exception &ex) {
2603 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2604 return NOTI_EX_ERROR_IO_ERROR;
2606 return NOTI_EX_ERROR_NONE;
2609 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2611 if (handle == nullptr || request_id == nullptr) {
2612 LOGE("Invalid parameter");
2613 return NOTI_EX_ERROR_INVALID_PARAMETER;
2616 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2617 *request_id = stub->DeleteAll();
2618 } catch (Exception &ex) {
2619 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2620 return NOTI_EX_ERROR_IO_ERROR;
2622 return NOTI_EX_ERROR_NONE;
2625 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2626 noti_ex_item_h noti, int *request_id) {
2627 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2628 LOGE("Invalid parameter");
2629 return NOTI_EX_ERROR_INVALID_PARAMETER;
2632 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2633 Handle* item = static_cast<Handle*>(noti);
2634 if (item->GetPtr().get() == nullptr) {
2635 LOGE("Invalid noti reference can not be sended");
2636 return NOTI_EX_ERROR_INVALID_PARAMETER;
2638 *request_id = stub->Hide(item->GetPtr());
2640 } catch (Exception &ex) {
2641 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2642 return NOTI_EX_ERROR_IO_ERROR;
2644 return NOTI_EX_ERROR_NONE;
2647 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2648 noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2649 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2650 LOGE("Invalid parameter");
2651 return NOTI_EX_ERROR_INVALID_PARAMETER;
2654 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2655 *item = new Handle(stub->FindByRootID(root_id));
2656 } catch (Exception &ex) {
2657 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2658 return NOTI_EX_ERROR_IO_ERROR;
2660 return NOTI_EX_ERROR_NONE;
2663 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2664 noti_ex_event_info_h info, noti_ex_error_e error) {
2665 if (handle == nullptr || info == nullptr) {
2666 LOGE("Invalid parameter");
2667 return NOTI_EX_ERROR_INVALID_PARAMETER;
2670 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2671 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2672 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2673 static_cast<NotificationError>(error));
2674 } catch (Exception &ex) {
2675 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2676 return NOTI_EX_ERROR_IO_ERROR;
2678 return NOTI_EX_ERROR_NONE;
2681 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2682 noti_ex_manager_h handle, int *cnt) {
2684 if (handle == nullptr || cnt == nullptr) {
2685 LOGE("Invalid parameter");
2686 return NOTI_EX_ERROR_INVALID_PARAMETER;
2689 ManagerStub* stub = static_cast<ManagerStub*>(handle);
2690 *cnt = stub->GetCount();
2691 } catch (Exception &ex) {
2692 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2693 return NOTI_EX_ERROR_IO_ERROR;
2695 return NOTI_EX_ERROR_NONE;
2698 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2699 const char *id, float min, float current, float max) {
2702 if (handle == nullptr) {
2703 LOGE("Invalid parameter");
2704 return NOTI_EX_ERROR_INVALID_PARAMETER;
2708 p = new (std::nothrow) ProgressItem(id, min, current, max);
2710 p = new (std::nothrow) ProgressItem(min, current, max);
2713 LOGE("Out-of-memory");
2714 return NOTI_EX_ERROR_OUT_OF_MEMORY;
2717 *handle = new Handle(shared_ptr<AbstractItem>(p));
2719 return NOTI_EX_ERROR_NONE;
2722 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2723 noti_ex_item_h handle, float *current) {
2724 if (handle == nullptr || current == nullptr) {
2725 LOGE("Invalid parameter");
2726 return NOTI_EX_ERROR_INVALID_PARAMETER;
2729 Handle *h = static_cast<Handle*>(handle);
2730 if (!h->IsValidType(AbstractItem::Progress)) {
2731 LOGE("Invalid handle type");
2732 return NOTI_EX_ERROR_INVALID_PARAMETER;
2734 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2735 *current = p->GetCurrent();
2737 return NOTI_EX_ERROR_NONE;
2740 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2741 noti_ex_item_h handle, float current) {
2742 if (handle == nullptr) {
2743 LOGE("Invalid parameter");
2744 return NOTI_EX_ERROR_INVALID_PARAMETER;
2747 Handle *h = static_cast<Handle*>(handle);
2748 if (!h->IsValidType(AbstractItem::Progress)) {
2749 LOGE("Invalid handle type");
2750 return NOTI_EX_ERROR_INVALID_PARAMETER;
2752 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2753 p->SetCurrent(current);
2755 return NOTI_EX_ERROR_NONE;
2758 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2760 if (handle == nullptr || min == nullptr) {
2761 LOGE("Invalid parameter");
2762 return NOTI_EX_ERROR_INVALID_PARAMETER;
2765 Handle *h = static_cast<Handle*>(handle);
2766 if (!h->IsValidType(AbstractItem::Progress)) {
2767 LOGE("Invalid handle type");
2768 return NOTI_EX_ERROR_INVALID_PARAMETER;
2770 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2773 return NOTI_EX_ERROR_NONE;
2776 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2778 if (handle == nullptr || max == nullptr) {
2779 LOGE("Invalid parameter");
2780 return NOTI_EX_ERROR_INVALID_PARAMETER;
2783 Handle *h = static_cast<Handle*>(handle);
2784 if (!h->IsValidType(AbstractItem::Progress)) {
2785 LOGE("Invalid handle type");
2786 return NOTI_EX_ERROR_INVALID_PARAMETER;
2788 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2791 return NOTI_EX_ERROR_NONE;
2794 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2796 if (handle == nullptr || type == nullptr) {
2797 LOGE("Invalid parameter");
2798 return NOTI_EX_ERROR_INVALID_PARAMETER;
2801 Handle *h = static_cast<Handle*>(handle);
2802 if (!h->IsValidType(AbstractItem::Progress)) {
2803 LOGE("Invalid handle type");
2804 return NOTI_EX_ERROR_INVALID_PARAMETER;
2806 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2807 *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2809 return NOTI_EX_ERROR_NONE;
2812 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2814 if (handle == nullptr) {
2815 LOGE("Invalid parameter");
2816 return NOTI_EX_ERROR_INVALID_PARAMETER;
2819 Handle *h = static_cast<Handle*>(handle);
2820 if (!h->IsValidType(AbstractItem::Progress)) {
2821 LOGE("Invalid handle type");
2822 return NOTI_EX_ERROR_INVALID_PARAMETER;
2824 ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2825 p->SetProgressType(static_cast<ProgressItem::Type>(type));
2827 return NOTI_EX_ERROR_NONE;
2830 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2831 noti_ex_reporter_events_s event_callbacks, void *data) {
2832 if (handle == nullptr) {
2833 LOGE("Invalid parameter");
2834 return NOTI_EX_ERROR_INVALID_PARAMETER;
2837 ReporterStub* stub = new (std::nothrow) ReporterStub(
2838 unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2839 unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2840 if (stub == nullptr) {
2841 LOGE("Fail to create manager");
2842 return NOTI_EX_ERROR_IO_ERROR;
2844 stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2845 new ReporterCallbackInfo(event_callbacks, data)));
2847 *handle = static_cast<noti_ex_reporter_h>(stub);
2849 return NOTI_EX_ERROR_NONE;
2852 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2853 if (handle == nullptr) {
2854 LOGE("Invalid parameter");
2855 return NOTI_EX_ERROR_INVALID_PARAMETER;
2857 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2859 return NOTI_EX_ERROR_NONE;
2862 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2863 noti_ex_event_info_h info, noti_ex_error_e error) {
2864 if (handle == nullptr || info == nullptr) {
2865 LOGE("Invalid parameter");
2866 return NOTI_EX_ERROR_INVALID_PARAMETER;
2869 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2870 IEventInfo* c_info = static_cast<IEventInfo*>(info);
2871 stub->SendError(static_cast<const IEventInfo&>(*c_info),
2872 static_cast<NotificationError>(error));
2873 } catch (Exception &ex) {
2874 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2875 return NOTI_EX_ERROR_IO_ERROR;
2877 return NOTI_EX_ERROR_NONE;
2880 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2881 noti_ex_item_h noti, int *request_id) {
2882 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2883 LOGE("Invalid parameter");
2884 return NOTI_EX_ERROR_INVALID_PARAMETER;
2887 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2888 Handle* h = static_cast<Handle*>(noti);
2889 if (h->GetPtr().get() == nullptr) {
2890 LOGE("Invalid noti reference can not be sended");
2891 return NOTI_EX_ERROR_INVALID_PARAMETER;
2893 *request_id = stub->Post(h->GetPtr());
2895 } catch (Exception &ex) {
2896 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2897 return NOTI_EX_ERROR_IO_ERROR;
2899 return NOTI_EX_ERROR_NONE;
2902 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2903 noti_ex_item_h *noti_list, int count, int *request_id) {
2905 if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2906 LOGE("Invalid parameter");
2907 return NOTI_EX_ERROR_INVALID_PARAMETER;
2910 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2911 list<shared_ptr<item::AbstractItem>> notiList;
2912 for (int i = 0; i < count; i++) {
2913 Handle* item = static_cast<Handle*>(noti_list[i]);
2914 notiList.push_back(item->GetPtr());
2916 *request_id = stub->Post(notiList);
2917 } catch (Exception &ex) {
2918 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2919 return NOTI_EX_ERROR_IO_ERROR;
2921 return NOTI_EX_ERROR_NONE;
2924 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2925 noti_ex_item_h noti, int *request_id) {
2926 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2927 LOGE("Invalid parameter");
2928 return NOTI_EX_ERROR_INVALID_PARAMETER;
2931 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2932 Handle* item = static_cast<Handle*>(noti);
2933 if (item->GetPtr().get() == nullptr) {
2934 LOGE("Invalid noti reference can not be sended");
2935 return NOTI_EX_ERROR_INVALID_PARAMETER;
2937 *request_id = stub->Update(item->GetPtr());
2939 } catch (Exception &ex) {
2940 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2941 return NOTI_EX_ERROR_IO_ERROR;
2943 return NOTI_EX_ERROR_NONE;
2946 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2947 noti_ex_item_h noti, int *request_id) {
2948 if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2949 LOGE("Invalid parameter");
2950 return NOTI_EX_ERROR_INVALID_PARAMETER;
2953 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2954 Handle* item = static_cast<Handle*>(noti);
2955 if (item->GetPtr().get() == nullptr) {
2956 LOGE("Invalid noti reference can not be sended");
2957 return NOTI_EX_ERROR_INVALID_PARAMETER;
2959 *request_id = stub->Delete(item->GetPtr());
2961 } catch (Exception &ex) {
2962 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2963 return NOTI_EX_ERROR_IO_ERROR;
2965 return NOTI_EX_ERROR_NONE;
2968 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2969 noti_ex_reporter_h handle, int *request_id) {
2970 if (handle == nullptr || request_id == nullptr) {
2971 LOGE("Invalid parameter");
2972 return NOTI_EX_ERROR_INVALID_PARAMETER;
2975 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2976 *request_id = stub->DeleteAll();
2977 } catch (Exception &ex) {
2978 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2979 return NOTI_EX_ERROR_IO_ERROR;
2981 return NOTI_EX_ERROR_NONE;
2984 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2985 noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2986 if (handle == nullptr || root_id == nullptr || item == nullptr) {
2987 LOGE("Invalid parameter");
2988 return NOTI_EX_ERROR_INVALID_PARAMETER;
2991 ReporterStub* stub = static_cast<ReporterStub*>(handle);
2992 *item = new Handle(stub->FindByRootID(root_id));
2993 } catch (Exception &ex) {
2994 LOGE("%s %d", ex.what(), ex.GetErrorCode());
2995 return NOTI_EX_ERROR_IO_ERROR;
2997 return NOTI_EX_ERROR_NONE;
3000 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3001 const char *id, const char *text, const char *hyperlink) {
3002 if (handle == nullptr || text == nullptr) {
3003 LOGE("Invalid parameter");
3004 return NOTI_EX_ERROR_INVALID_PARAMETER;
3010 p = new (std::nothrow) TextItem(id, std::string(text),
3011 std::string(hyperlink));
3013 p = new (std::nothrow) TextItem(id, std::string(text));
3016 LOGE("Out-of-memory");
3017 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3020 *handle = new Handle(shared_ptr<AbstractItem>(p));
3022 return NOTI_EX_ERROR_NONE;
3025 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3026 const char *contents) {
3027 if (handle == nullptr || contents == nullptr) {
3028 LOGE("Invalid parameter");
3029 return NOTI_EX_ERROR_INVALID_PARAMETER;
3032 Handle* p = static_cast<Handle*>(handle);
3033 if (!p->IsValidType(AbstractItem::Text)) {
3034 LOGE("Invalid handle type");
3035 return NOTI_EX_ERROR_INVALID_PARAMETER;
3037 TextItem* ti = static_cast<TextItem*>(p->Get());
3038 ti->SetContents(std::string(contents));
3040 return NOTI_EX_ERROR_NONE;
3043 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3045 if (handle == nullptr || contents == nullptr) {
3046 LOGE("Invalid parameter");
3047 return NOTI_EX_ERROR_INVALID_PARAMETER;
3050 Handle* p = static_cast<Handle*>(handle);
3051 if (!p->IsValidType(AbstractItem::Text)) {
3052 LOGE("Invalid handle type");
3053 return NOTI_EX_ERROR_INVALID_PARAMETER;
3056 TextItem* ti = static_cast<TextItem*>(p->Get());
3058 if (ti->GetMultiLanguage() != nullptr &&
3059 !ti->GetMultiLanguage()->GetTranslatedString().empty())
3060 str = ti->GetMultiLanguage()->GetTranslatedString();
3061 else if (!ti->GetContents().empty())
3062 str = ti->GetContents();
3064 *contents = strdup(str.c_str());
3065 if (*contents == nullptr) {
3066 LOGE("Out-of-memory");
3067 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3070 return NOTI_EX_ERROR_NONE;
3073 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3074 noti_ex_item_h handle, char **hyper_link) {
3075 if (handle == nullptr || hyper_link == nullptr) {
3076 LOGE("Invalid parameter");
3077 return NOTI_EX_ERROR_INVALID_PARAMETER;
3080 Handle* p = static_cast<Handle*>(handle);
3081 if (!p->IsValidType(AbstractItem::Text)) {
3082 LOGE("Invalid handle type");
3083 return NOTI_EX_ERROR_INVALID_PARAMETER;
3085 TextItem* ti = static_cast<TextItem*>(p->Get());
3086 if (!ti->GetHyperLink().empty()) {
3087 *hyper_link = strdup(ti->GetHyperLink().c_str());
3088 if (*hyper_link == nullptr) {
3089 LOGE("Out-of-memory");
3090 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3094 return NOTI_EX_ERROR_NONE;
3097 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3098 noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3099 if (handle == nullptr) {
3100 LOGE("Invalid parameter");
3101 return NOTI_EX_ERROR_INVALID_PARAMETER;
3104 Handle* p = static_cast<Handle*>(handle);
3105 if (!p->IsValidType(AbstractItem::Text)) {
3106 LOGE("Invalid handle type");
3107 return NOTI_EX_ERROR_INVALID_PARAMETER;
3110 TextItem* ti = static_cast<TextItem*>(p->Get());
3111 if (multi == nullptr) {
3112 ti->SetMultiLanguage(nullptr);
3113 return NOTI_EX_ERROR_NONE;
3116 shared_ptr<MultiLanguage> mul_ptr =
3117 *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3118 ti->SetMultiLanguage(mul_ptr);
3119 ti->GetMultiLanguage()->UpdateString();
3121 return NOTI_EX_ERROR_NONE;
3124 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3125 const char *id, time_t time) {
3128 if (handle == nullptr) {
3129 LOGE("Invalid parameter");
3130 return NOTI_EX_ERROR_INVALID_PARAMETER;
3135 p = new (std::nothrow) TimeItem(id, time);
3137 p = new (std::nothrow) TimeItem(time);
3139 p = new (std::nothrow) TimeItem();
3143 LOGE("Out-of-memory");
3144 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3147 *handle = new Handle(shared_ptr<AbstractItem>(p));
3149 return NOTI_EX_ERROR_NONE;
3152 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3154 if (handle == nullptr || time == nullptr) {
3155 LOGE("Invalid parameter");
3156 return NOTI_EX_ERROR_INVALID_PARAMETER;
3158 Handle* h = static_cast<Handle*>(handle);
3159 if (!h->IsValidType(AbstractItem::Time)) {
3160 LOGE("Invalid handle type");
3161 return NOTI_EX_ERROR_INVALID_PARAMETER;
3163 TimeItem* p = static_cast<TimeItem*>(h->Get());
3164 *time = p->GetTime();
3166 return NOTI_EX_ERROR_NONE;
3169 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3171 if (handle == nullptr) {
3172 LOGE("Invalid parameter");
3173 return NOTI_EX_ERROR_INVALID_PARAMETER;
3175 Handle* h = static_cast<Handle*>(handle);
3176 if (!h->IsValidType(AbstractItem::Time)) {
3177 LOGE("Invalid handle type");
3178 return NOTI_EX_ERROR_INVALID_PARAMETER;
3180 TimeItem* p = static_cast<TimeItem*>(h->Get());
3183 return NOTI_EX_ERROR_NONE;
3186 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3187 noti_ex_action_h *handle, const char *extra) {
3188 if (handle == nullptr) {
3189 LOGE("Invalid parameter");
3190 return NOTI_EX_ERROR_INVALID_PARAMETER;
3193 string extra_str = "";
3195 extra_str = string(extra);
3197 shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3198 new (std::nothrow) VisibilityAction(extra_str));
3199 if (ptr == nullptr) {
3200 LOGE("Out-of-memory");
3201 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3206 return NOTI_EX_ERROR_NONE;
3209 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3210 const char *id, bool visible) {
3211 if (handle == nullptr || id == nullptr) {
3212 LOGE("Invalid parameter");
3213 return NOTI_EX_ERROR_INVALID_PARAMETER;
3216 shared_ptr<AbstractAction>* ptr =
3217 static_cast<shared_ptr<AbstractAction>*>(handle);
3218 VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3219 action->SetVisibility(id, visible);
3221 return NOTI_EX_ERROR_NONE;
3224 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3225 const char* msgid, const char* format, ...) {
3226 if (handle == nullptr || msgid == nullptr || format == nullptr) {
3227 LOGE("Invalid parameter");
3228 return NOTI_EX_ERROR_INVALID_PARAMETER;
3231 const char* format_idx = format;
3234 va_start(args, format);
3235 while (*format_idx != '\0') {
3236 char* arg = nullptr;
3239 stringstream stream;
3240 if (*format_idx == '%') {
3241 switch (*(format_idx + 1)) {
3243 arg = va_arg(args, char *);
3244 arr.push_back(string(arg));
3247 arg_i = va_arg(args, int);
3248 arr.push_back(to_string(arg_i));
3251 arg_f = va_arg(args, double);
3252 stream << std::fixed << std::setprecision(2) << arg_f;
3253 arr.push_back(stream.str());
3261 MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3263 LOGE("Out-of-memory");
3264 return NOTI_EX_ERROR_OUT_OF_MEMORY;
3266 *handle = new shared_ptr<MultiLanguage>(p);
3268 return NOTI_EX_ERROR_NONE;
3271 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3272 if (handle == nullptr) {
3273 LOGE("Invalid parameter");
3274 return NOTI_EX_ERROR_INVALID_PARAMETER;
3277 shared_ptr<MultiLanguage>* mul_ptr =
3278 reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3280 return NOTI_EX_ERROR_NONE;
3283 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3284 noti_ex_item_h item, int64_t* private_id) {
3285 if (item == nullptr || private_id == nullptr) {
3286 LOGE("Invalid parameter");
3287 return NOTI_EX_ERROR_INVALID_PARAMETER;
3290 Handle* h = static_cast<Handle*>(item);
3291 *private_id = static_pointer_cast<IItemInfoInternal>(
3292 h->Get()->GetInfo())->GetPrivateId();
3294 return NOTI_EX_ERROR_NONE;
3297 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3298 noti_ex_item_h item, int64_t priv_id) {
3299 if (item == nullptr) {
3300 LOGE("Invalid parameter");
3301 return NOTI_EX_ERROR_INVALID_PARAMETER;
3304 Handle* h = static_cast<Handle*>(item);
3305 static_pointer_cast<IItemInfoInternal>(
3306 h->Get()->GetInfo())->SetPrivateId(priv_id);
3308 return NOTI_EX_ERROR_NONE;
3311 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3312 if (list == nullptr) {
3313 LOGE("Invalid parameter");
3314 return NOTI_EX_ERROR_INVALID_PARAMETER;
3317 LOGI("Free strings (%d)", count);
3318 for (int i = 0; i < count; i++)
3322 return NOTI_EX_ERROR_NONE;
3325 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3326 if (handle == nullptr) {
3327 LOGE("Invalid parameter");
3328 return NOTI_EX_ERROR_INVALID_PARAMETER;
3330 Handle* h = static_cast<Handle*>(handle);
3331 if (!h->IsValidType(AbstractItem::Group)) {
3332 LOGE("Invalid handle type");
3333 return NOTI_EX_ERROR_INVALID_PARAMETER;
3335 GroupItem* p = static_cast<GroupItem*>(h->Get());
3336 p->RemoveChildren();
3338 return NOTI_EX_ERROR_NONE;