Header for the machines related functions in Synema. More...
#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | machine_t |
A machine with it's internal data and list of available tools. More... | |
Functions | |
GList * | machine_list_new (const gchar *, GList *) |
Scans a machines folder and returns a list of machines present in this folder. | |
void | machine_list_free (GList *) |
Frees a list of machines and the machines it contains. | |
gint | machine_list_remove (GList **, machine_t *) |
Removes a machine from a machines list without freeing it. | |
machine_t * | machine_list_find_by_name (GList *, const gchar *) |
Searches a machines list for a machine whose name is given as a parameter. | |
gint | machine_cmp (machine_t *, machine_t *) |
Compares two machines. | |
const gchar * | machine_get_display_name (machine_t *) |
Returns the display name of a machine. | |
const gchar * | machine_get_folder_name (machine_t *) |
Returns the folder name of a machine. | |
gint | machine_is_all_machines (machine_t *) |
Tells if a machine_t struct represents all the machines. | |
GList * | machine_get_list_for_plugin (const gchar *, gboolean) |
Returns a list of machines that have reports for a given plugin. |
Header for the machines related functions in Synema.
This header files provides utilities related to machines and describes the machine_t data structure.
Definition in file machine.h.
Compares two machines.
This functions compares two machine_t structs and tells if the machines are identical. It may be appropriate for sorting if both parameters are not NULL. It will then return the alphabetical order of the folder names of the machines.
[in] | m1 | the first machine |
[in] | m2 | the second machine |
Definition at line 373 of file machine.c.
00374 { 00375 if (m1 == NULL) 00376 return (m2 == NULL) ? 0 : -1; 00377 00378 if (m2 == NULL) 00379 return 1; 00380 00381 return g_strcmp0 (m1->folder_name, m2->folder_name); 00382 }
const gchar* machine_get_display_name | ( | machine_t * | m | ) |
Returns the display name of a machine.
This functions returns the display name of a machine. It should not be freed because it belongs to the machine_t struct.
[in] | m | the machine whose name you want |
Definition at line 386 of file machine.c.
00387 { 00388 return (m) ? m->display_name : NULL; 00389 }
const gchar* machine_get_folder_name | ( | machine_t * | m | ) |
Returns the folder name of a machine.
This functions returns the folder name of a machine. It should not be freed because it belongs to the machine_t struct.
[in] | m | the machine whose name you want |
Definition at line 393 of file machine.c.
00394 { 00395 return (m) ? m->folder_name : NULL; 00396 }
GList* machine_get_list_for_plugin | ( | const gchar * | plugin_name, | |
gboolean | add_all_machines | |||
) |
Returns a list of machines that have reports for a given plugin.
This function goes through the machines list of the current Synema instance and returns a list of pointers to machines that have reports for a plugin whose name is given as a parameter.
[in] | plugin_name | the name of the plugin for which you want a list of machines |
[in] | add_all_machines | if TRUE, the virtual machine "All Machines" is added to the list (if it's not empty) |
Definition at line 412 of file machine.c.
00413 { 00414 synema_instance_t *inst = synema_instance (); 00415 gchar *reports_dir = NULL; 00416 GList *final_list = NULL; 00417 GList *iter = inst->machines_list; 00418 struct stat buff; 00419 00420 if (iter) { 00421 do { 00422 if ((machine_is_all_machines (iter->data)) && (add_all_machines)) { 00423 final_list = g_list_prepend (final_list, iter->data); 00424 } else { 00425 reports_dir = g_strdup_printf ("%s/%s/"REPORTS_DIR"/%s", 00426 inst->machines_dir, 00427 machine_get_folder_name (iter->data), 00428 plugin_name); 00429 00430 if (g_stat (reports_dir, &buff) == 0) { 00431 if (S_ISDIR (buff.st_mode)) 00432 final_list = g_list_prepend (final_list, iter->data); 00433 } 00434 00435 g_free (reports_dir); 00436 } 00437 } while ((iter = g_list_next (iter)) != NULL); 00438 } 00439 00440 return final_list; 00441 }
gint machine_is_all_machines | ( | machine_t * | m | ) |
Tells if a machine_t struct represents all the machines.
This functions tells if the given machine_t is identical to a special virtual machine_t struct that represents all the machines available in the application.
[in] | m | the machine to check |
Definition at line 400 of file machine.c.
00401 { 00402 g_return_val_if_fail (m != NULL, 0); 00403 00404 if ((m->_virtual == FALSE) || (g_strcmp0 (m->folder_name, ALL_MACHINES_FOLDER_NAME))) 00405 return 0; 00406 else 00407 return 1; 00408 }
machine_t* machine_list_find_by_name | ( | GList * | list, | |
const gchar * | name | |||
) |
Searches a machines list for a machine whose name is given as a parameter.
This function searches through a list of machines for one whose folder name matches the one given as a parameter. It returns NULL if the machine is not in the list.
[in] | list | the list of machines to browse |
[in] | name | the folder name to look for |
Definition at line 326 of file machine.c.
00327 { 00328 GList *iter = list; 00329 00330 if (iter) { 00331 do { 00332 if (g_strcmp0 (machine_get_folder_name (iter->data), name) == 0) 00333 return iter->data; 00334 } while ((iter = g_list_next (iter)) != NULL); 00335 } 00336 00337 return NULL; 00338 }
void machine_list_free | ( | GList * | list | ) |
Frees a list of machines and the machines it contains.
This functions frees all the machines present in a given list, and then frees the list.
[in] | list | the list to free |
GList* machine_list_new | ( | const gchar * | top_path, | |
GList * | plugins | |||
) |
Scans a machines folder and returns a list of machines present in this folder.
This function scans a folder to find machine directories inside it, and builds a list of machine_t for each machine.
[in] | top_path | the path in which the machines are |
[in] | plugins | the list of currently available plugins |
Definition at line 266 of file machine.c.
00267 { 00268 GError *err = NULL; 00269 GFile *top_dir = NULL; 00270 GFileEnumerator *dir_enum = NULL; 00271 GFileInfo *current = NULL; 00272 GList *list = NULL; 00273 machine_t *allm = NULL; 00274 00275 top_dir = g_file_new_for_path (top_path); 00276 dir_enum = g_file_enumerate_children (top_dir, "standard::name,standard::display-name", G_FILE_QUERY_INFO_NONE, NULL, &err); 00277 if (err) { 00278 g_warning ("machine_list_new::enumerate_children: %s", err->message); 00279 g_clear_error (&err); 00280 return NULL; 00281 } 00282 00283 allm = g_malloc (sizeof (machine_t)); 00284 allm->_virtual = TRUE; 00285 allm->display_name = g_strdup (ALL_MACHINES_DISPLAY_NAME); 00286 allm->folder_name = g_strdup (ALL_MACHINES_FOLDER_NAME); 00287 allm->monitoring_tools = NULL; 00288 00289 while ((current = g_file_enumerator_next_file (dir_enum, NULL, &err)) != NULL) { 00290 if (err) { 00291 g_warning ("machine_list_new::next_file: %s", err->message); 00292 g_clear_error (&err); 00293 } else { 00294 if (g_strcmp0 (g_file_info_get_name (current), ALL_MACHINES_FOLDER_NAME) != 0) { 00295 machine_t *machine = g_malloc (sizeof (machine_t)); 00296 list = g_list_prepend (list, machine); 00297 machine_get_info (top_dir, current, machine, plugins); 00298 g_object_unref (current); 00299 } 00300 } 00301 } 00302 00303 if (list) { 00304 list = g_list_append (list, allm); 00305 } else { 00306 machine_free (allm); 00307 } 00308 00309 g_object_unref (dir_enum); 00310 g_object_unref (top_dir); 00311 return list; 00312 }
gint machine_list_remove | ( | GList ** | list, | |
machine_t * | elem | |||
) |
Removes a machine from a machines list without freeing it.
This functions removes a machine from a machines list. It does not free the machine.
[in,out] | list | a pointer to the list (can be modified) |
[in,out] | elem | the element to remove |