X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=network%2Fmessage.h;fp=network%2Fmessage.h;h=2620d7cef3dc83632f95ca33b5a22bbe0bec40c8;hp=0000000000000000000000000000000000000000;hb=7bcf3798d7e4edb49345f40c7c543f7a9bb97805;hpb=09494f0681def3c6cf585eda25b8bb236560ddac diff --git a/network/message.h b/network/message.h new file mode 100644 index 00000000..2620d7ce --- /dev/null +++ b/network/message.h @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by The Quassel Team * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _MESSAGE_H_ +#define _MESSAGE_H_ + +#include +#include +#include + +class Server; +class Buffer; +class Message; + +typedef void (*sendHandlerType)(Message *); // handler for commands sent by the user +typedef void (*recvHandlerType)(Message *); // handler for incoming messages + +/** + * This contains information that depends (solely) on the message type, such as the handler function and help texts. + * Most of these are defined at compile time, but more may be added at runtime. + */ +struct CmdType { + int type; + QString cmd; + QString cmdDescr; + QString args; + QString argsDescr; + recvHandlerType recvHandler; + sendHandlerType sendHandler; + +}; + +/** + * +*/ +class Message { + public: + Message(Server *server, Buffer *buffer, QString cmd, QString prefix, QStringList args = QStringList()); + + virtual ~Message() {}; + + static void init(recvHandlerType defaultRevcHandler, sendHandlerType defaultSendHandler); + static Message * createFromServerString(Server *server, QString srvMsg); + //static Message * createFromUserString(Server *server, Buffer *buffer, QString usrMsg); + //static registerCmd(); + //static unregisterCmd(); + + inline Server * getServer() { return server; } + inline Buffer * getBuffer() { return buffer; } + inline int getType() { return type; } + inline QString getPrefix() { return prefix; } + inline QString getCmd() { return cmd; } + inline QStringList getParams() { return params; } + inline recvHandlerType getRecvHandler(); + inline sendHandlerType getSendHandler(); + + protected: + Server *server; + Buffer *buffer; + int type; + QString prefix; + QString cmd; + QStringList params; + recvHandlerType recvHandler; + sendHandlerType sendHandler; + static recvHandlerType defaultRecvHandler; + static sendHandlerType defaultSendHandler; + + static QHash cmdTypes; +}; + + +/** This is only used to have a nice way for defining builtin commands. + * We create an array of these in builtin_cmds.cpp and read this to fill our + * command hash. + */ +struct BuiltinCmd { + QString cmd; + QString cmdDescr; + QString args; + QString argsDescr; + recvHandlerType recvHandler; + sendHandlerType sendHandler; +}; + +#endif