-
Notifications
You must be signed in to change notification settings - Fork 39
/
common.h
executable file
·72 lines (61 loc) · 3.3 KB
/
common.h
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
68
69
70
71
72
/**************************************************************
* Copyright (c) 2010-2013, Dynamic Network Services, Inc.
* Jake Montgomery ([email protected]) & Tom Daly ([email protected])
* Distributed under the FreeBSD License - see LICENSE
***************************************************************/
// Common header for the beacon and control
#pragma once
#include "standard.h"
#include "log.h"
// TODO: These static port numbers are arbitrary, and can be changed if needed.
// A system should be put into place to allow these to be set.
#define PORTNUM 957
#define ALT_PORTNUM 958
/// magic message header .. in network order
extern const uint32_t MagicMessageNumber;
// Maximum length of a single line in the beacon->control reply.
const size_t MaxReplyLineSize = 2046;
// Maximum length of command from control->beacon
const size_t MaxCommandSize = 1024; // really this is probably to large given the current command set?
extern const char *SofwareVesrion;
extern const char *ControlAppName;
extern const char *BeaconAppName;
// This is like gLog.Optional(), but does not evaluate the parameters if logging
// is off. It incurs extra locking overhead, so only use when parameters include
// expensive function calls.
#define LogOptional(type, format, ...) \
do { if(gLog.LogTypeEnabled(type)) gLog.Message(type, format, ## __VA_ARGS__); } while(0)
/**
* An assertion that is thrown to the log in debug builds only.
*/
#ifdef BFD_DEBUG
#ifndef BFD_SAFE_ASSERT
// Asserts exit process
#define LogAssert(x) \
((x) ? true:(gLog.Message(Log::Critical, "ASSERT FAILED: %s:%d: %s: assertion %s failed", __FILE__, __LINE__, __func__, #x), exit(1), false))
#define LogAssertFalse(msg) \
(gLog.Message(Log::Critical, "ASSERT FALSE: %s:%d: %s: %s", __FILE__, __LINE__, __func__, msg), exit(1), false)
#define LogVerifyFalse(msg) \
(gLog.Message(Log::Critical, "ASSERT FALSE: %s:%d: %s: %s", __FILE__, __LINE__, __func__, msg), exit(1), false)
#define LogVerify(x) \
((x) ? true:(gLog.Message(Log::Critical, "VERIFY FAILED: %s:%d: %s: assertion %s failed", __FILE__, __LINE__, __func__, #x), exit(1), false))
#else
// Asserts merely log
#define LogAssert(x) \
((x) ? true:(gLog.Message(Log::Critical, "ASSERT FAILED: %s:%d: %s: assertion %s failed", __FILE__, __LINE__, __func__, #x), false))
#define LogAssertFalse(msg) \
(gLog.Message(Log::Critical, "ASSERT FALSE: %s:%d: %s: %s", __FILE__, __LINE__, __func__, msg), false)
#define LogVerifyFalse(msg) \
(gLog.Message(Log::Critical, "ASSERT FALSE: %s:%d: %s: %s", __FILE__, __LINE__, __func__, msg), false)
#define LogVerify(x) \
((x) ? true:(gLog.Message(Log::Critical, "VERIFY FAILED: %s:%d: %s: assertion %s failed", __FILE__, __LINE__, __func__, #x), false))
#endif
#else
// Release ... no asserts.
#define LogAssert(x) /*nothing*/
#define LogAssertFalse(msg) /*nothing*/
#define LogVerify(x) \
((x) ? true:(gLog.Message(Log::Critical, "VERIFY FAILED: %s:%d: %s: assertion %s failed", __FILE__, __LINE__, __func__, #x), false))
#define LogVerifyFalse(msg) \
(gLog.Message(Log::Critical, "ASSERT FALSE: %s:%d: %s: %s", __FILE__, __LINE__, __func__, msg), false)
#endif