Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/states/state.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 // @author Brett Ponsler (bponsler (at) wpi (dot) edu) 00035 #include "state.h" 00036 #include "../lib/engagement_params.h" 00037 #include "../actors/actor_manager.h" 00038 00039 State::State() : 00040 EventSink() 00041 { 00042 // No name or actor given 00043 this->name_ = ""; 00044 this->actor_ = ""; 00045 } 00046 00047 State::State(std::string name, std::string actor, EventSink *sink) : 00048 EventSink(sink) 00049 { 00050 // Set the name and actor for this object 00051 this->name_ = name; 00052 this->actor_ = actor; 00053 } 00054 00055 State::~State() { 00056 // Intentionally left blank 00057 } 00058 00059 void State::castEvent(Event event) 00060 { 00061 // Cast the event with the parent event sink 00062 this->parent_->castEvent(event); 00063 } 00064 00065 bool State::compareAdditional(std::vector<std::string> additional, 00066 std::string compare) 00067 { 00068 // Make sure we have a valid parent 00069 if (this->parent_ == NULL) 00070 return false; 00071 00072 // Compare the additional with the event sink 00073 return (this->parent_->compareAdditional(additional, compare)); 00074 } 00075 00076 Event State::received(std::string topic, ros::Message *message) 00077 { 00078 // Get the data type and MD5 sum of this message 00079 std::string data = message->__getDataType(); 00080 00081 this->debug(30, "Received topic: [%s]", topic.c_str()); 00082 this->debug(30, "Received message [%s]\n", data.c_str()); 00083 00084 // Create an empty event, which will help us determine 00085 // whether an event was created and needs to be handled 00086 Event event = Event(); 00087 00088 // Send the message to the state 00089 if (data == engagement_msgs::ActorID::__s_getDataType()) 00090 event = this->received(topic, (engagement_msgs::ActorID*)message); 00091 else if (data == engagement_msgs::ActorIDStatus::__s_getDataType()) 00092 event = this->received(topic, (engagement_msgs::ActorIDStatus*)message); 00093 else if (data == engagement_msgs::Empty::__s_getDataType()) 00094 event = this->received(topic, (engagement_msgs::Empty*)message); 00095 else if (data == bml_msgs::Entity::__s_getDataType()) 00096 event = this->received(topic, (bml_msgs::Entity*)message); 00097 else if (data == bml_msgs::Flag::__s_getDataType()) 00098 event = this->received(topic, (bml_msgs::Flag*)message); 00099 else if (data == engagement_msgs::HumanAdjacencyPair::__s_getDataType()) 00100 event = this->received(topic, (engagement_msgs::HumanAdjacencyPair*)message); 00101 else if (data == engagement_msgs::HumanBackchannel::__s_getDataType()) 00102 event = this->received(topic, (engagement_msgs::HumanBackchannel*)message); 00103 else if (data == engagement_msgs::HumanDirectedGaze::__s_getDataType()) 00104 event = this->received(topic, (engagement_msgs::HumanDirectedGaze*)message); 00105 else if (data == engagement_msgs::HumanMutualFacialGaze::__s_getDataType()) 00106 event = this->received(topic, (engagement_msgs::HumanMutualFacialGaze*)message); 00107 else if (data == engagement_msgs::Performance::__s_getDataType()) 00108 event = this->received(topic, (engagement_msgs::Performance*)message); 00109 else if (data == engagement_srvs::ActorStatistics::Request::__s_getDataType()) 00110 event = this->received(topic, (engagement_srvs::ActorStatistics::Request*)message); 00111 else if (data == engagement_srvs::RobotAdjacencyPair::Request::__s_getDataType()) 00112 event = this->received(topic, (engagement_srvs::RobotAdjacencyPair::Request*)message); 00113 else if (data == engagement_srvs::RobotDirectedGaze::Request::__s_getDataType()) 00114 event = this->received(topic, (engagement_srvs::RobotDirectedGaze::Request*)message); 00115 else if (data == engagement_srvs::RobotMutualFacialGaze::Request::__s_getDataType()) 00116 event = this->received(topic, (engagement_srvs::RobotMutualFacialGaze::Request*)message); 00117 else if (data == engagement_msgs::Speech::__s_getDataType()) 00118 event = this->received(topic, (engagement_msgs::Speech*)message); 00119 else 00120 this->error("Received unknown message type: [%s]", data.c_str()); 00121 00122 return event; 00123 } 00124 00125 Event State::received(std::string topic, engagement_msgs::ActorID *message) 00126 { 00127 // Return a blank event if this has not been overridden 00128 return Event(); 00129 } 00130 00131 Event State::received(std::string topic, engagement_msgs::ActorIDStatus *message) 00132 { 00133 // Return a blank event if this has not been overridden 00134 return Event(); 00135 } 00136 00137 Event State::received(std::string topic, engagement_msgs::Empty *message) 00138 { 00139 // Return a blank event if this has not been overridden 00140 return Event(); 00141 } 00142 00143 Event State::received(std::string topic, bml_msgs::Entity *message) 00144 { 00145 // Return a blank event if this has not been overridden 00146 return Event(); 00147 } 00148 00149 Event State::received(std::string topic, bml_msgs::Flag *message) 00150 { 00151 // Return a blank event if this has not been overridden 00152 return Event(); 00153 } 00154 00155 Event State::received(std::string topic, 00156 engagement_msgs::HumanAdjacencyPair *message) 00157 { 00158 // Return a blank event if this has not been overridden 00159 return Event(); 00160 } 00161 00162 Event State::received(std::string topic, 00163 engagement_msgs::HumanBackchannel *message) 00164 { 00165 // Return a blank event if this has not been overridden 00166 return Event(); 00167 } 00168 00169 Event State::received(std::string topic, 00170 engagement_msgs::HumanDirectedGaze *message) 00171 { 00172 // Return a blank event if this has not been overridden 00173 return Event(); 00174 } 00175 00176 Event State::received(std::string topic, 00177 engagement_msgs::HumanMutualFacialGaze *message) 00178 { 00179 // Return a blank event if this has not been overridden 00180 return Event(); 00181 } 00182 00183 Event State::received(std::string topic, engagement_msgs::Performance *message) 00184 { 00185 // Return a blank event if this has not been overridden 00186 return Event(); 00187 } 00188 00189 Event State::received(std::string topic, 00190 engagement_srvs::ActorStatistics::Request *message) 00191 { 00192 // Return a blank event if this has not been overridden 00193 return Event(); 00194 } 00195 00196 Event State::received(std::string topic, 00197 engagement_srvs::RobotAdjacencyPair::Request *message) 00198 { 00199 // Return a blank event if this has not been overridden 00200 return Event(); 00201 } 00202 00203 Event State::received(std::string topic, 00204 engagement_srvs::RobotDirectedGaze::Request *message) 00205 { 00206 // Return a blank event if this has not been overridden 00207 return Event(); 00208 } 00209 00210 Event State::received(std::string topic, 00211 engagement_srvs::RobotMutualFacialGaze::Request *message) 00212 { 00213 // Return a blank event if this has not been overridden 00214 return Event(); 00215 } 00216 00217 Event State::received(std::string topic, engagement_msgs::Speech *message) 00218 { 00219 // Return a blank event if this has not been overridden 00220 return Event(); 00221 } 00222 00223 Actor *State::getActor() 00224 { 00225 return ActorManager::findActor(this->actor_); 00226 } 00227 00228 const char *State::getName() 00229 { 00230 return this->name_.c_str(); 00231 } |