Coding Guidelines/Glib Utilities

From wiki.zmanda.com
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Amanda links against the Glib library because it is full of useful utilities that make C code easier to read and write. However, Amanda's minimum version required is Glib-2.2.0, which was released in late 2002. Your development system probably contains a much more recent and featureful version of the library, but you cannot use any of those new features! Consult the Glib-2.2.0 documentation before using any glib features not listed below.

Don't Use These

  • G_DEFINE_TYPE doesn't work as expected in older versions - define the type manually.

Use These

Useful items from Glib:

  • GMainLoop (but avoid Glib's child watch source -- Amanda provides a replacement in event.h / Amanda::MainLoop)
  • threads and thread pools
  • memory allocation utilities such as g_new0
  • logging functions
  • string-handling functions (try to use either the Amanda string functions or Glib's, but not both, for the sake of readability)
  • simple XML parser
  • All sorts of data types:
    • GSList (singly linked list)
    • GList (doubly linked list)
    • GHashTable
    • GPtrArray (a resizeable array of generic pointers)
    • GString