Fawkes API  Fawkes Development Version
mapper_factory.cpp
1 
2 /***************************************************************************
3  * mapper_factory.cpp - Factory for Player proxy to Fawkes interface mappers
4  *
5  * Created: Tue Sep 30 00:41:08 2008
6  * Copyright 2006-2008 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 "mapper_factory.h"
24 #include "position_mapper.h"
25 #include "motor_mapper.h"
26 #include "laser_mapper.h"
27 
28 #include <interfaces/ObjectPositionInterface.h>
29 #include <interfaces/MotorInterface.h>
30 #include <interfaces/Laser360Interface.h>
31 #include <libplayerc++/playerc++.h>
32 
33 using namespace PlayerCc;
34 using namespace fawkes;
35 
36 /** @class PlayerMapperFactory "mapper_factory.h"
37  * Player Fawkes mapper factory.
38  * Factory class to create mappers from Fawkes interfaces to Player proxies.
39  * @author Tim Niemueller
40  */
41 
42 /** Create a mapp instance.
43  * Tries to figure out the type of the interface and proxy and if a known matching
44  * exists will return an appropriate mapper.
45  * @param varname variable name
46  * @param interface Fawkes interface instance
47  * @param proxy Player proxy instance
48  * @return a mapper instance for the given interface and proxy otherwise
49  * @exception Exception thrown if no known mapping exists for the given
50  * interfaces.
51  */
54  fawkes::Interface *interface,
55  PlayerCc::ClientProxy *proxy)
56 {
58 
59  if ( (rv = try_create<ObjectPositionInterface, Position2dProxy, PlayerPositionMapper>(varname, interface, proxy)) != NULL ) {
60  return rv;
61  } else if ( (rv = try_create<MotorInterface, Position2dProxy, PlayerMotorPositionMapper>(varname, interface, proxy)) != NULL ) {
62  return rv;
63  } else if ( (rv = try_create<Laser360Interface, LaserProxy, PlayerLaserMapper>(varname, interface, proxy)) != NULL ) {
64  return rv;
65  } else {
66  throw Exception("Unknown mapping, don't know how to map Fawkes interface %s "
67  "to Player proxy %s",
68  interface->type(), proxy->GetInterfaceStr().c_str());
69  }
70 }
Fawkes library namespace.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Player proxy to Fawkes interface mapper interface.
Definition: mapper.h:28
const char * type() const
Get type of interface.
Definition: interface.cpp:651
Base class for exceptions in Fawkes.
Definition: exception.h:36
static PlayerProxyFawkesInterfaceMapper * create_mapper(std::string varname, fawkes::Interface *interface, PlayerCc::ClientProxy *proxy)
Create a mapp instance.