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