def __init__(self): BaseCpcNode.__init__(self) event.EventConsumerMixin.__init__(self, self._event_handler) event.EventProducerMixin.__init__(self) self._line_handler = None self.running = 0 self._children_have_been_discovered = 0 self._autodisc_done_evt = Event() return
def __init__(self): BaseCpcNode.__init__(self) event.EventConsumerMixin.__init__(self,self._event_handler) event.EventProducerMixin.__init__(self) self._line_handler = None self.running = 0 self._children_have_been_discovered = 0 self._autodisc_done_evt = Event() return
class CpcNode(BaseCpcNode, event.EventConsumerMixin, event.EventProducerMixin): _state_table = { 0: 'Stopped', 1: 'Able to send', 2: 'Preempted by CPC modem' } def __init__(self): BaseCpcNode.__init__(self) event.EventConsumerMixin.__init__(self, self._event_handler) event.EventProducerMixin.__init__(self) self._line_handler = None self.running = 0 self._children_have_been_discovered = 0 self._autodisc_done_evt = Event() return def start(self): if self.running == 0: assert isinstance(self.parent, Port), 'Parent of CpcNode must be Port, not %s' \ % self.parent.__class__.__name__ self._line_handler = LineHandler(self.parent) self._line_handler.event_subscribe(self, AutoDiscDoneEvent) self._autodisc_done_evt.clear() self._line_handler.start() self.running = 1 BaseCpcNode.start(self) return def stop(self): if self.running != 0: BaseCpcNode.stop(self) self.running = 0 self._line_handler.stop() del self._line_handler self._line_handler = None return def get_state(self): if self._line_handler: return self._line_handler.get_state() return None def get(self, skipCache=0): state = self.get_state() return self._state_table[state] def _discover_children(self): if (self.running != 0) and (self._children_have_been_discovered == 0): autodisc_period = self._line_handler.get_autodiscover_period() self._autodisc_done_evt.wait() # If we timed out or the LineHandler never found any devices, then abort: if (not self._autodisc_done_evt.isSet()) \ or (self._line_handler.get_state() == 0): self.event_generate(event.Event(source=self)) msglog.log('mpx',msglog.types.ERR,'CPC_UHP: LineHandler autodisc failed.' \ ' Aborting child autodisc.') # Don't come back this way until node has been stopped and restarted: self._children_have_been_discovered = 1 return self._nascent_children # should be empty devs = self._line_handler.get_devs() for dev_id, dev_inst_data in devs.items(): dev = dev_inst_data.dev dev_child = DeviceNode(dev) dev_node_name = dev.get_name() if dev_node_name is None: msglog.log('mpx',msglog.types.ERR,'Failed to get name from device %s' \ % id(dev)) continue self._nascent_children[dev_node_name] = dev_child self._children_have_been_discovered = 1 return self._nascent_children def get_alarms(self): if self._line_handler is None: return [] return self._line_handler.get_alarms() def _event_handler(self, event): if not isinstance(event, AutoDiscDoneEvent): return self._autodisc_done_evt.set() return
class CpcNode(BaseCpcNode,event.EventConsumerMixin,event.EventProducerMixin): _state_table = {0:'Stopped',1:'Able to send',2:'Preempted by CPC modem'} def __init__(self): BaseCpcNode.__init__(self) event.EventConsumerMixin.__init__(self,self._event_handler) event.EventProducerMixin.__init__(self) self._line_handler = None self.running = 0 self._children_have_been_discovered = 0 self._autodisc_done_evt = Event() return def start(self): if self.running == 0: assert isinstance(self.parent, Port), 'Parent of CpcNode must be Port, not %s' \ % self.parent.__class__.__name__ self._line_handler = LineHandler(self.parent) self._line_handler.event_subscribe(self,AutoDiscDoneEvent) self._autodisc_done_evt.clear() self._line_handler.start() self.running = 1 BaseCpcNode.start(self) return def stop(self): if self.running != 0: BaseCpcNode.stop(self) self.running = 0 self._line_handler.stop() del self._line_handler self._line_handler = None return def get_state(self): if self._line_handler: return self._line_handler.get_state() return None def get(self, skipCache=0): state = self.get_state() return self._state_table[state] def _discover_children(self): if (self.running != 0) and (self._children_have_been_discovered == 0): autodisc_period = self._line_handler.get_autodiscover_period() self._autodisc_done_evt.wait() # If we timed out or the LineHandler never found any devices, then abort: if (not self._autodisc_done_evt.isSet()) \ or (self._line_handler.get_state() == 0): self.event_generate(event.Event(source=self)) msglog.log('mpx',msglog.types.ERR,'CPC_UHP: LineHandler autodisc failed.' \ ' Aborting child autodisc.') # Don't come back this way until node has been stopped and restarted: self._children_have_been_discovered = 1 return self._nascent_children # should be empty devs = self._line_handler.get_devs() for dev_id,dev_inst_data in devs.items(): dev = dev_inst_data.dev dev_child = DeviceNode(dev) dev_node_name = dev.get_name() if dev_node_name is None: msglog.log('mpx',msglog.types.ERR,'Failed to get name from device %s' \ % id(dev)) continue self._nascent_children[dev_node_name] = dev_child self._children_have_been_discovered = 1 return self._nascent_children def get_alarms(self): if self._line_handler is None: return [] return self._line_handler.get_alarms() def _event_handler(self, event): if not isinstance(event, AutoDiscDoneEvent): return self._autodisc_done_evt.set() return