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