Fix TextItem create issue
[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_shared_paths(noti_ex_item_h handle,
1975     char ***path, int *count) {
1976   if (handle == nullptr || path == nullptr || count == nullptr) {
1977     LOGE("Invalid parameter");
1978     return NOTI_EX_ERROR_INVALID_PARAMETER;
1979   }
1980   Handle* p = static_cast<Handle*>(handle);
1981   list<string> shared_path = p->Get()->GetSharedPath();
1982   char** tmp_path = (char**)calloc(shared_path.size(), sizeof(char*));
1983   if (tmp_path == nullptr) {
1984     LOGE("Fail to create items");
1985     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1986   }
1987
1988   int idx = 0;
1989   for (auto& i : shared_path) {
1990     tmp_path[idx] = strdup(i.c_str());
1991     if (tmp_path[idx] == nullptr) {
1992       __noti_ex_free_str_array(tmp_path, idx);
1993       LOGE("Out of memory");
1994       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1995     }
1996     idx++;
1997   }
1998
1999   *path = tmp_path;
2000   *count = shared_path.size();
2001   return NOTI_EX_ERROR_NONE;
2002 }
2003
2004 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2005     char **id) {
2006   if (handle == nullptr || id == nullptr) {
2007     LOGE("Invalid parameter");
2008     return NOTI_EX_ERROR_INVALID_PARAMETER;
2009   }
2010   Handle* h = static_cast<Handle*>(handle);
2011   AbstractItem* p = h->Get();
2012   *id = strdup(p->GetId().c_str());
2013   return NOTI_EX_ERROR_NONE;
2014 }
2015
2016 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2017     const char *id) {
2018   if (handle == nullptr || id == nullptr) {
2019     LOGE("Invalid parameter");
2020     return NOTI_EX_ERROR_INVALID_PARAMETER;
2021   }
2022   Handle* p = static_cast<Handle*>(handle);
2023   p->Get()->SetId(id);
2024   return NOTI_EX_ERROR_NONE;
2025 }
2026
2027 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2028     noti_ex_action_h *action) {
2029   if (handle == nullptr || action == nullptr) {
2030     LOGE("Invalid parameter");
2031     return NOTI_EX_ERROR_INVALID_PARAMETER;
2032   }
2033   Handle* p = static_cast<Handle*>(handle);
2034   if (p->Get()->GetAction() == nullptr) {
2035     *action = nullptr;
2036     return NOTI_EX_ERROR_NONE;
2037   }
2038   *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2039       p->Get()->GetAction()));
2040
2041   return NOTI_EX_ERROR_NONE;
2042 }
2043
2044 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2045     noti_ex_action_h action) {
2046   if (handle == nullptr) {
2047     LOGE("Invalid parameter");
2048     return NOTI_EX_ERROR_INVALID_PARAMETER;
2049   }
2050
2051   Handle* p = static_cast<Handle*>(handle);
2052   if (action == nullptr) {
2053     p->Get()->SetAction(nullptr);
2054     return NOTI_EX_ERROR_NONE;
2055   }
2056
2057   shared_ptr<AbstractAction>* ptr =
2058       static_cast<shared_ptr<AbstractAction>*>(action);
2059   p->Get()->SetAction(*ptr);
2060   return NOTI_EX_ERROR_NONE;
2061 }
2062
2063 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2064     noti_ex_style_h *style) {
2065   if (handle == nullptr || style == nullptr) {
2066     LOGE("Invalid parameter");
2067     return NOTI_EX_ERROR_INVALID_PARAMETER;
2068   }
2069
2070   Handle* p = static_cast<Handle*>(handle);
2071   shared_ptr<Style> s = p->Get()->GetStyle();
2072   if (s.get() == nullptr) {
2073     LOGW("Style is null");
2074     *style = nullptr;
2075     return NOTI_EX_ERROR_NONE;
2076   }
2077
2078   auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2079   if (ptr == nullptr || ptr->get() == nullptr) {
2080     LOGE("Out of memory");
2081     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2082   }
2083
2084   *style = ptr;
2085   return NOTI_EX_ERROR_NONE;
2086 }
2087
2088 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2089     noti_ex_style_h style) {
2090   if (handle == nullptr) {
2091     LOGE("Invalid parameter");
2092     return NOTI_EX_ERROR_INVALID_PARAMETER;
2093   }
2094
2095   Handle* p = static_cast<Handle*>(handle);
2096   if (style == nullptr) {
2097     p->Get()->SetStyle(nullptr);
2098     return NOTI_EX_ERROR_NONE;
2099   }
2100
2101   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2102   p->Get()->SetStyle(*s);
2103   return NOTI_EX_ERROR_NONE;
2104 }
2105
2106 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2107     bool visible) {
2108   if (handle == nullptr) {
2109     LOGE("Invalid parameter");
2110     return NOTI_EX_ERROR_INVALID_PARAMETER;
2111   }
2112
2113   Handle* p = static_cast<Handle*>(handle);
2114   p->Get()->SetVisible(visible);
2115   return NOTI_EX_ERROR_NONE;
2116 }
2117
2118 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2119     bool *visible) {
2120   if (handle == nullptr || visible == nullptr) {
2121     LOGE("Invalid parameter");
2122     return NOTI_EX_ERROR_INVALID_PARAMETER;
2123   }
2124
2125   Handle* p = static_cast<Handle*>(handle);
2126   *visible = p->Get()->GetVisible();
2127   return NOTI_EX_ERROR_NONE;
2128 }
2129
2130 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2131     bool enable) {
2132   if (handle == nullptr) {
2133     LOGE("Invalid parameter");
2134     return NOTI_EX_ERROR_INVALID_PARAMETER;
2135   }
2136
2137   Handle* p = static_cast<Handle*>(handle);
2138   p->Get()->SetEnable(enable);
2139   return NOTI_EX_ERROR_NONE;
2140 }
2141
2142 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2143     bool *enable) {
2144   if (handle == nullptr || enable == nullptr) {
2145     LOGE("Invalid parameter");
2146     return NOTI_EX_ERROR_INVALID_PARAMETER;
2147   }
2148
2149   Handle* p = static_cast<Handle*>(handle);
2150   *enable = p->Get()->GetEnable();
2151   return NOTI_EX_ERROR_NONE;
2152 }
2153
2154 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2155     const char *receiver_group) {
2156   if (handle == nullptr || receiver_group == nullptr) {
2157     LOGE("Invalid parameter");
2158     return NOTI_EX_ERROR_INVALID_PARAMETER;
2159   }
2160
2161   Handle* p = static_cast<Handle*>(handle);
2162   p->Get()->AddReceiver(receiver_group);
2163   return NOTI_EX_ERROR_NONE;
2164 }
2165
2166 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2167     const char *receiver_group) {
2168   if (handle == nullptr || receiver_group == nullptr) {
2169     LOGE("Invalid parameter");
2170     return NOTI_EX_ERROR_INVALID_PARAMETER;
2171   }
2172
2173   Handle* p = static_cast<Handle*>(handle);
2174   p->Get()->RemoveReceiver(receiver_group);
2175   return NOTI_EX_ERROR_NONE;
2176 }
2177
2178 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2179     char ***receiver_list, int *count) {
2180   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2181     LOGE("Invalid parameter");
2182     return NOTI_EX_ERROR_INVALID_PARAMETER;
2183   }
2184
2185   Handle* p = static_cast<Handle*>(handle);
2186   list<string> receivers = p->Get()->GetReceiverList();
2187   if (receivers.size() == 0) {
2188     *receiver_list = nullptr;
2189     *count = 0;
2190     return NOTI_EX_ERROR_NONE;
2191   }
2192
2193   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2194   if (tmp_list == nullptr) {
2195     LOGE("Out of memory");
2196     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2197   }
2198
2199   int idx = 0;
2200   for (auto& i : receivers) {
2201     tmp_list[idx] = strdup(i.c_str());
2202     if (tmp_list[idx] == nullptr) {
2203       __noti_ex_free_str_array(tmp_list, idx);
2204       LOGE("Out of memory");
2205       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2206     }
2207     idx++;
2208   }
2209
2210   *receiver_list = tmp_list;
2211   *count = receivers.size();
2212   return NOTI_EX_ERROR_NONE;
2213 }
2214
2215 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2216     int policy) {
2217   if (handle == nullptr) {
2218     LOGE("Invalid parameter");
2219     return NOTI_EX_ERROR_INVALID_PARAMETER;
2220   }
2221
2222   Handle* p = static_cast<Handle*>(handle);
2223   p->Get()->SetPolicy(policy);
2224   return NOTI_EX_ERROR_NONE;
2225 }
2226
2227 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2228     int *policy) {
2229   if (handle == nullptr || policy == nullptr) {
2230     LOGE("Invalid parameter");
2231     return NOTI_EX_ERROR_INVALID_PARAMETER;
2232   }
2233
2234   Handle* p = static_cast<Handle*>(handle);
2235   *policy = p->Get()->GetPolicy();
2236   return NOTI_EX_ERROR_NONE;
2237 }
2238
2239 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2240     char **channel) {
2241   if (handle == nullptr || channel == nullptr) {
2242     LOGE("Invalid parameter");
2243     return NOTI_EX_ERROR_INVALID_PARAMETER;
2244   }
2245
2246   Handle* p = static_cast<Handle*>(handle);
2247   if (!p->Get()->GetChannel().empty())
2248     *channel = strdup(p->Get()->GetChannel().c_str());
2249   else
2250     *channel = nullptr;
2251
2252   return NOTI_EX_ERROR_NONE;
2253 }
2254
2255 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2256     const char *channel) {
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   p->Get()->SetChannel(channel);
2264   return NOTI_EX_ERROR_NONE;
2265 }
2266
2267 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2268     noti_ex_led_info_h led) {
2269   if (handle == nullptr) {
2270     LOGE("Invalid parameter");
2271     return NOTI_EX_ERROR_INVALID_PARAMETER;
2272   }
2273
2274   Handle* p = static_cast<Handle*>(handle);
2275   if (led == nullptr) {
2276     p->Get()->SetLEDInfo(nullptr);
2277     return NOTI_EX_ERROR_NONE;
2278   }
2279   shared_ptr<LEDInfo>* led_ptr =
2280       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2281   p->Get()->SetLEDInfo(*led_ptr);
2282   return NOTI_EX_ERROR_NONE;
2283 }
2284
2285 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2286     noti_ex_led_info_h *led) {
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 (p->Get()->GetLEDInfo() != nullptr)
2294     *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2295   else
2296     *led = nullptr;
2297   return NOTI_EX_ERROR_NONE;
2298 }
2299
2300 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2301     const char *path) {
2302   if (handle == nullptr) {
2303     LOGE("Invalid parameter");
2304     return NOTI_EX_ERROR_INVALID_PARAMETER;
2305   }
2306
2307   Handle* p = static_cast<Handle*>(handle);
2308   if (path == nullptr)
2309     p->Get()->SetSoundPath("");
2310   else
2311     p->Get()->SetSoundPath(path);
2312   return NOTI_EX_ERROR_NONE;
2313 }
2314
2315 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2316     const char *path) {
2317   if (handle == nullptr) {
2318     LOGE("Invalid parameter");
2319     return NOTI_EX_ERROR_INVALID_PARAMETER;
2320   }
2321
2322   Handle* p = static_cast<Handle*>(handle);
2323   if (path == nullptr)
2324     p->Get()->SetVibrationPath("");
2325   else
2326     p->Get()->SetVibrationPath(path);
2327   return NOTI_EX_ERROR_NONE;
2328 }
2329
2330 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2331     char **path) {
2332   if (handle == nullptr || path == 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()->GetSoundPath().empty())
2339     *path = nullptr;
2340   else
2341     *path = strdup(p->Get()->GetSoundPath().c_str());
2342   return NOTI_EX_ERROR_NONE;
2343 }
2344
2345 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2346     char **path) {
2347   if (handle == nullptr || path == 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()->GetVibrationPath().empty())
2354     *path = nullptr;
2355   else
2356     *path = strdup(p->Get()->GetVibrationPath().c_str());
2357   return NOTI_EX_ERROR_NONE;
2358 }
2359
2360 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2361     noti_ex_item_info_h *info) {
2362   if (handle == nullptr || info == 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()->GetInfo() == nullptr)
2369     *info = nullptr;
2370   else
2371     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2372   return NOTI_EX_ERROR_NONE;
2373 }
2374
2375 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2376     char **id) {
2377   if (handle == nullptr || id == nullptr) {
2378     LOGE("Invalid parameter");
2379     return NOTI_EX_ERROR_INVALID_PARAMETER;
2380   }
2381
2382   Handle* p = static_cast<Handle*>(handle);
2383   if (p->Get()->GetSenderAppId().empty())
2384     *id = nullptr;
2385   else
2386     *id = strdup(p->Get()->GetSenderAppId().c_str());
2387   return NOTI_EX_ERROR_NONE;
2388 }
2389
2390 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2391     char **tag) {
2392   if (handle == nullptr || tag == nullptr) {
2393     LOGE("Invalid parameter");
2394     return NOTI_EX_ERROR_INVALID_PARAMETER;
2395   }
2396
2397   Handle* p = static_cast<Handle*>(handle);
2398   if (p->Get()->GetTag().empty())
2399     *tag = nullptr;
2400   else
2401     *tag = strdup(p->Get()->GetTag().c_str());
2402   return NOTI_EX_ERROR_NONE;
2403 }
2404
2405 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2406     const char *tag) {
2407   if (handle == nullptr) {
2408     LOGE("Invalid parameter");
2409     return NOTI_EX_ERROR_INVALID_PARAMETER;
2410   }
2411
2412   Handle* p = static_cast<Handle*>(handle);
2413   if (tag == nullptr)
2414     p->Get()->SetTag("");
2415   else
2416     p->Get()->SetTag(tag);
2417   return NOTI_EX_ERROR_NONE;
2418 }
2419
2420 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2421     bool* ongoing) {
2422   if (handle == nullptr || ongoing == nullptr) {
2423     LOGE("Invalid parameter");
2424     return NOTI_EX_ERROR_INVALID_PARAMETER;
2425   }
2426
2427   Handle* p = static_cast<Handle*>(handle);
2428   *ongoing = p->Get()->GetOnGoingState();
2429
2430   return NOTI_EX_ERROR_NONE;
2431 }
2432
2433 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2434     bool ongoing) {
2435   if (handle == nullptr) {
2436     LOGE("Invalid parameter");
2437     return NOTI_EX_ERROR_INVALID_PARAMETER;
2438   }
2439
2440   Handle* p = static_cast<Handle*>(handle);
2441   p->Get()->SetOnGoingState(ongoing);
2442
2443   return NOTI_EX_ERROR_NONE;
2444 }
2445
2446 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2447     int type, bool* exist) {
2448   if (handle == nullptr || exist == nullptr) {
2449     LOGE("Invalid parameter");
2450     return NOTI_EX_ERROR_INVALID_PARAMETER;
2451   }
2452
2453   Handle* p = static_cast<Handle*>(handle);
2454   *exist = p->Get()->IsItemTypeExist(type);
2455
2456   return NOTI_EX_ERROR_NONE;
2457 }
2458
2459 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2460     int* type) {
2461   if (handle == nullptr || type == nullptr) {
2462     LOGE("Invalid parameter");
2463     return NOTI_EX_ERROR_INVALID_PARAMETER;
2464   }
2465
2466   Handle* p = static_cast<Handle*>(handle);
2467   *type = p->Get()->GetMainType();
2468
2469   return NOTI_EX_ERROR_NONE;
2470 }
2471
2472 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2473     const char* id, int type) {
2474   if (handle == nullptr || id == nullptr) {
2475     LOGE("Invalid parameter");
2476     return NOTI_EX_ERROR_INVALID_PARAMETER;
2477   }
2478
2479   Handle* p = static_cast<Handle*>(handle);
2480   if (!(p->Get()->SetMainType(string(id),
2481                     static_cast<AbstractItem::MainType>(type))))
2482     return NOTI_EX_ERROR_INVALID_PARAMETER;
2483
2484   return NOTI_EX_ERROR_NONE;
2485 }
2486
2487 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2488     int type, noti_ex_item_h* item) {
2489   if (handle == nullptr || item == nullptr) {
2490     LOGE("Invalid parameter");
2491     return NOTI_EX_ERROR_INVALID_PARAMETER;
2492   }
2493
2494   Handle* h = static_cast<Handle*>(handle);
2495   if (!h->IsValidType(AbstractItem::Group)) {
2496     LOGE("Invalid handle type");
2497     return NOTI_EX_ERROR_INVALID_PARAMETER;
2498   }
2499
2500   GroupItem* p = static_cast<GroupItem*>(h->Get());
2501   AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2502   if (find_item.GetType() == AbstractItem::NullObject) {
2503     LOGW("Not exist ID");
2504     *item = nullptr;
2505     return NOTI_EX_ERROR_NONE;
2506   }
2507   *item = new Handle(&find_item);
2508
2509   return NOTI_EX_ERROR_NONE;
2510 }
2511
2512 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2513     const char *key, bundle **value) {
2514   if (handle == nullptr || key == nullptr || value == nullptr) {
2515     LOGE("Invalid handle type");
2516     return NOTI_EX_ERROR_INVALID_PARAMETER;
2517   }
2518
2519   Handle* p = static_cast<Handle*>(handle);
2520
2521   Bundle b = p->Get()->GetExtensionData(key);
2522   if (b.GetCount() == 0)
2523     *value = nullptr;
2524   else
2525     *value = b.GetHandle();
2526
2527   return NOTI_EX_ERROR_NONE;
2528 }
2529
2530 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2531     const char *key, bundle *value) {
2532   if (handle == nullptr || key == nullptr || value == nullptr) {
2533     LOGE("Invalid handle type");
2534     return NOTI_EX_ERROR_INVALID_PARAMETER;
2535   }
2536
2537   Bundle b = Bundle(value);
2538
2539   Handle* p = static_cast<Handle*>(handle);
2540   p->Get()->SetExtensionData(key, b);
2541
2542   return NOTI_EX_ERROR_NONE;
2543 }
2544
2545 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2546     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2547     void *data) {
2548   if (handle == nullptr) {
2549     LOGE("Invalid parameter");
2550     return NOTI_EX_ERROR_INVALID_PARAMETER;
2551   }
2552
2553   string receiver_group_str = "";
2554   if (receiver_group)
2555     receiver_group_str = string(receiver_group);
2556
2557   ManagerStub* stub = new (std::nothrow) ManagerStub(
2558       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2559       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2560       receiver_group_str);
2561   if (stub == nullptr) {
2562     LOGE("Fail to create manager");
2563     return NOTI_EX_ERROR_IO_ERROR;
2564   }
2565   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2566       new ManagerCallbackInfo(event_callbacks, data)));
2567   *handle = static_cast<noti_ex_manager_h>(stub);
2568
2569   return NOTI_EX_ERROR_NONE;
2570 }
2571
2572 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2573   if (handle == nullptr) {
2574     LOGE("Invalid parameter");
2575     return NOTI_EX_ERROR_INVALID_PARAMETER;
2576   }
2577   ManagerStub* stub = static_cast<ManagerStub*>(handle);
2578   delete stub;
2579   return NOTI_EX_ERROR_NONE;
2580 }
2581
2582 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2583     noti_ex_item_h **items, int *count) {
2584   if (handle == nullptr || items == nullptr || count == nullptr) {
2585     LOGE("Invalid parameter");
2586     return NOTI_EX_ERROR_INVALID_PARAMETER;
2587   }
2588
2589   try {
2590     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2591     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2592     if (item_list.size() == 0) {
2593       *items = nullptr;
2594       *count = 0;
2595       return NOTI_EX_ERROR_NONE;
2596     }
2597     noti_ex_item_h* added_item =
2598         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2599     if (added_item == nullptr) {
2600       LOGE("Fail to create items");
2601       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2602     }
2603
2604     int idx = 0;
2605     for (auto& i : item_list) {
2606       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2607     }
2608     *items = added_item;
2609     *count = item_list.size();
2610   } catch (Exception &ex) {
2611     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2612     return NOTI_EX_ERROR_IO_ERROR;
2613   }
2614   return NOTI_EX_ERROR_NONE;
2615 }
2616
2617 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2618     noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2619   if (handle == nullptr || channel == nullptr ||
2620       items == nullptr || count == nullptr) {
2621     LOGE("Invalid parameter");
2622     return NOTI_EX_ERROR_INVALID_PARAMETER;
2623   }
2624
2625   try {
2626     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2627     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2628     if (item_list.size() == 0) {
2629       *items = nullptr;
2630       *count = 0;
2631       return NOTI_EX_ERROR_NONE;
2632     }
2633     noti_ex_item_h* added_item =
2634         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2635     if (added_item == nullptr) {
2636       LOGE("Fail to create items");
2637       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2638     }
2639
2640     int idx = 0;
2641     for (auto& i : item_list) {
2642       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2643     }
2644     *items = added_item;
2645     *count = item_list.size();
2646   } catch (Exception &ex) {
2647     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2648     return NOTI_EX_ERROR_IO_ERROR;
2649   }
2650
2651   return NOTI_EX_ERROR_NONE;
2652 }
2653
2654 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2655     noti_ex_item_h noti, int *request_id) {
2656   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2657     LOGE("Invalid parameter");
2658     return NOTI_EX_ERROR_INVALID_PARAMETER;
2659   }
2660   try {
2661     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2662     Handle* sp = static_cast<Handle*>(noti);
2663     if (sp->GetPtr().get() == nullptr) {
2664       LOGE("Invalid noti reference can not be sended");
2665       return NOTI_EX_ERROR_INVALID_PARAMETER;
2666     } else {
2667       *request_id = stub->Update(sp->GetPtr());
2668     }
2669   } catch (Exception &ex) {
2670     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2671     return NOTI_EX_ERROR_IO_ERROR;
2672   }
2673   return NOTI_EX_ERROR_NONE;
2674 }
2675
2676 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2677     noti_ex_item_h noti, int *request_id) {
2678   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2679     LOGE("Invalid parameter");
2680     return NOTI_EX_ERROR_INVALID_PARAMETER;
2681   }
2682   try {
2683     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2684     Handle* item = static_cast<Handle*>(noti);
2685     if (item->GetPtr().get() == nullptr) {
2686       LOGE("Invalid noti reference can not be sended");
2687       return NOTI_EX_ERROR_INVALID_PARAMETER;
2688     } else {
2689       *request_id = stub->Delete(item->GetPtr());
2690     }
2691   } catch (Exception &ex) {
2692     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2693     return NOTI_EX_ERROR_IO_ERROR;
2694   }
2695   return NOTI_EX_ERROR_NONE;
2696 }
2697
2698 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2699     int *request_id) {
2700   if (handle == nullptr || request_id == nullptr) {
2701     LOGE("Invalid parameter");
2702     return NOTI_EX_ERROR_INVALID_PARAMETER;
2703   }
2704   try {
2705     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2706     *request_id = stub->DeleteAll();
2707   } catch (Exception &ex) {
2708     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2709     return NOTI_EX_ERROR_IO_ERROR;
2710   }
2711   return NOTI_EX_ERROR_NONE;
2712 }
2713
2714 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2715     noti_ex_item_h noti, int *request_id) {
2716   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2717     LOGE("Invalid parameter");
2718     return NOTI_EX_ERROR_INVALID_PARAMETER;
2719   }
2720   try {
2721     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2722     Handle* item = static_cast<Handle*>(noti);
2723     if (item->GetPtr().get() == nullptr) {
2724       LOGE("Invalid noti reference can not be sended");
2725       return NOTI_EX_ERROR_INVALID_PARAMETER;
2726     } else {
2727       *request_id = stub->Hide(item->GetPtr());
2728     }
2729   } catch (Exception &ex) {
2730     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2731     return NOTI_EX_ERROR_IO_ERROR;
2732   }
2733   return NOTI_EX_ERROR_NONE;
2734 }
2735
2736 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2737     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2738   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2739     LOGE("Invalid parameter");
2740     return NOTI_EX_ERROR_INVALID_PARAMETER;
2741   }
2742   try {
2743     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2744     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2745     if (ptr == nullptr) {
2746       LOGW("Not exist ID");
2747       *item = nullptr;
2748       return NOTI_EX_ERROR_NONE;
2749     }
2750     *item = new Handle(ptr);
2751   } catch (Exception &ex) {
2752     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2753     return NOTI_EX_ERROR_IO_ERROR;
2754   }
2755   return NOTI_EX_ERROR_NONE;
2756 }
2757
2758 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2759     noti_ex_event_info_h info, noti_ex_error_e error) {
2760   if (handle == nullptr || info == nullptr) {
2761     LOGE("Invalid parameter");
2762     return NOTI_EX_ERROR_INVALID_PARAMETER;
2763   }
2764   try {
2765     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2766     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2767     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2768         static_cast<NotificationError>(error));
2769   } catch (Exception &ex) {
2770     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2771     return NOTI_EX_ERROR_IO_ERROR;
2772   }
2773   return NOTI_EX_ERROR_NONE;
2774 }
2775
2776 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2777     noti_ex_manager_h handle, int *cnt) {
2778
2779   if (handle == nullptr || cnt == nullptr) {
2780     LOGE("Invalid parameter");
2781     return NOTI_EX_ERROR_INVALID_PARAMETER;
2782   }
2783   try {
2784     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2785     *cnt = stub->GetCount();
2786   } catch (Exception &ex) {
2787     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2788     return NOTI_EX_ERROR_IO_ERROR;
2789   }
2790   return NOTI_EX_ERROR_NONE;
2791 }
2792
2793 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2794     const char *id, float min, float current, float max) {
2795   ProgressItem* p;
2796
2797   if (handle == nullptr) {
2798     LOGE("Invalid parameter");
2799     return NOTI_EX_ERROR_INVALID_PARAMETER;
2800   }
2801
2802   if (id)
2803     p = new (std::nothrow) ProgressItem(id, min, current, max);
2804   else
2805     p = new (std::nothrow) ProgressItem(min, current, max);
2806
2807   if (p == nullptr) {
2808     LOGE("Out-of-memory");
2809     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2810   }
2811
2812   *handle = new Handle(shared_ptr<AbstractItem>(p));
2813
2814   return NOTI_EX_ERROR_NONE;
2815 }
2816
2817 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2818     noti_ex_item_h handle, float *current) {
2819   if (handle == nullptr || current == nullptr) {
2820     LOGE("Invalid parameter");
2821     return NOTI_EX_ERROR_INVALID_PARAMETER;
2822   }
2823
2824   Handle *h = static_cast<Handle*>(handle);
2825   if (!h->IsValidType(AbstractItem::Progress)) {
2826     LOGE("Invalid handle type");
2827     return NOTI_EX_ERROR_INVALID_PARAMETER;
2828   }
2829   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2830   *current = p->GetCurrent();
2831
2832   return NOTI_EX_ERROR_NONE;
2833 }
2834
2835 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
2836     noti_ex_item_h handle, float current) {
2837   if (handle == nullptr) {
2838     LOGE("Invalid parameter");
2839     return NOTI_EX_ERROR_INVALID_PARAMETER;
2840   }
2841
2842   Handle *h = static_cast<Handle*>(handle);
2843   if (!h->IsValidType(AbstractItem::Progress)) {
2844     LOGE("Invalid handle type");
2845     return NOTI_EX_ERROR_INVALID_PARAMETER;
2846   }
2847   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2848   p->SetCurrent(current);
2849
2850   return NOTI_EX_ERROR_NONE;
2851 }
2852
2853 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
2854     float *min) {
2855   if (handle == nullptr || min == nullptr) {
2856     LOGE("Invalid parameter");
2857     return NOTI_EX_ERROR_INVALID_PARAMETER;
2858   }
2859
2860   Handle *h = static_cast<Handle*>(handle);
2861   if (!h->IsValidType(AbstractItem::Progress)) {
2862     LOGE("Invalid handle type");
2863     return NOTI_EX_ERROR_INVALID_PARAMETER;
2864   }
2865   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2866   *min = p->GetMin();
2867
2868   return NOTI_EX_ERROR_NONE;
2869 }
2870
2871 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
2872     float *max) {
2873   if (handle == nullptr || max == nullptr) {
2874     LOGE("Invalid parameter");
2875     return NOTI_EX_ERROR_INVALID_PARAMETER;
2876   }
2877
2878   Handle *h = static_cast<Handle*>(handle);
2879   if (!h->IsValidType(AbstractItem::Progress)) {
2880     LOGE("Invalid handle type");
2881     return NOTI_EX_ERROR_INVALID_PARAMETER;
2882   }
2883   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2884   *max = p->GetMax();
2885
2886   return NOTI_EX_ERROR_NONE;
2887 }
2888
2889 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
2890     int* type) {
2891   if (handle == nullptr || type == nullptr) {
2892     LOGE("Invalid parameter");
2893     return NOTI_EX_ERROR_INVALID_PARAMETER;
2894   }
2895
2896   Handle *h = static_cast<Handle*>(handle);
2897   if (!h->IsValidType(AbstractItem::Progress)) {
2898     LOGE("Invalid handle type");
2899     return NOTI_EX_ERROR_INVALID_PARAMETER;
2900   }
2901   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2902   *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
2903
2904   return NOTI_EX_ERROR_NONE;
2905 }
2906
2907 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
2908     int type) {
2909   if (handle == nullptr) {
2910     LOGE("Invalid parameter");
2911     return NOTI_EX_ERROR_INVALID_PARAMETER;
2912   }
2913
2914   Handle *h = static_cast<Handle*>(handle);
2915   if (!h->IsValidType(AbstractItem::Progress)) {
2916     LOGE("Invalid handle type");
2917     return NOTI_EX_ERROR_INVALID_PARAMETER;
2918   }
2919   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2920   p->SetProgressType(static_cast<ProgressItem::Type>(type));
2921
2922   return NOTI_EX_ERROR_NONE;
2923 }
2924
2925 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
2926     noti_ex_reporter_events_s event_callbacks, void *data) {
2927   if (handle == nullptr) {
2928     LOGE("Invalid parameter");
2929     return NOTI_EX_ERROR_INVALID_PARAMETER;
2930   }
2931
2932   ReporterStub* stub = new (std::nothrow) ReporterStub(
2933       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
2934       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
2935   if (stub == nullptr) {
2936     LOGE("Fail to create manager");
2937     return NOTI_EX_ERROR_IO_ERROR;
2938   }
2939   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
2940       new ReporterCallbackInfo(event_callbacks, data)));
2941
2942   *handle = static_cast<noti_ex_reporter_h>(stub);
2943
2944   return NOTI_EX_ERROR_NONE;
2945 }
2946
2947 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
2948   if (handle == nullptr) {
2949     LOGE("Invalid parameter");
2950     return NOTI_EX_ERROR_INVALID_PARAMETER;
2951   }
2952   ReporterStub* stub = static_cast<ReporterStub*>(handle);
2953   delete stub;
2954   return NOTI_EX_ERROR_NONE;
2955 }
2956
2957 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
2958     noti_ex_event_info_h info, noti_ex_error_e error) {
2959   if (handle == nullptr || info == nullptr) {
2960     LOGE("Invalid parameter");
2961     return NOTI_EX_ERROR_INVALID_PARAMETER;
2962   }
2963   try {
2964     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2965     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2966     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2967         static_cast<NotificationError>(error));
2968   } catch (Exception &ex) {
2969     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2970     return NOTI_EX_ERROR_IO_ERROR;
2971   }
2972   return NOTI_EX_ERROR_NONE;
2973 }
2974
2975 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
2976     noti_ex_item_h noti, int *request_id) {
2977   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2978     LOGE("Invalid parameter");
2979     return NOTI_EX_ERROR_INVALID_PARAMETER;
2980   }
2981   try {
2982     ReporterStub* stub = static_cast<ReporterStub*>(handle);
2983     Handle* h = static_cast<Handle*>(noti);
2984     if (h->GetPtr().get() == nullptr) {
2985       LOGE("Invalid noti reference can not be sended");
2986       return NOTI_EX_ERROR_INVALID_PARAMETER;
2987     } else {
2988       *request_id = stub->Post(h->GetPtr());
2989     }
2990   } catch (Exception &ex) {
2991     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2992     return NOTI_EX_ERROR_IO_ERROR;
2993   }
2994   return NOTI_EX_ERROR_NONE;
2995 }
2996
2997 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
2998     noti_ex_item_h *noti_list, int count, int *request_id) {
2999
3000   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3001     LOGE("Invalid parameter");
3002     return NOTI_EX_ERROR_INVALID_PARAMETER;
3003   }
3004   try {
3005     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3006     list<shared_ptr<item::AbstractItem>> notiList;
3007     for (int i = 0; i < count; i++) {
3008       Handle* item = static_cast<Handle*>(noti_list[i]);
3009       notiList.push_back(item->GetPtr());
3010     }
3011     *request_id = stub->Post(notiList);
3012   } catch (Exception &ex) {
3013     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3014     return NOTI_EX_ERROR_IO_ERROR;
3015   }
3016   return NOTI_EX_ERROR_NONE;
3017 }
3018
3019 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3020     noti_ex_item_h noti, int *request_id) {
3021   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3022     LOGE("Invalid parameter");
3023     return NOTI_EX_ERROR_INVALID_PARAMETER;
3024   }
3025   try {
3026     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3027     Handle* item = static_cast<Handle*>(noti);
3028     if (item->GetPtr().get() == nullptr) {
3029       LOGE("Invalid noti reference can not be sended");
3030       return NOTI_EX_ERROR_INVALID_PARAMETER;
3031     } else {
3032       *request_id = stub->Update(item->GetPtr());
3033     }
3034   } catch (Exception &ex) {
3035     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3036     return NOTI_EX_ERROR_IO_ERROR;
3037   }
3038   return NOTI_EX_ERROR_NONE;
3039 }
3040
3041 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3042     noti_ex_item_h noti, int *request_id) {
3043   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3044     LOGE("Invalid parameter");
3045     return NOTI_EX_ERROR_INVALID_PARAMETER;
3046   }
3047   try {
3048     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3049     Handle* item = static_cast<Handle*>(noti);
3050     if (item->GetPtr().get() == nullptr) {
3051       LOGE("Invalid noti reference can not be sended");
3052       return NOTI_EX_ERROR_INVALID_PARAMETER;
3053     } else {
3054       *request_id = stub->Delete(item->GetPtr());
3055     }
3056   } catch (Exception &ex) {
3057     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3058     return NOTI_EX_ERROR_IO_ERROR;
3059   }
3060   return NOTI_EX_ERROR_NONE;
3061 }
3062
3063 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3064     noti_ex_reporter_h handle, int *request_id) {
3065   if (handle == nullptr || request_id == nullptr) {
3066     LOGE("Invalid parameter");
3067     return NOTI_EX_ERROR_INVALID_PARAMETER;
3068   }
3069   try {
3070     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3071     *request_id = stub->DeleteAll();
3072   } catch (Exception &ex) {
3073     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3074     return NOTI_EX_ERROR_IO_ERROR;
3075   }
3076   return NOTI_EX_ERROR_NONE;
3077 }
3078
3079 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3080     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3081   if (handle == nullptr || root_id == nullptr || item == nullptr) {
3082     LOGE("Invalid parameter");
3083     return NOTI_EX_ERROR_INVALID_PARAMETER;
3084   }
3085   try {
3086     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3087     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3088     if (ptr == nullptr) {
3089       LOGW("Not exist ID");
3090       *item = nullptr;
3091       return NOTI_EX_ERROR_NONE;
3092     }
3093     *item = new Handle(ptr);
3094   } catch (Exception &ex) {
3095     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3096     return NOTI_EX_ERROR_IO_ERROR;
3097   }
3098   return NOTI_EX_ERROR_NONE;
3099 }
3100
3101 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3102     const char *id, const char *text, const char *hyperlink) {
3103   if (handle == nullptr || text == nullptr) {
3104     LOGE("Invalid parameter");
3105     return NOTI_EX_ERROR_INVALID_PARAMETER;
3106   }
3107
3108   TextItem* p;
3109
3110   if (id == NULL)
3111     id = "";
3112
3113   if (hyperlink)
3114     p = new (std::nothrow) TextItem(id, std::string(text),
3115                 std::string(hyperlink));
3116   else
3117     p = new (std::nothrow) TextItem(id, std::string(text));
3118
3119   if (p == nullptr) {
3120     LOGE("Out-of-memory");
3121     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3122   }
3123
3124   *handle = new Handle(shared_ptr<AbstractItem>(p));
3125
3126   return NOTI_EX_ERROR_NONE;
3127 }
3128
3129 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3130     const char *contents) {
3131   if (handle == nullptr || contents == nullptr) {
3132     LOGE("Invalid parameter");
3133     return NOTI_EX_ERROR_INVALID_PARAMETER;
3134   }
3135
3136   Handle* p = static_cast<Handle*>(handle);
3137   if (!p->IsValidType(AbstractItem::Text)) {
3138     LOGE("Invalid handle type");
3139     return NOTI_EX_ERROR_INVALID_PARAMETER;
3140   }
3141   TextItem* ti = static_cast<TextItem*>(p->Get());
3142   ti->SetContents(std::string(contents));
3143
3144   return NOTI_EX_ERROR_NONE;
3145 }
3146
3147 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3148     char **contents) {
3149   if (handle == nullptr || contents == 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
3160   TextItem* ti = static_cast<TextItem*>(p->Get());
3161   string str;
3162   if (ti->GetMultiLanguage() != nullptr &&
3163       !ti->GetMultiLanguage()->GetTranslatedString().empty())
3164     str = ti->GetMultiLanguage()->GetTranslatedString();
3165   else if (!ti->GetContents().empty())
3166     str = ti->GetContents();
3167
3168   *contents = strdup(str.c_str());
3169   if (*contents == nullptr) {
3170     LOGE("Out-of-memory");
3171     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3172   }
3173
3174   return NOTI_EX_ERROR_NONE;
3175 }
3176
3177 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3178     noti_ex_item_h handle, char **hyper_link) {
3179   if (handle == nullptr || hyper_link == nullptr) {
3180     LOGE("Invalid parameter");
3181     return NOTI_EX_ERROR_INVALID_PARAMETER;
3182   }
3183
3184   Handle* p = static_cast<Handle*>(handle);
3185   if (!p->IsValidType(AbstractItem::Text)) {
3186     LOGE("Invalid handle type");
3187     return NOTI_EX_ERROR_INVALID_PARAMETER;
3188   }
3189   TextItem* ti = static_cast<TextItem*>(p->Get());
3190   if (!ti->GetHyperLink().empty()) {
3191     *hyper_link = strdup(ti->GetHyperLink().c_str());
3192     if (*hyper_link == nullptr) {
3193       LOGE("Out-of-memory");
3194       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3195     }
3196   } else {
3197     *hyper_link = nullptr;
3198   }
3199
3200   return NOTI_EX_ERROR_NONE;
3201 }
3202
3203 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3204     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3205   if (handle == nullptr) {
3206     LOGE("Invalid parameter");
3207     return NOTI_EX_ERROR_INVALID_PARAMETER;
3208   }
3209
3210   Handle* p = static_cast<Handle*>(handle);
3211   if (!p->IsValidType(AbstractItem::Text)) {
3212     LOGE("Invalid handle type");
3213     return NOTI_EX_ERROR_INVALID_PARAMETER;
3214   }
3215
3216   TextItem* ti = static_cast<TextItem*>(p->Get());
3217   if (multi == nullptr) {
3218     ti->SetMultiLanguage(nullptr);
3219     return NOTI_EX_ERROR_NONE;
3220   }
3221
3222   shared_ptr<MultiLanguage> mul_ptr =
3223       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3224   ti->SetMultiLanguage(mul_ptr);
3225   ti->GetMultiLanguage()->UpdateString();
3226
3227   return NOTI_EX_ERROR_NONE;
3228 }
3229
3230 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3231     const char *id, time_t time) {
3232   TimeItem* p;
3233
3234   if (handle == nullptr) {
3235     LOGE("Invalid parameter");
3236     return NOTI_EX_ERROR_INVALID_PARAMETER;
3237   }
3238
3239   if (time) {
3240     if (id)
3241       p = new (std::nothrow) TimeItem(id, time);
3242     else
3243       p = new (std::nothrow) TimeItem(time);
3244   } else {
3245       p = new (std::nothrow) TimeItem();
3246   }
3247
3248   if (p == nullptr) {
3249     LOGE("Out-of-memory");
3250     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3251   }
3252
3253   *handle = new Handle(shared_ptr<AbstractItem>(p));
3254
3255   return NOTI_EX_ERROR_NONE;
3256 }
3257
3258 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3259     time_t *time) {
3260   if (handle == nullptr || time == nullptr) {
3261     LOGE("Invalid parameter");
3262     return NOTI_EX_ERROR_INVALID_PARAMETER;
3263   }
3264   Handle* h = static_cast<Handle*>(handle);
3265   if (!h->IsValidType(AbstractItem::Time)) {
3266     LOGE("Invalid handle type");
3267     return NOTI_EX_ERROR_INVALID_PARAMETER;
3268   }
3269   TimeItem* p = static_cast<TimeItem*>(h->Get());
3270   *time = p->GetTime();
3271
3272   return NOTI_EX_ERROR_NONE;
3273 }
3274
3275 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3276     time_t time) {
3277   if (handle == nullptr) {
3278     LOGE("Invalid parameter");
3279     return NOTI_EX_ERROR_INVALID_PARAMETER;
3280   }
3281   Handle* h = static_cast<Handle*>(handle);
3282   if (!h->IsValidType(AbstractItem::Time)) {
3283     LOGE("Invalid handle type");
3284     return NOTI_EX_ERROR_INVALID_PARAMETER;
3285   }
3286   TimeItem* p = static_cast<TimeItem*>(h->Get());
3287   p->SetTime(time);
3288
3289   return NOTI_EX_ERROR_NONE;
3290 }
3291
3292 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3293     noti_ex_action_h *handle, const char *extra) {
3294   if (handle == nullptr) {
3295     LOGE("Invalid parameter");
3296     return NOTI_EX_ERROR_INVALID_PARAMETER;
3297   }
3298
3299   string extra_str = "";
3300   if (extra != NULL)
3301     extra_str = string(extra);
3302
3303   shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3304       new (std::nothrow) VisibilityAction(extra_str));
3305   if (ptr == nullptr) {
3306     LOGE("Out-of-memory");
3307     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3308   }
3309
3310   *handle = ptr;
3311
3312   return NOTI_EX_ERROR_NONE;
3313 }
3314
3315 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3316     const char *id, bool visible) {
3317   if (handle == nullptr || id == nullptr) {
3318     LOGE("Invalid parameter");
3319     return NOTI_EX_ERROR_INVALID_PARAMETER;
3320   }
3321
3322   shared_ptr<AbstractAction>* ptr =
3323       static_cast<shared_ptr<AbstractAction>*>(handle);
3324   VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3325   action->SetVisibility(id, visible);
3326
3327   return NOTI_EX_ERROR_NONE;
3328 }
3329
3330 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3331     const char* msgid, const char* format, ...) {
3332   if (handle == nullptr || msgid == nullptr || format == nullptr) {
3333     LOGE("Invalid parameter");
3334     return NOTI_EX_ERROR_INVALID_PARAMETER;
3335   }
3336
3337   const char* format_idx = format;
3338   vector<string> arr;
3339   va_list args;
3340   va_start(args, format);
3341   while (*format_idx != '\0') {
3342     char* arg = nullptr;
3343     int arg_i;
3344     double arg_f;
3345     stringstream stream;
3346     if (*format_idx == '%') {
3347       switch (*(format_idx + 1)) {
3348         case 's':
3349           arg = va_arg(args, char *);
3350           arr.push_back(string(arg));
3351           break;
3352         case 'd':
3353           arg_i = va_arg(args, int);
3354           arr.push_back(to_string(arg_i));
3355           break;
3356         case 'f':
3357           arg_f = va_arg(args, double);
3358           stream << std::fixed << std::setprecision(2) << arg_f;
3359           arr.push_back(stream.str());
3360           break;
3361       }
3362     }
3363     format_idx++;
3364   }
3365   va_end(args);
3366
3367   MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3368   if (p == nullptr) {
3369     LOGE("Out-of-memory");
3370     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3371   }
3372   *handle = new shared_ptr<MultiLanguage>(p);
3373
3374   return NOTI_EX_ERROR_NONE;
3375 }
3376
3377 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3378   if (handle == nullptr) {
3379     LOGE("Invalid parameter");
3380     return NOTI_EX_ERROR_INVALID_PARAMETER;
3381   }
3382
3383   shared_ptr<MultiLanguage>* mul_ptr =
3384       reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3385   delete mul_ptr;
3386   return NOTI_EX_ERROR_NONE;
3387 }
3388
3389 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3390     noti_ex_item_h item, int64_t* private_id) {
3391   if (item == nullptr || private_id == nullptr) {
3392     LOGE("Invalid parameter");
3393     return NOTI_EX_ERROR_INVALID_PARAMETER;
3394   }
3395
3396   Handle* h = static_cast<Handle*>(item);
3397   *private_id = static_pointer_cast<IItemInfoInternal>(
3398       h->Get()->GetInfo())->GetPrivateId();
3399
3400   return NOTI_EX_ERROR_NONE;
3401 }
3402
3403 extern "C" EXPORT_API int noti_ex_item_set_private_id(
3404     noti_ex_item_h item, int64_t priv_id) {
3405   if (item == nullptr) {
3406     LOGE("Invalid parameter");
3407     return NOTI_EX_ERROR_INVALID_PARAMETER;
3408   }
3409
3410   Handle* h = static_cast<Handle*>(item);
3411   static_pointer_cast<IItemInfoInternal>(
3412       h->Get()->GetInfo())->SetPrivateId(priv_id);
3413
3414   return NOTI_EX_ERROR_NONE;
3415 }
3416
3417 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3418   if (list == nullptr) {
3419     LOGE("Invalid parameter");
3420     return NOTI_EX_ERROR_INVALID_PARAMETER;
3421   }
3422
3423   LOGI("Free strings (%d)", count);
3424   for (int i = 0; i < count; i++)
3425     free(list[i]);
3426   free(list);
3427
3428   return NOTI_EX_ERROR_NONE;
3429 }
3430
3431 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3432   if (handle == nullptr) {
3433     LOGE("Invalid parameter");
3434     return NOTI_EX_ERROR_INVALID_PARAMETER;
3435   }
3436   Handle* h = static_cast<Handle*>(handle);
3437   if (!h->IsValidType(AbstractItem::Group)) {
3438     LOGE("Invalid handle type");
3439     return NOTI_EX_ERROR_INVALID_PARAMETER;
3440   }
3441   GroupItem* p = static_cast<GroupItem*>(h->Get());
3442   p->RemoveChildren();
3443
3444   return NOTI_EX_ERROR_NONE;
3445 }