summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Gaio <miguel.gaio@renault.com>2017-12-13 15:25:30 +0100
committerEric Laurent <elaurent@google.com>2019-04-26 10:59:31 -0700
commit8a68f31307cfcffa4497078430bf3c59a5c2571c (patch)
treed0a3c1e5dc0f7e5db2e75ce42e355297504749a7
parentaab0b59ff5415492655d5dcb4664e3780bd061ed (diff)
downloadplatform_external_parameter-framework-8a68f31307cfcffa4497078430bf3c59a5c2571c.tar.gz
platform_external_parameter-framework-8a68f31307cfcffa4497078430bf3c59a5c2571c.tar.bz2
platform_external_parameter-framework-8a68f31307cfcffa4497078430bf3c59a5c2571c.zip
AF_UNIX socket enablement: make socket bind address more generic
Reword serverPort to bindAddress. Change bindAddress type to std::string as uint16_t is limited to tcp/udp port. Bug: 130284799 Test: make Change-Id: I84925f857f7983d5182600f7f272a43ba2f37b16 Signed-off-by: Miguel Gaio <miguel.gaio@renault.com>
-rw-r--r--upstream/parameter/ParameterFrameworkConfiguration.cpp8
-rw-r--r--upstream/parameter/ParameterFrameworkConfiguration.h4
-rw-r--r--upstream/parameter/ParameterMgr.cpp10
-rw-r--r--upstream/remote-processor/BackgroundRemoteProcessorServer.cpp4
-rw-r--r--upstream/remote-processor/BackgroundRemoteProcessorServer.h2
-rw-r--r--upstream/remote-processor/RemoteProcessorServer.cpp14
-rw-r--r--upstream/remote-processor/RemoteProcessorServer.h8
-rw-r--r--upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py8
-rw-r--r--upstream/test/test-platform/TestPlatform.cpp4
-rw-r--r--upstream/test/test-platform/TestPlatform.h2
-rw-r--r--upstream/test/test-platform/main.cpp10
11 files changed, 41 insertions, 33 deletions
diff --git a/upstream/parameter/ParameterFrameworkConfiguration.cpp b/upstream/parameter/ParameterFrameworkConfiguration.cpp
index bf735fd..1f18f45 100644
--- a/upstream/parameter/ParameterFrameworkConfiguration.cpp
+++ b/upstream/parameter/ParameterFrameworkConfiguration.cpp
@@ -53,10 +53,10 @@ bool CParameterFrameworkConfiguration::isTuningAllowed() const
return _bTuningAllowed;
}
-// Server port
-uint16_t CParameterFrameworkConfiguration::getServerPort() const
+// Server bind address
+const std::string &CParameterFrameworkConfiguration::getServerBindAddress() const
{
- return _uiServerPort;
+ return _bindAddress;
}
// From IXmlSink
@@ -70,7 +70,7 @@ bool CParameterFrameworkConfiguration::fromXml(const CXmlElement &xmlElement,
xmlElement.getAttribute("TuningAllowed", _bTuningAllowed);
// Server port
- xmlElement.getAttribute("ServerPort", _uiServerPort);
+ xmlElement.getAttribute("ServerPort", _bindAddress);
// Base
return base::fromXml(xmlElement, serializingContext);
diff --git a/upstream/parameter/ParameterFrameworkConfiguration.h b/upstream/parameter/ParameterFrameworkConfiguration.h
index 8972beb..83bb49f 100644
--- a/upstream/parameter/ParameterFrameworkConfiguration.h
+++ b/upstream/parameter/ParameterFrameworkConfiguration.h
@@ -43,7 +43,7 @@ public:
bool isTuningAllowed() const;
// Server port
- uint16_t getServerPort() const;
+ const std::string &getServerBindAddress() const;
// From IXmlSink
bool fromXml(const CXmlElement &xmlElement,
@@ -58,5 +58,5 @@ private:
// Tuning allowed
bool _bTuningAllowed{false};
// Server port
- uint16_t _uiServerPort{0};
+ std::string _bindAddress;
};
diff --git a/upstream/parameter/ParameterMgr.cpp b/upstream/parameter/ParameterMgr.cpp
index debf81d..91dd329 100644
--- a/upstream/parameter/ParameterMgr.cpp
+++ b/upstream/parameter/ParameterMgr.cpp
@@ -129,7 +129,7 @@ using namespace core;
// Used for remote processor server creation
typedef IRemoteProcessorServerInterface *(*CreateRemoteProcessorServer)(
- uint16_t uiPort, IRemoteCommandHandler *pCommandHandler);
+ std::string bindAddress, IRemoteCommandHandler *pCommandHandler);
// Config File System looks normally like this:
// ---------------------------------------------
@@ -2852,11 +2852,11 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError)
return true;
}
- auto port = getConstFrameworkConfiguration()->getServerPort();
+ auto bindAddress = getConstFrameworkConfiguration()->getServerBindAddress();
try {
// The ownership of remoteComandHandler is given to Bg remote processor server.
- _pRemoteProcessorServer = new BackgroundRemoteProcessorServer(port, createCommandHandler());
+ _pRemoteProcessorServer = new BackgroundRemoteProcessorServer(bindAddress, createCommandHandler());
} catch (std::runtime_error &e) {
strError = string("ParameterMgr: Unable to create Remote Processor Server: ") + e.what();
return false;
@@ -2869,11 +2869,11 @@ bool CParameterMgr::handleRemoteProcessingInterface(string &strError)
if (!_pRemoteProcessorServer->start(strError)) {
ostringstream oss;
- oss << "ParameterMgr: Unable to start remote processor server on port " << port;
+ oss << "ParameterMgr: Unable to start remote processor server on " << bindAddress;
strError = oss.str() + ": " + strError;
return false;
}
- info() << "Remote Processor Server started on port " << port;
+ info() << "Remote Processor Server started on " << bindAddress;
return true;
}
diff --git a/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp b/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp
index 0820786..b880107 100644
--- a/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp
+++ b/upstream/remote-processor/BackgroundRemoteProcessorServer.cpp
@@ -31,8 +31,8 @@
#include "RemoteProcessorServer.h"
BackgroundRemoteProcessorServer::BackgroundRemoteProcessorServer(
- uint16_t uiPort, std::unique_ptr<IRemoteCommandHandler> &&commandHandler)
- : _server(new CRemoteProcessorServer(uiPort)), mCommandHandler(std::move(commandHandler))
+ std::string bindAddress, std::unique_ptr<IRemoteCommandHandler> &&commandHandler)
+ : _server(new CRemoteProcessorServer(bindAddress)), mCommandHandler(std::move(commandHandler))
{
}
diff --git a/upstream/remote-processor/BackgroundRemoteProcessorServer.h b/upstream/remote-processor/BackgroundRemoteProcessorServer.h
index 221c08b..22c0242 100644
--- a/upstream/remote-processor/BackgroundRemoteProcessorServer.h
+++ b/upstream/remote-processor/BackgroundRemoteProcessorServer.h
@@ -40,7 +40,7 @@ class REMOTE_PROCESSOR_EXPORT BackgroundRemoteProcessorServer final
: public IRemoteProcessorServerInterface
{
public:
- BackgroundRemoteProcessorServer(uint16_t uiPort,
+ BackgroundRemoteProcessorServer(std::string bindAddress,
std::unique_ptr<IRemoteCommandHandler> &&commandHandler);
~BackgroundRemoteProcessorServer() override;
diff --git a/upstream/remote-processor/RemoteProcessorServer.cpp b/upstream/remote-processor/RemoteProcessorServer.cpp
index d3fefdd..8aa753c 100644
--- a/upstream/remote-processor/RemoteProcessorServer.cpp
+++ b/upstream/remote-processor/RemoteProcessorServer.cpp
@@ -36,11 +36,12 @@
#include "AnswerMessage.h"
#include "RemoteCommandHandler.h"
#include "Socket.h"
+#include "convert.hpp"
using std::string;
-CRemoteProcessorServer::CRemoteProcessorServer(uint16_t uiPort)
- : _uiPort(uiPort), _io_service(), _acceptor(_io_service), _socket(_io_service)
+CRemoteProcessorServer::CRemoteProcessorServer(std::string bindAddress)
+ : _bindAddress(bindAddress), _io_service(), _acceptor(_io_service), _socket(_io_service)
{
}
@@ -55,7 +56,12 @@ bool CRemoteProcessorServer::start(string &error)
using namespace asio;
try {
- ip::tcp::endpoint endpoint(ip::tcp::v6(), _uiPort);
+ uint16_t port;
+
+ if (!convertTo(_bindAddress, port)) {
+ throw std::invalid_argument("unable to convert bind Address: " + _bindAddress);
+ }
+ ip::tcp::endpoint endpoint(ip::tcp::v6(), port);
_acceptor.open(endpoint.protocol());
@@ -66,7 +72,7 @@ bool CRemoteProcessorServer::start(string &error)
_acceptor.bind(endpoint);
_acceptor.listen();
} catch (std::exception &e) {
- error = "Unable to listen on port " + std::to_string(_uiPort) + ": " + e.what();
+ error = "Unable to listen on port " + _bindAddress + ": " + e.what();
return false;
}
diff --git a/upstream/remote-processor/RemoteProcessorServer.h b/upstream/remote-processor/RemoteProcessorServer.h
index 2da0113..ab70a24 100644
--- a/upstream/remote-processor/RemoteProcessorServer.h
+++ b/upstream/remote-processor/RemoteProcessorServer.h
@@ -31,7 +31,7 @@
#include "remote_processor_export.h"
-#include <stdint.h>
+#include <string>
#include "RemoteProcessorServerInterface.h"
#include <asio.hpp>
@@ -40,7 +40,7 @@ class IRemoteCommandHandler;
class REMOTE_PROCESSOR_EXPORT CRemoteProcessorServer : public IRemoteProcessorServerInterface
{
public:
- CRemoteProcessorServer(uint16_t uiPort);
+ CRemoteProcessorServer(std::string bindAddress);
virtual ~CRemoteProcessorServer();
// State
@@ -54,8 +54,8 @@ private:
// New connection
void handleNewConnection(IRemoteCommandHandler &commandHandler);
- // Port number
- uint16_t _uiPort;
+ // Bind address
+ std::string _bindAddress;
asio::io_service _io_service;
asio::ip::tcp::acceptor _acceptor;
diff --git a/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py b/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py
index d75084c..714a41d 100644
--- a/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py
+++ b/upstream/test/functional-tests-legacy/Util/PfwUnitTestLib.py
@@ -74,18 +74,18 @@ class Pfw(RemoteCli):
class Hal(RemoteCli):
# Arbitrary choosen port, try to avoid conflicting with IANA registered ports
- testPlatformPort = 18444
- platform_command = ["remote-process", "localhost", str(testPlatformPort)]
+ testPlatformBindAddress = "18444"
+ platform_command = ["remote-process", "localhost", testPlatformBindAddress]
def __init__(self, pfw):
self.pfw = pfw
# Starts the HAL exe
def startHal(self):
- cmd= ["test-platform", os.environ["PFW_TEST_CONFIGURATION"], str(self.testPlatformPort)]
+ cmd= ["test-platform", os.environ["PFW_TEST_CONFIGURATION"], self.testPlatformBindAddress]
self.setRemoteProcess(subprocess.Popen(cmd))
# Wait for the test-platform listening socket
- while socket.socket().connect_ex(("localhost", self.testPlatformPort)) != 0:
+ while socket.socket().connect_ex(("localhost", int(self.testPlatformBindAddress))) != 0:
assert self.remoteProcess.poll() == None, "Test platform has failed to start. Return code: %s" % self.remoteProcess.returncode
time.sleep(0.01)
diff --git a/upstream/test/test-platform/TestPlatform.cpp b/upstream/test/test-platform/TestPlatform.cpp
index 69715ea..d090939 100644
--- a/upstream/test/test-platform/TestPlatform.cpp
+++ b/upstream/test/test-platform/TestPlatform.cpp
@@ -38,8 +38,8 @@
using std::string;
-CTestPlatform::CTestPlatform(const string &strClass, uint16_t iPortNumber)
- : mParameterMgrPlatformConnector(strClass), mLogger(), mRemoteProcessorServer(iPortNumber)
+CTestPlatform::CTestPlatform(const string &strClass, std::string bindAddress)
+ : mParameterMgrPlatformConnector(strClass), mLogger(), mRemoteProcessorServer(bindAddress)
{
mParameterMgrPlatformConnector.setLogger(&mLogger);
}
diff --git a/upstream/test/test-platform/TestPlatform.h b/upstream/test/test-platform/TestPlatform.h
index f9c27f7..8917dbb 100644
--- a/upstream/test/test-platform/TestPlatform.h
+++ b/upstream/test/test-platform/TestPlatform.h
@@ -45,7 +45,7 @@ class CTestPlatform
typedef CCommandHandler::CommandStatus CommandReturn;
public:
- CTestPlatform(const std::string &strclass, uint16_t iPortNumber);
+ CTestPlatform(const std::string &strclass, std::string bindAddress);
virtual ~CTestPlatform();
// Init
diff --git a/upstream/test/test-platform/main.cpp b/upstream/test/test-platform/main.cpp
index 6cb5267..58f3d04 100644
--- a/upstream/test/test-platform/main.cpp
+++ b/upstream/test/test-platform/main.cpp
@@ -41,11 +41,11 @@ using std::cerr;
using std::endl;
using std::string;
-static const uint16_t defaultPortNumber = 5001;
+static const std::string defaultBindAddress("5001");
static void showUsage()
{
- cerr << "test-platform [-h|--help] <file path> [port number, default " << defaultPortNumber
+ cerr << "test-platform [-h|--help] <file path> [port number, default " << defaultBindAddress
<< "]" << endl;
}
@@ -87,14 +87,16 @@ int main(int argc, char *argv[])
options.pop_front();
// Handle optional port number argument
- uint16_t portNumber = defaultPortNumber;
+ auto bindAddress = defaultBindAddress;
if (not options.empty()) {
+ uint16_t portNumber;
if (not convertTo(options.front(), portNumber)) {
showInvalidUsage("Could not convert \"" + options.front() +
"\" to a socket port number.");
return 2;
};
+ bindAddress = options.front();
options.pop_front();
}
@@ -105,7 +107,7 @@ int main(int argc, char *argv[])
}
string strError;
- if (!CTestPlatform(filePath, portNumber).run(strError)) {
+ if (!CTestPlatform(filePath, bindAddress).run(strError)) {
cerr << "Test-platform error:" << strError.c_str() << endl;
return -1;