JPSclient.h 2.35 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * JPSclient.h
 *
 *  Created on: Apr 21, 2015
 *      Author: piccolo
 */

#ifndef MATSIM_JPSCLIENT_H_
#define MATSIM_JPSCLIENT_H_

#include <grpc/grpc.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
16 17
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
18
#include <grpc++/status.h>
19

Ulrich Kemloh's avatar
Ulrich Kemloh committed
20 21 22 23 24 25
#include "MATSimInterface.grpc.pb.h"

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
26 27
using grpc::ChannelInterface;
using grpc::ClientContext;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
28 29
using org::matsim::hybrid::MATSim2ExternHasSpace;
using org::matsim::hybrid::MATSim2ExternHasSpaceConfirmed;
30

Ulrich Kemloh's avatar
Ulrich Kemloh committed
31
using namespace org::matsim::hybrid;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
32

33 34
class Building;
class Pedestrian;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
35 36 37 38

class JPSclient
{
public:
39 40 41 42 43 44 45 46 47 48

     /**
      * Constructor
      * @param channel, the rpc channel for the communication
      */
     JPSclient(std::shared_ptr<ChannelInterface> channel);

     /**
      * Destructor
      */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
49
     virtual ~JPSclient();
50 51 52 53 54 55 56 57 58 59 60

     /**
      * Process the finished agents queue
      */
     void ProcessAgentQueue(Building* building);

     /**
      * Shutdown the channel
      */
     void Shutdown()
     {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
61 62
          _jupedsimChannel.reset();
          _matsimChannel.reset();
63 64
     }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
65 66 67 68 69
     bool NotifyExternalService(const std::string& host, int port);

     bool SendAgentToMatsim(Pedestrian* ped);

     bool NotifyEndOfSimulation();
70

71 72 73 74 75 76 77 78 79 80 81 82 83
     /**
      * Request the maximal number of agents
      * @return
      */
     int RequestMaxNumberAgents();

     /**
      * JuPedsim uses integer for the agent ID, MATSim uses string.
      * @param jpsID, the jupedsim internal ID
      * @param matsimID, the matsim string id
      */
     void MapMatsimAgentToJPSagent(int jpsID, std::string matsimID)
     {
84
          //if()
85 86 87
          _mapMatsimID2JPSID[jpsID]=matsimID;
     }

88 89 90 91 92
private:
     bool HasSpaceOnJuPedSim(int nodeID);
     bool SendAgentToJuPedSim(Pedestrian* ped);

private:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
93 94
     std::unique_ptr<ExternInterfaceService::Stub> _jupedsimChannel;
     std::unique_ptr<MATSimInterfaceService::Stub> _matsimChannel;
95 96
     //map the matsim agent id to the jupedsim agent id
     std::map<int,std::string> _mapMatsimID2JPSID;
97 98 99
     //map the pedestrian id, to a time which is set
     // if the pedestrian could not be transfered to matsim
     std::map <int,int>_counter;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
100 101 102
};

#endif /* MATSIM_JPSCLIENT_H_ */