activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r397654 [9/12] - in /incubator/activemq/trunk/openwire-cpp: ./ src/ src/command/ src/gram/ src/gram/java/ src/gram/java/org/ src/gram/java/org/apache/ src/gram/java/org/apache/activemq/ src/gram/java/org/apache/activemq/openwire/ src/gram/j...
Date Thu, 27 Apr 2006 21:59:44 GMT
Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITextMessage.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITextMessage.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITextMessage.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITextMessage.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,42 @@
+/*
+ * 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 Cms_ITextMessage_hpp_
+#define Cms_ITextMessage_hpp_
+
+#include <string>
+#include "cms/IMessage.hpp"
+
+namespace apache
+{
+  namespace cms
+  {
+    using namespace std;
+
+/*
+ * Represents a text based message.
+ */
+struct ITextMessage : IMessage
+{
+    virtual p<string> getText() = 0 ;
+    virtual void setText(const char* txt) = 0 ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_ITextMessage_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITopic.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITopic.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITopic.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/ITopic.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,43 @@
+/*
+ * 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 Cms_ITopic_hpp_
+#define Cms_ITopic_hpp_
+
+#include <string>
+#include "cms/IDestination.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace cms
+  {
+    using namespace ifr;
+    using namespace std;
+
+/*
+ * 
+ */
+struct ITopic : IDestination
+{
+    virtual p<string> getTopicName() = 0 ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_ITopic_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageEOFException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageEOFException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageEOFException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageEOFException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,44 @@
+/*
+ * 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 Cms_MessageEOFException_hpp_
+#define Cms_MessageEOFException_hpp_
+
+#include "cms/CmsException.hpp"
+
+namespace apache
+{
+  namespace cms
+  {
+
+/*
+ * Signals that an unexpected end of stream has been reached when reading
+ * a message.
+ */
+class MessageEOFException : public CmsException
+{
+public:
+    MessageEOFException() : CmsException()
+       { /* no-op */ } ;
+    MessageEOFException(const char *msg) : CmsException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_MessageEOFException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageFormatException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageFormatException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageFormatException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageFormatException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,44 @@
+/*
+ * 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 Cms_MessageFormatException_hpp_
+#define Cms_MessageFormatException_hpp_
+
+#include "cms/CmsException.hpp"
+
+namespace apache
+{
+  namespace cms
+  {
+
+/*
+ * Signals that a client attempts to use a data type not supported by a
+ * message or attempts to read data in a message as the wrong type.
+ */
+class MessageFormatException : public CmsException
+{
+public:
+    MessageFormatException() : CmsException()
+       { /* no-op */ } ;
+    MessageFormatException(const char *msg) : CmsException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_MessageFormatException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotReadableException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotReadableException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotReadableException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotReadableException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,43 @@
+/*
+ * 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 Cms_MessageNotReadableException_hpp_
+#define Cms_MessageNotReadableException_hpp_
+
+#include "cms/CmsException.hpp"
+
+namespace apache
+{
+  namespace cms
+  {
+
+/*
+ * Signals that a message is in read-only mode.
+ */
+class MessageNotReadableException : public CmsException
+{
+public:
+    MessageNotReadableException() : CmsException()
+       { /* no-op */ } ;
+    MessageNotReadableException(const char *msg) : CmsException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_MessageNotReadableException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotWritableException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotWritableException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotWritableException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/cms/MessageNotWritableException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,43 @@
+/*
+ * 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 Cms_MessageNotWritableException_hpp_
+#define Cms_MessageNotWritableException_hpp_
+
+#include "cms/CmsException.hpp"
+
+namespace apache
+{
+  namespace cms
+  {
+
+/*
+ * Signals that a message is in read-only mode.
+ */
+class MessageNotWritableException : public CmsException
+{
+public:
+    MessageNotWritableException() : CmsException()
+       { /* no-op */ } ;
+    MessageNotWritableException(const char *msg) : CmsException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Cms_MessageNotWritableException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/ConversionException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/ConversionException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/ConversionException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/ConversionException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,45 @@
+/*
+ * 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 Ppr_ConversionException_hpp_
+#define Ppr_ConversionException_hpp_
+
+#include "ppr/TraceException.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+
+/*
+ * Signals that an illegal data conversion has occurred.
+ */
+class ConversionException : public TraceException
+{
+public:
+    ConversionException() : TraceException()
+       { /* no-op */ } ;
+    ConversionException(const char *const& msg) : TraceException(msg)
+       { /* no-op */ } ;
+    ConversionException(const char* fileName, int lineNo, const char* msg) : TraceException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Ppr_ConversionException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/IllegalArgumentException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/IllegalArgumentException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/IllegalArgumentException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/IllegalArgumentException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,45 @@
+/*
+ * 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 Ppr_IllegalArgumentException_hpp_
+#define Ppr_IllegalArgumentException_hpp_
+
+#include "ppr/TraceException.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+
+/*
+ * Signals that a method has been passed an illegal or inappropriate argument.
+ */
+class IllegalArgumentException : public TraceException
+{
+public:
+    IllegalArgumentException() : TraceException()
+       { /* no-op */ } ;
+    IllegalArgumentException(const char *const& msg) : TraceException(msg)
+       { /* no-op */ } ;
+    IllegalArgumentException(const char* fileName, int lineNo, const char* msg) : TraceException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Ppr_IllegalArgumentException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/InvalidOperationException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/InvalidOperationException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/InvalidOperationException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/InvalidOperationException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,45 @@
+/*
+ * 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 Ppr_InvalidOperationException_hpp_
+#define Ppr_InvalidOperationException_hpp_
+
+#include "ppr/TraceException.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+
+/*
+ * Signals that an invalid operation has been attempted.
+ */
+class InvalidOperationException : public TraceException
+{
+public:
+    InvalidOperationException() : TraceException()
+       { /* no-op */ } ;
+    InvalidOperationException(const char *const& msg) : TraceException(msg)
+       { /* no-op */ } ;
+    InvalidOperationException(const char* fileName, int lineNo, const char* msg) : TraceException(msg)
+       { /* no-op */ } ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Ppr_IllegalArgumentException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,72 @@
+/*
+ * 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 "ppr/TraceException.hpp"
+
+using namespace apache::ppr;
+
+/*
+ * 
+ */
+TraceException::TraceException()
+   : exception()
+{
+    // no-op
+} ;
+
+/*
+ * 
+ */
+TraceException::TraceException(const char* msg, ...)
+{
+    va_list vargs ;
+
+    va_start(vargs, msg) ;
+    buildMessage(msg, vargs) ;
+}
+
+void TraceException::buildMessage(const char* format, va_list& vargs)
+{
+    // Allocate buffer with a guess of it's size
+    array<char> buffer (128);
+
+    // Format string
+    for (;;) {
+        int size = vsnprintf(buffer.c_array(), buffer.size(), format, vargs);
+        if (size > -1 && size < (int) buffer.size()) {
+            // Guessed size was enough. Assign the string.
+            message.assign (buffer.c_array(), size);
+            break;
+        }
+        // Guessed size was not enough.
+        if (size > -1) {
+            // Reallocate a new buffer that will fit.
+            buffer = array<char> (size + 1);
+        } else {
+            // Implementation of vsnprintf() did not return a valid required size.
+            // Reallocate a new buffer. Double the guess of size.
+            buffer = array<char> (buffer.size() * 2);
+        }
+    }
+}
+
+const char* TraceException::what() const throw()
+{
+    if( message.empty() )
+        return exception::what() ;
+    else
+        return message.c_str() ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/TraceException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,56 @@
+/*
+ * 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 Ppr_TraceException_hpp_
+#define Ppr_TraceException_hpp_
+
+#include <exception>
+#include <string>
+#include <stdarg.h>
+#include <stdio.h>
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    using namespace std;
+    using namespace ifr;
+
+/*
+ * Base class for all exceptions containing trace information.
+ */
+class TraceException : public exception
+{
+    string message ;
+
+public:
+    TraceException() ;
+    TraceException(const char* msg, ...) ;
+    virtual ~TraceException() throw () {}
+
+    virtual const char* what() const throw() ;
+
+protected:
+    virtual void buildMessage(const char* format, va_list& vargs) ;
+} ;
+
+/* namespace */
+  }
+}
+
+#endif /*Ppr_TraceException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,77 @@
+/* 
+ * 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 "ppr/io/ByteArrayInputStream.hpp"
+
+using namespace apache::ppr::io;
+
+/*
+ *
+ */
+ByteArrayInputStream::ByteArrayInputStream(array<char> buffer)
+{
+    this->body     = (buffer != NULL) ? buffer : NULL ;
+    this->bodySize = (buffer != NULL) ? (int)body.size() : 0 ;
+    this->offset   = 0 ;
+}
+
+/*
+ *
+ */
+ByteArrayInputStream::~ByteArrayInputStream()
+{
+    // no-op
+}
+
+void ByteArrayInputStream::close() throw(IOException)
+{
+    // no-op
+}
+
+/*
+ *
+ */
+array<char> ByteArrayInputStream::toArray()
+{
+    array<char> retBody ;
+
+    // Create return body and copy current contents
+    retBody = array<char> (bodySize) ;
+    memcpy(retBody.c_array(), body.c_array(), bodySize) ;
+
+    return retBody ;
+}
+
+/*
+ *
+ */
+int ByteArrayInputStream::read(char* buf, int index, int length) throw(IOException)
+{
+    // Check for EOF offset
+    if( offset > bodySize )
+        throw EOFException() ;
+
+    // Copy bytes from supplied buffer
+    for( int i = index ; i < length ; i++, offset++ )
+    {
+        // Check for body EOF
+        if( offset > bodySize )
+            return length - i ;
+
+        buf[i] = body[offset] ;
+    }
+    return length ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayInputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,59 @@
+/* 
+ * 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 Ppr_ByteArrayInputStream_hpp_
+#define Ppr_ByteArrayInputStream_hpp_
+
+#include "ppr/io/DataInputStream.hpp"
+#include "ppr/io/EOFException.hpp"
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace ifr;
+
+/*
+ * ByteArrayInputStream reads primitive C++ data types from an
+ * in-memory byte array.
+ */
+class ByteArrayInputStream : public DataInputStream
+{
+private:
+    array<char> body ;
+    int         bodySize,
+                offset ;
+
+public:
+    ByteArrayInputStream(array<char> buffer) ;
+    ~ByteArrayInputStream() ;
+
+    virtual array<char> toArray() ;
+
+    virtual void close() throw(IOException) ;
+    virtual int read(char* buffer, int index, int count) throw(IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ByteArrayInputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,122 @@
+/* 
+ * 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 "ppr/io/ByteArrayOutputStream.hpp"
+
+using namespace apache::ppr::io;
+
+/*
+ *
+ */
+ByteArrayOutputStream::ByteArrayOutputStream()
+{
+    this->body       = array<char> (INITIAL_SIZE) ;
+    this->bodySize   = INITIAL_SIZE ;
+    this->bodyLength = 0 ;
+    this->offset     = 0 ;
+}
+
+/*
+ *
+ */
+ByteArrayOutputStream::ByteArrayOutputStream(array<char> buffer)
+{
+    this->body       = (buffer != NULL ) ? buffer : array<char> (INITIAL_SIZE) ;
+    this->bodySize   = (int)body.size() ;
+    this->bodyLength = 0 ;
+    this->offset     = 0 ;
+}
+
+/*
+ *
+ */
+ByteArrayOutputStream::~ByteArrayOutputStream()
+{
+    // no-op
+}
+
+/*
+ *
+ */
+array<char> ByteArrayOutputStream::toArray()
+{
+    // Return NULL if no array content
+    if( bodyLength == 0 ) 
+        return NULL ;
+
+    // Create return body and copy current contents
+    array<char> retBody = array<char> (bodyLength) ;
+    memcpy(retBody.c_array(), body.c_array(), bodyLength) ;
+
+    return retBody ;
+}
+
+/*
+ *
+ */
+void ByteArrayOutputStream::close() throw(IOException)
+{
+    // no-op
+}
+
+/*
+ *
+ */
+void ByteArrayOutputStream::flush() throw(IOException)
+{
+    // no-op
+}
+
+/*
+ *
+ */
+int ByteArrayOutputStream::write(const char* buf, int index, int length) throw(IOException)
+{
+    // Assert buffer parameter
+    if( buf == NULL )
+        return 0 ;
+
+    // Copy bytes from supplied buffer
+    for( int i = index ; i < length ; i++, offset++ )
+    {
+        // Check for EOF offset
+        if( offset > bodySize )
+            expandBody() ;
+
+        body[offset] = buf[i] ;
+    }
+    // Update content length
+    bodyLength = offset ;
+
+    return length ;
+}
+
+/*
+ *
+ */
+void ByteArrayOutputStream::expandBody()
+{
+    array<char> newBody ;
+    int         newSize = bodySize + ByteArrayOutputStream::EXPAND_SIZE ;
+
+    // Create new body and copy current contents
+    newBody = array<char> (newSize) ;
+    memcpy(newBody.c_array(), body.c_array(), bodySize) ;
+
+    // Clean up and use new content body
+    body     = newBody ;
+    bodySize = newSize ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/ByteArrayOutputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,67 @@
+/* 
+ * 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 Ppr_ByteArrayOutputStream_hpp_
+#define Ppr_ByteArrayOutputStream_hpp_
+
+#include "ppr/io/DataOutputStream.hpp"
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace ifr;
+
+/*
+ * ByteArrayOutputStream writes primitive C++ data types to a
+ * in memory byte array.
+ */
+class ByteArrayOutputStream : public DataOutputStream
+{
+private:
+    array<char> body ;
+    int         bodySize,
+                bodyLength,
+                offset ;
+
+    const static int INITIAL_SIZE = 256 ;
+    const static int EXPAND_SIZE  = 128 ;
+
+public:
+    ByteArrayOutputStream() ;
+    ByteArrayOutputStream(array<char> buffer) ;
+    virtual ~ByteArrayOutputStream() ;
+
+    virtual array<char> toArray() ;
+
+    virtual void close() throw(IOException) ;
+    virtual void flush() throw(IOException) ;
+    virtual int write(const char* buffer, int index, int length) throw(IOException) ;
+
+protected:
+    virtual void expandBody() ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ByteArrayOutputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,146 @@
+/* 
+ * 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 "ppr/io/DataInputStream.hpp"
+
+using namespace apache::ppr::io;
+
+/*
+ *
+ */
+DataInputStream::DataInputStream()
+{
+    // no-op
+}
+
+/*
+ *
+ */
+DataInputStream::~DataInputStream()
+{
+    // no-op
+}
+
+/*
+ *
+ */
+char DataInputStream::readByte() throw(IOException)
+{
+    char value ;
+
+    // Read a single byte
+    read(&value, 0, sizeof(char)) ;
+    return value ;
+}
+
+/*
+ *
+ */
+bool DataInputStream::readBoolean() throw(IOException)
+{
+    // Read a boolean
+    return ( readByte() ) ? true : false ;
+}
+
+/*
+ *
+ */
+double DataInputStream::readDouble() throw(IOException)
+{
+    double value ;
+
+    // Read a double and convert from big endian to little endian if necessary
+    read((char*)&value, 0, sizeof(double) ) ;
+    return ntohd(value) ;
+}
+
+/*
+ *
+ */
+float DataInputStream::readFloat() throw(IOException)
+{
+    float value ;
+
+    // Read a float and convert from big endian to little endian if necessary
+    read((char*)&value, 0, sizeof(float)) ;
+    return ntohf(value) ;
+}
+
+/*
+ *
+ */
+short DataInputStream::readShort() throw(IOException)
+{
+    short value ;
+
+    // Read a short and convert from big endian to little endian if necessary
+    read((char*)&value, 0, sizeof(short)) ;
+    return ntohs(value) ;
+}
+
+/*
+ *
+ */
+int DataInputStream::readInt() throw(IOException)
+{
+    int value ;
+
+    // Read an int and convert from big endian to little endian if necessary
+    read((char*)&value, 0, sizeof(int)) ;
+    return ntohi(value) ;
+}
+
+/*
+ *
+ */
+long long DataInputStream::readLong() throw(IOException)
+{
+    long long value ;
+
+    // Read a long long and convert from big endian to little endian if necessary
+    read((char*)&value, 0, sizeof(long long)) ;
+    return ntohll(value) ;
+}
+
+/*
+ *
+ */
+p<string> DataInputStream::readString() throw(IOException)
+{
+    p<string> value ;
+    char*     buffer ;
+    short     length ;
+
+    // Read length of string
+    length = readShort() ;
+    if (length < 0) {
+        throw IOException ("Negative length of string");
+    } else if (length > 0) {
+        buffer = new char[length+1] ;
+
+        // Read string bytes
+        read(buffer, 0, length) ;
+        *(buffer+length) = '\0' ;
+
+        // Create string class
+        value = new string() ;
+        value->assign(buffer) ;
+
+        return value ;
+    } else {
+        return new string ("");
+    }
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataInputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,67 @@
+/* 
+ * 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 Ppr_DataInputStream_hpp_
+#define Ppr_DataInputStream_hpp_
+
+#include "ppr/io/IInputStream.hpp"
+#include "ppr/util/Endian.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace apache::ppr::util; //htonx and ntohx functions.
+      using namespace ifr;
+
+/*
+ * The DataInputStream class reads primitive C++ data types from an
+ * underlying input stream in a Java compatible way. Strings are
+ * read as raw bytes, no character decoding is performed.
+ *
+ * All numeric data types are assumed to be available in big
+ * endian (network byte order) and are converted automatically
+ * to little endian if needed by the platform.
+ *
+ * Should any error occur an IOException will be thrown.
+ */
+class DataInputStream : public IInputStream
+{
+public:
+    DataInputStream() ;
+    virtual ~DataInputStream() ;
+
+    virtual void close() throw(IOException) = 0 ;
+    virtual int read(char* buffer, int index, int count) throw(IOException) = 0 ;
+    virtual char readByte() throw(IOException) ;
+    virtual bool readBoolean() throw(IOException) ;
+    virtual double readDouble() throw(IOException) ;
+    virtual float readFloat() throw(IOException) ;
+    virtual short readShort() throw(IOException) ;
+    virtual int readInt() throw(IOException) ;
+    virtual long long readLong() throw(IOException) ;
+    virtual p<string> readString() throw(IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_DataInputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,82 @@
+/* 
+ * 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 "ppr/io/DataOutputStream.hpp"
+
+using namespace apache::ppr::io;
+
+void DataOutputStream::writeByte(char value) throw(IOException)
+{
+    // Write a single byte
+    write((char*)&value, 0, sizeof(char)) ;
+}
+
+void DataOutputStream::writeBoolean(bool value) throw(IOException)
+{
+    // Write a boolean
+    ( value ) ? writeByte(0x01) : writeByte(0x00) ;
+}
+
+void DataOutputStream::writeDouble(double v) throw(IOException)
+{
+    // Write a double, convert from little endian to big endian if necessary
+    double value = htond(v) ;
+    write((char*)&value, 0, sizeof(double)) ;
+}
+
+void DataOutputStream::writeFloat(float v) throw(IOException)
+{
+    // Write a float, convert from little endian to big endian if necessary
+    float value = htonf(v) ;
+    write((char*)&value, 0, sizeof(float)) ;
+}
+
+void DataOutputStream::writeShort(short v) throw(IOException)
+{
+    // Write a short, convert from little endian to big endian if necessary
+    short value = htons(v) ;
+    write((char*)&value, 0, sizeof(short)) ;
+}
+
+void DataOutputStream::writeInt(int v) throw(IOException)
+{
+    // Write an int, convert from little endian to big endian if necessary
+    int value = htoni(v) ;
+    write((char*)&value, 0, sizeof(int)) ;
+}
+
+void DataOutputStream::writeLong(long long v) throw(IOException)
+{
+    // Write a long long, convert from little endian to big endian if necessary
+    long long value = htonll(v) ;
+    write((char*)&value, 0, sizeof(long long)) ;
+}
+
+void DataOutputStream::writeString(p<string> value) throw(IOException)
+{
+    // Assert argument
+    if( value == NULL )
+        return ;
+    if( value->length() > USHRT_MAX )
+        throw IOException("String length exceeds maximum length") ;
+
+    // Write length of string
+    short length = (short)value->length() ;
+    writeShort( length ) ;
+
+    // Write string contents
+    write((char*)value->c_str(), 0, length) ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/DataOutputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,65 @@
+/* 
+ * 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 Ppr_DataOutputStream_hpp_
+#define Ppr_DataOutputStream_hpp_
+
+#include "ppr/io/IOutputStream.hpp"
+#include "ppr/util/Endian.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace apache::ppr::util; // htonx and ntohx functions.
+      using namespace ifr;
+
+/*
+ * The DataOutputStream class writes primitive C++ data types to an
+ * underlying output stream in a Java compatible way. Strings
+ * are written as raw bytes, no character encoding is performed.
+ *
+ * All numeric data types are written in big endian (network byte
+ * order) and if the platform is little endian they are converted
+ * automatically.
+ *
+ * Should any error occur an IOException will be thrown.
+ */
+class DataOutputStream : public IOutputStream
+{
+public:
+    virtual void close() throw(IOException) = 0 ;
+    virtual void flush() throw(IOException) = 0 ;
+    virtual int write(const char* buffer, int index, int count) throw(IOException) = 0 ;
+    virtual void writeByte(char v) throw(IOException) ;
+    virtual void writeBoolean(bool v) throw(IOException) ;
+    virtual void writeDouble(double v) throw(IOException) ;
+    virtual void writeFloat(float v) throw(IOException) ;
+    virtual void writeShort(short v) throw(IOException) ;
+    virtual void writeInt(int v) throw(IOException) ;
+    virtual void writeLong(long long v) throw(IOException) ;
+    virtual void writeString(p<string> v) throw(IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_DataOutputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/EOFException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/EOFException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/EOFException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/EOFException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,53 @@
+/*
+ * 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 Ppr_EOFException_hpp_
+#define Ppr_EOFException_hpp_
+
+#include "ppr/io/IOException.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace apache::ppr;
+      using namespace std ;
+
+/*
+ * Signals that end-of-file has been reached.
+ */
+class EOFException : public IOException
+{
+public:
+    EOFException() : IOException()
+    { /* no-op */ } ;
+    EOFException(const char* msg, ...)
+    {
+        va_list vargs ;
+
+        va_start(vargs, msg) ;
+        TraceException::buildMessage(msg, vargs) ;
+    }
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_EOFException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IInputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IInputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IInputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IInputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,63 @@
+/*
+ * 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 Ppr_IInputStream_hpp_
+#define Ppr_IInputStream_hpp_
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
+
+#include <string>
+#include "ppr/io/IOException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace std;
+      using namespace ifr;
+
+/*
+ * The IInputStream interface provides for reading bytes from a binary stream
+ * and reconstructing from them data in any of the C++ primitive types.
+ * Strings are read as raw bytes, no character decoding is performed. If
+ * any byte cannot be read for any reason, an IOException is thrown.
+ */
+struct IInputStream : Interface
+{
+    virtual void close() throw(IOException) = 0 ;
+    virtual int read(char* buffer, int index, int count) throw(IOException) = 0 ;
+    virtual char readByte() throw(IOException) = 0 ;
+    virtual bool readBoolean() throw(IOException) = 0 ;
+    virtual double readDouble() throw(IOException) = 0 ;
+    virtual float readFloat() throw(IOException) = 0 ;
+    virtual short readShort() throw(IOException) = 0 ;
+    virtual int readInt() throw(IOException) = 0 ;
+    virtual long long readLong() throw(IOException) = 0 ;
+    virtual p<string> readString() throw(IOException) = 0 ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_IInputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOException.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOException.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOException.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOException.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,53 @@
+/*
+ * 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 Ppr_IOException_hpp_
+#define Ppr_IOException_hpp_
+
+#include "ppr/TraceException.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace apache::ppr;
+      using namespace std ;
+
+/*
+ * Signals that an I/O exception of some sort has occurred.
+ */
+class IOException : public TraceException
+{
+public:
+    IOException() : TraceException()
+    { /* no-op */ } ;
+    IOException(const char* msg, ...)
+    {
+        va_list vargs ;
+
+        va_start(vargs, msg) ;
+        TraceException::buildMessage(msg, vargs) ;
+    }
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_IOException_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOutputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOutputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOutputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/IOutputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,65 @@
+/*
+ * 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 Ppr_IOutputStream_hpp_
+#define Ppr_IOutputStream_hpp_
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
+
+#include <string>
+#include "ppr/io/IOException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace std;
+      using namespace ifr;
+
+/*
+ * The IOutputStream interface provides for converting data from any of the
+ * C++ primitive types to a series of bytes and writing these bytes to
+ * a binary stream. Strings are written as raw bytes, no character
+ * encoding is performed. If a byte cannot be written for any reason,
+ * an IOException is thrown. 
+ */
+struct IOutputStream : Interface
+{
+    virtual void close() throw(IOException) = 0 ;
+    virtual void flush() throw(IOException) = 0 ;
+    virtual int write(const char* buffer, int index, int count) throw(IOException) = 0 ;
+    virtual void writeByte(char v) throw(IOException) = 0 ;
+    virtual void writeBoolean(bool v) throw(IOException) = 0 ;
+    virtual void writeDouble(double v) throw(IOException) = 0 ;
+    virtual void writeFloat(float v) throw(IOException) = 0 ;
+    virtual void writeShort(short v) throw(IOException) = 0 ;
+    virtual void writeInt(int v) throw(IOException) = 0 ;
+    virtual void writeLong(long long v) throw(IOException) = 0 ;
+    virtual void writeString(p<string> v) throw(IOException) = 0 ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_IOutputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,56 @@
+/* 
+ * 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 "ppr/io/SocketInputStream.hpp"
+
+using namespace apache::ppr::io;
+
+void SocketInputStream::close() throw(IOException)
+{
+    // no-op
+}
+
+/*
+ *
+ */
+int SocketInputStream::read(char* buf, int index, int size) throw(IOException)
+{
+    char* buffer = buf + index ;
+    int   length, remaining = size ;
+
+    // Loop until requested number of bytes are read
+    while( remaining > 0 )
+    {
+        // Try to read remaining bytes
+        length = remaining ;
+
+        try
+        {
+            // Read some bytes from socket
+            length = socket->receive(buffer, length) ;
+        }
+        catch( SocketException se )
+        {
+            // Exit on any error
+            throw IOException("Failed to read from socket; error message = %s, at %s line %d", se.what(), __FILE__, __LINE__) ;
+        }
+
+        // Adjust buffer pointer and remaining number of bytes
+        buffer    += length ;
+        remaining -= length ;
+	}
+	return size ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketInputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,56 @@
+/* 
+ * 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 Ppr_SocketInputStream_hpp_
+#define Ppr_SocketInputStream_hpp_
+
+#include "ppr/io/DataInputStream.hpp"
+#include "ppr/net/ISocket.hpp"
+#include "ppr/net/SocketException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace ifr ;
+      using namespace apache::ppr::net ;
+      using namespace apache::ppr::util ;
+
+/*
+ * SocketInputStream reads primitive C++ data types from a
+ * socket stream. It currently uses PPR sockets for
+ * platform independency.
+ */
+class SocketInputStream : public DataInputStream
+{
+private:
+    p<ISocket> socket ;
+public:
+    SocketInputStream(p<ISocket> socket) : socket (socket) {}
+public:
+    virtual void close() throw(IOException) ;
+    virtual int read(char* buffer, int index, int size) throw(IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_SocketInputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,77 @@
+/* 
+ * 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 "ppr/io/SocketOutputStream.hpp"
+
+using namespace apache::ppr::io;
+
+/*
+ *
+ */
+SocketOutputStream::SocketOutputStream(p<ISocket> socket)
+{
+    this->socket = socket ;
+}
+
+/*
+ *
+ */
+SocketOutputStream::~SocketOutputStream()
+{
+    // no-op
+}
+
+void SocketOutputStream::close() throw(IOException)
+{
+    // no-op
+}
+
+void SocketOutputStream::flush() throw(IOException)
+{
+    // no-op
+}
+
+/*
+ *
+ */
+int SocketOutputStream::write(const char* buf, int index, int size) throw(IOException)
+{
+    const char*  buffer = buf + index ;
+    int          length, remaining = size ;
+
+    // Loop until requested number of bytes are read
+    while( remaining > 0 )
+    {
+        // Try to write remaining bytes
+        length = remaining ;
+
+        try
+        {
+            // Write some bytes to socket
+            length = socket->send(buffer, length) ;
+        }
+        catch( SocketException se )
+        {
+            // Exit on any error
+            throw IOException("Failed to write to socket; error message = %s, at %s line %d", se.what(), __FILE__, __LINE__) ;
+        }
+
+        // Adjust buffer pointer and remaining number of bytes
+        buffer    += length ;
+        remaining -= length ;
+	}
+	return size ;
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/io/SocketOutputStream.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,59 @@
+/* 
+ * 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 Ppr_SocketOutputStream_hpp_
+#define Ppr_SocketOutputStream_hpp_
+
+#include "ppr/io/DataOutputStream.hpp"
+#include "ppr/net/ISocket.hpp"
+#include "ppr/net/SocketException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace io
+    {
+      using namespace ifr ;
+      using namespace apache::ppr::net ;
+      using namespace apache::ppr::util ;
+
+/*
+ * SocketOutputStream writes primitive C++ data types to a
+ * socket stream. It currently uses PPR sockets for
+ * platform independency.
+ */
+class SocketOutputStream : public DataOutputStream
+{
+private:
+    p<ISocket> socket ;
+
+public:
+    SocketOutputStream(p<ISocket> socket) ;
+    virtual ~SocketOutputStream() ;
+
+    virtual void close() throw(IOException) ;
+    virtual void flush() throw(IOException) ;
+    virtual int write(const char* buffer, int index, int size) throw(IOException) ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_SocketOutputStream_hpp_*/

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocket.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocket.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocket.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocket.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,69 @@
+/*
+ * 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 Ppr_IServerSocket_hpp_
+#define Ppr_IServerSocket_hpp_
+
+#include "ppr/net/ISocket.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace ifr;
+
+/*
+ *
+ */
+struct IServerSocket : Interface
+{
+    /** Bind and listen to given IP/dns and port.
+        @param host IP address or host name.
+        @param port TCP port between 1..655535
+    */
+    virtual void bind(const char* host, int port) throw (SocketException) = 0 ;
+
+    /** Bind and listen to given IP/dns and port.
+        @param host IP address or host name.
+        @param port TCP port between 1..655535
+        @param backlog Size of listen backlog.
+    */
+    virtual void bind(const char* host, int port, int backlog) throw (SocketException) = 0 ;
+
+    /** Blocks until a client connects to the bound socket.
+        @return new socket. Never returns NULL.
+    */
+    virtual p<ISocket> accept() throw (SocketException) = 0 ;
+
+    /** Closes the server socket.
+    */
+    virtual void close() = 0 ;
+
+    /** @return true of the server socket is bound.
+    */ 
+    virtual bool isBound() const = 0 ;
+};
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_IServerSocket_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocketFactory.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocketFactory.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocketFactory.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/IServerSocketFactory.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,46 @@
+/*
+ * 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 Ppr_IServerSocketFactory_hpp_
+#define Ppr_IServerSocketFactory_hpp_
+
+#include "ppr/net/IServerSocket.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace ifr;
+
+/*
+ *
+ */
+struct IServerSocketFactory : Interface
+{
+    // Creates an unbound server socket, ready to call bind() on.
+    virtual p<IServerSocket> createServerSocket() = 0 ;
+};
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_IServerSocketFactory_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocket.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,68 @@
+/*
+ * 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 Ppr_ISocket_hpp_
+#define Ppr_ISocket_hpp_
+
+#include "ppr/net/SocketException.hpp"
+#include "ppr/util/ifr/p"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace ifr;
+
+/*
+ *
+ */
+struct ISocket : Interface
+{
+    /**
+    */
+    virtual void connect(const char* host, int port) throw (SocketException) = 0 ;
+    /**
+    */
+    virtual void setSoTimeout(int millisecs) throw (SocketException) = 0;
+    /**
+    */
+    virtual int  getSoTimeout() const = 0;
+    /**
+    */
+    virtual int  receive(char* buff, int size) throw (SocketException) = 0;
+    /**
+    */
+    virtual int  send(const unsigned char* buff, int size) throw (SocketException) = 0;
+    /**
+    */
+    virtual int  send(const char* buff, int size) throw (SocketException) = 0;
+    /**
+    */
+    virtual void close() = 0;
+    /**
+    */
+    virtual bool isConnected() const = 0;
+};
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ISocket_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ISocketFactory.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,46 @@
+/*
+ * 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 Ppr_ISocketFactory_hpp_
+#define Ppr_ISocketFactory_hpp_
+
+#include "ISocket.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace ifr;
+
+/*
+ *
+ */
+struct ISocketFactory : Interface
+{
+    /** Creates an unconnected socket ready to call connect() on.
+    */
+    virtual p<ISocket> createSocket() = 0 ;
+} ;
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ISocketFactory_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,158 @@
+/*
+ * 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.
+ */
+
+#ifdef unix
+#include <unistd.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#else
+#include <Winsock2.h>
+#include <Ws2tcpip.h> 
+#include <sys/stat.h>
+#define stat _stat
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "ppr/net/ServerSocket.hpp"
+
+using namespace apache::ppr::net;
+
+inline int SOCKETclose( Socket::SocketHandle sock )
+{
+#ifdef unix
+	return ::close(sock);
+#else
+	return ::closesocket(sock);
+#endif
+}
+
+ServerSocket::ServerSocket() : socketHandle (Socket::INVALID_SOCKET_HANDLE)
+{
+#ifndef unix
+    if( Socket::staticSocketInitializer.getSocketInitError() != NULL )
+        throw *Socket::staticSocketInitializer.getSocketInitError();
+#endif
+}
+
+ServerSocket::~ServerSocket()
+{
+    if( isBound() )
+    {
+        // No shutdown, just close - dont want blocking destructor.
+        SOCKETclose (socketHandle);
+    }
+}
+
+void ServerSocket::bind (const char* host, int port) throw (SocketException)
+{
+    bind(host, port, SOMAXCONN);
+}
+
+void ServerSocket::bind (const char* host, int port, int backlog) throw (SocketException)
+{
+    SocketHandle listen_socket_handle;
+	int          ret ;
+
+    if( isBound() )
+        throw SocketException ("Socket already bound") ;
+
+	listen_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0) ;
+
+    if( listen_socket_handle < 0 )
+        throw SocketException ("Could not create socket");
+
+    if( port <= 0 || port > 65535 )
+        throw SocketException ("Port out of range");
+
+    sockaddr_in bind_addr;
+	bind_addr.sin_family = AF_INET;
+	bind_addr.sin_port = htons((short)port);
+	bind_addr.sin_addr.s_addr = 0; // To be set later down...
+    memset(&bind_addr.sin_zero, 0, sizeof(bind_addr.sin_zero));
+
+    // Resolve name
+    ::addrinfo hints;
+    memset(&hints, 0, sizeof(addrinfo));
+    hints.ai_family = PF_INET;
+    struct addrinfo *res_ptr = NULL;
+
+    if( ::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL )
+        throw SocketException ("Could not resolve name");
+    else
+    {
+        assert(res_ptr->ai_addr->sa_family == AF_INET);
+        // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
+        assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
+        bind_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
+        freeaddrinfo(res_ptr);
+    }
+
+	ret = ::bind(listen_socket_handle,
+				 (sockaddr *)&bind_addr, sizeof(bind_addr));
+
+	if( ret < 0 )
+    {
+        SOCKETclose (listen_socket_handle);
+		throw SocketException ("Could not bind");
+	}
+    ret = ::listen(listen_socket_handle, backlog);
+    if( ret < 0 )
+    {
+        SOCKETclose (listen_socket_handle);
+        throw SocketException ("Could not listen");
+    }
+    socketHandle = listen_socket_handle;
+}
+
+void ServerSocket::close ()
+{
+    if( isBound() )
+    {
+        SOCKETclose (this->socketHandle);
+        this->socketHandle = Socket::INVALID_SOCKET_HANDLE;
+    }
+}
+
+bool ServerSocket::isBound() const
+{
+    return this->socketHandle != Socket::INVALID_SOCKET_HANDLE;
+}
+
+p<ISocket> ServerSocket::accept () throw (SocketException)
+{
+    struct sockaddr_in temp;
+#ifdef unix
+    socklen_t temp_len = sizeof (sockaddr_in);
+#else
+    int temp_len = sizeof (sockaddr_in);
+#endif
+    SocketHandle ss_socket_handle = Socket::INVALID_SOCKET_HANDLE;
+
+    ss_socket_handle = ::accept(this->socketHandle, (struct sockaddr*)&temp, &temp_len);
+    if (ss_socket_handle < 0) {
+        throw SocketException ("Accept Error");
+    }
+    return new Socket (ss_socket_handle);
+}

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocket.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,84 @@
+/*
+ * 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 Ppr_ServerSocket_hpp_
+#define Ppr_ServerSocket_hpp_
+
+#include "ppr/net/IServerSocket.hpp"
+#include "ppr/net/Socket.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace ifr;
+
+/*
+ *
+ */
+class ServerSocket : public IServerSocket
+{
+public:
+    typedef Socket::SocketHandle SocketHandle;
+private:
+    SocketHandle socketHandle;
+public:
+    /** Constructor.
+        Creates a non-bound server socket.
+    */
+    ServerSocket();
+
+    /** Destructor.
+        Releases socket handle if close() hasn't been called.
+    */
+    virtual ~ServerSocket();
+public:
+    /** Bind and listen to given IP/dns and port.
+        @param host IP address or host name.
+        @param port TCP port between 1..655535
+    */
+    virtual void bind (const char* host, int port) throw (SocketException);
+
+    /** Bind and listen to given IP/dns and port.
+        @param host IP address or host name.
+        @param port TCP port between 1..655535
+        @param backlog Size of listen backlog.
+    */
+    virtual void bind (const char* host, int port, int backlog) throw (SocketException);
+
+    /** Blocks until a client connects to the bound socket.
+        @return new socket. Never returns NULL.
+    */
+    virtual p<ISocket> accept () throw (SocketException);
+
+    /** Closes the server socket.
+    */
+    virtual void close();
+
+    /** @return true of the server socket is bound.
+    */ 
+    virtual bool isBound() const;
+};
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ServerSocket_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/ServerSocketFactory.hpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,50 @@
+/*
+ * 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 Ppr_ServerSocketFactory_hpp_
+#define Ppr_ServerSocketFactory_hpp_
+
+#include "ppr/net/IServerSocketFactory.hpp"
+#include "ppr/net/ServerSocket.hpp"
+
+namespace apache
+{
+  namespace ppr
+  {
+    namespace net
+    {
+      using namespace std;
+
+/*
+ *
+ */
+class ServerSocketFactory : public IServerSocketFactory
+{
+public:
+    /** Creates an unbound TCP/IP server socket, ready to call bind() on.
+    */
+    virtual p<IServerSocket> createSocket() {
+        return new ServerSocket();
+    }
+};
+
+/* namespace */
+    }
+  }
+}
+
+#endif /*Ppr_ServerSocketFactory_hpp_*/
+

Added: incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp?rev=397654&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/main/cpp/ppr/net/Socket.cpp Thu Apr 27 14:59:28 2006
@@ -0,0 +1,293 @@
+/*
+ * 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.
+ */
+
+#ifdef unix
+#include <unistd.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#else
+#include <Winsock2.h>
+#include <Ws2tcpip.h> 
+#include <sys/stat.h>
+#define stat _stat
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "ppr/net/Socket.hpp"
+
+using namespace apache::ppr::net;
+
+inline int
+SOCKETclose( Socket::SocketHandle sock )
+{
+#ifdef unix
+	return ::close(sock);
+#else
+	return ::closesocket(sock);
+#endif
+}
+
+#ifndef unix // Static socket initializer needed for winsock
+Socket::StaticSocketInitializer::StaticSocketInitializer () {
+    const WORD version_needed = MAKEWORD(2,2); // lo-order byte: major version
+    WSAData temp;
+    if (WSAStartup(version_needed, &temp)){
+        socketInitError = new SocketException ("winsock.dll was not found");
+    }
+}
+Socket::StaticSocketInitializer::~StaticSocketInitializer () {
+    WSACleanup();
+}
+
+Socket::StaticSocketInitializer apache::ppr::net::Socket::staticSocketInitializer;
+#endif
+
+Socket::Socket() : socketHandle (INVALID_SOCKET_HANDLE)
+{
+#ifndef unix
+    if (staticSocketInitializer.getSocketInitError() != NULL) {
+        throw *staticSocketInitializer.getSocketInitError();
+    }
+#endif
+}
+
+Socket::Socket(Socket::SocketHandle socketHandle) : socketHandle (socketHandle)
+{
+}
+
+Socket::~Socket()
+{
+    if (isConnected()) {
+        // No shutdown, just close - dont want blocking destructor.
+        SOCKETclose (socketHandle);
+    }
+}
+
+void
+Socket::connect (const char* host, int port) throw (SocketException)
+{
+	int ret;
+    SocketHandle cs_socket_handle;
+    if (isConnected()) {
+        throw SocketException ("Socket already connected");
+    }
+	cs_socket_handle = ::socket(AF_INET, SOCK_STREAM, 0);
+	if (cs_socket_handle < 0) {
+        throw SocketException ("Could not create socket");
+	}
+    if (port <= 0 || port > 65535) {
+        throw SocketException ("Port out of range");
+    }
+    sockaddr_in target_addr;
+	target_addr.sin_family = AF_INET;
+	target_addr.sin_port = htons((short)port);
+	target_addr.sin_addr.s_addr = 0; // To be set later down...
+    memset(&target_addr.sin_zero, 0, sizeof(target_addr.sin_zero));
+
+    // Resolve name
+    ::addrinfo hints;
+    memset(&hints, 0, sizeof(addrinfo));
+    hints.ai_family = PF_INET;
+    struct addrinfo *res_ptr = NULL;
+    if (::getaddrinfo(host, NULL, &hints, &res_ptr) != 0 || res_ptr == NULL) {
+        throw SocketException ("Could not resolve name");
+    } else {
+        assert(res_ptr->ai_addr->sa_family == AF_INET);
+        // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr is a 32 bit value, not an unsigned long.
+        assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
+        target_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
+        freeaddrinfo(res_ptr);
+    }
+
+    ret = ::connect(cs_socket_handle, (const sockaddr *) &target_addr, sizeof(target_addr));
+	if (ret < 0) {
+        SOCKETclose (cs_socket_handle);
+		throw SocketException ("Could not connect to host");
+	}
+    socketHandle = cs_socket_handle;
+}
+
+void
+Socket::setSoTimeout (int millisecs) throw (SocketException)
+{
+#ifdef unix
+  timeval timot;
+  timot.tv_sec = millisecs / 1000;
+  timot.tv_usec = (millisecs % 1000) * 1000;
+#else
+  int timot = millisecs;
+#endif
+  ::setsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (const char*) &timot, sizeof (timot));
+  ::setsockopt (socketHandle, SOL_SOCKET, SO_SNDTIMEO, (const char*) &timot, sizeof (timot));
+}
+
+int
+Socket::getSoTimeout () const
+{
+#ifdef unix
+  timeval timot;
+  timot.tv_sec = 0;
+  timot.tv_usec = 0;
+  socklen_t size = sizeof(timot);
+#else
+  int timot = 0;
+  int size = sizeof(timot);
+#endif
+  
+  ::getsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char*) &timot, &size);
+#ifdef unix
+  return (timot.tv_sec * 1000) + (timot.tv_usec / 1000);
+#else
+  return timot;
+#endif
+}
+#include "ppr/util/Hex.hpp"
+
+int Socket::receive (char* buff, int size) throw (SocketException)
+{
+    if (!isConnected()) {
+        throw SocketException ("Socket not connected");
+    }
+#ifdef unix
+	int rc = ::read(this->socketHandle, buff, size);
+    if (rc < 0) {
+        throw SocketException ("Socket::receieve() failed - socket may have been disconnected") ;
+    }
+#else
+	int rc = ::recv(this->socketHandle, buff, size, 0);
+    if (rc < 0) {
+        char errmsg[256];
+        sprintf (errmsg, "Socket::receive() failed. WSAGetLastError() returned %d", WSAGetLastError());
+        throw SocketException (errmsg);
+    }
+    //printf ("----receive---[%s]\n", apache::ppr::util::Hex::toString (array<char> (buff, rc))->c_str());
+#endif
+    return rc;
+}
+
+int
+Socket::send (const char* buff, int size) throw (SocketException)
+{
+    if (!isConnected()) {
+        throw SocketException ("Socket not connected");
+    }
+#ifdef unix
+	int rc = ::write(this->socketHandle, buff, size);
+    if (rc < 0) {
+        throw SocketException ("Socket::send() failed - socket may have been disconnected");
+    }
+#else
+	int rc = ::send(this->socketHandle, buff, size, 0);
+    if (rc < 0) {
+        char errmsg[256];
+        sprintf (errmsg, "Socket::send() failed. WSAGetLastError() returned %d", WSAGetLastError());
+        throw SocketException (errmsg);
+    }
+#endif
+    //printf ("SOCKETSEND[%s]\n", Hex::toString (array<char> (buff, rc))->c_str());
+    return rc;
+}
+
+int
+Socket::send (const unsigned char* buff, int size) throw (SocketException)
+{
+    return send (reinterpret_cast<const char*> (buff), size);
+}
+
+
+void
+Socket::close ()
+{
+    if (isConnected()) {
+        ::shutdown(this->socketHandle, 2);
+        SOCKETclose (this->socketHandle);
+        this->socketHandle = INVALID_SOCKET_HANDLE;
+    }
+}
+
+bool
+Socket::isConnected() const {
+    return this->socketHandle != INVALID_SOCKET_HANDLE;
+}
+
+
+//
+// Unit test
+//
+#ifdef UNITTEST
+
+#include "ppr/util/ifr/array"
+#include <iostream>
+#include <cassert>
+#include "Thread.hpp"
+#include "ServerSocket.hpp"
+
+class TestServer : public Thread
+{
+public:
+    TestServer () {}
+protected:
+    virtual void run () throw (p<exception>) 
+    {
+        p<ServerSocket> serverSocket = new ServerSocket();
+        serverSocket->bind ("127.0.0.1", 19000);
+        cout << "Server bind successful" << endl;
+        p<ISocket> client = serverSocket->accept();
+        cout << "Server has accepted a connection" << endl;
+        array<char> buff (13);
+        int count = client->receive (buff.c_array(), (int)buff.size());
+        cout << "Server has received " << count << " bytes from client" << endl;
+        assert (count == 13);
+        assert (strcmp (buff.c_array(), "Hello Socket") == 0);
+        cout << "Message was as expected" << endl;
+        cout << "Server sending Good Bye to client and closing connection" << endl;
+        client->send ("Good Bye", 9);
+        client->close();
+    }
+};
+
+void testSocket()
+{
+    p<TestServer> server = new TestServer();
+    cout << "Starting up test server" << endl;
+    server->start ();
+    Socket s;
+    cout << "Trying to connect to server" << endl;
+    s.connect ("127.0.0.1", 19000);
+    cout << "Client sending message to server" << endl;
+    s.send ("Hello Socket", 13);
+    cout << "Client has sent message now" << endl;
+    array<char> buff (9);
+    int count = s.receive (buff.c_array(), (int) buff.size());
+    cout << "Client got a response from server of " << count << " bytes." << endl;
+    assert (count == 9);
+    assert (strcmp (buff.c_array(), "Good Bye") == 0);
+    cout << "Client has verified the server's message" << endl;
+    cout << "Client closes the connection" << endl;
+    s.close();
+}
+
+#endif // UNITTEST
+



Mime
View raw message