Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/errorlog.h
Parent Directory
|
Revision Log
Revision 1741 -
(show annotations)
(download)
(as text)
Sat Jul 11 14:25:16 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 6517 byte(s)
Sat Jul 11 14:25:16 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 6517 byte(s)
Merge change from MS-Windows branch (offset_t).
1 | /*************************************** |
2 | Header file for error log file data types and associated function prototypes. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2013-2015 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 | #ifndef ERRORLOG_H |
24 | #define ERRORLOG_H /*+ To stop multiple inclusions. +*/ |
25 | |
26 | #include <stdint.h> |
27 | #include <sys/types.h> |
28 | |
29 | #include "types.h" |
30 | #include "typesx.h" |
31 | |
32 | #include "files.h" |
33 | |
34 | |
35 | /*+ 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 | typedef struct _ErrorLogs |
65 | { |
66 | ErrorLogsFile file; /*+ The header data from the file. +*/ |
67 | |
68 | #if !SLIM |
69 | |
70 | char *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 | offset_t offsetsoffset; /*+ An allocated array with a copy of the file offsets. +*/ |
84 | |
85 | offset_t errorlogsoffset_geo; /*+ The offset of the geographical error logs within the file. +*/ |
86 | offset_t errorlogsoffset_nongeo; /*+ The offset of the non-geographical error logs within the file. +*/ |
87 | |
88 | offset_t stringsoffset; /*+ The offset of the error strings within the file. +*/ |
89 | |
90 | ErrorLog cached[2]; /*+ Some cached error logs read from the file in slim mode. +*/ |
91 | |
92 | char cachestring[1024]; /*+ A cached copy of the error string read from the file in slim mode. +*/ |
93 | |
94 | #endif |
95 | } |
96 | ErrorLogs; |
97 | |
98 | |
99 | /* Error log functions in errorlog.c */ |
100 | |
101 | ErrorLogs *LoadErrorLogs(const char *filename); |
102 | |
103 | void DestroyErrorLogs(ErrorLogs *errorlogs); |
104 | |
105 | void GetErrorLogLatLong(ErrorLogs *errorlogs,index_t index,ErrorLog *errorlogp,double *latitude,double *longitude); |
106 | |
107 | |
108 | /* Macros and inline functions */ |
109 | |
110 | #if !SLIM |
111 | |
112 | /*+ Return an ErrorLog pointer given a set of errorlogs and an index. +*/ |
113 | #define LookupErrorLog(xxx,yyy,ppp) (&(xxx)->errorlogs_geo[yyy]) |
114 | |
115 | /*+ Return the offset of a geographical region given a set of errorlogs. +*/ |
116 | #define LookupErrorLogOffset(xxx,yyy) ((xxx)->offsets[yyy]) |
117 | |
118 | /*+ Return the string for an error log. +*/ |
119 | #define LookupErrorLogString(xxx,yyy) (&(xxx)->strings[(xxx)->errorlogs_geo[yyy].offset]) |
120 | |
121 | #else |
122 | |
123 | /* Prototypes */ |
124 | |
125 | static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int position); |
126 | |
127 | static inline index_t LookupErrorLogOffset(ErrorLogs *errorlogs,index_t index); |
128 | |
129 | static inline char *LookupErrorLogString(ErrorLogs *errorlogs,index_t index); |
130 | |
131 | /* Inline functions */ |
132 | |
133 | /*++++++++++++++++++++++++++++++++++++++ |
134 | Find the ErrorLog information for a particular error log. |
135 | |
136 | ErrorLog *LookupErrorLog Returns a pointer to the cached error log information. |
137 | |
138 | ErrorLogs *errorlogs The set of errorlogs to use. |
139 | |
140 | index_t index The index of the error log. |
141 | |
142 | int position The position in the cache to store the value. |
143 | ++++++++++++++++++++++++++++++++++++++*/ |
144 | |
145 | static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int position) |
146 | { |
147 | SlimFetch(errorlogs->fd,&errorlogs->cached[position-1],sizeof(ErrorLog),errorlogs->errorlogsoffset_geo+(offset_t)index*sizeof(ErrorLog)); |
148 | |
149 | return(&errorlogs->cached[position-1]); |
150 | } |
151 | |
152 | |
153 | /*++++++++++++++++++++++++++++++++++++++ |
154 | Find the offset of error logs in a geographical region. |
155 | |
156 | index_t LookupErrorLogOffset Returns the index offset. |
157 | |
158 | ErrorLogs *errorlogs The set of error logs to use. |
159 | |
160 | index_t index The index of the offset. |
161 | ++++++++++++++++++++++++++++++++++++++*/ |
162 | |
163 | static inline index_t LookupErrorLogOffset(ErrorLogs *errorlogs,index_t index) |
164 | { |
165 | index_t offset; |
166 | |
167 | SlimFetch(errorlogs->fd,&offset,sizeof(index_t),errorlogs->offsetsoffset+(offset_t)index*sizeof(index_t)); |
168 | |
169 | return(offset); |
170 | } |
171 | |
172 | |
173 | /*++++++++++++++++++++++++++++++++++++++ |
174 | Find the string associated with a particular error log. |
175 | |
176 | char *LookupErrorLogString Returns the error string. |
177 | |
178 | ErrorLogs *errorlogs The set of error logs to use. |
179 | |
180 | index_t index The index of the string. |
181 | ++++++++++++++++++++++++++++++++++++++*/ |
182 | |
183 | static inline char *LookupErrorLogString(ErrorLogs *errorlogs,index_t index) |
184 | { |
185 | ErrorLog *errorlog=LookupErrorLog(errorlogs,index,2); |
186 | |
187 | SlimFetch(errorlogs->fd,errorlogs->cachestring,errorlog->length,errorlogs->stringsoffset+errorlog->offset); |
188 | |
189 | return(errorlogs->cachestring); |
190 | } |
191 | |
192 | #endif |
193 | |
194 | |
195 | #endif /* ERRORLOG_H */ |