提交 7a606941 编写于 作者: J jp9000

obs-properties: Add a few features

Just wanted the ability to be able to add private data to the properties
data.  Makes it a little easier to manage data if you get updates from
controls.
上级 79b88c4c
...@@ -85,6 +85,8 @@ struct obs_property { ...@@ -85,6 +85,8 @@ struct obs_property {
struct obs_properties { struct obs_properties {
const char *locale; const char *locale;
void *param;
void (*destroy)(void *param);
struct obs_property *first_property; struct obs_property *first_property;
struct obs_property **last; struct obs_property **last;
...@@ -99,6 +101,32 @@ obs_properties_t obs_properties_create(const char *locale) ...@@ -99,6 +101,32 @@ obs_properties_t obs_properties_create(const char *locale)
return props; return props;
} }
void obs_properties_set_param(obs_properties_t props,
void *param, void (*destroy)(void *param))
{
if (!props)
return;
if (props->param && props->destroy)
props->destroy(props->param);
props->param = param;
props->destroy = destroy;
}
void *obs_properties_get_param(obs_properties_t props)
{
return props ? props->param : NULL;
}
obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param))
{
struct obs_properties *props = obs_properties_create(locale);
obs_properties_set_param(props, param, destroy);
return props;
}
static void obs_property_destroy(struct obs_property *property) static void obs_property_destroy(struct obs_property *property)
{ {
if (property->type == OBS_PROPERTY_LIST) { if (property->type == OBS_PROPERTY_LIST) {
...@@ -113,6 +141,10 @@ void obs_properties_destroy(obs_properties_t props) ...@@ -113,6 +141,10 @@ void obs_properties_destroy(obs_properties_t props)
{ {
if (props) { if (props) {
struct obs_property *p = props->first_property; struct obs_property *p = props->first_property;
if (props->destroy && props->param)
props->destroy(props->param);
while (p) { while (p) {
struct obs_property *next = p->next; struct obs_property *next = p->next;
obs_property_destroy(p); obs_property_destroy(p);
......
...@@ -61,8 +61,14 @@ typedef struct obs_property *obs_property_t; ...@@ -61,8 +61,14 @@ typedef struct obs_property *obs_property_t;
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
EXPORT obs_properties_t obs_properties_create(const char *locale); EXPORT obs_properties_t obs_properties_create(const char *locale);
EXPORT obs_properties_t obs_properties_create_param(const char *locale,
void *param, void (*destroy)(void *param));
EXPORT void obs_properties_destroy(obs_properties_t props); EXPORT void obs_properties_destroy(obs_properties_t props);
EXPORT void obs_properties_set_param(obs_properties_t props,
void *param, void (*destroy)(void *param));
EXPORT void *obs_properties_get_param(obs_properties_t props);
EXPORT const char *obs_properties_locale(obs_properties_t props); EXPORT const char *obs_properties_locale(obs_properties_t props);
EXPORT obs_property_t obs_properties_first(obs_properties_t props); EXPORT obs_property_t obs_properties_first(obs_properties_t props);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册