00001
00002
00003
00004
00005
00006 #include "GuiSvc/GuiSvc.h"
00007
00008 #include "GaudiKernel/SvcFactory.h"
00009 #include "GaudiKernel/MsgStream.h"
00010
00011 #include "GaudiKernel/Incident.h"
00012 #include "GaudiKernel/IIncidentSvc.h"
00013 #include "GaudiKernel/Property.h"
00014
00015
00016 #include "gui/GuiMgr.h"
00017 #include "gui/Menu.h"
00018 #include "gui/SubMenu.h"
00019 #include "gui/SimpleCommand.h"
00020
00021
00022 static SvcFactory<GuiSvc> a_factory;
00023 const ISvcFactory& GuiSvcFactory = a_factory;
00024
00025
00026
00027
00028
00030
00031 : Service(name,svc)
00032 {
00033
00034
00035
00036 declareProperty ("size", m_size=-300);
00037 declareProperty( "pause_interval", m_pause_interval=0);
00038 declareProperty( "paused", m_paused=true);
00039
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 StatusCode GuiSvc::initialize ()
00049 {
00050 using namespace gui;
00051 StatusCode status = Service::initialize ();
00052
00053
00054
00055 setProperties ();
00056
00057
00058 MsgStream log( msgSvc(), name() );
00059
00060
00061 m_guiMgr = new gui::GuiMgr(m_size, 2, m_pause_interval);
00062
00063
00064 IIncidentSvc* incsvc = 0;
00065 StatusCode sc = serviceLocator()->getService ("IncidentSvc",
00066 IID_IIncidentSvc, reinterpret_cast<IInterface*&>( incsvc ));
00067
00068 if( status.isFailure() ) return status;
00069
00070 incsvc->addListener(this, "BeginEvent", 100);
00071 incsvc->addListener(this, "EndEvent", 0);
00072
00073
00074 gui::SubMenu& sub_menu= m_guiMgr->subMenu();
00075
00076 sub_menu.addButton("set max event...",
00077 new SimpleCommand<GuiSvc>(this, &GuiSvc::queryEvtMax));
00078
00079 sub_menu.addButton("Quit Loop",
00080 new SimpleCommand<GuiSvc>(this, &GuiSvc::quit));
00081
00082 m_guiMgr->menu().add(new MenuClient<GuiSvc>(this));
00083
00084
00085 return status;
00086 }
00087
00088
00089 void GuiSvc::queryPause()
00090 {
00091 m_guiMgr->menu().query("Enter new pause interval in ms (0: no pause, -1 infinite)",
00092 &m_pause_interval);
00093 }
00094 void GuiSvc::queryEvtMax()
00095 {
00096 IProperty* glastPropMgr=0;
00097 StatusCode status =
00098 serviceLocator()->getService("EventSelector", IID_IProperty,
00099 reinterpret_cast<IInterface*&>( glastPropMgr ));
00100 if( status.isFailure() ) return;
00101
00102 IntegerProperty evtMax("EvtMax",0);
00103 status = glastPropMgr->getProperty( &evtMax );
00104 if (status.isFailure()) return;
00105
00106 int max_event = evtMax.value();
00107 m_guiMgr->menu().query("Enter new max_event",& max_event);
00108
00109 evtMax = max_event;
00110 status = glastPropMgr->setProperty( evtMax );
00111 glastPropMgr->release();
00112
00113 }
00114
00115
00116 void GuiSvc::quit() {
00117 IProperty* glastPropMgr=0;
00118 StatusCode status =
00119 serviceLocator()->getService("EventSelector", IID_IProperty,
00120 reinterpret_cast<IInterface*&>( glastPropMgr ));
00121 if( status.isFailure() ) return;
00122
00123 IntegerProperty evtMax("EvtMax",0);
00124 status = glastPropMgr->getProperty( &evtMax );
00125 if (status.isFailure()) return;
00126
00127 evtMax = -1;
00128 status = glastPropMgr->setProperty( evtMax );
00129 glastPropMgr->release();
00130 m_guiMgr->resume();
00131 }
00132
00133
00134 void GuiSvc::handle(const Incident &inc)
00135 {
00136 if( inc.type()=="BeginEvent")beginEvent();
00137 else if(inc.type()=="EndEvent")endEvent();
00138
00139 }
00140
00141
00142 void GuiSvc::beginEvent()
00143 {
00144 using namespace gui;
00145 static bool first=true;
00146 if( first) { first=false;
00147
00148
00149 m_guiMgr->setState( m_paused? GuiMgr::PAUSED : GuiMgr::RUNNING);
00150 MsgStream log( msgSvc(), name() );
00151
00152 log << MSG::INFO << "starting GuiSvc GUI in "
00153 << (m_guiMgr->state()==GuiMgr::PAUSED? "PAUSED": "RUNNING" ) << " state" << endreq;
00154 m_guiMgr->menu().run();
00155 }
00156 m_guiMgr->begin_event();
00157 }
00158
00159 void GuiSvc::endEvent()
00160 {
00161 m_guiMgr->end_event();
00162 }
00163
00164
00165
00166 StatusCode GuiSvc::finalize ()
00167 {
00168 StatusCode status = StatusCode::SUCCESS;
00169
00170 delete m_guiMgr;
00171 return status;
00172 }
00174 StatusCode GuiSvc::queryInterface(const IID& riid, void** ppvInterface) {
00175 if ( IID_IGuiSvc.versionMatch(riid) ) {
00176 *ppvInterface = (IGuiSvc*)this;
00177 }
00178 else {
00179 return Service::queryInterface(riid, ppvInterface);
00180 }
00181 addRef();
00182 return SUCCESS;
00183 }
00184