You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/28 10:22:55 UTC
svn commit: r426431 [8/14] - in /incubator/activemq/branches/activemq-4.0:
activemq-core/src/gram/script/
activemq-core/src/main/java/org/apache/activemq/kaha/impl/
activemq-core/src/main/java/org/apache/activemq/openwire/v1/
activemq-core/src/test/jav...
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.cpp Fri Jul 28 01:22:48 2006
@@ -1,804 +1,804 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "activemq/protocol/openwire/OpenWireMarshaller.hpp"
-
-using namespace apache::activemq::protocol::openwire;
-
-#ifdef MACOSX
-#define BOOLSIZE 1
-#else
-#define BOOLSIZE sizeof(bool)
-#endif
-
-
-// --- Constructors -------------------------------------------------
-
-/*
- *
- */
-OpenWireMarshaller::OpenWireMarshaller(p<WireFormatInfo> formatInfo)
-{
- this->formatInfo = formatInfo ;
-}
-
-// --- Operation methods --------------------------------------------
-
-/*
- *
- */
-int OpenWireMarshaller::marshalBoolean(bool value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeBoolean(value) ;
-
- return (int)BOOLSIZE ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalByte(char value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeByte(value) ;
-
- return (int)sizeof(char) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalShort(short value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeShort(value) ;
-
- return (int)sizeof(short) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalInt(int value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeInt(value) ;
-
- return (int)sizeof(int) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalLong(long long value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeLong(value) ;
-
- return (int)sizeof(long long) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalFloat(float value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeFloat(value) ;
-
- return (int)sizeof(float) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalDouble(double value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- writer->writeDouble(value) ;
-
- return (int)sizeof(double) ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalString(p<string> value, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( mode == IMarshaller::MARSHAL_WRITE )
- {
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "activemq/protocol/openwire/OpenWireMarshaller.hpp"
+
+using namespace apache::activemq::protocol::openwire;
+
+#ifdef MACOSX
+#define BOOLSIZE 1
+#else
+#define BOOLSIZE sizeof(bool)
+#endif
+
+
+// --- Constructors -------------------------------------------------
+
+/*
+ *
+ */
+OpenWireMarshaller::OpenWireMarshaller(p<WireFormatInfo> formatInfo)
+{
+ this->formatInfo = formatInfo ;
+}
+
+// --- Operation methods --------------------------------------------
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalBoolean(bool value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeBoolean(value) ;
+
+ return (int)BOOLSIZE ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalByte(char value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeByte(value) ;
+
+ return (int)sizeof(char) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalShort(short value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeShort(value) ;
+
+ return (int)sizeof(short) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalInt(int value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeInt(value) ;
+
+ return (int)sizeof(int) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalLong(long long value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeLong(value) ;
+
+ return (int)sizeof(long long) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalFloat(float value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeFloat(value) ;
+
+ return (int)sizeof(float) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalDouble(double value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ writer->writeDouble(value) ;
+
+ return (int)sizeof(double) ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalString(p<string> value, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ {
writer->writeBoolean( value != NULL ) ;
- writer->writeString(value) ;
- }
- int size = 0 ;
-
- // Null marker
- size += BOOLSIZE ;
-
- if( value != NULL )
- {
- // String char counter and length
- size += sizeof(short) ;
- size += (int)value->length() ;
- }
- return size ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalObject(p<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- int size = 0 ;
-
- // Write data structure type
- if( mode == IMarshaller::MARSHAL_WRITE )
- {
- // Null marker
- writer->writeBoolean( object != NULL ) ;
-
- // Data structure type
- if( object != NULL )
- writer->writeByte( object->getDataStructureType() ) ;
- }
-
- // Length of null marker
- size += BOOLSIZE ;
-
- if( object != NULL )
- {
- // Length of data structure type
- size += sizeof(char) ;
-
- // Marshal the command body
- size += object->marshal(smartify(this), mode, writer) ;
- }
- return size ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalObjectArray(array<IDataStructure> objects, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- int size = 0 ;
-
- // Write length of array
- if( mode == IMarshaller::MARSHAL_WRITE )
- {
- // Null object marker
- writer->writeBoolean( objects != NULL ) ;
-
- // Check for NULL array
- if( objects != NULL )
- writer->writeShort( (short)objects.size() ) ;
- else
- return BOOLSIZE ;
- }
- // Check for NULL array
- if( objects == NULL )
- return BOOLSIZE ;
-
- // Add size for null marker and array length
- size += BOOLSIZE ;
- size += sizeof(short) ;
-
- // Write/measure each object in array
- for( int i = 0; i < (int)objects.size(); i++ )
- size += objects[i]->marshal(smartify(this), mode, writer) ;
-
- return size ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalByteArray(array<char> values, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- int size = 0 ;
-
- // Write length/content of array
- if( mode == IMarshaller::MARSHAL_WRITE )
- {
- // Null marker
- writer->writeBoolean( values != NULL ) ;
-
- // Check for NULL array
- if( values != NULL )
- {
- // Array length
- int length = (int)values.size() ;
-
- // Length and content
- writer->writeInt( length ) ;
- writer->write( values.c_array(), 0, length) ;
- }
- }
- // Check for NULL array
- if( values == NULL )
- return BOOLSIZE ;
-
- // Add size for null marker, array length and content
- size += BOOLSIZE ;
- size += sizeof(int) ;
- size += (int)values.size() ;
-
- return size ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::marshalMap(p<PropertyMap> object, int mode, p<IOutputStream> writer) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- int size = 0 ;
-
- // Check for NULL map
- if( object == NULL )
- return sizeof(int) ;
-
- PropertyMap::iterator tempIter ;
- string key ;
- MapItemHolder val ;
-
- // Add size for map item count
- size += sizeof(int) ;
-
- // Calculate size of map
- if( mode == IMarshaller::MARSHAL_SIZE )
- {
- // Loop through map contents
- for( tempIter = object->begin() ;
- tempIter != object->end() ;
- tempIter++ )
- {
- array<char> buffer ;
-
- // Extract key-value
- key = tempIter->first ;
- val = tempIter->second ;
-
- // Add size for key char count, lenght of key and value type
- size += sizeof(short) ;
- size += (int)key.length() ;
- size += sizeof(unsigned char) ;
-
- // Write the map value
- switch( val.getType() )
- {
- case MapItemHolder::BOOLEAN:
- size += BOOLSIZE ;
- break ;
- case MapItemHolder::BYTE:
- size += sizeof(char) ;
- break ;
- case MapItemHolder::BYTEARRAY:
- buffer = val.getBytes() ;
- size += (int)buffer.size() ;
- break ;
- case MapItemHolder::DOUBLE:
- size += sizeof(double) ;
- break ;
- case MapItemHolder::FLOAT:
- size += sizeof(float) ;
- break ;
- case MapItemHolder::INTEGER:
- size += sizeof(int) ;
- break ;
- case MapItemHolder::LONG:
- size += sizeof(long) ;
- break ;
- case MapItemHolder::SHORT:
- size += sizeof(short) ;
- break ;
- default:
- size += (int)val.getString()->size() ;
- }
- }
- }
-
- // Write size/content of map
- else if( mode == IMarshaller::MARSHAL_WRITE )
- {
- // Write 'null' marker
- if( object == NULL )
- {
- writer->writeInt(-1) ;
- return size ;
- }
-
- // Write map item count
- writer->writeInt( (int)object->size()) ;
-
- // Loop through map contents
- for( tempIter = object->begin() ;
- tempIter != object->end() ;
- tempIter++ )
- {
- array<char> buffer ;
-
- // Extract key-value
- key = tempIter->first ;
- val = tempIter->second ;
-
- // Add size for key char count, lenght of key and value type
- size += sizeof(short) ;
- size += (int)key.length() ;
- size += sizeof(unsigned char) ;
-
- // Write the map key
- writer->writeString( p<string>( new string(tempIter->first) ) ) ;
-
- // Write the map value
- switch( val.getType() )
- {
- case MapItemHolder::BOOLEAN:
- writer->writeByte( TYPE_BOOLEAN ) ;
- writer->writeBoolean( val.getBoolean() ) ;
- size += BOOLSIZE ;
- break ;
- case MapItemHolder::BYTE:
- writer->writeByte( TYPE_BYTE ) ;
- writer->writeByte( val.getByte() ) ;
- size += sizeof(char) ;
- break ;
- case MapItemHolder::BYTEARRAY:
- writer->writeByte( TYPE_BYTEARRAY ) ;
- buffer = val.getBytes() ;
- writer->writeInt( (int)buffer.size() ) ;
- writer->write(buffer.c_array(), 0, (int)buffer.size()) ;
- size += (int)buffer.size() ;
- break ;
- case MapItemHolder::DOUBLE:
- writer->writeByte( TYPE_DOUBLE ) ;
- writer->writeDouble( val.getDouble() ) ;
- size += sizeof(double) ;
- break ;
- case MapItemHolder::FLOAT:
- writer->writeByte( TYPE_FLOAT ) ;
- writer->writeFloat( val.getFloat() ) ;
- size += sizeof(float) ;
- break ;
- case MapItemHolder::INTEGER:
- writer->writeByte( TYPE_INTEGER ) ;
- writer->writeInt( val.getInt() ) ;
- size += sizeof(int) ;
- break ;
- case MapItemHolder::LONG:
- writer->writeByte( TYPE_LONG ) ;
- writer->writeLong( val.getLong() ) ;
- size += sizeof(long) ;
- break ;
- case MapItemHolder::SHORT:
- writer->writeByte( TYPE_SHORT ) ;
- writer->writeShort( val.getShort() ) ;
- size += sizeof(short) ;
- break ;
- case MapItemHolder::STRING:
- writer->writeByte( TYPE_STRING ) ;
- writer->writeString( val.getString() ) ;
- size += (int)val.getString()->size() ;
- break ;
- default:
- writer->writeByte( TYPE_NULL ) ;
- }
- }
- }
- return size ;
- }
- else
- {
- // Not yet implemented (tight marshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-bool OpenWireMarshaller::unmarshalBoolean(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readBoolean() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-char OpenWireMarshaller::unmarshalByte(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readByte() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-/*
- *
- */
-short OpenWireMarshaller::unmarshalShort(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readShort() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-int OpenWireMarshaller::unmarshalInt(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readInt() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-long long OpenWireMarshaller::unmarshalLong(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readLong() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-float OpenWireMarshaller::unmarshalFloat(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readFloat() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-double OpenWireMarshaller::unmarshalDouble(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- return reader->readFloat() ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return 0 ;
-}
-
-/*
- *
- */
-p<string> OpenWireMarshaller::unmarshalString(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- if( reader->readBoolean() )
- return reader->readString() ;
- else
- return NULL ;
- }
- else
- {
- // Not yet implemented (loose unmarshalling)
- }
- return NULL ;
-}
-
-/*
- *
- */
-p<IDataStructure> OpenWireMarshaller::unmarshalObject(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- // Null marker
- if( !reader->readBoolean() )
- return NULL ;
-
- // Read data structure
- unsigned char dataType = reader->readByte() ;
-
- // Create command object
- p<IDataStructure> object = AbstractCommand::createObject(dataType) ;
- if( object == NULL )
- throw IOException("Unmarshal failed; unknown data structure type %d, at %s line %d", dataType, __FILE__, __LINE__) ;
-
- // Finally, unmarshal command body
- object->unmarshal(smartify(this), IMarshaller::MARSHAL_READ, reader) ;
- return object ;
- }
- else
- {
- // Not yet implemented (tight unmarshalling)
- }
- return NULL ;
-}
-
-/*
- *
- */
-array<IDataStructure> OpenWireMarshaller::unmarshalObjectArray(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- // Null marker
- if( !reader->readBoolean() )
- return NULL ;
-
- int length = reader->readShort() ;
-
- // Check for NULL array
- if( length == 0 )
- {
- return NULL;
- }
-
- // Create array
- array<IDataStructure> objects (length) ;
-
- // Unmarshal each item in array
- for( int i = 0 ; i < length ; i++ )
- objects[i] = unmarshalObject(mode, reader) ;
-
- return objects ;
- }
- else
- {
- // Not yet implemented (loose unmarshalling)
- }
- return NULL;
-}
-
-/*
- *
- */
-array<char> OpenWireMarshaller::unmarshalByteArray(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- // Null marker
- if( !reader->readBoolean() )
- return NULL ;
-
- int length = reader->readInt() ;
-
- // Check for NULL array
- if( length == 0 )
- return NULL ;
-
- // Create array
- array<char> value (length);
-
- // Unmarshal all bytes in array
- reader->read(value.c_array(), 0, length) ;
-
- return value ;
- }
- else
- {
- // Not yet implemented (loose unmarshalling)
- }
- return NULL ;
-}
-
-/*
- *
- */
-p<PropertyMap> OpenWireMarshaller::unmarshalMap(int mode, p<IInputStream> reader) throw(IOException)
-{
- if( !formatInfo->getTightEncodingEnabled() )
- {
- // Get size of map
- int size = reader->readInt() ;
-
- // Check for NULL map
- if( size < 0 )
- return NULL ;
-
- // Create map
- p<PropertyMap> object = new PropertyMap() ;
- p<string> key ;
- MapItemHolder val ;
- array<char> buffer ;
- unsigned char type ;
- int length ;
-
- // Loop through and read all key-values
- for( int i = 0 ; i < size ; i++ )
- {
- // Get next key
- key = reader->readString() ;
-
- // Get the primitive type
- type = reader->readByte() ;
-
- // Depending on type read next value
- switch( type )
- {
- case TYPE_BOOLEAN:
- val = MapItemHolder( reader->readBoolean() ) ;
- break ;
- case TYPE_BYTE:
- val = MapItemHolder( reader->readByte() ) ;
- break ;
- case TYPE_BYTEARRAY:
- length = reader->readInt() ;
- buffer = array<char> (length) ;
- reader->read(buffer.c_array(), 0, length) ;
- val = MapItemHolder( buffer ) ;
- break ;
- case TYPE_DOUBLE:
- val = MapItemHolder( reader->readDouble() ) ;
- break ;
- case TYPE_FLOAT:
- val = MapItemHolder( reader->readFloat() ) ;
- break ;
- case TYPE_INTEGER:
- val = MapItemHolder( reader->readInt() ) ;
- break ;
- case TYPE_LONG:
- val = MapItemHolder( reader->readLong() ) ;
- break ;
- case TYPE_SHORT:
- val = MapItemHolder( reader->readShort() ) ;
- break ;
- case TYPE_STRING:
- val = MapItemHolder( reader->readString() ) ;
- break ;
- default:
- val = MapItemHolder() ;
- }
- // Insert value into property map
- (*object)[key->c_str()] = val ;
- }
- return object ;
- }
- else
- {
- // Not yet implemented (loose unmarshalling)
- }
- return NULL;
-}
+ writer->writeString(value) ;
+ }
+ int size = 0 ;
+
+ // Null marker
+ size += BOOLSIZE ;
+
+ if( value != NULL )
+ {
+ // String char counter and length
+ size += sizeof(short) ;
+ size += (int)value->length() ;
+ }
+ return size ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalObject(p<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ int size = 0 ;
+
+ // Write data structure type
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ {
+ // Null marker
+ writer->writeBoolean( object != NULL ) ;
+
+ // Data structure type
+ if( object != NULL )
+ writer->writeByte( object->getDataStructureType() ) ;
+ }
+
+ // Length of null marker
+ size += BOOLSIZE ;
+
+ if( object != NULL )
+ {
+ // Length of data structure type
+ size += sizeof(char) ;
+
+ // Marshal the command body
+ size += object->marshal(smartify(this), mode, writer) ;
+ }
+ return size ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalObjectArray(array<IDataStructure> objects, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ int size = 0 ;
+
+ // Write length of array
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ {
+ // Null object marker
+ writer->writeBoolean( objects != NULL ) ;
+
+ // Check for NULL array
+ if( objects != NULL )
+ writer->writeShort( (short)objects.size() ) ;
+ else
+ return BOOLSIZE ;
+ }
+ // Check for NULL array
+ if( objects == NULL )
+ return BOOLSIZE ;
+
+ // Add size for null marker and array length
+ size += BOOLSIZE ;
+ size += sizeof(short) ;
+
+ // Write/measure each object in array
+ for( int i = 0; i < (int)objects.size(); i++ )
+ size += objects[i]->marshal(smartify(this), mode, writer) ;
+
+ return size ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalByteArray(array<char> values, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ int size = 0 ;
+
+ // Write length/content of array
+ if( mode == IMarshaller::MARSHAL_WRITE )
+ {
+ // Null marker
+ writer->writeBoolean( values != NULL ) ;
+
+ // Check for NULL array
+ if( values != NULL )
+ {
+ // Array length
+ int length = (int)values.size() ;
+
+ // Length and content
+ writer->writeInt( length ) ;
+ writer->write( values.c_array(), 0, length) ;
+ }
+ }
+ // Check for NULL array
+ if( values == NULL )
+ return BOOLSIZE ;
+
+ // Add size for null marker, array length and content
+ size += BOOLSIZE ;
+ size += sizeof(int) ;
+ size += (int)values.size() ;
+
+ return size ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::marshalMap(p<PropertyMap> object, int mode, p<IOutputStream> writer) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ int size = 0 ;
+
+ // Check for NULL map
+ if( object == NULL )
+ return sizeof(int) ;
+
+ PropertyMap::iterator tempIter ;
+ string key ;
+ MapItemHolder val ;
+
+ // Add size for map item count
+ size += sizeof(int) ;
+
+ // Calculate size of map
+ if( mode == IMarshaller::MARSHAL_SIZE )
+ {
+ // Loop through map contents
+ for( tempIter = object->begin() ;
+ tempIter != object->end() ;
+ tempIter++ )
+ {
+ array<char> buffer ;
+
+ // Extract key-value
+ key = tempIter->first ;
+ val = tempIter->second ;
+
+ // Add size for key char count, lenght of key and value type
+ size += sizeof(short) ;
+ size += (int)key.length() ;
+ size += sizeof(unsigned char) ;
+
+ // Write the map value
+ switch( val.getType() )
+ {
+ case MapItemHolder::BOOLEAN:
+ size += BOOLSIZE ;
+ break ;
+ case MapItemHolder::BYTE:
+ size += sizeof(char) ;
+ break ;
+ case MapItemHolder::BYTEARRAY:
+ buffer = val.getBytes() ;
+ size += (int)buffer.size() ;
+ break ;
+ case MapItemHolder::DOUBLE:
+ size += sizeof(double) ;
+ break ;
+ case MapItemHolder::FLOAT:
+ size += sizeof(float) ;
+ break ;
+ case MapItemHolder::INTEGER:
+ size += sizeof(int) ;
+ break ;
+ case MapItemHolder::LONG:
+ size += sizeof(long) ;
+ break ;
+ case MapItemHolder::SHORT:
+ size += sizeof(short) ;
+ break ;
+ default:
+ size += (int)val.getString()->size() ;
+ }
+ }
+ }
+
+ // Write size/content of map
+ else if( mode == IMarshaller::MARSHAL_WRITE )
+ {
+ // Write 'null' marker
+ if( object == NULL )
+ {
+ writer->writeInt(-1) ;
+ return size ;
+ }
+
+ // Write map item count
+ writer->writeInt( (int)object->size()) ;
+
+ // Loop through map contents
+ for( tempIter = object->begin() ;
+ tempIter != object->end() ;
+ tempIter++ )
+ {
+ array<char> buffer ;
+
+ // Extract key-value
+ key = tempIter->first ;
+ val = tempIter->second ;
+
+ // Add size for key char count, lenght of key and value type
+ size += sizeof(short) ;
+ size += (int)key.length() ;
+ size += sizeof(unsigned char) ;
+
+ // Write the map key
+ writer->writeString( p<string>( new string(tempIter->first) ) ) ;
+
+ // Write the map value
+ switch( val.getType() )
+ {
+ case MapItemHolder::BOOLEAN:
+ writer->writeByte( TYPE_BOOLEAN ) ;
+ writer->writeBoolean( val.getBoolean() ) ;
+ size += BOOLSIZE ;
+ break ;
+ case MapItemHolder::BYTE:
+ writer->writeByte( TYPE_BYTE ) ;
+ writer->writeByte( val.getByte() ) ;
+ size += sizeof(char) ;
+ break ;
+ case MapItemHolder::BYTEARRAY:
+ writer->writeByte( TYPE_BYTEARRAY ) ;
+ buffer = val.getBytes() ;
+ writer->writeInt( (int)buffer.size() ) ;
+ writer->write(buffer.c_array(), 0, (int)buffer.size()) ;
+ size += (int)buffer.size() ;
+ break ;
+ case MapItemHolder::DOUBLE:
+ writer->writeByte( TYPE_DOUBLE ) ;
+ writer->writeDouble( val.getDouble() ) ;
+ size += sizeof(double) ;
+ break ;
+ case MapItemHolder::FLOAT:
+ writer->writeByte( TYPE_FLOAT ) ;
+ writer->writeFloat( val.getFloat() ) ;
+ size += sizeof(float) ;
+ break ;
+ case MapItemHolder::INTEGER:
+ writer->writeByte( TYPE_INTEGER ) ;
+ writer->writeInt( val.getInt() ) ;
+ size += sizeof(int) ;
+ break ;
+ case MapItemHolder::LONG:
+ writer->writeByte( TYPE_LONG ) ;
+ writer->writeLong( val.getLong() ) ;
+ size += sizeof(long) ;
+ break ;
+ case MapItemHolder::SHORT:
+ writer->writeByte( TYPE_SHORT ) ;
+ writer->writeShort( val.getShort() ) ;
+ size += sizeof(short) ;
+ break ;
+ case MapItemHolder::STRING:
+ writer->writeByte( TYPE_STRING ) ;
+ writer->writeString( val.getString() ) ;
+ size += (int)val.getString()->size() ;
+ break ;
+ default:
+ writer->writeByte( TYPE_NULL ) ;
+ }
+ }
+ }
+ return size ;
+ }
+ else
+ {
+ // Not yet implemented (tight marshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+bool OpenWireMarshaller::unmarshalBoolean(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readBoolean() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+char OpenWireMarshaller::unmarshalByte(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readByte() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+/*
+ *
+ */
+short OpenWireMarshaller::unmarshalShort(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readShort() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+int OpenWireMarshaller::unmarshalInt(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readInt() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+long long OpenWireMarshaller::unmarshalLong(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readLong() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+float OpenWireMarshaller::unmarshalFloat(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readFloat() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+double OpenWireMarshaller::unmarshalDouble(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ return reader->readFloat() ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return 0 ;
+}
+
+/*
+ *
+ */
+p<string> OpenWireMarshaller::unmarshalString(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ if( reader->readBoolean() )
+ return reader->readString() ;
+ else
+ return NULL ;
+ }
+ else
+ {
+ // Not yet implemented (loose unmarshalling)
+ }
+ return NULL ;
+}
+
+/*
+ *
+ */
+p<IDataStructure> OpenWireMarshaller::unmarshalObject(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ // Null marker
+ if( !reader->readBoolean() )
+ return NULL ;
+
+ // Read data structure
+ unsigned char dataType = reader->readByte() ;
+
+ // Create command object
+ p<IDataStructure> object = AbstractCommand::createObject(dataType) ;
+ if( object == NULL )
+ throw IOException("Unmarshal failed; unknown data structure type %d, at %s line %d", dataType, __FILE__, __LINE__) ;
+
+ // Finally, unmarshal command body
+ object->unmarshal(smartify(this), IMarshaller::MARSHAL_READ, reader) ;
+ return object ;
+ }
+ else
+ {
+ // Not yet implemented (tight unmarshalling)
+ }
+ return NULL ;
+}
+
+/*
+ *
+ */
+array<IDataStructure> OpenWireMarshaller::unmarshalObjectArray(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ // Null marker
+ if( !reader->readBoolean() )
+ return NULL ;
+
+ int length = reader->readShort() ;
+
+ // Check for NULL array
+ if( length == 0 )
+ {
+ return NULL;
+ }
+
+ // Create array
+ array<IDataStructure> objects (length) ;
+
+ // Unmarshal each item in array
+ for( int i = 0 ; i < length ; i++ )
+ objects[i] = unmarshalObject(mode, reader) ;
+
+ return objects ;
+ }
+ else
+ {
+ // Not yet implemented (loose unmarshalling)
+ }
+ return NULL;
+}
+
+/*
+ *
+ */
+array<char> OpenWireMarshaller::unmarshalByteArray(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ // Null marker
+ if( !reader->readBoolean() )
+ return NULL ;
+
+ int length = reader->readInt() ;
+
+ // Check for NULL array
+ if( length == 0 )
+ return NULL ;
+
+ // Create array
+ array<char> value (length);
+
+ // Unmarshal all bytes in array
+ reader->read(value.c_array(), 0, length) ;
+
+ return value ;
+ }
+ else
+ {
+ // Not yet implemented (loose unmarshalling)
+ }
+ return NULL ;
+}
+
+/*
+ *
+ */
+p<PropertyMap> OpenWireMarshaller::unmarshalMap(int mode, p<IInputStream> reader) throw(IOException)
+{
+ if( !formatInfo->getTightEncodingEnabled() )
+ {
+ // Get size of map
+ int size = reader->readInt() ;
+
+ // Check for NULL map
+ if( size < 0 )
+ return NULL ;
+
+ // Create map
+ p<PropertyMap> object = new PropertyMap() ;
+ p<string> key ;
+ MapItemHolder val ;
+ array<char> buffer ;
+ unsigned char type ;
+ int length ;
+
+ // Loop through and read all key-values
+ for( int i = 0 ; i < size ; i++ )
+ {
+ // Get next key
+ key = reader->readString() ;
+
+ // Get the primitive type
+ type = reader->readByte() ;
+
+ // Depending on type read next value
+ switch( type )
+ {
+ case TYPE_BOOLEAN:
+ val = MapItemHolder( reader->readBoolean() ) ;
+ break ;
+ case TYPE_BYTE:
+ val = MapItemHolder( reader->readByte() ) ;
+ break ;
+ case TYPE_BYTEARRAY:
+ length = reader->readInt() ;
+ buffer = array<char> (length) ;
+ reader->read(buffer.c_array(), 0, length) ;
+ val = MapItemHolder( buffer ) ;
+ break ;
+ case TYPE_DOUBLE:
+ val = MapItemHolder( reader->readDouble() ) ;
+ break ;
+ case TYPE_FLOAT:
+ val = MapItemHolder( reader->readFloat() ) ;
+ break ;
+ case TYPE_INTEGER:
+ val = MapItemHolder( reader->readInt() ) ;
+ break ;
+ case TYPE_LONG:
+ val = MapItemHolder( reader->readLong() ) ;
+ break ;
+ case TYPE_SHORT:
+ val = MapItemHolder( reader->readShort() ) ;
+ break ;
+ case TYPE_STRING:
+ val = MapItemHolder( reader->readString() ) ;
+ break ;
+ default:
+ val = MapItemHolder() ;
+ }
+ // Insert value into property map
+ (*object)[key->c_str()] = val ;
+ }
+ return object ;
+ }
+ else
+ {
+ // Not yet implemented (loose unmarshalling)
+ }
+ return NULL;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.hpp Fri Jul 28 01:22:48 2006
@@ -1,112 +1,112 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ActiveMQ_OpenWireMarshaller_hpp_
-#define ActiveMQ_OpenWireMarshaller_hpp_
-
-// Turn off warning message for ignored exception specification
-#ifdef _MSC_VER
-#pragma warning( disable : 4290 )
-#endif
-
-#include <string>
-#include <map>
-#include "activemq/IDataStructure.hpp"
-#include "activemq/command/AbstractCommand.hpp"
-#include "activemq/command/WireFormatInfo.hpp"
-#include "activemq/protocol/IMarshaller.hpp"
-#include "activemq/protocol/openwire/OpenWireProtocol.hpp"
-#include "ppr/io/DataOutputStream.hpp"
-#include "ppr/io/DataInputStream.hpp"
-#include "ppr/io/IOException.hpp"
-#include "ppr/util/MapItemHolder.hpp"
-#include "ppr/util/ifr/array"
-#include "ppr/util/ifr/p"
-
-namespace apache
-{
- namespace activemq
- {
- namespace protocol
- {
- namespace openwire
- {
- using namespace ifr ;
- using namespace apache::activemq;
- using namespace apache::activemq::command;
- using namespace apache::activemq::protocol;
- using namespace apache::ppr::io;
- using namespace apache::ppr::util;
-
-/*
- * A helper class with marshalling methods for the OpenWire protocol.
- */
-class OpenWireMarshaller : public IMarshaller
-{
-private:
- p<WireFormatInfo> formatInfo ;
-
-public:
- // Primitive types
- static const unsigned char TYPE_NULL = 0 ;
- static const unsigned char TYPE_BOOLEAN = 1 ;
- static const unsigned char TYPE_BYTE = 2 ;
- static const unsigned char TYPE_CHAR = 3 ;
- static const unsigned char TYPE_SHORT = 4 ;
- static const unsigned char TYPE_INTEGER = 5 ;
- static const unsigned char TYPE_LONG = 6 ;
- static const unsigned char TYPE_DOUBLE = 7 ;
- static const unsigned char TYPE_FLOAT = 8 ;
- static const unsigned char TYPE_STRING = 9 ;
- static const unsigned char TYPE_BYTEARRAY = 10 ;
-
-public:
- OpenWireMarshaller(p<WireFormatInfo> formatInfo) ;
-
- virtual int marshalBoolean(bool value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalByte(char value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalShort(short value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalInt(int value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalLong(long long value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalFloat(float value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalDouble(double value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalString(p<string> value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalObject(p<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalObjectArray(array<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalByteArray(array<char> value, int mode, p<IOutputStream> writer) throw(IOException) ;
- virtual int marshalMap(p<PropertyMap> value, int mode, p<IOutputStream> writer) throw(IOException) ;
-
- virtual bool unmarshalBoolean(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual char unmarshalByte(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual short unmarshalShort(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual int unmarshalInt(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual long long unmarshalLong(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual float unmarshalFloat(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual double unmarshalDouble(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual p<string> unmarshalString(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual p<IDataStructure> unmarshalObject(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual array<IDataStructure> unmarshalObjectArray(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual array<char> unmarshalByteArray(int mode, p<IInputStream> reader) throw(IOException) ;
- virtual p<PropertyMap> unmarshalMap(int mode, p<IInputStream> reader) throw(IOException) ;
-} ;
-
-/* namespace */
- }
- }
- }
-}
-
-#endif /*ActiveMQ_OpenWireMarshaller_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ActiveMQ_OpenWireMarshaller_hpp_
+#define ActiveMQ_OpenWireMarshaller_hpp_
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
+
+#include <string>
+#include <map>
+#include "activemq/IDataStructure.hpp"
+#include "activemq/command/AbstractCommand.hpp"
+#include "activemq/command/WireFormatInfo.hpp"
+#include "activemq/protocol/IMarshaller.hpp"
+#include "activemq/protocol/openwire/OpenWireProtocol.hpp"
+#include "ppr/io/DataOutputStream.hpp"
+#include "ppr/io/DataInputStream.hpp"
+#include "ppr/io/IOException.hpp"
+#include "ppr/util/MapItemHolder.hpp"
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+ namespace activemq
+ {
+ namespace protocol
+ {
+ namespace openwire
+ {
+ using namespace ifr ;
+ using namespace apache::activemq;
+ using namespace apache::activemq::command;
+ using namespace apache::activemq::protocol;
+ using namespace apache::ppr::io;
+ using namespace apache::ppr::util;
+
+/*
+ * A helper class with marshalling methods for the OpenWire protocol.
+ */
+class OpenWireMarshaller : public IMarshaller
+{
+private:
+ p<WireFormatInfo> formatInfo ;
+
+public:
+ // Primitive types
+ static const unsigned char TYPE_NULL = 0 ;
+ static const unsigned char TYPE_BOOLEAN = 1 ;
+ static const unsigned char TYPE_BYTE = 2 ;
+ static const unsigned char TYPE_CHAR = 3 ;
+ static const unsigned char TYPE_SHORT = 4 ;
+ static const unsigned char TYPE_INTEGER = 5 ;
+ static const unsigned char TYPE_LONG = 6 ;
+ static const unsigned char TYPE_DOUBLE = 7 ;
+ static const unsigned char TYPE_FLOAT = 8 ;
+ static const unsigned char TYPE_STRING = 9 ;
+ static const unsigned char TYPE_BYTEARRAY = 10 ;
+
+public:
+ OpenWireMarshaller(p<WireFormatInfo> formatInfo) ;
+
+ virtual int marshalBoolean(bool value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalByte(char value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalShort(short value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalInt(int value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalLong(long long value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalFloat(float value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalDouble(double value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalString(p<string> value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalObject(p<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalObjectArray(array<IDataStructure> object, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalByteArray(array<char> value, int mode, p<IOutputStream> writer) throw(IOException) ;
+ virtual int marshalMap(p<PropertyMap> value, int mode, p<IOutputStream> writer) throw(IOException) ;
+
+ virtual bool unmarshalBoolean(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual char unmarshalByte(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual short unmarshalShort(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual int unmarshalInt(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual long long unmarshalLong(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual float unmarshalFloat(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual double unmarshalDouble(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual p<string> unmarshalString(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual p<IDataStructure> unmarshalObject(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual array<IDataStructure> unmarshalObjectArray(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual array<char> unmarshalByteArray(int mode, p<IInputStream> reader) throw(IOException) ;
+ virtual p<PropertyMap> unmarshalMap(int mode, p<IInputStream> reader) throw(IOException) ;
+} ;
+
+/* namespace */
+ }
+ }
+ }
+}
+
+#endif /*ActiveMQ_OpenWireMarshaller_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireMarshaller.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireProtocol.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireProtocol.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireProtocol.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireProtocol.cpp Fri Jul 28 01:22:48 2006
@@ -1,142 +1,142 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "activemq/protocol/openwire/OpenWireProtocol.hpp"
-#include "activemq/protocol/openwire/OpenWireMarshaller.hpp"
-
-using namespace apache::activemq::protocol::openwire;
-
-// --- Static initialization ----------------------------------------
-
-const char OpenWireProtocol::MAGIC[8] = { 'A', 'c', 't', 'i', 'v', 'e', 'M', 'Q' } ;
-const int OpenWireProtocol::PROTOCOL_VERSION = 1 ;
-const char OpenWireProtocol::NULL_TYPE = 0 ;
-
-
-/*
- *
- */
-OpenWireProtocol::OpenWireProtocol()
-{
- array<char> magic (8);
- memcpy (magic.c_array(), "ActiveMQ", 8);
-
- // Create and configure wire format
- wireFormatInfo = new WireFormatInfo() ;
- wireFormatInfo->setMagic( magic ) ;
- wireFormatInfo->setVersion( PROTOCOL_VERSION ) ;
- wireFormatInfo->setStackTraceEnabled(true) ;
- wireFormatInfo->setTcpNoDelayEnabled(true) ;
- wireFormatInfo->setSizePrefixDisabled(false) ;
- wireFormatInfo->setTightEncodingEnabled(false) ;
-
- // Create wire marshaller
- wireMarshaller = new OpenWireMarshaller(wireFormatInfo) ;
-}
-
-/*
- *
- */
-p<WireFormatInfo> OpenWireProtocol::getWireFormatInfo()
-{
- return wireFormatInfo ;
-}
-
-/*
- *
- */
-bool OpenWireProtocol::getStackTraceEnabled()
-{
- return wireFormatInfo->getStackTraceEnabled() ;
-}
-
-/*
- *
- */
-void OpenWireProtocol::handshake(p<ITransport> transport)
-{
- // Send the wireformat we're using
- transport->oneway( getWireFormatInfo() ) ;
-}
-
-/*
- *
- */
-void OpenWireProtocol::marshal(p<IDataStructure> object, p<IOutputStream> writer) throw(IOException)
-{
- int size = 0 ;
-
- // Was a non-NULL object supplied
- if( object != NULL )
- {
- unsigned char dataType = object->getDataStructureType() ;
-
- // Calculate size to be marshalled if configured
- if( !wireFormatInfo->getSizePrefixDisabled() )
- {
- size = 1 ; // data structure type
- size += object->marshal(wireMarshaller, IMarshaller::MARSHAL_SIZE, writer) ;
-
- // Write size header
- writer->writeInt(size) ;
- }
- // Finally, write command type and body
- writer->writeByte(dataType) ;
- object->marshal(wireMarshaller, IMarshaller::MARSHAL_WRITE, writer) ;
- }
- else // ...NULL object
- {
- // Calculate size to be marshalled if configured
- if( !wireFormatInfo->getSizePrefixDisabled() )
- {
- // Calculate size to be marshalled
- size = 1 ; // data structure type
-
- // Write size header
- writer->writeInt(size) ;
- }
- // Write NULL command type and empty body
- writer->writeByte(NULL_TYPE) ;
- }
-}
-
-/*
- *
- */
-p<IDataStructure> OpenWireProtocol::unmarshal(p<IInputStream> reader) throw(IOException)
-{
- int size = 0 ;
-
- // Read packet size if configured
- if( !wireFormatInfo->getSizePrefixDisabled() )
- size = reader->readInt() ;
-
- // First byte is the data structure type
- unsigned char dataType = reader->readByte() ;
-
- // Check for NULL type
- if( dataType == NULL_TYPE )
- return NULL ;
-
- // Create command object
- p<IDataStructure> object = AbstractCommand::createObject(dataType) ;
- if( object == NULL )
- throw IOException("Unmarshal failed; unknown data structure type %d, at %s line %d", dataType, __FILE__, __LINE__) ;
-
- // Finally, unmarshal command body
- object->unmarshal(wireMarshaller, IMarshaller::MARSHAL_READ, reader) ;
- return object ;
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "activemq/protocol/openwire/OpenWireProtocol.hpp"
+#include "activemq/protocol/openwire/OpenWireMarshaller.hpp"
+
+using namespace apache::activemq::protocol::openwire;
+
+// --- Static initialization ----------------------------------------
+
+const char OpenWireProtocol::MAGIC[8] = { 'A', 'c', 't', 'i', 'v', 'e', 'M', 'Q' } ;
+const int OpenWireProtocol::PROTOCOL_VERSION = 1 ;
+const char OpenWireProtocol::NULL_TYPE = 0 ;
+
+
+/*
+ *
+ */
+OpenWireProtocol::OpenWireProtocol()
+{
+ array<char> magic (8);
+ memcpy (magic.c_array(), "ActiveMQ", 8);
+
+ // Create and configure wire format
+ wireFormatInfo = new WireFormatInfo() ;
+ wireFormatInfo->setMagic( magic ) ;
+ wireFormatInfo->setVersion( PROTOCOL_VERSION ) ;
+ wireFormatInfo->setStackTraceEnabled(true) ;
+ wireFormatInfo->setTcpNoDelayEnabled(true) ;
+ wireFormatInfo->setSizePrefixDisabled(false) ;
+ wireFormatInfo->setTightEncodingEnabled(false) ;
+
+ // Create wire marshaller
+ wireMarshaller = new OpenWireMarshaller(wireFormatInfo) ;
+}
+
+/*
+ *
+ */
+p<WireFormatInfo> OpenWireProtocol::getWireFormatInfo()
+{
+ return wireFormatInfo ;
+}
+
+/*
+ *
+ */
+bool OpenWireProtocol::getStackTraceEnabled()
+{
+ return wireFormatInfo->getStackTraceEnabled() ;
+}
+
+/*
+ *
+ */
+void OpenWireProtocol::handshake(p<ITransport> transport)
+{
+ // Send the wireformat we're using
+ transport->oneway( getWireFormatInfo() ) ;
+}
+
+/*
+ *
+ */
+void OpenWireProtocol::marshal(p<IDataStructure> object, p<IOutputStream> writer) throw(IOException)
+{
+ int size = 0 ;
+
+ // Was a non-NULL object supplied
+ if( object != NULL )
+ {
+ unsigned char dataType = object->getDataStructureType() ;
+
+ // Calculate size to be marshalled if configured
+ if( !wireFormatInfo->getSizePrefixDisabled() )
+ {
+ size = 1 ; // data structure type
+ size += object->marshal(wireMarshaller, IMarshaller::MARSHAL_SIZE, writer) ;
+
+ // Write size header
+ writer->writeInt(size) ;
+ }
+ // Finally, write command type and body
+ writer->writeByte(dataType) ;
+ object->marshal(wireMarshaller, IMarshaller::MARSHAL_WRITE, writer) ;
+ }
+ else // ...NULL object
+ {
+ // Calculate size to be marshalled if configured
+ if( !wireFormatInfo->getSizePrefixDisabled() )
+ {
+ // Calculate size to be marshalled
+ size = 1 ; // data structure type
+
+ // Write size header
+ writer->writeInt(size) ;
+ }
+ // Write NULL command type and empty body
+ writer->writeByte(NULL_TYPE) ;
+ }
+}
+
+/*
+ *
+ */
+p<IDataStructure> OpenWireProtocol::unmarshal(p<IInputStream> reader) throw(IOException)
+{
+ int size = 0 ;
+
+ // Read packet size if configured
+ if( !wireFormatInfo->getSizePrefixDisabled() )
+ size = reader->readInt() ;
+
+ // First byte is the data structure type
+ unsigned char dataType = reader->readByte() ;
+
+ // Check for NULL type
+ if( dataType == NULL_TYPE )
+ return NULL ;
+
+ // Create command object
+ p<IDataStructure> object = AbstractCommand::createObject(dataType) ;
+ if( object == NULL )
+ throw IOException("Unmarshal failed; unknown data structure type %d, at %s line %d", dataType, __FILE__, __LINE__) ;
+
+ // Finally, unmarshal command body
+ object->unmarshal(wireMarshaller, IMarshaller::MARSHAL_READ, reader) ;
+ return object ;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/protocol/openwire/OpenWireProtocol.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.cpp Fri Jul 28 01:22:48 2006
@@ -1,142 +1,142 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "activemq/transport/CorrelatorFilter.hpp"
-
-using namespace apache::activemq::transport;
-
-
-// --- Constructors -------------------------------------------------
-
-/*
- *
- */
-CorrelatorFilter::CorrelatorFilter(p<ITransport> next) :
- TransportFilter(next)
-{
- this->next = next ;
- this->nextCommandId = 0 ;
-}
-
-
-// --- Operation methods --------------------------------------------
-
-/*
- *
- */
-void CorrelatorFilter::oneway(p<ICommand> command)
-{
- // Set command id and that no response is required
- command->setCommandId( getNextCommandId() ) ;
- command->setResponseRequired(false) ;
-
- this->next->oneway(command) ;
-}
-
-/*
- *
- */
-p<FutureResponse> CorrelatorFilter::asyncRequest(p<ICommand> command)
-{
- // Set command id and that a response is required
- command->setCommandId( getNextCommandId() ) ;
- command->setResponseRequired(true) ;
-
- // Register a future response holder with the command id
- p<FutureResponse> future = new FutureResponse() ;
- requestMap[command->getCommandId()] = future ;
-
- // Transmit command
- this->next->oneway(command) ;
-
- return future ;
-}
-
-/*
- *
- */
-p<Response> CorrelatorFilter::request(p<ICommand> command)
-{
- p<FutureResponse> future = asyncRequest(command) ;
- p<Response> response = future->getResponse() ;
-
- if( response == NULL )
- {
- p<BrokerError> brokerError = new BrokerError() ;
- brokerError->setMessage("Timed out waiting for response from broker") ;
- throw BrokerException(brokerError) ;
- }
- else if ( response->getDataStructureType() == ExceptionResponse::TYPE )
- {
- p<ExceptionResponse> er = p_cast<ExceptionResponse> (response) ;
- p<BrokerError> brokerError = er->getException() ;
- throw BrokerException(brokerError) ;
- }
- return response ;
-}
-
-
-// --- Event methods ------------------------------------------------
-
-/*
- *
- */
-void CorrelatorFilter::onCommand(p<ITransport> transport, p<ICommand> command)
-{
- if( command->getDataStructureType() == Response::TYPE )
- {
- p<Response> response = p_cast<Response>(command) ;
- p<FutureResponse> future = requestMap[response->getCorrelationId()] ;
-
- if( future != NULL )
- {
- if( response->getDataStructureType() == ExceptionResponse::TYPE )
- {
- p<ExceptionResponse> er = p_cast<ExceptionResponse> (response) ;
- p<BrokerError> brokerError = er->getException() ;
-
- if( listener != NULL )
- {
- BrokerException brokerException = BrokerException(brokerError) ;
- listener->onError(smartify(this), brokerException) ;
- }
- }
- future->setResponse(response) ;
- }
- else
- cout << "Unknown response ID: " << response->getCorrelationId() << endl ;
- }
- else
- {
- if( listener != NULL )
- listener->onCommand(smartify(this), command) ;
- else
- cout << "ERROR: No handler available to process command: " << command->getDataStructureType() << endl ;
- }
-}
-
-
-// --- Implementation methods ---------------------------------------
-
-/*
- *
- */
-int CorrelatorFilter::getNextCommandId()
-{
- // Wait for lock and then fetch next command id
- LOCKED_SCOPE (mutex);
- return (short) ++nextCommandId ;
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "activemq/transport/CorrelatorFilter.hpp"
+
+using namespace apache::activemq::transport;
+
+
+// --- Constructors -------------------------------------------------
+
+/*
+ *
+ */
+CorrelatorFilter::CorrelatorFilter(p<ITransport> next) :
+ TransportFilter(next)
+{
+ this->next = next ;
+ this->nextCommandId = 0 ;
+}
+
+
+// --- Operation methods --------------------------------------------
+
+/*
+ *
+ */
+void CorrelatorFilter::oneway(p<ICommand> command)
+{
+ // Set command id and that no response is required
+ command->setCommandId( getNextCommandId() ) ;
+ command->setResponseRequired(false) ;
+
+ this->next->oneway(command) ;
+}
+
+/*
+ *
+ */
+p<FutureResponse> CorrelatorFilter::asyncRequest(p<ICommand> command)
+{
+ // Set command id and that a response is required
+ command->setCommandId( getNextCommandId() ) ;
+ command->setResponseRequired(true) ;
+
+ // Register a future response holder with the command id
+ p<FutureResponse> future = new FutureResponse() ;
+ requestMap[command->getCommandId()] = future ;
+
+ // Transmit command
+ this->next->oneway(command) ;
+
+ return future ;
+}
+
+/*
+ *
+ */
+p<Response> CorrelatorFilter::request(p<ICommand> command)
+{
+ p<FutureResponse> future = asyncRequest(command) ;
+ p<Response> response = future->getResponse() ;
+
+ if( response == NULL )
+ {
+ p<BrokerError> brokerError = new BrokerError() ;
+ brokerError->setMessage("Timed out waiting for response from broker") ;
+ throw BrokerException(brokerError) ;
+ }
+ else if ( response->getDataStructureType() == ExceptionResponse::TYPE )
+ {
+ p<ExceptionResponse> er = p_cast<ExceptionResponse> (response) ;
+ p<BrokerError> brokerError = er->getException() ;
+ throw BrokerException(brokerError) ;
+ }
+ return response ;
+}
+
+
+// --- Event methods ------------------------------------------------
+
+/*
+ *
+ */
+void CorrelatorFilter::onCommand(p<ITransport> transport, p<ICommand> command)
+{
+ if( command->getDataStructureType() == Response::TYPE )
+ {
+ p<Response> response = p_cast<Response>(command) ;
+ p<FutureResponse> future = requestMap[response->getCorrelationId()] ;
+
+ if( future != NULL )
+ {
+ if( response->getDataStructureType() == ExceptionResponse::TYPE )
+ {
+ p<ExceptionResponse> er = p_cast<ExceptionResponse> (response) ;
+ p<BrokerError> brokerError = er->getException() ;
+
+ if( listener != NULL )
+ {
+ BrokerException brokerException = BrokerException(brokerError) ;
+ listener->onError(smartify(this), brokerException) ;
+ }
+ }
+ future->setResponse(response) ;
+ }
+ else
+ cout << "Unknown response ID: " << response->getCorrelationId() << endl ;
+ }
+ else
+ {
+ if( listener != NULL )
+ listener->onCommand(smartify(this), command) ;
+ else
+ cout << "ERROR: No handler available to process command: " << command->getDataStructureType() << endl ;
+ }
+}
+
+
+// --- Implementation methods ---------------------------------------
+
+/*
+ *
+ */
+int CorrelatorFilter::getNextCommandId()
+{
+ // Wait for lock and then fetch next command id
+ LOCKED_SCOPE (mutex);
+ return (short) ++nextCommandId ;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.hpp Fri Jul 28 01:22:48 2006
@@ -1,66 +1,66 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ActiveMQ_CorrelatorFilter_hpp_
-#define ActiveMQ_CorrelatorFilter_hpp_
-
-#include <iostream>
-#include "activemq/BrokerException.hpp"
-#include "activemq/command/Response.hpp"
-#include "activemq/command/ExceptionResponse.hpp"
-#include "activemq/transport/TransportFilter.hpp"
-#include "ppr/util/ifr/p"
-
-namespace apache
-{
- namespace activemq
- {
- namespace transport
- {
- using namespace ifr;
- using namespace apache::activemq;
- using namespace apache::activemq::command;
-
-/*
- * Interface for commands.
- */
-class CorrelatorFilter : public TransportFilter
-{
-protected:
- SimpleMutex mutex ;
- map<int, p<FutureResponse> > requestMap ;
- int nextCommandId ;
-
-public:
- CorrelatorFilter(p<ITransport> next) ;
- virtual ~CorrelatorFilter() {}
-
- virtual void oneway(p<ICommand> command) ;
- virtual p<FutureResponse> asyncRequest(p<ICommand> command) ;
- virtual p<Response> request(p<ICommand> command) ;
-
- virtual void onCommand(p<ITransport> transport, p<ICommand> command) ;
-
-protected:
- virtual int getNextCommandId() ;
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*ActiveMQ_CorrelatorFilter_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ActiveMQ_CorrelatorFilter_hpp_
+#define ActiveMQ_CorrelatorFilter_hpp_
+
+#include <iostream>
+#include "activemq/BrokerException.hpp"
+#include "activemq/command/Response.hpp"
+#include "activemq/command/ExceptionResponse.hpp"
+#include "activemq/transport/TransportFilter.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+ namespace activemq
+ {
+ namespace transport
+ {
+ using namespace ifr;
+ using namespace apache::activemq;
+ using namespace apache::activemq::command;
+
+/*
+ * Interface for commands.
+ */
+class CorrelatorFilter : public TransportFilter
+{
+protected:
+ SimpleMutex mutex ;
+ map<int, p<FutureResponse> > requestMap ;
+ int nextCommandId ;
+
+public:
+ CorrelatorFilter(p<ITransport> next) ;
+ virtual ~CorrelatorFilter() {}
+
+ virtual void oneway(p<ICommand> command) ;
+ virtual p<FutureResponse> asyncRequest(p<ICommand> command) ;
+ virtual p<Response> request(p<ICommand> command) ;
+
+ virtual void onCommand(p<ITransport> transport, p<ICommand> command) ;
+
+protected:
+ virtual int getNextCommandId() ;
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*ActiveMQ_CorrelatorFilter_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/CorrelatorFilter.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.cpp Fri Jul 28 01:22:48 2006
@@ -1,80 +1,80 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "activemq/transport/FutureResponse.hpp"
-
-using namespace apache::activemq::transport;
-
-/*
- *
- */
-FutureResponse::FutureResponse()
-{
- complete = false ;
- response = NULL ;
- maxWait = 3 ;
- mutex = new SimpleMutex() ;
- semaphore = new Semaphore() ;
-}
-
-p<Response> FutureResponse::getResponse()
-{
- // Wait for response to arrive
- LOCKED_SCOPE (mutex);
- while ( response == NULL )
- {
- LOCKED_SCOPE_UNLOCK;
- semaphore->wait(maxWait); // BUG: Why have a max wait when what you do is just to wait again and again? //dafah
- LOCKED_SCOPE_RELOCK;
- }
- return response ;
-}
-
-void FutureResponse::setResponse(p<Response> response)
-{
- {
- LOCKED_SCOPE (mutex);
- this->response = response ;
- complete = true ;
- }
- // Signal that response has arrived
- semaphore->notify() ;
-}
-
-bool FutureResponse::isCompleted()
-{
- return complete ;
-}
-
-bool FutureResponse::getCompletedSynchronously()
-{
- return false ;
-}
-
-p<SimpleMutex> FutureResponse::getAsyncWaitHandle()
-{
- return mutex ;
-}
-
-p<Response> FutureResponse::getAsyncState()
-{
- return response ;
-}
-
-void FutureResponse::setAsyncState(p<Response> response)
-{
- setResponse( response ) ;
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "activemq/transport/FutureResponse.hpp"
+
+using namespace apache::activemq::transport;
+
+/*
+ *
+ */
+FutureResponse::FutureResponse()
+{
+ complete = false ;
+ response = NULL ;
+ maxWait = 3 ;
+ mutex = new SimpleMutex() ;
+ semaphore = new Semaphore() ;
+}
+
+p<Response> FutureResponse::getResponse()
+{
+ // Wait for response to arrive
+ LOCKED_SCOPE (mutex);
+ while ( response == NULL )
+ {
+ LOCKED_SCOPE_UNLOCK;
+ semaphore->wait(maxWait); // BUG: Why have a max wait when what you do is just to wait again and again? //dafah
+ LOCKED_SCOPE_RELOCK;
+ }
+ return response ;
+}
+
+void FutureResponse::setResponse(p<Response> response)
+{
+ {
+ LOCKED_SCOPE (mutex);
+ this->response = response ;
+ complete = true ;
+ }
+ // Signal that response has arrived
+ semaphore->notify() ;
+}
+
+bool FutureResponse::isCompleted()
+{
+ return complete ;
+}
+
+bool FutureResponse::getCompletedSynchronously()
+{
+ return false ;
+}
+
+p<SimpleMutex> FutureResponse::getAsyncWaitHandle()
+{
+ return mutex ;
+}
+
+p<Response> FutureResponse::getAsyncState()
+{
+ return response ;
+}
+
+void FutureResponse::setAsyncState(p<Response> response)
+{
+ setResponse( response ) ;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/activemq/transport/FutureResponse.hpp Fri Jul 28 01:22:48 2006
@@ -1,66 +1,66 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef ActiveMQ_FutureResponse_hpp_
-#define ActiveMQ_FutureResponse_hpp_
-
-#include <string>
-#include "activemq/command/Response.hpp"
-#include "ppr/thread/SimpleMutex.hpp"
-#include "ppr/thread/Semaphore.hpp"
-#include "ppr/util/ifr/p"
-
-namespace apache
-{
- namespace activemq
- {
- namespace transport
- {
- using namespace ifr;
- using namespace apache::activemq::command;
- using namespace apache::ppr::thread;
-
-/*
- * Interface for commands.
- */
-class FutureResponse
-{
-private:
- p<Response> response ;
- p<SimpleMutex> mutex ;
- p<Semaphore> semaphore ;
- int maxWait ;
- bool complete ;
-
-public:
- FutureResponse() ;
- virtual ~FutureResponse() {}
-
- virtual p<Response> getResponse() ;
- virtual void setResponse(p<Response> response) ;
- virtual p<Response> getAsyncState() ;
- virtual void setAsyncState(p<Response> response) ;
- virtual p<SimpleMutex> getAsyncWaitHandle() ; // BUG: Shouldn't we return the semaphore here? What is it needed for? SHouldn't we require to use getResponse() instead? //dafah
- virtual bool isCompleted() ;
- virtual bool getCompletedSynchronously() ;
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*ActiveMQ_FutureResponse_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ActiveMQ_FutureResponse_hpp_
+#define ActiveMQ_FutureResponse_hpp_
+
+#include <string>
+#include "activemq/command/Response.hpp"
+#include "ppr/thread/SimpleMutex.hpp"
+#include "ppr/thread/Semaphore.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+ namespace activemq
+ {
+ namespace transport
+ {
+ using namespace ifr;
+ using namespace apache::activemq::command;
+ using namespace apache::ppr::thread;
+
+/*
+ * Interface for commands.
+ */
+class FutureResponse
+{
+private:
+ p<Response> response ;
+ p<SimpleMutex> mutex ;
+ p<Semaphore> semaphore ;
+ int maxWait ;
+ bool complete ;
+
+public:
+ FutureResponse() ;
+ virtual ~FutureResponse() {}
+
+ virtual p<Response> getResponse() ;
+ virtual void setResponse(p<Response> response) ;
+ virtual p<Response> getAsyncState() ;
+ virtual void setAsyncState(p<Response> response) ;
+ virtual p<SimpleMutex> getAsyncWaitHandle() ; // BUG: Shouldn't we return the semaphore here? What is it needed for? SHouldn't we require to use getResponse() instead? //dafah
+ virtual bool isCompleted() ;
+ virtual bool getCompletedSynchronously() ;
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*ActiveMQ_FutureResponse_hpp_*/