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

acq2xx_client.cpp

Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file acq2xx_client.cpp                                                    */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2006 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of Version 2 of the GNU General Public License
00009     as published by the Free Software Foundation;
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file acq2xx_client.cpp client WS application
00022  *
00023  * multi role program, with role selected by executable file, in the manner of
00024  * busybox. On Linux, use softlinks to the single main executable. On Windows.
00025  * copy and rename the executable.
00026  *
00027  * - Usage selected by file name:
00028  *  - acq2sh [remote shell commands]  
00029  *   - runs remote shell command (reads stdin if no commands given)
00030  *  - acqcmd [command]
00031  *   - simulates acqcmd functional control
00032  *  - acqstat
00033  *   - output capture status, short cut "acqcmd getStatus" control
00034  *  - setArm
00035  *   - short cut "acqcmd setArm" control
00036  *  - acq2script [remote shell commands]
00037  *   - runs remote shell commands (reads stdin if no commands given). 
00038  *   - Similar to acq2sh, but with per command status output and stop on first e *     error. Program outputs error code at finish
00039  */
00040 
00041 #include "soapH.h"
00042 #include "acq2xx.nsmap"
00043 
00044 using namespace std;
00045 #include <iostream>
00046 #include <vector>
00047 
00048 #include "local.h"
00049 #include <stdio.h>
00050 #include <string.h>
00051 
00052 
00053 #include "acq2xx_client_api.h"
00054 
00055 /** pick up target URL from environment */
00056 #define ENV_URL "ACQ2XX_WS_URL"
00057 
00058 /** set verbosity from environment */
00059 #define ENV_VERBOSE "ACQ2XX_WS_VERBOSE"
00060 
00061 /** select low level test harness example */
00062 #define ENV_TESTHARNESS "TESTHARNESS"
00063 // @@todo make AcqStatus a first class object with a print() method */
00064 static void print(acq2xx__AcqStatus& status)
00065 {
00066         printf("%30s : %d \"%s\"\n", "state", 
00067                status.state, status.state_string);
00068 #define STAT_PRINT(field) printf("%30s : %d\n", #field, status.field)
00069 
00070         STAT_PRINT(numsamples);
00071         STAT_PRINT(prelen);
00072         STAT_PRINT(postlen);
00073         STAT_PRINT(elapsed);
00074         STAT_PRINT(nchan);
00075 }
00076 
00077 /** default URL. */
00078 static char *URL = "http://acq196_001:66666";
00079 
00080 extern int verbose;
00081 
00082 static int test_harness();
00083 
00084 #ifdef WIN32
00085 int acq2xx_main(int argc, char* argv[])
00086 #else
00087         int main(int argc, char* argv[]) 
00088 #endif
00089 {
00090         char command[256] = {};
00091         char *s;
00092 
00093         char* method = basename(argv[0]);  /* prog name selects action */
00094 
00095         if (getenv(ENV_URL)){
00096                 URL = getenv(ENV_URL);
00097         }
00098         if (getenv(ENV_VERBOSE)){
00099                 verbose = atoi(getenv(ENV_VERBOSE));
00100         }
00101         if (getenv(ENV_TESTHARNESS)){
00102                 return test_harness();
00103         }
00104         for (int iarg = 1; iarg != argc; ++iarg){
00105                 strcat(command, argv[iarg]);
00106                 strcat(command, " ");
00107                 assert(strlen(command) < sizeof(command));
00108         }
00109 
00110 
00111         if (strcmp(method, "acq2sh") == 0){
00112                 return acq2xx_client_acq2sh(URL, command);
00113         }else if (strcmp(method, "acqcmd") == 0){
00114                 int rc = soap_call_acq2xx__acqcmd(
00115                                         soap_new(), URL, "", command, s);
00116                 printf("%s\n", s);
00117                 return rc;
00118         }else if (strcmp(method, "acqstat") == 0){
00119                 acq2xx__AcqStatus status;
00120                 int rc = soap_call_acq2xx__getAcqStatus(
00121                         soap_new(), URL, "", status);
00122                 print(status);
00123                 return rc;
00124         }else if (strcmp(method, "setArm") == 0){
00125                 int block = argc > 2? atoi(argv[2]): 0;
00126                 acq2xx__AcqStatus status;
00127                 int rc = soap_call_acq2xx__setArm(
00128                         soap_new(), URL, "", block, status);
00129                 print(status);
00130                 return rc;
00131         }else if (strcmp(method, "acq2script") == 0){
00132                 return acq2xx_client_acq2script(URL, command);
00133 
00134         }else{
00135                 soap* soap = soap_new();
00136                 int rc = soap_call_acq2xx__getVersion(soap, URL, "",
00137                                                       ACQ2XX_H_VERSION, s);
00138 
00139                 if (rc != 0){
00140                         return rc;
00141                 }
00142                 if (strcmp(ACQ2XX_H_VERSION, s) == 0){
00143                         info("PERFECT version match %s", ACQ2XX_H_VERSION);
00144                 }else{
00145                         info("WARNING: version mismatch client: %s server %s",
00146                             ACQ2XX_H_VERSION, s);
00147                 }
00148                 rc = soap_call_acq2xx__acq2sh(soap_new(), URL, "", 
00149                                                   "echo `hostname` `date`", s);
00150 
00151                 if (rc != 0){
00152                         return rc;
00153                 }
00154                 printf("%s\n", s);
00155                 return rc;
00156         }
00157 }
00158 
00159 
00160 static int test_harness()
00161 {
00162         soap* soap = soap_new();
00163         acq2xx__acq2scriptResponse sr;          
00164         acq2xx__Transaction tr("test transaction");
00165         cout << "Sending: "; tr.print();
00166         soap_call_acq2xx__acq2script(soap, URL, "", &tr, sr);
00167         cout << "Replied: "; sr.out->print();
00168 
00169         cout << endl << endl << endl;
00170 
00171         acq2xx__TransactionList l(4);
00172         l.name = "my test list";
00173         l[0] = new acq2xx__Transaction("T0");
00174         l[1] = new acq2xx__Transaction("T1");
00175         l[2] = new acq2xx__Transaction("T2");
00176         l[3] = new acq2xx__Transaction("T3");
00177 
00178         cout << "Sending list: "; l.print();
00179         soap_call_acq2xx__acq2script(soap, URL, "", &l, sr);
00180         cout << "Replied: "; sr.out->print();
00181 
00182 
00183 
00184         acq2xx__acq2scriptResponse sr2;
00185         acq2xx__Transaction* s1 = new acq2xx__ShellTransaction("ps");
00186         cout << "Sending transaction: "; s1->print();
00187         soap_call_acq2xx__acq2script(soap, URL, "", s1, sr2);
00188         cout << "Replied: " << sr2.out->getResult() << endl;
00189         cout << "Replied: "; sr2.out->print();
00190 
00191         acq2xx__Transaction* s2 = new acq2xx__ShellTransaction("date");
00192 
00193         l[1] = s1;
00194         l[2] = s2;
00195         l[3] = new acq2xx__ShellTransaction("balderdash");
00196 
00197         cout << "Sending list: "; l.print();
00198         soap_call_acq2xx__acq2script(soap, URL, "", &l, sr);
00199         cout << "Replied: "; sr.out->print();
00200         return 0;
00201 }
00202 
00203 

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