Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.13.1.2
openapi_syncdb.h
Go to the documentation of this file.
1 
9 /*********************************************************************
10 *
11 * Copyright 2016-2023 Broadcom.
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 **********************************************************************
26 *
27 * @filename syncdb_api.h
28 *
29 * @purpose API for the Synchronization Database
30 *
31 * @component
32 *
33 * @note
34 *
35 * @create 7/5/2012
36 *
37 * @end
38 *
39 **********************************************************************/
40 #ifndef SYNCDB_API_H_INCLUDED
41 #define SYNCDB_API_H_INCLUDED
42 
43 #include <pthread.h>
44 
49 #define SYNCDB_AGENT_MAX_MSG_SIZE 8000
50 
55 #define SYNCDB_TABLE_NAME_SIZE 32
56 
60 #define SYNCDB_MAX_STR_LEN 256
61 
65 #define SYNCDB_RECORD_MAX_SIZE (1024*64)
66 
67 /* Supported Data Table Types.
68 */
69 #define SYNCDB_TABLE_TYPE_RECORD 0
70 #define SYNCDB_TABLE_TYPE_STORABLE_RECORD 1
71 #define SYNCDB_TABLE_TYPE_AVL_TREE 2
72 #define SYNCDB_TABLE_TYPE_QUEUE 3
73 
74 /* Return Codes from the syncdb API functions.
75 */
76 #define SYNCDB_OK (0)
77 #define SYNCDB_ERROR (-1)
78 #define SYNCDB_MAX_CLIENTS (-2)
79 #define SYNCDB_DUPNAME (-3)
80 #define SYNCDB_NO_TABLE (-4)
81 #define SYNCDB_FULL (-5)
82 #define SYNCDB_SIZE (-6)
83 #define SYNCDB_NOT_FOUND (-7)
84 #define SYNCDB_SCHEMA_ERROR (-8)
85 #define SYNCDB_ENTRY_EXISTS (-9)
86 #define SYNCDB_TIMEOUT (-10)
88 /* Data Table Status.
89 ** The status is a bit mask returned by the syncdbTableStatusGet() function.
90 ** The status is maintained per client.
91 */
92 
96 #define SYNCDB_TABLE_STAT_EXISTS (1 << 0)
97 
105 #define SYNCDB_TABLE_STAT_CHANGED (1 << 1)
106 
116 #define SYNCDB_TABLE_STAT_AVL_TREE_PURGED (1 << 2)
117 
126 #define SYNCDB_TABLE_STAT_NEW_TABLE (1 << 3)
127 
128 /******** Data Table Creation Flags
129 ** The flags specified on the table create call.
130 ** The flags is a bit mask returned by the syncdbTableStatusGet() function.
131 ********/
137 #define SYNCDB_TABLE_FLAG_STORABLE (1 << 0)
138 
143 #define SYNCDB_TABLE_FLAG_NVRAM (1 << 1)
144 
149 #define SYNCDB_TABLE_FLAG_FILE_LOAD (1 << 2)
150 
151 
156 #define SYNCDB_TABLE_FLAG_EXISTS (1 << 3)
157 
163 #define SYNCDB_TABLE_FLAG_NSF (1 << 4)
164 
166 typedef struct
167 {
170  int client_id;
171  unsigned long long seqNum;
172  pthread_mutex_t client_lock;
173  unsigned int rxTimeout;
175 
178 typedef struct
179 {
180  char table_name [SYNCDB_TABLE_NAME_SIZE];
185  unsigned int table_version;
186 
189  unsigned int table_flags;
190 
193  unsigned int table_status;
194 
199 
204 
210 
213 typedef struct
214 {
215  int client_id;
216  char client_description [SYNCDB_MAX_STR_LEN];
222 
223 /********************************
224 ** Storable Record Schema
225 ********************************/
226 
227 /* The AVL trees and records can be stored in a file system using JSON notation.
228 ** In order to store information in the file system the table creator must tell syncdb how
229 ** the data is formatted. Also to facilitate data format changes the table creator must
230 ** tell syncdb the default values of fields that are not present in the file.
231 */
232 
238 #define SYNCDB_JSON_MAX_SCHEMA_SIZE (SYNCDB_RECORD_MAX_SIZE)
239 
263 typedef enum
264 {
265  SYNCDB_JSON_NUMBER = 1,
266  SYNCDB_JSON_STRING = 2,
267  SYNCDB_JSON_ARRAY = 3
269 
272 typedef struct syncdbJsonNode_s
273 {
274  syncdbJsonDataType_e data_type;
275 
283  char *data_name;
284 
290  unsigned int data_offset;
291 
294  unsigned int data_size;
295 
296  union {
297  unsigned long long default_number;
299  } val;
300 
302 
305 typedef enum
306 {
320 
321 /********************************
322 ** syncdb API Functions
323 *********************************/
324 
325 /*****************************************************************/
354 int syncdbUtilSchemaCreate (syncdbJsonNode_t *element_node,
355  unsigned int node_schema_size,
356  char *schema_buf,
357  unsigned int buf_size,
358  unsigned int *schema_size,
359  unsigned int data_element_size,
360  syncdbSchemaError_e *schema_error
361  );
362 
363 /*****************************************************************/
410 int syncdbClientRegister (char *client_name,
411  syncdbClientHandle_t *client_id);
412 
413 /*****************************************************************/
429 
430 /*****************************************************************/
447  syncdbClientStatus_t *client_status);
448 
449 /*****************************************************************/
471 int syncdbTableStore (syncdbClientHandle_t *client_id,
472  char *table_name,
473  unsigned int nvram);
474 
475 /*****************************************************************/
509  int timeout_secs);
510 
511 /*****************************************************************/
540  char *table_name);
541 
542 /*****************************************************************/
567  int num_tables,
568  syncdbDataTableStatus_t *table_list);
569 
570 /*****************************************************************/
607  char *table_name,
608  unsigned int table_version,
609  unsigned int max_elements,
610  unsigned int max_live_elements,
611  unsigned int node_size,
612  unsigned int key_size,
613  unsigned int flags,
614  char * schema,
615  unsigned int schema_size);
616 
617 /*****************************************************************/
646  char *table_name,
647  unsigned int table_version,
648  unsigned int node_size,
649  unsigned int flags,
650  char * schema,
651  unsigned int schema_size);
652 
653 /*****************************************************************/
668  char *table_name);
669 
670 /*****************************************************************/
705 int syncdbInsert (syncdbClientHandle_t *client_id,
706  char *table_name,
707  void *element,
708  unsigned int size);
709 
710 /*****************************************************************/
736 int syncdbDelete (syncdbClientHandle_t *client_id,
737  char *table_name,
738  void *element,
739  unsigned int size);
740 
741 /*****************************************************************/
769 int syncdbSet (syncdbClientHandle_t *client_id,
770  char *table_name,
771  void *element,
772  unsigned int size);
773 
774 /*****************************************************************/
816 int syncdbFieldSet (syncdbClientHandle_t *client_id,
817  char *table_name,
818  void *element,
819  unsigned int size,
820  unsigned int field_offset,
821  unsigned int field_size);
822 
823 /*****************************************************************/
857 int syncdbGet (syncdbClientHandle_t *client_id,
858  char *table_name,
859  void *element,
860  unsigned int size,
861  int *delete_pending);
862 
863 /*****************************************************************/
913 int syncdbFieldGet (syncdbClientHandle_t *client_id,
914  char *table_name,
915  void *element,
916  unsigned int size,
917  unsigned int field_offset,
918  unsigned int field_size,
919  int flags_unchanged,
920  int *delete_pending);
921 
922 /*****************************************************************/
955 int syncdbGetNext (syncdbClientHandle_t *client_id,
956  char *table_name,
957  void *element,
958  unsigned int size,
959  int *delete_pending);
960 
961 /*****************************************************************/
997  char *table_name,
998  void *element,
999  unsigned int size,
1000  int *delete_pending);
1001 
1002 /*****************************************************************/
1017 int syncdbNsfModeSet (syncdbClientHandle_t *client_id,
1018  unsigned int sync_mode,
1019  unsigned int max_msg_size);
1020 
1021 #endif /* SYNCDB_API_H_INCLUDED */
1022 
int num_non_deleted_elements
Number of records that are not in delete-pending state.
Client Table Status.
int client_id
Unique Syncdb client identifier.
int table_type
If the table exists then this specifies the table type.
Integer size is not 1, 2, 4, or 8.
Data element has 8 or more bytes beyond last schema node.
int num_elements
Number of records in the table.
int syncdbTableDelete(syncdbClientHandle_t *client_id, char *table_name)
Delete specified table or all tables.
int syncdbAvlTableCreate(syncdbClientHandle_t *client_id, char *table_name, unsigned int table_version, unsigned int max_elements, unsigned int max_live_elements, unsigned int node_size, unsigned int key_size, unsigned int flags, char *schema, unsigned int schema_size)
Create AVL Table.
int syncdbUtilSchemaCreate(syncdbJsonNode_t *element_node, unsigned int node_schema_size, char *schema_buf, unsigned int buf_size, unsigned int *schema_size, unsigned int data_element_size, syncdbSchemaError_e *schema_error)
Generate a storable record schema.
int cmd_socket
Socket for sending commands to Syncdb process.
int client_id
syncdb client ID of the client for which to retrieve the status
The element has the same name as another element in the schema.
int syncdbTableStore(syncdbClientHandle_t *client_id, char *table_name, unsigned int nvram)
Store specified table or all tables into the file system.
int syncdbInsert(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size)
Insert a new entry into the AVL table.
Default value for an integer does not fit into size.
int syncdbClientStatusGet(syncdbClientHandle_t *client_id, syncdbClientStatus_t *client_status)
Get client information for the specified client ID.
struct syncdbJsonNode_s syncdbJsonNode_t
The JSON node definition.
int syncdbGet(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size, int *delete_pending)
Get an entry from the table.
int syncdbGetNextChanged(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size, int *delete_pending)
Get the Next Changed entry from the table.
unsigned int data_size
The size of this data element in bytes.
#define SYNCDB_MAX_STR_LEN
Maximum length for string fields used by syncdb.
syncdbSchemaError_e
The following errors may be reported during schema validation.
int syncdbClientRegister(char *client_name, syncdbClientHandle_t *client_id)
Register a new client with the syncdb.
int syncdbFieldGet(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size, unsigned int field_offset, unsigned int field_size, int flags_unchanged, int *delete_pending)
Get the specified field in an entry from the table.
#define SYNCDB_TABLE_NAME_SIZE
Maximum size of the text string that uniquely identifies a database table.
int syncdbNsfModeSet(syncdbClientHandle_t *client_id, unsigned int sync_mode, unsigned int max_msg_size)
Tell SyncDB that it should start or stop data sync with the backup manager.
unsigned int table_version
The version of the table.
unsigned int data_offset
Offset of this element from the beginning of the data buffer.
Data type is not Number, String or Array.
int syncdbFieldSet(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size, unsigned int field_offset, unsigned int field_size)
Set the specified field in an entry in the table.
int num_table_purges
Number of AVL tree purge events sent to the client.
unsigned long long seqNum
Sequence number to track the correct response from server.
int notify_socket
Socket for waiting on events from Syncdb process.
unsigned long long default_number
Default value for SYNCDB_JSON_NUMBER object.
The JSON node definition.
char * data_name
The unique identifier for this variable.
int num_commands
Total number of commands issued by this client.
Schema nodes overlap each other.
int syncdbGetNext(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size, int *delete_pending)
Get the Next entry from the table.
No node with offset set to 0.
char * default_string
Default value for SYNCDB_JSON_STRING object.
int syncdbClientDeregister(syncdbClientHandle_t *client_id)
Deregister a client from the syncdb.
int num_table_change_events
Total number of table-change notifications sent to the client.
Found an element with size equal to 0.
Default value for a string does not fit into size.
syncdbJsonDataType_e
The syncdb supports the following JSON data types: SYNCDB_JSON_NUMBER - A numeric value...
int syncdbRecordTableCreate(syncdbClientHandle_t *client_id, char *table_name, unsigned int table_version, unsigned int node_size, unsigned int flags, char *schema, unsigned int schema_size)
Create a Record Table.
int syncdbTableStatusGet(syncdbClientHandle_t *client_id, int num_tables, syncdbDataTableStatus_t *table_list)
Get Table Status as it pertains to the specified client.
int syncdbTableChangeNotify(syncdbClientHandle_t *client_id, char *table_name)
Notify this client about changes to the specified table.
pthread_mutex_t client_lock
Per-client semaphore.
Two schema nodes have an 8 or more byte gap between them.
Schema node offset plus size is larger than data element.
int syncdbTableChangeCheck(syncdbClientHandle_t *client_id, int timeout_secs)
Check whether any change notifications are pending for this client.
Data Table Status.
int syncdbSet(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size)
Set an entry in the table.
syncdb Client Handle.
unsigned int table_status
Bit Mask.
unsigned int table_flags
Flags specified on table creation.
int syncdbDelete(syncdbClientHandle_t *client_id, char *table_name, void *element, unsigned int size)
Delete an entry from the AVL table.
int client_pid
Linux Process ID for this client.
unsigned int rxTimeout
Command socket receive timeout.