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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
|
/******************************************************************************
* File name : distributor.c
* Title : REPORT PACKAGE - Message Distributor
* Date created : 01 SEP, 1996
* Revision : 1.0
* Author : Zvika Zilberman
*
* Description : Report distributor provides the duplicating of
* messages to the several destinations.
*
******************************************************************************
*
* Procedures:
*
* ReportFd - Add or remove file descriptor to/from the
* list of destinations
* ReportFunc - Add or remove funtion to/from the list of
* destnations
* ReportEnableAll - Resume the work of distributor
*
* Functions, internal for Report:
*
* distibutorInit - Initialize message distributor
* reportDistribute - Send message to destibutor
*
* Local functions:
*
* messageDistribute - Forward message to all destinations.
* reportService - Distibutor Task main function
*
******************************************************************************
*
* History:
* 01.09.96 Ilia Maller - start of coding
* 21.02.97 Ilia Maller - minor improvements
* 17.09.97 Zvika Zilberman - porting to DCME SWINFRA
*
******************************************************************************/
/*------------- Includes --------------------------------*/
#include "include.h"
#include "report.h"
#include "filter.h"
#include "distributor.h"
/*------------- Local Definitions -----------------------*/
#define SEVERITY_MASK(severity) ((severity) & 0x10)
#define REPORT_ROOT_NAME "system"
#define REPORT_TASK_STACK_SIZE 1024
typedef struct
{
FormatType format;
char *message;
char *FileName;
int LineNumber;
int errorCode;
ErrorSeverity severity;
int parameter1;
int parameter2;
}INPUT_MESSAGE;
#define INPUT_MESSAGE_LEN sizeof(INPUT_MESSAGE)
ReportFunction ReportFunc1 = NULL;
ReportFunction ReportFunc2 = NULL;
typedef struct
{
int fd;
ReportFunction function;
}DESTINATION;
#define DESTINATION_SIZE sizeof(DESTINATION)
#define NUM_OF_DESTINATIONS 2
typedef struct
{
char name[11];
bool IsActive; /* false - discard its messages. true - send them. */
bool IsAlive; /* false - if not in action, can not be used or seen */
DESTINATION dest[NUM_OF_DESTINATIONS];
} DistributorElement;
static void messageDistribute(char *msg,
int DistTableEntry,
char *FileName,
int LineNumber,
int errorCode,
int parameter1,
int parameter2);
/*static STATUS reportFormat(char *buffer,
int *maxlen,
const char *message,
int errorCode,
ErrorSeverity severity,
int parameter1,
int parameter2);*/
static int FindFreeDestinationElement(int DistTableEntry);
/*------------- Local Data ------------------------------*/
static Mailbox_Handle inputQueue;
/* Table where output of distributor (destinations) stored
Every element of the table may be or file descriptor
or function address.
The destinations stored unsorted */
static DistributorElement *Dist_Table;
static int DistCounter; /* number of current elements in the table */
static int NumOfDistributions;
/***************************************************************************
*
* Name : distibutorInit
*
* Function : Initialize message distributor
*
* Notes : Function uses malloc for memory allocation
*
* Parameters: priority - distributor task priority
* maxMsgs - maximum number of messages stored in
* destributor task queue
* maxDstr - maximum number of distributors
*
* Return value: STATUS - OK or ERROR
**************************************************************************/
STATUS distibutorInit( int priority, int maxMsgs, int maxDstr )
{
static int initialized = false;
int i, j;
if (initialized)
return OK;
NumOfDistributions = maxDstr;
/* create mailbox to recive messages */
inputQueue = Mailbox_create(INPUT_MESSAGE_LEN,maxMsgs, 0,0);
if (inputQueue == NULL)
return ERROR;
/* create table for destionations. malloc takes care about allignment */
Dist_Table = (DistributorElement *)malloc(sizeof(DistributorElement)*(maxDstr+1));
if (Dist_Table == NULL)
return ERROR;
/* initialize table */
for (i=0; i<=maxDstr; i++)
{
for (j=0; j<NUM_OF_DESTINATIONS; j++)
{
Dist_Table[i].dest[j].fd = -1;
Dist_Table[i].dest[j].function = NULL;
}
Dist_Table[i].IsActive = false;
Dist_Table[i].IsAlive = false;
}
/* Reset the internal (basic) distributor */
strcpy(Dist_Table[0].name,REPORT_ROOT_NAME);
Dist_Table[0].IsActive = true;
Dist_Table[0].IsAlive = true;
/* initialize local data */
DistCounter = 1;
initialized = true;
return OK;
}
/***************************************************************************
*
* Name : reportDistribute
*
* Function : Send message to destibutor
*
* Notes : Function trancates message if it length grater
* than INPUT_MESSAGE_LEN
*
* Parameters: message - user message
* extErrorType - error type and severity
* errorCode - error code
* parameter1 - user parameter 1
* parameter2 - user parameter 2
*
* Return value: STATUS - OK or ERROR
**************************************************************************/
STATUS reportDistribute(FormatType format,
char *message,
char *FileName,
int LineNumber,
int errorCode,
ErrorSeverity severity,
int parameter1,
int parameter2)
{
INPUT_MESSAGE msg;
int Distributor = GET_PRIVATE_SEVERITY(severity);
if (isReportActive() == false)
{
LogToFile(message,FileName, LineNumber,errorCode, severity, parameter1);
}
if (Distributor > 0)
{
if (Dist_Table[Distributor].IsAlive == false)
return OK;
if (Dist_Table[Distributor].IsActive == false)
return OK;
}
else if (Dist_Table[0].IsActive == false)
return OK;
/* truncate if message length greater than defined */
msg.format = format;
msg.message = message;
msg.FileName = FileName;
msg.LineNumber = LineNumber;
msg.errorCode = errorCode;
msg.severity = severity;
msg.parameter1 = parameter1;
msg.parameter2 = parameter2;
if (inputQueue != NULL)
Mailbox_post(inputQueue , &msg, BIOS_NO_WAIT);
return OK;
}
/***************************************************************************
*
* Name : reportService
*
* Function : Distibutor Task main function
*
* Notes :
*
* Return value: void
**************************************************************************/
Void reportService(UArg arg0, UArg arg1)
{
INPUT_MESSAGE msg;
//static char buf[REPORT_MAX_MSG_LEN + REPORT_MSG_FORMAT_LEN];
int DistTableEntry;//,msgLen, errCode, par1, par2;
ReportInitParams InitParams;
InitParams.DistributorQueueMaxMsgs = 60;
InitParams.DistributorTaskPriority = 6;
InitParams.MaxNumOfFilterNames = 30;
InitParams.MaxNumberOfPrivateDistributors = 2;
ReportInit (InitParams);
while(1)
{
Mailbox_pend(inputQueue , &msg, BIOS_WAIT_FOREVER);
DistTableEntry = (SEVERITY_MASK(msg.severity) == RpPrivate) ? (msg.severity >> 5) : 0;
// /* format received string */
// /*if (msg.format == REPORT_FORMAT)
// {
// msgLen = REPORT_MAX_MSG_LEN + REPORT_MSG_FORMAT_LEN;
// reportFormat(buf, &msgLen, msg.message, msg.errorCode,
// msg.severity, msg.parameter1, msg.parameter2);
// errCode = msg.errorCode;
// par1 = msg.parameter1;
// par2 = msg.parameter2;
// }
// else /* MESSAGE_FORMAT - regular message */
// {
// msgLen = strlen(msg.message);
// if (msgLen > REPORT_MAX_MSG_LEN-1)
// msgLen = REPORT_MAX_MSG_LEN-1;
// strcpy(buf,msg.message);
// errCode = 0;
// par1 = 0;
// par2 = 0;
// }*/
/* send message to subscribers */
messageDistribute( msg.message, DistTableEntry,msg.FileName, msg.LineNumber,msg.errorCode,msg.severity,msg.parameter1);
}
}
/*----------------------------------------------------------------------------*/
/*----------------------------- Private Severity -----------------------------*/
/*----------------------------------------------------------------------------*/
/***************************************************************************
*
* Name : ReportDistributor
*
* Function : Add static distributor
*
* Notes : The name is given in order to note the severity name
* during the report exception.
*
* Parameters: distributorName - The severity's name must be up to 10
* letters long.
* SwitchAddRemove - REPORT_ADD to add the new static severity,
* REPORT_REMOVE to remove it.
*
* Return value: the new distributor handle, or -1 and thus:
* errno = REPORT_ERROR_NAME_TOO_LONG in case of long name,
* errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the distributor
* was already removed,
* errno = REPORT_ERROR_NAME_NOT_EXISTS if the distributorName
* not exists,
* errno = REPORT_ERROR_TABLE_FULL if there are already too
* many distributors,
* errno = REPORT_ERROR_NAME_EXISTS if the distributorName
* already exists.
**************************************************************************/
DistributorHandle ReportDistributor(const char *distributorName, uint32_t SwitchAddRemove)
{
int index;
if ((DistCounter > NumOfDistributions) && (SwitchAddRemove == REPORT_ADD))
{
errno = REPORT_ERROR_TABLE_FULL;
return -1;
}
if (strlen(distributorName) > 10)
{
errno = REPORT_ERROR_NAME_TOO_LONG;
return -1;
}
else if ((strcmp(distributorName,"system")==0) || ((strcmp(distributorName,"SYSTEM")==0)))
{
errno = REPORT_ERROR_NAME;
return -1;
}
if (IsNameExistsInFiltersTable(distributorName))
{
errno = REPORT_ERROR_NAME_EXISTS;
return -1;
}
for (index=1; index<DistCounter; index++)
if (strcmp(Dist_Table[index].name,distributorName)==0)
{
if (SwitchAddRemove == REPORT_ADD)
{
if (Dist_Table[index].IsAlive)
{
errno = REPORT_ERROR_NAME_EXISTS;
return -1;
}
else
{
Dist_Table[index].IsAlive = true;
return index;
}
}
else /* Private severity disable */
{
if (Dist_Table[index].IsAlive)
{
Dist_Table[index].IsAlive = false;
return index;
}
else
{
errno = REPORT_ERROR_NAME_ALREADY_DISABLE;
return -1;
}
}
}
if (SwitchAddRemove == REPORT_REMOVE)
{
errno = REPORT_ERROR_NAME_NOT_EXISTS;
return -1; /* nothing to remove */
}
strcpy(Dist_Table[DistCounter].name,distributorName);
Dist_Table[DistCounter].IsAlive = true;
DistCounter++;
return (DistCounter-1);
}
/***************************************************************************
*
* Name : ReportAddDistributor
*
* Function : Add static distributor
*
* Notes :
*
* Parameters: distributorName - The name must be up to 10 letters long
*
* Return value: the new distributor handle, or -1 and thus:
* errno = REPORT_ERROR_NAME_TOO_LONG in case of long name,
* errno = REPORT_ERROR_TABLE_FULL if there are already too
* many distributors,
* errno = REPORT_ERROR_NAME_EXISTS if the distributorName
* already exists.
**************************************************************************/
DistributorHandle ReportAddDistributor(const char *distributorName)
{
return ReportDistributor(distributorName,REPORT_ADD);
}
/***************************************************************************
*
* Name : ReportRemoveDistributor
*
* Function : Remove static distributor
*
* Notes : The distributor's messages will be discarded.
* Its name will be no longer seen in the distributor's list
* when the REP_CONTROL is typed in the Monitor.
*
* Parameters: distributorName - The severity's name must be up to 10
* letters long.
*
* Return value: OK; or ERROR and thus errno is set to one of the following:
* errno = REPORT_ERROR_NAME_TOO_LONG in case of long name,
* errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the distributor
* was already removed,
* errno = REPORT_ERROR_NAME_NOT_EXISTS if the distributorName
* not exists.
**************************************************************************/
STATUS ReportRemoveDistributor(const char *distributorName)
{
return ReportDistributor(distributorName,REPORT_REMOVE);
}
/***************************************************************************
*
* Name : ReportDistributorControl
*
* Function : Disable / enable the flow of reports given its static
* severity
*
* Notes : Disable reports using the constant REPORT_OFF
* Enable the reports using the constant REPORT_ON
*
* Return value: OK or ERROR if illegal Distributor
**************************************************************************/
STATUS ReportDistributorControl(DistributorHandle Distributor, uint32_t SwitchOnOff)
{
if ((Distributor > DistCounter) || (Distributor < 0))
return ERROR;
Dist_Table[Distributor].IsActive = (SwitchOnOff == REPORT_ON) ? true : false;
return OK;
}
/***************************************************************************
*
* Name : ReportGetDistributorHandleByName
*
* Function : Get the severity handle given the severity's name
*
* Notes :
*
* Return value: the handle; or -1 if no such name
**************************************************************************/
DistributorHandle ReportGetDistributorHandleByName(const char *distributorName)
{
int index;
for (index = 0; index <= DistCounter; index++)
if (ReportStrCmp(distributorName,Dist_Table[index].name))
{
if (Dist_Table[index].IsAlive)
return index;
else
return -1; /* disable used */
}
return -1;
}
/***************************************************************************
*
* Name : GetDistributorParamsByHandle
*
* Function : Get the static severity details according to its handle
*
* Parameters : DistributorHandle - table entry
* name - buffer to contain the static severity's name
* IsActive - a reference to a boolean flag
*
* Notes : The name field must exceeds 10 bytes long
*
* Return value: OK or ERROR and then:
* errno = REPORT_ERROR_ILLEGAL_PARAMETER if no such entry
* errno = REPORT_ERROR_FILTER_NOT_ALIVE if the static
* severity has already removed.
**************************************************************************/
STATUS GetDistributorParamsByHandle(uint32_t DistributorHandle, char *name, bool *IsActive)
{
if (DistributorHandle >= DistCounter)
{
errno = REPORT_ERROR_ILLEGAL_PARAMETER;
return ERROR;
}
if ((Dist_Table[DistributorHandle].IsAlive) == false)
{
errno = REPORT_ERROR_FILTER_NOT_ALIVE;
return ERROR;
}
strcpy(name,Dist_Table[DistributorHandle].name);
*IsActive = Dist_Table[DistributorHandle].IsActive;
return OK;
}
/***************************************************************************
*
* Name : ReportFd
*
* Function : Add or remove a file descriptor to/from the output distributor
*
* Notes :
*
* Parameters: fd - file descriptor. Supplied by the user
* SwitchAddRemove - REPORT_ADD to add the fd
* REPORT_REMOVE to remove it.
* Distributor - 0 if not concerned with any static
* severity, or the static severity's handle
* to set with the given fd
*
* Return value: OK or ERROR with:
* errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list
* is full
* errno = REPORT_ERROR_ILLEGAL_PARAMETER if (fd == -1) or
* not found if asked to remove
**************************************************************************/
STATUS ReportFd(int fd, uint32_t SwitchAddRemove, DistributorHandle Distributor)
{
int index = 0, i;
if (SwitchAddRemove == REPORT_ADD)
{
index = FindFreeDestinationElement(Distributor);
/* check for the table overflow */
if (index == -1)
{
errno = REPORT_ERROR_NOT_ENOUGH_MEMORY;
return ERROR;
}
}
/* consistency check: don't add illegal fd */
if (fd == -1)
{
errno = REPORT_ERROR_ILLEGAL_PARAMETER;
return ERROR;
}
/* search for fd */
for( i = 0; i < NUM_OF_DESTINATIONS; i++ )
if ( Dist_Table[Distributor].dest[i].fd == fd )
break;
if (i == NUM_OF_DESTINATIONS)
{
if (SwitchAddRemove == REPORT_REMOVE)
{
errno = REPORT_ERROR_CODE_NOT_FOUND;
return ERROR;
}
/* Add fd */
/* add new destination to the end of the table */
Dist_Table[Distributor].dest[index].fd = fd;
/* set the function to NULL to ensure that destination is nothing but fd */
Dist_Table[Distributor].dest[index].function = NULL;
}
else if (SwitchAddRemove == REPORT_ADD)
return OK; /* this fd is already exists in the table */
else /* Remove fd */
Dist_Table[Distributor].dest[i].fd = -1;
return OK;
}
/***************************************************************************
*
* Name : ReportFunc
*
* Function : Add or remove an output routine to/from the distributor
*
* Notes :
*
* Parameters: func - hook to the routine. Supplied by the user .
* SwitchAddRemove - REPORT_ADD to add the hook
* REPORT_REMOVE to remove it.
* Distributor - Set 0 if not concerned with any static
* severity, or give the static severity's
* handle to set with the given fd.
*
* Return value: OK or ERROR with:
* errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list
* is full
* errno = REPORT_ERROR_ILLEGAL_PARAMETER if (func == NULL)
**************************************************************************/
STATUS ReportFunc(ReportFunction func, uint32_t SwitchAddRemove, DistributorHandle Distributor)
{
//int index = 0, i;
/* consistency check: don't add illegal pointer */
if( func == NULL )
{
errno = REPORT_ERROR_ILLEGAL_PARAMETER;
return ERROR;
}
if (SwitchAddRemove == REPORT_REMOVE)
{
if (ReportFunc1 == func)
{
ReportFunc1 = NULL;
return OK;
}
if (ReportFunc2 == func)
{
ReportFunc2 = NULL;
return OK;
}
errno = REPORT_ERROR_CODE_NOT_FOUND;
return ERROR;
}
if (SwitchAddRemove == REPORT_ADD)
{
if ((func == ReportFunc1)||(func == ReportFunc2))
{
REPORT_MSG (REPORT_ADD,"Report function already exist");
return OK;
}
if (ReportFunc1 == NULL)
{
ReportFunc1 = func;
return OK;
}
if (ReportFunc2 == NULL)
{
ReportFunc2 = func;
return OK;
}
errno = REPORT_ERROR_CODE_NOT_FOUND;
return ERROR;
}
return OK;
}
/***************************************************************************
*
* Name : ReportMessage2Dist
*
* Function : Report a message to the appropriate distributor
*
* Notes : The distributor handle should be passed using the macro
* SET_PRIVATE_DISTRIBUTOR
*
* Return value: OK or ERROR if failed to send to distributor
**************************************************************************/
STATUS ReportMessage2Dist(DistributorHandle distributor, const char *message)
{
return reportDistribute(MESSAGE_FORMAT, message,NULL, 0, 0, distributor, 0, 0);
}
/***************************************************************************
*
* Name : ReportMonitorFunc
*
* Function : Add/remove an output routine that prints to the monitor
*
* Notes : Hiding Report messages from appearing on the monitor is
* enable when the HALT> prompt is shown (by pressing <ENTER>).
* The filtering is done using an internal routine.
* This routine can be added/removed using this call.
* It can be added either to the regular distributor or to the
* distributor of each of the static severities.
*
* Parameters: SwitchAddRemove - REPORT_ADD to add the routine
* REPORT_REMOVE to remove it.
* Distributor - Set 0 if not concerned with any static
* severity, or give the static severity's
* handle to set with it .
*
* Return value: void
**************************************************************************/
/*void ReportMonitorFunc(uint32_t SwitchAddRemove, uint32_t Distributor)
{
switch (SwitchAddRemove)
{
case REPORT_ADD:
ReportFunc(MonitorFuncRoutine, REPORT_ADD, Distributor);
break;
case REPORT_REMOVE:
ReportFunc(MonitorFuncRoutine, REPORT_REMOVE, Distributor);
break;
}
}
*/
/*------------- messageDistribute ------------------------*/
/*
* Forward message to all destinations.
*
* Parameters:
* void* msg - address of the message
* int len - message length
*
* Returns:
* None
*
*/
char reportmsg[254];
static void messageDistribute(char *msg,
int DistTableEntry,
char *FileName,
int LineNumber,
int errorCode,
int Severity,
int parameter)
{
//int index;
/* pass through the table and send message to destination.
Assume for consistency: when the destination is fd,
it should not be -1 and function must be NULL.
If the destination is function, it's address must not be NULL
and fd should be -1 */
/* for (index = 0; index < NUM_OF_DESTINATIONS; index++ )
{
if (Dist_Table[DistTableEntry].dest[index].function != NULL)
Dist_Table[DistTableEntry].dest[index].function(msg,FileName,LineNumber,errorCode,parameter1,parameter2);
}
*/
strncpy (reportmsg,msg,250);
reportmsg[251] = NULL;
if (ReportFunc1 != NULL)
ReportFunc1(reportmsg, FileName,LineNumber,errorCode,Severity, parameter);
if (ReportFunc2 != NULL)
ReportFunc2(reportmsg, FileName,LineNumber,errorCode,Severity, parameter);
}
/*------------- reportFormat --------------------------*/
/*
* The function converts mesage with error type, code, etc. into string
* with length using the following format (example):
* "H/W Error #12,05,01: Bus error (0xffde,0x1234)"
*
* Parameters:
* char* buffer - buffer to store the formatted message
* int* maxlen - length of the buffer. If the estimated length
* of the formatted message exceeds maxlen,
* function returns ERROR, set errno to
* REPORT_ERROR_NOT_ENOUGH_MEMORY and buffer left unchanged.
* char* message - user message
* UNIT16 extErrorType - error type and severity
* ERRORCODE errorCode - error code
* uint32_t32 parameter1 - user parameter 1
* uint32_t32 parameter2 - user parameter 2
*
*/
//STATUS reportFormat(char *buffer,
// int *maxlen,
// const char *message,
// int errorCode,
// ErrorSeverity severity,
// int parameter1,
// int parameter2)
//{
// int DstrTableEntry;
// char *name;
// static char* severities[8] = {"Message","Warning","","Error","","","","Fatal error"};
//
// /* Total message length w/o text is REPORT_MSG_FORMAT_LEN bytes */
// int msgLen = strlen(message) + REPORT_MSG_FORMAT_LEN;
//
// /* check if message fit the supplied buffer */
// if (*maxlen < msgLen)
// {
// errno = REPORT_ERROR_NOT_ENOUGH_MEMORY;
// return ERROR;
// }
// /* Format message.
// ATTENTION: DON'T forget to change REPORT_MSG_FORMAT_LEN
// when changing the format string */
// if (SEVERITY_MASK(severity) == RpPrivate)
// {
// DstrTableEntry = (severity >> 5);
// if (Dist_Table[DstrTableEntry].IsAlive == false)
// {
// errno = REPORT_ERROR_ILLEGAL_PARAMETER;
// return ERROR;
// }
// name = Dist_Table[DstrTableEntry].name;
// }
// else
// name = severities[severity-1];
//
// *maxlen = sprintf(buffer,"%s: #%d: %s (0x%x,0x%x)\r\n",name,errorCode,message,parameter1,parameter2);
// return OK;
//}
/***************************************************************************
*
* Name : FindFreeDestinationElement
*
* Function : Find Free Destination Element.
*
* Notes :
*
* Return value: index if found , ERROR - otherwise
**************************************************************************/
int FindFreeDestinationElement(int DistTableEntry)
{
int index;
for (index=0; index<NUM_OF_DESTINATIONS; index++)
if ((Dist_Table[DistTableEntry].dest[index].fd == -1) &&
(Dist_Table[DistTableEntry].dest[index].function == NULL))
return index;
return ERROR;
}
/***************************************************************************
*
* Name : ReportStrCmp
*
* Function : compare between two string with case-insensitive.
*
* Notes :
*
* Return value: true - strings are identical; false - otherwise
**************************************************************************/
bool ReportStrCmp(const char *str1, const char *str2)
{
int i=0;
while ((str1[i] != '\0') || (str2[i] != '\0'))
{
if (tolower(str1[i]) != tolower(str2[i]))
return false;
i++;
}
if ((str1[i] == '\0') && (str2[i] == '\0'))
return true;
return false;
}
/***************************************************************************
*
* Name : IsNameExistsInDistributorTable
*
* Function : Check if a given name is already found in the table
* of the static severities
*
* Notes :
*
* Return value: true if found; false otherwise
**************************************************************************/
bool IsNameExistsInDistributorTable(const char *name)
{
int index;
for (index=0; index<=DistCounter; index++)
if (ReportStrCmp(name,Dist_Table[index].name) == true)
return true;
return false;
}
|