1 /* 2 This file is part of Kismet 3 4 Kismet is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 Kismet is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Kismet; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 20 #ifndef __MESSAGEBUS_H__ 21 #define __MESSAGEBUS_H__ 22 23 #include "config.h" 24 25 #include <string> 26 #include <vector> 27 28 #include "globalregistry.h" 29 30 // Message flags for queuing data 31 #define MSGFLAG_NONE 0 32 #define MSGFLAG_DEBUG 1 33 #define MSGFLAG_INFO 2 34 #define MSGFLAG_ERROR 4 35 #define MSGFLAG_ALERT 8 36 #define MSGFLAG_FATAL 16 37 // Don't propagate it past local display systems 38 #define MSGFLAG_LOCAL 32 39 // Force printing of the error in the shutdown messages, sort of a "fatal lite" 40 #define MSGFLAG_PRINT 64 41 #define MSGFLAG_ALL (MSGFLAG_DEBUG | MSGFLAG_INFO | \ 42 MSGFLAG_ERROR | MSGFLAG_ALERT | \ 43 MSGFLAG_FATAL) 44 // Combine 45 #define MSGFLAG_PRINTERROR (MSGFLAG_ERROR | MSGFLAG_PRINT) 46 47 // A subscriber to the message bus. It subscribes with a mask of 48 // what messages it wants to handle 49 class MessageClient { 50 public: MessageClient()51 MessageClient() { 52 fprintf(stderr, "FATAL OOPS: MessageClient::MessageClient() called " 53 "with no global registry\n"); 54 exit(1); 55 } 56 MessageClient(GlobalRegistry * in_globalreg,void * in_aux)57 MessageClient(GlobalRegistry *in_globalreg, void *in_aux) { 58 globalreg = in_globalreg; 59 auxptr = in_aux; 60 } 61 ~MessageClient()62 virtual ~MessageClient() { } 63 64 virtual void ProcessMessage(string in_msg, int in_flags) = 0; 65 protected: 66 GlobalRegistry *globalreg; 67 void *auxptr; 68 }; 69 70 class StdoutMessageClient : public MessageClient { 71 public: StdoutMessageClient(GlobalRegistry * in_globalreg,void * in_aux)72 StdoutMessageClient(GlobalRegistry *in_globalreg, void *in_aux) : 73 MessageClient(in_globalreg, in_aux) { } ~StdoutMessageClient()74 virtual ~StdoutMessageClient() { } 75 void ProcessMessage(string in_msg, int in_flags); 76 }; 77 78 class MessageBus { 79 public: 80 // Inject a message into the bus 81 void InjectMessage(string in_msg, int in_flags); 82 83 // Link a meessage display system 84 void RegisterClient(MessageClient *in_subcriber, int in_mask); 85 void RemoveClient(MessageClient *in_unsubscriber); 86 87 protected: 88 typedef struct { 89 MessageClient *client; 90 int mask; 91 } busclient; 92 93 vector<MessageBus::busclient *> subscribers; 94 }; 95 96 97 #endif 98 99