-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuuzwaail.hpp
174 lines (149 loc) · 6.97 KB
/
vuuzwaail.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/****
* Vuuzwaail
* Copyright (C) 2024 Takym.
*
* distributed under the MIT License.
****/
#pragma once
#ifndef VUUZWAAIL_HPP
#define VUUZWAAIL_HPP
#define VZWL_TITLE "Vuuzwaail"
#define VZWL_COPYRIGHT "Copyright (C) 2024 Takym."
#define VZWL_VERSION_MAJOR 0
#define VZWL_VERSION_MINOR 0
#define VZWL_VERSION_PATCH 0
#define VZWL_VERSION_BUILD 0
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
namespace vzwl
{
extern bool debugModeEnabled;
typedef int ReturnCode;
#define VZWL_RET vzwl::ReturnCode
#define VZWL_RET_SUCCEEDED ((VZWL_RET)(0))
#define VZWL_RET_FAILED_STARTUP(num) ((VZWL_RET)(0x00000000 | num))
#define VZWL_RET_FAILED_PROCESSOR(num) ((VZWL_RET)(0x00010000 | num))
#define VZWL_RET_FAILED_STARTUP_MISSING_CMDLINE_ARGS VZWL_RET_FAILED_STARTUP (0x0001)
#define VZWL_RET_FAILED_STARTUP_INIT_LOGGING VZWL_RET_FAILED_STARTUP (0x0002)
#define VZWL_RET_FAILED_PROCESSOR_ANY VZWL_RET_FAILED_PROCESSOR(0x0000)
#define VZWL_RET_FAILED_PROCESSOR_INIT VZWL_RET_FAILED_PROCESSOR(0x0001)
#define VZWL_RET_FAILED_PROCESSOR_DEINIT VZWL_RET_FAILED_PROCESSOR(0x0002)
#define VZWL_RET_FAILED_PROCESSOR_RUN VZWL_RET_FAILED_PROCESSOR(0x0003)
#define VZWL_RET_FAILED_PROCESSOR_RUN_AND_DEINIT VZWL_RET_FAILED_PROCESSOR(0x0004)
typedef const char *const cstr_t;
typedef struct _CMDLINE_OPTIONS_ {
int argc;
char **argv;
char **envp;
bool showLogo;
bool showVersion;
bool showHelp;
} CmdlineOptions, *LpCmdlineOptions;
typedef enum _COMPONENT_TYPE_ {
Unknown = -1,
Uninitialized,
Processor,
Memory,
Storage
} ComponentType;
typedef uint32_t ComponentId;
typedef struct _COMPONENT_ Component, *LpComponent;
typedef void (*SendFunc )(LpComponent lpThisComp, int32_t key, int32_t data);
typedef int32_t (*ReceiveFunc )(LpComponent lpThisComp, int32_t key );
typedef bool (*TesterDoerFunc)(LpComponent lpThisComp );
struct _COMPONENT_ {
ComponentType type;
ComponentId id;
SendFunc send;
ReceiveFunc receive;
TesterDoerFunc run;
TesterDoerFunc deinit;
void *data;
};
#define VZWL_INIT_CHECK_TYPE \
if (lpComp->type != Uninitialized) { \
lWARNln(LOG_NAME, "The specified component is initialized already. Type ID: %d", lpComp->type); \
ENDED; \
return false; \
}
#define VZWL_INIT_COMMON(typeValue, idValue) \
lpComp->type = (typeValue); \
lpComp->id = (idValue); \
lpComp->send = _send; \
lpComp->receive = _receive; \
lpComp->run = _run; \
lpComp->deinit = _deinit; \
lpComp->data = data;
#define VZWL_DEINIT_CHECK_TYPE(typeValue, displayName) \
if (lpThisComp->type != (typeValue)) { \
lWARNln(LOG_NAME, "The specified component is not a " #displayName ". Type ID: %d", lpThisComp->type); \
ENDED; \
return false; \
}
#define VZWL_DEINIT_COMMON \
lpThisComp->type = Uninitialized; \
lpThisComp->send = nullptr; \
lpThisComp->receive = nullptr; \
lpThisComp->run = nullptr; \
lpThisComp->deinit = nullptr; \
lpThisComp->data = nullptr;
namespace logging
{
typedef struct ::tm *LpDateTime;
typedef std::string LogLevel;
typedef std::string LogName;
#define VZWL_LOG_NS vzwl::logging
#define VZWL_LOG_LEVEL VZWL_LOG_NS::LogLevel
#define VZWL_LOG_LEVEL_NULL ((VZWL_LOG_LEVEL)("NULL" ))
#define VZWL_LOG_LEVEL_PRINT ((VZWL_LOG_LEVEL)("PRINT"))
#define VZWL_LOG_LEVEL_TRACE ((VZWL_LOG_LEVEL)("TRACE"))
#define VZWL_LOG_LEVEL_DEBUG ((VZWL_LOG_LEVEL)("DEBUG"))
#define VZWL_LOG_LEVEL_INFO ((VZWL_LOG_LEVEL)("INFO" ))
#define VZWL_LOG_LEVEL_WARN ((VZWL_LOG_LEVEL)("WARN" ))
#define VZWL_LOG_LEVEL_BUG ((VZWL_LOG_LEVEL)("BUG" ))
#define VZWL_LOG_LEVEL_ERROR ((VZWL_LOG_LEVEL)("ERROR"))
#define VZWL_LOG_LEVEL_FATAL ((VZWL_LOG_LEVEL)("FATAL"))
#define VZWL_LOG_BEGIN(name) VZWL_LOG_NS::lTRACEln(name, "Executing `%s`...", __PRETTY_FUNCTION__);
#define VZWL_LOG_ENDED(name) VZWL_LOG_NS::lTRACEln(name, "Completed `%s`!", __PRETTY_FUNCTION__);
bool init (cstr_t tag );
void deinit (ReturnCode ret );
LpDateTime getDtNow(LpDateTime result );
void lprintf (LogLevel logLevel, LogName logName, cstr_t messageFormat, ...);
void lprintln(LogLevel logLevel, LogName logName, cstr_t messageFormat, ...);
void lPRINTf ( LogName logName, cstr_t messageFormat, ...);
void lPRINTln( LogName logName, cstr_t messageFormat, ...);
void lTRACEf ( LogName logName, cstr_t messageFormat, ...);
void lTRACEln( LogName logName, cstr_t messageFormat, ...);
void lDEBUGf ( LogName logName, cstr_t messageFormat, ...);
void lDEBUGln( LogName logName, cstr_t messageFormat, ...);
void lINFOf ( LogName logName, cstr_t messageFormat, ...);
void lINFOln ( LogName logName, cstr_t messageFormat, ...);
void lWARNf ( LogName logName, cstr_t messageFormat, ...);
void lWARNln ( LogName logName, cstr_t messageFormat, ...);
void lBUGf ( LogName logName, cstr_t messageFormat, ...);
void lBUGln ( LogName logName, cstr_t messageFormat, ...);
void lERRORf ( LogName logName, cstr_t messageFormat, ...);
void lERRORln( LogName logName, cstr_t messageFormat, ...);
void lFATALf ( LogName logName, cstr_t messageFormat, ...);
void lFATALln( LogName logName, cstr_t messageFormat, ...);
}
namespace processor
{
bool init(LpComponent lpComp, size_t compCount);
}
namespace memory
{
bool init(LpComponent lpComp, ComponentId id, size_t size, void *buf);
}
namespace storage
{
bool init(LpComponent lpComp, ComponentId id, size_t size, cstr_t fname);
}
}
#endif // VUUZWAAIL_HPP