Project

General

Profile

Revision 453

fixed compile errors in colonetserver

View differences:

trunk/code/projects/colonet/lib/colonet_defs.h
147 147
#define SERVER_REPORT_POSITION_TO_ROBOT 0x55
148 148

  
149 149
#define CLIENT_REQUEST_ROBOT_POSITIONS 0x56
150
#define CLIENT_ASSIGN_POSITION_TO_ROBOT_ID 0x57
150
#define CLIENT_ASSIGN_ROBOT_ID 0x57
151 151

  
152 152
/* End low-level robot commands */
153 153

  
trunk/code/projects/colonet/ColonetServer/Command.cpp
24 24

  
25 25
using namespace std;
26 26

  
27
Command::Command(ConnectionPool * connection_pool_temp) {
27
Command::Command(ConnectionPool * connection_pool_temp, ColonetServer* cs) {
28 28
  connection_pool = connection_pool_temp;
29
  colonet_server = cs;
29 30
}
30 31

  
31 32
Command::~Command() {}
......
224 225
    }
225 226
    break;
226 227

  
227
  case CLIENT_ASSIGN_POSITION_TO_ROBOT_ID:
228
  case CLIENT_ASSIGN_ROBOT_ID:
228 229
    
229 230
    break;
230 231

  
231 232
  default:
232
    char * my_current_message = "Hi, how are you?\n";
233
    char * my_current_message = "Invalid request!\n";
233 234
    printf("Sending %s\n", my_current_message);
234 235
    connection_pool->write_to_client(pool_index, my_current_message, strlen(my_current_message));
235 236
    break;
......
283 284
int Command::parse_request_robot_positions(int pool_index) {
284 285
  printf("TODO - parse_request_robot_positions\n");
285 286
  
286
  map<int, VisionPosition> positions = colonet_server.getPositionMonitor()->getAllRobotPositions();
287
  map<int, VisionPosition> positions = colonet_server->getPositionMonitor()->getAllRobotPositions();
287 288

  
288 289
  return 0;
289 290
}
trunk/code/projects/colonet/ColonetServer/includes/ConnectionPool.h
9 9
#include <sys/select.h>
10 10

  
11 11
#include <colonet_wireless.h>
12
#include <ColonetServer.h>
12 13

  
13 14
#define MAX_TOKENS 15
14 15
#define MAX_TOKEN_SIZE 30
......
31 32
#define READ_BUFFER_SIZE 1024
32 33
#define WRITE_BUFFER_SIZE 4096
33 34

  
35
class ColonetServer;
36

  
34 37
class ConnectionPool {
35 38

  
36 39
public:
37
  ConnectionPool();
40
  ConnectionPool(ColonetServer* cs);
38 41
  ~ConnectionPool();
39 42

  
40 43
  int add_client(int client_file_descriptor);
......
59 62
  int read_buffer_size[MAX_CONNECTIONS];
60 63
  char * write_buffer[MAX_CONNECTIONS];
61 64
  int write_buffer_size[MAX_CONNECTIONS];
65
  ColonetServer* colonet_server;
62 66

  
63 67
  int read_data(int pool_index, int client_file_descriptor);
64 68
  int write_data(int pool_index, int client_file_descriptor);
trunk/code/projects/colonet/ColonetServer/includes/ColonetServer.h
6 6
#ifndef COLONETSERVER_H
7 7
#define COLONETSERVER_H
8 8

  
9
 class ConnectionPool;
10

  
9 11
#include <ConnectionPool.h>
10 12
#include <PositionMonitor.h>
11 13
#include <Log.h>
......
22 24
  PositionMonitor* getPositionMonitor(void);
23 25

  
24 26
private:
25
  ConnectionPool connection_pool;
27
  ConnectionPool* connection_pool;
26 28
  Log* logger;
27 29
  int listen_socket;
28 30
  PositionMonitor position_monitor;
trunk/code/projects/colonet/ColonetServer/includes/PositionMonitor.h
26 26
  int startMonitoring(void);
27 27
  int stopMonitoring(void);
28 28
  int updatePositions(void);
29
  
29 30

  
30 31
  map<int, VisionPosition> getAllRobotPositions(void);
31 32
  int getRobotPosition(int robot_id, int* xbuf, int* ybuf);
trunk/code/projects/colonet/ColonetServer/includes/Command.h
9 9
#define COMMAND_H
10 10

  
11 11
#include <ConnectionPool.h>
12
#include <ColonetServer.h>
12 13
#include <list>
13 14

  
14 15
class Command {
15 16
 public:
16
  Command(ConnectionPool * connection_pool);
17
  Command(ConnectionPool * connection_pool, ColonetServer* cs);
17 18
  ~Command();
18 19

  
19 20
  int parse_command(char* command, int pool_index);
......
30 31
  int parse_request_robot_positions(int pool_index);
31 32

  
32 33
  ConnectionPool * connection_pool;
34
  ColonetServer* colonet_server;
33 35
};
34 36

  
35 37

  
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp
23 23
/**
24 24
 * @brief The default constructor for ConnectionPool
25 25
 */
26
ConnectionPool::ConnectionPool() {
26
ConnectionPool::ConnectionPool(ColonetServer* cs) {
27
  colonet_server = cs;
28

  
27 29
  max_file_descriptor = 0;
28 30
  next_available_slot = 0;
29 31
  number_clients_ready = 0;
......
335 337
        break;
336 338
      }
337 339

  
338
      Command command(this);
340
      Command command(this, colonet_server);
339 341
      if (command.parse_command(temporary_command_buffer, pool_index) != 0) {
340 342
        fprintf(stderr, "Error parsing command\n");
341 343
        break;
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
38 38
 */
39 39
ColonetServer::ColonetServer() {
40 40
  listen_socket = 0;
41
  connection_pool = new ConnectionPool(this);
41 42
}
42 43

  
43 44
/**
44 45
 * @brief Destructor for ColonetServer
45 46
 */
46 47
ColonetServer::~ColonetServer() {
48
  delete connection_pool;
47 49
}
48 50

  
49 51
/**
......
94 96
 * @brief Starts the server running (starts an infinite loop)
95 97
 */
96 98
int ColonetServer::run_server() {
97
  connection_pool.add_new_socket_to_pool(listen_socket);
99
  connection_pool->add_new_socket_to_pool(listen_socket);
98 100

  
99 101
  int accept_socket = 0;
100 102
  struct sockaddr_in client_addr;
......
105 107
  }
106 108

  
107 109
  while(1) {
110
    connection_pool->perform_select(listen_socket);
108 111

  
109
    connection_pool.perform_select(listen_socket);
110

  
111 112
    //either no descriptors are ready or there was an error
112
    if (connection_pool.get_number_clients_ready() <= 0) {
113
    if (connection_pool->get_number_clients_ready() <= 0) {
113 114
      continue;
114 115
    }
115 116

  
116
    if (connection_pool.is_socket_ready_to_read(listen_socket)) {
117
    if (connection_pool->is_socket_ready_to_read(listen_socket)) {
117 118
      printf("Something is trying to connect...\n");
118 119
      if ((accept_socket = accept(listen_socket, (struct sockaddr*) &client_addr, &client_addr_size)) < 0) {
119 120
        if (errno == EMFILE) {
......
133 134
        logger->log_string(LOG_TYPE_CONNECT, log_buffer);
134 135
      }
135 136

  
136
      if (connection_pool.add_client(accept_socket) < 0) {
137
      if (connection_pool->add_client(accept_socket) < 0) {
137 138
        printf("\tThere was an error when trying to add a client to the connection pool.");
138 139
        continue;
139 140
      }
......
146 147
      }
147 148
    }
148 149

  
149
    if (connection_pool.check_clients() < 0) {
150
    if (connection_pool->check_clients() < 0) {
150 151
      printf("\tThere was an error trying to update the clients.");
151 152
      continue;
152 153
    }
......
162 163
* @param len - Length of the data param.
163 164
*/
164 165
int ColonetServer::process_received_wireless_message(int dest, char* data, int len) {
165
  if (connection_pool.write_to_client(dest, data, len) == ERROR_INVALID_CLIENT_ID) {
166
  if (connection_pool->write_to_client(dest, data, len) == ERROR_INVALID_CLIENT_ID) {
166 167
    printf("The robot wanted to pass the data to a client not in the pool.\n");
167 168
    return -1;
168 169
  }

Also available in: Unified diff