open-vm-tools 11.2.0
plugin.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2008-2019,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 
227 #define TOOLS_CORE_SIG_GLOBALCONF_UPDATE "tcs_globalconf_update"
228 
229 #endif
230 
238 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
239 
247 #define TOOLS_CORE_EVENTS_TOOLS_NEED_REBOOT "VMToolsNeedReboot"
248 
249 #define TOOLS_CORE_EVENTS_GLOBAL_SCOPE "Global"
250 
251 
252 
262 typedef enum {
263  TOOLS_CORE_API_V1 = 0x1,
264 } ToolsCoreAPI;
265 
266 
271 typedef struct ToolsAppCtx {
275  const gchar *name;
277  gboolean isVMware;
281  GMainLoop *mainLoop;
283  RpcChannel *rpc;
285  GKeyFile *config;
286 #if defined(G_PLATFORM_WIN32)
287 
288  gboolean comInitialized;
289 #else
290 
291  int blockFD;
293  int uinputFD;
295  const char **envp;
296 #endif
297 
303  gpointer serviceObj;
305 
306 #if defined(G_PLATFORM_WIN32)
307 
314 static inline gboolean
315 ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
316 {
317  if (!ctx->comInitialized) {
318  HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
319  ctx->comInitialized = SUCCEEDED(ret);
320  if (!ctx->comInitialized) {
321  g_log(ctx->name, G_LOG_LEVEL_WARNING,
322  "COM initialization failed(0x%x)\n", ret);
323  }
324  }
325  return ctx->comInitialized;
326 }
327 #endif
328 
329 
330 /* Capabilities. */
331 
333 typedef enum {
334  TOOLS_CAP_OLD = 0,
335  TOOLS_CAP_OLD_NOVAL = 1,
336  TOOLS_CAP_NEW = 2
338 
348 typedef struct ToolsAppCapability {
355  const gchar *name;
360  GuestCapabilities index;
362  guint value;
364 
365 
366 /* Application registration. */
367 
369 typedef enum {
390 } ToolsAppType;
391 
392 
393 struct ToolsPluginData;
394 
403 typedef struct ToolsAppProvider {
405  const gchar *name;
414  size_t regSize;
424  void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
436  gboolean (*registerApp)(ToolsAppCtx *ctx,
437  struct ToolsAppProvider *prov,
438  struct ToolsPluginData *plugin,
439  gpointer reg);
450  void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
463  void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
465 
466 
477 typedef struct ToolsAppReg {
478  ToolsAppType type;
479  GArray *data;
481 
482 
496 typedef struct ToolsServiceProperty {
497  const char *name;
499 
500 
510 typedef struct ToolsPluginSignalCb {
511  const gchar *signame;
512  gpointer callback;
513  gpointer clientData;
515 
516 
531 typedef struct ToolsPluginData {
533  char const *name;
538  GArray *regs;
569  gboolean (*errorCb)(ToolsAppCtx *ctx,
570  ToolsAppType type,
571  gpointer data,
572  struct ToolsPluginData *plugin);
574  gpointer _private;
576 
582 #if defined(G_PLATFORM_WIN32)
583 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
584 #elif defined(GCC_EXPLICIT_EXPORT)
585 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
586 #else
587 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
588 #endif
589 
601 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
602 
605 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */
606 
TOOLS_APP_GUESTRPC
@ TOOLS_APP_GUESTRPC
Definition: plugin.h:373
ToolsAppProvider::activate
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition: plugin.h:424
ToolsAppProvider::regSize
size_t regSize
Definition: plugin.h:414
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:463
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:303
ToolsAppCtx
struct ToolsAppCtx ToolsAppCtx
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:436
ToolsPluginData
struct ToolsPluginData ToolsPluginData
ToolsAppReg
Definition: plugin.h:477
ToolsPluginData
Definition: plugin.h:531
ToolsServiceProperty
Definition: plugin.h:496
guestrpc.h
ToolsPluginData::name
char const * name
Definition: plugin.h:533
ToolsAppProvider::regType
ToolsAppType regType
Definition: plugin.h:412
ToolsAppCtx::version
ToolsCoreAPI version
Definition: plugin.h:273
ToolsAppCapability::name
const gchar * name
Definition: plugin.h:355
ToolsAppProvider
Definition: plugin.h:403
ToolsAppCtx::envp
const char ** envp
Definition: plugin.h:295
TOOLS_SVC_PROPERTY
@ TOOLS_SVC_PROPERTY
Definition: plugin.h:389
ToolsAppCapability
struct ToolsAppCapability ToolsAppCapability
utils.h
ToolsAppCtx::rpc
RpcChannel * rpc
Definition: plugin.h:283
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition: plugin.h:281
ToolsAppProvider
struct ToolsAppProvider ToolsAppProvider
ToolsAppCtx
Definition: plugin.h:271
ToolsAppCtx::config
GKeyFile * config
Definition: plugin.h:285
ToolsAppCapability
Definition: plugin.h:348
ToolsCoreAPI
ToolsCoreAPI
Definition: plugin.h:262
ToolsPluginSignalCb
Definition: plugin.h:510
ToolsCapabilityType
ToolsCapabilityType
Definition: plugin.h:333
ToolsAppCtx::errorCode
int errorCode
Definition: plugin.h:279
ToolsAppCapability::index
GuestCapabilities index
Definition: plugin.h:360
ToolsPluginSignalCb
struct ToolsPluginSignalCb ToolsPluginSignalCb
TOOLS_APP_SIGNALS
@ TOOLS_APP_SIGNALS
Definition: plugin.h:378
ToolsAppProvider::shutdown
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition: plugin.h:450
ToolsAppType
ToolsAppType
Definition: plugin.h:369
ToolsAppCtx::uinputFD
int uinputFD
Definition: plugin.h:293
TOOLS_APP_PROVIDER
@ TOOLS_APP_PROVIDER
Definition: plugin.h:384
ToolsServiceProperty
struct ToolsServiceProperty ToolsServiceProperty
ToolsAppProvider::name
const gchar * name
Definition: plugin.h:405
ToolsPluginData::_private
gpointer _private
Definition: plugin.h:574
ToolsAppCtx::blockFD
int blockFD
Definition: plugin.h:291
ToolsPluginData::regs
GArray * regs
Definition: plugin.h:538
ToolsAppReg
struct ToolsAppReg ToolsAppReg
ToolsAppCapability::value
guint value
Definition: plugin.h:362
ToolsAppCtx::name
const gchar * name
Definition: plugin.h:275
ToolsAppCtx::isVMware
gboolean isVMware
Definition: plugin.h:277
ToolsPluginData::errorCb
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition: plugin.h:569
ToolsAppCapability::type
ToolsCapabilityType type
Definition: plugin.h:350