| 1 |
/* @(#)xcc.c 19.1 (ESO-DMD) 02/25/03 13:58:26 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*+++++++++++++++++++++++ XC interface module XCC +++++++++++++++++++++++ |
| 30 |
.LANGUAGE C |
| 31 |
.IDENTIFICATION Module XCC |
| 32 |
.AUTHOR K. Banse ESO - Garching |
| 33 |
.KEYWORDS background Midas, communication |
| 34 |
.ENVIRONMENT VMS and UNIX |
| 35 |
.COMMENTS |
| 36 |
holds XCCSND, XCCWAI, XCCRDX |
| 37 |
.REMARKS |
| 38 |
.VERSION [1.00] 940425: creation |
| 39 |
981130 |
| 40 |
----------------------------------------------------------------------------*/ |
| 41 |
|
| 42 |
#include <midas_def.h> |
| 43 |
#include <xconndef.h> |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
/* |
| 48 |
|
| 49 |
*/ |
| 50 |
|
| 51 |
int XCCSND(cid,comline,secs,retstat) |
| 52 |
|
| 53 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 54 |
.PURPOSE |
| 55 |
send a command to background Midas with/without waiting for its termination |
| 56 |
.ALGORITHM |
| 57 |
use `outmail' |
| 58 |
.RETURNS |
| 59 |
return status ( 0 = o.k ) |
| 60 |
= 1; socket connection was closed by command just sent |
| 61 |
= 2; time out, `secs' seconds have passed without return |
| 62 |
= -1; problems with socket/file communication |
| 63 |
= -90; invalid input to this interface |
| 64 |
--------------------------------------------------------*/ |
| 65 |
|
| 66 |
int cid; /* IN: connection id */ |
| 67 |
char *comline; /* IN : command line to be executed by background |
| 68 |
Midas */ |
| 69 |
int secs; /* IN: max. no. of seconds to wait, |
| 70 |
= 0; indicates no wait |
| 71 |
= -1; indicates that we wait forever */ |
| 72 |
int retstat[2]; /* IN: return status from Background Midas (if wait), |
| 73 |
in case of status < 0 above, retstat[0] |
| 74 |
holds the specific error code */ |
| 75 |
|
| 76 |
{ |
| 77 |
int stat; |
| 78 |
|
| 79 |
char Comndline[MAX_MIDAS_LINE+4]; |
| 80 |
|
| 81 |
|
| 82 |
if ((cid < 0) || (cid >= MAX_BACK) || (BKMIDAS[cid].UNIT[0] == ' ')) |
| 83 |
return (-90); |
| 84 |
|
| 85 |
|
| 86 |
if (secs == 0) |
| 87 |
{ |
| 88 |
BKMIDAS[cid].WAIT = 0; |
| 89 |
BKMIDAS[cid].FLAG = 'N'; |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
if (secs < 0) |
| 94 |
BKMIDAS[cid].WAIT = -1; /* wait forever */ |
| 95 |
else |
| 96 |
BKMIDAS[cid].WAIT = secs; |
| 97 |
BKMIDAS[cid].FLAG = 'Y'; |
| 98 |
} |
| 99 |
|
| 100 |
Comndline[0] = XCONNECT.MYUNIT[0]; /* include return address */ |
| 101 |
Comndline[1] = XCONNECT.MYUNIT[1]; |
| 102 |
(void)strncpy(&Comndline[2],comline,MAX_MIDAS_LINE); |
| 103 |
Comndline[MAX_MIDAS_LINE+2] = '\0'; /* for security */ |
| 104 |
|
| 105 |
stat = outmail(1,Comndline,cid,retstat); |
| 106 |
if (stat != 0) |
| 107 |
{ |
| 108 |
if (stat == 4) |
| 109 |
stat = -1; |
| 110 |
else if (stat == 5) |
| 111 |
stat = -1; |
| 112 |
else if (stat == 7) /* socket connection was closed */ |
| 113 |
stat = 1; |
| 114 |
} |
| 115 |
|
| 116 |
return (stat); |
| 117 |
} |
| 118 |
|
| 119 |
/* |
| 120 |
|
| 121 |
*/ |
| 122 |
|
| 123 |
int XCCWAI(cid,retstat) |
| 124 |
|
| 125 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 126 |
.PURPOSE |
| 127 |
wait for return from a command which was sent to background Midas before |
| 128 |
.ALGORITHM |
| 129 |
use `outmail' |
| 130 |
.RETURNS |
| 131 |
= 0; o.k., parameter `retstat' holds status from background Midas |
| 132 |
= 1; background Midas busy |
| 133 |
= 2; no command sent before to background unit |
| 134 |
= -1; problems with socket/file communication |
| 135 |
= -90; invalid input to this interface |
| 136 |
--------------------------------------------------------*/ |
| 137 |
|
| 138 |
int cid; /* IN: connection id */ |
| 139 |
int retstat[2]; /* IN: status from command execution in background |
| 140 |
Midas if `stat' = 0; |
| 141 |
if `stat' < 0 then retstat[0] holds the |
| 142 |
communication error code */ |
| 143 |
|
| 144 |
{ |
| 145 |
int stat; |
| 146 |
|
| 147 |
char wstr[8]; /* just placeholder */ |
| 148 |
|
| 149 |
|
| 150 |
if ((cid < 0) || (cid >= MAX_BACK) || (BKMIDAS[cid].UNIT[0] == ' ')) |
| 151 |
return (-90); |
| 152 |
|
| 153 |
|
| 154 |
stat = outmail(2,wstr,cid,retstat); |
| 155 |
if (stat != 0) |
| 156 |
{ |
| 157 |
if (stat == 4) |
| 158 |
stat = -1; |
| 159 |
else if (stat == 5) |
| 160 |
stat = -1; |
| 161 |
else if (stat == 9) |
| 162 |
stat = 2; |
| 163 |
} |
| 164 |
|
| 165 |
return (stat); |
| 166 |
} |
| 167 |
|
| 168 |
/* |
| 169 |
|
| 170 |
*/ |
| 171 |
|
| 172 |
int XCCRDX(cid,retstat) |
| 173 |
|
| 174 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 175 |
.PURPOSE |
| 176 |
read the exec status of a command which was sent to background Midas before |
| 177 |
and has terminated by now |
| 178 |
.ALGORITHM |
| 179 |
use `outmail' |
| 180 |
.RETURNS |
| 181 |
= 0; o.k., parameter `retstat' holds exec status of command |
| 182 |
= 1; background Midas busy |
| 183 |
= 2; no command sent before to background unit |
| 184 |
= -1; problems with socket/file communication |
| 185 |
= -90; invalid input to this interface |
| 186 |
--------------------------------------------------------*/ |
| 187 |
|
| 188 |
int cid; /* IN: connection id */ |
| 189 |
int retstat[2]; /* IN: status from command execution in background |
| 190 |
Midas if `stat' = 0; |
| 191 |
if `stat' < 0 then retstat[0] holds the |
| 192 |
communication error code */ |
| 193 |
|
| 194 |
{ |
| 195 |
int stat; |
| 196 |
|
| 197 |
char wstr[8]; /* just placeholder */ |
| 198 |
|
| 199 |
|
| 200 |
if ((cid < 0) || (cid >= MAX_BACK) || (BKMIDAS[cid].UNIT[0] == ' ')) |
| 201 |
return (-90); |
| 202 |
|
| 203 |
|
| 204 |
stat = outmail(4,wstr,cid,retstat); /* read status of last command */ |
| 205 |
if (stat != 0) |
| 206 |
{ |
| 207 |
if (stat == 4) |
| 208 |
stat = -1; |
| 209 |
else if (stat == 5) |
| 210 |
stat = -1; |
| 211 |
else if (stat == 9) |
| 212 |
stat = 2; |
| 213 |
} |
| 214 |
|
| 215 |
return (stat); |
| 216 |
} |
| 217 |
|
| 218 |
|