* Dropped asserts from plugin code.
authorUrban Wallasch <urban.wallasch@freenet.de>
Mon, 19 Aug 2019 11:02:58 +0000 (13:02 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Mon, 19 Aug 2019 11:02:58 +0000 (13:02 +0200)
* Trivial fixes and changes to includes, comments and whitespace.

telehttpd.c
teleshmem.cpp

index 6f9e843ecfd7ba1c6248422528ce2c8fb41cb94a..4e06fac996a0ea1b0883e3c8e661e7430533e0e0 100644 (file)
@@ -358,7 +358,7 @@ static int config( int argc, char *argv[] ) {
 int main(int argc, char *argv[]) {
     signal(SIGTERM, handle_signal);
     signal(SIGINT,  handle_signal);
-    // We don't want do get killed by some thread writing to a stale socket:
+    // We don't want to get killed by some thread writing to a stale socket:
     signal(SIGPIPE, SIG_IGN);
 
     if ( 0 != config( argc, argv ) )
index e00e63fa57366e50ca1d93e1628c7283e629e957..8c5c561143a30f1bbad02ee7b58ea1f642637fda 100644 (file)
@@ -1,37 +1,33 @@
 /**
- * @brief Simple logger.
+ * @brief Shared memory telemetry plugin.
  *
- * Writes the output into file inside the current directory.
+ * Makes telemetry data available to other processes via shared memory.
  */
 
 // Windows stuff.
-
 #ifdef _WIN32
 #  define WINVER 0x0500
 #  define _WIN32_WINNT 0x0500
 #  include <windows.h>
 #endif
 
+// Linux
+#ifdef __linux__
+#  include <unistd.h>
+#  include <pthread.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 
-#include <pthread.h>
-
 // SDK
-
 #include "scssdk_telemetry.h"
 #include "eurotrucks2/scssdk_eut2.h"
 #include "eurotrucks2/scssdk_telemetry_eut2.h"
 #include "amtrucks/scssdk_ats.h"
 #include "amtrucks/scssdk_telemetry_ats.h"
 
-//LINUX
-
-#include <unistd.h>
-#include <signal.h>
-
 #define UNUSED(x)
 
 /**
@@ -169,10 +165,10 @@ static void log_named_value( const scs_named_value_t *nv ) {
     }
 }
 #else
-#define log_open()      0
-#define log_close()
-#define log_print(...)
-#define log_named_value(...)
+#  define log_open()      0
+#  define log_close()
+#  define log_print(...)
+#  define log_named_value(...)
 #endif // def LOGGING
 
 
@@ -264,14 +260,12 @@ SCSAPI_VOID telemetry_frame_start(const scs_event_t UNUSED(event), const void *c
 
     // When we just initialized itself, assume that the time started
     // just now.
-
     if (last_timestamp == static_cast<scs_timestamp_t>(-1)) {
         last_timestamp = info->paused_simulation_time;
     }
 
     // The timer might be sometimes restarted (e.g. after load) while
     // we want to provide continuous time on our output.
-
     if (info->flags & SCS_TELEMETRY_FRAME_START_FLAG_timer_restart) {
         last_timestamp = 0;
     }
@@ -452,19 +446,20 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e
     }
 }
 
-// Handling of individual channels.
+/**
+ * @brief Handling of individual channels.
+ */
 
 SCSAPI_VOID telemetry_store_dplacement(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_dplacement);
-    assert(context);
     telemetry_state_t *const tele = static_cast<telemetry_state_t *>(context);
 
     // This callback was registered with the SCS_TELEMETRY_CHANNEL_FLAG_no_value flag
     // so it is called even when the value is not available.
     if ( !value || value->type != SCS_VALUE_TYPE_dplacement ) {
+        lock_shm();
         tele->placement_isvalid = false;
+        unlock_shm();
         return;
     }
     lock_shm();
@@ -480,12 +475,6 @@ SCSAPI_VOID telemetry_store_dplacement(const scs_string_t name, const scs_u32_t
 
 SCSAPI_VOID telemetry_store_double(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration
-    // so this callback is only called when a valid value is available.
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_double);
-    assert(context);
     lock_shm();
     *static_cast<double *>(context) = value->value_double.value;
     unlock_shm();
@@ -493,12 +482,6 @@ SCSAPI_VOID telemetry_store_double(const scs_string_t name, const scs_u32_t inde
 
 SCSAPI_VOID telemetry_store_double_nz(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration
-    // so this callback is only called when a valid value is available.
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_double);
-    assert(context);
     if (value->value_double.value) {
         lock_shm();
         *static_cast<double *>(context) = value->value_double.value;
@@ -508,12 +491,6 @@ SCSAPI_VOID telemetry_store_double_nz(const scs_string_t name, const scs_u32_t i
 
 SCSAPI_VOID telemetry_store_s32(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration
-    // so this callback is only called when a valid value is available.
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_s32);
-    assert(context);
     lock_shm();
     *static_cast<int32_t *>(context) = value->value_s32.value;
     unlock_shm();
@@ -521,12 +498,6 @@ SCSAPI_VOID telemetry_store_s32(const scs_string_t name, const scs_u32_t index,
 
 SCSAPI_VOID telemetry_store_u32(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration
-    // so this callback is only called when a valid value is available.
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_u32);
-    assert(context);
     lock_shm();
     *static_cast<uint32_t *>(context) = value->value_u32.value;
     unlock_shm();
@@ -534,12 +505,6 @@ SCSAPI_VOID telemetry_store_u32(const scs_string_t name, const scs_u32_t index,
 
 SCSAPI_VOID telemetry_store_bool(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context)
 {
-    // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration
-    // so this callback is only called when a valid value is available.
-
-    assert(value);
-    assert(value->type == SCS_VALUE_TYPE_bool);
-    assert(context);
     lock_shm();
     *static_cast<bool *>(context) = value->value_bool.value;
     unlock_shm();
@@ -594,7 +559,6 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
 
         // Below the minimum version there might be some missing features (only minor change) or
         // incompatible values (major change).
-
         const scs_u32_t MINIMAL_VERSION = SCS_TELEMETRY_EUT2_GAME_VERSION_1_01;
         if (version_params->common.game_version < MINIMAL_VERSION) {
             log_print("WARNING: Too old version of the game, some features might behave incorrectly\n");
@@ -602,7 +566,6 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
         }
 
         // Future versions are fine as long the major version is not changed.
-
         const scs_u32_t IMPLEMENTED_VERSION = SCS_TELEMETRY_EUT2_GAME_VERSION_CURRENT;
         if (SCS_GET_MAJOR_VERSION(version_params->common.game_version) > SCS_GET_MAJOR_VERSION(IMPLEMENTED_VERSION)) {
             log_print("WARNING: Too new major version of the game, some features might behave incorrectly\n");
@@ -613,7 +576,6 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
 
         // Bellow the minimum version there might be some missing features (only minor change) or
         // incompatible values (major change).
-
         const scs_u32_t MINIMAL_VERSION = SCS_TELEMETRY_ATS_GAME_VERSION_1_01;
         if (version_params->common.game_version < MINIMAL_VERSION) {
             log_print("WARNING: Too old version of the game, some features might behave incorrectly\n");
@@ -621,7 +583,6 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
         }
 
         // Future versions are fine as long the major version is not changed.
-
         const scs_u32_t IMPLEMENTED_VERSION = SCS_TELEMETRY_ATS_GAME_VERSION_CURRENT;
         if (SCS_GET_MAJOR_VERSION(version_params->common.game_version) > SCS_GET_MAJOR_VERSION(IMPLEMENTED_VERSION)) {
             log_print("WARNING: Too new major version of the game, some features might behave incorrectly\n");
@@ -659,7 +620,6 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in
     // it (SCS_RESULT_not_found) or if does not support the requested type
     // (SCS_RESULT_unsupported_type). For purpose of this example we ignore the failues
     // so the unsupported channels will remain at theirs default value.
-
     const bool channels_registered =
            (version_params->register_for_channel(SCS_TELEMETRY_CHANNEL_game_time, SCS_U32_NIL, SCS_VALUE_TYPE_u32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_u32, &telemetry->game_time) == SCS_RESULT_ok)
         && (version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_dplacement, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_dplacement, telemetry) == SCS_RESULT_ok)
@@ -705,7 +665,6 @@ SCSAPI_VOID scs_telemetry_shutdown(void)
 {
     // Any cleanup needed. The registrations will be removed automatically
     // so there is no need to do that manually.
-
     drop_shm();
     log_close();
 }