comparison src/g23m-aci/aci/db.h @ 162:53929b40109c

src/g23m-aci: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2016 02:02:43 +0000
parents
children
comparison
equal deleted inserted replaced
161:4557e2a9c18e 162:53929b40109c
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 /*
40 Database type
41 */
42 typedef enum
43 {
44
45 DB_UNMANAGED, /* Not managed (1:1 slave of another file) */
46 DB_FREELIST /* Fast free list maintained */
47
48 } T_DB_TYPE;
49
50 /*
51 Database affected records (History log)
52 */
53 typedef struct
54 {
55
56 USHORT entries; /* Number of affected entries */
57 USHORT field_id[DB_MAX_AFFECTED]; /* Elementary file, e.g. EF_ADN */
58 USHORT record[DB_MAX_AFFECTED]; /* Corresponding record within elementary file*/
59
60 } T_DB_CHANGED;
61
62 /*
63 Database Information
64 */
65 typedef struct
66 {
67 BOOL clean; /* Database consistent */
68 BOOL tracked; /* Tracked for external storage device */
69 } T_DB_INFO;
70
71 /*
72 File Information
73 */
74 typedef struct
75 {
76
77 BOOL clean; /* Database consistent */
78 T_DB_TYPE entry_type; /* Type of database field */
79 USHORT record_size; /* Record size */
80 USHORT num_records; /* Number of records */
81 USHORT used_records; /* Number of used records */
82
83 } T_DB_INFO_FIELD;
84
85 /*
86 Search node
87 Note: This node is internal to DBM.
88 */
89 typedef struct
90 {
91
92 UBYTE top;
93 UBYTE bottom;
94
95 } T_DB_SEARCH_NODE;
96
97 /*
98 Database return codes
99 */
100 typedef enum
101 {
102
103 DB_OK = 0, /* Execution of command completed */
104 DB_FAIL = -1, /* Execution of command failed within db */
105 DB_FAIL_FS = -2, /* Unexpected failure of FFS */
106 DB_FULL = -3, /* Database is full */
107 DB_INVALID_DB = -4, /* Database handle not known */
108 DB_INVALID_FIELD = -5, /* Invalid index requested */
109 DB_INVALID_RECORD = -6, /* Invalid record requested */
110 DB_INVALID_INDEX = -7, /* Invalid index requested */
111 DB_INVALID_SIZE = -8, /* Invalid size given */
112 DB_EMPTY_RECORD = -9, /* Attempted to read a free record */
113
114 /* Architecture document need to be updated for following constants */
115
116 DB_EXISTS = -10,/* Database already exists */
117 DB_FIELD_EXISTS = -11,/* Elementary file already exists */
118 DB_HISTORY_FULL = -12,/* Change log full */
119 DB_NOT_INITIALISED = -13,/* Database not initialised */
120 DB_IN_USE = -14,/* Database in use */
121 DB_RECORD_NOT_FOUND = -15 /* Record not found */
122
123 } T_DB_CODE;
124
125
126 /*
127 This function is used in db_create_index
128 */
129
130 typedef int (*T_COMP_FUNC)( int db_handle,
131 USHORT field_id,
132 USHORT record_1,
133 USHORT record_2,
134 ULONG flags );
135
136 /*
137 This function is used for db_search
138 */
139
140 typedef int (*T_SEARCH_FUNC)( ULONG Flags,
141 const UBYTE* Search_tag,
142 int db_handle,
143 USHORT field_id,
144 USHORT record_num );
145
146 /*
147 Interface Functions
148 */
149
150 EXTERN void db_init ( void );
151
152 EXTERN int db_create ( const char* directory,
153 UBYTE num_of_fields,
154 BOOL tracked );
155
156 EXTERN int db_open ( const char* directory );
157
158 EXTERN T_DB_CODE db_create_field ( int db_handle,
159 T_DB_TYPE db_type,
160 USHORT field_id,
161 USHORT record_size,
162 USHORT num_of_records );
163
164 EXTERN int db_write_record ( int db_handle,
165 USHORT field_id,
166 USHORT record_num,
167 USHORT offset,
168 USHORT length,
169 const UBYTE* buffer );
170
171 EXTERN int db_update_ext_bitmap(int db_handle,
172 USHORT field_id,
173 USHORT record_num,
174 BOOL flag);
175
176
177 /*
178 1) If ACI would like to use incremental sort, it needs to call
179 db_update_index at end of writing/deleting the record(s).
180 If the index does not exist, it would be created.
181
182 Note that ACI can call this function after every record or
183 after 'n' records (n>1) and DB would process it properly.
184
185 2) If ACI would like to use quick sort, it can go for db_create_index
186 at any moment.
187
188 db_create_index is compatible with db_update_index and vice versa.
189
190 */
191 EXTERN T_DB_CODE db_create_index ( int db_handle,
192 USHORT field_id,
193 UBYTE sort_index,
194 T_COMP_FUNC compare_function,
195 ULONG flags );
196
197 EXTERN T_DB_CODE db_update_index ( int db_handle,
198 USHORT field_id,
199 UBYTE sort_index,
200 T_COMP_FUNC compare_function,
201 ULONG flags );
202
203 EXTERN T_DB_CODE db_get_phy_from_idx ( int db_handle,
204 USHORT field_id,
205 UBYTE sort_index,
206 USHORT order_num );
207
208 EXTERN T_DB_CODE db_flush (int db_handle);
209
210 EXTERN int db_read_record ( int db_handle,
211 USHORT field_id,
212 USHORT record_num,
213 USHORT offset,
214 USHORT length,
215 UBYTE* buffer );
216
217 EXTERN T_DB_CODE db_read_change_log ( int db_handle,
218 T_DB_CHANGED* changed);
219
220 EXTERN T_DB_CODE db_delete_record ( int db_handle,
221 USHORT field_id,
222 USHORT record_num );
223
224 EXTERN T_DB_CODE db_info ( int db_handle,
225 T_DB_INFO* db_info );
226
227 EXTERN T_DB_CODE db_info_field ( int db_handle,
228 USHORT field_id,
229 T_DB_INFO_FIELD* info_field );
230
231 EXTERN int db_find_free_record ( int db_handle,
232 USHORT field_id );
233
234 EXTERN T_DB_CODE db_field_changed ( int db_handle,
235 USHORT field_id,
236 BOOL* changed );
237
238 EXTERN T_DB_CODE db_record_empty ( int db_handle,
239 USHORT field_id,
240 USHORT record_num,
241 BOOL* empty );
242
243 EXTERN int db_search ( int db_handle,
244 USHORT field_id,
245 UBYTE sort_index,
246 SHORT* order_num,
247 T_SEARCH_FUNC search_function,
248 ULONG flags,
249 const UBYTE* search_tag );
250
251 EXTERN int db_get_last_fs_error ( void );
252
253 EXTERN T_DB_CODE db_close ( int db_handle );
254
255 EXTERN void db_exit ( void );
256
257 EXTERN T_DB_CODE db_remove_index ( int db_handle,
258 USHORT field_id,
259 UBYTE sort_index );
260
261 EXTERN T_DB_CODE db_remove_field ( int db_handle,
262 USHORT field_id );
263
264 EXTERN T_DB_CODE db_remove ( const char* directory );
265
266 #endif