open-vm-tools 10.0.5
|
00001 /********************************************************* 00002 * Copyright (C) 2008-2015 VMware, Inc. All rights reserved. 00003 * 00004 * This program is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License as published 00006 * by the Free Software Foundation version 2.1 and no later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00010 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public 00011 * License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00016 * 00017 *********************************************************/ 00018 00019 #ifndef _VMWARE_TOOLS_PLUGIN_H_ 00020 #define _VMWARE_TOOLS_PLUGIN_H_ 00021 00032 #include <glib.h> 00033 #if defined(G_PLATFORM_WIN32) 00034 # include <windows.h> 00035 # include <objbase.h> 00036 #endif 00037 #include "vmware/guestrpc/capabilities.h" 00038 #include "vmware/tools/guestrpc.h" 00039 #include "vmware/tools/utils.h" 00040 00049 #define VMTOOLSAPP_ERROR(ctx, err) do { \ 00050 ASSERT((err) != 0); \ 00051 (ctx)->errorCode = (err); \ 00052 g_main_loop_quit((ctx)->mainLoop); \ 00053 } while (0) 00054 00055 00065 #define VMTOOLSAPP_ATTACH_SOURCE(ctx, src, cb, data, destroy) do { \ 00066 GSource *__src = (src); \ 00067 g_source_set_callback(__src, (GSourceFunc) (cb), (data), (destroy)); \ 00068 g_source_attach(__src, g_main_loop_get_context((ctx)->mainLoop)); \ 00069 } while (0) 00070 00075 #define TOOLS_IS_MAIN_SERVICE(ctx) (strcmp((ctx)->name, \ 00076 VMTOOLS_GUEST_SERVICE) == 0) 00077 00082 #define TOOLS_IS_USER_SERVICE(ctx) (strcmp((ctx)->name, \ 00083 VMTOOLS_USER_SERVICE) == 0) 00084 00085 /* Indentation levels for the state log function below. */ 00086 #define TOOLS_STATE_LOG_ROOT 0 00087 #define TOOLS_STATE_LOG_CONTAINER 1 00088 #define TOOLS_STATE_LOG_PLUGIN 2 00089 00100 static inline void 00101 ToolsCore_LogState(guint level, 00102 const char *fmt, 00103 ...) 00104 { 00105 gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt); 00106 00107 va_list args; 00108 va_start(args, fmt); 00109 g_logv("state", G_LOG_LEVEL_INFO, indented, args); 00110 va_end(args); 00111 00112 g_free(indented); 00113 } 00114 00115 00127 #define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities" 00128 00136 #define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload" 00137 00147 #define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state" 00148 00156 #define TOOLS_CORE_SIG_RESET "tcs_reset" 00157 00170 #define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option" 00171 00179 #define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown" 00180 00181 #if defined(G_PLATFORM_WIN32) 00182 00209 #define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control" 00210 00211 #endif 00212 00220 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx" 00221 00222 00232 typedef enum { 00233 TOOLS_CORE_API_V1 = 0x1, 00234 } ToolsCoreAPI; 00235 00236 00241 typedef struct ToolsAppCtx { 00243 ToolsCoreAPI version; 00245 const gchar *name; 00247 gboolean isVMware; 00249 int errorCode; 00251 GMainLoop *mainLoop; 00253 RpcChannel *rpc; 00255 GKeyFile *config; 00256 #if defined(G_PLATFORM_WIN32) 00257 00258 gboolean comInitialized; 00259 #else 00260 00261 int blockFD; 00263 const char **envp; 00264 #endif 00265 00271 gpointer serviceObj; 00272 } ToolsAppCtx; 00273 00274 #if defined(G_PLATFORM_WIN32) 00275 00282 G_INLINE_FUNC gboolean 00283 ToolsCore_InitializeCOM(ToolsAppCtx *ctx) 00284 { 00285 if (!ctx->comInitialized) { 00286 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 00287 ctx->comInitialized = SUCCEEDED(ret); 00288 if (!ctx->comInitialized) { 00289 g_log(ctx->name, G_LOG_LEVEL_WARNING, 00290 "COM initialization failed(0x%x)\n", ret); 00291 } 00292 } 00293 return ctx->comInitialized; 00294 } 00295 #endif 00296 00297 00298 /* Capabilities. */ 00299 00301 typedef enum { 00302 TOOLS_CAP_OLD = 0, 00303 TOOLS_CAP_OLD_NOVAL = 1, 00304 TOOLS_CAP_NEW = 2 00305 } ToolsCapabilityType; 00306 00316 typedef struct ToolsAppCapability { 00318 ToolsCapabilityType type; 00323 const gchar *name; 00328 GuestCapabilities index; 00330 guint value; 00331 } ToolsAppCapability; 00332 00333 00334 /* Application registration. */ 00335 00337 typedef enum { 00341 TOOLS_APP_GUESTRPC = 1, 00346 TOOLS_APP_SIGNALS = 2, 00352 TOOLS_APP_PROVIDER = 3, 00357 TOOLS_SVC_PROPERTY = 4, 00358 } ToolsAppType; 00359 00360 00361 struct ToolsPluginData; 00362 00371 typedef struct ToolsAppProvider { 00373 const gchar *name; 00380 ToolsAppType regType; 00382 size_t regSize; 00392 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err); 00404 gboolean (*registerApp)(ToolsAppCtx *ctx, 00405 struct ToolsAppProvider *prov, 00406 struct ToolsPluginData *plugin, 00407 gpointer reg); 00418 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov); 00431 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg); 00432 } ToolsAppProvider; 00433 00434 00445 typedef struct ToolsAppReg { 00446 ToolsAppType type; 00447 GArray *data; 00448 } ToolsAppReg; 00449 00450 00464 typedef struct ToolsServiceProperty { 00465 const char *name; 00466 } ToolsServiceProperty; 00467 00468 00478 typedef struct ToolsPluginSignalCb { 00479 const gchar *signame; 00480 gpointer callback; 00481 gpointer clientData; 00482 } ToolsPluginSignalCb; 00483 00484 00499 typedef struct ToolsPluginData { 00501 char const *name; 00506 GArray *regs; 00537 gboolean (*errorCb)(ToolsAppCtx *ctx, 00538 ToolsAppType type, 00539 gpointer data, 00540 struct ToolsPluginData *plugin); 00542 gpointer _private; 00543 } ToolsPluginData; 00544 00550 #if defined(G_PLATFORM_WIN32) 00551 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport) 00552 #elif defined(GCC_EXPLICIT_EXPORT) 00553 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default"))) 00554 #else 00555 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C 00556 #endif 00557 00569 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx); 00570 00573 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */ 00574