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
135#define SERVICE_ERROR_TRIGGERED -37
139#define JAZZ_DEFAULT_CONFIG_PATH "config/jazz_config.ini"
168 return ((str[1] & 0x1f) << 5) | (str[0] & 0x1F);
178 TimePoint now = std::chrono::steady_clock::now();
180 return std::chrono::duration_cast<std::chrono::microseconds>(now - big_bang).count();
190 char ch = p_name++[0];
195 if (ch <
'A' || ch >
'z' || (ch >
'Z' && ch <
'a'))
198 for (
int i = 1; i < NAME_SIZE; i++) {
199 char ch = p_name++[0];
204 if (ch <
'0' || ch >
'z' || (ch >
'9' && ch <
'A') || (ch >
'Z' && ch <
'_') || ch == 0x60)
228 bool get_key(
const char *key,
int &value);
229 bool get_key(
const char *key,
double &value);
252 Logger(
const char *output_file_name);
254 const char *config_key);
259 void log (
int loglevel,
const char *message);
260 void log_printf(
int loglevel,
const char *fmt, ...);
261 void log_printf(
int loglevel,
const char *fmt, va_list args);
308 inline void log(
int loglevel,
const char *message) {
if (
p_log !=
nullptr)
p_log->
log(loglevel, message); }
319 if (
p_log !=
nullptr) {
A configuration file as a key/value store.
Definition utils.h:218
int num_keys()
Definition utils.cpp:380
void debug_put(const String key, const String val)
Definition utils.cpp:470
bool get_key(const char *key, int &value)
Definition utils.cpp:391
bool load_config(const char *input_file_name)
Definition utils.cpp:339
std::map< String, String > config
The configuration key/value store.
Definition utils.h:238
A simple logger.
Definition utils.h:248
void log_printf(int loglevel, const char *fmt,...)
Definition utils.cpp:618
void log(int loglevel, const char *message)
Definition utils.cpp:576
TimePoint big_bang
The time when the logger was created.
Definition utils.h:274
void InitLogger()
Definition utils.cpp:515
std::filebuf * f_buff
The buffer for the stream.
Definition utils.h:273
char file_name[MAX_FILENAME_LENGTH]
The name of the log file.
Definition utils.h:271
~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:272
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:288
bool get_conf_key(const char *key, String &value)
Definition utils.h:357
bool get_conf_key(const char *key, int &value)
Definition utils.h:335
void log(int loglevel, const char *message)
Definition utils.h:308
void log_printf(int loglevel, const char *fmt,...)
Definition utils.h:318
pLogger p_log
The logger.
Definition utils.h:360
virtual pChar const id()
Definition utils.cpp:666
bool get_conf_key(const char *key, double &value)
Definition utils.h:346
virtual StatusCode start()
A simple start()/shut_down() interface (Restart is: shut_down(TRUE):start())
Definition utils.cpp:678
pConfigFile p_conf
The configuration file.
Definition utils.h:361
virtual StatusCode shut_down()
Definition utils.cpp:693
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:363
int TenBitIntLUT[TENBITS_LUT_SIZE]
A lookup table for all the possible results of a TenBitsAtAddress() call -> integer.
Definition utils.h:153
std::string String
A standard string used in many other places in Jazz.
Definition types.h:239
int TenBitsAtAddress(const char *str)
Get ten bits taking the least significant 5 of the first two characters of a string.
Definition utils.h:167
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:189
Logger * pLogger
A pointer to a Logger object.
Definition utils.h:276
char * pChar
A pointer to a char buffer.
Definition types.h:189
void * TenBitPtrLUT[TENBITS_LUT_SIZE]
A lookup table for all the possible results of a TenBitsAtAddress() call -> pointer.
Definition utils.h:157
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:176
ConfigFile * pConfigFile
A pointer to a ConfigFile object.
Definition utils.h:240
String CleanConfigArgument(String s)
Remove quotes and (space and tab) outside quotes from a string.
Definition utils.cpp:301
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:142
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:177