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