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