Subversion Repositories HelenOS

Rev

Rev 1285 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1285 Rev 1330
1
#include <ipc.h>
1
#include <ipc.h>
2
#include <stdio.h>
2
#include <stdio.h>
3
#include <unistd.h>
3
#include <unistd.h>
4
#include <stdlib.h>
4
#include <stdlib.h>
5
#include <ns.h>
5
#include <ns.h>
6
#include <errno.h>
6
#include <errno.h>
7
/*
7
/*
8
irq_cmd_t msim_cmds[1] = {
8
irq_cmd_t msim_cmds[1] = {
9
    { CMD_MEM_READ_1, (void *)0xB0000000, 0 }
9
    { CMD_MEM_READ_1, (void *)0xB0000000, 0 }
10
};
10
};
11
 
11
 
12
irq_code_t msim_kbd = {
12
irq_code_t msim_kbd = {
13
    1,
13
    1,
14
    msim_cmds
14
    msim_cmds
15
};
15
};
16
*/
16
*/
17
/*
17
/*
18
irq_cmd_t i8042_cmds[1] = {
18
irq_cmd_t i8042_cmds[1] = {
19
    { CMD_PORT_READ_1, (void *)0x60, 0 }
19
    { CMD_PORT_READ_1, (void *)0x60, 0 }
20
};
20
};
21
 
21
 
22
irq_code_t i8042_kbd = {
22
irq_code_t i8042_kbd = {
23
    1,
23
    1,
24
    i8042_cmds
24
    i8042_cmds
25
};
25
};
26
*/
26
*/
27
 
27
 
28
static int service;
28
static int service;
29
 
29
 
30
int main(int argc, char **argv)
30
int main(int argc, char **argv)
31
{
31
{
32
    ipc_call_t call;
32
    ipc_call_t call;
33
    ipc_callid_t callid;
33
    ipc_callid_t callid;
-
 
34
    char *as;
34
   
35
   
35
    ipcarg_t retval, arg1, arg2;
36
    ipcarg_t retval, arg1, arg2;
36
 
37
 
37
    printf("NS:Name service started.\n");
38
    printf("NS:Name service started.\n");
38
//  ipc_register_irq(2, &msim_kbd);
39
//  ipc_register_irq(2, &msim_kbd);
39
//  ipc_register_irq(1, &i8042_kbd);
40
//  ipc_register_irq(1, &i8042_kbd);
40
    while (1) {
41
    while (1) {
41
        callid = ipc_wait_for_call(&call, 0);
42
        callid = ipc_wait_for_call(&call, 0);
42
        printf("NS:Call phone=%lX..", call.phoneid);
43
        printf("NS:Call phone=%lX..", call.phoneid);
43
        switch (IPC_GET_METHOD(call)) {
44
        switch (IPC_GET_METHOD(call)) {
-
 
45
        case IPC_M_AS_SEND:
-
 
46
            as = (char *)IPC_GET_ARG2(call);
-
 
47
            printf("Received as: %P, size:%d\n", as, IPC_GET_ARG3(call));
-
 
48
            retval = ipc_answer(callid, 0,(sysarg_t)(1024*1024), 0);
-
 
49
            if (!retval) {
-
 
50
                printf("Reading shared memory...");
-
 
51
                printf("Text: %s", as);
-
 
52
            } else
-
 
53
                printf("Failed answer: %d\n", retval);
-
 
54
            continue;
-
 
55
            break;
44
        case IPC_M_INTERRUPT:
56
        case IPC_M_INTERRUPT:
45
            printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call));
57
            printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call));
46
            break;
58
            break;
47
        case IPC_M_PHONE_HUNGUP:
59
        case IPC_M_PHONE_HUNGUP:
48
            printf("Phone hung up.\n");
60
            printf("Phone hung up.\n");
49
            retval = 0;
61
            retval = 0;
50
            break;
62
            break;
51
        case IPC_M_CONNECT_TO_ME:
63
        case IPC_M_CONNECT_TO_ME:
52
            printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call));
64
            printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call));
53
            service = IPC_GET_ARG3(call);
65
            service = IPC_GET_ARG3(call);
54
            retval = 0;
66
            retval = 0;
55
            break;
67
            break;
56
        case IPC_M_CONNECT_ME_TO:
68
        case IPC_M_CONNECT_ME_TO:
57
            printf("Connectme(%P)to: %zd\n",
69
            printf("Connectme(%P)to: %zd\n",
58
                   IPC_GET_ARG3(call), IPC_GET_ARG1(call));
70
                   IPC_GET_ARG3(call), IPC_GET_ARG1(call));
59
            retval = 0;
71
            retval = 0;
60
            break;
72
            break;
61
        case NS_PING:
73
        case NS_PING:
62
            printf("Ping...%P %P\n", IPC_GET_ARG1(call),
74
            printf("Ping...%P %P\n", IPC_GET_ARG1(call),
63
                   IPC_GET_ARG2(call));
75
                   IPC_GET_ARG2(call));
64
            retval = 0;
76
            retval = 0;
65
            arg1 = 0xdead;
77
            arg1 = 0xdead;
66
            arg2 = 0xbeef;
78
            arg2 = 0xbeef;
67
            break;
79
            break;
68
        case NS_HANGUP:
80
        case NS_HANGUP:
69
            printf("Closing connection.\n");
81
            printf("Closing connection.\n");
70
            retval = EHANGUP;
82
            retval = EHANGUP;
71
            break;
83
            break;
72
        case NS_PING_SVC:
84
        case NS_PING_SVC:
73
            printf("NS:Pinging service %d\n", service);
85
            printf("NS:Pinging service %d\n", service);
74
            ipc_call_sync(service, NS_PING, 0xbeef, 0);
86
            ipc_call_sync(service, NS_PING, 0xbeef, 0);
75
            printf("NS:Got pong\n");
87
            printf("NS:Got pong\n");
76
            break;
88
            break;
77
        default:
89
        default:
78
            printf("Unknown method: %zd\n", IPC_GET_METHOD(call));
90
            printf("Unknown method: %zd\n", IPC_GET_METHOD(call));
79
            retval = ENOENT;
91
            retval = ENOENT;
80
            break;
92
            break;
81
        }
93
        }
82
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
94
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
83
            printf("Answerinh\n");
95
            printf("Answerinh\n");
84
            ipc_answer(callid, retval, arg1, arg2);
96
            ipc_answer(callid, retval, arg1, arg2);
85
        }
97
        }
86
    }
98
    }
87
}
99
}
88
 
100