Commit dd5d0702 authored by yannick legoc's avatar yannick legoc
Browse files

Merge branch 'rapidjson' into 'master'

Rapidjson

See merge request !5
parents 636b218c a5a162c7
......@@ -25,6 +25,7 @@ git log --graph main_master cpp_master
# we have to rewrite the history in the C++ API branch and rebase w.r.t. the main
git rebase -i main_master cpp_master
git checkout master
git subtree merge -P cameo-api-cpp/ cpp_master
# you need to solve few conflicts :-)
......
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: ForIndentation
BreakBeforeBraces: Linux
#UseTab: UT_AlignWithSpaces # available in release later than 9
UseTab: ForContinuationAndIndentation
BreakBeforeBraces: Custom
BraceWrapping:
AfterNamespace: false
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 110
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AccessModifierOffset: 0
NamespaceIndentation: Inner
\ No newline at end of file
AlignConsecutiveDeclarations: false
AlignTrailingComments: true
AccessModifierOffset: -8 # It has to be equal to the tab size
NamespaceIndentation: None
PointerAlignment: Left
AlwaysBreakAfterReturnType: None
SortIncludes: false
......@@ -3,13 +3,19 @@ if(NOT DEFINED PROJECT_NAME)
# Project name and version
project(cameo VERSION 1.0.1 LANGUAGES CXX)
#cmake_policy(SET CMP0048 NEW)
endif()
message("========================================")
message("Project ${PROJECT_NAME}, major version: ${PROJECT_VERSION_MAJOR}, version ${PROJECT_VERSION}")
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FetchContent)
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS True)
option(BUILD_SHARED_LIBS "Building dynamic (ON) or static (OFF)" ON)
#set(BUILD_SHARED_LIBS True)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
......@@ -29,9 +35,22 @@ endif()
#------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(ZeroMQ REQUIRED)
find_package(Rapidjson REQUIRED)
find_package(Rapidjson QUIET)
if(NOT Rapidjson_FOUND)
message(WARNING "Using Rapidjson from GIT repository")
FetchContent_Declare(rapidjson
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG v1.1.0
GIT_SHALLOW True
#INSTALL_COMMAND "make install"
)
FetchContent_GetProperties(rapidjson)
FetchContent_Populate(rapidjson)
set(Rapidjson_ROOT ${rapidjson_SOURCE_DIR})
find_package(Rapidjson REQUIRED)
endif()
message(${Rapidjson_INCLUDE_DIRS})
#------------------------------------------------------------
# Libraries
#------------------------------------------------------------
......@@ -39,9 +58,6 @@ find_package(Rapidjson REQUIRED)
#---------------
# Files
file(GLOB_RECURSE CAMEO_SOURCE_FILES "src/*.cpp")
#file(GLOB CAMEO_PUBLIC_HEADER_FILES "./*.h")
#message(${CAMEO_PUBLIC_HEADER_FILES})
#message(${CAMEO_SOURCE_FILES})
add_library(cameo ${CAMEO_SOURCE_FILES})
target_link_libraries(cameo PRIVATE zmq)
......@@ -50,14 +66,17 @@ target_include_directories(cameo
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(cameo
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
#target_include_directories(cameo PRIVATE ${DOCTEST_INCLUDE_DIR})
#target_compile_features(cameo PUBLIC cxx_std_11)
set_target_properties(cameo PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
message(${PROJECT_VERSION_MAJOR})
message(${PROJECT_VERSION})
#---------------
# Library version
write_basic_package_version_file(cameoConfigVersion.cmake
......@@ -119,6 +138,24 @@ export(TARGETS cameo FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake)
#enable_testing()
#add_subdirectory(test)
# include(ExternalProject)
# find_package(Git REQUIRED)
# ExternalProject_Add(
# doctest
# PREFIX ${CMAKE_BINARY_DIR}/doctest
# GIT_REPOSITORY https://github.com/onqtam/doctest.git
# TIMEOUT 10
# UPDATE_COMMAND ${GIT_EXECUTABLE} pull
# CONFIGURE_COMMAND ""
# BUILD_COMMAND ""
# INSTALL_COMMAND ""
# LOG_DOWNLOAD ON
# )
# # Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope
# ExternalProject_Get_Property(doctest source_dir)
# set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")
#include(CMakeFindDependencyMacro)
#find_dependency(
......@@ -135,7 +172,7 @@ if (DOXYGEN_FOUND)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( doc
add_custom_target( cameo_doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
......
......@@ -346,13 +346,13 @@ LOOKUP_CACHE_SIZE = 0
# normally produced when WARNINGS is set to YES.
# The default value is: NO.
EXTRACT_ALL = NO
EXTRACT_ALL = YES
# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
# The default value is: NO.
EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES
# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
# scope will be included in the documentation.
......@@ -1795,7 +1795,7 @@ DIA_PATH =
# and usage relations if the target is undocumented or is not a class.
# The default value is: YES.
HIDE_UNDOC_RELATIONS = YES
HIDE_UNDOC_RELATIONS = NO
# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
# available from the path. This tool is part of Graphviz (see:
......@@ -1870,7 +1870,7 @@ GROUP_GRAPHS = YES
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
UML_LOOK = NO
UML_LOOK = YES
# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
# class node. If there are many fields or methods and many nodes the graph may
......@@ -1978,7 +1978,7 @@ DOT_IMAGE_FORMAT = png
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
INTERACTIVE_SVG = NO
INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
......
......@@ -42,4 +42,14 @@ In file included from /opt/panosc/cameo/src/impl/SocketWaitingImpl.h:23,
/usr/include/zmq.hpp:1267:10: note: declared here
bool recv(message_t *msg_, int flags_ = 0)
^~~~
## Development
How to find the list of public headers and check that they are all in the include/ directory
1. move all the headers in src/
2. move cameo.h to include/
3. run the following command multiple times until there is no output
```
#!/bin/fish
set -l ORIG_DIR src
for f in (for file in include/*; grep include $file | grep '"'; end | sort | uniq | sed 's|.* "||;s|"||'); if [ -e $ORIG_DIR/$f ] ; echo $f; git mv $ORIG_DIR/$f include/; end; end
```
......@@ -40,8 +40,8 @@
namespace cameo {
enum Option {
NONE = 0,
OUTPUTSTREAM = 1
NONE = 0,
OUTPUTSTREAM = 1
};
class Server;
......@@ -72,18 +72,23 @@ typedef int32_t State;
#undef ERROR
const State UNKNOWN = 0;
const State STARTING = 1;
const State RUNNING = 2;
const State STOPPING = 4;
const State KILLING = 8;
const State UNKNOWN = 0;
const State STARTING = 1;
const State RUNNING = 2;
const State STOPPING = 4;
const State KILLING = 8;
const State PROCESSING_ERROR = 16;
const State FAILURE = 32;
const State SUCCESS = 64;
const State STOPPED = 128;
const State KILLED = 256;
const State FAILURE = 32;
const State SUCCESS = 64;
const State STOPPED = 128;
const State KILLED = 256;
/** \class This
* \brief class managing the current CAMEO application.
*
* \details The application has to be launched by CAMEO command line or another CAMEO app
* \todo why this does not inherit from the Instance class?
*/
class This : private Services, private EventListener {
friend class cameo::application::Publisher;
......@@ -98,7 +103,7 @@ class This : private Services, private EventListener {
friend class cameo::Server;
friend std::ostream& operator<<(std::ostream&, const cameo::application::This&);
typedef std::function<void ()> StopFunctionType;
typedef std::function<void()> StopFunctionType;
public:
/**
......@@ -118,28 +123,30 @@ public:
void releasePort(int port) const;
private:
Com(Server * server, int applicationId);
Com(Server* server, int applicationId);
Server * m_server;
Server* m_server;
int m_applicationId;
};
This();
~This();
static void init(int argc, char *argv[]);
static void init(int argc, char* argv[]);
static void init(const std::string& name, const std::string& endpoint);
/**
* The terminate call is not necessary unless the static instance of This is not destroyed automatically.
* The terminate call is not necessary unless the static instance of This is not destroyed
* automatically.
*/
static void terminate();
static const std::string& getName();
static int getId();
/// \brief returns the name of the CAMEO application corresponding to this instance
static const std::string& getName();
static int getId(); ///< returns the ID number of the instance
static void setTimeout(int timeout);
static int getTimeout();
static const Endpoint& getEndpoint();
static const Endpoint& getEndpoint(); ///< returns the TCP address of this instance
static Server& getServer();
static const Com& getCom();
......@@ -151,16 +158,17 @@ public:
static bool isStopping();
/**
* Sets the stop handler with stopping time that overrides the one that may be defined in the configuration of the server.
* Sets the stop handler with stopping time that overrides the one that may be defined in the
* configuration of the server.
*/
template<typename Type>
template <typename Type>
static void handleStop(Type function, int stoppingTime = -1) {
m_instance.handleStopImpl(function, stoppingTime);
}
static void cancelWaitings();
static bool setRunning();
static bool setRunning(); ///< sets the current instance in RUNNING state
/**
* Sets the result.
......@@ -174,7 +182,7 @@ public:
static std::unique_ptr<Instance> connectToStarter();
private:
void initApplication(int argc, char *argv[]);
void initApplication(int argc, char* argv[]);
void initApplication(const std::string& name, const std::string& endpoint);
static State parseState(const std::string& value);
......@@ -217,7 +225,7 @@ class Instance : private EventListener {
friend std::ostream& operator<<(std::ostream&, const Instance&);
public:
typedef std::function<void (State)> StateHandlerType;
typedef std::function<void(State)> StateHandlerType;
class Com {
......@@ -227,9 +235,9 @@ public:
std::string getKeyValue(const std::string& key) const;
private:
Com(Server * server);
Com(Server* server);
Server * m_server;
Server* m_server;
int m_applicationId;
};
......@@ -252,7 +260,7 @@ public:
State waitFor(const std::string& eventName);
State waitFor(KeyValue& keyValue);
void cancelWaitFor();
void cancelWaitFor(); // to unblock another instance
/**
* Deprecated.
......@@ -286,7 +294,7 @@ public:
std::shared_ptr<OutputStreamSocket> getOutputStreamSocket();
private:
Instance(Server * server);
Instance(Server* server);
void setId(int id);
void setErrorMessage(const std::string& message);
......@@ -295,7 +303,7 @@ private:
void setInitialState(State state);
State waitFor(int states, const std::string& eventName, KeyValue& keyValue, StateHandlerType handler, bool blocking);
Server * m_server;
Server* m_server;
std::shared_ptr<OutputStreamSocket> m_outputStreamSocket;
int m_id;
std::string m_errorMessage;
......@@ -374,7 +382,8 @@ public:
bool isEnded() const;
private:
Publisher(application::This * application, int publisherPort, int synchronizerPort, const std::string& name, int numberOfSubscribers);
Publisher(application::This* application, int publisherPort, int synchronizerPort,
const std::string& name, int numberOfSubscribers);
std::unique_ptr<PublisherImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -392,7 +401,7 @@ class Subscriber {
public:
~Subscriber();
static std::unique_ptr<Subscriber> create(Instance & instance, const std::string& publisherName);
static std::unique_ptr<Subscriber> create(Instance& instance, const std::string& publisherName);
const std::string& getPublisherName() const;
const std::string& getInstanceName() const;
......@@ -418,7 +427,9 @@ public:
void cancel();
private:
Subscriber(Server * server, int publisherPort, int synchronizerPort, const std::string& publisherName, int numberOfSubscribers, const std::string& instanceName, int instanceId, const std::string& instanceEndpoint, const std::string& statusEndpoint);
Subscriber(Server* server, int publisherPort, int synchronizerPort, const std::string& publisherName,
int numberOfSubscribers, const std::string& instanceName, int instanceId,
const std::string& instanceEndpoint, const std::string& statusEndpoint);
void init();
std::unique_ptr<SubscriberImpl> m_impl;
......@@ -456,7 +467,7 @@ public:
std::unique_ptr<Server> getServer();
private:
Request(std::unique_ptr<RequestImpl> & impl);
Request(std::unique_ptr<RequestImpl>& impl);
std::unique_ptr<RequestImpl> m_impl;
std::unique_ptr<Server> m_requesterServer;
......@@ -472,21 +483,26 @@ class Responder {
public:
~Responder();
/**
* Returns the responder with name.
/** \brief Returns the responder with name.
* throws ResponderCreationException.
*/
static std::unique_ptr<Responder> create(const std::string& name);
/// Returns the name of the responder
const std::string& getName() const;
void cancel();
/** \brief Receive a request
* blocking command
*/
std::unique_ptr<Request> receive();
/** check if it has been canceled */
bool isCanceled() const;
private:
Responder(application::This * application, int responderPort, const std::string& name);
Responder(application::This* application, int responderPort, const std::string& name);
std::unique_ptr<ResponderImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -497,7 +513,7 @@ private:
class Requester {
friend std::ostream& operator<<(std::ostream&, const Requester&);
friend std::ostream& operator<<(std::ostream&, const Requester&);
public:
~Requester();
......@@ -506,7 +522,7 @@ public:
* Returns the responder with name.
* throws RequesterCreationException.
*/
static std::unique_ptr<Requester> create(Instance & instance, const std::string& name);
static std::unique_ptr<Requester> create(Instance& instance, const std::string& name);
const std::string& getName() const;
......@@ -522,7 +538,8 @@ public:
bool isCanceled() const;
private:
Requester(application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId);
Requester(application::This* application, const std::string& url, int requesterPort,
int responderPort, const std::string& name, int responderId, int requesterId);
std::unique_ptr<RequesterImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -536,7 +553,8 @@ class Configuration {
friend std::ostream& operator<<(std::ostream&, const Configuration&);
public:
Configuration(const std::string& name, const std::string& description, bool singleInfo, bool restart, int startingTime, int stoppingTime);
Configuration(const std::string& name, const std::string& description, bool singleInfo, bool restart,
int startingTime, int stoppingTime);
const std::string& getName() const;
const std::string& getDescription() const;
......@@ -562,7 +580,8 @@ class Info {
friend std::ostream& operator<<(std::ostream&, const Info&);
public:
Info(const std::string& name, int id, int pid, State applicationState, State pastApplicationStates, const std::string& args);
Info(const std::string& name, int id, int pid, State applicationState, State pastApplicationStates,
const std::string& args);
int getId() const;
State getState() const;
......@@ -613,8 +632,7 @@ std::ostream& operator<<(std::ostream&, const cameo::application::Configuration&
std::ostream& operator<<(std::ostream&, const cameo::application::Info&);
std::ostream& operator<<(std::ostream&, const cameo::application::Port&);
}
}
} // namespace application
} // namespace cameo
#endif
......@@ -2,26 +2,40 @@ set(CMAKE_CXX_STANDARD 17)
add_executable(testendpoint TestEndpoint.cpp)
target_link_libraries(testendpoint PUBLIC
target_link_libraries(testendpoint PRIVATE
cameo
)
target_include_directories(testendpoint
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/
)
add_test(endpoint testendpoint)
add_executable(testapplicationidentity TestApplicationIdentity.cpp)
target_link_libraries(testapplicationidentity
PRIVATE cameo
)
target_include_directories(testapplicationidentity
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/
)
target_include_directories(testapplicationidentity
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
target_link_libraries(testapplicationidentity PUBLIC
cameo
)
add_test(applicationidentity testapplicationidentity)
add_executable(testapplicationwithstarteridentity TestApplicationWithStarterIdentity.cpp)
target_link_libraries(testapplicationwithstarteridentity PUBLIC
target_link_libraries(testapplicationwithstarteridentity PRIVATE
cameo
)
target_include_directories(testapplicationwithstarteridentity
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/
)
target_include_directories(testapplicationwithstarteridentity
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
add_test(applicationwithstarteridentity testapplicationwithstarteridentity)
#include "Test.h"
#include "../include/Strings.h"
#include "../include/JSON.h"
#include "../src/message/Message.h"
#include "Strings.h"
#include "JSON.h"
#include "message/Message.h"
#include <iostream>
using namespace std;
......
#include "Test.h"
#include "../include/Strings.h"
#include "../include/JSON.h"
#include "../src/message/Message.h"
#include "Strings.h"
#include "JSON.h"
#include "message/Message.h"
#include <iostream>
using namespace std;
......
#include "Test.h"
#include "../include/Strings.h"
#include "Strings.h"
#include <iostream>
using namespace std;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment