/* * pvsMsg.h * * Created on: 08.01.2010 * Author: sr */ #ifndef PVSMSG_H_ #define PVSMSG_H_ #include enum PVSMsgType { PVSCOMMAND = 'C', PVSMESSAGE = 'M', PVSLOGIN = 'L', PVSDAEMON = 'D', PVSUNKNOWN = 'U' }; class PVSServerConnection; class PVSListenServer; class PVSClientConnection; class QAbstractSocket; class PVSMsg { public: friend class PVSServerConnection; friend class PVSListenServer; friend class PVSClientConnection; PVSMsg(); PVSMsg(PVSMsgType type, QString _ident, QString msg, int recID = 0); PVSMsg(PVSMsg const& copyMe); ~PVSMsg(); int readMessage(QAbstractSocket* sock, bool udp = false); ///< -1 = error, 0 = incomplete, 1 = complete unsigned int getLength() { return _msgString.size(); }; void setIdent(QString ident); QString getIdent(); void setMessage(QString text); QString getMessage(); PVSMsgType getType() { return _msgType; } bool getBinaryData(char*& data, int& dataLen); ///< get binary representation of this PVSmsg unsigned int getRecID() { return _recID; } int getSndID() { return _sndID; } QString getRemoteIp() { return _remoteIp; } bool isMsgComplete() { return _buffFill > 0 && _buffFill == _buffLen; } private: void setSndID(int id); void setRecID(int id); bool makeSndBuff(); PVSMsgType _msgType; ///< type of message (command, message, login, daemon) QString _msgIdent; ///< message ident QString _msgString; ///< message string char *_buffer; ///< receive buffer int _buffLen; ///< size of complete message in bytes int _buffFill; ///< actual number of bytes in buffer int _sndID; int _recID; QString _remoteIp; }; #endif /* PVSMSG_H_ */