51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
#include <time.h>
|
||
|
#include <lmdb.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <poll.h>
|
||
|
#include <signal.h>
|
||
|
|
||
|
#include <logger.h>
|
||
|
#include <models/controller.h>
|
||
|
#include <database.h>
|
||
|
#include <config.h>
|
||
|
#include <constants.h>
|
||
|
#include <handlers.h>
|
||
|
#include <drivers.h>
|
||
|
#include <enums.h>
|
||
|
#include <helpers.h>
|
||
|
#include <wiringPi.h>
|
||
|
#include <piFace.h>
|
||
|
#include <wiring_debug.h>
|
||
|
|
||
|
void
|
||
|
handler_poll(struct pollfd *fds, controller_t *controller, MDB_env *mdb_env)
|
||
|
{
|
||
|
/* An event on one of the fds has occurred. */
|
||
|
for(int i = 0; i < POLL_FDS_COUNT; i++) {
|
||
|
if(fds[i].revents & POLLIN)
|
||
|
{
|
||
|
/* data may be read on device number i. */
|
||
|
LOG_DEBUG("fd %i may read data", fds[i].fd);
|
||
|
switch(i)
|
||
|
{
|
||
|
case POLL_FDS_DISCOVERY:
|
||
|
handler_discovery(fds[i].fd, controller);
|
||
|
break;
|
||
|
case POLL_FDS_COMMAND:
|
||
|
handler_command(fds[i].fd, controller);
|
||
|
controller_save(controller, mdb_env);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if(fds[i].revents & POLLHUP)
|
||
|
{
|
||
|
/* A hangup has occurred on device number i. */
|
||
|
LOG_DEBUG("fd %i got closed", fds[i].fd);
|
||
|
}
|
||
|
}
|
||
|
}
|