Loading src/lib/kinetic_allocator.c +26 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,32 @@ #include <stdlib.h> #include <pthread.h> KineticSession* KineticAllocator_NewSession(struct bus * b, KineticSessionConfig* config) { (void)b; // TODO: combine session w/connection, which will use this variable // Allocate a new session KineticSession* session = KineticCalloc(1, sizeof(KineticSession)); if (session == NULL) { LOG0("Failed allocating a new session!"); return NULL; } // Copy the supplied config into the session config session->config = *config; strncpy(session->config.host, config->host, sizeof(session->config.host)); return session; } void KineticAllocator_FreeSession(KineticSession* session) { if (session != NULL) { KineticFree(session); } } KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session) { KineticConnection* connection = KineticCalloc(1, sizeof(KineticConnection)); Loading src/lib/kinetic_allocator.h +3 −1 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ #include "kinetic_types_internal.h" KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session); KineticSession* KineticAllocator_NewSession(struct bus * b, KineticSessionConfig* config); void KineticAllocator_FreeSession(KineticSession* session); KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session); void KineticAllocator_FreeConnection(KineticConnection* connection); KineticPDU* KineticAllocator_NewPDU(KineticConnection* connection); Loading src/lib/kinetic_client.c +8 −11 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "kinetic_types_internal.h" #include "kinetic_client.h" #include "kinetic_allocator.h" #include "kinetic_session.h" #include "kinetic_controller.h" #include "kinetic_operation.h" Loading Loading @@ -86,30 +87,26 @@ KineticStatus KineticClient_CreateSession(KineticSessionConfig* const config, return KINETIC_STATUS_HMAC_REQUIRED; } // Allocate a new session KineticSession* s = KineticCalloc(1, sizeof(KineticSession)); // Create a new session KineticSession* s = KineticAllocator_NewSession(client->bus, config); if (s == NULL) { LOG0("Failed allocating a new session!"); LOG0("Failed to create session instance!"); return KINETIC_STATUS_MEMORY_ERROR; } // Copy the supplied config into the session config s->config = *config; strncpy(s->config.host, config->host, sizeof(s->config.host)); // Initialize the session instance KineticSession_Create(s, client); if (s->connection == NULL) { LOG0("Failed to create connection instance!"); KineticAllocator_FreeSession(s); return KINETIC_STATUS_CONNECTION_ERROR; } // Create the connection // Establish the connection KineticStatus status = KineticSession_Connect(s); if (status != KINETIC_STATUS_SUCCESS) { LOGF0("Failed creating connection to %s:%d", config->host, config->port); KineticSession_Destroy(s); s->connection = NULL; KineticSession_Destroy(s); KineticAllocator_FreeSession(s); return status; } Loading src/lib/kinetic_session.c +3 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,9 @@ KineticStatus KineticSession_Destroy(KineticSession * const session) #endif KineticAllocator_FreeConnection(session->connection); session->connection = NULL; KineticAllocator_FreeSession(session); return KINETIC_STATUS_SUCCESS; } Loading Loading
src/lib/kinetic_allocator.c +26 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,32 @@ #include <stdlib.h> #include <pthread.h> KineticSession* KineticAllocator_NewSession(struct bus * b, KineticSessionConfig* config) { (void)b; // TODO: combine session w/connection, which will use this variable // Allocate a new session KineticSession* session = KineticCalloc(1, sizeof(KineticSession)); if (session == NULL) { LOG0("Failed allocating a new session!"); return NULL; } // Copy the supplied config into the session config session->config = *config; strncpy(session->config.host, config->host, sizeof(session->config.host)); return session; } void KineticAllocator_FreeSession(KineticSession* session) { if (session != NULL) { KineticFree(session); } } KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session) { KineticConnection* connection = KineticCalloc(1, sizeof(KineticConnection)); Loading
src/lib/kinetic_allocator.h +3 −1 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ #include "kinetic_types_internal.h" KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session); KineticSession* KineticAllocator_NewSession(struct bus * b, KineticSessionConfig* config); void KineticAllocator_FreeSession(KineticSession* session); KineticConnection* KineticAllocator_NewConnection(struct bus * b, KineticSession* const session); void KineticAllocator_FreeConnection(KineticConnection* connection); KineticPDU* KineticAllocator_NewPDU(KineticConnection* connection); Loading
src/lib/kinetic_client.c +8 −11 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "kinetic_types_internal.h" #include "kinetic_client.h" #include "kinetic_allocator.h" #include "kinetic_session.h" #include "kinetic_controller.h" #include "kinetic_operation.h" Loading Loading @@ -86,30 +87,26 @@ KineticStatus KineticClient_CreateSession(KineticSessionConfig* const config, return KINETIC_STATUS_HMAC_REQUIRED; } // Allocate a new session KineticSession* s = KineticCalloc(1, sizeof(KineticSession)); // Create a new session KineticSession* s = KineticAllocator_NewSession(client->bus, config); if (s == NULL) { LOG0("Failed allocating a new session!"); LOG0("Failed to create session instance!"); return KINETIC_STATUS_MEMORY_ERROR; } // Copy the supplied config into the session config s->config = *config; strncpy(s->config.host, config->host, sizeof(s->config.host)); // Initialize the session instance KineticSession_Create(s, client); if (s->connection == NULL) { LOG0("Failed to create connection instance!"); KineticAllocator_FreeSession(s); return KINETIC_STATUS_CONNECTION_ERROR; } // Create the connection // Establish the connection KineticStatus status = KineticSession_Connect(s); if (status != KINETIC_STATUS_SUCCESS) { LOGF0("Failed creating connection to %s:%d", config->host, config->port); KineticSession_Destroy(s); s->connection = NULL; KineticSession_Destroy(s); KineticAllocator_FreeSession(s); return status; } Loading
src/lib/kinetic_session.c +3 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,9 @@ KineticStatus KineticSession_Destroy(KineticSession * const session) #endif KineticAllocator_FreeConnection(session->connection); session->connection = NULL; KineticAllocator_FreeSession(session); return KINETIC_STATUS_SUCCESS; } Loading