open-vm-tools 12.4.5
plugin.h
Go to the documentation of this file.
1/*********************************************************
2 * Copyright (c) 2008-2020,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_PLUGIN_H_
20#define _VMWARE_TOOLS_PLUGIN_H_
21
32/*
33 * glib.h should not be placed inside `extern "C"' blocks.
34 * However, this header is often placed inside such blocks.
35 * Here we change back into C++ for glib.h
36 */
37#ifdef __cplusplus
38extern "C++" {
39#endif
40#include <glib.h>
41#ifdef __cplusplus
42}
43#endif
44
45#if defined(G_PLATFORM_WIN32)
46# include <windows.h>
47# include <objbase.h>
48#endif
49#include "vmware/guestrpc/capabilities.h"
51#include "vmware/tools/utils.h"
52
61#define VMTOOLSAPP_ERROR(ctx, err) do { \
62 ASSERT((err) != 0); \
63 (ctx)->errorCode = (err); \
64 g_main_loop_quit((ctx)->mainLoop); \
65} while (0)
66
67
77#define VMTOOLSAPP_ATTACH_SOURCE(ctx, src, cb, data, destroy) do { \
78 GSource *__src = (src); \
79 g_source_set_callback(__src, (GSourceFunc) (cb), (data), (destroy)); \
80 g_source_attach(__src, g_main_loop_get_context((ctx)->mainLoop)); \
81} while (0)
82
87#define TOOLS_IS_MAIN_SERVICE(ctx) (strcmp((ctx)->name, \
88 VMTOOLS_GUEST_SERVICE) == 0)
89
94#define TOOLS_IS_USER_SERVICE(ctx) (strcmp((ctx)->name, \
95 VMTOOLS_USER_SERVICE) == 0)
96
97/* Indentation levels for the state log function below. */
98#define TOOLS_STATE_LOG_ROOT 0
99#define TOOLS_STATE_LOG_CONTAINER 1
100#define TOOLS_STATE_LOG_PLUGIN 2
101
112static inline void
113ToolsCore_LogState(guint level,
114 const char *fmt,
115 ...)
116{
117 gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt);
118
119 va_list args;
120 va_start(args, fmt);
121 g_logv("state", G_LOG_LEVEL_INFO, indented, args);
122 va_end(args);
123
124 g_free(indented);
125}
126
127
139#define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities"
140
148#define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload"
149
159#define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state"
160
168#define TOOLS_CORE_SIG_RESET "tcs_reset"
169
177#define TOOLS_CORE_SIG_NO_RPC "tcs_no_rpc"
178
191#define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
192
200#define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
201
202#if defined(G_PLATFORM_WIN32)
203
230#define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
231
232#endif
233
241#define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
242
249#define TOOLS_CORE_EVENTS_TOOLS_NEW_VERSION "VMToolsNewVersion"
250
258#define TOOLS_CORE_EVENTS_TOOLS_NEED_REBOOT "VMToolsNeedReboot"
259
260#define TOOLS_CORE_EVENTS_GLOBAL_SCOPE "Global"
261
262
263
273typedef enum {
274 TOOLS_CORE_API_V1 = 0x1,
276
277
279
287typedef void (*RegisterServiceProperty)(gpointer obj,
288 struct ToolsServiceProperty *prop);
289
294typedef struct ToolsAppCtx {
298 const gchar *name;
300 gboolean isVMware;
304 GMainLoop *mainLoop;
306 RpcChannel *rpc;
308 GKeyFile *config;
309#if defined(G_PLATFORM_WIN32)
311 gboolean comInitialized;
312#else
318 const char **envp;
319#endif
326 gpointer serviceObj;
327
335
336#if defined(G_PLATFORM_WIN32)
344static inline gboolean
345ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
346{
347 if (!ctx->comInitialized) {
348 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
349 ctx->comInitialized = SUCCEEDED(ret);
350 if (!ctx->comInitialized) {
351 g_log(ctx->name, G_LOG_LEVEL_WARNING,
352 "COM initialization failed(0x%x)\n", ret);
353 }
354 }
355 return ctx->comInitialized;
356}
357#endif
358
359
360/* Capabilities. */
361
363typedef enum {
364 TOOLS_CAP_OLD = 0,
365 TOOLS_CAP_OLD_NOVAL = 1,
366 TOOLS_CAP_NEW = 2
368
378typedef struct ToolsAppCapability {
385 const gchar *name;
390 GuestCapabilities index;
392 guint value;
394
395
396/* Application registration. */
397
421
422
423struct ToolsPluginData;
424
433typedef struct ToolsAppProvider {
435 const gchar *name;
444 size_t regSize;
454 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
466 gboolean (*registerApp)(ToolsAppCtx *ctx,
467 struct ToolsAppProvider *prov,
468 struct ToolsPluginData *plugin,
469 gpointer reg);
480 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
493 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
495
496
507typedef struct ToolsAppReg {
508 ToolsAppType type;
509 GArray *data;
511
512
526typedef struct ToolsServiceProperty {
527 const char *name;
529
530
540typedef struct ToolsPluginSignalCb {
541 const gchar *signame;
542 gpointer callback;
543 gpointer clientData;
545
546
561typedef struct ToolsPluginData {
563 char const *name;
568 GArray *regs;
599 gboolean (*errorCb)(ToolsAppCtx *ctx,
600 ToolsAppType type,
601 gpointer data,
602 struct ToolsPluginData *plugin);
604 gpointer _private;
606
612#if defined(G_PLATFORM_WIN32)
613# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
614#elif defined(GCC_EXPLICIT_EXPORT)
615# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
616#else
617# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
618#endif
619
631typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
632
635#endif /* _VMWARE_TOOLS_PLUGIN_H_ */
636
struct ToolsAppCtx ToolsAppCtx
ToolsCapabilityType
Definition plugin.h:363
struct ToolsPluginSignalCb ToolsPluginSignalCb
struct ToolsAppCapability ToolsAppCapability
struct ToolsAppReg ToolsAppReg
void(* RegisterServiceProperty)(gpointer obj, struct ToolsServiceProperty *prop)
Definition plugin.h:287
ToolsAppType
Definition plugin.h:399
struct ToolsAppProvider ToolsAppProvider
ToolsCoreAPI
Definition plugin.h:273
struct ToolsServiceProperty ToolsServiceProperty
struct ToolsPluginData ToolsPluginData
@ TOOLS_APP_GUESTRPC
Definition plugin.h:403
@ TOOLS_APP_SIGNALS
Definition plugin.h:408
@ TOOLS_SVC_PROPERTY
Definition plugin.h:419
@ TOOLS_APP_PROVIDER
Definition plugin.h:414
Definition plugin.h:378
GuestCapabilities index
Definition plugin.h:390
const gchar * name
Definition plugin.h:385
guint value
Definition plugin.h:392
ToolsCapabilityType type
Definition plugin.h:380
Definition plugin.h:294
ToolsCoreAPI version
Definition plugin.h:296
GKeyFile * config
Definition plugin.h:308
GMainLoop * mainLoop
Definition plugin.h:304
RpcChannel * rpc
Definition plugin.h:306
int uinputFD
Definition plugin.h:316
RegisterServiceProperty registerServiceProperty
Definition plugin.h:333
int blockFD
Definition plugin.h:314
const char ** envp
Definition plugin.h:318
const gchar * name
Definition plugin.h:298
gpointer serviceObj
Definition plugin.h:326
gboolean isVMware
Definition plugin.h:300
int errorCode
Definition plugin.h:302
Definition plugin.h:433
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition plugin.h:480
const gchar * name
Definition plugin.h:435
size_t regSize
Definition plugin.h:444
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition plugin.h:466
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition plugin.h:493
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition plugin.h:454
ToolsAppType regType
Definition plugin.h:442
Definition plugin.h:507
Definition plugin.h:561
char const * name
Definition plugin.h:563
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition plugin.h:599
GArray * regs
Definition plugin.h:568
gpointer _private
Definition plugin.h:604
Definition plugin.h:540
Definition plugin.h:526