/*
 * SPDX-FileCopyrightText: 2004 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#ifndef TANGO_COMMON_DEFINES_H_IN
#define TANGO_COMMON_DEFINES_H_IN

/* Define to 1 if you have the <io.h> header file. */
#cmakedefine TANGO_HAVE_IO_H

/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine TANGO_HAVE_UNISTD_H

#cmakedefine TANGO_USE_JPEG
#cmakedefine TANGO_USE_TELEMETRY
#cmakedefine TANGO_TELEMETRY_USE_HTTP
#cmakedefine TANGO_TELEMETRY_USE_GRPC

#include <ostream>
#include <sstream>

#define PROT_SEP "://"
#define TANGO_PROTOCOL "tango"

#define MODIFIER '#'
#define DBASE_YES "dbase=yes"
#define DBASE_NO "dbase=no"
#define MODIFIER_DBASE_NO "#dbase=no"

#define HOST_SEP ':'
#define PORT_SEP '/'
#define DEV_NAME_FIELD_SEP '/'
#define RES_SEP "->"
#define DEVICE_SEP '/'

#define FROM_IOR "IOR"
#define NOT_USED "Unused"

//
// Add some define for Win32 and omniORB
// !!!!!!!!!! In some cases, VC++ wizard generates Stdafx.h file which include
// windows.h file as their first include. Stdafx.h file is the first
// file which should be in included by the include files list. Therefore, in
// this case, it is not possible to define anything before windows.h file is
// included (except by modying stdafx.h file by hand...). In order to include
// Windows socket release 2 software, _WIN32_WINNT must be defined and set
// to something >= 0x0400. Therefore, in this case, define it in the project
// setting in the preprocessor definitions....
//
// Windows:
// The Windows VC compilers family defined _WIN32 (always) and _WIN64
// (when compiled as 64 bits)
// The Windows windef.h include file defines the preprocessor WIN32 on top of the
// _WIN32 one defined by the compiler itself.
//
// This means that on Windows 64 bits, we will have BOTH
//        _WIN32
//        WIN32
//        _WIN64
//
// Within Tango, Windows include files are included by the "idl/tango.h" include file
// included by tango.h after this file
//

#ifdef _WIN32
  #ifndef __WIN32__
    #define __WIN32__
  #endif
  #ifndef __x86__
    #define __x86__
  #endif
  #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0600
  #endif
  #ifndef __NT__
    #define __NT__
  #endif
  #ifndef __OSVERSION
    #define __OSVERSION 4
  #endif
#endif

//
// Define a common preprocessor macros for all Windows (32 or 64 bits)
//

#ifdef _WIN32
  #define _TG_WINDOWS_
#endif

//
// For Windows DLL (import and export nightmare)
//

#ifdef _TG_WINDOWS_
  #if ((defined _USRDLL) || (defined TANGO_HAS_DLL))
    #if (defined _TANGO_LIB)
      // basically never used as we have CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS set
      #define TANGO_IMP_EXP __declspec(dllexport)
      #define TANGO_IMP
    #else
      #define TANGO_IMP_EXP __declspec(dllimport)
      #define TANGO_IMP __declspec(dllimport)
    #endif /* _TANGO_LIB */
  #else
    #define TANGO_IMP_EXP
    #define TANGO_IMP
  #endif /* TANGO_HAS_DLL */

  #if (defined _TANGO_LIB)
    #define TANGO_REV_EXP
  #else
    #define TANGO_REV_EXP __declspec(dllexport)
  #endif /* _TANGO_LIB */
#else
  #define TANGO_IMP_EXP
  #define TANGO_REV_EXP
  #define TANGO_IMP
#endif /* _TG_WINDOWS_ */

//
// Some helper define
//

#define TangoSys_OMemStream std::ostringstream
#define TangoSys_MemStream std::stringstream
#define TangoSys_Pid int
#define TangoSys_Cout std::ostream

//
// For Microsoft compilers
//

#ifdef _TG_WINDOWS_
  #pragma warning(disable : 4355)
  #pragma warning(disable : 4715)
  #pragma warning(disable : 4786)
  #pragma warning(disable : 4267) // var : conversion from size_t to type, possible loss of data
  #pragma warning(disable : 4244) // conversion conversion from type1 to type2, possible loss of data
  #pragma warning(disable : 4996) // disable all deprecation warnings
#endif

//
// Define a common strcasecmp function
//

#ifndef _TG_WINDOWS_
  #define TG_strcasecmp strcasecmp
  #define TG_strncasecmp strncasecmp
#else
  #define TG_strcasecmp stricmp
  #define TG_strncasecmp strnicmp
#endif

//
// Define a macro for unused parameter warning
//

#ifdef _TG_WINDOWS_
  #define TANGO_UNUSED(var) var
#else
  #define TANGO_UNUSED(var) var __attribute__((unused))
#endif

#ifndef _TG_WINDOWS_
  #include <omniORB4/acconfig.h>

  #ifdef PACKAGE_BUGREPORT
    #undef PACKAGE_BUGREPORT
  #endif

  #ifdef PACKAGE_NAME
    #undef PACKAGE_NAME
  #endif

  #ifdef PACKAGE_STRING
    #undef PACKAGE_STRING
  #endif

  #ifdef PACKAGE_TARNAME
    #undef PACKAGE_TARNAME
  #endif

  #ifdef PACKAGE_VERSION
    #undef PACKAGE_VERSION
  #endif
#endif

#endif /* TANGO_COMMON_DEFINES_H_IN */
