#include #include #include #include #include #include #include #include #include controller_t* controller_create(void) { controller_t *new_controller = malloc(sizeof(*new_controller)); uuid_generate(new_controller->id); strncpy(new_controller->name, global_config.name, MAX_NAME_LENGTH); new_controller->name[MAX_NAME_LENGTH] = '\0'; new_controller->command_port = 0; new_controller->discovery_port = global_config.discovery_port; new_controller->relay_count = global_config.relay_count; new_controller->relays = malloc(sizeof(relay_t) * new_controller->relay_count); uint8_t i; for(i = 0; i < new_controller->relay_count; ++i) { new_controller->relays[i] = relay_create(i); } return new_controller; } void controller_set_name(controller_t *controller, char *name) { strncpy(controller->name, name, MAX_NAME_LENGTH); controller->name[MAX_NAME_LENGTH] = '\0'; } void controller_free(controller_t *controller) { for(int i = 0; i < controller->relay_count; ++i) { relay_free(controller->relays[i]); } free(controller->relays); free(controller); } void controller_debug(controller_t *controller) { if(controller == NULL) { LOG_DEBUG("controller is NULL"); return; } char uuid_str[37]; uuid_unparse(controller->id, uuid_str); LOG_DEBUG("(1/5) %s @ %p", uuid_str, (void*)controller); LOG_DEBUG("(2/5) name: %s", controller->name); LOG_DEBUG("(3/5) command_port: %5d discovery_port: %5d", controller->command_port, controller->discovery_port); LOG_DEBUG("(4/5) relay count: %3d", controller->relay_count); LOG_DEBUG("(5/5) relays @ %p:", (void*)controller->relays); for(uint8_t i = 0; i < controller->relay_count; ++i) { relay_debug(controller->relays[i]); } }