plugin.h
Go to the documentation of this file.
/*********************************************************
* Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* 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_
/*
* glib.h should not be placed inside `extern "C"' blocks.
* However, this header is often placed inside such blocks.
* Here we change back into C++ for glib.h
*/
#ifdef __cplusplus
extern "C++" {
#endif
#include <glib.h>
#ifdef __cplusplus
}
#endif
#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_NO_RPC "tcs_no_rpc"
#define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option"
#define TOOLS_CORE_SIG_PRE_SHUTDOWN "tcs_pre_shutdown"
#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"
#define TOOLS_CORE_EVENTS_TOOLS_NEW_VERSION "VMToolsNewVersion"
#define TOOLS_CORE_EVENTS_TOOLS_NEED_REBOOT "VMToolsNeedReboot"
#define TOOLS_CORE_EVENTS_GLOBAL_SCOPE "Global"
typedef enum {
TOOLS_CORE_API_V1 = 0x1,
} ToolsCoreAPI;
struct ToolsServiceProperty;
typedef void (*RegisterServiceProperty)(gpointer obj,
struct ToolsServiceProperty *prop);
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;
int uinputFD;
const char **envp;
#endif
gpointer serviceObj;
RegisterServiceProperty registerServiceProperty;
} ToolsAppCtx;
#if defined(G_PLATFORM_WIN32)
static inline 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_ */
ToolsCapabilityType
ToolsCapabilityType
Definition plugin.h:376
RegisterServiceProperty
void(* RegisterServiceProperty)(gpointer obj, struct ToolsServiceProperty *prop)
Definition plugin.h:300
ToolsAppType
ToolsAppType
Definition plugin.h:412
ToolsCoreAPI
ToolsCoreAPI
Definition plugin.h:286
TOOLS_APP_GUESTRPC
@ TOOLS_APP_GUESTRPC
Definition plugin.h:416
TOOLS_APP_SIGNALS
@ TOOLS_APP_SIGNALS
Definition plugin.h:421
TOOLS_SVC_PROPERTY
@ TOOLS_SVC_PROPERTY
Definition plugin.h:432
TOOLS_APP_PROVIDER
@ TOOLS_APP_PROVIDER
Definition plugin.h:427
guestrpc.h
ToolsAppCapability
Definition plugin.h:391
ToolsAppCapability::index
GuestCapabilities index
Definition plugin.h:403
ToolsAppCapability::name
const gchar * name
Definition plugin.h:398
ToolsAppCapability::value
guint value
Definition plugin.h:405
ToolsAppCapability::type
ToolsCapabilityType type
Definition plugin.h:393
ToolsAppCtx
Definition plugin.h:307
ToolsAppCtx::version
ToolsCoreAPI version
Definition plugin.h:309
ToolsAppCtx::config
GKeyFile * config
Definition plugin.h:321
ToolsAppCtx::mainLoop
GMainLoop * mainLoop
Definition plugin.h:317
ToolsAppCtx::rpc
RpcChannel * rpc
Definition plugin.h:319
ToolsAppCtx::uinputFD
int uinputFD
Definition plugin.h:329
ToolsAppCtx::registerServiceProperty
RegisterServiceProperty registerServiceProperty
Definition plugin.h:346
ToolsAppCtx::blockFD
int blockFD
Definition plugin.h:327
ToolsAppCtx::envp
const char ** envp
Definition plugin.h:331
ToolsAppCtx::name
const gchar * name
Definition plugin.h:311
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition plugin.h:339
ToolsAppCtx::isVMware
gboolean isVMware
Definition plugin.h:313
ToolsAppCtx::errorCode
int errorCode
Definition plugin.h:315
ToolsAppProvider
Definition plugin.h:446
ToolsAppProvider::shutdown
void(* shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov)
Definition plugin.h:493
ToolsAppProvider::name
const gchar * name
Definition plugin.h:448
ToolsAppProvider::regSize
size_t regSize
Definition plugin.h:457
ToolsAppProvider::registerApp
gboolean(* registerApp)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, struct ToolsPluginData *plugin, gpointer reg)
Definition plugin.h:479
ToolsAppProvider::dumpState
void(* dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg)
Definition plugin.h:506
ToolsAppProvider::activate
void(* activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err)
Definition plugin.h:467
ToolsAppProvider::regType
ToolsAppType regType
Definition plugin.h:455
ToolsAppReg
Definition plugin.h:520
ToolsPluginData
Definition plugin.h:574
ToolsPluginData::name
char const * name
Definition plugin.h:576
ToolsPluginData::errorCb
gboolean(* errorCb)(ToolsAppCtx *ctx, ToolsAppType type, gpointer data, struct ToolsPluginData *plugin)
Definition plugin.h:612
ToolsPluginData::regs
GArray * regs
Definition plugin.h:581
ToolsPluginData::_private
gpointer _private
Definition plugin.h:617
ToolsPluginSignalCb
Definition plugin.h:553
ToolsServiceProperty
Definition plugin.h:539
utils.h