Subversion Repositories HelenOS

Rev

Rev 3386 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3386 Rev 4718
Line 30... Line 30...
30
#include <unistd.h>
30
#include <unistd.h>
31
#include <async.h>
31
#include <async.h>
32
#include <errno.h>
32
#include <errno.h>
33
#include "../tester.h"
33
#include "../tester.h"
34
 
34
 
-
 
35
#define MAX_CONNECTIONS  50
-
 
36
 
-
 
37
static int connections[MAX_CONNECTIONS];
-
 
38
 
35
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
39
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
36
{
40
{
37
    ipc_callid_t callid;
-
 
38
    ipc_call_t call;
-
 
39
    ipcarg_t phonehash = icall->in_phone_hash;
-
 
40
    int retval;
-
 
41
    int i;
41
    unsigned int i;
42
 
42
   
43
    printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
43
    TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash);
44
    ipc_answer_0(iid, EOK);
44
    ipc_answer_0(iid, EOK);
45
    for (i = 0; i < 1024; i++)
45
    for (i = 0; i < MAX_CONNECTIONS; i++) {
46
        if (!connections[i]) {
46
        if (!connections[i]) {
47
            connections[i] = phonehash;
47
            connections[i] = icall->in_phone_hash;
48
            break;
48
            break;
49
        }
49
        }
-
 
50
    }
50
   
51
   
51
    while (1) {
52
    while (true) {
-
 
53
        ipc_call_t call;
52
        callid = async_get_call(&call);
54
        ipc_callid_t callid = async_get_call(&call);
-
 
55
        int retval;
-
 
56
       
53
        switch (IPC_GET_METHOD(call)) {
57
        switch (IPC_GET_METHOD(call)) {
54
        case IPC_M_PHONE_HUNGUP:
58
        case IPC_M_PHONE_HUNGUP:
55
            printf("Phone (%P) hung up.\n", phonehash);
59
            TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
56
            retval = 0;
60
            retval = 0;
57
            break;
61
            break;
-
 
62
        case IPC_TEST_METHOD:
-
 
63
            TPRINTF("Received well known message from %#x: %#x\n",
-
 
64
                icall->in_phone_hash, callid);
-
 
65
            ipc_answer_0(callid, EOK);
-
 
66
            break;
58
        default:
67
        default:
59
            printf("Received message from %P: %X\n", phonehash,
68
            TPRINTF("Received unknown message from %#x: %#x\n",
60
                callid);
69
                icall->in_phone_hash, callid);
61
            for (i = 0; i < 1024; i++)
-
 
62
                if (!callids[i]) {
-
 
63
                    callids[i] = callid;
70
            ipc_answer_0(callid, ENOENT);
64
                    break;
71
            break;
65
                }
-
 
66
            continue;
-
 
67
        }
72
        }
68
        ipc_answer_0(callid, retval);
-
 
69
    }
73
    }
70
}
74
}
71
 
75
 
72
char * test_register(bool quiet)
76
char *test_register(void)
73
{
77
{
74
    int i;
-
 
75
   
-
 
76
    async_set_client_connection(client_connection);
78
    async_set_client_connection(client_connection);
77
 
79
   
78
    for (i = IPC_TEST_START; i < IPC_TEST_START + 10; i++) {
-
 
79
        ipcarg_t phonead;
80
    ipcarg_t phonead;
80
        int res = ipc_connect_to_me(PHONE_NS, i, 0, 0, &phonead);
81
    int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
81
        if (!res)
82
    if (res != 0)
82
            break;
-
 
83
        printf("Failed registering as %d..:%d\n", i, res);
83
        return "Failed registering IPC service";
84
    }
84
   
85
    printf("Registered as service: %d\n", i);
85
    TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
86
    myservice = i;
86
    async_manager();
87
   
87
   
88
    return NULL;
88
    return NULL;
89
}
89
}