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