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