open-vm-tools 10.3.10

plugin.h
Go to the documentation of this file.
1 /*********************************************************
2 * Copyright (C) 2008-2018 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
170 #define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
171
179 #define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
180
181 #if defined(G_PLATFORM_WIN32)
182
209 #define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
210
211 #endif
212
220 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
221
222
232 typedef enum {
233 TOOLS_CORE_API_V1 = 0x1,
234 } ToolsCoreAPI;
235
236
241 typedef struct ToolsAppCtx {
243 ToolsCoreAPI version;
245 const gchar *name;
247 gboolean isVMware;
249 int errorCode;
251 GMainLoop *mainLoop;
253 RpcChannel *rpc;
255 GKeyFile *config;
256 #if defined(G_PLATFORM_WIN32)
257
258 gboolean comInitialized;
259 #else
260
261 int blockFD;
263 int uinputFD;
265 const char **envp;
266 #endif
267
273 gpointer serviceObj;
274 } ToolsAppCtx;
275
276 #if defined(G_PLATFORM_WIN32)
277
284 G_INLINE_FUNC gboolean
285 ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
286 {
287 if (!ctx->comInitialized) {
288 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
289 ctx->comInitialized = SUCCEEDED(ret);
290 if (!ctx->comInitialized) {
291 g_log(ctx->name, G_LOG_LEVEL_WARNING,
292 "COM initialization failed(0x%x)\n", ret);
293 }
294 }
295 return ctx->comInitialized;
296 }
297 #endif
298
299
300 /* Capabilities. */
301
303 typedef enum {
304 TOOLS_CAP_OLD = 0,
305 TOOLS_CAP_OLD_NOVAL = 1,
306 TOOLS_CAP_NEW = 2
307 } ToolsCapabilityType;
308
318 typedef struct ToolsAppCapability {
320 ToolsCapabilityType type;
325 const gchar *name;
330 GuestCapabilities index;
332 guint value;
333 } ToolsAppCapability;
334
335
336 /* Application registration. */
337
339 typedef enum {
343 TOOLS_APP_GUESTRPC = 1,
348 TOOLS_APP_SIGNALS = 2,
354 TOOLS_APP_PROVIDER = 3,
359 TOOLS_SVC_PROPERTY = 4,
360 } ToolsAppType;
361
362
363 struct ToolsPluginData;
364
373 typedef struct ToolsAppProvider {
375 const gchar *name;
382 ToolsAppType regType;
384 size_t regSize;
394 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
406 gboolean (*registerApp)(ToolsAppCtx *ctx,
407 struct ToolsAppProvider *prov,
408 struct ToolsPluginData *plugin,
409 gpointer reg);
420 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
433 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
434 } ToolsAppProvider;
435
436
447 typedef struct ToolsAppReg {
448 ToolsAppType type;
449 GArray *data;
450 } ToolsAppReg;
451
452
466 typedef struct ToolsServiceProperty {
467 const char *name;
468 } ToolsServiceProperty;
469
470
480 typedef struct ToolsPluginSignalCb {
481 const gchar *signame;
482 gpointer callback;
483 gpointer clientData;
484 } ToolsPluginSignalCb;
485
486
501 typedef struct ToolsPluginData {
503 char const *name;
508 GArray *regs;
539 gboolean (*errorCb)(ToolsAppCtx *ctx,
540 ToolsAppType type,
541 gpointer data,
542 struct ToolsPluginData *plugin);
544 gpointer _private;
545 } ToolsPluginData;
546
552 #if defined(G_PLATFORM_WIN32)
553 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
554 #elif defined(GCC_EXPLICIT_EXPORT)
555 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
556 #else
557 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
558 #endif
559
571 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
572
575 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */
576
ToolsPluginSignalCb
struct ToolsPluginSignalCb ToolsPluginSignalCb
ToolsAppCapability
Definition: plugin.h:318
TOOLS_APP_GUESTRPC
Definition: plugin.h:343
ToolsAppCapability::index
GuestCapabilities index
Definition: plugin.h:330
ToolsAppCtx::config
GKeyFile * config
Definition: plugin.h:255
ToolsAppCtx::isVMware
gboolean isVMware
Definition: plugin.h:247
ToolsAppCtx::rpc
RpcChannel * rpc
Definition: plugin.h:253
ToolsAppProvider::activate
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition: plugin.h:394
ToolsAppCtx::uinputFD
int uinputFD
Definition: plugin.h:263
ToolsPluginSignalCb
Definition: plugin.h:480
ToolsAppCtx
struct ToolsAppCtx ToolsAppCtx
ToolsAppCtx::errorCode
int errorCode
Definition: plugin.h:249
ToolsAppProvider::regType
ToolsAppType regType
Definition: plugin.h:382
ToolsAppCapability::type
ToolsCapabilityType type
Definition: plugin.h:320
ToolsAppProvider
struct ToolsAppProvider ToolsAppProvider
ToolsServiceProperty
Definition: plugin.h:466
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition: plugin.h:251
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:433
ToolsAppCtx::blockFD
int blockFD
Definition: plugin.h:261
TOOLS_SVC_PROPERTY
Definition: plugin.h:359
utils.h
ToolsAppCapability::value
guint value
Definition: plugin.h:332
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:406
ToolsAppCtx::name
const gchar * name
Definition: plugin.h:245
ToolsPluginData::_private
gpointer _private
Definition: plugin.h:544
guestrpc.h
ToolsCapabilityType
ToolsCapabilityType
Definition: plugin.h:303
ToolsPluginData::regs
GArray * regs
Definition: plugin.h:508
ToolsPluginData
struct ToolsPluginData ToolsPluginData
ToolsAppReg
Definition: plugin.h:447
ToolsPluginData::errorCb
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition: plugin.h:539
ToolsAppType
ToolsAppType
Definition: plugin.h:339
ToolsAppProvider
Definition: plugin.h:373
TOOLS_APP_SIGNALS
Definition: plugin.h:348
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:273
ToolsAppProvider::name
const gchar * name
Definition: plugin.h:375
ToolsPluginData
Definition: plugin.h:501
ToolsAppCapability
struct ToolsAppCapability ToolsAppCapability
TOOLS_APP_PROVIDER
Definition: plugin.h:354
ToolsAppCtx
Definition: plugin.h:241
ToolsAppCtx::version
ToolsCoreAPI version
Definition: plugin.h:243
ToolsAppCapability::name
const gchar * name
Definition: plugin.h:325
ToolsAppCtx::envp
const char ** envp
Definition: plugin.h:265
ToolsAppProvider::shutdown
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition: plugin.h:420
ToolsCoreAPI
ToolsCoreAPI
Definition: plugin.h:232
ToolsPluginData::name
char const * name
Definition: plugin.h:503
ToolsAppProvider::regSize
size_t regSize
Definition: plugin.h:384
ToolsAppReg
struct ToolsAppReg ToolsAppReg
ToolsServiceProperty
struct ToolsServiceProperty ToolsServiceProperty