pinger.c 1.41 KB
Newer Older
jdelange's avatar
jdelange committed
1
#include <stdio.h>
2
3
#include <request.h>
#include <deployment.h>
jdelange's avatar
jdelange committed
4
#include <po_hi_storage.h>
5
#include <po_hi_gqueue.h>
jdelange's avatar
jdelange committed
6
7

__po_hi_storage_packet_store_t packet_store;
jdelange's avatar
jdelange committed
8
9
10
11

void user_produce_pkts_init ()
{
  printf ("*** INIT PACKET PRODUCER ***\n");
jdelange's avatar
jdelange committed
12
13
14
15
16

  if (__po_hi_storage_packet_store_new (&packet_store) != __PO_HI_SUCCESS)
  {
      printf ("*** /!\ ERROR WHEN CREATING THE PACKET STORE /!\ ***\n");
  }
jdelange's avatar
jdelange committed
17
18
19
  fflush (stdout);
}

jdelange's avatar
jdelange committed
20
void user_produce_pkts ()
jdelange's avatar
jdelange committed
21
{
jdelange's avatar
jdelange committed
22
  static int p = 0;
jdelange's avatar
jdelange committed
23
  int ret;
jdelange's avatar
jdelange committed
24

jdelange's avatar
jdelange committed
25
  __po_hi_request_t pkt;
jdelange's avatar
jdelange committed
26
27
28
  pkt.vars.pinger_global_data_source.pinger_global_data_source = p;
  pkt.port = pinger_global_data_source;

jdelange's avatar
jdelange committed
29
30
  printf ("*** PRODUCE PKT WITH VALUE *** %d\n", p);
  p++;
jdelange's avatar
jdelange committed
31
32
33
34
35
36
37
38

  ret = __po_hi_storage_packet_store_write (&packet_store, &pkt);

  if (ret != __PO_HI_SUCCESS)
  {
      printf ("*** /!\\ ERROR WHEN WRITING A PACKET IN THE STORE (ret=%d) /!\\ ***\n", ret);
  }

jdelange's avatar
jdelange committed
39
40
  fflush (stdout);
}
jdelange's avatar
jdelange committed
41
42


jdelange's avatar
jdelange committed
43
44
void user_do_ping_spg ()
{
jdelange's avatar
jdelange committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

  int ret;
  __po_hi_request_t pkt;
  ret = __po_hi_storage_packet_store_read (&packet_store, &pkt);

  if (ret != __PO_HI_SUCCESS)
  {
      printf ("*** /!\\ ERROR WHEN READING A PACKET IN THE STORE /!\\ ***\n");

      if (ret == __PO_HI_UNAVAILABLE)
      {
         printf ("*** /!\\ ;_; NO PACKET AVAILABLE AT THIS TIME ;_; /!\\ ***\n");
      }
  }
  else
  {
      printf ("*** SENDING PKT *** \n");
      __po_hi_gqueue_store_out (node_a_pinger_k, pinger_local_data_source, &(pkt));
  }
jdelange's avatar
jdelange committed
64
65
  fflush (stdout);
}