diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/meson.build | 4 | ||||
-rw-r--r-- | src/ufo-roof-build-task.c | 26 | ||||
-rw-r--r-- | src/ufo-roof-config.c | 14 | ||||
-rw-r--r-- | src/ufo-roof-config.h | 10 | ||||
-rw-r--r-- | src/ufo-roof-filter-task.c (renamed from src/ufo-roof-plane-task.c) | 118 | ||||
-rw-r--r-- | src/ufo-roof-filter-task.h | 53 | ||||
-rw-r--r-- | src/ufo-roof-plane-task.h | 53 | ||||
-rw-r--r-- | src/ufo-roof-read-file.c | 6 | ||||
-rw-r--r-- | src/ufo-roof-read-file.h | 2 | ||||
-rw-r--r-- | src/ufo-roof-read-task.c | 62 |
11 files changed, 223 insertions, 127 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0967ffb..116b400 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.6) set(ufofilter_SRCS ufo-roof-read-task.c ufo-roof-build-task.c - ufo-roof-plane-task.c + ufo-roof-filter-task.c ) set(common_SRCS diff --git a/src/meson.build b/src/meson.build index 8a03a57..8f8930a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,7 +1,7 @@ plugins = [ 'roof-read', 'roof-build', - 'roof-plane', + 'roof-filter', ] roof_common_src = [ @@ -16,7 +16,7 @@ roof_plugin_src = { 'roof-build': [ 'ufo-roof-buffer.c', ], - 'roof-plane': [ + 'roof-filter': [ ], } diff --git a/src/ufo-roof-build-task.c b/src/ufo-roof-build-task.c index 93cb133..9d55d38 100644 --- a/src/ufo-roof-build-task.c +++ b/src/ufo-roof-build-task.c @@ -44,6 +44,7 @@ struct _UfoRoofBuildTaskPrivate { BuildType build; // What dataset do we build: ROOF sinogram or raw network data guint number; // Number of datasets to read gboolean stop; // Stop flag + gboolean simulate; // Indicates if we are running in network or simulation modes guint announced; // For debugging @@ -71,6 +72,7 @@ static GEnumValue build_values[] = { enum { PROP_0, PROP_STOP, + PROP_SIMULATE, PROP_NUMBER, PROP_BUILD, PROP_CONFIG, @@ -97,7 +99,7 @@ ufo_roof_build_task_setup (UfoTask *task, if (!priv->config) roof_setup_error(error, "ROOF configuration is not specified"); - priv->cfg = ufo_roof_config_new(priv->config, &gerr); + priv->cfg = ufo_roof_config_new(priv->config, priv->simulate?UFO_ROOF_CONFIG_SIMULATION:UFO_ROOF_CONFIG_DEFAULT, &gerr); if (!priv->cfg) roof_propagate_error(error, gerr, "roof-build-setup: "); @@ -281,15 +283,23 @@ ufo_roof_build_task_generate (UfoTask *task, case 32: ufo_buffer_convert(output, UFO_BUFFER_DEPTH_32U); break; + default: + printf("Usupported bit-depth %u\n", cfg->bit_depth); } } // Metadata: plane and sequential number within the plane g_value_init (&ival, G_TYPE_UINT); g_value_init (&lval, G_TYPE_ULONG); + if (priv->build != BUILD_UFO) { + g_value_set_uint (&ival, cfg->bit_depth); + ufo_buffer_set_metadata (output, "bpp", &ival); + } g_value_set_uint (&ival, 1 + seqid % cfg->n_planes); ufo_buffer_set_metadata (output, "plane", &ival); g_value_set_ulong (&lval, seqid / cfg->n_planes); + ufo_buffer_set_metadata (output, "plane_id", &lval); + g_value_set_ulong (&lval, seqid); ufo_buffer_set_metadata (output, "seqid", &lval); g_value_unset(&lval); g_value_unset(&ival); @@ -325,6 +335,9 @@ ufo_roof_build_task_set_property (GObject *object, case PROP_STOP: priv->stop = g_value_get_boolean (value); break; + case PROP_SIMULATE: + priv->simulate = g_value_get_boolean (value); + break; case PROP_NUMBER: priv->number = g_value_get_uint (value); break; @@ -356,6 +369,9 @@ ufo_roof_build_task_get_property (GObject *object, case PROP_STOP: g_value_set_boolean (value, priv->stop); break; + case PROP_SIMULATE: + g_value_set_boolean (value, priv->simulate); + break; case PROP_NUMBER: g_value_set_uint (value, priv->number); break; @@ -403,6 +419,14 @@ ufo_roof_build_task_class_init (UfoRoofBuildTaskClass *klass) FALSE, G_PARAM_READWRITE); + + properties[PROP_SIMULATE] = + g_param_spec_boolean ("simulate", + "Simulation mode", + "Read data from the specified files instead of network", + FALSE, + G_PARAM_READWRITE); + properties[PROP_NUMBER] = g_param_spec_uint("number", "Number of datasets to receive", diff --git a/src/ufo-roof-config.c b/src/ufo-roof-config.c index 4788a2a..17f4b30 100644 --- a/src/ufo-roof-config.c +++ b/src/ufo-roof-config.c @@ -43,9 +43,6 @@ void ufo_roof_config_free(UfoRoofConfig *cfg) { if (cfg) { UfoRoofConfigPrivate *priv = (UfoRoofConfigPrivate*)cfg; - if (cfg->path) - g_free(cfg->path); - if (priv->parser) g_object_unref (priv->parser); @@ -53,7 +50,7 @@ void ufo_roof_config_free(UfoRoofConfig *cfg) { } } -UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error) { +UfoRoofConfig *ufo_roof_config_new(const char *config, UfoRoofConfigFlags flags, GError **error) { UfoRoofConfigPrivate *priv; UfoRoofConfig *cfg; @@ -66,6 +63,7 @@ UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error) { JsonObject *performance = NULL; JsonObject *simulation = NULL; JsonObject *reconstruction = NULL; + JsonObject *data = NULL; GError *gerr = NULL; @@ -97,7 +95,6 @@ UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error) { cfg->dataset_size = 0; cfg->buffer_size = 2; cfg->drop_buffers = 0; - cfg->path = NULL; // Read configuration @@ -118,8 +115,11 @@ UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error) { roof_config_node_get(optics, root, object, "optics"); roof_config_node_get(network, root, object, "network"); roof_config_node_get(reconstruction, root, object, "reconstruction"); - roof_config_node_get(simulation, root, object, "simulation"); roof_config_node_get(performance, root, object, "performance"); + roof_config_node_get(data, root, object, "data"); + + if (flags&UFO_ROOF_CONFIG_SIMULATION) + roof_config_node_get(simulation, root, object, "simulation"); } if (hardware) { @@ -183,8 +183,6 @@ UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error) { } if (simulation) { - roof_config_node_get_string(cfg->path, simulation, "path"); - roof_config_node_get(cfg->first_file_number, simulation, int, "first_file_number"); roof_config_node_get(cfg->header_size, simulation, int, "header_size"); if (!cfg->payload_size) diff --git a/src/ufo-roof-config.h b/src/ufo-roof-config.h index b6ee748..34bef0b 100644 --- a/src/ufo-roof-config.h +++ b/src/ufo-roof-config.h @@ -25,8 +25,6 @@ typedef struct { // Network Server / Reader - gchar *path; // Location of data files for simmulation purposes (i.e. reading a sequence of files instead listening on the corresponding ports) - guint first_file_number; // Indicates if the numbering of files starts at 0 or 1 gchar *protocol; // Protocols: tcp, udp, tcp6, udp6, ... guint port; // First port guint n_streams; // Number of independent data streams (expected on sequential ports), by default equal to number of ROOF modules @@ -53,7 +51,13 @@ typedef struct { } UfoRoofConfig; -UfoRoofConfig *ufo_roof_config_new(const char *config, GError **error); +typedef enum { + UFO_ROOF_CONFIG_DEFAULT = 0, + UFO_ROOF_CONFIG_SIMULATION = 1 +} UfoRoofConfigFlags; + + +UfoRoofConfig *ufo_roof_config_new(const char *config, UfoRoofConfigFlags flags, GError **error); void ufo_roof_config_free(UfoRoofConfig *cfg); #endif /* __UFO_ROOF_CONFIG_H */ diff --git a/src/ufo-roof-plane-task.c b/src/ufo-roof-filter-task.c index 25c2bfa..01bc742 100644 --- a/src/ufo-roof-plane-task.c +++ b/src/ufo-roof-filter-task.c @@ -17,98 +17,90 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ -#include <stdio.h> - #ifdef __APPLE__ #include <OpenCL/cl.h> #else #include <CL/cl.h> #endif -#include "ufo-roof-plane-task.h" +#include "ufo-roof-filter-task.h" -struct _UfoRoofPlaneTaskPrivate { +struct _UfoRoofFilterTaskPrivate { gboolean ready; // Indicates if data is ready for generation + gboolean block; // Block output alltogether guint plane; // Selected plane (0 - pass everything trough) + gdouble fps; // Limit maximum frame rate }; static void ufo_task_interface_init (UfoTaskIface *iface); -G_DEFINE_TYPE_WITH_CODE (UfoRoofPlaneTask, ufo_roof_plane_task, UFO_TYPE_TASK_NODE, +G_DEFINE_TYPE_WITH_CODE (UfoRoofFilterTask, ufo_roof_filter_task, UFO_TYPE_TASK_NODE, G_IMPLEMENT_INTERFACE (UFO_TYPE_TASK, ufo_task_interface_init)) -#define UFO_ROOF_PLANE_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_ROOF_PLANE_TASK, UfoRoofPlaneTaskPrivate)) +#define UFO_ROOF_FILTER_TASK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_ROOF_FILTER_TASK, UfoRoofFilterTaskPrivate)) enum { PROP_0, PROP_PLANE, + PROP_FPS, + PROP_BLOCK, N_PROPERTIES }; static GParamSpec *properties[N_PROPERTIES] = { NULL, }; UfoNode * -ufo_roof_plane_task_new (void) +ufo_roof_filter_task_new (void) { - return UFO_NODE (g_object_new (UFO_TYPE_ROOF_PLANE_TASK, NULL)); + return UFO_NODE (g_object_new (UFO_TYPE_ROOF_FILTER_TASK, NULL)); } static void -ufo_roof_plane_task_setup (UfoTask *task, +ufo_roof_filter_task_setup (UfoTask *task, UfoResources *resources, GError **error) { } static void -ufo_roof_plane_task_get_requisition (UfoTask *task, +ufo_roof_filter_task_get_requisition (UfoTask *task, UfoBuffer **inputs, UfoRequisition *requisition, GError **error) { ufo_buffer_get_requisition (inputs[0], requisition); -/* int i; -// UfoRoofPlaneTaskPrivate *priv; - UfoRequisition in_req; - -// priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE (task); - ufo_buffer_get_requisition (inputs[0], &in_req); - - requisition->n_dims = in_req.n_dims; - for (i = 0; i < in_req.n_dims; i++) - requisition->dims[i] = in_req.dims[i];*/ } static guint -ufo_roof_plane_task_get_num_inputs (UfoTask *task) +ufo_roof_filter_task_get_num_inputs (UfoTask *task) { return 1; } static guint -ufo_roof_plane_task_get_num_dimensions (UfoTask *task, +ufo_roof_filter_task_get_num_dimensions (UfoTask *task, guint input) { return 2; } static UfoTaskMode -ufo_roof_plane_task_get_mode (UfoTask *task) +ufo_roof_filter_task_get_mode (UfoTask *task) { return UFO_TASK_MODE_CPU|UFO_TASK_MODE_REDUCTOR; } static gboolean -ufo_roof_plane_task_process (UfoTask *task, +ufo_roof_filter_task_process (UfoTask *task, UfoBuffer **inputs, UfoBuffer *output, UfoRequisition *requisition) { - UfoRoofPlaneTaskPrivate *priv; + UfoRoofFilterTaskPrivate *priv; - priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE (task); + priv = UFO_ROOF_FILTER_TASK_GET_PRIVATE (task); if (priv->plane) { int buf_plane; @@ -128,13 +120,13 @@ ufo_roof_plane_task_process (UfoTask *task, } static gboolean -ufo_roof_plane_task_generate (UfoTask *task, +ufo_roof_filter_task_generate (UfoTask *task, UfoBuffer *output, UfoRequisition *requisition) { - UfoRoofPlaneTaskPrivate *priv; + UfoRoofFilterTaskPrivate *priv; - priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE (task); + priv = UFO_ROOF_FILTER_TASK_GET_PRIVATE (task); if (!priv->ready) return FALSE; /* @@ -148,19 +140,24 @@ ufo_roof_plane_task_generate (UfoTask *task, return TRUE; } - static void -ufo_roof_plane_task_set_property (GObject *object, +ufo_roof_filter_task_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - UfoRoofPlaneTaskPrivate *priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE (object); + UfoRoofFilterTaskPrivate *priv = UFO_ROOF_FILTER_TASK_GET_PRIVATE (object); switch (property_id) { + case PROP_BLOCK: + priv->block = g_value_get_boolean(value); + break; case PROP_PLANE: priv->plane = g_value_get_uint (value); break; + case PROP_FPS: + priv->fps = g_value_get_double (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -168,17 +165,23 @@ ufo_roof_plane_task_set_property (GObject *object, } static void -ufo_roof_plane_task_get_property (GObject *object, +ufo_roof_filter_task_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - UfoRoofPlaneTaskPrivate *priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE (object); + UfoRoofFilterTaskPrivate *priv = UFO_ROOF_FILTER_TASK_GET_PRIVATE (object); switch (property_id) { + case PROP_BLOCK: + g_value_set_boolean (value, priv->block); + break; case PROP_PLANE: g_value_set_uint (value, priv->plane); break; + case PROP_FPS: + g_value_set_double (value, priv->fps); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -186,32 +189,38 @@ ufo_roof_plane_task_get_property (GObject *object, } static void -ufo_roof_plane_task_finalize (GObject *object) +ufo_roof_filter_task_finalize (GObject *object) { - G_OBJECT_CLASS (ufo_roof_plane_task_parent_class)->finalize (object); + G_OBJECT_CLASS (ufo_roof_filter_task_parent_class)->finalize (object); } static void ufo_task_interface_init (UfoTaskIface *iface) { - iface->setup = ufo_roof_plane_task_setup; - iface->get_num_inputs = ufo_roof_plane_task_get_num_inputs; - iface->get_num_dimensions = ufo_roof_plane_task_get_num_dimensions; - iface->get_mode = ufo_roof_plane_task_get_mode; - iface->get_requisition = ufo_roof_plane_task_get_requisition; - iface->process = ufo_roof_plane_task_process; - iface->generate = ufo_roof_plane_task_generate; - + iface->setup = ufo_roof_filter_task_setup; + iface->get_num_inputs = ufo_roof_filter_task_get_num_inputs; + iface->get_num_dimensions = ufo_roof_filter_task_get_num_dimensions; + iface->get_mode = ufo_roof_filter_task_get_mode; + iface->get_requisition = ufo_roof_filter_task_get_requisition; + iface->process = ufo_roof_filter_task_process; + iface->generate = ufo_roof_filter_task_generate; } static void -ufo_roof_plane_task_class_init (UfoRoofPlaneTaskClass *klass) +ufo_roof_filter_task_class_init (UfoRoofFilterTaskClass *klass) { GObjectClass *oclass = G_OBJECT_CLASS (klass); - oclass->set_property = ufo_roof_plane_task_set_property; - oclass->get_property = ufo_roof_plane_task_get_property; - oclass->finalize = ufo_roof_plane_task_finalize; + oclass->set_property = ufo_roof_filter_task_set_property; + oclass->get_property = ufo_roof_filter_task_get_property; + oclass->finalize = ufo_roof_filter_task_finalize; + + properties[PROP_BLOCK] = + g_param_spec_boolean ("block", + "Block/Unblock data stream", + "Blocks all data output from the filter", + FALSE, + G_PARAM_READWRITE); properties[PROP_PLANE] = g_param_spec_uint ("plane", @@ -220,14 +229,21 @@ ufo_roof_plane_task_class_init (UfoRoofPlaneTaskClass *klass) 0, G_MAXUINT, 0, G_PARAM_READWRITE); + properties[PROP_FPS] = + g_param_spec_double ("fps", + "Maximum frame rate", + "Limits maximum frame rate", + 0, G_MAXDOUBLE, 0, + G_PARAM_READWRITE); + for (guint i = PROP_0 + 1; i < N_PROPERTIES; i++) g_object_class_install_property (oclass, i, properties[i]); - g_type_class_add_private (oclass, sizeof(UfoRoofPlaneTaskPrivate)); + g_type_class_add_private (oclass, sizeof(UfoRoofFilterTaskPrivate)); } static void -ufo_roof_plane_task_init(UfoRoofPlaneTask *self) +ufo_roof_filter_task_init(UfoRoofFilterTask *self) { - self->priv = UFO_ROOF_PLANE_TASK_GET_PRIVATE(self); + self->priv = UFO_ROOF_FILTER_TASK_GET_PRIVATE(self); } diff --git a/src/ufo-roof-filter-task.h b/src/ufo-roof-filter-task.h new file mode 100644 index 0000000..920ba45 --- /dev/null +++ b/src/ufo-roof-filter-task.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2011-2013 Karlsruhe Institute of Technology + * + * This file is part of Ufo. + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __UFO_ROOF_FILTER_TASK_H +#define __UFO_ROOF_FILTER_TASK_H + +#include <ufo/ufo.h> + +G_BEGIN_DECLS + +#define UFO_TYPE_ROOF_FILTER_TASK (ufo_roof_filter_task_get_type()) +#define UFO_ROOF_FILTER_TASK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UFO_TYPE_ROOF_FILTER_TASK, UfoRoofFilterTask)) +#define UFO_IS_ROOF_FILTER_TASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UFO_TYPE_ROOF_FILTER_TASK)) +#define UFO_ROOF_FILTER_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UFO_TYPE_ROOF_FILTER_TASK, UfoRoofFilterTaskClass)) +#define UFO_IS_ROOF_FILTER_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UFO_TYPE_ROOF_FILTER_TASK)) +#define UFO_ROOF_FILTER_TASK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UFO_TYPE_ROOF_FILTER_TASK, UfoRoofFilterTaskClass)) + +typedef struct _UfoRoofFilterTask UfoRoofFilterTask; +typedef struct _UfoRoofFilterTaskClass UfoRoofFilterTaskClass; +typedef struct _UfoRoofFilterTaskPrivate UfoRoofFilterTaskPrivate; + +struct _UfoRoofFilterTask { + UfoTaskNode parent_instance; + + UfoRoofFilterTaskPrivate *priv; +}; + +struct _UfoRoofFilterTaskClass { + UfoTaskNodeClass parent_class; +}; + +UfoNode *ufo_roof_filter_task_new (void); +GType ufo_roof_filter_task_get_type (void); + +G_END_DECLS + +#endif diff --git a/src/ufo-roof-plane-task.h b/src/ufo-roof-plane-task.h deleted file mode 100644 index 7794065..0000000 --- a/src/ufo-roof-plane-task.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2011-2013 Karlsruhe Institute of Technology - * - * This file is part of Ufo. - * - * This library is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __UFO_ROOF_PLANE_TASK_H -#define __UFO_ROOF_PLANE_TASK_H - -#include <ufo/ufo.h> - -G_BEGIN_DECLS - -#define UFO_TYPE_ROOF_PLANE_TASK (ufo_roof_plane_task_get_type()) -#define UFO_ROOF_PLANE_TASK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UFO_TYPE_ROOF_PLANE_TASK, UfoRoofPlaneTask)) -#define UFO_IS_ROOF_PLANE_TASK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UFO_TYPE_ROOF_PLANE_TASK)) -#define UFO_ROOF_PLANE_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UFO_TYPE_ROOF_PLANE_TASK, UfoRoofPlaneTaskClass)) -#define UFO_IS_ROOF_PLANE_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UFO_TYPE_ROOF_PLANE_TASK)) -#define UFO_ROOF_PLANE_TASK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), UFO_TYPE_ROOF_PLANE_TASK, UfoRoofPlaneTaskClass)) - -typedef struct _UfoRoofPlaneTask UfoRoofPlaneTask; -typedef struct _UfoRoofPlaneTaskClass UfoRoofPlaneTaskClass; -typedef struct _UfoRoofPlaneTaskPrivate UfoRoofPlaneTaskPrivate; - -struct _UfoRoofPlaneTask { - UfoTaskNode parent_instance; - - UfoRoofPlaneTaskPrivate *priv; -}; - -struct _UfoRoofPlaneTaskClass { - UfoTaskNodeClass parent_class; -}; - -UfoNode *ufo_roof_plane_task_new (void); -GType ufo_roof_plane_task_get_type (void); - -G_END_DECLS - -#endif diff --git a/src/ufo-roof-read-file.c b/src/ufo-roof-read-file.c index a5eb69b..4ee11c6 100644 --- a/src/ufo-roof-read-file.c +++ b/src/ufo-roof-read-file.c @@ -55,7 +55,7 @@ static guint ufo_roof_read_file(UfoRoofReadInterface *iface, uint8_t *buffers, G } -UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, guint id, GError **error) { +UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, const char *path, guint file_id, GError **error) { UfoRoofReadFile *reader = (UfoRoofReadFile*)calloc(1, sizeof(UfoRoofReadFile)); if (!reader) roof_new_error(error, "Can't allocate UfoRoofReadFile"); @@ -67,7 +67,7 @@ UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, guint id, GErro reader->iface.close = ufo_roof_read_file_free; reader->iface.read =ufo_roof_read_file; - reader->fname = g_strdup_printf(cfg->path, id + cfg->first_file_number); + reader->fname = g_strdup_printf(path, file_id); if (!reader->fname) { free(reader); roof_new_error(error, "Can't build file name"); @@ -77,7 +77,7 @@ UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, guint id, GErro if (!reader->fd) { g_free(reader->fname); g_free(reader); - roof_new_error(error, "Can't open file %s", reader->fname); + roof_new_error(error, "Can't open file %i at path %s", file_id, path); } return (UfoRoofReadInterface*)reader; diff --git a/src/ufo-roof-read-file.h b/src/ufo-roof-read-file.h index 54bcf49..787b441 100644 --- a/src/ufo-roof-read-file.h +++ b/src/ufo-roof-read-file.h @@ -3,6 +3,6 @@ #include "ufo-roof-read.h" -UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, guint id, GError **error); +UfoRoofReadInterface *ufo_roof_read_file_new(UfoRoofConfig *cfg, const char *path, guint file_id, GError **error); #endif diff --git a/src/ufo-roof-read-task.c b/src/ufo-roof-read-task.c index 1582437..a8ddded 100644 --- a/src/ufo-roof-read-task.c +++ b/src/ufo-roof-read-task.c @@ -39,6 +39,9 @@ struct _UfoRoofReadTaskPrivate { guint id; // Reader ID (defince sequential port number) gboolean stop; // Flag requiring termination + gboolean simulate; // Indicates if we are running in network or simulation modes + gchar *path; // UFO file path for simulation mode + guint first_file_number; // Number of a first simulated file (0 or 1) }; static void ufo_task_interface_init (UfoTaskIface *iface); @@ -54,6 +57,9 @@ enum { PROP_ID, PROP_STOP, PROP_CONFIG, + PROP_SIMULATE, + PROP_PATH, + PROP_FIRST, N_PROPERTIES }; @@ -77,7 +83,7 @@ ufo_roof_read_task_setup (UfoTask *task, if (!priv->config) roof_setup_error(error, "ROOF configuration is not specified"); - priv->cfg = ufo_roof_config_new(priv->config, &gerr); + priv->cfg = ufo_roof_config_new(priv->config, priv->simulate?UFO_ROOF_CONFIG_SIMULATION:UFO_ROOF_CONFIG_DEFAULT, &gerr); if (!priv->cfg) roof_propagate_error(error, gerr, "roof_config_new: "); // Consistency checks @@ -85,9 +91,12 @@ ufo_roof_read_task_setup (UfoTask *task, roof_setup_error(error, "Specified Stream ID is %u, but only %u data streams is configured", priv->id, priv->cfg->n_streams); // Start actual reader - if (priv->cfg->path) - priv->reader = ufo_roof_read_file_new(priv->cfg, priv->id, &gerr); - else + if (priv->simulate) { + if (!priv->path) + roof_setup_error(error, "Path to simulated data should be specified"); + + priv->reader = ufo_roof_read_file_new(priv->cfg, priv->path, priv->id + priv->first_file_number, &gerr); + } else priv->reader = ufo_roof_read_socket_new(priv->cfg, priv->id, &gerr); if (!priv->reader) @@ -115,6 +124,11 @@ ufo_roof_read_task_finalize (GObject *object) priv->config = NULL; } + if (priv->path) { + g_free(priv->path); + priv->path = NULL; + } + G_OBJECT_CLASS (ufo_roof_read_task_parent_class)->finalize (object); } @@ -206,6 +220,16 @@ ufo_roof_read_task_set_property (GObject *object, case PROP_STOP: priv->stop = g_value_get_boolean (value); break; + case PROP_SIMULATE: + priv->simulate = g_value_get_boolean (value); + break; + case PROP_PATH: + if (priv->path) g_free(priv->path); + priv->path = g_value_dup_string(value); + break; + case PROP_FIRST: + priv->first_file_number = g_value_get_uint (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -230,6 +254,15 @@ ufo_roof_read_task_get_property (GObject *object, case PROP_STOP: g_value_set_boolean (value, priv->stop); break; + case PROP_SIMULATE: + g_value_set_boolean (value, priv->simulate); + break; + case PROP_PATH: + g_value_set_string(value, priv->path?priv->path:""); + break; + case PROP_FIRST: + g_value_set_uint (value, priv->first_file_number); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -277,6 +310,27 @@ ufo_roof_read_task_class_init (UfoRoofReadTaskClass *klass) FALSE, G_PARAM_READWRITE); + properties[PROP_SIMULATE] = + g_param_spec_boolean ("simulate", + "Simulation mode", + "Read data from the specified files instead of network", + FALSE, + G_PARAM_READWRITE); + + properties[PROP_PATH] = + g_param_spec_string ("path", + "Input files for simulation mode", + "Optional path to input files for simulation mode (parameter from configuration file is used if not specified)", + "", + G_PARAM_READWRITE); + + properties[PROP_FIRST] = + g_param_spec_uint ("first_file_number", + "Offset to the first read file", + "Offset to the first read file", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE); + for (guint i = PROP_0 + 1; i < N_PROPERTIES; i++) g_object_class_install_property (oclass, i, properties[i]); |