2 * \file ferret/lib/monitor/monitor.cc
3 * \brief Functions to access sensors from monitors.
6 * \author Martin Pohlack <mp26@os.inf.tu-dresden.de>
7 * \author Bjoern Doebel <doebel@tudos.org>
10 * (c) 2009 Technische Universität Dresden
11 * This file is part of TUD:OS and distributed under the terms of the
12 * GNU General Public License 2.
13 * Please see the COPYING-GPL-2 file for details.
15 #include <l4/ferret/types.h>
18 #include <iostream> // std::cout
19 #include <l4/cxx/ipc_stream> // L4::Ipc::Iostream
20 #include <l4/re/util/cap_alloc> // L4::Cap
21 #include <l4/re/dataspace> // L4Re::Dataspace
22 #include <l4/re/mem_alloc> // mem_alloc()
23 #include <l4/re/rm> // L4::Rm
24 #include <l4/re/env> // L4::Env
27 //#include <l4/ferret/clock.h>
28 #include <l4/ferret/comm.h>
29 #include <l4/ferret/monitor.h>
30 #include <l4/ferret/monitor_list.h>
31 #include <l4/ferret/sensordir.h>
33 #include <l4/ferret/sensors/common.h>
34 #include <l4/ferret/sensors/list_consumer.h>
35 //#include <l4/ferret/sensors/dplist_consumer.h>
36 //#include <l4/ferret/sensors/slist_consumer.h>
37 //#include <l4/ferret/sensors/ulist_consumer.h>
38 //#include <l4/ferret/sensors/tbuf.h>
39 //#include <l4/ferret/sensors/tbuf_consumer.h>
41 int ferret_attach(l4_cap_idx_t srv,
42 uint16_t major, uint16_t minor,
43 uint16_t instance, void ** addr)
46 * Locally alloc a cap for the new DS
48 L4::Cap<L4Re::Dataspace> ds = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
50 L4::Ipc::Iostream s(l4_utcb());
51 s << l4_umword_t(Attach);
52 s << major << minor << instance;
53 s << L4::Ipc::Small_buf(ds.cap(), 0);
55 l4_msgtag_t res = s.call(srv, /* Protocol = */ Monitor);
56 if (l4_ipc_error(res, l4_utcb()))
58 std::cout << "IPC error in " << __func__ << "()\n";
74 std::cout << "Successfully attached. Got DS.\n";
78 std::cout << "No DS mapped during attach.\n";
82 err = L4Re::Env::env()->rm()->attach(addr, ds->size(),
83 L4Re::Rm::Search_addr,
87 std::cout << "Could not attach DS in " << __func__ << "\n";
88 std::cout << "Error: " << l4sys_errtostr(err) << "\n";
93 * Sensor-specific processing
95 switch(((ferret_common_t*)*addr)->type)
98 ferret_list_init_consumer(addr);
108 std::cout << "Failure attaching to sensor " << ret << "\n";
114 int ferret_detach(l4_cap_idx_t srv,
115 uint16_t major, uint16_t minor,
116 uint16_t instance, void ** addr)
118 L4::Ipc::Iostream s(l4_utcb());
119 s << l4_umword_t(Detach);
120 s << major << minor << instance;
122 l4_msgtag_t res = s.call(srv, /* Protocol = */ Monitor);
123 if (l4_ipc_error(res, l4_utcb()))
125 std::cout << "IPC error in " << __func__ << "()\n";
138 * Sensor-specific processing
140 switch(((ferret_common_t*)*addr)->type)
149 L4::Cap<L4Re::Dataspace> ds(((ferret_common_t*)*addr)->ds_cap);
151 int err = L4Re::Env::env()->rm()->detach(*addr, 0);
153 std::cout << "detach: " << err << "\n";
155 if (err == L4Re::Rm::Detached_ds)
157 l4_msgtag_t res = l4_task_unmap(L4RE_THIS_TASK_CAP,
158 ds.fpage(), L4_FP_ALL_SPACES);
161 std::cout << "unmap error: " << l4_error(res) << "\n";
167 std::cout << "Error detaching sensor ds.\n";
173 std::cout << "Failure detaching sensor: " << ret << "\n";
179 int ferret_list(l4_cap_idx_t srv __attribute__((unused)),
180 ferret_monitor_list_entry_t ** entries __attribute__((unused)),
181 int count __attribute__((unused)),
182 int offset __attribute__((unused)))
186 CORBA_Environment _dice_corba_env = dice_default_environment;
187 _dice_corba_env.malloc = (dice_malloc_func)malloc;
188 _dice_corba_env.free = (dice_free_func)free;
190 // get sensor_dir task id lazily
191 if (l4_is_invalid_id(ferret_sensor_dir))
192 ferret_sensor_dir = ferret_comm_get_threadid();
194 ret = ferret_monitor_list_call(&ferret_sensor_dir, entries, &count, offset,