Author: tabish
Date: Thu Oct 7 15:40:45 2010
New Revision: 1005498
URL: http://svn.apache.org/viewvc?rev=1005498&view=rev
Log:
Basic implementation of the Message Producer Wrapper.
Modified:
activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.cpp
activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.h
Modified:
activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.cpp?rev=1005498&r1=1005497&r2=1005498&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.cpp
Thu Oct 7 15:40:45 2010
@@ -17,3 +17,92 @@
#include <CMS_MessageProducer.h>
+#include <Config.h>
+#include <types/CMS_Types.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <memory>
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status createProducer(CMS_Session* session, CMS_Destination* destination,
CMS_MessageProducer** producer) {
+
+ cms_status result = CMS_SUCCESS;
+ std::auto_ptr<CMS_MessageProducer> wrapper( new CMS_MessageProducer );
+
+ try{
+
+ if (session == NULL) {
+ result = CMS_ERROR;
+ } else {
+ if( destination != NULL && destination->destination != NULL ) {
+ wrapper->producer =
session->session->createProducer(destination->destination);
+ } else {
+ wrapper->producer = session->session->createProducer(NULL);
+ }
+ }
+
+ *producer = wrapper.release();
+ } catch(...) {
+ result = CMS_ERROR;
+ }
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status producerDefaultSend(CMS_MessageProducer* producer, CMS_Message*
message) {
+
+ cms_status result = CMS_SUCCESS;
+
+ try{
+
+ if (producer == NULL || message == NULL) {
+ result = CMS_ERROR;
+ } else {
+ producer->producer->send(message->message);
+ }
+
+ } catch(...) {
+ result = CMS_ERROR;
+ }
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status closeProducer(CMS_MessageProducer* producer) {
+
+ cms_status result = CMS_SUCCESS;
+
+ if(producer != NULL) {
+
+ try{
+ producer->producer->close();
+ } catch(...) {
+ result = CMS_ERROR;
+ }
+ }
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status destroyProducer(CMS_MessageProducer* producer) {
+
+ cms_status result = CMS_SUCCESS;
+
+ if(producer != NULL) {
+
+ try{
+ delete producer->producer;
+ delete producer;
+ } catch(...) {
+ result = CMS_ERROR;
+ }
+ }
+
+ return result;
+}
Modified:
activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.h?rev=1005498&r1=1005497&r2=1005498&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_MessageProducer.h Thu
Oct 7 15:40:45 2010
@@ -24,6 +24,52 @@
extern "C" {
#endif
+/**
+ * Given a Session instance, create a new Producer with the default settings.
+ *
+ * @param session
+ * The Session that is to be used to create the new Producer.
+ * @param destination
+ * The Destination that this Producer will publish to.
+ * @param producer
+ * The memory location where the newly allocated Producer instance is to
be stored.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status createProducer(CMS_Session* session, CMS_Destination* destination,
CMS_MessageProducer** producer);
+
+/**
+ * Given a Message Producer, send the given Message using that Producer.
+ *
+ * @param producer
+ * The Message Producer to use for this send operation.
+ * @param message
+ * The Message to send via the given Message Producer.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status producerDefaultSend(CMS_MessageProducer* producer, CMS_Message*
message);
+
+/**
+ * Closes the MessageProducer.
+ *
+ * @param producer
+ * The Producer that is to be closed.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status closeProducer(CMS_MessageProducer* producer);
+
+/**
+ * Destroys the given Producer instance.
+ *
+ * @param producer
+ * The Producer that is to be destroyed.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status destroyProducer(CMS_MessageProducer* producer);
+
#ifdef __cplusplus
}
#endif