root / branches / lib_additions / code / projects / colonet / ColonetServer / client.cpp @ 79
History | View | Annotate | Download (1.24 KB)
1 |
/** @file client.c
|
---|---|
2 |
*
|
3 |
* @author Jason Knichel
|
4 |
* @author Eugene Marinelli
|
5 |
*
|
6 |
* @TODO remove dependency on connection_pool
|
7 |
* @bug Weird segfault when processing tokens
|
8 |
*/
|
9 |
|
10 |
#include <string.h> |
11 |
#include <stdio.h> |
12 |
#include <unistd.h> |
13 |
#include <ctype.h> |
14 |
#include <errno.h> |
15 |
|
16 |
#include <colonet_wireless.h> |
17 |
|
18 |
#include "includes/client.h" |
19 |
#include "includes/options.h" |
20 |
#include "includes/ConnectionPool.h" |
21 |
|
22 |
/* Globals */
|
23 |
extern ConnectionPool * connection_pool;
|
24 |
|
25 |
|
26 |
/* Public functions */
|
27 |
int wirelessMessageHandler(ColonetPacket* pkt)
|
28 |
{ |
29 |
printf("Received wireless message!!!\n");
|
30 |
if (!pkt) {
|
31 |
printf("The packet pointer was null.\n");
|
32 |
return -1; |
33 |
} |
34 |
|
35 |
if ((int)pkt->msg_type == COLONET_RESPONSE) { |
36 |
printf("response\n");
|
37 |
|
38 |
int dest = (int)(pkt->msg_dest); |
39 |
char buffer[WRITE_BUFFER_SIZE];
|
40 |
|
41 |
int value = (int)(pkt->data[0]); |
42 |
snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value);
|
43 |
|
44 |
int len = strlen(buffer);
|
45 |
if (connection_pool->write_to_client(dest, buffer, len) == ERROR_INVALID_CLIENT_ID) {
|
46 |
printf("The robot wanted to pass the data to a client not in the pool.\n");
|
47 |
return -1; |
48 |
} |
49 |
|
50 |
printf("Put data in write buffer for client.\n");
|
51 |
} else {
|
52 |
printf("not a response\n");
|
53 |
} |
54 |
|
55 |
pkt = 0;
|
56 |
return 0; |
57 |
} |