/home/fwph/code/wurde/modules/visionModule/operators.cpp

Go to the documentation of this file.
00001 #include <visionModule.H>
00002 #include <vector>
00003 #include <set>
00004 #include <Logger.H>
00005 
00006 using namespace std;
00007 using namespace WURDEVision;
00008 using namespace WURDE;
00009 
00010 extern "C" {
00011         std::map<std::string, voperatorloader_ptr *, less<string> > operatorFactory;
00012 }
00013 
00014 namespace WURDEVision{
00015       
00016        void loadOperatorMap(vector<string> operatorLibs){
00017               void *handle;
00018 
00019               for(vector<string>::iterator iter=operatorLibs.begin();
00020                   iter!=operatorLibs.end(); iter++){
00021                      handle=dlopen(iter->c_str(),RTLD_NOW);
00022                      if(!handle){
00023                             g_error(dlerror());
00024                             continue;
00025                      }               
00026               }
00027 
00028               cout << operatorFactory.size() << " objects loaded.\n";
00029        }
00030 
00031        void loadOperators(VisionModuleConfig &theConfig, std::list<VisionOperator *> & theOperators, bool fakeit){
00032               VisionOperator *curr=NULL;          
00033               char logbuf[1024];
00034               g_debug("IN load operators");
00035 
00036               if(fakeit){
00037                      g_logdebug << "In loadOperators, we're faking it." << endl;
00038               }
00039 
00040               for(std::vector<OperatorConfig>::iterator iter=theConfig.operators.begin();
00041                   iter!=theConfig.operators.end(); iter++){
00042                      g_debug("Loading first operator");
00043                      curr=NULL;
00044                      bool okay=false;
00045                      
00046                      if(operatorFactory.find((*iter).type)!=operatorFactory.end()){
00047                             curr=operatorFactory[(*iter).type]((*iter).name);
00048                             sprintf(logbuf,"Created an operator type %s",(*iter).type.c_str());
00049                             g_debug(logbuf);
00050                      }else{
00051                             sprintf(logbuf,"Couldn't find operator plugin %s",(*iter).type.c_str());
00052                             g_warn(logbuf);
00053                             continue;
00054                      }
00055 
00056                      if(curr){
00057                             if(!fakeit){
00058                                    std::vector<CameraConfig>::iterator camiter;
00059                                    std::vector<CameraConfig>::iterator camiter2;
00060                                    g_logdebug << "Looking for cameras..." <<endl;
00061                                    for(camiter=iter->cameras.begin();camiter!=iter->cameras.end();
00062                                        camiter++){
00063                                            g_logdebug << "Looking for a camera. " <<endl;
00064                                           bool found=false;
00065                                           g_debug("Looking for a camera");
00066                                           for(camiter2=theConfig.cameras.begin();camiter2!=theConfig.cameras.end();
00067                                               camiter2++){
00068                                                  if((*camiter).name==(*camiter2).name){
00069                                                         found=true;
00070                                                         g_debug("Got the camera");
00071                                                         break;
00072                                                  }
00073                                           }
00074                                           
00075                                           if(!found){
00076                                                  okay=false;
00077                                                  g_error("Couldn't find a requested camera for one of the operators.");
00078                                                  break;
00079                                           }else{
00080                                                  curr->setCameras(iter->cameras);
00081                                                  g_debug("Operator is okay.");
00082                                                  okay=true;
00083                                                  
00084                                           }
00085                                    }
00086                                    
00087                                    if(!okay){
00088                                           g_debug("Operator not okay.");
00089                                           delete curr;
00090                                           continue;
00091                                    }
00092                                    
00093                                    curr->initOperator();
00094                                    curr->setName((*iter).name);
00095                             }
00096                             theOperators.push_back(curr);
00097                      }else{
00098                             g_debug("No operator object.");
00099                      }
00100               }
00101        }       
00102 }
00103 

Generated on Thu Feb 1 15:31:52 2007 for WURDE by  doxygen 1.5.1