Release version 0.5.85
[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     Handle handle(i);
1076     int ret = callback(
1077         static_cast<noti_ex_item_h>(&handle), data);
1078     if (ret != NOTI_EX_ERROR_NONE) {
1079       LOGW("callback return (%d) stop foreach", ret);
1080       break;
1081     }
1082   }
1083
1084   return NOTI_EX_ERROR_NONE;
1085 }
1086
1087 extern "C" EXPORT_API int noti_ex_item_image_create(noti_ex_item_h *handle,
1088     const char *id, const char *image_path) {
1089   ImageItem* p;
1090
1091   if (handle == nullptr  || image_path == nullptr) {
1092     LOGE("Invalid parameter");
1093     return NOTI_EX_ERROR_INVALID_PARAMETER;
1094   }
1095
1096   if (id)
1097     p = new (std::nothrow) ImageItem(id, image_path);
1098   else
1099     p = new (std::nothrow) ImageItem(image_path);
1100
1101   if (p == nullptr) {
1102     LOGE("Out-of-memory");
1103     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1104   }
1105
1106   *handle = new Handle(shared_ptr<AbstractItem>(p));
1107
1108   return NOTI_EX_ERROR_NONE;
1109 }
1110
1111 extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
1112     noti_ex_item_h handle, char **image_path) {
1113   if (handle == nullptr || image_path == nullptr) {
1114     LOGE("Invalid parameter");
1115     return NOTI_EX_ERROR_INVALID_PARAMETER;
1116   }
1117   Handle* h = static_cast<Handle*>(handle);
1118   if (!h->IsValidType(AbstractItem::Image)) {
1119     LOGE("Invalid handle type");
1120     return NOTI_EX_ERROR_INVALID_PARAMETER;
1121   }
1122   ImageItem* p = static_cast<ImageItem*>(h->Get());
1123   if (!p->GetImagePath().empty()) {
1124     *image_path = strdup(p->GetImagePath().c_str());
1125     if (*image_path == nullptr) {
1126       LOGE("Out-of-memory");
1127       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1128     }
1129   } else {
1130     *image_path = nullptr;
1131   }
1132
1133   return NOTI_EX_ERROR_NONE;
1134 }
1135
1136 extern "C" EXPORT_API int noti_ex_item_input_selector_create(
1137     noti_ex_item_h *handle, const char *id) {
1138   InputSelectorItem* p;
1139
1140   if (handle == nullptr) {
1141     LOGE("Invalid parameter");
1142     return NOTI_EX_ERROR_INVALID_PARAMETER;
1143   }
1144
1145   if (id)
1146     p = new (std::nothrow) InputSelectorItem(id);
1147   else
1148     p = new (std::nothrow) InputSelectorItem();
1149
1150   if (p == nullptr) {
1151     LOGE("Out-of-memory");
1152     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1153   }
1154
1155   *handle = new Handle(shared_ptr<AbstractItem>(p));
1156
1157   return NOTI_EX_ERROR_NONE;
1158 }
1159
1160 extern "C" EXPORT_API int noti_ex_item_input_selector_get_contents(
1161     noti_ex_item_h handle, char ***contents_list, int *count) {
1162   if (handle == nullptr || contents_list == nullptr || count == nullptr) {
1163     LOGE("Invalid parameter");
1164     return NOTI_EX_ERROR_INVALID_PARAMETER;
1165   }
1166
1167   Handle* h = static_cast<Handle*>(handle);
1168   if (!h->IsValidType(AbstractItem::InputSelector)) {
1169     LOGE("Invalid handle type");
1170     return NOTI_EX_ERROR_INVALID_PARAMETER;
1171   }
1172
1173   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1174   vector<shared_ptr<MultiLanguage>> arr = p->GetMultiLanguageArr();
1175   list<string> contents;
1176   if (arr.size() == 0) {
1177     contents = p->GetContents();
1178   } else {
1179     for (auto& i : arr) {
1180       contents.push_back(i->GetTranslatedString());
1181     }
1182   }
1183
1184   char **list = (char**)calloc(contents.size(), sizeof(char*));
1185   if (list == nullptr) {
1186     LOGE("Out of memory");
1187     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1188   }
1189
1190   int idx = 0;
1191   for (auto& i : contents) {
1192     list[idx] = strdup(i.c_str());
1193     if (list[idx] == nullptr) {
1194       __noti_ex_free_str_array(list, idx);
1195       LOGE("Out of memory");
1196       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1197     }
1198     idx++;
1199   }
1200
1201   *count = contents.size();
1202   *contents_list = list;
1203
1204   return NOTI_EX_ERROR_NONE;
1205 }
1206
1207 extern "C" EXPORT_API int noti_ex_item_input_selector_set_contents(
1208     noti_ex_item_h handle, const char **contents, int count) {
1209   if (handle == nullptr || contents == nullptr) {
1210     LOGE("Invalid parameter");
1211     return NOTI_EX_ERROR_INVALID_PARAMETER;
1212   }
1213
1214   list<string> new_contents;
1215   Handle* h = static_cast<Handle*>(handle);
1216   if (!h->IsValidType(AbstractItem::InputSelector)) {
1217     LOGE("Invalid handle type");
1218     return NOTI_EX_ERROR_INVALID_PARAMETER;
1219   }
1220   InputSelectorItem* p = static_cast<InputSelectorItem*>(h->Get());
1221   for (int i = 0; i < count; i++) {
1222     new_contents.push_back(contents[i]);
1223   }
1224   p->SetContents(move(new_contents));
1225
1226   return NOTI_EX_ERROR_NONE;
1227 }
1228
1229 extern "C" EXPORT_API int noti_ex_item_input_selector_set_multi_language_contents(
1230     noti_ex_item_h handle, noti_ex_multi_lang_h* multi_language_list, int count) {
1231   if (handle == nullptr) {
1232     LOGE("Invalid parameter");
1233     return NOTI_EX_ERROR_INVALID_PARAMETER;
1234   }
1235
1236   Handle* p = static_cast<Handle*>(handle);
1237   if (!p->IsValidType(AbstractItem::InputSelector)) {
1238     LOGE("Invalid handle type");
1239     return NOTI_EX_ERROR_INVALID_PARAMETER;
1240   }
1241
1242   vector<shared_ptr<MultiLanguage>> m_list;
1243   for (int i = 0; i < count; i++) {
1244     shared_ptr<MultiLanguage> mul_ptr =
1245       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi_language_list[i]);
1246     mul_ptr->UpdateString();
1247     m_list.push_back(mul_ptr);
1248   }
1249
1250   InputSelectorItem* input = static_cast<InputSelectorItem*>(p->Get());
1251   input->SetMultiLanguage(m_list);
1252
1253   return NOTI_EX_ERROR_NONE;
1254 }
1255
1256 extern "C" EXPORT_API int noti_ex_color_create(noti_ex_color_h *handle,
1257     unsigned char a, unsigned char r, unsigned char g, unsigned char b) {
1258   if (handle == nullptr) {
1259     LOGE("Invalid parameter");
1260     return NOTI_EX_ERROR_INVALID_PARAMETER;
1261   }
1262
1263   auto* ptr = new (std::nothrow) shared_ptr<Color>(
1264       new (std::nothrow) Color(a, r, g, b));
1265   if (ptr == nullptr || ptr->get() == nullptr) {
1266     LOGE("Out-of-memory");
1267     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1268   }
1269
1270   *handle = ptr;
1271
1272   return NOTI_EX_ERROR_NONE;
1273 }
1274
1275 extern "C" EXPORT_API int noti_ex_color_destroy(noti_ex_color_h handle) {
1276   if (handle == nullptr) {
1277     LOGE("Invalid parameter");
1278     return NOTI_EX_ERROR_INVALID_PARAMETER;
1279   }
1280
1281   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1282   delete p;
1283
1284   return NOTI_EX_ERROR_NONE;
1285 }
1286
1287 extern "C" EXPORT_API int noti_ex_color_get_alpha(noti_ex_color_h handle,
1288     unsigned char *val) {
1289   if (handle == nullptr || val == nullptr) {
1290     LOGE("Invalid parameter");
1291     return NOTI_EX_ERROR_INVALID_PARAMETER;
1292   }
1293
1294   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1295   *val = (*p)->GetAVal();
1296
1297   return NOTI_EX_ERROR_NONE;
1298 }
1299
1300 extern "C" EXPORT_API int noti_ex_color_get_red(noti_ex_color_h handle,
1301     unsigned char *val) {
1302   if (handle == nullptr || val == nullptr) {
1303     LOGE("Invalid parameter");
1304     return NOTI_EX_ERROR_INVALID_PARAMETER;
1305   }
1306
1307   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1308   *val = (*p)->GetRVal();
1309
1310   return NOTI_EX_ERROR_NONE;
1311 }
1312
1313 extern "C" EXPORT_API int noti_ex_color_get_green(noti_ex_color_h handle,
1314     unsigned char *val) {
1315   if (handle == nullptr || val == nullptr) {
1316     LOGE("Invalid parameter");
1317     return NOTI_EX_ERROR_INVALID_PARAMETER;
1318   }
1319
1320   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1321   *val = (*p)->GetGVal();
1322
1323   return NOTI_EX_ERROR_NONE;
1324 }
1325
1326 extern "C" EXPORT_API int noti_ex_color_get_blue(noti_ex_color_h handle,
1327     unsigned char *val) {
1328   if (handle == nullptr || val == nullptr) {
1329     LOGE("Invalid parameter");
1330     return NOTI_EX_ERROR_INVALID_PARAMETER;
1331   }
1332
1333   shared_ptr<Color>* p = static_cast<shared_ptr<Color>*>(handle);
1334   *val = (*p)->GetBVal();
1335
1336   return NOTI_EX_ERROR_NONE;
1337 }
1338
1339 extern "C" EXPORT_API int noti_ex_padding_create(noti_ex_padding_h *handle,
1340     int left, int top, int right, int bottom) {
1341   if (handle == nullptr) {
1342     LOGE("Invalid parameter");
1343     return NOTI_EX_ERROR_INVALID_PARAMETER;
1344   }
1345
1346   auto* ptr = new (std::nothrow) shared_ptr<Padding>(
1347       new (std::nothrow) Padding(left, top, right, bottom));
1348   if (ptr == nullptr || ptr->get() == nullptr) {
1349     LOGE("Out-of-memory");
1350     if (ptr != nullptr)
1351       delete(ptr);
1352     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1353   }
1354
1355   *handle = ptr;
1356
1357   return NOTI_EX_ERROR_NONE;
1358 }
1359
1360 extern "C" EXPORT_API int noti_ex_padding_destroy(noti_ex_padding_h handle) {
1361   if (handle == nullptr) {
1362     LOGE("Invalid parameter");
1363     return NOTI_EX_ERROR_INVALID_PARAMETER;
1364   }
1365
1366   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1367   delete p;
1368
1369   return NOTI_EX_ERROR_NONE;
1370 }
1371
1372 extern "C" EXPORT_API int noti_ex_padding_get_left(noti_ex_padding_h handle,
1373     int *val) {
1374   if (handle == nullptr || val == nullptr) {
1375     LOGE("Invalid parameter");
1376     return NOTI_EX_ERROR_INVALID_PARAMETER;
1377   }
1378
1379   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1380   *val = (*p)->GetLeft();
1381
1382   return NOTI_EX_ERROR_NONE;
1383 }
1384
1385 extern "C" EXPORT_API int noti_ex_padding_get_top(noti_ex_padding_h handle,
1386     int *val) {
1387   if (handle == nullptr || val == nullptr) {
1388     LOGE("Invalid parameter");
1389     return NOTI_EX_ERROR_INVALID_PARAMETER;
1390   }
1391
1392   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1393   *val = (*p)->GetTop();
1394
1395   return NOTI_EX_ERROR_NONE;
1396 }
1397
1398 extern "C" EXPORT_API int noti_ex_padding_get_right(noti_ex_padding_h handle,
1399     int *val) {
1400   if (handle == nullptr || val == nullptr) {
1401     LOGE("Invalid parameter");
1402     return NOTI_EX_ERROR_INVALID_PARAMETER;
1403   }
1404
1405   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1406   *val = (*p)->GetRight();
1407
1408   return NOTI_EX_ERROR_NONE;
1409 }
1410
1411 extern "C" EXPORT_API int noti_ex_padding_get_bottom(noti_ex_padding_h handle,
1412     int *val) {
1413   if (handle == nullptr || val == nullptr) {
1414     LOGE("Invalid parameter");
1415     return NOTI_EX_ERROR_INVALID_PARAMETER;
1416   }
1417
1418   shared_ptr<Padding>* p = static_cast<shared_ptr<Padding>*>(handle);
1419   *val = (*p)->GetBottom();
1420
1421   return NOTI_EX_ERROR_NONE;
1422 }
1423
1424 extern "C" EXPORT_API int noti_ex_geometry_create(noti_ex_geometry_h *handle,
1425     int x, int y, int w, int h) {
1426   if (handle == nullptr) {
1427     LOGE("Invalid parameter");
1428     return NOTI_EX_ERROR_INVALID_PARAMETER;
1429   }
1430
1431   auto* ptr = new (std::nothrow) shared_ptr<Geometry>(
1432       new (std::nothrow) Geometry(x, y, w, h));
1433   if (ptr == nullptr || ptr->get() == nullptr) {
1434     LOGE("Out-of-memory");
1435     if (ptr != nullptr)
1436       delete ptr;
1437     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1438   }
1439
1440   *handle = ptr;
1441
1442   return NOTI_EX_ERROR_NONE;
1443 }
1444
1445 extern "C" EXPORT_API int noti_ex_geometry_destroy(noti_ex_geometry_h handle) {
1446   if (handle == nullptr) {
1447     LOGE("Invalid parameter");
1448     return NOTI_EX_ERROR_INVALID_PARAMETER;
1449   }
1450
1451   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1452   delete p;
1453
1454   return NOTI_EX_ERROR_NONE;
1455 }
1456
1457 extern "C" EXPORT_API int noti_ex_geometry_get_x(noti_ex_geometry_h handle,
1458     int *val) {
1459   if (handle == nullptr || val == nullptr) {
1460     LOGE("Invalid parameter");
1461     return NOTI_EX_ERROR_INVALID_PARAMETER;
1462   }
1463
1464   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1465   *val = (*p)->GetX();
1466
1467   return NOTI_EX_ERROR_NONE;
1468 }
1469
1470 extern "C" EXPORT_API int noti_ex_geometry_get_y(noti_ex_geometry_h handle,
1471     int *val) {
1472   if (handle == nullptr || val == nullptr) {
1473     LOGE("Invalid parameter");
1474     return NOTI_EX_ERROR_INVALID_PARAMETER;
1475   }
1476
1477   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1478   *val = (*p)->GetY();
1479
1480   return NOTI_EX_ERROR_NONE;
1481 }
1482
1483 extern "C" EXPORT_API int noti_ex_geometry_get_width(noti_ex_geometry_h handle,
1484     int *val) {
1485   if (handle == nullptr || val == nullptr) {
1486     LOGE("Invalid parameter");
1487     return NOTI_EX_ERROR_INVALID_PARAMETER;
1488   }
1489
1490   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1491   *val = (*p)->GetWidth();
1492
1493   return NOTI_EX_ERROR_NONE;
1494 }
1495
1496 extern "C" EXPORT_API int noti_ex_geometry_get_height(noti_ex_geometry_h handle,
1497     int *val) {
1498   if (handle == nullptr || val == nullptr) {
1499     LOGE("Invalid parameter");
1500     return NOTI_EX_ERROR_INVALID_PARAMETER;
1501   }
1502
1503   shared_ptr<Geometry>* p = static_cast<shared_ptr<Geometry>*>(handle);
1504   *val = (*p)->GetHeight();
1505
1506   return NOTI_EX_ERROR_NONE;
1507 }
1508
1509 extern "C" EXPORT_API int noti_ex_style_create(noti_ex_style_h *handle,
1510     noti_ex_color_h color,
1511     noti_ex_padding_h padding,
1512     noti_ex_geometry_h geometry) {
1513   if (handle == nullptr) {
1514     LOGE("Invalid parameter");
1515     return NOTI_EX_ERROR_INVALID_PARAMETER;
1516   }
1517
1518   shared_ptr<Color> col = (color == nullptr) ?
1519       nullptr : *(static_cast<shared_ptr<Color>*>(color));
1520   shared_ptr<Padding> padd = (padding == nullptr) ?
1521       nullptr : *(static_cast<shared_ptr<Padding>*>(padding));
1522   shared_ptr<Geometry> geo = (geometry == nullptr) ?
1523       nullptr : *(static_cast<shared_ptr<Geometry>*>(geometry));
1524
1525   auto* ptr = new (std::nothrow) shared_ptr<Style>(
1526       new (std::nothrow) Style(col, padd, geo));
1527   if (ptr == nullptr || ptr->get() == nullptr) {
1528     LOGE("Out-of-memory");
1529     if (ptr != nullptr)
1530       delete ptr;
1531     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1532   }
1533
1534   *handle = ptr;
1535
1536   return NOTI_EX_ERROR_NONE;
1537 }
1538
1539 extern "C" EXPORT_API int noti_ex_style_destroy(noti_ex_style_h handle) {
1540   if (handle == nullptr) {
1541     LOGE("Invalid parameter");
1542     return NOTI_EX_ERROR_INVALID_PARAMETER;
1543   }
1544
1545   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1546   delete p;
1547
1548   return NOTI_EX_ERROR_NONE;
1549 }
1550
1551 extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
1552     noti_ex_padding_h *padding) {
1553   if (handle == nullptr || padding == nullptr) {
1554     LOGE("Invalid parameter");
1555     return NOTI_EX_ERROR_INVALID_PARAMETER;
1556   }
1557
1558   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1559   if ((*p)->GetPadding() == nullptr) {
1560     LOGW("Padding info is null");
1561     return NOTI_EX_ERROR_INVALID_PARAMETER;
1562   }
1563
1564   shared_ptr<Padding>* padd = new (std::nothrow) shared_ptr<Padding>(
1565       new (std::nothrow) Padding(*((*p)->GetPadding())));
1566   if (padd == nullptr || padd->get() == nullptr) {
1567     LOGE("Out-of-memory");
1568     *padding = nullptr;
1569     return NOTI_EX_ERROR_NONE;
1570   }
1571
1572   *padding = padd;
1573
1574   return NOTI_EX_ERROR_NONE;
1575 }
1576
1577
1578 extern "C" EXPORT_API int noti_ex_style_set_padding(noti_ex_style_h handle,
1579     noti_ex_padding_h padding) {
1580   if (handle == nullptr) {
1581     LOGE("Invalid parameter");
1582     return NOTI_EX_ERROR_INVALID_PARAMETER;
1583   }
1584
1585   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1586   if (padding == nullptr) {
1587     (*p)->SetPadding(nullptr);
1588     return NOTI_EX_ERROR_NONE;
1589   }
1590
1591   shared_ptr<Padding>* padd = static_cast<shared_ptr<Padding>*>(padding);
1592   (*p)->SetPadding(*padd);
1593
1594   return NOTI_EX_ERROR_NONE;
1595 }
1596
1597 extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
1598     noti_ex_color_h *color) {
1599   if (handle == nullptr || color == nullptr) {
1600     LOGE("Invalid parameter");
1601     return NOTI_EX_ERROR_INVALID_PARAMETER;
1602   }
1603
1604   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1605   if ((*p)->GetColor() == nullptr) {
1606     LOGW("Color info is null");
1607     *color = nullptr;
1608     return NOTI_EX_ERROR_NONE;
1609   }
1610
1611   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1612       new (std::nothrow) Color(*((*p)->GetColor())));
1613   if (col == nullptr || col->get() == nullptr) {
1614     LOGE("Out-of-memory");
1615     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1616   }
1617
1618   *color = col;
1619
1620   return NOTI_EX_ERROR_NONE;
1621 }
1622
1623 extern "C" EXPORT_API int noti_ex_style_set_color(
1624     noti_ex_style_h handle, noti_ex_color_h color) {
1625   if (handle == nullptr) {
1626     LOGE("Invalid parameter");
1627     return NOTI_EX_ERROR_INVALID_PARAMETER;
1628   }
1629
1630   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1631   if (color == nullptr) {
1632     (*p)->SetColor(nullptr);
1633     return NOTI_EX_ERROR_NONE;
1634   }
1635
1636   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1637   (*p)->SetColor(*col);
1638
1639   return NOTI_EX_ERROR_NONE;
1640 }
1641
1642 extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
1643     noti_ex_geometry_h *geometry) {
1644   if (handle == nullptr || geometry == nullptr) {
1645     LOGE("Invalid parameter");
1646     return NOTI_EX_ERROR_INVALID_PARAMETER;
1647   }
1648
1649   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1650   if ((*p)->GetGeometry() == nullptr) {
1651     LOGW("Geometry info is null");
1652     *geometry = nullptr;
1653     return NOTI_EX_ERROR_NONE;
1654   }
1655
1656   shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
1657       new (std::nothrow) Geometry(*((*p)->GetGeometry())));
1658   if (geo == nullptr || geo->get() == nullptr) {
1659     LOGE("Out-of-memory");
1660     if (geo != nullptr)
1661       delete geo;
1662     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1663   }
1664
1665   *geometry = geo;
1666
1667   return NOTI_EX_ERROR_NONE;
1668 }
1669
1670 extern "C" EXPORT_API int noti_ex_style_set_geometry(
1671     noti_ex_style_h handle, noti_ex_geometry_h geometry) {
1672   if (handle == nullptr) {
1673     LOGE("Invalid parameter");
1674     return NOTI_EX_ERROR_INVALID_PARAMETER;
1675   }
1676
1677   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1678   if (geometry == nullptr) {
1679     (*p)->SetGeometry(nullptr);
1680     return NOTI_EX_ERROR_NONE;
1681   }
1682
1683   shared_ptr<Geometry>* geo = static_cast<shared_ptr<Geometry>*>(geometry);
1684   (*p)->SetGeometry(*geo);
1685
1686   return NOTI_EX_ERROR_NONE;
1687 }
1688
1689 extern "C" EXPORT_API int noti_ex_style_get_background_image(
1690     noti_ex_style_h handle, char** background_image) {
1691   if (handle == nullptr || background_image == nullptr) {
1692     LOGE("Invalid parameter");
1693     return NOTI_EX_ERROR_INVALID_PARAMETER;
1694   }
1695
1696   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1697
1698   if ((*p)->GetBackgroundImage().empty())
1699     *background_image = nullptr;
1700   else
1701     *background_image = strdup((*p)->GetBackgroundImage().c_str());
1702
1703   return NOTI_EX_ERROR_NONE;
1704 }
1705
1706 extern "C" EXPORT_API int noti_ex_style_set_background_image(
1707     noti_ex_style_h handle, char* background_image) {
1708   if (handle == nullptr) {
1709     LOGE("Invalid parameter");
1710     return NOTI_EX_ERROR_INVALID_PARAMETER;
1711   }
1712
1713   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1714   if (background_image == nullptr)
1715     (*p)->SetBackgroundImage("");
1716   else
1717     (*p)->SetBackgroundImage(background_image);
1718
1719   return NOTI_EX_ERROR_NONE;
1720 }
1721
1722 extern "C" EXPORT_API int noti_ex_style_get_background_color(
1723     noti_ex_style_h handle, noti_ex_color_h* color) {
1724   if (handle == nullptr || color == nullptr) {
1725     LOGE("Invalid parameter");
1726     return NOTI_EX_ERROR_INVALID_PARAMETER;
1727   }
1728
1729   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1730   if ((*p)->GetBackgroundColor() == nullptr) {
1731     LOGW("Color info is null");
1732     *color = nullptr;
1733     return NOTI_EX_ERROR_NONE;
1734   }
1735
1736   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1737       new (std::nothrow) Color(*((*p)->GetBackgroundColor())));
1738   if (col == nullptr || col->get() == nullptr) {
1739     LOGE("Out-of-memory");
1740     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1741   }
1742
1743   *color = col;
1744
1745   return NOTI_EX_ERROR_NONE;
1746 }
1747
1748 extern "C" EXPORT_API int noti_ex_style_set_background_color(
1749     noti_ex_style_h handle, noti_ex_color_h color) {
1750   if (handle == nullptr) {
1751     LOGE("Invalid parameter");
1752     return NOTI_EX_ERROR_INVALID_PARAMETER;
1753   }
1754
1755   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
1756   if (color == nullptr) {
1757     (*p)->SetBackgroundColor(nullptr);
1758     return NOTI_EX_ERROR_NONE;
1759   }
1760
1761   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1762   (*p)->SetBackgroundColor(*col);
1763
1764   return NOTI_EX_ERROR_NONE;
1765 }
1766
1767 extern "C" EXPORT_API int noti_ex_led_info_create(noti_ex_led_info_h *handle,
1768     noti_ex_color_h color) {
1769   if (handle == nullptr || color == nullptr) {
1770     LOGE("Invalid parameter");
1771     return NOTI_EX_ERROR_INVALID_PARAMETER;
1772   }
1773
1774   shared_ptr<Color>* color_ptr = static_cast<shared_ptr<Color>*>(color);
1775   shared_ptr<LEDInfo>* p = new (std::nothrow) shared_ptr<LEDInfo>(
1776       new (std::nothrow) LEDInfo(*color_ptr));
1777   if (p == nullptr) {
1778     LOGE("Out-of-memory");
1779     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1780   }
1781
1782   *handle = p;
1783
1784   return NOTI_EX_ERROR_NONE;
1785 }
1786
1787 extern "C" EXPORT_API int noti_ex_led_info_destroy(noti_ex_led_info_h handle) {
1788   if (handle == nullptr) {
1789     LOGE("Invalid parameter");
1790     return NOTI_EX_ERROR_INVALID_PARAMETER;
1791   }
1792
1793   shared_ptr<LEDInfo>* led_ptr =
1794       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1795   delete led_ptr;
1796   return NOTI_EX_ERROR_NONE;
1797 }
1798
1799 extern "C" EXPORT_API int noti_ex_led_info_set_on_period(
1800     noti_ex_led_info_h handle, int ms) {
1801   if (handle == nullptr) {
1802     LOGE("Invalid parameter");
1803     return NOTI_EX_ERROR_INVALID_PARAMETER;
1804   }
1805
1806   shared_ptr<LEDInfo>* led_ptr =
1807       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1808   (*led_ptr)->SetOnPeriod(ms);
1809
1810   return NOTI_EX_ERROR_NONE;
1811 }
1812
1813 extern "C" EXPORT_API int noti_ex_led_info_get_on_period(
1814     noti_ex_led_info_h handle, int *ms) {
1815   if (handle == nullptr || ms == nullptr) {
1816     LOGE("Invalid parameter");
1817     return NOTI_EX_ERROR_INVALID_PARAMETER;
1818   }
1819
1820   shared_ptr<LEDInfo>* led_ptr =
1821       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1822   *ms = (*led_ptr)->GetOnPeriod();
1823
1824   return NOTI_EX_ERROR_NONE;
1825 }
1826
1827 extern "C" EXPORT_API int noti_ex_led_info_set_off_period(
1828     noti_ex_led_info_h handle, int ms) {
1829   if (handle == nullptr) {
1830     LOGE("Invalid parameter");
1831     return NOTI_EX_ERROR_INVALID_PARAMETER;
1832   }
1833
1834   shared_ptr<LEDInfo>* led_ptr =
1835       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1836   (*led_ptr)->SetOffPeriod(ms);
1837
1838   return NOTI_EX_ERROR_NONE;
1839 }
1840
1841 extern "C" EXPORT_API int noti_ex_led_info_get_off_period(
1842     noti_ex_led_info_h handle, int *ms) {
1843   if (handle == nullptr) {
1844     LOGE("Invalid parameter");
1845     return NOTI_EX_ERROR_INVALID_PARAMETER;
1846   }
1847
1848   shared_ptr<LEDInfo>* led_ptr =
1849       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1850   *ms = (*led_ptr)->GetOffPeriod();
1851
1852   return NOTI_EX_ERROR_NONE;
1853 }
1854
1855 extern "C" EXPORT_API int noti_ex_led_info_get_color(
1856     noti_ex_led_info_h handle, noti_ex_color_h *color) {
1857   if (handle == nullptr) {
1858     LOGE("Invalid parameter");
1859     return NOTI_EX_ERROR_INVALID_PARAMETER;
1860   }
1861
1862   shared_ptr<LEDInfo>* led_ptr =
1863       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
1864   if ((*led_ptr)->GetColor() == nullptr) {
1865     LOGW("Color is null");
1866     *color = nullptr;
1867     return NOTI_EX_ERROR_NONE;
1868   }
1869
1870   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
1871       new (std::nothrow) Color(*((*led_ptr)->GetColor())));
1872   if (col == nullptr || col->get() == nullptr) {
1873     LOGE("Out-of-memory");
1874     return NOTI_EX_ERROR_OUT_OF_MEMORY;
1875   }
1876
1877   *color = col;
1878
1879   return NOTI_EX_ERROR_NONE;
1880 }
1881
1882 extern "C" EXPORT_API int noti_ex_led_info_set_color(
1883     noti_ex_led_info_h handle, noti_ex_color_h color) {
1884   if (handle == nullptr) {
1885     LOGE("Invalid parameter");
1886     return NOTI_EX_ERROR_INVALID_PARAMETER;
1887   }
1888
1889   shared_ptr<LEDInfo>* p = static_cast<shared_ptr<LEDInfo>*>(handle);
1890   if (color == nullptr) {
1891     (*p)->SetColor(nullptr);
1892     return NOTI_EX_ERROR_NONE;
1893   }
1894
1895   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
1896   (*p)->SetColor(*col);
1897
1898   return NOTI_EX_ERROR_NONE;
1899 }
1900
1901 extern "C" EXPORT_API int noti_ex_action_destroy(noti_ex_action_h handle) {
1902   if (handle == nullptr) {
1903     LOGE("Invalid parameter");
1904     return NOTI_EX_ERROR_INVALID_PARAMETER;
1905   }
1906
1907   shared_ptr<AbstractAction>* ptr =
1908       static_cast<shared_ptr<AbstractAction>*>(handle);
1909   delete ptr;
1910
1911   return NOTI_EX_ERROR_NONE;
1912 }
1913
1914 extern "C" EXPORT_API int noti_ex_action_get_type(noti_ex_action_h handle,
1915     int *type) {
1916   if (handle == nullptr || type == nullptr) {
1917     LOGE("Invalid parameter");
1918     return NOTI_EX_ERROR_INVALID_PARAMETER;
1919   }
1920
1921   shared_ptr<AbstractAction>* ptr =
1922       static_cast<shared_ptr<AbstractAction>*>(handle);
1923   *type = (*ptr)->GetType();
1924
1925   return NOTI_EX_ERROR_NONE;
1926 }
1927
1928 extern "C" EXPORT_API int noti_ex_action_is_local(noti_ex_action_h handle,
1929     bool *local) {
1930   if (handle == nullptr || local == nullptr) {
1931     LOGE("Invalid parameter");
1932     return NOTI_EX_ERROR_INVALID_PARAMETER;
1933   }
1934
1935   shared_ptr<AbstractAction>* ptr =
1936       static_cast<shared_ptr<AbstractAction>*>(handle);
1937   *local = (*ptr)->IsLocal();
1938
1939   return NOTI_EX_ERROR_NONE;
1940 }
1941
1942 extern "C" EXPORT_API int noti_ex_action_execute(noti_ex_action_h handle,
1943     noti_ex_item_h item) {
1944   if (handle == nullptr || item == nullptr) {
1945     LOGE("Invalid parameter");
1946     return NOTI_EX_ERROR_INVALID_PARAMETER;
1947   }
1948   shared_ptr<AbstractAction>* ptr =
1949       static_cast<shared_ptr<AbstractAction>*>(handle);
1950   Handle* ih = static_cast<Handle*>(item);
1951   (*ptr)->Execute(ih->GetPtr());
1952
1953   return NOTI_EX_ERROR_NONE;
1954 }
1955
1956 extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
1957     char **extra) {
1958   if (handle == nullptr || extra == nullptr) {
1959     LOGE("Invalid parameter");
1960     return NOTI_EX_ERROR_INVALID_PARAMETER;
1961   }
1962
1963   shared_ptr<AbstractAction>* ptr =
1964       static_cast<shared_ptr<AbstractAction>*>(handle);
1965   if (!(*ptr)->GetExtra().empty()) {
1966     *extra = strdup((*ptr)->GetExtra().c_str());
1967     if (*extra == nullptr) {
1968       LOGE("Out-of-memory");
1969       return NOTI_EX_ERROR_OUT_OF_MEMORY;
1970     }
1971   } else {
1972     *extra = nullptr;
1973   }
1974
1975   return NOTI_EX_ERROR_NONE;
1976 }
1977
1978 extern "C" EXPORT_API int noti_ex_item_info_get_hide_time(
1979     noti_ex_item_info_h handle, int *hide_time) {
1980   if (handle == nullptr || hide_time == nullptr) {
1981     LOGE("Invalid parameter");
1982     return NOTI_EX_ERROR_INVALID_PARAMETER;
1983   }
1984   IItemInfo* p = static_cast<IItemInfo*>(handle);
1985   *hide_time = p->GetHideTime();
1986   return NOTI_EX_ERROR_NONE;
1987 }
1988
1989 extern "C" EXPORT_API int noti_ex_item_info_set_hide_time(
1990     noti_ex_item_info_h handle, int hide_time) {
1991   if (handle == nullptr) {
1992     LOGE("Invalid parameter");
1993     return NOTI_EX_ERROR_INVALID_PARAMETER;
1994   }
1995   IItemInfo* p = static_cast<IItemInfo*>(handle);
1996   p->SetHideTime(hide_time);
1997   return NOTI_EX_ERROR_NONE;
1998 }
1999
2000 extern "C" EXPORT_API int noti_ex_item_info_get_delete_time(
2001     noti_ex_item_info_h handle, int *delete_time) {
2002   if (handle == nullptr || delete_time == nullptr) {
2003     LOGE("Invalid parameter");
2004     return NOTI_EX_ERROR_INVALID_PARAMETER;
2005   }
2006   IItemInfo* p = static_cast<IItemInfo*>(handle);
2007   *delete_time = p->GetDeleteTime();
2008   return NOTI_EX_ERROR_NONE;
2009 }
2010
2011 extern "C" EXPORT_API int noti_ex_item_info_set_delete_time(
2012     noti_ex_item_info_h handle, int delete_time) {
2013   if (handle == nullptr) {
2014     LOGE("Invalid parameter");
2015     return NOTI_EX_ERROR_INVALID_PARAMETER;
2016   }
2017   IItemInfo* p = static_cast<IItemInfo*>(handle);
2018   p->SetDeleteTime(delete_time);
2019   return NOTI_EX_ERROR_NONE;
2020 }
2021
2022 extern "C" EXPORT_API int noti_ex_item_info_get_time(
2023     noti_ex_item_info_h handle, time_t *time) {
2024   if (handle == nullptr || time == nullptr) {
2025     LOGE("Invalid parameter");
2026     return NOTI_EX_ERROR_INVALID_PARAMETER;
2027   }
2028
2029   IItemInfo* p = static_cast<IItemInfo*>(handle);
2030   *time = p->GetTime();
2031   return NOTI_EX_ERROR_NONE;
2032 }
2033
2034 extern "C" EXPORT_API int noti_ex_item_destroy(noti_ex_item_h handle) {
2035   if (handle == nullptr) {
2036     LOGE("Invalid parameter");
2037     return NOTI_EX_ERROR_INVALID_PARAMETER;
2038   }
2039
2040   Handle* h = static_cast<Handle*>(handle);
2041   delete h;
2042   return NOTI_EX_ERROR_NONE;
2043 }
2044
2045 extern "C" EXPORT_API int noti_ex_item_find_by_id(noti_ex_item_h handle,
2046     const char *id, noti_ex_item_h *item) {
2047   if (handle == nullptr) {
2048     LOGE("Invalid parameter");
2049     return NOTI_EX_ERROR_INVALID_PARAMETER;
2050   }
2051
2052   Handle* p = static_cast<Handle*>(handle);
2053   AbstractItem& find_item = p->Get()->FindByID(string(id));
2054   if (find_item.GetType() == AbstractItem::NullObject) {
2055     LOGW("Not exist ID");
2056     *item = nullptr;
2057     return NOTI_EX_ERROR_NONE;
2058   }
2059
2060   *item = new Handle(&find_item);
2061   return NOTI_EX_ERROR_NONE;
2062 }
2063
2064 extern "C" EXPORT_API int noti_ex_item_get_type(noti_ex_item_h handle,
2065     int *type) {
2066   if (handle == nullptr || type == nullptr) {
2067     LOGE("Invalid parameter");
2068     return NOTI_EX_ERROR_INVALID_PARAMETER;
2069   }
2070
2071   Handle* h = static_cast<Handle*>(handle);
2072   AbstractItem* p = h->Get();
2073   *type = p->GetType();
2074   return NOTI_EX_ERROR_NONE;
2075 }
2076
2077 extern "C" EXPORT_API int noti_ex_item_get_id(noti_ex_item_h handle,
2078     char **id) {
2079   if (handle == nullptr || id == nullptr) {
2080     LOGE("Invalid parameter");
2081     return NOTI_EX_ERROR_INVALID_PARAMETER;
2082   }
2083   Handle* h = static_cast<Handle*>(handle);
2084   AbstractItem* p = h->Get();
2085   *id = strdup(p->GetId().c_str());
2086   return NOTI_EX_ERROR_NONE;
2087 }
2088
2089 extern "C" EXPORT_API int noti_ex_item_set_id(noti_ex_item_h handle,
2090     const char *id) {
2091   if (handle == nullptr || id == nullptr) {
2092     LOGE("Invalid parameter");
2093     return NOTI_EX_ERROR_INVALID_PARAMETER;
2094   }
2095   Handle* p = static_cast<Handle*>(handle);
2096   p->Get()->SetId(id);
2097   return NOTI_EX_ERROR_NONE;
2098 }
2099
2100 extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
2101     noti_ex_action_h *action) {
2102   if (handle == nullptr || action == nullptr) {
2103     LOGE("Invalid parameter");
2104     return NOTI_EX_ERROR_INVALID_PARAMETER;
2105   }
2106   Handle* p = static_cast<Handle*>(handle);
2107   if (p->Get()->GetAction() == nullptr) {
2108     *action = nullptr;
2109     return NOTI_EX_ERROR_NONE;
2110   }
2111   *action = static_cast<noti_ex_action_h>(new shared_ptr<AbstractAction>(
2112       p->Get()->GetAction()));
2113
2114   return NOTI_EX_ERROR_NONE;
2115 }
2116
2117 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
2118     noti_ex_action_h action) {
2119   if (handle == nullptr) {
2120     LOGE("Invalid parameter");
2121     return NOTI_EX_ERROR_INVALID_PARAMETER;
2122   }
2123
2124   Handle* p = static_cast<Handle*>(handle);
2125   if (action == nullptr) {
2126     p->Get()->SetAction(nullptr);
2127     return NOTI_EX_ERROR_NONE;
2128   }
2129
2130   shared_ptr<AbstractAction>* ptr =
2131       static_cast<shared_ptr<AbstractAction>*>(action);
2132   p->Get()->SetAction(*ptr);
2133   return NOTI_EX_ERROR_NONE;
2134 }
2135
2136 extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
2137     noti_ex_style_h *style) {
2138   if (handle == nullptr || style == nullptr) {
2139     LOGE("Invalid parameter");
2140     return NOTI_EX_ERROR_INVALID_PARAMETER;
2141   }
2142
2143   Handle* p = static_cast<Handle*>(handle);
2144   shared_ptr<Style> s = p->Get()->GetStyle();
2145   if (s.get() == nullptr) {
2146     LOGW("Style is null");
2147     *style = nullptr;
2148     return NOTI_EX_ERROR_NONE;
2149   }
2150
2151   auto* ptr = new (std::nothrow) shared_ptr<Style>(new (std::nothrow) Style(*s));
2152   if (ptr == nullptr || ptr->get() == nullptr) {
2153     LOGE("Out of memory");
2154     if (ptr != nullptr)
2155       delete ptr;
2156     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2157   }
2158
2159   *style = ptr;
2160   return NOTI_EX_ERROR_NONE;
2161 }
2162
2163 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
2164     noti_ex_style_h style) {
2165   if (handle == nullptr) {
2166     LOGE("Invalid parameter");
2167     return NOTI_EX_ERROR_INVALID_PARAMETER;
2168   }
2169
2170   Handle* p = static_cast<Handle*>(handle);
2171   if (style == nullptr) {
2172     p->Get()->SetStyle(nullptr);
2173     return NOTI_EX_ERROR_NONE;
2174   }
2175
2176   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
2177   p->Get()->SetStyle(*s);
2178   return NOTI_EX_ERROR_NONE;
2179 }
2180
2181 extern "C" EXPORT_API int noti_ex_item_set_visible(noti_ex_item_h handle,
2182     bool visible) {
2183   if (handle == nullptr) {
2184     LOGE("Invalid parameter");
2185     return NOTI_EX_ERROR_INVALID_PARAMETER;
2186   }
2187
2188   Handle* p = static_cast<Handle*>(handle);
2189   p->Get()->SetVisible(visible);
2190   return NOTI_EX_ERROR_NONE;
2191 }
2192
2193 extern "C" EXPORT_API int noti_ex_item_get_visible(noti_ex_item_h handle,
2194     bool *visible) {
2195   if (handle == nullptr || visible == nullptr) {
2196     LOGE("Invalid parameter");
2197     return NOTI_EX_ERROR_INVALID_PARAMETER;
2198   }
2199
2200   Handle* p = static_cast<Handle*>(handle);
2201   *visible = p->Get()->GetVisible();
2202   return NOTI_EX_ERROR_NONE;
2203 }
2204
2205 extern "C" EXPORT_API int noti_ex_item_set_enable(noti_ex_item_h handle,
2206     bool enable) {
2207   if (handle == nullptr) {
2208     LOGE("Invalid parameter");
2209     return NOTI_EX_ERROR_INVALID_PARAMETER;
2210   }
2211
2212   Handle* p = static_cast<Handle*>(handle);
2213   p->Get()->SetEnable(enable);
2214   return NOTI_EX_ERROR_NONE;
2215 }
2216
2217 extern "C" EXPORT_API int noti_ex_item_get_enable(noti_ex_item_h handle,
2218     bool *enable) {
2219   if (handle == nullptr || enable == nullptr) {
2220     LOGE("Invalid parameter");
2221     return NOTI_EX_ERROR_INVALID_PARAMETER;
2222   }
2223
2224   Handle* p = static_cast<Handle*>(handle);
2225   *enable = p->Get()->GetEnable();
2226   return NOTI_EX_ERROR_NONE;
2227 }
2228
2229 extern "C" EXPORT_API int noti_ex_item_add_receiver(noti_ex_item_h handle,
2230     const char *receiver_group) {
2231   if (handle == nullptr || receiver_group == nullptr) {
2232     LOGE("Invalid parameter");
2233     return NOTI_EX_ERROR_INVALID_PARAMETER;
2234   }
2235
2236   Handle* p = static_cast<Handle*>(handle);
2237   p->Get()->AddReceiver(receiver_group);
2238   return NOTI_EX_ERROR_NONE;
2239 }
2240
2241 extern "C" EXPORT_API int noti_ex_item_remove_receiver(noti_ex_item_h handle,
2242     const char *receiver_group) {
2243   if (handle == nullptr || receiver_group == nullptr) {
2244     LOGE("Invalid parameter");
2245     return NOTI_EX_ERROR_INVALID_PARAMETER;
2246   }
2247
2248   Handle* p = static_cast<Handle*>(handle);
2249   p->Get()->RemoveReceiver(receiver_group);
2250   return NOTI_EX_ERROR_NONE;
2251 }
2252
2253 extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
2254     char ***receiver_list, int *count) {
2255   if (handle == nullptr || receiver_list == nullptr || count == nullptr) {
2256     LOGE("Invalid parameter");
2257     return NOTI_EX_ERROR_INVALID_PARAMETER;
2258   }
2259
2260   Handle* p = static_cast<Handle*>(handle);
2261   list<string> receivers = p->Get()->GetReceiverList();
2262   if (receivers.size() == 0) {
2263     *receiver_list = nullptr;
2264     *count = 0;
2265     return NOTI_EX_ERROR_NONE;
2266   }
2267
2268   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
2269   if (tmp_list == nullptr) {
2270     LOGE("Out of memory");
2271     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2272   }
2273
2274   int idx = 0;
2275   for (auto& i : receivers) {
2276     tmp_list[idx] = strdup(i.c_str());
2277     if (tmp_list[idx] == nullptr) {
2278       __noti_ex_free_str_array(tmp_list, idx);
2279       LOGE("Out of memory");
2280       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2281     }
2282     idx++;
2283   }
2284
2285   *receiver_list = tmp_list;
2286   *count = receivers.size();
2287   return NOTI_EX_ERROR_NONE;
2288 }
2289
2290 extern "C" EXPORT_API int noti_ex_item_set_policy(noti_ex_item_h handle,
2291     int policy) {
2292   if (handle == nullptr) {
2293     LOGE("Invalid parameter");
2294     return NOTI_EX_ERROR_INVALID_PARAMETER;
2295   }
2296
2297   Handle* p = static_cast<Handle*>(handle);
2298   p->Get()->SetPolicy(policy);
2299   return NOTI_EX_ERROR_NONE;
2300 }
2301
2302 extern "C" EXPORT_API int noti_ex_item_get_policy(noti_ex_item_h handle,
2303     int *policy) {
2304   if (handle == nullptr || policy == nullptr) {
2305     LOGE("Invalid parameter");
2306     return NOTI_EX_ERROR_INVALID_PARAMETER;
2307   }
2308
2309   Handle* p = static_cast<Handle*>(handle);
2310   *policy = p->Get()->GetPolicy();
2311   return NOTI_EX_ERROR_NONE;
2312 }
2313
2314 extern "C" EXPORT_API int noti_ex_item_get_channel(noti_ex_item_h handle,
2315     char **channel) {
2316   if (handle == nullptr || channel == nullptr) {
2317     LOGE("Invalid parameter");
2318     return NOTI_EX_ERROR_INVALID_PARAMETER;
2319   }
2320
2321   Handle* p = static_cast<Handle*>(handle);
2322   if (!p->Get()->GetChannel().empty())
2323     *channel = strdup(p->Get()->GetChannel().c_str());
2324   else
2325     *channel = nullptr;
2326
2327   return NOTI_EX_ERROR_NONE;
2328 }
2329
2330 extern "C" EXPORT_API int noti_ex_item_set_channel(noti_ex_item_h handle,
2331     const char *channel) {
2332   if (handle == nullptr) {
2333     LOGE("Invalid parameter");
2334     return NOTI_EX_ERROR_INVALID_PARAMETER;
2335   }
2336
2337   Handle* p = static_cast<Handle*>(handle);
2338   p->Get()->SetChannel(channel);
2339   return NOTI_EX_ERROR_NONE;
2340 }
2341
2342 extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
2343     noti_ex_led_info_h led) {
2344   if (handle == nullptr) {
2345     LOGE("Invalid parameter");
2346     return NOTI_EX_ERROR_INVALID_PARAMETER;
2347   }
2348
2349   Handle* p = static_cast<Handle*>(handle);
2350   if (led == nullptr) {
2351     p->Get()->SetLEDInfo(nullptr);
2352     return NOTI_EX_ERROR_NONE;
2353   }
2354   shared_ptr<LEDInfo>* led_ptr =
2355       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
2356   p->Get()->SetLEDInfo(*led_ptr);
2357   return NOTI_EX_ERROR_NONE;
2358 }
2359
2360 extern "C" EXPORT_API int noti_ex_item_get_led_info(noti_ex_item_h handle,
2361     noti_ex_led_info_h *led) {
2362   if (handle == nullptr) {
2363     LOGE("Invalid parameter");
2364     return NOTI_EX_ERROR_INVALID_PARAMETER;
2365   }
2366
2367   Handle* p = static_cast<Handle*>(handle);
2368   if (p->Get()->GetLEDInfo() != nullptr)
2369     *led = new shared_ptr<LEDInfo>(p->Get()->GetLEDInfo());
2370   else
2371     *led = nullptr;
2372   return NOTI_EX_ERROR_NONE;
2373 }
2374
2375 extern "C" EXPORT_API int noti_ex_item_set_sound_path(noti_ex_item_h handle,
2376     const char *path) {
2377   if (handle == nullptr) {
2378     LOGE("Invalid parameter");
2379     return NOTI_EX_ERROR_INVALID_PARAMETER;
2380   }
2381
2382   Handle* p = static_cast<Handle*>(handle);
2383   if (path == nullptr)
2384     p->Get()->SetSoundPath("");
2385   else
2386     p->Get()->SetSoundPath(path);
2387   return NOTI_EX_ERROR_NONE;
2388 }
2389
2390 extern "C" EXPORT_API int noti_ex_item_set_vibration_path(noti_ex_item_h handle,
2391     const char *path) {
2392   if (handle == nullptr) {
2393     LOGE("Invalid parameter");
2394     return NOTI_EX_ERROR_INVALID_PARAMETER;
2395   }
2396
2397   Handle* p = static_cast<Handle*>(handle);
2398   if (path == nullptr)
2399     p->Get()->SetVibrationPath("");
2400   else
2401     p->Get()->SetVibrationPath(path);
2402   return NOTI_EX_ERROR_NONE;
2403 }
2404
2405 extern "C" EXPORT_API int noti_ex_item_get_sound_path(noti_ex_item_h handle,
2406     char **path) {
2407   if (handle == nullptr || path == nullptr) {
2408     LOGE("Invalid parameter");
2409     return NOTI_EX_ERROR_INVALID_PARAMETER;
2410   }
2411
2412   Handle* p = static_cast<Handle*>(handle);
2413   if (p->Get()->GetSoundPath().empty())
2414     *path = nullptr;
2415   else
2416     *path = strdup(p->Get()->GetSoundPath().c_str());
2417   return NOTI_EX_ERROR_NONE;
2418 }
2419
2420 extern "C" EXPORT_API int noti_ex_item_get_vibration_path(noti_ex_item_h handle,
2421     char **path) {
2422   if (handle == nullptr || path == nullptr) {
2423     LOGE("Invalid parameter");
2424     return NOTI_EX_ERROR_INVALID_PARAMETER;
2425   }
2426
2427   Handle* p = static_cast<Handle*>(handle);
2428   if (p->Get()->GetVibrationPath().empty())
2429     *path = nullptr;
2430   else
2431     *path = strdup(p->Get()->GetVibrationPath().c_str());
2432   return NOTI_EX_ERROR_NONE;
2433 }
2434
2435 extern "C" EXPORT_API int noti_ex_item_get_info(noti_ex_item_h handle,
2436     noti_ex_item_info_h *info) {
2437   if (handle == nullptr || info == nullptr) {
2438     LOGE("Invalid parameter");
2439     return NOTI_EX_ERROR_INVALID_PARAMETER;
2440   }
2441
2442   Handle* p = static_cast<Handle*>(handle);
2443   if (p->Get()->GetInfo() == nullptr)
2444     *info = nullptr;
2445   else
2446     *info = static_cast<noti_ex_item_info_h>(p->Get()->GetInfo().get());
2447   return NOTI_EX_ERROR_NONE;
2448 }
2449
2450 extern "C" EXPORT_API int noti_ex_item_get_sender_app_id(noti_ex_item_h handle,
2451     char **id) {
2452   if (handle == nullptr || id == nullptr) {
2453     LOGE("Invalid parameter");
2454     return NOTI_EX_ERROR_INVALID_PARAMETER;
2455   }
2456
2457   Handle* p = static_cast<Handle*>(handle);
2458   if (p->Get()->GetSenderAppId().empty())
2459     *id = nullptr;
2460   else
2461     *id = strdup(p->Get()->GetSenderAppId().c_str());
2462   return NOTI_EX_ERROR_NONE;
2463 }
2464
2465 extern "C" EXPORT_API int noti_ex_item_get_tag(noti_ex_item_h handle,
2466     char **tag) {
2467   if (handle == nullptr || tag == nullptr) {
2468     LOGE("Invalid parameter");
2469     return NOTI_EX_ERROR_INVALID_PARAMETER;
2470   }
2471
2472   Handle* p = static_cast<Handle*>(handle);
2473   if (p->Get()->GetTag().empty())
2474     *tag = nullptr;
2475   else
2476     *tag = strdup(p->Get()->GetTag().c_str());
2477   return NOTI_EX_ERROR_NONE;
2478 }
2479
2480 extern "C" EXPORT_API int noti_ex_item_set_tag(noti_ex_item_h handle,
2481     const char *tag) {
2482   if (handle == nullptr) {
2483     LOGE("Invalid parameter");
2484     return NOTI_EX_ERROR_INVALID_PARAMETER;
2485   }
2486
2487   Handle* p = static_cast<Handle*>(handle);
2488   if (tag == nullptr)
2489     p->Get()->SetTag("");
2490   else
2491     p->Get()->SetTag(tag);
2492   return NOTI_EX_ERROR_NONE;
2493 }
2494
2495 extern "C" EXPORT_API int noti_ex_item_get_ongoing_state(noti_ex_item_h handle,
2496     bool* ongoing) {
2497   if (handle == nullptr || ongoing == nullptr) {
2498     LOGE("Invalid parameter");
2499     return NOTI_EX_ERROR_INVALID_PARAMETER;
2500   }
2501
2502   Handle* p = static_cast<Handle*>(handle);
2503   *ongoing = p->Get()->GetOnGoingState();
2504
2505   return NOTI_EX_ERROR_NONE;
2506 }
2507
2508 extern "C" EXPORT_API int noti_ex_item_set_ongoing_state(noti_ex_item_h handle,
2509     bool ongoing) {
2510   if (handle == nullptr) {
2511     LOGE("Invalid parameter");
2512     return NOTI_EX_ERROR_INVALID_PARAMETER;
2513   }
2514
2515   Handle* p = static_cast<Handle*>(handle);
2516   p->Get()->SetOnGoingState(ongoing);
2517
2518   return NOTI_EX_ERROR_NONE;
2519 }
2520
2521 extern "C" EXPORT_API int noti_ex_item_check_type_exist(noti_ex_item_h handle,
2522     int type, bool* exist) {
2523   if (handle == nullptr || exist == nullptr) {
2524     LOGE("Invalid parameter");
2525     return NOTI_EX_ERROR_INVALID_PARAMETER;
2526   }
2527
2528   Handle* p = static_cast<Handle*>(handle);
2529   *exist = p->Get()->IsItemTypeExist(type);
2530
2531   return NOTI_EX_ERROR_NONE;
2532 }
2533
2534 extern "C" EXPORT_API int noti_ex_item_get_main_type(noti_ex_item_h handle,
2535     int* type) {
2536   if (handle == nullptr || type == nullptr) {
2537     LOGE("Invalid parameter");
2538     return NOTI_EX_ERROR_INVALID_PARAMETER;
2539   }
2540
2541   Handle* p = static_cast<Handle*>(handle);
2542   *type = p->Get()->GetMainType();
2543
2544   return NOTI_EX_ERROR_NONE;
2545 }
2546
2547 extern "C" EXPORT_API int noti_ex_item_set_main_type(noti_ex_item_h handle,
2548     const char* id, int type) {
2549   if (handle == nullptr || id == nullptr) {
2550     LOGE("Invalid parameter");
2551     return NOTI_EX_ERROR_INVALID_PARAMETER;
2552   }
2553
2554   Handle* p = static_cast<Handle*>(handle);
2555   if (!(p->Get()->SetMainType(string(id),
2556                     static_cast<AbstractItem::MainType>(type))))
2557     return NOTI_EX_ERROR_INVALID_PARAMETER;
2558
2559   return NOTI_EX_ERROR_NONE;
2560 }
2561
2562 extern "C" EXPORT_API int noti_ex_item_find_by_main_type(noti_ex_item_h handle,
2563     int type, noti_ex_item_h* item) {
2564   if (handle == nullptr || item == nullptr) {
2565     LOGE("Invalid parameter");
2566     return NOTI_EX_ERROR_INVALID_PARAMETER;
2567   }
2568
2569   Handle* h = static_cast<Handle*>(handle);
2570   if (!h->IsValidType(AbstractItem::Group)) {
2571     LOGE("Invalid handle type");
2572     return NOTI_EX_ERROR_INVALID_PARAMETER;
2573   }
2574
2575   GroupItem* p = static_cast<GroupItem*>(h->Get());
2576   AbstractItem& find_item = p->FindByMainType(static_cast<AbstractItem::MainType>(type));
2577   if (find_item.GetType() == AbstractItem::NullObject) {
2578     LOGW("Not exist ID");
2579     *item = nullptr;
2580     return NOTI_EX_ERROR_NONE;
2581   }
2582   *item = new Handle(&find_item);
2583
2584   return NOTI_EX_ERROR_NONE;
2585 }
2586
2587 extern "C" EXPORT_API int noti_ex_item_get_extension_data(noti_ex_item_h handle,
2588     const char *key, bundle **value) {
2589   if (handle == nullptr || key == nullptr || value == nullptr) {
2590     LOGE("Invalid handle type");
2591     return NOTI_EX_ERROR_INVALID_PARAMETER;
2592   }
2593
2594   Handle* p = static_cast<Handle*>(handle);
2595
2596   Bundle b = p->Get()->GetExtensionData(key);
2597   if (b.GetCount() == 0)
2598     *value = nullptr;
2599   else
2600     *value = bundle_dup(b.GetHandle());
2601
2602   return NOTI_EX_ERROR_NONE;
2603 }
2604
2605 extern "C" EXPORT_API int noti_ex_item_set_extension_data(noti_ex_item_h handle,
2606     const char *key, bundle *value) {
2607   if (handle == nullptr || key == nullptr || value == nullptr) {
2608     LOGE("Invalid handle type");
2609     return NOTI_EX_ERROR_INVALID_PARAMETER;
2610   }
2611
2612   Bundle b = Bundle(value);
2613
2614   Handle* p = static_cast<Handle*>(handle);
2615   p->Get()->SetExtensionData(key, b);
2616
2617   return NOTI_EX_ERROR_NONE;
2618 }
2619
2620 extern "C" EXPORT_API int noti_ex_manager_create(noti_ex_manager_h *handle,
2621     const char *receiver_group, noti_ex_manager_events_s event_callbacks,
2622     void *data) {
2623   if (handle == nullptr) {
2624     LOGE("Invalid parameter");
2625     return NOTI_EX_ERROR_INVALID_PARAMETER;
2626   }
2627
2628   string receiver_group_str = "";
2629   if (receiver_group)
2630     receiver_group_str = string(receiver_group);
2631
2632   ManagerStub* stub = new (std::nothrow) ManagerStub(
2633       unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
2634       unique_ptr<DBusEventListener>(new DBusEventListener(Manager::GetPath())),
2635       receiver_group_str);
2636   if (stub == nullptr) {
2637     LOGE("Fail to create manager");
2638     return NOTI_EX_ERROR_IO_ERROR;
2639   }
2640
2641   int ret = get_last_result();
2642   if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2643     LOGE("error(%d)", ret);
2644     delete stub;
2645     return ret;
2646   }
2647   stub->SetManagerCallbackInfo(unique_ptr<ManagerCallbackInfo>(
2648       new ManagerCallbackInfo(event_callbacks, data)));
2649   *handle = static_cast<noti_ex_manager_h>(stub);
2650
2651   return NOTI_EX_ERROR_NONE;
2652 }
2653
2654 extern "C" EXPORT_API int noti_ex_manager_destroy(noti_ex_manager_h handle) {
2655   if (handle == nullptr) {
2656     LOGE("Invalid parameter");
2657     return NOTI_EX_ERROR_INVALID_PARAMETER;
2658   }
2659   ManagerStub* stub = static_cast<ManagerStub*>(handle);
2660   delete stub;
2661   return NOTI_EX_ERROR_NONE;
2662 }
2663
2664 extern "C" EXPORT_API int noti_ex_manager_get(noti_ex_manager_h handle,
2665     noti_ex_item_h **items, int *count) {
2666   if (handle == nullptr || items == nullptr || count == nullptr) {
2667     LOGE("Invalid parameter");
2668     return NOTI_EX_ERROR_INVALID_PARAMETER;
2669   }
2670
2671   try {
2672     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2673     list<unique_ptr<item::AbstractItem>> item_list = stub->Get();
2674     int ret = get_last_result();
2675     if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2676       LOGE("error(%d)", ret);
2677       *items = nullptr;
2678       *count = 0;
2679       return ret;
2680     }
2681
2682     if (item_list.size() == 0) {
2683       *items = nullptr;
2684       *count = 0;
2685       return NOTI_EX_ERROR_NONE;
2686     }
2687
2688     noti_ex_item_h* added_item =
2689         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2690     if (added_item == nullptr) {
2691       LOGE("Fail to create items");
2692       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2693     }
2694
2695     int idx = 0;
2696     for (auto& i : item_list) {
2697       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2698     }
2699     *items = added_item;
2700     *count = item_list.size();
2701   } catch (Exception &ex) {
2702     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2703     return NOTI_EX_ERROR_IO_ERROR;
2704   }
2705   return NOTI_EX_ERROR_NONE;
2706 }
2707
2708 extern "C" EXPORT_API int noti_ex_manager_get_by_channel(
2709     noti_ex_manager_h handle, char* channel, noti_ex_item_h** items, int* count) {
2710   if (handle == nullptr || channel == nullptr ||
2711       items == nullptr || count == nullptr) {
2712     LOGE("Invalid parameter");
2713     return NOTI_EX_ERROR_INVALID_PARAMETER;
2714   }
2715
2716   try {
2717     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2718     list<unique_ptr<item::AbstractItem>> item_list = stub->Get(channel);
2719     int ret = get_last_result();
2720     if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2721       LOGE("error(%d)", ret);
2722       *items = nullptr;
2723       *count = 0;
2724       return ret;
2725     }
2726
2727     if (item_list.size() == 0) {
2728       *items = nullptr;
2729       *count = 0;
2730       return NOTI_EX_ERROR_NONE;
2731     }
2732     noti_ex_item_h* added_item =
2733         (noti_ex_item_h*)calloc(item_list.size(), sizeof(noti_ex_item_h));
2734     if (added_item == nullptr) {
2735       LOGE("Fail to create items");
2736       return NOTI_EX_ERROR_OUT_OF_MEMORY;
2737     }
2738
2739     int idx = 0;
2740     for (auto& i : item_list) {
2741       added_item[idx++] = static_cast<noti_ex_item_h>(new Handle(move(i)));
2742     }
2743     *items = added_item;
2744     *count = item_list.size();
2745   } catch (Exception &ex) {
2746     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2747     return NOTI_EX_ERROR_IO_ERROR;
2748   }
2749
2750   return NOTI_EX_ERROR_NONE;
2751 }
2752
2753 extern "C" EXPORT_API int noti_ex_manager_update(noti_ex_manager_h handle,
2754     noti_ex_item_h noti, int *request_id) {
2755   int ret = ERROR_NONE;
2756
2757   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2758     LOGE("Invalid parameter");
2759     return NOTI_EX_ERROR_INVALID_PARAMETER;
2760   }
2761   try {
2762     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2763     Handle* sp = static_cast<Handle*>(noti);
2764     if (sp->GetPtr().get() == nullptr) {
2765       LOGE("Invalid noti reference can not be sended");
2766       return NOTI_EX_ERROR_INVALID_PARAMETER;
2767     } else {
2768       ret = stub->Update(sp->GetPtr(), *request_id);
2769     }
2770   } catch (Exception &ex) {
2771     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2772     return NOTI_EX_ERROR_IO_ERROR;
2773   }
2774   return ret;
2775 }
2776
2777 extern "C" EXPORT_API int noti_ex_manager_delete(noti_ex_manager_h handle,
2778     noti_ex_item_h noti, int *request_id) {
2779   int ret = ERROR_NONE;
2780
2781   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2782     LOGE("Invalid parameter");
2783     return NOTI_EX_ERROR_INVALID_PARAMETER;
2784   }
2785
2786   try {
2787     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2788     Handle* item = static_cast<Handle*>(noti);
2789     if (item->GetPtr().get() == nullptr) {
2790       LOGE("Invalid noti reference can not be sended");
2791       return NOTI_EX_ERROR_INVALID_PARAMETER;
2792     } else {
2793       ret = stub->Delete(item->GetPtr(), *request_id);
2794     }
2795   } catch (Exception &ex) {
2796     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2797     return NOTI_EX_ERROR_IO_ERROR;
2798   }
2799
2800   return ret;
2801 }
2802
2803 extern "C" EXPORT_API int noti_ex_manager_delete_all(noti_ex_manager_h handle,
2804     int *request_id) {
2805   int ret = ERROR_NONE;
2806
2807   if (handle == nullptr || request_id == nullptr) {
2808     LOGE("Invalid parameter");
2809     return NOTI_EX_ERROR_INVALID_PARAMETER;
2810   }
2811   try {
2812     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2813     ret = stub->DeleteAll(*request_id);
2814   } catch (Exception &ex) {
2815     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2816     return NOTI_EX_ERROR_IO_ERROR;
2817   }
2818   return ret;
2819 }
2820
2821 extern "C" EXPORT_API int noti_ex_manager_delete_by_channel(
2822     noti_ex_manager_h handle, const char* channel, int* request_id) {
2823   int ret = ERROR_NONE;
2824
2825   if (handle == nullptr || channel == nullptr || request_id == nullptr) {
2826     LOGE("Invalid parameter");
2827     return NOTI_EX_ERROR_INVALID_PARAMETER;
2828   }
2829
2830   try {
2831     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2832     ret = stub->DeleteByChannel(channel, *request_id);
2833   } catch (Exception &ex) {
2834     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2835     return NOTI_EX_ERROR_IO_ERROR;
2836   }
2837
2838   return ret;
2839 }
2840
2841 extern "C" EXPORT_API int noti_ex_manager_delete_by_appid(
2842     noti_ex_manager_h handle, const char* app_id, int* request_id) {
2843   int ret = ERROR_NONE;
2844
2845   if (handle == nullptr || app_id == nullptr || request_id == nullptr) {
2846     LOGE("Invalid parameter");
2847     return NOTI_EX_ERROR_INVALID_PARAMETER;
2848   }
2849
2850   try {
2851     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2852     ret = stub->DeleteByAppId(app_id, *request_id);
2853   } catch (Exception &ex) {
2854     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2855     return NOTI_EX_ERROR_IO_ERROR;
2856   }
2857
2858   return ret;
2859 }
2860
2861 extern "C" EXPORT_API int noti_ex_manager_hide(noti_ex_manager_h handle,
2862     noti_ex_item_h noti, int *request_id) {
2863   int ret = ERROR_NONE;
2864
2865   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
2866     LOGE("Invalid parameter");
2867     return NOTI_EX_ERROR_INVALID_PARAMETER;
2868   }
2869   try {
2870     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2871     Handle* item = static_cast<Handle*>(noti);
2872     if (item->GetPtr().get() == nullptr) {
2873       LOGE("Invalid noti reference can not be sended");
2874       return NOTI_EX_ERROR_INVALID_PARAMETER;
2875     } else {
2876       ret = stub->Hide(item->GetPtr(), *request_id);
2877     }
2878   } catch (Exception &ex) {
2879     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2880     return NOTI_EX_ERROR_IO_ERROR;
2881   }
2882   return ret;
2883 }
2884
2885 extern "C" EXPORT_API int noti_ex_manager_find_by_root_id(
2886     noti_ex_manager_h handle, const char *root_id, noti_ex_item_h *item) {
2887   if (handle == nullptr || root_id == nullptr || item == nullptr) {
2888     LOGE("Invalid parameter");
2889     return NOTI_EX_ERROR_INVALID_PARAMETER;
2890   }
2891   try {
2892     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2893     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
2894     int ret = get_last_result();
2895     if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2896       LOGE("error(%d)", ret);
2897       return ret;
2898     }
2899
2900     if (ptr == nullptr) {
2901       LOGW("Not exist ID");
2902       *item = nullptr;
2903       return NOTI_EX_ERROR_NONE;
2904     }
2905     *item = new Handle(ptr);
2906   } catch (Exception &ex) {
2907     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2908     return NOTI_EX_ERROR_IO_ERROR;
2909   }
2910   return NOTI_EX_ERROR_NONE;
2911 }
2912
2913 extern "C" EXPORT_API int noti_ex_manager_send_error(noti_ex_manager_h handle,
2914     noti_ex_event_info_h info, noti_ex_error_e error) {
2915   if (handle == nullptr || info == nullptr) {
2916     LOGE("Invalid parameter");
2917     return NOTI_EX_ERROR_INVALID_PARAMETER;
2918   }
2919   try {
2920     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2921     IEventInfo* c_info = static_cast<IEventInfo*>(info);
2922     stub->SendError(static_cast<const IEventInfo&>(*c_info),
2923         static_cast<NotificationError>(error));
2924
2925     int ret = get_last_result();
2926     if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2927       LOGE("error(%d)", ret);
2928       return ret;
2929     }
2930   } catch (Exception &ex) {
2931     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2932     return NOTI_EX_ERROR_IO_ERROR;
2933   }
2934   return NOTI_EX_ERROR_NONE;
2935 }
2936
2937 extern "C" EXPORT_API int noti_ex_manager_get_notification_count(
2938     noti_ex_manager_h handle, int *count) {
2939   if (handle == nullptr || count == nullptr) {
2940     LOGE("Invalid parameter");
2941     return NOTI_EX_ERROR_INVALID_PARAMETER;
2942   }
2943   try {
2944     ManagerStub* stub = static_cast<ManagerStub*>(handle);
2945     *count = stub->GetCount();
2946
2947     int ret = get_last_result();
2948     if (ret == ERROR_PERMISSION_DENIED || ret == ERROR_IO_ERROR) {
2949       LOGE("error(%d)", ret);
2950       return ret;
2951     }
2952   } catch (Exception &ex) {
2953     LOGE("%s %d", ex.what(), ex.GetErrorCode());
2954     return NOTI_EX_ERROR_IO_ERROR;
2955   }
2956   return NOTI_EX_ERROR_NONE;
2957 }
2958
2959 extern "C" EXPORT_API int noti_ex_item_progress_create(noti_ex_item_h *handle,
2960     const char *id, float min, float current, float max) {
2961   ProgressItem* p;
2962
2963   if (handle == nullptr) {
2964     LOGE("Invalid parameter");
2965     return NOTI_EX_ERROR_INVALID_PARAMETER;
2966   }
2967
2968   if (id)
2969     p = new (std::nothrow) ProgressItem(id, min, current, max);
2970   else
2971     p = new (std::nothrow) ProgressItem(min, current, max);
2972
2973   if (p == nullptr) {
2974     LOGE("Out-of-memory");
2975     return NOTI_EX_ERROR_OUT_OF_MEMORY;
2976   }
2977
2978   *handle = new Handle(shared_ptr<AbstractItem>(p));
2979
2980   return NOTI_EX_ERROR_NONE;
2981 }
2982
2983 extern "C" EXPORT_API int noti_ex_item_progress_get_current(
2984     noti_ex_item_h handle, float *current) {
2985   if (handle == nullptr || current == nullptr) {
2986     LOGE("Invalid parameter");
2987     return NOTI_EX_ERROR_INVALID_PARAMETER;
2988   }
2989
2990   Handle *h = static_cast<Handle*>(handle);
2991   if (!h->IsValidType(AbstractItem::Progress)) {
2992     LOGE("Invalid handle type");
2993     return NOTI_EX_ERROR_INVALID_PARAMETER;
2994   }
2995   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
2996   *current = p->GetCurrent();
2997
2998   return NOTI_EX_ERROR_NONE;
2999 }
3000
3001 extern "C" EXPORT_API int noti_ex_item_progress_set_current(
3002     noti_ex_item_h handle, float current) {
3003   if (handle == nullptr) {
3004     LOGE("Invalid parameter");
3005     return NOTI_EX_ERROR_INVALID_PARAMETER;
3006   }
3007
3008   Handle *h = static_cast<Handle*>(handle);
3009   if (!h->IsValidType(AbstractItem::Progress)) {
3010     LOGE("Invalid handle type");
3011     return NOTI_EX_ERROR_INVALID_PARAMETER;
3012   }
3013   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3014   p->SetCurrent(current);
3015
3016   return NOTI_EX_ERROR_NONE;
3017 }
3018
3019 extern "C" EXPORT_API int noti_ex_item_progress_get_min(noti_ex_item_h handle,
3020     float *min) {
3021   if (handle == nullptr || min == nullptr) {
3022     LOGE("Invalid parameter");
3023     return NOTI_EX_ERROR_INVALID_PARAMETER;
3024   }
3025
3026   Handle *h = static_cast<Handle*>(handle);
3027   if (!h->IsValidType(AbstractItem::Progress)) {
3028     LOGE("Invalid handle type");
3029     return NOTI_EX_ERROR_INVALID_PARAMETER;
3030   }
3031   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3032   *min = p->GetMin();
3033
3034   return NOTI_EX_ERROR_NONE;
3035 }
3036
3037 extern "C" EXPORT_API int noti_ex_item_progress_get_max(noti_ex_item_h handle,
3038     float *max) {
3039   if (handle == nullptr || max == nullptr) {
3040     LOGE("Invalid parameter");
3041     return NOTI_EX_ERROR_INVALID_PARAMETER;
3042   }
3043
3044   Handle *h = static_cast<Handle*>(handle);
3045   if (!h->IsValidType(AbstractItem::Progress)) {
3046     LOGE("Invalid handle type");
3047     return NOTI_EX_ERROR_INVALID_PARAMETER;
3048   }
3049   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3050   *max = p->GetMax();
3051
3052   return NOTI_EX_ERROR_NONE;
3053 }
3054
3055 extern "C" EXPORT_API int noti_ex_item_progress_get_type(noti_ex_item_h handle,
3056     int* type) {
3057   if (handle == nullptr || type == nullptr) {
3058     LOGE("Invalid parameter");
3059     return NOTI_EX_ERROR_INVALID_PARAMETER;
3060   }
3061
3062   Handle *h = static_cast<Handle*>(handle);
3063   if (!h->IsValidType(AbstractItem::Progress)) {
3064     LOGE("Invalid handle type");
3065     return NOTI_EX_ERROR_INVALID_PARAMETER;
3066   }
3067   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3068   *type = static_cast<noti_ex_item_progress_type_e>(p->GetProgressType());
3069
3070   return NOTI_EX_ERROR_NONE;
3071 }
3072
3073 extern "C" EXPORT_API int noti_ex_item_progress_set_type(noti_ex_item_h handle,
3074     int type) {
3075   if (handle == nullptr) {
3076     LOGE("Invalid parameter");
3077     return NOTI_EX_ERROR_INVALID_PARAMETER;
3078   }
3079
3080   Handle *h = static_cast<Handle*>(handle);
3081   if (!h->IsValidType(AbstractItem::Progress)) {
3082     LOGE("Invalid handle type");
3083     return NOTI_EX_ERROR_INVALID_PARAMETER;
3084   }
3085   ProgressItem* p = static_cast<ProgressItem*>(h->Get());
3086   p->SetProgressType(static_cast<ProgressItem::Type>(type));
3087
3088   return NOTI_EX_ERROR_NONE;
3089 }
3090
3091 extern "C" EXPORT_API int noti_ex_reporter_create(noti_ex_reporter_h *handle,
3092     noti_ex_reporter_events_s event_callbacks, void *data) {
3093   if (handle == nullptr) {
3094     LOGE("Invalid parameter");
3095     return NOTI_EX_ERROR_INVALID_PARAMETER;
3096   }
3097
3098   ReporterStub* stub = new (std::nothrow) ReporterStub(
3099       unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
3100       unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath())));
3101   if (stub == nullptr) {
3102     LOGE("Fail to create manager");
3103     return NOTI_EX_ERROR_IO_ERROR;
3104   }
3105   stub->SetReporterCallbackInfo(unique_ptr<ReporterCallbackInfo>(
3106       new ReporterCallbackInfo(event_callbacks, data)));
3107
3108   *handle = static_cast<noti_ex_reporter_h>(stub);
3109
3110   return NOTI_EX_ERROR_NONE;
3111 }
3112
3113 extern "C" EXPORT_API int noti_ex_reporter_destroy(noti_ex_reporter_h handle) {
3114   if (handle == nullptr) {
3115     LOGE("Invalid parameter");
3116     return NOTI_EX_ERROR_INVALID_PARAMETER;
3117   }
3118   ReporterStub* stub = static_cast<ReporterStub*>(handle);
3119   delete stub;
3120   return NOTI_EX_ERROR_NONE;
3121 }
3122
3123 extern "C" EXPORT_API int noti_ex_reporter_send_error(noti_ex_reporter_h handle,
3124     noti_ex_event_info_h info, noti_ex_error_e error) {
3125   if (handle == nullptr || info == nullptr) {
3126     LOGE("Invalid parameter");
3127     return NOTI_EX_ERROR_INVALID_PARAMETER;
3128   }
3129   try {
3130     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3131     IEventInfo* c_info = static_cast<IEventInfo*>(info);
3132     stub->SendError(static_cast<const IEventInfo&>(*c_info),
3133         static_cast<NotificationError>(error));
3134   } catch (Exception &ex) {
3135     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3136     return NOTI_EX_ERROR_IO_ERROR;
3137   }
3138   return NOTI_EX_ERROR_NONE;
3139 }
3140
3141 extern "C" EXPORT_API int noti_ex_reporter_post(noti_ex_reporter_h handle,
3142     noti_ex_item_h noti, int *request_id) {
3143   int ret = NOTI_EX_ERROR_NONE;
3144
3145   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3146     LOGE("Invalid parameter");
3147     return NOTI_EX_ERROR_INVALID_PARAMETER;
3148   }
3149   try {
3150     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3151     Handle* h = static_cast<Handle*>(noti);
3152     if (h->GetPtr().get() == nullptr) {
3153       LOGE("Invalid noti reference can not be sended");
3154       return NOTI_EX_ERROR_INVALID_PARAMETER;
3155     } else {
3156       ret = stub->Post(h->GetPtr(), *request_id);
3157     }
3158   } catch (Exception &ex) {
3159     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3160     return NOTI_EX_ERROR_IO_ERROR;
3161   }
3162   return ret;
3163 }
3164
3165 extern "C" EXPORT_API int noti_ex_reporter_post_list(noti_ex_reporter_h handle,
3166     noti_ex_item_h *noti_list, int count, int *request_id) {
3167   int ret = NOTI_EX_ERROR_NONE;
3168
3169   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3170     LOGE("Invalid parameter");
3171     return NOTI_EX_ERROR_INVALID_PARAMETER;
3172   }
3173   try {
3174     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3175     list<shared_ptr<item::AbstractItem>> notiList;
3176     for (int i = 0; i < count; i++) {
3177       Handle* item = static_cast<Handle*>(noti_list[i]);
3178       notiList.push_back(item->GetPtr());
3179     }
3180     ret = stub->Post(notiList, *request_id);
3181   } catch (Exception &ex) {
3182     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3183     return NOTI_EX_ERROR_IO_ERROR;
3184   }
3185   return ret;
3186 }
3187
3188 extern "C" EXPORT_API int noti_ex_reporter_update(noti_ex_reporter_h handle,
3189     noti_ex_item_h noti, int *request_id) {
3190   int ret = NOTI_EX_ERROR_NONE;
3191
3192   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3193     LOGE("Invalid parameter");
3194     return NOTI_EX_ERROR_INVALID_PARAMETER;
3195   }
3196   try {
3197     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3198     Handle* item = static_cast<Handle*>(noti);
3199     if (item->GetPtr().get() == nullptr) {
3200       LOGE("Invalid noti reference can not be sended");
3201       return NOTI_EX_ERROR_INVALID_PARAMETER;
3202     } else {
3203       ret = stub->Update(item->GetPtr(), *request_id);
3204     }
3205   } catch (Exception &ex) {
3206     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3207     return NOTI_EX_ERROR_IO_ERROR;
3208   }
3209   return ret;
3210 }
3211
3212 extern "C" EXPORT_API int noti_ex_reporter_update_list(
3213     noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3214     int *request_id) {
3215   int ret = NOTI_EX_ERROR_NONE;
3216
3217   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3218     LOGE("Invalid parameter");
3219     return NOTI_EX_ERROR_INVALID_PARAMETER;
3220   }
3221   try {
3222     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3223     list<shared_ptr<item::AbstractItem>> notiList;
3224     for (int i = 0; i < count; i++) {
3225       Handle* item = static_cast<Handle*>(noti_list[i]);
3226       notiList.push_back(item->GetPtr());
3227     }
3228     ret = stub->Update(notiList, *request_id);
3229   } catch (Exception &ex) {
3230     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3231     return NOTI_EX_ERROR_IO_ERROR;
3232   }
3233   return ret;
3234 }
3235
3236 extern "C" EXPORT_API int noti_ex_reporter_delete(noti_ex_reporter_h handle,
3237     noti_ex_item_h noti, int *request_id) {
3238   int ret = NOTI_EX_ERROR_NONE;
3239
3240   if (handle == nullptr || noti == nullptr || request_id == nullptr) {
3241     LOGE("Invalid parameter");
3242     return NOTI_EX_ERROR_INVALID_PARAMETER;
3243   }
3244   try {
3245     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3246     Handle* item = static_cast<Handle*>(noti);
3247     if (item->GetPtr().get() == nullptr) {
3248       LOGE("Invalid noti reference can not be sended");
3249       return NOTI_EX_ERROR_INVALID_PARAMETER;
3250     } else {
3251       ret = stub->Delete(item->GetPtr(), *request_id);
3252     }
3253   } catch (Exception &ex) {
3254     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3255     return NOTI_EX_ERROR_IO_ERROR;
3256   }
3257   return ret;
3258 }
3259
3260 extern "C" EXPORT_API int noti_ex_reporter_delete_list(
3261     noti_ex_reporter_h handle, noti_ex_item_h *noti_list, int count,
3262     int *request_id) {
3263   int ret = NOTI_EX_ERROR_NONE;
3264
3265   if (handle == nullptr || noti_list == nullptr || request_id == nullptr) {
3266     LOGE("Invalid parameter");
3267     return NOTI_EX_ERROR_INVALID_PARAMETER;
3268   }
3269
3270   try {
3271     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3272     list<shared_ptr<item::AbstractItem>> notiList;
3273     for (int i = 0; i < count; i++) {
3274       Handle* item = static_cast<Handle*>(noti_list[i]);
3275       notiList.push_back(item->GetPtr());
3276     }
3277     ret = stub->Delete(notiList, *request_id);
3278   } catch (Exception &ex) {
3279     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3280     return NOTI_EX_ERROR_IO_ERROR;
3281   }
3282
3283   return ret;
3284 }
3285
3286 extern "C" EXPORT_API int noti_ex_reporter_delete_all(
3287     noti_ex_reporter_h handle, int *request_id) {
3288   int ret = NOTI_EX_ERROR_NONE;
3289
3290   if (handle == nullptr || request_id == nullptr) {
3291     LOGE("Invalid parameter");
3292     return NOTI_EX_ERROR_INVALID_PARAMETER;
3293   }
3294
3295   try {
3296     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3297     ret = stub->DeleteAll(*request_id);
3298   } catch (Exception &ex) {
3299     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3300     return NOTI_EX_ERROR_IO_ERROR;
3301   }
3302
3303   return ret;
3304 }
3305
3306 extern "C" EXPORT_API int noti_ex_reporter_delete_by_channel(
3307     noti_ex_reporter_h handle, const char* channel, int* request_id) {
3308   int ret = NOTI_EX_ERROR_NONE;
3309
3310   if (handle == nullptr || channel == nullptr || request_id == nullptr) {
3311     LOGE("Invalid parameter");
3312     return NOTI_EX_ERROR_INVALID_PARAMETER;
3313   }
3314
3315   try {
3316     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3317     ret = stub->DeleteByChannel(channel, *request_id);
3318   } catch (Exception &ex) {
3319     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3320     return NOTI_EX_ERROR_IO_ERROR;
3321   }
3322
3323   return ret;
3324 }
3325
3326 extern "C" EXPORT_API int noti_ex_reporter_find_by_root_id(
3327     noti_ex_reporter_h handle, const char *root_id, noti_ex_item_h *item) {
3328   if (handle == nullptr || root_id == nullptr || item == nullptr) {
3329     LOGE("Invalid parameter");
3330     return NOTI_EX_ERROR_INVALID_PARAMETER;
3331   }
3332   try {
3333     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3334     shared_ptr<AbstractItem> ptr = stub->FindByRootID(root_id);
3335     if (ptr == nullptr) {
3336       LOGW("Not exist ID");
3337       *item = nullptr;
3338       return NOTI_EX_ERROR_NONE;
3339     }
3340     *item = new Handle(ptr);
3341   } catch (Exception &ex) {
3342     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3343     return NOTI_EX_ERROR_IO_ERROR;
3344   }
3345   return NOTI_EX_ERROR_NONE;
3346 }
3347
3348 extern "C" EXPORT_API int noti_ex_reporter_find_by_channel(noti_ex_reporter_h handle,
3349     const char *channel, noti_ex_item_h **noti_list, int *count) {
3350   if (handle == nullptr || channel == nullptr || noti_list == nullptr
3351       || count == nullptr) {
3352     LOGE("Invalid parameter");
3353     return NOTI_EX_ERROR_INVALID_PARAMETER;
3354   }
3355
3356   Handle** list_item = nullptr;
3357
3358   try {
3359     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3360     list<unique_ptr<AbstractItem>> list_ptr = stub->FindByChannel(channel);
3361     if (list_ptr.empty()) {
3362       LOGW("Not exist ID");
3363       *noti_list = nullptr;
3364       *count = 0;
3365       return NOTI_EX_ERROR_NONE;
3366     }
3367
3368     int size = list_ptr.size();
3369     list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
3370     if (list_item == nullptr) {
3371       LOGE("Out of memory");
3372       *noti_list = nullptr;
3373       *count = 0;
3374       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3375     }
3376
3377     int i = 0;
3378     for (auto& ptr : list_ptr)
3379       list_item[i++] = new Handle(std::move(ptr));
3380
3381     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3382     *count = size;
3383   } catch (Exception &ex) {
3384     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3385     free(list_item);
3386     return NOTI_EX_ERROR_IO_ERROR;
3387   }
3388
3389   return NOTI_EX_ERROR_NONE;
3390 }
3391
3392 extern "C" EXPORT_API int noti_ex_reporter_find_all(noti_ex_reporter_h handle,
3393     noti_ex_item_h **noti_list, int *count) {
3394   if (handle == nullptr || noti_list == nullptr || count == nullptr) {
3395     LOGE("Invalid parameter");
3396     return NOTI_EX_ERROR_INVALID_PARAMETER;
3397   }
3398
3399   Handle** list_item = nullptr;
3400
3401   try {
3402     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3403     list<unique_ptr<AbstractItem>> list_ptr = stub->FindAll();
3404     if (list_ptr.empty()) {
3405       LOGW("Not exist ID");
3406       *noti_list = nullptr;
3407       return NOTI_EX_ERROR_NONE;
3408     }
3409
3410     int size = list_ptr.size();
3411     list_item = static_cast<Handle**>(calloc(size, sizeof(Handle*)));
3412     if (list_item == nullptr) {
3413       LOGE("Out of memory");
3414       *noti_list = nullptr;
3415       *count = 0;
3416       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3417     }
3418
3419     int i = 0;
3420     for (auto& ptr : list_ptr)
3421       list_item[i++] = new Handle(std::move(ptr));
3422
3423     *noti_list = reinterpret_cast<noti_ex_item_h*>(list_item);
3424     *count = size;
3425   } catch (Exception &ex) {
3426     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3427     free(list_item);
3428     return NOTI_EX_ERROR_IO_ERROR;
3429   }
3430
3431   return NOTI_EX_ERROR_NONE;
3432 }
3433
3434 extern "C" EXPORT_API int noti_ex_reporter_get_count_by_channel(
3435     noti_ex_reporter_h handle, const char *channel, int *count) {
3436   if (handle == nullptr || channel == nullptr || count == nullptr) {
3437     LOGE("Invalid parameter");
3438     return NOTI_EX_ERROR_INVALID_PARAMETER;
3439   }
3440
3441   try {
3442     ReporterStub* stub = static_cast<ReporterStub*>(handle);
3443     *count = stub->GetCount(channel);
3444   } catch (Exception &ex) {
3445     LOGE("%s %d", ex.what(), ex.GetErrorCode());
3446     return NOTI_EX_ERROR_IO_ERROR;
3447   }
3448
3449   return NOTI_EX_ERROR_NONE;
3450 }
3451
3452 extern "C" EXPORT_API int noti_ex_item_text_create(noti_ex_item_h *handle,
3453     const char *id, const char *text, const char *hyperlink) {
3454   if (handle == nullptr || text == nullptr) {
3455     LOGE("Invalid parameter");
3456     return NOTI_EX_ERROR_INVALID_PARAMETER;
3457   }
3458
3459   TextItem* p;
3460
3461   if (id == NULL)
3462     id = "";
3463
3464   if (hyperlink)
3465     p = new (std::nothrow) TextItem(id, std::string(text),
3466                 std::string(hyperlink));
3467   else
3468     p = new (std::nothrow) TextItem(id, std::string(text));
3469
3470   if (p == nullptr) {
3471     LOGE("Out-of-memory");
3472     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3473   }
3474
3475   *handle = new Handle(shared_ptr<AbstractItem>(p));
3476
3477   return NOTI_EX_ERROR_NONE;
3478 }
3479
3480 extern "C" EXPORT_API int noti_ex_item_text_set_contents(noti_ex_item_h handle,
3481     const char *contents) {
3482   if (handle == nullptr || contents == nullptr) {
3483     LOGE("Invalid parameter");
3484     return NOTI_EX_ERROR_INVALID_PARAMETER;
3485   }
3486
3487   Handle* p = static_cast<Handle*>(handle);
3488   if (!p->IsValidType(AbstractItem::Text)) {
3489     LOGE("Invalid handle type");
3490     return NOTI_EX_ERROR_INVALID_PARAMETER;
3491   }
3492   TextItem* ti = static_cast<TextItem*>(p->Get());
3493   ti->SetContents(std::string(contents));
3494
3495   return NOTI_EX_ERROR_NONE;
3496 }
3497
3498 extern "C" EXPORT_API int noti_ex_item_text_get_contents(noti_ex_item_h handle,
3499     char **contents) {
3500   if (handle == nullptr || contents == nullptr) {
3501     LOGE("Invalid parameter");
3502     return NOTI_EX_ERROR_INVALID_PARAMETER;
3503   }
3504
3505   Handle* p = static_cast<Handle*>(handle);
3506   if (!p->IsValidType(AbstractItem::Text)) {
3507     LOGE("Invalid handle type");
3508     return NOTI_EX_ERROR_INVALID_PARAMETER;
3509   }
3510
3511   TextItem* ti = static_cast<TextItem*>(p->Get());
3512   string str;
3513   if (ti->GetMultiLanguage() != nullptr &&
3514       !ti->GetMultiLanguage()->GetTranslatedString().empty())
3515     str = ti->GetMultiLanguage()->GetTranslatedString();
3516   else if (!ti->GetContents().empty())
3517     str = ti->GetContents();
3518
3519   *contents = strdup(str.c_str());
3520   if (*contents == nullptr) {
3521     LOGE("Out-of-memory");
3522     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3523   }
3524
3525   return NOTI_EX_ERROR_NONE;
3526 }
3527
3528 extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
3529     noti_ex_item_h handle, char **hyper_link) {
3530   if (handle == nullptr || hyper_link == nullptr) {
3531     LOGE("Invalid parameter");
3532     return NOTI_EX_ERROR_INVALID_PARAMETER;
3533   }
3534
3535   Handle* p = static_cast<Handle*>(handle);
3536   if (!p->IsValidType(AbstractItem::Text)) {
3537     LOGE("Invalid handle type");
3538     return NOTI_EX_ERROR_INVALID_PARAMETER;
3539   }
3540   TextItem* ti = static_cast<TextItem*>(p->Get());
3541   if (!ti->GetHyperLink().empty()) {
3542     *hyper_link = strdup(ti->GetHyperLink().c_str());
3543     if (*hyper_link == nullptr) {
3544       LOGE("Out-of-memory");
3545       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3546     }
3547   } else {
3548     *hyper_link = nullptr;
3549   }
3550
3551   return NOTI_EX_ERROR_NONE;
3552 }
3553
3554 extern "C" EXPORT_API int noti_ex_item_text_set_multi_language(
3555     noti_ex_item_h handle, noti_ex_multi_lang_h multi) {
3556   if (handle == nullptr) {
3557     LOGE("Invalid parameter");
3558     return NOTI_EX_ERROR_INVALID_PARAMETER;
3559   }
3560
3561   Handle* p = static_cast<Handle*>(handle);
3562   if (!p->IsValidType(AbstractItem::Text)) {
3563     LOGE("Invalid handle type");
3564     return NOTI_EX_ERROR_INVALID_PARAMETER;
3565   }
3566
3567   TextItem* ti = static_cast<TextItem*>(p->Get());
3568   if (multi == nullptr) {
3569     ti->SetMultiLanguage(nullptr);
3570     return NOTI_EX_ERROR_NONE;
3571   }
3572
3573   shared_ptr<MultiLanguage> mul_ptr =
3574       *reinterpret_cast<shared_ptr<MultiLanguage>*>(multi);
3575   ti->SetMultiLanguage(mul_ptr);
3576   ti->GetMultiLanguage()->UpdateString();
3577
3578   return NOTI_EX_ERROR_NONE;
3579 }
3580
3581 extern "C" EXPORT_API int noti_ex_item_time_create(noti_ex_item_h *handle,
3582     const char *id, time_t time) {
3583   TimeItem* p;
3584
3585   if (handle == nullptr) {
3586     LOGE("Invalid parameter");
3587     return NOTI_EX_ERROR_INVALID_PARAMETER;
3588   }
3589
3590   if (time) {
3591     if (id)
3592       p = new (std::nothrow) TimeItem(id, time);
3593     else
3594       p = new (std::nothrow) TimeItem(time);
3595   } else {
3596       p = new (std::nothrow) TimeItem();
3597   }
3598
3599   if (p == nullptr) {
3600     LOGE("Out-of-memory");
3601     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3602   }
3603
3604   *handle = new Handle(shared_ptr<AbstractItem>(p));
3605
3606   return NOTI_EX_ERROR_NONE;
3607 }
3608
3609 extern "C" EXPORT_API int noti_ex_item_time_get_time(noti_ex_item_h handle,
3610     time_t *time) {
3611   if (handle == nullptr || time == nullptr) {
3612     LOGE("Invalid parameter");
3613     return NOTI_EX_ERROR_INVALID_PARAMETER;
3614   }
3615   Handle* h = static_cast<Handle*>(handle);
3616   if (!h->IsValidType(AbstractItem::Time)) {
3617     LOGE("Invalid handle type");
3618     return NOTI_EX_ERROR_INVALID_PARAMETER;
3619   }
3620   TimeItem* p = static_cast<TimeItem*>(h->Get());
3621   *time = p->GetTime();
3622
3623   return NOTI_EX_ERROR_NONE;
3624 }
3625
3626 extern "C" EXPORT_API int noti_ex_item_time_set_time(noti_ex_item_h handle,
3627     time_t time) {
3628   if (handle == nullptr) {
3629     LOGE("Invalid parameter");
3630     return NOTI_EX_ERROR_INVALID_PARAMETER;
3631   }
3632   Handle* h = static_cast<Handle*>(handle);
3633   if (!h->IsValidType(AbstractItem::Time)) {
3634     LOGE("Invalid handle type");
3635     return NOTI_EX_ERROR_INVALID_PARAMETER;
3636   }
3637   TimeItem* p = static_cast<TimeItem*>(h->Get());
3638   p->SetTime(time);
3639
3640   return NOTI_EX_ERROR_NONE;
3641 }
3642
3643 extern "C" EXPORT_API int noti_ex_action_visibility_create(
3644     noti_ex_action_h *handle, const char *extra) {
3645   if (handle == nullptr) {
3646     LOGE("Invalid parameter");
3647     return NOTI_EX_ERROR_INVALID_PARAMETER;
3648   }
3649
3650   string extra_str = "";
3651   if (extra != NULL)
3652     extra_str = string(extra);
3653
3654   shared_ptr<AbstractAction>* ptr = new (std::nothrow) shared_ptr<AbstractAction>(
3655       new (std::nothrow) VisibilityAction(extra_str));
3656   if (ptr == nullptr) {
3657     LOGE("Out-of-memory");
3658     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3659   }
3660
3661   *handle = ptr;
3662
3663   return NOTI_EX_ERROR_NONE;
3664 }
3665
3666 extern "C" EXPORT_API int noti_ex_action_visibility_set(noti_ex_action_h handle,
3667     const char *id, bool visible) {
3668   if (handle == nullptr || id == nullptr) {
3669     LOGE("Invalid parameter");
3670     return NOTI_EX_ERROR_INVALID_PARAMETER;
3671   }
3672
3673   shared_ptr<AbstractAction>* ptr =
3674       static_cast<shared_ptr<AbstractAction>*>(handle);
3675   VisibilityAction* action = static_cast<VisibilityAction*>(ptr->get());
3676   action->SetVisibility(id, visible);
3677
3678   return NOTI_EX_ERROR_NONE;
3679 }
3680
3681 extern "C" EXPORT_API int noti_ex_multi_lang_create(noti_ex_multi_lang_h* handle,
3682     const char* msgid, const char* format, ...) {
3683   if (handle == nullptr || msgid == nullptr || format == nullptr) {
3684     LOGE("Invalid parameter");
3685     return NOTI_EX_ERROR_INVALID_PARAMETER;
3686   }
3687
3688   const char* format_idx = format;
3689   vector<string> arr;
3690   va_list args;
3691   va_start(args, format);
3692   while (*format_idx != '\0') {
3693     char* arg = nullptr;
3694     int arg_i;
3695     double arg_f;
3696     stringstream stream;
3697     if (*format_idx == '%') {
3698       switch (*(format_idx + 1)) {
3699         case 's':
3700           arg = va_arg(args, char *);
3701           arr.push_back(string(arg));
3702           break;
3703         case 'd':
3704           arg_i = va_arg(args, int);
3705           arr.push_back(to_string(arg_i));
3706           break;
3707         case 'f':
3708           arg_f = va_arg(args, double);
3709           stream << std::fixed << std::setprecision(2) << arg_f;
3710           arr.push_back(stream.str());
3711           break;
3712       }
3713     }
3714     format_idx++;
3715   }
3716   va_end(args);
3717
3718   MultiLanguage* p = new MultiLanguage(string(msgid), format, arr);
3719   if (p == nullptr) {
3720     LOGE("Out-of-memory");
3721     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3722   }
3723   *handle = new shared_ptr<MultiLanguage>(p);
3724
3725   return NOTI_EX_ERROR_NONE;
3726 }
3727
3728 extern "C" EXPORT_API int noti_ex_multi_lang_destroy(noti_ex_multi_lang_h handle) {
3729   if (handle == nullptr) {
3730     LOGE("Invalid parameter");
3731     return NOTI_EX_ERROR_INVALID_PARAMETER;
3732   }
3733
3734   shared_ptr<MultiLanguage>* mul_ptr =
3735       reinterpret_cast<shared_ptr<MultiLanguage>*>(handle);
3736   delete mul_ptr;
3737   return NOTI_EX_ERROR_NONE;
3738 }
3739
3740 extern "C" EXPORT_API int noti_ex_item_get_private_id(
3741     noti_ex_item_h handle, int64_t* private_id) {
3742   if (handle == nullptr || private_id == nullptr) {
3743     LOGE("Invalid parameter");
3744     return NOTI_EX_ERROR_INVALID_PARAMETER;
3745   }
3746
3747   Handle* h = static_cast<Handle*>(handle);
3748   *private_id = static_pointer_cast<IItemInfoInternal>(
3749       h->Get()->GetInfo())->GetPrivateId();
3750
3751   return NOTI_EX_ERROR_NONE;
3752 }
3753
3754 extern "C" EXPORT_API int noti_ex_item_free_string_list(char** list, int count) {
3755   if (list == nullptr) {
3756     LOGE("Invalid parameter");
3757     return NOTI_EX_ERROR_INVALID_PARAMETER;
3758   }
3759
3760   LOGI("Free strings (%d)", count);
3761   for (int i = 0; i < count; i++)
3762     free(list[i]);
3763   free(list);
3764
3765   return NOTI_EX_ERROR_NONE;
3766 }
3767
3768 extern "C" EXPORT_API int noti_ex_item_group_remove_children(noti_ex_item_h handle) {
3769   if (handle == nullptr) {
3770     LOGE("Invalid parameter");
3771     return NOTI_EX_ERROR_INVALID_PARAMETER;
3772   }
3773   Handle* h = static_cast<Handle*>(handle);
3774   if (!h->IsValidType(AbstractItem::Group)) {
3775     LOGE("Invalid handle type");
3776     return NOTI_EX_ERROR_INVALID_PARAMETER;
3777   }
3778   GroupItem* p = static_cast<GroupItem*>(h->Get());
3779   p->RemoveChildren();
3780
3781   return NOTI_EX_ERROR_NONE;
3782 }
3783
3784 extern "C" EXPORT_API int noti_ex_item_icon_create(noti_ex_item_h *handle,
3785     const char *id, const char *icon_path) {
3786   if (handle == nullptr || icon_path == nullptr) {
3787     LOGE("Invalid parameter");
3788     return NOTI_EX_ERROR_INVALID_PARAMETER;
3789   }
3790
3791   IconItem* p;
3792   if (id)
3793     p = new (std::nothrow) IconItem(id, icon_path);
3794   else
3795     p = new (std::nothrow) IconItem(icon_path);
3796
3797   if (p == nullptr) {
3798     LOGE("Out-of-memory");
3799     return NOTI_EX_ERROR_OUT_OF_MEMORY;
3800   }
3801
3802   *handle = new Handle(shared_ptr<AbstractItem>(p));
3803
3804   return NOTI_EX_ERROR_NONE;
3805 }
3806
3807 extern "C" EXPORT_API int noti_ex_item_icon_get_icon_path(noti_ex_item_h handle, char **icon_path) {
3808   if (handle == nullptr || icon_path == nullptr) {
3809     LOGE("Invalid parameter");
3810     return NOTI_EX_ERROR_INVALID_PARAMETER;
3811   }
3812
3813   Handle* h = static_cast<Handle*>(handle);
3814   if (!h->IsValidType(AbstractItem::Icon)) {
3815     LOGE("Invalid handle type");
3816     return NOTI_EX_ERROR_INVALID_PARAMETER;
3817   }
3818
3819   IconItem* p = static_cast<IconItem*>(h->Get());
3820   if (!p->GetImagePath().empty()) {
3821     *icon_path = strdup(p->GetImagePath().c_str());
3822     if (*icon_path == nullptr) {
3823       LOGE("Out-of-memory");
3824       return NOTI_EX_ERROR_OUT_OF_MEMORY;
3825     }
3826   } else {
3827     *icon_path = nullptr;
3828   }
3829
3830   return NOTI_EX_ERROR_NONE;
3831 }