m-config-static-objects: add device parser to create static devices
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "parser-device.h"
|
||||
#include "parser-node.h"
|
||||
#include "context.h"
|
||||
|
||||
@@ -98,6 +99,30 @@ on_device_added (WpObjectManager *om, WpProxy *proxy, gpointer p)
|
||||
wp_config_static_objects_context_create_node (self, node_data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parser_device_foreach_func (const struct WpParserDeviceData *device_data,
|
||||
gpointer data)
|
||||
{
|
||||
WpConfigStaticObjectsContext *self = data;
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (WP_PLUGIN (self));
|
||||
g_autoptr (WpDevice) device = NULL;
|
||||
g_return_val_if_fail (core, FALSE);
|
||||
|
||||
/* Create the device */
|
||||
device = wp_device_new_from_factory (core, device_data->factory,
|
||||
device_data->props ? wp_properties_ref (device_data->props) : NULL);
|
||||
if (!device) {
|
||||
wp_warning_object (self, "failed to create device");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* export */
|
||||
wp_proxy_augment (WP_PROXY (device), WP_PROXY_FEATURES_STANDARD, NULL,
|
||||
on_object_created, self);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parser_node_foreach_func (const struct WpParserNodeData *node_data,
|
||||
gpointer data)
|
||||
@@ -119,20 +144,43 @@ wp_config_static_objects_context_activate (WpPlugin * plugin)
|
||||
WpConfigStaticObjectsContext *self = WP_CONFIG_STATIC_OBJECTS_CONTEXT (plugin);
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (plugin);
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
g_autoptr (WpConfigParser) parser = NULL;
|
||||
|
||||
self->static_objects = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
|
||||
/* Create and install the device object manager */
|
||||
self->devices_om = wp_object_manager_new ();
|
||||
wp_object_manager_add_interest (self->devices_om, WP_TYPE_DEVICE, NULL);
|
||||
wp_object_manager_request_proxy_features (self->devices_om, WP_TYPE_DEVICE,
|
||||
WP_PROXY_FEATURE_INFO);
|
||||
g_signal_connect (self->devices_om, "object-added",
|
||||
(GCallback) on_device_added, self);
|
||||
wp_core_install_object_manager (core, self->devices_om);
|
||||
|
||||
/* Add the node parser and parse the node files */
|
||||
wp_configuration_add_extension (config, WP_PARSER_NODE_EXTENSION,
|
||||
WP_TYPE_PARSER_NODE);
|
||||
wp_configuration_reload (config, WP_PARSER_NODE_EXTENSION);
|
||||
|
||||
/* Install the object manager */
|
||||
wp_core_install_object_manager (core, self->devices_om);
|
||||
/* Add the device parser and parse the device files */
|
||||
wp_configuration_add_extension (config, WP_PARSER_DEVICE_EXTENSION,
|
||||
WP_TYPE_PARSER_DEVICE);
|
||||
wp_configuration_reload (config, WP_PARSER_DEVICE_EXTENSION);
|
||||
|
||||
/* Create static devices */
|
||||
{
|
||||
g_autoptr (WpConfigParser) parser =
|
||||
wp_configuration_get_parser (config, WP_PARSER_DEVICE_EXTENSION);
|
||||
wp_parser_device_foreach (WP_PARSER_DEVICE (parser),
|
||||
parser_device_foreach_func, self);
|
||||
}
|
||||
|
||||
/* Create static nodes without match-device */
|
||||
parser = wp_configuration_get_parser (config, WP_PARSER_NODE_EXTENSION);
|
||||
wp_parser_node_foreach (WP_PARSER_NODE (parser), parser_node_foreach_func,
|
||||
self);
|
||||
{
|
||||
g_autoptr (WpConfigParser) parser =
|
||||
wp_configuration_get_parser (config, WP_PARSER_NODE_EXTENSION);
|
||||
wp_parser_node_foreach (WP_PARSER_NODE (parser),
|
||||
parser_node_foreach_func, self);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -146,6 +194,7 @@ wp_config_static_objects_context_deactivate (WpPlugin *plugin)
|
||||
g_autoptr (WpCore) core = wp_plugin_get_core (plugin);
|
||||
if (core) {
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
wp_configuration_remove_extension (config, WP_PARSER_DEVICE_EXTENSION);
|
||||
wp_configuration_remove_extension (config, WP_PARSER_NODE_EXTENSION);
|
||||
}
|
||||
}
|
||||
@@ -153,15 +202,6 @@ wp_config_static_objects_context_deactivate (WpPlugin *plugin)
|
||||
static void
|
||||
wp_config_static_objects_context_init (WpConfigStaticObjectsContext *self)
|
||||
{
|
||||
self->static_objects = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
self->devices_om = wp_object_manager_new ();
|
||||
|
||||
/* Only handle devices */
|
||||
wp_object_manager_add_interest (self->devices_om, WP_TYPE_DEVICE, NULL);
|
||||
wp_object_manager_request_proxy_features (self->devices_om, WP_TYPE_DEVICE,
|
||||
WP_PROXY_FEATURE_INFO);
|
||||
g_signal_connect (self->devices_om, "object-added",
|
||||
(GCallback) on_device_added, self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user