A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Revision:
5:ae49385aff34
Parent:
4:98007eb79fa8
Child:
6:641a9672db08
--- a/connection.c	Tue Jun 07 10:49:20 2016 -0700
+++ b/connection.c	Fri Jul 01 10:42:48 2016 -0700
@@ -12,7 +12,6 @@
 #include "azure_c_shared_utility/tickcounter.h"
 
 #include "azure_uamqp_c/connection.h"
-#include "azure_uamqp_c/consolelogger.h"
 #include "azure_uamqp_c/frame_codec.h"
 #include "azure_uamqp_c/amqp_frame_codec.h"
 #include "azure_uamqp_c/amqp_definitions.h"
@@ -62,7 +61,6 @@
     ON_NEW_ENDPOINT on_new_endpoint;
     void* on_new_endpoint_callback_context;
 
-    LOGGER_LOG logger;
     ON_CONNECTION_STATE_CHANGED on_connection_state_changed;
     void* on_connection_state_changed_callback_context;
     ON_IO_ERROR on_io_error;
@@ -125,7 +123,7 @@
     {
         if (connection_instance->is_trace_on == 1)
         {
-            LOG(connection_instance->logger, LOG_LINE, "-> Header (AMQP 0.1.0.0)");
+            LOG(LOG_TRACE, LOG_LINE, "-> Header (AMQP 0.1.0.0)");
         }
 
         /* Codes_SRS_CONNECTION_01_041: [HDR SENT In this state the connection header has been sent to the peer but no connection header has been received.] */
@@ -184,15 +182,15 @@
     return result;
 }
 
-static void log_incoming_frame(LOGGER_LOG log, AMQP_VALUE performative)
+static void log_incoming_frame(AMQP_VALUE performative)
 {
     AMQP_VALUE descriptor = amqpvalue_get_inplace_descriptor(performative);
     if (descriptor != NULL)
     {
-        LOG(log, 0, "<- ");
-        LOG(log, 0, (char*)get_frame_type_as_string(descriptor));
+        LOG(LOG_TRACE, 0, "<- ");
+        LOG(LOG_TRACE, 0, (char*)get_frame_type_as_string(descriptor));
         char* performative_as_string = NULL;
-        LOG(log, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative)));
+        LOG(LOG_TRACE, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative)));
         if (performative_as_string != NULL)
         {
             amqpalloc_free(performative_as_string);
@@ -200,15 +198,15 @@
     }
 }
 
-static void log_outgoing_frame(LOGGER_LOG log, AMQP_VALUE performative)
+static void log_outgoing_frame(AMQP_VALUE performative)
 {
     AMQP_VALUE descriptor = amqpvalue_get_inplace_descriptor(performative);
     if (descriptor != NULL)
     {
-        LOG(log, 0, "-> ");
-        LOG(log, 0, (char*)get_frame_type_as_string(descriptor));
+        LOG(LOG_TRACE, 0, "-> ");
+        LOG(LOG_TRACE, 0, (char*)get_frame_type_as_string(descriptor));
         char* performative_as_string = NULL;
-        LOG(log, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative)));
+        LOG(LOG_TRACE, LOG_LINE, (performative_as_string = amqpvalue_to_string(performative)));
         if (performative_as_string != NULL)
         {
             amqpalloc_free(performative_as_string);
@@ -317,7 +315,7 @@
                     {
                         if (connection_instance->is_trace_on == 1)
                         {
-                            log_outgoing_frame(connection_instance->logger, open_performative_value);
+                            log_outgoing_frame(open_performative_value);
                         }
 
                         /* Codes_SRS_CONNECTION_01_046: [OPEN SENT In this state the connection headers have been exchanged. An open frame has been sent to the peer but no open frame has yet been received.] */
@@ -376,8 +374,9 @@
                 {
                     if (connection_instance->is_trace_on == 1)
                     {
-                        log_outgoing_frame(connection_instance->logger, close_performative_value);
+                        log_outgoing_frame(close_performative_value);
                     }
+
                     result = 0;
                 }
 
@@ -501,7 +500,7 @@
             {
                 if (connection_instance->is_trace_on == 1)
                 {
-                    LOG(connection_instance->logger, LOG_LINE, "<- Header (AMQP 0.1.0.0)");
+                    LOG(LOG_TRACE, LOG_LINE, "<- Header (AMQP 0.1.0.0)");
                 }
 
                 connection_set_state(connection_instance, CONNECTION_STATE_HDR_EXCH);
@@ -627,7 +626,7 @@
 static void on_empty_amqp_frame_received(void* context, uint16_t channel)
 {
     CONNECTION_INSTANCE* connection_instance = (CONNECTION_INSTANCE*)context;
-    LOG(connection_instance->logger, LOG_LINE, "<- Empty frame");
+    LOG(LOG_TRACE, LOG_LINE, "<- Empty frame");
     if (tickcounter_get_current_ms(connection_instance->tick_counter, &connection_instance->last_frame_received_time) != 0)
     {
         /* error */
@@ -661,7 +660,7 @@
 
                     if (connection_instance->is_trace_on == 1)
                     {
-                        log_incoming_frame(connection_instance->logger, performative);
+                        log_incoming_frame(performative);
                     }
 
                     if (is_open_type_by_descriptor(descriptor))
@@ -781,7 +780,7 @@
                         switch (performative_ulong)
                         {
                         default:
-                            LOG(connection_instance->logger, LOG_LINE, "Bad performative: %02x", performative);
+                            LOG(LOG_TRACE, LOG_LINE, "Bad performative: %02x", performative);
                             break;
 
                         case AMQP_BEGIN:
@@ -895,13 +894,12 @@
 /* Codes_SRS_CONNECTION_01_001: [connection_create shall open a new connection to a specified host/port.] */
 CONNECTION_HANDLE connection_create(XIO_HANDLE xio, const char* hostname, const char* container_id, ON_NEW_ENDPOINT on_new_endpoint, void* callback_context)
 {
-    return connection_create2(xio, hostname, container_id, on_new_endpoint, callback_context, NULL, NULL, NULL, NULL, NULL);
+    return connection_create2(xio, hostname, container_id, on_new_endpoint, callback_context, NULL, NULL, NULL, NULL);
 }
 
 /* Codes_SRS_CONNECTION_01_001: [connection_create shall open a new connection to a specified host/port.] */
 /* Codes_SRS_CONNECTION_22_002: [connection_create shall allow registering connections state and io error callbacks.] */
-/* Codes_SRS_CONNECTION_22_003: [connection_create shall allow registering a custom logger instead of default console logger.] */
-CONNECTION_HANDLE connection_create2(XIO_HANDLE xio, const char* hostname, const char* container_id, ON_NEW_ENDPOINT on_new_endpoint, void* callback_context, ON_CONNECTION_STATE_CHANGED on_connection_state_changed, void* on_connection_state_changed_context, ON_IO_ERROR on_io_error, void* on_io_error_context, LOGGER_LOG logger)
+CONNECTION_HANDLE connection_create2(XIO_HANDLE xio, const char* hostname, const char* container_id, ON_NEW_ENDPOINT on_new_endpoint, void* callback_context, ON_CONNECTION_STATE_CHANGED on_connection_state_changed, void* on_connection_state_changed_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
 {
     CONNECTION_INSTANCE* result;
 
@@ -918,18 +916,9 @@
         if (result != NULL)
         {
             result->io = xio;
-            if (logger != NULL)
-            {
-                result->logger = logger;
-            }
-            else
-            {
-                /* Codes_SRS_CONNECTION_22_004: [If no logger is provided, log messages are sent to console_logger.] */
-                result->logger = consolelogger_log;
-            }
 
             /* Codes_SRS_CONNECTION_01_082: [connection_create shall allocate a new frame_codec instance to be used for frame encoding/decoding.] */
-            result->frame_codec = frame_codec_create(frame_codec_error, result, result->logger);
+            result->frame_codec = frame_codec_create(frame_codec_error, result);
             if (result->frame_codec == NULL)
             {
                 /* Codes_SRS_CONNECTION_01_083: [If frame_codec_create fails then connection_create shall return NULL.] */
@@ -1411,7 +1400,7 @@
                     }
                     else
                     {
-                        LOG(connection->logger, LOG_LINE, "-> Empty frame");
+                        LOG(LOG_TRACE, LOG_LINE, "-> Empty frame");
 
                         connection->last_frame_sent_time = current_ms;
 
@@ -1625,8 +1614,9 @@
             {
                 if (connection->is_trace_on == 1)
                 {
-                    log_outgoing_frame(connection->logger, performative);
+                    log_outgoing_frame(performative);
                 }
+
                 if (tickcounter_get_current_ms(connection->tick_counter, &connection->last_frame_sent_time) != 0)
                 {
                     result = __LINE__;