open-vm-tools 11.2.0
plugin.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2008-2020 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 #include <glib.h>
33 #if defined(G_PLATFORM_WIN32)
34 # include <windows.h>
35 # include <objbase.h>
36 #endif
37 #include "vmware/guestrpc/capabilities.h"
38 #include "vmware/tools/guestrpc.h"
39 #include "vmware/tools/utils.h"
40 
49 #define VMTOOLSAPP_ERROR(ctx, err) do { \
50  ASSERT((err) != 0); \
51  (ctx)->errorCode = (err); \
52  g_main_loop_quit((ctx)->mainLoop); \
53 } while (0)
54 
55 
65 #define VMTOOLSAPP_ATTACH_SOURCE(ctx, src, cb, data, destroy) do { \
66  GSource *__src = (src); \
67  g_source_set_callback(__src, (GSourceFunc) (cb), (data), (destroy)); \
68  g_source_attach(__src, g_main_loop_get_context((ctx)->mainLoop)); \
69 } while (0)
70 
75 #define TOOLS_IS_MAIN_SERVICE(ctx) (strcmp((ctx)->name, \
76  VMTOOLS_GUEST_SERVICE) == 0)
77 
82 #define TOOLS_IS_USER_SERVICE(ctx) (strcmp((ctx)->name, \
83  VMTOOLS_USER_SERVICE) == 0)
84 
85 /* Indentation levels for the state log function below. */
86 #define TOOLS_STATE_LOG_ROOT 0
87 #define TOOLS_STATE_LOG_CONTAINER 1
88 #define TOOLS_STATE_LOG_PLUGIN 2
89 
100 static inline void
101 ToolsCore_LogState(guint level,
102  const char *fmt,
103  ...)
104 {
105  gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt);
106 
107  va_list args;
108  va_start(args, fmt);
109  g_logv("state", G_LOG_LEVEL_INFO, indented, args);
110  va_end(args);
111 
112  g_free(indented);
113 }
114 
115 
127 #define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities"
128 
136 #define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload"
137 
147 #define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state"
148 
156 #define TOOLS_CORE_SIG_RESET "tcs_reset"
157 
165 #define TOOLS_CORE_SIG_NO_RPC "tcs_no_rpc"
166 
179 #define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
180 
188 #define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
189 
190 #if defined(G_PLATFORM_WIN32)
191 
218 #define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
219 
220 #endif
221 
229 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
230 
237 #define TOOLS_CORE_EVENTS_TOOLS_NEW_VERSION "VMToolsNewVersion"
238 
246 #define TOOLS_CORE_EVENTS_TOOLS_NEED_REBOOT "VMToolsNeedReboot"
247 
248 #define TOOLS_CORE_EVENTS_GLOBAL_SCOPE "Global"
249 
250 
251 
261 typedef enum {
262  TOOLS_CORE_API_V1 = 0x1,
263 } ToolsCoreAPI;
264 
265 
266 struct ToolsServiceProperty;
267 
275 typedef void (*RegisterServiceProperty)(gpointer obj,
276  struct ToolsServiceProperty *prop);
277 
282 typedef struct ToolsAppCtx {
286  const gchar *name;
288  gboolean isVMware;
292  GMainLoop *mainLoop;
294  RpcChannel *rpc;
296  GKeyFile *config;
297 #if defined(G_PLATFORM_WIN32)
298 
299  gboolean comInitialized;
300 #else
301 
302  int blockFD;
304  int uinputFD;
306  const char **envp;
307 #endif
308 
314  gpointer serviceObj;
315 
322 } ToolsAppCtx;
323 
324 #if defined(G_PLATFORM_WIN32)
325 
332 static inline gboolean
333 ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
334 {
335  if (!ctx->comInitialized) {
336  HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
337  ctx->comInitialized = SUCCEEDED(ret);
338  if (!ctx->comInitialized) {
339  g_log(ctx->name, G_LOG_LEVEL_WARNING,
340  "COM initialization failed(0x%x)\n", ret);
341  }
342  }
343  return ctx->comInitialized;
344 }
345 #endif
346 
347 
348 /* Capabilities. */
349 
351 typedef enum {
352  TOOLS_CAP_OLD = 0,
353  TOOLS_CAP_OLD_NOVAL = 1,
354  TOOLS_CAP_NEW = 2
356 
366 typedef struct ToolsAppCapability {
373  const gchar *name;
378  GuestCapabilities index;
380  guint value;
382 
383 
384 /* Application registration. */
385 
387 typedef enum {
408 } ToolsAppType;
409 
410 
411 struct ToolsPluginData;
412 
421 typedef struct ToolsAppProvider {
423  const gchar *name;
432  size_t regSize;
442  void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
454  gboolean (*registerApp)(ToolsAppCtx *ctx,
455  struct ToolsAppProvider *prov,
456  struct ToolsPluginData *plugin,
457  gpointer reg);
468  void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
481  void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
483 
484 
495 typedef struct ToolsAppReg {
496  ToolsAppType type;
497  GArray *data;
498 } ToolsAppReg;
499 
500 
514 typedef struct ToolsServiceProperty {
515  const char *name;
517 
518 
528 typedef struct ToolsPluginSignalCb {
529  const gchar *signame;
530  gpointer callback;
531  gpointer clientData;
533 
534 
549 typedef struct ToolsPluginData {
551  char const *name;
556  GArray *regs;
587  gboolean (*errorCb)(ToolsAppCtx *ctx,
588  ToolsAppType type,
589  gpointer data,
590  struct ToolsPluginData *plugin);
592  gpointer _private;
594 
600 #if defined(G_PLATFORM_WIN32)
601 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
602 #elif defined(GCC_EXPLICIT_EXPORT)
603 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
604 #else
605 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
606 #endif
607 
619 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
620 
623 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */
624 
struct ToolsPluginSignalCb ToolsPluginSignalCb
Definition: plugin.h:366
Definition: plugin.h:391
GuestCapabilities index
Definition: plugin.h:378
GKeyFile * config
Definition: plugin.h:296
gboolean isVMware
Definition: plugin.h:288
RpcChannel * rpc
Definition: plugin.h:294
int uinputFD
Definition: plugin.h:304
Definition: plugin.h:528
struct ToolsAppCtx ToolsAppCtx
int errorCode
Definition: plugin.h:290
ToolsAppType regType
Definition: plugin.h:430
ToolsCapabilityType type
Definition: plugin.h:368
struct ToolsAppProvider ToolsAppProvider
Definition: plugin.h:514
GMainLoop * mainLoop
Definition: plugin.h:292
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:481
int blockFD
Definition: plugin.h:302
Definition: plugin.h:407
void(* RegisterServiceProperty)(gpointer obj, struct ToolsServiceProperty *prop)
Definition: plugin.h:275
guint value
Definition: plugin.h:380
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:454
const gchar * name
Definition: plugin.h:286
gpointer _private
Definition: plugin.h:592
ToolsCapabilityType
Definition: plugin.h:351
GArray * regs
Definition: plugin.h:556
struct ToolsPluginData ToolsPluginData
Definition: plugin.h:495
ToolsAppType
Definition: plugin.h:387
Definition: plugin.h:421
Definition: plugin.h:396
gpointer serviceObj
Definition: plugin.h:314
const gchar * name
Definition: plugin.h:423
Definition: plugin.h:549
struct ToolsAppCapability ToolsAppCapability
Definition: plugin.h:402
RegisterServiceProperty registerServiceProperty
Definition: plugin.h:321
Definition: plugin.h:282
ToolsCoreAPI version
Definition: plugin.h:284
const gchar * name
Definition: plugin.h:373
const char ** envp
Definition: plugin.h:306
ToolsCoreAPI
Definition: plugin.h:261
char const * name
Definition: plugin.h:551
size_t regSize
Definition: plugin.h:432
struct ToolsAppReg ToolsAppReg
struct ToolsServiceProperty ToolsServiceProperty