You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/02/08 00:35:23 UTC
svn commit: r504738 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire:
OpenWireCommandReader.cpp OpenWireCommandReader.h
Author: tabish
Date: Wed Feb 7 15:35:21 2007
New Revision: 504738
URL: http://svn.apache.org/viewvc?view=rev&rev=504738
Log:
http://issues.apache.org/activemq/browse/AMQCPP-30
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.h
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.cpp?view=auto&rev=504738
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.cpp Wed Feb 7 15:35:21 2007
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "OpenwireCommandReader.h"
+
+#include <activemq/concurrent/Thread.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::concurrent;
+using namespace activemq::connector;
+using namespace activemq::connector::openwire;
+using namespace activemq::transport;
+using namespace activemq::io;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+OpenwireCommandReader::OpenwireCommandReader(void)
+{
+ this->inputStream = NULL;
+ this->openWireFormat = NULL;
+ this->dataInputStream = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OpenwireCommandReader::OpenwireCommandReader( InputStream* inputStream,
+ OpenWireFormat* openWireFormat )
+{
+ this->setInputStream( inputStream );
+ this->openWireFormat = openWireFormat;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Command* OpenwireCommandReader::readCommand(void)
+ throw ( CommandIOException )
+{
+ try
+ {
+ if( inputStream == NULL ||
+ dataInputStream == NULL ||
+ openWireFormat == NULL)
+ {
+ throw IOException(
+ __FILE__, __LINE__,
+ "OpenwireCommandReader::read(char*,int) - class not properly initialized" );
+ }
+
+ return openWireFormat->unmarshal( dataInputStream );
+ }
+ AMQ_CATCH_RETHROW( CommandIOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, CommandIOException )
+ AMQ_CATCHALL_THROW( CommandIOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+size_t OpenwireCommandReader::read( unsigned char* buffer, size_t count )
+ throw( io::IOException )
+{
+ try
+ {
+ if( inputStream == NULL )
+ {
+ throw IOException(
+ __FILE__, __LINE__,
+ "OpenwireCommandReader::read(char*,int) - input stream is NULL" );
+ }
+
+ return inputStream->read( &buffer[head], count );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char OpenwireCommandReader::readByte(void) throw( io::IOException )
+{
+ try
+ {
+ if( inputStream == NULL )
+ {
+ throw IOException(
+ __FILE__, __LINE__,
+ "OpenwireCommandReader::read(char*,int) - "
+ "input stream is NULL" );
+ }
+
+ unsigned char c = 0;
+ inputStream->read( &c, 1 );
+ return c;
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.h?view=auto&rev=504738
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/OpenWireCommandReader.h Wed Feb 7 15:35:21 2007
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_CONNECTOR_OPENWIRE_OPENWIRECOMMANDREADER_H_
+#define _ACTIVEMQ_CONNECTOR_OPENWIRE_OPENWIRECOMMANDREADER_H_
+
+#include <activemq/transport/CommandReader.h>
+#include <activemq/io/InputStream.h>
+#include <activemq/io/DataInputStream.h>
+#include <activemq/transport/CommandIOException.h>
+#include <activemq/transport/Command.h>
+#include <activemq/connector/openwire/OpenWireFormat.h>
+
+namespace activemq{
+namespace connector{
+namespace openwire{
+
+ class OpenwireCommandReader : public transport::CommandReader
+ {
+ private:
+
+ /**
+ * The target input stream.
+ */
+ io::InputStream* inputStream;
+
+ /**
+ * Pointer to the OpenWireFormat object for this Reader
+ */
+ OpenWireFormat* openWireFormat;
+
+ /**
+ * This is our DataInputStream that we will wrap around the target
+ * input stream
+ */
+ io::DataInputStream* dataInputStream;
+
+ public:
+
+ /**
+ * Constructor.
+ */
+ OpenwireCommandReader();
+
+ /**
+ * Constructor.
+ * @param inputStream the target input stream.
+ * @param owFormat the OpenWireFormat object that handles unmarshaling
+ */
+ OpenwireCommandReader( io::InputStream* inputStream,
+ OpenWireFormat* openWireFormat );
+
+ virtual ~OpenwireCommandReader() {}
+
+ /**
+ * Reads a command from the given input stream.
+ * @return The next command available on the stream.
+ * @throws CommandIOException if a problem occurs during the read.
+ */
+ virtual transport::Command* readCommand()
+ throw ( transport::CommandIOException );
+
+ /**
+ * Sets the target input stream.
+ * @param Target Input Stream
+ */
+ virtual void setInputStream( io::InputStream* inputStream ){
+ this->inputStream = inputStream;
+ delete dataInputStream;
+ dataInputStream = new io::DataInputStram( inputStream );
+ }
+
+ /**
+ * Gets the target input stream.
+ * @return Target Input Stream
+ */
+ virtual io::InputStream* getInputStream(void){
+ return inputStream;
+ }
+
+ /**
+ * Sets the target input stream.
+ * @param Target Input Stream
+ */
+ virtual void setOpenWireFormat( OpenWireFormat* openWireFormat ){
+ this->openWireFormat = openWireFormat;
+ }
+
+ /**
+ * Gets the target input stream.
+ * @return Target Input Stream
+ */
+ virtual io::InputStream* getOpenWireFormat(void){
+ return this->openWireFormat;
+ }
+
+ /**
+ * Attempts to read an array of bytes from the stream.
+ * @param buffer The target byte buffer.
+ * @param count The number of bytes to read.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual size_t read( unsigned char* buffer, size_t count )
+ throw( io::IOException );
+
+ /**
+ * Attempts to read a byte from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char readByte() throw( io::IOException );
+
+ };
+
+}}}
+
+#endif /*_ACTIVEMQ_CONNECTOR_OPENWIRE_OPENWIRECOMMANDREADER_H_*/