diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/command-id.h | 31 | ||||
-rw-r--r-- | src/common/dispatcher.cpp | 53 | ||||
-rw-r--r-- | src/common/dispatcher.h | 70 | ||||
-rw-r--r-- | src/common/serialization.h | 15 | ||||
-rw-r--r-- | src/common/socket.cpp | 2 |
6 files changed, 171 insertions, 1 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index fbfd9ff..dcd149d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -27,6 +27,7 @@ SET(COMMON_PATH ${CERT_CHECKER_SRC_PATH}/common) SET(${TARGET_CERT_CHECKER_COMMON}_SRCS ${COMMON_PATH}/binary-queue.cpp ${COMMON_PATH}/connection.cpp + ${COMMON_PATH}/dispatcher.cpp ${COMMON_PATH}/mainloop.cpp ${COMMON_PATH}/service.cpp ${COMMON_PATH}/socket.cpp diff --git a/src/common/command-id.h b/src/common/command-id.h new file mode 100644 index 0000000..e154e1a --- /dev/null +++ b/src/common/command-id.h @@ -0,0 +1,31 @@ +/* + * 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 command-id.h + * @author Sangwan Kwon (sangwan.kwon@samsung.com) + * @version 1.0 + * @brief + */ +#pragma once + +namespace CCHECKER { + +enum class CommandId : int { + CC_OCSP_SYN = 0x01, + CC_OCSP_ACK = 0x02 +}; + +} // namespace CCHECKER diff --git a/src/common/dispatcher.cpp b/src/common/dispatcher.cpp new file mode 100644 index 0000000..9b46493 --- /dev/null +++ b/src/common/dispatcher.cpp @@ -0,0 +1,53 @@ +/* + * 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 dispatcher.cpp + * @author Jaemin Ryu (jm77.ryu@samsung.com) + * @version 1.0 + * @brief + */ +#include "common/dispatcher.h" + +#include <utility> + +#include "common/socket.h" + +namespace CCHECKER { + +Dispatcher::Dispatcher(const std::string &path) : m_address(path) +{ +} + +Dispatcher::~Dispatcher() +{ + disconnect(); +} + +void Dispatcher::connect() +{ + m_connection = std::make_shared<Connection>(Socket::connect(m_address)); +} + +void Dispatcher::disconnect() +{ +} + +bool Dispatcher::isConnected() +{ + return m_connection ? true : false; +} + +} // namespace CCHECKER diff --git a/src/common/dispatcher.h b/src/common/dispatcher.h new file mode 100644 index 0000000..def73ed --- /dev/null +++ b/src/common/dispatcher.h @@ -0,0 +1,70 @@ +/* + * 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 dispatcher.h + * @author Jaemin Ryu (jm77.ryu@samsung.com) + * @version 1.0 + * @brief + */ +#pragma once + +#include <string> + +#include "common/connection.h" +#include "common/binary-queue.h" + +namespace CCHECKER { + +class Dispatcher { +public: + Dispatcher(const std::string &path); + virtual ~Dispatcher(); + + Dispatcher(const Dispatcher &) = delete; + Dispatcher &operator=(const Dispatcher &) = delete; + Dispatcher(Dispatcher &&) = delete; + Dispatcher &operator=(Dispatcher &&) = delete; + + template<typename Type, typename ...Args> + Type methodCall(Args &&...args); + +private: + bool isConnected(void); + void connect(void); + void disconnect(void); + + std::string m_address; + ConnShPtr m_connection; +}; + +template<typename Type, typename ...Args> +Type Dispatcher::methodCall(Args &&...args) +{ + if (!isConnected()) + connect(); + + m_connection->send(BinaryQueue::Serialize(std::forward<Args>(args)...).pop()); + + BinaryQueue q; + q.push(m_connection->receive()); + + Type response; + q.Deserialize(response); + + return response; +} + +} // namespace CCHECKER diff --git a/src/common/serialization.h b/src/common/serialization.h index 7f0ee84..04bd89d 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -32,6 +32,8 @@ #include <set> #include <memory> +#include "common/command-id.h" + namespace CCHECKER { namespace Common { @@ -147,6 +149,11 @@ struct Serialization { stream.write(sizeof(*value), value); } + static void Serialize(IStream &stream, const CommandId value) + { + Serialize(stream, static_cast<int>(value)); + } + // std::string template <typename T, typename R, typename A> static void Serialize(IStream &stream, const std::basic_string<T, R, A> &str) @@ -399,6 +406,14 @@ struct Deserialization { { stream.read(sizeof(value), &value); } + + static void Deserialize(IStream &stream, CommandId &value) + { + int val; + Deserialize(stream, val); + value = static_cast<CommandId>(val); + } + static void Deserialize(IStream &stream, bool *&value) { value = new bool; diff --git a/src/common/socket.cpp b/src/common/socket.cpp index a829484..30c2edc 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -135,7 +135,7 @@ Socket Socket::connect(const std::string &path) std::error_code(errno, std::generic_category()), "socket connect failed!"); - LogInfo("Connect to CSR server success with fd:" << fd); + LogInfo("Connect to OCSP service success with fd:" << fd); return Socket(fd); } |