open-vm-tools 12.5.2
gdp.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (c) 2020-2021,2023-2024 Broadcom. All rights reserved.
3  * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation version 2.1 and no later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  *********************************************************/
19 
20 #ifndef _VMWARE_TOOLS_GDP_H_
21 #define _VMWARE_TOOLS_GDP_H_
22 
29 /*
30  * glib-object.h should not be placed inside `extern "C"' blocks.
31  * However, this header is often placed inside such blocks.
32  * Here we change back into C++ for glib-object.h
33  */
34 #ifdef __cplusplus
35 extern "C++" {
36 #endif
37 #include <glib-object.h>
38 #ifdef __cplusplus
39 }
40 #endif
41 
42 #include "vmware/tools/plugin.h"
43 
44 /*
45  * GDP Protocol version
46  */
47 #define GDP_PROTOCOL_VERSION 2
48 
49 /*
50  * GDP Protocol version before versioning was introduced.
51  */
52 #define GDP_PROTOCOL_UNVERSIONED_VERSION 1
53 
54 /*
55  * First GDP Protocol version to support versioning.
56  */
57 #define GDP_PROTOCOL_VERSIONED_VERSION 2
58 
59 /*
60  * Maximum GDP Data Message protocol version generated by GDP plugin.
61  */
62 #define GDP_PROTOCOL_DM_MAX_VERSION GDP_PROTOCOL_VERSION
63 
64 /*
65  * Maximum GDP Data Message Response protocol version handled by GDP plugin.
66  */
67 #define GDP_PROTOCOL_DM_RESP_MAX_VERSION GDP_PROTOCOL_VERSION
68 
69 /*
70  * Size in bytes:
71  * 17 * 4096 - Maximum VMCI datagram size
72  * 24 - VMCI datagram header size
73  */
74 #define GDP_MAX_PACKET_LEN (17 * 4096 - 24)
75 
76 /*
77  * Limit GDP packet JSON base64 key value size to (16 * 4096) bytes, then
78  * the rest JSON content will have (4096 - 24) bytes available.
79  *
80  * Base64 (16 * 4096) bytes are (12 * 4096) bytes before encoding.
81  */
82 #define GDP_USER_DATA_LEN (12 * 4096)
83 
84 /*
85  * Property name of the gdp plugin service in the tools
86  * applicatin context service object.
87  */
88 #define TOOLS_PLUGIN_SVC_PROP_GDP "tps_prop_gdp"
89 
90 /*
91  * GdpError definitions.
92  * The GDP_ERR_ITEM Tuple is:
93  * - GdpEnum name
94  * - error-id string id
95  * - Default error message string
96  *
97  * GDP_ERR_MAX item MUST BE LAST
98  */
99 #define GDP_ERR_LIST \
100  GDP_ERR_ITEM(GDP_ERROR_SUCCESS = 0, \
101  "success", \
102  "No error") \
103  GDP_ERR_ITEM(GDP_ERROR_INVALID_DATA, \
104  "invalid-data", \
105  "Invalid data") \
106  GDP_ERR_ITEM(GDP_ERROR_DATA_SIZE, \
107  "data-size", \
108  "Data size too large") \
109  GDP_ERR_ITEM(GDP_ERROR_GENERAL, \
110  "error", \
111  "General error") \
112  GDP_ERR_ITEM(GDP_ERROR_STOP, \
113  "stopped-for-shutdown", \
114  "Stopped for vmtoolsd shutdown") \
115  GDP_ERR_ITEM(GDP_ERROR_UNREACH, \
116  "publisher-unreachable", \
117  "Host daemon unreachable") \
118  GDP_ERR_ITEM(GDP_ERROR_TIMEOUT, \
119  "timeout", \
120  "Operation timed out") \
121  GDP_ERR_ITEM(GDP_ERROR_NO_SUBSCRIBERS, \
122  "no-subscribers", \
123  "No subscribers for data") \
124  GDP_ERR_ITEM(GDP_ERR_MAX, \
125  "last-error", \
126  "last-error")
127 
128 /*
129  * GdpError codes enum.
130  */
131 #define GDP_ERR_ITEM(a, b, c) a,
132 typedef enum GdpError {
133  GDP_ERR_LIST
134 } GdpError;
135 #undef GDP_ERR_ITEM
136 
137 
144 typedef struct ToolsPluginSvcGdp {
145  GdpError (*publish)(gint64 createTime,
146  const gchar *topic,
147  const gchar *token,
148  const gchar *category,
149  const gchar *data,
150  guint32 dataLen,
151  gboolean cacheData,
152  gboolean requireSubs);
154 
155 
156 /*
157  ******************************************************************************
158  * ToolsPluginSvcGdp_Publish -- */
184 static inline GdpError
185 ToolsPluginSvcGdp_Publish(ToolsAppCtx *ctx, // IN
186  gint64 createTime, // IN
187  const gchar *topic, // IN
188  const gchar *token, // IN, OPTIONAL
189  const gchar *category, // IN, OPTIONAL
190  const gchar *data, // IN
191  guint32 dataLen, // IN
192  gboolean cacheData, // IN
193  gboolean requireSubs) // IN
194 {
195  ToolsPluginSvcGdp *svcGdp = NULL;
196  g_object_get(ctx->serviceObj, TOOLS_PLUGIN_SVC_PROP_GDP, &svcGdp, NULL);
197  if (svcGdp != NULL && svcGdp->publish != NULL) {
198  return svcGdp->publish(createTime, topic, token,
199  category, data, dataLen, cacheData, requireSubs);
200  }
201  return GDP_ERROR_GENERAL;
202 }
203 
204 #endif /* _VMWARE_TOOLS_GDP_H_ */
Type of the public interface of the gdp plugin service.
Definition: gdp.h:144
gpointer serviceObj
Definition: plugin.h:326
struct ToolsPluginSvcGdp ToolsPluginSvcGdp
Type of the public interface of the gdp plugin service.
Definition: plugin.h:294