00001 // mutableserverresult.cpp: implementation of the MutableServerResult class. 00002 // 00004 00005 #include "mutableserverresult.h" 00006 00007 #include "logger.h" 00008 00010 // Construction/Destruction 00012 00013 MutableServerResult::MutableServerResult() 00014 { 00015 Status = MSB_RESULT_ERROR; 00016 } 00017 // 00018 // ----------------------------------------------------- 00019 // 00020 long MutableServerResult::BufferInitAlloc() 00021 { 00022 return (long)( MutableServerMessage::BufferInitAlloc() 00023 + 3 // longest result = "-1\n" 00024 ); 00025 } 00026 // 00027 // ----------------------------------------------------- 00028 // 00029 void MutableServerResult::FormatDerivativeData() 00030 { 00031 MutableServerMessage::FormatDerivativeData(); 00032 00033 char _b[5]; 00034 00035 sprintf( _b, "%d\n", Status ); 00036 00037 // append the result status 00038 00039 MessageBuffer.append( _b ); 00040 } 00041 // 00042 // ----------------------------------------------------- 00043 // 00044 void MutableServerResult::ParseDerivativeData() 00045 { 00046 Status = MSB_RESULT_ERROR; 00047 00048 MutableServerMessage::ParseDerivativeData(); 00049 00050 long _index; 00051 00052 if ( (_index = MessageBuffer.find("\n")) == MessageBuffer.npos ) 00053 { 00054 throw worm_exception("Unterminated message while parsing result code"); 00055 } 00056 00057 00058 std::string _status = MessageBuffer.substr( 0 , _index ); 00059 00060 // Remove this line from the buffer 00061 00062 MessageBuffer.erase( 0 , _index + 1 ); 00063 00064 Status = (short)atoi( _status.c_str() ); 00065 } 00066 // 00067 // ----------------------------------------------------- 00068 // 00069 void MutableServerResult::SetStatus( short p_status ) 00070 { 00071 if ( p_status != MSB_RESULT_GOOD 00072 && p_status != MSB_RESULT_BUSY 00073 && p_status != MSB_RESULT_FAIL 00074 && p_status != MSB_RESULT_ERROR 00075 ) 00076 { 00077 throw worm_exception("MutableServerResult::SetStatus(): invalid parameter"); 00078 } 00079 Status = p_status; 00080 } 00081 // 00082 // ----------------------------------------------------- 00083 // 00084 short MutableServerResult::GetStatus() { return Status; } 00085 // 00086 // ----------------------------------------------------- 00087 //