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