* Improved SDK version checking and logging.
authorUrban Wallasch <urban.wallasch@freenet.de>
Sun, 11 Aug 2019 15:07:47 +0000 (17:07 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sun, 11 Aug 2019 15:07:47 +0000 (17:07 +0200)
teleshmem.cpp

index 2e23dc63f0eea250004af3fc636c7139e2c0fe17..dac73ce3f4dfbfe4ef7ebf9a5283e5519d874d13 100644 (file)
@@ -92,6 +92,7 @@ static int log_open( void ) {
 
 static void log_close( void ) {
     if ( logfp ) {
+        fprintf( logfp, "\nclosing log\n" );
         fclose( logfp );
         logfp = NULL;
     }
@@ -204,7 +205,7 @@ static void log_named_value( const scs_named_value_t *nv ) {
     }
 }
 #else
-#define log_open()
+#define log_open()      0
 #define log_close()
 #define log_print(...)
 #define log_named_value(...)
@@ -491,15 +492,28 @@ SCSAPI_VOID telemetry_store_bool(const scs_string_t name, const scs_u32_t index,
  */
 SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_init_params_t *const params)
 {
-    log_open();
-
-    // We currently support only one version.
-
-    if (version != SCS_TELEMETRY_VERSION_1_01) {
+    const scs_telemetry_init_params_v100_t *const v100p = static_cast<const scs_telemetry_init_params_v100_t *>(params);
+    const unsigned version_req = SCS_TELEMETRY_VERSION_1_01;    // we currently require version 1.01
+    char vstr[20];
+    char rvstr[20];
+    char vlogstr[100];
+
+    if ( 0 != log_open() )
+        v100p->common.log( SCS_LOG_TYPE_warning, "[teleshmem] unable to open log file" );
+
+    sprintf( vstr, "%u.%02u", (unsigned)SCS_GET_MAJOR_VERSION(version), (unsigned)SCS_GET_MINOR_VERSION(version) );
+    sprintf( rvstr, "%u.%02u", (unsigned)SCS_GET_MAJOR_VERSION(version_req), (unsigned)SCS_GET_MINOR_VERSION(version_req) );
+    sprintf( vlogstr, "[teleshmem] got telemetry version %s", vstr );
+    log_print( "Got telemetry version %s.\n", vstr );
+    v100p->common.log( SCS_LOG_TYPE_message, vlogstr );
+    if ( version != version_req ) {
+        log_print( "Error: Want telemetry version %s, got %s\n", rvstr, vstr );
+        v100p->common.log( SCS_LOG_TYPE_warning, "[teleshmem] telemetry version not supported" );
         return SCS_RESULT_unsupported;
     }
 
-    const scs_telemetry_init_params_v100_t *const version_params = static_cast<const scs_telemetry_init_params_v100_t *>(params);
+    const scs_telemetry_init_params_v101_t *const version_params = static_cast<const scs_telemetry_init_params_v101_t *>(params);
+
     if ( !init_shm() ) {
         log_print( "FATAL: Unable to initialize shared memory\n" );
         version_params->common.log(SCS_LOG_TYPE_error, "[teleshmem] Unable to initialize shared memory");