Fix create string with NULL crash
[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   *contents_list = (char**)calloc(contents.size(), sizeof(char*));
911   int idx = 0;
912   for (auto& i : contents) {
913     *contents_list[idx++] = strdup(i.c_str());
914   }
915   *count = contents.size();
916
917   return NOTI_EX_ERROR_NONE;
918 }
919
920 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
921     noti_ex_item_h handle, const char **contents, int count) {
922   if (handle == nullptr || contents == nullptr) {
923     LOGE("Invalid parameter");
924     return NOTI_EX_ERROR_INVALID_PARAMETER;
925   }
926
927   list<string> new_contents;
928   Handle* h = static_cast<Handle*>(handle);
929   if (!h->IsValidType(AbstractItem::InputSelector)) {
930     LOGE("Invalid handle type");
931     return NOTI_EX_ERROR_INVALID_PARAMETER;
932   }
933   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
934   for (int i = 0; i < count; i++) {
935     new_contents.push_back(contents[i]);
936   }
937   p->SetContents(move(new_contents));
938
939   return NOTI_EX_ERROR_NONE;
940 }
941
942 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
943     unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
944   if (handle == nullptr) {
945     LOGE("Invalid parameter");
946     return NOTI_EX_ERROR_INVALID_PARAMETER;
947   }
948
949   auto* p = new (std::nothrow) Color(a, r, g, b);
950   if (p == nullptr) {
951     LOGE("Out-of-memory");
952     return NOTI_EX_ERROR_OUT_OF_MEMORY;
953   }
954
955   *handle = p;
956
957   return NOTI_EX_ERROR_NONE;
958 }
959
960 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
961   if (handle == nullptr) {
962     LOGE("Invalid parameter");
963     return NOTI_EX_ERROR_INVALID_PARAMETER;
964   }
965
966   Color* p = static_cast<Color*>(handle);
967   p->~Color();
968
969   return NOTI_EX_ERROR_NONE;
970 }
971
972 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
973     unsigned char *val) {
974   if (handle == nullptr || val == nullptr) {
975     LOGE("Invalid parameter");
976     return NOTI_EX_ERROR_INVALID_PARAMETER;
977   }
978
979   Color* p = static_cast<Color*>(handle);
980   *val = p->GetAVal();
981
982   return NOTI_EX_ERROR_NONE;
983 }
984
985 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
986     unsigned char *val) {
987   if (handle == nullptr || val == nullptr) {
988     LOGE("Invalid parameter");
989     return NOTI_EX_ERROR_INVALID_PARAMETER;
990   }
991
992   Color* p = static_cast<Color*>(handle);
993   *val = p->GetRVal();
994
995   return NOTI_EX_ERROR_NONE;
996 }
997
998 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
999     unsigned char *val) {
1000   if (handle == nullptr || val == nullptr) {
1001     LOGE("Invalid parameter");
1002     return NOTI_EX_ERROR_INVALID_PARAMETER;
1003   }
1004
1005   Color* p = static_cast<Color*>(handle);
1006   *val = p->GetGVal();
1007
1008   return NOTI_EX_ERROR_NONE;
1009 }
1010
1011 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1012     unsigned char *val) {
1013   if (handle == nullptr || val == nullptr) {
1014     LOGE("Invalid parameter");
1015     return NOTI_EX_ERROR_INVALID_PARAMETER;
1016   }
1017
1018   Color* p = static_cast<Color*>(handle);
1019   *val = p->GetBVal();
1020
1021   return NOTI_EX_ERROR_NONE;
1022 }
1023
1024 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1025     int left, int top, int right, int bottom) {
1026   if (handle == nullptr) {
1027     LOGE("Invalid parameter");
1028     return NOTI_EX_ERROR_INVALID_PARAMETER;
1029   }
1030
1031   auto* p = new (std::nothrow) Padding(left, top, right, bottom);
1032   if (p == nullptr) {
1033     LOGE("Out-of-memory");
1034     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1035   }
1036
1037   *handle = p;
1038
1039   return NOTI_EX_ERROR_NONE;
1040 }
1041
1042 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1043   if (handle == nullptr) {
1044     LOGE("Invalid parameter");
1045     return NOTI_EX_ERROR_INVALID_PARAMETER;
1046   }
1047
1048   Padding* p = static_cast<Padding*>(handle);
1049   p->~Padding();
1050
1051   return NOTI_EX_ERROR_NONE;
1052 }
1053
1054 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1055     int *val) {
1056   if (handle == nullptr || val == nullptr) {
1057     LOGE("Invalid parameter");
1058     return NOTI_EX_ERROR_INVALID_PARAMETER;
1059   }
1060
1061   Padding* p = static_cast<Padding*>(handle);
1062   *val = p->GetLeft();
1063
1064   return NOTI_EX_ERROR_NONE;
1065 }
1066
1067 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1068     int *val) {
1069   if (handle == nullptr || val == nullptr) {
1070     LOGE("Invalid parameter");
1071     return NOTI_EX_ERROR_INVALID_PARAMETER;
1072   }
1073
1074   Padding* p = static_cast<Padding*>(handle);
1075   *val = p->GetTop();
1076
1077   return NOTI_EX_ERROR_NONE;
1078 }
1079
1080 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1081     int *val) {
1082   if (handle == nullptr || val == nullptr) {
1083     LOGE("Invalid parameter");
1084     return NOTI_EX_ERROR_INVALID_PARAMETER;
1085   }
1086
1087   Padding* p = static_cast<Padding*>(handle);
1088   *val = p->GetRight();
1089
1090   return NOTI_EX_ERROR_NONE;
1091 }
1092
1093 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1094     int *val) {
1095   if (handle == nullptr || val == nullptr) {
1096     LOGE("Invalid parameter");
1097     return NOTI_EX_ERROR_INVALID_PARAMETER;
1098   }
1099
1100   Padding* p = static_cast<Padding*>(handle);
1101   *val = p->GetBottom();
1102
1103   return NOTI_EX_ERROR_NONE;
1104 }
1105
1106 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1107     int x, int y, int w, int h) {
1108   if (handle == nullptr) {
1109     LOGE("Invalid parameter");
1110     return NOTI_EX_ERROR_INVALID_PARAMETER;
1111   }
1112
1113   auto* p = new (std::nothrow) Geometry(x, y, w, h);
1114   if (p == nullptr) {
1115     LOGE("Out-of-memory");
1116     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1117   }
1118
1119   *handle = p;
1120
1121   return NOTI_EX_ERROR_NONE;
1122 }
1123
1124 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1125   if (handle == nullptr) {
1126     LOGE("Invalid parameter");
1127     return NOTI_EX_ERROR_INVALID_PARAMETER;
1128   }
1129
1130   Geometry* p = static_cast<Geometry*>(handle);
1131   p->~Geometry();
1132
1133   return NOTI_EX_ERROR_NONE;
1134 }
1135
1136 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1137     int *val) {
1138   if (handle == nullptr || val == nullptr) {
1139     LOGE("Invalid parameter");
1140     return NOTI_EX_ERROR_INVALID_PARAMETER;
1141   }
1142
1143   Geometry* p = static_cast<Geometry*>(handle);
1144   *val = p->GetX();
1145
1146   return NOTI_EX_ERROR_NONE;
1147 }
1148
1149 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1150     int *val) {
1151   if (handle == nullptr || val == nullptr) {
1152     LOGE("Invalid parameter");
1153     return NOTI_EX_ERROR_INVALID_PARAMETER;
1154   }
1155
1156   Geometry* p = static_cast<Geometry*>(handle);
1157   *val = p->GetY();
1158
1159   return NOTI_EX_ERROR_NONE;
1160 }
1161
1162 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1163     int *val) {
1164   if (handle == nullptr || val == nullptr) {
1165     LOGE("Invalid parameter");
1166     return NOTI_EX_ERROR_INVALID_PARAMETER;
1167   }
1168
1169   Geometry* p = static_cast<Geometry*>(handle);
1170   *val = p->GetWidth();
1171
1172   return NOTI_EX_ERROR_NONE;
1173 }
1174
1175 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1176     int *val) {
1177   if (handle == nullptr || val == nullptr) {
1178     LOGE("Invalid parameter");
1179     return NOTI_EX_ERROR_INVALID_PARAMETER;
1180   }
1181
1182   Geometry* p = static_cast<Geometry*>(handle);
1183   *val = p->GetHeight();
1184
1185   return NOTI_EX_ERROR_NONE;
1186 }
1187
1188 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1189     noti_ex_color_h color,
1190     noti_ex_padding_h padding,
1191     noti_ex_geometry_h geometry) {
1192   if (handle == nullptr) {
1193     LOGE("Invalid parameter");
1194     return NOTI_EX_ERROR_INVALID_PARAMETER;
1195   }
1196
1197   Color* color_ = static_cast<Color*>(color);
1198   Padding* padding_ = static_cast<Padding*>(padding);
1199   Geometry* geo_ = static_cast<Geometry*>(geometry);
1200
1201   auto* p = new (std::nothrow) Style(*color_, *padding_, *geo_);
1202   if (p == nullptr) {
1203     LOGE("Out-of-memory");
1204     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1205   }
1206
1207   *handle = p;
1208
1209   return NOTI_EX_ERROR_NONE;
1210 }
1211
1212 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1213   if (handle == nullptr) {
1214     LOGE("Invalid parameter");
1215     return NOTI_EX_ERROR_INVALID_PARAMETER;
1216   }
1217
1218   Style* p = static_cast<Style*>(handle);
1219   p->~Style();
1220
1221   return NOTI_EX_ERROR_NONE;
1222 }
1223
1224 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1225     noti_ex_padding_h *padding) {
1226   if (handle == nullptr || padding == nullptr) {
1227     LOGE("Invalid parameter");
1228     return NOTI_EX_ERROR_INVALID_PARAMETER;
1229   }
1230
1231   Style* p = static_cast<Style*>(handle);
1232   Padding* padding_ = new (std::nothrow) Padding(p->GetPadding());
1233   if (padding_ == nullptr) {
1234     LOGE("Out-of-memory");
1235     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1236   }
1237
1238   *padding = padding_;
1239
1240   return NOTI_EX_ERROR_NONE;
1241 }
1242
1243 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1244     noti_ex_color_h *color) {
1245   if (handle == nullptr || color == nullptr) {
1246     LOGE("Invalid parameter");
1247     return NOTI_EX_ERROR_INVALID_PARAMETER;
1248   }
1249
1250   Style* p = static_cast<Style*>(handle);
1251   Color* color_ = new (std::nothrow) Color(p->GetColor());
1252   if (color_ == nullptr) {
1253     LOGE("Out-of-memory");
1254     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1255   }
1256
1257   *color = color_;
1258
1259   return NOTI_EX_ERROR_NONE;
1260 }
1261
1262 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1263     noti_ex_geometry_h *geometry) {
1264   if (handle == nullptr || geometry == nullptr) {
1265     LOGE("Invalid parameter");
1266     return NOTI_EX_ERROR_INVALID_PARAMETER;
1267   }
1268
1269   Style* p = static_cast<Style*>(handle);
1270   Geometry* geo_ = new (std::nothrow) Geometry(p->GetGeometry());
1271   if (geo_ == nullptr) {
1272     LOGE("Out-of-memory");
1273     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1274   }
1275
1276   *geometry = geo_;
1277
1278   return NOTI_EX_ERROR_NONE;
1279 }
1280
1281 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1282     noti_ex_color_h color) {
1283   if (handle == nullptr) {
1284     LOGE("Invalid parameter");
1285     return NOTI_EX_ERROR_INVALID_PARAMETER;
1286   }
1287
1288   Color* color_ = static_cast<Color*>(color);
1289   auto* p = new (std::nothrow) LEDInfo(*color_);
1290   if (p == nullptr) {
1291     LOGE("Out-of-memory");
1292     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1293   }
1294
1295   *handle = p;
1296
1297   return NOTI_EX_ERROR_NONE;
1298 }
1299
1300 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1301   if (handle == nullptr) {
1302     LOGE("Invalid parameter");
1303     return NOTI_EX_ERROR_INVALID_PARAMETER;
1304   }
1305
1306   LEDInfo* p = static_cast<LEDInfo*>(handle);
1307   p->~LEDInfo();
1308
1309   return NOTI_EX_ERROR_NONE;
1310 }
1311
1312 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1313     noti_ex_led_info_h handle, int ms) {
1314   if (handle == nullptr) {
1315     LOGE("Invalid parameter");
1316     return NOTI_EX_ERROR_INVALID_PARAMETER;
1317   }
1318
1319   LEDInfo* p = static_cast<LEDInfo*>(handle);
1320   p->SetOnPeriod(ms);
1321
1322   return NOTI_EX_ERROR_NONE;
1323 }
1324
1325 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1326     noti_ex_led_info_h handle, int *ms) {
1327   if (handle == nullptr || ms == nullptr) {
1328     LOGE("Invalid parameter");
1329     return NOTI_EX_ERROR_INVALID_PARAMETER;
1330   }
1331
1332   LEDInfo* p = static_cast<LEDInfo*>(handle);
1333   *ms = p->GetOnPeriod();
1334
1335   return NOTI_EX_ERROR_NONE;
1336 }
1337
1338 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1339     noti_ex_led_info_h handle, int ms) {
1340   if (handle == nullptr) {
1341     LOGE("Invalid parameter");
1342     return NOTI_EX_ERROR_INVALID_PARAMETER;
1343   }
1344
1345   LEDInfo* p = static_cast<LEDInfo*>(handle);
1346   p->SetOffPeriod(ms);
1347
1348   return NOTI_EX_ERROR_NONE;
1349 }
1350
1351 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1352     noti_ex_led_info_h handle, int *ms) {
1353   if (handle == nullptr) {
1354     LOGE("Invalid parameter");
1355     return NOTI_EX_ERROR_INVALID_PARAMETER;
1356   }
1357
1358   LEDInfo* p = static_cast<LEDInfo*>(handle);
1359   *ms = p->GetOffPeriod();
1360
1361   return NOTI_EX_ERROR_NONE;
1362 }
1363
1364 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1365     noti_ex_led_info_h handle, noti_ex_color_h *color) {
1366   if (handle == nullptr) {
1367     LOGE("Invalid parameter");
1368     return NOTI_EX_ERROR_INVALID_PARAMETER;
1369   }
1370
1371   LEDInfo* p = static_cast<LEDInfo*>(handle);
1372   Color* color_ = new (std::nothrow) Color(p->GetColor());
1373   if (color_ == nullptr) {
1374     LOGE("Out-of-memory");
1375     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1376   }
1377
1378   *color = color_;
1379
1380   return NOTI_EX_ERROR_NONE;
1381 }
1382
1383 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1384   if (handle == nullptr) {
1385     LOGE("Invalid parameter");
1386     return NOTI_EX_ERROR_INVALID_PARAMETER;
1387   }
1388
1389   AbstractAction* p = static_cast<AbstractAction*>(handle);
1390   p->~AbstractAction();
1391
1392   return NOTI_EX_ERROR_NONE;
1393 }
1394
1395 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1396     int *type) {
1397   if (handle == nullptr || type == nullptr) {
1398     LOGE("Invalid parameter");
1399     return NOTI_EX_ERROR_INVALID_PARAMETER;
1400   }
1401
1402   AbstractAction* p = static_cast<AbstractAction*>(handle);
1403   *type = p->GetType();
1404
1405   return NOTI_EX_ERROR_NONE;
1406 }
1407
1408 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1409     bool *local) {
1410   if (handle == nullptr || local == nullptr) {
1411     LOGE("Invalid parameter");
1412     return NOTI_EX_ERROR_INVALID_PARAMETER;
1413   }
1414
1415   AbstractAction* p = static_cast<AbstractAction*>(handle);
1416   *local = p->IsLocal();
1417
1418   return NOTI_EX_ERROR_NONE;
1419 }
1420
1421 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1422     noti_ex_item_h item) {
1423   if (handle == nullptr || item==nullptr) {
1424     LOGE("Invalid parameter");
1425     return NOTI_EX_ERROR_INVALID_PARAMETER;
1426   }
1427   AbstractAction* p = static_cast<AbstractAction*>(handle);
1428   Handle* ih = static_cast<Handle*>(item);
1429   p->Execute(ih->GetPtr());
1430
1431   return NOTI_EX_ERROR_NONE;
1432 }
1433
1434 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1435     char **extra) {
1436   if (handle == nullptr || extra == nullptr) {
1437     LOGE("Invalid parameter");
1438     return NOTI_EX_ERROR_INVALID_PARAMETER;
1439   }
1440
1441   AbstractAction* p = static_cast<AbstractAction*>(handle);
1442   if (!p->GetExtra().empty()) {
1443     *extra = strdup(p->GetExtra().c_str());
1444     if (*extra == nullptr) {
1445       LOGE("Out-of-memory");
1446       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1447     }
1448   }
1449
1450   return NOTI_EX_ERROR_NONE;
1451 }
1452
1453 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1454     noti_ex_item_info_h handle, int *hide_time) {
1455   if (handle == nullptr || hide_time == nullptr) {
1456     LOGE("Invalid parameter");
1457     return NOTI_EX_ERROR_INVALID_PARAMETER;
1458   }
1459   IItemInfo* p = static_cast<IItemInfo*>(handle);
1460   *hide_time = p->GetHideTime();
1461   return NOTI_EX_ERROR_NONE;
1462 }
1463
1464 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1465     noti_ex_item_info_h handle, int hide_time) {
1466   if (handle == nullptr) {
1467     LOGE("Invalid parameter");
1468     return NOTI_EX_ERROR_INVALID_PARAMETER;
1469   }
1470   IItemInfo* p = static_cast<IItemInfo*>(handle);
1471   p->SetHideTime(hide_time);
1472   return NOTI_EX_ERROR_NONE;
1473 }
1474
1475 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1476     noti_ex_item_info_h handle, int *delete_time) {
1477   if (handle == nullptr || delete_time == nullptr) {
1478     LOGE("Invalid parameter");
1479     return NOTI_EX_ERROR_INVALID_PARAMETER;
1480   }
1481   IItemInfo* p = static_cast<IItemInfo*>(handle);
1482   *delete_time = p->GetDeleteTime();
1483   return NOTI_EX_ERROR_NONE;
1484 }
1485
1486 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1487     noti_ex_item_info_h handle, int delete_time) {
1488   if (handle == nullptr) {
1489     LOGE("Invalid parameter");
1490     return NOTI_EX_ERROR_INVALID_PARAMETER;
1491   }
1492   IItemInfo* p = static_cast<IItemInfo*>(handle);
1493   p->SetDeleteTime(delete_time);
1494   return NOTI_EX_ERROR_NONE;
1495 }
1496
1497 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1498     noti_ex_item_info_h handle, time_t *time) {
1499   if (handle == nullptr || time == nullptr) {
1500     LOGE("Invalid parameter");
1501     return NOTI_EX_ERROR_INVALID_PARAMETER;
1502   }
1503
1504   IItemInfo* p = static_cast<IItemInfo*>(handle);
1505   *time = p->GetTime();
1506   return NOTI_EX_ERROR_NONE;
1507 }
1508
1509 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1510   if (handle == nullptr) {
1511     LOGE("Invalid parameter");
1512     return NOTI_EX_ERROR_INVALID_PARAMETER;
1513   }
1514
1515   Handle* h = static_cast<Handle*>(handle);
1516   delete h;
1517   return NOTI_EX_ERROR_NONE;
1518 }
1519
1520 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1521     const char *id, noti_ex_item_h *item) {
1522   if (handle == nullptr) {
1523     LOGE("Invalid parameter");
1524     return NOTI_EX_ERROR_INVALID_PARAMETER;
1525   }
1526
1527   Handle* p = static_cast<Handle*>(handle);
1528   AbstractItem& find_item = p->Get()->FindByID(string(id));
1529   *item = new Handle(&find_item);
1530   return NOTI_EX_ERROR_NONE;
1531 }
1532
1533 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1534     int *type) {
1535   if (handle == nullptr || type == nullptr) {
1536     LOGE("Invalid parameter");
1537     return NOTI_EX_ERROR_INVALID_PARAMETER;
1538   }
1539
1540   Handle* h = static_cast<Handle*>(handle);
1541   AbstractItem* p = h->Get();
1542   *type = p->GetType();
1543   return NOTI_EX_ERROR_NONE;
1544 }
1545
1546 extern "C" EXPORT_API int noti_ex_item_get_shared_path(noti_ex_item_h handle,
1547     char ***path, int *count) {
1548   if (handle == nullptr || path == nullptr || count == nullptr) {
1549     LOGE("Invalid parameter");
1550     return NOTI_EX_ERROR_INVALID_PARAMETER;
1551   }
1552   Handle* p = static_cast<Handle*>(handle);
1553   list<string> shared_path = p->Get()->GetSharedPath();
1554   *path = (char**)calloc(shared_path.size(), sizeof(char*));
1555   int idx = 0;
1556   for (auto& i : shared_path) {
1557     *path[idx++] = strdup(i.c_str());
1558   }
1559   *count = shared_path.size();
1560   return NOTI_EX_ERROR_NONE;
1561 }
1562
1563 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1564     char **id) {
1565   if (handle == nullptr || id == nullptr) {
1566     LOGE("Invalid parameter");
1567     return NOTI_EX_ERROR_INVALID_PARAMETER;
1568   }
1569   Handle* h = static_cast<Handle*>(handle);
1570   AbstractItem* p = h->Get();
1571   *id = strdup(p->GetId().c_str());
1572   return NOTI_EX_ERROR_NONE;
1573 }
1574
1575 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1576     const char *id) {
1577   if (handle == nullptr || id == nullptr) {
1578     LOGE("Invalid parameter");
1579     return NOTI_EX_ERROR_INVALID_PARAMETER;
1580   }
1581   Handle* p = static_cast<Handle*>(handle);
1582   p->Get()->SetId(id);
1583   return NOTI_EX_ERROR_NONE;
1584 }
1585
1586 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1587     noti_ex_action_h *action) {
1588   if (handle == nullptr || action == nullptr) {
1589     LOGE("Invalid parameter");
1590     return NOTI_EX_ERROR_INVALID_PARAMETER;
1591   }
1592   Handle* p = static_cast<Handle*>(handle);
1593   if (p->Get()->GetAction() == nullptr) {
1594     *action = nullptr;
1595     return NOTI_EX_ERROR_NONE;
1596   }
1597   *action = static_cast<noti_ex_action_h>(p->Get()->GetAction().get());
1598
1599   return NOTI_EX_ERROR_NONE;
1600 }
1601
1602 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1603     noti_ex_action_h action) {
1604   if (handle == nullptr || action == nullptr) {
1605     LOGE("Invalid parameter");
1606     return NOTI_EX_ERROR_INVALID_PARAMETER;
1607   }
1608
1609   Handle* p = static_cast<Handle*>(handle);
1610   AbstractAction* a = static_cast<AbstractAction*>(action);
1611   p->Get()->SetAction(shared_ptr<AbstractAction>(a));
1612   return NOTI_EX_ERROR_NONE;
1613 }
1614
1615 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1616     noti_ex_style_h *style) {
1617   if (handle == nullptr || style == nullptr) {
1618     LOGE("Invalid parameter");
1619     return NOTI_EX_ERROR_INVALID_PARAMETER;
1620   }
1621
1622   Handle* p = static_cast<Handle*>(handle);
1623   shared_ptr<Style> s = p->Get()->GetStyle();
1624   *style = static_cast<noti_ex_style_h>(s.get());
1625   return NOTI_EX_ERROR_NONE;
1626 }
1627
1628 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1629     noti_ex_style_h style) {
1630   if (handle == nullptr || style == nullptr) {
1631     LOGE("Invalid parameter");
1632     return NOTI_EX_ERROR_INVALID_PARAMETER;
1633   }
1634
1635   Handle* p = static_cast<Handle*>(handle);
1636   Style* s = static_cast<Style*>(style);
1637   p->Get()->SetStyle(shared_ptr<Style>(s));
1638   return NOTI_EX_ERROR_NONE;
1639 }
1640
1641 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1642     bool visible) {
1643   if (handle == nullptr) {
1644     LOGE("Invalid parameter");
1645     return NOTI_EX_ERROR_INVALID_PARAMETER;
1646   }
1647
1648   Handle* p = static_cast<Handle*>(handle);
1649   p->Get()->SetVisible(visible);
1650   return NOTI_EX_ERROR_NONE;
1651 }
1652
1653 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1654     bool *visible) {
1655   if (handle == nullptr || visible == nullptr) {
1656     LOGE("Invalid parameter");
1657     return NOTI_EX_ERROR_INVALID_PARAMETER;
1658   }
1659
1660   Handle* p = static_cast<Handle*>(handle);
1661   *visible = p->Get()->GetVisible();
1662   return NOTI_EX_ERROR_NONE;
1663 }
1664
1665 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1666     bool enable) {
1667   if (handle == nullptr) {
1668     LOGE("Invalid parameter");
1669     return NOTI_EX_ERROR_INVALID_PARAMETER;
1670   }
1671
1672   Handle* p = static_cast<Handle*>(handle);
1673   p->Get()->SetEnable(enable);
1674   return NOTI_EX_ERROR_NONE;
1675 }
1676
1677 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1678     bool *enable) {
1679   if (handle == nullptr || enable == nullptr) {
1680     LOGE("Invalid parameter");
1681     return NOTI_EX_ERROR_INVALID_PARAMETER;
1682   }
1683
1684   Handle* p = static_cast<Handle*>(handle);
1685   *enable = p->Get()->GetEnable();
1686   return NOTI_EX_ERROR_NONE;
1687 }
1688
1689 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
1690     const char *receiver_group) {
1691   if (handle == nullptr || receiver_group == nullptr) {
1692     LOGE("Invalid parameter");
1693     return NOTI_EX_ERROR_INVALID_PARAMETER;
1694   }
1695
1696   Handle* p = static_cast<Handle*>(handle);
1697   p->Get()->AddReceiver(receiver_group);
1698   return NOTI_EX_ERROR_NONE;
1699 }
1700
1701 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
1702     const char *receiver_group) {
1703   if (handle == nullptr || receiver_group == nullptr) {
1704     LOGE("Invalid parameter");
1705     return NOTI_EX_ERROR_INVALID_PARAMETER;
1706   }
1707
1708   Handle* p = static_cast<Handle*>(handle);
1709   p->Get()->RemoveReceiver(receiver_group);
1710   return NOTI_EX_ERROR_NONE;
1711 }
1712
1713 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
1714     char ***receiver_list, int *count) {
1715   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
1716     LOGE("Invalid parameter");
1717     return NOTI_EX_ERROR_INVALID_PARAMETER;
1718   }
1719
1720   Handle* p = static_cast<Handle*>(handle);
1721   list<string> receivers = p->Get()->GetReceiverList();
1722   *receiver_list = (char**)calloc(receivers.size(), sizeof(char*));
1723   int idx = 0;
1724   for (auto& i : receivers) {
1725     *receiver_list[idx++] = strdup(i.c_str());
1726   }
1727   *count = receivers.size();
1728   return NOTI_EX_ERROR_NONE;
1729 }
1730
1731 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
1732     int policy) {
1733   if (handle == nullptr) {
1734     LOGE("Invalid parameter");
1735     return NOTI_EX_ERROR_INVALID_PARAMETER;
1736   }
1737
1738   Handle* p = static_cast<Handle*>(handle);
1739   p->Get()->SetPolicy(policy);
1740   return NOTI_EX_ERROR_NONE;
1741 }
1742
1743 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
1744     int *policy) {
1745   if (handle == nullptr || policy == nullptr) {
1746     LOGE("Invalid parameter");
1747     return NOTI_EX_ERROR_INVALID_PARAMETER;
1748   }
1749
1750   Handle* p = static_cast<Handle*>(handle);
1751   *policy = p->Get()->GetPolicy();
1752   return NOTI_EX_ERROR_NONE;
1753 }
1754
1755 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
1756     char **channel) {
1757   if (handle == nullptr || channel == nullptr) {
1758     LOGE("Invalid parameter");
1759     return NOTI_EX_ERROR_INVALID_PARAMETER;
1760   }
1761
1762   Handle* p = static_cast<Handle*>(handle);
1763   if (!p->Get()->GetChannel().empty())
1764     *channel = strdup(p->Get()->GetChannel().c_str());
1765   else
1766     *channel = nullptr;
1767
1768   return NOTI_EX_ERROR_NONE;
1769 }
1770
1771 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
1772     const char *channel) {
1773   if (handle == nullptr) {
1774     LOGE("Invalid parameter");
1775     return NOTI_EX_ERROR_INVALID_PARAMETER;
1776   }
1777
1778   Handle* p = static_cast<Handle*>(handle);
1779   p->Get()->SetChannel(channel);
1780   return NOTI_EX_ERROR_NONE;
1781 }
1782
1783 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
1784     noti_ex_led_info_h led) {
1785   if (handle == nullptr) {
1786     LOGE("Invalid parameter");
1787     return NOTI_EX_ERROR_INVALID_PARAMETER;
1788   }
1789
1790   Handle* p = static_cast<Handle*>(handle);
1791   LEDInfo* led_info = static_cast<LEDInfo*>(led);
1792   p->Get()->SetLEDInfo(shared_ptr<LEDInfo>(led_info));
1793   return NOTI_EX_ERROR_NONE;
1794 }
1795
1796 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
1797     noti_ex_led_info_h *led) {
1798   if (handle == nullptr) {
1799     LOGE("Invalid parameter");
1800     return NOTI_EX_ERROR_INVALID_PARAMETER;
1801   }
1802
1803   Handle* p = static_cast<Handle*>(handle);
1804   if (p->Get()->GetLEDInfo() != nullptr)
1805     *led = static_cast<noti_ex_led_info_h>(p->Get()->GetLEDInfo().get());
1806   else
1807     *led = nullptr;
1808   return NOTI_EX_ERROR_NONE;
1809 }
1810
1811 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
1812     const char *path) {
1813   if (handle == nullptr) {
1814     LOGE("Invalid parameter");
1815     return NOTI_EX_ERROR_INVALID_PARAMETER;
1816   }
1817
1818   Handle* p = static_cast<Handle*>(handle);
1819   if (path == nullptr)
1820     p->Get()->SetSoundPath("");
1821   else
1822     p->Get()->SetSoundPath(path);
1823   return NOTI_EX_ERROR_NONE;
1824 }
1825
1826 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
1827     const char *path) {
1828   if (handle == nullptr) {
1829     LOGE("Invalid parameter");
1830     return NOTI_EX_ERROR_INVALID_PARAMETER;
1831   }
1832
1833   Handle* p = static_cast<Handle*>(handle);
1834   if (path == nullptr)
1835     p->Get()->SetVibrationPath("");
1836   else
1837     p->Get()->SetVibrationPath(path);
1838   return NOTI_EX_ERROR_NONE;
1839 }
1840
1841 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
1842     char **path) {
1843   if (handle == nullptr || path == nullptr) {
1844     LOGE("Invalid parameter");
1845     return NOTI_EX_ERROR_INVALID_PARAMETER;
1846   }
1847
1848   Handle* p = static_cast<Handle*>(handle);
1849   if (p->Get()->GetSoundPath().empty())
1850     *path = nullptr;
1851   else
1852     *path = strdup(p->Get()->GetSoundPath().c_str());
1853   return NOTI_EX_ERROR_NONE;
1854 }
1855
1856 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
1857     char **path) {
1858   if (handle == nullptr || path == nullptr) {
1859     LOGE("Invalid parameter");
1860     return NOTI_EX_ERROR_INVALID_PARAMETER;
1861   }
1862
1863   Handle* p = static_cast<Handle*>(handle);
1864   if (p->Get()->GetVibrationPath().empty())
1865     *path = nullptr;
1866   else
1867     *path = strdup(p->Get()->GetVibrationPath().c_str());
1868   return NOTI_EX_ERROR_NONE;
1869 }
1870
1871 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
1872     noti_ex_item_info_h *info) {
1873   if (handle == nullptr || info == nullptr) {
1874     LOGE("Invalid parameter");
1875     return NOTI_EX_ERROR_INVALID_PARAMETER;
1876   }
1877
1878   Handle* p = static_cast<Handle*>(handle);
1879   if (p->Get()->GetInfo() == nullptr)
1880     *info = nullptr;
1881   else
1882     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
1883   return NOTI_EX_ERROR_NONE;
1884 }
1885
1886 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
1887     char **id) {
1888   if (handle == nullptr || id == nullptr) {
1889     LOGE("Invalid parameter");
1890     return NOTI_EX_ERROR_INVALID_PARAMETER;
1891   }
1892
1893   Handle* p = static_cast<Handle*>(handle);
1894   if (p->Get()->GetSenderAppId().empty())
1895     *id = nullptr;
1896   else
1897     *id = strdup(p->Get()->GetSenderAppId().c_str());
1898   return NOTI_EX_ERROR_NONE;
1899 }
1900
1901 extern "C" EXPORT_API int noti_ex_item_set_sender_app_id(noti_ex_item_h handle,
1902     const char *id) {
1903   if (handle == nullptr) {
1904     LOGE("Invalid parameter");
1905     return NOTI_EX_ERROR_INVALID_PARAMETER;
1906   }
1907
1908   Handle* p = static_cast<Handle*>(handle);
1909   if (id == nullptr)
1910     p->Get()->SetSenderAppId("");
1911   else
1912     p->Get()->SetSenderAppId(id);
1913   return NOTI_EX_ERROR_NONE;
1914 }
1915
1916 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
1917     char **tag) {
1918   if (handle == nullptr || tag == nullptr) {
1919     LOGE("Invalid parameter");
1920     return NOTI_EX_ERROR_INVALID_PARAMETER;
1921   }
1922
1923   Handle* p = static_cast<Handle*>(handle);
1924   if (p->Get()->GetTag().empty())
1925     *tag = nullptr;
1926   else
1927     *tag = strdup(p->Get()->GetTag().c_str());
1928   return NOTI_EX_ERROR_NONE;
1929 }
1930
1931 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
1932     const char *tag) {
1933   if (handle == nullptr) {
1934     LOGE("Invalid parameter");
1935     return NOTI_EX_ERROR_INVALID_PARAMETER;
1936   }
1937
1938   Handle* p = static_cast<Handle*>(handle);
1939   if (tag == nullptr)
1940     p->Get()->SetTag("");
1941   else
1942     p->Get()->SetTag(tag);
1943   return NOTI_EX_ERROR_NONE;
1944 }
1945
1946 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
1947     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
1948     void *data) {
1949   if (handle == nullptr) {
1950     LOGE("Invalid parameter");
1951     return NOTI_EX_ERROR_INVALID_PARAMETER;
1952   }
1953
1954   string receiver_group_str = "";
1955   if (receiver_group)
1956     receiver_group_str = string(receiver_group);
1957
1958   ManagerStub* stub = new (std::nothrow) ManagerStub(
1959       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
1960       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
1961       receiver_group_str);
1962   if (stub == nullptr) {
1963     LOGE("Fail to create manager");
1964     return NOTI_EX_ERROR_IO_ERROR;
1965   }
1966   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
1967       new ManagerCallbackInfo(event_callbacks, data)));
1968   *handle = static_cast<noti_ex_manager_h>(stub);
1969
1970   return NOTI_EX_ERROR_NONE;
1971 }
1972
1973 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
1974   if (handle == nullptr) {
1975     LOGE("Invalid parameter");
1976     return NOTI_EX_ERROR_INVALID_PARAMETER;
1977   }
1978   ManagerStub* stub = static_cast<ManagerStub*>(handle);
1979   delete stub;
1980   return NOTI_EX_ERROR_NONE;
1981 }
1982
1983 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
1984     noti_ex_item_h **items, int *count) {
1985   if (handle == nullptr || items == nullptr || count == nullptr) {
1986     LOGE("Invalid parameter");
1987     return NOTI_EX_ERROR_INVALID_PARAMETER;
1988   }
1989
1990   try {
1991     ManagerStub* stub = static_cast<ManagerStub*>(handle);
1992     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
1993     if (item_list.size() == 0) {
1994       *items = nullptr;
1995       *count = 0;
1996       return NOTI_EX_ERROR_NONE;
1997     }
1998     *items = (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
1999     if (*items == nullptr) {
2000       LOGE("Fail to create items");
2001       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2002     }
2003
2004     int idx = 0;
2005     for (auto& i : item_list) {
2006       *items[idx++] = new Handle(move(i));
2007     }
2008     *count = item_list.size();
2009   } catch (Exception &ex) {
2010     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2011     return NOTI_EX_ERROR_IO_ERROR;
2012   }
2013   return NOTI_EX_ERROR_NONE;
2014 }
2015
2016 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2017     noti_ex_item_h noti, int *request_id) {
2018   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2019     LOGE("Invalid parameter");
2020     return NOTI_EX_ERROR_INVALID_PARAMETER;
2021   }
2022   try {
2023     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2024     Handle* sp = static_cast<Handle*>(noti);
2025     if (sp->GetPtr().get() == nullptr) {
2026       LOGE("Invalid noti reference can not be sended");
2027       return NOTI_EX_ERROR_INVALID_PARAMETER;
2028     } else {
2029       *request_id = stub->Update(sp->GetPtr());
2030     }
2031   } catch (Exception &ex) {
2032     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2033     return NOTI_EX_ERROR_IO_ERROR;
2034   }
2035   return NOTI_EX_ERROR_NONE;
2036 }
2037
2038 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2039     noti_ex_item_h noti, int *request_id) {
2040   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2041     LOGE("Invalid parameter");
2042     return NOTI_EX_ERROR_INVALID_PARAMETER;
2043   }
2044   try {
2045     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2046     Handle* item = static_cast<Handle*>(noti);
2047     if (item->GetPtr().get() == nullptr) {
2048       LOGE("Invalid noti reference can not be sended");
2049       return NOTI_EX_ERROR_INVALID_PARAMETER;
2050     } else {
2051       *request_id = stub->Delete(item->GetPtr());
2052     }
2053   } catch (Exception &ex) {
2054     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2055     return NOTI_EX_ERROR_IO_ERROR;
2056   }
2057   return NOTI_EX_ERROR_NONE;
2058 }
2059
2060 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2061     int *request_id) {
2062   if (handle == nullptr || request_id == nullptr) {
2063     LOGE("Invalid parameter");
2064     return NOTI_EX_ERROR_INVALID_PARAMETER;
2065   }
2066   try {
2067     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2068     *request_id = stub->DeleteAll();
2069   } catch (Exception &ex) {
2070     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2071     return NOTI_EX_ERROR_IO_ERROR;
2072   }
2073   return NOTI_EX_ERROR_NONE;
2074 }
2075
2076 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2077     noti_ex_item_h noti, int *request_id) {
2078   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2079     LOGE("Invalid parameter");
2080     return NOTI_EX_ERROR_INVALID_PARAMETER;
2081   }
2082   try {
2083     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2084     Handle* item = static_cast<Handle*>(noti);
2085     if (item->GetPtr().get() == nullptr) {
2086       LOGE("Invalid noti reference can not be sended");
2087       return NOTI_EX_ERROR_INVALID_PARAMETER;
2088     } else {
2089       *request_id = stub->Hide(item->GetPtr());
2090     }
2091   } catch (Exception &ex) {
2092     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2093     return NOTI_EX_ERROR_IO_ERROR;
2094   }
2095   return NOTI_EX_ERROR_NONE;
2096 }
2097
2098 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2099     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2100   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2101     LOGE("Invalid parameter");
2102     return NOTI_EX_ERROR_INVALID_PARAMETER;
2103   }
2104   try {
2105     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2106     *item = new Handle(stub->FindByRootID(root_id));
2107   } catch (Exception &ex) {
2108     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2109     return NOTI_EX_ERROR_IO_ERROR;
2110   }
2111   return NOTI_EX_ERROR_NONE;
2112 }
2113
2114 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2115     noti_ex_event_info_h info, noti_ex_error_e error) {
2116   if (handle == nullptr || info == nullptr) {
2117     LOGE("Invalid parameter");
2118     return NOTI_EX_ERROR_INVALID_PARAMETER;
2119   }
2120   try {
2121     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2122     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2123     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2124         static_cast<NotificationError>(error));
2125   } catch (Exception &ex) {
2126     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2127     return NOTI_EX_ERROR_IO_ERROR;
2128   }
2129   return NOTI_EX_ERROR_NONE;
2130 }
2131
2132 extern "C" EXPORT_API int noti_ex_manager_get_count(noti_ex_manager_h handle,
2133     int *cnt) {
2134
2135   if (handle == nullptr || cnt == nullptr) {
2136     LOGE("Invalid parameter");
2137     return NOTI_EX_ERROR_INVALID_PARAMETER;
2138   }
2139   try {
2140     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2141     *cnt = stub->GetCount();
2142   } catch (Exception &ex) {
2143     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2144     return NOTI_EX_ERROR_IO_ERROR;
2145   }
2146   return NOTI_EX_ERROR_NONE;
2147 }
2148
2149 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2150     const char *id, float min, float current, float max) {
2151   ProgressItem* p;
2152
2153   if (handle == nullptr) {
2154     LOGE("Invalid parameter");
2155     return NOTI_EX_ERROR_INVALID_PARAMETER;
2156   }
2157
2158   if (id)
2159     p = new (std::nothrow) ProgressItem(id, min, current, max);
2160   else
2161     p = new (std::nothrow) ProgressItem(min, current, max);
2162
2163   if (p == nullptr) {
2164     LOGE("Out-of-memory");
2165     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2166   }
2167
2168   *handle = new Handle(p);
2169
2170   return NOTI_EX_ERROR_NONE;
2171 }
2172
2173 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2174     noti_ex_item_h handle, float *current) {
2175   if (handle == nullptr || current == nullptr) {
2176     LOGE("Invalid parameter");
2177     return NOTI_EX_ERROR_INVALID_PARAMETER;
2178   }
2179
2180   Handle *h = static_cast<Handle*>(handle);
2181   if (!h->IsValidType(AbstractItem::Progress)) {
2182     LOGE("Invalid handle type");
2183     return NOTI_EX_ERROR_INVALID_PARAMETER;
2184   }
2185   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2186   *current = p->GetCurrent();
2187
2188   return NOTI_EX_ERROR_NONE;
2189 }
2190
2191 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2192     noti_ex_item_h handle, float current) {
2193   if (handle == nullptr) {
2194     LOGE("Invalid parameter");
2195     return NOTI_EX_ERROR_INVALID_PARAMETER;
2196   }
2197
2198   Handle *h = static_cast<Handle*>(handle);
2199   if (!h->IsValidType(AbstractItem::Progress)) {
2200     LOGE("Invalid handle type");
2201     return NOTI_EX_ERROR_INVALID_PARAMETER;
2202   }
2203   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2204   p->SetCurrent(current);
2205
2206   return NOTI_EX_ERROR_NONE;
2207 }
2208
2209 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2210     float *min) {
2211   if (handle == nullptr || min == nullptr) {
2212     LOGE("Invalid parameter");
2213     return NOTI_EX_ERROR_INVALID_PARAMETER;
2214   }
2215
2216   Handle *h = static_cast<Handle*>(handle);
2217   if (!h->IsValidType(AbstractItem::Progress)) {
2218     LOGE("Invalid handle type");
2219     return NOTI_EX_ERROR_INVALID_PARAMETER;
2220   }
2221   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2222   *min = p->GetMin();
2223
2224   return NOTI_EX_ERROR_NONE;
2225 }
2226
2227 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2228     float *max) {
2229   if (handle == nullptr || max == nullptr) {
2230     LOGE("Invalid parameter");
2231     return NOTI_EX_ERROR_INVALID_PARAMETER;
2232   }
2233
2234   Handle *h = static_cast<Handle*>(handle);
2235   if (!h->IsValidType(AbstractItem::Progress)) {
2236     LOGE("Invalid handle type");
2237     return NOTI_EX_ERROR_INVALID_PARAMETER;
2238   }
2239   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2240   *max = p->GetMax();
2241
2242   return NOTI_EX_ERROR_NONE;
2243 }
2244
2245 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2246     noti_ex_reporter_events_s event_callbacks, void *data) {
2247   if (handle == nullptr) {
2248     LOGE("Invalid parameter");
2249     return NOTI_EX_ERROR_INVALID_PARAMETER;
2250   }
2251
2252   ReporterStub* stub = new (std::nothrow) ReporterStub(
2253       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2254       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2255   if (stub == nullptr) {
2256     LOGE("Fail to create manager");
2257     return NOTI_EX_ERROR_IO_ERROR;
2258   }
2259   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2260       new ReporterCallbackInfo(event_callbacks, data)));
2261
2262   *handle = static_cast<noti_ex_reporter_h>(stub);
2263
2264   return NOTI_EX_ERROR_NONE;
2265 }
2266
2267 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2268   if (handle == nullptr) {
2269     LOGE("Invalid parameter");
2270     return NOTI_EX_ERROR_INVALID_PARAMETER;
2271   }
2272   ReporterStub* stub = static_cast<ReporterStub*>(handle);
2273   delete stub;
2274   return NOTI_EX_ERROR_NONE;
2275 }
2276
2277 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2278     noti_ex_event_info_h info, noti_ex_error_e error) {
2279   if (handle == nullptr || info == nullptr) {
2280     LOGE("Invalid parameter");
2281     return NOTI_EX_ERROR_INVALID_PARAMETER;
2282   }
2283   try {
2284     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2285     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2286     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2287         static_cast<NotificationError>(error));
2288   } catch (Exception &ex) {
2289     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2290     return NOTI_EX_ERROR_IO_ERROR;
2291   }
2292   return NOTI_EX_ERROR_NONE;
2293 }
2294
2295 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2296     noti_ex_item_h noti, int *request_id) {
2297   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2298     LOGE("Invalid parameter");
2299     return NOTI_EX_ERROR_INVALID_PARAMETER;
2300   }
2301   try {
2302     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2303     Handle* h = static_cast<Handle*>(noti);
2304     if (h->GetPtr().get() == nullptr) {
2305       LOGE("Invalid noti reference can not be sended");
2306       return NOTI_EX_ERROR_INVALID_PARAMETER;
2307     } else {
2308       *request_id = stub->Post(h->GetPtr());
2309     }
2310   } catch (Exception &ex) {
2311     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2312     return NOTI_EX_ERROR_IO_ERROR;
2313   }
2314   return NOTI_EX_ERROR_NONE;
2315 }
2316
2317 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2318     noti_ex_item_h *noti_list, int count, int *request_id) {
2319
2320   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2321     LOGE("Invalid parameter");
2322     return NOTI_EX_ERROR_INVALID_PARAMETER;
2323   }
2324   try {
2325     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2326     list<shared_ptr<item::AbstractItem>> notiList;
2327     for (int i = 0; i < count; i++) {
2328       Handle* item = static_cast<Handle*>(noti_list[i]);
2329       notiList.push_back(item->GetPtr());
2330     }
2331     *request_id = stub->Post(notiList);
2332   } catch (Exception &ex) {
2333     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2334     return NOTI_EX_ERROR_IO_ERROR;
2335   }
2336   return NOTI_EX_ERROR_NONE;
2337 }
2338
2339 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2340     noti_ex_item_h noti, int *request_id) {
2341   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2342     LOGE("Invalid parameter");
2343     return NOTI_EX_ERROR_INVALID_PARAMETER;
2344   }
2345   try {
2346     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2347     Handle* item = static_cast<Handle*>(noti);
2348     if (item->GetPtr().get() == nullptr) {
2349       LOGE("Invalid noti reference can not be sended");
2350       return NOTI_EX_ERROR_INVALID_PARAMETER;
2351     } else {
2352       *request_id = stub->Update(item->GetPtr());
2353     }
2354   } catch (Exception &ex) {
2355     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2356     return NOTI_EX_ERROR_IO_ERROR;
2357   }
2358   return NOTI_EX_ERROR_NONE;
2359 }
2360
2361 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2362     noti_ex_item_h noti, int *request_id) {
2363   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2364     LOGE("Invalid parameter");
2365     return NOTI_EX_ERROR_INVALID_PARAMETER;
2366   }
2367   try {
2368     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2369     Handle* item = static_cast<Handle*>(noti);
2370     if (item->GetPtr().get() == nullptr) {
2371       LOGE("Invalid noti reference can not be sended");
2372       return NOTI_EX_ERROR_INVALID_PARAMETER;
2373     } else {
2374       *request_id = stub->Delete(item->GetPtr());
2375     }
2376   } catch (Exception &ex) {
2377     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2378     return NOTI_EX_ERROR_IO_ERROR;
2379   }
2380   return NOTI_EX_ERROR_NONE;
2381 }
2382
2383 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2384     noti_ex_reporter_h handle, int *request_id) {
2385   if (handle == nullptr || request_id == nullptr) {
2386     LOGE("Invalid parameter");
2387     return NOTI_EX_ERROR_INVALID_PARAMETER;
2388   }
2389   try {
2390     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2391     *request_id = stub->DeleteAll();
2392   } catch (Exception &ex) {
2393     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2394     return NOTI_EX_ERROR_IO_ERROR;
2395   }
2396   return NOTI_EX_ERROR_NONE;
2397 }
2398
2399 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2400     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2401   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2402     LOGE("Invalid parameter");
2403     return NOTI_EX_ERROR_INVALID_PARAMETER;
2404   }
2405   try {
2406     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2407     *item = new Handle(stub->FindByRootID(root_id));
2408   } catch (Exception &ex) {
2409     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2410     return NOTI_EX_ERROR_IO_ERROR;
2411   }
2412   return NOTI_EX_ERROR_NONE;
2413 }
2414
2415 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2416     const char *id, const char *text, const char *hyper_link) {
2417   if (handle == nullptr) {
2418     LOGE("Invalid parameter");
2419     return NOTI_EX_ERROR_INVALID_PARAMETER;
2420   }
2421
2422   auto* p = new (std::nothrow) TextItem(id, std::string(text),
2423                 std::string(hyper_link));
2424   if (p == nullptr) {
2425     LOGE("Out-of-memory");
2426     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2427   }
2428
2429   *handle = new Handle(p);
2430
2431   return NOTI_EX_ERROR_NONE;
2432 }
2433
2434 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2435     const char *contents) {
2436   if (handle == nullptr) {
2437     LOGE("Invalid parameter");
2438     return NOTI_EX_ERROR_INVALID_PARAMETER;
2439   }
2440
2441   Handle* p = static_cast<Handle*>(handle);
2442   if (!p->IsValidType(AbstractItem::Text)) {
2443     LOGE("Invalid handle type");
2444     return NOTI_EX_ERROR_INVALID_PARAMETER;
2445   }
2446   TextItem* ti = static_cast<TextItem*>(p->Get());
2447   ti->SetContents(std::string(contents));
2448
2449   return NOTI_EX_ERROR_NONE;
2450 }
2451
2452 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2453     char **contents) {
2454   if (handle == nullptr || contents == nullptr) {
2455     LOGE("Invalid parameter");
2456     return NOTI_EX_ERROR_INVALID_PARAMETER;
2457   }
2458
2459   Handle* p = static_cast<Handle*>(handle);
2460   if (!p->IsValidType(AbstractItem::Text)) {
2461     LOGE("Invalid handle type");
2462     return NOTI_EX_ERROR_INVALID_PARAMETER;
2463   }
2464   TextItem* ti = static_cast<TextItem*>(p->Get());
2465   if (!ti->GetContents().empty()) {
2466     *contents = strdup(ti->GetContents().c_str());
2467     if (*contents == nullptr) {
2468       LOGE("Out-of-memory");
2469       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2470     }
2471   }
2472
2473   return NOTI_EX_ERROR_NONE;
2474 }
2475
2476 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2477     noti_ex_item_h handle, char **hyper_link) {
2478   if (handle == nullptr || hyper_link == nullptr) {
2479     LOGE("Invalid parameter");
2480     return NOTI_EX_ERROR_INVALID_PARAMETER;
2481   }
2482
2483   Handle* p = static_cast<Handle*>(handle);
2484   if (!p->IsValidType(AbstractItem::Text)) {
2485     LOGE("Invalid handle type");
2486     return NOTI_EX_ERROR_INVALID_PARAMETER;
2487   }
2488   TextItem* ti = static_cast<TextItem*>(p->Get());
2489   if (!ti->GetHyperLink().empty()) {
2490     *hyper_link = strdup(ti->GetHyperLink().c_str());
2491     if (*hyper_link == nullptr) {
2492       LOGE("Out-of-memory");
2493       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2494     }
2495   }
2496
2497   return NOTI_EX_ERROR_NONE;
2498 }
2499
2500 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
2501     const char *id, time_t time) {
2502   TimeItem* p;
2503
2504   if (handle == nullptr) {
2505     LOGE("Invalid parameter");
2506     return NOTI_EX_ERROR_INVALID_PARAMETER;
2507   }
2508
2509   if (time) {
2510     if (id)
2511       p = new (std::nothrow) TimeItem(id, time);
2512     else
2513       p = new (std::nothrow) TimeItem(time);
2514   } else {
2515       p = new (std::nothrow) TimeItem();
2516   }
2517
2518   if (p == nullptr) {
2519     LOGE("Out-of-memory");
2520     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2521   }
2522
2523   *handle = new Handle(p);
2524
2525   return NOTI_EX_ERROR_NONE;
2526 }
2527
2528 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
2529     time_t *time) {
2530   if (handle == nullptr || time == nullptr) {
2531     LOGE("Invalid parameter");
2532     return NOTI_EX_ERROR_INVALID_PARAMETER;
2533   }
2534   Handle* h = static_cast<Handle*>(handle);
2535   if (!h->IsValidType(AbstractItem::Time)) {
2536     LOGE("Invalid handle type");
2537     return NOTI_EX_ERROR_INVALID_PARAMETER;
2538   }
2539   TimeItem* p = static_cast<TimeItem*>(h->Get());
2540   *time = p->GetTime();
2541
2542   return NOTI_EX_ERROR_NONE;
2543 }
2544
2545 extern "C" EXPORT_API int noti_ex_action_visibility_create(
2546     noti_ex_action_h *handle, const char *extra) {
2547   if (handle == nullptr) {
2548     LOGE("Invalid parameter");
2549     return NOTI_EX_ERROR_INVALID_PARAMETER;
2550   }
2551
2552   string extra_str = "";
2553   if (extra != NULL)
2554     extra_str = string(extra);
2555
2556   auto* p = new (std::nothrow) VisibilityAction(extra_str);
2557   if (p == nullptr) {
2558     LOGE("Out-of-memory");
2559     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2560   }
2561
2562   *handle = p;
2563
2564   return NOTI_EX_ERROR_NONE;
2565 }
2566
2567 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
2568     const char *id, bool visible) {
2569   if (handle == nullptr || id == nullptr) {
2570     LOGE("Invalid parameter");
2571     return NOTI_EX_ERROR_INVALID_PARAMETER;
2572   }
2573
2574   VisibilityAction* p = static_cast<VisibilityAction*>(handle);
2575   p->SetVisibility(id, visible);
2576
2577   return NOTI_EX_ERROR_NONE;
2578 }