FreeCalypso > hg > tcs211-l1-reconst
comparison g23m/condat/ms/src/aci/db.h @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : PHB | |
4 | Modul : DBM | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2005 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : Interface betweeen ACI_SIM and DBM module | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 #ifndef DB_H | |
21 #define DB_H | |
22 | |
23 #include "typedefs.h" | |
24 #define DB_MAX_AFFECTED 5 /* As per architecture document */ | |
25 | |
26 #define MAX_DBs 2 /* This needs to increased if DBM is used | |
27 for storing new databases (say SMSs) */ | |
28 | |
29 #define MAX_NUM_FILES 255 /* As per architecture document */ | |
30 | |
31 #define MAX_NUM_OF_SORT_INDEXS 4 /* As per architecture document */ | |
32 | |
33 #define MAX_NUM_RECORDS 254 /* As per architecture document */ | |
34 | |
35 #define INVALID_FIELD_ID 0xFFFF | |
36 | |
37 #define INVALID_SORT_INDEX 0xFF | |
38 | |
39 /* Insertion sort is available */ | |
40 #define INSERTION_SORT | |
41 | |
42 /* | |
43 Database type | |
44 */ | |
45 typedef enum | |
46 { | |
47 | |
48 DB_UNMANAGED, /* Not managed (1:1 slave of another file) */ | |
49 DB_FREELIST, /* Fast free list maintained */ | |
50 | |
51 } T_DB_TYPE; | |
52 | |
53 /* | |
54 Database affected records (History log) | |
55 */ | |
56 typedef struct | |
57 { | |
58 | |
59 USHORT entries; /* Number of affected entries */ | |
60 USHORT field_id[DB_MAX_AFFECTED]; /* Elementary file, e.g. EF_ADN */ | |
61 USHORT record[DB_MAX_AFFECTED]; /* Corresponding record within elementary file*/ | |
62 | |
63 } T_DB_CHANGED; | |
64 | |
65 /* | |
66 Database Information | |
67 */ | |
68 typedef struct | |
69 { | |
70 BOOL clean; /* Database consistent */ | |
71 BOOL tracked; /* Tracked for external storage device */ | |
72 } T_DB_INFO; | |
73 | |
74 /* | |
75 File Information | |
76 */ | |
77 typedef struct | |
78 { | |
79 | |
80 BOOL clean; /* Database consistent */ | |
81 T_DB_TYPE entry_type; /* Type of database field */ | |
82 USHORT record_size; /* Record size */ | |
83 USHORT num_records; /* Number of records */ | |
84 USHORT used_records; /* Number of used records */ | |
85 | |
86 } T_DB_INFO_FIELD; | |
87 | |
88 /* | |
89 Search node | |
90 Note: This node is internal to DBM. | |
91 */ | |
92 typedef struct | |
93 { | |
94 | |
95 UBYTE top; | |
96 UBYTE bottom; | |
97 | |
98 } T_DB_SEARCH_NODE; | |
99 | |
100 /* | |
101 Database return codes | |
102 */ | |
103 typedef enum | |
104 { | |
105 | |
106 DB_OK = 0, /* Execution of command completed */ | |
107 DB_FAIL = -1, /* Execution of command failed within db */ | |
108 DB_FAIL_FS = -2, /* Unexpected failure of FFS */ | |
109 DB_FULL = -3, /* Database is full */ | |
110 DB_INVALID_DB = -4, /* Database handle not known */ | |
111 DB_INVALID_FIELD = -5, /* Invalid index requested */ | |
112 DB_INVALID_RECORD = -6, /* Invalid record requested */ | |
113 DB_INVALID_INDEX = -7, /* Invalid index requested */ | |
114 DB_INVALID_SIZE = -8, /* Invalid size given */ | |
115 DB_EMPTY_RECORD = -9, /* Attempted to read a free record */ | |
116 | |
117 /* Architecture document need to be updated for following constants */ | |
118 | |
119 DB_EXISTS = -10,/* Database already exists */ | |
120 DB_FIELD_EXISTS = -11,/* Elementary file already exists */ | |
121 DB_HISTORY_FULL = -12,/* Change log full */ | |
122 DB_NOT_INITIALISED = -13,/* Database not initialised */ | |
123 DB_IN_USE = -14,/* Database in use */ | |
124 DB_RECORD_NOT_FOUND = -15 /* Record not found */ | |
125 | |
126 } T_DB_CODE; | |
127 | |
128 | |
129 /* | |
130 This function is used in db_create_index | |
131 */ | |
132 | |
133 typedef int (*T_COMP_FUNC)( int db_handle, | |
134 USHORT field_id, | |
135 USHORT record_1, | |
136 USHORT record_2, | |
137 ULONG flags ); | |
138 | |
139 /* | |
140 This function is used for db_search | |
141 */ | |
142 | |
143 typedef int (*T_SEARCH_FUNC)( ULONG Flags, | |
144 const UBYTE* Search_tag, | |
145 int db_handle, | |
146 USHORT field_id, | |
147 USHORT record_num ); | |
148 | |
149 /* | |
150 Interface Functions | |
151 */ | |
152 | |
153 EXTERN void db_init ( void ); | |
154 | |
155 EXTERN int db_create ( const char* directory, | |
156 UBYTE num_of_fields, | |
157 BOOL tracked ); | |
158 | |
159 EXTERN int db_open ( const char* directory ); | |
160 | |
161 EXTERN T_DB_CODE db_create_field ( int db_handle, | |
162 T_DB_TYPE db_type, | |
163 USHORT field_id, | |
164 USHORT record_size, | |
165 USHORT num_of_records ); | |
166 | |
167 EXTERN int db_write_record ( int db_handle, | |
168 USHORT field_id, | |
169 USHORT record_num, | |
170 USHORT offset, | |
171 USHORT length, | |
172 const UBYTE* buffer ); | |
173 | |
174 /* | |
175 1) If ACI would like to use incremental sort, it needs to call | |
176 db_update_index at end of writing/deleting the record(s). | |
177 If the index does not exist, it would be created. | |
178 | |
179 Note that ACI can call this function after every record or | |
180 after 'n' records (n>1) and DB would process it properly. | |
181 | |
182 2) If ACI would like to use quick sort, it can go for db_create_index | |
183 at any moment. | |
184 | |
185 db_create_index is compatible with db_update_index and vice versa. | |
186 | |
187 */ | |
188 EXTERN T_DB_CODE db_create_index ( int db_handle, | |
189 USHORT field_id, | |
190 UBYTE sort_index, | |
191 T_COMP_FUNC compare_function, | |
192 ULONG flags ); | |
193 | |
194 #ifdef INSERTION_SORT | |
195 EXTERN T_DB_CODE db_update_index ( int db_handle, | |
196 USHORT field_id, | |
197 UBYTE sort_index, | |
198 T_COMP_FUNC compare_function, | |
199 ULONG flags ); | |
200 #endif /* INSERTION_SORT */ | |
201 | |
202 EXTERN T_DB_CODE db_get_phy_from_idx ( int db_handle, | |
203 USHORT field_id, | |
204 UBYTE sort_index, | |
205 USHORT order_num ); | |
206 | |
207 EXTERN T_DB_CODE db_flush (int db_handle); | |
208 | |
209 EXTERN int db_read_record ( int db_handle, | |
210 USHORT field_id, | |
211 USHORT record_num, | |
212 USHORT offset, | |
213 USHORT length, | |
214 UBYTE* buffer ); | |
215 | |
216 EXTERN T_DB_CODE db_read_change_log ( int db_handle, | |
217 T_DB_CHANGED* changed); | |
218 | |
219 EXTERN T_DB_CODE db_delete_record ( int db_handle, | |
220 USHORT field_id, | |
221 USHORT record_num ); | |
222 | |
223 EXTERN T_DB_CODE db_info ( int db_handle, | |
224 T_DB_INFO* db_info ); | |
225 | |
226 EXTERN T_DB_CODE db_info_field ( int db_handle, | |
227 USHORT field_id, | |
228 T_DB_INFO_FIELD* info_field ); | |
229 | |
230 EXTERN int db_find_free_record ( int db_handle, | |
231 USHORT field_id ); | |
232 | |
233 EXTERN T_DB_CODE db_field_changed ( int db_handle, | |
234 USHORT field_id, | |
235 BOOL* changed ); | |
236 | |
237 EXTERN T_DB_CODE db_record_empty ( int db_handle, | |
238 USHORT field_id, | |
239 USHORT record_num, | |
240 BOOL* empty ); | |
241 | |
242 EXTERN int db_search ( int db_handle, | |
243 USHORT field_id, | |
244 UBYTE sort_index, | |
245 UBYTE* order_num, | |
246 T_SEARCH_FUNC search_function, | |
247 ULONG flags, | |
248 const UBYTE* search_tag ); | |
249 | |
250 EXTERN int db_get_last_fs_error ( void ); | |
251 | |
252 EXTERN T_DB_CODE db_close ( int db_handle ); | |
253 | |
254 EXTERN void db_exit ( void ); | |
255 | |
256 EXTERN T_DB_CODE db_remove_index ( int db_handle, | |
257 USHORT field_id, | |
258 UBYTE sort_index ); | |
259 | |
260 EXTERN T_DB_CODE db_remove_field ( int db_handle, | |
261 USHORT field_id ); | |
262 | |
263 EXTERN T_DB_CODE db_remove ( const char* directory ); | |
264 | |
265 #endif |