SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
TraCIServerAPI_Junction.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// APIs for getting/setting junction values via TraCI
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#ifndef NO_TRACI
34
35
#include "
TraCIConstants.h
"
36
#include <
microsim/MSNet.h
>
37
#include <
microsim/MSJunction.h
>
38
#include <
microsim/MSJunctionControl.h
>
39
#include <
microsim/MSNet.h
>
40
#include "
TraCIServerAPI_Junction.h
"
41
42
#ifdef CHECK_MEMORY_LEAKS
43
#include <
foreign/nvwa/debug_new.h
>
44
#endif // CHECK_MEMORY_LEAKS
45
46
47
// ===========================================================================
48
// used namespaces
49
// ===========================================================================
50
using namespace
traci;
51
52
53
// ===========================================================================
54
// method definitions
55
// ===========================================================================
56
bool
57
TraCIServerAPI_Junction::processGet
(
TraCIServer
& server,
tcpip::Storage
& inputStorage,
58
tcpip::Storage
& outputStorage) {
59
// variable
60
int
variable = inputStorage.
readUnsignedByte
();
61
std::string
id
= inputStorage.
readString
();
62
// check variable
63
if
(variable !=
ID_LIST
&& variable !=
VAR_POSITION
&& variable !=
ID_COUNT
) {
64
return
server.
writeErrorStatusCmd
(
CMD_GET_JUNCTION_VARIABLE
,
"Get Junction Variable: unsupported variable specified"
, outputStorage);
65
}
66
// begin response building
67
tcpip::Storage
tempMsg;
68
// response-code, variableID, objectID
69
tempMsg.
writeUnsignedByte
(
RESPONSE_GET_JUNCTION_VARIABLE
);
70
tempMsg.
writeUnsignedByte
(variable);
71
tempMsg.
writeString
(
id
);
72
if
(variable ==
ID_LIST
) {
73
std::vector<std::string> ids;
74
MSNet::getInstance
()->
getJunctionControl
().
insertIDs
(ids);
75
tempMsg.
writeUnsignedByte
(
TYPE_STRINGLIST
);
76
tempMsg.
writeStringList
(ids);
77
}
else
if
(variable ==
ID_COUNT
) {
78
std::vector<std::string> ids;
79
MSNet::getInstance
()->
getJunctionControl
().
insertIDs
(ids);
80
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
81
tempMsg.
writeInt
((
int
) ids.size());
82
}
else
{
83
MSJunction
* j =
MSNet::getInstance
()->
getJunctionControl
().
get
(
id
);
84
if
(j == 0) {
85
return
server.
writeErrorStatusCmd
(
CMD_GET_JUNCTION_VARIABLE
,
"Junction '"
+
id
+
"' is not known"
, outputStorage);
86
}
87
switch
(variable) {
88
case
ID_LIST
:
89
break
;
90
case
VAR_POSITION
:
91
tempMsg.
writeUnsignedByte
(
POSITION_2D
);
92
tempMsg.
writeDouble
(j->
getPosition
().
x
());
93
tempMsg.
writeDouble
(j->
getPosition
().
y
());
94
break
;
95
default
:
96
break
;
97
}
98
}
99
server.
writeStatusCmd
(
CMD_GET_JUNCTION_VARIABLE
,
RTYPE_OK
,
""
, outputStorage);
100
server.
writeResponseWithLength
(outputStorage, tempMsg);
101
return
true
;
102
}
103
104
105
bool
106
TraCIServerAPI_Junction::getPosition
(
const
std::string&
id
,
Position
& p) {
107
MSJunction
* j =
MSNet::getInstance
()->
getJunctionControl
().
get
(
id
);
108
if
(j == 0) {
109
return
false
;
110
}
111
p = j->
getPosition
();
112
return
true
;
113
}
114
115
116
TraCIRTree
*
117
TraCIServerAPI_Junction::getTree
() {
118
TraCIRTree
* t =
new
TraCIRTree
();
119
const
std::map<std::string, MSJunction*>& junctions =
MSNet::getInstance
()->
getJunctionControl
().
getMyMap
();
120
for
(std::map<std::string, MSJunction*>::const_iterator i = junctions.begin(); i != junctions.end(); ++i) {
121
Boundary
b = (*i).second->getShape().getBoxBoundary();
122
t->
addObject
((*i).second, b);
123
}
124
return
t;
125
}
126
127
#endif
128
129
130
/****************************************************************************/
131
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
traci-server
TraCIServerAPI_Junction.cpp
Generated on Sun Jun 16 2013 07:08:38 for SUMO - Simulation of Urban MObility by
1.8.1.2