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+=_text.size()+stringpad;
00022
00023 return used;
00024 }
00025
00026 unsigned int
00027 TextMsgEvent::LoadBinaryBuffer(const char buf[], unsigned int len) {
00028 unsigned int origlen=len;
00029 unsigned int used;
00030 if(0==(used=EventBase::LoadBinaryBuffer(buf,len))) return 0;
00031 len-=used; buf+=used;
00032 if(0==(used=checkCreator("EventBase::TextMsgEvent",buf,len,true))) return 0;
00033 len-=used; buf+=used;
00034 if(0==(used=decode(_text,buf,len))) return 0;
00035 len-=used; buf+=used;
00036
00037
00038 return origlen-len;
00039 }
00040
00041 unsigned int
00042 TextMsgEvent::SaveBinaryBuffer(char buf[], unsigned int len) const {
00043 unsigned int origlen=len;
00044 unsigned int used;
00045 if(0==(used=EventBase::SaveBinaryBuffer(buf,len))) return 0;
00046 len-=used; buf+=used;
00047 if(0==(used=saveCreator("EventBase::TextMsgEvent",buf,len))) return 0;
00048 len-=used; buf+=used;
00049 if(0==(used=encode(_text,buf,len))) return 0;
00050 len-=used; buf+=used;
00051
00052
00053 return origlen-len;
00054 }
00055
00056 void TextMsgEvent::LoadXML(xmlNode* node) {
00057 if(node==NULL)
00058 return;
00059
00060 EventBase::LoadXML(node);
00061
00062 for(xmlNode* cur = skipToElement(node->children); cur!=NULL; cur = skipToElement(cur->next)) {
00063 if(xmlStrcmp(cur->name, (const xmlChar *)"param"))
00064 continue;
00065
00066 xmlChar * name = xmlGetProp(cur,(const xmlChar*)"name");
00067 if(name==NULL)
00068 throw bad_format(cur,"property missing name");
00069
00070 xmlChar * val = xmlGetProp(cur,(const xmlChar*)"value");
00071 if(val==NULL)
00072 throw bad_format(cur,"property missing value");
00073
00074 if(xmlStrcmp(name, (const xmlChar *)"text")==0)
00075 _text=(const char*)val;
00076
00077 xmlFree(val);
00078 xmlFree(name);
00079 }
00080 }
00081
00082 void TextMsgEvent::SaveXML(xmlNode * node) const {
00083 if(node==NULL)
00084 return;
00085 EventBase::SaveXML(node);
00086
00087
00088 for(xmlNode* cur = skipToElement(node->children); cur!=NULL; ) {
00089 if(xmlStrcmp(cur->name, (const xmlChar *)"param")==0) {
00090 xmlUnlinkNode(cur);
00091 xmlFreeNode(cur);
00092 cur = skipToElement(node->children);
00093 } else
00094 cur = skipToElement(cur->next);
00095 }
00096
00097 xmlNode* cur=xmlNewChild(node,NULL,(const xmlChar*)"param",NULL);
00098 if(cur==NULL)
00099 throw bad_format(node,"Error: VisionObjectEvent xml error on saving param");
00100 xmlSetProp(cur,(const xmlChar*)"name",(const xmlChar*)"text");
00101 xmlSetProp(cur,(const xmlChar*)"value",(const xmlChar*)_text.c_str());
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113