예제 #1
0
static int
Wmii_init(Wmii *self, PyObject *args, PyObject *kwds)
{
    PyObject *address, *tmp;
    const char *adr;

    if (!PyArg_ParseTuple(args, "S", &address))
        return -1;

    if(address) {
        if (self->client) {
            ixp_unmount(self->client);
        }

        tmp = self->address;
        Py_INCREF(address);
        self->address = address;

        adr = PyString_AsString(address);


        //printf("** Wmii([%s]) **\n", adr);
        self->client = ixp_mount(adr);
        //printf("self->client: %d\n", self->client);
        if(!self->client) {
            PyErr_SetString(PyExc_RuntimeError, "Could not connect to server");
            return -1;
        }

        Py_XDECREF(tmp);
    }

    return 0;
}
예제 #2
0
static void
Wmii_dealloc(Wmii *self)
{
    if (self->client)
    {
        ixp_unmount(self->client);
    }
    Py_XDECREF(self->address);
    self->ob_type->tp_free((PyObject*)self);
}
예제 #3
0
static int l_ixp_gc (lua_State *L)
{
	struct ixp *ixp = lixp_checkixp (L, 1);

	DBGF("** ixp:__gc (%p [%s]) **\n", ixp, ixp->address);

	ixp_unmount (ixp->client);
	free ((char*)ixp->address);

	return 0;
}
예제 #4
0
int
main(int argc, char **argv) {
    int i;
    UpClient *upclient;
    IxpClient *client;

    signals_setup(&quit_handler);

    client = ixp_nsmount("wmii");
    if(client == NULL) {
        printf("ixp_nsmount: %s\n", ixp_errbuf());
        abort();
    }

    mainloop = g_main_loop_new(NULL, FALSE);

    upclient = up_client_new();

    sb_init(&sb, client);
    sb_add(&sb, &sbe_ac);    
    for(i = 0; i < MAX_BATTERIES; i++) {
        sb_add(&sb, &sbe_batteries[i]);
    }

    up_client_enumerate_devices_sync(upclient, NULL, NULL);

    g_signal_connect(upclient, "device-added", G_CALLBACK(device_added_cb), NULL);
    g_signal_connect(upclient, "device-removed", G_CALLBACK(device_removed_cb), NULL);
    g_signal_connect(upclient, "device-changed", G_CALLBACK(device_changed_cb), NULL);
    g_signal_connect(upclient, "changed", G_CALLBACK(changed_cb), NULL);

    update_sb(upclient);

    g_main_loop_run(mainloop);

    sb_finish(&sb);

    ixp_unmount(client);
}
예제 #5
0
int
main(int argc, char **argv) {
    int n, nfds, res;
    struct itimerspec timerits;
    struct epoll_event events[MAX_EVENTS];
    struct epoll_event timerevent;
    IxpClient* client;
    struct sb sb;

    signals_setup(&quit_handler);

    struct sb_entry sbe_sda = {
        .sbe_path = "/rbar/60_sda",
        .sbe_private = "sda",
        .sbe_init = &init_block,
        .sbe_update = &update_block,
        .sbe_foreground = 0xbbbbbb,
        .sbe_background = 0x444444,
        .sbe_border     = 0x555555,        
    };

    struct sb_entry sbe_sdb = {
        .sbe_path = "/rbar/61_sdb",
        .sbe_private = "sdb",
        .sbe_init = &init_block,
        .sbe_update = &update_block,
        .sbe_foreground = 0xbbbbbb,
        .sbe_background = 0x444444,
        .sbe_border     = 0x555555,        
    };

    struct sb_entry sbe_sdc = {
        .sbe_path = "/rbar/62_sdc",
        .sbe_private = "sdc",
        .sbe_init = &init_block,
        .sbe_update = &update_block,
        .sbe_foreground = 0xbbbbbb,
        .sbe_background = 0x444444,
        .sbe_border     = 0x555555,        
    };

    int epollfd = epoll_create1(EPOLL_CLOEXEC);
    if(epollfd == -1) {
        perror("epoll_create");
        abort();
    }

    int timerfd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
    if(timerfd == -1) {
        perror("timerfd_create");
        abort();
    }
    timerevent.events = EPOLLIN;
    timerevent.data.fd = timerfd;
    timerits.it_interval.tv_sec = 0;
    timerits.it_interval.tv_nsec = 250 * 1000 * 1000;
    timerits.it_value.tv_sec = timerits.it_interval.tv_sec;
    timerits.it_value.tv_nsec = timerits.it_interval.tv_nsec;

    client = ixp_nsmount("wmii");
    if(client == NULL) {
        printf("ixp_nsmount: %s\n", ixp_errbuf());
        abort();
    }

    res = epoll_ctl(epollfd, EPOLL_CTL_ADD, timerfd, &timerevent);
    if(res == -1) {
        perror("epoll_ctl");
        abort();
    }
        
    res = timerfd_settime(timerfd, 0, &timerits, NULL);
    if(res == -1) {
        perror("timerfd_settime");
        abort();
    }

    sb_init(&sb, client);
    sb_add(&sb, &sbe_sda);
    sb_add(&sb, &sbe_sdb);
    sb_add(&sb, &sbe_sdc);

    while(1) {
        nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
        if(nfds == -1) {
		    if(errno != EINTR) {
                perror("epoll_wait");
                abort();
			}
        }

        if(should_quit) {
            break;
        }
        
        for (n = 0; n < nfds; n++) {
            if(events[n].data.fd == timerfd) {
                uint64_t x;
                read(timerfd, &x, sizeof(x));
                sb_update(&sb);
            }
        }
    }

    sb_finish(&sb);

    ixp_unmount(client);

    return 0;
}