tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Notification / NotificationUtil.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include "NotificationUtil.h"
19
20 #include <sstream>
21
22 #include <PlatformException.h>
23 #include <Logger.h>
24
25 using namespace DeviceAPI::Common;
26
27 namespace DeviceAPI {
28 namespace Notification {
29
30 void NotificationUtil::throwNotificationException(const int error_code,
31     const std::string &hint)
32 {
33     std::stringstream ss;
34     ss << hint << " : " << getNotificationErrorMessage(error_code);
35     LOGE("%s", ss.str().c_str());
36
37     switch (error_code) {
38         case NOTIFICATION_ERROR_NOT_EXIST_ID:
39             throw NotFoundException(ss.str().c_str());
40         default:
41             throw UnknownException(ss.str().c_str());
42     }
43 }
44
45 std::string NotificationUtil::getNotificationErrorMessage(const int error_code)
46 {
47     switch (error_code) {
48         case NOTIFICATION_ERROR_INVALID_PARAMETER:
49             return "Invalid parameter";
50         case NOTIFICATION_ERROR_OUT_OF_MEMORY:
51             return "Out of memory";
52         case NOTIFICATION_ERROR_IO_ERROR:
53             return "I/O error";
54         case NOTIFICATION_ERROR_PERMISSION_DENIED:
55             return "Permission denied";
56         case NOTIFICATION_ERROR_FROM_DB:
57             return "Error from DB query";
58         case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
59             return "Already exist private ID";
60         case NOTIFICATION_ERROR_FROM_DBUS:
61             return "Error from DBus";
62         case NOTIFICATION_ERROR_NOT_EXIST_ID:
63             return "Not exist private ID";
64         case NOTIFICATION_ERROR_SERVICE_NOT_READY:
65             return "No reponse from notification service";
66         default:
67             return "Unknown Error";
68     }
69 }
70
71 }
72 }