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