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

SctTestMain.cpp

00001 #include "TestApi.h"
00002 #include "Configuration.h"
00003 #include "Sct/Exception.h"
00004 
00005 #include "Sct_SctApi/SctApiServer.h"
00006 #include "sctConf/configipc.h"
00007 
00008 #include <ipc/object.h>
00009 #include <ipc/server.h>
00010 #include <pmg/pmg_initSync.h>
00011 
00012 #include <iostream>
00013 #include <boost/shared_ptr.hpp>
00014 
00015 using namespace std;
00016 using namespace boost;
00017 using namespace SctConfiguration;
00018 using namespace SctTest;
00019 
00020 auto_ptr<IPCServer> ipcServer;
00021 shared_ptr<SctConfiguration::Configuration> configServer;
00022 
00023 void pmgSynch(void *) {
00024     pmg_initSync();
00025 }
00026 
00027 int main(int argc, char** argv) {
00028     Sct::setExceptionHandlers(argv[0]);
00029 
00030     IPCCore::init(true); // Try reentrant for DDC IS callbacks
00031     IPCPartition p("SCT");
00032     ipcServer.reset(new IPCServer(Sct_SctApi_C_SctApi_serverName, p));
00033 
00034     try {
00035         //For some reason these 2 lines don't work - really strange bug...so use default constructor trick
00036         //configServer.reset(new ConfigIPC());
00037         //auto_ptr<TestApi> api(new TestApi(configServer));
00038         auto_ptr<TestApi> api(new TestApi());
00039 
00040         if (!SctTest::Configuration::instance().publish()) {
00041             cout << "Failed to publish Configuration" << endl;
00042             return 2;
00043         }
00044 
00045 //        if (!HighLevelApi::instance().publish()) {
00046 //            cout << "Failed to publish HighLevelApi" << endl;
00047 //            return 3;
00048 //        }
00049 
00050         auto_ptr<SctApiServer> h(new SctApiServer(*api, Sct_SctApi_C_SctApi_instanceName, ipcServer.get()));
00051 
00052         // Try publishing it
00053         if (!h->publish()) {
00054             cout << "Failed to publish SctTestApi" << std::endl;
00055             return 2;
00056         }
00057 
00058         cout << "Serving...\n";
00059 
00060         ipcServer->doSoon(pmgSynch, NULL);
00061         ipcServer->run();
00062 
00063         cout << "Run over" << std::endl;
00064         h->withdraw();
00065         SctTest::Configuration::instance().withdraw();
00066 //        HighLevelApi::instance().withdraw();
00067 
00068     } catch(SctConfiguration::ConfigurationException &c) {
00069         std::cout << "ConfigurationException: " << c.what() << std::endl;
00070 
00071         MRSStream mrsStream(p);
00072         mrsStream << "SctTestApi" << MRS_FATAL << MRS_QUALIF("SctTestApi") << MRS_TEXT("Configuration server not running!") << ENDM;
00073 
00074         exit(1);
00075     }
00076 }

Generated on Thu Jul 8 11:41:14 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5