Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
asyncipp._IPPConnectionThread Class Reference

An asynchronous libcups API using IPP with a separate worker thread. More...

List of all members.

Public Member Functions

def __init__
def __del__
def set_auth_info
def run

Public Attributes

 host
 port
 user
 idle

Private Member Functions

def _auth
def _reply
def _error

Private Attributes

 _queue
 _conn
 _encryption
 _reply_handler
 _error_handler
 _auth_handler
 _auth_queue
 _destroyed

Detailed Description

An asynchronous libcups API using IPP with a separate worker thread.

This is the worker thread.

Definition at line 43 of file asyncipp.py.


Constructor & Destructor Documentation

def asyncipp._IPPConnectionThread.__init__ (   self,
  queue,
  conn,
  reply_handler = None,
  error_handler = None,
  auth_handler = None,
  user = None,
  host = None,
  port = None,
  encryption = None 
)

Definition at line 46 of file asyncipp.py.

00046 
00047                   encryption=None):
00048                   
00049         threading.Thread.__init__ (self)
00050         self.setDaemon (True)
00051         self._queue = queue
00052         self._conn = conn
00053         self.host = host
00054         self.port = port
00055         self._encryption = encryption
00056         self._reply_handler = reply_handler
00057         self._error_handler = error_handler
00058         self._auth_handler = auth_handler
00059         self._auth_queue = Queue.Queue (1)
00060         self.user = user
00061         self._destroyed = False
00062         debugprint ("+%s" % self)

Definition at line 63 of file asyncipp.py.

00063 
00064     def __del__ (self):
00065         debug.debugprint ("-%s" % self)


Member Function Documentation

def asyncipp._IPPConnectionThread._auth (   self,
  prompt,
  conn = None,
  method = None,
  resource = None 
) [private]

Definition at line 165 of file asyncipp.py.

00165 
00166     def _auth (self, prompt, conn=None, method=None, resource=None):
00167         def prompt_auth (prompt):
00168             gtk.gdk.threads_enter ()
00169             if conn == None:
00170                 self._auth_handler (prompt, self._conn)
00171             else:
00172                 self._auth_handler (prompt, self._conn, method, resource)
00173 
00174             gtk.gdk.threads_leave ()
00175             return False
00176 
00177         if self._auth_handler == None:
00178             return ""
00179 
00180         gobject.idle_add (prompt_auth, prompt)
00181         password = self._auth_queue.get ()
00182         return password

Here is the caller graph for this function:

def asyncipp._IPPConnectionThread._error (   self,
  exc 
) [private]

Definition at line 194 of file asyncipp.py.

00194 
00195     def _error (self, exc):
00196         def send_error (handler, exc):
00197             if not self._destroyed:
00198                 gtk.gdk.threads_enter ()
00199                 handler (self._conn, exc)
00200                 gtk.gdk.threads_leave ()
00201             return False
00202 
00203         if not self._destroyed and self._error_handler:
00204             debugprint ("Add %s to idle" % self._error_handler)
00205             gobject.idle_add (send_error, self._error_handler, exc)

Here is the caller graph for this function:

def asyncipp._IPPConnectionThread._reply (   self,
  result 
) [private]

Definition at line 183 of file asyncipp.py.

00183 
00184     def _reply (self, result):
00185         def send_reply (handler, result):
00186             if not self._destroyed:
00187                 gtk.gdk.threads_enter ()
00188                 handler (self._conn, result)
00189                 gtk.gdk.threads_leave ()
00190             return False
00191 
00192         if not self._destroyed and self._reply_handler:
00193             gobject.idle_add (send_reply, self._reply_handler, result)

Here is the caller graph for this function:

Definition at line 69 of file asyncipp.py.

00069 
00070     def run (self):
00071         if self.host == None:
00072             self.host = cups.getServer ()
00073         if self.port == None:
00074             self.port = cups.getPort ()
00075         if self._encryption == None:
00076             self._encryption = cups.getEncryption ()
00077 
00078         if self.user:
00079             cups.setUser (self.user)
00080         else:
00081             self.user = cups.getUser ()
00082 
00083         cups.setPasswordCB2 (self._auth)
00084 
00085         try:
00086             conn = cups.Connection (host=self.host,
00087                                     port=self.port,
00088                                     encryption=self._encryption)
00089             self._reply (None)
00090         except RuntimeError, e:
00091             conn = None
00092             self._error (e)
00093 
00094         while True:
00095             # Wait to find out what operation to try.
00096             debugprint ("Awaiting further instructions")
00097             self.idle = self._queue.empty ()
00098             item = self._queue.get ()
00099             debugprint ("Next task: %s" % repr (item))
00100             if item == None:
00101                 # Our signal to quit.
00102                 self._queue.task_done ()
00103                 break
00104 
00105             self.idle = False
00106             (fn, args, kwds, rh, eh, ah) = item
00107             if rh != False:
00108                 self._reply_handler = rh
00109             if eh != False:
00110                 self._error_handler = eh
00111             if ah != False:
00112                 self._auth_handler = ah
00113 
00114             if fn == True:
00115                 # Our signal to change user and reconnect.
00116                 self.user = args[0]
00117                 cups.setUser (self.user)
00118                 debugprint ("Set user=%s; reconnecting..." % self.user)
00119                 cups.setPasswordCB2 (self._auth)
00120 
00121                 try:
00122                     conn = cups.Connection (host=self.host,
00123                                             port=self.port,
00124                                             encryption=self._encryption)
00125                     debugprint ("...reconnected")
00126 
00127                     self._queue.task_done ()
00128                     self._reply (None)
00129                 except RuntimeError, e:
00130                     debugprint ("...failed")
00131                     self._queue.task_done ()
00132                     self._error (e)
00133 
00134                 continue
00135 
00136             # Normal IPP operation.  Try to perform it.
00137             try:
00138                 debugprint ("Call %s" % fn)
00139                 result = fn (conn, *args, **kwds)
00140                 if fn == cups.Connection.adminGetServerSettings.__call__:
00141                     # Special case for a rubbish bit of API.
00142                     if result == {}:
00143                         # Authentication failed, but we aren't told that.
00144                         raise cups.IPPError (cups.IPP_NOT_AUTHORIZED, '')
00145 
00146                 debugprint ("...success")
00147                 self._reply (result)
00148             except Exception, e:
00149                 debugprint ("...failure")
00150                 self._error (e)
00151 
00152             self._queue.task_done ()
00153 
00154         debugprint ("Thread exiting")
00155         self._destroyed = True
00156         del self._conn # already destroyed
00157         del self._reply_handler
00158         del self._error_handler
00159         del self._auth_handler
00160         del self._queue
00161         del self._auth_queue
00162         del conn
00163 
00164         cups.setPasswordCB2 (None)

Here is the call graph for this function:

def asyncipp._IPPConnectionThread.set_auth_info (   self,
  password 
)

Definition at line 66 of file asyncipp.py.

00066 
00067     def set_auth_info (self, password):
00068         self._auth_queue.put (password)


Member Data Documentation

Definition at line 57 of file asyncipp.py.

Definition at line 58 of file asyncipp.py.

Definition at line 51 of file asyncipp.py.

Definition at line 60 of file asyncipp.py.

Definition at line 54 of file asyncipp.py.

Definition at line 56 of file asyncipp.py.

Definition at line 50 of file asyncipp.py.

Definition at line 55 of file asyncipp.py.

Definition at line 52 of file asyncipp.py.

Definition at line 96 of file asyncipp.py.

Definition at line 53 of file asyncipp.py.

Definition at line 59 of file asyncipp.py.


The documentation for this class was generated from the following file: