<'
# Copyright (c) 2012-2013, 2017-2018, 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
#

if {[llength $argv] != 1} { error "expected arguments: component" }
lassign $argv component

# compute handy shortcuts
set comp [$component name]
set COMP [string toupper [$component name]]

lang c
'>
#include "autoconf/acheader.h"

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

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

genom_public 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,
                  "<"[string map {\" \\\"} [json-param-defval $s in inout]]">",
                  NULL);
}

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

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

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

<'}'>
