Changeset 82 in tmcsimulator for branches/FEPSimulator/FEPSim.cpp
- Timestamp:
- 10/06/2017 06:54:21 PM (9 years ago)
- File:
-
- 1 moved
-
branches/FEPSimulator/FEPSim.cpp (moved) (moved from branches/FEPSimulator/FEPClient.cpp) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/FEPSimulator/FEPSim.cpp
r80 r82 1 #include "FEP Client.h"1 #include "FEPSim.h" 2 2 3 3 /** … … 7 7 * @param networkFile the xml network file 8 8 */ 9 FEP Client::FEPClient(char * host, char * networkFile) {10 networkReader = new NetworkReader( networkFile);11 createClient(host);9 FEPSim::FEPSim(char * ATMShost, char * xml) { 10 networkReader = new NetworkReader(xml); 11 this->ATMSHost = ATMShost; 12 12 updateATMS(); 13 13 } … … 16 16 * Destructor 17 17 */ 18 FEP Client::~FEPClient() {18 FEPSim::~FEPSim() { 19 19 cout << "Destroying client..." << endl; 20 20 clnt_destroy(clnt); … … 25 25 * @param response pointer to fep_reply struct 26 26 */ 27 void FEP Client::handleCallResponse(void *response) {27 void FEPSim::handleCallResponse(void *response) { 28 28 /* If ATMS reply call fails */ 29 29 if (response == NULL) { 30 30 clnt_perror(clnt, "RPC call failed"); 31 } /* If ATMS reply is successful */31 }/* If ATMS reply is successful */ 32 32 else { 33 33 cout << "Successful RPC call to ATMS..." << endl; … … 38 38 * Sends an fep_reply for every line in the FEP. 39 39 */ 40 void FEP Client::updateATMS() {40 void FEPSim::updateATMS() { 41 41 int i, j; // i == line_index, j == lds_index 42 42 void *rv; 43 44 43 vector<FEP_LINE*> lines = networkReader->getLines(); 45 44 vector<STATION*> ldsMap = networkReader->getStations(); … … 122 121 * @param host rpc server ip 123 122 */ 124 void FEP Client::createClient(char * host) {123 void FEPSim::createClient(char * host) { 125 124 /* Create RPC Client to communicate with ATMS */ 126 125 cout << "Creating RPC Client" << endl; … … 142 141 int main(int argc, char *argv[]) { 143 142 144 char *host; 145 char *networkFile; 146 147 if (argc < 3) { 148 cout << "usage: " << argv[0] << " server_host networkFile" << endl; 143 int sockfd, newsockfd, portno, clilen; 144 char buffer[BUFF_SIZE]; 145 struct sockaddr_in serv_addr, cli_addr; 146 int n; 147 148 char *FEPSimHost = argv[1]; 149 portno = atoi(argv[2]); 150 151 /* First call to socket() function */ 152 sockfd = socket(AF_INET, SOCK_STREAM, 0); 153 154 if (sockfd < 0) { 155 perror("ERROR opening socket"); 149 156 exit(1); 150 157 } 151 158 152 /* Create RPC Client to send an fep_reply to ATMS */ 153 host = argv[1]; 154 networkFile = argv[2]; 155 156 FEPClient *client = new FEPClient(host, networkFile); 157 delete client; 159 /* Initialize socket structure */ 160 bzero((char *) &serv_addr, sizeof (serv_addr)); 161 162 serv_addr.sin_family = AF_INET; 163 serv_addr.sin_addr.s_addr = INADDR_ANY; 164 serv_addr.sin_port = htons(portno); 165 166 /* Now bind the host address using bind() call.*/ 167 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) { 168 perror("ERROR on binding"); 169 exit(1); 170 } 171 172 /* Now start listening for the clients, here process will 173 * go in sleep mode and will wait for the incoming connection 174 */ 175 176 listen(sockfd, 5); 177 clilen = sizeof (cli_addr); 178 179 /* Accept actual connection from the client */ 180 while(1) { 181 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen); 182 183 if (newsockfd < 0) { 184 perror("ERROR on accept"); 185 exit(1); 186 } 187 188 /* If connection is established then start communicating */ 189 bzero(buffer, BUFF_SIZE); 190 191 // NEEDS OUTER LOOP TO GET WHOLE MESSAGE FROM TCP CONN 192 n = read(newsockfd, buffer, sizeof(buffer)); 193 194 if (n < 0) { 195 perror("ERROR reading from socket"); 196 exit(1); 197 } 198 199 /* Create RPC Client to send an fep_reply to ATMS */ 200 201 FEPSim *client = new FEPSim(FEPSimHost, buffer); 202 delete client; 203 } 158 204 159 205 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
