Esempio n. 1
0
 def __init__(self, port):
     self.lock = Lock()
     self.port = port
     self.units = {}
     self.connected = 0
     if not port.is_open():
         port.open()
Esempio n. 2
0
 def __init__(self):
     ConfigurableNode.__init__(self)
     self._url = 'unknown'
     self._poll_event = None
     self._period = 0.2
     # Pre-load attributes.
     self.off_text = "Off"
     self.on_text = "On"
     self.auto_text = "Auto"
     self.reverse_output = 0
     self.output = REQUIRED
     self.input = REQUIRED
     self.period = self._period
     self.asyncOK = 1
     self.state = 2
     self.debug = 0
     self.__running = False
     self._init_debug()
     self.OFF = EnumeratedValue(0, self.off_text)
     self.ON = EnumeratedValue(1, self.on_text)
     self.AUTO = EnumeratedValue(2, self.auto_text)
     self._NORMAL = 0
     self._SAFETY = 1
     self._output_state = self._NORMAL
     self._output_lock = Lock()
     self._changes_at = 0
     self._waiting_value = None
     self._value = None
     self._lock = Lock()
     return
Esempio n. 3
0
class XCommandIface(TcpConnection):
    def __init__(self, port, host, debug):
        self.__lock = Lock() # lock serializes XCommandIface messaging
        super(XCommandIface, self).__init__(port, host, debug)
        return
        
    def write(self, method_name, params):
        self.__lock.acquire()
        try:
            if not self.connection_ok():
                self.open_connection()
            # marshal data from param tuple
            data = xmlrpclib.dumps(tuple([params]), method_name)
            #payload is 4 byte, little endian, field representing the length of
            #the xml data, followed by the data
            msg = struct.pack('<I', len(data)) + data
            try:
                self._s.send(msg)
            except:
                msglog.log('Adura', ERR, 'Error writing to XCommand socket.')
                raise EConnectionError
            rslt = self.read()
        finally:
            self.close_connection()
            self.__lock.release()
            
    def read(self):
        # leading 4 bytes indicates length of xml-rpc response payload 
        read_len = struct.unpack('<I', self._s.recv(4, timeout=SOCK_OP_TIMEOUT))[0]
        # retreive and marshall the results.  If the xml-rpc packet represents a 
        # fault condition, loads() raises a Fault exception.  @fixme - need a 
        # better understanding of their normal result structure
        rslt = xmlrpclib.loads(self._s.recv(read_len, timeout=SOCK_OP_TIMEOUT))[0]
        return rslt
Esempio n. 4
0
 def __init__(self):
     Exporter.__init__(self)
     EventConsumerMixin.__init__(self, self.handle_connected,
                                 self.connection_event_error)
     self.running = 0
     self._scheduled = None
     self._lock = Lock()
Esempio n. 5
0
 def __init__(self):
     self.observers = {}
     self.data = None
     self.running = False
     self._ob_lock = Lock()
     super(BrivoDispatcher, self).__init__()
     return
Esempio n. 6
0
class CachedValue(CompositeNode):
    def __init__(self):
        self._lock = Lock()
        self._value = _Value()
        CompositeNode.__init__(self)

    def configure(self, config):
        CompositeNode.configure(self, config)
        set_attribute(self, 'expires_after', 0, config, float)
        set_attribute(self, 'node', self.parent, config, as_node)

    def configuration(self):
        config = CompositeNode.configuration(self)
        get_attribute(self, 'expires_after', config, str)
        get_attribute(self, 'node', config, as_node_url)
        return config

    def get(self, skipCache=0):
        self._lock.acquire()
        try:
            if self._value.age() > self.expires_after:
                self._value.set(self.node.get())
        finally:
            self._lock.release()
        return self._value.get()
Esempio n. 7
0
class AlarmLogger(ServiceNode):
    def __init__(self):
        self.__lock = Lock()
        ServiceNode.__init__(self)

    def configure(self, config):
        ServiceNode.configure(self, config)
        set_attribute(self, 'log', REQUIRED, config)

    def configuration(self):
        config = ServiceNode.configuration(self)
        get_attribute(self, 'log', config, as_node_url)
        return config

    def start(self):
        self.log = as_node(self.log)
        ServiceNode.start(self)

    def stop(self):
        self.log = as_node_url(self.log)
        ServiceNode.stop(self)

    def export(self, alarm):
        self.__lock.acquire()
        try:
            self.log.add_entry([
                time.time(), alarm.source.name, alarm.timestamp,
                alarm.critical, alarm.values, alarm.message
            ])
        finally:
            self.__lock.release()
Esempio n. 8
0
 def __init__(self):
     ConfigurableNode.__init__(self)
     self._url = 'unknown'
     self._poll_event = None
     self._period = 0.2
     # Pre-load attributes.
     self.off_text = "Off"
     self.on_text = "On"
     self.auto_text = "Auto"
     self.reverse_output = 0
     self.output = REQUIRED
     self.input = REQUIRED
     self.period = self._period
     self.asyncOK = 1
     self.state = 2
     self.debug = 0
     self.__running = False
     self._init_debug()
     self.OFF = EnumeratedValue(0, self.off_text)
     self.ON = EnumeratedValue(1, self.on_text)
     self.AUTO = EnumeratedValue(2, self.auto_text)
     self._NORMAL = 0
     self._SAFETY = 1
     self._output_state = self._NORMAL
     self._output_lock = Lock()
     self._changes_at = 0
     self._waiting_value = None
     self._value = None
     self._lock = Lock()
     return
Esempio n. 9
0
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.lock = Lock()
     self.pool = ThreadPool(3)
     self.queue = Queue()
     self.simple_action_counter = 0
     return
Esempio n. 10
0
class _Lock:
    def __init__(self):
        self._minutes = 0
        self._lock = Lock()
        self._scheduled = None
        self._stack = None
    def acquire(self,blocking=0):        
        value = self._lock.acquire(blocking)
        self._stack = traceback.extract_stack()
        self._schedule_print()
        return value
    def release(self):
        try:
            if self._scheduled:
                self._scheduled.cancel()
        finally:
            self._lock.release()
    def locked(self):
        return self._lock.locked()
    def _schedule_print(self):
        self._scheduled = scheduler.after(60,self._print,(self._stack,))
    def _print(self,stack):
        self._minutes += 1
        print 'Lock acquired: %s min' % self._minutes
        print string.join(traceback.format_list(stack))
        if self.locked():
            self._schedule_print()                 
Esempio n. 11
0
 def __init__(self):
     self.__alarm_queue = Queue()
     self.__current_thread = None
     self.__lock = Lock()
     self._init_default_attribute_values()
     Client.__init__(self)
     return
Esempio n. 12
0
 def __init__(self, node):
     self.__lock = Lock()
     self.__last_save = {}
     self.max_seq = -1
     self.pending_seqs = []
     self.inprocess_seqs = []
     PersistentDataObject.__init__(self, node, auto_load=True)
     return
Esempio n. 13
0
 def __init__(self):
     self._subscription_lock = Lock()
     self._subscribed = 0
     self._subscribers = {}
     self._last_value = None
     self._last_rcvd = None
     self._decode_indexes = {}
     return
Esempio n. 14
0
 def __init__(self):
     self.__lock = Lock()
     self.__rids = {}
     self.__identifiers = {}
     self.__rid_filters = {}
     self.__class_cache = {}
     self.__consumers = weakref.WeakKeyDictionary()
     self.__pending = []
Esempio n. 15
0
 def __init__(self):
     self._lock = Lock()
     self._started = 0
     self._alarm = []  # can have a whole MESS o' alarms at startup...
     self._scheduled = None
     self.trigger_node_url_posn = None  # allow source stamping
     self.trigger_node_msg_posn = None  # allow source stamping
     self._waiting_alarm_sid = None
     ServiceNode.__init__(self)
Esempio n. 16
0
 def __init__(self):
     self.rt_request_obj = device.real_time_value_req()
     self.rt_response_obj = device.real_time_value_res()
     self.cr_request_obj = device.control_relay_req()
     self.cr_response_obj = device.control_relay_res()
     self.rt_lock = Lock()
     self.cr_lock = Lock()
     self.rt_last_updated = 0
     super(DeviceRT, self).__init__()
Esempio n. 17
0
 def __init__( self ):
     ConfigurableNode.__init__( self )
     self.isRunning = 0
     self.ipcheck_pid = 0
     self._lock = Lock()
     self.thread = None
     self.first_time = 0
     self.log_name = 'broadway'
     self.update_count = 0
Esempio n. 18
0
 def __init__(self, timeout, scan_time):
     #self._c == {group_id:{addr:last_msg}}
     self._c = {}
     self._cache_lock = Lock()  #can add more granular locking, if need be
     self._subscr_list = {}  # == {(group_id,addr):[call_back_meth]}  ...
     self.timeout = timeout
     if not scan_time:
         self.scan_time = max(self.timeout / 4, 30)
     self._scan_scheduled = None
Esempio n. 19
0
 def __init__(self):
     CompositeNode.__init__(self)
     EventProducerMixin.__init__(self)
     self._schedule_lock = Lock()
     self._schedule_condition = Condition()
     self._value_lock = Lock()
     self._value_condition = Condition()
     self.__schedule = None
     self.__value = None
Esempio n. 20
0
 def __init__(self):
     Node.__init__(self)
     self._dev_name = None  # Can programmatically override BEFORE start.
     self._lock = Lock()
     self._popen = None
     self._apps = []
     self._groups = []
     self._discovery_ts = None
     return
Esempio n. 21
0
 def __init__(self):
     self.rt_request_obj = device.real_time_value_req()
     self.rt_response_obj = device.real_time_value_res()
     self.cr_request_obj = device.control_relay_req()
     self.cr_response_obj = device.control_relay_res()
     self.rt_lock = Lock()
     self.cr_lock = Lock()
     self.rt_last_updated = 0
     super(DeviceRT, self).__init__()
Esempio n. 22
0
 def __init__(self):
     CompositeNode.__init__(self)
     EventProducerMixin.__init__(self)
     self._schedule_lock = Lock()
     self._schedule_condition = Condition()
     self._value_lock = Lock()
     self._value_condition = Condition()
     self.__schedule = None
     self.__value = None
Esempio n. 23
0
 def __init__(self):
     Calculator.__init__(self)
     EventProducerMixin.__init__(self)
     self._state = self.INITIALIZING
     self._current_id = None
     self._scheduled = None
     self._state_lock = Lock()
     self._schedule_lock = Lock()
     self.require_acknowledge = 0
     return
Esempio n. 24
0
 def __init__(self, parent, line_handler, command, timeout=1.0):
     self._ion = parent
     self._lh = line_handler
     self._command = command
     self._timeout = timeout
     self._cache = None
     self._timestamp = time.time()
     self._expire_after = self._timestamp - 1.0
     self._lock = Lock() # Light weight, non-reentrant lock.
     self._map = {}
Esempio n. 25
0
 def __init__(self):
     self._last_rcvd = 0
     self._subscribers = 0
     self._scheduled = None
     self._skip_cache = False
     self._cached_result = None
     self._exec_delay = _Buffer(5)
     self._subscription_lock = Lock()
     CompositeNode.__init__(self)
     EventProducerMixin.__init__(self)
Esempio n. 26
0
 def __init__(self, *args, **kw):
     dict.__init__(self, *args, **kw)
     self.__busy = False
     self.__lock = Lock()
     # The StubNotifier is used during the creation of the real
     # SocketMapNotifier().
     self.__notifier = StubNotifier()
     # Creating the SocketMapNotifier will add it to this SocketMap.
     self.__notifier = SocketMapNotifier(self)
     return
Esempio n. 27
0
 def __init__(self):
     self.__server = None
     self.__sched_lock = Lock()
     self.__sched_thread = None
     self.__schedules = Queue()
     self.__pv = None
     super(LightingGroup, self).__init__()
     EventConsumerMixin.__init__(self, self._sched_update,
                                 self._sched_exception)
     return
Esempio n. 28
0
 def __init__(self,socket,*args):
     if not isinstance(socket,_Socket):
         raise EInvalidValue('socket',socket,
                             'Must be mpx.lib.socket.socket')
     self._safety = 0
     if isinstance(socket,_SafetySocket):
         self._safety = 1
     self._socket = socket
     self._ssl = _original_ssl(socket._socket,*args)
     self._lock = Lock()
Esempio n. 29
0
 def __init__(self):
     self._history = None
     self._history_lock = Lock()
     self._sid = None
     self._nid = 1
     self._poll_failure = False
     self._scheduled = None
     self.running = False
     super(Kwh2Kw, self).__init__()
     return
Esempio n. 30
0
 def __init__(self):
     Calculator.__init__(self)
     EventProducerMixin.__init__(self)
     self._state = self.INITIALIZING
     self._current_id = None
     self._scheduled = None
     self._state_lock = Lock()
     self._schedule_lock = Lock()
     self.require_acknowledge = 0
     return
Esempio n. 31
0
 def __init__(self):
     self._cpex_lock=RLock() # cpex switch list lock, used for setting/getting the "primary" cpex switch.
     self._cache_lock=Lock() # domain value cache lock.
     self._cpex_switch_map_lock = Lock() # lock for cpex switches cache data structure
     self._cache_value=None
     self._cache_time=0
     self._cpex_switch_map_cache=SwitchMap({})
     self._cpex_switch_map_time=0
     self.ttl=30
     self._reinit()
     return
Esempio n. 32
0
 def __init__(self):
     CompositeNode.__init__(self)
     ProxyMixin.__init__(self)
     MetaMixin.__init__(self)
     # consideration: memory utilization.  This really is redundant,
     # since the properties are also mapped into the node tree.
     self._properties = {}
     self._properties_list = []
     self._properties_loaded = False
     self._load_lock = Lock()
     self.__security_manager = None
Esempio n. 33
0
 def __init__(self):
     self.function = None
     self._calculator = None
     self.__node = None
     self.__node_url = None
     self.__lock = Lock()
     self.__started = 0
     self._sid = None
     self._present_value = None
     Column.__init__(self)
     EventConsumerMixin.__init__(self, self.change_of_value)
Esempio n. 34
0
 def __init__(self):
     # overridden by subclasses
     self._pv_index = None
     self._last_rcvd = 0.0
     self._last_rcvd_dlta = 0.0
     self._cached_value = None
     self._cached_result = None
     self._prop_values = None
     self._subscription_lock = Lock()
     CompositeNode.__init__(self)
     EventProducerMixin.__init__(self)
     return
Esempio n. 35
0
 def __init__(self):
     ARMNode.__init__(self)
     AutoDiscoveredNode.__init__(self)
     self._lock = Lock()
     self.conversion_list = {}
     self._queue = Queue()
     self.debug = 0
     self.running = 0
     self._start_called = 0
     self.devices = ''
     self.device_addresses = []
     self._been_discovered = 0
Esempio n. 36
0
class CANBus(ARMNode, AutoDiscoveredNode):

    def __init__(self):
        ARMNode.__init__(self)
        AutoDiscoveredNode.__init__(self)
        self._lock = Lock()
        self.conversion_list = {}
        self._queue = Queue()
        self.debug = 0
        self.running = 0
        self._start_called = 0
        self.devices = ''
        self.device_addresses = []
        self._been_discovered = 0

    def lock(self):
        self._lock.acquire()
    def unlock(self):
        self._lock.release()

    ##
    # @see node.ARMNode#configure
    #
    def configure(self,config):
        ARMNode.configure(self,config)

    
    def configuration(self):
        config = ARMNode.configuration(self)
        #get_attribute(self, 'devices', config)
        return config
        

    ##
    # start temperature conversions
    #
    def start(self):
        ARMNode.start(self)
        self.running = 0
    
    def stop(self):
        self.running = 0

    ##
    # discover and create object instances
    #
    def _discover_children(self, force=0):
        if force:
            self._been_discovered = 0
        if self.running == 1 and not self._been_discovered:
            pass
        return self._nascent_children
Esempio n. 37
0
class ExplicitSocketMap(dict):
    def __init__(self, *args, **kw):
        dict.__init__(self, *args, **kw)
        self.__lock = Lock()
        self.__notifier = SocketMapNotifier(self)
        return
    def wakeup(self):
        self.__lock.acquire()
        try:
            self.__notifier.wakeup()
        finally:
            self.__lock.release()
        return
Esempio n. 38
0
class VirtualSubNet:
    def __init__(self, owner):
        self._lock = Lock()
        self._thread = None
        self.owner = owner
        return

    def start(self):
        self._lock.acquire()
        try:
            if not self._thread:
                t = VirtualSubNetThread(self.owner)
                t.start()
                # Add interlock for successful start-up... (wait on Q for
                # 10 seconds).
                self._thread = t
        finally:
            self._lock.release()
        return

    def stop(self):
        self._lock.acquire()
        try:
            if self._thread:
                self._thread.stop()
                self._thread = None
        finally:
            self._lock.release()
        return
Esempio n. 39
0
class UniqueID(PersistentDataObject):
    def __init__(self,node):
        self._lock = Lock()
        self.id = 0
        PersistentDataObject.__init__(self,node)
        self.load()
    def allocate_id(self):
        self._lock.acquire()
        try:
            id = self.id
            self.id += 1
            self.save('id')
        finally:
            self._lock.release()
        return id
Esempio n. 40
0
 def __init__(self):
     super(DRASManager, self).__init__()
     self.__scheduled = None
     self.__observers = {}
     self.__lock = Lock()
     self.running = 0
     return
Esempio n. 41
0
 def __init__(self, port):
     self.lock = Lock()    
     self.port = port
     self.units = {}
     self.connected = 0
     if not port.is_open():
         port.open()
Esempio n. 42
0
 def __init__(self):
     self.observers = {}
     self.data = None
     self.running = False
     self._ob_lock = Lock()
     super(BrivoDispatcher, self).__init__()
     return
Esempio n. 43
0
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.lock = Lock()
     self.pool = ThreadPool(3)
     self.queue = Queue()
     self.simple_action_counter = 0
     return
Esempio n. 44
0
 def __init__(self):
     self.__alarm_queue = Queue()
     self.__current_thread = None
     self.__lock = Lock()
     self._init_default_attribute_values()
     Client.__init__(self)
     return
 def __init__(self, *args, **kw):
     DefaultTestFixture.__init__(self, *args,**kw)
     EventConsumerMixin.__init__(self, self.change_of_value)
     self.__event_lock = Lock()
     self.__event_updated_values = {}
     self._cov_counter = 0
     return
Esempio n. 46
0
class TunnelManager(CompositeNode):
    def __init__(self, *args):
        global PTY_DEVS
        self._lock = Lock()
        self._pty_devs = []
        self._ptys_allocated = 0
        module_lock.acquire()
        try:
            if PTY_DEVS is None:
                PTY_DEVS = []
                for major in 'wxyz':
                    for minor in '0123456789abcdef':
                        PTY_DEVS.append('/dev/pty%s%s' % (major, minor))
        finally:
            module_lock.release()
            
    def configure(self, config):
        # vcp_limit is a "hidden" attribute.
        set_attribute(self, 'vcp_limit', 64, config, int)
        CompositeNode.configure(self, config)
        
    def configuration(self):
        config = CompositeNode.configuration(self)
        get_attribute(self, 'vcp_limit', config, str)
        return config
    
    ##
    # Allocate a pseudo-terminal for use by the Port object.
    #
    # @return a string, ie. /dev/ptyr0. 
    def get_pty(self):
        global PTY_DEVS
        self._lock.acquire()
        try:
            while len(PTY_DEVS):
                pty = PTY_DEVS.pop()
                try:
                    # confirm that the pty is accessible.
                    fd = open(pty)
                    fd.close()
                    self._ptys_allocated += 1
                    return pty
                except:
                    pass
            raise EResourceError
        finally:
            self._lock.release()
Esempio n. 47
0
 def __init__(self):
     self._link = None #get 'actual' node
     self.link = None
     self._proxy_get = None #set to actual's preferred get method
     self._proxy_set = None
     self._proxy_start_exception = None
     self._proxy_sid = None
     self.proxy_direction = GET_ONLY #direction subscription "pushes" the data
     self._proxy_active_source = None
     self._proxy_active_destination = None
     self._proxy_active_lock = Lock()
     self._proxy_active_thread_lock = Lock()
     self._proxy_active_event = None
     self._proxy_trigger_counter = 0
     self._retry_win_high = 30
     EventConsumerMixin.__init__(self, self.change_of_value)
     self.debug = debug
Esempio n. 48
0
 def __init__(self):
     self._subscription_lock = Lock()
     self._subscribed = 0
     self._subscribers = {}
     self._last_value = None
     self._last_rcvd = None
     self._decode_indexes = {}
     return
Esempio n. 49
0
 def __init__(self, node):
     self.__lock = Lock()
     self.__last_save = {}
     self.max_seq = -1
     self.pending_seqs = []
     self.inprocess_seqs = []
     PersistentDataObject.__init__(self, node, auto_load=True)
     return
Esempio n. 50
0
 def __init__(self):
     self._lock = Lock()
     self._started = 0
     self._alarm = [] # can have a whole MESS o' alarms at startup...
     self._scheduled = None
     self.trigger_node_url_posn = None # allow source stamping
     self.trigger_node_msg_posn = None # allow source stamping
     self._waiting_alarm_sid = None
     ServiceNode.__init__(self)
Esempio n. 51
0
 def __init__(self):
     Node.__init__(self)
     self._dev_name = None  # Can programmatically override BEFORE start.
     self._lock = Lock()
     self._popen = None
     self._apps = []
     self._groups = []
     self._discovery_ts = None
     return
Esempio n. 52
0
 def __init__(self, timeout, scan_time):
     #self._c == {group_id:{addr:last_msg}}
     self._c = {}
     self._cache_lock = Lock() #can add more granular locking, if need be
     self._subscr_list = {} # == {(group_id,addr):[call_back_meth]}  ... 
     self.timeout = timeout
     if not scan_time:
         self.scan_time = max(self.timeout / 4, 30)
     self._scan_scheduled = None
Esempio n. 53
0
 def __init__(self, *args, **kw):
     dict.__init__(self, *args, **kw)
     self.__busy = False
     self.__lock = Lock()
     # The StubNotifier is used during the creation of the real
     # SocketMapNotifier().
     self.__notifier = StubNotifier()
     # Creating the SocketMapNotifier will add it to this SocketMap.
     self.__notifier = SocketMapNotifier(self)
     return
Esempio n. 54
0
 def __init__(self):
     self._history = None
     self._history_lock = Lock()
     self._sid = None
     self._nid = 1
     self._poll_failure = False
     self._scheduled = None
     self.running = False
     super(Kwh2Kw, self).__init__()
     return
Esempio n. 55
0
 class Consumer(EventConsumerAbstract):
     def __init__(self, *args, **kw):
         EventConsumerAbstract.__init__(self, *args, **kw)
         self.entries = []
         self.errors = []
         self.lock = Lock()
     def event_thread(self,event):
         # The values returned in the event:
         values = event.values
         # The column as read from the source Log instance:
         column_dict = event.source[event.seq]
         # A map of COLUMN_DICT keys to VALUES indexes.
         column_value_map = {
             'timestamp':0, 'reverse':1, 'c2':2, 'c3':3
             }
         # Validate that the list of values matches the actual column in
         # the log:
         for key,index in column_value_map.items():
             if not column_dict.has_key(key):
                 self.errors.append('column_dict has no %r key.' % key)
                 return
             if index >= len(values):
                 self.errors.append('Index(%r) >= len(values:%r).' %
                                    (index, len(values)))
                 return
             if column_dict[key] != values[index]:
                 self.errors.append(
                     'column_dict[%r]:%r != values[%r]:%r' % (
                     key, column_dict[key], index, values[index]))
                 return
         self.lock.acquire()
         try:
             # If any entries are left, the test will fail.
             self.entries.remove(values)
         except:
             # Also, if errors is not empty the test will fail.
             self.errors.append("Failed to find %r in entries." %
                                values)
         self.lock.release()
     def event_handler(self,event):
         t = Thread(target=self.event_thread, args=(event,))
         t.start()
         return