Graph-IT

supcon.clone module

# -*- coding: utf-8 -*-

import supcon.intf

class _Clone(supcon.intf.Implementation):

  def __init__(self, local, rnode, rpath, interface):
    super().__init__(interface)

    self.__local = local
    self.__rnode = rnode
    self.__rpath = rpath

    for event in self.interface.events:
      self.__local.on(self.__rnode, self.__rpath, self.intf, event, self.__on)

  def __del__(self):
    for event in self.interface.events:
      self.__local.off(self.__rnode, self.__rpath, self.intf, event, self.__on)

  def __on(self, args: dict, event):
    (_Node, _Path, _Intf, eEvent) = event
    self.fire(eEvent, args)

  def call(self, method, inArgs):
    #print('_Clone.call', method, inArgs)
    return self.__local.call(self.__rnode, self.__rpath, self.intf, method, inArgs)

class Cloner(object):

  def __init__(self, local: supcon.intf.Node, lPath: str, rNode: str, rPath: str, rIntf: str):
    #print('Cloner.__init__')
    self.__local = local
    self.__lPath = lPath

    self.__rNode = rNode
    self.__rPath = rPath
    self.__rIntf = rIntf

    self.__impl = None

    self.__local.on(self.__local.name, '/', 'supcon.Local', 'intf', self.__onIntf)
    self.__local.on(self.__local.name, '/', 'supcon.Local', 'intfLost', self.__onIntf)

    nodes = local.nodes()
    if nodes.hasIntf(rNode, rPath, rIntf):
      self.__setupImpl(nodes[rNode][rPath][rIntf])

  @property
  def local(self) -> supcon.intf.Node:
    return self.__local

  @property
  def lPath(self) -> str:
    return self.__lPath

  @property
  def rNode(self) -> str:
    return self.__rNode

  @property
  def rPath(self) -> str:
    return self.__rPath

  @property
  def rIntf(self) -> str:
    return self.__rIntf

  def __onIntf(self, args, event):
    if args['node'] != self.__rNode or args['path'] != self.__rPath:
      return
    aInterface = supcon.intf.DInterface.load(args['intf'])
    if aInterface.name != self.__rIntf:
      return

    if event[3] == 'intf':
      self.__setupImpl(aInterface)
    else:
      self.__teardownImpl()

  def __setupImpl(self, interface):
    #print('Cloner.__setupImpl')
    self.__impl = _Clone(self.__local, self.__rNode, self.__rPath, interface)
    self.__local.register(self.__lPath, self.__impl)

  def __teardownImpl(self):
    self.__local.unregister(self.__lPath, self.__impl)
    self.__impl = None

Classes

class Cloner

class Cloner(object):

  def __init__(self, local: supcon.intf.Node, lPath: str, rNode: str, rPath: str, rIntf: str):
    #print('Cloner.__init__')
    self.__local = local
    self.__lPath = lPath

    self.__rNode = rNode
    self.__rPath = rPath
    self.__rIntf = rIntf

    self.__impl = None

    self.__local.on(self.__local.name, '/', 'supcon.Local', 'intf', self.__onIntf)
    self.__local.on(self.__local.name, '/', 'supcon.Local', 'intfLost', self.__onIntf)

    nodes = local.nodes()
    if nodes.hasIntf(rNode, rPath, rIntf):
      self.__setupImpl(nodes[rNode][rPath][rIntf])

  @property
  def local(self) -> supcon.intf.Node:
    return self.__local

  @property
  def lPath(self) -> str:
    return self.__lPath

  @property
  def rNode(self) -> str:
    return self.__rNode

  @property
  def rPath(self) -> str:
    return self.__rPath

  @property
  def rIntf(self) -> str:
    return self.__rIntf

  def __onIntf(self, args, event):
    if args['node'] != self.__rNode or args['path'] != self.__rPath:
      return
    aInterface = supcon.intf.DInterface.load(args['intf'])
    if aInterface.name != self.__rIntf:
      return

    if event[3] == 'intf':
      self.__setupImpl(aInterface)
    else:
      self.__teardownImpl()

  def __setupImpl(self, interface):
    #print('Cloner.__setupImpl')
    self.__impl = _Clone(self.__local, self.__rNode, self.__rPath, interface)
    self.__local.register(self.__lPath, self.__impl)

  def __teardownImpl(self):
    self.__local.unregister(self.__lPath, self.__impl)
    self.__impl = None

Ancestors (in MRO)

Instance variables

var lPath

var local

var rIntf

var rNode

var rPath

Methods

def __init__(

self, local, lPath, rNode, rPath, rIntf)

Initialize self. See help(type(self)) for accurate signature.

def __init__(self, local: supcon.intf.Node, lPath: str, rNode: str, rPath: str, rIntf: str):
  #print('Cloner.__init__')
  self.__local = local
  self.__lPath = lPath
  self.__rNode = rNode
  self.__rPath = rPath
  self.__rIntf = rIntf
  self.__impl = None
  self.__local.on(self.__local.name, '/', 'supcon.Local', 'intf', self.__onIntf)
  self.__local.on(self.__local.name, '/', 'supcon.Local', 'intfLost', self.__onIntf)
  nodes = local.nodes()
  if nodes.hasIntf(rNode, rPath, rIntf):
    self.__setupImpl(nodes[rNode][rPath][rIntf])