Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
add config-cxx to client
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal committed Jan 14, 2024
1 parent 6328da1 commit cdaf78b
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 47 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "externals/loguru"]
path = externals/loguru
url = https://github.com/emilk/loguru.git
[submodule "externals/dotenv-cpp"]
path = externals/dotenv-cpp
url = https://github.com/laserpants/dotenv-cpp.git
[submodule "externals/json"]
path = externals/json
url = https://github.com/nlohmann/json.git
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_subdirectory(externals)

set(GMOCK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/googletest/googlemock/include")
set(GTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/googletest/googletest/include")
set(DOTENV_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/dotenv-cpp/include")

enable_testing()

Expand Down
2 changes: 0 additions & 2 deletions apps/client/.env.example

This file was deleted.

4 changes: 3 additions & 1 deletion apps/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(SOURCES
config/ConfigProvider.cpp
core/configProvider/ConfigProvider.cpp
api/SessionImpl.cpp
api/SocketConnectorImpl.cpp
api/MessageFactoryImpl.cpp
Expand Down Expand Up @@ -126,6 +126,7 @@ target_link_libraries(${EXECUTABLE_NAME} PUBLIC
collection
envParser
fmt::fmt
config-cxx
)

target_include_directories(${EXECUTABLE_NAME} PUBLIC ${GMOCK_INCLUDE_DIR} ${DOTENV_INCLUDE_DIR})
Expand All @@ -148,6 +149,7 @@ target_link_libraries(${EXECUTABLE_NAME}UT PUBLIC
envParser
faker-cxx
fmt::fmt
config-cxx
)

target_include_directories(${EXECUTABLE_NAME}UT PUBLIC ${GMOCK_INCLUDE_DIR})
Expand Down
11 changes: 3 additions & 8 deletions apps/client/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@
#include "api/SessionImpl.h"
#include "api/SocketConnectorImpl.h"
#include "common/filesystem/GetProjectPath.h"
#include "config/ConfigProvider.h"
#include "core/configProvider/ConfigProvider.h"
#include "gui/qml/LoaderController.h"
#include "gui/states/StateFactory.h"
#include "gui/states/StateMachine.h"
#include "laserpants/dotenv/dotenv.h"
#include "loguru.hpp"
#include "messages/MessageReaderImpl.h"
#include "messages/MessageSenderImpl.h"
#include "messages/MessageSerializerImpl.h"

int main(int argc, char* argv[])
{
auto dotEnvPath = common::filesystem::getProjectPath("chatroom") + "/apps/client/.env";

dotenv::init(dotEnvPath.c_str());

loguru::g_preamble_date = false;

loguru::init(argc, argv);

client::config::ConfigProvider configProvider;
client::core::ConfigProvider configProvider;

const auto serverHost = configProvider.getServerHost();

Expand Down Expand Up @@ -65,5 +60,5 @@ int main(int argc, char* argv[])

std::thread api{[&] { context.run(); }};

return app.exec();
return QGuiApplication::exec();
}
16 changes: 0 additions & 16 deletions apps/client/config/ConfigProvider.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions apps/client/config/ConfigProvider.h

This file was deleted.

6 changes: 6 additions & 0 deletions apps/client/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"server": {
"host": "SERVER_HOST",
"port": "SERVER_PORT"
}
}
6 changes: 6 additions & 0 deletions apps/client/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"server": {
"host": "127.0.0.1",
"port": 3000
}
}
18 changes: 18 additions & 0 deletions apps/client/core/configProvider/ConfigProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "ConfigProvider.h"

#include "envParser/EnvironmentParser.h"

namespace client::core
{
ConfigProvider::ConfigProvider() : config{std::make_unique<config::Config>()} {}

std::string ConfigProvider::getServerHost() const
{
return config->get<std::string>("server.host");
}

int ConfigProvider::getServerPort() const
{
return config->get<int>("server.port");
}
}
21 changes: 21 additions & 0 deletions apps/client/core/configProvider/ConfigProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <memory>
#include <string>

#include "config-cxx/Config.h"

namespace client::core
{
class ConfigProvider
{
public:
ConfigProvider();

std::string getServerHost() const;
int getServerPort() const;

private:
std::unique_ptr<config::Config> config;
};
}
1 change: 0 additions & 1 deletion apps/server/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "common/filesystem/GetProjectPath.h"
#include "fmt/format.h"
#include "laserpants/dotenv/dotenv.h"
#include "loguru.hpp"
#include "server/core/configProvider/ConfigProvider.h"
#include "server/core/database/DatabaseConnectionFactory.h"
Expand Down
1 change: 0 additions & 1 deletion externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(LOGURU_WITH_STREAMS 1)
set(LOGURU_THREADNAME_WIDTH 11)
set(LOGURU_FILENAME_WIDTH 30)
add_subdirectory(loguru)
add_subdirectory(dotenv-cpp)
set(BUILD_FAKER_TESTS OFF)
add_subdirectory(faker-cxx)
add_subdirectory(cpr)
Expand Down
1 change: 0 additions & 1 deletion externals/dotenv-cpp
Submodule dotenv-cpp deleted from f493f4

0 comments on commit cdaf78b

Please sign in to comment.