Revision: 43139
          http://brlcad.svn.sourceforge.net/brlcad/?rev=43139&view=rev
Author:   davidloman
Date:     2011-02-08 19:56:08 +0000 (Tue, 08 Feb 2011)

Log Message:
-----------
First cut at implementation of AbstractNetMsg in java.

Added Paths:
-----------
    
geomcore/trunk/src/interfaces/java/src/org/brlcad/geometryservice/net/msg/AbstractNetMsg.java

Added: 
geomcore/trunk/src/interfaces/java/src/org/brlcad/geometryservice/net/msg/AbstractNetMsg.java
===================================================================
--- 
geomcore/trunk/src/interfaces/java/src/org/brlcad/geometryservice/net/msg/AbstractNetMsg.java
                               (rev 0)
+++ 
geomcore/trunk/src/interfaces/java/src/org/brlcad/geometryservice/net/msg/AbstractNetMsg.java
       2011-02-08 19:56:08 UTC (rev 43139)
@@ -0,0 +1,114 @@
+/*                  G S S T A T I C S . J A V A
+ * BRL-CAD
+ *
+ * Copyright (c) 2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file GSStatics.java
+ *
+ */
+
+package org.brlcad.geometryservice.net.msg;
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.brlcad.geometryservice.GSStatics;
+import org.brlcad.geometryservice.net.ByteBufferReader;
+import org.brlcad.geometryservice.net.ByteBufferWriter;
+
+public abstract class AbstractNetMsg {
+
+       /* Header */
+       
+       protected short magic01;
+       protected short magic02;
+       protected int msgLen;
+
+       protected short msgType;
+       protected UUID msgUUID;
+       protected boolean hasReUUID;
+       protected UUID reUUID;
+       
+       /* Cstr used for instantiating an object manually */
+       protected AbstractNetMsg(short msgType) {
+               this.magic01 = GSStatics.magic01;
+               this.magic02 = GSStatics.magic02;
+               this.msgUUID = UUID.randomUUID();
+               this.hasReUUID = false;
+               this.reUUID = null;
+       }
+       
+       /* Cstr used for instantiating an object manually, but replying 
regarding another msg. */
+       protected AbstractNetMsg(short msgType, AbstractNetMsg reMsg) {
+               this(msgType);
+               this.hasReUUID = true;
+               this.reUUID = reMsg.getMsgUUID();
+       }
+       
+       /* Cstr used for deserializing an object */
+       protected AbstractNetMsg(ByteBufferReader reader)
+       {
+               /* Header items */
+               this.msgUUID = reader.getUUID();                
+               this.hasReUUID = reader.getBoolean();
+               
+               if (this.hasReUUID) 
+                       this.reUUID = reader.getUUID();
+       
+               /* Subclass items */
+               this._deserialize(reader);
+       }
+       
+       /* Force subclasses to implement a means of deserialization */
+       protected abstract void _deserialize(ByteBufferReader reader);
+       
+       /* method used to serializing object's current state */
+       public void serialize(ByteBuffer bb) {
+               ByteBufferWriter writer = new ByteBufferWriter(bb);
+
+               /* Header items */
+               writer.putUUID(this.msgUUID);
+               writer.putBoolean(this.hasReUUID);
+               
+               if (this.hasReUUID) 
+                       writer.putUUID(this.reUUID);
+               
+               /* Subclass items */
+               this._serialize(writer);
+       }
+       
+       
+       /* Force subclasses to implement a means of serialization */
+       protected abstract void _serialize(ByteBufferWriter writer);
+       
+       
+       /*
+        * Getters
+        */
+       public final UUID getMsgUUID() {
+               return msgUUID;
+       }
+
+       public final boolean hasReUUID() {
+               return hasReUUID;
+       }
+
+       public final UUID getReUUID() {
+               return reUUID;
+       }
+       
+}


Property changes on: 
geomcore/trunk/src/interfaces/java/src/org/brlcad/geometryservice/net/msg/AbstractNetMsg.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native


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

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to