a8b6fd72bc2fc0a97cf16e0761a5a9892affb950
[barrelfish] / lib / int_route / client / client.c
1 /**
2  * \file
3  * \brief Contains helper functions for clients of the interrupt routing service
4  */
5
6 /*
7  * Copyright (c) 2009, 2010, 2012, ETH Zurich.
8  * All rights reserved.
9  *
10  * This file is distributed under the terms in the attached LICENSE file.
11  * If you do not find this file, copies can be found by writing to:
12  * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
13  */
14 #include <stdio.h>
15 #include <string.h>
16
17 #include <barrelfish/barrelfish.h>
18 #include <barrelfish/nameservice_client.h>
19 #include <skb/skb.h> // read list
20 #include <int_route/int_route_client.h>
21 #include <int_route/int_route_debug.h>
22
23 #include <if/int_route_service_defs.h>
24 //#include <if/int_route_service_rpcclient_defs.h>
25
26 static struct int_route_state {
27     bool request_done;
28     struct int_route_rpc_client * client;
29     struct int_route_service_binding * binding;
30
31 } int_route_state_st;
32
33
34 static struct int_route_state * get_int_route_state(void){
35     return &int_route_state_st;
36 }
37
38 static void bind_cb(void *st, errval_t binderr, struct int_route_service_binding *b) {
39     assert(err_is_ok(binderr));
40     get_int_route_state()->binding = b;
41 }
42
43 //errval_t int_route_add_controller(int bus, int dev, int fun,
44 //        int_route_service_controller_type_t type) {
45 //    struct int_route_service_binding * b = get_int_route_state()->binding;
46 //    assert(b != null);
47 //    // int_route_service_pci_address_t addr, int_route_service_controller_type_t type
48 //    int_route_service_pci_address_t addr = {.bus = bus, .device = device, .fun = fun}
49 //    b->rx_vtbl.add_controller_call(b, addr, type);
50 //}
51 //
52 //
53 //errval_t int_route_route(struct capref intin, struct capref dest){
54 //    errval_t err;
55 //    struct int_route_service_binding * b = get_int_route_state()->binding;
56 //    assert(b != null);
57 //    return b->tx_vtbl.route_call(b, NULL, intin, dest);
58 //}
59
60 errval_t int_route_client_connect(void){
61     errval_t err;
62     iref_t iref;
63     struct int_route_state *state = get_int_route_state();
64
65     /* check if the RPC client already has been initialized */
66     if (state->binding != NULL) {
67         return SYS_ERR_OK;
68     }
69
70     err = nameservice_blocking_lookup("int_route_service", &iref);
71     if (err_is_fail(err)) {
72         return err;
73     }
74
75     state->request_done = false;
76     err = int_route_service_bind(iref, bind_cb, NULL, get_default_waitset(),
77                    IDC_BIND_FLAGS_DEFAULT);
78     if (err_is_fail(err)) {
79         return err_push(err, FLOUNDER_ERR_BIND);
80     }
81
82     /* XXX: wait for connection to complete */
83     while (!state->request_done) {
84         messages_wait_and_handle_next();
85     }
86
87     return SYS_ERR_OK;
88 }