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