Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * mapper_factory.cpp - Factory for Player proxy to Fawkes interface mappers 00004 * 00005 * Created: Tue Sep 30 00:41:08 2008 00006 * Copyright 2006-2008 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 "mapper_factory.h" 00024 #include "position_mapper.h" 00025 #include "motor_mapper.h" 00026 #include "laser_mapper.h" 00027 00028 #include <interfaces/ObjectPositionInterface.h> 00029 #include <interfaces/MotorInterface.h> 00030 #include <interfaces/Laser360Interface.h> 00031 #include <libplayerc++/playerc++.h> 00032 00033 using namespace PlayerCc; 00034 using namespace fawkes; 00035 00036 /** @class PlayerMapperFactory "mapper_factory.h" 00037 * Player Fawkes mapper factory. 00038 * Factory class to create mappers from Fawkes interfaces to Player proxies. 00039 * @author Tim Niemueller 00040 */ 00041 00042 /** Create a mapp instance. 00043 * Tries to figure out the type of the interface and proxy and if a known matching 00044 * exists will return an appropriate mapper. 00045 * @param varname variable name 00046 * @param interface Fawkes interface instance 00047 * @param proxy Player proxy instance 00048 * @return a mapper instance for the given interface and proxy otherwise 00049 * @exception Exception thrown if no known mapping exists for the given 00050 * interfaces. 00051 */ 00052 PlayerProxyFawkesInterfaceMapper * 00053 PlayerMapperFactory::create_mapper(std::string varname, 00054 fawkes::Interface *interface, 00055 PlayerCc::ClientProxy *proxy) 00056 { 00057 PlayerProxyFawkesInterfaceMapper *rv = NULL; 00058 00059 if ( (rv = try_create<ObjectPositionInterface, Position2dProxy, PlayerPositionMapper>(varname, interface, proxy)) != NULL ) { 00060 return rv; 00061 } else if ( (rv = try_create<MotorInterface, Position2dProxy, PlayerMotorPositionMapper>(varname, interface, proxy)) != NULL ) { 00062 return rv; 00063 } else if ( (rv = try_create<Laser360Interface, LaserProxy, PlayerLaserMapper>(varname, interface, proxy)) != NULL ) { 00064 return rv; 00065 } else { 00066 throw Exception("Unknown mapping, don't know how to map Fawkes interface %s " 00067 "to Player proxy %s", 00068 interface->type(), proxy->GetInterfaceStr().c_str()); 00069 } 00070 }