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

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

Generated on Mon Aug 3 03:02:22 2009 by  doxygen 1.4.7