int main(int argc, char **argv) { struct thread thread; master = thread_master_create(NULL); openzlog("grammar_sandbox", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); /* Library inits. */ cmd_init(1); host.name = strdup("test"); host.domainname = strdup("testdomainname"); vty_init(master, true); memory_init(); yang_init(); nb_init(master, NULL, 0); vty_stdio(vty_do_exit); /* Fetch next active thread. */ while (thread_fetch(master, &thread)) thread_call(&thread); /* Not reached. */ exit(0); }
int main(int argc, char *argv[]) { int ret = 0; pthread_t spi_handler, event_handler; void *rv; fd = open(device, O_RDWR); if (fd < 0) die("can't open device"); /* * spi mode */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); if (ret == -1) die("can't set spi mode"); ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); if (ret == -1) die("can't get spi mode"); /* * bits per word */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) die("can't set bits per word"); ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); if (ret == -1) die("can't get bits per word"); /* * max speed hz */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) die("can't set max speed hz"); ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); if (ret == -1) die("can't get max speed hz"); nb_init(); nb_register(nb_changed, 0, NB_SIZE - 1); nb_register(joy_changed, NB_O_JOY_X, NB_O_JOY_Y); if (pthread_create(&spi_handler, NULL, nb_worker, NULL) < 0) { die("Thread creation failed: %s", strerror(errno)); } if (pthread_create(&event_handler, NULL, event_worker, NULL) < 0) { die("Thread creation failed: %s", strerror(errno)); } pthread_join(spi_handler, &rv); pthread_join(event_handler, &rv); close(fd); pthread_exit(NULL); return ret; }