Commit c2d0423c authored by Scott Vokes's avatar Scott Vokes
Browse files

API change: Use a struct for KineticClient_Init settings.

This allows adding settings without breaking the source API, as long as
there are default values porvided.

Add options for the number of writer, reader, and max threadpool threads.
parent c729c643
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -26,8 +26,7 @@
/**
 * Initializes the Kinetic API and configures logging destination.
 *
 * @param log_file (path to log file, 'stdout' to log to STDOUT, NULL to disable logging)
 * @param log_level Logging level (-1:none, 0:error, 1:info, 2:verbose, 3:full)
 * @param config A configuration struct.
 *
 * @return          Returns a pointer to a `KineticClient`. You need to pass 
 *                  this pointer to KineticClient_CreateConnection() to create 
@@ -36,7 +35,7 @@
 *                  are no active connections. The pointer should be release
 *                  with KineticClient_Shutdown()
 */
KineticClient * KineticClient_Init(const char* log_file, int log_level);
KineticClient * KineticClient_Init(KineticClientConfig *config);

/**
 * @brief Performs shutdown/cleanup of the kinetic-c client lib
+27 −0
Original line number Diff line number Diff line
@@ -362,6 +362,33 @@ struct _KineticP2P_Operation {
    KineticP2P_OperationData* operations; // pointer must remain valid until operations complete
};

/* Default values for the KineticClientConfig struct, which will be used
 * if the corresponding field in the struct is 0. */
#define KINETIC_CLIENT_DEFAULT_LOG_LEVEL 0
#define KINETIC_CLIENT_DEFAULT_WRITER_THREADS 4
#define KINETIC_CLIENT_DEFAULT_READER_THREADS 4
#define KINETIC_CLIENT_DEFAULT_MAX_THREADPOOL_THREADS 8

/**
 * @brief Configuration values for the KineticClient connection.
 *
 * Configuration for the KineticClient connection. If fields are zeroed out, default
 * values will be used.
 * 
 * @var logFile (path to log file, 'stdout' to log to STDOUT, NULL to disable logging)
 * @var logLevel Logging level (-1:none, 0:error, 1:info, 2:verbose, 3:full)
 * @var writerThreads Number of threads used for handling outgoing requests
 * @var readerThreads Number of threads used for handling incoming responses and status messages
 * @var maxThreadpoolThreads Max number of threads to use for the threadpool that handles response callbacks.
 */
typedef struct {
    const char *logFile;
    int logLevel;
    uint8_t writerThreads;
    uint8_t readerThreads;
    uint8_t maxThreadpoolThreads;
} KineticClientConfig;

const char* KineticMessageType_GetName(KineticMessageType type);

#define KINETIC_DEVICE_INFO_SCRATCH_BUF_LEN (1024 * 1024 * 4) // Will get reallocated to actual/used size post-copy
+5 −1
Original line number Diff line number Diff line
@@ -124,7 +124,11 @@ int main(int argc, char** argv)
        }
    };
    
    KineticClient * client = KineticClient_Init("stdout", 1);
    KineticClientConfig client_config = {
        .logFile = "stdout",
        .logLevel = 1,
    };
    KineticClient * client = KineticClient_Init(&client_config);
    if (client == NULL) { return 1; }
    status = KineticClient_CreateConnection(&session, client);
    if (status != KINETIC_STATUS_SUCCESS) {
+5 −1
Original line number Diff line number Diff line
@@ -57,7 +57,11 @@ int main(int argc, char** argv)
        }
    };
    
    KineticClient * client = KineticClient_Init("stdout", 1);
    KineticClientConfig client_config = {
        .logFile = "stdout",
        .logLevel = 1,
    };
    KineticClient * client = KineticClient_Init(&client_config);
    if (client == NULL) { return 1; }
    status = KineticClient_CreateConnection(&session, client);
    if (status != KINETIC_STATUS_SUCCESS) {
+5 −1
Original line number Diff line number Diff line
@@ -111,7 +111,11 @@ int main(int argc, char** argv)
        }
    };
    
    KineticClient * client = KineticClient_Init("stdout", 1);
    KineticClientConfig client_config = {
        .logFile = "stdout",
        .logLevel = 1,
    };
    KineticClient * client = KineticClient_Init(&client_config);
    if (client == NULL) { return 1; }
    status = KineticClient_CreateConnection(&session, client);
    if (status != KINETIC_STATUS_SUCCESS) {
Loading