PEP#: 305
authormike <mike>
Sat, 6 Oct 2007 00:38:20 +0000 (00:38 +0000)
committermike <mike>
Sat, 6 Oct 2007 00:38:20 +0000 (00:38 +0000)
TITLE: VxWorks Port

DESCRIPTION: Ongoing VxWorks porting.

12 files changed:
Makefile
mak/platform_VXWORKS_PENTIUM_GNU.mak
src/Pegasus/Common/Buffer.h [new file with mode: 0644]
src/Pegasus/Compiler/cimmofMetaConsumer.cpp
src/Pegasus/Repository/Makefile
src/Pegasus/Repository/MemoryResidentRepository.cpp
src/Pegasus/Repository/MemoryResidentRepository.h
src/Pegasus/Repository/Serialization.cpp [new file with mode: 0644]
src/Pegasus/Repository/Serialization.h [new file with mode: 0644]
src/Pegasus/Repository/tests/Serialization/Makefile [new file with mode: 0644]
src/Pegasus/Repository/tests/Serialization/Serialization.cpp [new file with mode: 0644]
vxworks/cimserver/cimserver.cpp

index 10f54db7f72efaf69f9900d0ca17adf391ec5997..48c707ef28dc32329a9485d89f79e06cdaeb6d97 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,6 @@ ifeq ($(OS_TYPE),vxworks)
         src/Service \
         src/Pegasus/Provider \
         src/Pegasus/Repository \
-        src/Pegasus/Repository/tests \
         src/Pegasus/Server/ProviderRegistrationManager \
         src/Pegasus/ProviderManager2 \
         src/Pegasus/ProviderManager2/Default \
index 8d686ae05b36112f800f9824bef15782a236c536..fea3fefb3c96725c0667728041f409fc8efec8be 100644 (file)
@@ -145,4 +145,6 @@ PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET=1
 
 PEGASUS_USE_MEMORY_RESIDENT_REPOSITORY=1
 
+PEGASUS_REMOVE_TRACE=1
+
 export PEGASUS_USE_STATIC_LIBRARIES=true
diff --git a/src/Pegasus/Common/Buffer.h b/src/Pegasus/Common/Buffer.h
new file mode 100644 (file)
index 0000000..4eb109d
--- /dev/null
@@ -0,0 +1,272 @@
+//%2006////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation, The Open Group.
+// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; Symantec Corporation; The Open Group.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#ifndef Pegasus_Buffer_h
+#define Pegasus_Buffer_h
+
+#include <Pegasus/Common/Config.h>
+#include <Pegasus/Common/Linkage.h>
+#include <cstring>
+
+PEGASUS_NAMESPACE_BEGIN
+
+struct BufferRep
+{
+    Uint32 size;
+    Uint32 cap;
+    char data[1];
+};
+
+class PEGASUS_COMMON_LINKAGE Buffer
+{
+public:
+
+    Buffer();
+
+    Buffer(const Buffer& x);
+
+    Buffer(const char* data, Uint32 size);
+
+    ~Buffer();
+
+    Buffer& operator=(const Buffer& x);
+
+    void swap(Buffer& x);
+
+    Uint32 size() const;
+
+    Uint32 capacity() const;
+
+    /**
+        Returns a pointer to a character buffer with the Buffer contents.
+        The character buffer is null-terminated even if the Buffer contents
+        do not include a null termination character.
+     */
+    const char* getData() const;
+
+    char get(Uint32 i) const;
+
+    void set(Uint32 i, char x);
+
+    const char& operator[](Uint32 i) const;
+
+    void reserveCapacity(Uint32 cap);
+
+    void grow(Uint32 size, char x = '\0');
+
+    void append(char x);
+
+    void append(const char* data, Uint32 size);
+
+    void append(char c1, char c2);
+
+    void append(char c1, char c2, char c3, char c4);
+
+    void append(
+        char c1, char c2, char c3, char c4, char c5, char c6, char c7, char c8);
+
+    void insert(Uint32 pos, const char* data, Uint32 size);
+
+    void remove(Uint32 pos, Uint32 size);
+
+    void remove(Uint32 pos);
+
+    void clear();
+
+private:
+
+    void _reserve_aux(Uint32 cap);
+
+    void _append_char_aux();
+
+    BufferRep* _rep;
+    static BufferRep _empty_rep;
+};
+
+inline Buffer::Buffer() : _rep(&_empty_rep)
+{
+}
+
+inline Buffer::~Buffer()
+{
+    if (_rep->cap != 0)
+        free(_rep);
+}
+
+inline void Buffer::swap(Buffer& x)
+{
+    BufferRep* tmp = _rep;
+    _rep = x._rep;
+    x._rep = tmp;
+}
+
+inline Uint32 Buffer::size() const
+{
+    return _rep->size;
+}
+
+inline Uint32 Buffer::capacity() const
+{
+    return _rep->cap;
+}
+
+inline const char* Buffer::getData() const
+{
+    if (_rep->cap == 0)
+    {
+        const_cast<Buffer*>(this)->_append_char_aux();
+    }
+
+    _rep->data[_rep->size] = '\0';
+
+    return _rep->data;
+}
+
+inline char Buffer::get(Uint32 i) const
+{
+    return _rep->data[i];
+}
+
+inline void Buffer::set(Uint32 i, char x)
+{
+    _rep->data[i] = x;
+}
+
+inline const char& Buffer::operator[](Uint32 i) const
+{
+    return _rep->data[i];
+}
+
+inline void Buffer::reserveCapacity(Uint32 cap)
+{
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+}
+
+inline void Buffer::grow(Uint32 size, char x)
+{
+    Uint32 cap = _rep->size + size;
+
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+
+    memset(_rep->data + _rep->size, x, size);
+    _rep->size += size;
+}
+
+inline void Buffer::append(char x)
+{
+    if (_rep->size == _rep->cap)
+        _append_char_aux();
+
+    _rep->data[_rep->size++] = x;
+}
+
+inline void Buffer::append(const char* data, Uint32 size)
+{
+    Uint32 cap = _rep->size + size;
+
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+
+    memcpy(_rep->data + _rep->size, data, size);
+    _rep->size += size;
+}
+
+inline void Buffer::clear()
+{
+    if (_rep->cap != 0)
+        _rep->size = 0;
+}
+
+inline void Buffer::remove(Uint32 pos)
+{
+    remove(pos, 1);
+}
+
+inline void Buffer::append(char c1, char c2, char c3, char c4)
+{
+    Uint32 cap = _rep->size + 4;
+
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+
+    char* p = _rep->data + _rep->size;
+    p[0] = c1;
+    p[1] = c2;
+    p[2] = c3;
+    p[3] = c4;
+    _rep->size += 4;
+}
+
+inline void Buffer::append(char c1, char c2)
+{
+    Uint32 cap = _rep->size + 2;
+
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+
+    char* p = _rep->data + _rep->size;
+    p[0] = c1;
+    p[1] = c2;
+    _rep->size += 2;
+}
+
+inline void Buffer::append(
+    char c1, char c2, char c3, char c4, char c5, char c6, char c7, char c8)
+{
+    Uint32 cap = _rep->size + 8;
+
+    if (cap > _rep->cap)
+        _reserve_aux(cap);
+
+    char* p = _rep->data + _rep->size;
+    p[0] = c1;
+    p[1] = c2;
+    p[2] = c3;
+    p[3] = c4;
+    p[4] = c5;
+    p[5] = c6;
+    p[6] = c7;
+    p[7] = c8;
+    _rep->size += 8;
+}
+
+inline bool operator==(const Buffer& x, const Buffer& y)
+{
+    return memcmp(x.getData(), y.getData(), x.size()) == 0;
+}
+
+PEGASUS_NAMESPACE_END
+
+#endif /* Pegasus_Buffer_h */
index a516aa68f94e99794a4ed5cb69253dfd0785eb85..0ae9b361ece185a0b264e672f6a9ef524be888db 100644 (file)
@@ -517,14 +517,14 @@ static void _writeSint32(FILE* os, Sint32 x)
 
 static void _writeUint64(FILE* os, Uint64 x)
 {
-    Uint64 x0 = (x >> 56) & 0x000000FF;
-    Uint64 x1 = (x >> 48) & 0x000000FF;
-    Uint64 x2 = (x >> 40) & 0x000000FF;
-    Uint64 x3 = (x >> 32) & 0x000000FF;
-    Uint64 x4 = (x >> 24) & 0x000000FF;
-    Uint64 x5 = (x >> 16) & 0x000000FF;
-    Uint64 x6 = (x >>  8) & 0x000000FF;
-    Uint64 x7 = (x >>  0) & 0x000000FF;
+    Uint64 x0 = (x >> 56) & 0x00000000000000FF;
+    Uint64 x1 = (x >> 48) & 0x00000000000000FF;
+    Uint64 x2 = (x >> 40) & 0x00000000000000FF;
+    Uint64 x3 = (x >> 32) & 0x00000000000000FF;
+    Uint64 x4 = (x >> 24) & 0x00000000000000FF;
+    Uint64 x5 = (x >> 16) & 0x00000000000000FF;
+    Uint64 x6 = (x >>  8) & 0x00000000000000FF;
+    Uint64 x7 = (x >>  0) & 0x00000000000000FF;
     fprintf(os, "\\%03o", (int)x0);
     fprintf(os, "\\%03o", (int)x1);
     fprintf(os, "\\%03o", (int)x2);
index ec50de4cf44848c0ce01c7f3c0254437a1801e49..36cf8cc75ffb39ec5f4c9fcd4777ad2cb3d6c4e1 100644 (file)
@@ -112,7 +112,7 @@ DEFAULT_REPOSITORY_SOURCES = \
     InheritanceTree.cpp \
     RepositoryDeclContext.cpp \
     RepositoryQueryContext.cpp \
-    Filtering.cpp 
+    Filtering.cpp
 
 MEMORY_RESIDENT_REPOSITORY_SOURCES = \
     MemoryResidentRepository.cpp \
@@ -122,7 +122,8 @@ MEMORY_RESIDENT_REPOSITORY_SOURCES = \
     RepositoryDeclContext.cpp \
     RepositoryQueryContext.cpp \
     MetaRepository.cpp \
-    Filtering.cpp 
+    Filtering.cpp \
+    Serialization.cpp
 
 ifdef PEGASUS_USE_MEMORY_RESIDENT_REPOSITORY
   SOURCES += $(MEMORY_RESIDENT_REPOSITORY_SOURCES)
index 519f4d16d253764d113abc6d6362c490b0aed2db..e14a875a55b99e4c148f288ca4ca66d7717d6e6a 100644 (file)
@@ -37,6 +37,7 @@
 #include "RepositoryDeclContext.h"
 #include "MetaRepository.h"
 #include "Filtering.h"
+#include "Serialization.h"
 
 PEGASUS_NAMESPACE_BEGIN
 
@@ -147,12 +148,17 @@ static void _print(const CIMInstance& ci)
 //
 //==============================================================================
 
+static void (*_saveHandler)(const Buffer& buffer);
+static void (*_loadHandler)(Buffer& buffer);
+
 MemoryResidentRepository::MemoryResidentRepository(
     const String& repositoryRoot, 
     Uint32 repositoryMode) 
     : 
     Repository(repositoryRoot, repositoryMode)
 {
+    // Load users data if any:
+    _processLoadHandler();
 }
 
 MemoryResidentRepository::~MemoryResidentRepository()
@@ -224,6 +230,7 @@ void MemoryResidentRepository::deleteInstance(
         _throw(CIM_ERR_NOT_FOUND, "%s", *Str(instanceName));
 
     _rep.remove(pos);
+    _processSaveHandler();
 }
 
 void MemoryResidentRepository::createClass(
@@ -261,6 +268,7 @@ CIMObjectPath MemoryResidentRepository::createInstance(
     // Add instance to array:
 
     _rep.append(NamespaceInstancePair(nameSpace, ci));
+    _processSaveHandler();
 
     return cop;
 }
@@ -324,6 +332,7 @@ void MemoryResidentRepository::modifyInstance(
     // Replace original instance.
 
     _rep[pos].second = resultInstance;
+    _processSaveHandler();
 }
 
 Array<CIMClass> MemoryResidentRepository::enumerateClasses(
@@ -759,4 +768,64 @@ Uint32 MemoryResidentRepository::_findInstance(
     return PEG_NOT_FOUND;
 }
 
+void MemoryResidentRepository::setSaveHandler(
+    void (*handler)(const Buffer& buffer))
+{
+    _saveHandler = handler;
+}
+
+void MemoryResidentRepository::setLoadHandler(
+    void (*handler)(Buffer& buffer))
+{
+    _loadHandler = handler;
+}
+
+void MemoryResidentRepository::_processSaveHandler()
+{
+    if (!_saveHandler)
+        return;
+
+    Buffer out;
+
+    for (Uint32 i = 0; i < _rep.size(); i++)
+    {
+        SerializeNameSpace(out, _rep[i].first);
+        SerializeInstance(out, _rep[i].second);
+    }
+
+    (*_saveHandler)(out);
+}
+
+void MemoryResidentRepository::_processLoadHandler()
+{
+    if (!_loadHandler)
+        return;
+
+    Buffer in;
+    (*_loadHandler)(in);
+    size_t pos = 0;
+
+    while (pos != in.size())
+    {
+        CIMNamespaceName nameSpace;
+
+        if (DeserializeNameSpace(in, pos, nameSpace) != 0)
+        {
+            printf("***** DeserializeNameSpace() failed\n");
+            return;
+        }
+
+        CIMInstance cimInstance;
+
+        if (DeserializeInstance(in, pos, cimInstance) != 0)
+        {
+            printf("***** DeserializeInstance() failed\n");
+            return;
+        }
+
+        printf("===== MemoryResidentRepository: loaded instance\n");
+        _rep.append(NamespaceInstancePair(nameSpace, cimInstance));
+    }
+}
+
 PEGASUS_NAMESPACE_END
index 64bbc12ade51d20955393d31955dba5f4d25fa24..c0de4569730de1bf1261158fabb388ca97439e62 100644 (file)
@@ -37,6 +37,7 @@
 #include <Pegasus/Common/Config.h>
 #include <Pegasus/Repository/Repository.h>
 #include <Pegasus/Common/Pair.h>
+#include <Pegasus/Common/Buffer.h>
 
 PEGASUS_NAMESPACE_BEGIN
 
@@ -49,9 +50,10 @@ typedef Pair<CIMNamespaceName, CIMInstance> NamespaceInstancePair;
 class RepositoryDeclContext;
 class compilerDeclContext;
 
+
 /** Virtual base class for CIMRepository implementations.
 */
-class MemoryResidentRepository : public Repository
+class PEGASUS_REPOSITORY_LINKAGE MemoryResidentRepository : public Repository
 {
 public:
 
@@ -288,12 +290,26 @@ public:
         bool lock);
 #endif
 
-private:
+    // Sets the global save handler that is called whenever the memory-resident
+    // instance repository is modified. The buffer argument is a serialized
+    // copy of the memory-resident instance repository. The handler can do
+    // things such as save the buffer on disk for later use.
+    static void setSaveHandler(void (*handler)(const Buffer& buffer));
+
+    // Sets the global load handler that is called whenever an instance of
+    // MemoryResidentRepository is created in order to load the initial set
+    // of instances (if any).
+    static void setLoadHandler(void (*handler)(Buffer& buffer));
 
+private:
     Uint32 _findInstance(
         const CIMNamespaceName& nameSpace,
         const CIMObjectPath& instanceName);
 
+    void _processSaveHandler();
+
+    void _processLoadHandler();
+
     Array<NamespaceInstancePair> _rep;
 };
 
diff --git a/src/Pegasus/Repository/Serialization.cpp b/src/Pegasus/Repository/Serialization.cpp
new file mode 100644 (file)
index 0000000..912c78e
--- /dev/null
@@ -0,0 +1,1408 @@
+//%2006////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation, The Open Group.
+// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; Symantec Corporation; The Open Group.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#include "Serialization.h"
+
+#define RETURN_FAILURE \
+    do \
+    { \
+        printf("***** RETURN_FAILURE: %s(%d)\n", __FILE__, __LINE__); \
+        return -1; \
+    } \
+    while (0)
+
+PEGASUS_NAMESPACE_BEGIN
+
+//==============================================================================
+//
+// Limitations:
+//
+//     1. Does not handle CIMObjects that contain CIMClass.
+//
+//==============================================================================
+
+static Uint32 _INSTANCE_MAGIC = 0x20D54A36;
+
+class Str
+{
+public:
+    Str(const String& s) : _cstr(s.getCString()) { }
+    Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
+    Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
+    Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
+    Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
+    Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
+    const char* operator*() const { return (const char*)_cstr; }
+    operator const char*() const { return (const char*)_cstr; }
+private:
+    CString _cstr;
+};
+
+static void _PutUint8(Buffer& out, Uint8 x)
+{
+    out.append(x);
+}
+
+static void _PutBoolean(Buffer& out, Boolean x)
+{
+    _PutUint8(out, x ? 1 : 0);
+}
+
+static void _PutUint16(Buffer& out, Uint16 x)
+{
+    Uint8 x0 = Uint8((x >> 8) & 0x00FF);
+    Uint8 x1 = Uint8((x >> 0) & 0x00FF);
+    out.append(x0, x1);
+}
+
+static void _PutUint32(Buffer& out, Uint32 x)
+{
+    Uint8 x0 = Uint8((x >> 24) & 0x000000FF);
+    Uint8 x1 = Uint8((x >> 16) & 0x000000FF);
+    Uint8 x2 = Uint8((x >>  8) & 0x000000FF);
+    Uint8 x3 = Uint8((x >>  0) & 0x000000FF);
+    out.append(x0, x1, x2, x3);
+}
+
+static void _PutUint64(Buffer& out, Uint64 x)
+{
+    Uint8 x0 = Uint8((x >> 56) & 0x00000000000000FF);
+    Uint8 x1 = Uint8((x >> 48) & 0x00000000000000FF);
+    Uint8 x2 = Uint8((x >> 40) & 0x00000000000000FF);
+    Uint8 x3 = Uint8((x >> 32) & 0x00000000000000FF);
+    Uint8 x4 = Uint8((x >> 24) & 0x00000000000000FF);
+    Uint8 x5 = Uint8((x >> 16) & 0x00000000000000FF);
+    Uint8 x6 = Uint8((x >>  8) & 0x00000000000000FF);
+    Uint8 x7 = Uint8((x >>  0) & 0x00000000000000FF);
+    out.append(x0, x1, x2, x3, x4, x5, x6, x7);
+}
+
+static void _PutSint8(Buffer& out, Sint8 x)
+{
+    return _PutUint8(out, Uint8(x));
+}
+
+static void _PutSint16(Buffer& out, Sint16 x)
+{
+    return _PutUint16(out, Uint16(x));
+}
+
+static void _PutSint32(Buffer& out, Sint32 x)
+{
+    return _PutUint32(out, Uint32(x));
+}
+
+static void _PutSint64(Buffer& out, Sint64 x)
+{
+    return _PutUint64(out, Uint64(x));
+}
+
+static void _PutReal32(Buffer& out, Real32 x)
+{
+    return _PutUint32(out, *((Uint32*)&x));
+}
+
+static void _PutReal64(Buffer& out, Real64 x)
+{
+    return _PutUint64(out, *((Uint64*)&x));
+}
+
+static void _PutChar16(Buffer& out, Char16 x)
+{
+    return _PutUint16(out, Uint16(x));
+}
+
+static int _GetUint8(const Buffer& in, size_t& pos, Uint8& x)
+{
+    if (in.size() < 1)
+        RETURN_FAILURE;
+
+    const Uint8* p = (const Uint8*)(in.getData() + pos);
+    x = p[0];
+    pos++;
+
+    return 0;
+}
+
+static int _GetBoolean(const Buffer& in, size_t& pos, Boolean& x)
+{
+    Uint8 tmp;
+
+    if (_GetUint8(in, pos, tmp) != 0)
+        RETURN_FAILURE;
+
+    if (tmp != 0 && tmp != 1)
+        RETURN_FAILURE;
+
+    x = Boolean(tmp);
+    return 0;
+}
+
+static int _GetUint16(const Buffer& in, size_t& pos, Uint16& x)
+{
+    if (in.size() < 2)
+        RETURN_FAILURE;
+
+    const Uint8* p = (const Uint8*)(in.getData() + pos);
+    Uint16 x0 = p[0];
+    Uint16 x1 = p[1];
+    x = (x0 << 8) | x1;
+    pos += 2;
+
+    return 0;
+}
+
+static int _GetUint32(const Buffer& in, size_t& pos, Uint32& x)
+{
+    if (in.size() < 4)
+        RETURN_FAILURE;
+
+    const Uint8* p = (const Uint8*)(in.getData() + pos);
+    Uint32 x0 = p[0];
+    Uint32 x1 = p[1];
+    Uint32 x2 = p[2];
+    Uint32 x3 = p[3];
+    x = (x0 << 24) | (x1 << 16) | (x2 << 8) | x3;
+    pos += 4;
+
+    return 0;
+}
+
+static int _GetUint64(const Buffer& in, size_t& pos, Uint64& x)
+{
+    if (in.size() < 8)
+        RETURN_FAILURE;
+
+    const Uint8* p = (const Uint8*)(in.getData() + pos);
+    Uint64 x0 = p[0];
+    Uint64 x1 = p[1];
+    Uint64 x2 = p[2];
+    Uint64 x3 = p[3];
+    Uint64 x4 = p[4];
+    Uint64 x5 = p[5];
+    Uint64 x6 = p[6];
+    Uint64 x7 = p[7];
+    x = (x0 << 56) | (x1 << 48) | (x2 << 40) | (x3 << 32) |
+        (x4 << 24) | (x5 << 16) | (x6 << 8) | x7;
+    pos += 8;
+
+    return 0;
+}
+
+static int _GetSint8(const Buffer& in, size_t& pos, Sint8& x)
+{
+    return _GetUint8(in, pos, *((Uint8*)&x));
+}
+
+static int _GetSint16(const Buffer& in, size_t& pos, Sint16& x)
+{
+    return _GetUint16(in, pos, *((Uint16*)&x));
+}
+
+static int _GetSint32(const Buffer& in, size_t& pos, Sint32& x)
+{
+    return _GetUint32(in, pos, *((Uint32*)&x));
+}
+
+static int _GetSint64(const Buffer& in, size_t& pos, Sint64& x)
+{
+    return _GetUint64(in, pos, *((Uint64*)&x));
+}
+
+static int _GetReal32(const Buffer& in, size_t& pos, Real32& x)
+{
+    return _GetUint32(in, pos, *((Uint32*)&x));
+}
+
+static int _GetReal64(const Buffer& in, size_t& pos, Real64& x)
+{
+    return _GetUint64(in, pos, *((Uint64*)&x));
+}
+
+static int _GetChar16(const Buffer& in, size_t& pos, Char16& x)
+{
+    return _GetUint16(in, pos, *((Uint16*)&x));
+}
+
+static void _PutString(Buffer& out, const String& str)
+{
+    CString cstr(str.getCString());
+    Uint32 size = strlen(cstr);
+
+    // Pack size:
+    _PutUint32(out, size);
+
+    // Pack UTF8 characters:
+    out.append(cstr, size);
+}
+
+static void _PutDateTime(Buffer& out, const CIMDateTime& x)
+{
+    _PutString(out, x.toString());
+}
+
+static void _PutObjectPath(Buffer& out, const CIMObjectPath& x)
+{
+    // Serialize host:
+
+    _PutString(out, x.getHost());
+
+    //  Serialize namespace:
+
+    _PutString(out, x.getNameSpace().getString());
+
+    // Serialize class name:
+
+    _PutString(out, x.getClassName().getString());
+
+    // Serialize key bindings:
+
+    const Array<CIMKeyBinding>& kbs = x.getKeyBindings();
+    _PutUint32(out, kbs.size());
+
+    for (Uint32 i = 0, n = kbs.size(); i < n; i++)
+    {
+        const CIMKeyBinding& kb = kbs[i];
+
+        // Serialize name:
+
+        _PutString(out, kb.getName().getString());
+
+        // Serialize type:
+
+        _PutUint8(out, kb.getType());
+
+        // Serialize value:
+
+        _PutString(out, kb.getValue());
+    }
+}
+
+static int _PutValue(Buffer& out, const CIMValue& cv)
+{
+    // Serialize type (set MSB if array).
+
+    Uint8 type = Uint8(cv.getType());
+
+    if (cv.isArray())
+        type |= 0x80;
+
+    _PutUint8(out, type);
+
+    // Serialize the value itself:
+
+    if (cv.isArray())
+    {
+        switch (cv.getType())
+        {
+            case CIMTYPE_BOOLEAN:
+            {
+                Array<Boolean> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutBoolean(out, x[i]);
+                break;
+            }
+            case CIMTYPE_UINT8:
+            {
+                Array<Uint8> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutUint8(out, x[i]);
+                break;
+            }
+            case CIMTYPE_SINT8:
+            {
+                Array<Sint8> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutSint8(out, x[i]);
+                break;
+            }
+            case CIMTYPE_UINT16:
+            {
+                Array<Uint16> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutUint16(out, x[i]);
+                break;
+            }
+            case CIMTYPE_SINT16:
+            {
+                Array<Sint16> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutSint16(out, x[i]);
+                break;
+            }
+            case CIMTYPE_UINT32:
+            {
+                Array<Uint32> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutUint32(out, x[i]);
+                break;
+            }
+            case CIMTYPE_SINT32:
+            {
+                Array<Sint32> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutSint32(out, x[i]);
+                break;
+            }
+            case CIMTYPE_UINT64:
+            {
+                Array<Uint64> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutUint64(out, x[i]);
+                break;
+            }
+            case CIMTYPE_SINT64:
+            {
+                Array<Sint64> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutSint64(out, x[i]);
+                break;
+            }
+            case CIMTYPE_REAL32:
+            {
+                Array<Real32> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutReal32(out, x[i]);
+                break;
+            }
+            case CIMTYPE_REAL64:
+            {
+                Array<Real64> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutReal64(out, x[i]);
+                break;
+            }
+            case CIMTYPE_CHAR16:
+            {
+                Array<Char16> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutChar16(out, x[i]);
+                break;
+            }
+            case CIMTYPE_STRING:
+            {
+                Array<String> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutString(out, x[i]);
+                break;
+            }
+            case CIMTYPE_DATETIME:
+            {
+                Array<CIMDateTime> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutDateTime(out, x[i]);
+                break;
+            }
+            case CIMTYPE_REFERENCE:
+            {
+                Array<CIMObjectPath> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    _PutObjectPath(out, x[i]);
+                break;
+            }
+            case CIMTYPE_OBJECT:
+            {
+                Array<CIMObject> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                {
+                    if (!x[i].isInstance())
+                        RETURN_FAILURE;
+
+                    CIMInstance ci(x[i]);
+
+                    SerializeInstance(out, ci);
+                }
+                break;
+            }
+#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
+# ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
+            case CIMTYPE_INSTANCE:
+            {
+                Array<CIMInstance> x;
+                cv.get(x);
+                _PutUint32(out, x.size());
+
+                for (Uint32 i = 0; i < x.size(); i++)
+                    SerializeInstance(out, x[i]);
+                break;
+            }
+# endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
+#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
+        }
+    }
+    else
+    {
+        switch (cv.getType())
+        {
+            case CIMTYPE_BOOLEAN:
+            {
+                Boolean x;
+                cv.get(x);
+                _PutBoolean(out, x);
+                break;
+            }
+            case CIMTYPE_UINT8:
+            {
+                Uint8 x;
+                cv.get(x);
+                _PutUint8(out, x);
+                break;
+            }
+            case CIMTYPE_SINT8:
+            {
+                Sint8 x;
+                cv.get(x);
+                _PutSint8(out, x);
+                break;
+            }
+            case CIMTYPE_UINT16:
+            {
+                Uint16 x;
+                cv.get(x);
+                _PutUint16(out, x);
+                break;
+            }
+            case CIMTYPE_SINT16:
+            {
+                Sint16 x;
+                cv.get(x);
+                _PutSint16(out, x);
+                break;
+            }
+            case CIMTYPE_UINT32:
+            {
+                Uint32 x;
+                cv.get(x);
+                _PutUint32(out, x);
+                break;
+            }
+            case CIMTYPE_SINT32:
+            {
+                Sint32 x;
+                cv.get(x);
+                _PutSint32(out, x);
+                break;
+            }
+            case CIMTYPE_UINT64:
+            {
+                Uint64 x;
+                cv.get(x);
+                _PutUint64(out, x);
+                break;
+            }
+            case CIMTYPE_SINT64:
+            {
+                Sint64 x;
+                cv.get(x);
+                _PutSint64(out, x);
+                break;
+            }
+            case CIMTYPE_REAL32:
+            {
+                Real32 x;
+                cv.get(x);
+                _PutReal32(out, x);
+                break;
+            }
+            case CIMTYPE_REAL64:
+            {
+                Real64 x;
+                cv.get(x);
+                _PutReal64(out, x);
+                break;
+            }
+            case CIMTYPE_CHAR16:
+            {
+                Char16 x;
+                cv.get(x);
+                _PutChar16(out, x);
+                break;
+            }
+            case CIMTYPE_STRING:
+            {
+                String x;
+                cv.get(x);
+                _PutString(out, x);
+                break;
+            }
+            case CIMTYPE_DATETIME:
+            {
+                CIMDateTime x;
+                cv.get(x);
+                _PutDateTime(out, x);
+                break;
+            }
+            case CIMTYPE_REFERENCE:
+            {
+                CIMObjectPath x;
+                cv.get(x);
+                _PutObjectPath(out, x);
+                break;
+            }
+            case CIMTYPE_OBJECT:
+            {
+                CIMObject co;
+                cv.get(co);
+
+                if (!co.isInstance())
+                    RETURN_FAILURE;
+
+                CIMInstance ci(co);
+
+                SerializeInstance(out, ci);
+                break;
+            }
+#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
+# ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
+            case CIMTYPE_INSTANCE:
+            {
+                CIMInstance ci;
+                cv.get(ci);
+                SerializeInstance(out, ci);
+                break;
+            }
+# endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
+#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
+        }
+    }
+
+    return 0;
+}
+
+static int _GetString(
+    const Buffer& in, size_t& pos, String& str)
+{
+    // Deserialize size:
+
+    Uint32 size;
+
+    if (_GetUint32(in, pos, size) != 0)
+        RETURN_FAILURE;
+
+    // Read string:
+
+    str.append(&in[pos], size);
+    pos += size;
+
+    return 0;
+}
+
+static int _GetDateTime(const Buffer& in, size_t& pos, CIMDateTime& x)
+{
+    String str;
+
+    if (_GetString(in, pos, str) != 0)
+        RETURN_FAILURE;
+
+    try
+    {
+        x.set(str);
+    }
+    catch (...)
+    {
+        RETURN_FAILURE;
+    }
+    return 0;
+}
+
+static int _GetObjectPath(
+    const Buffer& in, 
+    size_t& pos, 
+    CIMObjectPath& cop)
+{
+    // Deserialize host:
+
+    String host;
+
+    if (_GetString(in, pos, host) != 0)
+        RETURN_FAILURE;
+
+    // Deserialize namespace:
+
+    CIMNamespaceName nameSpace;
+    {
+        String nameSpaceString;
+
+        if (_GetString(in, pos, nameSpaceString) != 0)
+            RETURN_FAILURE;
+
+        if (nameSpaceString.size() != 0)
+            nameSpace = nameSpaceString;
+    }
+
+    // Deserialize className:
+
+    CIMName className;
+    {
+        String classNameString;
+
+        if (_GetString(in, pos, classNameString) != 0)
+            RETURN_FAILURE;
+
+        if (classNameString.size() != 0)
+            className = classNameString;
+    }
+
+    // Deserialize the number of key bindings:
+
+    Uint32 size;
+
+    if (_GetUint32(in, pos, size) != 0)
+        RETURN_FAILURE;
+
+    // Deserialize the key bindings.
+
+    Array<CIMKeyBinding> kbs;
+
+    for (Uint32 i = 0; i < size; i++)
+    {
+        // Deserialize name:
+
+        String name;
+
+        if (_GetString(in, pos, name) != 0)
+            RETURN_FAILURE;
+
+        // Deserialize and check type:
+
+        Uint8 type;
+
+        if (_GetUint8(in, pos, type) != 0)
+            RETURN_FAILURE;
+
+        if (type != CIMKeyBinding::BOOLEAN && type != CIMKeyBinding::STRING &&
+            type != CIMKeyBinding::NUMERIC && type != CIMKeyBinding::REFERENCE)
+        {
+            RETURN_FAILURE;
+        }
+
+        // Deserialize value:
+
+        String value;
+
+        if (_GetString(in, pos, value) != 0)
+            RETURN_FAILURE;
+
+        // Add key binding:
+
+        try
+        {
+            kbs.append(CIMKeyBinding(name, value, CIMKeyBinding::Type(type)));
+        }
+        catch (...)
+        {
+            RETURN_FAILURE;
+        }
+    }
+
+    // Create the object path:
+
+    try
+    {
+        cop = CIMObjectPath(host, nameSpace, className, kbs);
+    }
+    catch (...)
+    {
+        RETURN_FAILURE;
+    }
+
+    return 0;
+}
+
+static int _GetValue(
+    const Buffer& in, 
+    size_t& pos,
+    CIMValue& value)
+{
+    value.clear();
+
+    // Deserialize type and isArray:
+
+    Boolean isArray;
+    Uint32 type;
+    {
+        Uint8 tmp;
+        
+        if (_GetUint8(in, pos, tmp) != 0)
+            RETURN_FAILURE;
+
+        isArray = tmp & 0x80;
+        type = CIMType(tmp & 0x7F);
+    }
+
+    // Deserialize the value itself:
+
+    if (isArray)
+    {
+        Uint32 size;
+
+        if (_GetUint32(in, pos, size) != 0)
+            RETURN_FAILURE;
+
+        switch (type)
+        {
+            case CIMTYPE_BOOLEAN:
+            {
+                Array<Boolean> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Boolean x;
+
+                    if (_GetBoolean(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_UINT8:
+            {
+                Array<Uint8> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Uint8 x;
+
+                    if (_GetUint8(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_SINT8:
+            {
+                Array<Sint8> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Sint8 x;
+
+                    if (_GetSint8(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_UINT16:
+            {
+                Array<Uint16> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Uint16 x;
+
+                    if (_GetUint16(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_SINT16:
+            {
+                Array<Sint16> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Sint16 x;
+
+                    if (_GetSint16(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_UINT32:
+            {
+                Array<Uint32> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Uint32 x;
+
+                    if (_GetUint32(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_SINT32:
+            {
+                Array<Sint32> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Sint32 x;
+
+                    if (_GetSint32(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_UINT64:
+            {
+                Array<Uint64> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Uint64 x;
+
+                    if (_GetUint64(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_SINT64:
+            {
+                Array<Sint64> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Sint64 x;
+
+                    if (_GetSint64(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_REAL32:
+            {
+                Array<Real32> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Real32 x;
+
+                    if (_GetReal32(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_REAL64:
+            {
+                Array<Real64> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Real64 x;
+
+                    if (_GetReal64(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_CHAR16:
+            {
+                Array<Char16> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    Char16 x;
+
+                    if (_GetChar16(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_STRING:
+            {
+                Array<String> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    String x;
+
+                    if (_GetString(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_DATETIME:
+            {
+                Array<CIMDateTime> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    CIMDateTime x;
+
+                    if (_GetDateTime(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_REFERENCE:
+            {
+                Array<CIMObjectPath> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    CIMObjectPath x;
+
+                    if (_GetObjectPath(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+            case CIMTYPE_OBJECT:
+            {
+                Array<CIMObject> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    CIMInstance x;
+
+                    if (DeserializeInstance(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(CIMObject(x));
+                }
+                value.set(a);
+                break;
+            }
+#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
+# ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
+            case CIMTYPE_INSTANCE:
+            {
+                Array<CIMInstance> a;
+
+                for (Uint32 i = 0; i < size; i++)
+                {
+                    CIMInstance x;
+
+                    if (DeserializeInstance(in, pos, x) != 0)
+                        RETURN_FAILURE;
+
+                    a.append(x);
+                }
+                value.set(a);
+                break;
+            }
+# endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
+#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
+            default:
+                RETURN_FAILURE;
+        }
+    }
+    else
+    {
+        switch (type)
+        {
+            case CIMTYPE_BOOLEAN:
+            {
+                Boolean x;
+
+                if (_GetBoolean(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_UINT8:
+            {
+                Uint8 x;
+
+                if (_GetUint8(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_SINT8:
+            {
+                Sint8 x;
+
+                if (_GetSint8(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_UINT16:
+            {
+                Uint16 x;
+
+                if (_GetUint16(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_SINT16:
+            {
+                Sint16 x;
+
+                if (_GetSint16(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_UINT32:
+            {
+                Uint32 x;
+
+                if (_GetUint32(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_SINT32:
+            {
+                Sint32 x;
+
+                if (_GetSint32(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_UINT64:
+            {
+                Uint64 x;
+
+                if (_GetUint64(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_SINT64:
+            {
+                Sint64 x;
+
+                if (_GetSint64(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_REAL32:
+            {
+                Real32 x;
+
+                if (_GetReal32(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_REAL64:
+            {
+                Real64 x;
+
+                if (_GetReal64(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_CHAR16:
+            {
+                Char16 x;
+
+                if (_GetChar16(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_STRING:
+            {
+                String x;
+
+                if (_GetString(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_DATETIME:
+            {
+                CIMDateTime x;
+
+                if (_GetDateTime(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_REFERENCE:
+            {
+                CIMObjectPath x;
+
+                if (_GetObjectPath(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+            case CIMTYPE_OBJECT:
+            {
+                CIMInstance x;
+
+                if (DeserializeInstance(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(CIMObject(x));
+                break;
+            }
+#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
+# ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
+            case CIMTYPE_INSTANCE:
+            {
+                CIMInstance x;
+
+                if (DeserializeInstance(in, pos, x) != 0)
+                    RETURN_FAILURE;
+
+                value.set(x);
+                break;
+            }
+# endif /* PEGASUS_EMBEDDED_INSTANCE_SUPPORT */
+#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
+            default:
+                RETURN_FAILURE;
+        }
+    }
+
+    return 0;
+}
+
+void SerializeInstance(Buffer& out, const CIMInstance& ci)
+{
+    // Serialize magic number:
+
+    _PutUint32(out, _INSTANCE_MAGIC);
+
+    // Serialize object path:
+
+    _PutObjectPath(out, ci.getPath());
+
+    // Serialize properties:
+
+    _PutUint32(out, ci.getPropertyCount());
+
+    for (Uint32 i = 0, n = ci.getPropertyCount(); i < n; i++)
+    {
+        const CIMConstProperty cp = ci.getProperty(i);
+
+        // Serialize property name:
+
+        _PutString(out, cp.getName().getString());
+
+        // Serialize the value:
+
+        _PutValue(out, cp.getValue());
+    }
+}
+
+int DeserializeInstance(
+    const Buffer& in, 
+    size_t& pos,
+    CIMInstance& ci)
+{
+    // Deserialize magic number:
+
+    Uint32 magic;
+
+    if (_GetUint32(in, pos, magic) != 0 || magic != _INSTANCE_MAGIC)
+        RETURN_FAILURE;
+
+    // Deserialize object path:
+
+    CIMObjectPath cop;
+
+    if (_GetObjectPath(in, pos, cop) != 0)
+        RETURN_FAILURE;
+
+    // Create the instance:
+
+    try
+    {
+        ci = CIMInstance(cop.getClassName());
+        ci.setPath(cop);
+    }
+    catch (...)
+    {
+        RETURN_FAILURE;
+    }
+
+    // Get property count:
+
+    Uint32 propertyCount = 0;
+
+    if (_GetUint32(in, pos, propertyCount) != 0)
+        RETURN_FAILURE;
+
+    // Deserialize properties:
+
+    for (Uint32 i = 0; i < propertyCount; i++)
+    {
+        // Deserialize property name:
+
+        String name;
+
+        if (_GetString(in, pos, name) != 0)
+            RETURN_FAILURE;
+
+        // Deserialize property value:
+
+        CIMValue value;
+
+        if (_GetValue(in, pos, value) != 0)
+            RETURN_FAILURE;
+
+        // Add property to instance.
+
+        try
+        {
+            ci.addProperty(CIMProperty(name, value));
+        }
+        catch (Exception& e)
+        {
+            RETURN_FAILURE;
+        }
+    }
+
+    return 0;
+}
+
+void SerializeNameSpace(
+    Buffer& out, 
+    const CIMNamespaceName& nameSpace)
+{
+    _PutString(out, nameSpace.getString());
+}
+
+int DeserializeNameSpace(
+    const Buffer& in, 
+    size_t& pos,
+    CIMNamespaceName& nameSpace)
+{
+    String tmp;
+
+    if (_GetString(in, pos, tmp) != 0)
+        RETURN_FAILURE;
+
+    nameSpace = tmp;
+    return 0;
+}
+
+PEGASUS_NAMESPACE_END
diff --git a/src/Pegasus/Repository/Serialization.h b/src/Pegasus/Repository/Serialization.h
new file mode 100644 (file)
index 0000000..58ac9a7
--- /dev/null
@@ -0,0 +1,66 @@
+//%2006////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation, The Open Group.
+// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; Symantec Corporation; The Open Group.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _Pegasus_Repository_Serialization_h
+#define _Pegasus_Repository_Serialization_h
+
+#include <Pegasus/Common/Config.h>
+#include <Pegasus/Common/CIMInstance.h>
+#include <Pegasus/Common/Buffer.h>
+#include <Pegasus/Common/Array.h>
+#include <Pegasus/Common/String.h>
+#include "Linkage.h"
+
+PEGASUS_NAMESPACE_BEGIN
+
+PEGASUS_REPOSITORY_LINKAGE void SerializeNameSpace(
+    Buffer& out, 
+    const CIMNamespaceName& nameSpace);
+
+PEGASUS_REPOSITORY_LINKAGE int DeserializeNameSpace(
+    const Buffer& in, 
+    size_t& pos,
+    CIMNamespaceName& nameSpace);
+
+PEGASUS_REPOSITORY_LINKAGE void SerializeInstance(
+    Buffer& out, 
+    const CIMInstance& cimInstance);
+
+PEGASUS_REPOSITORY_LINKAGE int DeserializeInstance(
+    const Buffer& in, 
+    size_t& pos,
+    CIMInstance& cimInstance);
+
+PEGASUS_NAMESPACE_END
+
+#endif /* _Pegasus_Repository_Serialization_h */
diff --git a/src/Pegasus/Repository/tests/Serialization/Makefile b/src/Pegasus/Repository/tests/Serialization/Makefile
new file mode 100644 (file)
index 0000000..b08218b
--- /dev/null
@@ -0,0 +1,47 @@
+#//%2006////////////////////////////////////////////////////////////////////////
+#//
+#// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+#// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+#// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+#// IBM Corp.; EMC Corporation, The Open Group.
+#// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+#// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+#// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+#// EMC Corporation; VERITAS Software Corporation; The Open Group.
+#// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+#// EMC Corporation; Symantec Corporation; The Open Group.
+#//
+#// Permission is hereby granted, free of charge, to any person obtaining a copy
+#// of this software and associated documentation files (the "Software"), to
+#// deal in the Software without restriction, including without limitation the
+#// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+#// sell copies of the Software, and to permit persons to whom the Software is
+#// furnished to do so, subject to the following conditions:
+#// 
+#// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+#// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+#// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+#// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+#// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+#// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+#// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+#// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#//
+#//==============================================================================
+ROOT = ../../../../..
+DIR = Pegasus/Repository/tests/Serialization
+include $(ROOT)/mak/config.mak
+include ../libraries.mak
+
+LOCAL_DEFINES = -DPEGASUS_INTERNALONLY
+
+PROGRAM = TestSerialization
+SOURCES = Serialization.cpp
+
+include $(ROOT)/mak/program.mak
+
+tests:
+       $(PROGRAM)
+
+poststarttests:
+
diff --git a/src/Pegasus/Repository/tests/Serialization/Serialization.cpp b/src/Pegasus/Repository/tests/Serialization/Serialization.cpp
new file mode 100644 (file)
index 0000000..7582fe7
--- /dev/null
@@ -0,0 +1,139 @@
+//%2006////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
+// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
+// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation, The Open Group.
+// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
+// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; VERITAS Software Corporation; The Open Group.
+// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
+// EMC Corporation; Symantec Corporation; The Open Group.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#include <cctype>
+#include <Pegasus/Common/Config.h>
+#include <Pegasus/Repository/Serialization.h>
+#include <Pegasus/Common/PegasusAssert.h>
+
+PEGASUS_USING_PEGASUS;
+PEGASUS_USING_STD;
+
+static void _dump(const char* s, size_t n)
+{
+    for (size_t i = 0; i < n; i++)
+    {
+        char c = s[i];
+
+        if (isprint(c))
+            printf("%c", c);
+        else
+            printf("[%02X]", (unsigned char)c);
+    }
+
+    printf("\n");
+}
+
+void test()
+{
+    // Create embedded instance:
+
+    CIMInstance emb("EmbClass");
+    emb.addProperty(CIMProperty("Key", Uint32(777)));
+
+    // Create instance:
+
+    CIMInstance ci1("MyClass");
+    CIMObjectPath cop("MyClass.Key=7777");
+    ci1.setPath(cop);
+    ci1.addProperty(CIMProperty("Key", Uint32(7777)));
+    ci1.addProperty(CIMProperty("Message", String("Hello World!")));
+    ci1.addProperty(CIMProperty("Count", Uint32(1234)));
+    ci1.addProperty(CIMProperty("Flag", Boolean(true)));
+
+    Array<String> colors;
+    colors.append("Red");
+    colors.append("Green");
+    colors.append("Blue");
+    ci1.addProperty(CIMProperty("Colors", colors));
+
+    ci1.addProperty(CIMProperty("Ref1", 
+        CIMObjectPath("RefClass.Key1=99,Key2=\"Hello\",Key3=False")));
+
+    ci1.addProperty(CIMProperty("Emb1", emb));
+
+    // Serialize instance:
+
+    Buffer out;
+    {
+        Array<String> tbl;
+        SerializeInstance(tbl, out, ci1);
+        SerializeInstance(tbl, out, ci1);
+    }
+
+    // _dump(out.getData(), out.size());
+
+    // Deserialize instance:
+
+    CIMInstance ci2;
+    {
+        Buffer in(out);
+        Array<String> tbl;
+        size_t pos = 0;
+
+        if (DeserializeInstance(tbl, in, pos, ci2) != 0)
+            PEGASUS_TEST_ASSERT(0);
+    }
+
+    // Check instance:
+
+    PEGASUS_TEST_ASSERT(ci1.identical(ci2));
+
+    // Print
+#if 0
+    {
+        CIMObject co1(ci1);
+        cout << co1.toString() << endl;
+        printf("===========================================\n");
+        CIMObject co2(ci2);
+        cout << co2.toString() << endl;
+    }
+#endif
+}
+
+int main(int argc, char** argv)
+{
+    try
+    {
+        test();
+    }
+    catch (...)
+    {
+        PEGASUS_TEST_ASSERT(0);
+    }
+
+    cout << argv[0] << " +++++ passed all tests" << endl;
+
+    return 0;
+}
index fc3480c5aee1af47713c2647725d580527e276d9..70bddeb9b9593318d44701ad04c9106117e910d3 100644 (file)
@@ -33,6 +33,7 @@
 #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/String.h>
 #include <Pegasus/Repository/MetaRepository.h>
+#include <Pegasus/Repository/MemoryResidentRepository.h>
 #include <Pegasus/Server/ProviderTable.h>
 #include <Pegasus/Provider/CIMProvider.h>
 #include "root_cimv2_namespace.h"
@@ -64,13 +65,73 @@ static Pegasus::ProviderTableEntry _providerTable[] =
     { 0, 0, 0, 0, 0 },
 };
 
+static const char INSTANCE_REPOISTORY_PATH[] = "redbird:/tmp/instances.dat";
+
+static void _loadHandler(Buffer& buffer)
+{
+    printf("===== _loadHandler()\n");
+
+    // If this file exists, pass its contents to the memory resident 
+    // repository.
+
+    FILE* is = fopen(INSTANCE_REPOISTORY_PATH, "rb");
+
+    if (!is)
+    {
+        printf("DOES NOT EXIST[%s]\n", INSTANCE_REPOISTORY_PATH);
+        return;
+    }
+
+    size_t n;
+    char buf[4096];
+
+    while ((n = fread(buf, 1, sizeof(buf), is)) > 0)
+        buffer.append(buf, n);
+
+    fclose(is);
+}
+
+static void _saveHandler(const Buffer& buffer)
+{
+    printf("===== _saveHandler()\n");
+
+    FILE* os = fopen(INSTANCE_REPOISTORY_PATH, "wb");
+
+    if (!os)
+    {
+        printf("FAILED TO OPEN[%s]\n", INSTANCE_REPOISTORY_PATH);
+        return;
+    }
+
+    const char* data = buffer.getData();
+    size_t size = buffer.size();
+
+    if (fwrite(data, 1, size, os) != size)
+    {
+        printf("FAILED TO WRITE[%s]\n", INSTANCE_REPOISTORY_PATH);
+    }
+
+    fclose(os);
+}
+
 int main(int argc, char** argv)
 {
+    // Setup the provider table:
+
     pegasusProviderTable = _providerTable;
 
+    // Add namespaces to the meta-repository:
+
     MetaRepository::addNameSpace(&root_PG_InterOp_namespace);
     MetaRepository::addNameSpace(&root_cimv2_namespace);
     MetaRepository::addNameSpace(&root_PG_Internal_namespace);
 
+    // Arrange for load/save repository handlers to be invoked.
+
+    MemoryResidentRepository::setLoadHandler(_loadHandler);
+    MemoryResidentRepository::setSaveHandler(_saveHandler);
+
+    // Run the pegasus server:
+
     return PegasusServerMain(argc, argv);
 }