A collection of useful functions.
More...
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 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] | path | Path in UTF-8 (should not be NULL). |
[out] | err | Where 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
-
Convenience macro around VMTools_WrapArray.
typedef gboolean(* SignalSourceCb)(const siginfo_t *, gpointer) |
Type of callback used by the signal event source.
G_BEGIN_DECLS void vm_free |
( |
void * |
ptr | ) |
|
Frees a pointer allocated by the vmtools library.
- Parameters
-
[in] | ptr | Pointer 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] | timeout | The 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] | path | Path to the configuration file, or NULL for default Tools config file. |
[in] | flags | Flags for opening the file. |
[in,out] | config | Where to store the config dictionary; when reloading the file, the old config object will be destroyed. |
[in,out] | mtime | Last 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:
1 GSource *src = VMTools_NewSignalSource(signum);
2 g_source_set_callback(src, MyCallback, myData, NULL);
3 g_source_attach(src, myContext);
- Note
- This API is not available on Win32.
- Parameters
-
[in] | signum | Signal 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] | data | The array data. The original data is copied into the new array. |
[in] | elemSize | The size of each element in the array. |
[in] | count | The 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] | path | Where to save the data. |
[in] | config | Config data. |
[out] | err | Where to store error information (may be NULL). |
- Returns
- Whether saving was successful.