aura  0.1
 All Data Structures Functions Variables Modules Pages
packetizer8-simple.c
1 #include <aura/aura.h>
2 #include <aura/packetizer.h>
3 
4 static int numfails;
5 int expected[] =
6 {
7  0x00,
8  0x11,
9  0x22,
10  0x33,
11  0x44,
12  0x55,
13 };
14 
15 static int curpacket;
16 void recvcb(struct aura_buffer *buf, void *arg)
17 {
18  slog(0, SLOG_INFO, "Got a packet from packetizer");
19  uint32_t result = aura_buffer_get_u32(buf);
20  if (expected[curpacket]!=result) {
21  slog(0, SLOG_ERROR, "expected %d got %d packet %d", expected[curpacket],
22  result, curpacket);
23  numfails++;
24  }
25  curpacket++;
27 }
28 
29 
30 void queue_packet(struct aura_packetizer *pkt, char *buf, int offset, uint32_t value)
31 {
32  struct aura_packet8 *pck = (struct aura_packet8 *) &buf[offset];
33  memcpy(pck->data, &value, sizeof(value));
34  aura_packetizer_encapsulate(pkt, pck, 0x4);
35  pkt->cont = 0;
36  pkt->expect_cont = 0;
37 }
38 
39 int main() {
40  slog_init(NULL, 18);
41 
42  struct aura_node *node = aura_open("dummy", NULL);
43  struct aura_packetizer *pkt = aura_packetizer_create(node);
44  if (!pkt)
45  BUG(node, "Fuck!");
46 
47  aura_packetizer_set_receive_cb(pkt, recvcb, NULL);
48  char buf[1024];
49  memset(buf,0x0, 1024 );
50 
51 
52  queue_packet(pkt, buf, 10, expected[0]);
53  /* packet overlapping the header */
54  queue_packet(pkt, buf, 18+sizeof(struct aura_packet8), expected[1]);
55  queue_packet(pkt, buf, 20+sizeof(struct aura_packet8), expected[1]);
56  /* packet overlapping data */
57  queue_packet(pkt, buf, 64, expected[2]);
58  queue_packet(pkt, buf, 64 + sizeof(struct aura_packet8), expected[2]);
59 
60  queue_packet(pkt, buf, 90, expected[3]);
61  int i;
62 
63  /* First, let's feed it byte by byte */
64  for (i=0; i<256; i++)
65  aura_packetizer_feed(pkt, &buf[i], 1);
66  curpacket = 0;
67  /* Next, in one chunk */
68  aura_packetizer_feed(pkt, buf, 256);
69  /* Clean up, let valgrind do it's job */
70  aura_packetizer_destroy(pkt);
71  aura_close(node);
72  return numfails;
73 }
uint32_t aura_buffer_get_u32(struct aura_buffer *buf)
Get an unsigned 32 bit integer from aura buffer.
struct aura_node * aura_open(const char *name, const char *opts)
Definition: aura.c:34
void aura_buffer_release(struct aura_buffer *buf)
Definition: buffer.c:80
void aura_close(struct aura_node *node)
Definition: aura.c:102