1 /* 2 * Copyright 1999, Be Incorporated. 3 * Copyright (c) 1999-2000, Eric Moon. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions, and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions, and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 28 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 33 //////////////////////////////////////////////////////////// 34 // MultiInvoker.h 35 // -------------- 36 // Declares the MultiInvoker class. 37 // 38 39 40 #ifndef _MultiInvoker_h 41 #define _MultiInvoker_h 42 43 #include <List.h> 44 45 //////////////////////////////////////////////////////////// 46 // Class: MultiInvoker 47 // ------------------- 48 // A BInvoker-like class that allows you to send messages 49 // to multiple targets. In addition, it will work with 50 // any BMessenger-derived class that you create. 51 52 class MultiInvoker 53 { 54 public: 55 MultiInvoker(); 56 MultiInvoker(const MultiInvoker& src); 57 virtual ~MultiInvoker(); 58 59 MultiInvoker& operator=(const MultiInvoker& src); 60 61 virtual void SetMessage(BMessage* message); 62 BMessage* Message() const; 63 uint32 Command() const; 64 65 virtual status_t AddTarget(const BHandler* h, const BLooper* loop=0); 66 67 // For this version of AddTarget, the MultiInvoker 68 // will assume ownership of the messenger. 69 virtual status_t AddTarget(BMessenger* messenger); 70 virtual void RemoveTarget(const BHandler* h); 71 virtual void RemoveTarget(int32 index); 72 int32 IndexOfTarget(const BHandler* h) const; 73 int32 CountTargets() const; 74 BHandler* TargetAt(int32 index, BLooper** looper=0) const; 75 BMessenger* MessengerAt(int32 index) const; 76 bool IsTargetLocal(int32 index) const; 77 78 void SetTimeout(bigtime_t timeout); 79 bigtime_t Timeout() const; 80 81 virtual void SetHandlerForReply(BHandler* h); 82 BHandler* HandlerForReply() const; 83 84 virtual status_t Invoke(BMessage* msg =0); 85 86 private: 87 void Clear(); 88 void Clone(const MultiInvoker& src); 89 90 BMessage* m_message; 91 BList m_messengers; 92 bigtime_t m_timeout; 93 BHandler* m_replyHandler; 94 }; 95 96 #endif /* _MultiInvoker_h */ 97