use the -newos toolchain even if -elf is present.
[newos.git] / apps / inputd / InputServer.cpp
blob9e03961b827c74bab872e7b01acea5447268435d
1 /*
2 ** Copyright 2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #include <sys/types.h>
6 #include <sys/syscalls.h>
7 #include <unistd.h>
8 #include <stdio.h>
10 #include <win/Event.h>
11 using namespace os::gui;
13 #include "InputServer.h"
14 #include "KeyboardDevice.h"
15 #include "PS2Device.h"
17 InputServer::InputServer()
19 mEventPort = _kern_port_create(64, "input_event_port");
20 mLock = _kern_sem_create(1, "input_event_lock");
23 InputServer::~InputServer()
25 _kern_port_delete(mEventPort);
26 _kern_sem_delete(mLock);
29 int InputServer::FindDevices()
31 int fd;
33 // for now we'll just cycle through every possible type
34 fd = open("/dev/keyboard", 0);
35 if(fd >= 0) {
36 InputDevice *dev = new KeyboardDevice(fd, this);
38 dev->Run();
41 fd = open("/dev/ps2mouse", 0);
42 if(fd >= 0) {
43 InputDevice *dev = new PS2Device(fd, this);
45 dev->Run();
48 return 0;
51 void InputServer::PostEvent(const Event &event)
53 _kern_sem_acquire(mLock, 1);
55 #if 0
56 printf("InputServer::PostEvent: what %d ", event.what);
57 switch(event.what) {
58 case EVT_KEY_DOWN:
59 case EVT_KEY_UP:
60 printf("key 0x%x mod 0x%x\n", event.key, event.modifiers);
61 break;
62 case EVT_MOUSE_MOVED:
63 printf("x %d y %d mod 0x%x\n", event.x, event.y, event.modifiers);
64 break;
65 default:
66 printf("unknown format\n");
68 #endif
70 _kern_port_write(mEventPort, 0, const_cast<Event *>(&event), sizeof(event));
72 _kern_sem_release(mLock, 1);
75 int InputServer::Run()
77 FindDevices();
79 for(;;)
80 sleep(1);
82 return 0;