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);
00031 IPCPartition p("SCT");
00032 ipcServer.reset(new IPCServer(Sct_SctApi_C_SctApi_serverName, p));
00033
00034 try {
00035
00036
00037
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
00046
00047
00048
00049
00050 auto_ptr<SctApiServer> h(new SctApiServer(*api, Sct_SctApi_C_SctApi_instanceName, ipcServer.get()));
00051
00052
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
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 }