Skip to content
Snippets Groups Projects
Commit d2f6367e authored by Christoph Kampmeyer's avatar Christoph Kampmeyer
Browse files

Template server example:

  - Added ApplicationModule, test and config
  - Extended CMakeLists.txt accordingly
  - TODO: .dmap-, .map-files
parent 1b3e7abf
No related branches found
No related tags found
No related merge requests found
# CMakeLists.txt template for an ApplicationCore-based server
# *installed* application core library. It is not included from the main CMakeLists.txt
# which is used to build ApplicationCore itself.
#
#
PROJECT(ChimeraTK-ApplicationCore-TemplateServer)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
#SET(PROJECT_NAME demo_${PROJECT_BASE_NAME})
# Use the project template to get the settings required for an application core project
set(${PROJECT_NAME}_MAJOR_VERSION 01)
set(${PROJECT_NAME}_MINOR_VERSION 00)
......@@ -20,8 +18,7 @@ include(cmake/set_default_flags.cmake)
# Add the dependencies. We need ApplicationCore and a control system adapter implementation.
add_dependency(ChimeraTK-ApplicationCore 01.08 REQUIRED)
#FIXME: Make the adapter configurable via command line parameter
#add_dependency(ChimeraTK-ControlSystemAdapter-DoocsAdapter 00.10 REQUIRED)
# Select control system adapter
IF(ADAPTER STREQUAL "OPCUA")
message("Building against the OPC UA ControlSystemAdater")
add_dependency(ChimeraTK-ControlSystemAdapter-OPCUAAdapter REQUIRED)
......@@ -45,34 +42,54 @@ ELSE()
ENDIF()
# Define compiler and link flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ChimeraTK-ApplicationCore_CXX_FLAGS}")
set(CMAKE_LINK_FLAGS "-Wl,--no-as-needed ${Adapter_LINK_FLAGS} ${ChimeraTK-ApplicationCore_LINK_FLAGS}")
# configure version.h
configure_file(include/version.h.in ${PROJECT_BINARY_DIR}/version/version.h)
configure_file(server/include/version.h.in ${PROJECT_BINARY_DIR}/version/version.h)
include_directories(${PROJECT_BINARY_DIR}/version)
# Module and Server include directories
include_directories(${CMAKE_SOURCE_DIR}/modules/include ${CMAKE_SOURCE_DIR}/server/include)
include_directories(${CMAKE_SOURCE_DIR}/include)
AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src server_sources)
# Process server modules
add_subdirectory(${CMAKE_SOURCE_DIR}/modules)
# The server proper. It depends on application core and the control system adapter implementation.
add_executable(${PROJECT_NAME} ${server_sources})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS} ${Adapter_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME} ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
set(SERVER_SRC ${CMAKE_SOURCE_DIR}/server/src/Server.cc)
# The server executable. It depends on application core and the control system adapter implementation.
add_executable(${PROJECT_NAME} ${SERVER_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
# We compile the same sources with the GENERATE_XML flag to get an xml generator.
# This one does not depent on a control system adapter implementation.
add_executable(${PROJECT_NAME}-xmlGenerator ${server_sources})
add_executable(${PROJECT_NAME}-xmlGenerator ${SERVER_SRC})
set_target_properties( ${PROJECT_NAME}-xmlGenerator PROPERTIES COMPILE_FLAGS "-DGENERATE_XML")
set_target_properties(${PROJECT_NAME}-xmlGenerator PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME}-xmlGenerator ${ChimeraTK-ApplicationCore_LIBRARIES})
target_link_libraries(${PROJECT_NAME}-xmlGenerator ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES})
# copy the (test) config files to the build directory for tests
FILE( COPY config/ DESTINATION ${PROJECT_BINARY_DIR})
# Tests:
# There are no dedicated tests for this demo. But we run the xml generator to
# check that the variable household can successfully be initialised.
# The test will fail if the xml generator crashes, just a smoke test.
# Process tests:
ENABLE_TESTING()
add_test(${PROJECT_NAME}-xmlGenerator ${PROJECT_NAME}-xmlGenerator)
add_subdirectory(${CMAKE_SOURCE_DIR}/tests)
## copy the (test) config files to the build directory for tests
#FILE( COPY config/ DESTINATION ${PROJECT_BINARY_DIR})
## Add all tests residing in the "tests" directory
#aux_source_directory(${CMAKE_SOURCE_DIR}/tests testExecutables)
#foreach( testExecutableSrcFile ${testExecutables})
# #NAME_WE means the base name without path and (longest) extension
# get_filename_component(excutableName ${testExecutableSrcFile} NAME_WE)
# add_executable(${excutableName} ${testExecutableSrcFile})
# set_target_properties(${excutableName} PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS}")
# target_link_libraries(${PROJECT_NAME} ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
# add_test(${excutableName} ${excutableName})
#endforeach( testExecutableSrcFile )
# Installation:
# FIXME: For doocs we need a special treatment when installing to /export/doocs/server (don't install to bin subdirectory, but a directory named like the server). This should go to the project template.
......
<configuration>
<variable name="var1" type="int32" value="42"/>
<module name="Module1">
<variable name="var1" type="int32" value="3"/>
<variable name="var2" type="int32" value="7"/>
</module>
</configuration>
# CMakeLists.txt for server modules
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
include_directories(include)
aux_source_directory(src library_sources)
message("In subdir: ** ${PROJECT_NAME}")
# Build the modules into a shared library so they are only
# instanciated once, if multiple server instances are run
add_library(${PROJECT_NAME}lib SHARED ${library_sources})
set_target_properties(${PROJECT_NAME}lib PROPERTIES VERSION ${${PROJECT_NAME}_FULL_LIBRARY_VERSION}
SOVERSION ${${PROJECT_NAME}_SOVERSION})
target_link_libraries(${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${ADAPTER_LIBRARIES})
#ifndef TEMPLATEMODULE_H
#define TEMPLATEMODULE_H
#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
namespace ctk = ChimeraTK;
struct TemplateModule : public ctk::ApplicationModule {
using ctk::ApplicationModule::ApplicationModule;
~TemplateModule(){}
void mainLoop() override;
};
#endif // TEMPLATEMODULE_H
#include "TemplateModule.h"
void TemplateModule::mainLoop(){
std::cout << " Processing TemplateModule::mainLoop()" << std::endl;
}
/*
* piezoctrlserver.h
*
* Created on: Mar 12, 2018
* Author: Christoph Kampmeyer
*/
#ifndef INCLUDE_SERVER_H_
#define INCLUDE_SERVER_H_
#ifndef SERVER_H_
#define SERVER_H_
#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
#include <ChimeraTK/ApplicationCore/ConfigReader.h>
// TODO Note to optionally use to trigger
//#include <ChimeraTK/ApplicationCore/PeriodicTrigger.h>
#include "TemplateModule.h"
namespace ctk = ChimeraTK;
/**
* Server - An ApplicationCore template server
*
* The Application object for this server. It provides
* dummy Device- and ApplicationModules and a ConfigReader.
*
* All modules are simply connected to the ControlSystem.
* No triggering is implemented, as this is specific to the application
* (either provided by a Device or a ChimeraTK::PeriodicTrigger).
*/
struct Server : public ctk::Application {
Server() : Application("ApplicationCore-TemplateServer") {}
Server() : ctk::Application("ApplicationCore_TemplateServer") {}
~Server() override { shutdown(); }
//ctk::PeriodicTrigger timer{this, "Timer", "Periodic timer for device readout", 1000};
ctk::ConfigReader config{this, "Configuration", getName() + "_base_config.xml"};
ctk::ControlSystemModule cs;
ctk::DeviceModule dev{this, "Device"};
// ctk::DeviceModule externalTrigger{this, "ExtTrigger"};
TemplateModule templateModule{this, "TemplateModule", "This is a template module, adapt as needed!"};
void defineConnections() override;
};
#endif /* INCLUDE_SERVER_H_ */
#endif /* SERVER_H_ */
#include <iostream>
#include "Server.h"
#include "version.h"
#include <ChimeraTK/ApplicationCore/EnableXMLGenerator.h>
static Server piezoCtrlServer;
/// The Server instance
static Server theServer;
void Server::defineConnections() {
ctk::setDMapFilePath("devices.dmap");
......
# CMakeLists.txt for test modules
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
# Add BOOST dependencies
FIND_PACKAGE(Boost COMPONENTS thread system unit_test_framework REQUIRED)
# copy the (test) config files to the build directory for tests
FILE( COPY ${CMAKE_SOURCE_DIR}/config/ DESTINATION ${PROJECT_BINARY_DIR})
# The tests also require the server headers (TODO Potentially, module includes are also needed)
include_directories(${CMAKE_SOURCE_DIR}/server/include)
# Add all tests residing in the "tests" directory
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} testExecutables)
foreach( testExecutableSrcFile ${testExecutables})
#NAME_WE means the base name without path and (longest) extension
get_filename_component(excutableName ${testExecutableSrcFile} NAME_WE)
add_executable(${excutableName} ${testExecutableSrcFile})
# TODO Get Server.cc as variable from top-level CMakeLists.txt
target_sources(${excutableName} PRIVATE ${CMAKE_SOURCE_DIR}/server/src/Server.cc)
set_target_properties(${excutableName}
PROPERTIES
LINK_FLAGS "${CMAKE_LINK_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
target_link_libraries(${excutableName} ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
add_test(${excutableName} ${excutableName})
endforeach( testExecutableSrcFile )
// Define a name for the test module.
#define BOOST_TEST_MODULE testTemplateServer
// Only after defining the name include the unit test header.
#include <boost/test/included/unit_test.hpp>
#include <ChimeraTK/ApplicationCore/TestFacility.h>
#include "Server.h"
// Declare the server instance
static Server theServer;
static ChimeraTK::TestFacility testFacility;
struct TestFixture {
TestFixture(){
testFacility.runApplication();
}
};
static TestFixture fixture;
using namespace boost::unit_test_framework;
/// TestSuite for the server, adapt name
BOOST_AUTO_TEST_SUITE(TemplateServerTestSuite)
/**********************************************************************************************************************/
/// A template test case
BOOST_AUTO_TEST_CASE(testTemplate){
std::cout << "testTemplate" << std::endl;
}
/**********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE_END()
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