Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * fvretriever_plugin.cpp - FireVision Retriever Plugin 00004 * 00005 * Created: Tue Jun 26 17:35:33 2007 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #include "fvretriever_plugin.h" 00024 #include "retriever_thread.h" 00025 00026 #include <core/exceptions/software.h> 00027 00028 #include <set> 00029 00030 using namespace fawkes; 00031 using namespace firevision; 00032 00033 /** @class FvRetrieverPlugin "fvretriever_plugin.h" 00034 * FireVision Retriever Plugin. 00035 * This is the FireVision retriever plugin. It is a simple plugin that will 00036 * fetch images from a specific camera defined as a configuration setting. 00037 * 00038 * @author Tim Niemueller 00039 */ 00040 00041 /** Constructor. 00042 * @param config Fawkes configuration 00043 */ 00044 FvRetrieverPlugin::FvRetrieverPlugin(Configuration *config) 00045 : Plugin(config) 00046 { 00047 00048 std::set<std::string> configs; 00049 std::set<std::string> ignored_configs; 00050 00051 std::string prefix = "/firevision/retriever/camera/"; 00052 00053 Configuration::ValueIterator *vi = config->search(prefix.c_str()); 00054 while (vi->next()) { 00055 00056 std::string cfg_name = std::string(vi->path()).substr(prefix.length()); 00057 cfg_name = cfg_name.substr(0, cfg_name.find("/")); 00058 00059 if ( (configs.find(cfg_name) == configs.end()) && 00060 (ignored_configs.find(cfg_name) == ignored_configs.end()) ) 00061 { 00062 00063 std::string cfg_prefix = prefix + cfg_name + "/"; 00064 00065 if ( ! vi->is_string() ) { 00066 throw TypeMismatchException("Only values of type string are valid for camera" 00067 " argument strings, but got %s for %s", 00068 vi->type(), vi->path()); 00069 } 00070 00071 bool active = true; 00072 try { 00073 active = config->get_bool((cfg_prefix + "active").c_str()); 00074 } catch (Exception &e) {} // ignored, assume enabled 00075 00076 if (active) { 00077 thread_list.push_back(new FvRetrieverThread(vi->get_string().c_str(), 00078 cfg_name, cfg_prefix)); 00079 configs.insert(cfg_name); 00080 } else { 00081 //printf("Ignoring laser config %s\n", cfg_name.c_str()); 00082 ignored_configs.insert(cfg_name); 00083 } 00084 } 00085 } 00086 00087 delete vi; 00088 00089 if ( thread_list.empty() ) { 00090 throw Exception("No cameras have been set for fvretriever"); 00091 } 00092 00093 } 00094 00095 PLUGIN_DESCRIPTION("Reads images from cameras and stores them in shared memory") 00096 EXPORT_PLUGIN(FvRetrieverPlugin)