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