open-vm-tools 13.0.0
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 
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 
113 static inline void
114 ToolsCore_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 {
311  const gchar *name;
313  gboolean isVMware;
317  GMainLoop *mainLoop;
319  RpcChannel *rpc;
321  GKeyFile *config;
322 #if defined(G_PLATFORM_WIN32)
323 
324  gboolean comInitialized;
325 #else
326 
327  int blockFD;
329  int uinputFD;
331  const char **envp;
332 #endif
333 
339  gpointer serviceObj;
340 
347 } ToolsAppCtx;
348 
349 #if defined(G_PLATFORM_WIN32)
350 
357 static inline gboolean
358 ToolsCore_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
381 
391 typedef struct ToolsAppCapability {
398  const gchar *name;
403  GuestCapabilities index;
405  guint value;
407 
408 
409 /* Application registration. */
410 
412 typedef enum {
433 } ToolsAppType;
434 
435 
436 struct ToolsPluginData;
437 
446 typedef struct ToolsAppProvider {
448  const gchar *name;
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);
508 
509 
520 typedef struct ToolsAppReg {
521  ToolsAppType type;
522  GArray *data;
523 } ToolsAppReg;
524 
525 
539 typedef struct ToolsServiceProperty {
540  const char *name;
542 
543 
553 typedef struct ToolsPluginSignalCb {
554  const gchar *signame;
555  gpointer callback;
556  gpointer clientData;
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;
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 
648 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */
649 
struct ToolsPluginSignalCb ToolsPluginSignalCb
Definition: plugin.h:391
Definition: plugin.h:416
GuestCapabilities index
Definition: plugin.h:403
GKeyFile * config
Definition: plugin.h:321
gboolean isVMware
Definition: plugin.h:313
RpcChannel * rpc
Definition: plugin.h:319
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition: plugin.h:467
int uinputFD
Definition: plugin.h:329
Definition: plugin.h:553
struct ToolsAppCtx ToolsAppCtx
int errorCode
Definition: plugin.h:315
ToolsAppType regType
Definition: plugin.h:455
ToolsCapabilityType type
Definition: plugin.h:393
struct ToolsAppProvider ToolsAppProvider
Definition: plugin.h:539
GMainLoop * mainLoop
Definition: plugin.h:317
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:506
int blockFD
Definition: plugin.h:327
Definition: plugin.h:432
void(* RegisterServiceProperty)(gpointer obj, struct ToolsServiceProperty *prop)
Definition: plugin.h:300
guint value
Definition: plugin.h:405
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:479
const gchar * name
Definition: plugin.h:311
gpointer _private
Definition: plugin.h:617
ToolsCapabilityType
Definition: plugin.h:376
GArray * regs
Definition: plugin.h:581
struct ToolsPluginData ToolsPluginData
Definition: plugin.h:520
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition: plugin.h:612
ToolsAppType
Definition: plugin.h:412
Definition: plugin.h:446
Definition: plugin.h:421
gpointer serviceObj
Definition: plugin.h:339
const gchar * name
Definition: plugin.h:448
Definition: plugin.h:574
struct ToolsAppCapability ToolsAppCapability
Definition: plugin.h:427
RegisterServiceProperty registerServiceProperty
Definition: plugin.h:346
Definition: plugin.h:307
ToolsCoreAPI version
Definition: plugin.h:309
const gchar * name
Definition: plugin.h:398
const char ** envp
Definition: plugin.h:331
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition: plugin.h:493
ToolsCoreAPI
Definition: plugin.h:286
char const * name
Definition: plugin.h:576
size_t regSize
Definition: plugin.h:457
struct ToolsAppReg ToolsAppReg
struct ToolsServiceProperty ToolsServiceProperty