00001 static char rcsid[] = "$Header: /home/cvsuser/cvsroot/JSOC/proj/jpe/apps/call_dsds.c,v 1.1 2009/02/03 22:17:57 production Exp $";
00002
00003
00004 #include <sys/time.h>
00005 #include <pvm3.h>
00006 #include <soi_error.h>
00007 #include <unistd.h>
00008 #include "pe.h"
00009
00010 #define RESPDSDS 3600
00011
00012 void printkey (KEY *key);
00013 void print_asctime(int (*msgf)(char *fmt, ...));
00014 KEY *unpack_dsds(int (*msgf)(char *fmt, ...));
00015 int resp_dsds(int dsdstid);
00016
00017 static int reqack;
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 KEY *call_dsds(KEY **list, int reqtype, int dsdstid, int mytid,
00032 int (*msgf)(char *fmt, ...), int dbflg)
00033 {
00034 KEY *keybad, *retlist;
00035 char *username;
00036 int status;
00037
00038 if(!dsdstid) {
00039 (*msgf)("Called call_dsds() w/null dsdstid\n");
00040 return(NULL);
00041 }
00042 pvm_initsend(PvmDataDefault);
00043 pvm_pkint(&reqtype, 1, 1);
00044 status=0;
00045 pvm_pkint(&status, 1, 1);
00046 setkey_int(list, "pe_tid", mytid);
00047 if(!(username = (char *)getenv("USER"))) username = "nouser";
00048 setkey_str(list, "USER", username);
00049 if(dbflg) {
00050 printf("\nThe keylist before the dsds_svc call %d is:\n", reqtype);
00051 keyiterate( printkey, *list);
00052 }
00053 if(keybad=(KEY *)pack_keylist(*list)) {
00054 (*msgf)("Err packing a pvm msg to dsds_svc, type=%d name=%s\n",
00055 keybad->type, keybad->name);
00056 return(NULL);
00057 }
00058 if(pvm_send(dsdstid, MSGDSDS)) {
00059 (*msgf)("Error calling dsds_svc\n");
00060 return(NULL);
00061 }
00062 if(resp_dsds(dsdstid)) {
00063 (*msgf)("Timeout receiving response from dsds_svc (req=%d): ", reqtype);
00064 print_asctime(msgf);
00065 return(NULL);
00066 }
00067 if(retlist = unpack_dsds(msgf)) {
00068 if(dbflg) {
00069 printf("\nThe keylist after the dsds_svc call %d is:\n", reqack);
00070 keyiterate( printkey, retlist);
00071 }
00072 }
00073 return(retlist);
00074 }
00075
00076
00077
00078
00079 KEY *unpack_dsds(int (*msgf)(char *fmt, ...))
00080 {
00081 KEY *list;
00082 int status;
00083 char *errtxt;
00084
00085 pvm_upkint(&reqack, 1, 1);
00086 pvm_upkint(&status, 1, 1);
00087 if(status) {
00088 switch(status) {
00089 case DS_NO_LAGO:
00090 errtxt = "Can't retrieve. No ampex_svc";
00091 break;
00092 case DS_ALLOC_ERR:
00093 errtxt = "Can't allocate storage";
00094 break;
00095 case DS_DATA_QRY:
00096 errtxt = "DB query failed. No such ds?";
00097 break;
00098 case DS_MAX_LAGO_ERR:
00099 errtxt = "Max# of active Ampex retrieves";
00100 break;
00101 case AMPEX_READ_ERROR:
00102 errtxt = "Ampex read error";
00103 break;
00104 default:
00105 errtxt = "see soi_error.h";
00106 break;
00107 }
00108 (*msgf)("Dsds_svc returned error code %d: %s\n", status, errtxt);
00109 return(NULL);
00110 }
00111 list=newkeylist();
00112 if(!(list=(KEY *)unpack_keylist(list))) {
00113 (*msgf)("Error unpacking keylist from dsds_svc\n");
00114 return(NULL);
00115 }
00116 return(list);
00117 }
00118
00119
00120
00121 int resp_dsds(int dsdstid)
00122 {
00123 struct timeval tvalr;
00124 long tsr;
00125 int retcode, bufid;
00126
00127
00128 gettimeofday(&tvalr, NULL);
00129 tsr = tvalr.tv_sec;
00130 while(1) {
00131 if(bufid=pvm_nrecv(dsdstid, MSGDSDS)) {
00132 if(bufid < 0)
00133 retcode = -1;
00134 else
00135 retcode = 0;
00136 break;
00137 }
00138 gettimeofday(&tvalr, NULL);
00139 if(tvalr.tv_sec - tsr > RESPDSDS) {
00140 retcode = -1;
00141 break;;
00142 }
00143 usleep(200);
00144 }
00145 return(retcode);
00146 }
00147
00148
00149
00150 void print_asctime(int (*msgf)(char *fmt, ...))
00151 {
00152 struct timeval tvalr;
00153 struct tm *t_ptr;
00154 int tvalr_int;
00155
00156 gettimeofday(&tvalr, NULL);
00157 tvalr_int = (int)tvalr.tv_sec;
00158 t_ptr = localtime(&tvalr_int);
00159 (*msgf)("%s", asctime(t_ptr));
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234