Пример #1
0
bool
TraCIServer::readTypeCheckingStringList(tcpip::Storage& inputStorage, std::vector<std::string>& into) {
    if (inputStorage.readUnsignedByte() != TYPE_STRINGLIST) {
        return false;
    }
    into = inputStorage.readStringList();
    return true;
}
Пример #2
0
bool
TraCIServerAPI_Lane::processSet(TraCIServer &server, tcpip::Storage &inputStorage,
                                tcpip::Storage &outputStorage) {
    std::string warning = ""; // additional description for response
    // variable
    int variable = inputStorage.readUnsignedByte();
    if (variable!=VAR_MAXSPEED&&variable!=VAR_LENGTH&&variable!=LANE_ALLOWED&&variable!=LANE_DISALLOWED) {
        server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Change Lane State: unsupported variable specified", outputStorage);
        return false;
    }
    // id
    std::string id = inputStorage.readString();
    MSLane *l = MSLane::dictionary(id);
    if (l==0) {
        server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Lane '" + id + "' is not known", outputStorage);
        return false;
    }
    // process
    int valueDataType = inputStorage.readUnsignedByte();
    switch (variable) {
    case VAR_MAXSPEED: {
        // speed
        if (valueDataType!=TYPE_FLOAT) {
            server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "The speed must be given as a float.", outputStorage);
            return false;
        }
        SUMOReal val = inputStorage.readFloat();
        l->setMaxSpeed(val);
    }
    break;
    case VAR_LENGTH: {
        // speed
        if (valueDataType!=TYPE_FLOAT) {
            server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "The length must be given as a float.", outputStorage);
            return false;
        }
        SUMOReal val = inputStorage.readFloat();
        l->setLength(val);
    }
    break;
    case LANE_ALLOWED: {
        if (valueDataType!=TYPE_STRINGLIST) {
            server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Allowed classes must be given as a list of strings.", outputStorage);
            return false;
        }
        std::vector<SUMOVehicleClass> allowed;
        parseVehicleClasses(inputStorage.readStringList(), allowed);
        l->setAllowedClasses(allowed);
        l->getEdge().rebuildAllowedLanes();
    }
    break;
    case LANE_DISALLOWED: {
        if (valueDataType!=TYPE_STRINGLIST) {
            server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_ERR, "Not allowed classes must be given as a list of strings.", outputStorage);
            return false;
        }
        std::vector<SUMOVehicleClass> disallowed;
        parseVehicleClasses(inputStorage.readStringList(), disallowed);
        l->setNotAllowedClasses(disallowed);
        l->getEdge().rebuildAllowedLanes();
    }
    break;
    default:
        break;
    }
    server.writeStatusCmd(CMD_SET_LANE_VARIABLE, RTYPE_OK, warning, outputStorage);
    return true;
}