summaryrefslogtreecommitdiff
path: root/mcast/netcv2dvbip/misc.h
blob: edc269db425d3e865f8de8f73397976ee8bf5390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef __MISC_H
#define __MISC_H

#ifdef _MSC_VER
   typedef unsigned __int64 uint64_t;	// Define it from MSVC's internal type
#else
   #include <stdint.h>		    // Use the C99 official header
#endif

#define bool int

#ifndef __STL_CONFIG_H // in case some plugin needs to use the STL
template<class T> inline T xmin(T a, T b) { return a <= b ? a : b; }
template<class T> inline T xmax(T a, T b) { return a >= b ? a : b; }
template<class T> inline int xsgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
template<class T> inline void xswap(T &a, T &b) { T t = a; a = b; b = t; }
#endif

#ifdef WIN32
typedef unsigned long in_addr_t;
#define SCKT SOCKET
#else
#include <arpa/inet.h>
#define SCKT int
#endif

#ifndef NULL
#define NULL 0
#endif

#ifdef WIN32
#define strdup _strdup
#endif

#define HI_BYTE(byte)    (((byte) >> 4) & 0x0F)
#define LO_BYTE(byte)    ((byte) & 0x0F)

extern void log_socket_error(const char* msg);
extern bool GetAbsTime(struct timespec *Abstime, int MillisecondsFromNow);

#ifdef WIN32
struct timezone {
               int tz_minuteswest;     /* minutes west of Greenwich */
               int tz_dsttime;         /* type of DST correction */
};
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
bool IsUserAdmin( bool* pbAdmin );
bool IsVistaOrHigher();
#else
#include <sys/time.h>
#endif

class cTimeMs {
private:
  uint64_t begin;
public:
  cTimeMs(int Ms = 0);
      ///< Creates a timer with ms resolution and an initial timeout of Ms.
  static uint64_t Now(void);
  void Set(int Ms = 0);
  bool TimedOut(void);
  uint64_t Elapsed(void);
};

extern int quiet;

#endif