Commit ae7744be authored by Ulrich Kemloh's avatar Ulrich Kemloh

MATSIM/JUPEDSIM hybrid simulation stub

parent 8930d207
......@@ -286,7 +286,6 @@ TraVisToClient::createServerSocket(unsigned short portNumber)
}
dtrace("server started at port %hu", portNumber);
dtrace("leaving createServerSocket()");
return (sock);
}
......
......@@ -25,7 +25,6 @@
*
**/
#ifndef TRAVISTOCLIENT_H_
#define TRAVISTOCLIENT_H_
......@@ -48,7 +47,6 @@
// fprintf(stderr, "%-15s|%03d| ", fileName, lineNumber);
// }
// #ifdef TRACE_LOGGING
/*
......@@ -62,20 +60,15 @@
fprintf(stderr, "ERROR: "), \
fprintf(stderr, __VA_ARGS__), \
_printErrorMessage())
*/
*/
// // #define dtrace(...) _printDebugLine(__FILE__, __LINE__, false, __VA_ARGS__)
// // #define derror(...) _printDebugLine(__FILE__, __LINE__, true, __VA_ARGS__)
// #else
// #define dtrace(...) ((void) 0)
// #define derror(...) (fprintf(stderr, __VA_ARGS__), _printErrorMessage())
// #endif /* TRACE_LOGGING */
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
......@@ -95,7 +88,6 @@ typedef int socklen_t;
#define startSocketSession() _startWin32SocketSession()
#define stopSocketSession() _stopWin32SocketSession()
#else
#include <unistd.h>
#include <netinet/in.h>
......@@ -111,17 +103,15 @@ typedef int socket_t;
#define SOCKET_ERROR (-1)
#endif
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED (5000) ///< up to this number, ports are reserved and should not be used
#endif
#define PORT 8989
#define HOST "localhost"
class TraVisToClient {
class TraVisToClient
{
public:
/// create a client with specific parameters
......@@ -147,7 +137,8 @@ private:
unsigned long lookupHostAddress(const char *hostName);
socket_t createClientSocket(const char *serverName, unsigned short portNumber);
socket_t createClientSocket(const char *serverName,
unsigned short portNumber);
socket_t createServerSocket(unsigned short portNumber);
......@@ -166,8 +157,6 @@ private:
#define closesocket close
#endif
private:
bool _isConnected;
socket_t _tcpSocket;
......
/*
* HybridSimulationManager.cpp
*
* Created on: Apr 20, 2015
* Author: piccolo
*/
#include "HybridSimulationManager.h"
#include <thread>
#include <functional>
HybridSimulationManager::HybridSimulationManager()
{
// TODO Auto-generated constructor stub
}
HybridSimulationManager::~HybridSimulationManager()
{
// TODO Auto-generated destructor stub
}
bool HybridSimulationManager::Init()
{
}
bool HybridSimulationManager::Run()
{
std::thread t1(&HybridSimulationManager::RunClient, this);
std::thread t2(&HybridSimulationManager::RunServer, this);
t1.join();
t2.join();
return true;
}
bool HybridSimulationManager::RunClient()
{
//check the message queue and send
do
{
} while (!_shutdown);
return true;
}
bool HybridSimulationManager::RunServer()
{
//check the message queue and send
do
{
} while (!_shutdown);
return true;
}
void HybridSimulationManager::Shutdown()
{
_shutdown = true;
}
/*
//
// blocking_tcp_echo_server.cpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <cstdlib>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>
using boost::asio::ip::tcp;
const int max_length = 1024;
typedef boost::shared_ptr<tcp::socket> socket_ptr;
void session(socket_ptr sock)
{
try
{
for (;;)
{
char data[max_length];
boost::system::error_code error;
size_t length = sock->read_some(boost::asio::buffer(data), error);
if (error == boost::asio::error::eof)
break; // Connection closed cleanly by peer.
else if (error)
throw boost::system::system_error(error); // Some other error.
boost::asio::write(*sock, boost::asio::buffer(data, length));
}
}
catch (std::exception& e)
{
std::cerr << "Exception in thread: " << e.what() << "\n";
}
}
void server(boost::asio::io_service& io_service, short port)
{
tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
for (;;)
{
socket_ptr sock(new tcp::socket(io_service));
a.accept(*sock);
boost::thread t(boost::bind(session, sock));
}
}
int main(int argc, char* argv[])
{
try
{
if (argc != 2)
{
std::cerr << "Usage: blocking_tcp_echo_server <port>\n";
return 1;
}
boost::asio::io_service io_service;
using namespace std; // For atoi.
server(io_service, atoi(argv[1]));
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
*/
/*
* HybridSimulationManager.h
*
* Created on: Apr 20, 2015
* Author: piccolo
*/
#ifndef HYBRIDSIMULATIONMANAGER_H_
#define HYBRIDSIMULATIONMANAGER_H_
class HybridSimulationManager
{
public:
HybridSimulationManager();
virtual ~HybridSimulationManager();
bool Init();
bool Run();
bool RunClient();
bool RunServer();
void Shutdown();
private:
bool _shutdown=false;
};
#endif /* HYBRIDSIMULATIONMANAGER_H_ */
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
syntax = "proto2";
option java_generic_services = true;
option java_outer_classname="ProtoMATSimInterface";
option java_package = "playground.gregor.proto";
message MATSim2ExternPutAgent {
message Agent {
required string id = 1;
required string enterNode = 2;
repeated string nodes = 3;
}
required Agent agent = 1;
}
message MATSim2ExternHasSpace {
required string nodeId = 1;
}
message MATSim2ExternHasSpaceConfirmed {
required bool hasSpace = 1;
}
message MATSim2ExternPutAgentConfirmed {
}
message Extern2MATSim {
message Agent {
required string id = 1;
required string leaveNode = 2;
}
required Agent agent = 15;
}
message Extern2MATSimConfirmed {
required bool accepted = 1;
}
message ExternSimStepFinished {
required double time = 1;
}
message ExternSimStepFinishedReceived {
}
message ExternDoSimStep {
required double fromTime = 1;
required double toTime = 2;
}
message ExternDoSimStepReceived {
}
message ExternalConnect {
}
message ExternalConnectConfirmed {
}
message ExternOnPrepareSim {
}
message ExternOnPrepareSimConfirmed {
}
message ExternAfterSim {
}
message ExternAfterSimConfirmed {
}
message AgentsStuck {
repeated string agentId = 1;
}
message AgentsStuckConfirmed{
}
service MATSimInterfaceService {
rpc reqExtern2MATSim(Extern2MATSim) returns (Extern2MATSimConfirmed);
rpc reqAgentStuck(AgentsStuck) returns (AgentsStuckConfirmed);
rpc reqExternalConnect(ExternalConnect) returns (ExternalConnectConfirmed);
rpc reqExternSimStepFinished(ExternSimStepFinished) returns (ExternSimStepFinishedReceived);
}
service ExternInterfaceService {
rpc reqMATSim2ExternHasSpace(MATSim2ExternHasSpace) returns (MATSim2ExternHasSpaceConfirmed);
rpc reqMATSim2ExternPutAgent(MATSim2ExternPutAgent) returns (MATSim2ExternPutAgentConfirmed);
rpc reqExternDoSimStep(ExternDoSimStep) returns (ExternDoSimStepReceived);
rpc reqExternOnPrepareSim(ExternOnPrepareSim) returns (ExternOnPrepareSimConfirmed);
rpc reqExternAfterSim(ExternAfterSim) returns (ExternAfterSimConfirmed);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment