Audacious  $Id:Doxyfile42802007-03-2104:39:00Znenolod$
Defines | Functions | Variables
tuple.c File Reference

Basic Tuple handling API. More...

#include <glib.h>
#include <mowgli.h>
#include <audacious/i18n.h>
#include "config.h"
#include "tuple.h"
#include "audstrings.h"
#include "stringpool.h"

Go to the source code of this file.

Defines

#define APPEND(b,...)
#define TUPLE_LOCK_WRITE(X)   g_static_mutex_lock (& tuple_mutex)
 Convenience macros to lock the globally used internal Tuple system structures.
#define TUPLE_UNLOCK_WRITE(X)   g_static_mutex_unlock (& tuple_mutex)
 Convenience macros to lock the globally used internal Tuple system structures.
#define TUPLE_LOCK_READ(X)   g_static_mutex_lock (& tuple_mutex)
 Convenience macros to lock the globally used internal Tuple system structures.
#define TUPLE_UNLOCK_READ(X)   g_static_mutex_unlock (& tuple_mutex)
 Convenience macros to lock the globally used internal Tuple system structures.

Functions

static gboolean set_string (Tuple *tuple, const gint nfield, const gchar *field, gchar *string, gboolean take)
static void tuple_value_destroy (TupleValue *value)
static void tuple_value_destroy_cb (const gchar *key, void *data, void *priv)
static void tuple_destroy (gpointer data)
static Tupletuple_new_unlocked (void)
Tupletuple_new (void)
 Allocates a new empty Tuple structure.
static TupleValuetuple_associate_data (Tuple *tuple, const gint cnfield, const gchar *field, TupleValueType ftype)
 (Re)associates data into given Tuple field.
void tuple_set_filename (Tuple *tuple, const gchar *name)
 Sets filename/URI related fields of a Tuple structure, based on the given filename argument.
static TupleValuetuple_copy_value (TupleValue *src)
 Creates a copy of given TupleValue structure, with copied data.
Tupletuple_copy (const Tuple *src)
 Creates a copy of given Tuple structure, with copied data.
Tupletuple_new_from_filename (const gchar *filename)
 Allocates a new Tuple structure, setting filename/URI related fields based on the given filename argument by calling tuple_set_filename.
static gint tuple_get_nfield (const gchar *field)
gboolean tuple_associate_string (Tuple *tuple, const gint nfield, const gchar *field, const gchar *string)
 Associates copy of given string to a field in specified Tuple.
gboolean tuple_associate_string_rel (Tuple *tuple, const gint nfield, const gchar *field, gchar *string)
 Associates given string to a field in specified Tuple.
gboolean tuple_associate_int (Tuple *tuple, const gint nfield, const gchar *field, gint integer)
 Associates given integer to a field in specified Tuple.
void tuple_disassociate (Tuple *tuple, const gint cnfield, const gchar *field)
 Disassociates given field from specified Tuple structure.
TupleValueType tuple_get_value_type (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns TupleValueType of given Tuple field.
const gchar * tuple_get_string (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns pointer to a string associated to Tuple field.
gint tuple_get_int (const Tuple *tuple, gint cnfield, const gchar *field)
 Returns integer associated to Tuple field.
void tuple_set_format (Tuple *t, const gchar *format, gint chans, gint rate, gint brate)

Variables

const TupleBasicType tuple_fields [FIELD_LAST]
 Ordered table of basic Tuple field names and their TupleValueType.
static mowgli_heap_t * tuple_heap = NULL
 A mowgli heap containing all the allocated tuples.
static mowgli_heap_t * tuple_value_heap = NULL
 A mowgli heap containing values contained by tuples.
static mowgli_object_class_t tuple_klass
static GStaticMutex tuple_mutex = G_STATIC_MUTEX_INIT
 Global lock to preserve data consistency of heaps.

Detailed Description

Basic Tuple handling API.

Definition in file tuple.c.


Define Documentation

#define APPEND (   b,
  ... 
)
Value:
snprintf (b + strlen (b), sizeof b - strlen (b), \
 __VA_ARGS__)

Definition at line 670 of file tuple.c.

Referenced by tuple_set_format().

#define TUPLE_LOCK_READ (   X)    g_static_mutex_lock (& tuple_mutex)

Convenience macros to lock the globally used internal Tuple system structures.

Definition at line 101 of file tuple.c.

Referenced by tuple_get_int(), tuple_get_string(), and tuple_get_value_type().

#define TUPLE_LOCK_WRITE (   X)    g_static_mutex_lock (& tuple_mutex)

Convenience macros to lock the globally used internal Tuple system structures.

Definition at line 99 of file tuple.c.

Referenced by set_string(), tuple_associate_int(), tuple_copy(), tuple_destroy(), tuple_disassociate(), and tuple_new().

#define TUPLE_UNLOCK_READ (   X)    g_static_mutex_unlock (& tuple_mutex)

Convenience macros to lock the globally used internal Tuple system structures.

Definition at line 102 of file tuple.c.

Referenced by tuple_get_int(), tuple_get_string(), and tuple_get_value_type().

#define TUPLE_UNLOCK_WRITE (   X)    g_static_mutex_unlock (& tuple_mutex)

Convenience macros to lock the globally used internal Tuple system structures.

Definition at line 100 of file tuple.c.

Referenced by set_string(), tuple_associate_data(), tuple_associate_int(), tuple_copy(), tuple_destroy(), tuple_disassociate(), and tuple_new().


Function Documentation

static gboolean set_string ( Tuple tuple,
const gint  nfield,
const gchar *  field,
gchar *  string,
gboolean  take 
) [static]

Definition at line 409 of file tuple.c.

Referenced by tuple_associate_string(), tuple_associate_string_rel(), and tuple_set_filename().

static TupleValue * tuple_associate_data ( Tuple tuple,
const gint  cnfield,
const gchar *  field,
TupleValueType  ftype 
) [static]

(Re)associates data into given Tuple field.

If specified field already exists in the Tuple, any data from it is freed and this current TupleValue struct is returned.

If field does NOT exist, a new structure is allocated from global heap, added to Tuple and returned.

Attention:
This function has (unbalanced) Tuple structure unlocking, so please make sure you use it only exactly like it is used in tuple_associate_string(), etc.
Parameters:
[in]tupleTuple structure to be manipulated.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]ftypeType of the field to be associated.
Returns:
Pointer to associated TupleValue structure.

Definition at line 351 of file tuple.c.

Referenced by set_string(), and tuple_associate_int().

gboolean tuple_associate_int ( Tuple tuple,
const gint  nfield,
const gchar *  field,
gint  integer 
)

Associates given integer to a field in specified Tuple.

If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]integerInteger to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 502 of file tuple.c.

Referenced by tuple_set_filename(), and tuple_set_format().

gboolean tuple_associate_string ( Tuple tuple,
const gint  nfield,
const gchar *  field,
const gchar *  string 
)

Associates copy of given string to a field in specified Tuple.

If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]stringString to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 443 of file tuple.c.

Referenced by tuple_set_format().

gboolean tuple_associate_string_rel ( Tuple tuple,
const gint  nfield,
const gchar *  field,
gchar *  string 
)

Associates given string to a field in specified Tuple.

The caller gives up ownership of the string. If field already exists, old value is freed and replaced.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]nfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
[in]stringString to be associated to given field in Tuple.
Returns:
TRUE if operation was succesful, FALSE if not.

Definition at line 472 of file tuple.c.

Tuple* tuple_copy ( const Tuple src)

Creates a copy of given Tuple structure, with copied data.

Parameters:
[in]srcTuple structure to be made a copy of.
Returns:
Pointer to newly allocated Tuple.

Definition at line 268 of file tuple.c.

static TupleValue* tuple_copy_value ( TupleValue src) [static]

Creates a copy of given TupleValue structure, with copied data.

Parameters:
[in]srcTupleValue structure to be made a copy of.
Returns:
Pointer to newly allocated TupleValue or NULL if error occured or source was NULL.

Definition at line 237 of file tuple.c.

Referenced by tuple_copy().

static void tuple_destroy ( gpointer  data) [static]

Definition at line 121 of file tuple.c.

Referenced by tuple_new_unlocked().

void tuple_disassociate ( Tuple tuple,
const gint  cnfield,
const gchar *  field 
)

Disassociates given field from specified Tuple structure.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.

Definition at line 526 of file tuple.c.

gint tuple_get_int ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns integer associated to Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
Integer value or 0 if the field/key did not exist.
Bug:
There is no way to distinguish error situations if the associated value is zero.

Definition at line 641 of file tuple.c.

Referenced by entry_set_tuple_real(), read_gain_from_tuple(), tuple_compare_int(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

static gint tuple_get_nfield ( const gchar *  field) [static]
const gchar* tuple_get_string ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns pointer to a string associated to Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
Pointer to string or NULL if the field/key did not exist. The returned string is const, and must not be freed or modified.

Definition at line 599 of file tuple.c.

Referenced by describe_song(), playlist_select_by_patterns(), title_from_tuple(), tuple_compare_string(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_make_title_string(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

TupleValueType tuple_get_value_type ( const Tuple tuple,
gint  cnfield,
const gchar *  field 
)

Returns TupleValueType of given Tuple field.

Desired field can be specified either by key name or if it is one of basic fields, by TupleBasicType index.

Parameters:
[in]tupleTuple structure pointer.
[in]cnfieldTupleBasicType index or -1 if key name is to be used instead.
[in]fieldString acting as key name or NULL if nfield is used.
Returns:
TupleValueType of the field or TUPLE_UNKNOWN if there was an error.

Definition at line 562 of file tuple.c.

Referenced by entry_set_tuple_real(), tuple_compare_int(), tuple_formatter_expression_empty(), tuple_formatter_expression_match(), tuple_formatter_process_expr(), and tuple_value_to_gvalue().

Tuple* tuple_new ( void  )

Allocates a new empty Tuple structure.

Must be freed via tuple_free().

Returns:
Pointer to newly allocated Tuple.

Definition at line 171 of file tuple.c.

Referenced by tuple_new_from_filename().

Tuple* tuple_new_from_filename ( const gchar *  filename)

Allocates a new Tuple structure, setting filename/URI related fields based on the given filename argument by calling tuple_set_filename.

Parameters:
[in]filenameFilename URI.
Returns:
Pointer to newly allocated Tuple.

Definition at line 312 of file tuple.c.

Referenced by entry_set_failed().

static Tuple* tuple_new_unlocked ( void  ) [static]

Definition at line 143 of file tuple.c.

Referenced by tuple_copy(), and tuple_new().

void tuple_set_filename ( Tuple tuple,
const gchar *  name 
)

Sets filename/URI related fields of a Tuple structure, based on the given filename argument.

The fields set are: FIELD_FILE_PATH, FIELD_FILE_NAME and FIELD_FILE_EXT.

Parameters:
[in]filenameFilename URI.
[in,out]tupleTuple structure to manipulate.

Definition at line 195 of file tuple.c.

Referenced by tuple_new_from_filename().

void tuple_set_format ( Tuple t,
const gchar *  format,
gint  chans,
gint  rate,
gint  brate 
)

Definition at line 673 of file tuple.c.

static void tuple_value_destroy ( TupleValue value) [static]

Definition at line 105 of file tuple.c.

Referenced by tuple_destroy(), tuple_disassociate(), and tuple_value_destroy_cb().

static void tuple_value_destroy_cb ( const gchar *  key,
void *  data,
void *  priv 
) [static]

Definition at line 115 of file tuple.c.

Referenced by tuple_destroy().


Variable Documentation

const TupleBasicType tuple_fields[FIELD_LAST]

Ordered table of basic Tuple field names and their TupleValueType.

Definition at line 40 of file tuple.c.

Referenced by audacious_rc_get_tuple_fields(), and tuple_evalctx_add_var().

mowgli_heap_t* tuple_heap = NULL [static]

A mowgli heap containing all the allocated tuples.

Definition at line 85 of file tuple.c.

Referenced by tuple_destroy(), and tuple_new_unlocked().

mowgli_object_class_t tuple_klass [static]

Definition at line 89 of file tuple.c.

Referenced by tuple_new_unlocked().

GStaticMutex tuple_mutex = G_STATIC_MUTEX_INIT [static]

Global lock to preserve data consistency of heaps.

Definition at line 92 of file tuple.c.

mowgli_heap_t* tuple_value_heap = NULL [static]

A mowgli heap containing values contained by tuples.

Definition at line 88 of file tuple.c.

Referenced by tuple_associate_data(), tuple_copy_value(), tuple_new_unlocked(), and tuple_value_destroy().