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