Use logic which idlequeue shall be used to idlequeue module.

This commit is contained in:
Stephan Erb 2009-01-11 17:11:17 +00:00
parent f8e6635edf
commit 0f61260578
2 changed files with 42 additions and 24 deletions

View File

@ -16,11 +16,16 @@
Idlequeues are Gajim's network heartbeat. Transports can be plugged as Idlequeues are Gajim's network heartbeat. Transports can be plugged as
idle objects and be informed about possible IO. idle objects and be informed about possible IO.
''' '''
import os
import select import select
import logging import logging
import gobject
log = logging.getLogger('gajim.c.x.idlequeue') log = logging.getLogger('gajim.c.x.idlequeue')
try:
import gobject
HAVE_GOBJECT = True
except ImportError:
HAVE_GOBJECT = False
FLAG_WRITE = 20 # write only FLAG_WRITE = 20 # write only
FLAG_READ = 19 # read only FLAG_READ = 19 # read only
@ -31,6 +36,19 @@ PENDING_READ = 3 # waiting read event
PENDING_WRITE = 4 # waiting write event PENDING_WRITE = 4 # waiting write event
IS_CLOSED = 16 # channel closed 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: class IdleObject:
''' '''
@ -66,6 +84,10 @@ class IdleQueue:
3. Check file descriptor of plugged objects for read, write and error 3. Check file descriptor of plugged objects for read, write and error
events events
''' '''
# (timeout, boolean)
# Boolean is True if timeout is specified in seconds, False means miliseconds
PROCESS_TIMEOUT = (200, False)
def __init__(self): def __init__(self):
self.queue = {} self.queue = {}
@ -315,6 +337,9 @@ class GlibIdleQueue(IdleQueue):
Extends IdleQueue to use glib io_add_wath, instead of select/poll Extends IdleQueue to use glib io_add_wath, instead of select/poll
In another 'non gui' implementation of Gajim IdleQueue can be used safetly. 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): def _init_idle(self):
''' '''

View File

@ -2856,16 +2856,16 @@ class Interface:
helpers.launch_browser_mailer(kind, url) helpers.launch_browser_mailer(kind, url)
def process_connections(self): def process_connections(self):
''' called each foo (200) miliseconds. Check for idlequeue timeouts. ''' Called each foo (200) miliseconds. Check for idlequeue timeouts. '''
'''
try: try:
gajim.idlequeue.process() gajim.idlequeue.process()
except Exception: except Exception:
# Otherwise, an exception will stop our loop # Otherwise, an exception will stop our loop
if gajim.idlequeue.__class__ == idlequeue.GlibIdleQueue: timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
gobject.timeout_add_seconds(2, self.process_connections) if in_seconds:
gobject.timeout_add_seconds(timeout, self.process_connections)
else: else:
gobject.timeout_add(200, self.process_connections) gobject.timeout_add(timeout, self.process_connections)
raise raise
return True # renew timeout (loop for ever) return True # renew timeout (loop for ever)
@ -3110,15 +3110,7 @@ class Interface:
else: else:
gajim.log.setLevel(None) gajim.log.setLevel(None)
# pygtk2.8+ on win, breaks io_add_watch. gajim.idlequeue = idlequeue.get_idlequeue()
# 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()
# resolve and keep current record of resolved hosts # resolve and keep current record of resolved hosts
gajim.resolver = resolver.get_resolver(gajim.idlequeue) gajim.resolver = resolver.get_resolver(gajim.idlequeue)
gajim.socks5queue = socks5.SocksQueue(gajim.idlequeue, gajim.socks5queue = socks5.SocksQueue(gajim.idlequeue,
@ -3270,10 +3262,11 @@ class Interface:
self.last_ftwindow_update = 0 self.last_ftwindow_update = 0
gobject.timeout_add(100, self.autoconnect) gobject.timeout_add(100, self.autoconnect)
if gajim.idlequeue.__class__ == idlequeue.GlibIdleQueue: timeout, in_seconds = gajim.idlequeue.PROCESS_TIMEOUT
gobject.timeout_add_seconds(2, self.process_connections) if in_seconds:
gobject.timeout_add_seconds(timeout, self.process_connections)
else: else:
gobject.timeout_add(200, self.process_connections) gobject.timeout_add(timeout, self.process_connections)
gobject.timeout_add_seconds(gajim.config.get( gobject.timeout_add_seconds(gajim.config.get(
'check_idle_every_foo_seconds'), self.read_sleepy) 'check_idle_every_foo_seconds'), self.read_sleepy)