activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1005283 - in /activemq/activemq-cpp/trunk/activemq-c/src/main/c: CMS_Connection.cpp CMS_Connection.h CMS_Session.cpp CMS_Session.h cms.h
Date Wed, 06 Oct 2010 22:45:40 GMT
Author: tabish
Date: Wed Oct  6 22:45:40 2010
New Revision: 1005283

URL: http://svn.apache.org/viewvc?rev=1005283&view=rev
Log:
implements parts of the Connection and Session API wrapper.

Modified:
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.cpp
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.h
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.cpp
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.h
    activemq/activemq-cpp/trunk/activemq-c/src/main/c/cms.h

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.cpp?rev=1005283&r1=1005282&r2=1005283&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.cpp Wed Oct  6 22:45:40
2010
@@ -16,3 +16,97 @@
  */
 
 #include <CMS_Connection.h>
+
+#include <Config.h>
+#include <types/CMS_Types.h>
+
+#include <activemq/core/ActiveMQConnection.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <memory>
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status createDefaultConnection(CMS_ConnectionFactory* factory, CMS_Connection** connection)
{
+
+    cms_status result = CMS_SUCCESS;
+    std::auto_ptr<CMS_Connection> wrapper( new CMS_Connection );
+
+    try{
+
+        if (factory == NULL) {
+            result = CMS_ERROR;
+        } else {
+            wrapper->connection = factory->factory->createConnection();
+        }
+
+        *connection = wrapper.release();
+    } catch(...) {
+        result = CMS_ERROR;
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status createConnection(CMS_ConnectionFactory* factory,
+                            CMS_Connection** connection,
+                            const char* username,
+                            const char* password,
+                            const char* clientId) {
+
+    cms_status result = CMS_SUCCESS;
+    std::auto_ptr<CMS_Connection> wrapper( new CMS_Connection );
+
+    try{
+
+        if (factory == NULL) {
+            result = CMS_ERROR;
+        } else {
+            wrapper->connection = factory->factory->createConnection(username, password,
clientId);
+        }
+
+        *connection = wrapper.release();
+    } catch(...) {
+        result = CMS_ERROR;
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status destroyConnection(CMS_Connection* connection) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(connection != NULL) {
+
+        try{
+            delete connection->connection;
+            delete connection;
+        } catch(...) {
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status startConnection(CMS_Connection* connection) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(connection != NULL) {
+
+        try{
+            connection->connection->start();
+        } catch(...) {
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.h?rev=1005283&r1=1005282&r2=1005283&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.h (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Connection.h Wed Oct  6 22:45:40
2010
@@ -24,6 +24,62 @@
 extern "C" {
 #endif
 
+/**
+ * Creates a new Connection from the given ConnectionFactory instance using the defaults
+ * that are configured in the given Connection Factory.
+ *
+ * @param factory
+ *      The ConnectionFactory to use to create a new Connection.
+ * @param connection
+ *      The address of the location to store the new Connection instance.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status createDefaultConnection(CMS_ConnectionFactory* factory, CMS_Connection** connection);
+
+/**
+ * Creates a new Connection from the given ConnectionFactory instance.  The caller can specify
+ * the user name, password and client Id that will be used in the newly created Connection.
+ *
+ * @param factory
+ *      The ConnectionFactory to use to create a new Connection.
+ * @param connection
+ *      The address of the location to store the new Connection instance.
+ * @param username
+ *      The user name that will be sent to the Broker for Authentication (can be NULL).
+ * @param password
+ *      The password that will be sent to the Broker for Authentication (can be NULL).
+ * @param clientId
+ *      The clientId that will be assigned to the newly allocated Connection (can be NULL).
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status createConnection(CMS_ConnectionFactory* factory,
+                            CMS_Connection** connection,
+                            const char* username,
+                            const char* password,
+                            const char* clientId);
+
+/**
+ * Destroys the given Connection instance, all Connection Resources should have been
+ * deallocated at this point.
+ *
+ * @param connection
+ *      The Connection that is to be destroyed.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status destroyConnection(CMS_Connection* connection);
+
+/**
+ * Starts the Connection instance.  Until a Connection is started any Message Consumers
+ * created by Sessions linked to the Connection will not be able to receive Messages.
+ *
+ * @param connection
+ *      The Connection that is to be started.
+ */
+cms_status startConnection(CMS_Connection* connection);
+
 #ifdef __cplusplus
 }
 #endif

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.cpp?rev=1005283&r1=1005282&r2=1005283&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.cpp Wed Oct  6 22:45:40
2010
@@ -16,3 +16,112 @@
  */
 
 #include <CMS_Session.h>
+
+#include <Config.h>
+#include <types/CMS_Types.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <memory>
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status createDefaultSession(CMS_Connection* connection, CMS_Session** session) {
+
+    cms_status result = CMS_SUCCESS;
+    std::auto_ptr<CMS_Session> wrapper( new CMS_Session );
+
+    try{
+
+        if (connection == NULL) {
+            result = CMS_ERROR;
+        } else {
+            wrapper->session = connection->connection->createSession();
+        }
+
+        *session = wrapper.release();
+    } catch(...) {
+        result = CMS_ERROR;
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status createSession(CMS_Connection* connection, CMS_Session** session, ACKNOWLEDGMENT_MODE
ackMode) {
+
+    cms_status result = CMS_SUCCESS;
+    std::auto_ptr<CMS_Session> wrapper( new CMS_Session );
+
+    try{
+
+        if (connection == NULL) {
+            result = CMS_ERROR;
+        } else {
+
+            cms::Session::AcknowledgeMode cmsAckType = cms::Session::AUTO_ACKNOWLEDGE;
+
+            switch(ackMode) {
+                case AUTO_ACKNOWLEDGE:
+                    break;
+                case DUPS_OK_ACKNOWLEDGE:
+                    cmsAckType = cms::Session::DUPS_OK_ACKNOWLEDGE;
+                    break;
+                case CLIENT_ACKNOWLEDGE:
+                    cmsAckType = cms::Session::CLIENT_ACKNOWLEDGE;
+                    break;
+                case SESSION_TRANSACTED:
+                    cmsAckType = cms::Session::SESSION_TRANSACTED;
+                    break;
+                case INDIVIDUAL_ACKNOWLEDGE:
+                    cmsAckType = cms::Session::INDIVIDUAL_ACKNOWLEDGE;
+                    break;
+                default:
+                    return CMS_UNKNOWN_ACKTYPE;
+            }
+            wrapper->session = connection->connection->createSession(cmsAckType);
+        }
+
+        *session = wrapper.release();
+    } catch(...) {
+        result = CMS_ERROR;
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status destroySession(CMS_Session* session) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(session != NULL) {
+
+        try{
+            delete session->session;
+            delete session;
+        } catch(...) {
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms_status closeSession(CMS_Session* session) {
+
+    cms_status result = CMS_SUCCESS;
+
+    if(session != NULL) {
+
+        try{
+            session->session->close();
+        } catch(...) {
+            result = CMS_ERROR;
+        }
+    }
+
+    return result;
+}

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.h?rev=1005283&r1=1005282&r2=1005283&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.h (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/CMS_Session.h Wed Oct  6 22:45:40 2010
@@ -24,6 +24,55 @@
 extern "C" {
 #endif
 
+/**
+ * Given a Connection instance, create a new Session with the default Session
+ * ack mode of Auto-Acknowledge.
+ *
+ * @param connection
+ *      The Connection that is to be used to create the new Session.
+ * @param session
+ *      The memory location where the newly allocated Session instance is to be stored.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status createDefaultSession(CMS_Connection* connection, CMS_Session** session);
+
+/**
+ * Given a Connection instance, create a new Session with the specified Session
+ * ack mode.
+ *
+ * @param connection
+ *      The Connection that is to be used to create the new Session.
+ * @param session
+ *      The memory location where the newly allocated Session instance is to be stored.
+ * @param ackMode
+ *      The Acknowledgment Mode that is assigned the newly created Session.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status createSession(CMS_Connection* connection, CMS_Session** session, ACKNOWLEDGMENT_MODE
ackMode);
+
+/**
+ * Destroys the given Connection instance, all Connection Resources should have been
+ * deallocated at this point.
+ *
+ * @param session
+ *      The Session that is to be destroyed.
+ *
+ * @return result code indicating the success or failure of the operation.
+ */
+cms_status destroySession(CMS_Session* session);
+
+/**
+ * Closes the Session instance, all Session resources are also closed when the parent
+ * Session is closed.  Client's must still deallocate the Session resource that they
+ * created from this Session.
+ *
+ * @param session
+ *      The Session that is to be closed.
+ */
+cms_status closeSession(CMS_Session* session);
+
 #ifdef __cplusplus
 }
 #endif

Modified: activemq/activemq-cpp/trunk/activemq-c/src/main/c/cms.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-c/src/main/c/cms.h?rev=1005283&r1=1005282&r2=1005283&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-c/src/main/c/cms.h (original)
+++ activemq/activemq-cpp/trunk/activemq-c/src/main/c/cms.h Wed Oct  6 22:45:40 2010
@@ -54,7 +54,7 @@ typedef struct CMS_Destination CMS_Desti
  */
 
 /** Enum that defines the various message types supported by CMS. */
-typedef enum MESSAGE_TYPE {
+enum MESSAGE_TYPE {
     CMS_MESSAGE,
     CMS_BYTES_MESSAGE,
     CMS_MAP_MESSAGE,
@@ -63,13 +63,22 @@ typedef enum MESSAGE_TYPE {
 };
 
 /** Enum that defines the various destination types that are supported by CMS. */
-typedef enum DESTINATION_TYPE {
+enum DESTINATION_TYPE {
     CMS_TOPIC,
     CMS_QUEUE,
     CMS_TEMPORARY_TOPIC,
     CMS_TEMPORARY_QUEUE
 };
 
+/** Enum that defines the various Message Acknowledgment modes that are supported by CMS.
*/
+enum ACKNOWLEDGMENT_MODE {
+    AUTO_ACKNOWLEDGE,
+    DUPS_OK_ACKNOWLEDGE,
+    CLIENT_ACKNOWLEDGE,
+    SESSION_TRANSACTED,
+    INDIVIDUAL_ACKNOWLEDGE
+};
+
 /** Result code returned from wrapper functions to indicate success or failure. */
 typedef int cms_status;
 
@@ -78,8 +87,18 @@ typedef int cms_status;
  * Exception Types or the type of errors that some CMS API calls can encounter.
  */
 
-#define CMS_SUCCESS       0
-#define CMS_ERROR         1
+#define CMS_SUCCESS                 0
+#define CMS_ERROR                   1
+#define CMS_UNSUPPORTEDOP           2
+#define CMS_ILLEGAL_STATE           3
+#define CMS_SECURITY_ERROR          4
+#define CMS_INVALID_CLIENTID        5
+#define CMS_INVALID_DESTINATION     6
+#define CMS_INVALID_SELECTOR        7
+#define CMS_MESSAGE_EOF             8
+#define CMS_MESSAGE_NOT_READABLE    9
+#define CMS_MESSAGE_NOT_WRITABLE    10
+#define CMS_UNKNOWN_ACKTYPE         11
 
 /**
  * C Functions used to initialize and shutdown the ActiveMQ-C library.



Mime
View raw message