TextMsgEvent.cc
Go to the documentation of this file.00001 #include "TextMsgEvent.h"
00002 #include <sstream>
00003 #include <libxml/tree.h>
00004
00005 const EventBase::classTypeID_t TextMsgEvent::autoRegisterTextMsgEvent=getTypeRegistry().registerType<TextMsgEvent>(makeClassTypeID("TXTM"));
00006
00007 std::string
00008 TextMsgEvent::getDescription(bool showTypeSpecific, unsigned int verbosity) const {
00009 if(!showTypeSpecific)
00010 return EventBase::getDescription(showTypeSpecific,verbosity);
00011 std::ostringstream logdata;
00012 logdata << EventBase::getDescription(showTypeSpecific,verbosity) << '\t' << _text;
00013 return logdata.str();
00014 }
00015
00016 unsigned int
00017 TextMsgEvent::getBinSize() const {
00018 unsigned int used=EventBase::getBinSize();
00019 if(saveFormat==XML)
00020 return used;
00021
00022 used+=creatorSize("EventBase::TextMsgEvent");
00023 used+=getSerializedSize(_text);
00024
00025 return used;
00026 }
00027
00028 unsigned int
00029 TextMsgEvent::loadBinaryBuffer(const char buf[], unsigned int len) {
00030 unsigned int origlen=len;
00031 if(!checkInc(EventBase::loadBinaryBuffer(buf,len),buf,len)) return 0;
00032 if(!checkCreatorInc("EventBase::TextMsgEvent",buf,len,true)) return 0;
00033 if(!decodeInc(_text,buf,len)) return 0;
00034
00035
00036 return origlen-len;
00037 }
00038
00039 unsigned int
00040 TextMsgEvent::saveBinaryBuffer(char buf[], unsigned int len) const {
00041 unsigned int origlen=len;
00042 if(!checkInc(EventBase::saveBinaryBuffer(buf,len),buf,len)) return 0;
00043 if(!saveCreatorInc("EventBase::TextMsgEvent",buf,len)) return 0;
00044 if(!encodeInc(_text,buf,len)) return 0;
00045
00046 return origlen-len;
00047 }
00048
00049 void TextMsgEvent::loadXML(xmlNode* node) {
00050 if(node==NULL)
00051 return;
00052
00053 EventBase::loadXML(node);
00054
00055 for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00056 if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00057 continue;
00058
00059 xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00060 if(name==NULL)
00061 throw bad_format(cur,"property missing name");
00062
00063 xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00064 if(val==NULL)
00065 throw bad_format(cur,"property missing value");
00066
00067 if(xmlStrcmp(name, (const xmlChar *)"text")==0)
00068 _text=(const char*)val;
00069
00070 xmlFree(val);
00071 xmlFree(name);
00072 }
00073 }
00074
00075 void TextMsgEvent::saveXML(xmlNode * node) const {
00076 if(node==NULL)
00077 return;
00078 EventBase::saveXML(node);
00079
00080
00081 for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00082 if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00083 xmlUnlinkNode(cur);
00084 xmlFreeNode(cur);
00085 cur = skipToElement(node->children);
00086 } else
00087 cur = skipToElement(cur->next);
00088 }
00089
00090 xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL);
00091 if(cur==NULL)
00092 throw bad_format(node,"Error: TextMsgEvent xml error on saving param");
00093 xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)"text");
00094 xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)_text.c_str());
00095 }
00096
00097
00098
00099
00100