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