00001
00017 #include "OSSolverAgent.h"
00018 #include "OSWSUtil.h"
00019
00020 #include <cstdlib>
00021
00022
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
00032
00033 if (solverURI.find("http://") != string::npos) solverURI = solverURI.substr(7);
00034
00035 posSlash = solverURI.find("/", nstart);
00036 if(posSlash != std::string::npos) nstart = posSlash;
00037 postURI = solverURI.substr(nstart, solverURI.size() - 1);
00038
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
00058 int numInputs = 2;
00059 string smethod = "solve";
00060 string msInputs[2];
00061
00062
00063 msInputs[0] = WSUtil::SOAPify( osil) ;
00064 msInputs[1] = WSUtil::SOAPify( osol) ;
00065 string msInputNames[2] = {"osil", "osol"};
00066 string sSoapAction = "OSSolverService#solve";
00067
00068 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00069 smethod, msInputs, msInputNames, sSoapAction);
00070
00071
00072 solveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00073
00074
00075
00076 solveResult = WSUtil::deSOAPify( solveResult);
00077
00078
00079
00080 sOSrL = WSUtil::getOSxL(solveResult, "solve");
00081
00082
00083 return sOSrL;
00084 }
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
00093 std::cout << "SEND THE FILE " << std::endl;
00094
00095 uploadResult = WSUtil::sendSOAPMessage( theHTTPPOST, solverAddress, solverPortNumber);
00096 return uploadResult;
00097 }
00098
00099
00100 bool OSSolverAgent::send(string osil, string osol){
00101 string theSOAP;
00102 string sendResult;
00103
00104 int numInputs = 2;
00105 string smethod = "send";
00106 string msInputs[2];
00107
00108
00109 msInputs[0] = WSUtil::SOAPify( osil) ;
00110 msInputs[1] = WSUtil::SOAPify( osol) ;
00111 string msInputNames[2] = {"osil", "osol"};
00112 string sSoapAction = "OSSolverService#send";
00113
00114 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00115 smethod, msInputs, msInputNames, sSoapAction);
00116
00117 sendResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00118
00119 sendResult = WSUtil::deSOAPify( sendResult);
00120
00121 sendResult = WSUtil::getOSxL(sendResult, "send");
00122 if( sendResult.find("true") != string::npos ) return true;
00123 else return false;
00124 }
00125
00126 string OSSolverAgent::getJobID(string osol){
00127 string sjobID = "";
00128 string getJobIDResult;
00129 string theSOAP;
00130
00131 int numInputs = 1;
00132 string smethod = "getJobID";
00133 string msInputs[1];
00134
00135
00136 msInputs[0] = WSUtil::SOAPify( osol) ;
00137 string msInputNames[1] = {"osol"};
00138 string sSoapAction = "OSSolverService#getJobID";
00139
00140 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00141 smethod, msInputs, msInputNames, sSoapAction);
00142
00143 getJobIDResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00144
00145 getJobIDResult = WSUtil::deSOAPify( getJobIDResult);
00146
00147 sjobID = WSUtil::getOSxL(getJobIDResult, "getJobID");
00148 return sjobID;
00149 }
00150
00151 string OSSolverAgent::retrieve(string osol){
00152 string sOSrL;
00153 string retrieveResult;
00154 string theSOAP;
00155
00156 int numInputs = 1;
00157 string smethod = "retrieve";
00158 string msInputs[1];
00159
00160
00161 msInputs[0] = WSUtil::SOAPify( osol) ;
00162 string msInputNames[1] = {"osol"};
00163 string sSoapAction = "OSSolverService#retrieve";
00164
00165 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00166 smethod, msInputs, msInputNames, sSoapAction);
00167
00168 retrieveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00169
00170 retrieveResult = WSUtil::deSOAPify( retrieveResult);
00171
00172 sOSrL = WSUtil::getOSxL(retrieveResult, "retrieve");
00173 return sOSrL;
00174 }
00175
00176 string OSSolverAgent::kill(string osol){
00177 string sOSpL;
00178 string killResult;
00179 string theSOAP;
00180
00181 int numInputs = 1;
00182 string smethod = "kill";
00183 string msInputs[1];
00184
00185
00186 msInputs[0] = WSUtil::SOAPify( osol) ;
00187 string msInputNames[1] = {"osol"};
00188 string sSoapAction = "OSSolverService#kill";
00189
00190 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00191 smethod, msInputs, msInputNames, sSoapAction);
00192
00193 killResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00194
00195 killResult = WSUtil::deSOAPify( killResult);
00196
00197 sOSpL = WSUtil::getOSxL( killResult, "kill");
00198 return sOSpL;
00199 }
00200
00201 string OSSolverAgent::knock(string ospl, string osol){
00202 string sOSpL;
00203 string theSOAP;
00204 string knockResult;
00205
00206 int numInputs = 2;
00207 string smethod = "knock";
00208 string msInputs[2];
00209
00210
00211 msInputs[0] = WSUtil::SOAPify( ospl) ;
00212 msInputs[1] = WSUtil::SOAPify( osol) ;
00213 string msInputNames[2] = {"ospl", "osol"};
00214 string sSoapAction = "OSSolverService#knock";
00215
00216 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00217 smethod, msInputs, msInputNames, sSoapAction);
00218
00219 knockResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00220
00221 knockResult = WSUtil::deSOAPify( knockResult);
00222
00223 sOSpL = WSUtil::getOSxL( knockResult, "knock");
00224 return sOSpL;
00225 }