1 /*****************************************************************************/ 2 // OpenBeOS InputServer 3 // 4 // Version: [0.0.5] [Development Stage] 5 // 6 // [Description] 7 // 8 // 9 // This application and all source files used in its construction, except 10 // where noted, are licensed under the MIT License, and have been written 11 // and are: 12 // 13 // Copyright (c) 2002 OpenBeOS Project 14 // 15 // Permission is hereby granted, free of charge, to any person obtaining a 16 // copy of this software and associated documentation files (the "Software"), 17 // to deal in the Software without restriction, including without limitation 18 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 // and/or sell copies of the Software, and to permit persons to whom the 20 // Software is furnished to do so, subject to the following conditions: 21 // 22 // The above copyright notice and this permission notice shall be included 23 // in all copies or substantial portions of the Software. 24 // 25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 // DEALINGS IN THE SOFTWARE. 32 /*****************************************************************************/ 33 34 35 #include <stdio.h> 36 37 #include "InputServer.h" 38 #include "Path.h" 39 #include "Directory.h" 40 #include "FindDirectory.h" 41 #include "Entry.h" 42 #include "Locker.h" 43 #include "Debug.h" 44 45 #include "InputServerDeviceListEntry.h" 46 #include "InputServerFilterListEntry.h" 47 #include "InputServerMethodListEntry.h" 48 #include "Message.h" 49 50 // include app_server headers for communication 51 52 #include "PortLink.h" 53 #include "ServerProtocol.h" 54 55 #define SERVER_PORT_NAME "OBappserver" 56 #define SERVER_INPUT_PORT "OBinputport" 57 #define X_VALUE "x" 58 #define Y_VALUE "y" 59 60 61 extern "C" void RegisterDevices(input_device_ref** devices) 62 { 63 printf("RegisterDevices\n"); 64 }; 65 66 67 // Static InputServer member variables. 68 // 69 BList InputServer::gInputDeviceList; 70 BLocker InputServer::gInputDeviceListLocker; 71 72 BList InputServer::mInputServerDeviceList; 73 BList InputServer::mInputServerFilterList; 74 BList InputServer::mInputServerMethodList; 75 76 77 /* 78 * 79 */ 80 int main() 81 { 82 InputServer *myInputServer; 83 84 myInputServer = new InputServer; 85 86 myInputServer->Run(); 87 88 delete myInputServer; 89 } 90 91 92 /* 93 * Method: InputServer::InputServer() 94 * Descr: 95 */ 96 InputServer::InputServer(void) : BApplication("application/x-vnd.OBOS-input_server") 97 { 98 void *pointer; 99 100 EventLoop(pointer); 101 102 InitTestDevice(); 103 104 // InitDevices(); 105 InitFilters(); 106 InitMethods(); 107 } 108 109 /* 110 * Method: InputServer::InputServer() 111 * Descr: 112 */ 113 InputServer::~InputServer(void) 114 { 115 } 116 117 118 /* 119 * Method: InputServer::ArgvReceived() 120 * Descr: 121 */ 122 void InputServer::ArgvReceived(int32 argc, char** argv) 123 { 124 if (2 == argc) 125 { 126 if (0 == strcmp("-q", argv[1]) ) 127 { 128 // :TODO: Shutdown and restart the InputServer. 129 printf("InputServer::ArgvReceived - Restarting . . .\n"); 130 status_t quit_status; 131 //BMessenger msgr = BMessenger("application/x-vnd.OpenBeOS-input_server", -1, &quit_status); 132 BMessenger msgr = BMessenger("application/x-vnd.OBOS-input_server", -1, &quit_status); 133 if (B_OK == quit_status) 134 { 135 BMessage msg = BMessage(B_QUIT_REQUESTED); 136 msgr.SendMessage(&msg); 137 } 138 else 139 { 140 printf("Unable to send Quit message to running InputServer."); 141 } 142 } 143 } 144 } 145 146 147 /* 148 * Method: InputServer::InitKeyboardMouseStates() 149 * Descr: 150 */ 151 void InputServer::InitKeyboardMouseStates(void) 152 { 153 // This is where we read in the preferences data for the mouse and keyboard as well as 154 // determine the screen resolution from the app_server and find the center of the screen 155 // sMousePos is then set to the center of the screen. 156 157 sMousePos.x = 200; 158 sMousePos.y = 200; 159 160 } 161 162 void InputServer::InitTestDevice() 163 { 164 printf("InputServer::InitTestDevice - Enter\n"); 165 const char* path = "/boot/home/Projects/InputServer/ISD/nervous/nervous"; 166 printf("InputServer::InitTestDevice - Loading add-on . . .\n"); 167 image_id addon_image = load_add_on(path); 168 if (B_ERROR != addon_image) 169 { 170 status_t isd_status = B_NO_INIT; 171 BInputServerDevice* (*func)() = NULL; 172 printf("InputServer::InitTestDevice - Resolving symbol . . .\n"); 173 if (B_OK == get_image_symbol(addon_image, "instantiate_input_device", B_SYMBOL_TYPE_TEXT, (void**)&func) ) 174 { 175 printf("Found instantiate_input_device.\n"); 176 if (NULL != func) 177 { 178 BInputServerDevice* isd = (*func)(); 179 if (NULL != isd) 180 { 181 printf("InputServer::InitTestDevice - Calling InitCheck . . .\n"); 182 isd_status = isd->InitCheck(); 183 mInputServerDeviceList.AddItem( 184 new InputServerDeviceListEntry(path, isd_status, isd) ); 185 if (B_OK == isd_status) 186 { 187 //printf("Starting Nervous . . .\n"); 188 //isd->Start("Nervous Device", NULL); 189 } 190 else 191 { 192 printf("InitCheck failed.\n"); 193 } 194 } 195 } 196 } 197 if (B_OK != isd_status) 198 { 199 // Free resources associated with ISD's 200 // that failed to initialize. 201 // 202 //unload_add_on(addon_image); 203 } 204 } 205 printf("InputServer::InitTestDevice - Exit\n"); 206 } 207 208 /* 209 * Method: InputServer::InitDevices() 210 * Descr: 211 */ 212 void InputServer::InitDevices(void) 213 { 214 BDirectory dir; 215 BPath addon_dir; 216 BPath addon_path; 217 BEntry entry; 218 directory_which addon_dirs[] = 219 { 220 B_BEOS_ADDONS_DIRECTORY, 221 B_COMMON_ADDONS_DIRECTORY, 222 B_USER_ADDONS_DIRECTORY 223 }; 224 const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which); 225 226 printf("InputServer::InitDevices - Enter\n"); 227 228 // Find all Input Server Devices in each of the predefined 229 // addon directories. 230 // 231 for (int i = 0; i < addon_dir_count; i++) 232 { 233 if (B_OK == find_directory(addon_dirs[i], &addon_dir) ) 234 { 235 addon_dir.Append("input_server/devices"); 236 dir.SetTo(addon_dir.Path() ); 237 while (B_NO_ERROR == dir.GetNextEntry(&entry, false) ) 238 { 239 entry.GetPath(&addon_path); 240 printf("Adding %s . . .\n", addon_path.Path() ); 241 AddInputServerDevice(addon_path.Path() ); 242 } 243 } 244 } 245 printf("InputServer::InitDevices - Exit\n"); 246 } 247 248 249 /* 250 * Method: InputServer::AddInputServerDevice() 251 * Descr: 252 */ 253 status_t InputServer::AddInputServerDevice(const char* path) 254 { 255 image_id addon_image= load_add_on(path); 256 if (B_ERROR != addon_image) 257 { 258 status_t isd_status = B_NO_INIT; 259 BInputServerDevice* (*func)() = NULL; 260 if (B_OK == get_image_symbol(addon_image, "instantiate_input_device", B_SYMBOL_TYPE_TEXT, (void**)&func) ) 261 { 262 if (NULL != func) 263 { 264 /* 265 // :DANGER: Only reenable this section if this 266 // InputServer can start and manage the 267 // devices, otherwise the system will hang. 268 // 269 BInputServerDevice* isd = (*func)(); 270 if (NULL != isd) 271 { 272 isd_status = isd->InitCheck(); 273 mInputServerDeviceList.AddItem( 274 new InputServerDeviceListEntry(path, isd_status, isd) ); 275 } 276 */ 277 mInputServerDeviceList.AddItem( 278 new InputServerDeviceListEntry(path, B_NO_INIT, NULL) ); 279 } 280 } 281 if (B_OK != isd_status) 282 { 283 // Free resources associated with ISD's 284 // that failed to initialize. 285 // 286 unload_add_on(addon_image); 287 } 288 } 289 return 0; 290 } 291 292 293 /* 294 * Method: InputServer::InitFilters() 295 * Descr: 296 */ 297 void InputServer::InitFilters(void) 298 { 299 BDirectory dir; 300 BPath addon_dir; 301 BPath addon_path; 302 BEntry entry; 303 directory_which addon_dirs[] = 304 { 305 B_BEOS_ADDONS_DIRECTORY, 306 B_COMMON_ADDONS_DIRECTORY, 307 B_USER_ADDONS_DIRECTORY 308 }; 309 const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which); 310 311 printf("InputServer::InitFilters - Enter\n"); 312 313 // Find all Input Filters in each of the predefined 314 // addon directories. 315 // 316 for (int i = 0; i < addon_dir_count; i++) 317 { 318 if (B_OK == find_directory(addon_dirs[i], &addon_dir) ) 319 { 320 addon_dir.Append("input_server/filters"); 321 dir.SetTo(addon_dir.Path() ); 322 while (B_NO_ERROR == dir.GetNextEntry(&entry, false) ) 323 { 324 entry.GetPath(&addon_path); 325 printf("Adding %s . . .\n", addon_path.Path() ); 326 AddInputServerFilter(addon_path.Path() ); 327 } 328 } 329 } 330 printf("InputServer::InitFilters - Exit\n"); 331 } 332 333 334 /* 335 * Method: InputServer::AddInputServerFilter() 336 * Descr: 337 */ 338 status_t InputServer::AddInputServerFilter(const char* path) 339 { 340 image_id addon_image= load_add_on(path); 341 if (B_ERROR != addon_image) 342 { 343 status_t isf_status = B_NO_INIT; 344 BInputServerFilter* (*func)() = NULL; 345 if (B_OK == get_image_symbol(addon_image, "instantiate_input_filter", B_SYMBOL_TYPE_TEXT, (void**)&func) ) 346 { 347 if (NULL != func) 348 { 349 /* 350 // :DANGER: Only reenable this section if this 351 // InputServer can start and manage the 352 // filters, otherwise the system will hang. 353 // 354 BInputFilter isf = (*func)(); 355 if (NULL != isf) 356 { 357 isf_status = isf->InitCheck(); 358 mInputServerFilterList.AddItem( 359 new InputServerFilterListEntry(path, isf_status, isf ); 360 } 361 */ 362 mInputServerFilterList.AddItem( 363 new InputServerFilterListEntry(path, B_NO_INIT, NULL) ); 364 } 365 } 366 if (B_OK != isf_status) 367 { 368 // Free resources associated with InputServerFilters 369 // that failed to initialize. 370 // 371 unload_add_on(addon_image); 372 } 373 } 374 return 0; 375 } 376 377 378 /* 379 * Method: InputServer::InitMethods() 380 * Descr: 381 */ 382 void InputServer::InitMethods(void) 383 { 384 BDirectory dir; 385 BPath addon_dir; 386 BPath addon_path; 387 BEntry entry; 388 directory_which addon_dirs[] = 389 { 390 B_BEOS_ADDONS_DIRECTORY, 391 B_COMMON_ADDONS_DIRECTORY, 392 B_USER_ADDONS_DIRECTORY 393 }; 394 const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which); 395 396 printf("InputServer::InitMethods - Enter\n"); 397 398 // Find all Input Methods in each of the predefined 399 // addon directories. 400 // 401 for (int i = 0; i < addon_dir_count; i++) 402 { 403 if (B_OK == find_directory(addon_dirs[i], &addon_dir) ) 404 { 405 addon_dir.Append("input_server/methods"); 406 dir.SetTo(addon_dir.Path() ); 407 while (B_NO_ERROR == dir.GetNextEntry(&entry, false) ) 408 { 409 entry.GetPath(&addon_path); 410 printf("Adding %s . . .\n", addon_path.Path() ); 411 AddInputServerMethod(addon_path.Path() ); 412 } 413 } 414 } 415 printf("InputServer::InitMethods - Exit\n"); 416 } 417 418 419 /* 420 * Method: InputServer::AddInputServerMethod() 421 * Descr: 422 */ 423 status_t InputServer::AddInputServerMethod(const char* path) 424 { 425 image_id addon_image= load_add_on(path); 426 if (B_ERROR != addon_image) 427 { 428 status_t ism_status = B_NO_INIT; 429 BInputServerMethod* (*func)() = NULL; 430 if (B_OK == get_image_symbol(addon_image, "instantiate_input_method", B_SYMBOL_TYPE_TEXT, (void**)&func) ) 431 { 432 if (NULL != func) 433 { 434 /* 435 // :DANGER: Only reenable this section if this 436 // InputServer can start and manage the 437 // methods, otherwise the system will hang. 438 // 439 BInputServerMethod ism = (*func)(); 440 if (NULL != ism) 441 { 442 ism_status = ism->InitCheck(); 443 mInputServerMethodList.AddItem( 444 new InputServerMethodListEntry(path, ism_status, ism) ); 445 } 446 */ 447 mInputServerMethodList.AddItem( 448 new InputServerMethodListEntry(path, B_NO_INIT, NULL) ); 449 } 450 } 451 if (B_OK != ism_status) 452 { 453 // Free resources associated with InputServerMethods 454 // that failed to initialize. 455 // 456 unload_add_on(addon_image); 457 } 458 } 459 return 0; 460 } 461 462 463 /* 464 * Method: InputServer::QuitRequested() 465 * Descr: 466 */ 467 bool InputServer::QuitRequested(void) 468 { 469 kill_thread(ISPortThread); 470 delete_port(EventLooperPort); 471 EventLooperPort = -1; 472 return true; 473 } 474 475 // --------------------------------------------------------------- 476 // InputServer::ReadyToRun(void) 477 // 478 // Verifies to see if the input_server is able to start. 479 // 480 // 481 // Parameters: 482 // None 483 // 484 // Returns: 485 // B_OK if the 486 // --------------------------------------------------------------- 487 void InputServer::ReadyToRun(void) 488 { 489 } 490 491 492 /* 493 * Method: InputServer::MessageReceived() 494 * Descr: 495 */ 496 void InputServer::MessageReceived(BMessage *message) 497 { 498 BMessenger *app_server; 499 switch(message->what) 500 { 501 case SET_METHOD: 502 { 503 //HandleSetMethod(); 504 break; 505 } 506 case GET_MOUSE_TYPE: 507 { 508 //HandleGetSetMouseType(); 509 break; 510 } 511 case SET_MOUSE_TYPE: 512 { 513 //HandleGetSetMouseType(); 514 break; 515 } 516 case GET_MOUSE_ACCELERATION: 517 { 518 //HandleGetSetMouseAcceleration(); 519 break; 520 } 521 case SET_MOUSE_ACCELERATION: 522 { 523 //HandleGetSetMouseAcceleration(); 524 break; 525 } 526 case GET_KEY_REPEAT_DELAY: 527 { 528 //HandleGetSetKeyRepeatDelay(); 529 break; 530 } 531 case SET_KEY_REPEAT_DELAY: 532 { 533 //HandleGetSetKeyRepeatDelay(); 534 break; 535 } 536 case GET_KEY_INFO: 537 { 538 //HandleGetKeyInfo(); 539 break; 540 } 541 case GET_MODIFIERS: 542 { 543 //HandleGetModifiers(); 544 break; 545 } 546 case SET_MODIFIER_KEY: 547 { 548 //HandleSetModifierKey(); 549 break; 550 } 551 case SET_KEYBOARD_LOCKS: 552 { 553 //HandleSetKeyboardLocks(); 554 break; 555 } 556 case GET_MOUSE_SPEED: 557 { 558 //HandleGetSetMouseSpeed(); 559 break; 560 } 561 case SET_MOUSE_SPEED: 562 { 563 //HandleGetSetMouseSpeed(); 564 break; 565 } 566 case SET_MOUSE_POSITION: 567 { 568 //HandleSetMousePosition(); 569 break; 570 } 571 case GET_MOUSE_MAP: 572 { 573 //HandleGetSetMouseMap(); 574 break; 575 } 576 case SET_MOUSE_MAP: 577 { 578 //HandleGetSetMouseMap(); 579 break; 580 } 581 case GET_KEYBOARD_ID: 582 { 583 //HandleGetKeyboardID(); 584 break; 585 } 586 case GET_CLICK_SPEED: 587 { 588 //HandleGetSetClickSpeed(); 589 break; 590 } 591 case SET_CLICK_SPEED: 592 { 593 //HandleGetSetClickSpeed(); 594 break; 595 } 596 case GET_KEY_REPEAT_RATE: 597 { 598 //HandleGetSetKeyRepeatRate(); 599 break; 600 } 601 case SET_KEY_REPEAT_RATE: 602 { 603 //HandleGetSetKeyRepeatRate(); 604 break; 605 } 606 case GET_KEY_MAP: 607 { 608 //HandleGetSetKeyMap(); 609 break; 610 } 611 case SET_KEY_MAP: 612 { 613 //HandleGetSetKeyMap(); 614 break; 615 } 616 case FOCUS_IM_AWARE_VIEW: 617 { 618 //HandleFocusUnfocusIMAwareView(); 619 break; 620 } 621 case UNFOCUS_IM_AWARE_VIEW: 622 { 623 //HandleFocusUnfocusIMAwareView(); 624 break; 625 } 626 case B_QUIT_REQUESTED: 627 { 628 QuitRequested(); 629 } 630 631 default: 632 { 633 printf("Default message . . .\n"); 634 app_server = new BMessenger("application/x-vnd.Be-APPS", -1, NULL); 635 if (app_server->IsValid()) 636 { 637 //app_server->SendMessage(message); 638 639 } 640 delete app_server; 641 break; 642 } 643 } 644 } 645 646 647 /* 648 * Method: InputServer::HandleSetMethod() 649 * Descr: 650 */ 651 void InputServer::HandleSetMethod(BMessage *) 652 { 653 } 654 655 656 /* 657 * Method: InputServer::HandleGetSetMouseType() 658 * Descr: 659 */ 660 void InputServer::HandleGetSetMouseType(BMessage *, 661 BMessage *) 662 { 663 } 664 665 666 /* 667 * Method: InputServer::HandleGetSetMouseAcceleration() 668 * Descr: 669 */ 670 void InputServer::HandleGetSetMouseAcceleration(BMessage *, 671 BMessage *) 672 { 673 } 674 675 676 /* 677 * Method: InputServer::HandleGetSetKeyRepeatDelay() 678 * Descr: 679 */ 680 void InputServer::HandleGetSetKeyRepeatDelay(BMessage *, 681 BMessage *) 682 { 683 } 684 685 686 /* 687 * Method: InputServer::HandleGetKeyInfo() 688 * Descr: 689 */ 690 void InputServer::HandleGetKeyInfo(BMessage *, 691 BMessage *) 692 { 693 } 694 695 696 /* 697 * Method: InputServer::HandleGetModifiers() 698 * Descr: 699 */ 700 void InputServer::HandleGetModifiers(BMessage *, 701 BMessage *) 702 { 703 } 704 705 706 /* 707 * Method: InputServer::HandleSetModifierKey() 708 * Descr: 709 */ 710 void InputServer::HandleSetModifierKey(BMessage *, 711 BMessage *) 712 { 713 } 714 715 716 /* 717 * Method: InputServer::HandleSetKeyboardLocks() 718 * Descr: 719 */ 720 void InputServer::HandleSetKeyboardLocks(BMessage *, 721 BMessage *) 722 { 723 } 724 725 726 /* 727 * Method: InputServer::HandleGetSetMouseSpeed() 728 * Descr: 729 */ 730 void InputServer::HandleGetSetMouseSpeed(BMessage *, 731 BMessage *) 732 { 733 } 734 735 736 /* 737 * Method: InputServer::HandleSetMousePosition() 738 * Descr: 739 */ 740 void InputServer::HandleSetMousePosition(BMessage *message, BMessage *outbound) 741 { 742 743 // this assumes that both supplied pointers are identical 744 745 ASSERT(outbound == message); 746 747 sMousePos.x = 200; 748 sMousePos.y = 200; 749 750 int32 xValue, 751 yValue; 752 753 message->FindInt32("x",xValue); 754 printf("[HandleSetMousePosition] x = %lu:\n",xValue); 755 756 switch(message->what){ 757 case B_MOUSE_MOVED:{ 758 // get point and button from msg 759 if((outbound->FindInt32(X_VALUE,&xValue) == B_OK) && (outbound->FindInt32(Y_VALUE,&yValue) == B_OK)){ 760 sMousePos.x += xValue; 761 sMousePos.y += yValue; 762 outbound->ReplaceInt32(X_VALUE,sMousePos.x); 763 outbound->ReplaceInt32(Y_VALUE,sMousePos.y); 764 } 765 break; 766 } 767 // Should be some Mouse Down and Up code here .. 768 // Along with some Key Down and up codes .. 769 default: 770 break; 771 772 } 773 } 774 775 776 /* 777 * Method: InputServer::HandleGetSetMouseMap() 778 * Descr: 779 */ 780 void InputServer::HandleGetSetMouseMap(BMessage *, 781 BMessage *) 782 { 783 } 784 785 786 /* 787 * Method: InputServer::HandleGetKeyboardID() 788 * Descr: 789 */ 790 void InputServer::HandleGetKeyboardID(BMessage *, 791 BMessage *) 792 { 793 } 794 795 796 /* 797 * Method: InputServer::HandleGetSetClickSpeed() 798 * Descr: 799 */ 800 void InputServer::HandleGetSetClickSpeed(BMessage *, 801 BMessage *) 802 { 803 } 804 805 806 /* 807 * Method: InputServer::HandleGetSetKeyRepeatRate() 808 * Descr: 809 */ 810 void InputServer::HandleGetSetKeyRepeatRate(BMessage *, 811 BMessage *) 812 { 813 } 814 815 816 /* 817 * Method: InputServer::HandleGetSetKeyMap() 818 * Descr: 819 */ 820 void InputServer::HandleGetSetKeyMap(BMessage *, 821 BMessage *) 822 { 823 } 824 825 826 /* 827 * Method: InputServer::HandleFocusUnfocusIMAwareView() 828 * Descr: 829 */ 830 void InputServer::HandleFocusUnfocusIMAwareView(BMessage *, 831 BMessage *) 832 { 833 } 834 835 836 /* 837 * Method: InputServer::EnqueueDeviceMessage() 838 * Descr: 839 */ 840 status_t InputServer::EnqueueDeviceMessage(BMessage *message) 841 { 842 //return (write_port(fEventPort, (int32)message, NULL, 0)); 843 return (write_port(EventLooperPort, (int32)message, NULL, 0)); 844 } 845 846 847 /* 848 * Method: InputServer::EnqueueMethodMessage() 849 * Descr: 850 */ 851 status_t InputServer::EnqueueMethodMessage(BMessage *) 852 { 853 return 0; 854 } 855 856 857 /* 858 * Method: InputServer::UnlockMethodQueue() 859 * Descr: 860 */ 861 status_t InputServer::UnlockMethodQueue(void) 862 { 863 return 0; 864 } 865 866 867 /* 868 * Method: InputServer::LockMethodQueue() 869 * Descr: 870 */ 871 status_t InputServer::LockMethodQueue(void) 872 { 873 return 0; 874 } 875 876 877 /* 878 * Method: InputServer::SetNextMethod() 879 * Descr: 880 */ 881 status_t InputServer::SetNextMethod(bool) 882 { 883 return 0; 884 } 885 886 887 /* 888 * Method: InputServer::SetActiveMethod() 889 * Descr: 890 */ 891 /* 892 InputServer::SetActiveMethod(_BMethodAddOn_ *) 893 { 894 return 0; 895 } 896 */ 897 898 899 /* 900 * Method: InputServer::MethodReplicant() 901 * Descr: 902 */ 903 const BMessenger* InputServer::MethodReplicant(void) 904 { 905 return NULL; 906 } 907 908 909 /* 910 * Method: InputServer::EventLoop() 911 * Descr: 912 */ 913 status_t InputServer::EventLoop(void *) 914 { 915 printf("Starting event loop . . .\n"); 916 EventLooperPort = create_port(100, "obos_is_event_port"); 917 if(EventLooperPort < 0) { 918 _sPrintf("OBOS InputServer: create_port error: (0x%x) %s\n",EventLooperPort,strerror(EventLooperPort)); 919 } 920 ISPortThread = spawn_thread(ISPortWatcher, "_input_server_event_loop_", B_REAL_TIME_DISPLAY_PRIORITY+3, this); 921 resume_thread(ISPortThread); 922 923 return 0; 924 } 925 926 927 /* 928 * Method: InputServer::EventLoopRunning() 929 * Descr: 930 */ 931 bool InputServer::EventLoopRunning(void) 932 { 933 return true; 934 } 935 936 937 /* 938 * Method: InputServer::DispatchEvents() 939 * Descr: 940 */ 941 bool InputServer::DispatchEvents(BList *eventList) 942 { 943 BMessage *event; 944 945 for ( int32 i = 0; NULL != (event = (BMessage *)eventList->ItemAt(i)); i++ ) 946 { 947 // now we must send each event to the app_server 948 DispatchEvent(event); 949 } 950 return true; 951 }// end DispatchEvents() 952 953 int InputServer::DispatchEvent(BMessage *message) 954 { 955 // variables 956 int32 xValue, 957 yValue; 958 uint32 buttons = 0; 959 960 message->FindInt32("x",xValue); 961 printf("[DispatchEvent] x = %lu:\n",xValue); 962 963 port_id pid = find_port(SERVER_INPUT_PORT); 964 PortLink *appsvrlink = new PortLink(pid); 965 switch(message->what){ 966 case B_MOUSE_MOVED:{ 967 // get point and button from msg 968 if((message->FindInt32(X_VALUE,&xValue) == B_OK) && (message->FindInt32(Y_VALUE,&yValue) == B_OK)){ 969 int64 time=(int64)real_time_clock(); 970 appsvrlink->SetOpCode(B_MOUSE_MOVED); 971 appsvrlink->Attach(&time,sizeof(int64)); 972 appsvrlink->Attach((float)xValue); 973 appsvrlink->Attach((float)yValue); 974 message->FindInt32("buttons",buttons); 975 appsvrlink->Attach(&buttons,sizeof(int32)); 976 appsvrlink->Flush(); 977 printf("B_MOUSE_MOVED: x = %lu: y = %lu: time = %llu: buttons = %lu\n",xValue,yValue,time,buttons); 978 } 979 break; 980 } 981 // Should be some Mouse Down and Up code here .. 982 // Along with some Key Down and up codes .. 983 default: 984 break; 985 986 } 987 delete appsvrlink; 988 return true; 989 } 990 991 /* 992 * Method: InputServer::CacheEvents() 993 * Descr: 994 */ 995 bool InputServer::CacheEvents(BList *) 996 { 997 return true; 998 } 999 1000 1001 /* 1002 * Method: InputServer::GetNextEvents() 1003 * Descr: 1004 */ 1005 const BList* InputServer::GetNextEvents(BList *) 1006 { 1007 return NULL; 1008 } 1009 1010 1011 /* 1012 * Method: InputServer::FilterEvents() 1013 * Descr: This method applies all defined filters to each event in the 1014 * supplied list. The supplied list is modified to reflect the 1015 * output of the filters. 1016 * The method returns true if the filters were applied to all 1017 * events without error and false otherwise. 1018 */ 1019 bool InputServer::FilterEvents(BList *eventsToFilter) 1020 { 1021 if (NULL != eventsToFilter) 1022 { 1023 BInputServerFilter* current_filter; 1024 BMessage* current_event; 1025 int32 filter_index = 0; 1026 int32 event_index = 0; 1027 1028 while (NULL != (current_filter = (BInputServerFilter*)mInputServerFilterList.ItemAt(filter_index) ) ) 1029 { 1030 // Apply the current filter to all available event messages. 1031 // 1032 while (NULL != (current_event = (BMessage*)eventsToFilter->ItemAt(event_index) ) ) 1033 { 1034 // Storage for new event messages generated by the filter. 1035 // 1036 BList out_list; 1037 1038 // Apply the current filter to the current event message. 1039 // 1040 filter_result result = current_filter->Filter(current_event, &out_list); 1041 if (B_DISPATCH_MESSAGE == result) 1042 { 1043 // Use the result in current_message; ignore out_list. 1044 // 1045 event_index++; 1046 1047 // Free resources associated with items in out_list. 1048 // 1049 void* out_item; 1050 for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++) 1051 { 1052 delete out_item; 1053 } 1054 } 1055 else if (B_SKIP_MESSAGE == result) 1056 { 1057 // Use the result in out_list (if any); ignore current message. 1058 // 1059 eventsToFilter->RemoveItem(event_index); 1060 eventsToFilter->AddList(&out_list, event_index); 1061 event_index += out_list.CountItems(); 1062 1063 // NOTE: eventsToFilter now owns out_list's items. 1064 } 1065 else 1066 { 1067 // Error - Free resources associated with items in out_list and return. 1068 // 1069 void* out_item; 1070 for (int32 i = 0; NULL != (out_item = out_list.ItemAt(i) ); i++) 1071 { 1072 delete out_item; 1073 } 1074 return false; 1075 } 1076 1077 // NOTE: The BList destructor frees out_lists's resources here. 1078 // It does NOT free the resources associated with out_list's 1079 // member items - those should either already be deleted or 1080 // should be owned by eventsToFilter. 1081 } 1082 1083 } // while() 1084 1085 filter_index++; 1086 1087 } // while() 1088 1089 return true; 1090 } 1091 1092 1093 /* 1094 * Method: InputServer::SanitizeEvents() 1095 * Descr: 1096 */ 1097 bool InputServer::SanitizeEvents(BList *) 1098 { 1099 return true; 1100 } 1101 1102 1103 /* 1104 * Method: InputServer::MethodizeEvents() 1105 * Descr: 1106 */ 1107 bool InputServer::MethodizeEvents(BList *, 1108 bool) 1109 { 1110 return true; 1111 } 1112 1113 1114 /* 1115 * Method: InputServer::StartStopDevices() 1116 * Descr: 1117 */ 1118 status_t InputServer::StartStopDevices(const char* deviceName, 1119 input_device_type deviceType, 1120 bool doStart) 1121 { 1122 printf("StartStopDevice: Enter\n"); 1123 for (int i = gInputDeviceList.CountItems() - 1; i >= 0; i--) 1124 { 1125 printf("Device #%d\n", i); 1126 InputDeviceListItem* item = (InputDeviceListItem*)gInputDeviceList.ItemAt(i); 1127 if (NULL != item) 1128 { 1129 BInputServerDevice* isd = item->mIsd; 1130 input_device_ref* dev = item->mDev; 1131 printf("Hey\n"); 1132 if ( (NULL != isd) && (NULL != dev) ) 1133 { 1134 printf(" Starting/stopping: %s\n", dev->name); 1135 if (deviceType == dev->type) 1136 { 1137 if (doStart) isd->Start(dev->name, dev->cookie); 1138 else isd->Stop(dev->name, dev->cookie); 1139 } 1140 } 1141 } 1142 } 1143 printf("StartStopDevice: Exit\n"); 1144 1145 return B_OK; 1146 } 1147 1148 1149 /* 1150 * Method: InputServer::ControlDevices() 1151 * Descr: 1152 */ 1153 status_t InputServer::ControlDevices(const char *, 1154 input_device_type, 1155 unsigned long, 1156 BMessage *) 1157 { 1158 return 0; 1159 } 1160 1161 1162 /* 1163 * Method: InputServer::DoMouseAcceleration() 1164 * Descr: 1165 */ 1166 bool InputServer::DoMouseAcceleration(long *, 1167 long *) 1168 { 1169 return true; 1170 } 1171 1172 1173 /* 1174 * Method: InputServer::SetMousePos() 1175 * Descr: 1176 */ 1177 bool InputServer::SetMousePos(long *, 1178 long *, 1179 long, 1180 long) 1181 { 1182 return true; 1183 } 1184 1185 1186 /* 1187 * Method: InputServer::SetMousePos() 1188 * Descr: 1189 */ 1190 bool InputServer::SetMousePos(long *, 1191 long *, 1192 BPoint) 1193 { 1194 return true; 1195 } 1196 1197 1198 /* 1199 * Method: InputServer::SetMousePos() 1200 * Descr: 1201 */ 1202 bool InputServer::SetMousePos(long *, 1203 long *, 1204 float, 1205 float) 1206 { 1207 return true; 1208 } 1209 1210 1211 /* 1212 * Method: InputServer::SafeMode() 1213 * Descr: 1214 */ 1215 bool InputServer::SafeMode(void) 1216 { 1217 return true; 1218 } 1219 1220 int32 InputServer::ISPortWatcher(void *arg) 1221 { 1222 InputServer *self = (InputServer*)arg; 1223 self->WatchPort(); 1224 return (B_NO_ERROR); 1225 } 1226 1227 void InputServer::WatchPort() 1228 { 1229 int32 code; 1230 ssize_t length; 1231 char *buffer; 1232 status_t err; 1233 1234 while (true) { 1235 // Block until we find the size of the next message 1236 length = port_buffer_size(EventLooperPort); 1237 buffer = (char*)malloc(length); 1238 printf("[Event Looper] BMessage Size = %lu\n", length); 1239 //event = NULL; 1240 BMessage *event = new BMessage(); 1241 err = read_port(EventLooperPort, &code, buffer, length); 1242 if(err != length) { 1243 if(err >= 0) { 1244 printf("InputServer: failed to read full packet (read %lu of %lu)\n",err,length); 1245 } else { 1246 printf("InputServer: read_port error: (0x%lx) %s\n",err,strerror(err)); 1247 } 1248 }else{ 1249 1250 if ((err = event->Unflatten(buffer)) < 0) { 1251 printf("[InputServer] Unflatten() error: (0x%lx) %s\n",err,strerror(err)); 1252 } else { 1253 // This is where the message should be processed. 1254 event->PrintToStream(); 1255 1256 HandleSetMousePosition(event, event); 1257 1258 DispatchEvent(event); 1259 1260 //printf("Event writen to port\n"); 1261 delete(event); 1262 } 1263 1264 } 1265 free(buffer); 1266 if(event!=NULL) { 1267 //delete(event); 1268 event = NULL; 1269 } 1270 } 1271 1272 } 1273 1274