Use logic which idlequeue shall be used to idlequeue module.
This commit is contained in:
parent
f8e6635edf
commit
0f61260578
|
@ -16,11 +16,16 @@
|
|||
Idlequeues are Gajim's network heartbeat. Transports can be plugged as
|
||||
idle objects and be informed about possible IO.
|
||||
'''
|
||||
|
||||
import os
|
||||
import select
|
||||
import logging
|
||||
import gobject
|
||||
log = logging.getLogger('gajim.c.x.idlequeue')
|
||||
try:
|
||||
import gobject
|
||||
HAVE_GOBJECT = True
|
||||
except ImportError:
|
||||
HAVE_GOBJECT = False
|
||||
|
||||
|
||||
FLAG_WRITE = 20 # write only
|
||||
FLAG_READ = 19 # read only
|
||||
|
@ -31,6 +36,19 @@ PENDING_READ = 3 # waiting read event
|
|||
PENDING_WRITE = 4 # waiting write event
|
||||
IS_CLOSED = 16 # channel closed
|
||||
|
||||
def get_idlequeue():
|
||||
''' Get an appropriate idlequeue '''
|
||||
if os.name == 'nt':
|
||||
# gobject.io_add_watch does not work on windows
|
||||
return SelectIdleQueue()
|
||||
else:
|
||||
if HAVE_GOBJECT:
|
||||
# Gajim's default Idlequeue
|
||||
return GlibIdleQueue()
|
||||
else:
|
||||
# GUI less implementation
|
||||
return SelectIdleQueue()
|
||||
|
||||
|
||||
class IdleObject:
|
||||
'''
|
||||
|
@ -66,6 +84,10 @@ class IdleQueue:
|
|||
3. Check file descriptor of plugged objects for read, write and error
|
||||
events
|
||||
'''
|
||||
# (timeout, boolean)
|
||||
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
||||
PROCESS_TIMEOUT = (200, False)
|
||||
|
||||
def __init__(self):
|
||||
self.queue = {}
|
||||
|
||||
|
@ -315,6 +337,9 @@ class GlibIdleQueue(IdleQueue):
|
|||
Extends IdleQueue to use glib io_add_wath, instead of select/poll
|
||||
In another 'non gui' implementation of Gajim IdleQueue can be used safetly.
|
||||
'''
|
||||
# (timeout, boolean)
|
||||
# Boolean is True if timeout is specified in seconds, False means miliseconds
|
||||
PROCESS_TIMEOUT = (2, True)
|
||||
|
||||
def _init_idle(self):
|
||||
'''
|
||||
|
|
27
src/gajim.py
27
src/gajim.py
|
@ -2856,16 +2856,16 @@ class Interface:
|
|||
helpers.launch_browser_mailer(kind, url)
|
||||
|
||||
def process_connections(self):
|
||||
''' called each foo (200) miliseconds. Check for idlequeue timeouts.
|
||||
'''
|
||||
''' Called each foo (200) miliseconds. Check for idlequeue timeouts. '''
|
||||
try:
|
||||
gajim.idlequeue.process()
|
||||
except Exception:
|
||||
# Otherwise, an exception will stop our loop
|
||||
if gajim.idlequeue.__class__ == idlequeue.GlibIdleQueue:
|
||||
gobject.timeout_add_seconds(2, self.process_connections)
|
||||
timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
|
||||
if in_seconds:
|
||||
gobject.timeout_add_seconds(timeout, self.process_connections)
|
||||
else:
|
||||
gobject.timeout_add(200, self.process_connections)
|
||||
gobject.timeout_add(timeout, self.process_connections)
|
||||
raise
|
||||
return True # renew timeout (loop for ever)
|
||||
|
||||
|
@ -3110,15 +3110,7 @@ class Interface:
|
|||
else:
|
||||
gajim.log.setLevel(None)
|
||||
|
||||
# pygtk2.8+ on win, breaks io_add_watch.
|
||||
# We use good old select.select()
|
||||
if os.name == 'nt':
|
||||
gajim.idlequeue = idlequeue.SelectIdleQueue()
|
||||
else:
|
||||
# in a nongui implementation, just call:
|
||||
# gajim.idlequeue = IdleQueue() , and
|
||||
# gajim.idlequeue.process() each foo miliseconds
|
||||
gajim.idlequeue = idlequeue.GlibIdleQueue()
|
||||
gajim.idlequeue = idlequeue.get_idlequeue()
|
||||
# resolve and keep current record of resolved hosts
|
||||
gajim.resolver = resolver.get_resolver(gajim.idlequeue)
|
||||
gajim.socks5queue = socks5.SocksQueue(gajim.idlequeue,
|
||||
|
@ -3270,10 +3262,11 @@ class Interface:
|
|||
self.last_ftwindow_update = 0
|
||||
|
||||
gobject.timeout_add(100, self.autoconnect)
|
||||
if gajim.idlequeue.__class__ == idlequeue.GlibIdleQueue:
|
||||
gobject.timeout_add_seconds(2, self.process_connections)
|
||||
timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
|
||||
if in_seconds:
|
||||
gobject.timeout_add_seconds(timeout, self.process_connections)
|
||||
else:
|
||||
gobject.timeout_add(200, self.process_connections)
|
||||
gobject.timeout_add(timeout, self.process_connections)
|
||||
gobject.timeout_add_seconds(gajim.config.get(
|
||||
'check_idle_every_foo_seconds'), self.read_sleepy)
|
||||
|
||||
|
|
Loading…
Reference in New Issue