Skip to content

Commit

Permalink
[Communication] CLEAN the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
guparan committed Aug 3, 2020
1 parent 59142c1 commit a8de521
Show file tree
Hide file tree
Showing 34 changed files with 201 additions and 164 deletions.
152 changes: 78 additions & 74 deletions applications/plugins/Communication/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,124 +1,128 @@
Cmake_minimum_required(VERSION 3.1)
project(Communication)
Cmake_minimum_required(VERSION 3.12)
project(Communication VERSION 1.0)

option(PLUGIN_COMMUNICATION_Oscpack "Make use of the Oscpack protocol" OFF)
option(PLUGIN_COMMUNICATION_ZMQ "Make use of the ZMQ protocol" OFF)
option(PLUGIN_COMMUNICATION_VRPN "Make use of the VRPN protocol" OFF)
find_package(SofaFramework REQUIRED)

set(COMMUNICATION_MAJOR_VERSION 1)
set(COMMUNICATION_MINOR_VERSION 0)
set(COMMUNICATION_VERSION ${COMMUNICATION_MAJOR_VERSION}.${COMMUNICATION_MINOR_VERSION})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake" DESTINATION lib COMPONENT headers)

set(HEADER_FILES
config.h
components/CommunicationSubscriber.h
components/CommunicationSubscriber.inl
components/communicationCircularBuffer.h
components/communicationCircularBuffer.inl
components/serverCommunication.h
components/serverCommunication.inl

components/CommunicationCircularBuffer.h
components/CommunicationCircularBuffer.inl
components/ServerCommunication.h
components/ServerCommunication.inl
)

set(SOURCE_FILES
initCommunication.cpp
components/CommunicationSubscriber.cpp
components/communicationCircularBuffer.cpp
components/serverCommunication.cpp
components/CommunicationCircularBuffer.cpp
components/ServerCommunication.cpp
)

set(EXTRA_FILES
README.md
examples/ZMQ/primitives/Sender/senderRequest.scn
examples/ZMQ/primitives/Sender/senderPublisher.scn

examples/ZMQ/primitives/Receiver/receiverRequest.scn
examples/ZMQ/primitives/Receiver/receiverPublisher.scn

examples/ZMQ/matrix/Sender/senderRequest.scn
examples/ZMQ/matrix/Sender/senderPublisher.scn

examples/ZMQ/matrix/Receiver/receiverRequest.scn
examples/ZMQ/matrix/Receiver/receiverPublisher.scn

examples/OSC/primitives/Sender/sender.scn

examples/OSC/primitives/Receiver/receiver.scn

examples/OSC/matrix/Sender/sender.scn

examples/OSC/matrix/Receiver/receiver.scn

examples/VRPN/primitives/Sender/Sender.scn
examples/VRPN/primitives/Receiver/Receiver.scn

examples/VRPN/matrix/Sender/Sender.scn
examples/VRPN/matrix/Receiver/Receiver.scn
)

find_package(SofaFramework REQUIRED)
set(PROTOCOL_LIBS "")

#COMMUNICATION ZMQ
# ZMQ
find_package(ZMQ QUIET)
option(PLUGIN_COMMUNICATION_ZMQ "Make use of the ZMQ" ${ZMQ_FOUND})
if(PLUGIN_COMMUNICATION_ZMQ)
find_package(ZMQ REQUIRED)
sofa_find_package(ZMQ REQUIRED)
message("Found ZMQ libraries")
include_directories(${ZMQ_INCLUDE_DIRS})
list(APPEND PROTOCOL_LIBS ${ZMQ_LIBRARIES})

list(APPEND HEADER_FILES
components/serverCommunicationZMQ.h
components/serverCommunicationZMQ.inl
components/ServerCommunicationZMQ.h
components/ServerCommunicationZMQ.inl
)

list(APPEND SOURCE_FILES
components/serverCommunicationZMQ.cpp
components/ServerCommunicationZMQ.cpp
)
list(APPEND EXTRA_FILES
examples/ZMQ/primitives/Sender/senderRequest.scn
examples/ZMQ/primitives/Sender/senderPublisher.scn
examples/ZMQ/primitives/Receiver/receiverRequest.scn
examples/ZMQ/primitives/Receiver/receiverPublisher.scn
examples/ZMQ/matrix/Sender/senderRequest.scn
examples/ZMQ/matrix/Sender/senderPublisher.scn
examples/ZMQ/matrix/Receiver/receiverRequest.scn
examples/ZMQ/matrix/Receiver/receiverPublisher.scn
)
endif()

#COMMUNICATION OSC
# Oscpack
find_package(Oscpack QUIET)
option(PLUGIN_COMMUNICATION_Oscpack "Make use of the Oscpack" ${Oscpack_FOUND})
if(PLUGIN_COMMUNICATION_Oscpack)
find_package(Oscpack REQUIRED)
sofa_find_package(Oscpack REQUIRED)
message("Found Oscpack libraries")
include_directories(${Oscpack_INCLUDE_DIRS})
list(APPEND PROTOCOL_LIBS ${Oscpack_LIBRARIES})

list(APPEND HEADER_FILES
components/serverCommunicationOSC.h
components/serverCommunicationOSC.inl
components/ServerCommunicationOSC.h
components/ServerCommunicationOSC.inl
)

list(APPEND SOURCE_FILES
components/serverCommunicationOSC.cpp
components/ServerCommunicationOSC.cpp
)
list(APPEND EXTRA_FILES
examples/OSC/primitives/Sender/sender.scn
examples/OSC/primitives/Receiver/receiver.scn
examples/OSC/matrix/Sender/sender.scn
examples/OSC/matrix/Receiver/receiver.scn
)
endif()

#COMMUNICATION VRPN
# VRPN
find_package(VRPN QUIET)
option(PLUGIN_COMMUNICATION_VRPN "Make use of the VRPN" ${VRPN_FOUND})
if(PLUGIN_COMMUNICATION_VRPN)
find_package(VRPN REQUIRED)
sofa_find_package(VRPN REQUIRED)
message("Found VRPN libraries")
include_directories(${VRPN_INCLUDE_DIRS})
list(APPEND PROTOCOL_LIBS ${VRPN_LIBRARIES})

list(APPEND HEADER_FILES
components/serverCommunicationVRPN.h
components/serverCommunicationVRPN.inl
components/ServerCommunicationVRPN.h
components/ServerCommunicationVRPN.inl
)

list(APPEND SOURCE_FILES
components/serverCommunicationVRPN.cpp
components/ServerCommunicationVRPN.cpp
)
list(APPEND EXTRA_FILES
examples/VRPN/primitives/Sender/Sender.scn
examples/VRPN/primitives/Receiver/Receiver.scn
examples/VRPN/matrix/Sender/Sender.scn
examples/VRPN/matrix/Receiver/Receiver.scn
)
endif()

add_subdirectory(Communication_test)

IF(WIN32)
add_definitions(-D_WINSOCKAPI_)
ENDIF(WIN32)
if(WIN32)
add_definitions(-D_WINSOCKAPI_)
endif()

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES})
target_link_libraries(${PROJECT_NAME} ${Oscpack_LIBRARIES} ${ZMQ_LIBRARIES} ${VRPN_LIBRARIES} SofaCore SofaBaseLinearSolver SofaSimulationGraph)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_Communication")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(${PROJECT_NAME} SofaCore SofaBaseLinearSolver SofaSimulationGraph)
target_link_libraries(${PROJECT_NAME} ${PROTOCOL_LIBS})

sofa_generate_package(
NAME ${PROJECT_NAME}
TARGETS ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
RELOCATABLE "plugins"
)

install(TARGETS ${PROJECT_NAME}
COMPONENT Communication_libraries
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(PLUGIN_COMMUNICATION_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(PLUGIN_COMMUNICATION_BUILD_TESTS)
enable_testing()
add_subdirectory(Communication_test)
endif()
27 changes: 27 additions & 0 deletions applications/plugins/Communication/CommunicationConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# CMake package configuration file for @PROJECT_NAME@

@PACKAGE_INIT@

set(COMMUNICATION_HAVE_ZMQ @COMMUNICATION_HAVE_ZMQ@)
set(COMMUNICATION_HAVE_OSCPACK @COMMUNICATION_HAVE_OSCPACK@)
set(COMMUNICATION_HAVE_VRPN @COMMUNICATION_HAVE_VRPN@)

find_package(SofaCore REQUIRED)
find_package(SofaBase REQUIRED)
find_package(SofaSimulation REQUIRED)

if(COMMUNICATION_HAVE_ZMQ)
find_package(ZMQ QUIET REQUIRED)
endif()
if(COMMUNICATION_HAVE_OSCPACK)
find_package(Oscpack QUIET REQUIRED)
endif()
if(COMMUNICATION_HAVE_VRPN)
find_package(VRPN QUIET REQUIRED)
endif()

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
endif()

check_required_components(@PROJECT_NAME@)
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,30 @@ set(SOURCE_FILES
Communication_test.cpp
)

#COMMUNICATION ZMQ
if(PLUGIN_COMMUNICATION_ZMQ)
if (ZMQ_FOUND)
list(APPEND SOURCE_FILES
Communication_testZMQ.cpp
)
endif ()
# ZMQ
if(PLUGIN_COMMUNICATION_ZMQ AND ZMQ_FOUND)
list(APPEND SOURCE_FILES
Communication_testZMQ.cpp
)
endif()

#COMMUNICATION OSC
if(PLUGIN_COMMUNICATION_Oscpack)
if (Oscpack_FOUND)
list(APPEND SOURCE_FILES
Communication_testOSC.cpp
)
endif ()
# OSC
if(PLUGIN_COMMUNICATION_Oscpack AND Oscpack_FOUND)
list(APPEND SOURCE_FILES
Communication_testOSC.cpp
)
endif()

#COMMUNICATION VRPN
if(PLUGIN_COMMUNICATION_VRPN)
if (VRPN_FOUND)
list(APPEND SOURCE_FILES
Communication_testVRPN.cpp
)
endif ()
# VRPN
if(PLUGIN_COMMUNICATION_VRPN AND VRPN_FOUND)
list(APPEND SOURCE_FILES
Communication_testVRPN.cpp
)
endif()

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaTest Communication ${Oscpack_LIBRARIES} ${ZMQ_LIBRARIES} ${VRPN_LIBRARIES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaTest Communication)
target_link_libraries(${PROJECT_NAME} ${PROTOCOL_LIBS})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..")

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ using sofa::simulation::Simulation ;
using sofa::core::ObjectFactory ;

// COMMUNICATION PART
#include <Communication/components/serverCommunication.h>
#include <Communication/components/ServerCommunication.h>
#include <Communication/components/CommunicationSubscriber.h>
using sofa::component::communication::ServerCommunication;
using sofa::component::communication::CommunicationSubscriber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ using sofa::simulation::Simulation ;
using sofa::core::ObjectFactory ;

// COMMUNICATION PART
#include <Communication/components/serverCommunication.h>
#include <Communication/components/serverCommunicationOSC.h>
#include <Communication/components/ServerCommunication.h>
#include <Communication/components/ServerCommunicationOSC.h>
#include <Communication/components/CommunicationSubscriber.h>
using sofa::component::communication::ServerCommunication;
using sofa::component::communication::ServerCommunicationOSC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ using sofa::simulation::Simulation ;
using sofa::core::ObjectFactory ;

// COMMUNICATION PART
#include <Communication/components/serverCommunication.h>
#include <Communication/components/serverCommunicationVRPN.h>
#include <Communication/components/ServerCommunication.h>
#include <Communication/components/ServerCommunicationVRPN.h>
#include <Communication/components/CommunicationSubscriber.h>
using sofa::component::communication::ServerCommunication;
using sofa::component::communication::ServerCommunicationVRPN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ using sofa::simulation::Simulation ;
using sofa::core::ObjectFactory ;

// COMMUNICATION PART
#include <Communication/components/serverCommunication.h>
#include <Communication/components/serverCommunicationZMQ.h>
#include <Communication/components/ServerCommunication.h>
#include <Communication/components/ServerCommunicationZMQ.h>
#include <Communication/components/CommunicationSubscriber.h>
using sofa::component::communication::ServerCommunication;
using sofa::component::communication::ServerCommunicationZMQ;
Expand Down
16 changes: 16 additions & 0 deletions applications/plugins/Communication/cmake/FindOscpack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# - Try to find Oscpack
# Once done this will define
# Oscpack_FOUND - System has Oscpack
# Oscpack_INCLUDE_DIRS - The Oscpack include directories
# Oscpack_LIBRARIES - The libraries needed to use Oscpack

find_path(Oscpack_INCLUDE_DIR osc/OscTypes.h)
find_library(Oscpack_LIBRARY Oscpack)

set(Oscpack_LIBRARIES ${Oscpack_LIBRARY})
set(Oscpack_INCLUDE_DIRS ${Oscpack_INCLUDE_DIR})

# handle the QUIETLY and REQUIRED arguments and set Oscpack_FOUND to TRUE
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Oscpack DEFAULT_MSG Oscpack_LIBRARY Oscpack_INCLUDE_DIR)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# VRPN_INCLUDE_DIRS - The VRPN include directories
# VRPN_LIBRARIES - The libraries needed to use VRPN

find_path ( VRPN_INCLUDE_DIR vrpn.h )
find_library ( VRPN_LIBRARY NAMES vrpn )
find_path(VRPN_INCLUDE_DIR vrpn.h)
find_library(VRPN_LIBRARY NAMES vrpn)

set ( VRPN_LIBRARIES ${VRPN_LIBRARY} )
set ( VRPN_INCLUDE_DIRS ${VRPN_INCLUDE_DIR} )
set(VRPN_LIBRARIES ${VRPN_LIBRARY})
set(VRPN_INCLUDE_DIRS ${VRPN_INCLUDE_DIR})

include ( FindPackageHandleStandardArgs )
# handle the QUIETLY and REQUIRED arguments and set VRPN_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args ( VRPN DEFAULT_MSG VRPN_LIBRARY VRPN_INCLUDE_DIR )
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(VRPN DEFAULT_MSG VRPN_LIBRARY VRPN_INCLUDE_DIR)
16 changes: 16 additions & 0 deletions applications/plugins/Communication/cmake/FindZMQ.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# - Try to find ZMQ
# Once done this will define
# ZMQ_FOUND - System has ZMQ
# ZMQ_INCLUDE_DIRS - The ZMQ include directories
# ZMQ_LIBRARIES - The libraries needed to use ZMQ

find_path(ZMQ_INCLUDE_DIR zmq.h)
find_library(ZMQ_LIBRARY NAMES zmq)

set(ZMQ_LIBRARIES ${ZMQ_LIBRARY})
set(ZMQ_INCLUDE_DIRS ${ZMQ_INCLUDE_DIR})

# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ZMQ DEFAULT_MSG ZMQ_LIBRARY ZMQ_INCLUDE_DIR)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Contact information: [email protected] *
******************************************************************************/
#include <Communication/config.h>
#include <Communication/components/communicationBinder.h>
#include <Communication/components/CommunicationBinder.h>
#include <sofa/core/ObjectFactory.h>

using sofa::core::RegisterObject ;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#include "communicationCircularBuffer.inl"
#include "CommunicationCircularBuffer.inl"

namespace sofa
{
Expand Down
File renamed without changes.
Loading

0 comments on commit a8de521

Please sign in to comment.