Fix compile errors in Linux

This commit is contained in:
nsubiron 2017-03-14 11:55:37 +01:00
parent 6eb9727cb8
commit 02baff814e
10 changed files with 387 additions and 424 deletions

View File

@ -1,6 +1,10 @@
cmake_minimum_required (VERSION 2.6)
project (CarlaServer)
SET(CMAKE_CXX_COMPILER clang++)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED 14)
# Boost configuration
SET(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED system date_time regex)

View File

@ -3,6 +3,9 @@ BUILD_FOLDER=build
vsproject:
cmake -H. -B$(BUILD_FOLDER) -G "Visual Studio 14 2015 Win64"
stproject:
cmake -H. -B$(BUILD_FOLDER) -G "Sublime Text 2 - Ninja"
clean:
rm -Rf build CMakeFiles

View File

@ -3,7 +3,7 @@
#include <iostream>
namespace carla {
namespace server {
namespace server {
// -- Static methods ---------------------------------------------------------
template <typename ERROR_CODE>
@ -13,7 +13,7 @@ namespace carla {
// This is the thread that sends a string over the TCP socket.
static void serverWorkerThread(TCPServer &server, std::string &message) {
static void serverWorkerThread(TCPServer &server, const std::string &message) {
TCPServer::error_code error;
//message = message.size.c_ + message;
@ -63,7 +63,7 @@ namespace carla {
}
static void worldSendThread(TCPServer &server, std::string &message) {
static void worldSendThread(TCPServer &server, const std::string &message) {
TCPServer::error_code error;
//message = message.size + message;
@ -83,13 +83,16 @@ namespace carla {
_world(worldPort),
_server(writePort),
_client(readPort),
_worldThread([this]() {return worldReceiveThread(this->_world); },
[this](std::string &msg) { worldSendThread(this->_world, msg); },
[this]() {Connect(this->_world); }),
_serverThread([this](std::string &str) { serverWorkerThread(this->_server, str); },
[this]() {Connect(this->_server); }),
_clientThread([this]() { return clientWorkerThread(this->_client); },
[this]() {Connect(this->_client); })
_worldThread{
[this]() { return worldReceiveThread(this->_world); },
[this](const std::string &msg) { worldSendThread(this->_world, msg); },
[this]() { Connect(this->_world); }},
_serverThread{
[this](const std::string &str) { serverWorkerThread(this->_server, str); },
[this]() { Connect(this->_server); }},
_clientThread{
[this]() { return clientWorkerThread(this->_client); },
[this]() { Connect(this->_client); }}
{
/*std::cout << "WorldPort: " << worldPort << std::endl;
@ -138,5 +141,6 @@ namespace carla {
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
return _worldThread.tryPop(info);
}
}
}
}

View File

@ -3,12 +3,13 @@
#include "carla/server/Protocol.h"
#include "carla/server/TCPServer.h"
#include "carla/thread/AsyncReadWriteJobQueue.h"
#include "carla/thread/AsyncReaderJobQueue.h"
#include "carla/thread/AsyncWriterJobQueue.h"
#include "carla/thread/AsyncReadWriteJobQueue.h"
namespace carla {
namespace server {
namespace server {
class CarlaCommunication : private NonCopyable {
public:
@ -39,7 +40,7 @@ namespace carla {
thread::AsyncWriterJobQueue<std::string> _clientThread;
thread::AsyncReadWriteJobQueue<std::string, std::string> _worldThread;
};
}
}
}

View File

@ -7,7 +7,6 @@
#include <memory>
namespace carla {
namespace server {
// -- CarlaServer ------------------------------------------------------------

View File

@ -13,7 +13,6 @@
namespace carla {
namespace server {
struct Color {
char red;
char green;
@ -41,13 +40,14 @@ namespace server {
struct Scene_Values {
std::vector<Position> _possible_Positions;
std::vector<const float*> _projection_Matrix;
std::vector<const float *> _projection_Matrix;
};
enum Mode {
MONO = 0,
STEREO = 1
};
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
/// and one for receiving messages (read).
///
@ -85,27 +85,27 @@ namespace server {
////Try to read if the client has selected an end & start point. Return false if the queue is empty
bool tryReadEpisodeStart(float &start_index, float &end_index);
int GetModesCount() const;
int GetScenesCount() const;
void setMode(Mode mode);
Mode GetMode() const;
void SetScene(int scene);
int GetScene() const;
void SetReset(bool reset);
bool Reset() const;
bool Reset() const;
private:
//std::mutex _mutex;
std::atomic<Mode> _mode = MONO;
std::atomic<Mode> _mode {MONO};
std::atomic_int _scene;
std::atomic_bool _reset;
@ -115,7 +115,6 @@ namespace server {
const std::unique_ptr<CarlaCommunication> _communication;
const std::unique_ptr<Protocol> _proto;
};
} // namespace server

View File

@ -1,47 +0,0 @@
#include "Carla.h"
#include <boost/asio.hpp>
#include <boost\bind.hpp>
namespace carla {
namespace server {
class TCPConnection : public boost::enable_shared_from_this<TCPConnection>
{
public:
typedef boost::shared_ptr<TCPConnection> pointer;
static pointer create(boost::asio::io_service &io_service) {
return pointer(new TCPConnection(io_service));
}
boost::asio::ip::tcp::socket& socket() {
return socket_;
}
void Send(const std::string &message) {
message_ = message;
boost::asio::async_write(socket_, boost::asio::buffer(message_),
boost::bind(&TCPConnection::handle_write, shared_from_this()));
}
private:
TCPConnection(boost::asio::io_service& io_service)
: socket_(io_service)
{
}
void handle_write(const boost::system::error_code& /*error*/,
size_t /*bytes_transferred*/)
{
}
std::string message_;
boost::asio::ip::tcp::socket socket_;
};
}
}

View File

@ -13,7 +13,7 @@ namespace thread {
/// Executes the given job asynchronously. Every item that the job returns is
/// added to the queue.
template <typename W, typename R>
template<typename W, typename R>
class CARLA_API AsyncReadWriteJobQueue {
public:
@ -21,7 +21,10 @@ namespace thread {
using ReadingJob = std::function<void(R)>;
using ConnectJob = std::function<void()>;
explicit AsyncReadWriteJobQueue(WritingJob &&writingJob, ReadingJob &&readingJob, ConnectJob &&connectJob) :
explicit AsyncReadWriteJobQueue(
WritingJob && writingJob,
ReadingJob && readingJob,
ConnectJob && connectJob) :
_done(false),
_writeJob(std::move(writingJob)),
_readJob(std::move(readingJob)),

View File

@ -30,7 +30,7 @@ static std::string daytimeString() {
return str;
}
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
try {
if (argc != 6) {
std::cerr << "Usage: server <send-port> <read-port>" << std::endl;
@ -44,7 +44,6 @@ int main(int argc, char* argv[]) {
// Let's simulate the game loop.
Color c1;
c1.red = 255;
c1.green = 0;
@ -70,7 +69,7 @@ int main(int argc, char* argv[]) {
//c4.alpha = 0;
std::vector<Color> img;
for (int i=0; i < 1024; ++i) img.push_back(c1);
for (int i = 0; i < 1024; ++i) img.push_back(c1);
std::vector<Color> img_2;
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
@ -101,7 +100,6 @@ int main(int argc, char* argv[]) {
testData.depth_1 = depth_1;
testData.depth_2 = depth_2;
std::cout << "Server send World" << std::endl;
server.sendWorld();
@ -111,16 +109,16 @@ int main(int argc, char* argv[]) {
std::cout << "Server wait scene init" << std::endl;
do {
end = server.tryReadSceneInit(mode, scene);
}while (!end);
} while (!end);
std::vector<Position> positions;
std::vector<const float*> pMatrix;
std::vector<const float *> pMatrix;
positions.push_back(Position{ 0.0f, 0.0f });
positions.push_back(Position{ 1.0f, 2.0f });
positions.push_back(Position{ 3.0f, 4.0f });
positions.push_back(Position { 0.0f, 0.0f });
positions.push_back(Position { 1.0f, 2.0f });
positions.push_back(Position { 3.0f, 4.0f });
float list[16] = { 10.0, 10.0,10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
float list[16] = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
pMatrix.push_back(list);
@ -141,8 +139,7 @@ int main(int argc, char* argv[]) {
do {
end = server.tryReadEpisodeStart(startPoint, endPoint);
}
while (!end);
} while (!end);
std::cout << "Server send end reset" << std::endl;
@ -156,22 +153,22 @@ int main(int argc, char* argv[]) {
std::cout << "------> RESET <------" << std::endl;
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
server.sendEndReset();
}
else {
} else {
if (wait_control && server.tryReadControl(steer, gas)) {
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
wait_control = false;
}
else if (!wait_control) {
} else if (!wait_control) {
server.sendReward(testData);
wait_control = true;
}
}
Sleep(100);
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms);
}
}
} catch (const std::exception &e) {