Fawkes API Fawkes Development Version
fvretriever_plugin.cpp
1
2/***************************************************************************
3 * fvretriever_plugin.cpp - FireVision Retriever Plugin
4 *
5 * Created: Tue Jun 26 17:35:33 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include "fvretriever_plugin.h"
24
25#include "retriever_thread.h"
26
27#include <core/exceptions/software.h>
28
29#include <set>
30
31using namespace fawkes;
32using namespace firevision;
33
34/** @class FvRetrieverPlugin "fvretriever_plugin.h"
35 * FireVision Retriever Plugin.
36 * This is the FireVision retriever plugin. It is a simple plugin that will
37 * fetch images from a specific camera defined as a configuration setting.
38 *
39 * @author Tim Niemueller
40 */
41
42/** Constructor.
43 * @param config Fawkes configuration
44 */
46{
47 std::set<std::string> configs;
48 std::set<std::string> ignored_configs;
49
50 std::string prefix = "/firevision/retriever/camera/";
51
52 Configuration::ValueIterator *vi = config->search(prefix.c_str());
53 while (vi->next()) {
54 std::string cfg_name = std::string(vi->path()).substr(prefix.length());
55 cfg_name = cfg_name.substr(0, cfg_name.find("/"));
56
57 if ((configs.find(cfg_name) == configs.end())
58 && (ignored_configs.find(cfg_name) == ignored_configs.end())) {
59 std::string cfg_prefix = prefix + cfg_name + "/";
60
61 bool active = true;
62 try {
63 active = config->get_bool((cfg_prefix + "active").c_str());
64 } catch (Exception &e) {
65 } // ignored, assume enabled
66 std::string cam_string = config->get_string((cfg_prefix + "string").c_str());
67
68 if (active) {
69 thread_list.push_back(new FvRetrieverThread(cam_string, cfg_name, cfg_prefix));
70 configs.insert(cfg_name);
71 } else {
72 //printf("Ignoring retriever config %s\n", cfg_name.c_str());
73 ignored_configs.insert(cfg_name);
74 }
75 }
76 }
77
78 delete vi;
79
80 if (thread_list.empty()) {
81 throw Exception("No cameras have been set for fvretriever");
82 }
83}
84
85PLUGIN_DESCRIPTION("Reads images from cameras and stores them in shared memory")
86EXPORT_PLUGIN(FvRetrieverPlugin)
FireVision Retriever Plugin.
FvRetrieverPlugin(fawkes::Configuration *config)
Constructor.
FireVision retriever thread.
Iterator interface to iterate over config values.
Definition: config.h:75
virtual const char * path() const =0
Path of value.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Interface for configuration handling.
Definition: config.h:68
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
Base class for exceptions in Fawkes.
Definition: exception.h:36
Plugin interface class.
Definition: plugin.h:34
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
Configuration * config
Fawkes configuration.
Definition: plugin.h:58
void push_back(Thread *thread)
Add thread to the end.
Fawkes library namespace.