char *name = packmsg_get_str_dup(&in);
packmsg_skip_element(&in); /* submesh */
- int32_t devclass = packmsg_get_int32(&in);
+ dev_class_t devclass = packmsg_get_int32(&in);
uint32_t count = packmsg_get_array(&in);
if(!name) {
}
}
- if((int)devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ if(devclass < 0 || devclass >= DEV_CLASS_COUNT) {
logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
meshlink_errno = MESHLINK_EINVAL;
return NULL;
}
}
- if((int)params->devclass < 0 || params->devclass > _DEV_CLASS_MAX) {
+ if(params->devclass < 0 || params->devclass >= DEV_CLASS_COUNT) {
logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
meshlink_errno = MESHLINK_EINVAL;
return NULL;
}
meshlink_node_t **meshlink_get_all_nodes_by_dev_class(meshlink_handle_t *mesh, dev_class_t devclass, meshlink_node_t **nodes, size_t *nmemb) {
- if(!mesh || ((int)devclass < 0) || (devclass > _DEV_CLASS_MAX) || !nmemb) {
+ if(!mesh || devclass < 0 || devclass >= DEV_CLASS_COUNT || !nmemb) {
meshlink_errno = MESHLINK_EINVAL;
return NULL;
}
DEV_CLASS_STATIONARY = 1,
DEV_CLASS_PORTABLE = 2,
DEV_CLASS_UNKNOWN = 3,
- _DEV_CLASS_MAX = 3
+ DEV_CLASS_COUNT
} dev_class_t;
/// Invitation flags
struct ecdsa *private_key;
struct ecdsa *invitation_key;
- int32_t devclass;
+ dev_class_t devclass;
int invitation_timeout;
int pinginterval; /* seconds between pings */
if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) {
unsigned int connects = 0;
- for(int32_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(dev_class_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass) {
connects += 1;
if(min_connects < cur_connects /*&& cur_connects <= max_connects*/) {
unsigned int connects = 0;
- for(int32_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(dev_class_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass) {
connects += 1;
}
}
- int32_t devclass = packmsg_get_int32(&in);
+ dev_class_t devclass = packmsg_get_int32(&in);
bool blacklisted = packmsg_get_bool(&in);
config_free(&config);
- if(!packmsg_input_ok(&in) || devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ if(!packmsg_input_ok(&in) || devclass < 0 || devclass >= DEV_CLASS_COUNT) {
return false;
}
n->edge_tree = new_edge_tree();
n->mtu = MTU;
n->maxmtu = MTU;
- n->devclass = _DEV_CLASS_MAX;
+ n->devclass = DEV_CLASS_UNKNOWN;
return n;
}
// Private member variables
node_status_t status;
uint16_t minmtu; /* Probed minimum MTU */
- int32_t devclass;
+ dev_class_t devclass;
// Used for packet I/O
sptps_t sptps;
return false;
}
- if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ if(devclass < 0 || devclass >= DEV_CLASS_COUNT) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ACK", c->name, "devclass invalid");
return false;
}
/* Create an edge_t for this connection */
- assert(devclass >= 0 && devclass <= _DEV_CLASS_MAX);
+ assert(devclass >= 0 && devclass < DEV_CLASS_COUNT);
c->edge = new_edge();
c->edge->from = mesh->self;
// Check if devclasses are valid
- if(from_devclass < 0 || from_devclass > _DEV_CLASS_MAX) {
+ if(from_devclass < 0 || from_devclass >= DEV_CLASS_COUNT) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "from devclass invalid");
return false;
}
- if(to_devclass < 0 || to_devclass > _DEV_CLASS_MAX) {
+ if(to_devclass < 0 || to_devclass >= DEV_CLASS_COUNT) {
logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "to devclass invalid");
return false;
}
assert(mesh_nut);
meshlink_set_log_cb(mesh_nut, TEST_MESHLINK_LOG_LEVEL, log_message);
- nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, _DEV_CLASS_MAX + 10, NULL, &nnodes);
+ nodes = meshlink_get_all_nodes_by_dev_class(mesh_nut, DEV_CLASS_COUNT + 10, NULL, &nnodes);
assert_int_equal(nodes, NULL);
assert_int_not_equal(meshlink_errno, 0);