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 2011/01/05 16:53:18 UTC

svn commit: r1055493 - in /activemq/activemq-cpp/trunk/activemq-c/src/main/c: CMS_TextMessage.cpp CMS_TextMessage.h Makefile.am

Author: tabish
Date: Wed Jan  5 15:53:18 2011
New Revision: 1055493

URL: http://svn.apache.org/viewvc?rev=1055493&view=rev
Log:
Adds in the API for getting and setting the TextMessage body.

Added:
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/Makefile.am

Added: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp?rev=1055493&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp Wed Jan  5 15:53:18 2011
@@ -0,0 +1,110 @@
+/*
+ * 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 <CMS_Message.h>
+#include <CMS_TextMessage.h>
+
+#include <Config.h>
+#include <types/CMS_Types.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <memory>
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status getMessageText(CMS_Message* message, char* dest, int size) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(message != NULL && dest != NULL) {
+
+        if( size <= 0 ) {
+            return CMS_ERROR;
+        }
+
+        if( message->type != CMS_TEXT_MESSAGE ) {
+            return CMS_INVALID_MESSAGE_TYPE;
+        }
+
+        try{
+
+            cms::TextMessage* txtMessage = dynamic_cast<cms::TextMessage*>( message->message );
+
+            std::string msgText = txtMessage->getText();
+
+            if(!msgText.empty()) {
+
+                std::size_t pos = 0;
+                for(; pos < msgText.size() && pos < (std::size_t)size - 1; ++pos) {
+                    dest[pos] = msgText.at(pos);
+                }
+
+                dest[pos] = '\0';
+            } else {
+                dest[0] = '\0';
+            }
+
+        } catch(cms::MessageFormatException& ex) {
+            dest[0] = '\0';
+            result = CMS_MESSAGE_FORMAT_ERROR;
+        } catch(...) {
+            dest[0] = '\0';
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status setMessageText(CMS_Message* message, const char* value) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(message != NULL && value != NULL) {
+
+        if( message->type != CMS_TEXT_MESSAGE ) {
+            return CMS_INVALID_MESSAGE_TYPE;
+        }
+
+        try{
+
+            cms::TextMessage* txtMessage = dynamic_cast<cms::TextMessage*>( message->message );
+
+            if(strlen(value) > 0) {
+                txtMessage->setText(value);
+            } else {
+                txtMessage->setText("");
+            }
+
+        } catch(cms::MessageNotWriteableException& ex) {
+            result = CMS_MESSAGE_NOT_WRITABLE;
+        } catch(...) {
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h?rev=1055493&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h (added)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h Wed Jan  5 15:53:18 2011
@@ -0,0 +1,58 @@
+/*
+ * 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 <cms.h>
+
+#ifndef _CMS_TEXTMESSAGE_WRAPPER_H_
+#define _CMS_TEXTMESSAGE_WRAPPER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Gets the string value contained in a TextMessage body.
+ *
+ * @param message
+ *      The message that the text is retreived from.
+ * @param dest
+ *      The address to store the value of the message text.
+ * @param size
+ *      The size of the character array that is provided to receive the string payload.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status getMessageText(CMS_Message* message, char* dest, int size);
+
+/**
+ * Sets a value of the String body of the given Text Message.  If the given message is
+ * not a cms::TextMessage than an error code is returned.
+ *
+ * @param message
+ *      The message that the property is to be set in.
+ * @param value
+ *      The value to store in the given message body.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status setMessageText(CMS_Message* message, const char* value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CMS_TEXTMESSAGE_WRAPPER_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_TextMessage.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/Makefile.am?rev=1055493&r1=1055492&r2=1055493&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/Makefile.am Wed Jan  5 15:53:18 2011
@@ -23,6 +23,7 @@ cc_sources = \
     CMS_MessageConsumer.cpp \
     CMS_MessageProducer.cpp \
     CMS_Session.cpp \
+    CMS_TextMessage.cpp \
     cms.cpp
 
 
@@ -34,6 +35,7 @@ h_sources = \
     CMS_MessageConsumer.h \
     CMS_MessageProducer.h \
     CMS_Session.h \
+    CMS_TextMessage.h \
     Config.h \
     cms.h \
     types/CMS_Types.h