return 0;
}
-static nw_port_type_t nw_port_setup_type(nw_port* port) {
- const char* type = nw_config_get(port->config, "TYPE");
- if (!type)
- return NW_PORT_UNKNOWN;
-
- return nw_port_type_from_string(type);
-}
-
static int nw_port_set_link(nw_port* port, nw_link* link) {
// Do nothing if the same link is being re-assigned
if (port->link == link)
if (r)
goto ERROR;
- // Determine type
- port->type = nw_port_setup_type(port);
- if (!port->type) {
- ERROR("Could not determine type of port %s\n", port->name);
- goto ERROR;
- }
-
// Perform some common initialization
r = nw_port_setup_common(port);
if (r)
return r;
}
-int nw_port_create(nw_port** port, nw_daemon* daemon, const char* name) {
+int nw_port_create(nw_port** port, nw_daemon* daemon, nw_port_type_t type, const char* name) {
int r;
// Allocate a new object
// Initialize reference counter
p->nrefs = 1;
+ // Store the type
+ p->type = type;
+
// Store the name
r = nw_string_set(p->name, name);
if (r)
return r;
}
+int nw_port_create_from_config(nw_port** port, nw_daemon* daemon,
+ const char* name, const char* path) {
+ nw_config* config = NULL;
+ int r;
+
+ // Initialize the configuration
+ r = nw_config_create(&config, path);
+ if (r)
+ goto ERROR;
+
+ // Fetch the type
+ const char* type = nw_config_get(config, "TYPE");
+ if (!type) {
+ ERROR("Port configuration %s has no TYPE\n", path);
+ r = 1;
+ goto ERROR;
+ }
+
+ // Create a new port
+ r = nw_port_create(port, daemon, nw_port_type_from_string(type), name);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ if (config)
+ nw_config_unref(config);
+
+ return r;
+}
+
nw_port* nw_port_ref(nw_port* port) {
port->nrefs++;
#include "address.h"
#include "daemon.h"
-int nw_port_create(nw_port** port, nw_daemon* daemon, const char* name);
+int nw_port_create(nw_port** port, nw_daemon* daemon,
+ nw_port_type_t type, const char* name);
+int nw_port_create_from_config(nw_port** port, nw_daemon* daemon,
+ const char* name, const char* path);
nw_port* nw_port_ref(nw_port* port);
nw_port* nw_port_unref(nw_port* port);