1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13/*- import 'helpers/error.c' as error with context -*/
14/*- import 'helpers/marshal.c' as marshal with context -*/
15
16/*? assert(isinstance(connector, namespace)) ?*/
17
18#include <sel4/sel4.h>
19#include <assert.h>
20#include <limits.h>
21#include <stddef.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sync/sem-bare.h>
25#include <camkes/dataport.h>
26#include <camkes/error.h>
27#include <camkes/marshal_macros.h>
28#include <camkes/tls.h>
29
30/*? macros.show_includes(me.instance.type.includes) ?*/
31/*? macros.show_includes(me.interface.type.includes) ?*/
32
33/*- set methods_len = len(me.interface.type.methods) -*/
34/*- set instance = me.instance.name -*/
35/*- set interface = me.interface.name -*/
36
37/* Interface-specific error handling */
38/*- set error_handler = '%s_error_handler' % me.interface.name -*/
39/*? error.make_error_handler(interface, error_handler) ?*/
40
41#define CAMKES_INTERFACE_NAME "/*? interface ?*/"
42#define CAMKES_INSTANCE_NAME "/*? instance ?*/"
43#define CAMKES_ERROR_HANDLER /*? error_handler ?*/
44
45/*- for i, m in enumerate(me.interface.type.methods) -*/
46
47/*- set input_parameters = list(filter(lambda('x: x.direction in [\'refin\', \'in\', \'inout\']'), m.parameters)) -*/
48/*? marshal.make_marshal_input_symbols(m.name, '%s_marshal_inputs' % m.name, i, methods_len, input_parameters) ?*/
49
50/*- set output_parameters = list(filter(lambda('x: x.direction in [\'out\', \'inout\']'), m.parameters)) -*/
51/*? marshal.make_unmarshal_output_symbols(m.name, '%s_unmarshal_outputs' % m.name, i, output_parameters, m.return_type, connector.recv_buffer_size_fixed) ?*/
52
53/*- if m.return_type is not none --*/
54    /*? macros.show_type(m.return_type) ?*/ /*- else -*/
55    void /*- endif -*/
56/*?- me.interface.name ?*/_/*? m.name ?*/(/*? marshal.show_input_parameter_list(m.parameters, ['in', 'refin', 'out', 'inout'], namespace_prefix='p_') ?*/)
57{
58
59    /*? begin_send(connector) ?*/
60
61    unsigned size;
62    /*-- if m.return_type is not none -*/
63      /*? macros.show_type(m.return_type) ?*/ return_val;
64      /*? macros.show_type(m.return_type) ?*/ *return_ptr = &return_val;
65    /*- endif -*/
66
67    /* Marshal all the parameters */
68    unsigned length = /*? marshal.call_marshal_input('%s_marshal_inputs' % m.name, connector.send_buffer, connector.send_buffer_size, input_parameters, namespace_prefix='p_') ?*/;
69    if (unlikely(length == UINT_MAX)) {
70        /* Error in marshalling; bail out. */
71        /*-- if m.return_type is not none -*/
72            /*-- if m.return_type == 'string' -*/
73                return NULL;
74            /*-- else -*/
75                memset(return_ptr, 0, sizeof(* return_ptr));
76                return * return_ptr;
77            /*- endif -*/
78        /*-- else -*/
79            return;
80        /*-- endif -*/
81    }
82
83    /*? perform_call(connector, "size", "length", namespace_prefix='rpc_') ?*/
84
85    /* Unmarshal the response */
86    int err = /*? marshal.call_unmarshal_output('%s_unmarshal_outputs' % m.name, connector.recv_buffer, "size", output_parameters, m.return_type, "return_ptr", namespace_prefix='p_') ?*/;
87    if (unlikely(err != 0)) {
88        /* Error in unmarshalling; bail out. */
89        /*-- if m.return_type is not none -*/
90            /*-- if m.return_type == 'string' -*/
91                return NULL;
92            /*-- else -*/
93                memset(return_ptr, 0, sizeof(* return_ptr));
94                return * return_ptr;
95            /*-- endif -*/
96        /*-- else -*/
97            return;
98        /*-- endif -*/
99    }
100
101    /*? release_recv(connector) ?*/
102
103    /*- if m.return_type is not none -*/
104        return *return_ptr;
105    /*- endif -*/
106}
107/*- endfor -*/
108