CMS 3D CMS Logo

VisWebFrameworkService.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisFramework/VisWebFrameworkBase/interface/VisWebFrameworkService.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisEventProcessorService.h"
00005 #include "VisFramework/VisFrameworkBase/interface/VisQueueProcessor.h"
00006 #include "VisFramework/VisFrameworkBase/interface/VisAppearanceService.h"
00007 #include "Iguana/WebFramework/interface/IgBrowserManager.h"
00008 #include "Iguana/Framework/interface/IgTwig.h"
00009 #include "Iguana/Studio/interface/IgDocumentData.h"
00010 #include "Iguana/Framework/interface/IgRepSet.h"
00011 #include "Iguana/Framework/interface/IgState.h"
00012 #include "Iguana/Framework/interface/IgArgsElement.h"
00013 #include "Iguana/Framework/interface/IgPluginLoader.h"
00014 #include "Iguana/Framework/interface/IgEnvsElement.h"
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 
00017 #include <classlib/utils/Log.h>
00018 #include <classlib/utils/Callback.h>
00019 #include <classlib/utils/DebugAids.h>
00020 
00021 #include <qfile.h>
00022 
00023 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00024 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00025 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00026 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00027 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00028 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00029 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00030 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00031 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00032 
00033 VisWebFrameworkService::VisWebFrameworkService (IgState *state)
00034     : IgWebService (state)
00035 {
00036     registerCallback ("nextEvent", lat::CreateCallback (this, &VisWebFrameworkService::nextEvent));
00037     registerCallback ("reconfigure", lat::CreateCallback (this, &VisWebFrameworkService::nextEvent));
00038 }
00039 
00040 void
00041 VisWebFrameworkService::doInitSession (IgState *state)
00042 {
00043     VisEventProcessorService *eventProcessorService 
00044         = VisEventProcessorService::get (state);
00045 
00046     VisAppearanceService *appearService = VisAppearanceService::get (state);
00047     if (! appearService)
00048     {
00049         appearService = new VisAppearanceService (state);
00050         ASSERT (appearService);
00051 
00052         IgEnvsElement *envs = IgEnvsElement::get (state);
00053         std::string configString;
00054         if (envs->getEnv ("IGUANA_CONFIG", configString))
00055         {       
00056             appearService->setConfiguration (configString);
00057         }
00058     }
00059 
00060     if (!eventProcessorService)
00061     {
00062         std::cerr << "Event processor initialised" << std::endl;
00063         std::cerr << "on state "<< state << std::endl;
00064         
00065         eventProcessorService = new VisEventProcessorService (state);    
00066         eventProcessorService
00067             ->onUnhandledException (lat::CreateCallback (this,
00068                                                          &VisWebFrameworkService::onUnhandledException));
00069 
00070         eventProcessorService->initEventProcessor ();
00071         
00072         IgDocumentData *dd = IgDocumentData::get (state);       
00073         if (! dd)
00074         {
00075             dd = new IgDocumentData (state, 0);     
00076         }
00077         dd->root("", true);
00078 
00079         // FIXME: this should move to IgWebStudio initialisation...
00080         IgBrowserManager *manager = IgBrowserManager::get (state);
00081         if (! manager)
00082         {
00083             manager = new IgBrowserManager (state);         
00084         }
00085 
00086         // FIXME: also this should go to WebStudio, probably...
00087         IgPluginLoader *loader = IgPluginLoader::get (state);
00088         if (! loader)
00089         {
00090             loader = new IgPluginLoader (state);            
00091         }
00092     }    
00093 }
00094 
00095 void
00096 VisWebFrameworkService::reconfigure (Arguments *arguments)
00097 {
00098     IgState *state = arguments->state ();
00099     QIODevice *outputDevice = arguments->outputDevice ();
00100     ArgumentsMap &args = *(arguments->args ());
00101     
00102     if (args.find ("parameterSet") == args.end ())
00103     {   
00104         this->sendError (outputDevice);
00105         return; 
00106     }
00107     
00108     this->doReconfigure (state, args["parameterSet"]);    
00109 }
00110 
00111 void
00112 VisWebFrameworkService::doReconfigure (IgState *state, 
00113                                        const std::string& parameterSet)
00114 {
00115     VisEventProcessorService *service = VisEventProcessorService::get (state);
00116     ASSERT (service);
00117     
00118     service->reInitEventProcessor (parameterSet); 
00119 }
00120 
00121 void
00122 VisWebFrameworkService::nextEvent (Arguments *arguments)
00123 {
00124     IgState *state = arguments->state ();
00125     QIODevice *outputDevice = arguments->outputDevice ();
00126     this->doNextEvent (state);
00127     this->sendDone (outputDevice);    
00128 }
00129 
00130 void
00131 VisWebFrameworkService::doNextEvent (IgState *state)
00132 {
00133     IgTwig *root = IgDocumentData::get (state)->root ();
00134     IgRepSet::invalidate (root, IgTwig::SELF_MASK);
00135     
00136     try 
00137     {
00138         if (VisEventProcessorService *eventProcessorService 
00139             = VisEventProcessorService::get (state)) 
00140         {
00141             (*eventProcessorService)->run (1);
00142         }
00143     }
00144     catch (...)
00145     {
00146         std::cerr << "Some exception occurred... But I dont care." << std::endl;        
00147     }
00148  
00149     if (VisQueueProcessor *proc = VisQueueProcessor::get (state))
00150         proc->scheduleNextEvent ();    
00151 }
00152 
00153 void
00154 VisWebFrameworkService::onUnhandledException (void)
00155 {
00156     std::cerr << "Unhandled exception occured" << std::endl;    
00157 }
00158 
00159 
00160 const char *
00161 VisWebFrameworkService::catalogLabel (void)
00162 {
00163     return "Framework";    
00164 }

Generated on Tue Jun 9 17:50:05 2009 for CMSSW by  doxygen 1.5.4