Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/src/recognition/actors/actor_manager.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 /* 00035 * actor_manager.cpp 00036 * 00037 * Created on: Nov 3, 2010 00038 * Author: Brett Ponsler (bponsler (at) wpi (dot) edu) 00039 */ 00040 #include "actor_manager.h" 00041 00042 ActorManager *ActorManager::instance_ = NULL; 00043 00044 ActorManager::ActorManager() 00045 { 00046 this->actors_ = std::map<std::string, Actor*>(); 00047 } 00048 00049 void ActorManager::destroy() { 00050 if (ActorManager::instance_ != NULL) { 00051 // Clear the actors, and destroy each one 00052 ActorManager::instance_->actors_.clear(); 00053 00054 delete ActorManager::instance_; 00055 ActorManager::instance_ = NULL; 00056 } 00057 } 00058 00059 ActorManager *ActorManager::getInstance() 00060 { 00061 if (ActorManager::instance_ == NULL) 00062 ActorManager::instance_ = new ActorManager(); 00063 00064 return ActorManager::instance_; 00065 } 00066 00067 Actor *ActorManager::createActor(std::string actor) 00068 { 00069 // Ensure the actor exists 00070 if (actor != "") { 00071 ActorManager *inst = ActorManager::getInstance(); 00072 00073 // Create the new actor, then add it to the map 00074 Actor *act = new Actor(actor); 00075 inst->actors_.insert(std::pair<std::string, Actor*>(actor, act)); 00076 00077 return act; 00078 } 00079 00080 return NULL; 00081 } 00082 00083 void ActorManager::removeActor(std::string actor) 00084 { 00085 ActorManager *inst = ActorManager::getInstance(); 00086 inst->actors_.erase(actor); 00087 } 00088 00089 Actor *ActorManager::findActor(std::string actor) 00090 { 00091 ActorManager *inst = ActorManager::getInstance(); 00092 std::map<std::string, Actor*>::iterator iter = inst->actors_.find(actor); 00093 00094 return (iter != inst->actors_.end() ? iter->second : NULL); 00095 } 00096 00097 bool ActorManager::isAlive(std::string actor) 00098 { 00099 return (ActorManager::findActor(actor) != NULL); 00100 } 00101 00102 void ActorManager::relayToActors(std::string topic, ros::Message *message) 00103 { 00104 ActorManager *inst = ActorManager::getInstance(); 00105 00106 // Create iterators for the actors 00107 std::map<std::string, Actor*>::iterator iter; 00108 00109 // Relay the message and topic to all the actors 00110 for(iter = inst->actors_.begin(); iter != inst->actors_.end(); iter++) 00111 { 00112 // Make sure the actor exists before relaying the message to it 00113 if (iter->second != NULL) 00114 iter->second->received(topic, message); 00115 } 00116 } |