Project

General

Profile

Revision 139

Added by Jason knichel over 16 years ago

changed how the command gets its connection pool a little bit

View differences:

Command.cpp
9 9
#include <stdio.h>
10 10
#include <string.h>
11 11
#include <ctype.h>
12

  
13 12
#include "includes/Command.h"
14 13
#include "includes/ConnectionPool.h"
15 14

  
16
Command::Command() {
15
Command::Command(ConnectionPool * connection_pool_temp) {
16
  connection_pool = connection_pool_temp;
17 17
}
18 18

  
19 19
Command::~Command() {
20 20
}
21 21

  
22
int Command::parse_command(char* command, int pool_index, ConnectionPool * connection_pool) {
22
int Command::parse_command(char* command, int pool_index) {
23 23
  char tokens[MAX_TOKENS][MAX_TOKEN_SIZE];
24 24
  int number_tokens = 0;
25 25
  char* end_pointer = NULL;
26 26
  int command_id;
27 27

  
28
  if (!connection_pool) {
29
    return -1;
30
  }
31

  
28 32
  if (!command) {
29 33
    return -1;
30 34
  }
......
50 54
      return -1;
51 55
    }
52 56
  } else if (command_id == REQUEST_FROM_SERVER) {
53
    if (parse_request_from_server(number_tokens, tokens, connection_pool, pool_index)) {
57
    if (parse_request_from_server(number_tokens, tokens, pool_index)) {
54 58
      return -1;
55 59
    }
56 60
  }
......
175 179
}
176 180

  
177 181

  
178
int Command::parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], ConnectionPool * connection_pool, int pool_index) {
182
int Command::parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) {
179 183
  char* end_pointer = NULL;
180 184

  
185
  if (!connection_pool) {
186
    return -1;
187
  }
188

  
181 189
  if (number_tokens < 2)
182 190
    return -1;
183 191

  
......
190 198
  }
191 199
    
192 200
  if (second_token == REQUEST_BOM_MATRIX) {
193
    if (parse_request_bom_matrix(connection_pool, pool_index)) {
201
    if (parse_request_bom_matrix(pool_index)) {
194 202
      return -1;
195 203
    }
196 204
  } else if (second_token == REQUEST_XBEE_IDS) {
197
    if (parse_request_xbee_ids(connection_pool, pool_index)) {
205
    if (parse_request_xbee_ids(pool_index)) {
198 206
      return -1;
199 207
    }
200 208
  } else {
......
206 214
  return 0;
207 215
}
208 216

  
209
int Command::parse_request_bom_matrix(ConnectionPool * connection_pool, int pool_index) {
217
int Command::parse_request_bom_matrix(int pool_index) {
210 218
  char response_bom_matrix_buffer[MAX_RESPONSE_LEN];
211 219
  char temp_bom_matrix_buffer[MAX_RESPONSE_LEN];
212 220
 
221
  if (!connection_pool) {
222
    return -1;
223
  }
224

  
213 225
  //TODO: change after we start keeping track of bom matrix
214 226
  int number_robots = rand()%10;
215 227
  int bom_matrix[number_robots][number_robots];
......
243 255
  return 0;
244 256
}
245 257

  
246
int Command::parse_request_xbee_ids(ConnectionPool * connection_pool, int pool_index) {
258
int Command::parse_request_xbee_ids(int pool_index) {
247 259
  //TODO: make this better
248 260
  int number_robots = rand() % 10;
249 261

  
250 262
  char xbee_id_buffer[MAX_RESPONSE_LEN];
251 263
  char temp_xbee_id_buffer[MAX_RESPONSE_LEN];
252 264
      
265
  if (!connection_pool) {
266
    return -1;
267
  }
268

  
253 269
  snprintf(xbee_id_buffer, MAX_RESPONSE_LEN, "%d %d %d", RESPONSE_TO_CLIENT_REQUEST, REQUEST_XBEE_IDS, number_robots);
254 270
      
255 271
  printf("number of robots is %d\n", number_robots);

Also available in: Unified diff