open-vm-tools 13.1.10
plugin.h
Go to the documentation of this file.
1/*********************************************************
2 * Copyright (c) 2008-2026 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_PLUGIN_H_
21#define _VMWARE_TOOLS_PLUGIN_H_
22
32
33/*
34 * glib.h should not be placed inside `extern "C"' blocks.
35 * However, this header is often placed inside such blocks.
36 * Here we change back into C++ for glib.h
37 */
38#ifdef __cplusplus
39extern "C++" {
40#endif
41#include <glib.h>
42#ifdef __cplusplus
43}
44#endif
45
46#if defined(G_PLATFORM_WIN32)
47# include <windows.h>
48# include <objbase.h>
49#endif
50#include "vmware/guestrpc/capabilities.h"
52#include "vmware/tools/utils.h"
53
62#define VMTOOLSAPP_ERROR(ctx, err) do { \
63 ASSERT((err) != 0); \
64 (ctx)->errorCode = (err); \
65 g_main_loop_quit((ctx)->mainLoop); \
66} while (0)
67
68
78#define VMTOOLSAPP_ATTACH_SOURCE(ctx, src, cb, data, destroy) do { \
79 GSource *__src = (src); \
80 g_source_set_callback(__src, (GSourceFunc) (cb), (data), (destroy)); \
81 g_source_attach(__src, g_main_loop_get_context((ctx)->mainLoop)); \
82} while (0)
83
88#define TOOLS_IS_MAIN_SERVICE(ctx) (strcmp((ctx)->name, \
89 VMTOOLS_GUEST_SERVICE) == 0)
90
95#define TOOLS_IS_USER_SERVICE(ctx) (strcmp((ctx)->name, \
96 VMTOOLS_USER_SERVICE) == 0)
97
98/* Indentation levels for the state log function below. */
99#define TOOLS_STATE_LOG_ROOT 0
100#define TOOLS_STATE_LOG_CONTAINER 1
101#define TOOLS_STATE_LOG_PLUGIN 2
102
112
113static inline void
114ToolsCore_LogState(guint level,
115 const char *fmt,
116 ...)
117{
118 gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt);
119
120 va_list args;
121 va_start(args, fmt);
122 g_logv("state", G_LOG_LEVEL_INFO, indented, args);
123 va_end(args);
124
125 g_free(indented);
126}
127
128
140#define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities"
141
149#define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload"
150
160#define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state"
161
169#define TOOLS_CORE_SIG_RESET "tcs_reset"
170
178#define TOOLS_CORE_SIG_NO_RPC "tcs_no_rpc"
179
192#define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
193
204#define TOOLS_CORE_SIG_PRE_SHUTDOWN "tcs_pre_shutdown"
205
213#define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
214
215#if defined(G_PLATFORM_WIN32)
216
243#define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
244
245#endif
246
254#define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
255
262#define TOOLS_CORE_EVENTS_TOOLS_NEW_VERSION "VMToolsNewVersion"
263
271#define TOOLS_CORE_EVENTS_TOOLS_NEED_REBOOT "VMToolsNeedReboot"
272
273#define TOOLS_CORE_EVENTS_GLOBAL_SCOPE "Global"
274
275
276
286typedef enum {
287 TOOLS_CORE_API_V1 = 0x1,
289
290
292
300typedef void (*RegisterServiceProperty)(gpointer obj,
301 struct ToolsServiceProperty *prop);
302
307typedef struct ToolsAppCtx {
311 const gchar *name;
313 gboolean isVMware;
317 GMainLoop *mainLoop;
319 RpcChannel *rpc;
321 GKeyFile *config;
322#if defined(G_PLATFORM_WIN32)
324 gboolean comInitialized;
325#else
331 int envFD;
333 const char **envp;
334#endif
341 gpointer serviceObj;
342
350
351#if defined(G_PLATFORM_WIN32)
359static inline gboolean
360ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
361{
362 if (!ctx->comInitialized) {
363 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
364 ctx->comInitialized = SUCCEEDED(ret);
365 if (!ctx->comInitialized) {
366 g_log(ctx->name, G_LOG_LEVEL_WARNING,
367 "COM initialization failed(0x%x)\n", ret);
368 }
369 }
370 return ctx->comInitialized;
371}
372#endif
373
374
375/* Capabilities. */
376
378typedef enum {
379 TOOLS_CAP_OLD = 0,
380 TOOLS_CAP_OLD_NOVAL = 1,
381 TOOLS_CAP_NEW = 2
383
393typedef struct ToolsAppCapability {
400 const gchar *name;
405 GuestCapabilities index;
407 guint value;
409
410
411/* Application registration. */
412
436
437
438struct ToolsPluginData;
439
448typedef struct ToolsAppProvider {
450 const gchar *name;
459 size_t regSize;
469 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
481 gboolean (*registerApp)(ToolsAppCtx *ctx,
482 struct ToolsAppProvider *prov,
483 struct ToolsPluginData *plugin,
484 gpointer reg);
495 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
508 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
510
511
522typedef struct ToolsAppReg {
523 ToolsAppType type;
524 GArray *data;
526
527
541typedef struct ToolsServiceProperty {
542 const char *name;
544
545
554
555typedef struct ToolsPluginSignalCb {
556 const gchar *signame;
557 gpointer callback;
558 gpointer clientData;
560
561
576typedef struct ToolsPluginData {
578 char const *name;
583 GArray *regs;
614 gboolean (*errorCb)(ToolsAppCtx *ctx,
615 ToolsAppType type,
616 gpointer data,
617 struct ToolsPluginData *plugin);
619 gpointer _private;
621
627#if defined(G_PLATFORM_WIN32)
628# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
629#elif defined(GCC_EXPLICIT_EXPORT)
630# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
631#else
632# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
633#endif
634
646typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
647
649
650#endif /* _VMWARE_TOOLS_PLUGIN_H_ */
651
ToolsCapabilityType
Definition plugin.h:378
void(*) RegisterServiceProperty(gpointer obj, struct ToolsServiceProperty *prop)
Definition plugin.h:300
ToolsAppType
Definition plugin.h:414
ToolsCoreAPI
Definition plugin.h:286
@ TOOLS_APP_GUESTRPC
Definition plugin.h:418
@ TOOLS_APP_SIGNALS
Definition plugin.h:423
@ TOOLS_SVC_PROPERTY
Definition plugin.h:434
@ TOOLS_APP_PROVIDER
Definition plugin.h:429
Definition plugin.h:393
GuestCapabilities index
Definition plugin.h:405
const gchar * name
Definition plugin.h:400
guint value
Definition plugin.h:407
ToolsCapabilityType type
Definition plugin.h:395
Definition plugin.h:307
ToolsCoreAPI version
Definition plugin.h:309
GKeyFile * config
Definition plugin.h:321
GMainLoop * mainLoop
Definition plugin.h:317
RpcChannel * rpc
Definition plugin.h:319
int uinputFD
Definition plugin.h:329
RegisterServiceProperty registerServiceProperty
Definition plugin.h:348
int blockFD
Definition plugin.h:327
const char ** envp
Definition plugin.h:333
const gchar * name
Definition plugin.h:311
gpointer serviceObj
Definition plugin.h:341
gboolean isVMware
Definition plugin.h:313
int errorCode
Definition plugin.h:315
int envFD
Definition plugin.h:331
Definition plugin.h:448
gboolean(*) registerApp(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition plugin.h:481
const gchar * name
Definition plugin.h:450
size_t regSize
Definition plugin.h:459
void(*) dumpState(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition plugin.h:508
void(*) activate(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition plugin.h:469
void(*) shutdown(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition plugin.h:495
ToolsAppType regType
Definition plugin.h:457
Definition plugin.h:522
Definition plugin.h:576
char const * name
Definition plugin.h:578
gboolean(*) errorCb(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition plugin.h:614
GArray * regs
Definition plugin.h:583
gpointer _private
Definition plugin.h:619
Definition plugin.h:555
Definition plugin.h:541