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