1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Invoker.h 23 // Author: Frans van Nispen (xlr8@tref.nl) 24 // Description: BInvoker class defines a protocol for objects that 25 // post messages to a "target". 26 //------------------------------------------------------------------------------ 27 28 #ifndef _INVOKER_H 29 #define _INVOKER_H 30 31 // Standard Includes ----------------------------------------------------------- 32 33 // System Includes ------------------------------------------------------------- 34 #include <BeBuild.h> 35 #include <Messenger.h> 36 37 // Project Includes ------------------------------------------------------------ 38 39 // Local Includes -------------------------------------------------------------- 40 41 // Local Defines --------------------------------------------------------------- 42 43 // Globals --------------------------------------------------------------------- 44 45 class BHandler; 46 class BLooper; 47 class BMessage; 48 49 // BInvoker class -------------------------------------------------------------- 50 class BInvoker { 51 public: 52 BInvoker(); 53 BInvoker(BMessage *message, 54 const BHandler *handler, 55 const BLooper *looper = NULL); 56 BInvoker(BMessage *message, BMessenger target); 57 virtual ~BInvoker(); 58 59 virtual status_t SetMessage(BMessage *message); 60 BMessage *Message() const; 61 uint32 Command() const; 62 63 virtual status_t SetTarget(const BHandler *h, const BLooper *loop = NULL); 64 virtual status_t SetTarget(BMessenger messenger); 65 bool IsTargetLocal() const; 66 BHandler *Target(BLooper **looper = NULL) const; 67 BMessenger Messenger() const; 68 69 virtual status_t SetHandlerForReply(BHandler *handler); 70 BHandler *HandlerForReply() const; 71 72 virtual status_t Invoke(BMessage *msg = NULL); 73 74 // Invoke with BHandler notification. Use this to perform an 75 // Invoke() with some other kind of notification change code. 76 // (A raw invoke should always notify as B_CONTROL_INVOKED.) 77 // Unlike a raw Invoke(), there is no standard message that is 78 // sent. If 'msg' is NULL, then nothing will be sent to this 79 // invoker's target... however, a notification message will 80 // still be sent to any watchers of the invoker's handler. 81 // Note that the BInvoker class does not actually implement 82 // any of this behavior -- it is up to subclasses to override 83 // Invoke() and call Notify() with the appropriate change code. 84 status_t InvokeNotify(BMessage *msg, uint32 kind = B_CONTROL_INVOKED); 85 status_t SetTimeout(bigtime_t timeout); 86 bigtime_t Timeout() const; 87 88 protected: 89 // Return the change code for a notification. This is either 90 // B_CONTROL_INVOKED for raw Invoke() calls, or the kind 91 // supplied to InvokeNotify(). In addition, 'notify' will be 92 // set to true if this was an InvokeNotify() call, else false. 93 uint32 InvokeKind(bool* notify = NULL); 94 95 // Start and end an InvokeNotify context around an Invoke() call. 96 // These are only needed for writing custom methods that 97 // emulate the standard InvokeNotify() call. 98 void BeginInvokeNotify(uint32 kind = B_CONTROL_INVOKED); 99 void EndInvokeNotify(); 100 101 // Private or reserved --------------------------------------------------------- 102 private: 103 // to be able to keep binary compatibility 104 virtual void _ReservedInvoker1(); 105 virtual void _ReservedInvoker2(); 106 virtual void _ReservedInvoker3(); 107 108 BInvoker(const BInvoker&); 109 BInvoker &operator=(const BInvoker&); 110 111 BMessage *fMessage; 112 BMessenger fMessenger; 113 BHandler *fReplyTo; 114 bigtime_t fTimeout; 115 uint32 fNotifyKind; 116 uint32 _reserved[1]; // to be able to keep binary compatibility 117 }; 118 //------------------------------------------------------------------------------ 119 120 #endif // _INVOKER_H 121 122 /* 123 * $Log $ 124 * 125 * $Id $ 126 * 127 */ 128 129