Commit 180fbbf5 authored by Maverick Chardet's avatar Maverick Chardet
Browse files

Implémentation du Switch

parent b77f04b9
......@@ -2,12 +2,15 @@
** Urgent
- Corriger suppression de DataProvider
** Hacks temporaires
- Switch: pour l'instant, un switch est une place spéciale qui surcharge la fonction qui renvoie sa liste des docks de sortie. L'utilisateur le déclare dans self.switches comme un tuple (nom,f) où f prend en entrée une référence vers le composant et le nom du comportement actuel et retourne une liste d'indices de docks de sortie (ordre = ordre de déclaration des transitions qui sortent du switch). Si le switch utilise un port data, il doit être bindé aux transitions qui arrivent sur le switch.
** Vérifications
- Vérifier que le groupes se comportent comme prévu
- Vérifier que la transition _init a résolu les problèmes de ports sur l'état initial et de groupes contenant l'état initial
- Vérifier la suppression correcte de DataProvider
** Fonctionalités
......
......@@ -9,7 +9,7 @@
import sys, time
from queue import Queue
from abc import ABCMeta, abstractmethod
from typing import Dict, Tuple, List, Set
from typing import Dict, Tuple, List, Set, Callable
from concerto.place import Dock, Place
from concerto.dependency import DepType, Dependency
......@@ -122,6 +122,7 @@ class Component (object, metaclass=ABCMeta):
self.hidden_from_gantt_chart = False
self.places : List[str] = []
self.switches : List[Tuple[str,Callable[[Place,str],List[int]]]] = []
self.transitions : Dict[str,Tuple] = {}
self.groups : Dict[str,List[str]] = {}
self.dependencies : Dict[str,Tuple] = {}
......@@ -215,6 +216,35 @@ class Component (object, metaclass=ABCMeta):
if initial:
self.set_initial_place(initial)
def add_switches(self, switches : List[Tuple[str,Callable[[Place,str],List[int]]]], initial=None):
for key in switches:
self.add_switch(key)
if initial is not None:
self.set_initial_place(initial)
def add_switch(self, tuple : Tuple[str,Callable[[Place,str],List[int]]], initial=False):
"""
This method offers the possibility to add a single place to an
already existing dictionary of places.
:param name: the name of the place to add
:param initial: whether the place is the initial place of the component (default: False)
"""
(name, override_f) = tuple
if name in self.st_places:
raise Exception("Trying to add '%s' as a place while it is already a place"%name)
elif name in self.st_transitions:
raise Exception("Trying to add '%s' as a place while it is already a transition"%name)
elif name in self.st_groups:
raise Exception("Trying to add '%s' as a place while it is already a group"%name)
self.st_places[name] = Place(name, override_f, cp=self) # TODO: Remove cp
self.place_dependencies[name] = []
self.place_groups[name] = []
if initial:
self.set_initial_place(initial)
def add_groups(self, groups : Dict[str,List[str]]):
......
......@@ -50,11 +50,13 @@ class Place (object):
A place represents an evolution state in the deployment of a component.
"""
def __init__(self,name):
def __init__(self,name,override_get_output_docks=None,cp=None): # TODO remove cp
self.name = name
self.override_get_output_docks = override_get_output_docks
self.input_docks = {} # dictionary behavior -> docks[]
self.output_docks = {} # dictionary behavior -> docks[]
self.provides = []
self.cp=cp # TODO remove cp
def create_input_dock(self, transition : Transition):
"""
......@@ -120,4 +122,7 @@ class Place (object):
if behavior not in self.output_docks:
return []
else:
return self.output_docks[behavior]
if self.override_get_output_docks is not None:
return [self.output_docks[behavior][i] for i in self.override_get_output_docks(self.cp, behavior)]
else:
return self.output_docks[behavior]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment