libubx/ubx.c
int ubx_port_add(ubx_block_t *b, const char *name, const char *doc,
	     const char *in_type_name, long in_data_len,
	     const char *out_type_name, long out_data_len, uint32_t state)
{
	int i, ret;
	ubx_port_t *parr;
	ubx_type_t *in_type = NULL, *out_type = NULL;

	if (b == NULL) {
		ret = EINVALID_BLOCK;
		goto out;
	}

	if (b->prototype == NULL) {
		ubx_err(b, "modifying prototype block not allowed");
		ret = EINVALID_BLOCK_TYPE;
		goto out;
	}

	if (in_type_name) {
		in_type = ubx_type_get(b->ni, in_type_name);
		if (in_type == NULL) {
			ubx_err(b, "failed to resolve in_type %s", in_type_name);
			ret = EINVALID_TYPE;
			goto out;
		}
	}

	if (out_type_name) {
		out_type = ubx_type_get(b->ni, out_type_name);
		if (out_type == NULL) {
			ubx_err(b, "failed to resolve out_type %s", out_type_name);
			ret = EINVALID_TYPE;
			goto out;
		}
	}

	if (ubx_port_get(b, name)) {
		ubx_err(b, "port_add: %s already exists", name);
		ret = EENTEXISTS;
		goto out;
	}

	i = get_num_ports(b);

	parr = realloc(b->ports, (i + 2) * sizeof(ubx_port_t));

	if (parr == NULL) {
		ubx_err(b, "out of mem, port not added");
		ret = EOUTOFMEM;
		goto out;
	}

	b->ports = parr;

	/* setup port */
	ret = ubx_clone_port_data(&b->ports[i], name, doc,
				in_type, in_data_len,
				out_type, out_data_len, state);

	b->ports[i].block = b;

	if (ret) {
		ubx_err(b, "cloning port data failed");
		memset(&b->ports[i], 0x0, sizeof(ubx_port_t));
		/* nothing else to cleanup, really */
	}

	/* set dummy stopper to NULL */
	memset(&b->ports[i + 1], 0x0, sizeof(ubx_port_t));

 out:
	return ret;
}
/**
 * ubx_port_add - a port to a block instance and resolve types.
 *
 * @param b
 * @param name
 * @param doc
 * @param in_type_name
 * @param in_data_len
 * @param out_type_name
 * @param out_data_len
 * @param state
 *
 * @return < 0 in case of error, 0 otherwise.
 */
a port to a block instance and resolve types.

@return < 0 in case of error, 0 otherwise.
a port to a block instance and resolve types . @return < 0 in case of error 0 otherwise .
int ubx_port_add(ubx_block_t *b, const char *name, const char *doc,
	     const char *in_type_name, long in_data_len,
	     const char *out_type_name, long out_data_len, uint32_t state)
{
	int i, ret;
	ubx_port_t *parr;
	ubx_type_t *in_type = NULL, *out_type = NULL;
	if (b == NULL) {
		ret = EINVALID_BLOCK;
		goto out;
	}
	if (b->prototype == NULL) {
		ubx_err(b, "modifying prototype block not allowed");
		ret = EINVALID_BLOCK_TYPE;
		goto out;
	}
	if (in_type_name) {
		in_type = ubx_type_get(b->ni, in_type_name);
		if (in_type == NULL) {
			ubx_err(b, "failed to resolve in_type %s", in_type_name);
			ret = EINVALID_TYPE;
			goto out;
		}
	}
	if (out_type_name) {
		out_type = ubx_type_get(b->ni, out_type_name);
		if (out_type == NULL) {
			ubx_err(b, "failed to resolve out_type %s", out_type_name);
			ret = EINVALID_TYPE;
			goto out;
		}
	}
	if (ubx_port_get(b, name)) {
		ubx_err(b, "port_add: %s already exists", name);
		ret = EENTEXISTS;
		goto out;
	}
	i = get_num_ports(b);
	parr = realloc(b->ports, (i + 2) * sizeof(ubx_port_t));
	if (parr == NULL) {
		ubx_err(b, "out of mem, port not added");
		ret = EOUTOFMEM;
		goto out;
	}
	b->ports = parr;
	ret = ubx_clone_port_data(&b->ports[i], name, doc,
				in_type, in_data_len,
				out_type, out_data_len, state);
	b->ports[i].block = b;
	if (ret) {
		ubx_err(b, "cloning port data failed");
		memset(&b->ports[i], 0x0, sizeof(ubx_port_t));
	}
	memset(&b->ports[i + 1], 0x0, sizeof(ubx_port_t));
 out:
	return ret;
}
int ubx_port_add ( ubx_block_t * b , const char * name , const char * doc , const char * in_type_name , long in_data_len , const char * out_type_name , long out_data_len , uint32_t state ) { int i , ret ; ubx_port_t * parr ; ubx_type_t * in_type = NULL , * out_type = NULL ; if ( b == NULL ) { ret = EINVALID_BLOCK ; goto out ; } if ( b -> prototype == NULL ) { ubx_err ( b , " " ) ; ret = EINVALID_BLOCK_TYPE ; goto out ; } if ( in_type_name ) { in_type = ubx_type_get ( b -> ni , in_type_name ) ; if ( in_type == NULL ) { ubx_err ( b , " " , in_type_name ) ; ret = EINVALID_TYPE ; goto out ; } } if ( out_type_name ) { out_type = ubx_type_get ( b -> ni , out_type_name ) ; if ( out_type == NULL ) { ubx_err ( b , " " , out_type_name ) ; ret = EINVALID_TYPE ; goto out ; } } if ( ubx_port_get ( b , name ) ) { ubx_err ( b , " " , name ) ; ret = EENTEXISTS ; goto out ; } i = get_num_ports ( b ) ; parr = realloc ( b -> ports , ( i + 2 ) * sizeof ( ubx_port_t ) ) ; if ( parr == NULL ) { ubx_err ( b , " " ) ; ret = EOUTOFMEM ; goto out ; } b -> ports = parr ; ret = ubx_clone_port_data ( & b -> ports [ i ] , name , doc , in_type , in_data_len , out_type , out_data_len , state ) ; b -> ports [ i ] . block = b ; if ( ret ) { ubx_err ( b , " " ) ; memset ( & b -> ports [ i ] , 0x0 , sizeof ( ubx_port_t ) ) ; } memset ( & b -> ports [ i + 1 ] , 0x0 , sizeof ( ubx_port_t ) ) ; out : return ret ; }
ubx_port_add - a port to a block instance and resolve types.
ubx_port_add - a port to a block instance and resolve types .
/* setup port */ /* nothing else to cleanup, really */ /* set dummy stopper to NULL */