open-vm-tools 9.4.0
plugin.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2008 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 
71 /* Indentation levels for the state log function below. */
72 #define TOOLS_STATE_LOG_ROOT 0
73 #define TOOLS_STATE_LOG_CONTAINER 1
74 #define TOOLS_STATE_LOG_PLUGIN 2
75 
86 static inline void
87 ToolsCore_LogState(guint level,
88  const char *fmt,
89  ...)
90 {
91  gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt);
92 
93  va_list args;
94  va_start(args, fmt);
95  g_logv("state", G_LOG_LEVEL_INFO, indented, args);
96  va_end(args);
97 
98  g_free(indented);
99 }
100 
101 
113 #define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities"
114 
122 #define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload"
123 
133 #define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state"
134 
142 #define TOOLS_CORE_SIG_RESET "tcs_reset"
143 
156 #define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
157 
165 #define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
166 
167 #if defined(G_PLATFORM_WIN32)
168 
195 #define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
196 
197 #endif
198 
206 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
207 
208 
218 typedef enum {
219  TOOLS_CORE_API_V1 = 0x1,
220 } ToolsCoreAPI;
221 
222 
227 typedef struct ToolsAppCtx {
231  const gchar *name;
233  gboolean isVMware;
237  GMainLoop *mainLoop;
241  GKeyFile *config;
242 #if defined(G_PLATFORM_WIN32)
243 
244  gboolean comInitialized;
245 #else
246 
247  int blockFD;
249  const char **envp;
250 #endif
251 
257  gpointer serviceObj;
258 } ToolsAppCtx;
259 
260 #if defined(G_PLATFORM_WIN32)
261 
268 G_INLINE_FUNC gboolean
269 ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
270 {
271  if (!ctx->comInitialized) {
272  HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
273  ctx->comInitialized = SUCCEEDED(ret);
274  if (!ctx->comInitialized) {
275  g_log(ctx->name, G_LOG_LEVEL_WARNING,
276  "COM initialization failed(0x%x)\n", ret);
277  }
278  }
279  return ctx->comInitialized;
280 }
281 #endif
282 
283 
284 /* Capabilities. */
285 
287 typedef enum {
288  TOOLS_CAP_OLD = 0,
289  TOOLS_CAP_OLD_NOVAL = 1,
290  TOOLS_CAP_NEW = 2
292 
302 typedef struct ToolsAppCapability {
309  const gchar *name;
314  GuestCapabilities index;
316  guint value;
318 
319 
320 /* Application registration. */
321 
323 typedef enum {
344 } ToolsAppType;
345 
346 
347 struct ToolsPluginData;
348 
357 typedef struct ToolsAppProvider {
359  const gchar *name;
368  size_t regSize;
378  void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
390  gboolean (*registerApp)(ToolsAppCtx *ctx,
391  struct ToolsAppProvider *prov,
392  struct ToolsPluginData *plugin,
393  gpointer reg);
404  void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
417  void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
419 
420 
431 typedef struct ToolsAppReg {
432  ToolsAppType type;
433  GArray *data;
434 } ToolsAppReg;
435 
436 
450 typedef struct ToolsServiceProperty {
451  const char *name;
453 
454 
464 typedef struct ToolsPluginSignalCb {
465  const gchar *signame;
466  gpointer callback;
467  gpointer clientData;
469 
470 
485 typedef struct ToolsPluginData {
487  char const *name;
492  GArray *regs;
523  gboolean (*errorCb)(ToolsAppCtx *ctx,
524  ToolsAppType type,
525  gpointer data,
526  struct ToolsPluginData *plugin);
528  gpointer _private;
530 
536 #if defined(G_PLATFORM_WIN32)
537 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
538 #elif defined(GCC_EXPLICIT_EXPORT)
539 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
540 #else
541 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
542 #endif
543 
555 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
556 
559 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */
560