/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/src/OSAgent/OSSolverAgent.cpp

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

Generated on Sat Mar 29 22:38:01 2008 by  doxygen 1.5.3