Add PathConfig 60/28960/8
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 17 Oct 2014 12:48:46 +0000 (14:48 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Fri, 14 Nov 2014 16:27:28 +0000 (17:27 +0100)
Put all default paths into globally visible namespaces.

Change-Id: I4f234c5558e828cbcacf86de8d266e89a0ad687c

src/admin/logic/Logic.cpp
src/client-async/logic/Logic.cpp
src/client/logic/Logic.cpp
src/common/CMakeLists.txt
src/common/config/PathConfig.cpp [new file with mode: 0644]
src/common/config/PathConfig.h [new file with mode: 0644]
src/common/sockets/SocketPath.cpp [deleted file]
src/common/sockets/SocketPath.h [deleted file]
src/service/main/Cynara.cpp
src/service/main/Cynara.h
src/service/sockets/SocketManager.cpp

index 0deccb9..506ecbf 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <cynara-error.h>
 #include <common.h>
+#include <config/PathConfig.h>
 #include <exceptions/Exception.h>
 #include <exceptions/UnexpectedErrorException.h>
 #include <log/log.h>
@@ -39,7 +40,6 @@
 #include <response/CodeResponse.h>
 #include <response/pointers.h>
 #include <sockets/SocketClient.h>
-#include <sockets/SocketPath.h>
 #include <types/ProtocolFields.h>
 
 #include "Logic.h"
@@ -47,7 +47,7 @@
 namespace Cynara {
 
 Logic::Logic() {
-    m_socketClient = std::make_shared<SocketClient>(SocketPath::admin,
+    m_socketClient = std::make_shared<SocketClient>(PathConfig::SocketPath::admin,
                                                     std::make_shared<ProtocolAdmin>());
 }
 
index 8babbed..921c2d6 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <cache/CapacityCache.h>
 #include <common.h>
+#include <config/PathConfig.h>
 #include <exceptions/Exception.h>
 #include <exceptions/NoMemoryException.h>
 #include <exceptions/UnexpectedErrorException.h>
@@ -36,7 +37,6 @@
 #include <response/CancelResponse.h>
 #include <response/CheckResponse.h>
 #include <sockets/Socket.h>
-#include <sockets/SocketPath.h>
 
 #include "Logic.h"
 
@@ -45,7 +45,7 @@ namespace Cynara {
 Logic::Logic(cynara_status_callback callback, void *userStatusData)
     : m_statusCallback(callback, userStatusData) {
     m_socketClient = std::make_shared<SocketClientAsync>(
-        SocketPath::client, std::make_shared<ProtocolClient>());
+        PathConfig::SocketPath::client, std::make_shared<ProtocolClient>());
 
     m_cache = std::make_shared<CapacityCache>();
     auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
index 4886b78..e05a168 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <cache/CapacityCache.h>
 #include <common.h>
+#include <config/PathConfig.h>
 #include <cynara-error.h>
 #include <exceptions/Exception.h>
 #include <exceptions/UnexpectedErrorException.h>
@@ -36,7 +37,6 @@
 #include <response/CheckResponse.h>
 #include <response/pointers.h>
 #include <sockets/SocketClient.h>
-#include <sockets/SocketPath.h>
 
 #include <logic/Logic.h>
 
@@ -48,7 +48,8 @@ static ProtocolFrameSequenceNumber generateSequenceNumber(void) {
 }
 
 Logic::Logic() {
-    m_socket = std::make_shared<SocketClient>(SocketPath::client, std::make_shared<ProtocolClient>());
+    m_socket = std::make_shared<SocketClient>(PathConfig::SocketPath::client,
+                                              std::make_shared<ProtocolClient>());
     m_cache = std::make_shared<CapacityCache>();
     auto naiveInterpreter = std::make_shared<NaiveInterpreter>();
     m_cache->registerPlugin(PredefinedPolicyType::ALLOW, naiveInterpreter);
index 6cd0005..61debfd 100644 (file)
@@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES(
     )
 
 SET(COMMON_SOURCES
+    ${COMMON_PATH}/config/PathConfig.cpp
     ${COMMON_PATH}/containers/BinaryQueue.cpp
     ${COMMON_PATH}/log/log.cpp
     ${COMMON_PATH}/protocol/ProtocolAdmin.cpp
@@ -49,7 +50,6 @@ 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/config/PathConfig.cpp b/src/common/config/PathConfig.cpp
new file mode 100644 (file)
index 0000000..a5a603b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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/config/PathConfig.cpp
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       This file specifies PathConfig namespace containing values of default cynara paths
+ */
+
+#include "PathConfig.h"
+
+namespace Cynara {
+namespace PathConfig {
+
+//main paths
+const std::string statePath(
+#ifdef CYNARA_STATE_PATH
+        CYNARA_STATE_PATH
+#else
+        "/var/lib/cynara/"
+#endif
+      );
+
+const std::string libraryPath(
+#ifdef CYNARA_LIB_PATH
+        CYNARA_LIB_PATH
+#else
+        "/usr/lib/cynara/"
+#endif
+      );
+
+const std::string clientPath("/run/cynara/");
+
+namespace SocketPath {
+const std::string client(clientPath + "cynara.socket");
+const std::string admin(clientPath + "cynara-admin.socket");
+} // namespace SocketPath
+
+namespace StoragePath {
+const std::string dbDir(statePath + "db/");
+} // namespace StoragePath
+
+namespace PluginPath {
+const std::string clientDir(libraryPath + "plugin/client/");
+const std::string serviceDir(libraryPath + "plugin/service/");
+} // namespace PluginPath
+
+} // namespace PathConfig
+} // namespace Cynara
+
+
+
diff --git a/src/common/config/PathConfig.h b/src/common/config/PathConfig.h
new file mode 100644 (file)
index 0000000..27b10c2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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/config/PathConfig.h
+ * @author      Zofia Abramowska <z.abramowska@samsung.com>
+ * @version     1.0
+ * @brief       This file specifies PathConfig namespace containing default cynara paths
+ */
+
+#ifndef SRC_COMMON_CONFIG_PATHCONFIG_H_
+#define SRC_COMMON_CONFIG_PATHCONFIG_H_
+
+#include <string>
+
+namespace Cynara {
+namespace PathConfig {
+
+extern const std::string statePath;
+extern const std::string libraryPath;
+extern const std::string clientPath;
+
+namespace SocketPath {
+extern const std::string client;
+extern const std::string admin;
+} // namespace SocketPath
+
+namespace StoragePath {
+extern const std::string dbDir;
+} // namespace StoragePath
+
+namespace PluginPath {
+extern const std::string clientDir;
+extern const std::string serviceDir;
+} // namespace PluginPath
+
+} // namespace PathConfig
+} // namespace Cynara
+
+#endif /* SRC_COMMON_CONFIG_PATHCONFIG_H_ */
diff --git a/src/common/sockets/SocketPath.cpp b/src/common/sockets/SocketPath.cpp
deleted file mode 100644 (file)
index c64e2ff..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  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 <m.niesluchow@samsung.com>
- * @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
deleted file mode 100644 (file)
index cca867d..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  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 <m.niesluchow@samsung.com>
- * @version     1.0
- * @brief       Header for common socket paths
- */
-
-#ifndef  SRC_COMMON_SOCKETS_SOCKETPATH_H_
-#define  SRC_COMMON_SOCKETS_SOCKETPATH_H_
-
-#include <string>
-
-namespace Cynara {
-namespace SocketPath {
-
-extern const std::string client;
-extern const std::string admin;
-
-} // namespace SocketPath
-} // namespace Cynara
-
-#endif // SRC_COMMON_SOCKETS_SOCKETPATH_H_
index 1a0d45e..c0f77ef 100644 (file)
@@ -23,6 +23,7 @@
 #include <memory>
 #include <stddef.h>
 
+#include <config/PathConfig.h>
 #include <log/log.h>
 #include <exceptions/InitException.h>
 
@@ -45,38 +46,11 @@ Cynara::~Cynara() {
     finalize();
 }
 
-const std::string Cynara::storageDir(void) {
-    std::string dir("/var/lib/cynara/");
-
-#ifdef CYNARA_STATE_PATH
-    dir = CYNARA_STATE_PATH;
-#else
-    LOGW("Cynara compiled without CYNARA_STATE_PATH flag. Using default database directory.");
-#endif
-
-    dir += "db/";
-    LOGI("Cynara database path <%s>", dir.c_str());
-    return dir;
-}
-
-const std::string Cynara::pluginDir(void) {
-    std::string dir("/usr/lib/cynara/");
-
-#ifdef CYNARA_LIB_PATH
-    dir = CYNARA_LIB_PATH;
-#else
-    LOGW("Cynara compiled without CYNARA_LIB_PATH flag. Using default plugin directory.");
-#endif
-    dir += "plugin/";
-    LOGI("Cynara plugin path <%s>", dir.c_str());
-    return dir;
-}
-
 void Cynara::init(void) {
     m_logic = std::make_shared<Logic>();
-    m_pluginManager = std::make_shared<PluginManager>(pluginDir());
+    m_pluginManager = std::make_shared<PluginManager>(PathConfig::PluginPath::serviceDir);
     m_socketManager = std::make_shared<SocketManager>();
-    m_storageBackend = std::make_shared<InMemoryStorageBackend>(storageDir());
+    m_storageBackend = std::make_shared<InMemoryStorageBackend>(PathConfig::StoragePath::dbDir);
     m_storage = std::make_shared<Storage>(*m_storageBackend);
 
     m_logic->bindPluginManager(m_pluginManager);
index e89eda3..2eb94dc 100644 (file)
 namespace Cynara {
 
 class Cynara {
-private:
-    LogicPtr m_logic;
-    PluginManagerPtr m_pluginManager;
-    SocketManagerPtr m_socketManager;
-    StoragePtr m_storage;
-    StorageBackendPtr m_storageBackend;
-
-    static const std::string pluginDir(void);
-    static const std::string storageDir(void);
-
 public:
     Cynara();
     ~Cynara();
@@ -45,6 +35,13 @@ public:
     void init(void);
     void run(void);
     void finalize(void);
+
+private:
+    LogicPtr m_logic;
+    PluginManagerPtr m_pluginManager;
+    SocketManagerPtr m_socketManager;
+    StoragePtr m_storage;
+    StorageBackendPtr m_storageBackend;
 };
 
 } // namespace Cynara
index c9e1692..3161dc7 100644 (file)
 
 #include <log/log.h>
 #include <common.h>
+#include <config/PathConfig.h>
 #include <exceptions/DescriptorNotExistsException.h>
 #include <exceptions/InitException.h>
 #include <exceptions/UnexpectedErrorException.h>
-#include <sockets/SocketPath.h>
 
 #include <logic/Logic.h>
 #include <main/Cynara.h>
@@ -73,10 +73,10 @@ void SocketManager::init(void) {
     const mode_t clientSocketUMask(0);
     const mode_t adminSocketUMask(0077);
 
-    createDomainSocket(std::make_shared<ProtocolClient>(), SocketPath::client, clientSocketUMask,
-                       true);
-    createDomainSocket(std::make_shared<ProtocolAdmin>(), SocketPath::admin, adminSocketUMask,
-                       false);
+    createDomainSocket(std::make_shared<ProtocolClient>(), PathConfig::SocketPath::client,
+                       clientSocketUMask, true);
+    createDomainSocket(std::make_shared<ProtocolAdmin>(), PathConfig::SocketPath::admin,
+                       adminSocketUMask, false);
     createSignalSocket(std::make_shared<ProtocolSignal>());
     LOGI("SocketManger init done");
 }