1 /* 2 * iroster.cpp 3 * (c) 2002, Carlos Hasan, for Haiku. 4 * Compile: gcc -Wall -Wno-multichar -O2 -o iroster iroster.cpp -lbe 5 */ 6 7 #include <stdio.h> 8 #include <string.h> 9 #include <interface/Input.h> 10 #include <support/List.h> 11 12 static int list_devices() 13 { 14 BList list; 15 BInputDevice *device; 16 int i, n; 17 status_t err; 18 19 printf(" name type state \n"); 20 printf("--------------------------------------------------\n"); 21 22 if ((err = get_input_devices(&list))!=B_OK) { 23 fprintf(stderr, "error while get_input_devices: %s\n", strerror(err)); 24 return -1; 25 } 26 27 n = list.CountItems(); 28 if (n == 0) { 29 printf("...no input devices found...\n"); 30 } 31 32 for (i = 0; i < n; i++) { 33 device = (BInputDevice *) list.ItemAt(i); 34 35 printf("%23s %18s %7s\n", 36 device->Name(), 37 device->Type() == B_POINTING_DEVICE ? "B_POINTING_DEVICE" : 38 device->Type() == B_KEYBOARD_DEVICE ? "B_KEYBOARD_DEVICE" : "B_UNDEFINED_DEVICE", 39 device->IsRunning() ? "running" : "stopped"); 40 } 41 42 return 0; 43 } 44 45 static void start_device(const char *name) 46 { 47 BInputDevice *device; 48 status_t status; 49 50 device = find_input_device(name); 51 if (device == NULL) { 52 printf("Error finding device \"%s\"\n", name); 53 } 54 else if ((status = device->Start()) != B_OK) { 55 printf("Error starting device \"%s\" (%" B_PRId32 ")\n", name, status); 56 } 57 else { 58 printf("Started device \"%s\"\n", name); 59 } 60 if (device != NULL) 61 delete device; 62 } 63 64 static void stop_device(const char *name) 65 { 66 BInputDevice *device; 67 status_t status; 68 69 device = find_input_device(name); 70 if (device == NULL) { 71 printf("Error finding device \"%s\"\n", name); 72 } 73 else if ((status = device->Stop()) != B_OK) { 74 printf("Error stopping device \"%s\" (%" B_PRId32 ")\n", name, status); 75 } 76 else { 77 printf("Stopped device \"%s\"\n", name); 78 } 79 if (device != NULL) 80 delete device; 81 } 82 83 int main(int argc, char *argv[]) 84 { 85 int i; 86 const char *name; 87 88 if (argc <= 1) { 89 return list_devices(); 90 } 91 else { 92 for (i = 1; i < argc; i++) { 93 name = argv[i]; 94 if (name[0] == '+') { 95 start_device(name + 1); 96 } 97 else if (name[0] == '-') { 98 stop_device(name + 1); 99 } 100 else { 101 printf("USAGE: %s [+|-]input_device_name\n", argv[0]); 102 } 103 } 104 } 105 return 0; 106 } 107 108