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