plugin.h
Go to the documentation of this file.
/*********************************************************
* Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
#ifndef _VMWARE_TOOLS_PLUGIN_H_
#define _VMWARE_TOOLS_PLUGIN_H_
#include <glib.h>
#if defined(G_PLATFORM_WIN32)
# include <windows.h>
# include <objbase.h>
#endif
#include "vmware/guestrpc/capabilities.h"
#include "vmware/tools/guestrpc.h"
#include "vmware/tools/utils.h"
#define VMTOOLSAPP_ERROR(ctx, err) do { \
ASSERT((err) != 0); \
(ctx)->errorCode = (err); \
g_main_loop_quit((ctx)->mainLoop); \
} while (0)
#define VMTOOLSAPP_ATTACH_SOURCE(ctx, src, cb, data, destroy) do { \
GSource *__src = (src); \
g_source_set_callback(__src, (GSourceFunc) (cb), (data), (destroy)); \
g_source_attach(__src, g_main_loop_get_context((ctx)->mainLoop)); \
} while (0)
#define TOOLS_IS_MAIN_SERVICE(ctx) (strcmp((ctx)->name, \
VMTOOLS_GUEST_SERVICE) == 0)
#define TOOLS_IS_USER_SERVICE(ctx) (strcmp((ctx)->name, \
VMTOOLS_USER_SERVICE) == 0)
/* Indentation levels for the state log function below. */
#define TOOLS_STATE_LOG_ROOT 0
#define TOOLS_STATE_LOG_CONTAINER 1
#define TOOLS_STATE_LOG_PLUGIN 2
static inline void
ToolsCore_LogState(guint level,
const char *fmt,
...)
{
gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt);
va_list args;
va_start(args, fmt);
g_logv("state", G_LOG_LEVEL_INFO, indented, args);
va_end(args);
g_free(indented);
}
#define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities"
#define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload"
#define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state"
#define TOOLS_CORE_SIG_RESET "tcs_reset"
#define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
#define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown"
#if defined(G_PLATFORM_WIN32)
#define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control"
#endif
#define TOOLS_CORE_PROP_CTX "tcs_app_ctx"
typedef enum {
TOOLS_CORE_API_V1 = 0x1,
} ToolsCoreAPI;
typedef struct ToolsAppCtx {
ToolsCoreAPI version;
const gchar *name;
gboolean isVMware;
int errorCode;
GMainLoop *mainLoop;
RpcChannel *rpc;
GKeyFile *config;
#if defined(G_PLATFORM_WIN32)
gboolean comInitialized;
#else
int blockFD;
const char **envp;
#endif
gpointer serviceObj;
} ToolsAppCtx;
#if defined(G_PLATFORM_WIN32)
G_INLINE_FUNC gboolean
ToolsCore_InitializeCOM(ToolsAppCtx *ctx)
{
if (!ctx->comInitialized) {
HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
ctx->comInitialized = SUCCEEDED(ret);
if (!ctx->comInitialized) {
g_log(ctx->name, G_LOG_LEVEL_WARNING,
"COM initialization failed(0x%x)\n", ret);
}
}
return ctx->comInitialized;
}
#endif
/* Capabilities. */
typedef enum {
TOOLS_CAP_OLD = 0,
TOOLS_CAP_OLD_NOVAL = 1,
TOOLS_CAP_NEW = 2
} ToolsCapabilityType;
typedef struct ToolsAppCapability {
ToolsCapabilityType type;
const gchar *name;
GuestCapabilities index;
guint value;
} ToolsAppCapability;
/* Application registration. */
typedef enum {
TOOLS_APP_GUESTRPC = 1,
TOOLS_APP_SIGNALS = 2,
TOOLS_APP_PROVIDER = 3,
TOOLS_SVC_PROPERTY = 4,
} ToolsAppType;
struct ToolsPluginData;
typedef struct ToolsAppProvider {
const gchar *name;
ToolsAppType regType;
size_t regSize;
void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err);
gboolean (*registerApp)(ToolsAppCtx *ctx,
struct ToolsAppProvider *prov,
struct ToolsPluginData *plugin,
gpointer reg);
void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov);
void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg);
} ToolsAppProvider;
typedef struct ToolsAppReg {
ToolsAppType type;
GArray *data;
} ToolsAppReg;
typedef struct ToolsServiceProperty {
const char *name;
} ToolsServiceProperty;
typedef struct ToolsPluginSignalCb {
const gchar *signame;
gpointer callback;
gpointer clientData;
} ToolsPluginSignalCb;
typedef struct ToolsPluginData {
char const *name;
GArray *regs;
gboolean (*errorCb)(ToolsAppCtx *ctx,
ToolsAppType type,
gpointer data,
struct ToolsPluginData *plugin);
gpointer _private;
} ToolsPluginData;
#if defined(G_PLATFORM_WIN32)
# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport)
#elif defined(GCC_EXPLICIT_EXPORT)
# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default")))
#else
# define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C
#endif
typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx);
#endif /* _VMWARE_TOOLS_PLUGIN_H_ */
ToolsPluginSignalCb
struct ToolsPluginSignalCb ToolsPluginSignalCb
ToolsAppCapability
Definition: plugin.h:316
TOOLS_APP_GUESTRPC
Definition: plugin.h:341
ToolsAppCapability::index
GuestCapabilities index
Definition: plugin.h:328
ToolsAppCtx::config
GKeyFile * config
Definition: plugin.h:255
ToolsAppCtx::isVMware
gboolean isVMware
Definition: plugin.h:247
ToolsAppCtx::rpc
RpcChannel * rpc
Definition: plugin.h:253
ToolsPluginSignalCb
Definition: plugin.h:478
ToolsAppCtx
struct ToolsAppCtx ToolsAppCtx
ToolsAppCtx::errorCode
int errorCode
Definition: plugin.h:249
ToolsAppProvider::regType
ToolsAppType regType
Definition: plugin.h:380
ToolsAppCapability::type
ToolsCapabilityType type
Definition: plugin.h:318
ToolsAppProvider
struct ToolsAppProvider ToolsAppProvider
ToolsServiceProperty
Definition: plugin.h:464
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition: plugin.h:251
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition: plugin.h:431
ToolsAppCtx::blockFD
int blockFD
Definition: plugin.h:261
TOOLS_SVC_PROPERTY
Definition: plugin.h:357
utils.h
ToolsAppCapability::value
guint value
Definition: plugin.h:330
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition: plugin.h:404
ToolsAppCtx::name
const gchar * name
Definition: plugin.h:245
ToolsPluginData::_private
gpointer _private
Definition: plugin.h:542
guestrpc.h
ToolsCapabilityType
ToolsCapabilityType
Definition: plugin.h:301
ToolsPluginData::regs
GArray * regs
Definition: plugin.h:506
ToolsPluginData
struct ToolsPluginData ToolsPluginData
ToolsAppReg
Definition: plugin.h:445
ToolsAppType
ToolsAppType
Definition: plugin.h:337
ToolsAppProvider
Definition: plugin.h:371
TOOLS_APP_SIGNALS
Definition: plugin.h:346
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:271
ToolsAppProvider::name
const gchar * name
Definition: plugin.h:373
ToolsPluginData
Definition: plugin.h:499
ToolsAppCapability
struct ToolsAppCapability ToolsAppCapability
TOOLS_APP_PROVIDER
Definition: plugin.h:352
ToolsAppCtx
Definition: plugin.h:241
ToolsAppCtx::version
ToolsCoreAPI version
Definition: plugin.h:243
ToolsAppCapability::name
const gchar * name
Definition: plugin.h:323
ToolsAppCtx::envp
const char ** envp
Definition: plugin.h:263
ToolsCoreAPI
ToolsCoreAPI
Definition: plugin.h:232
ToolsPluginData::name
char const * name
Definition: plugin.h:501
ToolsAppProvider::regSize
size_t regSize
Definition: plugin.h:382
ToolsAppReg
struct ToolsAppReg ToolsAppReg
ToolsServiceProperty
struct ToolsServiceProperty ToolsServiceProperty