tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Download / DownloadUtil.h
1 // Tizen Web Device API
2 // Copyright (c) 2014 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 #ifndef __TIZEN_DOWNLOAD_UTIL_H__
18 #define __TIZEN_DOWNLOAD_UTIL_H__
19
20 #include <string>
21
22 #include <PlatformException.h>
23 #include <Logger.h>
24 #include <download.h>
25 #include <net_connection.h>
26
27 namespace DeviceAPI {
28 namespace Download {
29
30 class DownloadUtil {
31 public:
32     template <class T = DeviceAPI::Common::UnknownException>
33     static void throwDownloadException(const int errorCode, const std::string &hint) {
34         std::string log = DownloadUtil::getDownloadLogMessage(errorCode, hint);
35         LOGE("%s", log.c_str());
36         throw T(log.c_str());
37     }
38     static std::string getDownloadErrorMessage(const int errorCode);
39     static std::string getDownloadLogMessage(const int errorCode, const std::string &hint);
40
41     template <class T = DeviceAPI::Common::UnknownException>
42     static void throwConnectionException(const int errorCode, const std::string &hint) {
43         std::string log = DownloadUtil::getConnectionLogMessage(errorCode, hint);
44         LOGE("%s", log.c_str());
45         throw T(log.c_str());
46     }
47     static std::string getConnectionErrorMessage(const int errorCode);
48     static std::string getConnectionLogMessage(const int errorCode, const std::string &hint);
49 };
50
51 } // Download
52 } // DeviceAPI
53
54 #endif // __TIZEN_DOWNLOAD_UTIL_H__