00001
00018 #include "OSSolverAgent.h"
00019 #include "OSWSUtil.h"
00020 #include "CoinTime.hpp"
00021 #include "OSParameters.h"
00022
00023 #include <cstdlib>
00024
00025 #ifdef HAVE_CTIME
00026 # include <ctime>
00027 #else
00028 # ifdef HAVE_TIME_H
00029 # include <time.h>
00030 # else
00031 # error "don't have header file for time"
00032 # endif
00033 #endif
00034
00035
00036
00037 using std::string;
00038 using std::cout;
00039 using std::endl;
00040
00041 OSSolverAgent::OSSolverAgent(string solverURI) : OShL() {
00042 int nstart = 0;
00043 string::size_type posSlash;
00044
00045
00046 if (solverURI.find("http://") != string::npos) solverURI = solverURI.substr(7);
00047
00048 posSlash = solverURI.find("/", nstart);
00049 if(posSlash != std::string::npos) nstart = posSlash;
00050 postURI = solverURI.substr(nstart, solverURI.size() - 1);
00051
00052 string::size_type colonlocation = solverURI.find(":");
00053 if(colonlocation == string::npos) {
00054 solverAddress = solverURI.substr(0, nstart);
00055 solverPortNumber = 80;
00056 }
00057 else{
00058 solverPortNumber = atoi( &solverURI.substr(colonlocation + 1, nstart - colonlocation - 1)[0] ) ;
00059 solverAddress = solverURI.substr(0, colonlocation);
00060 }
00061 }
00062
00063 OSSolverAgent::~OSSolverAgent() {
00064 }
00065
00066 string OSSolverAgent::solve(string osil, string osol){
00067 string sOSrL ;
00068 string theSOAP;
00069 string solveResult;
00070 bool useCDATA = true;
00071
00072 int numInputs = 2;
00073 string smethod = "solve";
00074 string msInputs[2];
00075
00076
00077 msInputs[0] = WSUtil::SOAPify( osil, useCDATA) ;
00078 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00079 string msInputNames[2] = {"osil", "osol"};
00080 string sSoapAction = "OSSolverService#solve";
00081
00082 double cpuTime =0;
00083 double startTime = 0;
00084 startTime = CoinCpuTime();
00085 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00086 smethod, msInputs, msInputNames, sSoapAction);
00087
00088
00089 cpuTime = CoinCpuTime() - startTime;
00090
00091 startTime = CoinWallclockTime();
00092 solveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00093 cpuTime = CoinWallclockTime() - startTime;
00094
00095
00096
00097
00098 solveResult = WSUtil::getOSxL(solveResult, "solve");
00099
00100
00101 useCDATA = false;
00102 sOSrL = WSUtil::deSOAPify( solveResult, useCDATA);
00103
00104
00105
00106
00107
00108 return sOSrL;
00109 }
00110
00111 string OSSolverAgent::fileUpload( string osilFileName, string theOSiLFile){
00112 string theHTTPPOST="";
00113 string uploadResult="";
00114 string boundaryName = "AaB03x";
00115 theHTTPPOST = WSUtil::createFormDataUpload(solverAddress, postURI,
00116 osilFileName, theOSiLFile, boundaryName);
00117
00118 std::cout << "SEND THE FILE " << std::endl;
00119
00120 uploadResult = WSUtil::sendSOAPMessage( theHTTPPOST, solverAddress, solverPortNumber);
00121 return uploadResult;
00122 }
00123
00124
00125 bool OSSolverAgent::send(string osil, string osol){
00126 string theSOAP;
00127 string sendResult;
00128 bool useCDATA = true;
00129
00130 int numInputs = 2;
00131 string smethod = "send";
00132 string msInputs[2];
00133
00134
00135 msInputs[0] = WSUtil::SOAPify( osil, useCDATA) ;
00136 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00137 string msInputNames[2] = {"osil", "osol"};
00138 string sSoapAction = "OSSolverService#send";
00139
00140 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00141 smethod, msInputs, msInputNames, sSoapAction);
00142
00143 sendResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00144
00145 sendResult = WSUtil::getOSxL(sendResult, "send");
00146
00147 useCDATA = false;
00148 sendResult = WSUtil::deSOAPify( sendResult, useCDATA);
00149 if( sendResult.find("true") != string::npos ) return true;
00150 else return false;
00151 }
00152
00153 string OSSolverAgent::getJobID(string osol){
00154 string sjobID = "";
00155 string getJobIDResult;
00156 string theSOAP;
00157 bool useCDATA = true;
00158
00159 int numInputs = 1;
00160 string smethod = "getJobID";
00161 string msInputs[1];
00162
00163
00164 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00165 string msInputNames[1] = {"osol"};
00166 string sSoapAction = "OSSolverService#getJobID";
00167
00168 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00169 smethod, msInputs, msInputNames, sSoapAction);
00170
00171 getJobIDResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00172
00173 getJobIDResult = WSUtil::getOSxL(getJobIDResult, "getJobID");
00174
00175 useCDATA = false;
00176 sjobID = WSUtil::deSOAPify( getJobIDResult, useCDATA);
00177
00178 return sjobID;
00179 }
00180
00181 string OSSolverAgent::retrieve(string osol){
00182 string sOSrL;
00183 string retrieveResult;
00184 string theSOAP;
00185 bool useCDATA = true;
00186
00187 int numInputs = 1;
00188 string smethod = "retrieve";
00189 string msInputs[1];
00190
00191
00192 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00193 string msInputNames[1] = {"osol"};
00194 string sSoapAction = "OSSolverService#retrieve";
00195
00196 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00197 smethod, msInputs, msInputNames, sSoapAction);
00198
00199 retrieveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00200
00201 retrieveResult = WSUtil::getOSxL(retrieveResult, "retrieve");
00202
00203 useCDATA = false;
00204 sOSrL = WSUtil::deSOAPify( retrieveResult, useCDATA);
00205 return sOSrL;
00206 }
00207
00208 string OSSolverAgent::kill(string osol){
00209 string sOSpL;
00210 string killResult;
00211 string theSOAP;
00212 bool useCDATA = true;
00213
00214 int numInputs = 1;
00215 string smethod = "kill";
00216 string msInputs[1];
00217
00218
00219 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00220 string msInputNames[1] = {"osol"};
00221 string sSoapAction = "OSSolverService#kill";
00222
00223 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00224 smethod, msInputs, msInputNames, sSoapAction);
00225
00226 killResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00227
00228 killResult = WSUtil::getOSxL( killResult, "kill");
00229
00230 useCDATA = false;
00231 sOSpL = WSUtil::deSOAPify( killResult, useCDATA);
00232 return sOSpL;
00233 }
00234
00235 string OSSolverAgent::knock(string ospl, string osol){
00236 string sOSpL;
00237 string theSOAP;
00238 string knockResult;
00239 bool useCDATA = true;
00240
00241 int numInputs = 2;
00242 string smethod = "knock";
00243 string msInputs[2];
00244
00245
00246 msInputs[0] = WSUtil::SOAPify( ospl, useCDATA) ;
00247 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00248 string msInputNames[2] = {"ospl", "osol"};
00249 string sSoapAction = "OSSolverService#knock";
00250
00251 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00252 smethod, msInputs, msInputNames, sSoapAction);
00253
00254 knockResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00255
00256
00257 knockResult = WSUtil::getOSxL( knockResult, "knock");
00258
00259 useCDATA = false;
00260 sOSpL = WSUtil::deSOAPify( knockResult, useCDATA);
00261 return sOSpL;
00262 }