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 
31 using namespace fawkes;
32 using 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 
85 PLUGIN_DESCRIPTION("Reads images from cameras and stores them in shared memory")
86 EXPORT_PLUGIN(FvRetrieverPlugin)
fawkes::Plugin::config
Configuration * config
Fawkes configuration.
Definition: plugin.h:62
FvRetrieverPlugin
Definition: fvretriever_plugin.h:27
fawkes::Plugin::thread_list
ThreadList thread_list
Thread list member.
Definition: plugin.h:57
fawkes::ThreadList::push_back
void push_back(Thread *thread)
Add thread to the end.
Definition: thread_list.cpp:777
fawkes::Configuration::get_bool
virtual bool get_bool(const char *path)=0
fawkes::Configuration::ValueIterator
Definition: config.h:75
fawkes::Configuration
Definition: config.h:68
fawkes::Configuration::search
virtual ValueIterator * search(const char *path)=0
fawkes
FvRetrieverPlugin::FvRetrieverPlugin
FvRetrieverPlugin(fawkes::Configuration *config)
Constructor.
Definition: fvretriever_plugin.cpp:45
FvRetrieverThread
Definition: retriever_thread.h:43
fawkes::Configuration::get_string
virtual std::string get_string(const char *path)=0
fawkes::Configuration::ValueIterator::path
virtual const char * path() const =0
fawkes::Configuration::ValueIterator::next
virtual bool next()=0
fawkes::Plugin
Definition: plugin.h:37
fawkes::Exception
Definition: exception.h:39