]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ferret/examples/monitors/merge_mon/poll.c
update
[l4.git] / l4 / pkg / ferret / examples / monitors / merge_mon / poll.c
1 /**
2  * \file   ferret/examples/merge_mon/poll.c
3  * \brief  polls for outstanding sensors
4  *
5  * \date   2007-11-27
6  * \author Ronald Aigner  <ra3@os.inf.tu-dresden.de>
7  */
8 /*
9  * (c) 2007-2009 Technische Universität Dresden
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  */
14
15 #include <stdio.h>
16
17 #include <l4/sys/cache.h>
18 #include <l4/util/util.h>
19
20 #include <l4/ferret/monitor.h>
21 #include <l4/ferret/comm.h>
22 #include <l4/ferret/sensors/list_consumer.h>
23 //#include <l4/ferret/sensors/tbuf_consumer.h>
24
25 #include "poll.h"
26 #include "main.h"
27
28 static void polling_thread(void* arg)
29 {
30     int searching = 1;
31     int i, ret;
32     uint16_t type;
33
34     while (searching)
35     {
36         l4_sleep(1000);
37         searching = 0;
38
39         for (i = 0; i < sensor_count; i++)
40         {
41             if (sensors[i].open)
42                 continue;
43
44                         l4_cap_idx_t srv = lookup_sensordir();
45
46             searching = 1;
47             ret = ferret_att(srv, sensors[i].major, sensors[i].minor,
48                              sensors[i].instance, sensors[i].sensor);
49             if (ret)
50             {
51                 if (verbose)
52                 {
53                     printf("Still could not attach to %hu:%hu:%hu, retrying!\n",
54                            sensors[i].major, sensors[i].minor,
55                            sensors[i].instance);
56                 }
57                 continue;
58             }
59
60             // this looks a bit racy ...
61             sensors[i].copied    = 0;
62             sensors[i].last_lost = 0;
63             sensors[i].last_ts   = 0;
64
65             type = ((ferret_common_t *)(sensors[i].sensor))->type;
66             if (type != FERRET_LIST && type != FERRET_TBUF)
67             {
68                 printf("Found wrong sensor type (%d): %hu!\n", i, type);
69             }
70
71             if (verbose)
72             {
73                 printf("Attached to %hu:%hu:%hu.\n",
74                        sensors[i].major, sensors[i].minor,
75                        sensors[i].instance);
76             }
77
78             __asm__ __volatile__("": : :"memory");  // barrier
79             sensors[i].open = 1;
80         }
81     }
82 }
83
84 void poll_sensors(void)
85 {
86     l4thread_create_named(polling_thread, ".poll", 0, L4THREAD_CREATE_ASYNC);
87 }