open-vm-tools 2012.05.21
|
00001 /********************************************************* 00002 * Copyright (C) 2008 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 00071 /* Indentation levels for the state log function below. */ 00072 #define TOOLS_STATE_LOG_ROOT 0 00073 #define TOOLS_STATE_LOG_CONTAINER 1 00074 #define TOOLS_STATE_LOG_PLUGIN 2 00075 00086 static inline void 00087 ToolsCore_LogState(guint level, 00088 const char *fmt, 00089 ...) 00090 { 00091 gchar *indented = g_strdup_printf("%*s%s", 3 * level, "", fmt); 00092 00093 va_list args; 00094 va_start(args, fmt); 00095 g_logv("state", G_LOG_LEVEL_INFO, indented, args); 00096 va_end(args); 00097 00098 g_free(indented); 00099 } 00100 00101 00113 #define TOOLS_CORE_SIG_CAPABILITIES "tcs_capabilities" 00114 00122 #define TOOLS_CORE_SIG_CONF_RELOAD "tcs_conf_reload" 00123 00133 #define TOOLS_CORE_SIG_DUMP_STATE "tcs_dump_state" 00134 00142 #define TOOLS_CORE_SIG_RESET "tcs_reset" 00143 00156 #define TOOLS_CORE_SIG_SET_OPTION "tcs_set_option" 00157 00165 #define TOOLS_CORE_SIG_SHUTDOWN "tcs_shutdown" 00166 00167 #if defined(G_PLATFORM_WIN32) 00168 00195 #define TOOLS_CORE_SIG_SERVICE_CONTROL "tcs_service_control" 00196 00197 #endif 00198 00206 #define TOOLS_CORE_PROP_CTX "tcs_app_ctx" 00207 00208 00218 typedef enum { 00219 TOOLS_CORE_API_V1 = 0x1, 00220 } ToolsCoreAPI; 00221 00222 00227 typedef struct ToolsAppCtx { 00229 ToolsCoreAPI version; 00231 const gchar *name; 00233 gboolean isVMware; 00235 int errorCode; 00237 GMainLoop *mainLoop; 00239 RpcChannel *rpc; 00241 GKeyFile *config; 00242 #if defined(G_PLATFORM_WIN32) 00243 00244 gboolean comInitialized; 00245 #else 00246 00247 int blockFD; 00249 const char **envp; 00250 #endif 00251 00257 gpointer serviceObj; 00258 } ToolsAppCtx; 00259 00260 #if defined(G_PLATFORM_WIN32) 00261 00268 G_INLINE_FUNC gboolean 00269 ToolsCore_InitializeCOM(ToolsAppCtx *ctx) 00270 { 00271 if (!ctx->comInitialized) { 00272 HRESULT ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 00273 ctx->comInitialized = SUCCEEDED(ret); 00274 if (!ctx->comInitialized) { 00275 g_log(ctx->name, G_LOG_LEVEL_WARNING, 00276 "COM initialization failed(0x%x)\n", ret); 00277 } 00278 } 00279 return ctx->comInitialized; 00280 } 00281 #endif 00282 00283 00284 /* Capabilities. */ 00285 00287 typedef enum { 00288 TOOLS_CAP_OLD = 0, 00289 TOOLS_CAP_OLD_NOVAL = 1, 00290 TOOLS_CAP_NEW = 2 00291 } ToolsCapabilityType; 00292 00302 typedef struct ToolsAppCapability { 00304 ToolsCapabilityType type; 00309 const gchar *name; 00314 GuestCapabilities index; 00316 guint value; 00317 } ToolsAppCapability; 00318 00319 00320 /* Application registration. */ 00321 00323 typedef enum { 00327 TOOLS_APP_GUESTRPC = 1, 00332 TOOLS_APP_SIGNALS = 2, 00338 TOOLS_APP_PROVIDER = 3, 00343 TOOLS_SVC_PROPERTY = 4, 00344 00345 /* VMCF applications. */ 00346 00350 TOOLS_VMCF_OBJECT = 0x00010001, 00354 TOOLS_VMCF_SIGNAL = 0x00010002, 00358 TOOLS_VMCF_VOLT_OBJECT = 0x00010003, 00362 TOOLS_VMCF_VOLT_SIGNAL = 0x00010004, 00363 00364 } ToolsAppType; 00365 00366 00367 struct ToolsPluginData; 00368 00377 typedef struct ToolsAppProvider { 00379 const gchar *name; 00386 ToolsAppType regType; 00388 size_t regSize; 00398 void (*activate)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, GError **err); 00410 gboolean (*registerApp)(ToolsAppCtx *ctx, 00411 struct ToolsAppProvider *prov, 00412 struct ToolsPluginData *plugin, 00413 gpointer reg); 00424 void (*shutdown)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov); 00437 void (*dumpState)(ToolsAppCtx *ctx, struct ToolsAppProvider *prov, gpointer reg); 00438 } ToolsAppProvider; 00439 00440 00451 typedef struct ToolsAppReg { 00452 ToolsAppType type; 00453 GArray *data; 00454 } ToolsAppReg; 00455 00456 00470 typedef struct ToolsServiceProperty { 00471 const char *name; 00472 } ToolsServiceProperty; 00473 00474 00484 typedef struct ToolsPluginSignalCb { 00485 const gchar *signame; 00486 gpointer callback; 00487 gpointer clientData; 00488 } ToolsPluginSignalCb; 00489 00490 00505 typedef struct ToolsPluginData { 00507 char const *name; 00512 GArray *regs; 00543 gboolean (*errorCb)(ToolsAppCtx *ctx, 00544 ToolsAppType type, 00545 gpointer data, 00546 struct ToolsPluginData *plugin); 00548 gpointer _private; 00549 } ToolsPluginData; 00550 00556 #if defined(G_PLATFORM_WIN32) 00557 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __declspec(dllexport) 00558 #elif defined(GCC_EXPLICIT_EXPORT) 00559 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C __attribute__((visibility("default"))) 00560 #else 00561 # define TOOLS_MODULE_EXPORT VMTOOLS_EXTERN_C 00562 #endif 00563 00575 typedef ToolsPluginData *(*ToolsPluginOnLoad)(ToolsAppCtx *ctx); 00576 00579 #endif /* _VMWARE_TOOLS_PLUGIN_H_ */ 00580