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