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

Commit ecceecb

Browse files
committed
Merge pull request #353 from dawagner/dont-leak-asio-headers
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.
2 parents e73e2f0 + 7c0b65b commit ecceecb

File tree

17 files changed

+386
-98
lines changed

17 files changed

+386
-98
lines changed

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@ compiler:
1414
# it will not be necessary once travis worker is based on ubuntu > 12.04.
1515
# Install SWIG for bindings generation
1616
# Install valgrind for memcheck tests
17-
# Adding kubuntu-backports ppa for for cmake 2.8.12.
18-
# it is needed in case of multiple python version on host
17+
# Adding george-edison55-precise-backports ppa for for cmake 3.x.
1918
# Install python3-dev for the client simulator
2019
addons:
2120
apt:
2221
# Travis white list of ppa
2322
# https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
2423
sources:
2524
- ubuntu-toolchain-r-test
26-
- kubuntu-backports
25+
- george-edison55-precise-backports
2726
- llvm-toolchain-precise
2827
# Travis white list of dpkg packages
2928
# https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise
3029
packages:
3130
- swig
3231
- valgrind
3332
- g++-4.8
33+
- cmake-data
3434
- cmake
3535
- python3-dev
36-
- libasio-dev
3736
- clang-format-3.8
3837

3938
install:
@@ -80,6 +79,13 @@ script:
8079
cmake -DCMAKE_INSTALL_PREFIX=../install . &&
8180
make &&
8281
make install )
82+
# Keep this last
83+
- ( mkdir build_less_features && cd build_less_features &&
84+
rm -rf $PREFIX/asio-1.10.6 &&
85+
cmake -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_BUILD_TYPE=Debug
86+
-DNETWORKING=OFF -DPYTHON_BINDINGS=OFF -DC_BINDINGS=OFF .. &&
87+
make -j &&
88+
CTEST_OUTPUT_ON_FAILURE=1 make test )
8389

8490
after_success:
8591
# Push coverage info on codecov.io.

CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014-2015, Intel Corporation
1+
# Copyright (c) 2014-2016, Intel Corporation
22
# All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without modification,
@@ -26,10 +26,12 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

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

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

5154
include(SetVersion.cmake)
5255

@@ -102,6 +105,7 @@ endif()
102105
add_subdirectory(xmlserializer)
103106
add_subdirectory(parameter)
104107
add_subdirectory(utility)
108+
add_subdirectory(asio)
105109
add_subdirectory(remote-processor)
106110

107111
add_subdirectory(remote-process)

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,36 @@ sections:
7373

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

76-
- CMake (v2.8.12 or later) (v3.3.0 or later on Windows);
76+
- CMake (v3.2.2 or later) (v3.3.0 or later on Windows);
7777
- A C/C++ compiler supporting C++11;
7878
- libxml2 headers and libraries (Provided by the `libxml2-dev` on debian-based
7979
distributions);
80+
81+
If you want to use the remote command interface (`NETWORKING=ON` by default),
82+
you'll also need:
83+
8084
- Standalone ASIO (1.10.6 or later) (Provided by `libasio-dev` on debian-based
8185
distributions) ASIO is C++ header-only ASynchronous-IO library.
8286

83-
If you want to compile the *Python bindings*, you'll also need:
87+
If you want to compile the *Python bindings* (`PYTHON_BINDINGS=ON` by default),
88+
you'll also need:
8489

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

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

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

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

100107
**To list all available configuration options, try** `cmake -L` (you may also
101108
filter-out lines starting with `CMAKE_`).

asio/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) 2016, Intel Corporation
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without modification,
5+
# are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation and/or
12+
# other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
add_library(asio INTERFACE)
30+
31+
if (NETWORKING)
32+
# Find ASIO (the standalone version, not Boost) If asio isn't installed in
33+
# a standard directory, add the correct directory to CMAKE_PREFIX_PATH (see
34+
# the main README for more information).
35+
find_path(ASIO_DIR NAMES asio.hpp)
36+
# Hide this variable from CMake GUIs and `cmake -L`
37+
set_property(CACHE ASIO_DIR PROPERTY ADVANCED TRUE)
38+
if (NOT ASIO_DIR)
39+
message(SEND_ERROR
40+
" ASIO header (asio.hpp) could not be found.
41+
ASIO is used for networking. On Linux, you should install it using your
42+
package manager. On Windows, please refer to the main README.")
43+
endif()
44+
45+
# Ubuntu 14.04 packages asio 1.10.1 and clang 3.4.1.
46+
# In this environment, asio stand alone (set ASIO_STANDALONE)
47+
# does not correcly detect that the stl has CHRONO support (c++11).
48+
# Force the use of std::chrono by setting ASIO_HAS_STD_CHRONO
49+
target_include_directories(asio SYSTEM INTERFACE "${ASIO_DIR}")
50+
target_link_libraries(asio INTERFACE "${CMAKE_THREAD_LIBS_INIT}")
51+
target_compile_definitions(asio
52+
INTERFACE ASIO_STANDALONE
53+
INTERFACE ASIO_HAS_STD_CHRONO)
54+
else()
55+
# Stubbed version
56+
target_include_directories(asio INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/stub")
57+
endif()

asio/stub/asio.hpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2016, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation and/or
13+
* other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its contributors
16+
* may be used to endorse or promote products derived from this software without
17+
* specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
#pragma once
31+
32+
/** @file
33+
*
34+
* Stubs ASIO interfaces called by libremote-processor. This is used when
35+
* the user asks for networking support to be compiled out.
36+
*/
37+
38+
#include <system_error>
39+
40+
namespace asio
41+
{
42+
struct dummy_base
43+
{
44+
template <class... Args>
45+
dummy_base(Args &&...)
46+
{
47+
}
48+
void set_option(const dummy_base &) const {};
49+
};
50+
inline bool write(const dummy_base &, const dummy_base &, const dummy_base &)
51+
{
52+
return true;
53+
}
54+
inline bool read(const dummy_base &, const dummy_base &, const dummy_base &)
55+
{
56+
return true;
57+
}
58+
using buffer = dummy_base;
59+
struct io_service : dummy_base
60+
{
61+
template <class... Args>
62+
io_service(Args &&...)
63+
{
64+
throw std::runtime_error("Stub constructor called. Did you forget to set the "
65+
"'TuningAllowed' attribute to 'false' in the Parameter "
66+
"Framework's toplevel configuration file?");
67+
}
68+
69+
void run(const dummy_base &) const {};
70+
void stop() const {};
71+
};
72+
struct socket_base : dummy_base
73+
{
74+
using dummy_base::dummy_base;
75+
76+
using linger = dummy_base;
77+
using enable_connection_aborted = dummy_base;
78+
void close() const {};
79+
};
80+
81+
bool write(const dummy_base &, const dummy_base &, const dummy_base &);
82+
bool read(const dummy_base &, const dummy_base &, const dummy_base &);
83+
84+
struct error_code : dummy_base, std::error_code
85+
{
86+
};
87+
namespace error
88+
{
89+
static const error_code eof{};
90+
}
91+
92+
namespace ip
93+
{
94+
namespace tcp
95+
{
96+
using v6 = dummy_base;
97+
using no_delay = dummy_base;
98+
using socket = socket_base;
99+
struct endpoint : dummy_base
100+
{
101+
using dummy_base::dummy_base;
102+
103+
dummy_base protocol() const { return {}; };
104+
};
105+
struct acceptor : dummy_base
106+
{
107+
using dummy_base::dummy_base;
108+
109+
using reuse_address = dummy_base;
110+
void open(const dummy_base &) const {};
111+
void bind(const dummy_base &) const {};
112+
void listen() const {};
113+
void async_accept(const dummy_base &, const dummy_base &) const {};
114+
};
115+
}
116+
}
117+
}

parameter/ParameterMgr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#include "BitParameterType.h"
6868
#include "StringParameterType.h"
6969
#include "EnumParameterType.h"
70-
#include "BackgroundRemoteProcessorServerBuilder.h"
70+
#include "BackgroundRemoteProcessorServer.h"
7171
#include "ElementLocator.h"
7272
#include "CompoundRule.h"
7373
#include "SelectionCriterionRule.h"
@@ -2855,8 +2855,13 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError)
28552855

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

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

28612866
if (_pRemoteProcessorServer == NULL) {
28622867
strError = "ParameterMgr: Unable to create Remote Processor Server";

remote-process/CMakeLists.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, Intel Corporation
1+
# Copyright (c) 2014-2016, Intel Corporation
22
# All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without modification,
@@ -26,17 +26,14 @@
2626
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2727
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
add_executable(remote-process main.cpp)
29+
if(NETWORKING)
30+
add_executable(remote-process main.cpp)
3031

31-
set(CMAKE_THREAD_PREFER_PTHREAD 1)
32-
find_package(Threads REQUIRED)
32+
set(CMAKE_THREAD_PREFER_PTHREAD 1)
33+
find_package(Threads REQUIRED)
3334

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

42-
install(TARGETS remote-process RUNTIME DESTINATION bin)
38+
install(TARGETS remote-process RUNTIME DESTINATION bin)
39+
endif()

remote-process/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,23 @@
3636
#include <stdlib.h>
3737
#include "RequestMessage.h"
3838
#include "AnswerMessage.h"
39+
#include "Socket.h"
3940

4041
using namespace std;
4142

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

46-
if (requestMessage.serialize(socket, true, strError) != CRequestMessage::success) {
47+
if (requestMessage.serialize(Socket(socket), true, strError) != CRequestMessage::success) {
4748

4849
cerr << "Unable to send command to target: " << strError << endl;
4950
return false;
5051
}
5152

5253
///// Get answer
5354
CAnswerMessage answerMessage;
54-
if (answerMessage.serialize(socket, false, strError) != CRequestMessage::success) {
55+
if (answerMessage.serialize(Socket(socket), false, strError) != CRequestMessage::success) {
5556

5657
cerr << "Unable to received answer from target: " << strError << endl;
5758
return false;

0 commit comments

Comments
 (0)