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 2009/05/04 17:49:51 UTC

svn commit: r771337 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: Makefile.am activemq/wireformat/stomp/StompFrame.cpp activemq/wireformat/stomp/StompFrame.h activemq/wireformat/stomp/StompWireFormat.cpp

Author: tabish
Date: Mon May  4 15:49:51 2009
New Revision: 771337

URL: http://svn.apache.org/viewvc?rev=771337&view=rev
Log:
Somewhat functional Stomp WireFormat.  Client Ack doesn't seem to work, auto ack works fine.  Transactions are untested.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=771337&r1=771336&r2=771337&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Mon May  4 15:49:51 2009
@@ -308,6 +308,7 @@
     activemq/wireformat/stomp/StompCommandConstants.cpp \
     activemq/wireformat/stomp/marshal/Marshaler.cpp \
     activemq/wireformat/stomp/marshal/MarshalerHelper.cpp \
+    activemq/wireformat/stomp/StompFrame.cpp \
     activemq/wireformat/stomp/StompWireFormatFactory.cpp \
     activemq/wireformat/stomp/StompWireFormat.cpp \
     activemq/wireformat/WireFormatRegistry.cpp \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp?rev=771337&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp Mon May  4 15:49:51 2009
@@ -0,0 +1,104 @@
+/*
+ * 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 "StompFrame.h"
+
+#include <string>
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <activemq/wireformat/stomp/StompCommandConstants.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::wireformat;
+using namespace activemq::wireformat::stomp;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+StompFrame* StompFrame::clone() const {
+    StompFrame* frame = new StompFrame();
+    frame->copy( this );
+    return frame;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StompFrame::copy( const StompFrame* src ) {
+
+    this->setCommand( src->getCommand() );
+    this->properties.copy( &( src->getProperties() ) );
+    // Use the Vectors assignment operator.
+    this->body = src->getBody();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StompFrame::setBody( const unsigned char* bytes, std::size_t numBytes ) {
+
+    // Remove old data
+    body.clear();
+
+    // Copy data to internal buffer.
+    std::back_insert_iterator< std::vector<unsigned char> > iter( body );
+    std::copy( bytes, bytes + numBytes, iter );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StompFrame::toStream( decaf::io::OutputStream* stream ) const {
+
+    if( stream == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Stream Passed is Null" );
+    }
+
+    // Write the command.
+    const string& cmdString = this->getCommand();
+    stream->write( (unsigned char*)cmdString.c_str(), 0, cmdString.length() );
+    stream->write( '\n' );
+
+    // Write all the headers.
+    vector< pair<string,string> > headers = this->getProperties().toArray();
+    for( std::size_t ix=0; ix < headers.size(); ++ix ) {
+        string& name = headers[ix].first;
+        string& value = headers[ix].second;
+
+        stream->write( (unsigned char*)name.c_str(), 0, name.length() );
+        stream->write( ':' );
+        stream->write( (unsigned char*)value.c_str(), 0, value.length() );
+        stream->write( '\n' );
+    }
+
+    // Finish the header section with a form feed.
+    stream->write( '\n' );
+
+    // Write the body.
+    const std::vector<unsigned char>& body = this->getBody();
+    if( body.size() > 0 ) {
+        stream->write( &body[0], 0, body.size() );
+    }
+
+    if( ( this->getBodyLength() == 0 ) ||
+        ( this->getProperty( StompCommandConstants::HEADER_CONTENTLENGTH ) != "" ) ) {
+
+        stream->write( '\0' );
+    }
+
+    stream->write( '\n' );
+
+    // Flush the stream.
+    stream->flush();
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h?rev=771337&r1=771336&r2=771337&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompFrame.h Mon May  4 15:49:51 2009
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <map>
 #include <decaf/util/Properties.h>
+#include <decaf/io/OutputStream.h>
 #include <activemq/util/Config.h>
 
 namespace activemq{
@@ -61,23 +62,13 @@
          * caller is required to delete.
          * @return new copy of this message
          */
-        virtual StompFrame* clone() const {
-            StompFrame* frame = new StompFrame();
-            frame->copy( this );
-            return frame;
-        }
+        StompFrame* clone() const;
 
         /**
          * Copies the contents of the passed Frame to this one
          * @param src - Frame to copy
          */
-        virtual void copy( const StompFrame* src ) {
-
-            this->setCommand( src->getCommand() );
-            this->properties.copy( &( src->getProperties() ) );
-            // Use the Vectors assignment operator.
-            this->body = src->getBody();
-        }
+        void copy( const StompFrame* src );
 
         /**
          * Sets the command for this stomp frame.
@@ -171,15 +162,14 @@
          * @param bytes The byte buffer to be set in the body.
          * @param numBytes The number of bytes in the buffer.
          */
-        void setBody( const unsigned char* bytes, std::size_t numBytes ){
-
-            // Remove old data
-            body.clear();
+        void setBody( const unsigned char* bytes, std::size_t numBytes );
 
-            // Copy data to internal buffer.
-            std::back_insert_iterator< std::vector<unsigned char> > iter( body );
-            std::copy( bytes, bytes + numBytes, iter );
-        }
+        /**
+         * Writes this Frame to an OuputStream in the Stomp Frame Format.
+         *
+         * @param stream - The stream to write the Frame to.
+         */
+        void toStream( decaf::io::OutputStream* stream ) const;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp?rev=771337&r1=771336&r2=771337&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/stomp/StompWireFormat.cpp Mon May  4 15:49:51 2009
@@ -77,42 +77,8 @@
             return;
         }
 
-        // Write the command.
-        const string& cmdString = frame->getCommand();
-        out->write( (unsigned char*)cmdString.c_str(), 0, cmdString.length() );
-        out->writeByte( '\n' );
-
-        // Write all the headers.
-        vector< pair<string,string> > headers = frame->getProperties().toArray();
-        for( std::size_t ix=0; ix < headers.size(); ++ix ) {
-            string& name = headers[ix].first;
-            string& value = headers[ix].second;
-
-            out->write( (unsigned char*)name.c_str(), 0, name.length() );
-            out->writeByte( ':' );
-            out->write( (unsigned char*)value.c_str(), 0, value.length() );
-            out->writeByte( '\n' );
-        }
-
-        // Finish the header section with a form feed.
-        out->writeByte( '\n' );
-
-        // Write the body.
-        const std::vector<unsigned char>& body = frame->getBody();
-        if( body.size() > 0 ) {
-            out->write( &body[0], 0, body.size() );
-        }
-
-        if( ( frame->getBodyLength() == 0 ) ||
-            ( frame->getProperty( StompCommandConstants::HEADER_CONTENTLENGTH ) != "" ) ) {
-
-            out->writeByte( '\0' );
-        }
-
-        out->writeByte( '\n' );
-
-        // Flush the stream.
-        out->flush();
+        // Let the Frame write itself to the output stream
+        frame->toStream( out );
     }
     AMQ_CATCH_RETHROW( decaf::io::IOException )
     AMQ_CATCH_EXCEPTION_CONVERT( decaf::lang::Exception, decaf::io::IOException )