Subversion Repositories HelenOS

Rev

Rev 4602 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4602 Rev 4687
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include <stdio.h>
29
#include <stdio.h>
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
35
#define MAX_CONNECTIONS  50
36
 
36
 
37
static int connections[MAX_CONNECTIONS];
37
static int connections[MAX_CONNECTIONS];
38
 
38
 
39
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)
40
{
40
{
41
    unsigned int i;
41
    unsigned int i;
42
   
42
   
43
    TPRINTF("Connected phone %#x 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 < MAX_CONNECTIONS; i++) {
45
    for (i = 0; i < MAX_CONNECTIONS; i++) {
46
        if (!connections[i]) {
46
        if (!connections[i]) {
47
            connections[i] = icall->in_phone_hash;
47
            connections[i] = icall->in_phone_hash;
48
            break;
48
            break;
49
        }
49
        }
50
    }
50
    }
51
   
51
   
52
    while (true) {
52
    while (true) {
53
        ipc_call_t call;
53
        ipc_call_t call;
54
        ipc_callid_t callid = async_get_call(&call);
54
        ipc_callid_t callid = async_get_call(&call);
55
        int retval;
55
        int retval;
56
       
56
       
57
        switch (IPC_GET_METHOD(call)) {
57
        switch (IPC_GET_METHOD(call)) {
58
        case IPC_M_PHONE_HUNGUP:
58
        case IPC_M_PHONE_HUNGUP:
59
            TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
59
            TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
60
            retval = 0;
60
            retval = 0;
61
            break;
61
            break;
62
        case IPC_TEST_METHOD:
62
        case IPC_TEST_METHOD:
63
            TPRINTF("Received well known message from %#x: %#x\n",
63
            TPRINTF("Received well known message from %#x: %#x\n",
64
                icall->in_phone_hash, callid);
64
                icall->in_phone_hash, callid);
65
            ipc_answer_0(callid, EOK);
65
            ipc_answer_0(callid, EOK);
66
            break;
66
            break;
67
        default:
67
        default:
68
            TPRINTF("Received unknown message from %#x: %#x\n",
68
            TPRINTF("Received unknown message from %#x: %#x\n",
69
                icall->in_phone_hash, callid);
69
                icall->in_phone_hash, callid);
70
            ipc_answer_0(callid, ENOENT);
70
            ipc_answer_0(callid, ENOENT);
71
            break;
71
            break;
72
        }
72
        }
73
    }
73
    }
74
}
74
}
75
 
75
 
76
char *test_register(void)
76
char *test_register(void)
77
{
77
{
78
    async_set_client_connection(client_connection);
78
    async_set_client_connection(client_connection);
79
   
79
   
80
    ipcarg_t phonead;
80
    ipcarg_t phonead;
81
    int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
81
    int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
82
    if (res != 0)
82
    if (res != 0)
83
        return "Failed registering IPC service";
83
        return "Failed registering IPC service";
84
   
84
   
85
    TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
85
    TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
86
    async_manager();
86
    async_manager();
87
   
87
   
88
    return NULL;
88
    return NULL;
89
}
89
}
90
 
90