Exemple #1
0
 def __init__(self):
     self._threadpool = None
     self._init_complete = False
     self._port = None
     self._request = {}  # k:(rqst_type, addr,) v: request object
     self.__update_freqs = {}
     self.__callbacks = {}
     self.__callback_lock = threading.Lock()
     self.__port_lock = threading.Lock()
     CompositeNode.__init__(self)
Exemple #2
0
 def __init__(self, port):
     self.port = port
     self._lock = threading.Lock()  #for coordinating between threads 
     self._condition = threading.Condition(self._lock)
     self._mutex = threading.Lock()  #allow only one exclusive access at a time
     self._running = 0
     self._thread = None
     self.debug = debug
     self._offline = 0
     self.point_dictionary = {}
     self.broadcast_lists = {}
     self.password = ''
Exemple #3
0
 def __init__(self):
     CompositeNode.__init__(self)
     self._internal_lock = threading.Lock()
     self._lock = threading.Lock()          # @todo - use a separate lock for reading and writing - C.Turner
     self._devlock = None
     self.poll = None
     self.file = None
     self._buf = array.array('c')
     self._lock_requests = 0
     
     self._blocking = 0
     return
Exemple #4
0
 def __init__(self, length=None):
     self.length = length
     self.datastream = StringIO.StringIO()
     self._lock = threading.Lock()
     self._condition = threading.Condition(self._lock)
     self._stream_closed = 0
     self._done_collecting = 0
Exemple #5
0
    def __init__(self, name):
        _logs_lock.acquire()
        try:
            if _logs.has_key(name):
                from mpx.lib.msglog import types
                raise ENameInUse(name, logtype=types.ERR)
            self._lock = threading.Lock()
            self._lock.acquire()
            _logs[name] = self
        finally:
            _logs_lock.release()
        try:
            self.name = name
            self.eval = RExec().r_eval
            self.path = properties.LOGFILE_DIRECTORY
            self.filename = os.path.join(self.path, self.name + ".log")
            self.data_manager = _LogDataManager(self.filename)

            self._slice_position = 0
            self.max_return_length = 100000
            self.last_values = self._get_last_row()
            # It is likely that the log contains a higher seq number than
            #  the one that was last saved by DataManager, if so, update it.
            # NOTE: the data manager will have a higher number if a trim_g* was
            #       done and then the log was closed.
            if self.last_values:
                if self.last_values[-1] >= self.data_manager.inspect_seq():
                    self.data_manager.set_seq(self.last_values[-1] + 1)
                else:
                    self.last_values = []
        finally:
            self._lock.release()
Exemple #6
0
 def __init__(self):
     self.__callbacks = {}
     self.__callback_lock = threading.Lock()
     self._rqst_queue = None
     self.running = False
     self.port = None
     super(WXT510AsciiNetwork, self).__init__()
Exemple #7
0
 def __init__(self):
     self._running = 0
     self.driver = None
     self.mac_address = None
     self.discovery_mode = 'None'
     CompositeNode.__init__(self)
     AutoDiscoveredNode.__init__(self)
     EventProducerMixin.__init__(self)
     self.device_map = {} #keyed by mac address of clients; value=Child node
     self._out_q = [] #request queue
     self._out_q_cv = threading.Condition()
     self._mutex = threading.Lock() #prevent multiple access to outbound commands
     self._registered_clients = {}
     self.transceiver_state = TransceiverState[0]
     self.cov = ChangeOfValueEvent(self, None, self.transceiver_state)
     self.debug = debug
     self.timeout = 10 #seconds
     self.who_is_interval = 10 #seconds
     self.default_discovered_protocol_module = None
     # @todo
     # initailize this through configuration
     self.default_discovered_protocol_module = feu
     self.transceiver_state = 0
     self.relay_node = '/interfaces/relay1'  #this is temporary, should be None
     self.active_devices = {}
     self.status = None
Exemple #8
0
 def __init__(self, *args):
     # This is required for use of older system, remove later...
     self.__system_lock = threading.Lock()
     self.__renaming_user = None
     self.__running = threading.Event()
     self.__sysadmin = None
     self.__anonymous = None
     super(UserManager, self).__init__(*args)
Exemple #9
0
 def __init__(self, *args):
     self.dispatcher = Dispatcher()
     self._lock = threading.Lock()
     self.roles = []
     self.readonly = []
     self.homepage = '/'
     self.__password = ''
     self.description = ''
     super(User, self).__init__(*args)
Exemple #10
0
 def __init__(self):
     self._last_result = None
     CompositeNode.__init__(self)
     EventProducerMixin.__init__(self)
     self._subscribe_lock = threading.Lock()
     self._subscribed = 0
     self._last_rcvd = 0
     self._cached_result = None
     self._msg_req_type = None
     self._device_node = None
     self._protocol_node = None
Exemple #11
0
 def __init__(self, log, period, trigger=None):
     self.log = log
     self.period = period
     self.poll = select.poll()
     self._lock = threading.Lock()
     self._scheduled = None
     self.running = 0
     self.msglog = mpx.lib.msglog
     self.columns = []
     self.trigger = trigger
     self._collect_failure = {}
Exemple #12
0
 def __init__(self, callback, buffer_size=1024):
     CrossThreadStream.__init__(self)
     self._lock = threading.Lock()
     self._pollout = select.poll()
     self._pollout.register(self.c_connection.fileno(), select.POLLOUT)
     self._callback = callback
     self.c_connection.setblocking(0)
     self.s_connection.setblocking(1)
     self._meta = {}
     self._buffer_size = buffer_size
     self._buffer = ''
Exemple #13
0
 def __init__(self):
     self._lock = threading.Lock()
     self._lock.acquire()
     try:
         self._poll_obj = select.poll()
         self._far_cmd_skt = None
         self._near_cmd_skt = None
         self._create_cmd_skts(self._tmp_dir)
         self._poll_obj.register(self._near_cmd_skt.fileno(), select.POLLIN)
     finally:
         self._lock.release()
     return
Exemple #14
0
    def __init__(self):
        CompositeNode.__init__(self)
        self._internal_lock = threading.Lock()
        self._lock = threading.RLock()
        self._devlock = None
        self.poll = None
        self.file = None
        self._buf = array.array('c')
        self._lock_requests = 0

        self._blocking = 0
        return
Exemple #15
0
 def __init__(self,name):
     self._write_lock = _threading.Lock()
     self._trim_lock = _threading.Lock()
     self._trim_lock.acquire()
     self._write_lock.acquire()
     try:
         self.name = name
         self._queue = []
         self.eval = _security.RExec().r_eval
         self.path = properties.LOGFILE_DIRECTORY
         self.filename = os.path.join(self.path, self.name + ".log.2")
         self.data_manager = LogDataManager(self.filename)
         # If our file doesn't exist and one without a version number
         #  does, rename it (upgrade).
         if (not os.path.exists(self.filename)
             and _prior_version_exists(self.name,self.path)):
             from mpx.upgrade.log import log_1
             old = log_1.LogObject(name)
             self.data_manager.upgrade(old.data_manager)
             os.rename(old.filename,self.filename)
             old.destroy()
             del(log_1)
         self._slice_position = 0
         self.last_values = self._get_last_row()
         # It is likely that the log contains a higher seq number than
         #  the one that was last saved by DataManager, if so, update it.
         # NOTE: the data manager will have a higher number if a trim_g* was
         #       done and then the log was closed.
         if self.last_values:
             if self.last_values[-1] >= self.data_manager.inspect_seq():
                 self.data_manager.set_seq(self.last_values[-1] + 1)
             else:
                 self.last_values = []
     finally:
         self._write_lock.release()
         self._trim_lock.release()
Exemple #16
0
 def __init__(self):
     self.__q = Queue.Queue()
     self.__lock = threading.Lock()
Exemple #17
0
 def __init__(self):
     self._process = None  # Object returned by popen2.Popen4()
     self._is_connected = 0  # 1 if connected, 0 otherwise
     self._lock = threading.Lock(
     )  # Lock to make connect/disconnect thread safe
Exemple #18
0
 def __init__(self,*args,**kw):
     self.__lock = threading.Lock()
     return
Exemple #19
0
 def configure(self, columns, min_size=250, max_size=500):
     self.set_limits(min_size, max_size)
     LogObject.configure(self, columns)
     self._trim_check = _threading.Lock()
     return
Exemple #20
0
class AVR(CompositeNode):
    # Thread-safe lock.  Should be extended to be process independant.
    _lock = threading.Lock()

    def __init__(self):
        CompositeNode.__init__(self)
        self.debug = 0

    ##
    # @see mpx.ion.host.Host#configure
    #
    def configure(self, config):
        CompositeNode.configure(self, config)
        set_attribute(self, 'ncounters', REQUIRED, config, int)
        set_attribute(self, 'nDIs', REQUIRED, config, int)
        set_attribute(self, 'nrelays', REQUIRED, config, int)
        set_attribute(self, 'ndallas_busses', REQUIRED, config, int)
        set_attribute(self, 'nGPIOs', REQUIRED, config, int)

        # Open the avr devices.
        self.avr = None
        self.avroob = None
        try:
            self.avr = open("/dev/avr", "r+")
            self.avroob = open("/dev/avroob", "r")
            self.p = select.poll()
            self.p.register(self.avroob, select.POLLIN)
            avr_maj_ver = ord(self.invoke_message('\x17\x00\x00')[0])
            if (avr_maj_ver < 2) and (self.nGPIOs > 0):
                self.nGPIOs = 0
                msglog.log('mpx',msglog.types.ERR,'No GPIOs created; AVR version is %s; should be 2.x or greater.' \
                           % self.version())
            # Attach the counters, relays and dallas busses to the AVR.
            config_list = (('mpx.ion.host.avr.counter', 'counter',
                            self.ncounters), ('mpx.ion.host.avr.di', 'DI',
                                              self.nDIs),
                           ('mpx.ion.host.avr.relay', 'relay', self.nrelays),
                           ('mpx.ion.host.avr.dallasbus', 'dallas',
                            self.ndallas_busses), ('mpx.ion.host.avr.gpio',
                                                   'gpio', self.nGPIOs))
            for module, prefix, count in config_list:
                for i in range(1, count + 1):
                    name = prefix + str(i)
                    config = {
                        'name': name,
                        'id': i,
                        'avr': self,
                        'parent': self
                    }
                    ion = mpx.lib.factory(module)
                    ion.configure(config)
        except:
            msglog.log('broadway', msglog.types.ERR,
                       "Failed to open avr device.")
            msglog.exception()
            self.p = select.poll()
            if self.avr:
                self.avr.close()
                self.avr = None
            if self.avroob:
                self.avroob.close()
                self.avroob = None
            pass

        return

    # Actual AVR code.

    ##
    # Lock AVR for safe access.
    #
    def lock(self):
        self._lock.acquire()
        return

    ##
    # Unlock AVR to allow access.
    #
    def unlock(self):
        self._lock.release()
        return

    ##
    # Print msg.
    #
    # @param msg  Message to be printed.
    #
    def dump(self, msg):
        for b in msg:
            print "%02x" % (ord(b)),
        print

    ##
    # Get the version of the AVR module.
    #
    # @return AVR Version number.
    #
    def version(self):
        rsp = self.invoke_message('\x17\x00\x00')
        return "%d.%d" % (ord(rsp[0]), ord(rsp[1]))

    def wait_for_oob(self):
        # Only used by the AVR event thread.
        self.p.poll()
        return

    ##
    # Send message to AVR.
    #
    # @param msg  Message to send.
    # @return  Response sent back from AVR.
    #
    def invoke_message(self, msg):
        self.lock()
        try:
            if self.debug:
                print '> ',
                self.dump(msg)
            self.avr.write(msg)
            hdr = self.avr.read(3)
            rsp = self.avr.read(ord(hdr[2]))
            if self.debug:
                print '< ',
                self.dump(rsp)
        finally:
            self.unlock()
            pass
        return rsp
Exemple #21
0
from _log import LogEvent
from _log import LogObjectInfo

from _binary import BinaryColumnConfiguration


class _LogDict(dict):
    def singleton_unload_hook(self):
        pass


from mpx.lib import _singleton

_logs = _singleton.ReloadableSingletonFactory(_LogDict)

_logs_lock = threading.Lock()


def _setup_new_log(name, class_ref):
    _logs_lock.acquire()
    try:
        if not _logs.has_key(name):
            _logs[name] = class_ref(name)
        elif not ((hasattr(_logs[name], '__outside_log')
                   and _logs[name].__outside_log)
                  or isinstance(_logs[name], class_ref)):
            # The existing instance is not an instanciation of class_ref, nor
            # of a class derived from class_ref.
            raise ENameInUse(name)
        log = _logs[name]
    finally:
Exemple #22
0
        0x00, 0x00, 0x00, 0x00, type, b_data[0], b_data[1], 0x00
    ])
    if (ext):
        pkt.extend(ext)  # add extension to hdr

    pkt.extend(
        array.array('B', [b_flags[0], b_flags[1], b_flags[2], b_flags[3]]))

    debug_print(1, 'Formed outgoing pkt:')
    if debug_lvl > 0:
        print_array_as_hex(pkt)

    return pkt


host_channel_lock = threading.Lock()


class RzHostPkt(object):
    def __init__(self, pkt=None):
        self._pkt = pkt

    def tofile(self, fileno):
        #only one request at a time - once we do sequence packets we can relax this
        host_channel_lock.acquire()
        try:
            #examine type of packet going to modem server and prepare for response
            type = self._pkt[6]
            self._pkt.tofile(fileno)
            #wait for ACK or response
        finally: