open-vm-tools 2013.09.16

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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 {
229 ToolsCoreAPI version;
231 const gchar *name;
233 gboolean isVMware;
235 int errorCode;
237 GMainLoop *mainLoop;
239 RpcChannel *rpc;
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
291 } ToolsCapabilityType;
292
302 typedef struct ToolsAppCapability {
304 ToolsCapabilityType type;
309 const gchar *name;
314 GuestCapabilities index;
316 guint value;
317 } ToolsAppCapability;
318
319
320 /* Application registration. */
321
323 typedef enum {
327 TOOLS_APP_GUESTRPC = 1,
332 TOOLS_APP_SIGNALS = 2,
338 TOOLS_APP_PROVIDER = 3,
343 TOOLS_SVC_PROPERTY = 4,
344 } ToolsAppType;
345
346
347 struct ToolsPluginData;
348
357 typedef struct ToolsAppProvider {
359 const gchar *name;
366 ToolsAppType regType;
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);
418 } ToolsAppProvider;
419
420
431 typedef struct ToolsAppReg {
432 ToolsAppType type;
433 GArray *data;
434 } ToolsAppReg;
435
436
450 typedef struct ToolsServiceProperty {
451 const char *name;
452 } ToolsServiceProperty;
453
454
464 typedef struct ToolsPluginSignalCb {
465 const gchar *signame;
466 gpointer callback;
467 gpointer clientData;
468 } ToolsPluginSignalCb;
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;
529 } ToolsPluginData;
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
ToolsPluginSignalCb
struct ToolsPluginSignalCb ToolsPluginSignalCb
ToolsAppCapability
Definition: plugin.h:302
TOOLS_APP_GUESTRPC
Definition: plugin.h:327
ToolsAppCapability::index
GuestCapabilities index
Definition: plugin.h:314
ToolsAppCtx::config
GKeyFile * config
Definition: plugin.h:241
ToolsAppCtx::isVMware
gboolean isVMware
Definition: plugin.h:233
ToolsAppCtx::rpc
RpcChannel * rpc
Definition: plugin.h:239
ToolsPluginSignalCb
Definition: plugin.h:464
ToolsAppCtx
struct ToolsAppCtx ToolsAppCtx
ToolsAppCtx::errorCode
int errorCode
Definition: plugin.h:235
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:390
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:417
ToolsAppProvider::regType
ToolsAppType regType
Definition: plugin.h:366
ToolsAppCapability::type
ToolsCapabilityType type
Definition: plugin.h:304
ToolsAppProvider
struct ToolsAppProvider ToolsAppProvider
ToolsServiceProperty
Definition: plugin.h:450
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition: plugin.h:237
ToolsAppCtx::blockFD
int blockFD
Definition: plugin.h:247
TOOLS_SVC_PROPERTY
Definition: plugin.h:343
utils.h
ToolsAppCapability::value
guint value
Definition: plugin.h:316
ToolsAppCtx::name
const gchar * name
Definition: plugin.h:231
ToolsPluginData::_private
gpointer _private
Definition: plugin.h:528
guestrpc.h
ToolsCapabilityType
ToolsCapabilityType
Definition: plugin.h:287
ToolsPluginData::regs
GArray * regs
Definition: plugin.h:492
ToolsPluginData
struct ToolsPluginData ToolsPluginData
ToolsPluginData::errorCb
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition: plugin.h:523
ToolsAppReg
Definition: plugin.h:431
ToolsAppType
ToolsAppType
Definition: plugin.h:323
ToolsAppProvider
Definition: plugin.h:357
TOOLS_APP_SIGNALS
Definition: plugin.h:332
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:257
ToolsAppProvider::name
const gchar * name
Definition: plugin.h:359
ToolsPluginData
Definition: plugin.h:485
ToolsAppCapability
struct ToolsAppCapability ToolsAppCapability
ToolsAppProvider::activate
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition: plugin.h:378
TOOLS_APP_PROVIDER
Definition: plugin.h:338
ToolsAppCtx
Definition: plugin.h:227
ToolsAppCtx::version
ToolsCoreAPI version
Definition: plugin.h:229
ToolsAppCapability::name
const gchar * name
Definition: plugin.h:309
ToolsAppCtx::envp
const char ** envp
Definition: plugin.h:249
ToolsAppProvider::shutdown
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition: plugin.h:404
ToolsCoreAPI
ToolsCoreAPI
Definition: plugin.h:218
ToolsPluginData::name
char const * name
Definition: plugin.h:487
ToolsAppProvider::regSize
size_t regSize
Definition: plugin.h:368
ToolsAppReg
struct ToolsAppReg ToolsAppReg
ToolsServiceProperty
struct ToolsServiceProperty ToolsServiceProperty