Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #353 from dawagner/dont-leak-asio-headers
Browse files Browse the repository at this point in the history
Make network dependency optional

 - Add cmake option NETWORKING to stub ASIO
 - If networking is requested (tunning allowed), the PF will fail to start
 - Require cmake 3.0.0 for asio stub INTERFACE lib.
 - If networking is off, remove the asio dependency.

Internal: Don't leak asio headers from libremote-processor.
  • Loading branch information
krocard committed Feb 25, 2016
2 parents e73e2f0 + 7c0b65b commit ecceecb
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 98 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ compiler:
# it will not be necessary once travis worker is based on ubuntu > 12.04.
# Install SWIG for bindings generation
# Install valgrind for memcheck tests
# Adding kubuntu-backports ppa for for cmake 2.8.12.
# it is needed in case of multiple python version on host
# Adding george-edison55-precise-backports ppa for for cmake 3.x.
# Install python3-dev for the client simulator
addons:
apt:
# Travis white list of ppa
# https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
sources:
- ubuntu-toolchain-r-test
- kubuntu-backports
- george-edison55-precise-backports
- llvm-toolchain-precise
# Travis white list of dpkg packages
# https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise
packages:
- swig
- valgrind
- g++-4.8
- cmake-data
- cmake
- python3-dev
- libasio-dev
- clang-format-3.8

install:
Expand Down Expand Up @@ -80,6 +79,13 @@ script:
cmake -DCMAKE_INSTALL_PREFIX=../install . &&
make &&
make install )
# Keep this last
- ( mkdir build_less_features && cd build_less_features &&
rm -rf $PREFIX/asio-1.10.6 &&
cmake -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_BUILD_TYPE=Debug
-DNETWORKING=OFF -DPYTHON_BINDINGS=OFF -DC_BINDINGS=OFF .. &&
make -j &&
CTEST_OUTPUT_ON_FAILURE=1 make test )

after_success:
# Push coverage info on codecov.io.
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014-2015, Intel Corporation
# Copyright (c) 2014-2016, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -26,10 +26,12 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# working on 2.8.12 - broken on older versions.
# Known to work with CMake 3.2.2, might work with older 3.x versions, will not
# work with versions prior to 3.0.0.
# Visual Studio 14 needs 3.3.0; see https://cmake.org/Bug/print_bug_page.php?bug_id=15552
cmake_minimum_required(VERSION 2.8.12)
if(CMAKE_GENERATOR STRGREATER "Visual Studio 14 2015")
cmake_minimum_required(VERSION 3.2.2)
if((CMAKE_GENERATOR MATCHES "Visual Studio .*")
AND (CMAKE_GENERATOR STRGREATER "Visual Studio 14 2015"))
cmake_minimum_required(VERSION 3.3.0)
endif()

Expand All @@ -47,6 +49,7 @@ option(REQUIREMENTS "Generate the html version of the 'requirements' documentati
option(PYTHON_BINDINGS "Python library to use the Parameter Framework from python" ON)
option(C_BINDINGS "Library to use the Parameter Framework using a C API" ON)
option(FATAL_WARNINGS "Turn warnings into errors (-Werror flag)" ON)
option(NETWORKING "Set to OFF in order to stub networking code" ON)

include(SetVersion.cmake)

Expand Down Expand Up @@ -102,6 +105,7 @@ endif()
add_subdirectory(xmlserializer)
add_subdirectory(parameter)
add_subdirectory(utility)
add_subdirectory(asio)
add_subdirectory(remote-processor)

add_subdirectory(remote-process)
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,36 @@ sections:

In order to compile you'll need, at the very least:

- CMake (v2.8.12 or later) (v3.3.0 or later on Windows);
- CMake (v3.2.2 or later) (v3.3.0 or later on Windows);
- A C/C++ compiler supporting C++11;
- libxml2 headers and libraries (Provided by the `libxml2-dev` on debian-based
distributions);

If you want to use the remote command interface (`NETWORKING=ON` by default),
you'll also need:

- Standalone ASIO (1.10.6 or later) (Provided by `libasio-dev` on debian-based
distributions) ASIO is C++ header-only ASynchronous-IO library.

If you want to compile the *Python bindings*, you'll also need:
If you want to compile the *Python bindings* (`PYTHON_BINDINGS=ON` by default),
you'll also need:

- SWIG 2.0 (A binding generator);
- Python2.7 development environment (Provided by `python2.7-dev` on debian-based
distributions)

If you want to *compile and run the tests*, you'll also need:
If you want to *compile and run the tests* (`BUILD_TESTING=ON` by default),
you'll also need:

- Catch (Provided by `catch` on debian-based distributions). Catch is a
single-header test framework - as such you may also download it directly
[here](https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp);
- Python2.7 (Provided by `python2.7` on debian-based distribution - it is
preinstalled on most distributions).

If you want to *build the code documentation*, you'll need `doxygen` and
`graphviz`. This doc is already available to you - see the wiki.
If you want to *build the code documentation* (`DOXYGEN=OFF` by default), you'll
need `doxygen` and `graphviz`. This doc is already available to you - see the
wiki.

**To list all available configuration options, try** `cmake -L` (you may also
filter-out lines starting with `CMAKE_`).
Expand Down
57 changes: 57 additions & 0 deletions asio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2016, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

add_library(asio INTERFACE)

if (NETWORKING)
# Find ASIO (the standalone version, not Boost) If asio isn't installed in
# a standard directory, add the correct directory to CMAKE_PREFIX_PATH (see
# the main README for more information).
find_path(ASIO_DIR NAMES asio.hpp)
# Hide this variable from CMake GUIs and `cmake -L`
set_property(CACHE ASIO_DIR PROPERTY ADVANCED TRUE)
if (NOT ASIO_DIR)
message(SEND_ERROR
" ASIO header (asio.hpp) could not be found.
ASIO is used for networking. On Linux, you should install it using your
package manager. On Windows, please refer to the main README.")
endif()

# Ubuntu 14.04 packages asio 1.10.1 and clang 3.4.1.
# In this environment, asio stand alone (set ASIO_STANDALONE)
# does not correcly detect that the stl has CHRONO support (c++11).
# Force the use of std::chrono by setting ASIO_HAS_STD_CHRONO
target_include_directories(asio SYSTEM INTERFACE "${ASIO_DIR}")
target_link_libraries(asio INTERFACE "${CMAKE_THREAD_LIBS_INIT}")
target_compile_definitions(asio
INTERFACE ASIO_STANDALONE
INTERFACE ASIO_HAS_STD_CHRONO)
else()
# Stubbed version
target_include_directories(asio INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/stub")
endif()
117 changes: 117 additions & 0 deletions asio/stub/asio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2016, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

/** @file
*
* Stubs ASIO interfaces called by libremote-processor. This is used when
* the user asks for networking support to be compiled out.
*/

#include <system_error>

namespace asio
{
struct dummy_base
{
template <class... Args>
dummy_base(Args &&...)
{
}
void set_option(const dummy_base &) const {};
};
inline bool write(const dummy_base &, const dummy_base &, const dummy_base &)
{
return true;
}
inline bool read(const dummy_base &, const dummy_base &, const dummy_base &)
{
return true;
}
using buffer = dummy_base;
struct io_service : dummy_base
{
template <class... Args>
io_service(Args &&...)
{
throw std::runtime_error("Stub constructor called. Did you forget to set the "
"'TuningAllowed' attribute to 'false' in the Parameter "
"Framework's toplevel configuration file?");
}

void run(const dummy_base &) const {};
void stop() const {};
};
struct socket_base : dummy_base
{
using dummy_base::dummy_base;

using linger = dummy_base;
using enable_connection_aborted = dummy_base;
void close() const {};
};

bool write(const dummy_base &, const dummy_base &, const dummy_base &);
bool read(const dummy_base &, const dummy_base &, const dummy_base &);

struct error_code : dummy_base, std::error_code
{
};
namespace error
{
static const error_code eof{};
}

namespace ip
{
namespace tcp
{
using v6 = dummy_base;
using no_delay = dummy_base;
using socket = socket_base;
struct endpoint : dummy_base
{
using dummy_base::dummy_base;

dummy_base protocol() const { return {}; };
};
struct acceptor : dummy_base
{
using dummy_base::dummy_base;

using reuse_address = dummy_base;
void open(const dummy_base &) const {};
void bind(const dummy_base &) const {};
void listen() const {};
void async_accept(const dummy_base &, const dummy_base &) const {};
};
}
}
}
11 changes: 8 additions & 3 deletions parameter/ParameterMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#include "BitParameterType.h"
#include "StringParameterType.h"
#include "EnumParameterType.h"
#include "BackgroundRemoteProcessorServerBuilder.h"
#include "BackgroundRemoteProcessorServer.h"
#include "ElementLocator.h"
#include "CompoundRule.h"
#include "SelectionCriterionRule.h"
Expand Down Expand Up @@ -2855,8 +2855,13 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError)

auto port = getConstFrameworkConfiguration()->getServerPort();

// The ownership of remoteComandHandler is given to Bg remote processor server.
_pRemoteProcessorServer = new BackgroundRemoteProcessorServer(port, createCommandHandler());
try {
// The ownership of remoteComandHandler is given to Bg remote processor server.
_pRemoteProcessorServer = new BackgroundRemoteProcessorServer(port, createCommandHandler());
} catch (std::runtime_error &e) {
strError = string("ParameterMgr: Unable to create Remote Processor Server: ") + e.what();
return false;
}

if (_pRemoteProcessorServer == NULL) {
strError = "ParameterMgr: Unable to create Remote Processor Server";
Expand Down
21 changes: 9 additions & 12 deletions remote-process/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014, Intel Corporation
# Copyright (c) 2014-2016, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -26,17 +26,14 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

add_executable(remote-process main.cpp)
if(NETWORKING)
add_executable(remote-process main.cpp)

set(CMAKE_THREAD_PREFER_PTHREAD 1)
find_package(Threads REQUIRED)
set(CMAKE_THREAD_PREFER_PTHREAD 1)
find_package(Threads REQUIRED)

target_link_libraries(remote-process
PRIVATE remote-processor pfw_utility
# Remote-process does not use thread,
# nevertheless it uses asio resolver wich may use a thread (for async resolve).
# As a result remote-process must link with a thread library although not
# using the corresponding symbols.
PRIVATE "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(remote-process
PRIVATE remote-processor pfw_utility asio ${CMAKE_THREAD_LIBS_INIT})

install(TARGETS remote-process RUNTIME DESTINATION bin)
install(TARGETS remote-process RUNTIME DESTINATION bin)
endif()
5 changes: 3 additions & 2 deletions remote-process/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@
#include <stdlib.h>
#include "RequestMessage.h"
#include "AnswerMessage.h"
#include "Socket.h"

using namespace std;

bool sendAndDisplayCommand(asio::ip::tcp::socket &socket, CRequestMessage &requestMessage)
{
string strError;

if (requestMessage.serialize(socket, true, strError) != CRequestMessage::success) {
if (requestMessage.serialize(Socket(socket), true, strError) != CRequestMessage::success) {

cerr << "Unable to send command to target: " << strError << endl;
return false;
}

///// Get answer
CAnswerMessage answerMessage;
if (answerMessage.serialize(socket, false, strError) != CRequestMessage::success) {
if (answerMessage.serialize(Socket(socket), false, strError) != CRequestMessage::success) {

cerr << "Unable to received answer from target: " << strError << endl;
return false;
Expand Down
Loading

0 comments on commit ecceecb

Please sign in to comment.