00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "jsoc_main.h"
00010 #include "inthandles.h"
00011
00012
00013
00014
00015
00016
00017 #define ITEMCNT 7000
00018 #define NAMECNT 3000
00019 #define NAMELEN 17
00020 #define NAME32 33
00021 #define NAME30 31
00022 #define STRLEN 81
00023 #define STR60 61
00024 #define STR40 41
00025 #define STR16 17
00026 #define STR08 9
00027 #define STR06 7
00028 #define STR04 5
00029 #define STATECNT 256
00030 #define SYSCNT 64
00031 #define NCALSEGS 20
00032 #define BUFLEN 4000
00033 #define BUFMEAN 10
00034
00035
00036 #define IDLAPI_BEGIN(X) \
00037 int idl_##X(int argc, void **argv) \
00038 { \
00039 char *fnName = #X;
00040
00041 #define IDLAPI_END \
00042 }
00043
00044 typedef enum kDRMSObjType_enum
00045 {
00046 kDRMSObjType_Start = 0,
00047 kDRMSObjType_RecSet,
00048 kDRMSObjType_NumObjsPlusOne,
00049 } kDRMSObjType_t;
00050
00051 static const char *gObjTypeStrings[] =
00052 {
00053 NULL,
00054 "DRMS_RecordSet",
00055 NULL,
00056 };
00057
00058 int gDoLog = 0;
00059 int gVerbose = 0;
00060 pid_t gDRMSServerPID = 0;
00061 pid_t gTeePID = 0;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 static int IsValidDRMSObj(kDRMSObjType_t t)
00072 {
00073 return (t > kDRMSObjType_Start && t < kDRMSObjType_NumObjsPlusOne);
00074 }
00075
00076
00077
00078
00079 static const char *GetHandle(const void *ptr, kDRMSObjType_t type, const char *func)
00080 {
00081 const char *ret_str = NULL;
00082
00083 char buf[kMaxIDLHandleKey];
00084 char *pBuf = buf;
00085 const char *typeStr = NULL;
00086
00087 if (IsValidDRMSObj(type))
00088 {
00089 typeStr = gObjTypeStrings[type];
00090 snprintf(buf, sizeof(buf), "%p;%s;%s", ptr, typeStr, func);
00091 InsertJSOCStructure(&pBuf, (void *)ptr, kIDLHandleTypeDRMS, &ret_str);
00092 }
00093
00094 return ret_str;
00095 }
00096
00097
00098
00099
00100 static void *GetDRMSObj(const char *handle)
00101 {
00102 const char **pHandle = &handle;
00103 return GetJSOCStructure((void *)pHandle, kIDLHandleTypeDRMS);
00104 }
00105
00106 static void AddArg(char *argv, int *iarg, const char *argname, const char *argvalue)
00107 {
00108 snprintf(&(argv[*iarg * DRMS_MAXPATHLEN]), DRMS_MAXPATHLEN, "%s=%s", argname, argvalue);
00109 *iarg = *iarg + 1;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 IDLAPI_BEGIN(drms_open_records)
00122 {
00123 const char *seriesin = (char *)argv[0];
00124 char *handleout = (char *)argv[1];
00125 const int *bufsize = (char *)argv[2];
00126 char si[DRMS_MAXSERIESNAMELEN];
00127 const char *keyout = NULL;
00128 long success = 0;
00129 int stat;
00130 DRMS_RecordSet_t *recs = NULL;
00131
00132 fprintf(stdout, "Entering idl_drms_open_records\n");
00133 fprintf(stdout, " series: %s\n", seriesin);
00134 fprintf(stdout, " bufsize: %d\n", *bufsize);
00135
00136 strncpy(si, seriesin, sizeof(si));
00137
00138 recs = drms_open_records(drms_env, si, &stat);
00139 printf(" status %d\n", stat);
00140
00141 if (stat == DRMS_SUCCESS)
00142 {
00143 printf("got records okay\n");
00144 keyout = GetHandle(recs, kDRMSObjType_RecSet, fnName);
00145 if (keyout)
00146 {
00147 printf("created handle okay\n");
00148 snprintf(handleout, *bufsize, "%s", keyout);
00149 success = 1;
00150 }
00151 else
00152 {
00153 drms_close_records(recs, DRMS_FREE_RECORD);
00154 }
00155 }
00156
00157 return success;
00158 }
00159 IDLAPI_END
00160
00161
00162 IDLAPI_BEGIN(drms_process_records)
00163 {
00164
00165 const char *handlein = argv[0];
00166
00167 DRMS_RecordSet_t *rs = GetDRMSObj(handlein);
00168 return 0;
00169 }
00170 IDLAPI_END
00171
00172
00173
00174
00175 IDLAPI_BEGIN(db_connect)
00176 {
00177 void error_handler ();
00178 void warning_handler ();
00179
00180 long success = 0;
00181
00182 char *name_in;
00183 char *password_in;
00184 char *server_in;
00185 char *dbname_in;
00186 char *session_in;
00187
00188 fprintf(stdout, "Entering idl_db_connect\n");
00189
00190 if (gDRMSServerPID == 0)
00191 {
00192
00193 int dolog = 0;
00194 int verbose = 1;
00195 pid_t drms_server = 0;
00196 pid_t tee = 0;
00197
00198 char argvTemp[8 * DRMS_MAXPATHLEN];
00199 char **argvDRMS = NULL;
00200 int argcDRMS = 0;
00201 int iarg;
00202
00203 name_in = (char *)argv[0];
00204 password_in = (char *)argv[1];
00205 server_in = (char *)argv[2];
00206 dbname_in = (char *)argv[3];
00207 session_in = (char *)argv[4];
00208
00209 if (strlen(name_in) > 0)
00210 {
00211 AddArg(argvTemp, &argcDRMS, "JSOC_DBUSER", name_in);
00212 }
00213
00214 if (strlen(password_in) > 0)
00215 {
00216 AddArg(argvTemp, &argcDRMS, "JSOC_DBPASSWD", password_in);
00217 }
00218
00219 if (strlen(server_in) > 0)
00220 {
00221 AddArg(argvTemp, &argcDRMS, "JSOC_DBHOST", server_in);
00222 }
00223
00224 if (strlen(dbname_in) > 0)
00225 {
00226 AddArg(argvTemp, &argcDRMS, "JSOC_DBNAME", dbname_in);
00227 }
00228
00229 if (strlen(session_in) > 0)
00230 {
00231 AddArg(argvTemp, &argcDRMS, "DRMSSESSION", session_in);
00232 }
00233
00234
00235 argcDRMS++;
00236
00237 if (argcDRMS > 0)
00238 {
00239 argvDRMS = (char **)malloc(argcDRMS * sizeof(char *));
00240
00241 if (argvDRMS != 0)
00242 {
00243 iarg = 0;
00244
00245 argvDRMS[iarg++] = strdup("idlclient");
00246
00247
00248
00249 while (iarg < argcDRMS)
00250 {
00251 argvDRMS[iarg] = strdup(&(argvTemp[(iarg - 1) * DRMS_MAXPATHLEN]));
00252 fprintf(stdout, argvDRMS[iarg]);
00253 fprintf(stdout, "\n");
00254 iarg++;
00255 }
00256 }
00257 }
00258
00259 if (StartUp(argcDRMS, argvDRMS, &dolog, &verbose, &drms_server, &tee) == kIDLRet_Success)
00260 {
00261 printf("drms_server pid: %d, tee pid: %d\n", drms_server, tee);
00262 gDoLog = dolog;
00263 gVerbose = verbose;
00264 gDRMSServerPID = drms_server;
00265 gTeePID = tee;
00266 success = 1;
00267 }
00268 else
00269 {
00270 fprintf(stdout, "DRMS Error: couldn't create drms session.\n");
00271 }
00272
00273 if (argvDRMS)
00274 {
00275 free(argvDRMS);
00276 }
00277 }
00278
00279 return success;
00280 }
00281 IDLAPI_END
00282
00283
00284
00285
00286
00287
00288 IDLAPI_BEGIN(db_disconnect)
00289 {
00290 long success = 0;
00291
00292 fprintf(stdout, "Entering idl_db_disconnect\n");
00293
00294 if (gDRMSServerPID != 0)
00295 {
00296 int abortFlag = *((int *)(argv[0]));
00297
00298 success =
00299 (ShutDown(abortFlag, gDoLog, gVerbose, gDRMSServerPID, gTeePID) == kIDLRet_Success);
00300
00301 if (success)
00302 {
00303 gDRMSServerPID = 0;
00304 }
00305 }
00306
00307 return success;
00308 }
00309 IDLAPI_END