Skip to content

Commit

Permalink
Add version information
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Meyer <[email protected]>
  • Loading branch information
thibaultmeyer committed Sep 17, 2021
1 parent c33ae45 commit 83f0c15
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
cmake-build-debug
cmake-build-release
out/
CMakeSettings.json
.vs/
cmake-build-debug/
cmake-build-release/
CMakeSettings.json
out/
src/version.h
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ ENDIF (MSVC)
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")

# Configure version.h file
SET(LIBSNOWFLAKEID_VERSION_STRING "1.0.0")
SET(LIBSNOWFLAKEID_VERSION_NUMBER "100")
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/res/version.h.template ${CMAKE_SOURCE_DIR}/src/version.h)

# Display build type
IF (NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "Build type: -")
Expand All @@ -29,6 +34,8 @@ ENDIF (CMAKE_USE_PTHREADS_INIT)
# Source Files
SET(SOURCE_FILES ${SOURCE_FILES}
src/snowflakeid_destroy.c
src/snowflakeid_get_version_as_int.c
src/snowflakeid_get_version_as_str.c
src/snowflakeid_initialize.c
src/snowflakeid_next_value.c)

Expand Down
6 changes: 6 additions & 0 deletions res/version.h.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef LIBSNOWFLAKEID_VERSION_H
# define LIBSNOWFLAKEID_VERSION_H
# define LIBSNOWFLAKEID_VERSION_STRING "${LIBSNOWFLAKEID_VERSION_STRING}"
# define LIBSNOWFLAKEID_VERSION_NUMBER ${LIBSNOWFLAKEID_VERSION_NUMBER}

#endif //LIBSNOWFLAKEID_VERSION_H
14 changes: 14 additions & 0 deletions src/libsnowflakeid.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ typedef struct s_snowflakeid_generator_ctx {
*/
void snowflakeid_destroy(struct s_snowflakeid_generator_ctx *ctx);

/**
* Returns the SnowflakeID library version as a number.
*
* @return the SnowflakeID library version as a number (ie: 100)
*/
int snowflakeid_get_version_as_int(void);

/**
* Returns the SnowflakeID library version as a string.
*
* @return the SnowflakeID library version as a string (ie: 1.0.0)
*/
const char *snowflakeid_get_version_as_str(void);

/**
* Initialize Snowflake ID generator context.
*
Expand Down
5 changes: 5 additions & 0 deletions src/snowflakeid_get_version_as_int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "version.h"

int snowflakeid_get_version_as_int(void) {
return (LIBSNOWFLAKEID_VERSION_NUMBER);
}
5 changes: 5 additions & 0 deletions src/snowflakeid_get_version_as_str.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "version.h"

const char *snowflakeid_get_version_as_str(void) {
return (LIBSNOWFLAKEID_VERSION_STRING);
}
6 changes: 4 additions & 2 deletions test/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ int main(const int argc, const char *const *argv) {
}

if (argc > 2 && strcmp(argv[1], "PERFORMANCE") == 0) {
int max_value = atoi(argv[2]);
int max_value = (int) strtol(argv[2], NULL, 10);

printf("START PERFORMANCE TEST: %d\n", max_value);

uint64_t *id_array = malloc(sizeof(uint64_t) * max_value + 1);
Expand All @@ -51,11 +52,12 @@ int main(const int argc, const char *const *argv) {
id_array[idx] = snowflakeid_next_value(ctx);
}
uint64_t time_stop = get_current_time_ms();

printf("END PERFORMANCE TEST : %" PRIu64 "ms\n", time_stop - time_start);

free(id_array);
} else if (argc > 1 && strcmp(argv[1], "SINGLE") == 0) {
printf("libsnowflakeid version %s (%d)\n", snowflakeid_get_version_as_str(), snowflakeid_get_version_as_int());

uint64_t snowflakeid = snowflakeid_next_value(ctx);
printf("SINGLE: %" PRIu64 " (timestamp_ms: %" PRIu64 ", datacenter_id: %" PRIu8 ", worker_id: %" PRIu8 ", inc: %" PRIu16 ")\n",
snowflakeid,
Expand Down

0 comments on commit 83f0c15

Please sign in to comment.