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