/home/coin/SVN-release/OS-1.0.0/OS/src/OSAgent/OSSolverAgent.cpp

Go to the documentation of this file.
00001 
00017 #include "OSSolverAgent.h"
00018 #include "WSUtil.h"
00019 
00020 #include <cstdlib>
00021 
00022 //#define DEBUG
00023 
00024 using std::string;
00025 using std::cout; 
00026 using std::endl;
00027 
00028 OSSolverAgent::OSSolverAgent(string solverURI) : OShL() {
00029         int nstart = 0;
00030         // parse the solverURI
00031         // get rid of http:// if it is there
00032         if (solverURI.find("http://") != string::npos) solverURI = solverURI.substr(7);
00033         // now find the first "/" and put in nstart
00034         nstart = solverURI.find("/", nstart);
00035         postURI = solverURI.substr(nstart, solverURI.size() - 1);
00036         // Do we have a port number
00037         string::size_type colonlocation = solverURI.find(":");
00038         if(colonlocation == string::npos) {
00039                 solverAddress = solverURI.substr(0, nstart);
00040                 solverPortNumber = 80;
00041         }
00042         else{
00043                 solverPortNumber = atoi( &solverURI.substr(colonlocation + 1, nstart - colonlocation - 1)[0] ) ;
00044                 solverAddress = solverURI.substr(0, colonlocation);
00045         }
00046 }
00047 
00048 OSSolverAgent::~OSSolverAgent() {
00049 }
00050 
00051 string OSSolverAgent::solve(string osil, string osol){
00052         string sOSrL ; 
00053         string theSOAP; 
00054         string solveResult;
00055         // CreateSOAPMessage inputs
00056         int numInputs = 2;
00057         string smethod = "solve";
00058         string msInputs[2];
00059         // package up the inputs
00060         // first run them through SAOPify, e.g. replace < with &lt; etc.
00061         msInputs[0] = WSUtil::SOAPify( osil) ;
00062         msInputs[1] = WSUtil::SOAPify( osol) ;
00063         string msInputNames[2] = {"osil", "osol"};
00064         string sSoapAction = "OSSolverService#solve";
00065         // create the soap
00066         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00067                                 smethod, msInputs, msInputNames, sSoapAction);
00068         // send the soap to the HTTP server
00069         //std::cout << "SEND THE SOAP " << std::endl;
00070         solveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00071         // desoapify the result -- i.e. replace &lt; with <  etc.
00072         //std::cout << "CALL DESOAP WITH THE FOLLOWING " << std::endl;
00073         //std::cout << solveResult << std::endl;
00074         solveResult = WSUtil::deSOAPify( solveResult);
00075         // strip out the OSxL that we want from the SOAP envelope
00076         //std::cout << "DONE WITH DESOAP " << std::endl;
00077         //std::cout << solveResult << std::endl;
00078         sOSrL = WSUtil::getOSxL(solveResult, "solve");
00079         //std::cout << "RETURN THE OSRL " << std::endl;
00080         //std::cout << sOSrL << std::endl;
00081         return sOSrL;
00082 }//end solve
00083 
00084 string OSSolverAgent::fileUpload( string osilFileName, string theOSiLFile){ 
00085         string theHTTPPOST=""; 
00086         string uploadResult="";
00087         string boundaryName = "AaB03x";
00088         theHTTPPOST = WSUtil::createFormDataUpload(solverAddress, postURI, 
00089                 osilFileName,  theOSiLFile, boundaryName);
00090         // send the soap to the HTTP server
00091         std::cout << "SEND THE FILE " << std::endl;
00092         //std::cout << theHTTPPOST << std::endl;
00093         uploadResult = WSUtil::sendSOAPMessage( theHTTPPOST, solverAddress, solverPortNumber);
00094         return uploadResult;
00095 }//end solve
00096 
00097 
00098 bool OSSolverAgent::send(string osil, string osol){
00099         string theSOAP;
00100         string sendResult;
00101         // CreateSOAPMessage inputs
00102         int numInputs = 2;
00103         string smethod = "send";
00104         string msInputs[2];
00105         // package up the inputs
00106         // first run them through SAOPify, e.g. replace < with &lt; etc.
00107         msInputs[0] = WSUtil::SOAPify( osil) ;
00108         msInputs[1] = WSUtil::SOAPify( osol) ;
00109         string msInputNames[2] = {"osil", "osol"};
00110         string sSoapAction = "OSSolverService#send";
00111         // create the soap
00112         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00113                                 smethod, msInputs, msInputNames, sSoapAction);
00114         // send the soap to the HTTP server
00115         sendResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00116         // desoapify the result -- i.e. replace &lt; with <  etc.
00117         sendResult = WSUtil::deSOAPify( sendResult);
00118         // strip out the OSxL that we want from the SOAP envelope
00119         sendResult = WSUtil::getOSxL(sendResult, "send");
00120         if( sendResult.find("true") != string::npos ) return true;
00121         else return false;
00122 }//end send
00123 
00124 string OSSolverAgent::getJobID(string osol){
00125         string sjobID = "";
00126         string getJobIDResult; 
00127         string theSOAP;
00128         // CreateSOAPMessage inputs
00129         int numInputs = 1;
00130         string smethod = "getJobID";
00131         string msInputs[1];
00132         // package up the inputs
00133         // first run them through SAOPify, e.g. replace < with &lt; etc.
00134         msInputs[0] = WSUtil::SOAPify( osol) ;
00135         string msInputNames[1] = {"osol"};
00136         string sSoapAction = "OSSolverService#getJobID";
00137         // create the soap
00138         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00139                                 smethod, msInputs, msInputNames, sSoapAction);
00140         // send the soap to the HTTP server
00141         getJobIDResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00142         // desoapify the result -- i.e. replace &lt; with <  etc.
00143         getJobIDResult = WSUtil::deSOAPify( getJobIDResult);
00144         // strip out the OSxL that we want from the SOAP envelope
00145         sjobID =  WSUtil::getOSxL(getJobIDResult, "getJobID");
00146         return sjobID;
00147 }//end getJobID
00148 
00149 string OSSolverAgent::retrieve(string osol){
00150         string sOSrL;
00151         string retrieveResult; 
00152         string theSOAP;
00153         // CreateSOAPMessage inputs
00154         int numInputs = 1;
00155         string smethod = "retrieve";
00156         string msInputs[1];
00157         // package up the inputs
00158         // first run them through SAOPify, e.g. replace < with &lt; etc.
00159         msInputs[0] = WSUtil::SOAPify( osol) ;
00160         string msInputNames[1] = {"osol"};
00161         string sSoapAction = "OSSolverService#retrieve";
00162         // create the soap
00163         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00164                                 smethod, msInputs, msInputNames, sSoapAction);
00165         // send the soap to the HTTP server
00166         retrieveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00167         // desoapify the result -- i.e. replace &lt; with <  etc.
00168         retrieveResult = WSUtil::deSOAPify( retrieveResult);
00169         // strip out the OSxL that we want from the SOAP envelope
00170         sOSrL =  WSUtil::getOSxL(retrieveResult, "retrieve");
00171         return sOSrL;   
00172 }//end retrieve
00173 
00174 string OSSolverAgent::kill(string osol){
00175         string sOSpL;
00176         string killResult; 
00177         string theSOAP;
00178         // CreateSOAPMessage inputs
00179         int numInputs = 1;
00180         string smethod = "kill";
00181         string msInputs[1];
00182         // package up the inputs
00183         // first run them through SAOPify, e.g. replace < with &lt; etc.
00184         msInputs[0] = WSUtil::SOAPify( osol) ;
00185         string msInputNames[1] = {"osol"};
00186         string sSoapAction = "OSSolverService#kill";
00187         // create the soap
00188         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00189                                 smethod, msInputs, msInputNames, sSoapAction);
00190         // send the soap to the HTTP server
00191         killResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00192         // desoapify the result -- i.e. replace &lt; with <  etc.
00193         killResult = WSUtil::deSOAPify( killResult);
00194         // strip out the OSxL that we want from the SOAP envelope
00195         sOSpL =  WSUtil::getOSxL( killResult, "kill");
00196         return sOSpL;
00197 }//end kill
00198 
00199 string OSSolverAgent::knock(string ospl, string osol){
00200         string sOSpL; 
00201         string theSOAP;
00202         string knockResult;
00203         // CreateSOAPMessage inputs
00204         int numInputs = 2;
00205         string smethod = "knock";
00206         string msInputs[2];
00207         // package up the inputs
00208         // first run them through SAOPify, e.g. replace < with &lt; etc.
00209         msInputs[0] = WSUtil::SOAPify( ospl) ;
00210         msInputs[1] = WSUtil::SOAPify( osol) ;
00211         string msInputNames[2] = {"ospl", "osol"};
00212         string sSoapAction = "OSSolverService#knock";
00213         // create the soap
00214         theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI, 
00215                                 smethod, msInputs, msInputNames, sSoapAction);
00216         // send the soap to the HTTP server
00217         knockResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00218         // desoapify the result -- i.e. replace &lt; with <  etc.
00219         knockResult = WSUtil::deSOAPify( knockResult);
00220         // strip out the OSxL that we want from the SOAP envelope
00221         sOSpL = WSUtil::getOSxL( knockResult, "knock");
00222         return sOSpL;
00223 }//end knock

Generated on Thu May 15 22:15:04 2008 by  doxygen 1.4.7