<commit_before>/*
 *  PyRideCommon.h
 *  PyRIDE
 *
 *  Created by <NAME> on 20/04/2010.
 *  Copyright 2009 Galaxy Network. All rights reserved.
 *
 */

#ifndef PyRideCommon_h_DEFINED
#define PyRideCommon_h_DEFINED

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>

#include "PyRideCustom.h"

#define PYRIDE_PROTOCOL_VERSION  3
#define PYRIDE_MSG_INIT          0xAC
#define PYRIDE_MSG_END           '#'
#define PYRIDE_MSG_MIN_LENGTH    5
#define PYRIDE_MSG_HEADER_SIZE   4

#define PYRIDE_BROADCAST_IP                "255.255.255.255"
#define PYRIDE_CONTROL_PORT                29430
#define PYRIDE_VIDEO_STREAM_BASE_PORT      35210 //34529
#define PYRIDE_DEFAULT_BUFFER_SIZE         4096
#define PYRIDE_MSG_BUFFER_SIZE             10240
#define PYRIDE_AUDIO_SAMPLE_RATE           48000
#define PYRIDE_AUDIO_FRAME_SIZE            256
#define PYRIDE_AUDIO_BYTES_PER_PACKET      46
#define PYRIDE_AUDIO_BITS_PER_SAMPLE       16
#define PYRIDE_AUDIO_BYTES_PER_SAMPLE      (PYRIDE_AUDIO_BITS_PER_SAMPLE/8)
#define PYRIDE_AUDIO_PLAY_BUFFERS          2


#if defined( IOS_BUILD )
#define PYRIDE_LOGGING_INIT
#define DEBUG_MSG( MSG... ) \
  printf( "DEBUG: " ); \
  printf( MSG );

#define ERROR_MSG( MSG... )  \
  printf( "ERROR: " ); \
  printf( MSG );

#define WARNING_MSG( MSG... )  \
  printf( "WARNING: " ); \
  printf( MSG );

#define INFO_MSG( MSG... )  \
  printf( "INFO: " ); \
  printf( MSG );

#else // !IOS_BUILD
#ifdef WIN32

#define WM_FGNOTIFY WM_USER+1

#define PYRIDE_LOGGING_DECLARE( LOGNAME )

#define PYRIDE_LOGGING_INIT

#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( ... )
#else
#define DEBUG_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }
#endif

#define INFO_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }

#define WARNING_MSG(...)

#define ERROR_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }
#else
#define PYRIDE_LOGGING_DECLARE( LOGNAME ) \
FILE * s_pyridelog = NULL; \
const char * logFileName = LOGNAME

extern FILE * s_pyridelog;
#define PYRIDE_LOGGING_INIT \
{ \
  char * sep = NULL; \
  if ((sep = strrchr( (char*)logFileName, '/' )) != NULL ) { \
    struct stat sb; \
    int dirlen = sep - logFileName; \
    char * dirname = (char *) malloc( dirlen + 1 ); \
    memcpy( dirname, logFileName, dirlen ); \
    dirname[dirlen] = '\0'; \
    if (stat( dirname, &sb ) == -1) \
      mkdir( dirname, 0755 ); \
    free( dirname ); \
  } \
} \
s_pyridelog = fopen( logFileName, "a" )

//#define s_pyridelog stdout

#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( MSG... )
#else
#define DEBUG_MSG( MSG... ) \
fprintf( s_pyridelog, "DEBUG: " ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog )
#endif

#define INFO_MSG( MSG... ) \
fprintf( s_pyridelog, "INFO: " ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog )

#define WARNING_MSG( MSG... ) \
fprintf( s_pyridelog, "WARNING: " ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog )

#define ERROR_MSG( MSG... ) \
fprintf( s_pyridelog, "ERROR: " ); \
fprintf( s_pyridelog, MSG ); \
fflush( s_pyridelog )

#define PYRIDE_LOGGING_FINI fclose( s_pyridelog )
#endif // !WIN32
#endif // IOS_BUILD

#ifdef WIN32
#include <winsock2.h>
#define SOCKET_T  SOCKET
#else
#define SOCKET_T  int
#define INVALID_SOCKET -1
#endif

enum CommandStatus {
  NONE = 0,
  OK,
  FAIL,
  DUPLICATE
};

enum TeamColour {
  BlueTeam = 1,
  PinkTeam = 2
};

typedef enum {
  RAW = 0,
  RGB,
  PROCESSED,
  RGBA,
  BGRA
}ImageFormat;

typedef enum {
  ROBOT_TEAM_MSG      = 0x0,<commit_msg>Added safe guards for logging. Added a compiler warning to change encryption key for client server communication.<commit_after>/*
 *  PyRideCommon.h
 *  PyRIDE
 *
 *  Created by <NAME> on 20/04/2010.
 *  Copyright 2009 Galaxy Network. All rights reserved.
 *
 */

#ifndef PyRideCommon_h_DEFINED
#define PyRideCommon_h_DEFINED

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>

#include "PyRideCustom.h"

#define PYRIDE_PROTOCOL_VERSION  3
#define PYRIDE_MSG_INIT          0xAC
#define PYRIDE_MSG_END           '#'
#define PYRIDE_MSG_MIN_LENGTH    5
#define PYRIDE_MSG_HEADER_SIZE   4

#define PYRIDE_BROADCAST_IP                "255.255.255.255"
#define PYRIDE_CONTROL_PORT                29430
#define PYRIDE_VIDEO_STREAM_BASE_PORT      35210 //34529
#define PYRIDE_DEFAULT_BUFFER_SIZE         4096
#define PYRIDE_MSG_BUFFER_SIZE             10240
#define PYRIDE_AUDIO_SAMPLE_RATE           48000
#define PYRIDE_AUDIO_FRAME_SIZE            256
#define PYRIDE_AUDIO_BYTES_PER_PACKET      46
#define PYRIDE_AUDIO_BITS_PER_SAMPLE       16
#define PYRIDE_AUDIO_BYTES_PER_SAMPLE      (PYRIDE_AUDIO_BITS_PER_SAMPLE/8)
#define PYRIDE_AUDIO_PLAY_BUFFERS          2


#if defined( IOS_BUILD )
#define PYRIDE_LOGGING_INIT
#define DEBUG_MSG( MSG... ) \
  printf( "DEBUG: " ); \
  printf( MSG );

#define ERROR_MSG( MSG... )  \
  printf( "ERROR: " ); \
  printf( MSG );

#define WARNING_MSG( MSG... )  \
  printf( "WARNING: " ); \
  printf( MSG );

#define INFO_MSG( MSG... )  \
  printf( "INFO: " ); \
  printf( MSG );

#else // !IOS_BUILD
#ifdef WIN32

#define WM_FGNOTIFY WM_USER+1

#define PYRIDE_LOGGING_DECLARE( LOGNAME )

#define PYRIDE_LOGGING_INIT

#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( ... )
#else
#define DEBUG_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }
#endif

#define INFO_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }

#define WARNING_MSG(...)

#define ERROR_MSG(...) \
  { char outputStr[200]; \
    sprintf_s( outputStr, 200, __VA_ARGS__ ); \
    OutputDebugStringA( outputStr ); \
  }
#else
#define PYRIDE_NO_LOGGING \
FILE * s_pyridelog = NULL;

#define PYRIDE_LOGGING_DECLARE( LOGNAME ) \
FILE * s_pyridelog = NULL; \
const char * logFileName = LOGNAME

extern FILE * s_pyridelog;
#define PYRIDE_LOGGING_INIT \
{ \
  char * sep = NULL; \
  if ((sep = strrchr( (char*)logFileName, '/' )) != NULL ) { \
    struct stat sb; \
    int dirlen = sep - logFileName; \
    char * dirname = (char *) malloc( dirlen + 1 ); \
    memcpy( dirname, logFileName, dirlen ); \
    dirname[dirlen] = '\0'; \
    if (stat( dirname, &sb ) == -1) \
      mkdir( dirname, 0755 ); \
    free( dirname ); \
  } \
} \
s_pyridelog = fopen( logFileName, "a" )

//#define s_pyridelog stdout

#ifdef PRODUCT_RELEASE
#define DEBUG_MSG( MSG... )
#else
#define DEBUG_MSG( MSG... ) \
if (s_pyridelog) { \
  fprintf( s_pyridelog, "DEBUG: " ); \
  fprintf( s_pyridelog, MSG ); \
  fflush( s_pyridelog ); \
}
#endif

#define INFO_MSG( MSG... ) \
if (s_pyridelog) { \
  fprintf( s_pyridelog, "INFO: " ); \
  fprintf( s_pyridelog, MSG ); \
  fflush( s_pyridelog ); \
}

#define WARNING_MSG( MSG... ) \
if (s_pyridelog) { \
  fprintf( s_pyridelog, "WARNING: " ); \
  fprintf( s_pyridelog, MSG ); \
  fflush( s_pyridelog ); \
}
#define ERROR_MSG( MSG... ) \
if (s_pyridelog) { \
  fprintf( s_pyridelog, "ERROR: " ); \
  fprintf( s_pyridelog, MSG ); \
  fflush( s_pyridelog ); \
}

#define PYRIDE_LOGGING_FINI \
if (s_pyridelog) { \
  fclose( s_pyridelog ); \
}
#endif // !WIN32
#endif // IOS_BUILD

#ifdef WIN32
#include <winsock2.h>
#define SOCKET_T  SOCKET
#else
#define SOCKET_T  int
#define INVALID_SOCKET -1
#endif

#ifndef DEFINED_ENCRYPTION_KEY
#pragma message ( "Make sure you change the encryption key for PyRIDE client server communication. \
To disable this warning, set DEFINED_ENCRYPTION_KEY macro to true." )
#endif

enum CommandStatus {
  NONE = 0,
  OK,
  FAIL,
  DUPLICATE
};

enum TeamColour {
  BlueTeam = 1,
  PinkTeam = 2
};

typedef enum {
  RAW = 0,
  RGB,
  PROCESSED,
  RGBA,
  BGRA
}ImageFormat;

typedef enum {
  ROBOT_TEAM_MSG      = 0x0,
{'fraction_non_alphanumeric': 0.12834358909958557, 'fraction_numerical': 0.026623131985432626, 'mean_word_length': 3.158746736292428, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3911694', 'n_tokens_mistral': 3386, 'n_tokens_neox': 3197, 'n_words': 696}