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