From 1dcea79f6b7f2880b32091a3f0a035e878fa0e94 Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Mon, 15 Sep 2014 11:17:34 +0200 Subject: [PATCH] Move socket paths to common library Change-Id: I4b5bf9c2bc47aca6f87bb89942a09b2a8ae6e251 --- src/admin/logic/Logic.cpp | 5 ++--- src/client/logic/Logic.cpp | 5 ++--- src/common/CMakeLists.txt | 1 + src/common/sockets/SocketPath.cpp | 32 ++++++++++++++++++++++++++++++ src/common/sockets/SocketPath.h | 37 +++++++++++++++++++++++++++++++++++ src/service/sockets/SocketManager.cpp | 8 ++++---- 6 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 src/common/sockets/SocketPath.cpp create mode 100644 src/common/sockets/SocketPath.h diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp index 95ececc..89c2d2c 100644 --- a/src/admin/logic/Logic.cpp +++ b/src/admin/logic/Logic.cpp @@ -38,16 +38,15 @@ #include #include #include +#include #include #include "Logic.h" namespace Cynara { -const std::string adminSocketPath("/run/cynara/cynara-admin.socket"); - Logic::Logic() { - m_socketClient = std::make_shared(adminSocketPath, + m_socketClient = std::make_shared(SocketPath::admin, std::make_shared()); } diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index 2708318..d856042 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -35,20 +35,19 @@ #include #include #include +#include #include namespace Cynara { -const std::string clientSocketPath("/run/cynara/cynara.socket"); - static ProtocolFrameSequenceNumber generateSequenceNumber(void) { static ProtocolFrameSequenceNumber sequenceNumber = 0; return ++sequenceNumber; } Logic::Logic() { - m_socket = std::make_shared(clientSocketPath, std::make_shared()); + m_socket = std::make_shared(SocketPath::client, std::make_shared()); m_cache = std::make_shared(); auto naiveInterpreter = std::make_shared(); m_cache->registerPlugin(PredefinedPolicyType::ALLOW, naiveInterpreter); diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0901962..490a4f3 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -43,6 +43,7 @@ SET(COMMON_SOURCES ${COMMON_PATH}/response/ResponseTaker.cpp ${COMMON_PATH}/sockets/Socket.cpp ${COMMON_PATH}/sockets/SocketClient.cpp + ${COMMON_PATH}/sockets/SocketPath.cpp ${COMMON_PATH}/types/PolicyBucket.cpp ${COMMON_PATH}/types/PolicyKey.cpp ${COMMON_PATH}/types/PolicyKeyHelpers.cpp diff --git a/src/common/sockets/SocketPath.cpp b/src/common/sockets/SocketPath.cpp new file mode 100644 index 0000000..c64e2ff --- /dev/null +++ b/src/common/sockets/SocketPath.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014 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 src/common/sockets/SocketPath.cpp + * @author Marcin Niesluchowski + * @version 1.0 + * @brief Source file for common socket paths + */ + +#include "SocketPath.h" + +namespace Cynara { +namespace SocketPath { + +const std::string client("/run/cynara/cynara.socket"); +const std::string admin("/run/cynara/cynara-admin.socket"); + +} // namespace SocketPath +} // namespace Cynara diff --git a/src/common/sockets/SocketPath.h b/src/common/sockets/SocketPath.h new file mode 100644 index 0000000..cca867d --- /dev/null +++ b/src/common/sockets/SocketPath.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014 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 src/common/sockets/SocketPath.h + * @author Marcin Niesluchowski + * @version 1.0 + * @brief Header for common socket paths + */ + +#ifndef SRC_COMMON_SOCKETS_SOCKETPATH_H_ +#define SRC_COMMON_SOCKETS_SOCKETPATH_H_ + +#include + +namespace Cynara { +namespace SocketPath { + +extern const std::string client; +extern const std::string admin; + +} // namespace SocketPath +} // namespace Cynara + +#endif // SRC_COMMON_SOCKETS_SOCKETPATH_H_ diff --git a/src/service/sockets/SocketManager.cpp b/src/service/sockets/SocketManager.cpp index 29bc999..cb3c9b4 100644 --- a/src/service/sockets/SocketManager.cpp +++ b/src/service/sockets/SocketManager.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include
@@ -69,14 +70,13 @@ void SocketManager::run(void) { void SocketManager::init(void) { LOGI("SocketManger init start"); - const std::string clientSocketPath("/run/cynara/cynara.socket"); - const std::string adminSocketPath("/run/cynara/cynara-admin.socket"); const mode_t clientSocketUMask(0); const mode_t adminSocketUMask(0077); - createDomainSocket(std::make_shared(), clientSocketPath, clientSocketUMask, + createDomainSocket(std::make_shared(), SocketPath::client, clientSocketUMask, true); - createDomainSocket(std::make_shared(), adminSocketPath, adminSocketUMask, false); + createDomainSocket(std::make_shared(), SocketPath::admin, adminSocketUMask, + false); createSignalSocket(std::make_shared()); LOGI("SocketManger init done"); } -- 2.7.4