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