Пример #1
0
void* console_device(void * arg) {

    uint32_t scancode;
    iorq_t iorq;
    int i;
    char c;
    char * aux;
    
    memset(&keybd_device, 0, sizeof(device_t));
    strcpy(keybd_device.ln_link.name, "org.era.dev.console");
    keybd_device.iorq_queue = create_queue(10, sizeof(iorq_t));

    keybd_queue = create_queue(1, sizeof(uint32_t));
    register_interrupt_handler(IRQ1, &keypress_isr);
    monitor_writexy(0,24, " 1", 7, 0);
    
    for(;;) {
        queue_recv(keybd_device.iorq_queue, &iorq, QM_BLOCKING);
        if(iorq.io_desc == DC_READ) {
            i = 0;
            aux = (char *) iorq.io_dptr;
            memset(aux, 0, iorq.io_sz);
            
            while(1) {
                queue_recv(keybd_queue, &scancode, QM_BLOCKING);
                c = kbdus[scancode];
                if (c == '\n')
                    break;
                if ((c == '\b') && (i > 0)) {
                    aux[i] = '\0';
                    i--;
                    monitor_put('\b');
                    continue;
                }
                if (c == 0 || c == '\t' || i == (iorq.io_sz - 1))
                    continue;
                if(isprintable(c) ) {
                    aux[i++] = c;
                    monitor_put(c);
                }
            }
            monitor_put('\n');
            aux[i] = '\0';

            queue_send(iorq.io_response, NULL, QM_NONBLOCKING);
        }
    }
}
Пример #2
0
static int chan_recv(lua_State* L)
{
    struct queue_t* q = _lua_arg_queue(L);
    double timeout = _lua_arg_double(L, 2, 1, -1, _usage_recv);
    struct msg_t* msg = queue_recv(q, timeout);
    if (msg)
    {
        switch (msg->type)
        {
            case LUA_TSTRING:
                lua_pushlstring(L, msg->str, msg->str_len);
                break;
            case LUA_TNUMBER:
                lua_pushnumber(L, msg->num);
                break;
            case LUA_TBOOLEAN:
                lua_pushboolean(L, msg->bool_val);
                break;
            default:
                lua_pushstring(L, "bad internal state");
                lua_error(L);
                break;
        }
        free (msg);
    }
    else
    {
        lua_pushnil(L);
    }
    return 1;
}
Пример #3
0
// multiple writers
void *test2a(void *vptr_args)
{
	int thread_no = (int)vptr_args;
	char message[128];
	int buflen = 128, prio, i;
	time_t now;
	switch(thread_no)
	{
		case 0: //senders
		case 1:
		case 2:
		prio = 2 - thread_no;
		snprintf(message, 128, "Wiadomosc od watku %d", thread_no, prio);
		queue_send(&queue, message, strlen(message) + 1, prio, 0, NULL);
		break;
		
		case 3: //receiver
		// let's wait a ~second
		now = time(NULL);
		while(time(NULL) == now);
		for(i=0;i<3;i++)
		{
			queue_recv(&queue, message, &buflen, &prio, 0, NULL);
			printf("Odebrano wiadomosc o dlugosci %d i priorytecie %d: \"%s\"\n", buflen, prio, message);
		}
		break;
	}
}
Пример #4
0
// multiple writers/readers
void *test2b(void *vptr_args)
{
	int thread_no = (int)vptr_args;
	char message[128];
	int buflen = 128, prio, i;
	time_t now;
	switch(thread_no)
	{
		case 0: //senders
		case 1:
		case 2:
		queue_recv(&queue, message, &buflen, &prio, 0, NULL);
		printf("Watek %d otrzymal wiadomosc o priorytecie %d: \"%s\"\n", thread_no, prio, message);
		break;
		
		case 3: //receiver
		// let's wait a ~second
		strcpy(message, "Opozniona wiadomosc");
		buflen = strlen(message) + 1;
		for(i=0;i<3;i++)
		{
			now = time(NULL);
			while(time(NULL) == now);
			queue_send(&queue, message, buflen, i, 0, NULL);
		}
		break;
	}
}
Пример #5
0
// simple send & receive
void *test1(void *vptr_args)
{
	int thread_no = (int)vptr_args;
	char message[128];
	int buflen = 128, prio;
	switch(thread_no)
	{
		case 0: //sender
		strncpy(message, "To jest wiadomosc!", 128);
		queue_send(&queue, message, strlen(message) + 1, 1, 0, NULL);
		printf("Wyslano wiadomosc: %s\n", message);
		break;
		
		case 1: //receiver
		queue_recv(&queue, message, &buflen, &prio, 0, NULL);
		printf("Odebrano wiadomosc o dlugosci %d i priorytecie %d: %s\n", buflen, prio, message);
		break;
	}
}