memory_list.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 /*
19 * LOCAL includes
20 */
21 #include "memory_list.hpp"
22 
23 /*
24 * BOOST includes
25 */
26 #include <boost/foreach.hpp>
27 #define for_each BOOST_FOREACH
28 
29 namespace naoqi {
30 
31 namespace converter {
32 
33 MemoryListConverter::MemoryListConverter(const std::vector<std::string>& key_list, const std::string &name, const float &frequency, const qi::SessionPtr &session):
34  BaseConverter(name, frequency, session),
35  p_memory_(session->service("ALMemory")),
36  _key_list(key_list)
37 {}
38 
40 
41 }
42 
43 void MemoryListConverter::callAll(const std::vector<message_actions::MessageAction> &actions){
44  // Get inertial data
45  qi::AnyValue memData_anyvalue = p_memory_.call<qi::AnyValue>("getListData", _key_list);
46 
47  // Reset message
48  _msg = naoqi_bridge_msgs::MemoryList();
49  ros::Time now = ros::Time::now();
50  _msg.header.stamp = now;
51 
52  qi::AnyReferenceVector memData_anyref = memData_anyvalue.asListValuePtr();
53 
54  for(int i=0; i<memData_anyref.size();i++)
55  {
56  if(memData_anyref[i].content().kind() == qi::TypeKind_Int)
57  {
58  naoqi_bridge_msgs::MemoryPairInt tmp_msg;
59  tmp_msg.memoryKey = _key_list[i];
60  tmp_msg.data = memData_anyref[i].content().asInt32();
61  _msg.ints.push_back(tmp_msg);
62  }
63  else if(memData_anyref[i].content().kind() == qi::TypeKind_Float)
64  {
65  naoqi_bridge_msgs::MemoryPairFloat tmp_msg;
66  tmp_msg.memoryKey = _key_list[i];
67  tmp_msg.data = memData_anyref[i].content().asFloat();
68  _msg.floats.push_back(tmp_msg);
69  }
70  else if(memData_anyref[i].content().kind() == qi::TypeKind_String)
71  {
72  naoqi_bridge_msgs::MemoryPairString tmp_msg;
73  tmp_msg.memoryKey = _key_list[i];
74  tmp_msg.data = memData_anyref[i].content().asString();
75  _msg.strings.push_back(tmp_msg);
76  }
77  }
78 
80  {
81  callbacks_[action]( _msg);
82  }
83 }
84 
86 {
87  callbacks_[action] = cb;
88 }
89 
90 }
91 
92 }
void registerCallback(const message_actions::MessageAction action, Callback_t cb)
Definition: memory_list.cpp:85
boost::function< void(naoqi_bridge_msgs::MemoryList &) > Callback_t
Definition: memory_list.hpp:38
std::map< message_actions::MessageAction, Callback_t > callbacks_
Definition: memory_list.hpp:56
virtual void callAll(const std::vector< message_actions::MessageAction > &actions)
Definition: memory_list.cpp:43
std::vector< std::string > _key_list
Definition: memory_list.hpp:50
MemoryListConverter(const std::vector< std::string > &key_list, const std::string &name, const float &frequency, const qi::SessionPtr &session)
Definition: memory_list.cpp:33
naoqi_bridge_msgs::MemoryList _msg
Definition: memory_list.hpp:51
action
#define for_each
Definition: memory_list.cpp:27
static Time now()


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26