CvtTesterImpl.py

Go to the documentation of this file.
00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2004
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "CVT Tester"
00012 __author__  = "Jim Panetta <panetta@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = ("$Date: 2006/01/25 04:27:12 $").split(' ')[1]
00014 __version__ = "$Revision: 1.8 $"
00015 __release__  = "$Name: HEAD $"
00016 __credits__ = "SLAC"
00017 
00018 import LICOS.copyright_SLAC
00019 
00020 import sys, asyncore
00021 import threading
00022 from qt import *
00023 import psycopg
00024 
00025 from LICOS.core.thread.guiBridges         import GUIbridge
00026 from LICOS.lib.currValTable.CvtTester     import CvtTester
00027 from LICOS.lib.currValTable.CurrValClient import CurrValClient
00028 
00029 import LICOS.util.gOptions as gOptions
00030 from ISOC.TlmUtils.TlmRdbInterface import TlmRdbDb
00031 
00032 
00033 globalApp = QApplication([])
00034 killEvent = threading.Event()
00035 killEvent.clear()
00036 
00037 def asyncore_loop(timeout=1.0, use_poll=False, map=None):
00038   """replace the asyncore central loop and run it its own thread.
00039      Valid for Python 2.3.x
00040      Python 2.4 has an extra agument for loop, count.
00041   """
00042   if map is None:
00043       map = asyncore.socket_map
00044 
00045   if use_poll:
00046     if hasattr(select, 'poll'):
00047       poll_fun = asyncore.poll3
00048     else:
00049       poll_fun = asyncore.poll2
00050   else:
00051     poll_fun = asyncore.poll
00052 
00053   while map and not killEvent.isSet():
00054     poll_fun(timeout, map)
00055 
00056 class CvtTesterClient(CurrValClient):
00057   def __init__(self, host, port, mnemList, tlmdb, gui, guiBridge):
00058     CurrValClient.__init__(self, host, port, mnemList=mnemList)
00059     self.__items = {}
00060     self.__gui = gui
00061     self.__guiBridge = guiBridge
00062     self.__tlmdb = tlmdb
00063     pass
00064 
00065   def update(self, cv):
00066     # print "in update", cv.name
00067     self.__guiBridge.execGUImethodNR(self.__gui, self.__update, cv)
00068 
00069   def __update(self, cv):
00070     if cv.name not in self.__items:
00071       self.__items[cv.name] = QListViewItem(self.__gui.mnemonicTable)
00072       self.__items[cv.name].setText(0, cv.name)
00073     raw = cv.rawValue()
00074     self.__items[cv.name].setText( 1, str(raw) )
00075 
00076     egu = raw
00077     mObj = self.__tlmdb.mnem(cv.name)
00078     if mObj is not None:
00079       egu = mObj.conversion().egu(raw)
00080     self.__items[cv.name].setText( 2, str(egu) )
00081     self.__items[cv.name].setText( 3, str(cv.age()) )
00082     # self.__items[cv.name].repaint()
00083     self.__gui.update()
00084 
00085 
00086 class CvtTesterImpl(CvtTester):
00087   def __init__(self, cvtHost, cvtPort, mnemList, tlmdb, parent = None, name = None, fl = 0):
00088     CvtTester.__init__(self, parent, name, fl)
00089     self.__guiBridge = GUIbridge(threading.currentThread())
00090 
00091     self.__client = CvtTesterClient(cvtHost,cvtPort,mnemList, tlmdb, self, self.__guiBridge)
00092 
00093   def customEvent(self, e):
00094     """!\brief Post an event to the GUI thread.
00095 
00096     This method overrides the QObject base class's.  There is generally
00097     no reason to call this method directly.  It is called by the Qt
00098     infrastructure whenever the custom event is posted, e.g. by the following
00099     three methods of this class: createGUI, execGUImethodNR and execGUImethod.
00100 
00101     \param e A QEvent object
00102     """
00103     self.__guiBridge.handleCustomEvent(e)
00104 
00105 
00106 
00107 def usage():
00108   print """
00109 where:
00110   cvtHost       is the hostname of the CVT server
00111   cvtPort       is the connection port of the CVT server (typically 39800)
00112   cvList        is a quoted, comma separated list of requested current values
00113                 Ex: --cvList "LHKADAB33V,LHKADABTEMP"
00114   """
00115 
00116 def main():
00117   options = gOptions.Options(['cvtHost', 'cvtPort','cvList'])
00118   try:
00119     options.parse()
00120   except Exception, msg:
00121     options.usage(str(msg))
00122     usage()
00123     sys.exit()
00124 
00125   cvtHost = options.cvtHost
00126   cvtPort = int(options.cvtPort)
00127 
00128   mnemList = []
00129 
00130   if options.cvList is not None:
00131     tmp = options.cvList
00132     for mnem in tmp.split(','):
00133       mnemList.append(mnem)
00134 
00135   DSN = "user=trending dbname=trending host=gitow1 password=trending"
00136   db = psycopg.connect( DSN )
00137   dbc = db.cursor()
00138   tlmdb = TlmRdbDb(dbc)
00139 
00140   tlmdb.populate(source=79, build='B0-6-0')
00141 
00142 
00143 
00144   win = CvtTesterImpl(cvtHost, cvtPort, mnemList,tlmdb)
00145   globalApp.setMainWidget(win)
00146   win.show()
00147 
00148   QObject.connect(globalApp, SIGNAL("lastWindowClosed()"), globalApp, SLOT("quit()"))
00149 
00150   # start the asyncore loop.  Termination is set by killEvent
00151   threading.Thread(target=asyncore_loop).start()
00152   globalApp.exec_loop()
00153 
00154   killEvent.set()
00155 
00156 
00157 if __name__ == '__main__':
00158     main()

Generated on Thu Apr 27 20:52:41 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO