runTestService.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <iostream>
00027 #include <vector>
00028
00029 #include <signal.h>
00030 #include <argp.h>
00031
00032
00033 #include <ActiveObject.hpp>
00034 #include <ActiveObjectAce.hpp>
00035 #include <ActiveObjectManager.hpp>
00036 #include <ActiveObjectManagerAce.hpp>
00037 #include <CommunicationGateway.hpp>
00038
00039
00040 #include <DataFactory.hpp>
00041 #include <EntityDescriptionFactory.hpp>
00042 #include <EntityDescriptionRepository.hpp>
00043 #include <EntityRepository.hpp>
00044 #include <FilePathSearch.hpp>
00045 #include <Service.hpp>
00046 #include <ServiceBuildTask.hpp>
00047 #include <ServiceConfiguration.hpp>
00048 #include <ServiceTypeDescriptionFactory.hpp>
00049 #include <ServiceTypeDescriptionRepository.hpp>
00050 #include <Time.hpp>
00051 #include <XmlDocument.hpp>
00052 #include <XmlElement.hpp>
00053
00054
00055 #include "TestService.hpp"
00056
00057
00058 using std::cout;
00059 using std::endl;
00060
00061
00062 using mermaid::support::activeobject::ActiveObject;
00063 using mermaid::support::activeobject::ActiveObjectAce;
00064 using mermaid::support::activeobject::ActiveObjectManager;
00065 using mermaid::support::activeobject::ActiveObjectManagerAce;
00066 using mermaid::support::activeobject::Task;
00067 using mermaid::support::communication::CommunicationGateway;
00068 using mermaid::support::data::DataFactory;
00069 using boost::shared_ptr;
00070
00071 using mermaid::support::service::EntityDescriptionFactory;
00072 using mermaid::support::service::EntityDescriptionRepository;
00073 using mermaid::support::service::EntityRepository;
00074 using mermaid::support::service::Service;
00075 using mermaid::support::service::ServiceBuildTask;
00076 using mermaid::support::service::ServiceConfiguration;
00077 using mermaid::support::service::ServiceTypeDescriptionFactory;
00078 using mermaid::support::service::ServiceTypeDescriptionRepository;
00079 using mermaid::support::service::ServiceRequest;
00080 using mermaid::support::system::Time;
00081 using mermaid::support::system::FilePathSearch;
00082 using mermaid::support::xml::XmlDocument;
00083 using mermaid::support::xml::XmlElement;
00084
00085
00086
00087
00088 std::vector<std::string> dataDescriptionVector;
00089 std::vector<std::string> entityDescriptionVector;
00090 std::vector<std::string> pathVector;
00091 std::vector<std::string> serviceDescriptionVector;
00092
00093 shared_ptr<ActiveObject> ioActiveObject;
00094
00095 void exit_program (int sig)
00096 {
00097
00098
00099
00100 std::cerr << "Catched SIGINT..." << std::endl;
00101 std::cerr << "\tnumber of running Active Objects: " << ActiveObjectManagerAce::getInstance()->getNumberOfActiveObjects() << std::endl;
00102 std::cerr << "\tshutting down ActiveObjects..." << std::endl;
00103 ActiveObjectManagerAce::getInstance()->stopAllActiveObjects();
00104 std::cerr << "\tnumber of running Active Objects: " << ActiveObjectManagerAce::getInstance()->getNumberOfActiveObjects() << std::endl;
00105 std::cerr << "\tShutdown procedure finished." << std::endl;
00106 }
00107
00108 static error_t parse_opt (int key, char *arg, struct argp_state *state)
00109 {
00110
00111
00112 switch (key) {
00113 case 'd': {
00114
00115
00116
00117
00118 dataDescriptionVector.push_back (std::string (arg));
00119 break;
00120 }
00121 case 'e': {
00122
00123
00124
00125
00126
00127
00128
00129 entityDescriptionVector.push_back (std::string (arg));
00130 break;
00131 }
00132 case 'p': {
00133
00134
00135 pathVector.push_back (std::string (arg));
00136 break;
00137 }
00138 case 's': {
00139
00140
00141
00142
00143
00144
00145 serviceDescriptionVector.push_back (std::string (arg));
00146 break;
00147 }
00148 default:
00149
00150 return ARGP_ERR_UNKNOWN;
00151 }
00152 return 0;
00153 };
00154
00155 const char *argp_program_version = "Built with mlgen (MeRMaID Loader Generator)";
00156 const char *argp_program_bug_address = "<mafb@isr.ist.utl.pt>";
00157
00158 int main (int argc, char *argv[])
00159 {
00160 signal (SIGINT, &exit_program);
00161
00162 static struct argp_option options[] = {
00163 {"entity-description", 'e', "file", 0, "Define Entity Description file to load"},
00164 {"service-type-description", 's', "file", 0, "Define Service Type Description file to load"},
00165 {"data-type-description", 'd', "file", 0, "Define Data Type Description file to load"},
00166 {"search-path", 'p', "path", 0, "Define search path where to look for files"},
00167 {0}
00168 };
00169
00170
00171
00172 static char doc[] = "Deploys MeRMaID services";
00173
00174 static struct argp argp = {options, parse_opt, 0, doc};
00175
00176
00177
00178 argp_parse (&argp, argc, argv, 0, 0, 0);
00179
00180
00181 pathVector.push_back ("/opt/mermaid/config");
00182 pathVector.push_back ("./");
00183 pathVector.push_back ("./");
00184
00185
00186 ioActiveObject = ActiveObjectManagerAce::getInstance()->createActiveObject();
00187
00188
00189 ioActiveObject->start();
00190
00191
00192
00193 ActiveObjectManagerAce::getInstance()->waitForActiveObjectsToStop();
00194
00195 return 0;
00196 };
00197
00198 void setupServiceA (char dataDescFile[], char serviceTypeDescFile[], char entityDescFile[], char configFile[], char serviceName[])
00199 {
00200
00201
00202 dataDescriptionVector.push_back ("ping-tool-data-description-file.xml");
00203
00204 dataDescriptionVector.push_back (dataDescFile);
00205
00206
00207
00208
00209 serviceDescriptionVector.push_back ("ping-tool-service-type-description-file.xml");
00210
00211 serviceDescriptionVector.push_back (serviceTypeDescFile);
00212
00213
00214
00215 entityDescriptionVector.push_back (entityDescFile);
00216 std::vector<std::string>::iterator pathIterator;
00217 for (pathIterator = pathVector.begin(); pathIterator != pathVector.end(); ++pathIterator) {
00218 std::string path = *pathIterator;
00219 std::cerr << "Loading path: " << path << std::endl;
00220 FilePathSearch::addSearchPath (path);
00221 }
00222
00223 std::vector<std::string>::iterator dataDescriptionIterator;
00224 for (dataDescriptionIterator = dataDescriptionVector.begin(); dataDescriptionIterator != dataDescriptionVector.end(); ++dataDescriptionIterator) {
00225 std::string dataDescriptionFile = *dataDescriptionIterator;
00226 std::cerr << "Loading data type description file: " << dataDescriptionFile << std::endl;
00227 shared_ptr<XmlDocument> dataDoc = shared_ptr<XmlDocument> (new XmlDocument());
00228 dataDoc->parseFile (dataDescriptionFile);
00229 DataFactory::loadDataDescription (dataDoc);
00230 }
00231
00232 std::vector<std::string>::iterator serviceDescriptionIterator;
00233 for (serviceDescriptionIterator = serviceDescriptionVector.begin(); serviceDescriptionIterator != serviceDescriptionVector.end(); ++serviceDescriptionIterator) {
00234 std::string serviceDescriptionFile = *serviceDescriptionIterator;
00235 std::cerr << "Loading service type description file: " << serviceDescriptionFile << std::endl;
00236 shared_ptr<XmlDocument> docServiceType = shared_ptr<XmlDocument> (new XmlDocument());
00237 docServiceType->parseFile (serviceDescriptionFile);
00238 shared_ptr<XmlElement> serviceTypeDescriptionList = docServiceType->getRootElement();
00239 shared_ptr<ServiceTypeDescriptionRepository> serviceTypeDescriptionRepository = ServiceTypeDescriptionRepository::getInstance();
00240 ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository (serviceTypeDescriptionRepository, serviceTypeDescriptionList);
00241 }
00242
00243 std::vector<std::string>::iterator entityDescriptionIterator;
00244 for (entityDescriptionIterator = entityDescriptionVector.begin(); entityDescriptionIterator != entityDescriptionVector.end(); ++entityDescriptionIterator) {
00245 std::string entityDescriptionFile = *entityDescriptionIterator;
00246 std::cerr << "Loading entity type description file: " << entityDescriptionFile << std::endl;
00247 shared_ptr<XmlDocument> docEntityDescription = shared_ptr<XmlDocument> (new XmlDocument());
00248 docEntityDescription->parseFile (entityDescriptionFile);
00249 shared_ptr<XmlElement> entityDescriptionList = docEntityDescription->getRootElement();
00250 shared_ptr<EntityDescriptionRepository> entityDescriptionRepository = EntityDescriptionRepository::getInstance();
00251 shared_ptr<ServiceTypeDescriptionRepository> serviceTypeDescriptionRepository = ServiceTypeDescriptionRepository::getInstance();
00252 EntityDescriptionFactory::populateEntityDescriptionRepository (entityDescriptionRepository, entityDescriptionList, serviceTypeDescriptionRepository);
00253 }
00254
00255
00256 shared_ptr<EntityRepository> aoEntityRepository (new EntityRepository());
00257
00258
00259 {
00260 shared_ptr<XmlDocument> serviceConfigurationDocument (new XmlDocument());
00261 serviceConfigurationDocument->parseFile (configFile);
00262 shared_ptr<ServiceConfiguration> serviceConfiguration (new ServiceConfiguration (serviceConfigurationDocument));
00263 shared_ptr<Task> buildTestService ( (Task*) new ServiceBuildTask<TestService> (ioActiveObject, aoEntityRepository, "MyComputer", serviceName, serviceConfiguration));
00264 ioActiveObject->addTask (buildTestService);
00265 }
00266 }
00267