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