Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

Service.cpp

00001 #include "Service.h"
00002 #include "ArchivingWorkerGroup.h"
00003 #include "archiving/ArchRawScanResult.h"
00004 #include "archiving/ArchFitScanResult.h"
00005 
00006 #include "Sct/SctNames.h"
00007 #include "is/isinfo.h" 
00008 #include "Sct/IS/IOManagerIS.h"
00009 #include "SctData/TestResult.h"
00010 #include "SctData/ScanResult.h"
00011 #include "SctData/RawScanResult.h"
00012 #include "SctData/FitScanResult.h"
00013 #include <string>
00014 
00015 using namespace Sct;
00016 using namespace SctData;
00017 using namespace Sct::IS;
00018 using namespace boost;
00019 
00020 namespace SctArchivingService {
00021 
00022 ArchivingService::ArchivingService() : IPCObject(Archiving_C_ArchivingService_interfaceName, &server()) 
00023     , infoReceiver(new ISInfoReceiver(SctNames::getPartition())), group(new ArchivingWorkerGroup()) {    
00024 }
00025 
00026 
00027 IPCServer& ArchivingService::server() {
00028     static IPCServer* server = new IPCServer(Archiving_C_ArchivingService_serverName, SctNames::getPartition());
00029     return *server;
00030 }
00031 
00032 void ArchivingService::run() {
00033     cout<<" I am in ArchivingService::run() " <<endl;
00034     group->go(1);
00035     
00036     infoReceiver->subscribe("TestData", ".*TestResult.*", testDataISCallback,this);
00037     infoReceiver->subscribe(SctNames::getControlDataName().c_str(), ".*TestData.*", controlDataISCallback, this);
00038     infoReceiver->subscribe(SctNames::getFittedDataName().c_str(),  ".*FitScanResult.*", fitScanResultISCallback, this);
00039     infoReceiver->subscribe(SctNames::getEventDataName().c_str(), ".*RawScanResult.*", rawScanResultISCallback, this);
00040 }
00041 
00042 
00043 void ArchivingService::testDataISCallback(ISCallbackInfo * iscTest) {
00044     cout<<" I am in ArchivingService::testDataISCallback " <<endl;
00045     ArchivingService* aTest = static_cast<ArchivingService*>(iscTest->parameter());
00046     //cout<< " !!!! IS Object Name = " << isc->type().name()<<endl;
00047     aTest->archive(iscTest);
00048     
00049     
00050     /*
00051     if (isc->reason() != ISInfoCreated && isc->reason() != ISInfoUpdated ) return;
00052     shared_ptr<Serializable> ob = IOManagerIS::instance().read(*isc);
00053     cout << "!!!!!!!!! CLASS NAME ==== " << ob->getClassName() <<endl;
00054     if (ob == 0) {
00055         cerr << "Failed to get object from IS" << endl;
00056         return;
00057     }
00058 
00059     instance().group->push(ob);
00060     cout << "Bye bye Test" <<endl;
00061     */
00062 
00063 }
00064 
00065 void ArchivingService::controlDataISCallback(ISCallbackInfo * isc) {
00066     try {
00067         shared_ptr<TestData> testdata( new TestData() );
00068         isc->value(*testdata);
00069 
00070         if (isc->reason() == ISInfoCreated ) {
00071       cout << "Callback for new controldata object "<<endl;
00072 
00073       if (instance().group->findTest(*testdata).get() == 0 ) {
00074         cout << "Listener adding test" << endl;
00075         instance().group->addTest(testdata);
00076         cout << "Listener added test" << endl;
00077         //AT !!!!!! Just for now !!!!!!
00078         
00079       
00080       } 
00081       else {
00082         throw Sct::InvalidArgumentError(string("AnalysisService::TestCallback Test already exists: ")+string(isc->name()), __FILE__, __LINE__);
00083       }
00084       
00085       
00086     }
00087         
00088     } catch (Sct::Throwable& e) {
00089       e.sendToMrs(MRS_ERROR);
00090     }
00091 }
00092 
00093 void ArchivingService::rawScanResultISCallback(ISCallbackInfo * iscRaw) {
00094     cout<<" I am in ArchivingService::rawScanResultISCallback " <<endl;
00095      
00096     ArchivingService* aRaw = static_cast<ArchivingService*>(iscRaw->parameter());
00097     //cout<< " !!!! IS Object Name = " << isc->type().name()<<endl;
00098     aRaw->archive(iscRaw);
00099     
00100     
00101 
00102 
00103 }
00104 
00105 void ArchivingService::fitScanResultISCallback(ISCallbackInfo * iscFit) {
00106     cout<<" I am in ArchivingService::fitScanResultISCallback " <<endl;
00107      
00108     ArchivingService* aFit = static_cast<ArchivingService*>(iscFit->parameter());
00109     //cout<< " !!!! IS Object Name = " << isc->type().name()<<endl;
00110     aFit->archive(iscFit);
00111 
00112     
00113        
00114 
00115 }
00116 
00117 void ArchivingService::archive(ISCallbackInfo * isc) {
00118   //cout<<" I am in ArchivingService::archive " <<endl;
00119     
00120     if (isc->reason() != ISInfoCreated && isc->reason() != ISInfoUpdated ) return;
00121 
00122    
00123     
00124     
00125 
00126     shared_ptr<Serializable> ob = IOManagerIS::instance().read(*isc);
00127     cout << "!!!!!!!!! CLASS NAME ==== " << ob->getClassName() <<endl;
00128     if (ob == 0) {
00129         cerr << "Failed to get object from IS" << endl;
00130         return;
00131     }
00132 
00133     group->push(ob);
00134     cout << "PUSHED" <<endl;
00135     
00136 }
00137 
00138 
00139 
00140 
00141 ilu_T_CString ArchivingService::ping (ArchivingStatus *_status) {
00142     char* msg = new char[28];
00143     strcpy(msg, "Hello from ArchivingService");
00144     return msg;
00145 }
00146 
00147 
00148 ArchivingService& ArchivingService::instance() {
00149     if (!service)
00150         return initialize();
00151     return *service;
00152 }
00153 
00154 ArchivingService& ArchivingService::initialize() {
00155     if (!service) {
00156         service = new ArchivingService();
00157     }
00158     return *service;
00159 }
00160 
00161 ArchivingService* ArchivingService::service = 0;
00162 
00163 
00164 }

Generated on Thu Jul 15 09:50:53 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5