Fix the behavior of input_selector_get_contents
[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(noti_ex_item_h handle,
799     noti_ex_item_group_foreach_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_path(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_set_sender_app_id(noti_ex_item_h handle,
1903     const char *id) {
1904   if (handle == nullptr) {
1905     LOGE("Invalid parameter");
1906     return NOTI_EX_ERROR_INVALID_PARAMETER;
1907   }
1908
1909   Handle* p = static_cast<Handle*>(handle);
1910   if (id == nullptr)
1911     p->Get()->SetSenderAppId("");
1912   else
1913     p->Get()->SetSenderAppId(id);
1914   return NOTI_EX_ERROR_NONE;
1915 }
1916
1917 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1918     char **tag) {
1919   if (handle == nullptr || tag == nullptr) {
1920     LOGE("Invalid parameter");
1921     return NOTI_EX_ERROR_INVALID_PARAMETER;
1922   }
1923
1924   Handle* p = static_cast<Handle*>(handle);
1925   if (p->Get()->GetTag().empty())
1926     *tag = nullptr;
1927   else
1928     *tag = strdup(p->Get()->GetTag().c_str());
1929   return NOTI_EX_ERROR_NONE;
1930 }
1931
1932 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1933     const char *tag) {
1934   if (handle == nullptr) {
1935     LOGE("Invalid parameter");
1936     return NOTI_EX_ERROR_INVALID_PARAMETER;
1937   }
1938
1939   Handle* p = static_cast<Handle*>(handle);
1940   if (tag == nullptr)
1941     p->Get()->SetTag("");
1942   else
1943     p->Get()->SetTag(tag);
1944   return NOTI_EX_ERROR_NONE;
1945 }
1946
1947 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1948     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1949     void *data) {
1950   if (handle == nullptr) {
1951     LOGE("Invalid parameter");
1952     return NOTI_EX_ERROR_INVALID_PARAMETER;
1953   }
1954
1955   string receiver_group_str = "";
1956   if (receiver_group)
1957     receiver_group_str = string(receiver_group);
1958
1959   ManagerStub* stub = new (std::nothrow) ManagerStub(
1960       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1961       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1962       receiver_group_str);
1963   if (stub == nullptr) {
1964     LOGE("Fail to create manager");
1965     return NOTI_EX_ERROR_IO_ERROR;
1966   }
1967   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1968       new ManagerCallbackInfo(event_callbacks, data)));
1969   *handle = static_cast<noti_ex_manager_h>(stub);
1970
1971   return NOTI_EX_ERROR_NONE;
1972 }
1973
1974 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1975   if (handle == nullptr) {
1976     LOGE("Invalid parameter");
1977     return NOTI_EX_ERROR_INVALID_PARAMETER;
1978   }
1979   ManagerStub* stub = static_cast<ManagerStub*>(handle);
1980   delete stub;
1981   return NOTI_EX_ERROR_NONE;
1982 }
1983
1984 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1985     noti_ex_item_h **items, int *count) {
1986   if (handle == nullptr || items == nullptr || count == nullptr) {
1987     LOGE("Invalid parameter");
1988     return NOTI_EX_ERROR_INVALID_PARAMETER;
1989   }
1990
1991   try {
1992     ManagerStub* stub = static_cast<ManagerStub*>(handle);
1993     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1994     if (item_list.size() == 0) {
1995       *items = nullptr;
1996       *count = 0;
1997       return NOTI_EX_ERROR_NONE;
1998     }
1999     *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2000     if (*items == nullptr) {
2001       LOGE("Fail to create items");
2002       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2003     }
2004
2005     int idx = 0;
2006     for (auto& i : item_list) {
2007       *items[idx++] = new Handle(move(i));
2008     }
2009     *count = item_list.size();
2010   } catch (Exception &ex) {
2011     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2012     return NOTI_EX_ERROR_IO_ERROR;
2013   }
2014   return NOTI_EX_ERROR_NONE;
2015 }
2016
2017 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2018     noti_ex_item_h noti, int *request_id) {
2019   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2020     LOGE("Invalid parameter");
2021     return NOTI_EX_ERROR_INVALID_PARAMETER;
2022   }
2023   try {
2024     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2025     Handle* sp = static_cast<Handle*>(noti);
2026     if (sp->GetPtr().get() == nullptr) {
2027       LOGE("Invalid noti reference can not be sended");
2028       return NOTI_EX_ERROR_INVALID_PARAMETER;
2029     } else {
2030       *request_id = stub->Update(sp->GetPtr());
2031     }
2032   } catch (Exception &ex) {
2033     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2034     return NOTI_EX_ERROR_IO_ERROR;
2035   }
2036   return NOTI_EX_ERROR_NONE;
2037 }
2038
2039 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2040     noti_ex_item_h noti, int *request_id) {
2041   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2042     LOGE("Invalid parameter");
2043     return NOTI_EX_ERROR_INVALID_PARAMETER;
2044   }
2045   try {
2046     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2047     Handle* item = static_cast<Handle*>(noti);
2048     if (item->GetPtr().get() == nullptr) {
2049       LOGE("Invalid noti reference can not be sended");
2050       return NOTI_EX_ERROR_INVALID_PARAMETER;
2051     } else {
2052       *request_id = stub->Delete(item->GetPtr());
2053     }
2054   } catch (Exception &ex) {
2055     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2056     return NOTI_EX_ERROR_IO_ERROR;
2057   }
2058   return NOTI_EX_ERROR_NONE;
2059 }
2060
2061 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2062     int *request_id) {
2063   if (handle == nullptr || request_id == nullptr) {
2064     LOGE("Invalid parameter");
2065     return NOTI_EX_ERROR_INVALID_PARAMETER;
2066   }
2067   try {
2068     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2069     *request_id = stub->DeleteAll();
2070   } catch (Exception &ex) {
2071     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2072     return NOTI_EX_ERROR_IO_ERROR;
2073   }
2074   return NOTI_EX_ERROR_NONE;
2075 }
2076
2077 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2078     noti_ex_item_h noti, int *request_id) {
2079   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2080     LOGE("Invalid parameter");
2081     return NOTI_EX_ERROR_INVALID_PARAMETER;
2082   }
2083   try {
2084     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2085     Handle* item = static_cast<Handle*>(noti);
2086     if (item->GetPtr().get() == nullptr) {
2087       LOGE("Invalid noti reference can not be sended");
2088       return NOTI_EX_ERROR_INVALID_PARAMETER;
2089     } else {
2090       *request_id = stub->Hide(item->GetPtr());
2091     }
2092   } catch (Exception &ex) {
2093     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2094     return NOTI_EX_ERROR_IO_ERROR;
2095   }
2096   return NOTI_EX_ERROR_NONE;
2097 }
2098
2099 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2100     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2101   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2102     LOGE("Invalid parameter");
2103     return NOTI_EX_ERROR_INVALID_PARAMETER;
2104   }
2105   try {
2106     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2107     *item = new Handle(stub->FindByRootID(root_id));
2108   } catch (Exception &ex) {
2109     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2110     return NOTI_EX_ERROR_IO_ERROR;
2111   }
2112   return NOTI_EX_ERROR_NONE;
2113 }
2114
2115 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2116     noti_ex_event_info_h info, noti_ex_error_e error) {
2117   if (handle == nullptr || info == nullptr) {
2118     LOGE("Invalid parameter");
2119     return NOTI_EX_ERROR_INVALID_PARAMETER;
2120   }
2121   try {
2122     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2123     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2124     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2125         static_cast<NotificationError>(error));
2126   } catch (Exception &ex) {
2127     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2128     return NOTI_EX_ERROR_IO_ERROR;
2129   }
2130   return NOTI_EX_ERROR_NONE;
2131 }
2132
2133 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2134     int *cnt) {
2135
2136   if (handle == nullptr || cnt == nullptr) {
2137     LOGE("Invalid parameter");
2138     return NOTI_EX_ERROR_INVALID_PARAMETER;
2139   }
2140   try {
2141     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2142     *cnt = stub->GetCount();
2143   } catch (Exception &ex) {
2144     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2145     return NOTI_EX_ERROR_IO_ERROR;
2146   }
2147   return NOTI_EX_ERROR_NONE;
2148 }
2149
2150 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2151     const char *id, float min, float current, float max) {
2152   ProgressItem* p;
2153
2154   if (handle == nullptr) {
2155     LOGE("Invalid parameter");
2156     return NOTI_EX_ERROR_INVALID_PARAMETER;
2157   }
2158
2159   if (id)
2160     p = new (std::nothrow) ProgressItem(id, min, current, max);
2161   else
2162     p = new (std::nothrow) ProgressItem(min, current, max);
2163
2164   if (p == nullptr) {
2165     LOGE("Out-of-memory");
2166     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2167   }
2168
2169   *handle = new Handle(p);
2170
2171   return NOTI_EX_ERROR_NONE;
2172 }
2173
2174 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2175     noti_ex_item_h handle, float *current) {
2176   if (handle == nullptr || current == nullptr) {
2177     LOGE("Invalid parameter");
2178     return NOTI_EX_ERROR_INVALID_PARAMETER;
2179   }
2180
2181   Handle *h = static_cast<Handle*>(handle);
2182   if (!h->IsValidType(AbstractItem::Progress)) {
2183     LOGE("Invalid handle type");
2184     return NOTI_EX_ERROR_INVALID_PARAMETER;
2185   }
2186   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2187   *current = p->GetCurrent();
2188
2189   return NOTI_EX_ERROR_NONE;
2190 }
2191
2192 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2193     noti_ex_item_h handle, float current) {
2194   if (handle == nullptr) {
2195     LOGE("Invalid parameter");
2196     return NOTI_EX_ERROR_INVALID_PARAMETER;
2197   }
2198
2199   Handle *h = static_cast<Handle*>(handle);
2200   if (!h->IsValidType(AbstractItem::Progress)) {
2201     LOGE("Invalid handle type");
2202     return NOTI_EX_ERROR_INVALID_PARAMETER;
2203   }
2204   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2205   p->SetCurrent(current);
2206
2207   return NOTI_EX_ERROR_NONE;
2208 }
2209
2210 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2211     float *min) {
2212   if (handle == nullptr || min == nullptr) {
2213     LOGE("Invalid parameter");
2214     return NOTI_EX_ERROR_INVALID_PARAMETER;
2215   }
2216
2217   Handle *h = static_cast<Handle*>(handle);
2218   if (!h->IsValidType(AbstractItem::Progress)) {
2219     LOGE("Invalid handle type");
2220     return NOTI_EX_ERROR_INVALID_PARAMETER;
2221   }
2222   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2223   *min = p->GetMin();
2224
2225   return NOTI_EX_ERROR_NONE;
2226 }
2227
2228 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2229     float *max) {
2230   if (handle == nullptr || max == nullptr) {
2231     LOGE("Invalid parameter");
2232     return NOTI_EX_ERROR_INVALID_PARAMETER;
2233   }
2234
2235   Handle *h = static_cast<Handle*>(handle);
2236   if (!h->IsValidType(AbstractItem::Progress)) {
2237     LOGE("Invalid handle type");
2238     return NOTI_EX_ERROR_INVALID_PARAMETER;
2239   }
2240   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2241   *max = p->GetMax();
2242
2243   return NOTI_EX_ERROR_NONE;
2244 }
2245
2246 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2247     noti_ex_reporter_events_s event_callbacks, void *data) {
2248   if (handle == nullptr) {
2249     LOGE("Invalid parameter");
2250     return NOTI_EX_ERROR_INVALID_PARAMETER;
2251   }
2252
2253   ReporterStub* stub = new (std::nothrow) ReporterStub(
2254       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2255       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2256   if (stub == nullptr) {
2257     LOGE("Fail to create manager");
2258     return NOTI_EX_ERROR_IO_ERROR;
2259   }
2260   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2261       new ReporterCallbackInfo(event_callbacks, data)));
2262
2263   *handle = static_cast<noti_ex_reporter_h>(stub);
2264
2265   return NOTI_EX_ERROR_NONE;
2266 }
2267
2268 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2269   if (handle == nullptr) {
2270     LOGE("Invalid parameter");
2271     return NOTI_EX_ERROR_INVALID_PARAMETER;
2272   }
2273   ReporterStub* stub = static_cast<ReporterStub*>(handle);
2274   delete stub;
2275   return NOTI_EX_ERROR_NONE;
2276 }
2277
2278 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2279     noti_ex_event_info_h info, noti_ex_error_e error) {
2280   if (handle == nullptr || info == nullptr) {
2281     LOGE("Invalid parameter");
2282     return NOTI_EX_ERROR_INVALID_PARAMETER;
2283   }
2284   try {
2285     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2286     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2287     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2288         static_cast<NotificationError>(error));
2289   } catch (Exception &ex) {
2290     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2291     return NOTI_EX_ERROR_IO_ERROR;
2292   }
2293   return NOTI_EX_ERROR_NONE;
2294 }
2295
2296 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2297     noti_ex_item_h noti, int *request_id) {
2298   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2299     LOGE("Invalid parameter");
2300     return NOTI_EX_ERROR_INVALID_PARAMETER;
2301   }
2302   try {
2303     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2304     Handle* h = static_cast<Handle*>(noti);
2305     if (h->GetPtr().get() == nullptr) {
2306       LOGE("Invalid noti reference can not be sended");
2307       return NOTI_EX_ERROR_INVALID_PARAMETER;
2308     } else {
2309       *request_id = stub->Post(h->GetPtr());
2310     }
2311   } catch (Exception &ex) {
2312     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2313     return NOTI_EX_ERROR_IO_ERROR;
2314   }
2315   return NOTI_EX_ERROR_NONE;
2316 }
2317
2318 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2319     noti_ex_item_h *noti_list, int count, int *request_id) {
2320
2321   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2322     LOGE("Invalid parameter");
2323     return NOTI_EX_ERROR_INVALID_PARAMETER;
2324   }
2325   try {
2326     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2327     list<shared_ptr<item::AbstractItem>> notiList;
2328     for (int i = 0; i < count; i++) {
2329       Handle* item = static_cast<Handle*>(noti_list[i]);
2330       notiList.push_back(item->GetPtr());
2331     }
2332     *request_id = stub->Post(notiList);
2333   } catch (Exception &ex) {
2334     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2335     return NOTI_EX_ERROR_IO_ERROR;
2336   }
2337   return NOTI_EX_ERROR_NONE;
2338 }
2339
2340 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2341     noti_ex_item_h noti, int *request_id) {
2342   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2343     LOGE("Invalid parameter");
2344     return NOTI_EX_ERROR_INVALID_PARAMETER;
2345   }
2346   try {
2347     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2348     Handle* item = static_cast<Handle*>(noti);
2349     if (item->GetPtr().get() == nullptr) {
2350       LOGE("Invalid noti reference can not be sended");
2351       return NOTI_EX_ERROR_INVALID_PARAMETER;
2352     } else {
2353       *request_id = stub->Update(item->GetPtr());
2354     }
2355   } catch (Exception &ex) {
2356     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2357     return NOTI_EX_ERROR_IO_ERROR;
2358   }
2359   return NOTI_EX_ERROR_NONE;
2360 }
2361
2362 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2363     noti_ex_item_h noti, int *request_id) {
2364   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2365     LOGE("Invalid parameter");
2366     return NOTI_EX_ERROR_INVALID_PARAMETER;
2367   }
2368   try {
2369     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2370     Handle* item = static_cast<Handle*>(noti);
2371     if (item->GetPtr().get() == nullptr) {
2372       LOGE("Invalid noti reference can not be sended");
2373       return NOTI_EX_ERROR_INVALID_PARAMETER;
2374     } else {
2375       *request_id = stub->Delete(item->GetPtr());
2376     }
2377   } catch (Exception &ex) {
2378     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2379     return NOTI_EX_ERROR_IO_ERROR;
2380   }
2381   return NOTI_EX_ERROR_NONE;
2382 }
2383
2384 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2385     noti_ex_reporter_h handle, int *request_id) {
2386   if (handle == nullptr || request_id == nullptr) {
2387     LOGE("Invalid parameter");
2388     return NOTI_EX_ERROR_INVALID_PARAMETER;
2389   }
2390   try {
2391     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2392     *request_id = stub->DeleteAll();
2393   } catch (Exception &ex) {
2394     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2395     return NOTI_EX_ERROR_IO_ERROR;
2396   }
2397   return NOTI_EX_ERROR_NONE;
2398 }
2399
2400 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2401     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2402   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2403     LOGE("Invalid parameter");
2404     return NOTI_EX_ERROR_INVALID_PARAMETER;
2405   }
2406   try {
2407     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2408     *item = new Handle(stub->FindByRootID(root_id));
2409   } catch (Exception &ex) {
2410     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2411     return NOTI_EX_ERROR_IO_ERROR;
2412   }
2413   return NOTI_EX_ERROR_NONE;
2414 }
2415
2416 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2417     const char *id, const char *text, const char *hyper_link) {
2418   if (handle == nullptr) {
2419     LOGE("Invalid parameter");
2420     return NOTI_EX_ERROR_INVALID_PARAMETER;
2421   }
2422
2423   auto* p = new (std::nothrow) TextItem(id, std::string(text),
2424                 std::string(hyper_link));
2425   if (p == nullptr) {
2426     LOGE("Out-of-memory");
2427     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2428   }
2429
2430   *handle = new Handle(p);
2431
2432   return NOTI_EX_ERROR_NONE;
2433 }
2434
2435 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2436     const char *contents) {
2437   if (handle == nullptr) {
2438     LOGE("Invalid parameter");
2439     return NOTI_EX_ERROR_INVALID_PARAMETER;
2440   }
2441
2442   Handle* p = static_cast<Handle*>(handle);
2443   if (!p->IsValidType(AbstractItem::Text)) {
2444     LOGE("Invalid handle type");
2445     return NOTI_EX_ERROR_INVALID_PARAMETER;
2446   }
2447   TextItem* ti = static_cast<TextItem*>(p->Get());
2448   ti->SetContents(std::string(contents));
2449
2450   return NOTI_EX_ERROR_NONE;
2451 }
2452
2453 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2454     char **contents) {
2455   if (handle == nullptr || contents == nullptr) {
2456     LOGE("Invalid parameter");
2457     return NOTI_EX_ERROR_INVALID_PARAMETER;
2458   }
2459
2460   Handle* p = static_cast<Handle*>(handle);
2461   if (!p->IsValidType(AbstractItem::Text)) {
2462     LOGE("Invalid handle type");
2463     return NOTI_EX_ERROR_INVALID_PARAMETER;
2464   }
2465   TextItem* ti = static_cast<TextItem*>(p->Get());
2466   if (!ti->GetContents().empty()) {
2467     *contents = strdup(ti->GetContents().c_str());
2468     if (*contents == nullptr) {
2469       LOGE("Out-of-memory");
2470       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2471     }
2472   }
2473
2474   return NOTI_EX_ERROR_NONE;
2475 }
2476
2477 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2478     noti_ex_item_h handle, char **hyper_link) {
2479   if (handle == nullptr || hyper_link == nullptr) {
2480     LOGE("Invalid parameter");
2481     return NOTI_EX_ERROR_INVALID_PARAMETER;
2482   }
2483
2484   Handle* p = static_cast<Handle*>(handle);
2485   if (!p->IsValidType(AbstractItem::Text)) {
2486     LOGE("Invalid handle type");
2487     return NOTI_EX_ERROR_INVALID_PARAMETER;
2488   }
2489   TextItem* ti = static_cast<TextItem*>(p->Get());
2490   if (!ti->GetHyperLink().empty()) {
2491     *hyper_link = strdup(ti->GetHyperLink().c_str());
2492     if (*hyper_link == nullptr) {
2493       LOGE("Out-of-memory");
2494       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2495     }
2496   }
2497
2498   return NOTI_EX_ERROR_NONE;
2499 }
2500
2501 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2502     const char *id, time_t time) {
2503   TimeItem* p;
2504
2505   if (handle == nullptr) {
2506     LOGE("Invalid parameter");
2507     return NOTI_EX_ERROR_INVALID_PARAMETER;
2508   }
2509
2510   if (time) {
2511     if (id)
2512       p = new (std::nothrow) TimeItem(id, time);
2513     else
2514       p = new (std::nothrow) TimeItem(time);
2515   } else {
2516       p = new (std::nothrow) TimeItem();
2517   }
2518
2519   if (p == nullptr) {
2520     LOGE("Out-of-memory");
2521     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2522   }
2523
2524   *handle = new Handle(p);
2525
2526   return NOTI_EX_ERROR_NONE;
2527 }
2528
2529 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2530     time_t *time) {
2531   if (handle == nullptr || time == nullptr) {
2532     LOGE("Invalid parameter");
2533     return NOTI_EX_ERROR_INVALID_PARAMETER;
2534   }
2535   Handle* h = static_cast<Handle*>(handle);
2536   if (!h->IsValidType(AbstractItem::Time)) {
2537     LOGE("Invalid handle type");
2538     return NOTI_EX_ERROR_INVALID_PARAMETER;
2539   }
2540   TimeItem* p = static_cast<TimeItem*>(h->Get());
2541   *time = p->GetTime();
2542
2543   return NOTI_EX_ERROR_NONE;
2544 }
2545
2546 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2547     noti_ex_action_h *handle, const char *extra) {
2548   if (handle == nullptr) {
2549     LOGE("Invalid parameter");
2550     return NOTI_EX_ERROR_INVALID_PARAMETER;
2551   }
2552
2553   string extra_str = "";
2554   if (extra != NULL)
2555     extra_str = string(extra);
2556
2557   auto* p = new (std::nothrow) VisibilityAction(extra_str);
2558   if (p == nullptr) {
2559     LOGE("Out-of-memory");
2560     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2561   }
2562
2563   *handle = p;
2564
2565   return NOTI_EX_ERROR_NONE;
2566 }
2567
2568 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2569     const char *id, bool visible) {
2570   if (handle == nullptr || id == nullptr) {
2571     LOGE("Invalid parameter");
2572     return NOTI_EX_ERROR_INVALID_PARAMETER;
2573   }
2574
2575   VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2576   p->SetVisibility(id, visible);
2577
2578   return NOTI_EX_ERROR_NONE;
2579 }