summaryrefslogtreecommitdiff
path: root/open-vm-tools/lib/include/dataMap.h
blob: 690037fd036a2339b1a4ef36e3abb5d2a1651e28 (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
/*********************************************************
 * Copyright (C) 2013 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*********************************************************
 * The contents of this file are subject to the terms of the Common
 * Development and Distribution License (the "License") version 1.0
 * and no later version.  You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 *         http://www.opensource.org/licenses/cddl1.php
 *
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 *********************************************************/

#ifndef _DATA_MAP_H_
#define _DATA_MAP_H_

#include "hashMap.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef int32 DMKeyType;

/*
 * Error codes for DataMap APIs
 */
typedef enum {
   DMERR_SUCCESS,                  /* success code */
   DMERR_NOT_FOUND,                /* data does not exist */
   DMERR_ALREADY_EXIST,            /* field ID already exist */
   DMERR_DUPLICATED_FIELD_IDS,     /* duplicated IDs in deserilization */
   DMERR_INSUFFICIENT_MEM,         /* insufficient memory */
   DMERR_TYPE_MISMATCH,            /* type does not match */
   DMERR_INVALID_ARGS,             /* invalid arguments */
   DMERR_UNKNOWN_TYPE,             /* type unknow in decoding */
   DMERR_TRUNCATED_DATA,           /* more data expected during decoding */
   DMERR_BUFFER_TOO_SMALL,         /* a user buffer is too small */
} ErrorCode;

/*
 * Data field types
 */
typedef enum {
   DMFIELDTYPE_EMPTY,
   DMFIELDTYPE_INT64,
   DMFIELDTYPE_STRING,
   DMFIELDTYPE_INT64LIST,
   DMFIELDTYPE_STRINGLIST,
   DMFIELDTYPE_MAX
} DMFieldType;

typedef struct {
   HashMap *map;
   uint64 cookie;   /* so we know the datamap is not some garbage data */
} DataMap;

typedef struct {
   DMKeyType fieldId;
   const char *fieldName;
} FieldIdNameEntry;

/*
 * Initializer
 */
ErrorCode
DataMap_Create(DataMap *that);   // IN/OUT
ErrorCode
DataMap_Destroy(DataMap *that);   // IN/OUT
ErrorCode
DataMap_Copy(const DataMap *src,  // IN
             DataMap *dst);       // OUT
ErrorCode
DataMap_Serialize(const DataMap *that,   //IN
                  char **buf,            // OUT
                  int *bufLen);          // OUT
ErrorCode
DataMap_Deserialize(const char *bufIn,     // IN
                    const int32 bufLen,    // IN
                    DataMap *that);        // OUT

ErrorCode
DataMap_DeserializeContent(const char *bufIn,     // IN
                           const int32 bufLen,    // IN
                           DataMap *that);        // OUT
/*
 * Setters
 */

ErrorCode
DataMap_SetInt64(DataMap *that,      // IN/OUT
                 DMKeyType fieldId,  // IN
                 int64 value,        // IN
                 Bool replace);      // IN
ErrorCode
DataMap_SetString(DataMap *that,       // IN/OUT
                  DMKeyType fieldId,   // IN
                  char *str,           // IN
                  int32 strLen,        // IN
                  Bool replace);       // IN
ErrorCode
DataMap_SetInt64List(DataMap *that,        // IN/OUT
                     DMKeyType fieldId,    // IN
                     int64 *numList,       // IN
                     int32 listLen,        // IN
                     Bool replace);        // IN
ErrorCode
DataMap_SetStringList(DataMap *that,          // IN/OUT
                      DMKeyType fieldId,      // IN
                      char **strList,         // IN
                      int32 *strLens,         // IN
                      Bool replace);          // IN

/*
 *  Getters
 */

DMFieldType
DataMap_GetType(const DataMap *that,    // IN
                DMKeyType fieldId);     // IN

ErrorCode
DataMap_GetInt64(const DataMap *that,      // IN
                 DMKeyType fieldId,        // IN
                 int64 *value);            // OUT

ErrorCode
DataMap_GetString(const DataMap *that,      // IN
                  DMKeyType fieldId,        // IN
                  char **str,               // OUT
                  int32 *strLen);           // OUT

ErrorCode
DataMap_GetInt64List(const DataMap *that,      // IN
                     DMKeyType fieldId,        // IN
                     int64 **numList,          // OUT
                     int32 *listLen);          // OUT
ErrorCode
DataMap_GetStringList(const DataMap *that,      // IN
                      DMKeyType fieldId,        // IN
                      char ***strList,          // OUT
                      int32 **strLens);         // OUT

ErrorCode
DataMap_ToString(const DataMap *that,               // IN
                 FieldIdNameEntry *fieldIdList,     // IN
                 int32 fieldIdListLen,              // IN
                 int32 maxNumElements,              // IN
                 int32 maxStrLen,                   // IN
                 char **buf);                       // OUT

#ifdef __cplusplus
}    /* end of extern "C"  */
#endif


#endif // #ifdef _DATA_MAP_H_