Beispiel #1
0
/**
 * bt_persistence_save_list:
 * @list: (element-type BuzztraxCore.Persistence): a #GList
 * @doc; the xml-document
 * @node: the list xml node
 *
 * Iterates over a list of objects, which must implement the #BtPersistence
 * interface and calls bt_persistence_save() on each item.
 *
 * Returns: %TRUE if all elements have been serialized.
 */
gboolean
bt_persistence_save_list (const GList * list, xmlNodePtr const node)
{
  gboolean res = TRUE;

  for (; (list && res); list = g_list_next (list)) {
    if (BT_IS_PERSISTENCE (list->data)) {
      res &=
          (bt_persistence_save ((BtPersistence *) (list->data), node) != NULL);
    }
  }
  return res;
}
Beispiel #2
0
static gboolean
bt_song_io_native_xml_save (gconstpointer const _self,
    const BtSong * const song, GError ** err)
{
  const BtSongIONativeXML *const self = BT_SONG_IO_NATIVE_XML (_self);
  gboolean result = FALSE;
  gchar *const file_name;

  g_object_get ((gpointer) self, "file-name", &file_name, NULL);
  GST_INFO ("native io xml will now save song to \"%s\"",
      file_name ? file_name : "data");

  xmlDocPtr const song_doc = xmlNewDoc (XML_CHAR_PTR ("1.0"));
  if (song_doc) {
    xmlNodePtr const root_node =
        bt_persistence_save (BT_PERSISTENCE (song), NULL);
    if (root_node) {
      xmlDocSetRootElement (song_doc, root_node);
      if (file_name) {
        if (xmlSaveFile (file_name, song_doc) != -1) {
          result = TRUE;
          GST_INFO ("xml saved okay");
        } else {
          GST_WARNING ("failed to write song file \"%s\"", file_name);
          g_set_error_literal (err, G_IO_ERROR, g_io_error_from_errno (errno),
              g_strerror (errno));
        }
      } else {
        xmlChar *mem;
        guint len;
        gpointer data;

        xmlDocDumpMemory (song_doc, &mem, (int *) &len);
        data = g_memdup (mem, len);
        xmlFree (mem);
        g_object_set ((gpointer) self, "data", data, "data-len", len, NULL);
      }
    } else {
      g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED,
          "Failed to serialize XML doc.");
    }
  } else {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED,
        "Failed to create XML doc.");
  }

  g_free (file_name);
  return result;
}
Beispiel #3
0
static void
test_bt_wire_persistence (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  BtMachine *src =
      BT_MACHINE (bt_source_machine_new (song, "audiotestsrc", "audiotestsrc",
          0L, NULL));
  BtMachine *proc = BT_MACHINE (bt_processor_machine_new (song, "volume",
          "volume", 0L, NULL));
  BtWire *wire = bt_wire_new (song, src, proc, NULL);

  GST_INFO ("-- act --");
  xmlNodePtr parent = xmlNewNode (NULL, XML_CHAR_PTR ("buzztrax"));
  xmlNodePtr node = bt_persistence_save (BT_PERSISTENCE (wire), parent);

  GST_INFO ("-- assert --");
  fail_unless (node != NULL, NULL);
  ck_assert_str_eq ((gchar *) node->name, "wire");
  fail_unless (node->children != NULL, NULL);

  GST_INFO ("-- cleanup --");
  BT_TEST_END;
}