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: Messenger.h 23 // Author: Ingo Weinhold (bonefish@users.sf.net) 24 // Description: BMessenger delivers messages to local or remote targets. 25 //------------------------------------------------------------------------------ 26 27 #ifndef _MESSENGER_H 28 #define _MESSENGER_H 29 30 // Standard Includes ----------------------------------------------------------- 31 32 // System Includes ------------------------------------------------------------- 33 #include <BeBuild.h> 34 #include <OS.h> 35 #include <ByteOrder.h> 36 #include <Message.h> 37 38 // Project Includes ------------------------------------------------------------ 39 40 // Local Includes -------------------------------------------------------------- 41 42 // Local Defines --------------------------------------------------------------- 43 44 // Globals --------------------------------------------------------------------- 45 46 class BHandler; 47 class BLooper; 48 49 namespace BPrivate { 50 class TRoster; 51 }; 52 53 // BMessenger class ------------------------------------------------------------ 54 class BMessenger { 55 public: 56 BMessenger(); 57 BMessenger(const char *signature, team_id team = -1, 58 status_t *result = NULL); 59 BMessenger(const BHandler *handler, const BLooper *looper = NULL, 60 status_t *result = NULL); 61 BMessenger(const BMessenger &from); 62 ~BMessenger(); 63 64 // Target 65 66 bool IsTargetLocal() const; 67 BHandler *Target(BLooper **looper) const; 68 bool LockTarget() const; 69 status_t LockTargetWithTimeout(bigtime_t timeout) const; 70 71 // Message sending 72 73 status_t SendMessage(uint32 command, BHandler *replyTo = NULL) const; 74 status_t SendMessage(BMessage *message, BHandler *replyTo = NULL, 75 bigtime_t timeout = B_INFINITE_TIMEOUT) const; 76 status_t SendMessage(BMessage *message, BMessenger replyTo, 77 bigtime_t timeout = B_INFINITE_TIMEOUT) const; 78 status_t SendMessage(uint32 command, BMessage *reply) const; 79 status_t SendMessage(BMessage *message, BMessage *reply, 80 bigtime_t deliveryTimeout = B_INFINITE_TIMEOUT, 81 bigtime_t replyTimeout = B_INFINITE_TIMEOUT) const; 82 83 // Operators and misc 84 85 BMessenger &operator=(const BMessenger &from); 86 bool operator==(const BMessenger &other) const; 87 88 bool IsValid() const; 89 team_id Team() const; 90 91 //----- Private or reserved ----------------------------------------- 92 private: 93 friend class BRoster; 94 friend class BPrivate::TRoster; 95 friend class BMessage; 96 friend class BQuery; 97 friend inline void _set_message_reply_(BMessage *, BMessenger); 98 friend status_t swap_data(type_code, void *, size_t, swap_action); 99 friend bool operator<(const BMessenger &a, const BMessenger &b); 100 friend bool operator!=(const BMessenger &a, const BMessenger &b); 101 102 BMessenger(team_id team, port_id port, int32 token, bool preferred); 103 104 void InitData(const char *signature, team_id team, status_t *result); 105 106 private: 107 port_id fPort; 108 int32 fHandlerToken; 109 team_id fTeam; 110 int32 extra0; 111 int32 extra1; 112 bool fPreferredTarget; 113 bool extra2; 114 bool extra3; 115 bool extra4; 116 }; 117 118 _IMPEXP_BE bool operator<(const BMessenger &a, const BMessenger &b); 119 _IMPEXP_BE bool operator!=(const BMessenger &a, const BMessenger &b); 120 121 #endif // _MESSENGER_H 122