<'
# Copyright (c) 2012-2017, 2019-2020, 2022-2023, 2025-2026 LAAS/CNRS
# All rights reserved.
#
# Redistribution and use  in source  and binary  forms,  with or without
# modification, are permitted provided that the following conditions are
# met:
#
#   1. Redistributions of  source  code must retain the  above copyright
#      notice and this list of conditions.
#   2. Redistributions in binary form must reproduce the above copyright
#      notice and  this list of  conditions in the  documentation and/or
#      other materials provided with the distribution.
#
#                                      Anthony Mallet on Wed Mar 14 2012
#

args components
lang c
'>

<'foreach c $components {'>
<'  set comp [$c name]'>

/* <"[--- $comp =========================================================] "> */

#include "<"$comp">/c/client.h"

enum {
<'  foreach s [$c services] {'>
  genom_<"$comp">_svc_<"[$s name]">_index,
<'  }'>
  genom_<"$comp">_svc_max
};

enum {
<'  foreach p [$c ports out] {'>
  genom_<"$comp">_pout_<"[$p name]">_index,
<'  }'>
  genom_<"$comp">_pout_max
};

enum {
<'  foreach p [$c ports in] {'>
  genom_<"$comp">_pin_<"[$p name]">_index,
<'  }'>
  genom_<"$comp">_pin_max
};

static const struct genom_service_info genom_<"$comp">_service_info[] = {
<'  foreach s [$c services] {'>
  [genom_<"$comp">_svc_<"[$s name]">_index] = {
    .name = "<"[$s name]">",
    .input = "<"[string map {\" \\\"} [json-param $s in inout]]">",
    .output = "<"[string map {\" \\\"} [json-param $s inout out]]">",
    .meta = "<"[string map {\" \\\"} [json-param-meta $s in inout out]]">",
    .init_input = (genom_initfn)
    genom_<"$comp">_client_<"[$s name]">_init_input,
    .init_output = (genom_initfn)
    genom_<"$comp">_client_<"[$s name]">_init_output,
    .fini_input = (genom_finifn)
    genom_<"$comp">_client_<"[$s name]">_fini_input,
    .fini_output = (genom_finifn)
    genom_<"$comp">_client_<"[$s name]">_fini_output,
    .json_scan = (genom_json_scanfn)
    genom_<"$comp">_client_<"[$s name]">_json_scan,
    .json_print = (genom_json_printfn)
    genom_<"$comp">_client_<"[$s name]">_json_print,
    .send = (genom_request_sendfn)
    genom_<"$comp">_client_<"[$s name]">_rqst,
    .input_size = sizeof(struct genom_<"$comp">_<"[$s name]">_input),
    .output_size = sizeof(struct genom_<"$comp">_<"[$s name]">_output)
  },
<'  }'>
  { .name = NULL }
};

static const struct genom_port_info genom_<"$comp">_port_info[] = {
<'  foreach p [$c ports out] {'>
  [genom_<"$comp">_pout_<"[$p name]">_index] = {
    .name = "<"[$p name]">",
    .datatype = "<"[string map {\" \\\"} [json-port $p]]">",
    .meta = "<"[string map {\" \\\"} [json-port-meta $p]]">",
    .init_data = (genom_initfn)
    genom_<"$comp">_client_<"[$p name]">_init_data,
    .fini_data = (genom_finifn)
    genom_<"$comp">_client_<"[$p name]">_fini_data,
    .json_print = (genom_json_printfn)
    genom_<"$comp">_client_<"[$p name]">_json_print,
<'    if {"multiple" in [$p kind]} {'>
    .simple = 0,
    .data.multiple = (genom_port_multiple_datafn)
    genom_<"$comp">_client_<"[$p name]">_data,
    .read.multiple = (genom_port_multiple_readfn)
    genom_<"$comp">_client_<"[$p name]">_read,
<'    } else {'>
    .simple = 1,
    .data.simple = (genom_port_datafn)
    genom_<"$comp">_client_<"[$p name]">_data,
    .read.simple = (genom_port_readfn)
    genom_<"$comp">_client_<"[$p name]">_read,
<'    }'>
    .data_size = sizeof(<"[[$p datatype] declarator]">)
  },
<'  }'>
  { .name = NULL, .simple = 1 }
};

static const struct genom_pub_info genom_<"$comp">_pub_info[] = {
<'  foreach p [$c ports in] {'>
  [genom_<"$comp">_pin_<"[$p name]">_index] = {
    .name = "<"[$p name]">",
    .datatype = "<"[string map {\" \\\"} [json-port $p]]">",
    .meta = "<"[string map {\" \\\"} [json-port-meta $p]]">",
    .init_data = (genom_initfn)
    genom_<"$comp">_client_<"[$p name]">_init_data,
    .fini_data = (genom_finifn)
    genom_<"$comp">_client_<"[$p name]">_fini_data,
    .json_print = (genom_json_printfn)
    genom_<"$comp">_client_<"[$p name]">_json_print,
    .json_scan = (genom_json_scanfn)
    genom_<"$comp">_client_<"[$p name]">_json_scan,
    .open = genom_<"$comp">_client_<"[$p name]">_open,
    .close = genom_<"$comp">_client_<"[$p name]">_close,
    .data = (genom_port_multiple_datafn)
    genom_<"$comp">_client_<"[$p name]">_data,
    .write = (genom_port_multiple_writefn)
    genom_<"$comp">_client_<"[$p name]">_write,
    .data_size = sizeof(<"[[$p datatype] declarator]">)
  },
<'  }'>
  { .name = NULL }
};

const struct genom_client_info genom_<"$comp">_client_info = {
  .protocol = genom_client_protocol,
  .name = "<"$comp">",
  .options = genom_<"$comp">_options,

  .init = genom_<"$comp">_client_init,
  .fini = genom_<"$comp">_client_fini,
  .context = genom_<"$comp">_client_context,
  .instance = genom_<"$comp">_client_instance,
  .eventfd = genom_<"$comp">_client_eventfd,
  .service_info = genom_<"$comp">_client_service_info,
  .done = genom_<"$comp">_client_done,
  .wait = genom_<"$comp">_client_wait,
  .result = genom_<"$comp">_client_result,
  .clean = genom_<"$comp">_client_clean,
  .abort = genom_<"$comp">_client_abort,
  .doevents = genom_<"$comp">_client_doevents,
  .json_error = genom_<"$comp">_client_json_error,

  .nservices = <"[llength [$c services]]">,
  .services = genom_<"$comp">_service_info,

  .nports = <"[llength [$c ports out]]">,
  .ports = genom_<"$comp">_port_info,

  .npubs = <"[llength [$c ports in]]">,
  .pubs = genom_<"$comp">_pub_info
};

<'  foreach s [$c services] {'>
const struct genom_service_info *genom_<"$comp">_client_<"[$s name]">_info =
  &genom_<"$comp">_client_info
  .services[genom_<"$comp">_svc_<"[$s name]">_index];
<'  }'>

<'  foreach p [$c ports out] {'>
const struct genom_port_info *genom_<"$comp">_client_<"[$p name]">_info =
  &genom_<"$comp">_client_info
  .ports[genom_<"$comp">_pout_<"[$p name]">_index];
<'  }'>

<'  foreach p [$c ports in] {'>
const struct genom_pub_info *genom_<"$comp">_client_<"[$p name]">_info =
  &genom_<"$comp">_client_info
  .pubs[genom_<"$comp">_pin_<"[$p name]">_index];
<'  }'>

<'}'>
/* eof */
