etisserant@203: #!/usr/bin/env python etisserant@203: # -*- coding: utf-8 -*- andrej@1571: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. etisserant@203: # r@1455: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD etisserant@203: # r@1455: # See COPYING file for copyrights details. etisserant@203: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. etisserant@203: # andrej@1571: # This program is distributed in the hope that it will be useful, r@1455: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. etisserant@203: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. etisserant@203: etisserant@203: # Package initialisation etisserant@203: etisserant@203: from os import listdir, path etisserant@203: laurent@399: etisserant@203: _base_path = path.split(__file__)[0] etisserant@203: laurent@399: Edouard@733: def _GetLocalConnectorClassFactory(name): r@1455: return lambda: getattr(__import__(name, globals(), locals()), name + "_connector_factory") Edouard@733: Edouard@1440: connectors = {name:_GetLocalConnectorClassFactory(name) Edouard@1440: for name in listdir(_base_path) Edouard@1440: if path.isdir(path.join(_base_path, name)) Edouard@733: and not name.startswith("__")} etisserant@203: r@1455: Edouard@717: def ConnectorFactory(uri, confnodesroot): etisserant@203: """ etisserant@203: Return a connector corresponding to the URI etisserant@203: or None if cannot connect to URI etisserant@203: """ Edouard@1440: servicetype = uri.split("://")[0].upper() Edouard@1440: if servicetype == "LOCAL": Edouard@1440: # Local is special case Edouard@1440: # pyro connection to local runtime Edouard@1440: # started on demand, listening on random port Edouard@1440: servicetype = "PYRO" Edouard@1440: runtime_port = confnodesroot.AppFrame.StartLocalRuntime( Edouard@1440: taskbaricon=True) r@1455: uri = "PYROLOC://127.0.0.1:" + str(runtime_port) Edouard@1440: elif servicetype in connectors: Edouard@1440: pass r@1455: elif servicetype[-1] == 'S' and servicetype[:-1] in connectors: Edouard@1440: servicetype = servicetype[:-1] r@1455: else: Edouard@1440: return None Edouard@1440: Edouard@1440: # import module according to uri type Edouard@1440: connectorclass = connectors[servicetype]() Edouard@733: return connectorclass(uri, confnodesroot)