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