// demo comp - a remote component

component remote "demonstrate a remote component";

pin in  float to_remote    "a value passed to a remote HAL component";
pin in  float from_remote  "a value updated by a remote HAL component";

function _;

option singleton yes;
option rtapi_app no;

license "GPLv2 or later";
;;

#include "hal.h"

static char *name = "remote";

FUNCTION(_) {
    // this is not needed, but comp currently insists on
    // a thread function
}

int rtapi_app_main(void)
{
    int retval;

    comp_id = hal_xinit(TYPE_REMOTE, 0, 0, NULL, NULL, name);
    if (comp_id < 0) {
	rtapi_print_msg(RTAPI_MSG_ERR,
			"%s: ERROR: hal_init_remote() failed: %d\n",
			name, comp_id);
	return -1;
    }
    if ((retval = export(name, 0))) {
	rtapi_print_msg(RTAPI_MSG_ERR,
			"%s: ERROR: export(%s) failed: %d\n",
			name, name, retval);
	return -1;
    }
    // transition state to COMP_UNBOUND
    hal_ready(comp_id);
    // linking of pins now possible

    rtapi_print_msg(RTAPI_MSG_DBG,
		    "%s:  component initialized\n", name);

    return 0;
}

void rtapi_app_exit(void)
{
    hal_exit(comp_id);
}
