-
Notifications
You must be signed in to change notification settings - Fork 0
/
irserror.h
762 lines (662 loc) · 20.5 KB
/
irserror.h
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
//! \file
//! \ingroup error_processing_group
//! \brief Îáðàáîòêà îøèáîê
//!
//! Äàòà: 27.01.2011\n
//! Ðàííÿÿ äàòà: 16.09.2009
#ifndef IRSERRORH
#define IRSERRORH
// Íîìåð ôàéëà
#define IRSERRORH_IDX 6
#define IRS_ERROR_OUT_STATIC_EVENT
#include <irsdefs.h>
#ifdef __ICCAVR__
#include <pgmspace.h>
#endif //__ICCAVR__
#ifdef __BORLANDC__
#include <sysutils.hpp>
#endif //__BORLANDC__
#ifdef __ICCAVR__
#include <irsavrutil.h>
#endif //__ICCAVR__
#ifdef __ICCARM__
#ifndef IRS_STM32H7xx
#include <irsarmutil.h>
#endif // IRS_STM32H7xx
#endif // __ICCARM__
#include <irsconfig.h>
#include <irsdefs.h>
#include <irsint.h>
#include <irstime.h>
#include <irscpp.h>
#include <irsstrdefs.h>
#if defined(IRS_WIN32)
// Standart Windows headers
#include <winsock2.h>
#elif defined(IRS_LINUX)
// Standart Linux headers
#include <errno.h>
#endif // defined(IRS_LINUX)
#include <irsfinal.h>
//! \addtogroup error_processing_group
//! @{
// Îïåðàòîðû ñïåöèàëüíîãî âûâîäà irsm è irsu
#ifdef __ICCAVR__
#define irsm(cstr)\
""; { static char const IRS_ICCAVR_FLASH dbg_msg_cstring[] = cstr;\
irs::mlog() << dbg_msg_cstring; } irs::mlog() << ""
#else //__ICCAVR__
#define irsm(cstr) cstr
#endif //__ICCAVR__
#ifdef __ICCAVR__
#define IRS_STRM_ICCAVR_FLASH_OUT(out_stream, flash_string)\
{\
static char const IRS_ICCAVR_FLASH irs_stream_flash_string[] =\
flash_string;\
out_stream << irs_stream_flash_string;\
}
#define irsu(out_stream, spec_string)\
""; IRS_STRM_ICCAVR_FLASH_OUT(out_stream, spec_string); out_stream << ""
#else //__ICCAVR__
#define irsu(out_stream, spec_string) spec_string
#endif //__ICCAVR__
#ifdef __ICCAVR__
// Îïåðàöèÿ ñäâèãà äëÿ âûâîäà ñòðîê ðàçìåùåííûõ âî Flash â ïîòîê
// Âíå ïðîñòðàíñòâà èìåí irs ðàçìåùåíà íàìåðåííî
inline ostream& operator<<(ostream& a_strm,
char const IRS_ICCAVR_FLASH* ap_strg)
{
for (;*ap_strg != 0; ap_strg++) {
char out_char = *ap_strg;
a_strm << out_char;
}
return a_strm;
}
#ifdef NOP
// Ðåàëèçàöèÿ êîòîðîàÿ â áóäóùåì ìîæåò ïîíàäîáèòñÿ
// !!! Ïðîñüáà íå óäàëÿòü
inline ostream& operator<<(ostream& a_strm,
char const IRS_ICCAVR_FLASH* ap_strg)
{
enum {
buf_size = 100
};
static char buf[buf_size + 1] = { 0 };
#ifdef IRS_LIB_DEBUG
if (buf[buf_size] != 0) {
static char const IRS_ICCAVR_FLASH p_msg_no_zero_terminator[] =
"Â îïåðàòîðå ñäâèãà äëÿ ñòðîê âî Flash â áóôåðå îòñóòñòâóåò "
"çàâåðøàþùèé íóëü";
a_strm << endl << p_msg_no_zero_terminator << endl;
for (;;);
}
#endif //IRS_LIB_DEBUG
const size_t strg_size = strlen_G(ap_strg);
const size_t part_cnt = strg_size/buf_size;
char const IRS_ICCAVR_FLASH* strg_end = ap_strg + strg_size;
for (size_t part_idx = 0; part_idx < part_cnt; ++part_idx) {
char const IRS_ICCAVR_FLASH* strg_part_end = ap_strg + buf_size;
copy(ap_strg, strg_part_end, buf);
a_strm << buf;
ap_strg = strg_part_end;
}
if (ap_strg < strg_end) {
copy(ap_strg, strg_end, buf);
buf[strg_end - ap_strg] = 0;
a_strm << buf;
}
return a_strm;
}
#endif //NOP
#endif //__ICCAVR__
#ifdef IRS_LIB_FLASH_ASSERT
#define IRS_ASSERT_HELPER(error_code, assert_expr, message)\
{\
IRS_SPEC_CSTR_DECLARE(assert_expr_fstr, #assert_expr);\
IRS_SPEC_CSTR_DECLARE(file_fstr, __FILE__);\
IRS_SPEC_CSTR_DECLARE(message_fstr, message);\
irs::error_trans()->throw_error(error_code, file_fstr, __LINE__,\
irs::spec_assert(assert_expr_fstr, message_fstr));\
}
#else //IRS_LIB_FLASH_ASSERT
#define IRS_ASSERT_HELPER(error_code, assert_expr, message)\
{\
irs::error_trans()->throw_error(error_code, __FILE__, __LINE__,\
irs::spec_assert(#assert_expr, message));\
}
#endif //IRS_LIB_FLASH_ASSERT
#define IRS_ASSERT(assert_expr)\
{\
if (!(assert_expr)) {\
IRS_ASSERT_HELPER(irs::ec_assert, assert_expr, "");\
}\
}
#define IRS_ASSERT_EX(assert_expr, msg)\
{\
if (!(assert_expr)) {\
IRS_ASSERT_HELPER(irs::ec_assert, assert_expr, msg);\
}\
}
#define IRS_ASSERT_MSG(msg)\
{\
IRS_ASSERT_HELPER(irs::ec_assert, "Assert", msg);\
}
// Ýòîò êîä ìîæåò ïîíàäîáèòñÿ. Íå óäàëÿòü!
#ifdef NOP
#define IRS_DELETE_ASSERT(delete_var)\
{\
operator delete(delete_var, nothrow);\
delete_var = IRS_NULL;\
}
#define IRS_ARRAY_DELETE_ASSERT(delete_var)\
{\
operator delete[](delete_var, nothrow);\
delete_var = IRS_NULL;\
}
#endif //NOP
#ifdef IRS_LIB_FLASH_ASSERT
#define IRS_NEW_ASSERT(new_expr, file_idx)\
(irs::new_assert(new (nothrow) new_expr, file_idx, __LINE__))
#else //IRS_LIB_FLASH_ASSERT
#define IRS_NEW_ASSERT(new_expr, file_idx)\
(new new_expr)
#endif //IRS_LIB_FLASH_ASSERT
#define IRS_LIB_DELETE_ASSERT(delete_var)\
{\
delete (delete_var);\
void** void_ptr = reinterpret_cast<void**>(&(delete_var));\
*void_ptr = IRS_NULL;\
}
#define IRS_LIB_ARRAY_DELETE_ASSERT(delete_var)\
{\
delete[] (delete_var);\
void** void_ptr = reinterpret_cast<void**>(&(delete_var));\
*void_ptr = IRS_NULL;\
}
#ifdef IRS_LIB_FLASH_ASSERT
#define IRS_ERROR_HELPER(error_code, spec_data)\
{\
const void* message_spec = IRS_NULL;\
if (sizeof(char const IRS_ICCAVR_FLASH*) == sizeof(void*)) {\
IRS_SPEC_CSTR_DECLARE(message_fstr, spec_data);\
message_spec = reinterpret_cast<const void*>(message_fstr);\
} else {\
irs::mlog() << irsm("Íåñîîòâåòñòâèå ðàçìåðîâ óêàçàòåëÿ ñïåöèàëüíîãî ");\
irs::mlog() << irsm("òèïà C-ñòðîêè (char const IRS_ICCAVR_FLASH*) è");\
irs::mlog() << irsm("ñòàíäàðòíîãî (const char*) â ìàêðîñå ");\
irs::mlog() << irsm("IRS_ERROR_HELPER\n");\
irs::mlog() << irsm("Òåêñò ñîîáùåíèÿ: ") << irsm(spec_data);\
irs::mlog() << irsm("\nÄàëåå ñëåäóåò âûâîä ñîîáùåíèÿ îá îøèáêå ");\
irs::mlog() << irsm("áåç ýòîãî ñîîáùåíèÿ...\n") << endl;\
IRS_SPEC_CSTR_DECLARE(empty_fstr, "");\
message_spec = reinterpret_cast<const void*>(empty_fstr);\
}\
IRS_SPEC_CSTR_DECLARE(file_fstr, __FILE__);\
irs::error_trans()->throw_error(error_code, file_fstr, __LINE__,\
message_spec);\
}
#else //IRS_LIB_FLASH_ASSERT
#define IRS_ERROR_HELPER(error_code, spec_data)\
{\
irs::error_trans()->throw_error(error_code, __FILE__, __LINE__,\
static_cast<const void*>(spec_data));\
}
#endif //IRS_LIB_FLASH_ASSERT
#define IRS_ERROR(error_code, msg)\
{\
IRS_ERROR_HELPER(error_code, msg);\
}
#define IRS_ERROR_IF(assert_expr, error_code, msg)\
{\
if (assert_expr) {\
IRS_ERROR_HELPER(error_code, msg);\
}\
}
#define IRS_ERROR_IF_NOT(assert_expr, error_code, msg)\
{\
IRS_ERROR_IF(!(assert_expr), error_code, msg);\
}
#define IRS_FATAL_ERROR(msg) IRS_ERROR(irs::ec_fatal_error, msg)
#define IRS_DBG_RAW_MSG(msg)\
{\
irs::mlog() << msg;\
}
#define IRS_DBG_MSG(msg)\
{\
irs::mlog() << irs::sdatetime << msg << endl;\
}
#define IRS_DBG_MSG_IF(assert_expr, msg)\
{\
if (assert_expr) {\
IRS_DBG_MSG(msg);\
}\
}
#define IRS_DBG_MSG_SRC(msg)\
{\
irs::mlog() << irs::sdatetime << "Ôàéë: " << __FILE__;\
irs::mlog() << "; Ñòðîêà: " << __LINE__;\
irs::mlog() << "; Ôóíêöèÿ: " << __FUNC__ << "; ";\
irs::mlog() << msg << endl;\
}
#define IRS_DBG_MSG_SRC_ENG(msg)\
{\
irs::mlog() << irs::sdatetime << "File: " << __FILE__;\
irs::mlog() << "; Line: " << __LINE__;\
irs::mlog() << "; Function: " << __FUNC__ << "; ";\
irs::mlog() << msg << endl;\
}
#if defined(IRS_WIN32) || defined(IRS_LINUX)
#define IRS_SEND_LAST_ERROR()\
irs::send_last_message_err(__FILE__,__LINE__)
#define IRS_SEND_ERROR(error_code)\
irs::send_message_err(error_code,__FILE__,__LINE__)
#endif // defined(IRS_WIN32) || defined(IRS_LINUX)
#if defined(IRS_WIN32)
#define IRS_SEND_WIN_WSA_LAST_ERROR()\
irs::send_wsa_last_message_err(__FILE__,__LINE__)
#endif // IRS_WIN32
#ifdef IRS_LIB_DEBUG
#define IRS_LIB_ASSERT(assert_expr) IRS_ASSERT(assert_expr)
#define IRS_LIB_ASSERT_EX(assert_expr, msg) IRS_ASSERT_EX(assert_expr, msg)
#define IRS_LIB_ASSERT_MSG(msg) IRS_ASSERT_MSG(msg)
#define IRS_LIB_NEW_ASSERT(new_expr, file_idx)\
IRS_NEW_ASSERT(new_expr, file_idx)
#define IRS_LIB_ERROR(error_code, msg) IRS_ERROR(error_code, msg)
#define IRS_LIB_ERROR_IF(assert_expr, error_code, msg)\
IRS_ERROR_IF(assert_expr, error_code, msg)
#define IRS_LIB_ERROR_IF_NOT(assert_expr, error_code, msg)\
IRS_ERROR_IF_NOT(assert_expr, error_code, msg)
#define IRS_LIB_FATAL_ERROR(msg) IRS_FATAL_ERROR(msg)
#define IRS_LIB_DBG_RAW_MSG(msg) IRS_DBG_RAW_MSG(msg)
#define IRS_LIB_DBG_MSG(msg) IRS_DBG_MSG(msg)
#define IRS_LIB_DBG_MSG_IF(assert_expr, msg) IRS_DBG_MSG_IF(assert_expr, msg)
#define IRS_LIB_DBG_MSG_SRC(msg) IRS_DBG_MSG_SRC(msg)
#define IRS_LIB_DBG_MSG_SRC_ENG(msg) IRS_DBG_MSG_SRC_ENG(msg)
#define IRS_LIB_SEND_LAST_ERROR() IRS_SEND_LAST_ERROR()
#define IRS_LIB_SEND_ERROR() IRS_SEND_ERROR()
#define IRS_LIB_SEND_WIN_WSA_LAST_ERROR() IRS_SEND_WIN_WSA_LAST_ERROR()
#else // IRS_LIB_DEBUG
#define IRS_LIB_ASSERT(assert_expr)
#define IRS_LIB_ASSERT_EX(assert_expr, msg)
#define IRS_LIB_ASSERT_MSG(msg)
#define IRS_LIB_NEW_ASSERT(new_expr, file_idx) (new new_expr)
#define IRS_LIB_ERROR(error_code, msg)
#define IRS_LIB_ERROR_IF(assert_expr, error_code, msg)
#define IRS_LIB_ERROR_IF_NOT(assert_expr, error_code, msg)
#define IRS_LIB_FATAL_ERROR(msg)
#define IRS_LIB_DBG_RAW_MSG(msg)
#define IRS_LIB_DBG_MSG(msg)
#define IRS_LIB_DBG_MSG_IF(assert_expr, msg)
#define IRS_LIB_DBG_MSG_SRC(msg)
#define IRS_LIB_DBG_MSG_SRC_ENG(msg)
#define IRS_LIB_SEND_LAST_ERROR()
#define IRS_LIB_SEND_ERROR()
#define IRS_LIB_SEND_WIN_WSA_LAST_ERROR()
#endif // IRS_LIB_DEBUG
#ifdef IRS_LIB_DBG_KRASHENINNIKOV_MAXIM
#define IRS_LIB_DBG_MSG_KMV(msg) IRS_LIB_DBG_RAW_MSG(msg)
#else //IRS_LIB_DBG_KRASHENINNIKOV_MAXIM
#define IRS_LIB_DBG_MSG_KMV(msg)
#endif //IRS_LIB_DBG_KRASHENINNIKOV_MAXIM
//! @}
namespace irs {
//! \addtogroup error_processing_group
//! @{
// Òèï äëÿ êîäîâ îøèáîê
typedef irs_u16 error_code_t;
// Ñòàíäàðòíûé êîä îøèáêè (â ap_spec_data ñîäåðæèòñÿ ñîîáùåíèå â âèäå char*)
const error_code_t ec_standard = 0;
// Êîä îøèáêè äëÿ óòâåðæäåíèé (ap_spec_data òèïà et_spec_assert_t*)
const error_code_t ec_assert = 1;
// Êîä ôàòàëüíîé îøèáêè (ap_spec_data òèïà char*)
const error_code_t ec_fatal_error = 2;
// Êîä îøèáêè äëÿ óòâåðæäåíèé îïåðàòîðà new (ap_spec_data òèïà int*)
const error_code_t ec_new_assert = 3;
// Ïîëüçîâàòåëüñêèå êîäû îøèáîê
const error_code_t ec_user = 4;
// Ïðèåìî-ïåðåäàò÷èê îøèáîê (Èíòåðôåéñ)
class error_trans_base_t
{
public:
#ifdef IRS_LIB_FLASH_ASSERT
typedef char const IRS_ICCAVR_FLASH* cstr_type;
#else //IRS_LIB_FLASH_ASSERT
typedef const char* cstr_type;
#endif //IRS_LIB_FLASH_ASSERT
virtual ~error_trans_base_t() {}
// Ïåðåäàòü îøèáêó (òèï ap_spec_data îïðåäåëÿåòñÿ a_error_code)
virtual void throw_error(
error_code_t a_error_code = ec_standard,
cstr_type ap_file_name = 0,
int a_line_number = 0,
const void *ap_spec_data = 0
) = 0;
// Ñ÷èòàòü ïîñëåäíèé êîä îøèáêè
virtual error_code_t error_code() = 0;
// Ñ÷èòàòü èìÿ ôàéëà â êîòîðîì ïðîèçîøëà ïîñëåäíÿÿ îøèáêà
virtual cstr_type file_name() = 0;
// Ñ÷èòàòü íîìåð ñòðîêè â ôàéëå â êîòîðîé ïðîèçîøëà îøèáêà
virtual int line_number() = 0;
// Ñ÷èòàòü ñïåöèôè÷åñêèå äàííûå ñîîòâåòñòâóþùèå êîäó îøèáêè
virtual const void *spec_data() = 0;
// Äîáàâèòü îáðàáîò÷èê îøèáêè
virtual void add_handler(mxfact_event_t *ap_handler) = 0;
};
// Ïðèåìî-ïåðåäàò÷èê îøèáîê (Ñ÷èòûâàíèå óêàçàòåëÿ íà ýêçåìïëÿð)
error_trans_base_t *error_trans();
// Ñïåöèôè÷åñêèå äàííûå äëÿ óòâåðäåíèé â error_trans_base_t
struct et_spec_assert_t
{
// Óòâåðæäåíèå
error_trans_base_t::cstr_type assert_str;
// Ñîîáùåíèå
error_trans_base_t::cstr_type message;
};
// Ñïåöèôè÷åñêèå äàííûå äëÿ óòâåðäåíèé â error_trans_base_t
// (Ñ÷èòûâàíèå óêàçàòåëÿ íà ýêçåìïëÿð)
const void *spec_assert(error_trans_base_t::cstr_type assert_str,
error_trans_base_t::cstr_type message);
// Âûâîä èíôîðìàöèè îá îøèáêå äëÿ îáðàáîò÷èêîâ îøèáîê
class error_out_t
{
public:
typedef error_out_t this_type;
typedef event_function_t<this_type> out_func_obj_type;
enum {
m_out_func_list_def_size = ec_user
};
error_out_t(error_trans_base_t* ap_error_trans,
irs_size_t a_out_func_list_size = m_out_func_list_def_size);
void out_general_info(ostream &a_out,
error_trans_base_t::cstr_type ap_error_type);
void out_info(ostream &a_out);
void insert_out_func(error_code_t a_error_code,
event_t* ap_out_func);
void erase_out_func(error_code_t a_error_code);
private:
error_trans_base_t* mp_error_trans;
vector<event_t*> m_out_func_ptr_list;
out_func_obj_type m_out_unknown_error_obj;
#ifdef IRS_ERROR_OUT_STATIC_EVENT
out_func_obj_type m_out_standart_error_obj;
out_func_obj_type m_out_assert_error_obj;
out_func_obj_type m_out_fatal_error_obj;
out_func_obj_type m_out_new_assert_error_obj;
#else //IRS_ERROR_OUT_STATIC_EVENT
vector<out_func_obj_type> m_out_func_obj_list;
#endif //IRS_ERROR_OUT_STATIC_EVENT
ostream* mp_out;
#ifndef IRS_ERROR_OUT_STATIC_EVENT
static event_t* out_func_obj_extract_ptr(
out_func_obj_type& a_out_func_obj);
#endif //IRS_ERROR_OUT_STATIC_EVENT
void out_standart_error();
void out_assert_error();
void out_fatal_error();
void out_new_assert_error();
void out_unknown_error();
bool is_valid_error_code(error_code_t a_error_code);
error_trans_base_t* error_trans();
};
// Îáðàáîò÷èê îøèáîê äëÿ âûâîäà â ostream
class ostream_error_handler_t: public mxfact_event_t
{
private:
ostream* mp_out;
error_out_t m_error_out;
void exec()
{
mxfact_event_t::exec();
if (mp_out) {
m_error_out.out_info(*mp_out);
}
}
public:
ostream_error_handler_t(
ostream* ap_out = IRS_NULL,
error_trans_base_t* ap_error_trans = error_trans()
):
mp_out(ap_out),
m_error_out(ap_error_trans)
{
ap_error_trans->add_handler(this);
}
void out(ostream* ap_out)
{
mp_out = ap_out;
}
};
// Îáðàáîò÷èê îøèáîê äëÿ âûâîäà â ostream ñïåöèàëüíî äëÿ AVR
// c îñòàíîâêîé ïî îøèáêå è ìèãàíèåì ñâåòîäèîäà
#ifdef IRS_MICROCONTROLLER
#if not defined(IRS_STM32H7xx) && not defined(IRS_GCC_CORTEX_M)
class mc_error_handler_t: public mxfact_event_t
{
private:
ostream* mp_out;
error_out_t m_error_out;
blink_t m_error_blink;
void exec()
{
mxfact_event_t::exec();
if (mp_out) {
m_error_out.out_info(*mp_out);
}
for (;;) m_error_blink();
}
public:
mc_error_handler_t(
#ifdef __ICCAVR__
irs_avr_port_t a_error_blink_port,
#endif // __ICCAVR__
#ifdef __ICCARM__
arm_port_t& a_error_blink_port,
#endif // __ICCARM__
irs_u8 a_error_blink_bit,
ostream* ap_out = IRS_NULL,
error_trans_base_t* ap_error_trans = error_trans()
):
mp_out(ap_out),
m_error_out(ap_error_trans),
m_error_blink(a_error_blink_port, a_error_blink_bit, make_cnt_ms(50))
{
ap_error_trans->add_handler(this);
}
void out(ostream* ap_out)
{
mp_out = ap_out;
}
};
typedef mc_error_handler_t avr_error_handler_t;
#endif // IRS_STM32H7xx
class mc_error_handler_ex_t: public mxfact_event_t
{
private:
ostream* mp_out;
event_t* mp_error_event;
error_out_t m_error_out;
void exec()
{
mxfact_event_t::exec();
if (mp_out) {
m_error_out.out_info(*mp_out);
}
if (mp_error_event) {
mp_error_event->exec();
}
for (;;);
}
public:
mc_error_handler_ex_t(
ostream* ap_out,
event_t* ap_error_event = IRS_NULL,
error_trans_base_t* ap_error_trans = error_trans()
):
mp_out(ap_out),
mp_error_event(ap_error_event),
m_error_out(ap_error_trans)
{
ap_error_trans->add_handler(this);
}
void out(ostream* ap_out)
{
mp_out = ap_out;
}
void add_blink_event(event_t* ap_event)
{
mp_error_event = ap_event;
}
};
#endif //IRS_MICROCONTROLLER
// Îáðàáîò÷èê îøèáîê äëÿ âûâîäà îøèáîê â âèäå èñêëþ÷åíèÿ
#ifdef IRS_FULL_STDCPPLIB_SUPPORT
class exception_error_handler_t: public mxfact_event_t
{
private:
error_out_t m_error_out;
bool m_is_first_throw;
void exec()
{
mxfact_event_t::exec();
if (m_is_first_throw) {
m_is_first_throw = true;
ostringstream out_stream;
m_error_out.out_info(out_stream);
out_stream << '\0';
#ifdef __BORLANDC__
throw Exception(out_stream.str().c_str());
#else //__BORLANDC__
throw runtime_error(out_stream.str().c_str());
#endif //__BORLANDC__
}
m_is_first_throw = true;
}
public:
exception_error_handler_t(
error_trans_base_t* ap_error_trans = error_trans()
):
m_error_out(ap_error_trans),
m_is_first_throw(true)
{
ap_error_trans->add_handler(this);
}
};
#endif //IRS_FULL_STDCPPLIB_SUPPORT
#if (__IAR_SYSTEMS_ICC__ >= 9) || defined(IRS_FULL_STDCPPLIB_SUPPORT)
template<typename char_type, typename traits_type = char_traits<char_type>>
class basic_zerobuf : public basic_streambuf<char_type, traits_type>
{
public:
typedef typename traits_type::int_type int_type;
virtual int_type overflow(int_type = EOF)
{ return 0; }
virtual int_type underflow()
{ return 0; }
virtual int sync()
{ return this->overflow(); }
};
typedef basic_zerobuf<char> zerobuf;
typedef basic_zerobuf<wchar_t> wzerobuf;
template<class T>
basic_ostream<T>& basic_mlog()
{
static basic_zerobuf<T> buf;
static basic_ostream<T> mlog_obj(&buf);
return mlog_obj;
}
wostream& wmlog();
#else //(__IAR_SYSTEMS_ICC__ >= 9) || defined(IRS_FULL_STDCPPLIB_SUPPORT)
class zerobuf: public streambuf
{
public:
virtual int overflow(int = EOF)
{
return 0;
}
virtual int underflow()
{
return 0;
}
virtual int sync()
{
return overflow();
}
};
#endif // (__IAR_SYSTEMS_ICC__ >= 9) || defined(IRS_FULL_STDCPPLIB_SUPPORT)
ostream& mlog();
#ifndef __WATCOMC__
// Áèáëèîòåêà Watcom C++ íå ïîääåðæèâàåò óñòàíîâêó íîâîãî áóôåðà ÷åðåç rdbuf
class ostream_buf_init_t
{
public:
ostream_buf_init_t(ostream* ap_strm, streambuf *ap_buf)
{
ap_strm->rdbuf(ap_buf);
}
};
#endif //__WATCOMC__
#if defined(IRS_WIN32) || defined(IRS_LINUX)
int last_error_code();
irs::string last_error_str();
irs::string error_str(int a_error_code);
void send_format_msg(int a_error_code, const char* ap_file, int a_line);
void send_last_message_err(const char* ap_file, int a_line);
void send_wsa_last_message_err(const char* ap_file, int a_line);
void send_message_err(int a_error_code, const char* ap_file, int a_line);
#endif // defined(IRS_WIN32) || defined(IRS_LINUX)
#ifdef IRS_LIB_FLASH_ASSERT
template <class T>
T* new_assert(T* a_new_expr, int a_file_idx, int a_line)
{
if (a_new_expr == IRS_NULL) {
static int a_file_idx_hold = a_file_idx;
//static char const IRS_ICCAVR_FLASH empty_fstr[] = "";
irs::error_trans()->throw_error(irs::ec_new_assert, IRS_NULL, a_line,
&a_file_idx_hold);
}
return a_new_expr;
}
#else //IRS_LIB_FLASH_ASSERT
template <class T>
T* new_assert(T* a_new_expr, error_trans_base_t::cstr_type a_file,
int a_line)
{
if (a_new_expr == IRS_NULL) {
irs::error_trans()->throw_error(irs::ec_assert, a_file, a_line,
irs::spec_assert("new != NULL", IRS_NULL));
}
return a_new_expr;
}
#endif //IRS_LIB_FLASH_ASSERT
class debug_param_t
{
public:
typedef string_t string_type;
virtual void set(const string_type& a_name, size_t a_value_num) = 0;
virtual size_t get(const string_type& a_name) const = 0;
virtual bool is_exist(const string_type& a_name) const = 0;
};
debug_param_t& debug_param();
template <class T>
void debug_param_set_ptr(const string_t& a_name, const T* ap_ptr)
{
irs::debug_param().set(a_name, reinterpret_cast<size_t>(ap_ptr));
}
template <class T>
bool debug_param_check_ptr(const string_t& a_name, const T* ap_ptr)
{
bool is_ptr_equal = false;
bool is_param_exist = irs::debug_param().is_exist(a_name);
if (is_param_exist) {
size_t debuged_ptr_num = irs::debug_param().get(a_name);
const T* debuged_ptr = reinterpret_cast<const T*>(debuged_ptr_num);
if (ap_ptr == debuged_ptr) {
is_ptr_equal = true;
}
}
return is_ptr_equal;
}
irs_string_t conv_notprintable_to_hex(const irs_string_t& a_str);
//! @}
} //namespace irs
#endif //IRSERRORH