Merge branch 'tizen' into tizen_5.5
[platform/core/api/notification.git] / notification-ex / stub.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlog.h>
18 #include <glib.h>
19 #include <unistd.h>
20
21 #include <list>
22 #include <sstream>
23 #include <iomanip>
24
25 #include "api/notification_ex.h"
26 #include "api/notification_ex_internal.h"
27 #include "notification-ex/reporter.h"
28 #include "notification-ex/app_control_action.h"
29 #include "notification-ex/button_item.h"
30 #include "notification-ex/chat_message_item.h"
31 #include "notification-ex/checkbox_item.h"
32 #include "notification-ex/entry_item.h"
33 #include "notification-ex/group_item.h"
34 #include "notification-ex/input_selector_item.h"
35 #include "notification-ex/abstract_item.h"
36 #include "notification-ex/progress_item.h"
37 #include "notification-ex/time_item.h"
38 #include "notification-ex/visibility_action.h"
39 #include "notification-ex/event_info_internal.h"
40 #include "notification-ex/manager.h"
41 #include "notification-ex/dbus_sender.h"
42 #include "notification-ex/dbus_event_listener.h"
43 #include "notification-ex/exception.h"
44 #include "notification-ex/iitem_info_internal.h"
45 #include "notification-ex/icon_item.h"
46
47 #ifdef LOG_TAG
48 #undef LOG_TAG
49 #endif
50 #define LOG_TAG "NOTIFICATION_EX"
51
52 #ifdef EXPORT_API
53 #undef EXPORT_API
54 #endif
55 #define EXPORT_API __attribute__((visibility("default")))
56
57 using namespace std;
58 using namespace tizen_base;
59 using namespace notification::item;
60 using namespace notification;
61
62 namespace {
63
64 class Handle {
65  public:
66   explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
67   explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
68       : ref_(nullptr), ptr_(move(ptr)) { }
69   virtual ~Handle() = default;
70   item::AbstractItem* Get() const {
71     if (ptr_ == nullptr)
72       return ref_;
73     return ptr_.get();
74   }
75
76   bool IsValidType(int type) const {
77     return (Get()->GetType() == type
78         || Get()->GetType() >= AbstractItem::Custom);
79   }
80
81   std::shared_ptr<item::AbstractItem> GetPtr() const {
82     if (ptr_ == nullptr)
83       return std::shared_ptr<item::AbstractItem>({});
84     return ptr_;
85   }
86
87  private:
88   item::AbstractItem* ref_;
89   std::shared_ptr<item::AbstractItem> ptr_;
90 };
91
92 class ManagerCallbackInfo {
93  public:
94   ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
95     : user_data_(user_data) {
96     cb_.added = cb.added;
97     cb_.updated = cb.updated;
98     cb_.deleted = cb.deleted;
99     cb_.error = cb.error;
100   }
101
102   void InvokeAdded(Manager* manager, const IEventInfo& info,
103       list<shared_ptr<AbstractItem>> addedItem) {
104     if (cb_.added == nullptr)
105       return;
106     noti_ex_item_h* added_item =
107         (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
108     if (added_item == nullptr) {
109       LOGE("Out of memory");
110       return;
111     }
112
113     int idx = 0;
114     for (auto& i : addedItem) {
115       added_item[idx++] =
116           static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
117     }
118
119     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
120     cb_.added(static_cast<noti_ex_manager_h>(manager),
121         static_cast<noti_ex_event_info_h>(c_info), added_item,
122         addedItem.size(), user_data_);
123   }
124
125   void InvokeUpdated(Manager* manager, const IEventInfo& info,
126       shared_ptr<item::AbstractItem> updatedItem) {
127     if (cb_.updated == nullptr)
128       return;
129     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
130     cb_.updated(static_cast<noti_ex_manager_h>(manager),
131         static_cast<noti_ex_event_info_h>(c_info),
132         static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
133   }
134
135   void InvokeDeleted(Manager* manager, const IEventInfo& info,
136       shared_ptr<item::AbstractItem> deletedItem) {
137     if (cb_.deleted == nullptr)
138       return;
139     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
140     if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
141       cb_.deleted(static_cast<noti_ex_manager_h>(manager),
142         static_cast<noti_ex_event_info_h>(c_info),
143         nullptr, user_data_);
144     } else {
145       cb_.deleted(static_cast<noti_ex_manager_h>(manager),
146         static_cast<noti_ex_event_info_h>(c_info),
147         static_cast<noti_ex_item_h>(
148             new Handle(deletedItem)), user_data_);
149     }
150   }
151
152   void InvokeError(Manager* manager, NotificationError error, int requestId) {
153     if (cb_.error == nullptr)
154       return;
155     cb_.error(static_cast<noti_ex_manager_h>(manager),
156         static_cast<noti_ex_error_e>(error), requestId, user_data_);
157   }
158
159  private:
160   noti_ex_manager_events_s cb_;
161   void* user_data_;
162 };
163
164 class ManagerStub : public Manager {
165  public:
166   ManagerStub(std::unique_ptr<IEventSender> sender,
167       std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
168     : Manager(move(sender), move(listener), receiver_group) {
169   }
170
171   void OnAdd(const IEventInfo& info,
172       list<shared_ptr<AbstractItem>> addedItem) override {
173     cb_->InvokeAdded(this, info, addedItem);
174   }
175
176   void OnUpdate(const IEventInfo& info,
177       std::shared_ptr<item::AbstractItem> updatedItem) override {
178     cb_->InvokeUpdated(this, info, updatedItem);
179   }
180
181   void OnDelete(const IEventInfo& info,
182       shared_ptr<item::AbstractItem> deletedItem) override {
183     cb_->InvokeDeleted(this, info, deletedItem);
184   }
185
186   void OnError(NotificationError error, int requestId) override {
187     cb_->InvokeError(this, error, requestId);
188   }
189
190   int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
191     cb_ = move(ci);
192     return NOTI_EX_ERROR_NONE;
193   }
194
195   int ClearManagerCallbackInfo() {
196     cb_.reset();
197     return NOTI_EX_ERROR_NONE;
198   }
199
200  private:
201   unique_ptr<ManagerCallbackInfo> cb_;
202 };
203
204
205 class ReporterCallbackInfo {
206  public:
207   ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
208     : user_data_(user_data) {
209     cb_.event = cb.event;
210     cb_.error = cb.error;
211   }
212
213   void InvokeEvent(Reporter* reporter, const IEventInfo& info,
214       list<shared_ptr<AbstractItem>> notiList) {
215     if (cb_.event == nullptr)
216       return;
217     noti_ex_item_h* noti_list =
218         (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
219     if (noti_list == nullptr) {
220       LOGE("Out of memory");
221       return;
222     }
223
224     int idx = 0;
225     for (auto& i : notiList) {
226       noti_list[idx++] =
227           static_cast<noti_ex_item_h>(new Handle(i));
228     }
229
230     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
231     cb_.event(static_cast<noti_ex_reporter_h>(reporter),
232         static_cast<noti_ex_event_info_h>(c_info), noti_list,
233         notiList.size(), user_data_);
234     free(noti_list);
235   }
236
237   void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
238     if (cb_.error == nullptr)
239       return;
240     cb_.error(static_cast<noti_ex_reporter_h>(reporter),
241         static_cast<noti_ex_error_e>(error), requestId, user_data_);
242   }
243
244  private:
245   noti_ex_reporter_events_s cb_;
246   void* user_data_;
247 };
248
249 class ReporterStub : public Reporter {
250  public:
251   ReporterStub(std::unique_ptr<IEventSender> sender,
252       std::unique_ptr<IEventListener> listener)
253     : Reporter(move(sender), move(listener)) {
254   }
255
256   void OnEvent(const IEventInfo& info,
257       std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
258     cb_->InvokeEvent(this, info, notiList);
259   }
260
261   void OnError(NotificationError error, int requestId) override {
262     cb_->InvokeError(this, error, requestId);
263   }
264
265   int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
266     cb_ = move(ci);
267     return NOTI_EX_ERROR_NONE;
268   }
269
270   int ClearReporterCallbackInfo() {
271     cb_.reset();
272     return NOTI_EX_ERROR_NONE;
273   }
274
275  private:
276   unique_ptr<ReporterCallbackInfo> cb_;
277 };
278
279 }  // namespace
280
281 void __noti_ex_free_str_array(char** val, int length) {
282   int i;
283   for (i = 0; i < length ; i++)
284     free(val[i]);
285   free(val);
286 }
287
288 extern "C" EXPORT_API int noti_ex_action_app_control_create(
289     noti_ex_action_h *handle, app_control_h app_control,
290     const char *extra) {
291   if (handle == nullptr || app_control == nullptr) {
292     LOGE("Invalid parameter");
293     return NOTI_EX_ERROR_INVALID_PARAMETER;
294   }
295
296   shared_ptr<AbstractAction>* p;
297
298   if (extra) {
299     p = new (std::nothrow) shared_ptr<AbstractAction>(
300           new (std::nothrow) AppControlAction(app_control, extra));
301   } else {
302     p = new (std::nothrow) shared_ptr<AbstractAction>(
303           new (std::nothrow) AppControlAction(app_control));
304   }
305
306   if (p == nullptr) {
307     LOGE("Out-of-memory");
308     return NOTI_EX_ERROR_OUT_OF_MEMORY;
309   }
310
311   *handle = p;
312
313   return NOTI_EX_ERROR_NONE;
314 }
315
316 extern "C" EXPORT_API int noti_ex_action_app_control_set(
317     noti_ex_action_h handle, app_control_h app_control) {
318   if (handle == nullptr || app_control == nullptr) {
319     LOGE("Invalid parameter");
320     return NOTI_EX_ERROR_INVALID_PARAMETER;
321   }
322
323   shared_ptr<AbstractAction>* ptr =
324       static_cast<shared_ptr<AbstractAction>*>(handle);
325   AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
326   action->SetAppControl(app_control);
327
328   return NOTI_EX_ERROR_NONE;
329 }
330
331 extern "C" EXPORT_API int noti_ex_action_app_control_get(
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;
336   }
337
338   shared_ptr<AbstractAction>* ptr =
339       static_cast<shared_ptr<AbstractAction>*>(handle);
340   AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
341
342   app_control_h clone;
343   int r = app_control_clone(&clone, action->GetAppControl());
344   if (r != APP_CONTROL_ERROR_NONE) {
345     LOGE("failed to create a app_control handle : %d", r);
346     return NOTI_EX_ERROR_INVALID_PARAMETER;
347   }
348
349   *app_control = clone;
350
351   return NOTI_EX_ERROR_NONE;
352 }
353
354 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
355     const char *id, const char *title) {
356   ButtonItem* p;
357
358   if (handle == nullptr || title == nullptr) {
359     LOGE("Invalid parameter");
360     return NOTI_EX_ERROR_INVALID_PARAMETER;
361   }
362
363   if (id)
364     p = new (std::nothrow) ButtonItem(id, title);
365   else
366     p = new (std::nothrow) ButtonItem(title);
367
368   if (p == nullptr) {
369     LOGE("Out-of-memory");
370     return NOTI_EX_ERROR_OUT_OF_MEMORY;
371   }
372   *handle = new Handle(shared_ptr<AbstractItem>(p));
373
374   return NOTI_EX_ERROR_NONE;
375 }
376
377 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
378     char **title) {
379   if (handle == nullptr || title == nullptr) {
380     LOGE("Invalid parameter");
381     return NOTI_EX_ERROR_INVALID_PARAMETER;
382   }
383
384   Handle* sp = static_cast<Handle*>(handle);
385   if (!sp->IsValidType(AbstractItem::Button)) {
386     LOGE("Invalid handle type");
387     return NOTI_EX_ERROR_INVALID_PARAMETER;
388   }
389
390   ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
391   string str;
392   if (p->GetMultiLanguage() != nullptr &&
393       !p->GetMultiLanguage()->GetTranslatedString().empty())
394     str = p->GetMultiLanguage()->GetTranslatedString();
395   else if (!p->GetTitle().empty())
396     str = p->GetTitle();
397
398   *title = strdup(str.c_str());
399   if (*title == nullptr) {
400     LOGE("Out-of-memory");
401     return NOTI_EX_ERROR_OUT_OF_MEMORY;
402   }
403
404   return NOTI_EX_ERROR_NONE;
405 }
406
407 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
408     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
409   if (handle == nullptr) {
410     LOGE("Invalid parameter");
411     return NOTI_EX_ERROR_INVALID_PARAMETER;
412   }
413
414   Handle* p = static_cast<Handle*>(handle);
415   if (!p->IsValidType(AbstractItem::Button)) {
416     LOGE("Invalid handle type");
417     return NOTI_EX_ERROR_INVALID_PARAMETER;
418   }
419
420   ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
421   if (multi == nullptr) {
422     bi->SetMultiLanguage(nullptr);
423     return NOTI_EX_ERROR_NONE;
424   }
425
426   shared_ptr<MultiLanguage> mul_ptr =
427       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
428
429   mul_ptr->UpdateString();
430   bi->SetMultiLanguage(mul_ptr);
431
432   return NOTI_EX_ERROR_NONE;
433 }
434
435 extern "C" EXPORT_API int noti_ex_item_button_set_image(
436     noti_ex_item_h handle, const char *path) {
437   if (handle == nullptr || path == nullptr) {
438     LOGE("Invalid parameter");
439     return NOTI_EX_ERROR_INVALID_PARAMETER;
440   }
441
442   Handle* h = static_cast<Handle*>(handle);
443   if (!h->IsValidType(AbstractItem::Button)) {
444     LOGE("Invalid handle type");
445     return NOTI_EX_ERROR_INVALID_PARAMETER;
446   }
447
448   ButtonItem* p = static_cast<ButtonItem*>(h->Get());
449   p->SetImgPath(path);
450
451   return NOTI_EX_ERROR_NONE;
452 }
453
454 extern "C" EXPORT_API int noti_ex_item_button_get_image(
455     noti_ex_item_h handle, char **path) {
456   if (handle == nullptr || path == nullptr) {
457     LOGE("Invalid parameter");
458     return NOTI_EX_ERROR_INVALID_PARAMETER;
459   }
460
461   Handle* h = static_cast<Handle*>(handle);
462   if (!h->IsValidType(AbstractItem::Button)) {
463     LOGE("Invalid handle type");
464     return NOTI_EX_ERROR_INVALID_PARAMETER;
465   }
466
467   ButtonItem* p = static_cast<ButtonItem*>(h->Get());
468   if (!p->GetImgPath().empty())
469     *path = strdup(p->GetImgPath().c_str());
470   else
471     *path = nullptr;
472
473   return NOTI_EX_ERROR_NONE;
474 }
475
476 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
477     noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
478     noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
479     noti_ex_item_chat_message_type_e message_type) {
480   if (handle == nullptr || (text == nullptr && image == nullptr)
481       || name == nullptr || time == nullptr
482       || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
483     LOGE("Invalid parameter");
484     return NOTI_EX_ERROR_INVALID_PARAMETER;
485   }
486
487   if (id == NULL)
488     id = "";
489
490   auto* p = new (std::nothrow) ChatMessageItem(id,
491           dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
492           text == nullptr ? nullptr
493             : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
494           image == nullptr ? nullptr
495             : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
496           dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
497           static_cast<ChatMessageItem::Type>(message_type));
498   if (p == nullptr) {
499     LOGE("Out-of-memory");
500     return NOTI_EX_ERROR_OUT_OF_MEMORY;
501   }
502
503   *handle = new Handle(shared_ptr<AbstractItem>(p));
504
505   return NOTI_EX_ERROR_NONE;
506 }
507
508 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
509     noti_ex_item_h handle, noti_ex_item_h *name) {
510   if (handle == nullptr || name == nullptr) {
511     LOGE("Invalid parameter");
512     return NOTI_EX_ERROR_INVALID_PARAMETER;
513   }
514   Handle* h = static_cast<Handle*>(handle);
515   if (!h->IsValidType(AbstractItem::ChatMessage)) {
516     LOGE("Invalid handle type");
517     return NOTI_EX_ERROR_INVALID_PARAMETER;
518   }
519   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
520   if (p->GetNameItem().GetType() == AbstractItem::NullObject)
521     *name = nullptr;
522   else
523     *name = new Handle(&(p->GetNameItem()));
524
525   return NOTI_EX_ERROR_NONE;
526 }
527
528 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
529     noti_ex_item_h handle, noti_ex_item_h *text) {
530   if (handle == nullptr || text == nullptr) {
531     LOGE("Invalid parameter");
532     return NOTI_EX_ERROR_INVALID_PARAMETER;
533   }
534
535   Handle* h = static_cast<Handle*>(handle);
536   if (!h->IsValidType(AbstractItem::ChatMessage)) {
537     LOGE("Invalid handle type");
538     return NOTI_EX_ERROR_INVALID_PARAMETER;
539   }
540   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
541   if (p->GetTextItem().GetType() == AbstractItem::NullObject)
542     *text = nullptr;
543   else
544     *text = new Handle(&(p->GetTextItem()));
545
546   return NOTI_EX_ERROR_NONE;
547 }
548
549 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
550     noti_ex_item_h handle, noti_ex_item_h *image) {
551   if (handle == nullptr || image == nullptr) {
552     LOGE("Invalid parameter");
553     return NOTI_EX_ERROR_INVALID_PARAMETER;
554   }
555
556   Handle* h = static_cast<Handle*>(handle);
557   if (!h->IsValidType(AbstractItem::ChatMessage)) {
558     LOGE("Invalid handle type");
559     return NOTI_EX_ERROR_INVALID_PARAMETER;
560   }
561   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
562   if (p->GetImageItem().GetType() == AbstractItem::NullObject)
563     *image = nullptr;
564   else
565     *image =  new Handle(&(p->GetImageItem()));
566
567   return NOTI_EX_ERROR_NONE;
568 }
569
570 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
571     noti_ex_item_h handle, noti_ex_item_h *time) {
572   if (handle == nullptr || time == nullptr) {
573     LOGE("Invalid parameter");
574     return NOTI_EX_ERROR_INVALID_PARAMETER;
575   }
576
577   Handle* h = static_cast<Handle*>(handle);
578   if (!h->IsValidType(AbstractItem::ChatMessage)) {
579     LOGE("Invalid handle type");
580     return NOTI_EX_ERROR_INVALID_PARAMETER;
581   }
582   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
583   if (p->GetTimeItem().GetType() == AbstractItem::NullObject)
584     *time = nullptr;
585   else
586     *time = new Handle(&(p->GetTimeItem()));
587
588   return NOTI_EX_ERROR_NONE;
589 }
590
591 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
592     noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
593   if (handle == nullptr || message_type == nullptr) {
594     LOGE("Invalid parameter");
595     return NOTI_EX_ERROR_INVALID_PARAMETER;
596   }
597
598   Handle* h = static_cast<Handle*>(handle);
599   if (!h->IsValidType(AbstractItem::ChatMessage)) {
600     LOGE("Invalid handle type");
601     return NOTI_EX_ERROR_INVALID_PARAMETER;
602   }
603   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
604   *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
605
606   return NOTI_EX_ERROR_NONE;
607 }
608
609 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
610     const char *id, const char *title, bool checked) {
611   CheckBoxItem* p;
612
613   if (handle == nullptr || title == nullptr) {
614     LOGE("Invalid parameter");
615     return NOTI_EX_ERROR_INVALID_PARAMETER;
616   }
617
618   if (id == NULL)
619     id = "";
620
621   p = new (std::nothrow) CheckBoxItem(id, title, checked);
622   if (p == nullptr) {
623     LOGE("Out-of-memory");
624     return NOTI_EX_ERROR_OUT_OF_MEMORY;
625   }
626
627   *handle = new Handle(shared_ptr<AbstractItem>(p));
628
629   return NOTI_EX_ERROR_NONE;
630 }
631
632 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
633     char **title) {
634   if (handle == nullptr || title == nullptr) {
635     LOGE("Invalid parameter");
636     return NOTI_EX_ERROR_INVALID_PARAMETER;
637   }
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;
642   }
643
644   CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
645   string str;
646   if (p->GetMultiLanguage() != nullptr &&
647     !p->GetMultiLanguage()->GetTranslatedString().empty())
648     str = p->GetMultiLanguage()->GetTranslatedString();
649   else if (!p->GetTitle().empty())
650     str = p->GetTitle();
651
652   *title = strdup(str.c_str());
653   if (*title == nullptr) {
654     LOGE("Out-of-memory");
655     return NOTI_EX_ERROR_OUT_OF_MEMORY;
656   }
657
658   return NOTI_EX_ERROR_NONE;
659 }
660
661 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
662     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
663   if (handle == nullptr) {
664     LOGE("Invalid parameter");
665     return NOTI_EX_ERROR_INVALID_PARAMETER;
666   }
667
668   Handle* p = static_cast<Handle*>(handle);
669   if (!p->IsValidType(AbstractItem::CheckBox)) {
670     LOGE("Invalid handle type");
671     return NOTI_EX_ERROR_INVALID_PARAMETER;
672   }
673
674   CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
675   if (multi == nullptr) {
676     ci->SetMultiLanguage(nullptr);
677     return NOTI_EX_ERROR_NONE;
678   }
679
680   shared_ptr<MultiLanguage> mul_ptr =
681       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
682   mul_ptr->UpdateString();
683   ci->SetMultiLanguage(mul_ptr);
684
685   return NOTI_EX_ERROR_NONE;
686 }
687
688 extern "C" EXPORT_API int noti_ex_item_checkbox_get_check_state(
689     noti_ex_item_h handle, bool *checked) {
690   if (handle == nullptr || checked == nullptr) {
691     LOGE("Invalid parameter");
692     return NOTI_EX_ERROR_INVALID_PARAMETER;
693   }
694   Handle* h = static_cast<Handle*>(handle);
695   if (!h->IsValidType(AbstractItem::CheckBox)) {
696     LOGE("Invalid handle type");
697     return NOTI_EX_ERROR_INVALID_PARAMETER;
698   }
699   CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
700   *checked = p->IsChecked();
701
702   return NOTI_EX_ERROR_NONE;
703 }
704
705 extern "C" EXPORT_API int noti_ex_item_checkbox_set_check_state(
706     noti_ex_item_h handle, bool checked) {
707   if (handle == nullptr) {
708     LOGE("Invalid parameter");
709     return NOTI_EX_ERROR_INVALID_PARAMETER;
710   }
711
712   Handle* h = static_cast<Handle*>(handle);
713   if (!h->IsValidType(AbstractItem::CheckBox)) {
714     LOGE("Invalid handle type");
715     return NOTI_EX_ERROR_INVALID_PARAMETER;
716   }
717
718   CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
719   p->SetChecked(checked);
720
721   return NOTI_EX_ERROR_NONE;
722 }
723
724 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
725     const char *id) {
726   EntryItem* p;
727
728   if (handle == nullptr) {
729     LOGE("Invalid parameter");
730     return NOTI_EX_ERROR_INVALID_PARAMETER;
731   }
732
733   if (id)
734     p = new (std::nothrow) EntryItem(id);
735   else
736     p = new (std::nothrow) EntryItem();
737
738   if (p == nullptr) {
739     LOGE("Out-of-memory");
740     return NOTI_EX_ERROR_OUT_OF_MEMORY;
741   }
742
743   *handle = new Handle(shared_ptr<AbstractItem>(p));
744
745   return NOTI_EX_ERROR_NONE;
746 }
747
748 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
749     char **text) {
750   if (handle == nullptr || text == nullptr) {
751     LOGE("Invalid parameter");
752     return NOTI_EX_ERROR_INVALID_PARAMETER;
753   }
754
755   Handle* h = static_cast<Handle*>(handle);
756   if (!h->IsValidType(AbstractItem::Entry)) {
757     LOGE("Invalid handle type");
758     return NOTI_EX_ERROR_INVALID_PARAMETER;
759   }
760
761   EntryItem* p = static_cast<EntryItem*>(h->Get());
762   string str;
763   if (p->GetMultiLanguage() != nullptr &&
764       !p->GetMultiLanguage()->GetTranslatedString().empty())
765     str = p->GetMultiLanguage()->GetTranslatedString();
766   else if (!p->GetText().empty())
767     str = p->GetText();
768
769   *text = strdup(str.c_str());
770   if (*text == nullptr) {
771     LOGE("Out-of-memory");
772     return NOTI_EX_ERROR_OUT_OF_MEMORY;
773   }
774
775   return NOTI_EX_ERROR_NONE;
776 }
777
778 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
779     const char *text) {
780   if (handle == nullptr || text == nullptr) {
781     LOGE("Invalid parameter");
782     return NOTI_EX_ERROR_INVALID_PARAMETER;
783   }
784   Handle* h = static_cast<Handle*>(handle);
785   if (!h->IsValidType(AbstractItem::Entry)) {
786     LOGE("Invalid handle type");
787     return NOTI_EX_ERROR_INVALID_PARAMETER;
788   }
789   EntryItem* p = static_cast<EntryItem*>(h->Get());
790   p->SetText(std::string(text));
791
792   return NOTI_EX_ERROR_NONE;
793 }
794
795 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
796     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
797   if (handle == nullptr) {
798     LOGE("Invalid parameter");
799     return NOTI_EX_ERROR_INVALID_PARAMETER;
800   }
801
802   Handle* p = static_cast<Handle*>(handle);
803   if (!p->IsValidType(AbstractItem::Entry)) {
804     LOGE("Invalid handle type");
805     return NOTI_EX_ERROR_INVALID_PARAMETER;
806   }
807
808   EntryItem* ei = static_cast<EntryItem*>(p->Get());
809   if (multi == nullptr) {
810     ei->SetMultiLanguage(nullptr);
811     return NOTI_EX_ERROR_NONE;
812   }
813
814   shared_ptr<MultiLanguage> mul_ptr =
815       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
816   ei->SetMultiLanguage(mul_ptr);
817   ei->GetMultiLanguage()->UpdateString();
818
819   return NOTI_EX_ERROR_NONE;
820 }
821
822 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
823                 noti_ex_event_info_h* cloned_handle) {
824   if (handle == nullptr || cloned_handle == nullptr) {
825     LOGE("Invalid parameter");
826     return NOTI_EX_ERROR_INVALID_PARAMETER;
827   }
828
829   Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
830   EventInfo* info = new EventInfo(cloned);
831   *cloned_handle = info;
832   return NOTI_EX_ERROR_NONE;
833 }
834
835 extern "C" EXPORT_API int noti_ex_event_info_destroy(
836     noti_ex_event_info_h handle) {
837   if (handle == nullptr) {
838     LOGE("Invalid parameter");
839     return NOTI_EX_ERROR_INVALID_PARAMETER;
840   }
841   EventInfo* info = static_cast<EventInfo*>(handle);
842   delete info;
843   return NOTI_EX_ERROR_NONE;
844 }
845
846 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
847     noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
848   if (handle == nullptr || event_type == nullptr) {
849     LOGE("Invalid parameter");
850     return NOTI_EX_ERROR_INVALID_PARAMETER;
851   }
852   EventInfo* info = static_cast<EventInfo*>(handle);
853   *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
854
855   return NOTI_EX_ERROR_NONE;
856 }
857
858 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
859     noti_ex_event_info_h handle, char **owner) {
860   if (handle == nullptr || owner == nullptr) {
861     LOGE("Invalid parameter");
862     return NOTI_EX_ERROR_INVALID_PARAMETER;
863   }
864   EventInfo* info = static_cast<EventInfo*>(handle);
865   *owner = strdup(info->GetOwner().c_str());
866   return NOTI_EX_ERROR_NONE;
867 }
868
869 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
870     noti_ex_event_info_h handle, char **channel) {
871   if (handle == nullptr || channel == nullptr) {
872     LOGE("Invalid parameter");
873     return NOTI_EX_ERROR_INVALID_PARAMETER;
874   }
875   EventInfo* info = static_cast<EventInfo*>(handle);
876   *channel = strdup(info->GetChannel().c_str());
877   return NOTI_EX_ERROR_NONE;
878 }
879
880 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
881     noti_ex_event_info_h handle, char **item_id) {
882   if (handle == nullptr || item_id == nullptr) {
883     LOGE("Invalid parameter");
884     return NOTI_EX_ERROR_INVALID_PARAMETER;
885   }
886   EventInfo* info = static_cast<EventInfo*>(handle);
887   *item_id = strdup(info->GetItemId().c_str());
888   return NOTI_EX_ERROR_NONE;
889 }
890
891 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
892     noti_ex_event_info_h handle, int *req_id) {
893   if (handle == nullptr || req_id == nullptr) {
894     LOGE("Invalid parameter");
895     return NOTI_EX_ERROR_INVALID_PARAMETER;
896   }
897   EventInfo* info = static_cast<EventInfo*>(handle);
898   *req_id = info->GetRequestId();
899   return NOTI_EX_ERROR_NONE;
900 }
901
902 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
903     const char *id) {
904   GroupItem* p;
905
906   if (handle == nullptr) {
907     LOGE("Invalid parameter");
908     return NOTI_EX_ERROR_INVALID_PARAMETER;
909   }
910
911   if (id)
912     p = new (std::nothrow) GroupItem(id);
913   else
914     p = new (std::nothrow) GroupItem();
915
916   if (p == nullptr) {
917     LOGE("Out-of-memory");
918     return NOTI_EX_ERROR_OUT_OF_MEMORY;
919   }
920
921   *handle = new Handle(shared_ptr<AbstractItem>(p));
922
923   return NOTI_EX_ERROR_NONE;
924 }
925
926 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
927     bool vertical) {
928   if (handle == nullptr) {
929     LOGE("Invalid parameter");
930     return NOTI_EX_ERROR_INVALID_PARAMETER;
931   }
932   Handle* h = static_cast<Handle*>(handle);
933   if (!h->IsValidType(AbstractItem::Group)) {
934     LOGE("Invalid handle type");
935     return NOTI_EX_ERROR_INVALID_PARAMETER;
936   }
937   GroupItem* p = static_cast<GroupItem*>(h->Get());
938   p->SetDirection(vertical);
939
940   return NOTI_EX_ERROR_NONE;
941 }
942
943 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
944     bool *vertical) {
945   if (handle == nullptr) {
946     LOGE("Invalid parameter");
947     return NOTI_EX_ERROR_INVALID_PARAMETER;
948   }
949   Handle* h = static_cast<Handle*>(handle);
950   if (!h->IsValidType(AbstractItem::Group)) {
951     LOGE("Invalid handle type");
952     return NOTI_EX_ERROR_INVALID_PARAMETER;
953   }
954   GroupItem* p = static_cast<GroupItem*>(h->Get());
955   *vertical = p->IsVertical();
956
957   return NOTI_EX_ERROR_NONE;
958 }
959
960 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
961     char **label) {
962   if (handle == nullptr) {
963     LOGE("Invalid parameter");
964     return NOTI_EX_ERROR_INVALID_PARAMETER;
965   }
966   Handle* h = static_cast<Handle*>(handle);
967   if (!h->IsValidType(AbstractItem::Group)) {
968     LOGE("Invalid handle type");
969     return NOTI_EX_ERROR_INVALID_PARAMETER;
970   }
971   GroupItem* p = static_cast<GroupItem*>(h->Get());
972   if (!p->GetAppLabel().empty()) {
973     *label = strdup(p->GetAppLabel().c_str());
974     if (*label == nullptr) {
975       LOGE("Out-of-memory");
976       return NOTI_EX_ERROR_OUT_OF_MEMORY;
977     }
978   }
979
980   return NOTI_EX_ERROR_NONE;
981 }
982
983 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
984     noti_ex_item_h child) {
985   if (handle == nullptr || child == nullptr) {
986     LOGE("Invalid parameter");
987     return NOTI_EX_ERROR_INVALID_PARAMETER;
988   }
989   Handle* h = static_cast<Handle*>(handle);
990   if (!h->IsValidType(AbstractItem::Group)) {
991     LOGE("Invalid handle type");
992     return NOTI_EX_ERROR_INVALID_PARAMETER;
993   }
994   auto p = static_cast<GroupItem*>(h->Get());
995   p->AddChild((static_cast<Handle*>(child))->GetPtr());
996
997   return NOTI_EX_ERROR_NONE;
998 }
999
1000 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
1001     const char *item_id) {
1002   if (handle == nullptr || item_id == nullptr) {
1003     LOGE("Invalid parameter");
1004     return NOTI_EX_ERROR_INVALID_PARAMETER;
1005   }
1006   Handle* h = static_cast<Handle*>(handle);
1007   if (!h->IsValidType(AbstractItem::Group)) {
1008     LOGE("Invalid handle type");
1009     return NOTI_EX_ERROR_INVALID_PARAMETER;
1010   }
1011   GroupItem* p = static_cast<GroupItem*>(h->Get());
1012   p->RemoveChild(std::string(item_id));
1013
1014   return NOTI_EX_ERROR_NONE;
1015 }
1016
1017 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
1018     noti_ex_item_group_foreach_child_cb callback, void *data) {
1019   if (handle == nullptr || callback == nullptr) {
1020     LOGE("Invalid parameter");
1021     return NOTI_EX_ERROR_INVALID_PARAMETER;
1022   }
1023
1024   Handle* h = static_cast<Handle*>(handle);
1025   if (!h->IsValidType(AbstractItem::Group)) {
1026     LOGE("Invalid handle type");
1027     return NOTI_EX_ERROR_INVALID_PARAMETER;
1028   }
1029   GroupItem* p = static_cast<GroupItem*>(h->Get());
1030   list<shared_ptr<AbstractItem>> children = p->GetChildren();
1031   LOGI("Retrive (%zd)", children.size());
1032   for (auto i : children) {
1033     int ret = callback(
1034         static_cast<noti_ex_item_h>(new Handle(i)), data);
1035     if (ret != NOTI_EX_ERROR_NONE) {
1036       LOGW("callback return (%d) stop foreach", ret);
1037       break;
1038     }
1039   }
1040
1041   return NOTI_EX_ERROR_NONE;
1042 }
1043
1044 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1045     const char *id, const char *image_path) {
1046   ImageItem* p;
1047
1048   if (handle == nullptr  || image_path == nullptr) {
1049     LOGE("Invalid parameter");
1050     return NOTI_EX_ERROR_INVALID_PARAMETER;
1051   }
1052
1053   if (id)
1054     p = new (std::nothrow) ImageItem(id, image_path);
1055   else
1056     p = new (std::nothrow) ImageItem(image_path);
1057
1058   if (p == nullptr) {
1059     LOGE("Out-of-memory");
1060     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1061   }
1062
1063   *handle = new Handle(shared_ptr<AbstractItem>(p));
1064
1065   return NOTI_EX_ERROR_NONE;
1066 }
1067
1068 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1069     noti_ex_item_h handle, char **image_path) {
1070   if (handle == nullptr || image_path == nullptr) {
1071     LOGE("Invalid parameter");
1072     return NOTI_EX_ERROR_INVALID_PARAMETER;
1073   }
1074   Handle* h = static_cast<Handle*>(handle);
1075   if (!h->IsValidType(AbstractItem::Image)) {
1076     LOGE("Invalid handle type");
1077     return NOTI_EX_ERROR_INVALID_PARAMETER;
1078   }
1079   ImageItem* p = static_cast<ImageItem*>(h->Get());
1080   if (!p->GetImagePath().empty()) {
1081     *image_path = strdup(p->GetImagePath().c_str());
1082     if (*image_path == nullptr) {
1083       LOGE("Out-of-memory");
1084       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1085     }
1086   } else {
1087     *image_path = nullptr;
1088   }
1089
1090   return NOTI_EX_ERROR_NONE;
1091 }
1092
1093 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1094     noti_ex_item_h *handle, const char *id) {
1095   InputSelectorItem* p;
1096
1097   if (handle == nullptr) {
1098     LOGE("Invalid parameter");
1099     return NOTI_EX_ERROR_INVALID_PARAMETER;
1100   }
1101
1102   if (id)
1103     p = new (std::nothrow) InputSelectorItem(id);
1104   else
1105     p = new (std::nothrow) InputSelectorItem();
1106
1107   if (p == nullptr) {
1108     LOGE("Out-of-memory");
1109     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1110   }
1111
1112   *handle = new Handle(shared_ptr<AbstractItem>(p));
1113
1114   return NOTI_EX_ERROR_NONE;
1115 }
1116
1117 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1118     noti_ex_item_h handle, char ***contents_list, int *count) {
1119   if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1120     LOGE("Invalid parameter");
1121     return NOTI_EX_ERROR_INVALID_PARAMETER;
1122   }
1123
1124   Handle* h = static_cast<Handle*>(handle);
1125   if (!h->IsValidType(AbstractItem::InputSelector)) {
1126     LOGE("Invalid handle type");
1127     return NOTI_EX_ERROR_INVALID_PARAMETER;
1128   }
1129
1130   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1131   vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1132   list<string> contents;
1133   if (arr.size() == 0) {
1134     contents = p->GetContents();
1135   } else {
1136     for (auto& i : arr) {
1137       contents.push_back(i->GetTranslatedString());
1138     }
1139   }
1140
1141   char **list = (char**)calloc(contents.size(), sizeof(char*));
1142   if (list == nullptr) {
1143     LOGE("Out of memory");
1144     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1145   }
1146
1147   int idx = 0;
1148   for (auto& i : contents) {
1149     list[idx] = strdup(i.c_str());
1150     if (list[idx] == nullptr) {
1151       __noti_ex_free_str_array(list, idx);
1152       LOGE("Out of memory");
1153       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1154     }
1155     idx++;
1156   }
1157
1158   *count = contents.size();
1159   *contents_list = list;
1160
1161   return NOTI_EX_ERROR_NONE;
1162 }
1163
1164 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1165     noti_ex_item_h handle, const char **contents, int count) {
1166   if (handle == nullptr || contents == nullptr) {
1167     LOGE("Invalid parameter");
1168     return NOTI_EX_ERROR_INVALID_PARAMETER;
1169   }
1170
1171   list<string> new_contents;
1172   Handle* h = static_cast<Handle*>(handle);
1173   if (!h->IsValidType(AbstractItem::InputSelector)) {
1174     LOGE("Invalid handle type");
1175     return NOTI_EX_ERROR_INVALID_PARAMETER;
1176   }
1177   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1178   for (int i = 0; i < count; i++) {
1179     new_contents.push_back(contents[i]);
1180   }
1181   p->SetContents(move(new_contents));
1182
1183   return NOTI_EX_ERROR_NONE;
1184 }
1185
1186 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1187     noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1188   if (handle == nullptr) {
1189     LOGE("Invalid parameter");
1190     return NOTI_EX_ERROR_INVALID_PARAMETER;
1191   }
1192
1193   Handle* p = static_cast<Handle*>(handle);
1194   if (!p->IsValidType(AbstractItem::InputSelector)) {
1195     LOGE("Invalid handle type");
1196     return NOTI_EX_ERROR_INVALID_PARAMETER;
1197   }
1198
1199   vector<shared_ptr<MultiLanguage>> m_list;
1200   for (int i = 0; i < count; i++) {
1201     shared_ptr<MultiLanguage> mul_ptr =
1202       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1203     mul_ptr->UpdateString();
1204     m_list.push_back(mul_ptr);
1205   }
1206
1207   InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1208   input->SetMultiLanguage(m_list);
1209
1210   return NOTI_EX_ERROR_NONE;
1211 }
1212
1213 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1214     unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1215   if (handle == nullptr) {
1216     LOGE("Invalid parameter");
1217     return NOTI_EX_ERROR_INVALID_PARAMETER;
1218   }
1219
1220   auto* ptr = new (std::nothrow) shared_ptr<Color>(
1221       new (std::nothrow) Color(a, r, g, b));
1222   if (ptr == nullptr || ptr->get() == nullptr) {
1223     LOGE("Out-of-memory");
1224     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1225   }
1226
1227   *handle = ptr;
1228
1229   return NOTI_EX_ERROR_NONE;
1230 }
1231
1232 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1233   if (handle == nullptr) {
1234     LOGE("Invalid parameter");
1235     return NOTI_EX_ERROR_INVALID_PARAMETER;
1236   }
1237
1238   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1239   delete p;
1240
1241   return NOTI_EX_ERROR_NONE;
1242 }
1243
1244 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1245     unsigned char *val) {
1246   if (handle == nullptr || val == nullptr) {
1247     LOGE("Invalid parameter");
1248     return NOTI_EX_ERROR_INVALID_PARAMETER;
1249   }
1250
1251   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1252   *val = (*p)->GetAVal();
1253
1254   return NOTI_EX_ERROR_NONE;
1255 }
1256
1257 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1258     unsigned char *val) {
1259   if (handle == nullptr || val == nullptr) {
1260     LOGE("Invalid parameter");
1261     return NOTI_EX_ERROR_INVALID_PARAMETER;
1262   }
1263
1264   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1265   *val = (*p)->GetRVal();
1266
1267   return NOTI_EX_ERROR_NONE;
1268 }
1269
1270 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1271     unsigned char *val) {
1272   if (handle == nullptr || val == nullptr) {
1273     LOGE("Invalid parameter");
1274     return NOTI_EX_ERROR_INVALID_PARAMETER;
1275   }
1276
1277   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1278   *val = (*p)->GetGVal();
1279
1280   return NOTI_EX_ERROR_NONE;
1281 }
1282
1283 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1284     unsigned char *val) {
1285   if (handle == nullptr || val == nullptr) {
1286     LOGE("Invalid parameter");
1287     return NOTI_EX_ERROR_INVALID_PARAMETER;
1288   }
1289
1290   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1291   *val = (*p)->GetBVal();
1292
1293   return NOTI_EX_ERROR_NONE;
1294 }
1295
1296 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1297     int left, int top, int right, int bottom) {
1298   if (handle == nullptr) {
1299     LOGE("Invalid parameter");
1300     return NOTI_EX_ERROR_INVALID_PARAMETER;
1301   }
1302
1303   auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1304       new (std::nothrow) Padding(left, top, right, bottom));
1305   if (ptr == nullptr || ptr->get() == nullptr) {
1306     LOGE("Out-of-memory");
1307     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1308   }
1309
1310   *handle = ptr;
1311
1312   return NOTI_EX_ERROR_NONE;
1313 }
1314
1315 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1316   if (handle == nullptr) {
1317     LOGE("Invalid parameter");
1318     return NOTI_EX_ERROR_INVALID_PARAMETER;
1319   }
1320
1321   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1322   delete p;
1323
1324   return NOTI_EX_ERROR_NONE;
1325 }
1326
1327 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1328     int *val) {
1329   if (handle == nullptr || val == nullptr) {
1330     LOGE("Invalid parameter");
1331     return NOTI_EX_ERROR_INVALID_PARAMETER;
1332   }
1333
1334   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1335   *val = (*p)->GetLeft();
1336
1337   return NOTI_EX_ERROR_NONE;
1338 }
1339
1340 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1341     int *val) {
1342   if (handle == nullptr || val == nullptr) {
1343     LOGE("Invalid parameter");
1344     return NOTI_EX_ERROR_INVALID_PARAMETER;
1345   }
1346
1347   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1348   *val = (*p)->GetTop();
1349
1350   return NOTI_EX_ERROR_NONE;
1351 }
1352
1353 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1354     int *val) {
1355   if (handle == nullptr || val == nullptr) {
1356     LOGE("Invalid parameter");
1357     return NOTI_EX_ERROR_INVALID_PARAMETER;
1358   }
1359
1360   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1361   *val = (*p)->GetRight();
1362
1363   return NOTI_EX_ERROR_NONE;
1364 }
1365
1366 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1367     int *val) {
1368   if (handle == nullptr || val == nullptr) {
1369     LOGE("Invalid parameter");
1370     return NOTI_EX_ERROR_INVALID_PARAMETER;
1371   }
1372
1373   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1374   *val = (*p)->GetBottom();
1375
1376   return NOTI_EX_ERROR_NONE;
1377 }
1378
1379 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1380     int x, int y, int w, int h) {
1381   if (handle == nullptr) {
1382     LOGE("Invalid parameter");
1383     return NOTI_EX_ERROR_INVALID_PARAMETER;
1384   }
1385
1386   auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1387       new (std::nothrow) Geometry(x, y, w, h));
1388   if (ptr == nullptr || ptr->get() == nullptr) {
1389     LOGE("Out-of-memory");
1390     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1391   }
1392
1393   *handle = ptr;
1394
1395   return NOTI_EX_ERROR_NONE;
1396 }
1397
1398 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1399   if (handle == nullptr) {
1400     LOGE("Invalid parameter");
1401     return NOTI_EX_ERROR_INVALID_PARAMETER;
1402   }
1403
1404   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1405   delete p;
1406
1407   return NOTI_EX_ERROR_NONE;
1408 }
1409
1410 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1411     int *val) {
1412   if (handle == nullptr || val == nullptr) {
1413     LOGE("Invalid parameter");
1414     return NOTI_EX_ERROR_INVALID_PARAMETER;
1415   }
1416
1417   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1418   *val = (*p)->GetX();
1419
1420   return NOTI_EX_ERROR_NONE;
1421 }
1422
1423 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1424     int *val) {
1425   if (handle == nullptr || val == nullptr) {
1426     LOGE("Invalid parameter");
1427     return NOTI_EX_ERROR_INVALID_PARAMETER;
1428   }
1429
1430   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1431   *val = (*p)->GetY();
1432
1433   return NOTI_EX_ERROR_NONE;
1434 }
1435
1436 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1437     int *val) {
1438   if (handle == nullptr || val == nullptr) {
1439     LOGE("Invalid parameter");
1440     return NOTI_EX_ERROR_INVALID_PARAMETER;
1441   }
1442
1443   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1444   *val = (*p)->GetWidth();
1445
1446   return NOTI_EX_ERROR_NONE;
1447 }
1448
1449 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1450     int *val) {
1451   if (handle == nullptr || val == nullptr) {
1452     LOGE("Invalid parameter");
1453     return NOTI_EX_ERROR_INVALID_PARAMETER;
1454   }
1455
1456   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1457   *val = (*p)->GetHeight();
1458
1459   return NOTI_EX_ERROR_NONE;
1460 }
1461
1462 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1463     noti_ex_color_h color,
1464     noti_ex_padding_h padding,
1465     noti_ex_geometry_h geometry) {
1466   if (handle == nullptr) {
1467     LOGE("Invalid parameter");
1468     return NOTI_EX_ERROR_INVALID_PARAMETER;
1469   }
1470
1471   shared_ptr<Color> col = (color == nullptr) ?
1472       nullptr : *(static_cast<shared_ptr<Color>*>(color));
1473   shared_ptr<Padding> padd = (padding == nullptr) ?
1474       nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1475   shared_ptr<Geometry> geo = (geometry == nullptr) ?
1476       nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1477
1478   auto* ptr = new (std::nothrow) shared_ptr<Style>(
1479       new (std::nothrow) Style(col, padd, geo));
1480   if (ptr == nullptr || ptr->get() == nullptr) {
1481     LOGE("Out-of-memory");
1482     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1483   }
1484
1485   *handle = ptr;
1486
1487   return NOTI_EX_ERROR_NONE;
1488 }
1489
1490 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1491   if (handle == nullptr) {
1492     LOGE("Invalid parameter");
1493     return NOTI_EX_ERROR_INVALID_PARAMETER;
1494   }
1495
1496   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1497   delete p;
1498
1499   return NOTI_EX_ERROR_NONE;
1500 }
1501
1502 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1503     noti_ex_padding_h *padding) {
1504   if (handle == nullptr || padding == nullptr) {
1505     LOGE("Invalid parameter");
1506     return NOTI_EX_ERROR_INVALID_PARAMETER;
1507   }
1508
1509   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1510   if ((*p)->GetPadding() == nullptr) {
1511     LOGW("Padding info is null");
1512     return NOTI_EX_ERROR_INVALID_PARAMETER;
1513   }
1514
1515   shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1516       new (std::nothrow) Padding(*((*p)->GetPadding())));
1517   if (padd == nullptr || padd->get() == nullptr) {
1518     LOGE("Out-of-memory");
1519     *padding = nullptr;
1520     return NOTI_EX_ERROR_NONE;
1521   }
1522
1523   *padding = padd;
1524
1525   return NOTI_EX_ERROR_NONE;
1526 }
1527
1528
1529 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1530     noti_ex_padding_h padding) {
1531   if (handle == nullptr) {
1532     LOGE("Invalid parameter");
1533     return NOTI_EX_ERROR_INVALID_PARAMETER;
1534   }
1535
1536   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1537   if (padding == nullptr) {
1538     (*p)->SetPadding(nullptr);
1539     return NOTI_EX_ERROR_NONE;
1540   }
1541
1542   shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1543   (*p)->SetPadding(*padd);
1544
1545   return NOTI_EX_ERROR_NONE;
1546 }
1547
1548 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1549     noti_ex_color_h *color) {
1550   if (handle == nullptr || color == nullptr) {
1551     LOGE("Invalid parameter");
1552     return NOTI_EX_ERROR_INVALID_PARAMETER;
1553   }
1554
1555   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1556   if ((*p)->GetColor() == nullptr) {
1557     LOGW("Color info is null");
1558     *color = nullptr;
1559     return NOTI_EX_ERROR_NONE;
1560   }
1561
1562   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1563       new (std::nothrow) Color(*((*p)->GetColor())));
1564   if (col == nullptr || col->get() == nullptr) {
1565     LOGE("Out-of-memory");
1566     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1567   }
1568
1569   *color = col;
1570
1571   return NOTI_EX_ERROR_NONE;
1572 }
1573
1574 extern "C" EXPORT_API int noti_ex_style_set_color(
1575     noti_ex_style_h handle, noti_ex_color_h color) {
1576   if (handle == nullptr) {
1577     LOGE("Invalid parameter");
1578     return NOTI_EX_ERROR_INVALID_PARAMETER;
1579   }
1580
1581   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1582   if (color == nullptr) {
1583     (*p)->SetColor(nullptr);
1584     return NOTI_EX_ERROR_NONE;
1585   }
1586
1587   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1588   (*p)->SetColor(*col);
1589
1590   return NOTI_EX_ERROR_NONE;
1591 }
1592
1593 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1594     noti_ex_geometry_h *geometry) {
1595   if (handle == nullptr || geometry == nullptr) {
1596     LOGE("Invalid parameter");
1597     return NOTI_EX_ERROR_INVALID_PARAMETER;
1598   }
1599
1600   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1601   if ((*p)->GetGeometry() == nullptr) {
1602     LOGW("Geometry info is null");
1603     *geometry = nullptr;
1604     return NOTI_EX_ERROR_NONE;
1605   }
1606
1607   shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1608       new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1609   if (geo == nullptr || geo->get() == nullptr) {
1610     LOGE("Out-of-memory");
1611     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1612   }
1613
1614   *geometry = geo;
1615
1616   return NOTI_EX_ERROR_NONE;
1617 }
1618
1619 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1620     noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1621   if (handle == nullptr) {
1622     LOGE("Invalid parameter");
1623     return NOTI_EX_ERROR_INVALID_PARAMETER;
1624   }
1625
1626   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1627   if (geometry == nullptr) {
1628     (*p)->SetGeometry(nullptr);
1629     return NOTI_EX_ERROR_NONE;
1630   }
1631
1632   shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1633   (*p)->SetGeometry(*geo);
1634
1635   return NOTI_EX_ERROR_NONE;
1636 }
1637
1638 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1639     noti_ex_style_h handle, char** background_image) {
1640   if (handle == nullptr || background_image == nullptr) {
1641     LOGE("Invalid parameter");
1642     return NOTI_EX_ERROR_INVALID_PARAMETER;
1643   }
1644
1645   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1646
1647   if ((*p)->GetBackgroundImage().empty())
1648     *background_image = nullptr;
1649   else
1650     *background_image = strdup((*p)->GetBackgroundImage().c_str());
1651
1652   return NOTI_EX_ERROR_NONE;
1653 }
1654
1655 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1656     noti_ex_style_h handle, char* background_image) {
1657   if (handle == nullptr) {
1658     LOGE("Invalid parameter");
1659     return NOTI_EX_ERROR_INVALID_PARAMETER;
1660   }
1661
1662   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1663   if (background_image == nullptr)
1664     (*p)->SetBackgroundImage("");
1665   else
1666     (*p)->SetBackgroundImage(background_image);
1667
1668   return NOTI_EX_ERROR_NONE;
1669 }
1670
1671 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1672     noti_ex_style_h handle, noti_ex_color_h* color) {
1673   if (handle == nullptr || color == nullptr) {
1674     LOGE("Invalid parameter");
1675     return NOTI_EX_ERROR_INVALID_PARAMETER;
1676   }
1677
1678   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1679   if ((*p)->GetBackgroundColor() == nullptr) {
1680     LOGW("Color info is null");
1681     *color = nullptr;
1682     return NOTI_EX_ERROR_NONE;
1683   }
1684
1685   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1686       new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1687   if (col == nullptr || col->get() == nullptr) {
1688     LOGE("Out-of-memory");
1689     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1690   }
1691
1692   *color = col;
1693
1694   return NOTI_EX_ERROR_NONE;
1695 }
1696
1697 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1698     noti_ex_style_h handle, noti_ex_color_h color) {
1699   if (handle == nullptr) {
1700     LOGE("Invalid parameter");
1701     return NOTI_EX_ERROR_INVALID_PARAMETER;
1702   }
1703
1704   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1705   if (color == nullptr) {
1706     (*p)->SetBackgroundColor(nullptr);
1707     return NOTI_EX_ERROR_NONE;
1708   }
1709
1710   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1711   (*p)->SetBackgroundColor(*col);
1712
1713   return NOTI_EX_ERROR_NONE;
1714 }
1715
1716 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1717     noti_ex_color_h color) {
1718   if (handle == nullptr || color == nullptr) {
1719     LOGE("Invalid parameter");
1720     return NOTI_EX_ERROR_INVALID_PARAMETER;
1721   }
1722
1723   shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1724   shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1725       new (std::nothrow) LEDInfo(*color_ptr));
1726   if (p == nullptr) {
1727     LOGE("Out-of-memory");
1728     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1729   }
1730
1731   *handle = p;
1732
1733   return NOTI_EX_ERROR_NONE;
1734 }
1735
1736 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1737   if (handle == nullptr) {
1738     LOGE("Invalid parameter");
1739     return NOTI_EX_ERROR_INVALID_PARAMETER;
1740   }
1741
1742   shared_ptr<LEDInfo>* led_ptr =
1743       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1744   delete led_ptr;
1745   return NOTI_EX_ERROR_NONE;
1746 }
1747
1748 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1749     noti_ex_led_info_h handle, int ms) {
1750   if (handle == nullptr) {
1751     LOGE("Invalid parameter");
1752     return NOTI_EX_ERROR_INVALID_PARAMETER;
1753   }
1754
1755   shared_ptr<LEDInfo>* led_ptr =
1756       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1757   (*led_ptr)->SetOnPeriod(ms);
1758
1759   return NOTI_EX_ERROR_NONE;
1760 }
1761
1762 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1763     noti_ex_led_info_h handle, int *ms) {
1764   if (handle == nullptr || ms == nullptr) {
1765     LOGE("Invalid parameter");
1766     return NOTI_EX_ERROR_INVALID_PARAMETER;
1767   }
1768
1769   shared_ptr<LEDInfo>* led_ptr =
1770       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1771   *ms = (*led_ptr)->GetOnPeriod();
1772
1773   return NOTI_EX_ERROR_NONE;
1774 }
1775
1776 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1777     noti_ex_led_info_h handle, int ms) {
1778   if (handle == nullptr) {
1779     LOGE("Invalid parameter");
1780     return NOTI_EX_ERROR_INVALID_PARAMETER;
1781   }
1782
1783   shared_ptr<LEDInfo>* led_ptr =
1784       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1785   (*led_ptr)->SetOffPeriod(ms);
1786
1787   return NOTI_EX_ERROR_NONE;
1788 }
1789
1790 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1791     noti_ex_led_info_h handle, int *ms) {
1792   if (handle == nullptr) {
1793     LOGE("Invalid parameter");
1794     return NOTI_EX_ERROR_INVALID_PARAMETER;
1795   }
1796
1797   shared_ptr<LEDInfo>* led_ptr =
1798       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1799   *ms = (*led_ptr)->GetOffPeriod();
1800
1801   return NOTI_EX_ERROR_NONE;
1802 }
1803
1804 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1805     noti_ex_led_info_h handle, noti_ex_color_h *color) {
1806   if (handle == nullptr) {
1807     LOGE("Invalid parameter");
1808     return NOTI_EX_ERROR_INVALID_PARAMETER;
1809   }
1810
1811   shared_ptr<LEDInfo>* led_ptr =
1812       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1813   if ((*led_ptr)->GetColor() == nullptr) {
1814     LOGW("Color is null");
1815     *color = nullptr;
1816     return NOTI_EX_ERROR_NONE;
1817   }
1818
1819   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1820       new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1821   if (col == nullptr || col->get() == nullptr) {
1822     LOGE("Out-of-memory");
1823     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1824   }
1825
1826   *color = col;
1827
1828   return NOTI_EX_ERROR_NONE;
1829 }
1830
1831 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1832     noti_ex_led_info_h handle, noti_ex_color_h color) {
1833   if (handle == nullptr) {
1834     LOGE("Invalid parameter");
1835     return NOTI_EX_ERROR_INVALID_PARAMETER;
1836   }
1837
1838   shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1839   if (color == nullptr) {
1840     (*p)->SetColor(nullptr);
1841     return NOTI_EX_ERROR_NONE;
1842   }
1843
1844   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1845   (*p)->SetColor(*col);
1846
1847   return NOTI_EX_ERROR_NONE;
1848 }
1849
1850 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1851   if (handle == nullptr) {
1852     LOGE("Invalid parameter");
1853     return NOTI_EX_ERROR_INVALID_PARAMETER;
1854   }
1855
1856   shared_ptr<AbstractAction>* ptr =
1857       static_cast<shared_ptr<AbstractAction>*>(handle);
1858   delete ptr;
1859
1860   return NOTI_EX_ERROR_NONE;
1861 }
1862
1863 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1864     int *type) {
1865   if (handle == nullptr || type == nullptr) {
1866     LOGE("Invalid parameter");
1867     return NOTI_EX_ERROR_INVALID_PARAMETER;
1868   }
1869
1870   shared_ptr<AbstractAction>* ptr =
1871       static_cast<shared_ptr<AbstractAction>*>(handle);
1872   *type = (*ptr)->GetType();
1873
1874   return NOTI_EX_ERROR_NONE;
1875 }
1876
1877 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1878     bool *local) {
1879   if (handle == nullptr || local == nullptr) {
1880     LOGE("Invalid parameter");
1881     return NOTI_EX_ERROR_INVALID_PARAMETER;
1882   }
1883
1884   shared_ptr<AbstractAction>* ptr =
1885       static_cast<shared_ptr<AbstractAction>*>(handle);
1886   *local = (*ptr)->IsLocal();
1887
1888   return NOTI_EX_ERROR_NONE;
1889 }
1890
1891 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1892     noti_ex_item_h item) {
1893   if (handle == nullptr || item == nullptr) {
1894     LOGE("Invalid parameter");
1895     return NOTI_EX_ERROR_INVALID_PARAMETER;
1896   }
1897   shared_ptr<AbstractAction>* ptr =
1898       static_cast<shared_ptr<AbstractAction>*>(handle);
1899   Handle* ih = static_cast<Handle*>(item);
1900   (*ptr)->Execute(ih->GetPtr());
1901
1902   return NOTI_EX_ERROR_NONE;
1903 }
1904
1905 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1906     char **extra) {
1907   if (handle == nullptr || extra == nullptr) {
1908     LOGE("Invalid parameter");
1909     return NOTI_EX_ERROR_INVALID_PARAMETER;
1910   }
1911
1912   shared_ptr<AbstractAction>* ptr =
1913       static_cast<shared_ptr<AbstractAction>*>(handle);
1914   if (!(*ptr)->GetExtra().empty()) {
1915     *extra = strdup((*ptr)->GetExtra().c_str());
1916     if (*extra == nullptr) {
1917       LOGE("Out-of-memory");
1918       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1919     }
1920   } else {
1921     *extra = nullptr;
1922   }
1923
1924   return NOTI_EX_ERROR_NONE;
1925 }
1926
1927 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1928     noti_ex_item_info_h handle, int *hide_time) {
1929   if (handle == nullptr || hide_time == nullptr) {
1930     LOGE("Invalid parameter");
1931     return NOTI_EX_ERROR_INVALID_PARAMETER;
1932   }
1933   IItemInfo* p = static_cast<IItemInfo*>(handle);
1934   *hide_time = p->GetHideTime();
1935   return NOTI_EX_ERROR_NONE;
1936 }
1937
1938 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1939     noti_ex_item_info_h handle, int hide_time) {
1940   if (handle == nullptr) {
1941     LOGE("Invalid parameter");
1942     return NOTI_EX_ERROR_INVALID_PARAMETER;
1943   }
1944   IItemInfo* p = static_cast<IItemInfo*>(handle);
1945   p->SetHideTime(hide_time);
1946   return NOTI_EX_ERROR_NONE;
1947 }
1948
1949 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1950     noti_ex_item_info_h handle, int *delete_time) {
1951   if (handle == nullptr || delete_time == nullptr) {
1952     LOGE("Invalid parameter");
1953     return NOTI_EX_ERROR_INVALID_PARAMETER;
1954   }
1955   IItemInfo* p = static_cast<IItemInfo*>(handle);
1956   *delete_time = p->GetDeleteTime();
1957   return NOTI_EX_ERROR_NONE;
1958 }
1959
1960 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1961     noti_ex_item_info_h handle, int delete_time) {
1962   if (handle == nullptr) {
1963     LOGE("Invalid parameter");
1964     return NOTI_EX_ERROR_INVALID_PARAMETER;
1965   }
1966   IItemInfo* p = static_cast<IItemInfo*>(handle);
1967   p->SetDeleteTime(delete_time);
1968   return NOTI_EX_ERROR_NONE;
1969 }
1970
1971 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1972     noti_ex_item_info_h handle, time_t *time) {
1973   if (handle == nullptr || time == nullptr) {
1974     LOGE("Invalid parameter");
1975     return NOTI_EX_ERROR_INVALID_PARAMETER;
1976   }
1977
1978   IItemInfo* p = static_cast<IItemInfo*>(handle);
1979   *time = p->GetTime();
1980   return NOTI_EX_ERROR_NONE;
1981 }
1982
1983 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1984   if (handle == nullptr) {
1985     LOGE("Invalid parameter");
1986     return NOTI_EX_ERROR_INVALID_PARAMETER;
1987   }
1988
1989   Handle* h = static_cast<Handle*>(handle);
1990   delete h;
1991   return NOTI_EX_ERROR_NONE;
1992 }
1993
1994 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1995     const char *id, noti_ex_item_h *item) {
1996   if (handle == nullptr) {
1997     LOGE("Invalid parameter");
1998     return NOTI_EX_ERROR_INVALID_PARAMETER;
1999   }
2000
2001   Handle* p = static_cast<Handle*>(handle);
2002   AbstractItem& find_item = p->Get()->FindByID(string(id));
2003   if (find_item.GetType() == AbstractItem::NullObject) {
2004     LOGW("Not exist ID");
2005     *item = nullptr;
2006     return NOTI_EX_ERROR_NONE;
2007   }
2008
2009   *item = new Handle(&find_item);
2010   return NOTI_EX_ERROR_NONE;
2011 }
2012
2013 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2014     int *type) {
2015   if (handle == nullptr || type == nullptr) {
2016     LOGE("Invalid parameter");
2017     return NOTI_EX_ERROR_INVALID_PARAMETER;
2018   }
2019
2020   Handle* h = static_cast<Handle*>(handle);
2021   AbstractItem* p = h->Get();
2022   *type = p->GetType();
2023   return NOTI_EX_ERROR_NONE;
2024 }
2025
2026 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2027     char **id) {
2028   if (handle == nullptr || id == nullptr) {
2029     LOGE("Invalid parameter");
2030     return NOTI_EX_ERROR_INVALID_PARAMETER;
2031   }
2032   Handle* h = static_cast<Handle*>(handle);
2033   AbstractItem* p = h->Get();
2034   *id = strdup(p->GetId().c_str());
2035   return NOTI_EX_ERROR_NONE;
2036 }
2037
2038 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2039     const char *id) {
2040   if (handle == nullptr || id == nullptr) {
2041     LOGE("Invalid parameter");
2042     return NOTI_EX_ERROR_INVALID_PARAMETER;
2043   }
2044   Handle* p = static_cast<Handle*>(handle);
2045   p->Get()->SetId(id);
2046   return NOTI_EX_ERROR_NONE;
2047 }
2048
2049 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2050     noti_ex_action_h *action) {
2051   if (handle == nullptr || action == nullptr) {
2052     LOGE("Invalid parameter");
2053     return NOTI_EX_ERROR_INVALID_PARAMETER;
2054   }
2055   Handle* p = static_cast<Handle*>(handle);
2056   if (p->Get()->GetAction() == nullptr) {
2057     *action = nullptr;
2058     return NOTI_EX_ERROR_NONE;
2059   }
2060   *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2061       p->Get()->GetAction()));
2062
2063   return NOTI_EX_ERROR_NONE;
2064 }
2065
2066 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2067     noti_ex_action_h action) {
2068   if (handle == nullptr) {
2069     LOGE("Invalid parameter");
2070     return NOTI_EX_ERROR_INVALID_PARAMETER;
2071   }
2072
2073   Handle* p = static_cast<Handle*>(handle);
2074   if (action == nullptr) {
2075     p->Get()->SetAction(nullptr);
2076     return NOTI_EX_ERROR_NONE;
2077   }
2078
2079   shared_ptr<AbstractAction>* ptr =
2080       static_cast<shared_ptr<AbstractAction>*>(action);
2081   p->Get()->SetAction(*ptr);
2082   return NOTI_EX_ERROR_NONE;
2083 }
2084
2085 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2086     noti_ex_style_h *style) {
2087   if (handle == nullptr || style == nullptr) {
2088     LOGE("Invalid parameter");
2089     return NOTI_EX_ERROR_INVALID_PARAMETER;
2090   }
2091
2092   Handle* p = static_cast<Handle*>(handle);
2093   shared_ptr<Style> s = p->Get()->GetStyle();
2094   if (s.get() == nullptr) {
2095     LOGW("Style is null");
2096     *style = nullptr;
2097     return NOTI_EX_ERROR_NONE;
2098   }
2099
2100   auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2101   if (ptr == nullptr || ptr->get() == nullptr) {
2102     LOGE("Out of memory");
2103     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2104   }
2105
2106   *style = ptr;
2107   return NOTI_EX_ERROR_NONE;
2108 }
2109
2110 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2111     noti_ex_style_h style) {
2112   if (handle == nullptr) {
2113     LOGE("Invalid parameter");
2114     return NOTI_EX_ERROR_INVALID_PARAMETER;
2115   }
2116
2117   Handle* p = static_cast<Handle*>(handle);
2118   if (style == nullptr) {
2119     p->Get()->SetStyle(nullptr);
2120     return NOTI_EX_ERROR_NONE;
2121   }
2122
2123   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2124   p->Get()->SetStyle(*s);
2125   return NOTI_EX_ERROR_NONE;
2126 }
2127
2128 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2129     bool visible) {
2130   if (handle == nullptr) {
2131     LOGE("Invalid parameter");
2132     return NOTI_EX_ERROR_INVALID_PARAMETER;
2133   }
2134
2135   Handle* p = static_cast<Handle*>(handle);
2136   p->Get()->SetVisible(visible);
2137   return NOTI_EX_ERROR_NONE;
2138 }
2139
2140 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2141     bool *visible) {
2142   if (handle == nullptr || visible == nullptr) {
2143     LOGE("Invalid parameter");
2144     return NOTI_EX_ERROR_INVALID_PARAMETER;
2145   }
2146
2147   Handle* p = static_cast<Handle*>(handle);
2148   *visible = p->Get()->GetVisible();
2149   return NOTI_EX_ERROR_NONE;
2150 }
2151
2152 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2153     bool enable) {
2154   if (handle == nullptr) {
2155     LOGE("Invalid parameter");
2156     return NOTI_EX_ERROR_INVALID_PARAMETER;
2157   }
2158
2159   Handle* p = static_cast<Handle*>(handle);
2160   p->Get()->SetEnable(enable);
2161   return NOTI_EX_ERROR_NONE;
2162 }
2163
2164 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2165     bool *enable) {
2166   if (handle == nullptr || enable == nullptr) {
2167     LOGE("Invalid parameter");
2168     return NOTI_EX_ERROR_INVALID_PARAMETER;
2169   }
2170
2171   Handle* p = static_cast<Handle*>(handle);
2172   *enable = p->Get()->GetEnable();
2173   return NOTI_EX_ERROR_NONE;
2174 }
2175
2176 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2177     const char *receiver_group) {
2178   if (handle == nullptr || receiver_group == nullptr) {
2179     LOGE("Invalid parameter");
2180     return NOTI_EX_ERROR_INVALID_PARAMETER;
2181   }
2182
2183   Handle* p = static_cast<Handle*>(handle);
2184   p->Get()->AddReceiver(receiver_group);
2185   return NOTI_EX_ERROR_NONE;
2186 }
2187
2188 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2189     const char *receiver_group) {
2190   if (handle == nullptr || receiver_group == nullptr) {
2191     LOGE("Invalid parameter");
2192     return NOTI_EX_ERROR_INVALID_PARAMETER;
2193   }
2194
2195   Handle* p = static_cast<Handle*>(handle);
2196   p->Get()->RemoveReceiver(receiver_group);
2197   return NOTI_EX_ERROR_NONE;
2198 }
2199
2200 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2201     char ***receiver_list, int *count) {
2202   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2203     LOGE("Invalid parameter");
2204     return NOTI_EX_ERROR_INVALID_PARAMETER;
2205   }
2206
2207   Handle* p = static_cast<Handle*>(handle);
2208   list<string> receivers = p->Get()->GetReceiverList();
2209   if (receivers.size() == 0) {
2210     *receiver_list = nullptr;
2211     *count = 0;
2212     return NOTI_EX_ERROR_NONE;
2213   }
2214
2215   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2216   if (tmp_list == nullptr) {
2217     LOGE("Out of memory");
2218     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2219   }
2220
2221   int idx = 0;
2222   for (auto& i : receivers) {
2223     tmp_list[idx] = strdup(i.c_str());
2224     if (tmp_list[idx] == nullptr) {
2225       __noti_ex_free_str_array(tmp_list, idx);
2226       LOGE("Out of memory");
2227       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2228     }
2229     idx++;
2230   }
2231
2232   *receiver_list = tmp_list;
2233   *count = receivers.size();
2234   return NOTI_EX_ERROR_NONE;
2235 }
2236
2237 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2238     int policy) {
2239   if (handle == nullptr) {
2240     LOGE("Invalid parameter");
2241     return NOTI_EX_ERROR_INVALID_PARAMETER;
2242   }
2243
2244   Handle* p = static_cast<Handle*>(handle);
2245   p->Get()->SetPolicy(policy);
2246   return NOTI_EX_ERROR_NONE;
2247 }
2248
2249 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2250     int *policy) {
2251   if (handle == nullptr || policy == nullptr) {
2252     LOGE("Invalid parameter");
2253     return NOTI_EX_ERROR_INVALID_PARAMETER;
2254   }
2255
2256   Handle* p = static_cast<Handle*>(handle);
2257   *policy = p->Get()->GetPolicy();
2258   return NOTI_EX_ERROR_NONE;
2259 }
2260
2261 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2262     char **channel) {
2263   if (handle == nullptr || channel == nullptr) {
2264     LOGE("Invalid parameter");
2265     return NOTI_EX_ERROR_INVALID_PARAMETER;
2266   }
2267
2268   Handle* p = static_cast<Handle*>(handle);
2269   if (!p->Get()->GetChannel().empty())
2270     *channel = strdup(p->Get()->GetChannel().c_str());
2271   else
2272     *channel = nullptr;
2273
2274   return NOTI_EX_ERROR_NONE;
2275 }
2276
2277 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2278     const char *channel) {
2279   if (handle == nullptr) {
2280     LOGE("Invalid parameter");
2281     return NOTI_EX_ERROR_INVALID_PARAMETER;
2282   }
2283
2284   Handle* p = static_cast<Handle*>(handle);
2285   p->Get()->SetChannel(channel);
2286   return NOTI_EX_ERROR_NONE;
2287 }
2288
2289 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2290     noti_ex_led_info_h led) {
2291   if (handle == nullptr) {
2292     LOGE("Invalid parameter");
2293     return NOTI_EX_ERROR_INVALID_PARAMETER;
2294   }
2295
2296   Handle* p = static_cast<Handle*>(handle);
2297   if (led == nullptr) {
2298     p->Get()->SetLEDInfo(nullptr);
2299     return NOTI_EX_ERROR_NONE;
2300   }
2301   shared_ptr<LEDInfo>* led_ptr =
2302       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2303   p->Get()->SetLEDInfo(*led_ptr);
2304   return NOTI_EX_ERROR_NONE;
2305 }
2306
2307 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2308     noti_ex_led_info_h *led) {
2309   if (handle == nullptr) {
2310     LOGE("Invalid parameter");
2311     return NOTI_EX_ERROR_INVALID_PARAMETER;
2312   }
2313
2314   Handle* p = static_cast<Handle*>(handle);
2315   if (p->Get()->GetLEDInfo() != nullptr)
2316     *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2317   else
2318     *led = nullptr;
2319   return NOTI_EX_ERROR_NONE;
2320 }
2321
2322 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2323     const char *path) {
2324   if (handle == nullptr) {
2325     LOGE("Invalid parameter");
2326     return NOTI_EX_ERROR_INVALID_PARAMETER;
2327   }
2328
2329   Handle* p = static_cast<Handle*>(handle);
2330   if (path == nullptr)
2331     p->Get()->SetSoundPath("");
2332   else
2333     p->Get()->SetSoundPath(path);
2334   return NOTI_EX_ERROR_NONE;
2335 }
2336
2337 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2338     const char *path) {
2339   if (handle == nullptr) {
2340     LOGE("Invalid parameter");
2341     return NOTI_EX_ERROR_INVALID_PARAMETER;
2342   }
2343
2344   Handle* p = static_cast<Handle*>(handle);
2345   if (path == nullptr)
2346     p->Get()->SetVibrationPath("");
2347   else
2348     p->Get()->SetVibrationPath(path);
2349   return NOTI_EX_ERROR_NONE;
2350 }
2351
2352 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2353     char **path) {
2354   if (handle == nullptr || path == nullptr) {
2355     LOGE("Invalid parameter");
2356     return NOTI_EX_ERROR_INVALID_PARAMETER;
2357   }
2358
2359   Handle* p = static_cast<Handle*>(handle);
2360   if (p->Get()->GetSoundPath().empty())
2361     *path = nullptr;
2362   else
2363     *path = strdup(p->Get()->GetSoundPath().c_str());
2364   return NOTI_EX_ERROR_NONE;
2365 }
2366
2367 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2368     char **path) {
2369   if (handle == nullptr || path == nullptr) {
2370     LOGE("Invalid parameter");
2371     return NOTI_EX_ERROR_INVALID_PARAMETER;
2372   }
2373
2374   Handle* p = static_cast<Handle*>(handle);
2375   if (p->Get()->GetVibrationPath().empty())
2376     *path = nullptr;
2377   else
2378     *path = strdup(p->Get()->GetVibrationPath().c_str());
2379   return NOTI_EX_ERROR_NONE;
2380 }
2381
2382 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2383     noti_ex_item_info_h *info) {
2384   if (handle == nullptr || info == nullptr) {
2385     LOGE("Invalid parameter");
2386     return NOTI_EX_ERROR_INVALID_PARAMETER;
2387   }
2388
2389   Handle* p = static_cast<Handle*>(handle);
2390   if (p->Get()->GetInfo() == nullptr)
2391     *info = nullptr;
2392   else
2393     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2394   return NOTI_EX_ERROR_NONE;
2395 }
2396
2397 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2398     char **id) {
2399   if (handle == nullptr || id == nullptr) {
2400     LOGE("Invalid parameter");
2401     return NOTI_EX_ERROR_INVALID_PARAMETER;
2402   }
2403
2404   Handle* p = static_cast<Handle*>(handle);
2405   if (p->Get()->GetSenderAppId().empty())
2406     *id = nullptr;
2407   else
2408     *id = strdup(p->Get()->GetSenderAppId().c_str());
2409   return NOTI_EX_ERROR_NONE;
2410 }
2411
2412 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2413     char **tag) {
2414   if (handle == nullptr || tag == nullptr) {
2415     LOGE("Invalid parameter");
2416     return NOTI_EX_ERROR_INVALID_PARAMETER;
2417   }
2418
2419   Handle* p = static_cast<Handle*>(handle);
2420   if (p->Get()->GetTag().empty())
2421     *tag = nullptr;
2422   else
2423     *tag = strdup(p->Get()->GetTag().c_str());
2424   return NOTI_EX_ERROR_NONE;
2425 }
2426
2427 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2428     const char *tag) {
2429   if (handle == nullptr) {
2430     LOGE("Invalid parameter");
2431     return NOTI_EX_ERROR_INVALID_PARAMETER;
2432   }
2433
2434   Handle* p = static_cast<Handle*>(handle);
2435   if (tag == nullptr)
2436     p->Get()->SetTag("");
2437   else
2438     p->Get()->SetTag(tag);
2439   return NOTI_EX_ERROR_NONE;
2440 }
2441
2442 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2443     bool* ongoing) {
2444   if (handle == nullptr || ongoing == nullptr) {
2445     LOGE("Invalid parameter");
2446     return NOTI_EX_ERROR_INVALID_PARAMETER;
2447   }
2448
2449   Handle* p = static_cast<Handle*>(handle);
2450   *ongoing = p->Get()->GetOnGoingState();
2451
2452   return NOTI_EX_ERROR_NONE;
2453 }
2454
2455 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2456     bool ongoing) {
2457   if (handle == nullptr) {
2458     LOGE("Invalid parameter");
2459     return NOTI_EX_ERROR_INVALID_PARAMETER;
2460   }
2461
2462   Handle* p = static_cast<Handle*>(handle);
2463   p->Get()->SetOnGoingState(ongoing);
2464
2465   return NOTI_EX_ERROR_NONE;
2466 }
2467
2468 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2469     int type, bool* exist) {
2470   if (handle == nullptr || exist == nullptr) {
2471     LOGE("Invalid parameter");
2472     return NOTI_EX_ERROR_INVALID_PARAMETER;
2473   }
2474
2475   Handle* p = static_cast<Handle*>(handle);
2476   *exist = p->Get()->IsItemTypeExist(type);
2477
2478   return NOTI_EX_ERROR_NONE;
2479 }
2480
2481 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2482     int* type) {
2483   if (handle == nullptr || type == nullptr) {
2484     LOGE("Invalid parameter");
2485     return NOTI_EX_ERROR_INVALID_PARAMETER;
2486   }
2487
2488   Handle* p = static_cast<Handle*>(handle);
2489   *type = p->Get()->GetMainType();
2490
2491   return NOTI_EX_ERROR_NONE;
2492 }
2493
2494 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2495     const char* id, int type) {
2496   if (handle == nullptr || id == nullptr) {
2497     LOGE("Invalid parameter");
2498     return NOTI_EX_ERROR_INVALID_PARAMETER;
2499   }
2500
2501   Handle* p = static_cast<Handle*>(handle);
2502   if (!(p->Get()->SetMainType(string(id),
2503                     static_cast<AbstractItem::MainType>(type))))
2504     return NOTI_EX_ERROR_INVALID_PARAMETER;
2505
2506   return NOTI_EX_ERROR_NONE;
2507 }
2508
2509 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2510     int type, noti_ex_item_h* item) {
2511   if (handle == nullptr || item == nullptr) {
2512     LOGE("Invalid parameter");
2513     return NOTI_EX_ERROR_INVALID_PARAMETER;
2514   }
2515
2516   Handle* h = static_cast<Handle*>(handle);
2517   if (!h->IsValidType(AbstractItem::Group)) {
2518     LOGE("Invalid handle type");
2519     return NOTI_EX_ERROR_INVALID_PARAMETER;
2520   }
2521
2522   GroupItem* p = static_cast<GroupItem*>(h->Get());
2523   AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2524   if (find_item.GetType() == AbstractItem::NullObject) {
2525     LOGW("Not exist ID");
2526     *item = nullptr;
2527     return NOTI_EX_ERROR_NONE;
2528   }
2529   *item = new Handle(&find_item);
2530
2531   return NOTI_EX_ERROR_NONE;
2532 }
2533
2534 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2535     const char *key, bundle **value) {
2536   if (handle == nullptr || key == nullptr || value == nullptr) {
2537     LOGE("Invalid handle type");
2538     return NOTI_EX_ERROR_INVALID_PARAMETER;
2539   }
2540
2541   Handle* p = static_cast<Handle*>(handle);
2542
2543   Bundle b = p->Get()->GetExtensionData(key);
2544   if (b.GetCount() == 0)
2545     *value = nullptr;
2546   else
2547     *value = bundle_dup(b.GetHandle());
2548
2549   return NOTI_EX_ERROR_NONE;
2550 }
2551
2552 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2553     const char *key, bundle *value) {
2554   if (handle == nullptr || key == nullptr || value == nullptr) {
2555     LOGE("Invalid handle type");
2556     return NOTI_EX_ERROR_INVALID_PARAMETER;
2557   }
2558
2559   Bundle b = Bundle(value);
2560
2561   Handle* p = static_cast<Handle*>(handle);
2562   p->Get()->SetExtensionData(key, b);
2563
2564   return NOTI_EX_ERROR_NONE;
2565 }
2566
2567 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2568     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2569     void *data) {
2570   if (handle == nullptr) {
2571     LOGE("Invalid parameter");
2572     return NOTI_EX_ERROR_INVALID_PARAMETER;
2573   }
2574
2575   string receiver_group_str = "";
2576   if (receiver_group)
2577     receiver_group_str = string(receiver_group);
2578
2579   ManagerStub* stub = new (std::nothrow) ManagerStub(
2580       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2581       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2582       receiver_group_str);
2583   if (stub == nullptr) {
2584     LOGE("Fail to create manager");
2585     return NOTI_EX_ERROR_IO_ERROR;
2586   }
2587   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2588       new ManagerCallbackInfo(event_callbacks, data)));
2589   *handle = static_cast<noti_ex_manager_h>(stub);
2590
2591   return NOTI_EX_ERROR_NONE;
2592 }
2593
2594 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2595   if (handle == nullptr) {
2596     LOGE("Invalid parameter");
2597     return NOTI_EX_ERROR_INVALID_PARAMETER;
2598   }
2599   ManagerStub* stub = static_cast<ManagerStub*>(handle);
2600   delete stub;
2601   return NOTI_EX_ERROR_NONE;
2602 }
2603
2604 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2605     noti_ex_item_h **items, int *count) {
2606   if (handle == nullptr || items == nullptr || count == nullptr) {
2607     LOGE("Invalid parameter");
2608     return NOTI_EX_ERROR_INVALID_PARAMETER;
2609   }
2610
2611   try {
2612     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2613     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2614     if (item_list.size() == 0) {
2615       *items = nullptr;
2616       *count = 0;
2617       return NOTI_EX_ERROR_NONE;
2618     }
2619     noti_ex_item_h* added_item =
2620         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2621     if (added_item == nullptr) {
2622       LOGE("Fail to create items");
2623       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2624     }
2625
2626     int idx = 0;
2627     for (auto& i : item_list) {
2628       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2629     }
2630     *items = added_item;
2631     *count = item_list.size();
2632   } catch (Exception &ex) {
2633     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2634     return NOTI_EX_ERROR_IO_ERROR;
2635   }
2636   return NOTI_EX_ERROR_NONE;
2637 }
2638
2639 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2640     noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2641   if (handle == nullptr || channel == nullptr ||
2642       items == nullptr || count == nullptr) {
2643     LOGE("Invalid parameter");
2644     return NOTI_EX_ERROR_INVALID_PARAMETER;
2645   }
2646
2647   try {
2648     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2649     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2650     if (item_list.size() == 0) {
2651       *items = nullptr;
2652       *count = 0;
2653       return NOTI_EX_ERROR_NONE;
2654     }
2655     noti_ex_item_h* added_item =
2656         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2657     if (added_item == nullptr) {
2658       LOGE("Fail to create items");
2659       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2660     }
2661
2662     int idx = 0;
2663     for (auto& i : item_list) {
2664       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2665     }
2666     *items = added_item;
2667     *count = item_list.size();
2668   } catch (Exception &ex) {
2669     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2670     return NOTI_EX_ERROR_IO_ERROR;
2671   }
2672
2673   return NOTI_EX_ERROR_NONE;
2674 }
2675
2676 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2677     noti_ex_item_h noti, int *request_id) {
2678   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2679     LOGE("Invalid parameter");
2680     return NOTI_EX_ERROR_INVALID_PARAMETER;
2681   }
2682   try {
2683     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2684     Handle* sp = static_cast<Handle*>(noti);
2685     if (sp->GetPtr().get() == nullptr) {
2686       LOGE("Invalid noti reference can not be sended");
2687       return NOTI_EX_ERROR_INVALID_PARAMETER;
2688     } else {
2689       *request_id = stub->Update(sp->GetPtr());
2690     }
2691   } catch (Exception &ex) {
2692     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2693     return NOTI_EX_ERROR_IO_ERROR;
2694   }
2695   return NOTI_EX_ERROR_NONE;
2696 }
2697
2698 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2699     noti_ex_item_h noti, int *request_id) {
2700   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2701     LOGE("Invalid parameter");
2702     return NOTI_EX_ERROR_INVALID_PARAMETER;
2703   }
2704   try {
2705     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2706     Handle* item = static_cast<Handle*>(noti);
2707     if (item->GetPtr().get() == nullptr) {
2708       LOGE("Invalid noti reference can not be sended");
2709       return NOTI_EX_ERROR_INVALID_PARAMETER;
2710     } else {
2711       *request_id = stub->Delete(item->GetPtr());
2712     }
2713   } catch (Exception &ex) {
2714     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2715     return NOTI_EX_ERROR_IO_ERROR;
2716   }
2717   return NOTI_EX_ERROR_NONE;
2718 }
2719
2720 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2721     int *request_id) {
2722   if (handle == nullptr || request_id == nullptr) {
2723     LOGE("Invalid parameter");
2724     return NOTI_EX_ERROR_INVALID_PARAMETER;
2725   }
2726   try {
2727     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2728     *request_id = stub->DeleteAll();
2729   } catch (Exception &ex) {
2730     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2731     return NOTI_EX_ERROR_IO_ERROR;
2732   }
2733   return NOTI_EX_ERROR_NONE;
2734 }
2735
2736 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2737     noti_ex_manager_h handle, const char* channel, int* request_id) {
2738   if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2739     LOGE("Invalid parameter");
2740     return NOTI_EX_ERROR_INVALID_PARAMETER;
2741   }
2742
2743   try {
2744     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2745     *request_id = stub->DeleteByChannel(channel);
2746   } catch (Exception &ex) {
2747     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2748     return NOTI_EX_ERROR_IO_ERROR;
2749   }
2750
2751   return NOTI_EX_ERROR_NONE;
2752 }
2753
2754 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2755     noti_ex_manager_h handle, const char* app_id, int* request_id) {
2756   if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2757     LOGE("Invalid parameter");
2758     return NOTI_EX_ERROR_INVALID_PARAMETER;
2759   }
2760
2761   try {
2762     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2763     *request_id = stub->DeleteByAppId(app_id);
2764   } catch (Exception &ex) {
2765     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2766     return NOTI_EX_ERROR_IO_ERROR;
2767   }
2768
2769   return NOTI_EX_ERROR_NONE;
2770 }
2771
2772 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2773     noti_ex_item_h noti, int *request_id) {
2774   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2775     LOGE("Invalid parameter");
2776     return NOTI_EX_ERROR_INVALID_PARAMETER;
2777   }
2778   try {
2779     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2780     Handle* item = static_cast<Handle*>(noti);
2781     if (item->GetPtr().get() == nullptr) {
2782       LOGE("Invalid noti reference can not be sended");
2783       return NOTI_EX_ERROR_INVALID_PARAMETER;
2784     } else {
2785       *request_id = stub->Hide(item->GetPtr());
2786     }
2787   } catch (Exception &ex) {
2788     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2789     return NOTI_EX_ERROR_IO_ERROR;
2790   }
2791   return NOTI_EX_ERROR_NONE;
2792 }
2793
2794 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2795     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2796   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2797     LOGE("Invalid parameter");
2798     return NOTI_EX_ERROR_INVALID_PARAMETER;
2799   }
2800   try {
2801     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2802     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2803     if (ptr == nullptr) {
2804       LOGW("Not exist ID");
2805       *item = nullptr;
2806       return NOTI_EX_ERROR_NONE;
2807     }
2808     *item = new Handle(ptr);
2809   } catch (Exception &ex) {
2810     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2811     return NOTI_EX_ERROR_IO_ERROR;
2812   }
2813   return NOTI_EX_ERROR_NONE;
2814 }
2815
2816 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2817     noti_ex_event_info_h info, noti_ex_error_e error) {
2818   if (handle == nullptr || info == nullptr) {
2819     LOGE("Invalid parameter");
2820     return NOTI_EX_ERROR_INVALID_PARAMETER;
2821   }
2822   try {
2823     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2824     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2825     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2826         static_cast<NotificationError>(error));
2827   } catch (Exception &ex) {
2828     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2829     return NOTI_EX_ERROR_IO_ERROR;
2830   }
2831   return NOTI_EX_ERROR_NONE;
2832 }
2833
2834 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2835     noti_ex_manager_h handle, int *cnt) {
2836
2837   if (handle == nullptr || cnt == nullptr) {
2838     LOGE("Invalid parameter");
2839     return NOTI_EX_ERROR_INVALID_PARAMETER;
2840   }
2841   try {
2842     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2843     *cnt = stub->GetCount();
2844   } catch (Exception &ex) {
2845     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2846     return NOTI_EX_ERROR_IO_ERROR;
2847   }
2848   return NOTI_EX_ERROR_NONE;
2849 }
2850
2851 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2852     const char *id, float min, float current, float max) {
2853   ProgressItem* p;
2854
2855   if (handle == nullptr) {
2856     LOGE("Invalid parameter");
2857     return NOTI_EX_ERROR_INVALID_PARAMETER;
2858   }
2859
2860   if (id)
2861     p = new (std::nothrow) ProgressItem(id, min, current, max);
2862   else
2863     p = new (std::nothrow) ProgressItem(min, current, max);
2864
2865   if (p == nullptr) {
2866     LOGE("Out-of-memory");
2867     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2868   }
2869
2870   *handle = new Handle(shared_ptr<AbstractItem>(p));
2871
2872   return NOTI_EX_ERROR_NONE;
2873 }
2874
2875 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2876     noti_ex_item_h handle, float *current) {
2877   if (handle == nullptr || current == nullptr) {
2878     LOGE("Invalid parameter");
2879     return NOTI_EX_ERROR_INVALID_PARAMETER;
2880   }
2881
2882   Handle *h = static_cast<Handle*>(handle);
2883   if (!h->IsValidType(AbstractItem::Progress)) {
2884     LOGE("Invalid handle type");
2885     return NOTI_EX_ERROR_INVALID_PARAMETER;
2886   }
2887   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2888   *current = p->GetCurrent();
2889
2890   return NOTI_EX_ERROR_NONE;
2891 }
2892
2893 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2894     noti_ex_item_h handle, float current) {
2895   if (handle == nullptr) {
2896     LOGE("Invalid parameter");
2897     return NOTI_EX_ERROR_INVALID_PARAMETER;
2898   }
2899
2900   Handle *h = static_cast<Handle*>(handle);
2901   if (!h->IsValidType(AbstractItem::Progress)) {
2902     LOGE("Invalid handle type");
2903     return NOTI_EX_ERROR_INVALID_PARAMETER;
2904   }
2905   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2906   p->SetCurrent(current);
2907
2908   return NOTI_EX_ERROR_NONE;
2909 }
2910
2911 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2912     float *min) {
2913   if (handle == nullptr || min == nullptr) {
2914     LOGE("Invalid parameter");
2915     return NOTI_EX_ERROR_INVALID_PARAMETER;
2916   }
2917
2918   Handle *h = static_cast<Handle*>(handle);
2919   if (!h->IsValidType(AbstractItem::Progress)) {
2920     LOGE("Invalid handle type");
2921     return NOTI_EX_ERROR_INVALID_PARAMETER;
2922   }
2923   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2924   *min = p->GetMin();
2925
2926   return NOTI_EX_ERROR_NONE;
2927 }
2928
2929 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2930     float *max) {
2931   if (handle == nullptr || max == nullptr) {
2932     LOGE("Invalid parameter");
2933     return NOTI_EX_ERROR_INVALID_PARAMETER;
2934   }
2935
2936   Handle *h = static_cast<Handle*>(handle);
2937   if (!h->IsValidType(AbstractItem::Progress)) {
2938     LOGE("Invalid handle type");
2939     return NOTI_EX_ERROR_INVALID_PARAMETER;
2940   }
2941   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2942   *max = p->GetMax();
2943
2944   return NOTI_EX_ERROR_NONE;
2945 }
2946
2947 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2948     int* type) {
2949   if (handle == nullptr || type == nullptr) {
2950     LOGE("Invalid parameter");
2951     return NOTI_EX_ERROR_INVALID_PARAMETER;
2952   }
2953
2954   Handle *h = static_cast<Handle*>(handle);
2955   if (!h->IsValidType(AbstractItem::Progress)) {
2956     LOGE("Invalid handle type");
2957     return NOTI_EX_ERROR_INVALID_PARAMETER;
2958   }
2959   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2960   *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2961
2962   return NOTI_EX_ERROR_NONE;
2963 }
2964
2965 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2966     int type) {
2967   if (handle == nullptr) {
2968     LOGE("Invalid parameter");
2969     return NOTI_EX_ERROR_INVALID_PARAMETER;
2970   }
2971
2972   Handle *h = static_cast<Handle*>(handle);
2973   if (!h->IsValidType(AbstractItem::Progress)) {
2974     LOGE("Invalid handle type");
2975     return NOTI_EX_ERROR_INVALID_PARAMETER;
2976   }
2977   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2978   p->SetProgressType(static_cast<ProgressItem::Type>(type));
2979
2980   return NOTI_EX_ERROR_NONE;
2981 }
2982
2983 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2984     noti_ex_reporter_events_s event_callbacks, void *data) {
2985   if (handle == nullptr) {
2986     LOGE("Invalid parameter");
2987     return NOTI_EX_ERROR_INVALID_PARAMETER;
2988   }
2989
2990   ReporterStub* stub = new (std::nothrow) ReporterStub(
2991       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2992       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2993   if (stub == nullptr) {
2994     LOGE("Fail to create manager");
2995     return NOTI_EX_ERROR_IO_ERROR;
2996   }
2997   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2998       new ReporterCallbackInfo(event_callbacks, data)));
2999
3000   *handle = static_cast<noti_ex_reporter_h>(stub);
3001
3002   return NOTI_EX_ERROR_NONE;
3003 }
3004
3005 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3006   if (handle == nullptr) {
3007     LOGE("Invalid parameter");
3008     return NOTI_EX_ERROR_INVALID_PARAMETER;
3009   }
3010   ReporterStub* stub = static_cast<ReporterStub*>(handle);
3011   delete stub;
3012   return NOTI_EX_ERROR_NONE;
3013 }
3014
3015 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3016     noti_ex_event_info_h info, noti_ex_error_e error) {
3017   if (handle == nullptr || info == nullptr) {
3018     LOGE("Invalid parameter");
3019     return NOTI_EX_ERROR_INVALID_PARAMETER;
3020   }
3021   try {
3022     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3023     IEventInfo* c_info = static_cast<IEventInfo*>(info);
3024     stub->SendError(static_cast<const IEventInfo&>(*c_info),
3025         static_cast<NotificationError>(error));
3026   } catch (Exception &ex) {
3027     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3028     return NOTI_EX_ERROR_IO_ERROR;
3029   }
3030   return NOTI_EX_ERROR_NONE;
3031 }
3032
3033 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3034     noti_ex_item_h noti, int *request_id) {
3035   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3036     LOGE("Invalid parameter");
3037     return NOTI_EX_ERROR_INVALID_PARAMETER;
3038   }
3039   try {
3040     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3041     Handle* h = static_cast<Handle*>(noti);
3042     if (h->GetPtr().get() == nullptr) {
3043       LOGE("Invalid noti reference can not be sended");
3044       return NOTI_EX_ERROR_INVALID_PARAMETER;
3045     } else {
3046       *request_id = stub->Post(h->GetPtr());
3047     }
3048   } catch (Exception &ex) {
3049     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3050     return NOTI_EX_ERROR_IO_ERROR;
3051   }
3052   return NOTI_EX_ERROR_NONE;
3053 }
3054
3055 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3056     noti_ex_item_h *noti_list, int count, int *request_id) {
3057
3058   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3059     LOGE("Invalid parameter");
3060     return NOTI_EX_ERROR_INVALID_PARAMETER;
3061   }
3062   try {
3063     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3064     list<shared_ptr<item::AbstractItem>> notiList;
3065     for (int i = 0; i < count; i++) {
3066       Handle* item = static_cast<Handle*>(noti_list[i]);
3067       notiList.push_back(item->GetPtr());
3068     }
3069     *request_id = stub->Post(notiList);
3070   } catch (Exception &ex) {
3071     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3072     return NOTI_EX_ERROR_IO_ERROR;
3073   }
3074   return NOTI_EX_ERROR_NONE;
3075 }
3076
3077 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3078     noti_ex_item_h noti, int *request_id) {
3079   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3080     LOGE("Invalid parameter");
3081     return NOTI_EX_ERROR_INVALID_PARAMETER;
3082   }
3083   try {
3084     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3085     Handle* item = static_cast<Handle*>(noti);
3086     if (item->GetPtr().get() == nullptr) {
3087       LOGE("Invalid noti reference can not be sended");
3088       return NOTI_EX_ERROR_INVALID_PARAMETER;
3089     } else {
3090       *request_id = stub->Update(item->GetPtr());
3091     }
3092   } catch (Exception &ex) {
3093     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3094     return NOTI_EX_ERROR_IO_ERROR;
3095   }
3096   return NOTI_EX_ERROR_NONE;
3097 }
3098
3099 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3100     noti_ex_item_h noti, int *request_id) {
3101   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3102     LOGE("Invalid parameter");
3103     return NOTI_EX_ERROR_INVALID_PARAMETER;
3104   }
3105   try {
3106     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3107     Handle* item = static_cast<Handle*>(noti);
3108     if (item->GetPtr().get() == nullptr) {
3109       LOGE("Invalid noti reference can not be sended");
3110       return NOTI_EX_ERROR_INVALID_PARAMETER;
3111     } else {
3112       *request_id = stub->Delete(item->GetPtr());
3113     }
3114   } catch (Exception &ex) {
3115     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3116     return NOTI_EX_ERROR_IO_ERROR;
3117   }
3118   return NOTI_EX_ERROR_NONE;
3119 }
3120
3121 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3122     noti_ex_reporter_h handle, int *request_id) {
3123   if (handle == nullptr || request_id == nullptr) {
3124     LOGE("Invalid parameter");
3125     return NOTI_EX_ERROR_INVALID_PARAMETER;
3126   }
3127   try {
3128     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3129     *request_id = stub->DeleteAll();
3130   } catch (Exception &ex) {
3131     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3132     return NOTI_EX_ERROR_IO_ERROR;
3133   }
3134   return NOTI_EX_ERROR_NONE;
3135 }
3136
3137 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3138     noti_ex_reporter_h handle, const char* channel, int* request_id) {
3139   if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3140     LOGE("Invalid parameter");
3141     return NOTI_EX_ERROR_INVALID_PARAMETER;
3142   }
3143
3144   try {
3145     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3146     *request_id = stub->DeleteByChannel(channel);
3147   } catch (Exception &ex) {
3148     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3149     return NOTI_EX_ERROR_IO_ERROR;
3150   }
3151
3152   return NOTI_EX_ERROR_NONE;
3153 }
3154
3155 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3156     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3157   if (handle == nullptr || root_id == nullptr || item == nullptr) {
3158     LOGE("Invalid parameter");
3159     return NOTI_EX_ERROR_INVALID_PARAMETER;
3160   }
3161   try {
3162     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3163     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3164     if (ptr == nullptr) {
3165       LOGW("Not exist ID");
3166       *item = nullptr;
3167       return NOTI_EX_ERROR_NONE;
3168     }
3169     *item = new Handle(ptr);
3170   } catch (Exception &ex) {
3171     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3172     return NOTI_EX_ERROR_IO_ERROR;
3173   }
3174   return NOTI_EX_ERROR_NONE;
3175 }
3176
3177 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3178     const char *channel, noti_ex_item_h **noti_list, int *count) {
3179   if (handle == nullptr || channel == nullptr || noti_list == nullptr
3180       || count == nullptr) {
3181     LOGE("Invalid parameter");
3182     return NOTI_EX_ERROR_INVALID_PARAMETER;
3183   }
3184
3185   Handle** list_item = nullptr;
3186
3187   try {
3188     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3189     list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3190     if (list_ptr.empty()) {
3191       LOGW("Not exist ID");
3192       *noti_list = nullptr;
3193       return NOTI_EX_ERROR_NONE;
3194     }
3195
3196     int size = list_ptr.size();
3197     int i = 0;
3198
3199     list_item = (Handle**)calloc(size, sizeof(Handle*));
3200     for (auto& ptr : list_ptr)
3201       list_item[i++] = new Handle(std::move(ptr));
3202
3203     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3204     *count = size;
3205   } catch (Exception &ex) {
3206     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3207     free(list_item);
3208     return NOTI_EX_ERROR_IO_ERROR;
3209   }
3210
3211   return NOTI_EX_ERROR_NONE;
3212 }
3213
3214 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3215     noti_ex_item_h **noti_list, int *count) {
3216   if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3217     LOGE("Invalid parameter");
3218     return NOTI_EX_ERROR_INVALID_PARAMETER;
3219   }
3220
3221   Handle** list_item = nullptr;
3222
3223   try {
3224     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3225     list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3226     if (list_ptr.empty()) {
3227       LOGW("Not exist ID");
3228       *noti_list = nullptr;
3229       return NOTI_EX_ERROR_NONE;
3230     }
3231
3232     int size = list_ptr.size();
3233     int i = 0;
3234
3235     list_item = (Handle**)calloc(size, sizeof(Handle*));
3236     for (auto& ptr : list_ptr)
3237       list_item[i++] = new Handle(std::move(ptr));
3238
3239     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3240     *count = size;
3241   } catch (Exception &ex) {
3242     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3243     free(list_item);
3244     return NOTI_EX_ERROR_IO_ERROR;
3245   }
3246
3247   return NOTI_EX_ERROR_NONE;
3248 }
3249
3250 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3251     const char *id, const char *text, const char *hyperlink) {
3252   if (handle == nullptr || text == nullptr) {
3253     LOGE("Invalid parameter");
3254     return NOTI_EX_ERROR_INVALID_PARAMETER;
3255   }
3256
3257   TextItem* p;
3258
3259   if (id == NULL)
3260     id = "";
3261
3262   if (hyperlink)
3263     p = new (std::nothrow) TextItem(id, std::string(text),
3264                 std::string(hyperlink));
3265   else
3266     p = new (std::nothrow) TextItem(id, std::string(text));
3267
3268   if (p == nullptr) {
3269     LOGE("Out-of-memory");
3270     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3271   }
3272
3273   *handle = new Handle(shared_ptr<AbstractItem>(p));
3274
3275   return NOTI_EX_ERROR_NONE;
3276 }
3277
3278 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3279     const char *contents) {
3280   if (handle == nullptr || contents == nullptr) {
3281     LOGE("Invalid parameter");
3282     return NOTI_EX_ERROR_INVALID_PARAMETER;
3283   }
3284
3285   Handle* p = static_cast<Handle*>(handle);
3286   if (!p->IsValidType(AbstractItem::Text)) {
3287     LOGE("Invalid handle type");
3288     return NOTI_EX_ERROR_INVALID_PARAMETER;
3289   }
3290   TextItem* ti = static_cast<TextItem*>(p->Get());
3291   ti->SetContents(std::string(contents));
3292
3293   return NOTI_EX_ERROR_NONE;
3294 }
3295
3296 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3297     char **contents) {
3298   if (handle == nullptr || contents == nullptr) {
3299     LOGE("Invalid parameter");
3300     return NOTI_EX_ERROR_INVALID_PARAMETER;
3301   }
3302
3303   Handle* p = static_cast<Handle*>(handle);
3304   if (!p->IsValidType(AbstractItem::Text)) {
3305     LOGE("Invalid handle type");
3306     return NOTI_EX_ERROR_INVALID_PARAMETER;
3307   }
3308
3309   TextItem* ti = static_cast<TextItem*>(p->Get());
3310   string str;
3311   if (ti->GetMultiLanguage() != nullptr &&
3312       !ti->GetMultiLanguage()->GetTranslatedString().empty())
3313     str = ti->GetMultiLanguage()->GetTranslatedString();
3314   else if (!ti->GetContents().empty())
3315     str = ti->GetContents();
3316
3317   *contents = strdup(str.c_str());
3318   if (*contents == nullptr) {
3319     LOGE("Out-of-memory");
3320     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3321   }
3322
3323   return NOTI_EX_ERROR_NONE;
3324 }
3325
3326 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3327     noti_ex_item_h handle, char **hyper_link) {
3328   if (handle == nullptr || hyper_link == nullptr) {
3329     LOGE("Invalid parameter");
3330     return NOTI_EX_ERROR_INVALID_PARAMETER;
3331   }
3332
3333   Handle* p = static_cast<Handle*>(handle);
3334   if (!p->IsValidType(AbstractItem::Text)) {
3335     LOGE("Invalid handle type");
3336     return NOTI_EX_ERROR_INVALID_PARAMETER;
3337   }
3338   TextItem* ti = static_cast<TextItem*>(p->Get());
3339   if (!ti->GetHyperLink().empty()) {
3340     *hyper_link = strdup(ti->GetHyperLink().c_str());
3341     if (*hyper_link == nullptr) {
3342       LOGE("Out-of-memory");
3343       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3344     }
3345   } else {
3346     *hyper_link = nullptr;
3347   }
3348
3349   return NOTI_EX_ERROR_NONE;
3350 }
3351
3352 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3353     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3354   if (handle == nullptr) {
3355     LOGE("Invalid parameter");
3356     return NOTI_EX_ERROR_INVALID_PARAMETER;
3357   }
3358
3359   Handle* p = static_cast<Handle*>(handle);
3360   if (!p->IsValidType(AbstractItem::Text)) {
3361     LOGE("Invalid handle type");
3362     return NOTI_EX_ERROR_INVALID_PARAMETER;
3363   }
3364
3365   TextItem* ti = static_cast<TextItem*>(p->Get());
3366   if (multi == nullptr) {
3367     ti->SetMultiLanguage(nullptr);
3368     return NOTI_EX_ERROR_NONE;
3369   }
3370
3371   shared_ptr<MultiLanguage> mul_ptr =
3372       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3373   ti->SetMultiLanguage(mul_ptr);
3374   ti->GetMultiLanguage()->UpdateString();
3375
3376   return NOTI_EX_ERROR_NONE;
3377 }
3378
3379 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3380     const char *id, time_t time) {
3381   TimeItem* p;
3382
3383   if (handle == nullptr) {
3384     LOGE("Invalid parameter");
3385     return NOTI_EX_ERROR_INVALID_PARAMETER;
3386   }
3387
3388   if (time) {
3389     if (id)
3390       p = new (std::nothrow) TimeItem(id, time);
3391     else
3392       p = new (std::nothrow) TimeItem(time);
3393   } else {
3394       p = new (std::nothrow) TimeItem();
3395   }
3396
3397   if (p == nullptr) {
3398     LOGE("Out-of-memory");
3399     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3400   }
3401
3402   *handle = new Handle(shared_ptr<AbstractItem>(p));
3403
3404   return NOTI_EX_ERROR_NONE;
3405 }
3406
3407 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3408     time_t *time) {
3409   if (handle == nullptr || time == nullptr) {
3410     LOGE("Invalid parameter");
3411     return NOTI_EX_ERROR_INVALID_PARAMETER;
3412   }
3413   Handle* h = static_cast<Handle*>(handle);
3414   if (!h->IsValidType(AbstractItem::Time)) {
3415     LOGE("Invalid handle type");
3416     return NOTI_EX_ERROR_INVALID_PARAMETER;
3417   }
3418   TimeItem* p = static_cast<TimeItem*>(h->Get());
3419   *time = p->GetTime();
3420
3421   return NOTI_EX_ERROR_NONE;
3422 }
3423
3424 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3425     time_t time) {
3426   if (handle == nullptr) {
3427     LOGE("Invalid parameter");
3428     return NOTI_EX_ERROR_INVALID_PARAMETER;
3429   }
3430   Handle* h = static_cast<Handle*>(handle);
3431   if (!h->IsValidType(AbstractItem::Time)) {
3432     LOGE("Invalid handle type");
3433     return NOTI_EX_ERROR_INVALID_PARAMETER;
3434   }
3435   TimeItem* p = static_cast<TimeItem*>(h->Get());
3436   p->SetTime(time);
3437
3438   return NOTI_EX_ERROR_NONE;
3439 }
3440
3441 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3442     noti_ex_action_h *handle, const char *extra) {
3443   if (handle == nullptr) {
3444     LOGE("Invalid parameter");
3445     return NOTI_EX_ERROR_INVALID_PARAMETER;
3446   }
3447
3448   string extra_str = "";
3449   if (extra != NULL)
3450     extra_str = string(extra);
3451
3452   shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3453       new (std::nothrow) VisibilityAction(extra_str));
3454   if (ptr == nullptr) {
3455     LOGE("Out-of-memory");
3456     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3457   }
3458
3459   *handle = ptr;
3460
3461   return NOTI_EX_ERROR_NONE;
3462 }
3463
3464 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3465     const char *id, bool visible) {
3466   if (handle == nullptr || id == nullptr) {
3467     LOGE("Invalid parameter");
3468     return NOTI_EX_ERROR_INVALID_PARAMETER;
3469   }
3470
3471   shared_ptr<AbstractAction>* ptr =
3472       static_cast<shared_ptr<AbstractAction>*>(handle);
3473   VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3474   action->SetVisibility(id, visible);
3475
3476   return NOTI_EX_ERROR_NONE;
3477 }
3478
3479 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3480     const char* msgid, const char* format, ...) {
3481   if (handle == nullptr || msgid == nullptr || format == nullptr) {
3482     LOGE("Invalid parameter");
3483     return NOTI_EX_ERROR_INVALID_PARAMETER;
3484   }
3485
3486   const char* format_idx = format;
3487   vector<string> arr;
3488   va_list args;
3489   va_start(args, format);
3490   while (*format_idx != '\0') {
3491     char* arg = nullptr;
3492     int arg_i;
3493     double arg_f;
3494     stringstream stream;
3495     if (*format_idx == '%') {
3496       switch (*(format_idx + 1)) {
3497         case 's':
3498           arg = va_arg(args, char *);
3499           arr.push_back(string(arg));
3500           break;
3501         case 'd':
3502           arg_i = va_arg(args, int);
3503           arr.push_back(to_string(arg_i));
3504           break;
3505         case 'f':
3506           arg_f = va_arg(args, double);
3507           stream << std::fixed << std::setprecision(2) << arg_f;
3508           arr.push_back(stream.str());
3509           break;
3510       }
3511     }
3512     format_idx++;
3513   }
3514   va_end(args);
3515
3516   MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3517   if (p == nullptr) {
3518     LOGE("Out-of-memory");
3519     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3520   }
3521   *handle = new shared_ptr<MultiLanguage>(p);
3522
3523   return NOTI_EX_ERROR_NONE;
3524 }
3525
3526 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3527   if (handle == nullptr) {
3528     LOGE("Invalid parameter");
3529     return NOTI_EX_ERROR_INVALID_PARAMETER;
3530   }
3531
3532   shared_ptr<MultiLanguage>* mul_ptr =
3533       reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3534   delete mul_ptr;
3535   return NOTI_EX_ERROR_NONE;
3536 }
3537
3538 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3539     noti_ex_item_h item, int64_t* private_id) {
3540   if (item == nullptr || private_id == nullptr) {
3541     LOGE("Invalid parameter");
3542     return NOTI_EX_ERROR_INVALID_PARAMETER;
3543   }
3544
3545   Handle* h = static_cast<Handle*>(item);
3546   *private_id = static_pointer_cast<IItemInfoInternal>(
3547       h->Get()->GetInfo())->GetPrivateId();
3548
3549   return NOTI_EX_ERROR_NONE;
3550 }
3551
3552 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3553     noti_ex_item_h item, int64_t priv_id) {
3554   if (item == nullptr) {
3555     LOGE("Invalid parameter");
3556     return NOTI_EX_ERROR_INVALID_PARAMETER;
3557   }
3558
3559   Handle* h = static_cast<Handle*>(item);
3560   static_pointer_cast<IItemInfoInternal>(
3561       h->Get()->GetInfo())->SetPrivateId(priv_id);
3562
3563   return NOTI_EX_ERROR_NONE;
3564 }
3565
3566 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3567   if (list == nullptr) {
3568     LOGE("Invalid parameter");
3569     return NOTI_EX_ERROR_INVALID_PARAMETER;
3570   }
3571
3572   LOGI("Free strings (%d)", count);
3573   for (int i = 0; i < count; i++)
3574     free(list[i]);
3575   free(list);
3576
3577   return NOTI_EX_ERROR_NONE;
3578 }
3579
3580 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3581   if (handle == nullptr) {
3582     LOGE("Invalid parameter");
3583     return NOTI_EX_ERROR_INVALID_PARAMETER;
3584   }
3585   Handle* h = static_cast<Handle*>(handle);
3586   if (!h->IsValidType(AbstractItem::Group)) {
3587     LOGE("Invalid handle type");
3588     return NOTI_EX_ERROR_INVALID_PARAMETER;
3589   }
3590   GroupItem* p = static_cast<GroupItem*>(h->Get());
3591   p->RemoveChildren();
3592
3593   return NOTI_EX_ERROR_NONE;
3594 }
3595
3596 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3597     const char *id, const char *icon_path) {
3598   if (handle == nullptr || icon_path == nullptr) {
3599     LOGE("Invalid parameter");
3600     return NOTI_EX_ERROR_INVALID_PARAMETER;
3601   }
3602
3603   IconItem* p;
3604   if (id)
3605     p = new (std::nothrow) IconItem(id, icon_path);
3606   else
3607     p = new (std::nothrow) IconItem(icon_path);
3608
3609   if (p == nullptr) {
3610     LOGE("Out-of-memory");
3611     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3612   }
3613
3614   *handle = new Handle(shared_ptr<AbstractItem>(p));
3615
3616   return NOTI_EX_ERROR_NONE;
3617 }
3618
3619 int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3620   if (handle == nullptr || icon_path == nullptr) {
3621     LOGE("Invalid parameter");
3622     return NOTI_EX_ERROR_INVALID_PARAMETER;
3623   }
3624
3625   Handle* h = static_cast<Handle*>(handle);
3626   if (!h->IsValidType(AbstractItem::Icon)) {
3627     LOGE("Invalid handle type");
3628     return NOTI_EX_ERROR_INVALID_PARAMETER;
3629   }
3630
3631   IconItem* p = static_cast<IconItem*>(h->Get());
3632   if (!p->GetImagePath().empty()) {
3633     *icon_path = strdup(p->GetImagePath().c_str());
3634     if (*icon_path == nullptr) {
3635       LOGE("Out-of-memory");
3636       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3637     }
3638   } else {
3639     *icon_path = nullptr;
3640   }
3641
3642   return NOTI_EX_ERROR_NONE;
3643 }