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 #include "retriever_thread.h"
25 
26 #include <core/exceptions/software.h>
27 
28 #include <set>
29 
30 using namespace fawkes;
31 using namespace firevision;
32 
33 /** @class FvRetrieverPlugin "fvretriever_plugin.h"
34  * FireVision Retriever Plugin.
35  * This is the FireVision retriever plugin. It is a simple plugin that will
36  * fetch images from a specific camera defined as a configuration setting.
37  *
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor.
42  * @param config Fawkes configuration
43  */
45  : Plugin(config)
46 {
47 
48  std::set<std::string> configs;
49  std::set<std::string> ignored_configs;
50 
51  std::string prefix = "/firevision/retriever/camera/";
52 
53  Configuration::ValueIterator *vi = config->search(prefix.c_str());
54  while (vi->next()) {
55 
56  std::string cfg_name = std::string(vi->path()).substr(prefix.length());
57  cfg_name = cfg_name.substr(0, cfg_name.find("/"));
58 
59  if ( (configs.find(cfg_name) == configs.end()) &&
60  (ignored_configs.find(cfg_name) == ignored_configs.end()) )
61  {
62  std::string cfg_prefix = prefix + cfg_name + "/";
63 
64  bool active = true;
65  try {
66  active = config->get_bool((cfg_prefix + "active").c_str());
67  } catch (Exception &e) {} // ignored, assume enabled
68  std::string cam_string = config->get_string((cfg_prefix + "string").c_str());
69 
70  if (active) {
72  cfg_name, cfg_prefix));
73  configs.insert(cfg_name);
74  } else {
75  //printf("Ignoring retriever config %s\n", cfg_name.c_str());
76  ignored_configs.insert(cfg_name);
77  }
78  }
79  }
80 
81  delete vi;
82 
83  if ( thread_list.empty() ) {
84  throw Exception("No cameras have been set for fvretriever");
85  }
86 
87 }
88 
89 PLUGIN_DESCRIPTION("Reads images from cameras and stores them in shared memory")
90 EXPORT_PLUGIN(FvRetrieverPlugin)
FvRetrieverPlugin(fawkes::Configuration *config)
Constructor.
Plugin interface class.
Definition: plugin.h:33
FireVision retriever thread.
Fawkes library namespace.
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 bool next()=0
Check if there is another element and advance to this if possible.
Base class for exceptions in Fawkes.
Definition: exception.h:36
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
virtual const char * path() const =0
Path of value.
void push_back(Thread *thread)
Add thread to the end.
Iterator interface to iterate over config values.
Definition: config.h:72
Interface for configuration handling.
Definition: config.h:67
FireVision Retriever Plugin.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.