Skip to content
Snippets Groups Projects
Commit 5bc68558 authored by Carsten Patzke's avatar Carsten Patzke
Browse files

Create initial sub-project structure

Added project strucre; some tests & first producer

changed folder structure

Made test build optional

Changed project structure for producer

added doxygen

added doxygen to cmake

fixed doxygen file

made googletest separated

changed cmake strucure

Added head lock guard
parent 2798bc7c
No related branches found
No related tags found
No related merge requests found
Showing
with 2880 additions and 0 deletions
#Astyle
.orig
# Created by https://www.gitignore.io/api/c++,cmake,clion+all
### C++ ###
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### CLion+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Ruby plugin and RubyMine
/.rakeTasks
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### CLion+all Patch ###
# Ignores the whole idea folder
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
### CMake ###
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
build
# End of https://www.gitignore.io/api/c++,cmake,clion+all
### Doxygen ###
doxygen
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
project(HIDRA2)
option(BUILD_TESTS "Uses googletest to build tests" OFF)
option(BUILD_DOCS "Uses doxygen to build the documentaion" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/)
include(astyle)
include(gtest)
add_subdirectory(producer/api)
add_subdirectory(common/cpp)
add_subdirectory(producer/inotify-event-detector-cpp)
if(BUILD_DOCS)
include(doxygen)
endif()
function(astyle target source_files)
find_program(ASTYLE_EXECUTABLE astyle)
if(ASTYLE_EXECUTABLE)
message("Found astyle, using astyle to format code of target ${target}.")
add_custom_command(
TARGET ${target} PRE_BUILD
COMMAND
${ASTYLE_EXECUTABLE} -n --style=1tbs --indent-namespaces --indent-preproc-block ${source_files}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} VERBATIM
)
else()
message("Unable to find astyle. Skipping code formatting for ${target}")
endif()
endfunction()
find_program(DOXYGEN_EXECUTABLE doxygen)
if(DOXYGEN_EXECUTABLE)
message("Found doxygen. Using doxygen to build documentaion.")
add_custom_target(
documentation
COMMAND
${DOXYGEN_EXECUTABLE} doxygen.ini VERBATIM
WORKING_DIRECTORY ..
)
else()
message("Unable to find doxygen. Skipping code documentaion.")
endif()
if(BUILD_TESTS)
enable_testing()
endif()
function(gtest target test_source_files test_libraries)
if(BUILD_TESTS)
find_package (Threads)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_executable(test-${target} ${test_source_files})
target_link_libraries(test-${target} gtest gtest_main ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(test-${target} ${test_libraries})
add_test(NAME test-${target} COMMAND test-${target})
astyle(test-${target} ${test_source_files})
message("Added test 'test-${target}'")
else()
message("Skip test 'test-${target}'")
endif()
endfunction()
# HIDRA2
# C++ Projects
- /common/cpp
**Library:** Common library which get shared between the producer and receiver
- /producer/producer-api
**Library:** Producer library which can send data to the receiver
- /receiver
**Executable:** The receiver which can receive data from the producer
- /producer/inotify-event-detector-cpp
**Executable:** Implementation of the producer api with inotify
# Building
## With documentation
Need Doxygen >= [1.8.10](https://github.com/doxygen/doxygen/releases/tag/Release_1_8_11)
- mkdir build
- cd build
- cmake -DBUILD_DOCS=ON ..
## With tests
Need googletest >= [1.8.0](https://github.com/google/googletest/releases/tag/release-1.8.0)
- mkdir build
- cd build
- cmake -DBUILD_TESTS=ON ..
set(TARGET_NAME common)
set(SOURCE_FILES include/common/os.h include/common/networking.h)
################################
# Library
################################
add_library(${TARGET_NAME} SHARED ${SOURCE_FILES})
target_include_directories(${TARGET_NAME} PUBLIC include)
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
astyle(${TARGET_NAME} ${SOURCE_FILES})
################################
# Testing
################################
set(TEST_SOURCE_FILES unittests/test_common.cpp)
set(TEST_LIBRARIES common)
gtest(${TARGET_NAME} ${TEST_SOURCE_FILES} ${TEST_LIBRARIES})
# cpp-common
This is the common library folder.
Here are all files which are shared between all c++ projects
#ifndef HIDRA2__COMMON_NETWORKING_H
#define HIDRA2__COMMON_NETWORKING_H
#include <cstdint>
#include "os.h"
namespace HIDRA2
{
enum OP_CODE : uint8_t {
OP_CODE__HELLO,
};
enum ERROR_CODE : uint16_t {
ERR__NO_ERROR,
ERR__UNSUPPORTED_VERSION,
ERR__INTERNAL_SERVER_ERROR = 65535,
};
struct NetworkRequest {
OP_CODE op_code;
uint64_t request_id;
char data[];
};
struct NetworkResponse {
OP_CODE op_code;
uint64_t request_id;
ERROR_CODE error_code;
char data[];
};
struct OP_HelloRequest {
uint32_t client_version;
OS_TYPE os : 4;
bool is_x64 : 1;
};
struct OP_HelloResponse {
uint32_t server_version;
};
}
#endif //HIDRA2__COMMON_NETWORKING_H
#ifndef HIDRA2__COMMON_OS_H
#define HIDRA2__COMMON_OS_H
#include <cstdint>
namespace HIDRA2
{
enum OS_TYPE : uint8_t {
OS_UNKOWN,
OS_LINUX,
OS_WINDOWS,
OS_INVALID = 16, /* Never use more then 4 bit */
};
}
#endif //HIDRA2__COMMON_OS_H
#include <gtest/gtest.h>
TEST(EMPTY, REMOVEME)
{
EXPECT_EQ(1, 1);
}
doxygen.ini 0 → 100644
This diff is collapsed.
set(TARGET_NAME producer-api)
set(SOURCE_FILES src/producer/producer.cpp include/producer/producer.h)
################################
# Library
################################
add_library(${TARGET_NAME} SHARED ${SOURCE_FILES})
target_include_directories(${TARGET_NAME} PUBLIC include)
target_link_libraries(${TARGET_NAME} common)
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
astyle(${TARGET_NAME} ${SOURCE_FILES})
################################
# Testing
################################
set(TEST_SOURCE_FILES unittests/test_producer.cpp)
set(TEST_LIBRARIES producer-api)
gtest(${TARGET_NAME} ${TEST_SOURCE_FILES} ${TEST_LIBRARIES})
# cpp-producer
This is the producer implementation in c++
## Building this project
### Requirements
#### System
- Linux Kernel >= 4
#### Build Dependencies
- cmake4
##### Optional
- astyle
- doxygen
### How to build
- TODO
#ifndef HIDRA2__PRODUCER_PRODUCER_H
#define HIDRA2__PRODUCER_PRODUCER_H
#include <string>
namespace HIDRA2
{
class Producer
{
private:
static unsigned long kinit_count_;
Producer();
public:
static const uint32_t VERSION;
Producer(const Producer&) = delete;
Producer& operator=(const Producer&) = delete;
static Producer* CreateProducer(std::string receiver_address);
};
}
#endif //HIDRA2__PRODUCER_PRODUCER_H
#include <producer/producer.h>
unsigned long HIDRA2::Producer::kinit_count_ = 0;
const uint32_t HIDRA2::Producer::VERSION = 1;
HIDRA2::Producer::Producer()
{
kinit_count_++;
}
HIDRA2::Producer *HIDRA2::Producer::CreateProducer(std::string receiver_address)
{
return new Producer();
}
#include <gtest/gtest.h>
#include <producer/producer.h>
namespace
{
TEST(VERSION, VersionAboveZero)
{
EXPECT_GE(HIDRA2::Producer::VERSION, 0);
}
TEST(CreateProducer, PointerIsNotNullptr)
{
HIDRA2::Producer* prod = HIDRA2::Producer::CreateProducer("127.0.0.1");
EXPECT_NE(prod, nullptr);
}
}
set(TARGET_NAME inotify-event-detector-cpp)
set(SOURCE_FILES src/main.cpp)
################################
# Executable and link
################################
add_executable(${TARGET_NAME} ${SOURCE_FILES})
target_include_directories(${TARGET_NAME} PRIVATE include)
target_link_libraries(${TARGET_NAME} common producer-api)
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
astyle(${TARGET_NAME} ${SOURCE_FILES})
################################
# Testing
################################
set(TEST_SOURCE_FILES unittests/test_inotify_client.cpp)
gtest(${TARGET_NAME} ${TEST_SOURCE_FILES} "")
#include <producer/producer.h>
#include <iostream>
int main (int argc, char* argv[])
{
std::cout << "Running producer version: " << HIDRA2::Producer::VERSION << std::endl;
HIDRA2::Producer* producer = HIDRA2::Producer::CreateProducer("127.0.0.1");
if(!producer) {
std::cerr << "Fail to create producer" << std::endl;
return 1;
}
std::cout << "Successfully create producer " << std::hex << producer << std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment