0.9.14 release -- add: TIVI-1751 Home Screen needs to use system notifications framework
[profile/ivi/ico-uxf-homescreen.git] / lib / notification / CicoNotificationApp.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoNotificationApp.cpp
13  *
14  *  @brief  This file is implemetation of CicoNotificationApp class
15  */
16 //==========================================================================
17
18 #include <ico_log.h>
19
20 #include "CicoNotificationApp.h"
21
22 //--------------------------------------------------------------------------
23 /**
24  *  @brief  default constructor
25  */
26 //--------------------------------------------------------------------------
27 CicoNotificationApp::CicoNotificationApp()
28     : m_privateid(0)
29 {
30 }
31
32 //--------------------------------------------------------------------------
33 /**
34  *  @brief  destructor
35  */
36 //--------------------------------------------------------------------------
37 CicoNotificationApp::~CicoNotificationApp()
38 {
39 }
40
41 //--------------------------------------------------------------------------
42 /**
43  *  @brief  add notification
44  *
45  *  @param [in] ico notification handle
46  *
47  *  @return result
48  *  @retval true        success
49  *  @retval false       notification handle is null or
50  *                      notification_insert() failed
51  */
52 //--------------------------------------------------------------------------
53 bool
54 CicoNotificationApp::Add(CicoNotification noti)
55 {
56     if (true == noti.Empty()) {
57         ICO_WRN("notification handle is null.");
58         return false;
59     }
60
61     int retid = 0;
62     notification_error_e err = NOTIFICATION_ERROR_NONE;
63     err = notification_insert(noti.GetNotiHandle(), &retid);
64     if (NOTIFICATION_ERROR_NONE != err) {
65         ICO_ERR("notification_insert() failed(%d).", err);
66         return false;
67     }
68     m_privateid = retid;
69     return true;
70 }
71
72 //--------------------------------------------------------------------------
73 /**
74  *  @brief  update notification
75  *
76  *  @param [in] ico notification handle
77  *
78  *  @return result
79  *  @retval true        success
80  *  @retval false       notification handle is null or
81  *                      notification is not add yet or
82  *                      notification_update() failed
83  */
84 //--------------------------------------------------------------------------
85 bool
86 CicoNotificationApp::Update(CicoNotification noti)
87 {
88     if ((true == noti.Empty()) || (0 == m_privateid)) {
89         ICO_WRN("notification handle is null. or not add notification.");
90         return false;
91     }
92
93     notification_error_e err = NOTIFICATION_ERROR_NONE;
94     err = notification_update(noti.GetNotiHandle());
95     if (NOTIFICATION_ERROR_NONE != err) {
96         ICO_ERR("notification_update() failed(%d).", err);
97         return false;
98     }
99
100     return true;
101 }
102
103 //--------------------------------------------------------------------------
104 /**
105  *  @brief  delete notification
106  *
107  *  @param [in] ico notification handle
108  *
109  *  @return result
110  *  @retval true        success
111  *  @retval false       notification handle is null or
112  *                      notification is not add yet or
113  *                      notification_update() failed
114  */
115 //--------------------------------------------------------------------------
116 bool
117 CicoNotificationApp::Delete(CicoNotification noti)
118 {
119     if ((true == noti.Empty()) || (0 == m_privateid)) {
120         ICO_WRN("notification handle is null. or not add notification.");
121         return false;
122     }
123
124     const char *pkgname = noti.GetPkgname();
125     if (NULL == pkgname) {
126         return false;
127     }
128
129     notification_error_e err = notification_delete_by_priv_id(pkgname,
130                                                               noti.GetType(),
131                                                               m_privateid);
132     if (NOTIFICATION_ERROR_NONE != err) {
133         ICO_ERR("notification_delete_by_priv_id() failed(%d).", err);
134         return false;
135     }
136
137     return true;
138 }
139 // vim:set expandtab ts=4 sw=4: