1# 2# Copyright 2016, 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(D61_BSD) 11# 12 13void server_{{fname}}(void *rpc_userptr) {\n 14 15____rpc_sv_init(rpc_userptr);\n\n 16 17{{for type, itype, name, mode, dr, apfx, aref, apsfx in alist}} 18 ____ 19 20 {{if itype in ['buf', 'buf_array'] and mode != 'array'}} 21 {{py:type = type.replace('*', '') + '*'}} 22 {{endif}} 23 24 {{if mode == 'array'}} 25 rpc_buffer_t rpc_{{name}} = (rpc_buffer_t) 26 {{elif (itype != 'buf' and type != 'str') or mode == 'array'}} 27 {{type}} rpc_{{name}} = ({{type}}) 28 {{else}} 29 {{type}} rpc_{{name}} = rpc_malloc(sizeof({{type.replace('*', '')}}));\n 30 ____ 31 {{endif}} 32 33 rpc_sv_pop_{{itype}}{{apfx}}( 34 rpc_userptr 35 {{if itype == 'buf' and mode != 'array'}} 36 , rpc_{{name}} 37 {{endif}} 38 {{if itype in ['buf', 'buf_array']}} 39 , sizeof({{type.replace('*', '')}}) 40 {{endif}} 41 );\n 42{{endfor}} 43 44{{for type, itype, name, mode, dr, apfx, aref, apsfx in oalist}} 45 ____ 46 {{if itype == 'buf'}} 47 {{if mode == 'array'}} 48 {{py: lenv = 'rpc_' + apsfx.replace(', ', '')}} 49 rpc_buffer_t rpc_{{name}};\n 50 ____rpc_{{name}}.data = rpc_malloc({{lenv}} * sizeof({{type.replace('*', '')}}));\n 51 ____rpc_{{name}}.count = {{lenv}};\n 52 {{else}} 53 {{type.replace('*', '')}}* rpc_{{name}} = rpc_malloc(sizeof({{type.replace('*', '')}}));\n 54 {{endif}} 55 {{elif itype == 'str'}} 56 {{type}} rpc_{{name}} = rpc_malloc(RPC_DEFAULT_CHARBUF_SIZE); 57 // WARNING: This is not safe!\n 58 {{else}} 59 {{type}} rpc_{{name}} = 0; 60 {{if name != '__ret__'}} 61 // WARNING: Cannot have output type int.\n 62 {{endif}} 63 {{endif}} 64{{endfor}} 65\n 66 67{{for type, itype, name, mode, dr, apfx, aref, apsfx in calist}} 68 {{if mode == 'array'}} 69 ____rpc_sv_track_obj(rpc_userptr, rpc_{{name}}.data);\n 70 {{elif not itype in ['uint', 'cptr']}} 71 ____rpc_sv_track_obj(rpc_userptr, rpc_{{name}});\n 72 {{endif}} 73{{endfor}} 74\n 75 76{{for type, itype, name, mode, dr, apfx, aref, apsfx in ralist}} 77 {{if mode == 'array'}} 78 ____rpc_sv_track_obj(rpc_userptr, rpc_{{name}}.data);\n 79 {{elif not itype in ['uint', 'cptr']}} 80 ____rpc_sv_track_obj(rpc_userptr, rpc_{{name}});\n 81 {{endif}} 82{{endfor}} 83\n 84 85____ 86{{if return_type != 'void'}} 87 {{for type, itype, name, mode, dr, apfx, aref, apsfx in ralist}} 88 {{if aref == '&'}}{{py: aref = '*'}}{{endif}} 89 {{aref}}rpc_{{name}} = 90 {{break}} 91 {{endfor}} 92{{endif}} 93 {{fname}}_handler(rpc_userptr 94 {{for type, itype, name, mode, dr, apfx, aref, apsfx in calist}} 95 {{if mode == 'length' or mode == 'connect_ep'}}{{continue}}{{endif}} 96 {{if aref == '&'}} 97 {{# Since bufrefs have been sent over as ordinary buffers, we need to deref them 98 # before passing into the impl function.}} 99 {{py: aref = '*'}} 100 {{endif}} 101 {{if mode == 'array'}}{{py: aref = ''}}{{endif}} 102 , {{aref}}rpc_{{name}} 103 {{endfor}} 104);\n\n 105 106____reply_{{fname}}(rpc_userptr 107 {{for type, itype, name, mode, dr, apfx, aref, apsfx in oalist}} 108 {{if aref == '&'}} 109 {{# Since bufrefs have been sent over as ordinary buffers, we need to deref them 110 # before passing into the reply function.}} 111 {{py: aref = '*'}} 112 {{endif}} 113 , {{aref}}rpc_{{name}} 114 {{endfor}} 115);\n 116 117}\n\n 118 119void reply_{{fname}}(void *rpc_userptr 120 {{for type, itype, name, mode, dr, apfx, aref, apsfx in oalist}} 121 {{if mode == 'array'}}{{py: type = 'rpc_buffer_t'}}{{endif}} 122 , {{type}} rpc_{{name}} 123 {{endfor}} 124 ) {\n 125 126____rpc_reset_contents(rpc_userptr);\n 127 128{{for type, itype, name, mode, dr, apfx, aref, apsfx in oalist}} 129 ____rpc_sv_push_{{itype}}{{apfx}}( 130 rpc_userptr, {{aref}}rpc_{{name}} 131 {{if itype == 'buf'}} 132 , sizeof({{type.replace('*', '')}}) 133 {{endif}} 134 );\n 135{{endfor}} 136\n 137____rpc_sv_reply(rpc_userptr);\n 138____rpc_sv_free_tracked_objs(rpc_userptr);\n 139____rpc_sv_release(rpc_userptr);\n 140} 141\n 142