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