Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Data Fields | Globals | Related Pages

acq2xx_client_api.cpp

Go to the documentation of this file.
00001 #include "soapH.h"
00002 
00003 using namespace std;
00004 #include <iostream>
00005 #include <vector>
00006 
00007 #include "local.h"
00008 #include <stdio.h>
00009 #include <string.h>
00010 
00011 
00012 
00013 #include "acq2xx_client_api.h"
00014 
00015 #define SCRIPTFILE stdin
00016 
00017 int verbose = 0;
00018 
00019 static int acq2script(char *url, char *command)
00020 {
00021         soap soap;
00022         soap_init(&soap);
00023         acq2xx__ShellTransaction shellTransaction(command);
00024 
00025         acq2xx__acq2scriptResponse sr;
00026         int rc = soap_call_acq2xx__acq2script(
00027                 &soap, url, "", &shellTransaction, sr);
00028 
00029         if (rc == 0){
00030                 //sr.out->print();
00031                 cout << ((acq2xx__ShellTransaction*)sr.out)->getResult();
00032                 return sr.out->status? -1: 0;
00033         }
00034         return rc;
00035 }
00036 
00037 #define MAXCMD  256
00038 
00039 static int acq2script(char *url, FILE *fp)
00040 {
00041         vector<acq2xx__ShellTransaction*> transactions;
00042         char commandline[256];
00043 
00044         /** @todo does not handle line continuation .. */
00045         while(fgets(commandline, MAXCMD, fp)){
00046                 chomp(commandline);
00047                 if (strlen(commandline) == 0){
00048                         continue;
00049                 }else if (commandline[0] == '#'){
00050                         ;                                       /** possibility to add other types here */
00051                 }else{
00052                         transactions.push_back(new acq2xx__ShellTransaction(commandline));
00053                 }
00054         }
00055 
00056         if (verbose){
00057                 cerr << "Done processing. Number of transactions: " << 
00058                         transactions.size() << endl;
00059                 for (unsigned i = 0; i < transactions.size(); ++i){
00060                         cout << "[" << i << "] " << 
00061                                 transactions[i]->command << endl;
00062                 }
00063         }
00064 
00065         soap soap;
00066         soap_init(&soap);
00067         acq2xx__TransactionList tl(transactions.size());
00068 
00069         for (unsigned i = 0; i < transactions.size(); ++i){
00070                 tl[i] = transactions[i];
00071         }
00072         acq2xx__acq2scriptResponse sr;
00073         int rc = soap_call_acq2xx__acq2script(&soap, url, "", &tl, sr);
00074 
00075         if (rc == 0){
00076                 acq2xx__TransactionList &rtl = 
00077                                 *(acq2xx__TransactionList*)sr.out;
00078                 int err_status = 0;
00079                 for (int i = 0; i < rtl.getSize(); ++i){
00080                         if (rtl[i]->status != 0){
00081                                 err_status = rtl[i]->status;
00082                                 acq2xx__Transaction &trim = *rtl[i];
00083                                 cout << "[" << i << "] " << 
00084                                 rtl[i]->getCommand() << 
00085                                 " :: ERROR STATUS: " << trim.status <<
00086                                 " " << trim.getResult() << endl;
00087                         }else if (rtl[i]->complete == 0){
00088                                 cout << "[" << i << "] " << 
00089                                 rtl[i]->getCommand() << 
00090                                 " :: NOT EXECUTED " << endl;
00091                         }else{
00092                                 cout << rtl[i]->getResult();
00093                         }
00094                 }
00095 
00096 #ifdef IKNOWWHYTHISWORKS
00097                 return sr.out->status;
00098 #else
00099 // @todo total list status NOT returned. Fortunately, we already know this
00100 //              cout << "!IKNOWWHYTHISWORKS return " << err_status << endl;
00101                 return err_status == 0? 0: -1;
00102 #endif
00103         }else{  
00104                 return -1;
00105         }
00106 }
00107 
00108 
00109 
00110 
00111 
00112 int acq2xx_client_acq2script(char *url, char *command)
00113 {
00114         if (strlen(command)){
00115                 return acq2script(url, command);
00116         }else{
00117                 return acq2script(url, SCRIPTFILE);
00118         }
00119 }
00120 
00121 
00122 static int acq2sh(char *url, char* command)
00123 {
00124         char *s;
00125         soap soap;
00126         soap_init(&soap);
00127         int rc = soap_call_acq2xx__acq2sh(&soap, url, "", command, s);
00128 
00129         if (rc == 0){
00130                 printf("%s\n", s);
00131         }
00132         return rc;
00133 }
00134 
00135 static int acq2sh(char *url, FILE *fp)
00136 {
00137         static char* script = (char*)malloc(0x10000);
00138         char commandline[256];
00139         soap soap;
00140         soap_init(&soap);
00141         script[0] = '\0';
00142 
00143         /** @todo does not handle line continuation .. */
00144         while(fgets(commandline, MAXCMD, fp)){
00145                 chomp(commandline);
00146                 if (strlen(commandline) == 0){
00147                         continue;
00148                 }else if (commandline[0] == '#'){
00149                         ;                                       /** possibility to add other types here */
00150                 }else{
00151                         strcat(script, commandline);
00152                         strcat(script, ";");                    
00153                 }
00154         }
00155         
00156         char *s;
00157         int rc = soap_call_acq2xx__acq2sh(&soap, url, "", script, s);
00158 
00159         if (rc == 0){
00160                 printf("%s\n", s);
00161         }
00162 
00163         free(script);
00164         return rc;
00165 }
00166 
00167 
00168 
00169 
00170 
00171 int acq2xx_client_acq2sh(char *url, char* command)
00172 {
00173         if (strlen(command)){
00174                 return acq2sh(url, command);
00175         }else{
00176                 return acq2sh(url, SCRIPTFILE);
00177         }       
00178 }

Generated on Mon Aug 21 12:39:57 2006 for ACQ2XXWebServices by  doxygen 1.4.4