Merge "Add internal api to support C#" into tizen
[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.get() == nullptr) {
2038     LOGE("Style is null");
2039     return NOTI_EX_ERROR_INVALID_PARAMETER;
2040   }
2041
2042   auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2043   if (ptr == nullptr || ptr->get() == nullptr) {
2044     LOGE("Out of memory");
2045     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2046   }
2047
2048   *style = ptr;
2049   return NOTI_EX_ERROR_NONE;
2050 }
2051
2052 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2053     noti_ex_style_h style) {
2054   if (handle == nullptr || style == nullptr) {
2055     LOGE("Invalid parameter");
2056     return NOTI_EX_ERROR_INVALID_PARAMETER;
2057   }
2058
2059   Handle* p = static_cast<Handle*>(handle);
2060   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2061   p->Get()->SetStyle(*s);
2062   return NOTI_EX_ERROR_NONE;
2063 }
2064
2065 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2066     bool visible) {
2067   if (handle == nullptr) {
2068     LOGE("Invalid parameter");
2069     return NOTI_EX_ERROR_INVALID_PARAMETER;
2070   }
2071
2072   Handle* p = static_cast<Handle*>(handle);
2073   p->Get()->SetVisible(visible);
2074   return NOTI_EX_ERROR_NONE;
2075 }
2076
2077 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2078     bool *visible) {
2079   if (handle == nullptr || visible == nullptr) {
2080     LOGE("Invalid parameter");
2081     return NOTI_EX_ERROR_INVALID_PARAMETER;
2082   }
2083
2084   Handle* p = static_cast<Handle*>(handle);
2085   *visible = p->Get()->GetVisible();
2086   return NOTI_EX_ERROR_NONE;
2087 }
2088
2089 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2090     bool enable) {
2091   if (handle == nullptr) {
2092     LOGE("Invalid parameter");
2093     return NOTI_EX_ERROR_INVALID_PARAMETER;
2094   }
2095
2096   Handle* p = static_cast<Handle*>(handle);
2097   p->Get()->SetEnable(enable);
2098   return NOTI_EX_ERROR_NONE;
2099 }
2100
2101 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2102     bool *enable) {
2103   if (handle == nullptr || enable == nullptr) {
2104     LOGE("Invalid parameter");
2105     return NOTI_EX_ERROR_INVALID_PARAMETER;
2106   }
2107
2108   Handle* p = static_cast<Handle*>(handle);
2109   *enable = p->Get()->GetEnable();
2110   return NOTI_EX_ERROR_NONE;
2111 }
2112
2113 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2114     const char *receiver_group) {
2115   if (handle == nullptr || receiver_group == nullptr) {
2116     LOGE("Invalid parameter");
2117     return NOTI_EX_ERROR_INVALID_PARAMETER;
2118   }
2119
2120   Handle* p = static_cast<Handle*>(handle);
2121   p->Get()->AddReceiver(receiver_group);
2122   return NOTI_EX_ERROR_NONE;
2123 }
2124
2125 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2126     const char *receiver_group) {
2127   if (handle == nullptr || receiver_group == nullptr) {
2128     LOGE("Invalid parameter");
2129     return NOTI_EX_ERROR_INVALID_PARAMETER;
2130   }
2131
2132   Handle* p = static_cast<Handle*>(handle);
2133   p->Get()->RemoveReceiver(receiver_group);
2134   return NOTI_EX_ERROR_NONE;
2135 }
2136
2137 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2138     char ***receiver_list, int *count) {
2139   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2140     LOGE("Invalid parameter");
2141     return NOTI_EX_ERROR_INVALID_PARAMETER;
2142   }
2143
2144   Handle* p = static_cast<Handle*>(handle);
2145   list<string> receivers = p->Get()->GetReceiverList();
2146   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2147   if (tmp_list == nullptr) {
2148     LOGE("Out of memory");
2149     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2150   }
2151
2152   int idx = 0;
2153   for (auto& i : receivers) {
2154     tmp_list[idx] = strdup(i.c_str());
2155     if (tmp_list[idx] == nullptr) {
2156       __noti_ex_free_str_array(tmp_list, idx);
2157       LOGE("Out of memory");
2158       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2159     }
2160     idx++;
2161   }
2162
2163   *receiver_list = tmp_list;
2164   *count = receivers.size();
2165   return NOTI_EX_ERROR_NONE;
2166 }
2167
2168 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2169     int policy) {
2170   if (handle == nullptr) {
2171     LOGE("Invalid parameter");
2172     return NOTI_EX_ERROR_INVALID_PARAMETER;
2173   }
2174
2175   Handle* p = static_cast<Handle*>(handle);
2176   p->Get()->SetPolicy(policy);
2177   return NOTI_EX_ERROR_NONE;
2178 }
2179
2180 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2181     int *policy) {
2182   if (handle == nullptr || policy == nullptr) {
2183     LOGE("Invalid parameter");
2184     return NOTI_EX_ERROR_INVALID_PARAMETER;
2185   }
2186
2187   Handle* p = static_cast<Handle*>(handle);
2188   *policy = p->Get()->GetPolicy();
2189   return NOTI_EX_ERROR_NONE;
2190 }
2191
2192 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2193     char **channel) {
2194   if (handle == nullptr || channel == nullptr) {
2195     LOGE("Invalid parameter");
2196     return NOTI_EX_ERROR_INVALID_PARAMETER;
2197   }
2198
2199   Handle* p = static_cast<Handle*>(handle);
2200   if (!p->Get()->GetChannel().empty())
2201     *channel = strdup(p->Get()->GetChannel().c_str());
2202   else
2203     *channel = nullptr;
2204
2205   return NOTI_EX_ERROR_NONE;
2206 }
2207
2208 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2209     const char *channel) {
2210   if (handle == nullptr) {
2211     LOGE("Invalid parameter");
2212     return NOTI_EX_ERROR_INVALID_PARAMETER;
2213   }
2214
2215   Handle* p = static_cast<Handle*>(handle);
2216   p->Get()->SetChannel(channel);
2217   return NOTI_EX_ERROR_NONE;
2218 }
2219
2220 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2221     noti_ex_led_info_h led) {
2222   if (handle == nullptr) {
2223     LOGE("Invalid parameter");
2224     return NOTI_EX_ERROR_INVALID_PARAMETER;
2225   }
2226
2227   Handle* p = static_cast<Handle*>(handle);
2228   if (led == nullptr) {
2229      p->Get()->SetLEDInfo(nullptr);
2230      return NOTI_EX_ERROR_NONE;
2231   }
2232   shared_ptr<LEDInfo>* led_ptr =
2233       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2234   p->Get()->SetLEDInfo(*led_ptr);
2235   return NOTI_EX_ERROR_NONE;
2236 }
2237
2238 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2239     noti_ex_led_info_h *led) {
2240   if (handle == nullptr) {
2241     LOGE("Invalid parameter");
2242     return NOTI_EX_ERROR_INVALID_PARAMETER;
2243   }
2244
2245   Handle* p = static_cast<Handle*>(handle);
2246   if (p->Get()->GetLEDInfo() != nullptr)
2247     *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2248   else
2249     *led = nullptr;
2250   return NOTI_EX_ERROR_NONE;
2251 }
2252
2253 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2254     const char *path) {
2255   if (handle == nullptr) {
2256     LOGE("Invalid parameter");
2257     return NOTI_EX_ERROR_INVALID_PARAMETER;
2258   }
2259
2260   Handle* p = static_cast<Handle*>(handle);
2261   if (path == nullptr)
2262     p->Get()->SetSoundPath("");
2263   else
2264     p->Get()->SetSoundPath(path);
2265   return NOTI_EX_ERROR_NONE;
2266 }
2267
2268 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2269     const char *path) {
2270   if (handle == nullptr) {
2271     LOGE("Invalid parameter");
2272     return NOTI_EX_ERROR_INVALID_PARAMETER;
2273   }
2274
2275   Handle* p = static_cast<Handle*>(handle);
2276   if (path == nullptr)
2277     p->Get()->SetVibrationPath("");
2278   else
2279     p->Get()->SetVibrationPath(path);
2280   return NOTI_EX_ERROR_NONE;
2281 }
2282
2283 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2284     char **path) {
2285   if (handle == nullptr || path == nullptr) {
2286     LOGE("Invalid parameter");
2287     return NOTI_EX_ERROR_INVALID_PARAMETER;
2288   }
2289
2290   Handle* p = static_cast<Handle*>(handle);
2291   if (p->Get()->GetSoundPath().empty())
2292     *path = nullptr;
2293   else
2294     *path = strdup(p->Get()->GetSoundPath().c_str());
2295   return NOTI_EX_ERROR_NONE;
2296 }
2297
2298 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2299     char **path) {
2300   if (handle == nullptr || path == nullptr) {
2301     LOGE("Invalid parameter");
2302     return NOTI_EX_ERROR_INVALID_PARAMETER;
2303   }
2304
2305   Handle* p = static_cast<Handle*>(handle);
2306   if (p->Get()->GetVibrationPath().empty())
2307     *path = nullptr;
2308   else
2309     *path = strdup(p->Get()->GetVibrationPath().c_str());
2310   return NOTI_EX_ERROR_NONE;
2311 }
2312
2313 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2314     noti_ex_item_info_h *info) {
2315   if (handle == nullptr || info == nullptr) {
2316     LOGE("Invalid parameter");
2317     return NOTI_EX_ERROR_INVALID_PARAMETER;
2318   }
2319
2320   Handle* p = static_cast<Handle*>(handle);
2321   if (p->Get()->GetInfo() == nullptr)
2322     *info = nullptr;
2323   else
2324     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2325   return NOTI_EX_ERROR_NONE;
2326 }
2327
2328 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2329     char **id) {
2330   if (handle == nullptr || id == nullptr) {
2331     LOGE("Invalid parameter");
2332     return NOTI_EX_ERROR_INVALID_PARAMETER;
2333   }
2334
2335   Handle* p = static_cast<Handle*>(handle);
2336   if (p->Get()->GetSenderAppId().empty())
2337     *id = nullptr;
2338   else
2339     *id = strdup(p->Get()->GetSenderAppId().c_str());
2340   return NOTI_EX_ERROR_NONE;
2341 }
2342
2343 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2344     char **tag) {
2345   if (handle == nullptr || tag == nullptr) {
2346     LOGE("Invalid parameter");
2347     return NOTI_EX_ERROR_INVALID_PARAMETER;
2348   }
2349
2350   Handle* p = static_cast<Handle*>(handle);
2351   if (p->Get()->GetTag().empty())
2352     *tag = nullptr;
2353   else
2354     *tag = strdup(p->Get()->GetTag().c_str());
2355   return NOTI_EX_ERROR_NONE;
2356 }
2357
2358 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2359     const char *tag) {
2360   if (handle == nullptr) {
2361     LOGE("Invalid parameter");
2362     return NOTI_EX_ERROR_INVALID_PARAMETER;
2363   }
2364
2365   Handle* p = static_cast<Handle*>(handle);
2366   if (tag == nullptr)
2367     p->Get()->SetTag("");
2368   else
2369     p->Get()->SetTag(tag);
2370   return NOTI_EX_ERROR_NONE;
2371 }
2372
2373 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2374     bool* ongoing) {
2375   if (handle == nullptr || ongoing == nullptr) {
2376     LOGE("Invalid parameter");
2377     return NOTI_EX_ERROR_INVALID_PARAMETER;
2378   }
2379
2380   Handle* p = static_cast<Handle*>(handle);
2381   *ongoing = p->Get()->GetOnGoingState();
2382
2383   return NOTI_EX_ERROR_NONE;
2384 }
2385
2386 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2387     bool ongoing) {
2388   if (handle == nullptr) {
2389     LOGE("Invalid parameter");
2390     return NOTI_EX_ERROR_INVALID_PARAMETER;
2391   }
2392
2393   Handle* p = static_cast<Handle*>(handle);
2394   p->Get()->SetOnGoingState(ongoing);
2395
2396   return NOTI_EX_ERROR_NONE;
2397 }
2398
2399 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2400     int type, bool* exist) {
2401   if (handle == nullptr || exist == nullptr) {
2402     LOGE("Invalid parameter");
2403     return NOTI_EX_ERROR_INVALID_PARAMETER;
2404   }
2405
2406   Handle* p = static_cast<Handle*>(handle);
2407   *exist = p->Get()->IsItemTypeExist(type);
2408
2409   return NOTI_EX_ERROR_NONE;
2410 }
2411
2412 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2413     int* type) {
2414   if (handle == nullptr || type == nullptr) {
2415     LOGE("Invalid parameter");
2416     return NOTI_EX_ERROR_INVALID_PARAMETER;
2417   }
2418
2419   Handle* p = static_cast<Handle*>(handle);
2420   *type = p->Get()->GetMainType();
2421
2422   return NOTI_EX_ERROR_NONE;
2423 }
2424
2425 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2426     const char* id, int type) {
2427   if (handle == nullptr || id == nullptr) {
2428     LOGE("Invalid parameter");
2429     return NOTI_EX_ERROR_INVALID_PARAMETER;
2430   }
2431
2432   Handle* p = static_cast<Handle*>(handle);
2433   if (!(p->Get()->SetMainType(string(id),
2434                     static_cast<AbstractItem::MainType>(type))))
2435     return NOTI_EX_ERROR_INVALID_PARAMETER;
2436
2437   return NOTI_EX_ERROR_NONE;
2438 }
2439
2440 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2441     int type, noti_ex_item_h* item) {
2442   if (handle == nullptr || item == nullptr) {
2443     LOGE("Invalid parameter");
2444     return NOTI_EX_ERROR_INVALID_PARAMETER;
2445   }
2446
2447   Handle* h = static_cast<Handle*>(handle);
2448   if (!h->IsValidType(AbstractItem::Group)) {
2449     LOGE("Invalid handle type");
2450     return NOTI_EX_ERROR_INVALID_PARAMETER;
2451   }
2452
2453   GroupItem* p = static_cast<GroupItem*>(h->Get());
2454   AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2455   *item = new Handle(&find_item);
2456
2457   return NOTI_EX_ERROR_NONE;
2458 }
2459
2460 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2461     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2462     void *data) {
2463   if (handle == nullptr) {
2464     LOGE("Invalid parameter");
2465     return NOTI_EX_ERROR_INVALID_PARAMETER;
2466   }
2467
2468   string receiver_group_str = "";
2469   if (receiver_group)
2470     receiver_group_str = string(receiver_group);
2471
2472   ManagerStub* stub = new (std::nothrow) ManagerStub(
2473       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2474       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2475       receiver_group_str);
2476   if (stub == nullptr) {
2477     LOGE("Fail to create manager");
2478     return NOTI_EX_ERROR_IO_ERROR;
2479   }
2480   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2481       new ManagerCallbackInfo(event_callbacks, data)));
2482   *handle = static_cast<noti_ex_manager_h>(stub);
2483
2484   return NOTI_EX_ERROR_NONE;
2485 }
2486
2487 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2488   if (handle == nullptr) {
2489     LOGE("Invalid parameter");
2490     return NOTI_EX_ERROR_INVALID_PARAMETER;
2491   }
2492   ManagerStub* stub = static_cast<ManagerStub*>(handle);
2493   delete stub;
2494   return NOTI_EX_ERROR_NONE;
2495 }
2496
2497 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2498     noti_ex_item_h **items, int *count) {
2499   if (handle == nullptr || items == nullptr || count == nullptr) {
2500     LOGE("Invalid parameter");
2501     return NOTI_EX_ERROR_INVALID_PARAMETER;
2502   }
2503
2504   try {
2505     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2506     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2507     if (item_list.size() == 0) {
2508       *items = nullptr;
2509       *count = 0;
2510       return NOTI_EX_ERROR_NONE;
2511     }
2512     noti_ex_item_h* added_item =
2513         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2514     if (added_item == nullptr) {
2515       LOGE("Fail to create items");
2516       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2517     }
2518
2519     int idx = 0;
2520     for (auto& i : item_list) {
2521       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2522     }
2523     *items = added_item;
2524     *count = item_list.size();
2525   } catch (Exception &ex) {
2526     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2527     return NOTI_EX_ERROR_IO_ERROR;
2528   }
2529   return NOTI_EX_ERROR_NONE;
2530 }
2531
2532 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2533     noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2534   if (handle == nullptr || channel == nullptr ||
2535       items == nullptr || count == nullptr) {
2536     LOGE("Invalid parameter");
2537     return NOTI_EX_ERROR_INVALID_PARAMETER;
2538   }
2539
2540   try {
2541     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2542     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2543     if (item_list.size() == 0) {
2544       *items = nullptr;
2545       *count = 0;
2546       return NOTI_EX_ERROR_NONE;
2547     }
2548     noti_ex_item_h* added_item =
2549         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2550     if (added_item == nullptr) {
2551       LOGE("Fail to create items");
2552       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2553     }
2554
2555     int idx = 0;
2556     for (auto& i : item_list) {
2557       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2558     }
2559     *items = added_item;
2560     *count = item_list.size();
2561   } catch (Exception &ex) {
2562     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2563     return NOTI_EX_ERROR_IO_ERROR;
2564   }
2565
2566   return NOTI_EX_ERROR_NONE;
2567 }
2568
2569 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2570     noti_ex_item_h noti, int *request_id) {
2571   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2572     LOGE("Invalid parameter");
2573     return NOTI_EX_ERROR_INVALID_PARAMETER;
2574   }
2575   try {
2576     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2577     Handle* sp = static_cast<Handle*>(noti);
2578     if (sp->GetPtr().get() == nullptr) {
2579       LOGE("Invalid noti reference can not be sended");
2580       return NOTI_EX_ERROR_INVALID_PARAMETER;
2581     } else {
2582       *request_id = stub->Update(sp->GetPtr());
2583     }
2584   } catch (Exception &ex) {
2585     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2586     return NOTI_EX_ERROR_IO_ERROR;
2587   }
2588   return NOTI_EX_ERROR_NONE;
2589 }
2590
2591 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2592     noti_ex_item_h noti, int *request_id) {
2593   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2594     LOGE("Invalid parameter");
2595     return NOTI_EX_ERROR_INVALID_PARAMETER;
2596   }
2597   try {
2598     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2599     Handle* item = static_cast<Handle*>(noti);
2600     if (item->GetPtr().get() == nullptr) {
2601       LOGE("Invalid noti reference can not be sended");
2602       return NOTI_EX_ERROR_INVALID_PARAMETER;
2603     } else {
2604       *request_id = stub->Delete(item->GetPtr());
2605     }
2606   } catch (Exception &ex) {
2607     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2608     return NOTI_EX_ERROR_IO_ERROR;
2609   }
2610   return NOTI_EX_ERROR_NONE;
2611 }
2612
2613 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2614     int *request_id) {
2615   if (handle == nullptr || request_id == nullptr) {
2616     LOGE("Invalid parameter");
2617     return NOTI_EX_ERROR_INVALID_PARAMETER;
2618   }
2619   try {
2620     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2621     *request_id = stub->DeleteAll();
2622   } catch (Exception &ex) {
2623     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2624     return NOTI_EX_ERROR_IO_ERROR;
2625   }
2626   return NOTI_EX_ERROR_NONE;
2627 }
2628
2629 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2630     noti_ex_item_h noti, int *request_id) {
2631   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2632     LOGE("Invalid parameter");
2633     return NOTI_EX_ERROR_INVALID_PARAMETER;
2634   }
2635   try {
2636     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2637     Handle* item = static_cast<Handle*>(noti);
2638     if (item->GetPtr().get() == nullptr) {
2639       LOGE("Invalid noti reference can not be sended");
2640       return NOTI_EX_ERROR_INVALID_PARAMETER;
2641     } else {
2642       *request_id = stub->Hide(item->GetPtr());
2643     }
2644   } catch (Exception &ex) {
2645     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2646     return NOTI_EX_ERROR_IO_ERROR;
2647   }
2648   return NOTI_EX_ERROR_NONE;
2649 }
2650
2651 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2652     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2653   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2654     LOGE("Invalid parameter");
2655     return NOTI_EX_ERROR_INVALID_PARAMETER;
2656   }
2657   try {
2658     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2659     *item = new Handle(stub->FindByRootID(root_id));
2660   } catch (Exception &ex) {
2661     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2662     return NOTI_EX_ERROR_IO_ERROR;
2663   }
2664   return NOTI_EX_ERROR_NONE;
2665 }
2666
2667 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2668     noti_ex_event_info_h info, noti_ex_error_e error) {
2669   if (handle == nullptr || info == nullptr) {
2670     LOGE("Invalid parameter");
2671     return NOTI_EX_ERROR_INVALID_PARAMETER;
2672   }
2673   try {
2674     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2675     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2676     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2677         static_cast<NotificationError>(error));
2678   } catch (Exception &ex) {
2679     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2680     return NOTI_EX_ERROR_IO_ERROR;
2681   }
2682   return NOTI_EX_ERROR_NONE;
2683 }
2684
2685 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2686     noti_ex_manager_h handle, int *cnt) {
2687
2688   if (handle == nullptr || cnt == nullptr) {
2689     LOGE("Invalid parameter");
2690     return NOTI_EX_ERROR_INVALID_PARAMETER;
2691   }
2692   try {
2693     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2694     *cnt = stub->GetCount();
2695   } catch (Exception &ex) {
2696     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2697     return NOTI_EX_ERROR_IO_ERROR;
2698   }
2699   return NOTI_EX_ERROR_NONE;
2700 }
2701
2702 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2703     const char *id, float min, float current, float max) {
2704   ProgressItem* p;
2705
2706   if (handle == nullptr) {
2707     LOGE("Invalid parameter");
2708     return NOTI_EX_ERROR_INVALID_PARAMETER;
2709   }
2710
2711   if (id)
2712     p = new (std::nothrow) ProgressItem(id, min, current, max);
2713   else
2714     p = new (std::nothrow) ProgressItem(min, current, max);
2715
2716   if (p == nullptr) {
2717     LOGE("Out-of-memory");
2718     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2719   }
2720
2721   *handle = new Handle(shared_ptr<AbstractItem>(p));
2722
2723   return NOTI_EX_ERROR_NONE;
2724 }
2725
2726 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2727     noti_ex_item_h handle, float *current) {
2728   if (handle == nullptr || current == nullptr) {
2729     LOGE("Invalid parameter");
2730     return NOTI_EX_ERROR_INVALID_PARAMETER;
2731   }
2732
2733   Handle *h = static_cast<Handle*>(handle);
2734   if (!h->IsValidType(AbstractItem::Progress)) {
2735     LOGE("Invalid handle type");
2736     return NOTI_EX_ERROR_INVALID_PARAMETER;
2737   }
2738   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2739   *current = p->GetCurrent();
2740
2741   return NOTI_EX_ERROR_NONE;
2742 }
2743
2744 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2745     noti_ex_item_h handle, float current) {
2746   if (handle == nullptr) {
2747     LOGE("Invalid parameter");
2748     return NOTI_EX_ERROR_INVALID_PARAMETER;
2749   }
2750
2751   Handle *h = static_cast<Handle*>(handle);
2752   if (!h->IsValidType(AbstractItem::Progress)) {
2753     LOGE("Invalid handle type");
2754     return NOTI_EX_ERROR_INVALID_PARAMETER;
2755   }
2756   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2757   p->SetCurrent(current);
2758
2759   return NOTI_EX_ERROR_NONE;
2760 }
2761
2762 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2763     float *min) {
2764   if (handle == nullptr || min == nullptr) {
2765     LOGE("Invalid parameter");
2766     return NOTI_EX_ERROR_INVALID_PARAMETER;
2767   }
2768
2769   Handle *h = static_cast<Handle*>(handle);
2770   if (!h->IsValidType(AbstractItem::Progress)) {
2771     LOGE("Invalid handle type");
2772     return NOTI_EX_ERROR_INVALID_PARAMETER;
2773   }
2774   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2775   *min = p->GetMin();
2776
2777   return NOTI_EX_ERROR_NONE;
2778 }
2779
2780 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2781     float *max) {
2782   if (handle == nullptr || max == nullptr) {
2783     LOGE("Invalid parameter");
2784     return NOTI_EX_ERROR_INVALID_PARAMETER;
2785   }
2786
2787   Handle *h = static_cast<Handle*>(handle);
2788   if (!h->IsValidType(AbstractItem::Progress)) {
2789     LOGE("Invalid handle type");
2790     return NOTI_EX_ERROR_INVALID_PARAMETER;
2791   }
2792   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2793   *max = p->GetMax();
2794
2795   return NOTI_EX_ERROR_NONE;
2796 }
2797
2798 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2799     int* type) {
2800   if (handle == nullptr || type == nullptr) {
2801     LOGE("Invalid parameter");
2802     return NOTI_EX_ERROR_INVALID_PARAMETER;
2803   }
2804
2805   Handle *h = static_cast<Handle*>(handle);
2806   if (!h->IsValidType(AbstractItem::Progress)) {
2807     LOGE("Invalid handle type");
2808     return NOTI_EX_ERROR_INVALID_PARAMETER;
2809   }
2810   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2811   *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2812
2813   return NOTI_EX_ERROR_NONE;
2814 }
2815
2816 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2817     int type) {
2818   if (handle == nullptr) {
2819     LOGE("Invalid parameter");
2820     return NOTI_EX_ERROR_INVALID_PARAMETER;
2821   }
2822
2823   Handle *h = static_cast<Handle*>(handle);
2824   if (!h->IsValidType(AbstractItem::Progress)) {
2825     LOGE("Invalid handle type");
2826     return NOTI_EX_ERROR_INVALID_PARAMETER;
2827   }
2828   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2829   p->SetProgressType(static_cast<ProgressItem::Type>(type));
2830
2831   return NOTI_EX_ERROR_NONE;
2832 }
2833
2834 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2835     noti_ex_reporter_events_s event_callbacks, void *data) {
2836   if (handle == nullptr) {
2837     LOGE("Invalid parameter");
2838     return NOTI_EX_ERROR_INVALID_PARAMETER;
2839   }
2840
2841   ReporterStub* stub = new (std::nothrow) ReporterStub(
2842       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2843       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2844   if (stub == nullptr) {
2845     LOGE("Fail to create manager");
2846     return NOTI_EX_ERROR_IO_ERROR;
2847   }
2848   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2849       new ReporterCallbackInfo(event_callbacks, data)));
2850
2851   *handle = static_cast<noti_ex_reporter_h>(stub);
2852
2853   return NOTI_EX_ERROR_NONE;
2854 }
2855
2856 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2857   if (handle == nullptr) {
2858     LOGE("Invalid parameter");
2859     return NOTI_EX_ERROR_INVALID_PARAMETER;
2860   }
2861   ReporterStub* stub = static_cast<ReporterStub*>(handle);
2862   delete stub;
2863   return NOTI_EX_ERROR_NONE;
2864 }
2865
2866 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2867     noti_ex_event_info_h info, noti_ex_error_e error) {
2868   if (handle == nullptr || info == nullptr) {
2869     LOGE("Invalid parameter");
2870     return NOTI_EX_ERROR_INVALID_PARAMETER;
2871   }
2872   try {
2873     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2874     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2875     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2876         static_cast<NotificationError>(error));
2877   } catch (Exception &ex) {
2878     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2879     return NOTI_EX_ERROR_IO_ERROR;
2880   }
2881   return NOTI_EX_ERROR_NONE;
2882 }
2883
2884 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2885     noti_ex_item_h noti, int *request_id) {
2886   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2887     LOGE("Invalid parameter");
2888     return NOTI_EX_ERROR_INVALID_PARAMETER;
2889   }
2890   try {
2891     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2892     Handle* h = static_cast<Handle*>(noti);
2893     if (h->GetPtr().get() == nullptr) {
2894       LOGE("Invalid noti reference can not be sended");
2895       return NOTI_EX_ERROR_INVALID_PARAMETER;
2896     } else {
2897       *request_id = stub->Post(h->GetPtr());
2898     }
2899   } catch (Exception &ex) {
2900     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2901     return NOTI_EX_ERROR_IO_ERROR;
2902   }
2903   return NOTI_EX_ERROR_NONE;
2904 }
2905
2906 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2907     noti_ex_item_h *noti_list, int count, int *request_id) {
2908
2909   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2910     LOGE("Invalid parameter");
2911     return NOTI_EX_ERROR_INVALID_PARAMETER;
2912   }
2913   try {
2914     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2915     list<shared_ptr<item::AbstractItem>> notiList;
2916     for (int i = 0; i < count; i++) {
2917       Handle* item = static_cast<Handle*>(noti_list[i]);
2918       notiList.push_back(item->GetPtr());
2919     }
2920     *request_id = stub->Post(notiList);
2921   } catch (Exception &ex) {
2922     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2923     return NOTI_EX_ERROR_IO_ERROR;
2924   }
2925   return NOTI_EX_ERROR_NONE;
2926 }
2927
2928 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2929     noti_ex_item_h noti, int *request_id) {
2930   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2931     LOGE("Invalid parameter");
2932     return NOTI_EX_ERROR_INVALID_PARAMETER;
2933   }
2934   try {
2935     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2936     Handle* item = static_cast<Handle*>(noti);
2937     if (item->GetPtr().get() == nullptr) {
2938       LOGE("Invalid noti reference can not be sended");
2939       return NOTI_EX_ERROR_INVALID_PARAMETER;
2940     } else {
2941       *request_id = stub->Update(item->GetPtr());
2942     }
2943   } catch (Exception &ex) {
2944     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2945     return NOTI_EX_ERROR_IO_ERROR;
2946   }
2947   return NOTI_EX_ERROR_NONE;
2948 }
2949
2950 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2951     noti_ex_item_h noti, int *request_id) {
2952   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2953     LOGE("Invalid parameter");
2954     return NOTI_EX_ERROR_INVALID_PARAMETER;
2955   }
2956   try {
2957     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2958     Handle* item = static_cast<Handle*>(noti);
2959     if (item->GetPtr().get() == nullptr) {
2960       LOGE("Invalid noti reference can not be sended");
2961       return NOTI_EX_ERROR_INVALID_PARAMETER;
2962     } else {
2963       *request_id = stub->Delete(item->GetPtr());
2964     }
2965   } catch (Exception &ex) {
2966     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2967     return NOTI_EX_ERROR_IO_ERROR;
2968   }
2969   return NOTI_EX_ERROR_NONE;
2970 }
2971
2972 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2973     noti_ex_reporter_h handle, int *request_id) {
2974   if (handle == nullptr || request_id == nullptr) {
2975     LOGE("Invalid parameter");
2976     return NOTI_EX_ERROR_INVALID_PARAMETER;
2977   }
2978   try {
2979     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2980     *request_id = stub->DeleteAll();
2981   } catch (Exception &ex) {
2982     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2983     return NOTI_EX_ERROR_IO_ERROR;
2984   }
2985   return NOTI_EX_ERROR_NONE;
2986 }
2987
2988 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2989     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2990   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2991     LOGE("Invalid parameter");
2992     return NOTI_EX_ERROR_INVALID_PARAMETER;
2993   }
2994   try {
2995     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2996     *item = new Handle(stub->FindByRootID(root_id));
2997   } catch (Exception &ex) {
2998     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2999     return NOTI_EX_ERROR_IO_ERROR;
3000   }
3001   return NOTI_EX_ERROR_NONE;
3002 }
3003
3004 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3005     const char *id, const char *text, const char *hyperlink) {
3006   if (handle == nullptr || text == nullptr) {
3007     LOGE("Invalid parameter");
3008     return NOTI_EX_ERROR_INVALID_PARAMETER;
3009   }
3010
3011   TextItem* p;
3012
3013   if (hyperlink)
3014     p = new (std::nothrow) TextItem(id, std::string(text),
3015                 std::string(hyperlink));
3016   else
3017     p = new (std::nothrow) TextItem(id, std::string(text));
3018
3019   if (p == nullptr) {
3020     LOGE("Out-of-memory");
3021     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3022   }
3023
3024   *handle = new Handle(shared_ptr<AbstractItem>(p));
3025
3026   return NOTI_EX_ERROR_NONE;
3027 }
3028
3029 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3030     const char *contents) {
3031   if (handle == nullptr || contents == nullptr) {
3032     LOGE("Invalid parameter");
3033     return NOTI_EX_ERROR_INVALID_PARAMETER;
3034   }
3035
3036   Handle* p = static_cast<Handle*>(handle);
3037   if (!p->IsValidType(AbstractItem::Text)) {
3038     LOGE("Invalid handle type");
3039     return NOTI_EX_ERROR_INVALID_PARAMETER;
3040   }
3041   TextItem* ti = static_cast<TextItem*>(p->Get());
3042   ti->SetContents(std::string(contents));
3043
3044   return NOTI_EX_ERROR_NONE;
3045 }
3046
3047 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3048     char **contents) {
3049   if (handle == nullptr || contents == nullptr) {
3050     LOGE("Invalid parameter");
3051     return NOTI_EX_ERROR_INVALID_PARAMETER;
3052   }
3053
3054   Handle* p = static_cast<Handle*>(handle);
3055   if (!p->IsValidType(AbstractItem::Text)) {
3056     LOGE("Invalid handle type");
3057     return NOTI_EX_ERROR_INVALID_PARAMETER;
3058   }
3059
3060   TextItem* ti = static_cast<TextItem*>(p->Get());
3061   string str;
3062   if (ti->GetMultiLanguage() != nullptr &&
3063       !ti->GetMultiLanguage()->GetTranslatedString().empty())
3064     str = ti->GetMultiLanguage()->GetTranslatedString();
3065   else if (!ti->GetContents().empty())
3066     str = ti->GetContents();
3067
3068   *contents = strdup(str.c_str());
3069   if (*contents == nullptr) {
3070     LOGE("Out-of-memory");
3071     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3072   }
3073
3074   return NOTI_EX_ERROR_NONE;
3075 }
3076
3077 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3078     noti_ex_item_h handle, char **hyper_link) {
3079   if (handle == nullptr || hyper_link == nullptr) {
3080     LOGE("Invalid parameter");
3081     return NOTI_EX_ERROR_INVALID_PARAMETER;
3082   }
3083
3084   Handle* p = static_cast<Handle*>(handle);
3085   if (!p->IsValidType(AbstractItem::Text)) {
3086     LOGE("Invalid handle type");
3087     return NOTI_EX_ERROR_INVALID_PARAMETER;
3088   }
3089   TextItem* ti = static_cast<TextItem*>(p->Get());
3090   if (!ti->GetHyperLink().empty()) {
3091     *hyper_link = strdup(ti->GetHyperLink().c_str());
3092     if (*hyper_link == nullptr) {
3093       LOGE("Out-of-memory");
3094       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3095     }
3096   }
3097
3098   return NOTI_EX_ERROR_NONE;
3099 }
3100
3101 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3102     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3103   if (handle == nullptr) {
3104     LOGE("Invalid parameter");
3105     return NOTI_EX_ERROR_INVALID_PARAMETER;
3106   }
3107
3108   Handle* p = static_cast<Handle*>(handle);
3109   if (!p->IsValidType(AbstractItem::Text)) {
3110     LOGE("Invalid handle type");
3111     return NOTI_EX_ERROR_INVALID_PARAMETER;
3112   }
3113
3114   TextItem* ti = static_cast<TextItem*>(p->Get());
3115   if (multi == nullptr) {
3116     ti->SetMultiLanguage(nullptr);
3117     return NOTI_EX_ERROR_NONE;
3118   }
3119
3120   shared_ptr<MultiLanguage> mul_ptr =
3121       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3122   ti->SetMultiLanguage(mul_ptr);
3123   ti->GetMultiLanguage()->UpdateString();
3124
3125   return NOTI_EX_ERROR_NONE;
3126 }
3127
3128 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3129     const char *id, time_t time) {
3130   TimeItem* p;
3131
3132   if (handle == nullptr) {
3133     LOGE("Invalid parameter");
3134     return NOTI_EX_ERROR_INVALID_PARAMETER;
3135   }
3136
3137   if (time) {
3138     if (id)
3139       p = new (std::nothrow) TimeItem(id, time);
3140     else
3141       p = new (std::nothrow) TimeItem(time);
3142   } else {
3143       p = new (std::nothrow) TimeItem();
3144   }
3145
3146   if (p == nullptr) {
3147     LOGE("Out-of-memory");
3148     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3149   }
3150
3151   *handle = new Handle(shared_ptr<AbstractItem>(p));
3152
3153   return NOTI_EX_ERROR_NONE;
3154 }
3155
3156 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3157     time_t *time) {
3158   if (handle == nullptr || time == nullptr) {
3159     LOGE("Invalid parameter");
3160     return NOTI_EX_ERROR_INVALID_PARAMETER;
3161   }
3162   Handle* h = static_cast<Handle*>(handle);
3163   if (!h->IsValidType(AbstractItem::Time)) {
3164     LOGE("Invalid handle type");
3165     return NOTI_EX_ERROR_INVALID_PARAMETER;
3166   }
3167   TimeItem* p = static_cast<TimeItem*>(h->Get());
3168   *time = p->GetTime();
3169
3170   return NOTI_EX_ERROR_NONE;
3171 }
3172
3173 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3174     time_t time) {
3175   if (handle == nullptr) {
3176     LOGE("Invalid parameter");
3177     return NOTI_EX_ERROR_INVALID_PARAMETER;
3178   }
3179   Handle* h = static_cast<Handle*>(handle);
3180   if (!h->IsValidType(AbstractItem::Time)) {
3181     LOGE("Invalid handle type");
3182     return NOTI_EX_ERROR_INVALID_PARAMETER;
3183   }
3184   TimeItem* p = static_cast<TimeItem*>(h->Get());
3185   p->SetTime(time);
3186
3187   return NOTI_EX_ERROR_NONE;
3188 }
3189
3190 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3191     noti_ex_action_h *handle, const char *extra) {
3192   if (handle == nullptr) {
3193     LOGE("Invalid parameter");
3194     return NOTI_EX_ERROR_INVALID_PARAMETER;
3195   }
3196
3197   string extra_str = "";
3198   if (extra != NULL)
3199     extra_str = string(extra);
3200
3201   shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3202       new (std::nothrow) VisibilityAction(extra_str));
3203   if (ptr == nullptr) {
3204     LOGE("Out-of-memory");
3205     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3206   }
3207
3208   *handle = ptr;
3209
3210   return NOTI_EX_ERROR_NONE;
3211 }
3212
3213 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3214     const char *id, bool visible) {
3215   if (handle == nullptr || id == nullptr) {
3216     LOGE("Invalid parameter");
3217     return NOTI_EX_ERROR_INVALID_PARAMETER;
3218   }
3219
3220   shared_ptr<AbstractAction>* ptr =
3221       static_cast<shared_ptr<AbstractAction>*>(handle);
3222   VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3223   action->SetVisibility(id, visible);
3224
3225   return NOTI_EX_ERROR_NONE;
3226 }
3227
3228 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3229     const char* msgid, const char* format, ...) {
3230   if (handle == nullptr || msgid == nullptr || format == nullptr) {
3231     LOGE("Invalid parameter");
3232     return NOTI_EX_ERROR_INVALID_PARAMETER;
3233   }
3234
3235   const char* format_idx = format;
3236   vector<string> arr;
3237   va_list args;
3238   va_start(args, format);
3239   while (*format_idx != '\0') {
3240     char* arg = nullptr;
3241     int arg_i;
3242     double arg_f;
3243     stringstream stream;
3244     if (*format_idx == '%') {
3245       switch (*(format_idx + 1)) {
3246         case 's':
3247           arg = va_arg(args, char *);
3248           arr.push_back(string(arg));
3249           break;
3250         case 'd':
3251           arg_i = va_arg(args, int);
3252           arr.push_back(to_string(arg_i));
3253           break;
3254         case 'f':
3255           arg_f = va_arg(args, double);
3256           stream << std::fixed << std::setprecision(2) << arg_f;
3257           arr.push_back(stream.str());
3258           break;
3259       }
3260     }
3261     format_idx++;
3262   }
3263   va_end(args);
3264
3265   MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3266   if (p == nullptr) {
3267     LOGE("Out-of-memory");
3268     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3269   }
3270   *handle = new shared_ptr<MultiLanguage>(p);
3271
3272   return NOTI_EX_ERROR_NONE;
3273 }
3274
3275 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3276   if (handle == nullptr) {
3277     LOGE("Invalid parameter");
3278     return NOTI_EX_ERROR_INVALID_PARAMETER;
3279   }
3280
3281   shared_ptr<MultiLanguage>* mul_ptr =
3282       reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3283   delete mul_ptr;
3284   return NOTI_EX_ERROR_NONE;
3285 }
3286
3287 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3288     noti_ex_item_h item, int64_t* private_id) {
3289   if (item == nullptr || private_id == nullptr) {
3290     LOGE("Invalid parameter");
3291     return NOTI_EX_ERROR_INVALID_PARAMETER;
3292   }
3293
3294   Handle* h = static_cast<Handle*>(item);
3295   *private_id = static_pointer_cast<IItemInfoInternal>(
3296       h->Get()->GetInfo())->GetPrivateId();
3297
3298   return NOTI_EX_ERROR_NONE;
3299 }
3300
3301 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3302     noti_ex_item_h item, int64_t priv_id) {
3303   if (item == nullptr) {
3304     LOGE("Invalid parameter");
3305     return NOTI_EX_ERROR_INVALID_PARAMETER;
3306   }
3307
3308   Handle* h = static_cast<Handle*>(item);
3309   static_pointer_cast<IItemInfoInternal>(
3310       h->Get()->GetInfo())->SetPrivateId(priv_id);
3311
3312   return NOTI_EX_ERROR_NONE;
3313 }
3314
3315 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3316   if (list == nullptr) {
3317     LOGE("Invalid parameter");
3318     return NOTI_EX_ERROR_INVALID_PARAMETER;
3319   }
3320
3321   LOGI("Free strings (%d)", count);
3322   for (int i = 0; i < count; i++)
3323     free(list[i]);
3324   free(list);
3325
3326   return NOTI_EX_ERROR_NONE;
3327 }
3328
3329 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3330   if (handle == nullptr) {
3331     LOGE("Invalid parameter");
3332     return NOTI_EX_ERROR_INVALID_PARAMETER;
3333   }
3334   Handle* h = static_cast<Handle*>(handle);
3335   if (!h->IsValidType(AbstractItem::Group)) {
3336     LOGE("Invalid handle type");
3337     return NOTI_EX_ERROR_INVALID_PARAMETER;
3338   }
3339   GroupItem* p = static_cast<GroupItem*>(h->Get());
3340   p->RemoveChildren();
3341
3342   return NOTI_EX_ERROR_NONE;
3343 }