TraCIServerAPI_POI Class Reference

#include <TraCIServerAPI_POI.h>


Detailed Description

APIs for getting/setting POI values via TraCI.

Definition at line 43 of file TraCIServerAPI_POI.h.


Static Public Member Functions

static bool processGet (tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, bool withStatus=true) throw (traci::TraCIException)
 Processes a get value command (Command 0xa7: Get PoI Variable).
static bool processSet (tcpip::Storage &inputStorage, tcpip::Storage &outputStorage) throw (traci::TraCIException)
 Processes a set value command (Command 0xc7: Change PoI State).

Private Member Functions

TraCIServerAPI_POIoperator= (const TraCIServerAPI_POI &s)
 invalidated assignment operator
 TraCIServerAPI_POI (const TraCIServerAPI_POI &s)
 invalidated copy constructor

Constructor & Destructor Documentation

TraCIServerAPI_POI::TraCIServerAPI_POI ( const TraCIServerAPI_POI s  )  [private]

invalidated copy constructor


Member Function Documentation

TraCIServerAPI_POI& TraCIServerAPI_POI::operator= ( const TraCIServerAPI_POI s  )  [private]

invalidated assignment operator

bool TraCIServerAPI_POI::processGet ( tcpip::Storage inputStorage,
tcpip::Storage outputStorage,
bool  withStatus = true 
) throw (traci::TraCIException) [static]

Processes a get value command (Command 0xa7: Get PoI Variable).

Parameters:
[in] inputStorage The storage to read the command from
[out] outputStorage The storage to write the result to
[in] withStatus Whether the status message shall be written (not in subscription)

Definition at line 54 of file TraCIServerAPI_POI.cpp.

References RGBColor::blue(), CMD_GET_POI_VARIABLE, MSNet::getInstance(), ShapeContainer::getMaxLayer(), ShapeContainer::getMinLayer(), ShapeContainer::getPOICont(), MSNet::getShapeContainer(), PointOfInterest::getType(), RGBColor::green(), ID_LIST, RGBColor::red(), RESPONSE_GET_POI_VARIABLE, RTYPE_ERR, RTYPE_OK, tcpip::Storage::size(), TYPE_COLOR, TYPE_POSITION2D, TYPE_STRING, TYPE_STRINGLIST, VAR_COLOR, VAR_POSITION, VAR_TYPE, tcpip::Storage::writeFloat(), TraCIServerAPIHelper::writeStatusCmd(), tcpip::Storage::writeString(), tcpip::Storage::writeStringList(), tcpip::Storage::writeUnsignedByte(), Position2D::x(), and Position2D::y().

Referenced by traci::TraCIServer::dispatchCommand(), and traci::TraCIServer::processSingleSubscription().

00056                                                                       {
00057     std::string warning = ""; // additional description for response
00058     // variable & id
00059     int variable = inputStorage.readUnsignedByte();
00060     std::string id = inputStorage.readString();
00061     // check variable
00062     if (variable!=ID_LIST&&variable!=VAR_TYPE&&variable!=VAR_COLOR&&variable!=VAR_POSITION) {
00063         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_POI_VARIABLE, RTYPE_ERR, "Get PoI Variable: unsupported variable specified", outputStorage);
00064         return false;
00065     }
00066     // begin response building
00067     Storage tempMsg;
00068     //  response-code, variableID, objectID
00069     tempMsg.writeUnsignedByte(RESPONSE_GET_POI_VARIABLE);
00070     tempMsg.writeUnsignedByte(variable);
00071     tempMsg.writeString(id);
00072     // process request
00073     if (variable==ID_LIST) {
00074         std::vector<std::string> ids;
00075         ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
00076         for (int i = shapeCont.getMinLayer(); i <= shapeCont.getMaxLayer(); ++i) {
00077             shapeCont.getPOICont(i).insertIDs(ids);
00078         }
00079         tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
00080         tempMsg.writeStringList(ids);
00081     } else {
00082         PointOfInterest *p = 0;
00083         ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
00084         for (int i = shapeCont.getMinLayer(); i <= shapeCont.getMaxLayer()&&p==0; ++i) {
00085             p = shapeCont.getPOICont(i).get(id);
00086         }
00087         if (p==0) {
00088             TraCIServerAPIHelper::writeStatusCmd(CMD_GET_POI_VARIABLE, RTYPE_ERR, "POI '" + id + "' is not known", outputStorage);
00089             return false;
00090         }
00091         switch (variable) {
00092         case VAR_TYPE:
00093             tempMsg.writeUnsignedByte(TYPE_STRING);
00094             tempMsg.writeString(p->getType());
00095             break;
00096         case VAR_COLOR:
00097             tempMsg.writeUnsignedByte(TYPE_COLOR);
00098             tempMsg.writeUnsignedByte(static_cast<int>(p->red()*255.+.5));
00099             tempMsg.writeUnsignedByte(static_cast<int>(p->green()*255.+.5));
00100             tempMsg.writeUnsignedByte(static_cast<int>(p->blue()*255.+.5));
00101             tempMsg.writeUnsignedByte(255);
00102             break;
00103         case VAR_POSITION:
00104             tempMsg.writeUnsignedByte(TYPE_POSITION2D);
00105             tempMsg.writeFloat(p->x());
00106             tempMsg.writeFloat(p->y());
00107             break;
00108         default:
00109             break;
00110         }
00111     }
00112     if (withStatus) {
00113         TraCIServerAPIHelper::writeStatusCmd(CMD_GET_POI_VARIABLE, RTYPE_OK, warning, outputStorage);
00114     }
00115     // send response
00116     outputStorage.writeUnsignedByte(0); // command length -> extended
00117     outputStorage.writeInt(1 + 4 + tempMsg.size());
00118     outputStorage.writeStorage(tempMsg);
00119     return true;
00120 }

bool TraCIServerAPI_POI::processSet ( tcpip::Storage inputStorage,
tcpip::Storage outputStorage 
) throw (traci::TraCIException) [static]

Processes a set value command (Command 0xc7: Change PoI State).

Parameters:
[in] inputStorage The storage to read the command from
[out] outputStorage The storage to write the result to

Definition at line 124 of file TraCIServerAPI_POI.cpp.

References ShapeContainer::add(), ADD, CMD_SET_POI_VARIABLE, MSNet::getInstance(), ShapeContainer::getMaxLayer(), ShapeContainer::getMinLayer(), ShapeContainer::getPOICont(), MSNet::getShapeContainer(), REMOVE, ShapeContainer::removePOI(), RTYPE_ERR, RTYPE_OK, PointOfInterest::setType(), SUMOReal, TYPE_COLOR, TYPE_COMPOUND, TYPE_INTEGER, TYPE_POSITION2D, TYPE_STRING, VAR_COLOR, VAR_POSITION, VAR_TYPE, and TraCIServerAPIHelper::writeStatusCmd().

Referenced by traci::TraCIServer::dispatchCommand().

00125                                                                                   {
00126     std::string warning = ""; // additional description for response
00127     // variable
00128     int variable = inputStorage.readUnsignedByte();
00129     if (variable!=VAR_TYPE&&variable!=VAR_COLOR&&variable!=VAR_POSITION
00130             &&variable!=ADD&&variable!=REMOVE) {
00131         TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "Change PoI State: unsupported variable specified", outputStorage);
00132         return false;
00133     }
00134     // id
00135     std::string id = inputStorage.readString();
00136     PointOfInterest *p = 0;
00137     ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
00138     if (variable!=ADD&&variable!=REMOVE) {
00139         for (int i = shapeCont.getMinLayer(); i <= shapeCont.getMaxLayer()&&p==0; ++i) {
00140             p = shapeCont.getPOICont(i).get(id);
00141         }
00142         if (p==0) {
00143             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "POI '" + id + "' is not known", outputStorage);
00144             return false;
00145         }
00146     }
00147     // process
00148     int valueDataType = inputStorage.readUnsignedByte();
00149     switch (variable) {
00150     case VAR_TYPE: {
00151         if (valueDataType!=TYPE_STRING) {
00152             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The type must be given as a string.", outputStorage);
00153             return false;
00154         }
00155         std::string type = inputStorage.readString();
00156         p->setType(type);
00157     }
00158     break;
00159     case VAR_COLOR: {
00160         if (valueDataType!=TYPE_COLOR) {
00161             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The color must be given using an accoring type.", outputStorage);
00162             return false;
00163         }
00164         SUMOReal r = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00165         SUMOReal g = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00166         SUMOReal b = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00167         SUMOReal a = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00168         dynamic_cast<RGBColor*>(p)->set(r,g,b);
00169     }
00170     break;
00171     case VAR_POSITION: {
00172         if (valueDataType!=TYPE_POSITION2D) {
00173             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The position must be given using an accoring type.", outputStorage);
00174             return false;
00175         }
00176         SUMOReal x = inputStorage.readFloat();
00177         SUMOReal y = inputStorage.readFloat();
00178         dynamic_cast<Position2D*>(p)->set(x, y);
00179     }
00180     break;
00181     case ADD: {
00182         if (valueDataType!=TYPE_COMPOUND) {
00183             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "A compound object is needed for setting a new PoI.", outputStorage);
00184             return false;
00185         }
00186         unsigned int itemNo = inputStorage.readInt();
00187         // type
00188         if (inputStorage.readUnsignedByte()!=TYPE_STRING) {
00189             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The first PoI parameter must be the type encoded as a string.", outputStorage);
00190             return false;
00191         }
00192         std::string type = inputStorage.readString();
00193         // color
00194         if (inputStorage.readUnsignedByte()!=TYPE_COLOR) {
00195             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The second PoI parameter must be the color.", outputStorage);
00196             return false;
00197         }
00198         SUMOReal r = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00199         SUMOReal g = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00200         SUMOReal b = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00201         SUMOReal a = (SUMOReal) inputStorage.readUnsignedByte() / 255.;
00202         // layer
00203         if (inputStorage.readUnsignedByte()!=TYPE_INTEGER) {
00204             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The third PoI parameter must be the layer encoded as int.", outputStorage);
00205             return false;
00206         }
00207         int layer = inputStorage.readInt();
00208         // pos
00209         if (inputStorage.readUnsignedByte()!=TYPE_POSITION2D) {
00210             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The fourth PoI parameter must be the position.", outputStorage);
00211             return false;
00212         }
00213         SUMOReal x = inputStorage.readFloat();
00214         SUMOReal y = inputStorage.readFloat();
00215         //
00216         p = new PointOfInterest(id, type, Position2D(x, y), RGBColor(r, g, b));
00217         if (!shapeCont.add(layer, p)) {
00218             delete p;
00219             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "Could not add PoI.", outputStorage);
00220             return false;
00221         }
00222     }
00223     break;
00224     case REMOVE: {
00225         if (valueDataType!=TYPE_INTEGER) {
00226             TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "The layer must be given using an int.", outputStorage);
00227             return false;
00228         }
00229         int layer = inputStorage.readInt();
00230         if (!shapeCont.removePOI(layer, id)) {
00231             bool removed = false;
00232             for (int i = shapeCont.getMinLayer(); i <= shapeCont.getMaxLayer(); ++i) {
00233                 removed |= shapeCont.removePOI(i, id);
00234             }
00235             if (!removed) {
00236                 TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_ERR, "Could not remove PoI '" + id + "'", outputStorage);
00237                 return false;
00238             }
00239         }
00240     }
00241     break;
00242     default:
00243         break;
00244     }
00245     TraCIServerAPIHelper::writeStatusCmd(CMD_SET_POI_VARIABLE, RTYPE_OK, warning, outputStorage);
00246     return true;
00247 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:07:01 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6