Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ahDefs.C
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
33# include <ahDefs.H>
34# include <mutex>
35
36# define STR_LOG_LEN 256
37
38namespace Aleph
39{
40 bool daemonized = false;
41
43
44 bool verbose = false;
45
46 double max_time = 300; // seconds
47}
48
49/* void Aleph::syslog(const char * format, va_list ap) */
50/* { */
51/* int str_log_len = STR_LOG_LEN; */
52
53/* repeat: */
54/* //TODO: apartar el arreglo con obstack */
55/* char log_str[str_log_len + 1]; */
56/* int written_bytes = vsnprintf(log_str, str_log_len, format, ap); */
57/* if (written_bytes < str_log_len && written_bytes > -1) */
58/* { */
59/* ::syslog(LOG_NOTICE, "%s", log_str); */
60/* return; */
61/* } */
62
63/* str_log_len = written_bytes; */
64
65/* goto repeat; */
66/* } */
67
68
69static std::mutex aleph_message_mutex;
70
71# ifdef MESSAGES
72void Aleph::message(const char* file, int line, const char* format, ...)
73{
74 std::lock_guard<std::mutex> critical_section(aleph_message_mutex);
75
76 va_list ap;
77
78 va_start(ap, format);
79
80 /* if (Aleph::daemonized) */
81 /* { */
82 /* ::syslog(LOG_NOTICE, "%s: %u\n", file, line); */
83 /* Aleph::syslog(format, ap); */
84 /* } */
85 /* else */
86 /* { */
87 printf("%s:%u\n", file, line);
88 vfprintf(stdout, format, ap);
89 printf("\n");
90 /* } */
91 va_end(ap);
92}
93# else
94
95void Aleph::message(const char*, int, const char*, ...) { }
96
97# endif
98
99
100void Aleph::error(const char* file, int line, const char* format, ...)
101{
102 std::lock_guard<std::mutex> critical_section(aleph_message_mutex);
103
104 va_list ap;
105
106 va_start(ap, format);
107
108 /* if (Aleph::daemonized) */
109 /* { */
110 /* ::syslog(LOG_ERR, "Fatal error detected at %s %u\n", file, line); */
111 /* Aleph::syslog(format, ap); */
112 /* } */
113 /* else */
114 /* { */
115 printf("Fatal error detected in %s %u\n", file, line);
116 vfprintf(stdout, format, ap);
117 printf("\n");
118 /* } */
119
120 va_end(ap);
121
122 abort();
123}
124
125void Aleph::exit(const char* file, int line, const char* format, ...)
126{
127 std::lock_guard<std::mutex> critical_section(aleph_message_mutex);
128
129 va_list ap;
130
131 va_start(ap, format);
132
133 /* if (Aleph::daemonized) */
134 /* { */
135 /* ::syslog(LOG_NOTICE, "%s: %u\n", file, line); */
136 /* Aleph::syslog(format, ap); */
137 /* } */
138 /* else */
139 /* { */
140 vfprintf(stdout, format, ap);
141 printf("%s:%u\n", file, line);
142 printf("\n");
143 /* } */
144
145 va_end(ap);
146
147 ::exit(0);
148}
149
150
151void Aleph::warning(const char* file, int line, const char* format, ...)
152{
153 std::lock_guard<std::mutex> critical_section(aleph_message_mutex);
154
155 va_list ap;
156
157 va_start(ap, format);
158
159 /* if (daemonized) */
160 /* { */
161 /* ::syslog(LOG_WARNING, "Warning detected in %s %u\n", file, line); */
162 /* Aleph::syslog(format, ap); */
163 /* } */
164 /* else */
165 /* { */
166 printf("Warning detected in %s %u\n", file, line);
167 vfprintf(stdout, format, ap);
168 printf("\n");
169 /* } */
170
171 va_end(ap);
172}
static std::mutex aleph_message_mutex
Definition ahDefs.C:69
Core definitions, constants, and utility macros for Aleph-w.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
const IPv4_Address Null_IPv4_Address
Null/invalid IPv4 address constant.
Definition ahDefs.C:42
double max_time
Maximum allowed execution time (in seconds).
Definition ahDefs.C:46
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
Definition ahDefs.C:95
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
Definition ahDefs.C:125
void warning(const char *file, int line, const char *format,...)
Print a warning message with file and line info.
Definition ahDefs.C:151
uint32_t IPv4_Address
Type alias for IPv4 addresses stored as 32-bit integers.
Definition ahDefs.H:91
void error(const char *file, int line, const char *format,...)
Print an error message with file and line info.
Definition ahDefs.C:100
bool daemonized
Flag indicating if the process is running as a daemon.
Definition ahDefs.C:40
bool verbose
Flag enabling verbose output.
Definition ahDefs.C:44
ofstream file
Definition writeRb.C:51