1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #include <glib-object.h>
23 #include <glib/gi18n.h>
25 #include "mm-attribute-manager.h"
26 #include "mm-attribute-base-manager.h"
27 #include "mm-base-attributes.h"
29 static MMAttributeManager
*base_manager
= NULL
;
30 static GHashTable
*cached_attrs
= NULL
;
32 static void mm_attribute_manager_iface_init (MMAttributeManagerIface
*iface
);
34 G_DEFINE_TYPE_WITH_CODE (MMAttributeBaseManager
, mm_attribute_base_manager
,
36 G_IMPLEMENT_INTERFACE (MM_TYPE_ATTRIBUTE_MANAGER
,
37 mm_attribute_manager_iface_init
));
40 static const char * attribute_ids
[] = {
41 MM_ATTRIBUTE_BASE_URI
,
42 MM_ATTRIBUTE_BASE_NAME
45 static const GType attribute_types
[] = {
50 static const char * attribute_names
[] = {
55 static const char * attribute_descriptions
[] = {
56 N_("URI of the resource"),
57 N_("Name of the resource")
60 /* MMAttributeManager interface implementation */
63 impl_lookup_attribute (MMAttributeManager
*m
,
67 gboolean found
= FALSE
;
70 for (idx
= 0; idx
< G_N_ELEMENTS (attribute_ids
); idx
++) {
71 if (g_strcmp0 (attribute_ids
[idx
], id
) == 0) {
78 attr
= g_hash_table_lookup (cached_attrs
,
81 attr
= mm_attribute_new (attribute_types
[idx
],
84 attribute_descriptions
[idx
]);
85 g_hash_table_insert (cached_attrs
, (char *) attribute_ids
[idx
],
95 impl_get_supported_attributes (MMAttributeManager
*m
)
97 GList
*attributes
= NULL
;
101 for (idx
= 0; idx
< G_N_ELEMENTS (attribute_ids
); idx
++) {
102 attr
= g_hash_table_lookup (cached_attrs
,
105 attr
= mm_attribute_new (attribute_types
[idx
],
107 attribute_names
[idx
],
108 attribute_descriptions
[idx
]);
109 g_hash_table_insert (cached_attrs
, (char *) attribute_ids
[idx
],
112 attributes
= g_list_prepend (attributes
, attr
);
115 return g_list_reverse (attributes
);
119 mm_attribute_manager_iface_init (MMAttributeManagerIface
*iface
)
121 iface
->lookup_attribute
= impl_lookup_attribute
;
122 iface
->get_supported_attributes
= impl_get_supported_attributes
;
126 mm_attribute_base_manager_get (void)
129 base_manager
= MM_ATTRIBUTE_MANAGER (g_object_new (MM_TYPE_ATTRIBUTE_BASE_MANAGER
, NULL
));
136 mm_attribute_base_manager_finalize (GObject
*o
)
138 g_hash_table_destroy (cached_attrs
);
140 G_OBJECT_CLASS (mm_attribute_base_manager_parent_class
)->finalize (o
);
144 mm_attribute_base_manager_init (MMAttributeBaseManager
*abm
)
147 cached_attrs
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
148 NULL
, (GDestroyNotify
) mm_attribute_free
);
153 mm_attribute_base_manager_class_init (MMAttributeBaseManagerClass
*klass
)
155 G_OBJECT_CLASS (klass
)->finalize
= mm_attribute_base_manager_finalize
;