Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Bugcheck.h
Go to the documentation of this file.
1//
2// Bugcheck.h
3//
4// Library: Foundation
5// Package: Core
6// Module: Bugcheck
7//
8// Definition of the Bugcheck class and the self-testing macros.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Bugcheck_INCLUDED
18#define Foundation_Bugcheck_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include <string>
23#include <cstdlib>
24#if defined(_DEBUG)
25# include <iostream>
26#endif
27
28
29namespace Poco {
30
31
33 /// This class provides some static methods that are
34 /// used by the
35 /// poco_assert_dbg(), poco_assert(), poco_check_ptr(),
36 /// poco_bugcheck() and poco_unexpected() macros.
37 /// You should not invoke these methods
38 /// directly. Use the macros instead, as they
39 /// automatically provide useful context information.
40{
41public:
42 static void assertion(const char* cond, const char* file, int line, const char* text = 0);
43 /// An assertion failed. Break into the debugger, if
44 /// possible, then throw an AssertionViolationException.
45
46 static void nullPointer(const char* ptr, const char* file, int line);
47 /// An null pointer was encountered. Break into the debugger, if
48 /// possible, then throw an NullPointerException.
49
50 static void bugcheck(const char* file, int line);
51 /// An internal error was encountered. Break into the debugger, if
52 /// possible, then throw an BugcheckException.
53
54 static void bugcheck(const char* msg, const char* file, int line);
55 /// An internal error was encountered. Break into the debugger, if
56 /// possible, then throw an BugcheckException.
57
58 static void unexpected(const char* file, int line);
59 /// An exception was caught in a destructor. Break into debugger,
60 /// if possible and report exception. Must only be called from
61 /// within a catch () block as it rethrows the exception to
62 /// determine its class.
63
64 static void debugger(const char* file, int line);
65 /// An internal error was encountered. Break into the debugger, if
66 /// possible.
67
68 static void debugger(const char* msg, const char* file, int line);
69 /// An internal error was encountered. Break into the debugger, if
70 /// possible.
71
72protected:
73 static std::string what(const char* msg, const char* file, int line, const char* text = 0);
74};
75
76
77} // namespace Poco
78
79
80//
81// useful macros (these automatically supply line number and file name)
82//
83#if defined(__KLOCWORK__) || defined(__clang_analyzer__)
84
85
86// Short-circuit these macros when under static analysis.
87// Ideally, static analysis tools should understand and reason correctly about
88// noreturn methods such as Bugcheck::bugcheck(). In practice, they don't.
89// Help them by turning these macros into std::abort() as described here:
90// https://developer.klocwork.com/documentation/en/insight/10-1/tuning-cc-analysis#Usingthe__KLOCWORK__macro
91
92#include <cstdlib> // for abort
93#define poco_assert_dbg(cond) do { if (!(cond)) std::abort(); } while (0)
94#define poco_assert_msg_dbg(cond, text) do { if (!(cond)) std::abort(); } while (0)
95#define poco_assert(cond) do { if (!(cond)) std::abort(); } while (0)
96#define poco_assert_msg(cond, text) do { if (!(cond)) std::abort(); } while (0)
97#define poco_check_ptr(ptr) do { if (!(ptr)) std::abort(); } while (0)
98#define poco_bugcheck() do { std::abort(); } while (0)
99#define poco_bugcheck_msg(msg) do { std::abort(); } while (0)
100
101
102#else // defined(__KLOCWORK__) || defined(__clang_analyzer__)
103
104
105#if defined(_DEBUG)
106 #define poco_assert_dbg(cond)
107 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
108
109 #define poco_assert_msg_dbg(cond, text)
110 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__, text); else (void) 0
111#else
112 #define poco_assert_msg_dbg(cond, text)
113 #define poco_assert_dbg(cond)
114#endif
115
116
117#define poco_assert(cond)
118 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0
119
120
121#define poco_assert_msg(cond, text)
122 if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__, text); else (void) 0
123
124
125#define poco_check_ptr(ptr)
126 if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0
127
128
129#define poco_bugcheck()
130 Poco::Bugcheck::bugcheck(__FILE__, __LINE__)
131
132
133#define poco_bugcheck_msg(msg)
134 Poco::Bugcheck::bugcheck(msg, __FILE__, __LINE__)
135
136
137#endif // defined(__KLOCWORK__) || defined(__clang_analyzer__)
138
139
140#define poco_unexpected()
141 Poco::Bugcheck::unexpected(__FILE__, __LINE__);
142
143
144#define poco_debugger()
145 Poco::Bugcheck::debugger(__FILE__, __LINE__)
146
147
148#define poco_debugger_msg(msg)
149 Poco::Bugcheck::debugger(msg, __FILE__, __LINE__)
150
151
152#if defined(_DEBUG)
153# define poco_stdout_dbg(outstr)
154 std::cout << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
155#else
156# define poco_stdout_dbg(outstr)
157#endif
158
159
160#if defined(_DEBUG)
161# define poco_stderr_dbg(outstr)
162 std::cerr << __FILE__ << '(' << std::dec << __LINE__ << "):" << outstr << std::endl;
163#else
164# define poco_stderr_dbg(outstr)
165#endif
166
167
168//
169// poco_static_assert
170//
171// The following was ported from <boost/static_assert.hpp>
172//
173
174
175template <bool x>
176struct POCO_STATIC_ASSERTION_FAILURE;
177
178
179template <>
180struct POCO_STATIC_ASSERTION_FAILURE<true>
181{
182 enum
183 {
184 value = 1
185 };
186};
187
188
189template <int x>
191{
192};
193
194
195#if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
196#define poco_static_assert(B)
197 typedef char POCO_JOIN(poco_static_assert_typedef_, __LINE__)
198 [POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>::value]
199#else
200#define poco_static_assert(B)
201 typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>)>
202 POCO_JOIN(poco_static_assert_typedef_, __LINE__) POCO_UNUSED
203#endif
204
205
206#endif // Foundation_Bugcheck_INCLUDED
#define ARK_API
Definition Base.h:9
#define POCO_NO_SOO
Definition Config.h:82
#define POCO_DO_JOIN2(X, Y)
Definition Foundation.h:134
#define POCO_DO_JOIN(X, Y)
Definition Foundation.h:133
#define Foundation_API
Definition Foundation.h:60
#define POCO_JOIN(X, Y)
Definition Foundation.h:132
#define Net_API
Definition Net.h:47
#define NetSSL_API
Definition NetSSL.h:48
#define POCO_OS_WINDOWS_NT
Definition Platform.h:43
#define POCO_UNUSED
Definition Platform.h:274
#define POCO_OS_ANDROID
Definition Platform.h:41
#define POCO_OS_QNX
Definition Platform.h:37
#define POCO_OS_LINUX
Definition Platform.h:31
#define POCO_OS_SOLARIS
Definition Platform.h:36
#define POCO_ARCH_AMD64
Definition Platform.h:129
#define POCO_EXTERNAL_OPENSSL_SLPRO
Definition Crypto.h:24
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
std::mutex RequestMutex_
Definition Requests.cpp:47
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
Definition Requests.cpp:73
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Definition Requests.cpp:107
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
Definition Requests.cpp:79
std::vector< RequestData > RequestsVec_
Definition Requests.cpp:46
Requests(Requests &&)=delete
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
Definition Requests.cpp:129
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:238
Requests & operator=(Requests &&)=delete
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
Definition Requests.cpp:292
Requests & operator=(const Requests &)=delete
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
Definition Requests.cpp:162
static ARK_API Requests & Get()
Definition Requests.cpp:67
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:200
std::unique_ptr< impl > pimpl
Definition Requests.h:84
Requests(const Requests &)=delete
virtual void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback)=0
Added function will be called every frame.
virtual bool RemoveOnTickCallback(const FString &id)=0
Removes a on-tick callback.
Definition Logger.h:9
static std::shared_ptr< spdlog::logger > & GetLog()
Definition Logger.h:22
static std::string what(const char *msg, const char *file, int line, const char *text=0)
static void bugcheck(const char *msg, const char *file, int line)
static void nullPointer(const char *ptr, const char *file, int line)
static void debugger(const char *msg, const char *file, int line)
static void debugger(const char *file, int line)
static void bugcheck(const char *file, int line)
static void assertion(const char *cond, const char *file, int line, const char *text=0)
static void unexpected(const char *file, int line)
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
HTTPRequest(const std::string &method, const std::string &uri, const std::string &version)
Creates a HTTP/1.0 request with the given method and URI.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPResponse(HTTPStatus status)
HTTPStatus getStatus() const
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession)
std::string proxyRequestPrefix() const
Sends the given HTTPRequest over an existing connection.
HTTPSClientSession(Context::Ptr pContext, Session::Ptr pSession)
HTTPSClientSession(Context::Ptr pContext)
Creates a HTTPSClientSession using the given host and port.
void proxyAuthenticate(HTTPRequest &request)
Checks if we can reuse a persistent connection.
int read(char *buffer, std::streamsize length)
HTTPSClientSession(const HTTPSClientSession &)
void connect(const SocketAddress &address)
Refills the internal buffer.
HTTPSClientSession(const SecureStreamSocket &socket, Session::Ptr pSession)
X509Certificate serverCertificate()
HTTPSClientSession & operator=(const HTTPSClientSession &)
HTTPSClientSession(const std::string &host, Poco::UInt16 port=HTTPS_PORT)
HTTPSClientSession(const SecureStreamSocket &socket)
Creates an unconnected HTTPSClientSession.
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext)
RejectCertificateHandler(bool handleErrorsOnServerSide)
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
Definition NullStream.h:77
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
Definition URI.h:385
const std::string & getScheme() const
Definition URI.h:373
URI(const std::string &uri)
Creates an empty URI.
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
void error(const T &)
Definition IBaseApi.h:9
std::unique_ptr< IBaseApi > game_api
Definition IBaseApi.h:25
void NetSSL_API initializeSSL()
void Net_API uninitializeNetwork()
void Net_API initializeNetwork()
void NetSSL_API uninitializeSSL()
Definition format.h:408
Definition json.hpp:4518
std::function< void(bool, std::string)> callback
Definition Requests.cpp:41
static std::string escape(const std::string &s, bool strictJSON=false)