Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/errorlog.h
Parent Directory
|
Revision Log
Revision 1320 -
(hide annotations)
(download)
(as text)
Tue May 14 18:57:52 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5037 byte(s)
Tue May 14 18:57:52 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5037 byte(s)
Copy errorlogx.h to errorlog.h and create errorlog.c so that they mirror the nodes.h and nodes.c filenames. Add functions to read in a set of error logs from a file.
1 | amb | 1313 | /*************************************** |
2 | amb | 1320 | Header file for error log file data types and associated function prototypes. |
3 | amb | 1313 | |
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | This file Copyright 2013 Andrew M. Bishop | ||
7 | |||
8 | This program is free software: you can redistribute it and/or modify | ||
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | ***************************************/ | ||
21 | |||
22 | |||
23 | amb | 1320 | #ifndef ERRORLOG_H |
24 | #define ERRORLOG_H /*+ To stop multiple inclusions. +*/ | ||
25 | amb | 1313 | |
26 | #include <stdint.h> | ||
27 | amb | 1320 | #include <sys/types.h> |
28 | amb | 1313 | |
29 | #include "types.h" | ||
30 | #include "typesx.h" | ||
31 | |||
32 | amb | 1320 | #include "files.h" |
33 | amb | 1313 | |
34 | |||
35 | amb | 1317 | /*+ A structure containing information for an error message in the file. +*/ |
36 | typedef struct _ErrorLog | ||
37 | { | ||
38 | ll_off_t latoffset; /*+ The error message latitude offset within its bin. +*/ | ||
39 | ll_off_t lonoffset; /*+ The error message longitude offset within its bin. +*/ | ||
40 | |||
41 | uint32_t offset; /*+ The offset of the error message from the beginning of the text section. +*/ | ||
42 | uint32_t length; /*+ The length of the error message in the text section. +*/ | ||
43 | } | ||
44 | ErrorLog; | ||
45 | |||
46 | |||
47 | /*+ A structure containing the header from the error log file. +*/ | ||
48 | typedef struct _ErrorLogsFile | ||
49 | { | ||
50 | index_t number; /*+ The total number of error messages. +*/ | ||
51 | index_t number_geo; /*+ The number of error messages with a geographical location. +*/ | ||
52 | index_t number_nongeo; /*+ The number of error messages without a geographical location. +*/ | ||
53 | |||
54 | ll_bin_t latbins; /*+ The number of bins containing latitude. +*/ | ||
55 | ll_bin_t lonbins; /*+ The number of bins containing longitude. +*/ | ||
56 | |||
57 | ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/ | ||
58 | ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/ | ||
59 | } | ||
60 | ErrorLogsFile; | ||
61 | |||
62 | |||
63 | /*+ A structure containing a set of error log messages read from the file. +*/ | ||
64 | amb | 1320 | typedef struct _ErrorLogs |
65 | amb | 1317 | { |
66 | ErrorLogsFile file; /*+ The header data from the file. +*/ | ||
67 | |||
68 | #if !SLIM | ||
69 | |||
70 | void *data; /*+ The memory mapped data in the file. +*/ | ||
71 | |||
72 | index_t *offsets; /*+ A pointer to the array of offsets in the file. +*/ | ||
73 | |||
74 | ErrorLog *errorlogs_geo; /*+ A pointer to the array of geographical error logs in the file. +*/ | ||
75 | ErrorLog *errorlogs_nongeo; /*+ A pointer to the array of non-geographical error logs in the file. +*/ | ||
76 | |||
77 | char *strings; /*+ A pointer to the array of error strings in the file. +*/ | ||
78 | |||
79 | #else | ||
80 | |||
81 | int fd; /*+ The file descriptor for the file. +*/ | ||
82 | |||
83 | amb | 1320 | off_t offsetsoffset; /*+ An allocated array with a copy of the file offsets. +*/ |
84 | amb | 1317 | |
85 | off_t errorlogsoffset_geo; /*+ The offset of the geographical error logs within the file. +*/ | ||
86 | off_t errorlogsoffset_nongeo; /*+ The offset of the non-geographical error logs within the file. +*/ | ||
87 | |||
88 | off_t stringsoffset; /*+ The offset of the error strings within the file. +*/ | ||
89 | |||
90 | amb | 1320 | ErrorLog cached[2]; /*+ Some cached error logs read from the file in slim mode. +*/ |
91 | |||
92 | amb | 1317 | #endif |
93 | } | ||
94 | ErrorLogs; | ||
95 | |||
96 | |||
97 | amb | 1320 | /* Error log functions in errorlog.c */ |
98 | amb | 1317 | |
99 | amb | 1320 | ErrorLogs *LoadErrorLogs(const char *filename); |
100 | amb | 1317 | |
101 | amb | 1320 | void DestroyErrorLogs(ErrorLogs *errorlogs); |
102 | amb | 1317 | |
103 | amb | 1320 | |
104 | /* Macros and inline functions */ | ||
105 | |||
106 | #if !SLIM | ||
107 | |||
108 | /*+ Return an ErrorLog pointer given a set of errorlogs and an index. +*/ | ||
109 | #define LookupErrorLog(xxx,yyy,ggg,ppp) ((ggg)?(&(xxx)->errorlogs_geo[yyy]):(&(xxx)->errorlogs_nongeo[yyy])) | ||
110 | |||
111 | #else | ||
112 | |||
113 | /* Prototypes */ | ||
114 | |||
115 | static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int geo,int position); | ||
116 | |||
117 | /* Inline functions */ | ||
118 | |||
119 | /*++++++++++++++++++++++++++++++++++++++ | ||
120 | Find the ErrorLog information for a particular error log. | ||
121 | |||
122 | ErrorLog *LookupErrorLog Returns a pointer to the cached error log information. | ||
123 | |||
124 | ErrorLogs *errorlogs The set of errorlogs to use. | ||
125 | |||
126 | index_t index The index of the error log. | ||
127 | |||
128 | int geo Set to true if a geographical error log is required. | ||
129 | |||
130 | int position The position in the cache to store the value. | ||
131 | ++++++++++++++++++++++++++++++++++++++*/ | ||
132 | |||
133 | static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int geo,int position) | ||
134 | { | ||
135 | if(geo) | ||
136 | SeekReadFile(errorlogs->fd,&errorlogs->cached[position-1],sizeof(ErrorLog),errorlogs->errorlogsoffset_geo +(off_t)index*sizeof(ErrorLog)); | ||
137 | else | ||
138 | SeekReadFile(errorlogs->fd,&errorlogs->cached[position-1],sizeof(ErrorLog),errorlogs->errorlogsoffset_nongeo+(off_t)index*sizeof(ErrorLog)); | ||
139 | |||
140 | return(&errorlogs->cached[position-1]); | ||
141 | } | ||
142 | |||
143 | #endif | ||
144 | |||
145 | |||
146 | #endif /* ERRORLOG_H */ |