<'
# 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 Thu Mar 15 2012
#

args components
lang c
'>
#include "typeops-c.h"

#define genom_mkstr(...) #__VA_ARGS__

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

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

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

<'  foreach s [$c services] {'>

/* <"[--- Service [$s name] data init/fini ------------------------------]"> */

void
genom_<"$comp">_client_<"[$s name]">_init_input(
  struct genom_<"$comp">_<"[$s name]">_input *in)
{
<'    foreach p [$s parameters in inout] {'>
  genom_tinit_<"[[$p type] mangle]">(
    <"[[$p type] pass reference in->[$p name]]">);
<'    }'>

  /* set default value */
  genom_<"$comp">_client_<"[$s name]">_json_scan(
    in,
    genom_mkstr(<"[json-param-defval $s in inout]">),
    NULL);
}

void
genom_<"$comp">_client_<"[$s name]">_init_output(
  struct genom_<"$comp">_<"[$s name]">_output *out)
{
<'    if {![llength [$s parameters inout out]]} {'>
  (void)out; /* -Wunused-parameter */
<'    }'>
<'    foreach p [$s parameters inout out] {'>
  genom_tinit_<"[[$p type] mangle]">(
    <"[[$p type] pass reference out->[$p name]]">);
<'    }'>
}

void
genom_<"$comp">_client_<"[$s name]">_fini_input(
  struct genom_<"$comp">_<"[$s name]">_input *in)
{
<'    if {![llength [$s parameters in inout]]} {'>
  (void)in; /* -Wunused-parameter */
<'    }'>
<'    foreach p [$s parameters in inout] {'>
  genom_tfini_<"[[$p type] mangle]">(
    <"[[$p type] pass reference in->[$p name]]">);
<'    }'>
}

void
genom_<"$comp">_client_<"[$s name]">_fini_output(
  struct genom_<"$comp">_<"[$s name]">_output *out)
{
<'    if {![llength [$s parameters inout out]]} {'>
  (void)out; /* -Wunused-parameter */
<'    }'>
<'    foreach p [$s parameters inout out] {'>
  genom_tfini_<"[[$p type] mangle]">(
    <"[[$p type] pass reference out->[$p name]]">);
<'    }'>
}
<'  }'>

<'  foreach p [$component ports] {'>

/* <"[--- Port [$p name] data init/fini ---------------------------------]"> */

void
genom_<"$comp">_client_<"[$p name]">_init_data(
  <"[[$p datatype] argument reference data]">)
{
  genom_tinit_<"[[$p datatype] mangle]">(data);
}

void
genom_<"$comp">_client_<"[$p name]">_fini_data(
  <"[[$p datatype] argument reference data]">)
{
  genom_tfini_<"[[$p datatype] mangle]">(data);
}

<'  }'>
<'}'>
/* eof */
