Updated test resource config table batabases; implemented loading of custom libraries...
[profile/ivi/persistence-client-library.git] / include / persistence_client_library_file.h
1 #ifndef PERSISTENCE_CLIENT_LIBRARY_FILE_H
2 #define PERSISTENCE_CLIENT_LIBRARY_FILE_H
3
4 /******************************************************************************
5  * Project         Persistency
6  * (c) copyright   2011
7  * Company         XS Embedded GmbH
8  *****************************************************************************/
9 /******************************************************************************
10    Permission is hereby granted, free of charge, to any person obtaining
11    a copy of this software and associated documentation files (the "Software"),
12    to deal in the Software without restriction, including without limitation
13    the rights to use, copy, modify, merge, publish, distribute, sublicense,
14    and/or sell copies of the Software, and to permit persons to whom the
15    Software is furnished to do so, subject to the following conditions:
16
17    The above copyright notice and this permission notice shall be included
18    in all copies or substantial portions of the Software.
19
20    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24    DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26    OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 ******************************************************************************/
28  /**
29  * @file           persistence_client_library_file.h
30  * @ingroup        Persistence client library
31  * @author         Ingo Huerner (XSe) / Guy Sagnes (Continental)
32  * @brief          Header of the persistence client library.
33  *                 Library provides an API to access persistent data
34  * @see            
35  */
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 #define         PERSIST_FILEAPI_INTERFACE_VERSION   (0x01000000U)
43
44
45
46 /**
47  * @brief close the given POSIX file descriptor
48  *
49  * @param fd the file descriptor to close
50  *
51  * @return zero on success. On error, -1 is returned, and errno is set appropriately
52  */
53 int file_close(int fd);
54
55
56
57 /**
58  * @brief get the size of the file given by the file descriptor
59  *
60  * @param fd the POSIX file descriptor
61  *
62  * @return positive value. On error, -1 is returned, and errno is set appropriately
63  */
64 int file_get_size(int fd);
65
66
67
68 /**
69  * @brief map a file into the memory
70  *
71  * @param addr if NULL, kernel chooses address
72  * @param size the size in bytes to map into the memory
73  * @param offset in the file to map
74  * @param fd the POSIX file descriptor of the file to map
75  *
76  * @return a pointer to the mapped area, or on error the value MAP_FAILED
77  */
78 void* file_map_data(void* addr, long size, long offset, int fd);
79
80
81
82 /**
83  * @brief open a file
84  *
85  * @param ldbid logical database ID
86  * @param resource_id the resource ID
87  * @param user_no  the user ID
88  * @param seat_no  the seat number (seat 0 to 3)
89  *
90  * @return positive value: the POSIX file descriptor; negative value: Error code
91  */
92 int file_open(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
93
94
95
96 /**
97  * @brief read persistent data from a file
98  *
99  * @param fd POSIX file descriptor
100  * @param buffer buffer to read the data
101  * @param buffer_size the size buffer for reading
102  *
103  * @return positive value: the size read; negative value: error code
104  */
105 int file_read_data(int fd, void * buffer, unsigned long buffer_size);
106
107
108
109 /**
110  * @brief remove the file
111  *
112  * @param ldbid logical database ID
113  * @param resource_id the resource ID
114  * @param user_no  the user ID
115  * @param seat_no  the seat number (seat 0 to 3)
116  *
117  * @return positive value: success; negative value: error code
118  *
119  */
120 int file_remove(unsigned char ldbid, char* resource_id, unsigned char user_no, unsigned char seat_no);
121
122
123
124 /**
125  * @brief reposition the file descriptor
126  *
127  * @param fd the POSIX file descriptor
128  * @param offset the reposition offset
129  * @param whence the direction to reposition
130                  SEEK_SET
131                       The offset is set to offset bytes.
132                  SEEK_CUR
133                       The offset is set to its current location plus offset bytes.
134                  SEEK_END
135                       The offset is set to the size of the file plus offset bytes.
136  *
137  * @return positive value: resulting offset location; negative value: error code
138  */
139 int file_seek(int fd, long int offset, int whence);
140
141
142
143 /**
144  * @brief unmap the file from the memory
145  *
146  * @param address the address to unmap
147  * @param size the size in bytes to unmap
148  *
149  * @return on success 0; negative value: error code
150  */
151 int file_unmap_data(void* address, long size);
152
153
154
155 /**
156  * @brief write persistent data to file
157  *
158  * @param fd the POSIX file descriptor
159  * @param buffer the buffer to write
160  * @param buffer_size the size of the buffer to write in bytes
161  *
162 * @return positive value: bytes written; negative value: error code
163  */
164 int file_write_data(int fd, const void * buffer, unsigned long buffer_size);
165
166
167
168
169
170
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176
177 #endif /* PERSISTENCY_CLIENT_LIBRARY_FILE_H */
178