SctTestMain.cpp

00001 #include "TestApi.h"
00002 #include "Configuration.h"
00003 #include "Sct/Exception.h"
00004 
00005 #include "Sct_SctApi/SctApiServer.h"
00006 #include "Sct_SctApi/SctApiCrateServer.h"
00007 #include "sctConfIPC/configipc.h"
00008 #include "SctApi/Idiosyncrasy.h"
00009 
00010 #include <ipc/core.h>
00011 #include <ipc/object.h>
00012 #include <ipc/server.h>
00013 #include <pmg/pmg_initSync.h>
00014 #include <Sct/Addressing.h>
00015 #include <Sct/SctNames.h>
00016 
00017 #include <iostream>
00018 #include <boost/shared_ptr.hpp>
00019 
00020 using namespace std;
00021 using namespace boost;
00022 using namespace SctConfiguration;
00023 using namespace SctTest;
00024 
00025 IPCServer ipcServer;
00026 shared_ptr<SctConfiguration::Configuration> configServer;
00027 
00028 /*
00029  Obsolete:
00030   void pmgSynch(void *) {
00031     pmg_initSync();
00032 }
00033 */
00034 
00035 int main(int argc, char** argv) {
00036     Sct::setExceptionHandlers(argv[0]);
00037 
00038     IPCCore::init(argc,argv);
00039     IPCPartition p(::Sct::SctNames::getPartitionName());
00040     // Obsolete: ipcServer.reset(new IPCServer(Sct_SctApi_C_SctApi_serverName, p));
00041 
00042     try {
00043         //For some reason these 2 lines don't work - really strange bug...so use default constructor trick
00044         //configServer.reset(new ConfigIPC());
00045         //auto_ptr<TestApi> api(new TestApi(configServer));
00046     const Sct::UCID arbitraryUcid(0,0);
00047         SctApi::Idiosyncrasy id(arbitraryUcid);
00048 
00049         auto_ptr<TestApi> api(new TestApi(id));
00050 
00051         if (!SctTest::Configuration::instance().publish()) {
00052             cout << "Failed to publish Configuration" << endl;
00053             return 2;
00054         }
00055 
00056 //        if (!HighLevelApi::instance().publish()) {
00057 //            cout << "Failed to publish HighLevelApi" << endl;
00058 //            return 3;
00059 //        }
00060     
00061         auto_ptr<SctApiCrateServer> h2(new SctApiCrateServer(*api)); // probably this should be updated to be a "_destroy"ing deleter.
00062     
00063     SctApiServer::CrateDescriptors d; d.push_back(arbitraryUcid);
00064         auto_ptr<SctApiServer> h(new SctApiServer(d, Sct_SctApi::SctApiIPC::instanceName)); // probably this should be updated to be a "_destroy"ing deleter.
00065 
00066         // Try publishing it
00067         if (!h->publish()) {
00068             cout << "Failed to publish SctTestApi" << std::endl;
00069             return 2;
00070         }
00071 
00072         cout << "Serving...\n";
00073 
00074     // Obsolete:       ipcServer->doSoon(pmgSynch, NULL);
00075     pmg_initSync();
00076     ipcServer.run();
00077 
00078         cout << "Run over" << std::endl;
00079         h->withdraw();
00080         SctTest::Configuration::instance().withdraw();
00081 //        HighLevelApi::instance().withdraw();
00082 
00083     } catch(SctConfiguration::ConfigurationException &c) {
00084         std::cout << "ConfigurationException: " << c.what() << std::endl;
00085 
00086         MRSStream mrsStream(p);
00087         mrsStream << "SctTestApi" << MRS_FATAL << MRS_QUALIF("SctTestApi") << MRS_TEXT("Configuration server not running!") << ENDM;
00088 
00089         exit(1);
00090     }
00091 }

Generated on Mon Feb 6 14:01:29 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6