Exemplo n.º 1
0
int my_pipe(int filedes[2], int iline, char *pcfile)
{
	int r;
	r = save_pipe(filedes);
	if (r != -1)
	{
		add_fd_list(&g_pfdheader, filedes[0], iline, pcfile);
		add_fd_list(&g_pfdheader, filedes[1], iline, pcfile);
	}
	return r;
}
Exemplo n.º 2
0
int my_socket(int domain, int type, int protocol, int iline, char *pcfile)
{
	int r;
	r = save_socket(domain, type, protocol);
	if (r >= 0) add_fd_list(&g_pfdheader, r, iline, pcfile);
	return r;
}
Exemplo n.º 3
0
int my_creat(int iline, char *pcfile, const char *pathname, mode_t mode)
{
	int r;
	r = save_creat(pathname, mode);
	if (r >= 0) add_fd_list(&g_pfdheader, r, iline, pcfile);
	return r;
}
Exemplo n.º 4
0
int			add_in_channel_aux(t_channel *elem, int fd)
{
  if (add_fd_list(&(elem->root), fd) == -1)
    return (-1);
  elem->size += 1;
  return (0);
}
int open_value_file(unsigned int gpio)
{
    int fd;
    char filename[MAX_FILENAME] = "";

    // create file descriptor of value file
    if ((gpio >= USR_LED_GPIO_MIN) && (gpio <=  USR_LED_GPIO_MAX)) {
        snprintf(filename, sizeof(filename), "/sys/class/leds/beaglebone:green:usr%d/brightness", gpio -  USR_LED_GPIO_MIN);
    } else if (beaglebone_blue()) {
        //syslog(LOG_DEBUG, "Adafruit_BBIO: gpio open_value_file: beaglebone_blue() is true\n");
        switch(gpio) {
            case USR_LED_RED:
                snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness");
                break;
            case USR_LED_GREEN:
                snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness");
                break;
            case BAT25:
                snprintf(filename, sizeof(filename), "/sys/class/leds/bat25/brightness");
                break;
            case BAT50:
                snprintf(filename, sizeof(filename), "/sys/class/leds/bat50/brightness");
                break;
            case BAT75:
                snprintf(filename, sizeof(filename), "/sys/class/leds/bat75/brightness");
                break;
            case BAT100:
                snprintf(filename, sizeof(filename), "/sys/class/leds/bat100/brightness");
                break;
            case WIFI:
                snprintf(filename, sizeof(filename), "/sys/class/leds/wifi/brightness");
                break;
            default:
                snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
                break;
        }
    } else {
        //syslog(LOG_DEBUG, "Adafruit_BBIO: gpio open_value_file: default gpio path\n");
        snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
    }
    //syslog(LOG_DEBUG, "Adafruit_BBIO: gpio open_value_file: filename=%s\n", filename);
    
    // if(gpio == USR_LED_RED) {     // red LED
    //     snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness");
    // } else if(gpio == USR_LED_GREEN) {     // green LED
    //     snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness");
    // } else {
    //     snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
    // }

    if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0) {
        syslog(LOG_ERR, "Adafruit_BBIO: gpio open_value_file: %u couldn't open '%s': %i-%s",
               gpio, filename, errno, strerror(errno));
        return -1;
    }
    syslog(LOG_DEBUG, "Adafruit_BBIO: open_value_file(): opened file descriptor %d for pin %u.",fd, gpio);
    add_fd_list(gpio, fd);
    return fd;
}
Exemplo n.º 6
0
int my_dup(int oldfd, int iline, char *pcfile)
{
	int r;
	r = save_dup(oldfd);

	if (r != -1) add_fd_list(&g_pfdheader, r, iline, pcfile);
	return r;
}
Exemplo n.º 7
0
int my_accept(int s, struct sockaddr *addr, int *addrlen, int iline, char *pcfile)
{
	int r;

	r = save_accept(s, addr, addrlen);
	if (r >= 0) add_fd_list(&g_pfdheader, r, iline, pcfile);
	return r;
}
int open_value_file(unsigned int gpio)
{
    int fd;
    char filename[30];

    // create file descriptor of value file
    snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
    if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
        return -1;
    add_fd_list(gpio, fd);
    return fd;
}
Exemplo n.º 9
0
int			create_channel(t_channel **root, char *name, int fd)
{
  t_channel		*tmp;

  if ((tmp = malloc(sizeof(t_channel))) == NULL
      || (tmp->root = init_fds()) == NULL
      || add_fd_list(&(tmp->root), fd) == -1)
    return (-1);
  tmp->channel_name = strdup(name);
  tmp->size = 1;
  tmp->next = (*root);
  tmp->prev = (*root)->prev;
  tmp->next->prev = tmp;
  tmp->prev->next = tmp;
  return (0);
}
Exemplo n.º 10
0
int my_open(int iline, char *pcfile, const char *pathname, int flags, ...)
{
	int r;
        mode_t mode;

        if (flags & O_CREAT)
        {
		va_list arg;
		va_start(arg, flags);
		mode = va_arg(arg, mode_t);
		va_end(arg);
	}
	else mode = 0;
	
	r = save_open(pathname, flags, mode);
	if (r >= 0) add_fd_list(&g_pfdheader, r, iline, pcfile);
	return r;
}
Exemplo n.º 11
0
int init_vhost_client(VhostClient* vhost_client)
{
    int idx;

    if (!vhost_client->client)
        return -1;

    if (init_client(vhost_client->client) != 0)
        return -1;

    vhost_ioctl(vhost_client->client, VHOST_USER_SET_OWNER, 0);
    vhost_ioctl(vhost_client->client, VHOST_USER_GET_FEATURES, &vhost_client->features);
    vhost_ioctl(vhost_client->client, VHOST_USER_SET_MEM_TABLE, &vhost_client->memory);

    // push the vring table info to the server
    if (set_host_vring_table(vhost_client->vring_table_shm, VHOST_CLIENT_VRING_NUM,
            vhost_client->client) != 0) {
        // TODO: handle error here
    }

    // VringTable initalization
    vhost_client->vring_table.handler.context = (void*) vhost_client;
    vhost_client->vring_table.handler.avail_handler = avail_handler_client;
    vhost_client->vring_table.handler.map_handler = 0;

    for (idx = 0; idx < VHOST_CLIENT_VRING_NUM; idx++) {
        vhost_client->vring_table.vring[idx].kickfd = vhost_client->vring_table_shm[idx]->kickfd;
        vhost_client->vring_table.vring[idx].callfd = vhost_client->vring_table_shm[idx]->callfd;
        vhost_client->vring_table.vring[idx].desc = vhost_client->vring_table_shm[idx]->desc;
        vhost_client->vring_table.vring[idx].avail = &vhost_client->vring_table_shm[idx]->avail;
        vhost_client->vring_table.vring[idx].used = &vhost_client->vring_table_shm[idx]->used;
        vhost_client->vring_table.vring[idx].num = VHOST_VRING_SIZE;
        vhost_client->vring_table.vring[idx].last_avail_idx = 0;
        vhost_client->vring_table.vring[idx].last_used_idx = 0;
    }

    // Add handler for RX kickfd
    add_fd_list(&vhost_client->client->fd_list, FD_READ,
            vhost_client->vring_table.vring[VHOST_CLIENT_VRING_IDX_RX].kickfd,
            (void*) vhost_client, _kick_client);

    return 0;
}
Exemplo n.º 12
0
int add_edge_detect(unsigned int gpio, unsigned int edge)
// return values:
// 0 - Success
// 1 - Edge detection already added
// 2 - Other error
{
    int fd;
    pthread_t threads;
    struct epoll_event ev;
    long t = 0;

    // check to see if this gpio has been added already
    if (gpio_event_added(gpio) != 0)
        return 1;

    // export /sys/class/gpio interface
    gpio_export(gpio);
    gpio_set_direction(gpio, 1); // 1=input
    gpio_set_edge(gpio, edge);
    if ((fd = open_value_file(gpio)) == -1)
        return 2;
    add_fd_list(gpio,fd);

    // create epfd if not already open
    if ((epfd == -1) && ((epfd = epoll_create(1)) == -1))
        return 2;

    // add to epoll fd
    ev.events = EPOLLIN | EPOLLET | EPOLLPRI;
    ev.data.fd = fd;
    if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) == -1)
        return 2;

    // start poll thread if it is not already running
    if (!thread_running)
    {
        if (pthread_create(&threads, NULL, poll_thread, (void *)t) != 0)
            return 2;
    }

    return 0;
}