2 * \brief DOpE client library - L4 specific initialisation
4 * \author Norman Feske <nf2@inf.tu-dresden.de>
8 * Copyright (C) 2002-2003 Norman Feske <nf2@os.inf.tu-dresden.de>
9 * Technische Universitaet Dresden, Operating Systems Research Group
11 * This file is part of the DOpE package, which is distributed under
12 * the terms of the GNU General Public Licence 2. Please see the
13 * COPYING file for details.
16 /*** GENERAL INCLUDES ***/
21 #include <l4/util/util.h>
22 #include <l4/sys/factory.h>
23 #include <l4/sys/icu.h>
24 #include <l4/re/c/namespace.h>
25 #include <l4/re/c/util/cap_alloc.h>
26 #include <l4/re/c/dataspace.h>
27 #include <l4/re/c/event.h>
28 #include <l4/re/c/event_buffer.h>
29 #include <l4/re/c/rm.h>
31 #include <pthread-l4.h>
33 /*** LOCAL INCLUDES ***/
39 l4_cap_idx_t dope_server;
42 static l4re_event_buffer_consumer_t ev_buf;
44 struct dopelib_mutex *dopelib_cmdf_mutex;
45 struct dopelib_mutex *dopelib_cmd_mutex;
48 void dopelib_usleep(int usec);
49 void dopelib_usleep(int usec) {
53 void dope_process_event(l4re_event_t *ev);
55 /*** INTERFACE: HANDLE EVENTLOOP OF A DOpE CLIENT ***/
56 void dope_eventloop(void)
58 l4re_event_buffer_consumer_process(&ev_buf, ev_irq,
59 pthread_getl4cap(pthread_self()),
63 l4re_event_t *dope_event_get(void)
65 return l4re_event_buffer_next(&ev_buf);
68 /*** INTERFACE: CONNECT TO DOpE SERVER AND INIT CLIENT LIB ***
70 * return 0 on success, != 0 otherwise
74 static int initialized;
77 /* avoid double initialization */
81 INFO(printf("DOpElib(dope_init): ask for 'dope'...\n"));
83 dope_server = l4re_get_env_cap("dope");
84 if (l4_is_invalid_cap(dope_server))
86 ERROR(printf("no 'dope' cap found!\n"));
90 INFO(printf("DOpElib(dope_init): found some DOpE.\n"));
92 ev_ds = l4re_util_cap_alloc();
93 ev_irq = l4re_util_cap_alloc();
95 if (l4_is_invalid_cap(ev_irq))
97 l4re_util_cap_free(ev_ds);
101 if (l4_error(l4_factory_create_irq(l4re_env()->factory, ev_irq)))
103 l4re_util_cap_free(ev_ds);
104 l4re_util_cap_free(ev_irq);
108 if (l4_error(l4_icu_bind(dope_server, 0, ev_irq)))
110 l4re_util_cap_free_um(dope_server);
111 l4re_util_cap_free(ev_ds);
112 l4re_util_cap_free_um(ev_irq);
116 if (l4re_event_get(dope_server, ev_ds))
118 ERROR(printf("Did not get the event object!\n"));
119 l4re_util_cap_free_um(ev_ds);
120 l4re_util_cap_free_um(ev_irq);
125 ds_size = l4re_ds_size(ev_ds);
129 if (l4re_event_buffer_attach(&ev_buf, ev_ds, l4re_env()->rm))
132 /* create mutex to make dope_cmdf and dope_cmd thread save */
133 dopelib_cmdf_mutex = dopelib_mutex_create(0);
134 dopelib_cmd_mutex = dopelib_mutex_create(0);