00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2009: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 Mobots group, Laboratory of Robotics Systems, EPFL, Lausanne 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 any other version as decided by the two original authors 00013 Stephane Magnenat and Valentin Longchamp. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #ifndef ASEBA_DESCRIPTIONS_MANAGER_H 00025 #define ASEBA_DESCRIPTIONS_MANAGER_H 00026 00027 #include "msg.h" 00028 #include <string> 00029 00030 namespace Aseba 00031 { 00034 00037 class DescriptionsManager 00038 { 00039 protected: 00041 struct NodeDescription: public TargetDescription 00042 { 00043 NodeDescription(); 00044 NodeDescription(const TargetDescription& targetDescription); 00045 00046 unsigned namedVariablesReceptionCounter; 00047 unsigned localEventsReceptionCounter; 00048 unsigned nativeFunctionReceptionCounter; 00049 }; 00051 typedef std::map<unsigned, NodeDescription> NodesDescriptionsMap; 00052 NodesDescriptionsMap nodesDescriptions; 00053 00054 public: 00056 virtual ~DescriptionsManager() {} 00057 00059 void processMessage(const Message* message); 00060 00062 std::string getNodeName(unsigned nodeId) const; 00064 unsigned getNodeId(const std::string& name, bool *ok = 0) const; 00066 const TargetDescription * const getDescription(unsigned nodeId, bool *ok = 0) const; 00068 unsigned getVariablePos(unsigned nodeId, const std::string& name, bool *ok = 0) const; 00070 unsigned getVariableSize(unsigned nodeId, const std::string& name, bool *ok = 0) const; 00071 // TODO: reverse lookup? 00072 // TODO: move bytecode sender manager here, rename class? 00073 00074 protected: 00076 void checkIfNodeDescriptionComplete(unsigned id, const NodeDescription& description); 00077 00079 virtual void nodeProtocolVersionMismatch(const std::string &nodeName, uint16 protocolVersion) { } 00080 00082 virtual void nodeDescriptionReceived(unsigned nodeId) { } 00083 }; 00084 00086 } 00087 00088 #endif