1/* 2 * Copyright 2008-2019 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Niels Sascha Reedijk, niels.reedijk@gmail.com 7 * John Scipione, jscipione@gmail.com 8 * Adrien Destugues, pulkomandy@pulkomandy.tk 9 * 10 * Corresponds to: 11 * headers/os/app/Looper.h hrev52501 12 * src/kits/app/Looper.cpp hrev52501 13 */ 14 15 16/*! 17 \file Looper.h 18 \ingroup app 19 \ingroup libbe 20 \brief Provides the BLooper class. 21*/ 22 23 24/*! 25 \def B_LOOPER_PORT_DEFAULT_CAPACITY 26 \brief The default size of the port of a BLooper. 27 28 \since BeOS R3 29*/ 30 31 32/*! 33 \class BLooper 34 \ingroup app 35 \ingroup libbe 36 \brief Receive and process messages in a separate thread. 37 38 When an object of this class is created, the message loop can be started 39 with Run(). This spawns the thread that receives messages and processes 40 messages. Messages are actually passed on to \link BHandler handlers \endlink 41 that are associated with this looper. By default there is always one 42 handler available: the looper itself. To 'quit' a looper, you should pass 43 a \c B_QUIT_REQUESTED message using one of the message post functions. When 44 a looper receives such a request, it will \b delete itself. As such, looper 45 should <em>always be created on the heap</em> (with \c new), and never on 46 the stack. 47 48 Posting messages can be done using the various PostMessage() methods. 49 Whenever a message is posted, it will be added through to the message 50 queue. It is possible to apply filters (see AddCommonFilter()) to filter 51 out any messages that correspond with certain criteria. The method will 52 copy the contents of the message and this copy is processed, so make sure 53 you delete the original messages in case you create them on the heap. 54 The handler for the message is chosen using the following criteria: 55 56 -# If PostMessage() or the BMessenger is set to a specific handler, and 57 this handler is associated with this looper, than the message is 58 processed by that handler. 59 -# Else, the preferred handler is used. You can set this using 60 SetPreferredHandler(). 61 -# If there is no preferred handler, then the looper itself will process 62 the message. 63 64 Because a looper usually is used in multiple threads, you should make sure 65 you Lock() and Unlock() it during most operations. Locking calls can be 66 recursive (so multiple locks can come from a single thread), but make sure 67 you pair every Lock() with an Unlock() call. Failing to do so will 68 inevitably cause a deadlock. 69 70 Because a looper provides a separate thread, and the inherited handler is 71 usually a default handler, you will most often use this class by 72 subclassing it. For example, you are likely to subclass BWindow (which is 73 derived from BLooper) to customize your window and handle the messages 74 sent to that window. You can override Run() in case you want to perform 75 additional tasks before (or right after) starting the message loop. You can 76 override QuitRequested() if you want to decline quitting in certain 77 circumstances. You can override Quit() in case you want to perform 78 additional procedures during closing time. You can also override 79 DispatchMessage() if you want to do something with all incoming messages 80 before they are dispatched to a handler. 81 82 BLooper is one of the major base classes of the Haiku application 83 programmers interface. Closely related classes are BMessage, BHandler and 84 BMessenger. It is used in the interface kit, for example by the BWindow 85 class, which makes sure every window runs it its own thread. 86 87 BLooper is a part of the chain in the eloquent messaging structure. For a 88 proper understanding of all its facets, have a look at the \ref app_messaging 89 "messaging overview". 90 91 \since BeOS R3 92*/ 93 94 95/*! 96 \fn BLooper::BLooper(const char* name, int32 priority, int32 portCapacity) 97 \brief Construct a new BLooper with a \a priority and an \a capacity. 98 99 The new looper is, by default, not running yet. If you have set up 100 everything properly, you may call Run(). 101 102 \attention Remember that loopers should be created on the heap, because 103 they will \c delete themselves in the Quit() method. 104 105 \param name The name of the looper. 106 \param priority The priority of the message thread of this looper. The 107 default priority should be good enough for most tasks. Also, some 108 derived versions of BLooper will use a specialized priority. So it 109 is advised to leave this setting at the default, unless you know 110 why you would like another setting. 111 \param portCapacity Loopers use ports to send and receive messages (see 112 the kernel kit). Ports have a maximum capacity; if there are so many 113 messages queued that the port is full, all other incoming messages 114 are dropped. There are situations where the size of the port should 115 be different from the default. This might be when your looper 116 receives a lot of messages, or if the message handling thread runs 117 at a lower priority than normal, which would decrease the processing 118 speed. Finding a suitable value for these custom scenarios would be 119 done by testing. 120 121 \see Run() 122 123 \since BeOS R3 124*/ 125 126 127/*! 128 \fn BLooper::~BLooper() 129 \brief Destruct the looper. 130 131 You will never delete a looper yourself. You should pass a 132 \c B_QUIT_REQUESTED message, or if you are destroying the looper from 133 inside its own message handling thread, you should call Quit(). 134 135 \see Quit() 136 137 \since BeOS R3 138*/ 139 140 141///// Archiving ///// 142 143 144/*! 145 \name Archiving 146*/ 147 148 149//! @{ 150 151 152/*! 153 \fn BLooper::BLooper(BMessage* data) 154 \brief Construct a looper from an archived message. 155 156 The \a data message has to be constructed by a BLooper::Archive() call. 157 Note that the data that is restored, is merely the port capacity and the 158 name of the looper/handler. Other data, such as filters, is not archived by 159 the default archiver. 160 161 \warning This constructor does no type check whatsoever. Since you can pass 162 any BMessage, you should - if you are not sure about the exact 163 type - use the Instantiate() method, which does check the type. 164 165 \see Instantiate() 166 \see Archive() 167 168 \since BeOS R3 169*/ 170 171 172/*! 173 \fn BArchivable* BLooper::Instantiate(BMessage* data) 174 \brief Static method to instantiate a looper from an archived message. 175 176 \return A pointer to the instantiated looper, or \c NULL if the \a data 177 is not a valid archived BLooper object. 178 179 \see BLooper(BMessage* data) 180 181 \since BeOS R3 182*/ 183 184 185/*! 186 \fn status_t BLooper::Archive(BMessage* data, bool deep) const 187 \brief Archive a looper to a message 188 189 Currently, only the name and the port capacity are archived. Any other 190 data, such as the filters, is not stored. 191 192 \param data The message to archive the object in. 193 \param deep This parameter is ignored, as BLooper does not have children. 194 195 \retval B_OK Archiving succeeded. 196 \retval B_BAD_VALUE The \a data parameter is not a valid message. 197 198 \see BLooper::Instantiate(BMessage* data) 199 200 \since BeOS R3 201*/ 202 203 204//! @} 205 206 207/*! 208 \name Message Mechanics 209*/ 210 211 212//! @{ 213 214 215/*! 216 \fn status_t BLooper::PostMessage(uint32 command) 217 \brief Post a message with the \a command as \c what identifier to this 218 looper. 219 220 Posting a message puts it in the message queue. The message passes through 221 the default handler chain. 222 223 \param command The \c what identifier of the message to be sent. 224 225 \return A status code. 226 \retval B_OK The operation succeeded, and the message is sent to the port. 227 \retval B_ERROR There was a general operation error. 228 \retval B_BAD_VALUE This looper is not yet running and therefore cannot 229 receive messages. 230 231 \see PostMessage(BMessage *) if you want to send a message with data 232 members. 233 \see PostMessage(uint32, BHandler *, BHandler *) if you want to send a 234 message to a specific handler, and request a reply. 235 \see PostMessage(BMessage *, BHandler *, BHandler *) for the same thing, 236 but with a complete message. 237 238 \since BeOS R5 239*/ 240 241 242/*! 243 \fn status_t BLooper::PostMessage(BMessage* message) 244 \brief Post a \a message to this looper. 245 246 Posting a message puts it in the message queue. The message passes through 247 the default handler chain. 248 249 The \a message is copied, and as such, you should make sure you will not 250 leak it. The best way to send messages is like this: 251\code 252 BMessage message; 253 message.what = B_DO_SOMETHING; 254 message.AddString("some_data", "This is data") 255 256 aLooper->PostMessage(&message); 257\endcode 258 259 \param message The message you would like to pass to this method. 260 261 \return A status code. 262 \retval B_OK The operation succeeded, and the message is sent to the port. 263 \retval B_ERROR There was a general operation error. 264 \retval B_BAD_VALUE This looper is not yet running and therefore cannot 265 receive messages. 266 267 \see PostMessage(uint32) if you want to send a message without data 268 members. 269 \see PostMessage(uint32, BHandler *, BHandler *) if you want to send a 270 message to a specific handler, and request a reply. 271 \see PostMessage(BMessage *, BHandler *, BHandler *) for the same thing, 272 but with a complete message. 273 274 \since BeOS R5 275*/ 276 277 278/*! 279 \fn status_t BLooper::PostMessage(uint32 command, BHandler* handler, 280 BHandler* replyTo) 281 \brief Sends a message with \a command \c what identifier to the 282 \a handler associated with this looper. A response may be sent to the 283 \a replyTo handler asynchronously. 284 285 The target \a handler should be associated with this looper. This method 286 bypasses the default message queue. 287 288 \param command The value you want as the message's \c what identifier. 289 \param handler The handler you would like to pass this message to. 290 \param replyTo If you would like to request a reply, pass the handler to 291 which this reply should be directed to. If you pass \c NULL, you 292 will not receive a reply. 293 294 \return A status code. 295 \retval B_OK The operation succeeded, and the message is sent to the port. 296 \retval B_ERROR There was a general operation error. 297 \retval B_BAD_VALUE This looper is not yet running and therefore cannot 298 receive messages. 299 \retval B_MISMATCHED_VALUES The \a handler is not associated with this 300 looper. 301 302 \see PostMessage(uint32) if you want to send a message without data 303 members. 304 \see PostMessage(BMessage *) if you want to send a message with data 305 members. 306 \see PostMessage(BMessage *, BHandler *, BHandler *) if you want to send a 307 message to a specific handler, and request a reply. 308 309 \since BeOS R5 310*/ 311 312 313/*! 314 \fn status_t BLooper::PostMessage(BMessage* message, BHandler* handler, 315 BHandler* replyTo) 316 \brief Send a \a message to the \a handler associated with this looper. 317 A response may be sent to the \a replyTo handler asynchronously. 318 319 The target \a handler should be associated with this looper. This method 320 bypasses the default message queue. 321 322 The \a message is copied, and as such, you should make sure you will not 323 leak it. The best way to send messages is like this: 324\code 325 BMessage message; 326 message.what = B_DO_SOMETHING; 327 message.AddString("some_data", "This is data") 328 329 aLooper->PostMessage(&message, aHandler); 330\endcode 331 332 \param message The message you want to pass. 333 \param handler The handler you would like to pass this message to. 334 \param replyTo If you would like to request a reply, pass the handler to 335 which this reply should be directed to. If you pass \c NULL, you 336 will not receive a reply. 337 338 \return A status code. 339 \retval B_OK The operation succeeded, and the message is sent to the port. 340 \retval B_ERROR There was a general operation error. 341 \retval B_BAD_VALUE This looper is not yet running and therefore cannot 342 receive messages. 343 \retval B_MISMATCHED_VALUES The \a handler is not associated with this 344 looper. 345 346 \see PostMessage(uint32) if you want to send a message without data 347 members. 348 \see PostMessage(BMessage *) if you want to send a message with data 349 members. 350 \see PostMessage(uint32, BHandler *, BHandler *) if you want to send a 351 message without data to a specific handler, and request a reply. 352 353 \since BeOS R5 354*/ 355 356 357//! @} 358 359 360/*! 361 \name Message Processing 362*/ 363 364 365//! @{ 366 367 368/*! 369 \fn void BLooper::DispatchMessage(BMessage *message, BHandler *handler) 370 \brief Dispatch a message to a handler. Override if there are messages that 371 you want to catch before they are sent to the handlers. 372 373 This method is called by the message looping thread to dispatch a message 374 to \a handler. If you implement the BLooper class and your looper receives 375 messages that absolutely have to be processed by the looper instead of any 376 of the handlers, override this method. For example, the default 377 implementation catches B_QUIT_REQUESTED messages before they are sent to 378 the handlers, so that the looper will quit at those messages. 379 380 You are discouraged from using this method to filter out any messages you 381 do not want to process. For this, there is a more generic method using 382 the BMessageFilter class. If you want to skip messages with certain 383 patterns, have a look at the AddCommonFilter() and SetCommonFilterList() 384 methods. 385 386 If you do override this method, please remember to call the 387 DispatchMessage() method of the parent class. 388 389 \since BeOS R3 390*/ 391 392 393/*! 394 \fn void BLooper::MessageReceived(BMessage* message) 395 \brief Process a message received by the internal handler of this looper. 396 397 Reimplemented from BHandler::MessageReceived(); 398 399 \since BeOS R5 400*/ 401 402 403/*! 404 \fn BMessage* BLooper::CurrentMessage() const 405 \brief Retrieve the current message. 406 407 \attention Only call this method from within the thread that processes the 408 messages. It contains a pointer to the message that is currently 409 being handled. Due to the multithreaded nature of the operating 410 system, this method will not safely let you read the message 411 that is being processed by this handler from outside the context 412 of the processing. If you do want to use a message outside of 413 the processing thread, have a look at DetachCurrentMessage() to 414 safely retrieve a message. 415 416 \return A pointer to the message that is currently being processed. Note 417 that calling it from outside the thread that processes the message, 418 could give you a \c NULL pointer or an invalid pointer. 419 420 \since BeOS R5 421*/ 422 423 424/*! 425 \fn BMessage* BLooper::DetachCurrentMessage() 426 \brief Get ownership of the message currently being processed. 427 428 Retrieve the current message and gain ownership of it. This means that the 429 message will not be deleted as soon as the looper is done processing it. 430 You can then use it for different purposes. 431 432 \attention Only call this method from within the thread that processes the 433 messages. Due to the multithreaded nature of the operating 434 system, calling it from another thread is very likely to give 435 you an invalid or a \c NULL pointer. 436 437 \since BeOS R5 438*/ 439 440 441/*! 442 \fn void BLooper::DispatchExternalMessage(BMessage* message, 443 BHandler* handler, bool& _detached) 444 \brief Internal method to support single-threaded GUI toolkits 445 446 \since Haiku R1 447*/ 448 449 450/*! 451 \fn BMessageQueue* BLooper::MessageQueue() const 452 \brief Get a pointer to the internal message queue of this looper. 453 454 You can use this pointer to manipulate the message queue. Note that the 455 message that is being processed is already detached from this queue. 456 457 \return A pointer to the internal message queue. 458 459 \since BeOS R5 460*/ 461 462 463/*! 464 \fn bool BLooper::IsMessageWaiting() const 465 \brief Check if there is a message waiting. 466 467 \return \c true if there are still messages to be processed, 468 \c false if there is no message waiting. 469*/ 470 471 472//! @} 473 474 475/*! 476 \name Handler Management 477*/ 478 479 480//! @{ 481 482 483/*! 484 \fn void BLooper::AddHandler(BHandler* handler) 485 \brief Associate a \a handler to this looper. 486 487 The \a handler will be associated to this looper. By default, the handler 488 in this looper will be chained to the supplied \a handler. 489 490 \param handler The handler to associate with this looper. If the handler 491 is already associated to another looper, the operation will fail 492 silently. Check beforehand if you cannot be sure that the 493 \a handler is unassociated. 494 495 \see RemoveHandler() 496 497 \since BeOS R3 498*/ 499 500 501/*! 502 \fn bool BLooper::RemoveHandler(BHandler* handler) 503 \brief Disassociate a \a handler from this looper. 504 505 If the handler is disassociated, it can be reassociated to another looper. 506 507 \return \c true if the \a handler has been removed from this looper, 508 \c false The \a handler was invalid or the handler was not 509 associated to this looper. 510 511 \see AddHandler() 512 513 \since BeOS R3 514*/ 515 516 517/*! 518 \fn int32 BLooper::CountHandlers() const 519 \brief Get the number of handlers associated with this looper. 520 521 \see HandlerAt() 522 \see IndexOf() 523 524 \since BeOS R3 525*/ 526 527 528/*! 529 \fn BHandler* BLooper::HandlerAt(int32 index) const 530 \brief Get the handler at an \a index of the list of associated handlers. 531 532 \return A pointer to the handler at that \a index, or \c NULL if the 533 \a index is out of range. 534 535 \see CountHandlers() 536 \see IndexOf() 537 538 \since BeOS R3 539*/ 540 541 542/*! 543 \fn int32 BLooper::IndexOf(BHandler* handler) const 544 \brief Get the index of the \a handler that is in the associated handler 545 list. 546 547 \return The index of the handler in the list if the \a handler is in the 548 list, else this method will return -1. 549 550 \since BeOS R3 551*/ 552 553 554/*! 555 \fn BHandler* BLooper::PreferredHandler() const 556 \brief Get the preferred handler. 557 558 \return A pointer to the preferred handler, or \c NULL if none is set. 559 560 \see SetPreferredHandler() 561 562 \since BeOS R3 563*/ 564 565 566/*! 567 \fn void BLooper::SetPreferredHandler(BHandler* handler) 568 \brief Set a preferred handler. 569 570 If messages are posted to this looper using one of the PostMessage() 571 methods without a specific BHandler argument, the messages will be handled 572 by the looper itself (since a looper is a subclass of BHandler, this is 573 perfectly possible). If you want to override that behavior, you should set 574 a preferred handler. This handler will be called if incoming messages do 575 not ask to be directly passed on to a specific handler. 576 577 \param handler The preferred handler you want undesignated messages to be 578 handled by. If you want to unset the preferred handler, pass 579 \c NULL. If the supplied \a handler is not associated with this 580 looper, this call will fail silently and the current preferred 581 handler will be unset. 582 583 \see PreferredHandler() 584 585 \since BeOS R3 586*/ 587 588 589//! @} 590 591 592/*! 593 \name Loop Control 594*/ 595 596 597//! @{ 598 599 600/*! 601 \fn thread_id BLooper::Run() 602 \brief Start the event loop. 603 604 After the looper has been constructed, it needs to be started using this 605 method. A thread will be spawned, which will receive messages. 606 607 Make sure the looper is not yet running before you call this method. 608 609 \return A (positive) thread id if spawning the thread succeeded, or an 610 error code. 611 612 \since BeOS R3 613*/ 614 615 616/*! 617 \fn thread_id BLooper::Loop() 618 \brief Run the event loop in the current thread. 619 620 This method runs the event loop in an already existing thread. It blocks 621 until the looper stops looping. This can 622 be used to turn an existing thread into a BLooper. 623 624 Make sure the looper is not yet running before you call this method. 625 626 \since Haiku R1 627*/ 628 629 630/*! 631 \fn void BLooper::Quit() 632 \brief Hook method that is called after a \c B_QUIT_REQUESTED message. 633 634 If you want to quit and delete the looper, you should post a 635 \c B_QUIT_REQUESTED message. This will first call the hook method 636 QuitRequested(), which can be overridden in child classes in case there 637 are conditions that would prevent the looper to be quit. If you really 638 know what you are doing, and you definitely want to quit this looper, 639 you may call this method, but only after performing a Lock() operation. 640 641 Override this method if your subclass needs to perform specific clean-up 642 tasks. Remember to call the base class implementation when you're done. 643 644 \attention You will not have to delete the looper object, if a looper quits 645 it will delete itself. 646 647 \since BeOS R3 648*/ 649 650 651/*! 652 \fn bool BLooper::QuitRequested() 653 \brief Hook method that is called during a \c B_QUIT_REQUESTED message. 654 655 This hook function is called by the looper thread when a 656 \c B_QUIT_REQUESTED is received. The default implementation always accepts 657 the message, but if your subclass needs a special condition to be met 658 before actually accepting a quit message, you can test for that condition 659 in this hook method. A good example is a window (which is a derivative of 660 BLooper), which contains a modified document. The condition may be that a 661 modal dialog requesting a path of action is closed. 662 663 \return \c true if the looper can be quit and destroyed, 664 \c false if this method does not accept the quit message 665 and continue processing messages. 666 667 \since BeOS R3 668*/ 669 670 671/*! 672 \fn bool BLooper::Lock() 673 \brief Lock the looper. 674 675 For most operations involving the internal data of the looper, you need to 676 hold the lock. Each looper implements a global lock, which you can use to 677 perform operations on internal data in a thread-safe manner. 678 679 Do not forget to pair each Lock() request with an Unlock() request. Lock() 680 requests can be stacked, which means that recursively locking a looper from 681 a thread that actually holds the lock, will not cause a deadlock. See 682 BLocker for more information on locking internals. 683 684 \return \c true if the locking request succeeded, 685 \c false if the locking request could not be completed. There are a 686 variety of reasons for this to happen, for example when the 687 looper is destroyed. 688 689 \see Unlock() 690 \see LockWithTimeout() 691 \see IsLocked() 692 693 \since BeOS R5 694*/ 695 696 697/*! 698 \fn void BLooper::Unlock() 699 \brief Unlock a locked looper. 700 701 Use this method paired with Lock() calls, to release a lock. Make sure that 702 this method is only called on a locked looper. 703 704 \see Lock() 705 \see LockWithTimeout() 706 \see IsLocked() 707 708 \since BeOS R5 709*/ 710 711 712/*! 713 \fn bool BLooper::IsLocked() const 714 \brief Check if a looper is locked. 715 716 \return \c true if the looper is locked, 717 \c false if the looper is not locked, or the looper has been 718 deleted. 719 720 \see Lock() 721 \see Unlock() 722 \see LockWithTimeout() 723 724 \since BeOS R5 725*/ 726 727 728/*! 729 \fn status_t BLooper::LockWithTimeout(bigtime_t timeout) 730 \brief Lock a looper with a \a timeout. 731 732 This method locks the looper like Lock(), but if the locking request does 733 not succeed within the provided \a timeout, the method will return. 734 735 \param timeout The maximum time to wait for the lock request to succeed. 736 737 \return A status code. 738 \retval B_OK The lock is acquired. 739 \retval B_BAD_VALUE The looper has been destroyed. 740 \retval "other errors" There was an error acquiring the lock. 741 742 \see Lock() 743 \see Unlock() 744 \see IsLocked() 745 746 \since BeOS R5 747*/ 748 749 750/*! 751 \fn thread_id BLooper::Thread() const 752 \brief Return the thread id of the internal message looper thread. 753 754 If the looper is not yet running, this method will return 0. 755 756 \see Run() 757 758 \since BeOS R3 759*/ 760 761 762/*! 763 \fn team_id BLooper::Team() const 764 \brief Return the team id in which this looper exists. 765 766 \since BeOS R3 767*/ 768 769 770/*! 771 \fn BLooper* BLooper::LooperForThread(thread_id thread) 772 \brief Static method to retrieve a BLooper for a specified \a thread. 773 774 \since BeOS R3 775*/ 776 777 778//! @} 779 780 781/*! 782 \name Loop Debugging 783 784 These methods may aid you in debugging problems when they occur, but do not 785 use these in actual production code. These methods are unreliable because 786 they are not thread-safe, and as such are only useful in specific debugging 787 situations. Handle with care. 788*/ 789 790 791//! @{ 792 793 794/*! 795 \fn thread_id BLooper::LockingThread() const 796 \brief Return the thread id of the thread that currently holds the lock. 797 798 \since BeOS R3 799*/ 800 801 802/*! 803 \fn int32 BLooper::CountLocks() const 804 \brief Return the number of recursive locks that are currently being held 805 on this looper. 806 807 \since BeOS R3 808*/ 809 810 811/*! 812 \fn int32 BLooper::CountLockRequests() const 813 \brief Return the number of pending locks. 814 815 \since BeOS R3 816*/ 817 818 819/*! 820 \fn sem_id BLooper::Sem() const 821 \brief Return the id of the semaphore that is used to lock this looper. 822 823 \since BeOS R3 824*/ 825 826 827//! @} 828 829 830/*! 831 \name Scripting 832*/ 833 834 835//! @{ 836 837 838/*! 839 \fn BHandler* BLooper::ResolveSpecifier(BMessage* message, int32 index, 840 BMessage* specifier, int32 what, const char* property) 841 \brief Determine the proper handler for a scripting message. 842 843 \copydetails BHandler::ResolveSpecifier() 844*/ 845 846 847/*! 848 \fn status_t BLooper::GetSupportedSuites(BMessage* data) 849 \brief Reports the suites of messages and specifiers that derived classes 850 understand. 851 852 \copydetails BHandler::GetSupportedSuites() 853*/ 854 855 856//! @} 857 858 859/*! 860 \name Looper Message Filters 861 862 Note that filters added with these methods will be applied to all 863 associated handlers. Have a look at the filtering methods of the BHandler 864 class to see how filters can be applied to the inherited handler of this 865 looper specifically. 866*/ 867 868 869//! @{ 870 871 872/*! 873 \fn void BLooper::AddCommonFilter(BMessageFilter* filter) 874 \brief Add a common filter to the list of filters that are applied to all 875 incoming messages. 876 877 Filters can only be applied once, so they cannot be shared between loopers, 878 a handler and a looper or between two handlers. 879 880 The \a filter is not copied; rather a pointer is stored. Keep the \a filter 881 alive as long as it is used by a looper. 882 883 \see RemoveCommonFilter() 884 \see SetCommonFilterList() 885 \see CommonFilterList() 886 887 \since BeOS R3 888*/ 889 890 891/*! 892 \fn bool BLooper::RemoveCommonFilter(BMessageFilter* filter) 893 \brief Remove a \a filter from the common message filter list. 894 895 Note that this will not free the memory used by the \a filter, so you 896 should dispose of it yourself. 897 898 \see AddCommonFilter() 899 \see SetCommonFilterList() 900 \see CommonFilterList() 901 902 \since BeOS R3 903*/ 904 905 906/*! 907 \fn void BLooper::SetCommonFilterList(BList* filters) 908 \brief Set a new list of \a filters that need to be applied to all 909 incoming messages. 910 911 You are responsible for validating that all the items in the list of 912 \a filters are actual filters. The old list is discarded; all the filters 913 are \b destroyed. 914 915 Note that filters can only be applied to one looper or handler. If any 916 of the filters is already associated with another one, this call will fail. 917 918 \see AddCommonFilter() 919 \see RemoveCommonFilter() 920 \see CommonFilterList() 921 922 \since BeOS R3 923*/ 924 925 926/*! 927 \fn BList* BLooper::CommonFilterList() const 928 \brief Return a list of filters applied to all incoming messages. 929 930 \return A pointer to the internal filter list, or \c NULL if such a list 931 has not yet been created. Please note that you should use the 932 internal list management functions to manipulate the internal 933 filter list, in order to maintain internal consistency. 934 935 \see AddCommonFilter() 936 \see RemoveCommonFilter() 937 \see SetCommonFilterList() 938 939 \since BeOS R3 940*/ 941 942 943//! @} 944 945 946/*! 947 \fn status_t BLooper::Perform(perform_code d, void* arg) 948 \brief Internal method. 949 950 \since Haiku R1 951*/ 952 953 954/*! 955 \fn BMessage* BLooper::MessageFromPort(bigtime_t timeout) 956 \brief Hook method to retrieve a message from the looper's port. 957 958 The default implementation is called by the internal message looping thread 959 and retrieves the next message from the port that belongs to this looper. 960 961 If you use a looper in a context where it might receive messages from other 962 sources, you can override this method in order to insert these methods into 963 the message processing. Note that any messages that are returned by this 964 method will be deleted by this looper, so make sure you have ownership of 965 the message. If you override this method, remember to call the base 966 implementation every now and then, in order to retrieve the messages 967 arriving at the default port. 968 969 \since Haiku R1 970*/ 971