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