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