Skip to content

Commit

Permalink
core: introduces new macro to check the API/ABI version
Browse files Browse the repository at this point in the history
We plan to introduce fields in some structures. We need such a simple
way to let the application programmer check its installation is correct
and check the version it used at compile time was the same the version
currently known by the library.
  • Loading branch information
jfsmig committed Jun 21, 2016
1 parent cce5ab3 commit 40dc2bc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Used by `cmake`
| Macro | Default | Description |
| ----- | ------- | ----------- |
| OIOSDS_RELEASE | "master" | Global release name |
| OIOSDS_API_VERSION_SHORT | "1.0" | Minor version number |
| OIOSDS_PROJECT_VERSION_SHORT | "1.0" | Minor version number |

Used by `gcc`

Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ find_package(PkgConfig)
if (NOT DEFINED OIOSDS_RELEASE)
set(OIOSDS_RELEASE master)
endif ()
if (NOT DEFINED OIOSDS_API_VERSION_SHORT)
set(OIOSDS_API_VERSION_SHORT "1.0")
if (NOT DEFINED OIOSDS_PROJECT_VERSION_SHORT)
set(OIOSDS_PROJECT_VERSION_SHORT "1.0")
endif ()

set(OIOSDS_API_VERSION "${OIOSDS_RELEASE}/${OIOSDS_API_VERSION_SHORT}")
set(OIOSDS_PROJECT_VERSION "${OIOSDS_RELEASE}/${OIOSDS_PROJECT_VERSION_SHORT}")

if (NOT ABI_VERSION)
set(ABI_VERSION 0)
Expand Down Expand Up @@ -65,7 +65,7 @@ add_definitions(-D_LARGEFILE_SOURCE)
add_definitions(-D_LARGEFILE64_SOURCE)
add_definitions(-D_FILE_OFFSET_BITS=64)
add_definitions(-DHAVE_SOCKLEN_T)
add_definitions(-DOIOSDS_API_VERSION="${OIOSDS_API_VERSION}")
add_definitions(-DOIOSDS_PROJECT_VERSION="${OIOSDS_PROJECT_VERSION}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE("DEBUG symbols enabled")
add_definitions(-DG_ERRORCHECK_MUTEXES)
Expand Down
12 changes: 12 additions & 0 deletions core/oio_sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ License along with this library.
#ifndef OIO_SDS__sdk__oio_sds_h
#define OIO_SDS__sdk__oio_sds_h 1

/* Version started to be defined in June, 2016. Version prior to 20160600
* have no ABI incompatibilities. */
#define OIO_SDS_VERSION 20160600

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -73,6 +77,14 @@ void oio_log_more (void);
*/
char ** oio_sds_get_compile_options (void);

#ifdef OIO_SDS_VERSION
/* Returns the integer version of the API. Compare the version returned to the
* version you know from the OIO_SDS_VERSION macro. If it differs, the only
* behavior to have is upgrading your header AND your library to the same
* level. */
unsigned int oio_sds_version (void);
#endif /* defined OIO_SDS_VERSION */

/* Error management --------------------------------------------------------- */

void oio_error_free (struct oio_error_s *e);
Expand Down
2 changes: 2 additions & 0 deletions core/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ License along with this library.
#include <metautils/lib/metautils.h>
#include <metautils/lib/storage_policy.h>

unsigned int oio_sds_version (void) { return OIO_SDS_VERSION; }

struct oio_sds_s
{
gchar *session_id;
Expand Down
2 changes: 1 addition & 1 deletion proxy/transport_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ http_manage_request(struct req_ctx_s *r)

// Set the status line
g_string_append_printf(buf, "%s %d %s\r\n", r->request->version, code, msg);
g_string_append_printf(buf, "Server: oio-proxy/%s\r\n", OIOSDS_API_VERSION);
g_string_append_printf(buf, "Server: oio-proxy/%s\r\n", OIOSDS_PROJECT_VERSION);

if (0 == g_ascii_strcasecmp("HTTP/1.1", r->request->version)) {
// Manage the "Connection" header of http/1.1
Expand Down
2 changes: 1 addition & 1 deletion server/transport_gridd.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ dispatch_VERSION(struct gridd_reply_ctx_s *reply,
{
(void) gdata, (void) hdata;
reply->no_access();
reply->add_body(metautils_gba_from_string(OIOSDS_API_VERSION));
reply->add_body(metautils_gba_from_string(OIOSDS_PROJECT_VERSION));
reply->send_reply(CODE_FINAL_OK, "OK");
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/oio-sds.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ includedir=@CMAKE_INSTALL_PREFIX@/include

Name: OpenIO SDS
Description: SDS client API's
Version: @OIOSDS_API_VERSION_SHORT@
Version: @OIOSDS_PROJECT_VERSION_SHORT@
Requires.private: sqlite3, glib-2.0
Libs: -L${libdir} -loiocore -loiosds -loiosqlx -loiosqlx_direct -loiosqlx_local
Cflags: -I${includedir}
Expand Down

0 comments on commit 40dc2bc

Please sign in to comment.