open-vm-tools 9.4.0
Defines | Typedefs | Functions
Utility Functions

A collection of useful functions. More...

Defines

#define VMTOOLS_GUEST_SERVICE   "vmsvc"
#define VMTOOLS_USER_SERVICE   "vmusr"
#define VMTOOLS_EXTERN_C
#define VMTOOLS_GET_FILENAME_LOCAL(path, err)
#define VMTOOLS_RELEASE_FILENAME_LOCAL(path)   g_free(path)
#define VMTOOLS_WRAP_ARRAY(a)   VMTools_WrapArray((a), sizeof *(a), G_N_ELEMENTS(a))

Typedefs

typedef gboolean(* SignalSourceCb )(const siginfo_t *, gpointer)

Functions

G_BEGIN_DECLS void vm_free (void *ptr)
gboolean VMTools_LoadConfig (const gchar *path, GKeyFileFlags flags, GKeyFile **config, time_t *mtime)
gboolean VMTools_WriteConfig (const gchar *path, GKeyFile *config, GError **err)
GSource * VMTools_NewSignalSource (int signum)
gchar * VMTools_GetLibdir (void)
GSource * VMTools_CreateTimer (gint timeout)
 Create a timer based on a monotonic clock source.
GArray * VMTools_WrapArray (gconstpointer data, guint elemSize, guint count)

Detailed Description

A collection of useful functions.

This module contains functions for loading configuration data and extensions to the glib API that are useful when writing applications.


Define Documentation

#define VMTOOLS_GET_FILENAME_LOCAL (   path,
  err 
)
Value:
g_filename_from_utf8((path),  \
                                                                     -1,      \
                                                                     NULL,    \
                                                                     NULL,    \
                                                                     (err))

Converts an UTF-8 path to the local (i.e., glib) file name encoding. This is a no-op on Windows, since the local encoding is always UTF-8 in glib. The returned value should not be freed directly; instead, use VMTOOLS_RELEASE_FILENAME_LOCAL.

Parameters:
[in]pathPath in UTF-8 (should not be NULL).
[out]errWhere to store errors (type: GError **; may be NULL).
Returns:
The path in glib's filename encoding, or NULL on error.
#define VMTOOLS_RELEASE_FILENAME_LOCAL (   path)    g_free(path)

Frees a path allocated with VMTOOLS_GET_FILENAME_LOCAL. No-op on Windows.

Parameters:
[in]pathPath in UTF-8.
#define VMTOOLS_WRAP_ARRAY (   a)    VMTools_WrapArray((a), sizeof *(a), G_N_ELEMENTS(a))

Convenience macro around VMTools_WrapArray.


Typedef Documentation

typedef gboolean(* SignalSourceCb)(const siginfo_t *, gpointer)

Type of callback used by the signal event source.


Function Documentation

G_BEGIN_DECLS void vm_free ( void *  ptr)

Frees a pointer allocated by the vmtools library.

Parameters:
[in]ptrPointer to memory to be freed.
GSource * VMTools_CreateTimer ( gint  timeout)

Create a timer based on a monotonic clock source.

This timer differs from the glib timeout source, which uses the system time. It is recommended for code that needs more reliable time tracking, using a clock that is not affected by changes in the system time (which can happen when using NTP or the Tools time synchronization feature).

Parameters:
[in]timeoutThe timeout for the timer, must be >= 0.
Returns:
The new source.
gboolean VMTools_LoadConfig ( const gchar *  path,
GKeyFileFlags  flags,
GKeyFile **  config,
time_t *  mtime 
)

Loads the configuration file at the given path.

If an old configuration file is detected and the current process has write permission to the file, the configuration data will automatically upgraded to the new configuration format (the old configuration file is saved with a ".old" extension).

Parameters:
[in]pathPath to the configuration file, or NULL for default Tools config file.
[in]flagsFlags for opening the file.
[in,out]configWhere to store the config dictionary; when reloading the file, the old config object will be destroyed.
[in,out]mtimeLast known modification time of the config file. When the function succeeds, will contain the new modification time read from the file. If NULL (or 0), the config dictionary is always loaded.
Returns:
Whether a new config dictionary was loaded.
GSource * VMTools_NewSignalSource ( int  signum)

Creates a new source for the given signal.

Rather than processing the events in the signal handling context, the main loop is woken up and callbacks are processed in the main loop's thread.

The same "wakeup" file descriptors are used for all sources, so if sources are added to different main loop instances, all of them will be woken up if any signal for which handlers are registered occurs.

This code assumes that the rest of the app is not setting signal handlers directly, at least for signals for which glib sources have been set up.

Also note that on older Linux systems (pre-NPTL), some real-time signals are used by the pthread library and shouldn't be used by applications.

Example of setting a handler for a signal:

    GSource *src = VMTools_NewSignalSource(signum);
    g_source_set_callback(src, MyCallback, myData, NULL);
    g_source_attach(src, myContext);
Note:
This API is not available on Win32.
Parameters:
[in]signumSignal to watch.
Returns:
Pointer to the new source, NULL if failed to set signal handler.
GArray* VMTools_WrapArray ( gconstpointer  data,
guint  elemSize,
guint  count 
)

A convenience function for wrapping an array with a GArray instance.

Parameters:
[in]dataThe array data. The original data is copied into the new array.
[in]elemSizeThe size of each element in the array.
[in]countThe number of elements in the array.
Returns:
A new GArray.
gboolean VMTools_WriteConfig ( const gchar *  path,
GKeyFile *  config,
GError **  err 
)

Saves the given config data to the given path.

Parameters:
[in]pathWhere to save the data.
[in]configConfig data.
[out]errWhere to store error information (may be NULL).
Returns:
Whether saving was successful.