45#include <sys/syscall.h>
49#include "src/jazz_elements/types.h"
52#ifndef INCLUDED_JAZZ_CATCH2
53#define INCLUDED_JAZZ_CATCH2
55#include "src/catch2/catch.hpp"
61#ifndef INCLUDED_JAZZ_ELEMENTS_UTILS
62#define INCLUDED_JAZZ_ELEMENTS_UTILS
74#define TENBITS_LUT_SIZE 1024
92#define MAX_FILENAME_LENGTH 256
94#define MAX_BLOCK_SIZE 0x40000000
98#define SERVICE_NO_ERROR 0
99#define SERVICE_NOT_IMPLEMENTED -1
100#define SERVICE_ERROR_BAD_CONFIG -2
101#define SERVICE_ERROR_STARTING -3
102#define SERVICE_ERROR_NO_MEM -4
103#define SERVICE_ERROR_LOADING_STAT -5
104#define SERVICE_ERROR_NEW_BLOCK_ARGS -6
105#define SERVICE_ERROR_WRONG_TYPE -7
106#define SERVICE_ERROR_WRONG_NAME -8
107#define SERVICE_ERROR_WRONG_ARGUMENTS -9
108#define SERVICE_ERROR_BAD_BLOCK -10
109#define SERVICE_ERROR_BAD_NEW_KIND -11
110#define SERVICE_ERROR_BAD_KIND_ADD -12
111#define SERVICE_ERROR_WRITE_FORBIDDEN -13
112#define SERVICE_ERROR_WRITE_FAILED -14
113#define SERVICE_ERROR_REMOVE_FAILED -15
114#define SERVICE_ERROR_BLOCK_NOT_FOUND -16
115#define SERVICE_ERROR_CREATE_FAILED -17
116#define SERVICE_ERROR_PARSING_NAMES -18
117#define SERVICE_ERROR_PARSING_NUMBERS -19
118#define SERVICE_ERROR_TOO_DEEP -20
119#define SERVICE_ERROR_WRONG_BASE -21
120#define SERVICE_ERROR_PARSING_COMMAND -22
121#define SERVICE_ERROR_EMPTY_ENTITY -23
122#define SERVICE_ERROR_ENTITY_NOT_FOUND -24
123#define SERVICE_ERROR_LOW_PRIORITY -25
124#define SERVICE_ERROR_PARENT_NOT_FOUND -26
125#define SERVICE_ERROR_TOO_MANY_ENTITIES -27
126#define SERVICE_ERROR_NOT_APPLICABLE -28
127#define SERVICE_ERROR_IO_ERROR -29
128#define SERVICE_ERROR_BLOCK_TOO_BIG -30
129#define SERVICE_ERROR_BASE_FORBIDDEN -31
130#define SERVICE_ERROR_READ_FORBIDDEN -32
131#define SERVICE_ERROR_NOT_READY -33
132#define SERVICE_ERROR_MISC_SERVER -34
133#define SERVICE_ERROR_UNKNOWN_JAZZNODE -35
134#define SERVICE_ERROR_CORRUPTED -36
138#define JAZZ_DEFAULT_CONFIG_PATH "config/jazz_config.ini"
167 return ((str[1] & 0x1f) << 5) | (str[0] & 0x1F);
177 TimePoint now = std::chrono::steady_clock::now();
179 return std::chrono::duration_cast<std::chrono::microseconds>(now - big_bang).count();
189 char ch = p_name++[0];
194 if (ch <
'A' || ch >
'z' || (ch >
'Z' && ch <
'a'))
197 for (
int i = 1; i < NAME_SIZE; i++) {
198 char ch = p_name++[0];
203 if (ch <
'0' || ch >
'z' || (ch >
'9' && ch <
'A') || (ch >
'Z' && ch <
'_') || ch == 0x60)
227 bool get_key(
const char *key,
int &value);
228 bool get_key(
const char *key,
double &value);
229 bool get_key(
const char *key, std::string &value);
231 void debug_put(
const std::string key,
const std::string val);
235 std::map<std::string, std::string>
config;
249 Logger(
const char *output_file_name);
251 const char *config_key);
256 void log (
int loglevel,
const char *message);
257 void log_printf(
int loglevel,
const char *fmt, ...);
258 void log_printf(
int loglevel,
const char *fmt, va_list args);
305 inline void log(
int loglevel,
const char *message) {
if (
p_log !=
nullptr)
p_log->
log(loglevel, message); }
316 if (
p_log !=
nullptr) {
A configuration file as a key/value store.
Definition utils.h:217
int num_keys()
Definition utils.cpp:380
std::map< std::string, std::string > config
The configuration key/value store.
Definition utils.h:235
bool get_key(const char *key, int &value)
Definition utils.cpp:391
bool load_config(const char *input_file_name)
Definition utils.cpp:339
void debug_put(const std::string key, const std::string val)
Definition utils.cpp:470
A simple logger.
Definition utils.h:245
void log_printf(int loglevel, const char *fmt,...)
Definition utils.cpp:623
void log(int loglevel, const char *message)
Definition utils.cpp:576
TimePoint big_bang
The time when the logger was created.
Definition utils.h:271
void InitLogger()
Definition utils.cpp:515
std::filebuf * f_buff
The buffer for the stream.
Definition utils.h:270
char file_name[MAX_FILENAME_LENGTH]
The name of the log file.
Definition utils.h:268
~Logger()
Definition utils.cpp:540
int get_output_file_name(char *buff, int buff_size)
Definition utils.cpp:553
std::ofstream f_stream
The stream to the log file.
Definition utils.h:269
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:285
bool get_conf_key(const char *key, int &value)
Definition utils.h:332
void log(int loglevel, const char *message)
Definition utils.h:305
bool get_conf_key(const char *key, std::string &value)
Definition utils.h:354
void log_printf(int loglevel, const char *fmt,...)
Definition utils.h:315
pLogger p_log
The logger.
Definition utils.h:357
virtual pChar const id()
Definition utils.cpp:671
bool get_conf_key(const char *key, double &value)
Definition utils.h:343
virtual StatusCode start()
A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
Definition utils.cpp:683
pConfigFile p_conf
The configuration file.
Definition utils.h:358
virtual StatusCode shut_down()
Definition utils.cpp:698
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
Service * pService
A pointer to a Service object.
Definition utils.h:360
int TenBitIntLUT[TENBITS_LUT_SIZE]
A lookup table for all the possible results of a TenBitsAtAddress() call -> integer.
Definition utils.h:152
int TenBitsAtAddress(const char *str)
Get ten bits taking the least significant 5 of the first two characters of a string.
Definition utils.h:166
uint64_t MurmurHash64A(const void *key, int len)
MurmurHash2, 64-bit versions, by Austin Appleby.
Definition utils.cpp:250
bool valid_name(pChar p_name)
Check if a name is valid (Without using the regex).
Definition utils.h:188
Logger * pLogger
A pointer to a Logger object.
Definition utils.h:273
char * pChar
A pointer to a char buffer.
Definition types.h:185
std::string CleanConfigArgument(std::string s)
Remove quotes and (space and tab) outside quotes from a string.
Definition utils.cpp:301
void * TenBitPtrLUT[TENBITS_LUT_SIZE]
A lookup table for all the possible results of a TenBitsAtAddress() call -> pointer.
Definition utils.h:156
bool FileExists(const char *file_name)
Check if a file exists.
Definition utils.cpp:46
std::chrono::steady_clock::time_point TimePoint
A time point stored as 8 bytes.
Definition types.h:172
ConfigFile * pConfigFile
A pointer to a ConfigFile object.
Definition utils.h:237
char * ExpandEscapeSequences(char *buff)
Expand escaped strings at run-time.
Definition utils.cpp:81
int StatusCode
Type returned by the Service API.
Definition utils.h:141
pid_t FindProcessIdByName(const char *name)
Find the pid of a process given its name.
Definition utils.cpp:181
int64_t elapsed_mu_sec(TimePoint big_bang)
Return server running time in microseconds as a 64 bit integer.
Definition utils.h:176