Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
dd67992a
Commit
dd67992a
authored
Mar 14, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sticker: added "struct sticker"
The sticker struct can be used for enumerating values. This will replace the sticker_list_values() function.
parent
5b687795
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
0 deletions
+131
-0
song_sticker.c
src/song_sticker.c
+16
-0
song_sticker.h
src/song_sticker.h
+10
-0
sticker.c
src/sticker.c
+62
-0
sticker.h
src/sticker.h
+43
-0
No files found.
src/song_sticker.c
View file @
dd67992a
...
...
@@ -88,3 +88,19 @@ sticker_song_delete(const struct song *song)
return
ret
;
}
struct
sticker
*
sticker_song_get
(
const
struct
song
*
song
)
{
char
*
uri
;
struct
sticker
*
sticker
;
assert
(
song
!=
NULL
);
assert
(
song_in_database
(
song
));
uri
=
song_get_uri
(
song
);
sticker
=
sticker_load
(
"song"
,
uri
);
g_free
(
uri
);
return
sticker
;
}
src/song_sticker.h
View file @
dd67992a
...
...
@@ -24,6 +24,7 @@
#include <glib.h>
struct
song
;
struct
sticker
;
/**
* Returns one value from a song's sticker record. The caller must
...
...
@@ -53,4 +54,13 @@ sticker_song_list_values(const struct song *song);
bool
sticker_song_delete
(
const
struct
song
*
song
);
/**
* Loads the sticker for the specified song.
*
* @param song the song object
* @return a sticker object, or NULL on error or if there is no sticker
*/
struct
sticker
*
sticker_song_get
(
const
struct
song
*
song
);
#endif
src/sticker.c
View file @
dd67992a
...
...
@@ -27,6 +27,10 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "sticker"
struct
sticker
{
GHashTable
*
table
;
};
static
const
char
sticker_sql_create
[]
=
"CREATE TABLE IF NOT EXISTS sticker("
" type VARCHAR NOT NULL, "
...
...
@@ -433,3 +437,61 @@ sticker_delete(const char *type, const char *uri)
idle_add
(
IDLE_STICKER
);
return
true
;
}
void
sticker_free
(
struct
sticker
*
sticker
)
{
assert
(
sticker
!=
NULL
);
assert
(
sticker
->
table
!=
NULL
);
g_hash_table_destroy
(
sticker
->
table
);
g_free
(
sticker
);
}
const
char
*
sticker_get_value
(
struct
sticker
*
sticker
,
const
char
*
name
)
{
return
g_hash_table_lookup
(
sticker
->
table
,
name
);
}
struct
sticker_foreach_data
{
void
(
*
func
)(
const
char
*
name
,
const
char
*
value
,
gpointer
user_data
);
gpointer
user_data
;
};
static
void
sticker_foreach_func
(
gpointer
key
,
gpointer
value
,
gpointer
user_data
)
{
struct
sticker_foreach_data
*
data
=
user_data
;
data
->
func
(
key
,
value
,
data
->
user_data
);
}
void
sticker_foreach
(
struct
sticker
*
sticker
,
void
(
*
func
)(
const
char
*
name
,
const
char
*
value
,
gpointer
user_data
),
gpointer
user_data
)
{
struct
sticker_foreach_data
data
=
{
.
func
=
func
,
.
user_data
=
user_data
,
};
g_hash_table_foreach
(
sticker
->
table
,
sticker_foreach_func
,
&
data
);
}
struct
sticker
*
sticker_load
(
const
char
*
type
,
const
char
*
uri
)
{
struct
sticker
*
sticker
=
g_new
(
struct
sticker
,
1
);
sticker
->
table
=
sticker_list_values
(
type
,
uri
);
if
(
sticker
->
table
==
NULL
)
{
g_free
(
sticker
);
return
NULL
;
}
return
sticker
;
}
src/sticker.h
View file @
dd67992a
...
...
@@ -46,6 +46,8 @@
#include <stdbool.h>
struct
sticker
;
/**
* Opens the sticker database (if path is not NULL).
*/
...
...
@@ -94,4 +96,45 @@ sticker_store_value(const char *type, const char *uri,
bool
sticker_delete
(
const
char
*
type
,
const
char
*
uri
);
/**
* Frees resources held by the sticker object.
*
* @param sticker the sticker object to be freed
*/
void
sticker_free
(
struct
sticker
*
sticker
);
/**
* Determines a single value in a sticker.
*
* @param sticker the sticker object
* @param name the name of the sticker
* @return the sticker value, or NULL if none was found
*/
const
char
*
sticker_get_value
(
struct
sticker
*
sticker
,
const
char
*
name
);
/**
* Iterates over all sticker items in a sticker.
*
* @param sticker the sticker object
* @param func a callback function
* @param user_data an opaque pointer for the callback function
*/
void
sticker_foreach
(
struct
sticker
*
sticker
,
void
(
*
func
)(
const
char
*
name
,
const
char
*
value
,
gpointer
user_data
),
gpointer
user_data
);
/**
* Loads the sticker for the specified resource.
*
* @param type the resource type, e.g. "song"
* @param uri the URI of the resource, e.g. the song path
* @return a sticker object, or NULL on error or if there is no sticker
*/
struct
sticker
*
sticker_load
(
const
char
*
type
,
const
char
*
uri
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment