Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerInfoStrings.cpp

Go to the documentation of this file.
00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "Aria.h"
00027 #include "ArExport.h"
00028 #include "ArServerInfoStrings.h"
00029 
00030 AREXPORT ArServerInfoStrings::ArServerInfoStrings(ArServerBase *server) :
00031   myAddStringFunctor(this, &ArServerInfoStrings::addString),
00032   myNetGetStringsInfoCB(this, &ArServerInfoStrings::netGetStringsInfo),
00033   myNetGetStringsCB(this, &ArServerInfoStrings::netGetStrings)
00034 {
00035   myServer = server;
00036   if (myServer != NULL)
00037   {
00038     myServer->addData("getStringsInfo", 
00039                       "Gets the information about the 'getStrings' command",
00040                       &myNetGetStringsInfoCB,
00041                       "none", 
00042   "uByte2: count; repeating count times  string: name, uByte2: maxlength", 
00043                       "NavigationInfo", "RETURN_SINGLE");
00044     myServer->addData("getStrings", 
00045               "Gets the strings, for info about them see getStringsInfo",
00046                       &myNetGetStringsCB,
00047                       "none",
00048                       "byte2: count, repeating count: string", 
00049                       "NavigationInfo", "RETURN_SINGLE");
00050     
00051   }
00052   myMaxMaxLength = 512;
00053 }
00054 
00055 AREXPORT ArServerInfoStrings::~ArServerInfoStrings()
00056 {
00057 
00058 }
00059 
00060 AREXPORT void ArServerInfoStrings::buildStringsInfoPacket(void)
00061 {
00062   myStringsMutex.lock();
00063   std::list<ArStringInfoHolder *>::iterator it;
00064   ArStringInfoHolder *info;
00065   
00066   myStringInfoPacket.empty();
00067   ArTypes::UByte2 count;
00068   count = myStrings.size();
00069   myStringInfoPacket.uByte2ToBuf(count);
00070   for (it = myStrings.begin(); it != myStrings.end(); it++)
00071   {
00072     info = (*it);
00073     myStringInfoPacket.strToBuf(info->getName());
00074     myStringInfoPacket.uByte2ToBuf(info->getMaxLength());
00075   }
00076   myStringsMutex.unlock();
00077 }
00078 
00079 AREXPORT void ArServerInfoStrings::buildStringsPacket(void)
00080 {
00081   myStringsMutex.lock();
00082   if (myLastStringPacketBuild.mSecSince() < 100)
00083   {
00084     myStringsMutex.unlock();
00085     return;
00086   }
00087 
00088   myStringPacket.empty();
00089   std::list<ArStringInfoHolder *>::iterator it;
00090   ArStringInfoHolder *info;
00091 
00092   char *buf;
00093   buf = new char[myMaxMaxLength+1];
00094 
00095   for (it = myStrings.begin(); it != myStrings.end(); it++)
00096   {
00097     info = (*it);
00098     info->getFunctor()->invoke(buf, info->getMaxLength());
00099     myStringPacket.strToBuf(buf);
00100   }
00101 
00102   delete buf;
00103 
00104   myStringsMutex.unlock();
00105 }
00106 
00107 AREXPORT void ArServerInfoStrings::netGetStringsInfo(ArServerClient *client,
00108                                                         ArNetPacket *packet)
00109 {
00110   buildStringsInfoPacket();
00111   client->sendPacketTcp(&myStringInfoPacket);
00112 }
00113 
00114 AREXPORT void ArServerInfoStrings::netGetStrings(ArServerClient *client, 
00115                                                     ArNetPacket *packet)
00116 {
00117   buildStringsPacket();
00118   client->sendPacketTcp(&myStringPacket);
00119 }
00120 
00121 
00122 AREXPORT void ArServerInfoStrings::addString(
00123         const char *name, ArTypes::UByte2 maxLength,
00124         ArFunctor2<char *, ArTypes::UByte2> *functor)
00125 {
00126   myStringsMutex.lock();
00127   if (myMaxMaxLength < maxLength)
00128     myMaxMaxLength = maxLength;
00129   myStrings.push_back(new ArStringInfoHolder(name, maxLength, functor));
00130   myStringsMutex.unlock();
00131   buildStringsInfoPacket();
00132   myServer->broadcastPacketTcp(&myStringInfoPacket, "getStringsInfo");
00133 }
00134 
00135 

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0