Check coding style
[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 #include <sstream>
23 #include <iomanip>
24
25 #include "api/notification_ex_app_control_action.h"
26 #include "api/notification_ex_button.h"
27 #include "api/notification_ex_chat_message.h"
28 #include "api/notification_ex_checkbox.h"
29 #include "api/notification_ex_entry.h"
30 #include "api/notification_ex_event_info.h"
31 #include "api/notification_ex_group.h"
32 #include "api/notification_ex_image.h"
33 #include "api/notification_ex_input_selector.h"
34 #include "api/notification_ex_item.h"
35 #include "api/notification_ex_manager.h"
36 #include "api/notification_ex_progress.h"
37 #include "api/notification_ex_reporter.h"
38 #include "api/notification_ex_text.h"
39 #include "api/notification_ex_time.h"
40 #include "api/notification_ex_visibility_action.h"
41 #include "notification-ex/reporter.h"
42 #include "notification-ex/app_control_action.h"
43 #include "notification-ex/button_item.h"
44 #include "notification-ex/chat_message_item.h"
45 #include "notification-ex/checkbox_item.h"
46 #include "notification-ex/entry_item.h"
47 #include "notification-ex/group_item.h"
48 #include "notification-ex/input_selector_item.h"
49 #include "notification-ex/abstract_item.h"
50 #include "notification-ex/progress_item.h"
51 #include "notification-ex/time_item.h"
52 #include "notification-ex/visibility_action.h"
53 #include "notification-ex/event_info_internal.h"
54 #include "notification-ex/manager.h"
55 #include "notification-ex/dbus_sender.h"
56 #include "notification-ex/dbus_event_listener.h"
57 #include "notification-ex/exception.h"
58
59 #ifdef LOG_TAG
60 #undef LOG_TAG
61 #endif
62 #define LOG_TAG "NOTIFICATION_EX"
63
64 #ifdef EXPORT_API
65 #undef EXPORT_API
66 #endif
67 #define EXPORT_API __attribute__((visibility("default")))
68
69 using namespace std;
70 using namespace tizen_base;
71 using namespace notification::item;
72 using namespace notification;
73
74 namespace {
75
76 class Handle {
77  public:
78   explicit Handle(item::AbstractItem* ref) : ref_(ref) { }
79   explicit Handle(std::shared_ptr<item::AbstractItem> ptr)
80       : ref_(nullptr), ptr_(move(ptr)) { }
81   virtual ~Handle() = default;
82   item::AbstractItem* Get() const {
83     if (ptr_ == nullptr)
84       return ref_;
85     return ptr_.get();
86   }
87
88   bool IsValidType(int type) const {
89     return (Get()->GetType() == type
90         || Get()->GetType() >= AbstractItem::Custom);
91   }
92
93   std::shared_ptr<item::AbstractItem> GetPtr() const {
94     if (ptr_ == nullptr)
95       return std::shared_ptr<item::AbstractItem>({});
96     return ptr_;
97   }
98
99  private:
100   item::AbstractItem* ref_;
101   std::shared_ptr<item::AbstractItem> ptr_;
102 };
103
104 class ManagerCallbackInfo {
105  public:
106   ManagerCallbackInfo(noti_ex_manager_events_s cb, void* user_data)
107     : user_data_(user_data) {
108     cb_.added = cb.added;
109     cb_.updated = cb.updated;
110     cb_.deleted = cb.deleted;
111     cb_.error = cb.error;
112   }
113
114   void InvokeAdded(Manager* manager, const IEventInfo& info,
115       list<shared_ptr<AbstractItem>> addedItem) {
116     if (cb_.added == nullptr)
117       return;
118     noti_ex_item_h* added_item =
119         (noti_ex_item_h*)calloc(addedItem.size(), sizeof(noti_ex_item_h));
120     if (added_item == nullptr) {
121       LOGE("Out of memory");
122       return;
123     }
124
125     int idx = 0;
126     for (auto& i : addedItem) {
127       added_item[idx++] =
128           static_cast<noti_ex_item_h>(new Handle(shared_ptr<AbstractItem>(i)));
129     }
130
131     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
132     cb_.added(static_cast<noti_ex_manager_h>(manager),
133         static_cast<noti_ex_event_info_h>(c_info), added_item,
134         addedItem.size(), user_data_);
135     free(added_item);
136   }
137
138   void InvokeUpdated(Manager* manager, const IEventInfo& info,
139       shared_ptr<item::AbstractItem> updatedItem) {
140     if (cb_.updated == nullptr)
141       return;
142     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
143     cb_.updated(static_cast<noti_ex_manager_h>(manager),
144         static_cast<noti_ex_event_info_h>(c_info),
145         static_cast<noti_ex_item_h>(new Handle(updatedItem)), user_data_);
146   }
147
148   void InvokeDeleted(Manager* manager, const IEventInfo& info,
149       shared_ptr<item::AbstractItem> deletedItem) {
150     if (cb_.deleted == nullptr)
151       return;
152     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
153     if (c_info->GetEventType() == static_cast<int>(IEventInfo::EventType::DeleteAll)) {
154       cb_.deleted(static_cast<noti_ex_manager_h>(manager),
155         static_cast<noti_ex_event_info_h>(c_info),
156         nullptr, user_data_);
157     } else {
158       cb_.deleted(static_cast<noti_ex_manager_h>(manager),
159         static_cast<noti_ex_event_info_h>(c_info),
160         static_cast<noti_ex_item_h>(
161             new Handle(deletedItem)), user_data_);
162     }
163   }
164
165   void InvokeError(Manager* manager, NotificationError error, int requestId) {
166     if (cb_.error == nullptr)
167       return;
168     cb_.error(static_cast<noti_ex_manager_h>(manager),
169         static_cast<noti_ex_error_e>(error), requestId, user_data_);
170   }
171
172  private:
173   noti_ex_manager_events_s cb_;
174   void* user_data_;
175 };
176
177 class ManagerStub : public Manager {
178  public:
179   ManagerStub(std::unique_ptr<IEventSender> sender,
180       std::unique_ptr<IEventListener> listener, std::string receiver_group = "")
181     : Manager(move(sender), move(listener), receiver_group) {
182   }
183
184   void OnAdd(const IEventInfo& info,
185       list<shared_ptr<AbstractItem>> addedItem) override {
186     cb_->InvokeAdded(this, info, addedItem);
187   }
188
189   void OnUpdate(const IEventInfo& info,
190       std::shared_ptr<item::AbstractItem> updatedItem) override {
191     cb_->InvokeUpdated(this, info, updatedItem);
192   }
193
194   void OnDelete(const IEventInfo& info,
195       shared_ptr<item::AbstractItem> deletedItem) override {
196     cb_->InvokeDeleted(this, info, deletedItem);
197   }
198
199   void OnError(NotificationError error, int requestId) override {
200     cb_->InvokeError(this, error, requestId);
201   }
202
203   int SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo> ci) {
204     cb_ = move(ci);
205     return NOTI_EX_ERROR_NONE;
206   }
207
208   int ClearManagerCallbackInfo() {
209     cb_.reset();
210     return NOTI_EX_ERROR_NONE;
211   }
212
213  private:
214   unique_ptr<ManagerCallbackInfo> cb_;
215 };
216
217
218 class ReporterCallbackInfo {
219  public:
220   ReporterCallbackInfo(noti_ex_reporter_events_s cb, void* user_data)
221     : user_data_(user_data) {
222     cb_.event = cb.event;
223     cb_.error = cb.error;
224   }
225
226   void InvokeEvent(Reporter* reporter, const IEventInfo& info,
227       list<shared_ptr<AbstractItem>> notiList) {
228     if (cb_.event == nullptr)
229       return;
230     noti_ex_item_h* noti_list =
231         (noti_ex_item_h*)calloc(notiList.size(), sizeof(noti_ex_item_h));
232     if (noti_list == nullptr) {
233       LOGE("Out of memory");
234       return;
235     }
236
237     int idx = 0;
238     for (auto& i : notiList) {
239       noti_list[idx++] =
240           static_cast<noti_ex_item_h>(new Handle(i));
241     }
242
243     IEventInfo* c_info = const_cast<IEventInfo*>(&info);
244     cb_.event(static_cast<noti_ex_reporter_h>(reporter),
245         static_cast<noti_ex_event_info_h>(c_info), noti_list,
246         notiList.size(), user_data_);
247     free(noti_list);
248   }
249
250   void InvokeError(Reporter* reporter, NotificationError error, int requestId) {
251     if (cb_.error == nullptr)
252       return;
253     cb_.error(static_cast<noti_ex_reporter_h>(reporter),
254         static_cast<noti_ex_error_e>(error), requestId, user_data_);
255   }
256
257  private:
258   noti_ex_reporter_events_s cb_;
259   void* user_data_;
260 };
261
262 class ReporterStub : public Reporter {
263  public:
264   ReporterStub(std::unique_ptr<IEventSender> sender,
265       std::unique_ptr<IEventListener> listener)
266     : Reporter(move(sender), move(listener)) {
267   }
268
269   void OnEvent(const IEventInfo& info,
270       std::list<std::shared_ptr<item::AbstractItem>> notiList) override {
271     cb_->InvokeEvent(this, info, notiList);
272   }
273
274   void OnError(NotificationError error, int requestId) override {
275     cb_->InvokeError(this, error, requestId);
276   }
277
278   int SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo> ci) {
279     cb_ = move(ci);
280     return NOTI_EX_ERROR_NONE;
281   }
282
283   int ClearReporterCallbackInfo() {
284     cb_.reset();
285     return NOTI_EX_ERROR_NONE;
286   }
287
288  private:
289   unique_ptr<ReporterCallbackInfo> cb_;
290 };
291
292 }  // namespace
293
294 void __noti_ex_free_str_array(char** val, int length) {
295   int i;
296   for (i = 0; i < length ; i++)
297     free(val[i]);
298   free(val);
299 }
300
301 extern "C" EXPORT_API int noti_ex_action_app_control_create(
302     noti_ex_action_h *handle, app_control_h app_control,
303     const char *extra) {
304   if (handle == nullptr || app_control == nullptr) {
305     LOGE("Invalid parameter");
306     return NOTI_EX_ERROR_INVALID_PARAMETER;
307   }
308
309   shared_ptr<AbstractAction>* p;
310
311   if (extra) {
312     p = new (std::nothrow) shared_ptr<AbstractAction>(
313           new (std::nothrow) AppControlAction(app_control, extra));
314   } else {
315     p = new (std::nothrow) shared_ptr<AbstractAction>(
316           new (std::nothrow) AppControlAction(app_control));
317   }
318
319   if (p == nullptr) {
320     LOGE("Out-of-memory");
321     return NOTI_EX_ERROR_OUT_OF_MEMORY;
322   }
323
324   *handle = p;
325
326   return NOTI_EX_ERROR_NONE;
327 }
328
329 extern "C" EXPORT_API int noti_ex_action_app_control_set(
330     noti_ex_action_h handle, app_control_h app_control) {
331   if (handle == nullptr || app_control == nullptr) {
332     LOGE("Invalid parameter");
333     return NOTI_EX_ERROR_INVALID_PARAMETER;
334   }
335
336   shared_ptr<AbstractAction>* ptr =
337       static_cast<shared_ptr<AbstractAction>*>(handle);
338   AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
339   action->SetAppControl(app_control);
340
341   return NOTI_EX_ERROR_NONE;
342 }
343
344 extern "C" EXPORT_API int noti_ex_action_app_control_get(
345     noti_ex_action_h handle, app_control_h *app_control) {
346   if (handle == nullptr || app_control == nullptr) {
347     LOGE("Invalid parameter");
348     return NOTI_EX_ERROR_INVALID_PARAMETER;
349   }
350
351   shared_ptr<AbstractAction>* ptr =
352       static_cast<shared_ptr<AbstractAction>*>(handle);
353   AppControlAction* action = static_cast<AppControlAction*>(ptr->get());
354   *app_control = action->GetAppControl();
355
356   return NOTI_EX_ERROR_NONE;
357 }
358
359 extern "C" EXPORT_API int noti_ex_item_button_create(noti_ex_item_h *handle,
360     const char *id, const char *title) {
361   ButtonItem* p;
362
363   if (handle == nullptr || title == nullptr) {
364     LOGE("Invalid parameter");
365     return NOTI_EX_ERROR_INVALID_PARAMETER;
366   }
367
368   if (id)
369     p = new (std::nothrow) ButtonItem(id, title);
370   else
371     p = new (std::nothrow) ButtonItem(title);
372
373   if (p == nullptr) {
374     LOGE("Out-of-memory");
375     return NOTI_EX_ERROR_OUT_OF_MEMORY;
376   }
377   *handle = new Handle(shared_ptr<AbstractItem>(p));
378
379   return NOTI_EX_ERROR_NONE;
380 }
381
382 extern "C" EXPORT_API int noti_ex_item_button_get_title(noti_ex_item_h handle,
383     char **title) {
384   if (handle == nullptr || title == nullptr) {
385     LOGE("Invalid parameter");
386     return NOTI_EX_ERROR_INVALID_PARAMETER;
387   }
388
389   Handle* sp = static_cast<Handle*>(handle);
390   if (!sp->IsValidType(AbstractItem::Button)) {
391     LOGE("Invalid handle type");
392     return NOTI_EX_ERROR_INVALID_PARAMETER;
393   }
394
395   ButtonItem* p = static_cast<ButtonItem*>(sp->Get());
396   string str;
397   if (p->GetMultiLanguage() != nullptr &&
398       !p->GetMultiLanguage()->GetTranslatedString().empty())
399     str = p->GetMultiLanguage()->GetTranslatedString();
400   else if (!p->GetTitle().empty())
401     str = p->GetTitle();
402
403   *title = strdup(str.c_str());
404   if (*title == nullptr) {
405     LOGE("Out-of-memory");
406     return NOTI_EX_ERROR_OUT_OF_MEMORY;
407   }
408
409   return NOTI_EX_ERROR_NONE;
410 }
411
412 extern "C" EXPORT_API int noti_ex_item_button_set_multi_language_title(
413     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
414   if (handle == nullptr) {
415     LOGE("Invalid parameter");
416     return NOTI_EX_ERROR_INVALID_PARAMETER;
417   }
418
419   Handle* p = static_cast<Handle*>(handle);
420   if (!p->IsValidType(AbstractItem::Button)) {
421     LOGE("Invalid handle type");
422     return NOTI_EX_ERROR_INVALID_PARAMETER;
423   }
424
425   ButtonItem* bi = static_cast<ButtonItem*>(p->Get());
426   if (multi == nullptr) {
427     bi->SetMultiLanguage(nullptr);
428     return NOTI_EX_ERROR_NONE;
429   }
430
431   shared_ptr<MultiLanguage> mul_ptr =
432       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
433
434   mul_ptr->UpdateString();
435   bi->SetMultiLanguage(mul_ptr);
436
437   return NOTI_EX_ERROR_NONE;
438 }
439
440 extern "C" EXPORT_API int noti_ex_item_chat_message_create(
441     noti_ex_item_h *handle, const char *id, noti_ex_item_h name,
442     noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time,
443     noti_ex_item_chat_message_type_e message_type) {
444   if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) {
445     LOGE("Invalid parameter");
446     return NOTI_EX_ERROR_INVALID_PARAMETER;
447   }
448
449   auto* p = new (std::nothrow) ChatMessageItem(id,
450           dynamic_pointer_cast<TextItem>(static_cast<Handle*>(name)->GetPtr()),
451           dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
452           dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
453           dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
454           static_cast<ChatMessageItem::Type>(message_type));
455   if (p == nullptr) {
456     LOGE("Out-of-memory");
457     return NOTI_EX_ERROR_OUT_OF_MEMORY;
458   }
459
460   *handle = new Handle(shared_ptr<AbstractItem>(p));
461
462   return NOTI_EX_ERROR_NONE;
463 }
464
465 extern "C" EXPORT_API int noti_ex_item_chat_message_get_name(
466     noti_ex_item_h handle, noti_ex_item_h *name) {
467   if (handle == nullptr || name == nullptr) {
468     LOGE("Invalid parameter");
469     return NOTI_EX_ERROR_INVALID_PARAMETER;
470   }
471   Handle* h = static_cast<Handle*>(handle);
472   if (!h->IsValidType(AbstractItem::ChatMessage)) {
473     LOGE("Invalid handle type");
474     return NOTI_EX_ERROR_INVALID_PARAMETER;
475   }
476   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
477   *name = new Handle(&(p->GetNameItem()));
478
479   return NOTI_EX_ERROR_NONE;
480 }
481
482 extern "C" EXPORT_API int noti_ex_item_chat_message_get_text(
483     noti_ex_item_h handle, noti_ex_item_h *text) {
484   if (handle == nullptr || text == nullptr) {
485     LOGE("Invalid parameter");
486     return NOTI_EX_ERROR_INVALID_PARAMETER;
487   }
488
489   Handle* h = static_cast<Handle*>(handle);
490   if (!h->IsValidType(AbstractItem::ChatMessage)) {
491     LOGE("Invalid handle type");
492     return NOTI_EX_ERROR_INVALID_PARAMETER;
493   }
494   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
495   *text = new Handle(&(p->GetTextItem()));
496
497   return NOTI_EX_ERROR_NONE;
498 }
499
500 extern "C" EXPORT_API int noti_ex_item_chat_message_get_image(
501     noti_ex_item_h handle, noti_ex_item_h *image) {
502   if (handle == nullptr || image == nullptr) {
503     LOGE("Invalid parameter");
504     return NOTI_EX_ERROR_INVALID_PARAMETER;
505   }
506
507   Handle* h = static_cast<Handle*>(handle);
508   if (!h->IsValidType(AbstractItem::ChatMessage)) {
509     LOGE("Invalid handle type");
510     return NOTI_EX_ERROR_INVALID_PARAMETER;
511   }
512   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
513   *image =  new Handle(&(p->GetImageItem()));
514
515   return NOTI_EX_ERROR_NONE;
516 }
517
518 extern "C" EXPORT_API int noti_ex_item_chat_message_get_time(
519     noti_ex_item_h handle, noti_ex_item_h *time) {
520   if (handle == nullptr || time == nullptr) {
521     LOGE("Invalid parameter");
522     return NOTI_EX_ERROR_INVALID_PARAMETER;
523   }
524
525   Handle* h = static_cast<Handle*>(handle);
526   if (!h->IsValidType(AbstractItem::ChatMessage)) {
527     LOGE("Invalid handle type");
528     return NOTI_EX_ERROR_INVALID_PARAMETER;
529   }
530   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
531   *time = new Handle(&(p->GetTimeItem()));
532
533   return NOTI_EX_ERROR_NONE;
534 }
535
536 extern "C" EXPORT_API int noti_ex_item_chat_message_get_message_type(
537     noti_ex_item_h handle, noti_ex_item_chat_message_type_e *message_type) {
538   if (handle == nullptr || message_type == nullptr) {
539     LOGE("Invalid parameter");
540     return NOTI_EX_ERROR_INVALID_PARAMETER;
541   }
542
543   Handle* h = static_cast<Handle*>(handle);
544   if (!h->IsValidType(AbstractItem::ChatMessage)) {
545     LOGE("Invalid handle type");
546     return NOTI_EX_ERROR_INVALID_PARAMETER;
547   }
548   ChatMessageItem* p = static_cast<ChatMessageItem*>(h->Get());
549   *message_type = (noti_ex_item_chat_message_type_e)(p->GetMessageType());
550
551   return NOTI_EX_ERROR_NONE;
552 }
553
554 extern "C" EXPORT_API int noti_ex_item_checkbox_create(noti_ex_item_h *handle,
555     const char *id, const char *title, bool checked) {
556   CheckBoxItem* p;
557
558   if (handle == nullptr || title == nullptr) {
559     LOGE("Invalid parameter");
560     return NOTI_EX_ERROR_INVALID_PARAMETER;
561   }
562
563   p = new (std::nothrow) CheckBoxItem(id, title, checked);
564   if (p == nullptr) {
565     LOGE("Out-of-memory");
566     return NOTI_EX_ERROR_OUT_OF_MEMORY;
567   }
568
569   *handle = new Handle(shared_ptr<AbstractItem>(p));
570
571   return NOTI_EX_ERROR_NONE;
572 }
573
574 extern "C" EXPORT_API int noti_ex_item_checkbox_get_title(noti_ex_item_h handle,
575     char **title) {
576   if (handle == nullptr || title == nullptr) {
577     LOGE("Invalid parameter");
578     return NOTI_EX_ERROR_INVALID_PARAMETER;
579   }
580   Handle* h = static_cast<Handle*>(handle);
581   if (!h->IsValidType(AbstractItem::CheckBox)) {
582     LOGE("Invalid handle type");
583     return NOTI_EX_ERROR_INVALID_PARAMETER;
584   }
585
586   CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
587   string str;
588   if (p->GetMultiLanguage() != nullptr &&
589     !p->GetMultiLanguage()->GetTranslatedString().empty())
590     str = p->GetMultiLanguage()->GetTranslatedString();
591   else if (!p->GetTitle().empty())
592     str = p->GetTitle();
593
594   *title = strdup(str.c_str());
595   if (*title == nullptr) {
596     LOGE("Out-of-memory");
597     return NOTI_EX_ERROR_OUT_OF_MEMORY;
598   }
599
600   return NOTI_EX_ERROR_NONE;
601 }
602
603 extern "C" EXPORT_API int noti_ex_item_checkbox_set_multi_language_title(
604     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
605   if (handle == nullptr || multi == nullptr) {
606     LOGE("Invalid parameter");
607     return NOTI_EX_ERROR_INVALID_PARAMETER;
608   }
609
610   Handle* p = static_cast<Handle*>(handle);
611   if (!p->IsValidType(AbstractItem::CheckBox)) {
612     LOGE("Invalid handle type");
613     return NOTI_EX_ERROR_INVALID_PARAMETER;
614   }
615
616   CheckBoxItem* ci = static_cast<CheckBoxItem*>(p->Get());
617   if (multi == nullptr) {
618     ci->SetMultiLanguage(nullptr);
619     return NOTI_EX_ERROR_NONE;
620   }
621
622   shared_ptr<MultiLanguage> mul_ptr =
623       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
624   mul_ptr->UpdateString();
625   ci->SetMultiLanguage(mul_ptr);
626
627   return NOTI_EX_ERROR_NONE;
628 }
629
630 extern "C" EXPORT_API int noti_ex_item_checkbox_is_checked(noti_ex_item_h handle,
631     bool *checked) {
632   if (handle == nullptr || checked == 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::CheckBox)) {
638     LOGE("Invalid handle type");
639     return NOTI_EX_ERROR_INVALID_PARAMETER;
640   }
641   CheckBoxItem* p = static_cast<CheckBoxItem*>(h->Get());
642   *checked = p->IsChecked();
643
644   return NOTI_EX_ERROR_NONE;
645 }
646
647 extern "C" EXPORT_API int noti_ex_item_entry_create(noti_ex_item_h *handle,
648     const char *id) {
649   EntryItem* p;
650
651   if (handle == nullptr) {
652     LOGE("Invalid parameter");
653     return NOTI_EX_ERROR_INVALID_PARAMETER;
654   }
655
656   p = new (std::nothrow) EntryItem(id);
657   if (p == nullptr) {
658     LOGE("Out-of-memory");
659     return NOTI_EX_ERROR_OUT_OF_MEMORY;
660   }
661
662   *handle = new Handle(shared_ptr<AbstractItem>(p));
663
664   return NOTI_EX_ERROR_NONE;
665 }
666
667 extern "C" EXPORT_API int noti_ex_item_entry_get_text(noti_ex_item_h handle,
668     char **text) {
669   if (handle == nullptr || text == nullptr) {
670     LOGE("Invalid parameter");
671     return NOTI_EX_ERROR_INVALID_PARAMETER;
672   }
673
674   Handle* h = static_cast<Handle*>(handle);
675   if (!h->IsValidType(AbstractItem::Entry)) {
676     LOGE("Invalid handle type");
677     return NOTI_EX_ERROR_INVALID_PARAMETER;
678   }
679
680   EntryItem* p = static_cast<EntryItem*>(h->Get());
681   string str;
682   if (p->GetMultiLanguage() != nullptr &&
683       !p->GetMultiLanguage()->GetTranslatedString().empty())
684     str = p->GetMultiLanguage()->GetTranslatedString();
685   else if (!p->GetText().empty())
686     str = p->GetText();
687
688   *text = strdup(str.c_str());
689   if (*text == nullptr) {
690     LOGE("Out-of-memory");
691     return NOTI_EX_ERROR_OUT_OF_MEMORY;
692   }
693
694   return NOTI_EX_ERROR_NONE;
695 }
696
697 extern "C" EXPORT_API int noti_ex_item_entry_set_text(noti_ex_item_h handle,
698     const char *text) {
699   if (handle == nullptr || text == nullptr) {
700     LOGE("Invalid parameter");
701     return NOTI_EX_ERROR_INVALID_PARAMETER;
702   }
703   Handle* h = static_cast<Handle*>(handle);
704   if (!h->IsValidType(AbstractItem::Entry)) {
705     LOGE("Invalid handle type");
706     return NOTI_EX_ERROR_INVALID_PARAMETER;
707   }
708   EntryItem* p = static_cast<EntryItem*>(h->Get());
709   p->SetText(std::string(text));
710
711   return NOTI_EX_ERROR_NONE;
712 }
713
714 extern "C" EXPORT_API int noti_ex_item_entry_set_multi_language(
715     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
716   if (handle == nullptr || multi == nullptr) {
717     LOGE("Invalid parameter");
718     return NOTI_EX_ERROR_INVALID_PARAMETER;
719   }
720
721   Handle* p = static_cast<Handle*>(handle);
722   if (!p->IsValidType(AbstractItem::Entry)) {
723     LOGE("Invalid handle type");
724     return NOTI_EX_ERROR_INVALID_PARAMETER;
725   }
726
727   shared_ptr<MultiLanguage> mul_ptr =
728       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
729   EntryItem* ei = static_cast<EntryItem*>(p->Get());
730   ei->SetMultiLanguage(mul_ptr);
731   ei->GetMultiLanguage()->UpdateString();
732
733   return NOTI_EX_ERROR_NONE;
734 }
735
736 extern "C" EXPORT_API int noti_ex_event_info_clone(noti_ex_event_info_h handle,
737                 noti_ex_event_info_h* cloned_handle) {
738   if (handle == nullptr || cloned_handle == nullptr) {
739     LOGE("Invalid parameter");
740     return NOTI_EX_ERROR_INVALID_PARAMETER;
741   }
742
743   Bundle cloned = static_cast<EventInfo*>(handle)->Serialize();
744   EventInfo* info = new EventInfo(cloned);
745   *cloned_handle = info;
746   return NOTI_EX_ERROR_NONE;
747 }
748
749 extern "C" EXPORT_API int noti_ex_event_info_destroy(
750     noti_ex_event_info_h handle) {
751   if (handle == nullptr) {
752     LOGE("Invalid parameter");
753     return NOTI_EX_ERROR_INVALID_PARAMETER;
754   }
755   EventInfo* info = static_cast<EventInfo*>(handle);
756   delete info;
757   return NOTI_EX_ERROR_NONE;
758 }
759
760 extern "C" EXPORT_API int noti_ex_event_info_get_event_type(
761     noti_ex_event_info_h handle, noti_ex_event_info_type_e *event_type) {
762   if (handle == nullptr || event_type == nullptr) {
763     LOGE("Invalid parameter");
764     return NOTI_EX_ERROR_INVALID_PARAMETER;
765   }
766   EventInfo* info = static_cast<EventInfo*>(handle);
767   *event_type = static_cast<noti_ex_event_info_type_e>(info->GetEventType());
768
769   return NOTI_EX_ERROR_NONE;
770 }
771
772 extern "C" EXPORT_API int noti_ex_event_info_get_owner(
773     noti_ex_event_info_h handle, char **owner) {
774   if (handle == nullptr || owner == nullptr) {
775     LOGE("Invalid parameter");
776     return NOTI_EX_ERROR_INVALID_PARAMETER;
777   }
778   EventInfo* info = static_cast<EventInfo*>(handle);
779   *owner = strdup(info->GetOwner().c_str());
780   return NOTI_EX_ERROR_NONE;
781 }
782
783 extern "C" EXPORT_API int noti_ex_event_info_get_channel(
784     noti_ex_event_info_h handle, char **channel) {
785   if (handle == nullptr || channel == nullptr) {
786     LOGE("Invalid parameter");
787     return NOTI_EX_ERROR_INVALID_PARAMETER;
788   }
789   EventInfo* info = static_cast<EventInfo*>(handle);
790   *channel = strdup(info->GetChannel().c_str());
791   return NOTI_EX_ERROR_NONE;
792 }
793
794 extern "C" EXPORT_API int noti_ex_event_info_get_item_id(
795     noti_ex_event_info_h handle, char **item_id) {
796   if (handle == nullptr || item_id == nullptr) {
797     LOGE("Invalid parameter");
798     return NOTI_EX_ERROR_INVALID_PARAMETER;
799   }
800   EventInfo* info = static_cast<EventInfo*>(handle);
801   *item_id = strdup(info->GetItemId().c_str());
802   return NOTI_EX_ERROR_NONE;
803 }
804
805 extern "C" EXPORT_API int noti_ex_event_info_get_request_id(
806     noti_ex_event_info_h handle, int *req_id) {
807   if (handle == nullptr || req_id == nullptr) {
808     LOGE("Invalid parameter");
809     return NOTI_EX_ERROR_INVALID_PARAMETER;
810   }
811   EventInfo* info = static_cast<EventInfo*>(handle);
812   *req_id = info->GetRequestId();
813   return NOTI_EX_ERROR_NONE;
814 }
815
816 extern "C" EXPORT_API int noti_ex_item_group_create(noti_ex_item_h *handle,
817     const char *id) {
818   GroupItem* p;
819
820   if (handle == nullptr) {
821     LOGE("Invalid parameter");
822     return NOTI_EX_ERROR_INVALID_PARAMETER;
823   }
824
825   if (id)
826     p = new (std::nothrow) GroupItem(id);
827   else
828     p = new (std::nothrow) GroupItem();
829
830   if (p == nullptr) {
831     LOGE("Out-of-memory");
832     return NOTI_EX_ERROR_OUT_OF_MEMORY;
833   }
834
835   *handle = new Handle(shared_ptr<AbstractItem>(p));
836
837   return NOTI_EX_ERROR_NONE;
838 }
839
840 extern "C" EXPORT_API int noti_ex_item_group_set_direction(noti_ex_item_h handle,
841     bool vertical) {
842   if (handle == nullptr) {
843     LOGE("Invalid parameter");
844     return NOTI_EX_ERROR_INVALID_PARAMETER;
845   }
846   Handle* h = static_cast<Handle*>(handle);
847   if (!h->IsValidType(AbstractItem::Group)) {
848     LOGE("Invalid handle type");
849     return NOTI_EX_ERROR_INVALID_PARAMETER;
850   }
851   GroupItem* p = static_cast<GroupItem*>(h->Get());
852   p->SetDirection(vertical);
853
854   return NOTI_EX_ERROR_NONE;
855 }
856
857 extern "C" EXPORT_API int noti_ex_item_group_is_vertical(noti_ex_item_h handle,
858     bool *vertical) {
859   if (handle == nullptr) {
860     LOGE("Invalid parameter");
861     return NOTI_EX_ERROR_INVALID_PARAMETER;
862   }
863   Handle* h = static_cast<Handle*>(handle);
864   if (!h->IsValidType(AbstractItem::Group)) {
865     LOGE("Invalid handle type");
866     return NOTI_EX_ERROR_INVALID_PARAMETER;
867   }
868   GroupItem* p = static_cast<GroupItem*>(h->Get());
869   *vertical = p->IsVertical();
870
871   return NOTI_EX_ERROR_NONE;
872 }
873
874 extern "C" EXPORT_API int noti_ex_item_group_get_app_label(noti_ex_item_h handle,
875     char **label) {
876   if (handle == nullptr) {
877     LOGE("Invalid parameter");
878     return NOTI_EX_ERROR_INVALID_PARAMETER;
879   }
880   Handle* h = static_cast<Handle*>(handle);
881   if (!h->IsValidType(AbstractItem::Group)) {
882     LOGE("Invalid handle type");
883     return NOTI_EX_ERROR_INVALID_PARAMETER;
884   }
885   GroupItem* p = static_cast<GroupItem*>(h->Get());
886   if (!p->GetAppLabel().empty()) {
887     *label = strdup(p->GetAppLabel().c_str());
888     if (*label == nullptr) {
889       LOGE("Out-of-memory");
890       return NOTI_EX_ERROR_OUT_OF_MEMORY;
891     }
892   }
893
894   return NOTI_EX_ERROR_NONE;
895 }
896
897 extern "C" EXPORT_API int noti_ex_item_group_add_child(noti_ex_item_h handle,
898     noti_ex_item_h child) {
899   if (handle == nullptr || child == nullptr) {
900     LOGE("Invalid parameter");
901     return NOTI_EX_ERROR_INVALID_PARAMETER;
902   }
903   Handle* h = static_cast<Handle*>(handle);
904   if (!h->IsValidType(AbstractItem::Group)) {
905     LOGE("Invalid handle type");
906     return NOTI_EX_ERROR_INVALID_PARAMETER;
907   }
908   auto p = static_cast<GroupItem*>(h->Get());
909   p->AddChild((static_cast<Handle*>(child))->GetPtr());
910
911   return NOTI_EX_ERROR_NONE;
912 }
913
914 extern "C" EXPORT_API int noti_ex_item_group_remove_child(noti_ex_item_h handle,
915     const char *item_id) {
916   if (handle == nullptr || item_id == nullptr) {
917     LOGE("Invalid parameter");
918     return NOTI_EX_ERROR_INVALID_PARAMETER;
919   }
920   Handle* h = static_cast<Handle*>(handle);
921   if (!h->IsValidType(AbstractItem::Group)) {
922     LOGE("Invalid handle type");
923     return NOTI_EX_ERROR_INVALID_PARAMETER;
924   }
925   GroupItem* p = static_cast<GroupItem*>(h->Get());
926   p->RemoveChild(std::string(item_id));
927
928   return NOTI_EX_ERROR_NONE;
929 }
930
931 extern "C" EXPORT_API int noti_ex_item_group_foreach_child(noti_ex_item_h handle,
932     noti_ex_item_group_foreach_child_cb callback, void *data) {
933   if (handle == nullptr || callback == nullptr) {
934     LOGE("Invalid parameter");
935     return NOTI_EX_ERROR_INVALID_PARAMETER;
936   }
937
938   Handle* h = static_cast<Handle*>(handle);
939   if (!h->IsValidType(AbstractItem::Group)) {
940     LOGE("Invalid handle type");
941     return NOTI_EX_ERROR_INVALID_PARAMETER;
942   }
943   GroupItem* p = static_cast<GroupItem*>(h->Get());
944   list<shared_ptr<AbstractItem>> children = p->GetChildren();
945   LOGI("Retrive (%zd)", children.size());
946   for (auto i : children) {
947     int ret = callback(
948         static_cast<noti_ex_item_h>(new Handle(i)), data);
949     if (ret != NOTI_EX_ERROR_NONE) {
950       LOGW("callback return (%d) stop foreach", ret);
951       break;
952     }
953   }
954
955   return NOTI_EX_ERROR_NONE;
956 }
957
958 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
959     const char *id, const char *image_path) {
960   ImageItem* p;
961
962   if (handle == nullptr  || image_path == nullptr) {
963     LOGE("Invalid parameter");
964     return NOTI_EX_ERROR_INVALID_PARAMETER;
965   }
966
967   if (id)
968     p = new (std::nothrow) ImageItem(id, image_path);
969   else
970     p = new (std::nothrow) ImageItem(image_path);
971
972   if (p == nullptr) {
973     LOGE("Out-of-memory");
974     return NOTI_EX_ERROR_OUT_OF_MEMORY;
975   }
976
977   *handle = new Handle(shared_ptr<AbstractItem>(p));
978
979   return NOTI_EX_ERROR_NONE;
980 }
981
982 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
983     noti_ex_item_h handle, char **image_path) {
984   if (handle == nullptr || image_path == nullptr) {
985     LOGE("Invalid parameter");
986     return NOTI_EX_ERROR_INVALID_PARAMETER;
987   }
988   Handle* h = static_cast<Handle*>(handle);
989   if (!h->IsValidType(AbstractItem::Image)) {
990     LOGE("Invalid handle type");
991     return NOTI_EX_ERROR_INVALID_PARAMETER;
992   }
993   ImageItem* p = static_cast<ImageItem*>(h->Get());
994   if (!p->GetImagePath().empty()) {
995     *image_path = strdup(p->GetImagePath().c_str());
996     if (*image_path == nullptr) {
997       LOGE("Out-of-memory");
998       return NOTI_EX_ERROR_OUT_OF_MEMORY;
999     }
1000   }
1001
1002   return NOTI_EX_ERROR_NONE;
1003 }
1004
1005 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1006     noti_ex_item_h *handle, const char *id) {
1007   InputSelectorItem* p;
1008
1009   if (handle == nullptr) {
1010     LOGE("Invalid parameter");
1011     return NOTI_EX_ERROR_INVALID_PARAMETER;
1012   }
1013
1014   if (id)
1015     p = new (std::nothrow) InputSelectorItem(id);
1016   else
1017     p = new (std::nothrow) InputSelectorItem();
1018
1019   if (p == nullptr) {
1020     LOGE("Out-of-memory");
1021     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1022   }
1023
1024   *handle = new Handle(shared_ptr<AbstractItem>(p));
1025
1026   return NOTI_EX_ERROR_NONE;
1027 }
1028
1029 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1030     noti_ex_item_h handle, char ***contents_list, int *count) {
1031   if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1032     LOGE("Invalid parameter");
1033     return NOTI_EX_ERROR_INVALID_PARAMETER;
1034   }
1035
1036   Handle* h = static_cast<Handle*>(handle);
1037   if (!h->IsValidType(AbstractItem::InputSelector)) {
1038     LOGE("Invalid handle type");
1039     return NOTI_EX_ERROR_INVALID_PARAMETER;
1040   }
1041
1042   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1043   vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1044   list<string> contents;
1045   if (arr.size() == 0) {
1046     contents = p->GetContents();
1047   } else {
1048     for (auto& i : arr) {
1049       contents.push_back(i->GetTranslatedString());
1050     }
1051   }
1052
1053   char **list = (char**)calloc(contents.size(), sizeof(char*));
1054   if (list == nullptr) {
1055     LOGE("Out of memory");
1056     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1057   }
1058
1059   int idx = 0;
1060   for (auto& i : contents) {
1061     list[idx] = strdup(i.c_str());
1062     if (list[idx] == nullptr) {
1063       __noti_ex_free_str_array(list, idx);
1064       LOGE("Out of memory");
1065       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1066     }
1067     idx++;
1068   }
1069
1070   *count = contents.size();
1071   *contents_list = list;
1072
1073   return NOTI_EX_ERROR_NONE;
1074 }
1075
1076 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1077     noti_ex_item_h handle, const char **contents, int count) {
1078   if (handle == nullptr || contents == nullptr) {
1079     LOGE("Invalid parameter");
1080     return NOTI_EX_ERROR_INVALID_PARAMETER;
1081   }
1082
1083   list<string> new_contents;
1084   Handle* h = static_cast<Handle*>(handle);
1085   if (!h->IsValidType(AbstractItem::InputSelector)) {
1086     LOGE("Invalid handle type");
1087     return NOTI_EX_ERROR_INVALID_PARAMETER;
1088   }
1089   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1090   for (int i = 0; i < count; i++) {
1091     new_contents.push_back(contents[i]);
1092   }
1093   p->SetContents(move(new_contents));
1094
1095   return NOTI_EX_ERROR_NONE;
1096 }
1097
1098 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1099     noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1100   if (handle == nullptr) {
1101     LOGE("Invalid parameter");
1102     return NOTI_EX_ERROR_INVALID_PARAMETER;
1103   }
1104
1105   Handle* p = static_cast<Handle*>(handle);
1106   if (!p->IsValidType(AbstractItem::InputSelector)) {
1107     LOGE("Invalid handle type");
1108     return NOTI_EX_ERROR_INVALID_PARAMETER;
1109   }
1110
1111   vector<shared_ptr<MultiLanguage>> m_list;
1112   for (int i = 0; i < count; i++) {
1113     shared_ptr<MultiLanguage> mul_ptr =
1114       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1115     mul_ptr->UpdateString();
1116     m_list.push_back(mul_ptr);
1117   }
1118
1119   InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1120   input->SetMultiLanguage(m_list);
1121
1122   return NOTI_EX_ERROR_NONE;
1123 }
1124
1125 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1126     unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1127   if (handle == nullptr) {
1128     LOGE("Invalid parameter");
1129     return NOTI_EX_ERROR_INVALID_PARAMETER;
1130   }
1131
1132   auto* ptr = new (std::nothrow) shared_ptr<Color>(
1133       new (std::nothrow) Color(a, r, g, b));
1134   if (ptr == nullptr || ptr->get() == nullptr) {
1135     LOGE("Out-of-memory");
1136     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1137   }
1138
1139   *handle = ptr;
1140
1141   return NOTI_EX_ERROR_NONE;
1142 }
1143
1144 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1145   if (handle == nullptr) {
1146     LOGE("Invalid parameter");
1147     return NOTI_EX_ERROR_INVALID_PARAMETER;
1148   }
1149
1150   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1151   delete p;
1152
1153   return NOTI_EX_ERROR_NONE;
1154 }
1155
1156 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1157     unsigned char *val) {
1158   if (handle == nullptr || val == nullptr) {
1159     LOGE("Invalid parameter");
1160     return NOTI_EX_ERROR_INVALID_PARAMETER;
1161   }
1162
1163   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1164   *val = (*p)->GetAVal();
1165
1166   return NOTI_EX_ERROR_NONE;
1167 }
1168
1169 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1170     unsigned char *val) {
1171   if (handle == nullptr || val == nullptr) {
1172     LOGE("Invalid parameter");
1173     return NOTI_EX_ERROR_INVALID_PARAMETER;
1174   }
1175
1176   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1177   *val = (*p)->GetRVal();
1178
1179   return NOTI_EX_ERROR_NONE;
1180 }
1181
1182 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1183     unsigned char *val) {
1184   if (handle == nullptr || val == nullptr) {
1185     LOGE("Invalid parameter");
1186     return NOTI_EX_ERROR_INVALID_PARAMETER;
1187   }
1188
1189   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1190   *val = (*p)->GetGVal();
1191
1192   return NOTI_EX_ERROR_NONE;
1193 }
1194
1195 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1196     unsigned char *val) {
1197   if (handle == nullptr || val == nullptr) {
1198     LOGE("Invalid parameter");
1199     return NOTI_EX_ERROR_INVALID_PARAMETER;
1200   }
1201
1202   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1203   *val = (*p)->GetBVal();
1204
1205   return NOTI_EX_ERROR_NONE;
1206 }
1207
1208 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1209     int left, int top, int right, int bottom) {
1210   if (handle == nullptr) {
1211     LOGE("Invalid parameter");
1212     return NOTI_EX_ERROR_INVALID_PARAMETER;
1213   }
1214
1215   auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1216       new (std::nothrow) Padding(left, top, right, bottom));
1217   if (ptr == nullptr || ptr->get() == nullptr) {
1218     LOGE("Out-of-memory");
1219     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1220   }
1221
1222   *handle = ptr;
1223
1224   return NOTI_EX_ERROR_NONE;
1225 }
1226
1227 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1228   if (handle == nullptr) {
1229     LOGE("Invalid parameter");
1230     return NOTI_EX_ERROR_INVALID_PARAMETER;
1231   }
1232
1233   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1234   delete p;
1235
1236   return NOTI_EX_ERROR_NONE;
1237 }
1238
1239 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1240     int *val) {
1241   if (handle == nullptr || val == nullptr) {
1242     LOGE("Invalid parameter");
1243     return NOTI_EX_ERROR_INVALID_PARAMETER;
1244   }
1245
1246   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1247   *val = (*p)->GetLeft();
1248
1249   return NOTI_EX_ERROR_NONE;
1250 }
1251
1252 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1253     int *val) {
1254   if (handle == nullptr || val == nullptr) {
1255     LOGE("Invalid parameter");
1256     return NOTI_EX_ERROR_INVALID_PARAMETER;
1257   }
1258
1259   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1260   *val = (*p)->GetTop();
1261
1262   return NOTI_EX_ERROR_NONE;
1263 }
1264
1265 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1266     int *val) {
1267   if (handle == nullptr || val == nullptr) {
1268     LOGE("Invalid parameter");
1269     return NOTI_EX_ERROR_INVALID_PARAMETER;
1270   }
1271
1272   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1273   *val = (*p)->GetRight();
1274
1275   return NOTI_EX_ERROR_NONE;
1276 }
1277
1278 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1279     int *val) {
1280   if (handle == nullptr || val == nullptr) {
1281     LOGE("Invalid parameter");
1282     return NOTI_EX_ERROR_INVALID_PARAMETER;
1283   }
1284
1285   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1286   *val = (*p)->GetBottom();
1287
1288   return NOTI_EX_ERROR_NONE;
1289 }
1290
1291 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1292     int x, int y, int w, int h) {
1293   if (handle == nullptr) {
1294     LOGE("Invalid parameter");
1295     return NOTI_EX_ERROR_INVALID_PARAMETER;
1296   }
1297
1298   auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1299       new (std::nothrow) Geometry(x, y, w, h));
1300   if (ptr == nullptr || ptr->get() == nullptr) {
1301     LOGE("Out-of-memory");
1302     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1303   }
1304
1305   *handle = ptr;
1306
1307   return NOTI_EX_ERROR_NONE;
1308 }
1309
1310 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1311   if (handle == nullptr) {
1312     LOGE("Invalid parameter");
1313     return NOTI_EX_ERROR_INVALID_PARAMETER;
1314   }
1315
1316   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1317   delete p;
1318
1319   return NOTI_EX_ERROR_NONE;
1320 }
1321
1322 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1323     int *val) {
1324   if (handle == nullptr || val == nullptr) {
1325     LOGE("Invalid parameter");
1326     return NOTI_EX_ERROR_INVALID_PARAMETER;
1327   }
1328
1329   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1330   *val = (*p)->GetX();
1331
1332   return NOTI_EX_ERROR_NONE;
1333 }
1334
1335 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1336     int *val) {
1337   if (handle == nullptr || val == nullptr) {
1338     LOGE("Invalid parameter");
1339     return NOTI_EX_ERROR_INVALID_PARAMETER;
1340   }
1341
1342   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1343   *val = (*p)->GetY();
1344
1345   return NOTI_EX_ERROR_NONE;
1346 }
1347
1348 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1349     int *val) {
1350   if (handle == nullptr || val == nullptr) {
1351     LOGE("Invalid parameter");
1352     return NOTI_EX_ERROR_INVALID_PARAMETER;
1353   }
1354
1355   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1356   *val = (*p)->GetWidth();
1357
1358   return NOTI_EX_ERROR_NONE;
1359 }
1360
1361 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1362     int *val) {
1363   if (handle == nullptr || val == nullptr) {
1364     LOGE("Invalid parameter");
1365     return NOTI_EX_ERROR_INVALID_PARAMETER;
1366   }
1367
1368   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1369   *val = (*p)->GetHeight();
1370
1371   return NOTI_EX_ERROR_NONE;
1372 }
1373
1374 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1375     noti_ex_color_h color,
1376     noti_ex_padding_h padding,
1377     noti_ex_geometry_h geometry) {
1378   if (handle == nullptr) {
1379     LOGE("Invalid parameter");
1380     return NOTI_EX_ERROR_INVALID_PARAMETER;
1381   }
1382
1383   shared_ptr<Color> col = (color == nullptr) ?
1384       nullptr : *(static_cast<shared_ptr<Color>*>(color));
1385   shared_ptr<Padding> padd = (padding == nullptr) ?
1386       nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1387   shared_ptr<Geometry> geo = (geometry == nullptr) ?
1388       nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1389
1390   auto* ptr = new (std::nothrow) shared_ptr<Style>(
1391       new (std::nothrow) Style(col, padd, geo));
1392   if (ptr == nullptr || ptr->get() == nullptr) {
1393     LOGE("Out-of-memory");
1394     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1395   }
1396
1397   *handle = ptr;
1398
1399   return NOTI_EX_ERROR_NONE;
1400 }
1401
1402 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1403   if (handle == nullptr) {
1404     LOGE("Invalid parameter");
1405     return NOTI_EX_ERROR_INVALID_PARAMETER;
1406   }
1407
1408   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1409   delete p;
1410
1411   return NOTI_EX_ERROR_NONE;
1412 }
1413
1414 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1415     noti_ex_padding_h *padding) {
1416   if (handle == nullptr || padding == nullptr) {
1417     LOGE("Invalid parameter");
1418     return NOTI_EX_ERROR_INVALID_PARAMETER;
1419   }
1420
1421   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1422   if ((*p)->GetPadding() == nullptr) {
1423     LOGW("Padding info is null");
1424     return NOTI_EX_ERROR_INVALID_PARAMETER;
1425   }
1426
1427   shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1428       new (std::nothrow) Padding(*((*p)->GetPadding())));
1429   if (padd == nullptr || padd->get() == nullptr) {
1430     LOGE("Out-of-memory");
1431     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1432   }
1433
1434   *padding = padd;
1435
1436   return NOTI_EX_ERROR_NONE;
1437 }
1438
1439 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1440     noti_ex_color_h *color) {
1441   if (handle == nullptr || color == nullptr) {
1442     LOGE("Invalid parameter");
1443     return NOTI_EX_ERROR_INVALID_PARAMETER;
1444   }
1445
1446   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1447   if ((*p)->GetColor() == nullptr) {
1448     LOGW("Color info is null");
1449     return NOTI_EX_ERROR_INVALID_PARAMETER;
1450   }
1451
1452   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1453       new (std::nothrow) Color(*((*p)->GetColor())));
1454   if (col == nullptr || col->get() == nullptr) {
1455     LOGE("Out-of-memory");
1456     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1457   }
1458
1459   *color = col;
1460
1461   return NOTI_EX_ERROR_NONE;
1462 }
1463
1464 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1465     noti_ex_geometry_h *geometry) {
1466   if (handle == nullptr || geometry == nullptr) {
1467     LOGE("Invalid parameter");
1468     return NOTI_EX_ERROR_INVALID_PARAMETER;
1469   }
1470
1471   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1472   if ((*p)->GetGeometry() == nullptr) {
1473     LOGW("Geometry info is null");
1474     return NOTI_EX_ERROR_INVALID_PARAMETER;
1475   }
1476
1477   shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1478       new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1479   if (geo == nullptr || geo->get() == nullptr) {
1480     LOGE("Out-of-memory");
1481     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1482   }
1483
1484   *geometry = geo;
1485
1486   return NOTI_EX_ERROR_NONE;
1487 }
1488
1489 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1490     noti_ex_style_h handle, char** background_image) {
1491   if (handle == nullptr || background_image == nullptr) {
1492     LOGE("Invalid parameter");
1493     return NOTI_EX_ERROR_INVALID_PARAMETER;
1494   }
1495
1496   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1497   *background_image = strdup((*p)->GetBackgroundImage().c_str());
1498
1499   return NOTI_EX_ERROR_NONE;
1500 }
1501
1502 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1503     noti_ex_style_h handle, char* background_image) {
1504   if (handle == nullptr || background_image == nullptr) {
1505     LOGE("Invalid parameter");
1506     return NOTI_EX_ERROR_INVALID_PARAMETER;
1507   }
1508
1509   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1510   (*p)->SetBackgroundImage(background_image);
1511
1512   return NOTI_EX_ERROR_NONE;
1513 }
1514
1515 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1516     noti_ex_style_h handle, noti_ex_color_h* color) {
1517   if (handle == nullptr || color == nullptr) {
1518     LOGE("Invalid parameter");
1519     return NOTI_EX_ERROR_INVALID_PARAMETER;
1520   }
1521
1522   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1523   if ((*p)->GetBackgroundColor() == nullptr) {
1524     LOGW("Color info is null");
1525     return NOTI_EX_ERROR_INVALID_PARAMETER;
1526   }
1527
1528   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1529       new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1530   if (col == nullptr || col->get() == nullptr) {
1531     LOGE("Out-of-memory");
1532     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1533   }
1534
1535   *color = col;
1536
1537   return NOTI_EX_ERROR_NONE;
1538 }
1539
1540 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1541     noti_ex_style_h handle, noti_ex_color_h color) {
1542   if (handle == nullptr || color == nullptr) {
1543     LOGE("Invalid parameter");
1544     return NOTI_EX_ERROR_INVALID_PARAMETER;
1545   }
1546
1547   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1548   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1549   (*p)->SetBackgroundColor(*col);
1550
1551   return NOTI_EX_ERROR_NONE;
1552 }
1553
1554 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1555     noti_ex_color_h color) {
1556   if (handle == nullptr) {
1557     LOGE("Invalid parameter");
1558     return NOTI_EX_ERROR_INVALID_PARAMETER;
1559   }
1560
1561   shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1562   shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1563       new (std::nothrow) LEDInfo(*color_ptr));
1564   if (p == nullptr) {
1565     LOGE("Out-of-memory");
1566     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1567   }
1568
1569   *handle = p;
1570
1571   return NOTI_EX_ERROR_NONE;
1572 }
1573
1574 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1575   if (handle == nullptr) {
1576     LOGE("Invalid parameter");
1577     return NOTI_EX_ERROR_INVALID_PARAMETER;
1578   }
1579
1580   shared_ptr<LEDInfo>* led_ptr =
1581       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1582   delete led_ptr;
1583   return NOTI_EX_ERROR_NONE;
1584 }
1585
1586 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1587     noti_ex_led_info_h handle, int ms) {
1588   if (handle == nullptr) {
1589     LOGE("Invalid parameter");
1590     return NOTI_EX_ERROR_INVALID_PARAMETER;
1591   }
1592
1593   shared_ptr<LEDInfo>* led_ptr =
1594       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1595   (*led_ptr)->SetOnPeriod(ms);
1596
1597   return NOTI_EX_ERROR_NONE;
1598 }
1599
1600 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1601     noti_ex_led_info_h handle, int *ms) {
1602   if (handle == nullptr || ms == nullptr) {
1603     LOGE("Invalid parameter");
1604     return NOTI_EX_ERROR_INVALID_PARAMETER;
1605   }
1606
1607   shared_ptr<LEDInfo>* led_ptr =
1608       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1609   *ms = (*led_ptr)->GetOnPeriod();
1610
1611   return NOTI_EX_ERROR_NONE;
1612 }
1613
1614 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1615     noti_ex_led_info_h handle, int ms) {
1616   if (handle == nullptr) {
1617     LOGE("Invalid parameter");
1618     return NOTI_EX_ERROR_INVALID_PARAMETER;
1619   }
1620
1621   shared_ptr<LEDInfo>* led_ptr =
1622       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1623   (*led_ptr)->SetOffPeriod(ms);
1624
1625   return NOTI_EX_ERROR_NONE;
1626 }
1627
1628 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1629     noti_ex_led_info_h handle, int *ms) {
1630   if (handle == nullptr) {
1631     LOGE("Invalid parameter");
1632     return NOTI_EX_ERROR_INVALID_PARAMETER;
1633   }
1634
1635   shared_ptr<LEDInfo>* led_ptr =
1636       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1637   *ms = (*led_ptr)->GetOffPeriod();
1638
1639   return NOTI_EX_ERROR_NONE;
1640 }
1641
1642 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1643     noti_ex_led_info_h handle, noti_ex_color_h *color) {
1644   if (handle == nullptr) {
1645     LOGE("Invalid parameter");
1646     return NOTI_EX_ERROR_INVALID_PARAMETER;
1647   }
1648
1649   shared_ptr<LEDInfo>* led_ptr =
1650       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1651   if ((*led_ptr)->GetColor() == nullptr) {
1652     LOGE("Color is null");
1653     return NOTI_EX_ERROR_INVALID_PARAMETER;
1654   }
1655
1656   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1657       new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1658   if (col == nullptr || col->get() == nullptr) {
1659     LOGE("Out-of-memory");
1660     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1661   }
1662
1663   *color = col;
1664
1665   return NOTI_EX_ERROR_NONE;
1666 }
1667
1668 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1669   if (handle == nullptr) {
1670     LOGE("Invalid parameter");
1671     return NOTI_EX_ERROR_INVALID_PARAMETER;
1672   }
1673
1674   shared_ptr<AbstractAction>* ptr =
1675       static_cast<shared_ptr<AbstractAction>*>(handle);
1676   delete ptr;
1677
1678   return NOTI_EX_ERROR_NONE;
1679 }
1680
1681 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1682     int *type) {
1683   if (handle == nullptr || type == nullptr) {
1684     LOGE("Invalid parameter");
1685     return NOTI_EX_ERROR_INVALID_PARAMETER;
1686   }
1687
1688   shared_ptr<AbstractAction>* ptr =
1689       static_cast<shared_ptr<AbstractAction>*>(handle);
1690   *type = (*ptr)->GetType();
1691
1692   return NOTI_EX_ERROR_NONE;
1693 }
1694
1695 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1696     bool *local) {
1697   if (handle == nullptr || local == nullptr) {
1698     LOGE("Invalid parameter");
1699     return NOTI_EX_ERROR_INVALID_PARAMETER;
1700   }
1701
1702   shared_ptr<AbstractAction>* ptr =
1703       static_cast<shared_ptr<AbstractAction>*>(handle);
1704   *local = (*ptr)->IsLocal();
1705
1706   return NOTI_EX_ERROR_NONE;
1707 }
1708
1709 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1710     noti_ex_item_h item) {
1711   if (handle == nullptr || item == nullptr) {
1712     LOGE("Invalid parameter");
1713     return NOTI_EX_ERROR_INVALID_PARAMETER;
1714   }
1715   shared_ptr<AbstractAction>* ptr =
1716       static_cast<shared_ptr<AbstractAction>*>(handle);
1717   Handle* ih = static_cast<Handle*>(item);
1718   (*ptr)->Execute(ih->GetPtr());
1719
1720   return NOTI_EX_ERROR_NONE;
1721 }
1722
1723 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1724     char **extra) {
1725   if (handle == nullptr || extra == nullptr) {
1726     LOGE("Invalid parameter");
1727     return NOTI_EX_ERROR_INVALID_PARAMETER;
1728   }
1729
1730   shared_ptr<AbstractAction>* ptr =
1731       static_cast<shared_ptr<AbstractAction>*>(handle);
1732   if (!(*ptr)->GetExtra().empty()) {
1733     *extra = strdup((*ptr)->GetExtra().c_str());
1734     if (*extra == nullptr) {
1735       LOGE("Out-of-memory");
1736       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1737     }
1738   }
1739
1740   return NOTI_EX_ERROR_NONE;
1741 }
1742
1743 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1744     noti_ex_item_info_h handle, int *hide_time) {
1745   if (handle == nullptr || hide_time == nullptr) {
1746     LOGE("Invalid parameter");
1747     return NOTI_EX_ERROR_INVALID_PARAMETER;
1748   }
1749   IItemInfo* p = static_cast<IItemInfo*>(handle);
1750   *hide_time = p->GetHideTime();
1751   return NOTI_EX_ERROR_NONE;
1752 }
1753
1754 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1755     noti_ex_item_info_h handle, int hide_time) {
1756   if (handle == nullptr) {
1757     LOGE("Invalid parameter");
1758     return NOTI_EX_ERROR_INVALID_PARAMETER;
1759   }
1760   IItemInfo* p = static_cast<IItemInfo*>(handle);
1761   p->SetHideTime(hide_time);
1762   return NOTI_EX_ERROR_NONE;
1763 }
1764
1765 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
1766     noti_ex_item_info_h handle, int *delete_time) {
1767   if (handle == nullptr || delete_time == nullptr) {
1768     LOGE("Invalid parameter");
1769     return NOTI_EX_ERROR_INVALID_PARAMETER;
1770   }
1771   IItemInfo* p = static_cast<IItemInfo*>(handle);
1772   *delete_time = p->GetDeleteTime();
1773   return NOTI_EX_ERROR_NONE;
1774 }
1775
1776 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
1777     noti_ex_item_info_h handle, int delete_time) {
1778   if (handle == nullptr) {
1779     LOGE("Invalid parameter");
1780     return NOTI_EX_ERROR_INVALID_PARAMETER;
1781   }
1782   IItemInfo* p = static_cast<IItemInfo*>(handle);
1783   p->SetDeleteTime(delete_time);
1784   return NOTI_EX_ERROR_NONE;
1785 }
1786
1787 extern "C" EXPORT_API int noti_ex_item_info_get_time(
1788     noti_ex_item_info_h handle, time_t *time) {
1789   if (handle == nullptr || time == nullptr) {
1790     LOGE("Invalid parameter");
1791     return NOTI_EX_ERROR_INVALID_PARAMETER;
1792   }
1793
1794   IItemInfo* p = static_cast<IItemInfo*>(handle);
1795   *time = p->GetTime();
1796   return NOTI_EX_ERROR_NONE;
1797 }
1798
1799 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
1800   if (handle == nullptr) {
1801     LOGE("Invalid parameter");
1802     return NOTI_EX_ERROR_INVALID_PARAMETER;
1803   }
1804
1805   Handle* h = static_cast<Handle*>(handle);
1806   delete h;
1807   return NOTI_EX_ERROR_NONE;
1808 }
1809
1810 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
1811     const char *id, noti_ex_item_h *item) {
1812   if (handle == nullptr) {
1813     LOGE("Invalid parameter");
1814     return NOTI_EX_ERROR_INVALID_PARAMETER;
1815   }
1816
1817   Handle* p = static_cast<Handle*>(handle);
1818   AbstractItem& find_item = p->Get()->FindByID(string(id));
1819   *item = new Handle(&find_item);
1820   return NOTI_EX_ERROR_NONE;
1821 }
1822
1823 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
1824     int *type) {
1825   if (handle == nullptr || type == nullptr) {
1826     LOGE("Invalid parameter");
1827     return NOTI_EX_ERROR_INVALID_PARAMETER;
1828   }
1829
1830   Handle* h = static_cast<Handle*>(handle);
1831   AbstractItem* p = h->Get();
1832   *type = p->GetType();
1833   return NOTI_EX_ERROR_NONE;
1834 }
1835
1836 extern "C" EXPORT_API int noti_ex_item_get_shared_paths(noti_ex_item_h handle,
1837     char ***path, int *count) {
1838   if (handle == nullptr || path == nullptr || count == nullptr) {
1839     LOGE("Invalid parameter");
1840     return NOTI_EX_ERROR_INVALID_PARAMETER;
1841   }
1842   Handle* p = static_cast<Handle*>(handle);
1843   list<string> shared_path = p->Get()->GetSharedPath();
1844   char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1845   if (tmp_path == nullptr) {
1846     LOGE("Fail to create items");
1847     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1848   }
1849
1850   int idx = 0;
1851   for (auto& i : shared_path) {
1852     tmp_path[idx] = strdup(i.c_str());
1853     if (tmp_path[idx] == nullptr) {
1854       __noti_ex_free_str_array(tmp_path, idx);
1855       LOGE("Out of memory");
1856       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1857     }
1858     idx++;
1859   }
1860
1861   *path = tmp_path;
1862   *count = shared_path.size();
1863   return NOTI_EX_ERROR_NONE;
1864 }
1865
1866 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
1867     char **id) {
1868   if (handle == nullptr || id == nullptr) {
1869     LOGE("Invalid parameter");
1870     return NOTI_EX_ERROR_INVALID_PARAMETER;
1871   }
1872   Handle* h = static_cast<Handle*>(handle);
1873   AbstractItem* p = h->Get();
1874   *id = strdup(p->GetId().c_str());
1875   return NOTI_EX_ERROR_NONE;
1876 }
1877
1878 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
1879     const char *id) {
1880   if (handle == nullptr || id == nullptr) {
1881     LOGE("Invalid parameter");
1882     return NOTI_EX_ERROR_INVALID_PARAMETER;
1883   }
1884   Handle* p = static_cast<Handle*>(handle);
1885   p->Get()->SetId(id);
1886   return NOTI_EX_ERROR_NONE;
1887 }
1888
1889 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
1890     noti_ex_action_h *action) {
1891   if (handle == nullptr || action == nullptr) {
1892     LOGE("Invalid parameter");
1893     return NOTI_EX_ERROR_INVALID_PARAMETER;
1894   }
1895   Handle* p = static_cast<Handle*>(handle);
1896   if (p->Get()->GetAction() == nullptr) {
1897     *action = nullptr;
1898     return NOTI_EX_ERROR_NONE;
1899   }
1900   *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
1901       p->Get()->GetAction()));
1902
1903   return NOTI_EX_ERROR_NONE;
1904 }
1905
1906 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
1907     noti_ex_action_h action) {
1908   if (handle == nullptr || action == nullptr) {
1909     LOGE("Invalid parameter");
1910     return NOTI_EX_ERROR_INVALID_PARAMETER;
1911   }
1912
1913   Handle* p = static_cast<Handle*>(handle);
1914
1915   shared_ptr<AbstractAction>* ptr =
1916       static_cast<shared_ptr<AbstractAction>*>(action);
1917   p->Get()->SetAction(*ptr);
1918   return NOTI_EX_ERROR_NONE;
1919 }
1920
1921 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
1922     noti_ex_style_h *style) {
1923   if (handle == nullptr || style == nullptr) {
1924     LOGE("Invalid parameter");
1925     return NOTI_EX_ERROR_INVALID_PARAMETER;
1926   }
1927
1928   Handle* p = static_cast<Handle*>(handle);
1929   shared_ptr<Style> s = p->Get()->GetStyle();
1930   if (s.get() == nullptr) {
1931     LOGE("Style is null");
1932     return NOTI_EX_ERROR_INVALID_PARAMETER;
1933   }
1934
1935   auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
1936   if (ptr == nullptr || ptr->get() == nullptr) {
1937     LOGE("Out of memory");
1938     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1939   }
1940
1941   *style = ptr;
1942   return NOTI_EX_ERROR_NONE;
1943 }
1944
1945 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
1946     noti_ex_style_h style) {
1947   if (handle == nullptr || style == nullptr) {
1948     LOGE("Invalid parameter");
1949     return NOTI_EX_ERROR_INVALID_PARAMETER;
1950   }
1951
1952   Handle* p = static_cast<Handle*>(handle);
1953   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
1954   p->Get()->SetStyle(*s);
1955   return NOTI_EX_ERROR_NONE;
1956 }
1957
1958 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
1959     bool visible) {
1960   if (handle == nullptr) {
1961     LOGE("Invalid parameter");
1962     return NOTI_EX_ERROR_INVALID_PARAMETER;
1963   }
1964
1965   Handle* p = static_cast<Handle*>(handle);
1966   p->Get()->SetVisible(visible);
1967   return NOTI_EX_ERROR_NONE;
1968 }
1969
1970 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
1971     bool *visible) {
1972   if (handle == nullptr || visible == nullptr) {
1973     LOGE("Invalid parameter");
1974     return NOTI_EX_ERROR_INVALID_PARAMETER;
1975   }
1976
1977   Handle* p = static_cast<Handle*>(handle);
1978   *visible = p->Get()->GetVisible();
1979   return NOTI_EX_ERROR_NONE;
1980 }
1981
1982 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
1983     bool enable) {
1984   if (handle == nullptr) {
1985     LOGE("Invalid parameter");
1986     return NOTI_EX_ERROR_INVALID_PARAMETER;
1987   }
1988
1989   Handle* p = static_cast<Handle*>(handle);
1990   p->Get()->SetEnable(enable);
1991   return NOTI_EX_ERROR_NONE;
1992 }
1993
1994 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
1995     bool *enable) {
1996   if (handle == nullptr || enable == nullptr) {
1997     LOGE("Invalid parameter");
1998     return NOTI_EX_ERROR_INVALID_PARAMETER;
1999   }
2000
2001   Handle* p = static_cast<Handle*>(handle);
2002   *enable = p->Get()->GetEnable();
2003   return NOTI_EX_ERROR_NONE;
2004 }
2005
2006 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2007     const char *receiver_group) {
2008   if (handle == nullptr || receiver_group == nullptr) {
2009     LOGE("Invalid parameter");
2010     return NOTI_EX_ERROR_INVALID_PARAMETER;
2011   }
2012
2013   Handle* p = static_cast<Handle*>(handle);
2014   p->Get()->AddReceiver(receiver_group);
2015   return NOTI_EX_ERROR_NONE;
2016 }
2017
2018 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2019     const char *receiver_group) {
2020   if (handle == nullptr || receiver_group == nullptr) {
2021     LOGE("Invalid parameter");
2022     return NOTI_EX_ERROR_INVALID_PARAMETER;
2023   }
2024
2025   Handle* p = static_cast<Handle*>(handle);
2026   p->Get()->RemoveReceiver(receiver_group);
2027   return NOTI_EX_ERROR_NONE;
2028 }
2029
2030 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2031     char ***receiver_list, int *count) {
2032   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2033     LOGE("Invalid parameter");
2034     return NOTI_EX_ERROR_INVALID_PARAMETER;
2035   }
2036
2037   Handle* p = static_cast<Handle*>(handle);
2038   list<string> receivers = p->Get()->GetReceiverList();
2039   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2040   if (tmp_list == nullptr) {
2041     LOGE("Out of memory");
2042     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2043   }
2044
2045   int idx = 0;
2046   for (auto& i : receivers) {
2047     tmp_list[idx] = strdup(i.c_str());
2048     if (tmp_list[idx] == nullptr) {
2049       __noti_ex_free_str_array(tmp_list, idx);
2050       LOGE("Out of memory");
2051       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2052     }
2053     idx++;
2054   }
2055
2056   *receiver_list = tmp_list;
2057   *count = receivers.size();
2058   return NOTI_EX_ERROR_NONE;
2059 }
2060
2061 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2062     int policy) {
2063   if (handle == nullptr) {
2064     LOGE("Invalid parameter");
2065     return NOTI_EX_ERROR_INVALID_PARAMETER;
2066   }
2067
2068   Handle* p = static_cast<Handle*>(handle);
2069   p->Get()->SetPolicy(policy);
2070   return NOTI_EX_ERROR_NONE;
2071 }
2072
2073 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2074     int *policy) {
2075   if (handle == nullptr || policy == nullptr) {
2076     LOGE("Invalid parameter");
2077     return NOTI_EX_ERROR_INVALID_PARAMETER;
2078   }
2079
2080   Handle* p = static_cast<Handle*>(handle);
2081   *policy = p->Get()->GetPolicy();
2082   return NOTI_EX_ERROR_NONE;
2083 }
2084
2085 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2086     char **channel) {
2087   if (handle == nullptr || channel == nullptr) {
2088     LOGE("Invalid parameter");
2089     return NOTI_EX_ERROR_INVALID_PARAMETER;
2090   }
2091
2092   Handle* p = static_cast<Handle*>(handle);
2093   if (!p->Get()->GetChannel().empty())
2094     *channel = strdup(p->Get()->GetChannel().c_str());
2095   else
2096     *channel = nullptr;
2097
2098   return NOTI_EX_ERROR_NONE;
2099 }
2100
2101 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2102     const char *channel) {
2103   if (handle == nullptr) {
2104     LOGE("Invalid parameter");
2105     return NOTI_EX_ERROR_INVALID_PARAMETER;
2106   }
2107
2108   Handle* p = static_cast<Handle*>(handle);
2109   p->Get()->SetChannel(channel);
2110   return NOTI_EX_ERROR_NONE;
2111 }
2112
2113 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2114     noti_ex_led_info_h led) {
2115   if (handle == nullptr) {
2116     LOGE("Invalid parameter");
2117     return NOTI_EX_ERROR_INVALID_PARAMETER;
2118   }
2119
2120   Handle* p = static_cast<Handle*>(handle);
2121   shared_ptr<LEDInfo>* led_ptr =
2122       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2123   p->Get()->SetLEDInfo(*led_ptr);
2124   return NOTI_EX_ERROR_NONE;
2125 }
2126
2127 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2128     noti_ex_led_info_h *led) {
2129   if (handle == nullptr) {
2130     LOGE("Invalid parameter");
2131     return NOTI_EX_ERROR_INVALID_PARAMETER;
2132   }
2133
2134   Handle* p = static_cast<Handle*>(handle);
2135   if (p->Get()->GetLEDInfo() != nullptr)
2136     *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2137   else
2138     *led = nullptr;
2139   return NOTI_EX_ERROR_NONE;
2140 }
2141
2142 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2143     const char *path) {
2144   if (handle == nullptr) {
2145     LOGE("Invalid parameter");
2146     return NOTI_EX_ERROR_INVALID_PARAMETER;
2147   }
2148
2149   Handle* p = static_cast<Handle*>(handle);
2150   if (path == nullptr)
2151     p->Get()->SetSoundPath("");
2152   else
2153     p->Get()->SetSoundPath(path);
2154   return NOTI_EX_ERROR_NONE;
2155 }
2156
2157 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2158     const char *path) {
2159   if (handle == nullptr) {
2160     LOGE("Invalid parameter");
2161     return NOTI_EX_ERROR_INVALID_PARAMETER;
2162   }
2163
2164   Handle* p = static_cast<Handle*>(handle);
2165   if (path == nullptr)
2166     p->Get()->SetVibrationPath("");
2167   else
2168     p->Get()->SetVibrationPath(path);
2169   return NOTI_EX_ERROR_NONE;
2170 }
2171
2172 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2173     char **path) {
2174   if (handle == nullptr || path == nullptr) {
2175     LOGE("Invalid parameter");
2176     return NOTI_EX_ERROR_INVALID_PARAMETER;
2177   }
2178
2179   Handle* p = static_cast<Handle*>(handle);
2180   if (p->Get()->GetSoundPath().empty())
2181     *path = nullptr;
2182   else
2183     *path = strdup(p->Get()->GetSoundPath().c_str());
2184   return NOTI_EX_ERROR_NONE;
2185 }
2186
2187 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2188     char **path) {
2189   if (handle == nullptr || path == nullptr) {
2190     LOGE("Invalid parameter");
2191     return NOTI_EX_ERROR_INVALID_PARAMETER;
2192   }
2193
2194   Handle* p = static_cast<Handle*>(handle);
2195   if (p->Get()->GetVibrationPath().empty())
2196     *path = nullptr;
2197   else
2198     *path = strdup(p->Get()->GetVibrationPath().c_str());
2199   return NOTI_EX_ERROR_NONE;
2200 }
2201
2202 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2203     noti_ex_item_info_h *info) {
2204   if (handle == nullptr || info == nullptr) {
2205     LOGE("Invalid parameter");
2206     return NOTI_EX_ERROR_INVALID_PARAMETER;
2207   }
2208
2209   Handle* p = static_cast<Handle*>(handle);
2210   if (p->Get()->GetInfo() == nullptr)
2211     *info = nullptr;
2212   else
2213     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2214   return NOTI_EX_ERROR_NONE;
2215 }
2216
2217 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2218     char **id) {
2219   if (handle == nullptr || id == nullptr) {
2220     LOGE("Invalid parameter");
2221     return NOTI_EX_ERROR_INVALID_PARAMETER;
2222   }
2223
2224   Handle* p = static_cast<Handle*>(handle);
2225   if (p->Get()->GetSenderAppId().empty())
2226     *id = nullptr;
2227   else
2228     *id = strdup(p->Get()->GetSenderAppId().c_str());
2229   return NOTI_EX_ERROR_NONE;
2230 }
2231
2232 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2233     char **tag) {
2234   if (handle == nullptr || tag == nullptr) {
2235     LOGE("Invalid parameter");
2236     return NOTI_EX_ERROR_INVALID_PARAMETER;
2237   }
2238
2239   Handle* p = static_cast<Handle*>(handle);
2240   if (p->Get()->GetTag().empty())
2241     *tag = nullptr;
2242   else
2243     *tag = strdup(p->Get()->GetTag().c_str());
2244   return NOTI_EX_ERROR_NONE;
2245 }
2246
2247 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2248     const char *tag) {
2249   if (handle == nullptr) {
2250     LOGE("Invalid parameter");
2251     return NOTI_EX_ERROR_INVALID_PARAMETER;
2252   }
2253
2254   Handle* p = static_cast<Handle*>(handle);
2255   if (tag == nullptr)
2256     p->Get()->SetTag("");
2257   else
2258     p->Get()->SetTag(tag);
2259   return NOTI_EX_ERROR_NONE;
2260 }
2261
2262 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2263     bool* ongoing) {
2264   if (handle == nullptr || ongoing == nullptr) {
2265     LOGE("Invalid parameter");
2266     return NOTI_EX_ERROR_INVALID_PARAMETER;
2267   }
2268
2269   Handle* p = static_cast<Handle*>(handle);
2270   *ongoing = p->Get()->GetOnGoingState();
2271
2272   return NOTI_EX_ERROR_NONE;
2273 }
2274
2275 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2276     bool ongoing) {
2277   if (handle == nullptr) {
2278     LOGE("Invalid parameter");
2279     return NOTI_EX_ERROR_INVALID_PARAMETER;
2280   }
2281
2282   Handle* p = static_cast<Handle*>(handle);
2283   p->Get()->SetOnGoingState(ongoing);
2284
2285   return NOTI_EX_ERROR_NONE;
2286 }
2287
2288 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2289     int type, bool* exist) {
2290   if (handle == nullptr || exist == nullptr) {
2291     LOGE("Invalid parameter");
2292     return NOTI_EX_ERROR_INVALID_PARAMETER;
2293   }
2294
2295   Handle* p = static_cast<Handle*>(handle);
2296   *exist = p->Get()->IsItemTypeExist(type);
2297
2298   return NOTI_EX_ERROR_NONE;
2299 }
2300
2301 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2302     int* type) {
2303   if (handle == nullptr || type == nullptr) {
2304     LOGE("Invalid parameter");
2305     return NOTI_EX_ERROR_INVALID_PARAMETER;
2306   }
2307
2308   Handle* p = static_cast<Handle*>(handle);
2309   *type = p->Get()->GetMainType();
2310
2311   return NOTI_EX_ERROR_NONE;
2312 }
2313
2314 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2315     const char* id, int type) {
2316   if (handle == nullptr || id == nullptr) {
2317     LOGE("Invalid parameter");
2318     return NOTI_EX_ERROR_INVALID_PARAMETER;
2319   }
2320
2321   Handle* p = static_cast<Handle*>(handle);
2322   if (!(p->Get()->SetMainType(string(id),
2323                     static_cast<AbstractItem::MainType>(type))))
2324     return NOTI_EX_ERROR_INVALID_PARAMETER;
2325
2326   return NOTI_EX_ERROR_NONE;
2327 }
2328
2329 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2330     int type, noti_ex_item_h* item) {
2331   if (handle == nullptr || item == nullptr) {
2332     LOGE("Invalid parameter");
2333     return NOTI_EX_ERROR_INVALID_PARAMETER;
2334   }
2335
2336   Handle* h = static_cast<Handle*>(handle);
2337   if (!h->IsValidType(AbstractItem::Group)) {
2338     LOGE("Invalid handle type");
2339     return NOTI_EX_ERROR_INVALID_PARAMETER;
2340   }
2341
2342   GroupItem* p = static_cast<GroupItem*>(h->Get());
2343   AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2344   *item = new Handle(&find_item);
2345
2346   return NOTI_EX_ERROR_NONE;
2347 }
2348
2349 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2350     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2351     void *data) {
2352   if (handle == nullptr) {
2353     LOGE("Invalid parameter");
2354     return NOTI_EX_ERROR_INVALID_PARAMETER;
2355   }
2356
2357   string receiver_group_str = "";
2358   if (receiver_group)
2359     receiver_group_str = string(receiver_group);
2360
2361   ManagerStub* stub = new (std::nothrow) ManagerStub(
2362       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2363       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2364       receiver_group_str);
2365   if (stub == nullptr) {
2366     LOGE("Fail to create manager");
2367     return NOTI_EX_ERROR_IO_ERROR;
2368   }
2369   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2370       new ManagerCallbackInfo(event_callbacks, data)));
2371   *handle = static_cast<noti_ex_manager_h>(stub);
2372
2373   return NOTI_EX_ERROR_NONE;
2374 }
2375
2376 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2377   if (handle == nullptr) {
2378     LOGE("Invalid parameter");
2379     return NOTI_EX_ERROR_INVALID_PARAMETER;
2380   }
2381   ManagerStub* stub = static_cast<ManagerStub*>(handle);
2382   delete stub;
2383   return NOTI_EX_ERROR_NONE;
2384 }
2385
2386 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2387     noti_ex_item_h **items, int *count) {
2388   if (handle == nullptr || items == nullptr || count == nullptr) {
2389     LOGE("Invalid parameter");
2390     return NOTI_EX_ERROR_INVALID_PARAMETER;
2391   }
2392
2393   try {
2394     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2395     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2396     if (item_list.size() == 0) {
2397       *items = nullptr;
2398       *count = 0;
2399       return NOTI_EX_ERROR_NONE;
2400     }
2401     noti_ex_item_h* added_item =
2402         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2403     if (added_item == nullptr) {
2404       LOGE("Fail to create items");
2405       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2406     }
2407
2408     int idx = 0;
2409     for (auto& i : item_list) {
2410       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2411     }
2412     *items = added_item;
2413     *count = item_list.size();
2414   } catch (Exception &ex) {
2415     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2416     return NOTI_EX_ERROR_IO_ERROR;
2417   }
2418   return NOTI_EX_ERROR_NONE;
2419 }
2420
2421 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2422     noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2423   if (handle == nullptr || channel == nullptr ||
2424       items == nullptr || count == nullptr) {
2425     LOGE("Invalid parameter");
2426     return NOTI_EX_ERROR_INVALID_PARAMETER;
2427   }
2428
2429   try {
2430     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2431     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2432     if (item_list.size() == 0) {
2433       *items = nullptr;
2434       *count = 0;
2435       return NOTI_EX_ERROR_NONE;
2436     }
2437     noti_ex_item_h* added_item =
2438         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2439     if (added_item == nullptr) {
2440       LOGE("Fail to create items");
2441       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2442     }
2443
2444     int idx = 0;
2445     for (auto& i : item_list) {
2446       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2447     }
2448     *items = added_item;
2449     *count = item_list.size();
2450   } catch (Exception &ex) {
2451     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2452     return NOTI_EX_ERROR_IO_ERROR;
2453   }
2454
2455   return NOTI_EX_ERROR_NONE;
2456 }
2457
2458 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2459     noti_ex_item_h noti, int *request_id) {
2460   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2461     LOGE("Invalid parameter");
2462     return NOTI_EX_ERROR_INVALID_PARAMETER;
2463   }
2464   try {
2465     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2466     Handle* sp = static_cast<Handle*>(noti);
2467     if (sp->GetPtr().get() == nullptr) {
2468       LOGE("Invalid noti reference can not be sended");
2469       return NOTI_EX_ERROR_INVALID_PARAMETER;
2470     } else {
2471       *request_id = stub->Update(sp->GetPtr());
2472     }
2473   } catch (Exception &ex) {
2474     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2475     return NOTI_EX_ERROR_IO_ERROR;
2476   }
2477   return NOTI_EX_ERROR_NONE;
2478 }
2479
2480 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2481     noti_ex_item_h noti, int *request_id) {
2482   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2483     LOGE("Invalid parameter");
2484     return NOTI_EX_ERROR_INVALID_PARAMETER;
2485   }
2486   try {
2487     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2488     Handle* item = static_cast<Handle*>(noti);
2489     if (item->GetPtr().get() == nullptr) {
2490       LOGE("Invalid noti reference can not be sended");
2491       return NOTI_EX_ERROR_INVALID_PARAMETER;
2492     } else {
2493       *request_id = stub->Delete(item->GetPtr());
2494     }
2495   } catch (Exception &ex) {
2496     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2497     return NOTI_EX_ERROR_IO_ERROR;
2498   }
2499   return NOTI_EX_ERROR_NONE;
2500 }
2501
2502 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2503     int *request_id) {
2504   if (handle == nullptr || request_id == nullptr) {
2505     LOGE("Invalid parameter");
2506     return NOTI_EX_ERROR_INVALID_PARAMETER;
2507   }
2508   try {
2509     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2510     *request_id = stub->DeleteAll();
2511   } catch (Exception &ex) {
2512     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2513     return NOTI_EX_ERROR_IO_ERROR;
2514   }
2515   return NOTI_EX_ERROR_NONE;
2516 }
2517
2518 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2519     noti_ex_item_h noti, int *request_id) {
2520   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2521     LOGE("Invalid parameter");
2522     return NOTI_EX_ERROR_INVALID_PARAMETER;
2523   }
2524   try {
2525     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2526     Handle* item = static_cast<Handle*>(noti);
2527     if (item->GetPtr().get() == nullptr) {
2528       LOGE("Invalid noti reference can not be sended");
2529       return NOTI_EX_ERROR_INVALID_PARAMETER;
2530     } else {
2531       *request_id = stub->Hide(item->GetPtr());
2532     }
2533   } catch (Exception &ex) {
2534     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2535     return NOTI_EX_ERROR_IO_ERROR;
2536   }
2537   return NOTI_EX_ERROR_NONE;
2538 }
2539
2540 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2541     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2542   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2543     LOGE("Invalid parameter");
2544     return NOTI_EX_ERROR_INVALID_PARAMETER;
2545   }
2546   try {
2547     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2548     *item = new Handle(stub->FindByRootID(root_id));
2549   } catch (Exception &ex) {
2550     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2551     return NOTI_EX_ERROR_IO_ERROR;
2552   }
2553   return NOTI_EX_ERROR_NONE;
2554 }
2555
2556 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2557     noti_ex_event_info_h info, noti_ex_error_e error) {
2558   if (handle == nullptr || info == nullptr) {
2559     LOGE("Invalid parameter");
2560     return NOTI_EX_ERROR_INVALID_PARAMETER;
2561   }
2562   try {
2563     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2564     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2565     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2566         static_cast<NotificationError>(error));
2567   } catch (Exception &ex) {
2568     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2569     return NOTI_EX_ERROR_IO_ERROR;
2570   }
2571   return NOTI_EX_ERROR_NONE;
2572 }
2573
2574 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2575     noti_ex_manager_h handle, int *cnt) {
2576
2577   if (handle == nullptr || cnt == nullptr) {
2578     LOGE("Invalid parameter");
2579     return NOTI_EX_ERROR_INVALID_PARAMETER;
2580   }
2581   try {
2582     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2583     *cnt = stub->GetCount();
2584   } catch (Exception &ex) {
2585     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2586     return NOTI_EX_ERROR_IO_ERROR;
2587   }
2588   return NOTI_EX_ERROR_NONE;
2589 }
2590
2591 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2592     const char *id, float min, float current, float max) {
2593   ProgressItem* p;
2594
2595   if (handle == nullptr) {
2596     LOGE("Invalid parameter");
2597     return NOTI_EX_ERROR_INVALID_PARAMETER;
2598   }
2599
2600   if (id)
2601     p = new (std::nothrow) ProgressItem(id, min, current, max);
2602   else
2603     p = new (std::nothrow) ProgressItem(min, current, max);
2604
2605   if (p == nullptr) {
2606     LOGE("Out-of-memory");
2607     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2608   }
2609
2610   *handle = new Handle(shared_ptr<AbstractItem>(p));
2611
2612   return NOTI_EX_ERROR_NONE;
2613 }
2614
2615 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2616     noti_ex_item_h handle, float *current) {
2617   if (handle == nullptr || current == nullptr) {
2618     LOGE("Invalid parameter");
2619     return NOTI_EX_ERROR_INVALID_PARAMETER;
2620   }
2621
2622   Handle *h = static_cast<Handle*>(handle);
2623   if (!h->IsValidType(AbstractItem::Progress)) {
2624     LOGE("Invalid handle type");
2625     return NOTI_EX_ERROR_INVALID_PARAMETER;
2626   }
2627   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2628   *current = p->GetCurrent();
2629
2630   return NOTI_EX_ERROR_NONE;
2631 }
2632
2633 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2634     noti_ex_item_h handle, float current) {
2635   if (handle == nullptr) {
2636     LOGE("Invalid parameter");
2637     return NOTI_EX_ERROR_INVALID_PARAMETER;
2638   }
2639
2640   Handle *h = static_cast<Handle*>(handle);
2641   if (!h->IsValidType(AbstractItem::Progress)) {
2642     LOGE("Invalid handle type");
2643     return NOTI_EX_ERROR_INVALID_PARAMETER;
2644   }
2645   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2646   p->SetCurrent(current);
2647
2648   return NOTI_EX_ERROR_NONE;
2649 }
2650
2651 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2652     float *min) {
2653   if (handle == nullptr || min == nullptr) {
2654     LOGE("Invalid parameter");
2655     return NOTI_EX_ERROR_INVALID_PARAMETER;
2656   }
2657
2658   Handle *h = static_cast<Handle*>(handle);
2659   if (!h->IsValidType(AbstractItem::Progress)) {
2660     LOGE("Invalid handle type");
2661     return NOTI_EX_ERROR_INVALID_PARAMETER;
2662   }
2663   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2664   *min = p->GetMin();
2665
2666   return NOTI_EX_ERROR_NONE;
2667 }
2668
2669 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2670     float *max) {
2671   if (handle == nullptr || max == nullptr) {
2672     LOGE("Invalid parameter");
2673     return NOTI_EX_ERROR_INVALID_PARAMETER;
2674   }
2675
2676   Handle *h = static_cast<Handle*>(handle);
2677   if (!h->IsValidType(AbstractItem::Progress)) {
2678     LOGE("Invalid handle type");
2679     return NOTI_EX_ERROR_INVALID_PARAMETER;
2680   }
2681   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2682   *max = p->GetMax();
2683
2684   return NOTI_EX_ERROR_NONE;
2685 }
2686
2687 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2688     int* type) {
2689   if (handle == nullptr || type == nullptr) {
2690     LOGE("Invalid parameter");
2691     return NOTI_EX_ERROR_INVALID_PARAMETER;
2692   }
2693
2694   Handle *h = static_cast<Handle*>(handle);
2695   if (!h->IsValidType(AbstractItem::Progress)) {
2696     LOGE("Invalid handle type");
2697     return NOTI_EX_ERROR_INVALID_PARAMETER;
2698   }
2699   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2700   *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2701
2702   return NOTI_EX_ERROR_NONE;
2703 }
2704
2705 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2706     int type) {
2707   if (handle == nullptr) {
2708     LOGE("Invalid parameter");
2709     return NOTI_EX_ERROR_INVALID_PARAMETER;
2710   }
2711
2712   Handle *h = static_cast<Handle*>(handle);
2713   if (!h->IsValidType(AbstractItem::Progress)) {
2714     LOGE("Invalid handle type");
2715     return NOTI_EX_ERROR_INVALID_PARAMETER;
2716   }
2717   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2718   p->SetProgressType(static_cast<ProgressItem::Type>(type));
2719
2720   return NOTI_EX_ERROR_NONE;
2721 }
2722
2723 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2724     noti_ex_reporter_events_s event_callbacks, void *data) {
2725   if (handle == nullptr) {
2726     LOGE("Invalid parameter");
2727     return NOTI_EX_ERROR_INVALID_PARAMETER;
2728   }
2729
2730   ReporterStub* stub = new (std::nothrow) ReporterStub(
2731       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2732       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2733   if (stub == nullptr) {
2734     LOGE("Fail to create manager");
2735     return NOTI_EX_ERROR_IO_ERROR;
2736   }
2737   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2738       new ReporterCallbackInfo(event_callbacks, data)));
2739
2740   *handle = static_cast<noti_ex_reporter_h>(stub);
2741
2742   return NOTI_EX_ERROR_NONE;
2743 }
2744
2745 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2746   if (handle == nullptr) {
2747     LOGE("Invalid parameter");
2748     return NOTI_EX_ERROR_INVALID_PARAMETER;
2749   }
2750   ReporterStub* stub = static_cast<ReporterStub*>(handle);
2751   delete stub;
2752   return NOTI_EX_ERROR_NONE;
2753 }
2754
2755 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2756     noti_ex_event_info_h info, noti_ex_error_e error) {
2757   if (handle == nullptr || info == nullptr) {
2758     LOGE("Invalid parameter");
2759     return NOTI_EX_ERROR_INVALID_PARAMETER;
2760   }
2761   try {
2762     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2763     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2764     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2765         static_cast<NotificationError>(error));
2766   } catch (Exception &ex) {
2767     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2768     return NOTI_EX_ERROR_IO_ERROR;
2769   }
2770   return NOTI_EX_ERROR_NONE;
2771 }
2772
2773 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2774     noti_ex_item_h noti, int *request_id) {
2775   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2776     LOGE("Invalid parameter");
2777     return NOTI_EX_ERROR_INVALID_PARAMETER;
2778   }
2779   try {
2780     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2781     Handle* h = static_cast<Handle*>(noti);
2782     if (h->GetPtr().get() == nullptr) {
2783       LOGE("Invalid noti reference can not be sended");
2784       return NOTI_EX_ERROR_INVALID_PARAMETER;
2785     } else {
2786       *request_id = stub->Post(h->GetPtr());
2787     }
2788   } catch (Exception &ex) {
2789     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2790     return NOTI_EX_ERROR_IO_ERROR;
2791   }
2792   return NOTI_EX_ERROR_NONE;
2793 }
2794
2795 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2796     noti_ex_item_h *noti_list, int count, int *request_id) {
2797
2798   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
2799     LOGE("Invalid parameter");
2800     return NOTI_EX_ERROR_INVALID_PARAMETER;
2801   }
2802   try {
2803     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2804     list<shared_ptr<item::AbstractItem>> notiList;
2805     for (int i = 0; i < count; i++) {
2806       Handle* item = static_cast<Handle*>(noti_list[i]);
2807       notiList.push_back(item->GetPtr());
2808     }
2809     *request_id = stub->Post(notiList);
2810   } catch (Exception &ex) {
2811     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2812     return NOTI_EX_ERROR_IO_ERROR;
2813   }
2814   return NOTI_EX_ERROR_NONE;
2815 }
2816
2817 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
2818     noti_ex_item_h noti, int *request_id) {
2819   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2820     LOGE("Invalid parameter");
2821     return NOTI_EX_ERROR_INVALID_PARAMETER;
2822   }
2823   try {
2824     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2825     Handle* item = static_cast<Handle*>(noti);
2826     if (item->GetPtr().get() == nullptr) {
2827       LOGE("Invalid noti reference can not be sended");
2828       return NOTI_EX_ERROR_INVALID_PARAMETER;
2829     } else {
2830       *request_id = stub->Update(item->GetPtr());
2831     }
2832   } catch (Exception &ex) {
2833     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2834     return NOTI_EX_ERROR_IO_ERROR;
2835   }
2836   return NOTI_EX_ERROR_NONE;
2837 }
2838
2839 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
2840     noti_ex_item_h noti, int *request_id) {
2841   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2842     LOGE("Invalid parameter");
2843     return NOTI_EX_ERROR_INVALID_PARAMETER;
2844   }
2845   try {
2846     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2847     Handle* item = static_cast<Handle*>(noti);
2848     if (item->GetPtr().get() == nullptr) {
2849       LOGE("Invalid noti reference can not be sended");
2850       return NOTI_EX_ERROR_INVALID_PARAMETER;
2851     } else {
2852       *request_id = stub->Delete(item->GetPtr());
2853     }
2854   } catch (Exception &ex) {
2855     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2856     return NOTI_EX_ERROR_IO_ERROR;
2857   }
2858   return NOTI_EX_ERROR_NONE;
2859 }
2860
2861 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
2862     noti_ex_reporter_h handle, int *request_id) {
2863   if (handle == nullptr || request_id == nullptr) {
2864     LOGE("Invalid parameter");
2865     return NOTI_EX_ERROR_INVALID_PARAMETER;
2866   }
2867   try {
2868     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2869     *request_id = stub->DeleteAll();
2870   } catch (Exception &ex) {
2871     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2872     return NOTI_EX_ERROR_IO_ERROR;
2873   }
2874   return NOTI_EX_ERROR_NONE;
2875 }
2876
2877 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
2878     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
2879   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2880     LOGE("Invalid parameter");
2881     return NOTI_EX_ERROR_INVALID_PARAMETER;
2882   }
2883   try {
2884     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2885     *item = new Handle(stub->FindByRootID(root_id));
2886   } catch (Exception &ex) {
2887     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2888     return NOTI_EX_ERROR_IO_ERROR;
2889   }
2890   return NOTI_EX_ERROR_NONE;
2891 }
2892
2893 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
2894     const char *id, const char *text, const char *hyperlink) {
2895   if (handle == nullptr || text == nullptr) {
2896     LOGE("Invalid parameter");
2897     return NOTI_EX_ERROR_INVALID_PARAMETER;
2898   }
2899
2900   TextItem* p;
2901
2902   if (hyperlink)
2903     p = new (std::nothrow) TextItem(id, std::string(text),
2904                 std::string(hyperlink));
2905   else
2906     p = new (std::nothrow) TextItem(id, std::string(text));
2907
2908   if (p == nullptr) {
2909     LOGE("Out-of-memory");
2910     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2911   }
2912
2913   *handle = new Handle(shared_ptr<AbstractItem>(p));
2914
2915   return NOTI_EX_ERROR_NONE;
2916 }
2917
2918 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
2919     const char *contents) {
2920   if (handle == nullptr || contents == nullptr) {
2921     LOGE("Invalid parameter");
2922     return NOTI_EX_ERROR_INVALID_PARAMETER;
2923   }
2924
2925   Handle* p = static_cast<Handle*>(handle);
2926   if (!p->IsValidType(AbstractItem::Text)) {
2927     LOGE("Invalid handle type");
2928     return NOTI_EX_ERROR_INVALID_PARAMETER;
2929   }
2930   TextItem* ti = static_cast<TextItem*>(p->Get());
2931   ti->SetContents(std::string(contents));
2932
2933   return NOTI_EX_ERROR_NONE;
2934 }
2935
2936 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
2937     char **contents) {
2938   if (handle == nullptr || contents == nullptr) {
2939     LOGE("Invalid parameter");
2940     return NOTI_EX_ERROR_INVALID_PARAMETER;
2941   }
2942
2943   Handle* p = static_cast<Handle*>(handle);
2944   if (!p->IsValidType(AbstractItem::Text)) {
2945     LOGE("Invalid handle type");
2946     return NOTI_EX_ERROR_INVALID_PARAMETER;
2947   }
2948
2949   TextItem* ti = static_cast<TextItem*>(p->Get());
2950   string str;
2951   if (ti->GetMultiLanguage() != nullptr &&
2952       !ti->GetMultiLanguage()->GetTranslatedString().empty())
2953     str = ti->GetMultiLanguage()->GetTranslatedString();
2954   else if (!ti->GetContents().empty())
2955     str = ti->GetContents();
2956
2957   *contents = strdup(str.c_str());
2958   if (*contents == nullptr) {
2959     LOGE("Out-of-memory");
2960     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2961   }
2962
2963   return NOTI_EX_ERROR_NONE;
2964 }
2965
2966 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
2967     noti_ex_item_h handle, char **hyper_link) {
2968   if (handle == nullptr || hyper_link == nullptr) {
2969     LOGE("Invalid parameter");
2970     return NOTI_EX_ERROR_INVALID_PARAMETER;
2971   }
2972
2973   Handle* p = static_cast<Handle*>(handle);
2974   if (!p->IsValidType(AbstractItem::Text)) {
2975     LOGE("Invalid handle type");
2976     return NOTI_EX_ERROR_INVALID_PARAMETER;
2977   }
2978   TextItem* ti = static_cast<TextItem*>(p->Get());
2979   if (!ti->GetHyperLink().empty()) {
2980     *hyper_link = strdup(ti->GetHyperLink().c_str());
2981     if (*hyper_link == nullptr) {
2982       LOGE("Out-of-memory");
2983       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2984     }
2985   }
2986
2987   return NOTI_EX_ERROR_NONE;
2988 }
2989
2990 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
2991     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
2992   if (handle == nullptr) {
2993     LOGE("Invalid parameter");
2994     return NOTI_EX_ERROR_INVALID_PARAMETER;
2995   }
2996
2997   Handle* p = static_cast<Handle*>(handle);
2998   if (!p->IsValidType(AbstractItem::Text)) {
2999     LOGE("Invalid handle type");
3000     return NOTI_EX_ERROR_INVALID_PARAMETER;
3001   }
3002
3003   TextItem* ti = static_cast<TextItem*>(p->Get());
3004   if (multi == nullptr) {
3005     ti->SetMultiLanguage(nullptr);
3006     return NOTI_EX_ERROR_NONE;
3007   }
3008
3009   shared_ptr<MultiLanguage> mul_ptr =
3010       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3011   ti->SetMultiLanguage(mul_ptr);
3012   ti->GetMultiLanguage()->UpdateString();
3013
3014   return NOTI_EX_ERROR_NONE;
3015 }
3016
3017 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3018     const char *id, time_t time) {
3019   TimeItem* p;
3020
3021   if (handle == nullptr) {
3022     LOGE("Invalid parameter");
3023     return NOTI_EX_ERROR_INVALID_PARAMETER;
3024   }
3025
3026   if (time) {
3027     if (id)
3028       p = new (std::nothrow) TimeItem(id, time);
3029     else
3030       p = new (std::nothrow) TimeItem(time);
3031   } else {
3032       p = new (std::nothrow) TimeItem();
3033   }
3034
3035   if (p == nullptr) {
3036     LOGE("Out-of-memory");
3037     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3038   }
3039
3040   *handle = new Handle(shared_ptr<AbstractItem>(p));
3041
3042   return NOTI_EX_ERROR_NONE;
3043 }
3044
3045 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3046     time_t *time) {
3047   if (handle == nullptr || time == nullptr) {
3048     LOGE("Invalid parameter");
3049     return NOTI_EX_ERROR_INVALID_PARAMETER;
3050   }
3051   Handle* h = static_cast<Handle*>(handle);
3052   if (!h->IsValidType(AbstractItem::Time)) {
3053     LOGE("Invalid handle type");
3054     return NOTI_EX_ERROR_INVALID_PARAMETER;
3055   }
3056   TimeItem* p = static_cast<TimeItem*>(h->Get());
3057   *time = p->GetTime();
3058
3059   return NOTI_EX_ERROR_NONE;
3060 }
3061
3062 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3063     noti_ex_action_h *handle, const char *extra) {
3064   if (handle == nullptr) {
3065     LOGE("Invalid parameter");
3066     return NOTI_EX_ERROR_INVALID_PARAMETER;
3067   }
3068
3069   string extra_str = "";
3070   if (extra != NULL)
3071     extra_str = string(extra);
3072
3073   shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3074       new (std::nothrow) VisibilityAction(extra_str));
3075   if (ptr == nullptr) {
3076     LOGE("Out-of-memory");
3077     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3078   }
3079
3080   *handle = ptr;
3081
3082   return NOTI_EX_ERROR_NONE;
3083 }
3084
3085 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3086     const char *id, bool visible) {
3087   if (handle == nullptr || id == nullptr) {
3088     LOGE("Invalid parameter");
3089     return NOTI_EX_ERROR_INVALID_PARAMETER;
3090   }
3091
3092   shared_ptr<AbstractAction>* ptr =
3093       static_cast<shared_ptr<AbstractAction>*>(handle);
3094   VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3095   action->SetVisibility(id, visible);
3096
3097   return NOTI_EX_ERROR_NONE;
3098 }
3099
3100 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3101     const char* msgid, const char* format, ...) {
3102   if (handle == nullptr || msgid == nullptr || format == nullptr) {
3103     LOGE("Invalid parameter");
3104     return NOTI_EX_ERROR_INVALID_PARAMETER;
3105   }
3106
3107   const char* format_idx = format;
3108   vector<string> arr;
3109   va_list args;
3110   va_start(args, format);
3111   while (*format_idx != '\0') {
3112     char* arg = nullptr;
3113     int arg_i;
3114     double arg_f;
3115     stringstream stream;
3116     if (*format_idx == '%') {
3117       switch (*(format_idx + 1)) {
3118         case 's':
3119           arg = va_arg(args, char *);
3120           arr.push_back(string(arg));
3121           break;
3122         case 'd':
3123           arg_i = va_arg(args, int);
3124           arr.push_back(to_string(arg_i));
3125           break;
3126         case 'f':
3127           arg_f = va_arg(args, double);
3128           stream << std::fixed << std::setprecision(2) << arg_f;
3129           arr.push_back(stream.str());
3130           break;
3131       }
3132     }
3133     format_idx++;
3134   }
3135   va_end(args);
3136
3137   MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3138   if (p == nullptr) {
3139     LOGE("Out-of-memory");
3140     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3141   }
3142   *handle = new shared_ptr<MultiLanguage>(p);
3143
3144   return NOTI_EX_ERROR_NONE;
3145 }
3146
3147 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3148   if (handle == nullptr) {
3149     LOGE("Invalid parameter");
3150     return NOTI_EX_ERROR_INVALID_PARAMETER;
3151   }
3152
3153   shared_ptr<MultiLanguage>* mul_ptr =
3154       reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3155   delete mul_ptr;
3156   return NOTI_EX_ERROR_NONE;
3157 }