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