From tk at edam.speech.cs.cmu.edu Thu Dec 7 14:45:00 2006
From: tk at edam.speech.cs.cmu.edu (tk@edam.speech.cs.cmu.edu)
Date: Thu, 7 Dec 2006 14:45:00 -0500
Subject: [TeamTalk 9]: [546] TeamTalk/Agents: backendstub:
Message-ID: <200612071945.kB7Jj0ke011908@edam.speech.cs.cmu.edu>
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20061207/e32a4c47/attachment-0001.html
-------------- next part --------------
Modified: TeamTalk/Agents/Agents.sln
===================================================================
--- TeamTalk/Agents/Agents.sln 2006-11-09 20:10:38 UTC (rev 545)
+++ TeamTalk/Agents/Agents.sln 2006-12-07 19:44:59 UTC (rev 546)
@@ -35,6 +35,41 @@
EndProjectSection
EndProject
Global
+ GlobalSection(SourceCodeControl) = preSolution
+ SccNumberOfProjects = 8
+ SccProjectUniqueName0 = MultiDecoder\\Audio_Server\\Audio_Server.vcproj
+ SccProjectName0 = \u0022$/CommonAgents-2005/MultiDecoder/Audio_Server\u0022,\u0020ONACAAAA
+ SccLocalPath0 = MultiDecoder\\Audio_Server
+ SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName1 = Helios3\\Helios3.vcproj
+ SccProjectName1 = \u0022$/CommonAgents-2005/Helios3\u0022,\u0020ZJACAAAA
+ SccLocalPath1 = Helios3
+ SccProvider1 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName2 = Kalliope\\Kalliope.vcproj
+ SccProjectName2 = \u0022$/CommonAgents-2005/Kalliope\u0022,\u0020MLACAAAA
+ SccLocalPath2 = Kalliope
+ SccProvider2 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName3 = NlgServer2\\NlgServer2.vcproj
+ SccProjectName3 = \u0022$/CommonAgents-2005/NlgServer2\u0022,\u0020JOACAAAA
+ SccLocalPath3 = NlgServer2
+ SccProvider3 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName4 = Phoenix2\\phoenix2.vcproj
+ SccProjectName4 = \u0022$/CommonAgents-2005/Phoenix2\u0022,\u0020APACAAAA
+ SccLocalPath4 = Phoenix2
+ SccProvider4 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName5 = ProcessMonitor\\ProcessMonitor.vcproj
+ SccProjectName5 = \u0022$/CommonAgents-2005/ProcessMonitor\u0022,\u0020VPACAAAA
+ SccLocalPath5 = ProcessMonitor
+ SccProvider5 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName6 = RavenClaw\\RavenClaw.vcproj
+ SccProjectName6 = \u0022$/CommonAgents-2005/RavenClaw\u0022,\u0020PRACAAAA
+ SccLocalPath6 = RavenClaw
+ SccProvider6 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ SccProjectUniqueName7 = MultiDecoder\\Sphinx_Engine\\Sphinx_Engine.vcproj
+ SccProjectName7 = \u0022$/CommonAgents-2005/MultiDecoder/Sphinx_Engine\u0022,\u0020BOACAAAA
+ SccLocalPath7 = MultiDecoder\\Sphinx_Engine
+ SccProvider7 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
@@ -42,8 +77,8 @@
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C31484B0-179B-432D-AE1E-75FB90591F23}.Debug|Win32.ActiveCfg = Debug|Win32
{C31484B0-179B-432D-AE1E-75FB90591F23}.Debug|Win32.Build.0 = Debug|Win32
- {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.ActiveCfg = Release|Win32
- {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.Build.0 = Release|Win32
+ {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.ActiveCfg = Debug|Win32
+ {C31484B0-179B-432D-AE1E-75FB90591F23}.Release|Win32.Build.0 = Debug|Win32
{93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Debug|Win32.ActiveCfg = Debug|Win32
{93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Debug|Win32.Build.0 = Debug|Win32
{93C8F5F8-6C43-4179-9B9F-A31AA6438513}.Release|Win32.ActiveCfg = Release|Win32
Modified: TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj
===================================================================
--- TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-11-09 20:10:38 UTC (rev 545)
+++ TeamTalk/Agents/PrimitiveComm/PrimitiveComm.vcproj 2006-12-07 19:44:59 UTC (rev 546)
@@ -184,15 +184,11 @@
>
-
-
+
+
+
+
@@ -262,11 +266,11 @@
>
+
+
-#include
-
-#include "geometry.h"
-#include "utils.h"
-
-using namespace geometry;
-
-Vector::Vector() {};
-Vector::Vector(double X, double Y) : x(X), y(Y) {};
-Vector Vector::rotate(double rads) {
- double r = sqrt(x*x + y*y);
- double theta = atan2(y, x);
- x = r*cos(theta+rads);
- y = r*sin(theta+rads);
- return *this;
-}
-
-double Vector::length() const {
- return sqrt(x*x+y*y);
-};
-
-double Vector::angle() const {
- return atan2(y, x);
-};
-
-ostream& operator<<(ostream& out, const Vector& p) {
- return out << '[' << p.x << ',' << p.y << ']';
-};
-
-istream& operator>>(istream& in, Vector& p) {
- //expecting "\s*(\s*f\s+f\s*)" or "\s*f\s+f";
-
- bool has_paren = false;
-
- while(!in.eof()) {
- char c = in.peek();
- if (isspace(c)) {
- in.ignore();
- } else if (c == '(') {
- in.ignore();
- has_paren = true;
- break;
- } else break;
- }
-
- in >> p.x >> p.y;
-
- if(has_paren) {
- while(!in.eof()) {
- char c = in.peek();
- if (isspace(c)) {
- in.ignore();
- } else if (c == ')') {
- in.ignore();
- break;
- } else break;
- }
- }
-
- return in;
-};
-
-istream& operator>>(istream& in, geometry::Polygon& l) {
- l.clear();
- geometry::Point p;
- while(in >> p) {
- l.push_back(p);
- }
- return in;
-};
-
-Quadrilateral::Quadrilateral(Vector lower_left, Vector upper_right) : Polygon(4) {
- // axis-aligned quadrilateral
- at(0) = Point(lower_left.x, lower_left.y);
- at(1) = Point(lower_left.x, upper_right.y);
- at(2) = Point(upper_right.x, upper_right.y);
- at(3) = Point(upper_right.x, lower_left.y);
-};
-
-Quadrilateral::Quadrilateral(double x1, double y1, double x2, double y2) : Polygon(4) {
- at(0) = Point(MIN(x1, x2), MIN(y1, y2));
- at(1) = Point(MIN(x1, x2), MAX(y1, y2));
- at(2) = Point(MAX(x1, x2), MAX(y1, y2));
- at(3) = Point(MAX(x1, x2), MIN(y1, y2));
-};
-
-Quadrilateral::Quadrilateral(Vector p1, Vector p2, Vector p3, Vector p4) : Polygon(4) {
- at(0) = Point(p1.x, p1.y);
- at(1) = Point(p2.x, p2.y);
- at(2) = Point(p3.x, p3.y);
- at(3) = Point(p4.x, p4.y);
-};
-
-Quadrilateral::operator geometry::Polygon() const {
- return *this;
-};
-
-Point Quadrilateral::ll() const {
- Point retval = at(0);
- for(int i=1; i<4; i++) {
- if(at(i).x < retval.x || at(i).y < retval.y) retval = at(i);
- }
- return retval;
-};
-
-Point Quadrilateral::ul() const {
- Point retval = at(0);
- for(int i=1; i<4; i++) {
- if(at(i).x > retval.x || at(i).y < retval.y) retval = at(i);
- }
- return retval;
-};
-
-Point Quadrilateral::ur() const {
- Point retval = at(0);
- for(int i=1; i<4; i++) {
- if(at(i).x > retval.x || at(i).y > retval.y) retval = at(i);
- }
- return retval;
-};
-
-Point Quadrilateral::lr() const {
- Point retval = at(0);
- for(int i=1; i<4; i++) {
- if(at(i).x < retval.x || at(i).y > retval.y) retval = at(i);
- }
- return retval;
-};
-
Modified: TeamTalk/Agents/PrimitiveComm/geometry.h
===================================================================
--- TeamTalk/Agents/PrimitiveComm/geometry.h 2006-11-09 20:10:38 UTC (rev 545)
+++ TeamTalk/Agents/PrimitiveComm/geometry.h 2006-12-07 19:44:59 UTC (rev 546)
@@ -3,45 +3,122 @@
#include
+#include "utils.h"
+
using namespace std;
namespace geometry {
-struct Vector {
- double x, y;
- Vector();
- Vector(double x, double y);
- Vector rotate(double rads);
- double length() const;
- double angle() const;
+template struct Point {
+ T x, y;
+ Point() : x(0), y(0) {};
+ Point(T X, T Y) : x(X), y(Y) {};
+ template static Point Polar(L length, double angle) {
+ return Point((T)(cos(angle)*length), (T)(sin(angle)*length));
+ }
+ Point rotate(double rads) {
+ double r = sqrt(x*x + y*y);
+ double theta = atan2(y, x);
+ x = (T) (r*cos(theta+rads));
+ y = (T) (r*sin(theta+rads));
+ return *this;
+ }
+ double length() const {return sqrt(x*x+y*y);};
+ double angle() const {return atan2(y, x);};
+ Point operator-(const Point& rhs) const {
+ return Point(x-rhs.x, y-rhs.y);
+ }
+ Point& operator-=(const Point& rhs) {
+ x -= rhs.x;
+ y -= rhs.y;
+ return *this;
+ }
+ Point operator+(const Point& rhs) const {
+ return Point(x+rhs.x, y+rhs.y);
+ }
+ Point operator+=(const Point& rhs) {
+ x += rhs.x;
+ y += rhs.y;
+ return *this;
+ }
};
-typedef Vector Point;
+template struct Polygon : public vector< Point > {
+ Polygon() : vector< Point >() {};
+ Polygon (int n) : vector< Point >(n) {};
+ Polygon(const Polygon& p) : vector< Point >(p) {};
+};
-struct Polygon : public vector {
- Polygon() : vector() {};
- Polygon(int n) : vector(n) {};
- Polygon(const Polygon& p) : vector(p) {};
+template struct Quadrilateral : public Polygon {
+ Quadrilateral() : Polygon(4) {};
+ Quadrilateral(const Quadrilateral& q) : Polygon(q) {};
+ Quadrilateral(Point lower_left, Point upper_right) : Polygon(4) {
+ // axis-aligned quadrilateral
+ at(0) = Point(lower_left.x, lower_left.y);
+ at(1) = Point(lower_left.x, upper_right.y);
+ at(2) = Point(upper_right.x, upper_right.y);
+ at(3) = Point(upper_right.x, lower_left.y);
+ };
+ Quadrilateral(T x1, T x2, T y1, T y2) : Polygon(4) {
+ at(0) = Point(MIN(x1, x2), MIN(y1, y2));
+ at(1) = Point(MIN(x1, x2), MAX(y1, y2));
+ at(2) = Point(MAX(x1, x2), MAX(y1, y2));
+ at(3) = Point(MAX(x1, x2), MIN(y1, y2));
+ };
+ Quadrilateral(Point p1, Point p2, Point p3, Point p4): Polygon(4) {
+ at(0) = p1; at(1) = p2; at(2) = p3; at(3) = p4;
+ };
+ operator Polygon() const {return *this;}
+ Point ll() const {
+ Point retval = at(0);
+ for(int i=1; i<4; i++) {
+ if(at(i).x < retval.x || at(i).y < retval.y) retval = at(i);
+ }
+ return retval;
+ };
+ Point ul() const {
+ Point retval = at(0);
+ for(int i=1; i<4; i++) {
+ if(at(i).x > retval.x || at(i).y < retval.y) retval = at(i);
+ }
+ return retval;
+ };
+ Point ur() const {
+ Point retval = at(0);
+ for(int i=1; i<4; i++) {
+ if(at(i).x > retval.x || at(i).y > retval.y) retval = at(i);
+ }
+ return retval;
+ };
+ Point lr() const {
+ Point retval = at(0);
+ for(int i=1; i<4; i++) {
+ if(at(i).x < retval.x || at(i).y > retval.y) retval = at(i);
+ }
+ return retval;
+ };
};
-struct Quadrilateral : public Polygon {
- Quadrilateral() : Polygon(4) {};
- Quadrilateral(const Quadrilateral& q) : Polygon(q) {};
- Quadrilateral(Point lower_left, Point upper_right); // axis-aligned
- Quadrilateral(double x1, double x2, double y1, double y2); //another axis-aligned
- Quadrilateral(Point p1, Point p2, Point p3, Point p4); //generic
-
- operator Polygon () const;
- Point ll() const;
- Point ul() const;
- Point ur() const;
- Point lr() const;
+template struct Pose {
+ Point loc;
+ T yaw;
+ Pose() : loc(), yaw(0) {}
+ Pose(const Point& _loc, T _yaw) : loc(_loc), yaw(_yaw) {}
+ Pose(T _x, T _y, T _yaw) : loc(_x, _y), yaw(_yaw) {}
};
+} //end namespace geometry
+
+template
+ostream& operator<<(ostream& out, const geometry::Point& p) {
+ return out << '(' << p.x << ' ' << p.y << ')';
}
+template
+istream& operator>>(istream& in, geometry::Point& p) {
+ if(istreamLookFor(in, '(').fail()) return in;
+ if((in >> p.x).fail()) return in;
+ if((in >> p.y).fail()) return in;
+ return istreamLookFor(in, ')');
+}
-ostream& operator<<(ostream& out, const geometry::Vector& p);
-istream& operator>>(istream& in, geometry::Vector& p);
-istream& operator>>(istream& in, geometry::Polygon& l);
-
#endif //GEOMETRY
Modified: TeamTalk/Agents/PrimitiveComm/robot_client.cpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-11-09 20:10:38 UTC (rev 545)
+++ TeamTalk/Agents/PrimitiveComm/robot_client.cpp 2006-12-07 19:44:59 UTC (rev 546)
@@ -6,6 +6,7 @@
#include "robot_client.hpp"
#include "utils.h"
+#include "win_netutils.h"
#include
#include
#include
@@ -27,45 +28,48 @@
using namespace std;
using namespace TeamTalk;
-int inet_pton(int family, const char *strptr, void *addrptr) {
- if(family == AF_INET) {
- struct in_addr in_val;
-#ifdef WIN32
- in_val.S_un.S_addr = inet_addr(strptr);
-#else
- in_val.s_addr = inet_addr(strptr);
-#endif
- memcpy(addrptr, &in_val, sizeof(struct in_addr));
- return 1;
- }
- return -1;
+void RobotClient::connect(const string &loc, const string &voice,
+ const string &safeness, unsigned short port) {
+ voice_ = voice;
+ debug << "opening " << loc << ':' << port << endl;
+ open(loc.c_str(), port);
+ if(spawnback) (*spawnback)(name_, safeness);
}
-const unsigned short RobotClient::PORT = 32788;
+void (*RobotClient::spawnback)(const string&, const string&) = NULL;
+
+RobotClient::RobotClient(const string& name) : name_(name) {}
+
+RobotClient::RobotClient(const std::string& name, const std::string& loc,
+ const std::string& voice, const std::string& safeness, unsigned short port)
+ : name_(name) {
+ connect(loc, voice, safeness, port);
+}
+
+string RobotClient::getName() const {return name_;}
+string RobotClient::getVoice() const {return voice_;}
+
+bool RobotClient::operator<(const RobotClient& rhs) const {
+ return name_ < rhs.name_;
+}
+
+//const unsigned short RobotsClient::PORT = 32788;
//const unsigned int RobotClient::MAXLINE = 0xfff; //maximum size of received message <4k
//unsigned int RobotClient::KEEPALIVEPERIOD = 900; //time between pings 15min
//char* RobotClient::BROADCASTADDR = "192.168.1.255";
-RobotClient::RobotClient(const string& handle, void (*c)(const Msg*), void (*n)(const string&, const string&))
- : handle_(handle), callback_(c), spawnback_(n), callbackClass_(NULL)
+RobotsClient::RobotsClient(const string& handle, RobotCallback* robotCallback)
+ : handle_(handle), robotCallback_(robotCallback)
{
+ srand ((unsigned int)time(NULL));
+ Msg::taskIDCounter = rand();
initializeSocketLayer();
getMyAddress();
- //connectOpTrader();
serverThread_ = spawnServer();
}
-RobotClient::RobotClient(const string& handle, CallBackClass* c)
- : handle_(handle), callback_(NULL), callbackClass_(c)
+RobotsClient::~RobotsClient()
{
- initializeSocketLayer();
- getMyAddress();
- //connectOpTrader();
- serverThread_ = spawnServer();
-}
-
-RobotClient::~RobotClient()
-{
// issue: close recieve thread somehow?
#ifdef WIN32
@@ -73,47 +77,13 @@
#endif
}
-void RobotClient::initializeSocketLayer() {
+void RobotsClient::initializeSocketLayer() {
#ifdef WIN32
- {
- WORD wVersionRequested;
- WSADATA wsaData;
- int err;
- wVersionRequested = MAKEWORD( 2, 2 );
- err = WSAStartup( wVersionRequested, &wsaData );
- switch(err) {
- case 0: break; //successful
- case WSASYSNOTREADY:
- throw RobotClientException("Indicates that the underlying network subsystem is not ready for network communication.");
- case WSAVERNOTSUPPORTED:
- throw RobotClientException("The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation.");
- case WSAEINPROGRESS:
- throw RobotClientException("A blocking Windows Sockets 1.1 operation is in progress.");
- case WSAEPROCLIM:
- throw RobotClientException("Limit on the number of tasks supported by the Windows Sockets implementation has been reached.");
- case WSAEFAULT:
- throw RobotClientException("The lpWSAData is not a valid pointer.");
- default:
- throw RobotClientException("unknown error starting Windows sockets.");
- }
- }
+ initializeSockets();
#endif
}
-Boeing::RobotClient* RobotClient::find(const string& s) {
- map::iterator i = robotAddress.find(s);
- if(i == robotAddress.end()) {
- cerr << "didn't find '" << s << "' in ";
- for(map::iterator i = robotAddress.begin(); i != robotAddress.end(); i++) {
- cerr << "--" << i->first << "-- ";
- }
- cerr << endl;
- return NULL;
- }
- return i->second;
-}
-
-void RobotClient::getMyAddress() {
+void RobotsClient::getMyAddress() {
gethostname(hostname, Boeing::SADDR_LENGTH);
struct hostent *Host = gethostbyname(hostname);
in_addr me;
@@ -122,14 +92,12 @@
}
#ifdef WIN32
-HANDLE RobotClient::spawnServer() {
+HANDLE RobotsClient::spawnServer() {
#else
-pthread_t RobotClient::spawnServer() {
+pthread_t RobotsClient::spawnServer() {
#endif
//spawn server
- //cerr << "about to spawn server" << endl;
#ifdef WIN32
- //_beginthread(keepalive, 0, (void *) this);
return (HANDLE)_beginthread(readMessages, 0, (void *) this);
#else
pthread_t readingThread, keepaliveThread;
@@ -139,101 +107,45 @@
readMessages,
(void *) this
);
- pthread_create(
- &keepaliveThread,
- pthread_attr_default,
- keepalive,
- (void *) this
- );
return readingThread;
#endif
}
-bool RobotClient::addRobot(const string& name,
- const string& loc,
- const string& voice,
- const string& safeness,
- unsigned short port) {
-
- if(!port) port = PORT;
- robotAddress[name] = new Boeing::RobotClient();
- robotAddress[name]->open(loc.c_str(), port);
- robotVoice_[name] = voice;
- if(spawnback_) (*spawnback_)(name, safeness);
- //fixme
+//returns false if a robot by that name already exists
+//else it creates that robot client and inserts it
+bool RobotsClient::addRobot(const string& name, const string& loc,
+ const string& voice, const string& safeness,
+ unsigned short port)
+{
+ if(find(name)) return false;
+ insert(RobotClient(name, loc, voice, safeness, port));
return true;
}
-//adds undiscoverable robots from a file
-void RobotClient::addRobotsFile(const string& name,
- Boeing::TraderClient *tclient,
- Boeing::MapClient *mclient) {
- cerr << "about to add robots" << endl;
- ifstream Frobotips(name.c_str());
- if(!Frobotips) cerr << "problem opening " << name << endl;
- string rname;
- while(Frobotips >> rname) {
- if(rname.at(0) == '#') {
- ignoreToEndOfLine(Frobotips);
- continue;
- }
- toupper(rname);
- string rip;
- Frobotips >> rip;
- string::size_type i = rip.find(':');
- try {
- int port = 0;
- if(i != string::npos) {
- port = atoi(string(rip, i+1, rip.size()-i-1).c_str());
- rip.resize(i);
- }
- if(rname == "OPTRADER") {
- ignoreToEndOfLine(Frobotips);
- cerr << "adding optrader@" << rip << ':' << port << endl;
- tclient->open(rip.c_str(), port);
- } else if(rname == "MAPSERVER") {
- ignoreToEndOfLine(Frobotips);
- cerr << "adding mapserver@" << rip << ':' << port << endl;
- if(port) mclient->open(rip.c_str(), port);
- else mclient->open(rip.c_str());
- } else {
- string voice, safeness;
- Frobotips >> voice >> safeness;
- ignoreToEndOfLine(Frobotips);
- cerr << "adding robot@" << rip << ':' << port << ' ' << voice << ' ' << safeness << endl;
- addRobot(rname, rip, voice, safeness, port);
- }
- } catch(RobotClientException e) {
- cerr << "unable to add robot " << rname << '(' << rip << ')' << endl;
- cerr << e.what() << endl;
- }
- }
-}
-
//---------------------------
// receiving messages
#ifdef WIN32
-void RobotClient::readMessages(void *thisp)
+void RobotsClient::readMessages(void *thisp)
#else
-void* RobotClient::readMessages(void *thisp)
+void* RobotsClient::readMessages(void *thisp)
#endif
{
- RobotClient* me = (RobotClient *) thisp;
- cerr << "About to start reading thread" << endl;
+ RobotsClient* me = (RobotsClient *) thisp;
+ debug("client") << "About to start reading thread" << endl;
for(;;) {
bool gotAMessage = false;
- for(map::iterator i = me->robotAddress.begin();
- i != me->robotAddress.end(); i++) {
- const Boeing::MsgRobot* mesg = i->second->getNextMessage();
+ for(iterator i = me->begin(); i != me->end(); i++) {
+ const Boeing::MsgRobot* mesg = i->getNextMessage();
if(mesg == NULL) continue;
gotAMessage = true;
- Msg* m = Msg::interpret(mesg->buff, i->first);
+ Msg* m = Msg::interpretBoeingPacket(string(mesg->buff, sizeof(Boeing::MsgRobot)), i->getName());
if(m == NULL) continue;
- //if(!dynamic_cast(m)) {
- //report unless you get a monotonous location message
- cerr << "robot " << i->first << ": " << *m << endl;
- //}
+ //report unless you get a monotonous location message
+ if(dynamic_cast(m))
+ debug("client") << "robot " << i->getName() << ": " << m << endl;
+ else
+ info("client") << "robot " << i->getName() << ": " << m << endl;
{
//[2005-09-22] (tk): don't worry about pings for now
//MsgPingPP* ping = dynamic_cast(m);
@@ -245,108 +157,36 @@
// me->sendPacket(ping->handle(), MsgPingPP(me->handle_));
//}
}
- //cerr << "bout to call back" << endl;
- if (me->callback_ != NULL) {
- (*me->callback_)(m);
- } else {
- me->callbackClass_->callback(m);
- }
+ me->robotCallback_->processRobotMessage(m);
delete m;
}
if(!gotAMessage) Sleep(500);
}
}
-/*
-void RobotClient::broadcast() {
- //form broadcast addr
- sockaddr_in st_broadcast_addr;
- {
- memset(&st_broadcast_addr, 0, sizeof(struct sockaddr_in));
- st_broadcast_addr.sin_family = AF_INET;
- inet_pton(AF_INET, BROADCASTADDR, &st_broadcast_addr.sin_addr);
- st_broadcast_addr.sin_port = htons(PORT);
- }
+vector RobotsClient::getClientList() const {
+ vector ret;
+ for(const_iterator i = begin(); i != end(); i++) {
+ ret.push_back(i->getName());
+ }
+ return ret;
}
-*/
-vector RobotClient::getClientList() const {
- vector ret;
- for(map::const_iterator i = robotAddress.begin();
- i != robotAddress.end();
- i++) {
- ret.push_back(i->first);
- }
- return ret;
+RobotClient* RobotsClient::find(const string& name) {
+ iterator i = set::find(RobotClient(name));
+ if (i == end()) {
+ warn << "didn;t find robotclient for " << name << endl;
+ return NULL;
+ } else {
+ warn << "found robotclient " << ((void*)&*i) << " for " << name << endl;
+ }
+ return &*i;
}
-string RobotClient::find(const string& host, int port) const {
- for(map::const_iterator i = robotAddress.begin();
- i != robotAddress.end();
- i++) {
- if(i->second->getHost() == host && (port == 0 || i->second->getPort() == port)) return i->first;
- }
- return string();
-}
-
-string RobotClient::robotVoice(const string& robot_name) const {
- map::const_iterator i = robotVoice_.find(robot_name);
- if(i != robotVoice_.end()) return i->second;
- return string();
-}
-
-void RobotClient::wait() const {
+void RobotsClient::wait() const {
#ifdef WIN32
WaitForSingleObject(serverThread_, INFINITE);
#else
pthread_join(serverThread_, NULL);
#endif
}
-
- /*
- //here's some stuff that I might want to incorporate into udpsocket
- if (nready == SOCKET_ERROR) {
- select_error = WSAGetLastError();
- switch(select_error) {
- case WSANOTINITIALISED:
- throw RobotClientException("A successful WSAStartup call must occur before using this function.");
- case WSAEFAULT:
- throw RobotClientException("The name parameter is not a valid part of the user address space.");
- case WSAENETDOWN:
- throw RobotClientException("The network subsystem has failed.");
- case WSAEINVAL:
- throw RobotClientException("Invalid");
- case WSAEINTR:
- throw RobotClientException("A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.");
- case WSAEINPROGRESS:
- throw RobotClientException("A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.");
- case WSAENOTSOCK:
- throw RobotClientException("Not a socket");
- default:
- throw RobotClientException("unknown select exception");
- }
- }
- }
- if (rv == SOCKET_ERROR) {
- socket_error = WSAGetLastError();
- switch (socket_error) {
- case WSANOTINITIALISED: throw RobotClientException("A successful WSAStartup call must occur before using this function.");
- case WSAENETDOWN: throw RobotClientException(" The network subsystem has failed.");
- case WSAEFAULT: throw RobotClientException(" The buf parameter is not completely contained in a valid part of the user address space.");
- case WSAENOTCONN: throw RobotClientException(" The socket is not connected.");
- case WSAEINTR: throw RobotClientException(" The (blocking) call was canceled through WSACancelBlockingCall.");
- case WSAEINPROGRESS: throw RobotClientException(" A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.");
- case WSAENETRESET: throw RobotClientException(" The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.");
- case WSAENOTSOCK: throw RobotClientException(" The descriptor is not a socket.");
- case WSAEOPNOTSUPP: throw RobotClientException(" MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.");
- case WSAESHUTDOWN: throw RobotClientException(" The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.");
- case WSAEWOULDBLOCK: throw RobotClientException(" The socket is marked as nonblocking and the receive operation would block.");
- case WSAEMSGSIZE: throw RobotClientException(" The message was too large to fit into the specified buffer and was truncated.");
- case WSAEINVAL: throw RobotClientException(" The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative.");
- case WSAECONNABORTED: throw RobotClientException(" The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.");
- case WSAETIMEDOUT: throw RobotClientException(" The connection has been dropped because of a network failure or because the peer system failed to respond.");
- case WSAECONNRESET: throw RobotClientException(" The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable. On a UPD-datagram socket this error would indicate that a previous send operation resulted in an ICMP \"Port Unreachable\" message.");
- default: throw RobotClientException("unknown recv error");
- }
- }
- */
Modified: TeamTalk/Agents/PrimitiveComm/robot_client.hpp
===================================================================
--- TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-11-09 20:10:38 UTC (rev 545)
+++ TeamTalk/Agents/PrimitiveComm/robot_client.hpp 2006-12-07 19:44:59 UTC (rev 546)
@@ -1,8 +1,6 @@
#ifndef __ROBOT_CLIENT_H__
#define __ROBOT_CLIENT_H__
-// client class to manage UDP connections to robots
-
#ifdef WIN32
#include
#else
@@ -20,23 +18,13 @@
#include