Subversion Repositories HelenOS

Rev

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

Rev 1445 Rev 1447
1
/*
1
/*
2
 * Copyright (C) 2006 Josef Cejka
2
 * Copyright (C) 2006 Josef Cejka
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
 
29
 
30
#include <kbd.h>
30
#include <kbd.h>
31
#include <ipc/ipc.h>
31
#include <ipc/ipc.h>
32
#include <ipc/services.h>
32
#include <ipc/services.h>
33
#include <stdio.h>
33
#include <stdio.h>
34
#include <errno.h>
34
#include <errno.h>
35
 
35
 
36
#define NAME "CONSOLE"
36
#define NAME "CONSOLE"
37
 
37
 
38
int main(int argc, char *argv[])
38
int main(int argc, char *argv[])
39
{
39
{
40
    ipcarg_t phonead;
40
    ipcarg_t phonead;
41
    ipc_call_t call;
41
    ipc_call_t call;
42
    ipc_callid_t callid;
42
    ipc_callid_t callid;
43
    int phone_kbd, phone_fb;
43
    int phone_kbd, phone_fb;
44
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
44
    ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
45
   
45
   
46
    printf("Uspace console service started.\n");
46
    printf("Uspace console service started.\n");
47
   
47
   
48
   
48
   
49
    /* Connect to keyboard driver */
49
    /* Connect to keyboard driver */
50
 
50
 
51
    while ((phone_kbd = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
51
    while ((phone_kbd = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
52
    };
52
    };
53
   
53
   
54
    if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) {
54
    if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) {
55
        printf("%s: Error: Registering at naming service failed.\n", NAME);
55
        printf("%s: Error: Registering at naming service failed.\n", NAME);
56
        return -1;
56
        return -1;
57
    };
57
    };
58
 
58
 
59
    /* Connect to framebuffer driver */
59
    /* Connect to framebuffer driver */
60
   
60
   
61
    while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
61
    while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
62
    };
62
    };
63
   
63
   
64
   
64
   
65
    /* Register service at nameserver */
65
    /* Register service at nameserver */
66
    printf("%s: Registering at naming service.\n", NAME);
66
    printf("%s: Registering at naming service.\n", NAME);
67
 
67
 
68
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
68
    if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
69
        printf("%s: Error: Registering at naming service failed.\n", NAME);
69
        printf("%s: Error: Registering at naming service failed.\n", NAME);
70
        return -1;
70
        return -1;
71
    };
71
    };
72
   
72
   
73
    while (1) {
73
    while (1) {
74
        callid = ipc_wait_for_call(&call);
74
        callid = ipc_wait_for_call(&call);
75
        switch (IPC_GET_METHOD(call)) {
75
        switch (IPC_GET_METHOD(call)) {
76
            case IPC_M_PHONE_HUNGUP:
76
            case IPC_M_PHONE_HUNGUP:
77
                printf("%s: Phone hung up.\n", NAME);
77
                printf("%s: Phone hung up.\n", NAME);
78
                retval = 0;
78
                retval = 0;
79
                break;
79
                break;
80
            case IPC_M_CONNECT_ME_TO:
80
            case IPC_M_CONNECT_ME_TO:
81
                printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
81
                printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
82
                retval = 0;
82
                retval = 0;
83
                break;
83
                break;
84
            case KBD_PUSHCHAR:
84
            case KBD_PUSHCHAR:
85
                printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call));
85
                printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call));
86
                retval = 0;
86
                retval = 0;
-
 
87
               
87
                break;
88
                break;
88
            default:
89
            default:
89
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
90
                printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
90
                retval = ENOENT;
91
                retval = ENOENT;
91
                break;
92
                break;
92
        }
93
        }
93
 
94
 
94
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
95
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
95
            ipc_answer_fast(callid, retval, arg1, arg2);
96
            ipc_answer_fast(callid, retval, arg1, arg2);
96
        }
97
        }
97
    }
98
    }
98
 
99
 
99
    return 0;  
100
    return 0;  
100
}
101
}
101
 
102