Detach Exception class from common header 38/60238/1
authorKyungwook Tak <k.tak@samsung.com>
Wed, 24 Feb 2016 07:58:34 +0000 (16:58 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Wed, 24 Feb 2016 08:38:38 +0000 (17:38 +0900)
Change-Id: Ic9f4a21c4ce6ba99545a19e45e3f9c4d692171c0
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/common/CMakeLists.txt
src/common/include/tpkp_common.h
src/common/include/tpkp_exception.h [new file with mode: 0644]
src/common/src/tpkp_common.cpp
src/common/src/tpkp_exception.cpp [new file with mode: 0644]
src/common/ui/popup-bin/popup.cpp
src/curl/tpkp_curl.cpp
src/gnutls/tpkp_gnutls.cpp
test/CMakeLists.txt

index bf68943..b6e019e 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 #
 #    Licensed under the Apache License, Version 2.0 (the "License");
 #    you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ SET(TPKP_COMMON_SRCS
        url/url_parse_file.cc
        net/http/transport_security_state.cpp
        src/tpkp_common.cpp
+       src/tpkp_exception.cpp
        src/tpkp_parser.cpp
        src/tpkp_client_cache.cpp
        ui/popup_common.cpp
index c26add1..c64636f 100644 (file)
  */
 #pragma once
 
-#include <sys/types.h>
 #include <string>
 #include <vector>
 #include <memory>
-#include <sstream>
 #include <type_traits>
 
+#include "tpkp_exception.h"
 #include "tpkp_error.h"
-#include "tpkp_logger.h"
 
 #define EXPORT_API __attribute__((visibility("default")))
 
+/*
+ *  classes under this header may throw exception which declared in tpkp_exception.h
+ */
+
 namespace TPKP {
 
 enum class HashAlgo : int {
@@ -70,20 +72,6 @@ struct HashValue {
 
 using HashValueVector = std::vector<HashValue>;
 
-class EXPORT_API Exception : public std::exception {
-public:
-       explicit Exception(tpkp_e code, const std::string &message);
-       virtual const char *what(void) const noexcept;
-       tpkp_e code(void) const noexcept;
-
-private:
-       tpkp_e m_code;
-       std::string m_message;
-};
-
-EXPORT_API
-tpkp_e ExceptionSafe(const std::function<void()> &func) noexcept;
-
 class EXPORT_API Context {
 public:
        Context() = delete;
@@ -100,13 +88,3 @@ private:
 };
 
 }
-
-#define TPKP_THROW_EXCEPTION(code, message) \
-do {                                        \
-       std::ostringstream log;                 \
-       log << message;                         \
-       throw TPKP::Exception(code, log.str()); \
-} while(false)
-
-#define TPKP_CHECK_THROW_EXCEPTION(cond, code, message) \
-       if (!(cond)) TPKP_THROW_EXCEPTION(code, message)
diff --git a/src/common/include/tpkp_exception.h b/src/common/include/tpkp_exception.h
new file mode 100644 (file)
index 0000000..391f31c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        tpkp_exception.h
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Exceptions for internal use.
+ */
+#pragma once
+
+#include <sstream>
+#include <string>
+#include <exception>
+#include <functional>
+
+#include "tpkp_error.h"
+
+#define EXPORT_API __attribute__((visibility("default")))
+
+namespace TPKP {
+
+EXPORT_API
+tpkp_e ExceptionSafe(const std::function<void()> &func) noexcept;
+
+class EXPORT_API Exception : public std::exception {
+public:
+       explicit Exception(tpkp_e code, const std::string &message);
+       virtual const char *what(void) const noexcept;
+       tpkp_e code(void) const noexcept;
+
+private:
+       tpkp_e m_code;
+       std::string m_message;
+};
+
+}
+
+#define TPKP_THROW_EXCEPTION(code, message) \
+do {                                        \
+       std::ostringstream log;                 \
+       log << message;                         \
+       throw TPKP::Exception(code, log.str()); \
+} while(false)
+
+#define TPKP_CHECK_THROW_EXCEPTION(cond, code, message) \
+       if (!(cond)) TPKP_THROW_EXCEPTION(code, message)
index 3eb7d2d..0102d36 100644 (file)
@@ -30,6 +30,7 @@
 #include "net/http/transport_security_state.h"
 #include "net/http/transport_security_state_static.h"
 
+#include "tpkp_logger.h"
 #include "tpkp_parser.h"
 #include "ui/popup_runner.h"
 
@@ -45,41 +46,6 @@ inline size_t _arraySize(const T &t)
 
 namespace TPKP {
 
-Exception::Exception(tpkp_e code, const std::string &message)
-       : m_code(code)
-       , m_message(message)
-{}
-
-const char *Exception::what(void) const noexcept
-{
-       return m_message.c_str();
-}
-
-tpkp_e Exception::code(void) const noexcept
-{
-       return m_code;
-}
-
-tpkp_e ExceptionSafe(const std::function<void()> &func)
-{
-       try {
-               func();
-               return TPKP_E_NONE;
-       } catch (const Exception &e) {
-               SLOGE("Exception: %s", e.what());
-               return e.code();
-       } catch (const std::bad_alloc &e) {
-               SLOGE("bad_alloc std exception: %s", e.what());
-               return TPKP_E_MEMORY;
-       } catch (const std::exception &e) {
-               SLOGE("std exception: %s", e.what());
-               return TPKP_E_STD_EXCEPTION;
-       } catch (...) {
-               SLOGE("Unhandled exception occured!");
-               return TPKP_E_INTERNAL;
-       }
-}
-
 class Context::Impl {
 public:
        Impl() = delete;
diff --git a/src/common/src/tpkp_exception.cpp b/src/common/src/tpkp_exception.cpp
new file mode 100644 (file)
index 0000000..d488540
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        tpkp_exception.cpp
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Exceptions for internal uses
+ */
+#include "tpkp_exception.h"
+
+#include "tpkp_logger.h"
+
+namespace TPKP {
+
+Exception::Exception(tpkp_e code, const std::string &message)
+       : m_code(code)
+       , m_message(message)
+{}
+
+const char *Exception::what(void) const noexcept
+{
+       return m_message.c_str();
+}
+
+tpkp_e Exception::code(void) const noexcept
+{
+       return m_code;
+}
+
+tpkp_e ExceptionSafe(const std::function<void()> &func)
+{
+       try {
+               func();
+               return TPKP_E_NONE;
+       } catch (const Exception &e) {
+               SLOGE("Exception: %s", e.what());
+               return e.code();
+       } catch (const std::bad_alloc &e) {
+               SLOGE("bad_alloc std exception: %s", e.what());
+               return TPKP_E_MEMORY;
+       } catch (const std::exception &e) {
+               SLOGE("std exception: %s", e.what());
+               return TPKP_E_STD_EXCEPTION;
+       } catch (...) {
+               SLOGE("Unhandled exception occured!");
+               return TPKP_E_INTERNAL;
+       }
+}
+
+}
index 6b5c85f..d898946 100644 (file)
 #include <systemd/sd-daemon.h>
 #include <vconf.h>
 
-/*
- * TODO(k.tak): Separate TPKP::Exception related codes from tpkp_common
- *              not to include "tpkp_common.h" which have lot of dependencies
- */
-#include "tpkp_common.h"
+#include "tpkp_exception.h"
 #include "tpkp_logger.h"
 #include "ui/popup_common.h"
 
index 54a8462..44b1d1e 100644 (file)
@@ -29,6 +29,7 @@
 #include <curl/curl.h>
 
 #include "tpkp_common.h"
+#include "tpkp_logger.h"
 #include "tpkp_client_cache.h"
 
 namespace {
index 41fbd73..40bec5d 100644 (file)
@@ -31,6 +31,7 @@
 #include <gnutls/x509.h>
 
 #include "tpkp_common.h"
+#include "tpkp_logger.h"
 #include "tpkp_client_cache.h"
 
 namespace {
index 98e8c56..26191ee 100644 (file)
@@ -70,6 +70,7 @@ SET(TEST_POPUP_SRCS
        ${PROJECT_SOURCE_DIR}/src/common/url/url_parse_file.cc
        ${PROJECT_SOURCE_DIR}/src/common/net/http/transport_security_state.cpp
        ${PROJECT_SOURCE_DIR}/src/common/src/tpkp_common.cpp
+       ${PROJECT_SOURCE_DIR}/src/common/src/tpkp_exception.cpp
        ${PROJECT_SOURCE_DIR}/src/common/src/tpkp_parser.cpp
        ${PROJECT_SOURCE_DIR}/src/common/ui/popup_runner.cpp
        ${PROJECT_SOURCE_DIR}/src/common/ui/popup_common.cpp