Subversion Repositories HelenOS-historic

Rev

Rev 1445 | Rev 1451 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2006 Josef Cejka
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  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
  15.  *   derived from this software without specific prior written permission.
  16.  *
  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
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  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
  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
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29.  
  30. #include <kbd.h>
  31. #include <ipc/ipc.h>
  32. #include <ipc/services.h>
  33. #include <stdio.h>
  34. #include <errno.h>
  35.  
  36. #define NAME "CONSOLE"
  37.  
  38. int main(int argc, char *argv[])
  39. {
  40.     ipcarg_t phonead;
  41.     ipc_call_t call;
  42.     ipc_callid_t callid;
  43.     int phone_kbd, phone_fb;
  44.     ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
  45.    
  46.     printf("Uspace console service started.\n");
  47.    
  48.    
  49.     /* Connect to keyboard driver */
  50.  
  51.     while ((phone_kbd = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
  52.     };
  53.    
  54.     if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) {
  55.         printf("%s: Error: Registering at naming service failed.\n", NAME);
  56.         return -1;
  57.     };
  58.  
  59.     /* Connect to framebuffer driver */
  60.    
  61.     while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
  62.     };
  63.    
  64.    
  65.     /* Register service at nameserver */
  66.     printf("%s: Registering at naming service.\n", NAME);
  67.  
  68.     if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
  69.         printf("%s: Error: Registering at naming service failed.\n", NAME);
  70.         return -1;
  71.     };
  72.    
  73.     while (1) {
  74.         callid = ipc_wait_for_call(&call);
  75.         switch (IPC_GET_METHOD(call)) {
  76.             case IPC_M_PHONE_HUNGUP:
  77.                 printf("%s: Phone hung up.\n", NAME);
  78.                 retval = 0;
  79.                 break;
  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));
  82.                 retval = 0;
  83.                 break;
  84.             case KBD_PUSHCHAR:
  85.                 printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call));
  86.                 retval = 0;
  87.                
  88.                 break;
  89.             default:
  90.                 printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
  91.                 retval = ENOENT;
  92.                 break;
  93.         }
  94.  
  95.         if (! (callid & IPC_CALLID_NOTIFICATION)) {
  96.             ipc_answer_fast(callid, retval, arg1, arg2);
  97.         }
  98.     }
  99.  
  100.     return 0;  
  101. }
  102.