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