1# -*- coding: utf-8 -*-
2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3# Copyright (C) 2008-2019 German Aerospace Center (DLR) and others.
4# This program and the accompanying materials
5# are made available under the terms of the Eclipse Public License v2.0
6# which accompanies this distribution, and is available at
7# http://www.eclipse.org/legal/epl-v20.html
8# SPDX-License-Identifier: EPL-2.0
9
10# @file    _route.py
11# @author  Michael Behrisch
12# @author  Lena Kalleske
13# @date    2008-10-09
14# @version $Id$
15
16from __future__ import absolute_import
17from . import constants as tc
18from .domain import Domain
19from .storage import Storage
20
21_RETURN_VALUE_FUNC = {tc.VAR_EDGES: Storage.readStringList}
22
23
24class RouteDomain(Domain):
25
26    def __init__(self):
27        Domain.__init__(self, "route", tc.CMD_GET_ROUTE_VARIABLE, tc.CMD_SET_ROUTE_VARIABLE,
28                        tc.CMD_SUBSCRIBE_ROUTE_VARIABLE, tc.RESPONSE_SUBSCRIBE_ROUTE_VARIABLE,
29                        tc.CMD_SUBSCRIBE_ROUTE_CONTEXT, tc.RESPONSE_SUBSCRIBE_ROUTE_CONTEXT,
30                        _RETURN_VALUE_FUNC)
31
32    def getEdges(self, routeID):
33        """getEdges(string) -> list(string)
34
35        Returns a list of all edges in the route.
36        """
37        return self._getUniversal(tc.VAR_EDGES, routeID)
38
39    def add(self, routeID, edges):
40        """add(string, list(string)) -> None
41
42        Adds a new route with the given id consisting of the given list of edge IDs.
43        """
44        self._connection._beginMessage(tc.CMD_SET_ROUTE_VARIABLE, tc.ADD, routeID,
45                                       1 + 4 + sum(map(len, edges)) + 4 * len(edges))
46        self._connection._packStringList(edges)
47        self._connection._sendExact()
48
49
50RouteDomain()
51