Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file TraCIServerAPI_MultiEntryExit.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date 07.05.2009
18 : ///
19 : // APIs for getting/setting multi-entry/multi-exit detector values via TraCI
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <microsim/output/MSDetectorControl.h>
24 : #include <libsumo/MultiEntryExit.h>
25 : #include <libsumo/TraCIConstants.h>
26 : #include <libsumo/StorageHelper.h>
27 : #include "TraCIServerAPI_MultiEntryExit.h"
28 :
29 :
30 : // ===========================================================================
31 : // method definitions
32 : // ===========================================================================
33 : bool
34 974 : TraCIServerAPI_MultiEntryExit::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
35 : tcpip::Storage& outputStorage) {
36 974 : const int variable = inputStorage.readUnsignedByte();
37 974 : const std::string id = inputStorage.readString();
38 974 : server.initWrapper(libsumo::RESPONSE_GET_MULTIENTRYEXIT_VARIABLE, variable, id);
39 : try {
40 974 : if (!libsumo::MultiEntryExit::handleVariable(id, variable, &server, &inputStorage)) {
41 3 : return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
42 : }
43 1 : } catch (libsumo::TraCIException& e) {
44 1 : return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
45 1 : }
46 972 : server.writeStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
47 972 : server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
48 : return true;
49 : }
50 :
51 :
52 : bool
53 3 : TraCIServerAPI_MultiEntryExit::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
54 : tcpip::Storage& outputStorage) {
55 3 : std::string warning = ""; // additional description for response
56 : // variable
57 3 : int variable = inputStorage.readUnsignedByte();
58 3 : if (variable != libsumo::VAR_PARAMETER
59 : ) {
60 0 : return server.writeErrorStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, "Set Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
61 : }
62 : // id
63 3 : std::string id = inputStorage.readString();
64 : // process
65 : try {
66 : switch (variable) {
67 : case libsumo::VAR_PARAMETER: {
68 3 : StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
69 3 : const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
70 3 : const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
71 3 : libsumo::MultiEntryExit::setParameter(id, name, value);
72 : break;
73 : }
74 : default:
75 : break;
76 : }
77 0 : } catch (libsumo::TraCIException& e) {
78 0 : return server.writeErrorStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
79 0 : }
80 3 : server.writeStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
81 : return true;
82 : }
83 :
84 :
85 : /****************************************************************************/
|