JPSserver.h 2.09 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1 2 3 4 5 6 7 8 9 10
/*
 * JPSserver.h
 *
 *  Created on: Apr 21, 2015
 *      Author: piccolo
 */

#ifndef MATSIM_JPSSERVER_H_
#define MATSIM_JPSSERVER_H_

Ulrich Kemloh's avatar
Ulrich Kemloh committed
11
#include <iostream>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
12
#include <atomic>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
13

Ulrich Kemloh's avatar
Ulrich Kemloh committed
14 15 16 17 18 19 20 21 22 23 24 25
#include <grpc/grpc.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include "MATSimInterface.grpc.pb.h"

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
26
using namespace org::matsim::hybrid;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
27

28
//forward declarations
Ulrich Kemloh's avatar
Ulrich Kemloh committed
29 30
class Simulation;
class JPSclient;
31

Ulrich Kemloh's avatar
Ulrich Kemloh committed
32 33
class JPSserver final : public ExternInterfaceService::Service
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
34

Ulrich Kemloh's avatar
Ulrich Kemloh committed
35
public:
36 37 38 39
     /**
      * constructor with an agent source manager, which will be
      * responsible for positioning the agents.
      */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
40
     JPSserver(Simulation& src);
41 42 43 44

     /**
      * Destructor
      */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
45
     virtual ~JPSserver();
46

47
     /// The stub for these functions are automatically generated from the grpc module
Ulrich Kemloh's avatar
Ulrich Kemloh committed
48 49 50 51 52
     virtual Status reqMATSim2ExternHasSpace(ServerContext* context, const MATSim2ExternHasSpace* request, MATSim2ExternHasSpaceConfirmed* response);
     virtual Status reqMATSim2ExternPutAgent(ServerContext* context, const MATSim2ExternPutAgent* request, MATSim2ExternPutAgentConfirmed* response);
     virtual Status reqExternDoSimStep(ServerContext* context, const ExternDoSimStep* request, ExternDoSimStepReceived* response);
     virtual Status reqExternOnPrepareSim(ServerContext* context, const ExternOnPrepareSim* request, ExternOnPrepareSimConfirmed* response);
     virtual Status reqExternAfterSim(ServerContext* context, const ExternAfterSim* request, ExternAfterSimConfirmed* response);
53

Ulrich Kemloh's avatar
Ulrich Kemloh committed
54 55
     void RunSimulation();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
56
     void SetDuplexClient(std::shared_ptr<JPSclient>& client);
57 58 59
     //void SetAgentsSourcesManager(const AgentsSourcesManager& src) const;

private:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
60
    Simulation& _SimManager;
61
    bool _shutdown=false;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
62
    std::atomic<bool> _doSimulation;
63
    std::atomic<double> _maxSimTime;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
64
    std::shared_ptr<JPSclient> _jpsClient;
65 66
    int _maxAgents=0;
    //std::map<std::string, int> _mapMatsimID2JPSID;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
67 68 69
};

#endif /* MATSIM_JPSSERVER_H_ */