00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "OWBI1_config.h"
00037 #include "OWBI1_CIMBase.hpp"
00038 #include "OWBI1_Exception.hpp"
00039 #include "OWBI1_String.hpp"
00040 #include "OW_Format.hpp"
00041 #include "OW_Assertion.hpp"
00042 #include "OW_StringStream.hpp"
00043 #include "OW_BinarySerialization.hpp"
00044 #include <cstring>
00045
00046 namespace OWBI1
00047 {
00048 using namespace OpenWBEM;
00049 using std::istream;
00050 using std::ostream;
00052
00053 void
00054 CIMBase::readSig( istream& istr, const char* const sig )
00055 {
00056 char expected, read;
00057 OW_ASSERT( strlen(sig) == 1 );
00058 expected = sig[0];
00059 BinarySerialization::read(istr, &read, sizeof(read));
00060 if (expected != read)
00061 {
00062 OWBI1_THROW_ERR(BadCIMSignatureException,
00063 Format("Signature does not match. In CIMBase::readSig. signature read: %1, expected: %2",
00064 read, sig).c_str(), E_UNEXPECTED_SIGNATURE);
00065 }
00066 }
00068
00069 UInt32
00070 CIMBase::readSig(std::istream& istr, const char* const sig,
00071 const char* const verSig, UInt32 maxVersion)
00072 {
00073 UInt32 version = 0;
00074 char ch;
00075 OW_ASSERT( strlen(sig) == 1);
00076 OW_ASSERT( strlen(verSig) == 1);
00077
00078 BinarySerialization::read(istr, &ch, sizeof(ch));
00079 if (sig[0] != ch)
00080 {
00081 if (verSig[0] != ch)
00082 {
00083 OWBI1_THROW_ERR(BadCIMSignatureException,
00084 Format("Signature does not match. In CIMBase::readSig. "
00085 "signature read: %1, expected: %2 or %3",
00086 ch, sig, verSig).c_str(), E_UNEXPECTED_SIGNATURE);
00087 }
00088
00089
00090 BinarySerialization::readLen(istr, version);
00091 if (version > maxVersion)
00092 {
00093 OWBI1_THROW_ERR(BadCIMSignatureException,
00094 Format("CIMBase::readSig. Unknown version %1, only versions <= %2 are handled.",
00095 version, maxVersion).c_str(), E_UNKNOWN_VERSION);
00096 }
00097 }
00098
00099 return version;
00100 }
00101
00103
00104 void
00105 CIMBase::writeSig( ostream& ostr, const char* const sig )
00106 {
00107 OW_ASSERT(strlen(sig) == 1);
00108 BinarySerialization::write(ostr, sig, 1);
00109 }
00111
00112 void
00113 CIMBase::writeSig(std::ostream& ostr, const char* const sig, UInt32 version)
00114 {
00115 OW_ASSERT(strlen(sig) == 1);
00116 BinarySerialization::write(ostr, sig, 1);
00117
00118 BinarySerialization::writeLen(ostr, version);
00119 }
00120
00122 std::ostream& operator<<(std::ostream& ostr, const CIMBase& cb)
00123 {
00124 ostr << cb.toString();
00125 return ostr;
00126 }
00128 CIMBase::~CIMBase()
00129 {
00130 }
00131
00132 }
00133