Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/errorlog.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1652 - (hide annotations) (download) (as text)
Thu May 14 17:25:25 2015 UTC (9 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 6511 byte(s)
Replace all arithmetic involving 'void*' pointers with 'char*' since
it isn't strictly valid although it is accepted by gcc.

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 amb 1652 This file Copyright 2013-2015 Andrew M. Bishop
7 amb 1313
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 amb 1652 char *data; /*+ The memory mapped data in the file. +*/
71 amb 1317
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 1321 char cachestring[1024]; /*+ A cached copy of the error string read from the file in slim mode. +*/
93    
94 amb 1317 #endif
95     }
96     ErrorLogs;
97    
98    
99 amb 1320 /* Error log functions in errorlog.c */
100 amb 1317
101 amb 1320 ErrorLogs *LoadErrorLogs(const char *filename);
102 amb 1317
103 amb 1320 void DestroyErrorLogs(ErrorLogs *errorlogs);
104 amb 1317
105 amb 1321 void GetErrorLogLatLong(ErrorLogs *errorlogs,index_t index,ErrorLog *errorlogp,double *latitude,double *longitude);
106 amb 1320
107 amb 1321
108 amb 1320 /* Macros and inline functions */
109    
110     #if !SLIM
111    
112     /*+ Return an ErrorLog pointer given a set of errorlogs and an index. +*/
113 amb 1321 #define LookupErrorLog(xxx,yyy,ppp) (&(xxx)->errorlogs_geo[yyy])
114 amb 1320
115 amb 1321 /*+ 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 amb 1320 #else
122    
123     /* Prototypes */
124    
125 amb 1321 static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int position);
126 amb 1320
127 amb 1321 static inline index_t LookupErrorLogOffset(ErrorLogs *errorlogs,index_t index);
128    
129     static inline char *LookupErrorLogString(ErrorLogs *errorlogs,index_t index);
130    
131 amb 1320 /* 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 amb 1321 static inline ErrorLog *LookupErrorLog(ErrorLogs *errorlogs,index_t index,int position)
146 amb 1320 {
147 amb 1415 SlimFetch(errorlogs->fd,&errorlogs->cached[position-1],sizeof(ErrorLog),errorlogs->errorlogsoffset_geo+(off_t)index*sizeof(ErrorLog));
148 amb 1320
149     return(&errorlogs->cached[position-1]);
150     }
151    
152 amb 1321
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 amb 1415 SlimFetch(errorlogs->fd,&offset,sizeof(index_t),errorlogs->offsetsoffset+(off_t)index*sizeof(index_t));
168 amb 1321
169     return(offset);
170     }
171    
172    
173     /*++++++++++++++++++++++++++++++++++++++
174     Find the string associated with a particular error log.
175    
176 amb 1525 char *LookupErrorLogString Returns the error string.
177 amb 1321
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 amb 1415 SlimFetch(errorlogs->fd,errorlogs->cachestring,errorlog->length,errorlogs->stringsoffset+errorlog->offset);
188 amb 1321
189     return(errorlogs->cachestring);
190     }
191    
192 amb 1320 #endif
193    
194    
195     #endif /* ERRORLOG_H */