source: flair-src/trunk/lib/FlairMeta/src/UavFactory.cpp@ 140

Last change on this file since 140 was 122, checked in by Sanahuja Guillaume, 8 years ago

modifs uav vrpn i686

File size: 2.6 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[7]5// created: 2016/02/05
6// filename: UavFactory.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: construct a Uav based on the type name
14//
15//
16/*********************************************************************/
17
18#include "UavFactory.h"
19#include "FrameworkManager.h"
20#include "SimuX4.h"
21#include "SimuX8.h"
22#include "HdsX8.h"
23#include "XAir.h"
[45]24#include "compile_info.h"
[7]25
26using namespace std;
27using namespace flair::core;
28using namespace flair::filter;
29using namespace flair::meta;
30
[41]31namespace { // anonymous
[122]32 vector<flair::meta::Uav* (*)(string,string,UavMultiplex*)> *vectoroffunctions=NULL;
[41]33}
34
[45]35
36static void constructor() __attribute__((constructor));
37
38void constructor() {
39 compile_info("FlairMeta");
40}
41
42
[122]43Uav *CreateUav(string name, string uav_type,
[15]44 UavMultiplex *multiplex) {
[41]45
46 Uav *uav;
[45]47
48 if(vectoroffunctions!=NULL) {
49 for(int i=0;i<vectoroffunctions->size();i++) {
[122]50 uav=vectoroffunctions->at(i)(name,uav_type,multiplex);
[45]51 if(uav!=NULL) {
52 free(vectoroffunctions);
53 vectoroffunctions=NULL;
54 return uav;
55 }
56 }
[41]57 }
58
59 if (uav_type == "hds_x4") {
[122]60 getFrameworkManager()->Err("UAV type %s not yet implemented\n", uav_type.c_str());
[15]61 return NULL;
62 } else if (uav_type == "hds_x8") {
[122]63 return new HdsX8(name, multiplex);
[15]64 } else if (uav_type == "xair") {
[122]65 return new XAir(name, multiplex);
[15]66 } else if (uav_type == "hds_xufo") {
[122]67 getFrameworkManager()->Err("UAV type %s not yet implemented\n", uav_type.c_str());
[15]68 return NULL;
69 } else if (uav_type.compare(0, 7, "x4_simu") == 0) {
70 int simu_id = 0;
71 if (uav_type.size() > 7) {
72 simu_id = atoi(uav_type.substr(7, uav_type.size() - 7).c_str());
[7]73 }
[122]74 return new SimuX4(name, simu_id, multiplex);
[15]75 } else if (uav_type.compare(0, 7, "x8_simu") == 0) {
76 int simu_id = 0;
77 if (uav_type.size() > 7) {
78 simu_id = atoi(uav_type.substr(7, uav_type.size() - 7).c_str());
79 }
[122]80 return new SimuX8(name, simu_id, multiplex);
[15]81 } else {
[122]82 getFrameworkManager()->Err("UAV type %s unknown\n", uav_type.c_str());
[15]83 return NULL;
84 }
[7]85}
[41]86
[122]87void RegisterUavCreator(flair::meta::Uav*(*func)(string name, string type,
[41]88 UavMultiplex *multiplex)) {
[122]89 if(vectoroffunctions==NULL) vectoroffunctions=(vector<flair::meta::Uav* (*)(string,string,UavMultiplex*)>*)malloc(sizeof(vector<flair::meta::Uav* (*)(string,string,UavMultiplex*)>));
[41]90
[45]91 vectoroffunctions->push_back(func);
[41]92}
Note: See TracBrowser for help on using the repository browser.