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 
63  std::string cfg_prefix = prefix + cfg_name + "/";
64 
65  if ( ! vi->is_string() ) {
66  throw TypeMismatchException("Only values of type string are valid for camera"
67  " argument strings, but got %s for %s",
68  vi->type(), vi->path());
69  }
70 
71  bool active = true;
72  try {
73  active = config->get_bool((cfg_prefix + "active").c_str());
74  } catch (Exception &e) {} // ignored, assume enabled
75 
76  if (active) {
78  cfg_name, cfg_prefix));
79  configs.insert(cfg_name);
80  } else {
81  //printf("Ignoring laser config %s\n", cfg_name.c_str());
82  ignored_configs.insert(cfg_name);
83  }
84  }
85  }
86 
87  delete vi;
88 
89  if ( thread_list.empty() ) {
90  throw Exception("No cameras have been set for fvretriever");
91  }
92 
93 }
94 
95 PLUGIN_DESCRIPTION("Reads images from cameras and stores them in shared memory")
96 EXPORT_PLUGIN(FvRetrieverPlugin)
FvRetrieverPlugin(fawkes::Configuration *config)
Constructor.
Plugin interface class.
Definition: plugin.h:33
FireVision retriever thread.
virtual const char * type() const =0
Type of value.
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.
virtual bool is_string() const =0
Check if current value is a string.
Base class for exceptions in Fawkes.
Definition: exception.h:36
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
virtual std::string get_string() const =0
Get string value.
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:68
Interface for configuration handling.
Definition: config.h:63
FireVision Retriever Plugin.