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