Revision: 44727
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44727&view=rev
Author:   davidloman
Date:     2011-06-02 16:11:12 +0000 (Thu, 02 Jun 2011)

Log Message:
-----------
Reworked cstr to take full path rather than just object name.  Fixed 
deconstructor memory freeing.  Added EXT_MAGIC to serialization/deserialization 
routines.  Various other fixes.

Modified Paths:
--------------
    geomcore/trunk/include/ExtObject.h
    geomcore/trunk/src/GS/ExtObject.cxx

Modified: geomcore/trunk/include/ExtObject.h
===================================================================
--- geomcore/trunk/include/ExtObject.h  2011-06-02 16:09:19 UTC (rev 44726)
+++ geomcore/trunk/include/ExtObject.h  2011-06-02 16:11:12 UTC (rev 44727)
@@ -27,26 +27,33 @@
 #define __EXTOBJECT_H___
 
 #include "ByteBuffer.h"
+#include "GeometryChunkMsg.h"
 
 #include <bu.h>
 #include <string>
 
 class ExtObject {
 public:
+  /* Normal cstr */
   ExtObject(std::string objName, bu_external* ext);
+
+  /* factory method */
+  static ExtObject* makeExtObject(ByteBuffer* data);
+
   virtual  ~ExtObject(void);
 
   void serialize(ByteBuffer* bb);
   ByteBuffer* serialize();
 
-  std::string  getObjectName();
+  std::string  getFullPath();
 
+  GeometryChunkMsg* toGeometryChunkMsg(NetMsg* reply = 0);
+
   void  printObjState();
 
 private:
   bu_external* ext;
-  std::string filePath;
-  std::string objName;
+  std::string fullPath;
 };
 
 #endif /* __EXTOBJECT_H___ */

Modified: geomcore/trunk/src/GS/ExtObject.cxx
===================================================================
--- geomcore/trunk/src/GS/ExtObject.cxx 2011-06-02 16:09:19 UTC (rev 44726)
+++ geomcore/trunk/src/GS/ExtObject.cxx 2011-06-02 16:11:12 UTC (rev 44727)
@@ -25,39 +25,90 @@
 #include <iostream>
 
 
-ExtObject::ExtObject( std::string objName, bu_external* ext
-) : ext(ext), objName(objName) {}
+ExtObject::ExtObject( std::string fullPath, bu_external* ext
+) : ext(ext), fullPath(fullPath) {}
 
-ExtObject::~ExtObject(void){
-  delete ext;
+ExtObject::~ExtObject(void)
+{
+  bu_free(ext, "ExtObject dstr");
 }
 
+ExtObject*
+ExtObject::makeExtObject(ByteBuffer* bb)
+{
+  bu_external* ext = (bu_external*)bu_malloc(sizeof(bu_external), "ExtObject 
cstr");
+
+  std::cout << "Before BU_INIT_EXTERNAL\n";
+  BU_INIT_EXTERNAL(ext);
+  std::cout << "After BU_INIT_EXTERNAL\n";
+
+  /* Deserialize */
+
+  /* path */
+  std::string fullPath = bb->getString();
+  if (fullPath.length() <= 0) return NULL;
+
+  /* Magic */
+  ext->ext_magic = bb->get32bit();
+
+  /* Buf len */
+  ext->ext_nbytes = bb->get32bit();
+  if (ext->ext_nbytes <= 0) return NULL;
+
+  /* Buf */
+  ext->ext_buf = (uint8_t*)bu_malloc(ext->ext_nbytes, "ExtObject cstr");
+  bb->get((char*)ext->ext_buf, ext->ext_nbytes);
+
+  return new ExtObject(fullPath, ext);
+}
+
 void
 ExtObject::serialize(ByteBuffer* bb)
 {
+  bb->putString(this->fullPath);
+  bb->put32bit(this->ext->ext_magic);
+  bb->put32bit(this->ext->ext_nbytes);
   bb->put((char*)this->ext->ext_buf, this->ext->ext_nbytes);
 }
 
 ByteBuffer*
 ExtObject::serialize()
 {
-  return ByteBuffer::wrap((char*)this->ext->ext_buf, this->ext->ext_nbytes);
+  int size = this->fullPath.length() + sizeof(int) + this->ext->ext_nbytes;
+  ByteBuffer* bb = ByteBuffer::allocate(size);
+  this->serialize(bb);
+  return bb;
 }
 
 std::string
-ExtObject::getObjectName()
+ExtObject::getFullPath()
 {
-  return this->objName;
+  return this->fullPath;
 }
 
 void
 ExtObject::printObjState()
 {
   std::cout << "ext*: " << ((this->ext == NULL) ? "NULL" : "Set") << "\n";
-  std::cout << "filePath: " << filePath << "\n";
-  std::cout << "objName: " << objName << std::endl;
+  std::cout << "fullPath: " << fullPath << std::endl;
 }
 
+GeometryChunkMsg*
+ExtObject::toGeometryChunkMsg(NetMsg* reply)
+{
+  GeometryChunkMsg* chunk = NULL;
+  ByteBuffer* bb = this->serialize();
+
+  if (reply == NULL)
+    chunk = new GeometryChunkMsg(this->fullPath, bb);
+  else
+    chunk = new GeometryChunkMsg(reply, this->fullPath, bb);
+
+  delete bb;
+  return chunk;
+}
+
+
 // Local Variables:
 // tab-width: 8
 // mode: C++


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to