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
00030
00031
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
00041
00042 try {
00043
00044
00045
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
00057
00058
00059
00060
00061 auto_ptr<SctApiCrateServer> h2(new SctApiCrateServer(*api));
00062
00063 SctApiServer::CrateDescriptors d; d.push_back(arbitraryUcid);
00064 auto_ptr<SctApiServer> h(new SctApiServer(d, Sct_SctApi::SctApiIPC::instanceName));
00065
00066
00067 if (!h->publish()) {
00068 cout << "Failed to publish SctTestApi" << std::endl;
00069 return 2;
00070 }
00071
00072 cout << "Serving...\n";
00073
00074
00075 pmg_initSync();
00076 ipcServer.run();
00077
00078 cout << "Run over" << std::endl;
00079 h->withdraw();
00080 SctTest::Configuration::instance().withdraw();
00081
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 }