summaryrefslogtreecommitdiff
path: root/include_protected/persistence_client_library.h
blob: d34060e6685ca991a6da8336a3e3fd70a32b8afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef PERSISTENCE_CLIENT_LIBRARY_H
#define PERSISTENCE_CLIENT_LIBRARY_H

/******************************************************************************
 * Project         Persistency
 * (c) copyright   2012
 * Company         XS Embedded GmbH
 *****************************************************************************/
/******************************************************************************
 * This Source Code Form is subject to the terms of the
 * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
******************************************************************************/
 /**
 * @file           persistence_client_library.h
 * @ingroup        Persistence client library
 * @author         Ingo Huerner
 * @brief          Header of the persistence client library.
 *                 Library provides an API to access persistent data
 * @see            
 */


#ifdef __cplusplus
extern "C" {
#endif

#define  PERSIST_CLIENT_LIBRARY_INTERFACE_VERSION   (0x01000000U)

#include "../include/persistence_client_library_error_def.h"
#include "crc32.h"

#include <string.h>
#include <stdio.h>


/// constant definitions
enum _PersistenceConstantDef
{
   ResIsNoFile          = 0,        /// flag to identify that resource a not file
   ResIsFile            = 1,        /// flag to identify that resource a file
   AccessNoLock         = 1,        /// flag to indicate that access is not locked

   FileClosed           = 0,
   FileOpen             = 1,

   NsmShutdownNormal       = 1,     /// lifecycle shutdown normal
   NsmErrorStatus_OK       = 1,
   NsmErrorStatus_Fail     = -1,

   PrctKeySize             = 64,    /// persistence resource config table max key size
   PrctValueSize           = 256,   /// persistence resource config table max value size
   PrctDbTableSize         = 1024,  /// number of persistence resource config tables to store

   DbKeySize               = 64,    /// database max key size
   DbValueSize             = 16384, /// database max value size
   DbTableSize             = 1024,  /// database table size

   PasMsg_Block            = 1,     /// persistence administration service block access
   PasMsg_WriteBack        = 2,     /// persistence administration service write_back
   PasMsg_Unblock          = 4,     /// persistence administration service unblock access
   PasErrorStatus_RespPend = 88,    /// persistence administration service msg return status
   PasErrorStatus_OK       = 100,   /// persistence administration service msg return status
   PasErrorStatus_FAIL     = -1,    /// persistence administration service msg return status

   CustLibMaxLen = 128,             /// max length of the custom library name and path
   DbKeyMaxLen   = 128,             /// max database key length
   DbPathMaxLen  = 128,             /// max database path length
   MaxAppNameLen = 128,             /// max application name
   MaxPersHandle = 256,             /// max number of parallel open persistence handles

   defaultMaxKeyValDataSize = 16384 /// default limit the key-value data size to 16kB
};


/// enumerator used to identify the policy to manage the data
typedef enum _PersistencePolicy_e
{
   PersistencePolicy_wc    = 0,  /**< the data is managed write cached */
   PersistencePolicy_wt    = 1,  /**< the data is managed write through */
   PersistencePolicy_na    = 2,  /**< the data is not applicable */

   /** insert new entries here ... */
   PersistencePolicy_LastEntry         /**< last entry */

} PersistencePolicy_e;


/// enumerator used to identify the persistence storage to manage the data
typedef enum _PersistenceStorage_e
{
   PersistenceStorage_local    = 0,  /**< the data is managed local */
   PersistenceStorage_shared   = 1,  /**< the data is managed shared */
   PersistenceStorage_custom   = 2,  /**< the data is managed over custom client implementation */

   /** insert new entries here ... */
   PersistenceStoragePolicy_LastEntry         /**< last entry */

} PersistenceStorage_e;


/// structure used to manage database context
typedef struct _PersistenceDbContext_s
{
   unsigned char ldbid;
   unsigned char user_no;
   unsigned char seat_no;
} PersistenceDbContext_s;

/// structure used to manage the persistence configuration for a key
typedef struct _PersistenceConfigurationKey_s
{
   PersistencePolicy_e     policy;           /**< policy  */
   PersistenceStorage_e    storage;          /**< definition of storage to use */
   unsigned int            permission;       /**< access right, corresponds to UNIX */
   unsigned int            max_size;         /**< max size expected for the key */
   char *                  reponsible;       /**< name of responsible application */
   char *                  custom_name;      /**< name of the customer plugin */
} PersistenceConfigurationKey_s;


/// persistence information
typedef struct _PersistenceInfo_s
{
   PersistenceDbContext_s           context;          /**< database context*/
   PersistenceConfigurationKey_s    configKey;        /**< prct configuration key*/

} PersistenceInfo_s;


/// persistence resource config table type definition
typedef enum _PersistenceRCT_e
{
   PersistenceRCT_local         = 0,
   PersistenceRCT_shared_public = 1,
   PersistenceRCT_shared_group  = 2,

   PersistenceRCT_LastEntry                // last Entry

} PersistenceRCT_e;


/// resource configuration table name
extern const char* gResTableCfg;

/// shared cached default database
extern const char* gSharedCachedDefault;
/// shared cached database
extern const char* gSharedCached;
/// shared write through default database
extern const char* gSharedWtDefault;
/// shared write through database
extern const char* gSharedWt;

/// local cached default database
extern const char* gLocalCachedDefault;
/// local cached default database
extern const char* gLocalCached;
/// local write through default database
extern const char* gLocalWtDefault;
/// local write through default database
extern const char* gLocalWt;


/// directory structure node name defintion
extern const char* gNode;
/// directory structure user name defintion
extern const char* gUser;
/// directory structure seat name defintion
extern const char* gSeat;


/// path prefic for local cached database: /Data/mnt_c/<appId>/<database_name>
extern const char* gLocalCachePath;
/// path prefic for local write through database /Data/mnt_wt/<appId>/<database_name>
extern const char* gLocalWtPath;
/// path prefic for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name>
extern const char* gSharedCachePath;
/// path prefic for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name>
extern const char* gSharedWtPath;
/// path prefic for shared public cached database: /Data/mnt_c/Shared/Public//<database_name>
extern const char* gSharedPublicCachePath;
/// path prefic for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name>
extern const char* gSharedPublicWtPath;


/// application id
extern char gAppId[MaxAppNameLen];

/// max key value data size
extern int gMaxKeyValDataSize;

#ifdef __cplusplus
}
#endif

#endif /* PERSISTENCY_CLIENT_LIBRARY_H */