Commit 56037916 authored by Job Vranish's avatar Job Vranish
Browse files

merged

parents 84fea245 5efac16f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ LIB_DEPS = \
	$(LIB_DIR)/kinetic_logger.h \
	$(LIB_DIR)/kinetic_hmac.h \
	$(LIB_DIR)/kinetic_controller.h \
	$(LIB_DIR)/kinetic_device_info.h \
	$(LIB_DIR)/kinetic_serial_allocator.h \
	$(LIB_DIR)/kinetic_connection.h \
	$(LIB_DIR)/kinetic_types_internal.h \
	$(PUB_INC)/kinetic_types.h \
@@ -67,6 +69,8 @@ LIB_OBJS = \
	$(OUT_DIR)/kinetic_logger.o \
	$(OUT_DIR)/kinetic_hmac.o \
	$(OUT_DIR)/kinetic_controller.o \
	$(OUT_DIR)/kinetic_device_info.o \
	$(OUT_DIR)/kinetic_serial_allocator.o \
	$(OUT_DIR)/kinetic_connection.o \
	$(OUT_DIR)/kinetic_types_internal.o \
	$(OUT_DIR)/kinetic_types.o \
@@ -113,6 +117,10 @@ $(OUT_DIR)/kinetic_controller.o: $(LIB_DIR)/kinetic_controller.c $(LIB_DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) $(LIB_INCS)
$(OUT_DIR)/kinetic_connection.o: $(LIB_DIR)/kinetic_connection.c $(LIB_DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) $(LIB_INCS)
$(OUT_DIR)/kinetic_device_info.o: $(LIB_DIR)/kinetic_device_info.c $(LIB_DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) $(LIB_INCS)
$(OUT_DIR)/kinetic_serial_allocator.o: $(LIB_DIR)/kinetic_serial_allocator.c $(LIB_DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) $(LIB_INCS)
$(OUT_DIR)/kinetic_types_internal.o: $(LIB_DIR)/kinetic_types_internal.c $(LIB_DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) $(LIB_INCS)
$(OUT_DIR)/kinetic_types.o: $(LIB_DIR)/kinetic_types.c $(LIB_DEPS)
+27 −5
Original line number Diff line number Diff line
@@ -245,27 +245,44 @@ typedef struct {
    char* protocolVersion;
    char* protocolCompilationDate;
    char* protocolSourceHash;
    KineticDeviceInfo_Interface** interfaces;
    KineticDeviceInfo_Interface* interfaces;
    size_t numInterfaces;
    int32_t port;
    int32_t tlsPort;
} KineticDeviceInfo_Configuration;
typedef enum {
    KINETIC_MESSAGE_TYPE_GET = 0,
    KINETIC_MESSAGE_TYPE_INVALID = 0,
    KINETIC_MESSAGE_TYPE_GET_RESPONSE,
    KINETIC_MESSAGE_TYPE_GET,
    KINETIC_MESSAGE_TYPE_PUT_RESPONSE,
    KINETIC_MESSAGE_TYPE_PUT,
    KINETIC_MESSAGE_TYPE_DELETE_RESPONSE,
    KINETIC_MESSAGE_TYPE_DELETE,
    KINETIC_MESSAGE_TYPE_GETNEXT_RESPONSE,
    KINETIC_MESSAGE_TYPE_GETNEXT,
    KINETIC_MESSAGE_TYPE_GETPREVIOUS_RESPONSE,
    KINETIC_MESSAGE_TYPE_GETPREVIOUS,
    KINETIC_MESSAGE_TYPE_GETKEYRANGE_RESPONSE,
    KINETIC_MESSAGE_TYPE_GETKEYRANGE,
    KINETIC_MESSAGE_TYPE_GETVERSION_RESPONSE,
    KINETIC_MESSAGE_TYPE_GETVERSION,
    KINETIC_MESSAGE_TYPE_SETUP_RESPONSE,
    KINETIC_MESSAGE_TYPE_SETUP,
    KINETIC_MESSAGE_TYPE_GETLOG_RESPONSE,
    KINETIC_MESSAGE_TYPE_GETLOG,
    KINETIC_MESSAGE_TYPE_SECURITY_RESPONSE,
    KINETIC_MESSAGE_TYPE_SECURITY,
    KINETIC_MESSAGE_TYPE_PEER2PEERPUSH_RESPONSE,
    KINETIC_MESSAGE_TYPE_PEER2PEERPUSH,
    KINETIC_MESSAGE_TYPE_NOOP_RESPONSE,
    KINETIC_MESSAGE_TYPE_NOOP,
    KINETIC_MESSAGE_TYPE_FLUSHALLDATA_RESPONSE,
    KINETIC_MESSAGE_TYPE_FLUSHALLDATA,
    KINETIC_MESSAGE_TYPE_PINOP_RESPONSE,
    KINETIC_MESSAGE_TYPE_PINOP,
    KINETIC_MESSAGE_TYPE_MEDIASCAN_RESPONSE,
    KINETIC_MESSAGE_TYPE_MEDIASCAN,
    KINETIC_MESSAGE_TYPE_MEDIAOPTIMIZE_RESPONSE,
    KINETIC_MESSAGE_TYPE_MEDIAOPTIMIZE,
} KineticMessageType;
typedef struct {
@@ -290,17 +307,22 @@ typedef struct {
    ByteArray name;
} KineticDeviceInfo_Device;
typedef struct {
    KineticDeviceInfo_Utilization** utilizations;
    size_t totalLength;
    KineticDeviceInfo_Utilization* utilizations;
    size_t numUtilizations;
    KineticDeviceInfo_Temperature** temperatures;
    KineticDeviceInfo_Temperature* temperatures;
    size_t numTemperatures;
    KineticDeviceInfo_Capacity* capacity;
    KineticDeviceInfo_Configuration* configuration;
    KineticDeviceInfo_Statistics** statistics;
    KineticDeviceInfo_Statistics* statistics;
    size_t numStatistics;
    ByteArray messages;
    KineticDeviceInfo_Limits* limits;
    KineticDeviceInfo_Device* device;
} KineticDeviceInfo;

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

#endif // _KINETIC_TYPES_H
+173 −2
Original line number Diff line number Diff line
@@ -2,11 +2,86 @@
  "folders":
  [
    {
      "path": "."
      "follow_symlinks": true,
      "path": ".",
      "binary_file_patterns": ["build"]
    }
  ],
  "settings":
  {
    "binary_file_patterns":
    [
      "*.jpg",
      "*.jpeg",
      "*.png",
      "*.gif",
      "*.ttf",
      "*.tga",
      "*.dds",
      "*.ico",
      "*.eot",
      "*.pdf",
      "*.swf",
      "*.jar",
      "*.zip"
    ],
    "ensure_newline_at_eof_on_save": true,
    "file_exclude_patterns":
    [
      "*.pyc",
      "*.pyo",
      "*.exe",
      "*.dll",
      "*.obj",
      "*.o",
      "*.a",
      "*.lib",
      "*.so",
      "*.dylib",
      "*.ncb",
      "*.sdf",
      "*.suo",
      "*.pdb",
      "*.idb",
      ".DS_Store",
      "*.class",
      "*.psd",
      "*.d",
      "*.db",
      "*.dirstamp",
      "*.sublime-workspace"
    ],
    "folder_exclude_patterns":
    [
      ".svn",
      ".git",
      ".hg",
      "CVS",
      "cache",
      "out"
    ],
    "index_exclude_patterns":
    [
      "*.log",
      ".svn",
      ".git",
      ".hg",
      "CVS",
      "cache",
      "out",
      "build"
    ],
    "index_files": true,
    // "rulers":
    // [
    //  80,
    //  100
    // ],
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_automatic_white_space": true,
    "word_wrap": "true",
    "wrap_width": 0,
    "sublimeclang_dont_prepend_clang_includes": true,
    "sublimeclang_options":
    [
@@ -44,5 +119,101 @@
      "-I${folder:${project_path:kinetic-c.sublime-project}}/test/support/stubs",
      "-I${folder:${project_path:kinetic-c.sublime-project}}/test/support"
    ]
  },
	"build_systems":
	[
		{
			"cmd":
			[
				"rake"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Default Build",
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"clobber",
				"test_all"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Run all tests (full)",
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"test_all"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Run all tests (incremental)",
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"CC=/usr/bin/CC",
				"test:${file_name}"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Test current module w/Clang",
			"selector":
			[
				"source.c",
				"source.c++"
			],
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"CC=gcc-4.9",
				"test:${file_name}"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Test current module w/GCC",
			"selector":
			[
				"source.c",
				"source.c++"
			],
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"release"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Build test utility",
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"release",
				"run"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Build and run test utility",
			"working_dir": "${project_path}"
		},
		{
			"cmd":
			[
				"rake",
				"ci"
			],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "Full CI build",
			"working_dir": "${project_path}"
		}
	]
}
+0 −1
Original line number Diff line number Diff line
@@ -204,7 +204,6 @@ KineticStatus KineticClient_GetLog(KineticSessionHandle handle,
{
    assert(handle != KINETIC_HANDLE_INVALID);
    assert(info != NULL);
    // assert(*info != NULL);

    KineticOperation* operation = KineticController_CreateOperation(handle);
    if (operation == NULL) {return KINETIC_STATUS_MEMORY_ERROR;}
+153 −50
Original line number Diff line number Diff line
@@ -23,84 +23,187 @@
#include "kinetic_logger.h"
#include <stdlib.h>

static size_t sizeof_KineticDeviceInfo_Utilizations(const KineticProto_Command_GetLog* getLog)
#define COPY_VALUE_OPTIONAL(_attr, _dest, _src) { \
    if (_src->has_##_attr) { _dest->_attr = _src->_attr; } }
#define COPY_CSTRING(_attr, _dest, _src, _allocator) \
    if (_src->_attr != NULL) { \
        size_t len = strlen(_src->_attr)+1; \
        _dest->_attr = KineticSerialAllocator_AllocateChunk(_allocator, len); \
        memcpy(_dest->_attr, _src->_attr, len); \
    }
#define COPY_BYTES_OPTIONAL(_attr, _dest, _src, _allocator) \
    if (_src->has_##_attr) { \
        _dest->_attr.data = KineticSerialAllocator_AllocateChunk(_allocator, _src->_attr.len); \
        memcpy(_dest->_attr.data, _src->_attr.data, _src->_attr.len); \
        _dest->_attr.len = _src->_attr.len; \
    }

static void KineticDeviceInfo_ExtractUtilizations(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    size_t count = getLog->n_utilizations;
    size += count * (sizeof(KineticDeviceInfo_Utilization*) + sizeof(KineticDeviceInfo_Utilization));
    for (size_t i = 0; i < count; i++) {
        if (getLog->utilizations[i]->name != NULL) {
            size += strlen(getLog->utilizations[i]->name) + 1;
    info->numUtilizations = getLog->n_utilizations;
    if (info->numUtilizations > 0) {
        info->utilizations = KineticSerialAllocator_AllocateChunk(allocator,
            info->numUtilizations * sizeof(KineticDeviceInfo_Utilization));
        for (size_t i = 0; i < info->numUtilizations; i++) {
            KineticDeviceInfo_Utilization* destUtilization = &(info->utilizations[i]);
            COPY_CSTRING(name,         destUtilization, getLog->utilizations[i], allocator);
            COPY_VALUE_OPTIONAL(value, destUtilization, getLog->utilizations[i]);
        }
    }
    return size;
}

static size_t sizeof_KineticDeviceInfo_Temperatures(const KineticProto_Command_GetLog* getLog)
static void KineticDeviceInfo_ExtractTemperatures(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    if (getLog->n_temperatures > 0) {
        info->numTemperatures = getLog->n_temperatures;
        info->temperatures = KineticSerialAllocator_AllocateChunk(allocator,
            info->numTemperatures * sizeof(KineticDeviceInfo_Temperature));
        for (size_t i = 0; i < info->numTemperatures; i++) {
            KineticDeviceInfo_Temperature* destTemp = &info->temperatures[i];
            COPY_CSTRING(name,  destTemp, getLog->temperatures[i], allocator);
            COPY_VALUE_OPTIONAL(current, destTemp, getLog->temperatures[i]);
            COPY_VALUE_OPTIONAL(minimum, destTemp, getLog->temperatures[i]);
            COPY_VALUE_OPTIONAL(maximum, destTemp, getLog->temperatures[i]);
            COPY_VALUE_OPTIONAL(target,  destTemp, getLog->temperatures[i]);
        }
    }
static size_t sizeof_KineticDeviceInfo_Capacity(const KineticProto_Command_GetLog* getLog)
{
    size_t size = 0;
    return size;
}
static size_t sizeof_KineticDeviceInfo_Configuration(const KineticProto_Command_GetLog* getLog)

static void KineticDeviceInfo_ExtractCapacity(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    if (getLog->capacity != NULL) {
        info->capacity = KineticSerialAllocator_AllocateChunk(allocator, sizeof(KineticDeviceInfo_Capacity));
        COPY_VALUE_OPTIONAL(nominalCapacityInBytes, info->capacity, getLog->capacity);
        COPY_VALUE_OPTIONAL(portionFull,            info->capacity, getLog->capacity);
    }
}
static size_t sizeof_KineticDeviceInfo_Statistics(const KineticProto_Command_GetLog* getLog)

static void KineticDeviceInfo_ExtractConfiguration(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    if (getLog->configuration != NULL) {
        info->configuration = KineticSerialAllocator_AllocateChunk(allocator,
            sizeof(KineticDeviceInfo_Configuration));
        COPY_CSTRING(vendor,                  info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(model,                   info->configuration, getLog->configuration, allocator);
        COPY_BYTES_OPTIONAL(serialNumber,     info->configuration, getLog->configuration, allocator);
        COPY_BYTES_OPTIONAL(worldWideName,    info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(version,                 info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(compilationDate,         info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(sourceHash,              info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(protocolVersion,         info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(protocolCompilationDate, info->configuration, getLog->configuration, allocator);
        COPY_CSTRING(protocolSourceHash,      info->configuration, getLog->configuration, allocator);
        if (getLog->configuration->n_interface > 0) {
            info->configuration->interfaces = KineticSerialAllocator_AllocateChunk(allocator,
                sizeof(KineticDeviceInfo_Interface) * getLog->configuration->n_interface);
            info->configuration->numInterfaces = getLog->configuration->n_interface;
            for (size_t i = 0; i < getLog->configuration->n_interface; i++) {
                KineticDeviceInfo_Interface* destIface = &info->configuration->interfaces[i];
                KineticProto_Command_GetLog_Configuration_Interface* srcIface = getLog->configuration->interface[i];
                COPY_CSTRING(name,               destIface, srcIface, allocator);
                COPY_BYTES_OPTIONAL(MAC,         destIface, srcIface, allocator);
                COPY_BYTES_OPTIONAL(ipv4Address, destIface, srcIface, allocator);
                COPY_BYTES_OPTIONAL(ipv6Address, destIface, srcIface, allocator);
            }
        }
        COPY_VALUE_OPTIONAL(port,    info->configuration, getLog->configuration);
        COPY_VALUE_OPTIONAL(tlsPort, info->configuration, getLog->configuration);
    }
static size_t sizeof_messages(const KineticProto_Command_GetLog* getLog)
}

static void KineticDeviceInfo_ExtractStatistics(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    if (getLog->statistics != NULL && getLog->n_statistics > 0) {
        info->numStatistics = getLog->n_statistics;
        info->statistics = KineticSerialAllocator_AllocateChunk(allocator,
            sizeof(KineticDeviceInfo_Statistics) * getLog->n_statistics);
        for (size_t i = 0; i < getLog->n_statistics; i++) {
            KineticDeviceInfo_Statistics* destStats = &info->statistics[i];
            KineticProto_Command_GetLog_Statistics* srcStats = getLog->statistics[i];
            destStats->messageType = KineticProto_Command_MessageType_to_KineticMessageType(srcStats->messageType);
            COPY_VALUE_OPTIONAL(count, destStats, srcStats);
            COPY_VALUE_OPTIONAL(bytes, destStats, srcStats);
        }
    }
static size_t sizeof_KineticDeviceInfo_Limits(const KineticProto_Command_GetLog* getLog)
}

static void KineticDeviceInfo_ExtractMessages(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    COPY_BYTES_OPTIONAL(messages, info, getLog, allocator);
}
static size_t sizeof_KineticDeviceInfo_Device(const KineticProto_Command_GetLog* getLog)

static void KineticDeviceInfo_ExtractLimits(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    return size;
    if (getLog->limits != NULL) {
        info->limits = KineticSerialAllocator_AllocateChunk(allocator, sizeof(KineticDeviceInfo_Limits));
        info->limits->maxKeySize = getLog->limits->maxKeySize;
        info->limits->maxValueSize = getLog->limits->maxValueSize;
        info->limits->maxVersionSize = getLog->limits->maxVersionSize;
        info->limits->maxTagSize = getLog->limits->maxTagSize;
        info->limits->maxConnections = getLog->limits->maxConnections;
        info->limits->maxOutstandingReadRequests = getLog->limits->maxOutstandingReadRequests;
        info->limits->maxOutstandingWriteRequests = getLog->limits->maxOutstandingWriteRequests;
        info->limits->maxMessageSize = getLog->limits->maxMessageSize;
        info->limits->maxKeyRangeCount = getLog->limits->maxKeyRangeCount;
        info->limits->maxIdentityCount = getLog->limits->maxIdentityCount;
        info->limits->maxPinSize = getLog->limits->maxPinSize;
    }
}

static size_t sizeof_KineticDeviceInfo(const KineticProto_Command_GetLog* getLog)
static void KineticDeviceInfo_ExtractDevice(
    KineticDeviceInfo* info,
    const KineticProto_Command_GetLog* getLog,
    KineticSerialAllocator* allocator)
{
    size_t size = 0;
    size += sizeof(KineticDeviceInfo);
    size += sizeof_KineticDeviceInfo_Utilizations(getLog);
    size += sizeof_KineticDeviceInfo_Temperatures(getLog);
    size += sizeof_KineticDeviceInfo_Capacity(getLog);
    size += sizeof_KineticDeviceInfo_Configuration(getLog);
    size += sizeof_KineticDeviceInfo_Statistics(getLog);
    size += sizeof_messages(getLog);
    size += sizeof_KineticDeviceInfo_Limits(getLog);
    size += sizeof_KineticDeviceInfo_Device(getLog);
    return size;
    if (getLog->device != NULL) {
        info->device = KineticSerialAllocator_AllocateChunk(allocator, sizeof(KineticDeviceInfo_Device));
        COPY_BYTES_OPTIONAL(name, info->device, getLog->device, allocator);
    }
}

KineticDeviceInfo* KineticDeviceInfo_Create(const KineticProto_Command_GetLog* getLog)
{
    assert(getLog != NULL);

    // Determine the total size to allocate for all available data
    size_t totalSize = sizeof_KineticDeviceInfo(getLog);
    KineticDeviceInfo* info = NULL;

    // Allocate the data
    KineticSerialAllocator allocator = KineticSerialAllocator_Create(totalSize);

    info = (KineticDeviceInfo*)allocator.buffer;
    KineticSerialAllocator allocator = KineticSerialAllocator_Create(KINETIC_DEVICE_INFO_SCRATCH_BUF_LEN);

    // Copy data into the nested allocated structure tree
    KineticDeviceInfo* info = KineticSerialAllocator_AllocateChunk(&allocator, sizeof(KineticDeviceInfo));
    KineticDeviceInfo_ExtractUtilizations(info, getLog, &allocator);
    KineticDeviceInfo_ExtractCapacity(info, getLog, &allocator);
    KineticDeviceInfo_ExtractTemperatures(info, getLog, &allocator);
    KineticDeviceInfo_ExtractConfiguration(info, getLog, &allocator);
    KineticDeviceInfo_ExtractStatistics(info, getLog, &allocator);
    KineticDeviceInfo_ExtractMessages(info, getLog, &allocator);
    KineticDeviceInfo_ExtractLimits(info, getLog, &allocator);
    KineticDeviceInfo_ExtractDevice(info, getLog, &allocator);

    // Trim the buffer prior to returning in order to free up unused memory
    info->totalLength = allocator.used;
    info->totalLength = KineticSerialAllocator_TrimBuffer(&allocator);
    info = KineticSerialAllocator_GetBuffer(&allocator);
    LOGF2("Created KineticDeviceInfo @ 0x%0llX w/ length=%zu", info, info->totalLength);
    return info;
}
Loading