Project reorganization
This commit is contained in:
parent
d6f95d89fa
commit
a1ec9f731d
@ -4,9 +4,81 @@ project(jay
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
# Build type options
|
||||
option(JAY_ENABLE_ASAN "Enable Address Sanitizer" OFF)
|
||||
option(JAY_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
|
||||
option(JAY_ENABLE_TSAN "Enable Thread Sanitizer" OFF)
|
||||
option(JAY_ENABLE_STRICT "Enable strict compiler warnings" OFF)
|
||||
option(JAY_ENABLE_LTO "Enable Link Time Optimization" OFF)
|
||||
|
||||
# Set default build type if not specified
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (Debug/Release)" FORCE)
|
||||
endif()
|
||||
|
||||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
)
|
||||
|
||||
if(JAY_ENABLE_STRICT)
|
||||
add_compile_options(
|
||||
-Werror
|
||||
-Wconversion
|
||||
-Wnon-virtual-dtor
|
||||
-Wold-style-cast
|
||||
-Wcast-align
|
||||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wsign-conversion
|
||||
-Wnull-dereference
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_compile_options(-O0 -g3 -ggdb)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
add_compile_options(-O3 -DNDEBUG)
|
||||
endif()
|
||||
|
||||
if(JAY_ENABLE_ASAN)
|
||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||
add_link_options(-fsanitize=address)
|
||||
endif()
|
||||
|
||||
if(JAY_ENABLE_UBSAN)
|
||||
add_compile_options(-fsanitize=undefined)
|
||||
add_link_options(-fsanitize=undefined)
|
||||
endif()
|
||||
|
||||
if(JAY_ENABLE_TSAN)
|
||||
add_compile_options(-fsanitize=thread)
|
||||
add_link_options(-fsanitize=thread)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Link Time Optimization
|
||||
if(JAY_ENABLE_LTO)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT supported OUTPUT error)
|
||||
if(supported)
|
||||
message(STATUS "IPO / LTO enabled")
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(STATUS "IPO / LTO not supported: <${error}>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
cmake_policy(SET CMP0076 NEW)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
@ -18,20 +90,4 @@ pkg_check_modules(UUID REQUIRED uuid)
|
||||
|
||||
set(EXEC_NAME "jay")
|
||||
|
||||
add_executable(${EXEC_NAME} main.cpp jay.cpp)
|
||||
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(connection)
|
||||
add_subdirectory(module)
|
||||
add_subdirectory(shared)
|
||||
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${GLOOX_INCLUDE_DIRS})
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${UUID_INCLUDE_DIRS})
|
||||
target_link_libraries(${EXEC_NAME} PRIVATE
|
||||
${GLOOX_LIBRARIES}
|
||||
yaml-cpp
|
||||
${UUID_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS ${EXEC_NAME} RUNTIME DESTINATION bin)
|
||||
add_subdirectory(src)
|
@ -1,17 +0,0 @@
|
||||
set(SOURCES
|
||||
config.cpp
|
||||
actor.cpp
|
||||
router.cpp
|
||||
core.cpp
|
||||
loop.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
config.h
|
||||
actor.h
|
||||
router.h
|
||||
core.h
|
||||
loop.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
@ -1,13 +0,0 @@
|
||||
set(SOURCES
|
||||
module.cpp
|
||||
actor.cpp
|
||||
publish.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
module.h
|
||||
actor.h
|
||||
publish.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
@ -1,15 +0,0 @@
|
||||
set(SOURCES
|
||||
logger.cpp
|
||||
loggable.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
logger.h
|
||||
loggable.h
|
||||
definitions.h
|
||||
result.h
|
||||
utils.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
28
src/CMakeLists.txt
Normal file
28
src/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
jay.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
jay.h
|
||||
)
|
||||
|
||||
add_executable(${EXEC_NAME} main.cpp jay.cpp)
|
||||
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(connection)
|
||||
add_subdirectory(module)
|
||||
add_subdirectory(shared)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
||||
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${GLOOX_INCLUDE_DIRS})
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(${EXEC_NAME} PRIVATE ${UUID_INCLUDE_DIRS})
|
||||
target_link_libraries(${EXEC_NAME} PRIVATE
|
||||
${GLOOX_LIBRARIES}
|
||||
yaml-cpp
|
||||
${UUID_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS ${EXEC_NAME} RUNTIME DESTINATION bin)
|
17
src/component/CMakeLists.txt
Normal file
17
src/component/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
set(SOURCES
|
||||
config.cpp
|
||||
actor.cpp
|
||||
router.cpp
|
||||
core.cpp
|
||||
loop.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
config.h
|
||||
actor.h
|
||||
router.h
|
||||
core.h
|
||||
loop.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "actor.h"
|
||||
|
||||
Actor::Actor(const std::string& jid, const std::string& group) :
|
||||
jid(jid),
|
||||
group(group)
|
||||
Actor::Actor(const std::string& _jid, const std::string& _group) :
|
||||
jid(_jid),
|
||||
group(_group)
|
||||
{}
|
||||
|
||||
void Actor::setGroup(const std::string& newGroup) {
|
@ -70,6 +70,6 @@ void Core::initializeActors() {
|
||||
}
|
||||
|
||||
void Core::initializeResponses() {
|
||||
for (const std::pair<Shared::Result, Shared::Strings>& pair : config.getResponses())
|
||||
for (const std::pair<const Shared::Result, Shared::Strings>& pair : config.getResponses())
|
||||
router.setResponses(pair.first, pair.second);
|
||||
}
|
@ -5,9 +5,12 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <csignal>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "shared/definitions.h"
|
||||
|
||||
Loop::Loop(const Shared::Logger& logger):
|
||||
Shared::Loggable(logger, {"Loop"}),
|
||||
@ -19,8 +22,9 @@ Loop::Loop(const Shared::Logger& logger):
|
||||
running(false)
|
||||
{
|
||||
if (pipe(wakePipe) < 0) {
|
||||
fatal(std::string("pipe: ") + strerror(errno));
|
||||
std::exit(1);
|
||||
std::string message(strerror(errno));
|
||||
fatal("could not create Loop: " + message);
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
fcntl(wakePipe[0], F_SETFL, O_NONBLOCK);
|
||||
@ -203,6 +207,9 @@ void Loop::unregisterInstance(Loop* loop) {
|
||||
}
|
||||
|
||||
void Loop::signalHandler(int signum) {
|
||||
UNUSED(signum);
|
||||
|
||||
std::lock_guard lock(instanceMutex);
|
||||
for (Loop* loop : instances)
|
||||
loop->stop();
|
||||
}
|
@ -19,7 +19,7 @@ public:
|
||||
typedef std::function<void()> Callback;
|
||||
typedef std::map<int, Callback> Handlers;
|
||||
|
||||
Loop(const Shared::Logger& logger);
|
||||
explicit Loop(const Shared::Logger& logger);
|
||||
~Loop();
|
||||
|
||||
void run();
|
||||
@ -35,7 +35,6 @@ private:
|
||||
void syncHandlers();
|
||||
|
||||
private:
|
||||
|
||||
int wakePipe[2];
|
||||
Handlers handlers;
|
||||
Handlers handlersToAdd;
|
@ -70,7 +70,7 @@ int Connection::connect() {
|
||||
}
|
||||
|
||||
void Connection::disconnect() {
|
||||
if (state != connecting || state != connected)
|
||||
if (state != connecting && state != connected)
|
||||
return;
|
||||
|
||||
gloox->disconnect();
|
||||
@ -125,6 +125,8 @@ std::string Connection::errorTypeToString(gloox::StanzaErrorType err) {
|
||||
}
|
||||
|
||||
void Connection::handleMessage(const gloox::Message& message, gloox::MessageSession* session) {
|
||||
UNUSED(session);
|
||||
|
||||
if (message.subtype() != gloox::Message::Chat)
|
||||
return;
|
||||
|
||||
@ -138,6 +140,9 @@ void Connection::handleMessage(const gloox::Message& message, gloox::MessageSess
|
||||
}
|
||||
|
||||
void Connection::handleItemPublication(const std::string& id, const gloox::JID& service, const std::string& node, const gloox::PubSub::ItemList& itemList, const gloox::Error* err) {
|
||||
UNUSED(itemList);
|
||||
UNUSED(err);
|
||||
|
||||
std::string srv(node + "@" + service.full());
|
||||
|
||||
if (err) {
|
@ -4,13 +4,11 @@
|
||||
#include "jay.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
std::string readEnv(const std::string& key, const std::string& defaultValue = "") {
|
||||
const char* val = std::getenv(key.data());
|
||||
if (val)
|
||||
return std::string(val);
|
||||
if (const char* val = std::getenv(key.data()))
|
||||
return {val};
|
||||
|
||||
return defaultValue;
|
||||
}
|
13
src/module/CMakeLists.txt
Normal file
13
src/module/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
set(SOURCES
|
||||
module.cpp
|
||||
actor.cpp
|
||||
publish.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
module.h
|
||||
actor.h
|
||||
publish.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
15
src/shared/CMakeLists.txt
Normal file
15
src/shared/CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
set(SOURCES
|
||||
logger.cpp
|
||||
loggable.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
logger.h
|
||||
loggable.h
|
||||
definitions.h
|
||||
result.h
|
||||
utils.h
|
||||
)
|
||||
|
||||
target_sources(${EXEC_NAME} PRIVATE ${SOURCES})
|
@ -7,6 +7,8 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
namespace Shared {
|
||||
typedef std::vector<std::string> Strings;
|
||||
typedef std::map<std::string, Strings> Permissions;
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "loggable.h"
|
||||
|
||||
Shared::Loggable::Loggable(const Logger& logger, const std::vector<std::string>& domain) :
|
||||
logger(logger),
|
||||
domain(domain)
|
||||
Shared::Loggable::Loggable(const Logger& _logger, const std::vector<std::string>& _domain) :
|
||||
logger(_logger),
|
||||
domain(_domain)
|
||||
{}
|
||||
|
||||
void Shared::Loggable::trace(const std::string& message) const {
|
@ -120,7 +120,7 @@ Shared::Logger::Logger(Level level):
|
||||
level(level)
|
||||
{}
|
||||
|
||||
Shared::Logger::~Logger() {}
|
||||
Shared::Logger::~Logger() = default;
|
||||
|
||||
void Shared::Logger::handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) {
|
||||
writeTimestamp();
|
@ -22,8 +22,8 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
Logger(Level level = info);
|
||||
~Logger();
|
||||
explicit Logger(Level level = info);
|
||||
~Logger() override;
|
||||
|
||||
void handleLog(gloox::LogLevel level, gloox::LogArea area, const std::string& message) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user