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