Blender V2.61 - r43446

NG_NetworkMessage.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef NG_NETWORKMESSAGE_H
00033 #define NG_NETWORKMESSAGE_H
00034 
00035 #include "STR_HashedString.h"
00036 
00037 #ifdef WITH_CXX_GUARDEDALLOC
00038 #include "MEM_guardedalloc.h"
00039 #endif
00040 
00041 class NG_NetworkMessage
00042 {
00043     static int          s_nextID;
00044     int                 m_uniqueMessageID;  // intern counting MessageID
00045     unsigned int        m_ClientId;
00046     int                 m_refcount;
00047 
00048     STR_String          m_to;           // receiver
00049     STR_String          m_from;         // sender
00050     STR_String          m_subject;      // empty or propName
00051     STR_String          m_message;      // message or propValue
00052 
00053 protected:
00054     ~NG_NetworkMessage();
00055 
00056 public:
00057     NG_NetworkMessage(
00058         const STR_String& to,
00059         const STR_String& from,
00060         const STR_String& subject,
00061         const STR_String& body);
00062 
00063     void AddRef() {
00064         m_refcount++;
00065     }
00066 
00067     // This is not nice code you should'nt need to resort to
00068     // delete this.
00069     void Release()
00070     {
00071         if (! --m_refcount)
00072         {
00073             delete this;
00074         }
00075     }
00076 
00080     void SetMessageText(const STR_String& msgtext) {
00081         m_message = msgtext;
00082     }
00083 
00087     const STR_String& GetDestinationName() { return m_to;};
00088 
00092     const STR_String& GetSenderName() { return m_from;};
00093 
00097     const STR_String& GetSubject() { return m_subject;};
00098 
00102     const STR_String& GetMessageText() {
00103 //cout << "GetMessageText " << m_message << "\n";
00104         return m_message;
00105     }
00106     const STR_String& GetMessageText() const {
00107 //cout << "GetMessageText " << m_message << "\n";
00108         return m_message;
00109     }
00110 
00114     void SetSender(unsigned int ClientId) {
00115         m_ClientId = ClientId;
00116     }
00117 
00121     unsigned int GetSender(void) {
00122         return m_ClientId;
00123     }
00124 
00128     int GetMessageID() {
00129         return m_uniqueMessageID;
00130     }
00131     
00132     
00133 #ifdef WITH_CXX_GUARDEDALLOC
00134 public:
00135     void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:NG_NetworkMessage"); }
00136     void operator delete( void *mem ) { MEM_freeN(mem); }
00137 #endif
00138 };
00139 
00140 #endif //NG_NETWORKMESSAGE_H
00141