open-vm-tools 13.0.5

plugin.h
Go to the documentation of this file.
1/*********************************************************
2 * Copyright (c) 2008-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_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
39 extern "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"
51#include "vmware/tools/guestrpc.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
113 static 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
286 typedef enum {
287 TOOLS_CORE_API_V1 = 0x1,
288} ToolsCoreAPI;
289
290
291 struct ToolsServiceProperty;
292
300 typedef void (*RegisterServiceProperty)(gpointer obj,
301 struct ToolsServiceProperty *prop);
302
307 typedef struct ToolsAppCtx {
309 ToolsCoreAPI version;
311 const gchar *name;
313 gboolean isVMware;
315 int errorCode;
317 GMainLoop *mainLoop;
319 RpcChannel *rpc;
321 GKeyFile *config;
322#if defined(G_PLATFORM_WIN32)
324 gboolean comInitialized;
325#else
327 int blockFD;
329 int uinputFD;
331 const char **envp;
332#endif
339 gpointer serviceObj;
340
346 RegisterServiceProperty registerServiceProperty;
347} ToolsAppCtx;
348
349#if defined(G_PLATFORM_WIN32)
357 static inline gboolean
358ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
359{
360 if (!ctx->comInitialized) {
361 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
362 ctx->comInitialized = SUCCEEDED(ret);
363 if (!ctx->comInitialized) {
364 g_log(ctx->name, G_LOG_LEVEL_WARNING,
365 "COM initialization failed(0x%x)\n", ret);
366 }
367 }
368 return ctx->comInitialized;
369}
370#endif
371
372
373/* Capabilities. */
374
376 typedef enum {
377 TOOLS_CAP_OLD = 0,
378 TOOLS_CAP_OLD_NOVAL = 1,
379 TOOLS_CAP_NEW = 2
380} ToolsCapabilityType;
381
391 typedef struct ToolsAppCapability {
393 ToolsCapabilityType type;
398 const gchar *name;
403 GuestCapabilities index;
405 guint value;
406} ToolsAppCapability;
407
408
409/* Application registration. */
410
412 typedef enum {
416 TOOLS_APP_GUESTRPC = 1,
421 TOOLS_APP_SIGNALS = 2,
427 TOOLS_APP_PROVIDER = 3,
432 TOOLS_SVC_PROPERTY = 4,
433} ToolsAppType;
434
435
436 struct ToolsPluginData;
437
446 typedef struct ToolsAppProvider {
448 const gchar *name;
455 ToolsAppType regType;
457 size_t regSize;
467 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
479 gboolean (*registerApp)(ToolsAppCtx *ctx,
480 struct ToolsAppProvider *prov,
481 struct ToolsPluginData *plugin,
482 gpointer reg);
493 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
506 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
507} ToolsAppProvider;
508
509
520 typedef struct ToolsAppReg {
521 ToolsAppType type;
522 GArray *data;
523} ToolsAppReg;
524
525
539 typedef struct ToolsServiceProperty {
540 const char *name;
541} ToolsServiceProperty;
542
543
552
553 typedef struct ToolsPluginSignalCb {
554 const gchar *signame;
555 gpointer callback;
556 gpointer clientData;
557} ToolsPluginSignalCb;
558
559
574 typedef struct ToolsPluginData {
576 char const *name;
581 GArray *regs;
612 gboolean (*errorCb)(ToolsAppCtx *ctx,
613 ToolsAppType type,
614 gpointer data,
615 struct ToolsPluginData *plugin);
617 gpointer _private;
618} ToolsPluginData;
619
625#if defined(G_PLATFORM_WIN32)
626# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
627#elif defined(GCC_EXPLICIT_EXPORT)
628# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
629#else
630# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
631#endif
632
644 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
645
647
648#endif /* _VMWARE_TOOLS_PLUGIN_H_ */
649
ToolsCapabilityType
ToolsCapabilityType
Definition plugin.h:376
RegisterServiceProperty
void(* RegisterServiceProperty)(gpointer obj, struct ToolsServiceProperty *prop)
Definition plugin.h:300
ToolsAppType
ToolsAppType
Definition plugin.h:412
ToolsCoreAPI
ToolsCoreAPI
Definition plugin.h:286
TOOLS_APP_GUESTRPC
@ TOOLS_APP_GUESTRPC
Definition plugin.h:416
TOOLS_APP_SIGNALS
@ TOOLS_APP_SIGNALS
Definition plugin.h:421
TOOLS_SVC_PROPERTY
@ TOOLS_SVC_PROPERTY
Definition plugin.h:432
TOOLS_APP_PROVIDER
@ TOOLS_APP_PROVIDER
Definition plugin.h:427
guestrpc.h
ToolsAppCapability
Definition plugin.h:391
ToolsAppCapability::index
GuestCapabilities index
Definition plugin.h:403
ToolsAppCapability::name
const gchar * name
Definition plugin.h:398
ToolsAppCapability::value
guint value
Definition plugin.h:405
ToolsAppCapability::type
ToolsCapabilityType type
Definition plugin.h:393
ToolsAppCtx
Definition plugin.h:307
ToolsAppCtx::version
ToolsCoreAPI version
Definition plugin.h:309
ToolsAppCtx::config
GKeyFile * config
Definition plugin.h:321
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition plugin.h:317
ToolsAppCtx::rpc
RpcChannel * rpc
Definition plugin.h:319
ToolsAppCtx::uinputFD
int uinputFD
Definition plugin.h:329
ToolsAppCtx::registerServiceProperty
RegisterServiceProperty registerServiceProperty
Definition plugin.h:346
ToolsAppCtx::blockFD
int blockFD
Definition plugin.h:327
ToolsAppCtx::envp
const char ** envp
Definition plugin.h:331
ToolsAppCtx::name
const gchar * name
Definition plugin.h:311
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition plugin.h:339
ToolsAppCtx::isVMware
gboolean isVMware
Definition plugin.h:313
ToolsAppCtx::errorCode
int errorCode
Definition plugin.h:315
ToolsAppProvider
Definition plugin.h:446
ToolsAppProvider::shutdown
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition plugin.h:493
ToolsAppProvider::name
const gchar * name
Definition plugin.h:448
ToolsAppProvider::regSize
size_t regSize
Definition plugin.h:457
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition plugin.h:479
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition plugin.h:506
ToolsAppProvider::activate
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition plugin.h:467
ToolsAppProvider::regType
ToolsAppType regType
Definition plugin.h:455
ToolsAppReg
Definition plugin.h:520
ToolsPluginData
Definition plugin.h:574
ToolsPluginData::name
char const * name
Definition plugin.h:576
ToolsPluginData::errorCb
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition plugin.h:612
ToolsPluginData::regs
GArray * regs
Definition plugin.h:581
ToolsPluginData::_private
gpointer _private
Definition plugin.h:617
ToolsPluginSignalCb
Definition plugin.h:553
ToolsServiceProperty
Definition plugin.h:539
utils.h