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