OW_BinarySerialization.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #ifndef OW_BinarySerialization_HPP_
00037 #define OW_BinarySerialization_HPP_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_CIMFwd.hpp"
00041 #include "OW_Bool.hpp"
00042 #include "OW_CIMObjectPath.hpp"
00043 #include "OW_CIMNameSpace.hpp"
00044 #include "OW_CIMClass.hpp"
00045 #include "OW_CIMInstance.hpp"
00046 #include "OW_CIMQualifierType.hpp"
00047 #include "OW_CIMValue.hpp"
00048 #include "OW_ByteSwap.hpp"
00049 #include "OW_IfcsFwd.hpp"
00050 
00051 #if defined(OW_HAVE_OSTREAM) && defined(OW_HAVE_ISTREAM)
00052 #include <ostream>
00053 #include <istream>
00054 #else
00055 #include <iostream>
00056 #endif
00057 
00058 // The classes and functions defined in this file are not meant for general
00059 // use, they are internal implementation details.  They may change at any time.
00060 
00061 namespace OW_NAMESPACE
00062 {
00063 
00064 // Values for local API calls
00065 // This should be kept in sync with the repository version in HDBCommon.hpp
00066 // The general idea is to have it be a concatenation of release numbers with
00067 // a revision on the end (to prevent problems during development)
00068 // So 3000003 originated from version 3.0.0 rev 4
00069 //
00070 // 8/21/2003 - Changed from 3000003 to 3000004 because of a change in the
00071 //   structure of CIMInstance.  The name and alias were removed.
00072 // 10/25/2003 - 3000005. Changed enumClassNames to send over an enum of strings
00073 //   instead of object paths.
00074 // 2/6/2004 - 3000006. Changed CIMDateTime::{read,write}Object to write each
00075 //   item individually so struct packing doesn't cause incompatibilities.
00076 // 2/20/2004 - 3000007. Changed to not send an extra unnecessary signature,
00077 //   since all the CIM objects already send a signature.  Note that the 
00078 //   repository version was not incremented.
00079 // 7/22/2004 - 3000008. Changed signatures and added versioning. Now all
00080 //   readObject() calls will be able to read older versions as well as the
00081 //   current.  Introduced MinBinaryProtocolVersion which is the oldest version
00082 //   we can sucessfully read.
00083 const UInt32 BinaryProtocolVersion = 3000008;
00084 
00085 // This is the oldest version the code can handle.
00086 const UInt32 MinBinaryProtocolVersion = 3000007;
00087 
00088 // These values are all used by the binary protocol
00089 const UInt8 BIN_OK =          0;    // Success returned from server
00090 const UInt8 BIN_ERROR =       1;    // Error returned from server
00091 const UInt8 BIN_EXCEPTION =      2;    // CIM Exception returned from server
00092 const UInt8 IPC_AUTHENTICATE =   10;   // Authenticate
00093 const UInt8 IPC_FUNCTIONCALL =   11;   // Regular function call
00094 const UInt8 IPC_CLOSECONN =      12;   // Close connection
00095 const UInt8 BIN_DELETECLS =      20;      // Delete class
00096 const UInt8 BIN_DELETEINST =     21;      // Delete instance
00097 const UInt8 BIN_DELETEQUAL =     22;      // Delete qualifier type
00098 const UInt8 BIN_ENUMCLSS =    23;      // Enum class
00099 const UInt8 BIN_ENUMCLSNAMES =   24;      // Enum class names
00100 const UInt8 BIN_ENUMINSTS =      25;      // Enum instances
00101 const UInt8 BIN_ENUMINSTNAMES =  26;      // Enum instance names
00102 const UInt8 BIN_ENUMQUALS =      27;      // Enum qualifiers types
00103 const UInt8 BIN_GETCLS =         28;      // Get class
00104 const UInt8 BIN_GETINST =        29;      // Get instance
00105 const UInt8 BIN_INVMETH =        30;      // Invoke method
00106 const UInt8 BIN_GETQUAL =        31;      // Get qualifier type
00107 const UInt8 BIN_SETQUAL =        32;      // Set qualifier type
00108 const UInt8 BIN_MODIFYCLS =      33;      // Modify class
00109 const UInt8 BIN_CREATECLS =      34;      // Create class
00110 const UInt8 BIN_MODIFYINST =     35;      // Modify instances
00111 const UInt8 BIN_CREATEINST =     36;      // Create instance
00112 const UInt8 BIN_GETPROP =        37;      // Get property
00113 const UInt8 BIN_SETPROP =        38;      // Set property
00114 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00115 const UInt8 BIN_ASSOCNAMES =     39;      // Associator names
00116 const UInt8 BIN_ASSOCIATORS =    40;      // Associators
00117 const UInt8 BIN_REFNAMES =    41;      // Reference names
00118 const UInt8 BIN_REFERENCES =     42;      // References
00119 #endif
00120 const UInt8 BIN_EXECQUERY =      43;      // Execute query
00121 const UInt8 BIN_GETSVRFEATURES = 44;      // Get Server Features
00122 const UInt8 BINSIG_NS   =        100;
00123 const UInt8 BINSIG_OP =       101;
00124 const UInt8 BINSIG_CLS =         102;
00125 const UInt8 BINSIG_INST =        103;
00126 const UInt8 BINSIG_BOOL =        104;
00127 const UInt8 BINSIG_CLSENUM =     105;
00128 const UInt8 BINSIG_STR =         106;
00129 const UInt8 BINSIG_STRARRAY =    107;
00130 const UInt8 BINSIG_QUAL_TYPE =         108;
00131 const UInt8 BINSIG_VALUE =    109;
00132 const UInt8 BINSIG_OPENUM =      110;
00133 const UInt8 BINSIG_INSTENUM =    111;
00134 const UInt8 BINSIG_QUAL_TYPEENUM =     112;
00135 const UInt8 BINSIG_VALUEARRAY =  113;
00136 const UInt8 BINSIG_PARAMVALUEARRAY =   114;
00137 const UInt8 BINSIG_STRINGENUM =  115;
00138 const UInt8 END_CLSENUM =        150;
00139 const UInt8 END_OPENUM =         151;
00140 const UInt8 END_INSTENUM =    152;
00141 const UInt8 END_QUALENUM =    153;
00142 const UInt8 END_STRINGENUM =     154;
00144 namespace BinarySerialization
00145 {
00146    OW_COMMON_API void write(std::ostream& ostrm, const void* dataOut,
00147       int dataOutLen);
00148    OW_COMMON_API void verifySignature(std::istream& istrm, UInt8 validSig);
00149    inline void write(std::ostream& ostrm, Int32 val)
00150    {
00151       val = hton32(val);
00152       BinarySerialization::write(ostrm, &val, sizeof(val));
00153    }
00154    inline void write(std::ostream& ostrm, UInt32 val)
00155    {
00156       val = hton32(val);
00157       BinarySerialization::write(ostrm, &val, sizeof(val));
00158    }
00159    OW_COMMON_API void writeLen(std::ostream& ostrm, UInt32 len);
00160    inline void write(std::ostream& ostrm, UInt8 val)
00161    {
00162       BinarySerialization::write(ostrm, &val, sizeof(val));
00163    }
00164    inline void write(std::ostream& ostrm, UInt16 val)
00165    {
00166       val = hton16(val);
00167       BinarySerialization::write(ostrm, &val, sizeof(val));
00168    }
00169    inline void write(std::ostream& ostrm, Int16 val)
00170    {
00171       val = hton16(val);
00172       BinarySerialization::write(ostrm, &val, sizeof(val));
00173    }
00174    inline void write(std::ostream& ostrm, const String& str)
00175    {
00176       str.writeObject(ostrm);
00177    }
00178    inline void writeObject(std::ostream& ostrm, UInt8 sig,
00179       const CIMBase& obj)
00180    {
00181       obj.writeObject(ostrm);
00182    }
00183    inline void writeObjectPath(std::ostream& ostrm,
00184       const CIMObjectPath& op)
00185    {
00186       BinarySerialization::writeObject(ostrm, BINSIG_OP, op);
00187    }
00188    inline void writeNameSpace(std::ostream& ostrm,
00189       const CIMNameSpace& ns)
00190    {
00191       BinarySerialization::writeObject(ostrm, BINSIG_NS, ns);
00192    }
00193    inline void writeBool(std::ostream& ostrm,
00194       Bool arg)
00195    {
00196       BinarySerialization::write(ostrm, BINSIG_BOOL);
00197       arg.writeObject(ostrm);
00198    }
00199    inline void writeClass(std::ostream& ostrm, const CIMClass& cc)
00200    {
00201       BinarySerialization::writeObject(ostrm, BINSIG_CLS, cc);
00202    }
00203    inline void writeInstance(std::ostream& ostrm, const CIMInstance& ci)
00204    {
00205       BinarySerialization::writeObject(ostrm, BINSIG_INST, ci);
00206    }
00207    inline void writeQualType(std::ostream& ostrm, const CIMQualifierType& qt)
00208    {
00209       BinarySerialization::writeObject(ostrm, BINSIG_QUAL_TYPE, qt);
00210    }
00211    inline void writeValue(std::ostream& ostrm, const CIMValue& value)
00212    {
00213       BinarySerialization::writeObject(ostrm, BINSIG_VALUE, value);
00214    }
00215    inline void writeString(std::ostream& ostrm, const String& str)
00216    {
00217       BinarySerialization::write(ostrm, BINSIG_STR);
00218       str.writeObject(ostrm);
00219    }
00220    OW_COMMON_API void readLen(std::istream& istrm, UInt32& len);
00222    template <typename T>
00223    inline void
00224    readArray(std::istream& istr, T& a)
00225    {
00226       a.clear();
00227       UInt32 len;
00228       BinarySerialization::readLen(istr, len);
00229       
00230       a.reserve(len);
00231       for (UInt32 i = 0; i < len; i++)
00232       {
00233          typename T::value_type x;
00234          x.readObject(istr);
00235          a.push_back(x);
00236       }
00237    
00238    }
00239    
00241    template <typename T>
00242    inline void
00243    writeArray(std::ostream& ostrm, const T& a)
00244    {
00245       UInt32 len = static_cast<UInt32>(a.size());
00246       BinarySerialization::writeLen(ostrm, len);
00247       for (UInt32 i = 0; i < len; i++)
00248       {
00249          a.operator[](i).writeObject(ostrm);
00250       }
00251    }
00252    inline void writeStringArray(std::ostream& ostrm,
00253       const StringArray& stra)
00254    {
00255       BinarySerialization::write(ostrm, BINSIG_STRARRAY);
00256       writeArray(ostrm, stra);
00257    }
00258    OW_COMMON_API void writeStringArray(std::ostream& ostrm,
00259       const StringArray* propertyList);
00260    
00261    
00262    OW_COMMON_API void read(std::istream& istrm, void* dataIn, int dataInLen);
00263    inline void read(std::istream& istrm, String& arg)
00264    {
00265       arg.readObject(istrm);
00266    }
00267    inline void read(std::istream& istrm, Int32& val)
00268    {
00269       BinarySerialization::read(istrm, &val, sizeof(val));
00270       val = ntoh32(val);
00271    }
00272    inline void read(std::istream& istrm, UInt32& val)
00273    {
00274       BinarySerialization::read(istrm, &val, sizeof(val));
00275       val = ntoh32(val);
00276    }
00277    inline void read(std::istream& istrm, UInt16& val)
00278    {
00279       BinarySerialization::read(istrm, &val, sizeof(val));
00280       val = ntoh16(val);
00281    }
00282    inline void read(std::istream& istrm, Int16& val)
00283    {
00284       BinarySerialization::read(istrm, &val, sizeof(val));
00285       val = ntoh16(val);
00286    }
00287    inline void read(std::istream& istrm, UInt8& val)
00288    {
00289       BinarySerialization::read(istrm, &val, sizeof(val));
00290    }
00291    inline void readObject(std::istream& istrm, UInt8 validSig,
00292       CIMBase& obj)
00293    {
00294       obj.readObject(istrm);
00295    }
00296    inline CIMObjectPath readObjectPath(std::istream& istrm)
00297    {
00298       CIMObjectPath op(CIMNULL);
00299       BinarySerialization::readObject(istrm, BINSIG_OP, op);
00300       return op;
00301    }
00302    inline CIMInstance readInstance(std::istream& istrm)
00303    {
00304       CIMInstance ci(CIMNULL);
00305       BinarySerialization::readObject(istrm, BINSIG_INST, ci);
00306       return ci;
00307    }
00308    inline Bool readBool(std::istream& istrm)
00309    {
00310       BinarySerialization::verifySignature(istrm, BINSIG_BOOL);
00311       Bool b;
00312       b.readObject(istrm);
00313       return b;
00314    }
00315    inline CIMNameSpace readNameSpace(std::istream& istrm)
00316    {
00317       CIMNameSpace ns(CIMNULL);
00318       BinarySerialization::readObject(istrm, BINSIG_NS, ns);
00319       return ns;
00320    }
00321    inline CIMClass readClass(std::istream& istrm)
00322    {
00323       CIMClass cc(CIMNULL);
00324       BinarySerialization::readObject(istrm, BINSIG_CLS, cc);
00325       return cc;
00326    }
00327    inline String readString(std::istream& istrm)
00328    {
00329       BinarySerialization::verifySignature(istrm, BINSIG_STR);
00330       String rv;
00331       rv.readObject(istrm);
00332       return rv;
00333    }
00334    inline CIMQualifierType readQualType(std::istream& istrm)
00335    {
00336       CIMQualifierType qt(CIMNULL);
00337       BinarySerialization::readObject(istrm, BINSIG_QUAL_TYPE, qt);
00338       return qt;
00339    }
00340    inline CIMValue readValue(std::istream& istrm)
00341    {
00342       CIMValue value(CIMNULL);
00343       BinarySerialization::readObject(istrm, BINSIG_VALUE, value);
00344       return value;
00345    }
00346    inline StringArray readStringArray(std::istream& istrm)
00347    {
00348       BinarySerialization::verifySignature(istrm, BINSIG_STRARRAY);
00349       StringArray stra;
00350       readArray(istrm, stra);
00351       return stra;
00352    }
00353    OW_COMMON_API void readObjectPathEnum(std::istream& istrm, CIMObjectPathResultHandlerIFC& result);
00354    OW_COMMON_API void readClassEnum(std::istream& istrm, CIMClassResultHandlerIFC& result);
00355    OW_COMMON_API void readInstanceEnum(std::istream& istrm, CIMInstanceResultHandlerIFC& result);
00356    OW_COMMON_API void readQualifierTypeEnum(std::istream& istrm, CIMQualifierTypeResultHandlerIFC& result);
00357    OW_COMMON_API void readStringEnum(std::istream& istrm, StringResultHandlerIFC& result);
00358 } // end namespace BinarySerialization
00359 
00360 } // end namespace OW_NAMESPACE
00361 
00362 #endif   // OW_BinarySerialization_HPP_

Generated on Thu Feb 9 08:47:52 2006 for openwbem by  doxygen 1.4.6