scs_timestamp_t last_timestamp = static_cast<scs_timestamp_t>(-1);
/**
- * @brief Combined telemetry data.
+ * @brief Combined telemetry data and shared memory management.
*/
#include "telemetry.h"
struct telemetry_state_t *telemetry;
-/**
- * @brief Function writting message to the game internal log.
- */
-
static int shmid = -1;
-bool init_log(void)
+bool init_shm(void)
{
- if (shmid > 0) {
- return true;
- }
- shmid = shmget (SHM_KEY, sizeof (struct telemetry_state_t), IPC_CREAT | IPC_EXCL | 0600);
- telemetry = static_cast<struct telemetry_state_t *>(shmat (shmid, NULL, 0));
- return true;
+ if ( 0 < shmid )
+ return true;
+ shmid = shmget(SHM_KEY, sizeof *telemetry, IPC_CREAT | IPC_EXCL | 0600);
+ if ( 0 > shmid )
+ return false;
+ void *shmhnd;
+ if ( (void *)-1 == (shmhnd = shmat(shmid, NULL, 0)) )
+ return false;
+ telemetry = static_cast<struct telemetry_state_t *>(shmhnd);
+ return true;
}
-void finish_log(void)
+void release_shm(void)
{
- if (shmid < 0) {
- return;
- }
- shmdt (telemetry);
- shmctl (shmid, IPC_RMID, NULL);
- shmid = -1;
+ if ( 0 < shmid) {
+ shmdt(telemetry);
+ shmctl(shmid, IPC_RMID, NULL);
+ shmid = -1;
+ }
}
+/**
+ * @brief Function writting message to the game internal log.
+ */
+
void log_print(const char *const text, ...)
{
}
}
const scs_telemetry_init_params_v100_t *const version_params = static_cast<const scs_telemetry_init_params_v100_t *>(params);
- if (! init_log()) {
+ if (! init_shm()) {
version_params->common.log(SCS_LOG_TYPE_error, "Unable to initialize the log file");
return SCS_RESULT_generic_error;
}
// Any cleanup needed. The registrations will be removed automatically
// so there is no need to do that manually.
- finish_log();
+ release_shm();
}
// Cleanup
)
{
if (reason_for_call == DLL_PROCESS_DETACH) {
- finish_log();
+ release_shm();
}
return TRUE;
}
#ifdef __linux__
void __attribute__ ((destructor)) unload(void)
{
- finish_log();
+ release_shm();
}
#endif