Commit a952e350ccc5cf3092b3e3e70af446c5a1da0b09

Authored by Benjamin Renard
0 parents

First commit of DDClient project

.gitignore 0 → 100644
  1 +++ a/.gitignore
... ... @@ -0,0 +1,2 @@
  1 +.project
  2 +build/
... ...
CMakeLists.txt 0 → 100644
  1 +++ a/CMakeLists.txt
... ... @@ -0,0 +1,42 @@
  1 +cmake_minimum_required(VERSION 2.6)
  2 +
  3 +PROJECT(DDClient)
  4 +
  5 +add_definitions( -DLINUX )
  6 +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/bin/)
  7 +set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/${CMAKE_BUILD_TYPE}/lib/)
  8 +
  9 +if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  10 + #64 bits
  11 + MESSAGE( STATUS "64 bits" )
  12 + set(CMAKE_C_FLAGS_DEBUG "-ggdb -DLINUX -Dlinux -m64 -march=core2 -fPIC -D_REENTRANT -pthread")
  13 + set(CMAKE_C_FLAGS_RELEASE "-DLINUX -Dlinux -m64 -march=core2 -fPIC -D_REENTRANT -pthread")
  14 + set(CMAKE_CXX_FLAGS_DEBUG "-std=c++0x -fPIC -Wall -Wextra -ggdb -DLINUX -Dlinux -D_REENTRANT -malign-double -pthread")
  15 + set(CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -Wall -Wextra -fPIC -DLINUX -Dlinux -D_REENTRANT -malign-double -pthread -O3 -DNDEBUG")
  16 + set(USRLIB_DIR "/usr/lib64/:/usr/local/lib64/")
  17 +else( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  18 + #32 bits
  19 + MESSAGE( STATUS "32 bits" )
  20 + set(CMAKE_C_FLAGS_DEBUG "-ggdb -DLINUX -march=i686 -fPIC -Dlinux -D_REENTRANT -malign-double -pthread")
  21 + set(CMAKE_C_FLAGS_DEBUG "-DLINUX -march=i686 -fPIC -Dlinux -D_REENTRANT -malign-double -pthread")
  22 + set(CMAKE_CXX_FLAGS_DEBUG "-std=c++0x -fPIC -Wall -Wextra -ggdb -DLINUX -Dlinux -D_REENTRANT -malign-double -pthread")
  23 + set(CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -Wall -Wextra -fPIC -DLINUX -Dlinux -D_REENTRANT -malign-double -pthread -O3 -DNDEBUG")
  24 + set(USRLIB_DIR "/usr/lib/:/usr/local/lib/")
  25 +endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  26 +
  27 +
  28 +find_package( Threads REQUIRED )
  29 +
  30 +MESSAGE( STATUS "Build DDClient Project" )
  31 +add_subdirectory(src/DDClientLibC)
  32 +add_subdirectory(src/DDClientLibCpp)
  33 +add_subdirectory(src/TOOLS/DDCheckUser)
  34 +add_subdirectory(src/TOOLS/DDHtmlLogin)
  35 +add_subdirectory(src/TOOLS/DDLogin)
  36 +add_subdirectory(src/TOOLS/DDSimpleTestGetData)
  37 +add_subdirectory(src/TOOLS/DDSimpleTestGetMultiData)
  38 +
  39 +install(DIRECTORY "src/DDClientLibC/INCLUDE/" DESTINATION "include/DDClientLibC")
  40 +install(DIRECTORY "src/DDClientLibC/INCLUDE/" DESTINATION "include/DDClientLibCpp")
  41 +
  42 +SET(CMAKE_VERBOSE_MAKEFILE ON)
... ...
src/DDClientLibC/CMakeLists.txt 0 → 100644
  1 +++ a/src/DDClientLibC/CMakeLists.txt
... ... @@ -0,0 +1,22 @@
  1 +
  2 +PROJECT(DDClientLibC)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Library configuration
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 +)
  14 +
  15 +ADD_LIBRARY( DDClientLibC SHARED ${source_files} )
  16 +
  17 +target_link_libraries(
  18 + DDClientLibC
  19 + ${CMAKE_THREAD_LIBS_INIT}
  20 +)
  21 +
  22 +install (TARGETS DDClientLibC DESTINATION lib)
... ...
src/DDClientLibC/DD_client.c 0 → 100755
  1 +++ a/src/DDClientLibC/DD_client.c
... ... @@ -0,0 +1,978 @@
  1 +/* $Id: DD_client.c,v 1.4 2012/10/18 09:25:58 budnik Exp $ */
  2 +/*==============================================================
  3 + * DD SYSTEM
  4 + * DD_client.c
  5 + * V.6.0
  6 + * List of changes:
  7 + * November 1995, Version 1.0
  8 + * August 1999 :Access security system was installed by Alexandr Grigoriev (v3.0)
  9 + * October 22, 2002 - Communication ideology is changed (V.4.0)
  10 + * Oct 29, 2002 - Add DD_GetVersion() and some bags are corrected (V.4.1)
  11 + * May 1, 2003 - Network error is developped. (The header receiving is changed): V.4.2
  12 + * Nov 18, 2004 - Cach error is fixed.
  13 + * Jun 17, 2007 - Fedorov, V.4.5 Create new VI and Update data requests
  14 + * Sep 24, 2007 - Fedorov, V.4.6 Processing of return of Get_Data
  15 + * Dec 03, 2007 - Budnik, V.4.7 There may be several sessions with DD Server inside ONE
  16 + * Client session. Keep UserHost & UserName
  17 + * Oct 18, 2012 - Knizhnikova, V.4.8 new DD_SetTimeInfo() function
  18 + * Dec 15, 2012 - Fedorov, V.6.0. DD_GetMultiData(). Request structure is very changed, CurrentData is not a global structure
  19 + *===============================================================*/
  20 +
  21 +#include <unistd.h>
  22 +#include "DD.h"
  23 +#include "DD_comm.h"
  24 +#include "DD_Access.h"
  25 +#include <stdio.h>
  26 +#include <string.h>
  27 +
  28 +#include <netinet/in.h>
  29 +#include <arpa/inet.h>
  30 +
  31 +#define VERSION "V.6.0"
  32 +
  33 +/*------------------ GLOBAL STATIC VARIABLES --------------------------*/
  34 +int SocketID = -1; /* Global socket id for this communication session */
  35 +char UserName[USRLENGTH]="\0"; /* string for user name */
  36 +char UserHost[MAXHOSTLENGTH] = "\0"; /* IP of user's host in a string form */
  37 +int UserID; /* ID of user at the user's host */
  38 +extern int errno;
  39 +
  40 +/*================== FUNCTIONS =================================*/
  41 +
  42 +int getInfoFromHostName(const char *hostName, struct sockaddr_in *addr)
  43 +{
  44 + struct addrinfo hints;
  45 + memset(&hints, 0, sizeof(struct addrinfo));
  46 + hints.ai_family = AF_INET;
  47 + hints.ai_socktype = SOCK_STREAM;
  48 + hints.ai_flags = AI_PASSIVE;
  49 + hints.ai_protocol = 0;
  50 + hints.ai_canonname = NULL;
  51 + hints.ai_addr = NULL;
  52 + hints.ai_next = NULL;
  53 +
  54 + struct addrinfo *result;
  55 + int s;
  56 +
  57 + s = getaddrinfo(hostName, NULL, &hints, &result);
  58 +
  59 + if (s != 0)
  60 + {
  61 + return NOHOST;
  62 + }
  63 +
  64 + struct sockaddr_in *h;
  65 + h = (struct sockaddr_in *) result->ai_addr;
  66 +
  67 + memcpy(addr,h,sizeof(struct sockaddr_in));
  68 +
  69 + freeaddrinfo(result);
  70 +
  71 + return 0;
  72 +}
  73 +
  74 +/*----------------------- GET User Host-------------------------------*/
  75 +int GetUserHost()
  76 +{
  77 + char HostName[HOSTNAMELENGTH];
  78 + struct hostent *Host;
  79 + unsigned int HostAddress;
  80 + int userid;
  81 + static unsigned int m1 = 0X000000FF;
  82 + static unsigned int m2 = 0X0000FF00;
  83 + static unsigned int m3 = 0X00FF0000;
  84 + static unsigned int m4 = 0XFF000000;
  85 + unsigned int b1,b2,b3,b4;
  86 +
  87 + userid = getuid(); /* Get a client user ID */
  88 +
  89 +/* UserHost can be set by extern WEB function in case of WEB communicatio,
  90 + * or it should be defined as local host if DD_client is installed at USER
  91 + * computer
  92 + */
  93 + if(UserHost[0] == '\0')
  94 + {
  95 + gethostname(HostName,HOSTNAMELENGTH); /* Get a client host name */
  96 +
  97 + struct sockaddr_in addr;
  98 +
  99 + if (getInfoFromHostName(HostName,&addr) != 0)
  100 + return NOHOST;
  101 +
  102 + unsigned int b1, b2, b3, b4;
  103 + sscanf(inet_ntoa( addr.sin_addr), "%3u.%3u.%3u.%3u", &b1, &b2, &b3, &b4);
  104 + snprintf(UserHost, MAXHOSTLENGTH, "%03u.%03u.%03u.%03u", b1, b2, b3, b4);
  105 + }
  106 + return userid;
  107 +}
  108 +/*-------------------------------------------------------------------*/
  109 +
  110 +
  111 +/*------------------ MAKE_CONNECTION ---------------------------*/
  112 +/*
  113 + * The function returns opened socket, ready to read and write
  114 + */
  115 +int GetSocket()
  116 +/*
  117 + * Connect with remote server, and returns socket ID
  118 + * In case of error return error number according DD_comm.h
  119 + */
  120 +{
  121 +/*-------- Variables for resource file -----------------*/
  122 + char rname[PATHLENGTH]; /* name of res file */
  123 + char line[PATHLENGTH];
  124 + char *path;
  125 + FILE *resfile; /* resource file */
  126 + char *pline;
  127 +
  128 +/*---------- Variables for network ---------------------*/
  129 + static struct hostent *Host; /* name & internet (32b) address for
  130 + remout hosts (see netdb.h) */
  131 + static char RemSerName[PATHLENGTH]; /* name of remote server */
  132 +
  133 + struct servent *serv; /* pointer to static structure of
  134 + port number of registrated service */
  135 +
  136 + static struct sockaddr_in IntAFAddr; /* structure of internet address of type AF_INET
  137 + see <netinet/in.h>
  138 + to get name of socket we should
  139 + to convert pointer to this structure
  140 + to pointer to "srtruct sockaddr" where
  141 + all fields are "char array". */
  142 +
  143 + int AFAddrLen = sizeof(struct sockaddr_in); /* size of internet address, <netinet/in.h> 18 bytes*/
  144 + int ScAddrLen = sizeof(struct sockaddr); /* size of socket address, <sys/socket.h> 18 bytes*/
  145 +
  146 + int cc,i;
  147 + int arg = 0;
  148 + int normaddr;
  149 +/*
  150 + *---------- Getting socket and its address ---------------------*/
  151 +/*---------------- HOST and PORT ------------------------------*/
  152 + if((path = getenv("DDPATH")) == NULL)
  153 + {
  154 + strcpy(rname,"DD.res");
  155 + }
  156 + else
  157 + {
  158 + strcpy(rname,path);
  159 + strcat(rname, "/DD.res");
  160 + }
  161 +/*
  162 + (void *)strcpy(rname,"./DD.res");
  163 +*/
  164 + if((resfile = fopen(rname,"r")) == NULL)
  165 + {
  166 + fprintf(stderr,"No resource file, sorry\n");
  167 + exit(1);
  168 + }
  169 +
  170 + pline = fgets(RemSerName, PATHLENGTH-1, resfile);
  171 + pline = fgets(line, PATHLENGTH-1, resfile);
  172 + fclose(resfile);
  173 +
  174 + RemSerName[strlen(RemSerName)-1] = '\0';
  175 + sscanf(line,"%d",&(normaddr));
  176 +
  177 + if (getInfoFromHostName(RemSerName,&IntAFAddr) != 0)
  178 + return NOHOST;
  179 +
  180 + IntAFAddr.sin_port = htons((uint16_t)normaddr); /* Conversion of the port number to
  181 + universal net form */
  182 +/*---------------- END of FILE READING --------------------------*/
  183 +/*
  184 + *------- Trying to open socket with this address and name ---------
  185 + */
  186 +
  187 + if((SocketID = socket(AF_INET,SOCK_STREAM,PROTOCOL)) < 0)
  188 + {
  189 + perror("Socket:"); return(-1);
  190 + }
  191 +
  192 +/* Filling full internet address for socket "name"
  193 + * this address will be used to get communication point */
  194 +
  195 + IntAFAddr.sin_family = Host->h_addrtype;
  196 + memcpy(&IntAFAddr.sin_addr.s_addr,Host->h_addr_list[0],Host->h_length);
  197 +
  198 + /* Connection to server socket on remote computer */
  199 + if(connect(SocketID,(struct sockaddr *)&IntAFAddr,AFAddrLen) < 0)
  200 + { perror("connect"); return(-1); }
  201 +
  202 +/*
  203 + * Get Host name and Host ID for security application
  204 + */
  205 + if((UserID = GetUserHost()) < 0) return(NOHOST);
  206 +
  207 + return SocketID;
  208 +}
  209 +/*------------------- end of GetSocket ---------------------*/
  210 +
  211 +/*==================== Receive From Net ======================*/
  212 +/*
  213 + * Smart buffered receiver
  214 + */
  215 +int ReceiveFromNet(char *buf, int PacketSize)
  216 +{
  217 + int CurLength = 0;
  218 + int i,cc;
  219 + do
  220 + {
  221 + i = 0;
  222 + while(((cc = recv(SocketID,buf+ CurLength,PacketSize - CurLength,0)) < 0) && (i < TRY)) i++;
  223 + if(cc < 0) return -1;
  224 + CurLength = CurLength + cc;
  225 + } while(CurLength < PacketSize);
  226 + return 1;
  227 +}
  228 +
  229 +/*------------------ Open Virtual Instrument -----------------------*/
  230 +/*
  231 + * If no connection, connect to server, then try to order data set and return
  232 + * ID if OK or ErrorNumber if not
  233 + */
  234 +int DD_SetVariable(char *InstrName)
  235 +{
  236 + static caddr_t buff = NULL;
  237 + static XDR xdrs;
  238 + int InstrID; /* Instrumnet ID to return */
  239 + int cc,i;
  240 + int Request = OPENINSREQ;
  241 + int hostlen,userlen;
  242 + char *PUserHost = UserHost, *PUserName = UserName;
  243 + /* We need this because XDR works with adresses of pointers */
  244 +
  245 +/* If there is no connection, try to get it */
  246 + if(SocketID < 0)
  247 + if((SocketID = GetSocket()) < 0) return(NOCONNECTION);
  248 +
  249 +/* Encoding request by XDR to buf */
  250 +/* Buffer and stream allocation */
  251 + buff = (caddr_t)malloc(REQUESTLENGTH);
  252 +
  253 + xdrmem_create(&xdrs, buff, REQUESTLENGTH, XDR_ENCODE);
  254 +
  255 + xdr_int(&xdrs,&Request);
  256 + xdr_string(&xdrs, &InstrName, strlen(InstrName));
  257 +
  258 +/* Send Open Virtual Instrument request */
  259 +
  260 + if((cc = send(SocketID,buff,REQUESTLENGTH,0)) < 0)
  261 + {
  262 + perror("DD_SetVariable:");
  263 + free(buff);
  264 + xdr_destroy(&xdrs);
  265 + return(REQSENDERR);
  266 + }
  267 + xdrmem_create(&xdrs, buff, REQUESTLENGTH, XDR_FREE);
  268 +
  269 +/*-------- preparation an authorization request ----------------*/
  270 + if(UserName[0] == '\0') strcpy(UserName,NONAME);
  271 + hostlen = strlen(UserHost);
  272 + userlen = strlen(UserName);
  273 +
  274 + xdrmem_create(&xdrs, buff,REQUESTLENGTH, XDR_ENCODE);
  275 +
  276 + xdr_int(&xdrs,&UserID);
  277 + xdr_string(&xdrs, &PUserHost, hostlen);
  278 + xdr_string(&xdrs, &PUserName, userlen);
  279 +/* fprintf(stderr,"userid %d host %s DD_name %s\n",UserID,UserHost,UserName); */
  280 +
  281 +/* Send request */
  282 + if((cc = send(SocketID,buff,REQUESTLENGTH,0)) < 0)
  283 + {
  284 + perror("DD_Set_Variable:");
  285 + free(buff);
  286 + xdr_destroy(&xdrs);
  287 + return(REQSENDERR);
  288 + }
  289 +
  290 + free(buff);
  291 + xdr_destroy(&xdrs);
  292 +
  293 +/* Get reply */
  294 + buff = (caddr_t)malloc(REPLYLENGTH);
  295 +/*
  296 + i=0;
  297 + while(((cc = recv(SocketID,buff,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  298 +*/
  299 + if((cc = ReceiveFromNet(buff, REPLYLENGTH)) < 0)
  300 + {
  301 + perror("DD_SET_Variable:");
  302 + free(buff);
  303 + return(REPLYRECERR);
  304 + }
  305 +
  306 + xdrmem_create(&xdrs, buff, REPLYLENGTH, XDR_DECODE);
  307 + xdr_int(&xdrs,&InstrID);
  308 +
  309 +/* Free all */
  310 + free(buff);
  311 + xdr_destroy(&xdrs);
  312 +
  313 + return InstrID;
  314 +}
  315 +
  316 +/*----------------------- DD_GetInform -----------------------------*/
  317 +/*
  318 + * Returns "OK" if OK, fill DD_Data structure
  319 + * Return negative value if error
  320 + */
  321 +
  322 +int DD_GetInform(int VarID,char *AttrName,DD_data_t **data)
  323 +{
  324 + static void *v = NULL;
  325 + static DD_data_t idd = {DD_CHAR, 0, NULL,1, &v};
  326 + static caddr_t buf = NULL;
  327 + static XDR xdrs;
  328 + int id;
  329 + int cc;
  330 + int length;
  331 + int op = DATAINFOREQ;
  332 + int type; /* type of information or error */
  333 + int DimNumbers;
  334 + int PacketSize;
  335 + int CurLength;
  336 + int i;
  337 + u_int count;
  338 + u_int MaxNumber;
  339 +
  340 +/*------------------- Empty static data ------------------------*/
  341 + if(idd.Dimensions != NULL)
  342 + {
  343 + free(idd.Dimensions);
  344 + idd.Dimensions = NULL;
  345 + }
  346 + if(idd.Variables[0] != NULL)
  347 + {
  348 + free(idd.Variables[0]);
  349 + idd.Variables[0] = NULL;
  350 + }
  351 +
  352 +/*------------------ Check the Name length -----------------------*/
  353 + if(strlen(AttrName) > MAXVARLENGTH) length = MAXVARLENGTH;
  354 + else length = strlen(AttrName);
  355 +
  356 +/*----------- Allocation of memory and stream --------------------*/
  357 + buf = (caddr_t)malloc(REQUESTLENGTH);
  358 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  359 +
  360 +/*------------------- Encoding the request ----------------------*/
  361 + xdr_int(&xdrs,&op);
  362 + xdr_int(&xdrs,&VarID);
  363 + xdr_string(&xdrs, &AttrName, length);
  364 +
  365 +/*------------------------ Send request ---------------------------*/
  366 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  367 + {
  368 + perror("DD_GetInform:");
  369 + free(buf);
  370 + xdr_destroy(&xdrs);
  371 + return(REQSENDERR);
  372 + }
  373 + free(buf);
  374 + xdr_destroy(&xdrs);
  375 +
  376 +/*------------------------ Get reply header ------------------------*/
  377 +
  378 + buf = (caddr_t)malloc(REPLYLENGTH);
  379 +/*
  380 + i=0;
  381 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  382 + if(cc < 0)
  383 +*/
  384 + if((cc = ReceiveFromNet(buf, REPLYLENGTH)) < 0)
  385 + {
  386 + perror("DD_GetInform:");
  387 + free(buf);
  388 + return(REPLYRECERR);
  389 + }
  390 +
  391 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  392 + xdr_int(&xdrs,&type);
  393 + if(type < 0)
  394 + {
  395 + free(buf);
  396 + xdr_destroy(&xdrs);
  397 + return(type);
  398 + }
  399 + xdr_int(&xdrs,&DimNumbers);
  400 + xdr_int(&xdrs,&PacketSize);
  401 + free(buf);
  402 + xdr_destroy(&xdrs);
  403 +
  404 + idd.DimNumber = DimNumbers;
  405 + idd.type = type;
  406 +
  407 +/*---------------------------- Get Data Packet ----------------------*/
  408 + if(PacketSize > 0) buf = (caddr_t)malloc(PacketSize);
  409 + else return(REPLYRECERR);
  410 +
  411 + if((cc = ReceiveFromNet(buf, PacketSize)) < 0)
  412 + {
  413 + perror("DD_GetInform:");
  414 + free(buf);
  415 + return(REPLYRECERR);
  416 + }
  417 +
  418 +/*--------------------- Decoding data packet ------------------------*/
  419 + if(DimNumbers > 0)
  420 + {
  421 +/*----------- Memory allocation and xdr creating -----------------*/
  422 + xdrmem_create(&xdrs, buf, (u_int)PacketSize, XDR_DECODE);
  423 +
  424 +/*----------------- Dimensions decoding -------------------------*/
  425 + if(idd.Dimensions !=NULL) free(idd.Dimensions);
  426 + idd.Dimensions = (int *)malloc(DimNumbers*sizeof(int));
  427 +
  428 + xdr_array(&xdrs, (caddr_t *)&(idd.Dimensions),
  429 + &count,
  430 + (u_int )DimNumbers,
  431 + unixlen[DD_INT],
  432 + (xdrproc_t)xdr_int);
  433 +
  434 + count = 1;
  435 + for(i=0; i < DimNumbers;i++)
  436 + count = count*idd.Dimensions[i];
  437 + MaxNumber = count;
  438 + }
  439 + else
  440 + {
  441 + free(buf);
  442 + return(REPLYRECERR);
  443 + }
  444 +
  445 +/*---------------- Allocate memory for Variables and decoding ------------------*/
  446 + if(idd.Variables[0] != NULL) free(idd.Variables[0]);
  447 + idd.Variables[0] = (int *)malloc(unixlen[type] * MaxNumber);
  448 +
  449 + xdr_array(&xdrs,((caddr_t*)(&idd.Variables[0])),&count,
  450 + MaxNumber, unixlen[type], (xdrproc_t)ConvFunc[type]);
  451 +
  452 +/*-------------------------- Free all ------------------------------*/
  453 + free(buf);
  454 + xdr_destroy(&xdrs);
  455 +
  456 + *data = &idd;
  457 + return OK;
  458 +}
  459 +
  460 +/*====================================================
  461 + * DD_SetTime()
  462 + *====================================================*/
  463 +/*-----------------------------------------------------
  464 + * VarID - ID of Data Set
  465 + * Time - string in DD type
  466 + * Returns 1 if OK and negative in case of err
  467 + *---------------------------------------------------*/
  468 +
  469 +int DD_SetTime(int VarID,char *Time)
  470 +{
  471 + static caddr_t buf = NULL;
  472 + static XDR xdrs;
  473 + static int op = TIMESETREQ;
  474 + int type;
  475 + int cc,i;
  476 + int DoneFlag = 0;
  477 +
  478 + while(DoneFlag == 0)
  479 + {
  480 +/* Allocatein memory and stream */
  481 + buf = (caddr_t)malloc(REQUESTLENGTH);
  482 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  483 +
  484 +/* Encoding the request */
  485 + xdr_int(&xdrs,&op);
  486 + xdr_int(&xdrs,&VarID);
  487 + xdr_string(&xdrs, &Time, TIMELENGTH);
  488 +
  489 +/* Send request */
  490 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  491 + {
  492 + perror("DD_SetTime:");
  493 + free(buf);
  494 + xdr_destroy(&xdrs);
  495 + return(REQSENDERR);
  496 + }
  497 + free(buf);
  498 + xdr_destroy(&xdrs);
  499 +
  500 +/* Get reply header */
  501 +
  502 + buf = (caddr_t)malloc(REPLYLENGTH);
  503 + if((cc = ReceiveFromNet(buf, REPLYLENGTH)) < 0)
  504 + {
  505 + perror("DD_SetTime:");
  506 + free(buf);
  507 + return(REPLYRECERR);
  508 + }
  509 +
  510 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  511 + xdr_int(&xdrs,&type);
  512 +
  513 + free(buf);
  514 + xdr_destroy(&xdrs);
  515 +
  516 + if(type < 0)
  517 + {
  518 + if(type == CACHTOOREC) sleep((unsigned )(FILEACCMARG));
  519 + else return type;
  520 + }
  521 + else DoneFlag = 1;
  522 + }
  523 + return 1 ;
  524 +}
  525 +
  526 +/*==================================================================
  527 + * DD_SetTimeInfo()
  528 + *=================================================================*/
  529 +/*----------------------------------------------------------
  530 + * VarID - ID of Data Set
  531 + * Time - string in DD type
  532 + * RealTime - double : time value pointer points to
  533 + * Returns 1 if OK and negative in case of err
  534 + *----------------------------------------------------------*/
  535 +
  536 +int DD_SetTimeInfo(int VarID, char *Time, double *RealTime)
  537 +{
  538 + int err;
  539 + static char TimeInt[17] = "0000000000001000\0";
  540 + DD_data_t *data;
  541 +
  542 + err = DD_SetTime(VarID, Time);
  543 + if (err < 1) return err;
  544 +
  545 + err = DD_GetData(VarID, "Time", TimeInt, &data);
  546 + if (err < 0) return err;
  547 + if (data->VarNumber < 1) return OUTOFTIME;
  548 +
  549 + *RealTime = DD_Time2Double((char *)data->Variables[0]);
  550 +
  551 + //BRE - When the corresponding time is the last one of a file, MOREDATA is returned by DDServer.
  552 + // => force recall of DD_GetData to open the next file and finish correctly the request
  553 + if (err == MOREDATA)
  554 + {
  555 + if ((err = DD_GetData(VarID, (char *)"Time", TimeInt, &data)) < 0)
  556 + {
  557 + while ((err == WAITEXTCALL) || (err == TRYAGAIN))
  558 + {
  559 + sleep(2);
  560 + err = DD_GetData(VarID, (char *)"Time", TimeInt, &data);
  561 + }
  562 + }
  563 + }
  564 +
  565 + return 1 ;
  566 +}
  567 +
  568 +/*=========================================================
  569 + * DD_GetData()
  570 + * Just an interface to the DD_GetMultiData()
  571 + *========================================================*/
  572 +int DD_GetData(int VarID, char *VarName, char *TimeInt, DD_data_t **data)
  573 +{
  574 + char *xxx=VarName;
  575 + int err;
  576 + err = DD_GetMultiData(VarID, 1, &xxx, TimeInt, data, 1);
  577 + return err;
  578 +}
  579 +/*=========================================================
  580 + * DD_GetMultiData()
  581 + *========================================================*/
  582 +/*---------------------------------------------------------
  583 + * VarID - ID of open virtual instrument
  584 + * VarSize - the size of the array names
  585 + * VarNames - araay of the variables names
  586 + * TimeInt - Time interval in DD_time style
  587 + * data - returned data
  588 + * Return values:
  589 + * positives:
  590 + * MOREDELAY - call this function again after delay
  591 + * MOREDATA - call this function again to complete request
  592 + * OK - all data received
  593 + * negative value - error (see DD.h)
  594 + *---------------------------------------------------------*/
  595 +
  596 +int DD_GetMultiData(int VarID,size_t VarSize, char **VarNames,char *TimeInt,DD_data_t **data, int BackFlag)
  597 +{
  598 + static DD_data_t *CurrentData = NULL; /* Data records array to keep until the next call */
  599 + static size_t OldVarSize = 0;
  600 + static caddr_t buf = NULL;
  601 + static XDR xdrs;
  602 + static int LastPacketFlag = OK;
  603 + int id;
  604 + int cc;
  605 + int *NameLength = NULL; /* Array of lengths */
  606 + int XDRStrLen; /* xdr length of a string */
  607 + int XDRReqlength; // Length in bytes the XDR stream
  608 + int op = DATAGETREQ;
  609 + int type; /* type of information or error */
  610 + int DimNumbers;
  611 + int PacketSize;
  612 + int CurLength;
  613 + u_int count, MaxSize;
  614 + int i;
  615 +
  616 + /* Empty static data */
  617 + for(id = 0; id < OldVarSize; id++)
  618 + {
  619 + if(CurrentData[id].Dimensions != NULL)
  620 + {
  621 + free(CurrentData[id].Dimensions);
  622 + CurrentData[id].Dimensions = NULL;
  623 + }
  624 + if(CurrentData[id].Variables != NULL)
  625 + {
  626 + for(i = 0; i< CurrentData[id].VarNumber; i++)
  627 + free(CurrentData[id].Variables[i]);
  628 + free(CurrentData[id].Variables);
  629 + CurrentData[id].Variables = NULL;
  630 + }
  631 + }
  632 + free(CurrentData);
  633 +
  634 + /*--------------------------------------
  635 + * Create a new Current Data empty array
  636 + *-------------------------------------*/
  637 + OldVarSize = VarSize;
  638 + CurrentData = (DD_data_t *)malloc(sizeof(DD_data_t)*VarSize);
  639 + for(id = 0; id < VarSize; id++)
  640 + {
  641 + CurrentData[id].Dimensions = NULL;
  642 + CurrentData[id].Variables = NULL;
  643 + CurrentData[id].DimNumber = 0;
  644 + CurrentData[id].VarNumber = 0;
  645 + CurrentData[id].type = 0;
  646 + }
  647 + /*--------------------------------------------------------------
  648 + * The follows request preparation and send is performed only
  649 + * if the priveous data packed is completely received
  650 + *--------------------------------------------------------------*/
  651 + if((LastPacketFlag == OK) || (LastPacketFlag == MOREDELAY))
  652 + {
  653 + /*---------------------------------------
  654 + * Preparation of the array the name lengths
  655 + * Note that the names are cut down to the MAXVARLENGTH
  656 + * Calculation the packet size
  657 + *---------------------------------------*/
  658 + NameLength = (int *)malloc(sizeof(int)*VarSize);
  659 + XDRReqlength = 8; /* the length of the first+last arguments */
  660 + for(id = 0; id < VarSize; id++)
  661 + {
  662 + if(strlen(VarNames[id]) > MAXVARLENGTH) NameLength[id] = MAXVARLENGTH;
  663 + else NameLength[id] = strlen(VarNames[id]);
  664 + XDRStrLen = (NameLength[id] / 4) * 4;
  665 + if((NameLength[id] % 4) > 0) XDRStrLen += 4;
  666 + XDRReqlength += XDRStrLen + 4; // String length + 4 bytes length coding
  667 + //fprintf(stderr,"Variable %s, length %d, total %d\n",VarNames[id],XDRStrLen,XDRReqlength);
  668 + }
  669 + /*--------------------------------
  670 + * The first packet of the request of the standard size
  671 + * Allocation corresponding memory and stream
  672 + *------------------------------*/
  673 + buf = (caddr_t)malloc(REQUESTLENGTH);
  674 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  675 +
  676 + /* Encoding the request */
  677 + xdr_int(&xdrs,&op);
  678 + xdr_int(&xdrs,&VarID);
  679 + xdr_string(&xdrs,&TimeInt,TIMELENGTH);
  680 + xdr_int(&xdrs,&XDRReqlength);
  681 +
  682 + /* Send the first request */
  683 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  684 + {
  685 + perror("DD_GetData: First Request");
  686 + free(buf);
  687 + xdr_destroy(&xdrs);
  688 + return(REQSENDERR);
  689 + }
  690 + free(buf);
  691 + xdr_destroy(&xdrs);
  692 +
  693 + /*--------------------------------
  694 + * The Second packet of XDRReqlength size
  695 + * Allocation corresponding memory and stream
  696 + *------------------------------*/
  697 + buf = (caddr_t)malloc(XDRReqlength);
  698 + xdrmem_create(&xdrs, buf, XDRReqlength, XDR_ENCODE);
  699 + xdr_int(&xdrs,(int *)(&VarSize));
  700 + for(id = 0; id < VarSize; id++) xdr_string(&xdrs, &VarNames[id], NameLength[id]);
  701 + xdr_int(&xdrs,&BackFlag);
  702 +
  703 + /* Send the second request */
  704 + if((cc = send(SocketID,buf,XDRReqlength,0)) < 0)
  705 + {
  706 + perror("DD_GetData:Second Packet");
  707 + free(buf);
  708 + xdr_destroy(&xdrs);
  709 + return(REQSENDERR);
  710 + }
  711 + free(buf);
  712 + xdr_destroy(&xdrs);
  713 + }
  714 +
  715 + /*-----------------------------------------------------------
  716 + * Get the VarSize reply headers and VarSize data
  717 + *----------------------------------------------------------*/
  718 + for(id = 0; id < VarSize; id++)
  719 + {
  720 + /*-------------------
  721 + * The header
  722 + *-----------------*/
  723 + buf = (caddr_t)malloc(REPLYLENGTH);
  724 + if((cc = ReceiveFromNet(buf, REPLYLENGTH)) < 0)
  725 + {
  726 + perror("DD_GetData:Error while header receive");
  727 + free(buf);
  728 + return(REPLYRECERR);
  729 + }
  730 +
  731 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  732 + xdr_int(&xdrs,&type);
  733 + xdr_int(&xdrs,&DimNumbers);
  734 + xdr_int(&xdrs,&PacketSize);
  735 + free(buf);
  736 + xdr_destroy(&xdrs);
  737 +
  738 + if((type < 0) && (type != NOVAR)) /* Server returns unrecoverable error */
  739 + {
  740 + fprintf(stderr,"DD_GetData: Server returns %d, unrecovable error\n",type);
  741 + return type;
  742 + }
  743 +
  744 + /*----------- Header is received ----------------------*/
  745 + CurrentData[id].DimNumber = DimNumbers - 1;
  746 + CurrentData[id].type = type;
  747 +
  748 + /*--------------- Receive Data Packet ------------------------------*/
  749 + if(PacketSize > 0) buf = (caddr_t)malloc(PacketSize);
  750 + else return(REPLYRECERR);
  751 + if((cc = ReceiveFromNet(buf, PacketSize)) < 0)
  752 + {
  753 + perror("DD_GetData: Error while data packet receive");
  754 + free(buf);
  755 + return(REPLYRECERR);
  756 + }
  757 + /*----------------- Decoding data packet --------------------*/
  758 + if(DimNumbers > 1)
  759 + {
  760 + xdrmem_create(&xdrs, buf, (u_int)PacketSize, XDR_DECODE);
  761 + count = DimNumbers-1;
  762 + /* allocation memory for dimensions */
  763 + CurrentData[id].Dimensions = (int *)malloc((DimNumbers-1)*sizeof(int));
  764 +
  765 + xdr_int(&xdrs,&LastPacketFlag); /* Last Paket Indicatort*/
  766 + xdr_int(&xdrs,&CurrentData[id].VarNumber); /* Variables number */
  767 +
  768 + if(LastPacketFlag > 2)
  769 + {
  770 + LastPacketFlag = OK;
  771 + CurrentData[id].VarNumber = 0;
  772 + free(buf);
  773 + return(REPLYRECERR);
  774 + }
  775 +
  776 + /*----- Decoding dimensions array -------------------*/
  777 + xdr_array(&xdrs, (caddr_t *)&(CurrentData[id].Dimensions),
  778 + &count,
  779 + (u_int )DimNumbers-1,
  780 + unixlen[DD_INT],
  781 + (xdrproc_t)xdr_int);
  782 +
  783 + count = 1;
  784 + for(i=0; i < DimNumbers-1;i++)
  785 + {
  786 + count = count*CurrentData[id].Dimensions[i];
  787 + }
  788 + MaxSize = count;
  789 + }
  790 + else
  791 + {
  792 + if(type != NOVAR)
  793 + {
  794 + free(buf);
  795 + return(REPLYRECERR);
  796 + }
  797 + else
  798 + {
  799 + CurrentData[id].VarNumber = 0;
  800 + }
  801 + }
  802 +
  803 + /*---------- Decoding variables -------------------------*/
  804 + if(CurrentData[id].VarNumber != 0) CurrentData[id].Variables = (void *)malloc(CurrentData[id].VarNumber*sizeof(void *));
  805 + else CurrentData[id].Variables = NULL;
  806 +
  807 + for(i = 0; i < CurrentData[id].VarNumber; i++)
  808 + {
  809 + CurrentData[id].Variables[i] = (void *)malloc(unixlen[type]*MaxSize);
  810 + count = MaxSize;
  811 + xdr_array(&xdrs,(caddr_t *)(&(CurrentData[id].Variables[i])),&count,MaxSize,unixlen[type], (xdrproc_t)ConvFunc[type]);
  812 + }
  813 +
  814 + /* Free all */
  815 + free(buf);
  816 + xdr_destroy(&xdrs);
  817 + }
  818 + *data = CurrentData;
  819 + return(LastPacketFlag);
  820 +}
  821 +/*===================================================================*/
  822 +
  823 +/*-------------------------- DD_CLOSE --------------------------------*/
  824 +/*
  825 + *
  826 + * VarID - entry point of ID table
  827 + * Returns 1 if OK or negative err
  828 + * Close Socket if no VarID more ( this information supplyed by server )
  829 + */
  830 +
  831 +int DD_Close(int VarID)
  832 +{
  833 + static caddr_t buf = NULL;
  834 + static XDR xdrs;
  835 + static int op = CLOSEINSREQ;
  836 + int RemainedID; /* Server returns number of remained ID */
  837 + int cc,i;
  838 +/* Allocatein memory and stream */
  839 + buf = (caddr_t)malloc(REQUESTLENGTH);
  840 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  841 +
  842 +/* Encoding the request */
  843 + xdr_int(&xdrs,&op);
  844 + xdr_int(&xdrs,&VarID);
  845 +
  846 +/* Send request */
  847 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  848 + {
  849 + perror("DD_Close:");
  850 + free(buf);
  851 + xdr_destroy(&xdrs);
  852 + return(REQSENDERR);
  853 + }
  854 + free(buf);
  855 + xdr_destroy(&xdrs);
  856 +
  857 +/* Get reply header */
  858 +
  859 + buf = (caddr_t)malloc(REPLYLENGTH);
  860 +/*
  861 + i = 0;
  862 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  863 + if(cc < 0)
  864 +*/
  865 + if((cc = ReceiveFromNet(buf, REPLYLENGTH)) < 0)
  866 + {
  867 + perror("DD_Close:");
  868 + free(buf);
  869 + return(REPLYRECERR);
  870 + }
  871 +
  872 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  873 + xdr_int(&xdrs,&RemainedID);
  874 + if(RemainedID< 0)
  875 + {
  876 + free(buf);
  877 + xdr_destroy(&xdrs);
  878 + return(RemainedID);
  879 + }
  880 + free(buf);
  881 + xdr_destroy(&xdrs);
  882 +
  883 + if(RemainedID == 0)
  884 + {
  885 + shutdown(SocketID,2);
  886 + close(SocketID);
  887 + SocketID = -1;
  888 +/*
  889 + UserHost[0] = '\0';
  890 + UserName[0] = '\0';
  891 +*/
  892 + }
  893 +
  894 + return(1);
  895 +}
  896 +/*------------------------------------------------------------------------------*/
  897 +
  898 +/*=============== DATABASE UPDATE FUNCTIONS ====================================*/
  899 +/*------------------ DD_AddDataSet() -------------------------------------------*/
  900 +int DD_AddDataSet(char *DataSetName, char *RemSetID, char *BaseName)
  901 +{
  902 + static caddr_t buf = NULL;
  903 + static XDR xdrs;
  904 + static int op = ADDVIREQ;
  905 + int Err; /* Server returns OK or NOEXEC */
  906 + int cc,i,length;
  907 + int CloseFlag = 0;
  908 +
  909 +/* If there is no connection, try to get it */
  910 + if(SocketID < 0)
  911 + {
  912 + if((SocketID = GetSocket()) < 0) return(NOCONNECTION);
  913 + CloseFlag = 1; // To close Connection at the end
  914 + }
  915 +
  916 +/* Allocatein memory and stream */
  917 + buf = (caddr_t)malloc(REQUESTLENGTH);
  918 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  919 +
  920 +/* Encoding the request */
  921 + xdr_int(&xdrs,&op);
  922 +
  923 +/* Coding DataSetName */
  924 + if((length = strlen(DataSetName)) > MAXSETLENGTH) length = MAXSETLENGTH;
  925 + xdr_string(&xdrs, &DataSetName, length);
  926 +/* Coding RemSetID */
  927 + if((length = strlen(RemSetID)) > MAXVARLENGTH) length = MAXVARLENGTH;
  928 + xdr_string(&xdrs, &RemSetID, length);
  929 +/* Coding BaseName */
  930 + if((length = strlen(BaseName)) > MAXVARLENGTH) length = MAXVARLENGTH;
  931 + xdr_string(&xdrs, &BaseName, length);
  932 +
  933 +/* Send request */
  934 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  935 + {
  936 + perror("DD_AddDataSet:");
  937 + free(buf);
  938 + xdr_destroy(&xdrs);
  939 + return(REQSENDERR);
  940 + }
  941 + free(buf);
  942 + xdr_destroy(&xdrs);
  943 +
  944 +/* Get reply header */
  945 + buf = (caddr_t)malloc(REPLYLENGTH);
  946 + if((cc = ReceiveFromNet(buf, REPLYLENGTH)) < 0)
  947 + {
  948 + perror("DD_AddDataSet:");
  949 + free(buf);
  950 + return(REPLYRECERR);
  951 + }
  952 +
  953 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  954 + xdr_int(&xdrs,&Err);
  955 +
  956 + if(CloseFlag) // Close everything if function established connection
  957 + {
  958 + shutdown(SocketID,2);
  959 + close(SocketID);
  960 + SocketID = -1;
  961 +/* Session with DD Server was closed, but User Session continues !!!!! */
  962 + /* UserHost[0] = '\0';
  963 + UserName[0] = '\0'; */
  964 + }
  965 + return Err;
  966 +}
  967 +/*-----------------------------------------------------------------------------*/
  968 +
  969 +/*---------------------- DD GET VERSION ---------------------------------------*/
  970 +char *DD_GetVersion()
  971 +/*
  972 + * return static pointer to internal string with the DDLIB-SERVER package version
  973 + */
  974 +{
  975 + static char Version[] = VERSION;
  976 + return (char *)Version;
  977 +}
  978 +/*------------------------- End Library -------------------------------*/
... ...
src/DDClientLibC/DD_time.c 0 → 100755
  1 +++ a/src/DDClientLibC/DD_time.c
... ... @@ -0,0 +1,321 @@
  1 +/* ===================================================================
  2 + * Name : DD_time.c
  3 + * Version: : 4.1
  4 + * Author : Andrey Fedorov
  5 + * Institution : IRAP/UPS/CNRS Toulouse
  6 + * Modifications list:
  7 + * Oct 5, 2002: V.3.0, New functions DD_Time2Double and Double2DD_Time were added.
  8 + * March 26, 2010: V.3.1 YEARS up to 2025
  9 + * May 17, 2011: V.4.0 Fedorov, completely revised version.
  10 + * There is no more confuse between Time and Time Interval
  11 + * Sept 05, 2011: V.4.1 SetIntNew => arg TimeKind => to work with 1970-1973 : BR
  12 + *==================================================================*/
  13 +
  14 +#include "DD_time.h"
  15 +#include <stdio.h>
  16 +#include <string.h>
  17 +#include <stdarg.h>
  18 +
  19 +#define YEARS 56
  20 +#define STARTYEAR 1970
  21 +
  22 +/*---- Static array of days shift from Jan-1-1970 -------*/
  23 +/* 1970 1971 1972 1973 1974 1975 1976
  24 + * 1977 1978 1979 1980 1981 1982 1983
  25 + * 1984 1985 1986 1987 1988 1989 1990
  26 + * 1991 1992 1993 1994 1995 1996 1997
  27 + * 1998 1999 2000 2001 2002 2003 2004
  28 + * 2005 2006 2007 2008 2009 2010 2011
  29 + * 2012 2013 2014 2015 2016 2017 2018
  30 + * 2019 2020 2021 2022 2023 2024 2025
  31 + */
  32 +static double
  33 + YearDays[YEARS] = { 0.0, 365.0, 730.0, 1096.0, 1461.0, 1826.0, 2191.0,
  34 + 2557.0, 2922.0, 3287.0, 3652.0, 4018.0, 4383.0, 4748.0,
  35 + 5113.0, 5479.0, 5844.0, 6209.0, 6574.0, 6940.0, 7305.0,
  36 + 7670.0, 8035.0, 8401.0, 8766.0, 9131.0, 9496.0, 9862.0,
  37 + 10227.0, 10592.0, 10957.0, 11323.0, 11688.0, 12053.0, 12418.0,
  38 + 12784.0, 13149.0, 13514.0, 13879.0, 14245.0, 14610.0, 14975.0,
  39 + 15340.0, 15706.0, 16071.0, 16436.0, 16801.0, 17167.0, 17532.0,
  40 + 17897.0, 18262.0, 18628.0, 18993.0, 19358.0, 19723.0, 20089.0};
  41 +
  42 +/*-------------------------------------------------------------
  43 + * DAY_OF_YEAR = monthday[*][month-1]+day_of_month -1
  44 + *------------------------------------------------------------*/
  45 +static int monthday[2][12] =
  46 +{
  47 +{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
  48 +{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
  49 +};
  50 +
  51 +/*------------------------------------------------------------
  52 + * Global static Flag to show the current state of the time
  53 + * processor. Is it Time interval (0), or DD Time (1)
  54 + *----------------------------------------------------------*/
  55 +static int TimeFlag = 1;
  56 +/*================== INTERNAL FUNCTION ====================*/
  57 +/*-------------------- SetInt ----------------------------*/
  58 +void SetInt(dd_tmstr_t *UT)
  59 +{
  60 + SetIntNew(UT,DD_TM_UNKNOWN);
  61 +}
  62 +
  63 +void SetIntNew(dd_tmstr_t *UT,t_DDTimeKind timeKind) /* Fill int values of dd_tmstr_t */
  64 +/* If the double times field of UT structure is defined,
  65 + * this function fills remains fields of Year, day .... separately
  66 + */
  67 +{
  68 + static double msofday = 24.0*60.0*60.0;
  69 + static double msofhour = 60.0*60.0;
  70 + static double msofmin = 60.0;
  71 + long daynumber;
  72 + double msrest;
  73 + int i;
  74 +
  75 + daynumber = (long)(UT->times / msofday);
  76 + for(i=0;i<YEARS;i++) if(daynumber < (long)YearDays[i]) break;
  77 + i--;
  78 +
  79 + switch(timeKind)
  80 + {
  81 + case DD_TM_DATE :
  82 + {
  83 + //it's a date
  84 + UT->year = i+1970;
  85 + UT->day = (int)(daynumber - (long)YearDays[i]);
  86 + break;
  87 + }
  88 + case DD_TM_TIME_INTERVAL :
  89 + {
  90 + //it's a time interval
  91 + UT->year = 0;
  92 + UT->day = (int)(daynumber);
  93 + break;
  94 + }
  95 + default :
  96 + //compatibility mode
  97 + if(i > 3)
  98 + {
  99 + UT->year = i+1970;
  100 + UT->day = (int)(daynumber - (long)YearDays[i]);
  101 + }
  102 + else
  103 + {
  104 + UT->year = 0;
  105 + UT->day = (int)(daynumber);
  106 + }
  107 + break;
  108 + }
  109 +
  110 + msrest = UT->times - (double)daynumber * msofday;
  111 + UT->hour = (int)(msrest / msofhour);
  112 + msrest -= (double)(UT->hour)*msofhour;
  113 + UT->min = (int)(msrest / msofmin);
  114 + msrest -= (double)(UT->min)*msofmin;
  115 + UT->sec = (int)(msrest);
  116 + UT->msec = (int)((msrest - (double)(UT->sec))*1000.0);
  117 + return;
  118 +}
  119 +
  120 +/*---------------- end of SetInt -----------------------*/
  121 +
  122 +/*-------------------------------------------------------
  123 + * SetDouble()
  124 + * Returns the double value of seconds since 1 Jan 1970
  125 + * The calculations are made from already filled dd_tmstr_t.
  126 + * If UT->year
  127 + *------------------------------------------------------*/
  128 +void SetDouble(dd_tmstr_t *UT)
  129 +{
  130 + static double SecInMls = 1.0/1000.0;
  131 + static double SecImMin = 60.0;
  132 + static double SecInHour = 60.0*60.0;
  133 + static double SecInDay = 60.0*60.0*24.0;
  134 + if(UT->year >= STARTYEAR) // This is DD Time !
  135 + UT->times = (double)UT->msec*SecInMls +
  136 + (double)UT->sec +
  137 + (double)UT->min*SecImMin +
  138 + (double)UT->hour*SecInHour +
  139 + (double)UT->day*SecInDay +
  140 + YearDays[(UT->year - 1970)]*SecInDay;
  141 + else if(UT->year < STARTYEAR) // This is Time Interval
  142 + UT->times = (double)UT->msec*SecInMls +
  143 + (double)UT->sec +
  144 + (double)UT->min*SecImMin +
  145 + (double)UT->hour*SecInHour +
  146 + (double)UT->day*SecInDay +
  147 + YearDays[UT->year]*SecInDay;
  148 + else
  149 + UT->times = 0.0;
  150 + return;
  151 +}
  152 +/*----------------- end of SetDouble ---------------------*/
  153 +
  154 +/*=================== PUBLIC FUNCTIONS ==================*/
  155 +/*------------------- DD_Time2Double --------------------*/
  156 +double DD_Time2Double(dd_time_t UTstring)
  157 +{
  158 + static dd_tmstr_t UT;
  159 + static char year[5] = "0000\0";
  160 + static char day[4] = "000\0";
  161 + static char hour[3]= "00\0";
  162 + static char min[3] = "00\0";
  163 + static char sec[3]= "00\0";
  164 + static char msec[4] = "000\0";
  165 +
  166 + strncpy(year,UTstring,4);
  167 + strncpy(day,UTstring+4,3);
  168 + strncpy(hour,UTstring+7,2);
  169 + strncpy(min,UTstring+9,2);
  170 + strncpy(sec,UTstring+11,2);
  171 + strncpy(msec,UTstring+13,3);
  172 +
  173 + sscanf(year,"%d",&(UT.year));
  174 + sscanf(day,"%d",&(UT.day));
  175 + sscanf(min,"%d",&(UT.min));
  176 + sscanf(hour,"%d",&(UT.hour));
  177 + sscanf(sec,"%d",&(UT.sec));
  178 + sscanf(msec,"%d",&(UT.msec));
  179 + if(UT.year < STARTYEAR) TimeFlag = 0; // Time Inetrval
  180 +
  181 + SetDouble(&UT);
  182 + return UT.times;
  183 +}
  184 +/*------------------------------------------------------*/
  185 +
  186 +/*------------------- Double2DD_Time ---------------------*/
  187 + char *Double2DD_Time(double Time)
  188 + {
  189 + static dd_time_t UTstring;
  190 + dd_tmstr_t UT;
  191 +
  192 + UT.times = Time;
  193 + SetInt(&UT);
  194 + sprintf(UTstring,"%04d%03d%02d%02d%02d%03d",(UT.year),(UT.day),(UT.hour), (UT.min), (UT.sec),(UT.msec));
  195 + return &(UTstring[0]);
  196 + }
  197 +/*------------------------------------------------------------*/
  198 +
  199 +/*================== BACKUP COMPABILITY FUNCTIONS =================*/
  200 +/*-----------------------------------------------------------------
  201 + * ReadTime()
  202 + * Reads a standard DD time string as an argument
  203 + * and converts it into dd_tmstr_t structure.
  204 + * Function returns the pointer to the internal startic structure dd_tmstr_t.
  205 + * Function redefines TimeFlag.
  206 + *----------------------------------------------------------------*/
  207 +dd_tmstr_t *ReadTime(char *UTstring)
  208 +{
  209 + static dd_tmstr_t UT;
  210 + static char year[5] = "0000\0";
  211 + static char day[4] = "000\0";
  212 + static char hour[3]= "00\0";
  213 + static char min[3] = "00\0";
  214 + static char sec[3]= "00\0";
  215 + static char msec[4] = "000\0";
  216 +
  217 + strncpy(year,UTstring,4);
  218 + strncpy(day,UTstring+4,3);
  219 + strncpy(hour,UTstring+7,2);
  220 + strncpy(min,UTstring+9,2);
  221 + strncpy(sec,UTstring+11,2);
  222 + strncpy(msec,UTstring+13,3);
  223 +
  224 + sscanf(year,"%d",&(UT.year));
  225 + sscanf(day,"%d",&(UT.day));
  226 + sscanf(min,"%d",&(UT.min));
  227 + sscanf(hour,"%d",&(UT.hour));
  228 + sscanf(sec,"%d",&(UT.sec));
  229 + sscanf(msec,"%d",&(UT.msec));
  230 +
  231 + if(UT.year < STARTYEAR) TimeFlag = 0; // Time Inetrval
  232 +
  233 + SetDouble(&UT);
  234 + return(&UT);
  235 +}
  236 +/*-------------------- end of ReadTime ------------------------*/
  237 +
  238 +/*---------------------- Write Time ---------------------------*/
  239 +/* Function Write time convert use only double times field
  240 + * of dd_tmstr_t structure to print time in DD style
  241 + * in internal static string. The integer fields redefined.
  242 + * Function return string pointer.
  243 + */
  244 +
  245 +char *WriteTime(dd_tmstr_t *UT)
  246 +{
  247 + static dd_time_t UTstring;
  248 +
  249 + SetInt(UT);
  250 + sprintf(UTstring,"%04d%03d%02d%02d%02d%03d",(UT->year),(UT->day),(UT->hour),
  251 + (UT->min), (UT->sec),(UT->msec));
  252 + return(UTstring);
  253 +}
  254 +/*------------------- end of WriteTime -------------------*/
  255 +
  256 +void WriteFmtTime(dd_tmstr_t *UT,char *UTstring)
  257 +{
  258 + SetInt(UT);
  259 + sprintf(UTstring,"%04d:%03d:%02d:%02d:%02d",(UT->year),(UT->day),(UT->hour),
  260 + (UT->min), (UT->sec));
  261 +}
  262 +/*------------------- end of WriteFmtTime -------------------*/
  263 +
  264 +/*=========================================================
  265 + * Functions for DECODERs
  266 + * These functions make conversion from/to DD double/DD_time_structure and
  267 + * a integer array as follows:
  268 + * {Year, Month, Day_Of_Month, Hour, Min, Sec, Mls}
  269 + *========================================================*/
  270 +/*--------------------------------------------------------
  271 + * UT2double()
  272 + * Fille the DD_time_structure with double fild from the
  273 + * integer array (see the section header)
  274 + *-------------------------------------------------------*/
  275 +dd_tmstr_t *UT2double(unsigned *ut)
  276 +/* Fill the standard structure with double too using as
  277 + * argument 7 int length array in Gavrilova Passport Standard
  278 + */
  279 +{
  280 +static dd_tmstr_t UT;
  281 +int visocos;
  282 +
  283 +if(ut[0]%4 == 0) visocos = 1; else visocos = 0;
  284 +UT.year = ut[0];
  285 +UT.day = monthday[visocos][ut[1] - 1]+ut[2] - 1;
  286 +UT.hour = ut[3];
  287 +UT.min = ut[4];
  288 +UT.sec = ut[5];
  289 +UT.msec = ut[6];
  290 +
  291 +SetDouble(&UT);
  292 +return(&UT);
  293 +}
  294 +/*-------------------------------------------------------*/
  295 +/*-------------------------------------------------------
  296 + * Double2UT()
  297 + * Converts Standard DD double time to interger array (see
  298 + * the section header)
  299 + *--------------------------------------------------------*/
  300 +unsigned *Double2UT(double t)
  301 +{
  302 + static unsigned UT[7];
  303 + dd_tmstr_t tm;
  304 + int i,visocos;
  305 +
  306 + tm.times = t;
  307 + SetInt(&tm);
  308 + if(tm.year % 4 == 0) visocos = 1; else visocos = 0;
  309 + i = 0;
  310 + while((i < 12) && (tm.day >= monthday[visocos][i])) i++;
  311 + UT[0] = tm.year;
  312 + UT[1] = i;
  313 + UT[2] = tm.day +1 - monthday[visocos][i-1];
  314 + UT[3] = tm.hour;
  315 + UT[4] = tm.min;
  316 + UT[5] = tm.sec;
  317 + UT[6] = tm.msec;
  318 +
  319 + return( (unsigned *)UT);
  320 +}
  321 +/*=======================================================================*/
... ...
src/DDClientLibC/INCLUDE/DD.h 0 → 100755
  1 +++ a/src/DDClientLibC/INCLUDE/DD.h
... ... @@ -0,0 +1,143 @@
  1 +/*=================================================================================================
  2 + * DD SYSTEM
  3 + * DD.h
  4 + * Version: 6.0
  5 + * Description: The public header to use DD library libDD.a
  6 + * List of changes:
  7 + * Apr. 17, 2002 Fedorov, - New error constant to interrupt the
  8 + * transmission if data dimensions are changed from file
  9 + * to file
  10 + * Nov 18, 2004 - V.4.2 - Fedorov, New errors for CACH manipulating
  11 + * Jun 17, 2007 - V.4.6 Fedorov New requestes and external executables
  12 + * Aug 02, 2007 - V.4.7 Fedorov Modification of call external executables
  13 + * Sep 24, 2007 - V.5.0 Fedorov New status of Get Data: MOREDELAY
  14 + * May 21, 2008 - V.5.1 Fedorov New Status of SetTime: CTIMEISSHIFTED
  15 + * Oct 18, 2012 - V.5.2 Knizhnikova New DD_SetTimeInfo() function
  16 + *=================================================================================================*/
  17 +
  18 +#include "DD_time.h"
  19 +
  20 +typedef struct { int type; /* Type of variable in netcdf style */
  21 + int DimNumber; /* number of dimensions */
  22 + int *Dimensions; /* Dimensions array
  23 + * fastest change is last */
  24 + int VarNumber; /* Dimension of variable array */
  25 + void **Variables;/* Variables array pointer
  26 + * It is static array refreshed
  27 + * each call
  28 + */
  29 + } DD_data_t;
  30 +
  31 +/*------------------- FUNCTIONS ---------------------------*/
  32 +
  33 +#ifdef __cplusplus
  34 +extern "C" {
  35 +#endif
  36 +
  37 +extern int DD_SetVariable(char *VarName);
  38 +/*
  39 + * VarName - full name of variable <project>:<instrument>:<Variable>
  40 + * Returns VarID or negative in case of error (see bellow)
  41 + */
  42 +
  43 +extern int DD_GetInform(int VarID,char *AttrName, DD_data_t **data);
  44 +/*
  45 + * VarID - Variable ID from DD_SetVariable
  46 + * AttrName - name of attribute ( defined by konvention )
  47 + * data - address of data structure
  48 + * Returns 1 if OK and negative value in case of error (see bellow)
  49 + */
  50 +
  51 +extern int DD_SetTime(int VarID, char *Time);
  52 +/*
  53 + * VarID - Variable ID from DD_SetVariable
  54 + * Time - string defined in DD_time.h
  55 + * Returns 1 if OK and negative value in case of error (see bellow)
  56 + */
  57 +
  58 +extern int DD_SetTimeInfo(int VarID, char *Time, double *RealTime);
  59 +/*
  60 + * VarID - Variable ID from DD_SetVariable
  61 + * Time - string defined in DD_time.h
  62 + * RealTime - time pointer was set to
  63 + * Returns 1 if OK and negative value in case of error (see bellow)
  64 + */
  65 +
  66 +extern int DD_GetMultiData(int VarID, size_t VarSize, char **VarNames, char *TimeInt, DD_data_t **data, int BackFlag);
  67 +/*
  68 + * VarID - Variable ID from DD_SetVariable
  69 + * VarSize - number of variables to return
  70 + * VarNames - the array of Names of the requested Variable
  71 + * TimeInt - String of Time interval in DD_time style
  72 + * data - Data structures array
  73 + * BackFlag - 0 - pointer is at the lasy position, 1 - pointer returns to the start point
  74 + * Returns 1 if OK and negative value in case of error (see bellow)
  75 + */
  76 +
  77 +/* ----------------------------------------
  78 + * This function below just call DD_GetMultiData
  79 + * for backup
  80 + *---------------------------------------*/
  81 +extern int DD_GetData(int VarID, char *VarName, char *TimeInt, DD_data_t **data);
  82 +
  83 +extern int DD_MovePoint(int VarID, int RecordNumber);
  84 +/*
  85 + * VarID - Open virtual instrument ID
  86 + * int RecordNumber - +/- records to move
  87 + * Move pointer in the open instrument and return 1 or negative if error
  88 + */
  89 +
  90 +extern int DD_Close(int VarID);
  91 +/*
  92 + * VarID - Variable ID from DD_SetVariable
  93 + * Returns 1 if OK and negative value in case of error (see bellow)
  94 + */
  95 +
  96 +extern char *DD_GetVersion();
  97 +/*
  98 + * return static pointer to internal string with the DDLIB-SERVER package version
  99 + */
  100 +
  101 +/*----------- Data Update functions -----------------------------------*/
  102 +extern int DD_AddDataSet(char *DataSetName, char *RemSetID, char *BaseName);
  103 +/*
  104 + * Request for new VI. See ../DOC/TECHDOC/DDServFunct.html
  105 + */
  106 +
  107 +#ifdef __cplusplus
  108 +}
  109 +#endif
  110 +
  111 +/*--------------------- CONSTANTS -----------------------------------------*/
  112 +#define MOREDATA 1 /* There is data, but we have to call GetData again right now*/
  113 +#define MOREDELAY 2 /* There is data, but we have to call GetData again after delay */
  114 +#define OK 0 /* It is last data packet */
  115 +#define NOCONNECTION -1
  116 +#define TOOMANYREQ -2
  117 +#define REQSENDERR -3
  118 +#define REPLYRECERR -4
  119 +#define NOID -5
  120 +#define NOREFFILE -6
  121 +#define NOTIMESFILE -7
  122 +#define NOINFOFILE -8
  123 +#define NOVAR -9
  124 +#define OUTOFTIME -10
  125 +#define CACHERR -11 /* The error occured when program manipulated the cach */
  126 +#define CACHTOOREC -33 /* Off files in the CASH are created less then 5 sec ago */
  127 +#define WAITEXTCALL -34 /* Server Waits external call finish */
  128 +#define TRYAGAIN -35 /* Times file is locked. This request should be repeated again */
  129 +#define NODATAATTIME -36 /* Requested time is inside NODATA time interval */
  130 +#define GAPISSMALL -37 /* Gap is too small to call external archive */
  131 +#define CTIMEISSHIFTED -38 /* The request was in NoData interval, try again with time at the end */
  132 +#define DATAFILEERR -12 /* The error while manipulate with data file */
  133 +#define ENVIRERROR -13 /* Error in Environments */
  134 +#define NOPOINTER -14 /* The pointer points nowhere, SetTime were failed */
  135 +#define INTSERERR -15 /* Server internal error */
  136 +#define TIMEINEMPTY -16 /* No data for specified time interval */
  137 +#define NOEXEC -17 /* No executable */
  138 +
  139 +#define DD_SHORT 4
  140 +#define DD_INT 1
  141 +#define DD_FLOAT 2
  142 +#define DD_DOUBLE 3
  143 +#define DD_CHAR 0
... ...
src/DDClientLibC/INCLUDE/DD_Access.h 0 → 100755
  1 +++ a/src/DDClientLibC/INCLUDE/DD_Access.h
... ... @@ -0,0 +1,93 @@
  1 +/* ======================================================
  2 + *
  3 + * DD_Access.h
  4 + * V.2.0
  5 + * Last revision: Oct 7, 2002
  6 + * List of revisions: 1997 - version 1.0
  7 + * Oct 7, 2002 - version 2.0 (update a little )
  8 + */
  9 +
  10 +#define MAXHOSTLENGTH 16 /* IP-address: "255.255.255.255\0" */
  11 +#define USRLENGTH 21 /* Length of UserName: + \0 */
  12 +#define TICKETLENGTH 9 /* Length of passwd: 8 + \0 */
  13 +#define HOSTNAMELENGTH 120 /* Length of the user host name */
  14 +#define USERCASHLEN 100 /* Size of user_ticket.nc file must be 300 */
  15 +#define NONAME "no_name\0" /* Name of user in case of non-WEB connection */
  16 +#define ACCINSTR "iball:acc:all" /* Instrument which watch the access */
  17 +#define TICKET_PATH "/ACC/user_ticket.nc"
  18 +#define USERREFNAME "/ACC/user_info.nc"
  19 +#define LOGFILE "/ACC/login.log"
  20 +
  21 +/*------------ Errors of ACCESS ---------------------*/
  22 +#define NOPERMISSION -100
  23 +#define NOHOST -101
  24 +#define NOUSERSFILE -102
  25 +
  26 +/*--------------- Extern global variables -------------------*/
  27 +extern char UserName[USRLENGTH]; /* defined in DD_client.c */
  28 +extern char UserHost[MAXHOSTLENGTH]; /* defined in DD_client.c */
  29 +extern int UserID; /* defined in DD_client.c */
  30 +
  31 +/*--------------- Extern Functions ---------------------------*/
  32 +extern int FillStruct (int argc, void **argv);
  33 +/* This function used to set up the host address from IDL (when WWW access used)
  34 + * Arguments allocation is as follows:
  35 + * UserName - 0
  36 + * UserHost - 1
  37 + * Location: DD_idl.c -> DD_idl.so
  38 +*/
  39 +
  40 +extern int GetTicket(int UID, char *HostName, int DD_user_id);
  41 +/* Description: This function find the user data in user_cash.nc
  42 + * If O'k rewrite the line with new time.
  43 + * In case of a new user, remove the first line with
  44 + * older time data then a current time + 4.5 hours.
  45 + *
  46 + Takes 3 arguments: UserId (id in the romote host)
  47 + Remote host address(string,like "193.232.6.60\0")
  48 + DD_user_id(can see in user_info.nc)
  49 +
  50 + Returns 0 if O'k or NOPERMISSIONS, or ERROR
  51 +
  52 + If DD_log_name equal NULL searching for UserId, IP-address
  53 + If DD_log_name nonequal NULL searching for IP-address,DD_log_name*
  54 + *
  55 + */
  56 +extern int CheckTicket(char *NameUsr, char *Ticket);
  57 +/* Description: This function check if user exosts
  58 + * in user_info.nc file. Returns DD_id if O'k.
  59 + * It returns NOPERMISSION or other errors
  60 + */
  61 +
  62 +extern int ShowTicket(int userid, char *hostname, char *DD_name);
  63 +/*
  64 + * Show if user has authorisation to work
  65 + */
  66 +
  67 +extern int LoginRequest(char *UserPasswd, char *UserLogin, char *HostName);
  68 +/* Description: Library function for client-server using.
  69 + * Send ID, Password,UserLogin, and host to server.
  70 + * Compares the information with your {id,hostname and other}.
  71 + * Returns 0 if O'k, or a negative value in case
  72 + * of "NOPERMISSION" or error.
  73 + *
  74 + */
  75 +extern int SetUser(int UserID, char *HostName, char *LogName);
  76 +/* Description: Library function for client-server using.
  77 + * Send UserID, HostName to server.
  78 + * Compares the information with your {id,hostname}.
  79 + * Returns 1 if O'k, or a NOPERMISSION, or error number
  80 + */
  81 +
  82 +extern int CheckID(char *NameUsr);
  83 +/* Description: This function check the user name in user_info.nc file.
  84 + * Returns DD_id if exists.
  85 + * It returns NOPERMISSION or other errors
  86 + */
  87 +
  88 +extern void Put2Log(int UID, char *Host, char *LogName, int error);
  89 +/* Description: This function logs a user's ID, IP-address of a local host,
  90 + * login name and permission information into log file.
  91 + *
  92 + */
  93 +
... ...
src/DDClientLibC/INCLUDE/DD_comm.h 0 → 100755
  1 +++ a/src/DDClientLibC/INCLUDE/DD_comm.h
... ... @@ -0,0 +1,412 @@
  1 +/*=================================================================================
  2 + * DD SYSTEM base package
  3 + * DD_Server DD_Client library
  4 + * DD_comm.h
  5 + * V. 6.0
  6 + * Changes listing:
  7 + * Feb 27 1995 - V 1.0
  8 + * 13 Apr. 2002 - changed for NetCDF 3.3
  9 + * 03 Oct. 2002 - v.4.0 Fedorov, communication ideology is changed
  10 + * Oct 31, 2002 - V.4.1 Fedorov, UserName, UserHost and UserID transferred into DD_Access.h
  11 + * May 7, 2003 - V.4.2 Fedorov, The Cash structure is changed (flag of open file )
  12 + * June 17, 2003 - V.4.3 Fedorov, The Maximal Packet Size is changed
  13 + * Nov 18, 2004 - V.4.4 Fedorov, Some changes
  14 + * Aug 17, 2005 - V.4.5 Fedorov, Cach Time constant is changed
  15 + * Jun 17, 2007 - V.4.6 Fedorov, New requestes and external executables
  16 + * Aug 01, 2007 - V.4.7 Fedorov, Cache length = 20, New DD_Var_t structure
  17 + * Sep 20, 2007 - V.5.0 Fedorov, Update Time Info library now in the separate file
  18 + * Sep 23, 2007 - V.5.1 Fedorov, New interface of SetTime
  19 + * Sep 25, 2007 - V.5.2 Fedorov, Individual minimal gap
  20 + * Oct 08, 2007 - V.5.3 Budnik, php createVI.php <baseID> <remSetID> <ddSetID>
  21 + * Jan 25, 2008 - V.5.3.1 Budnik, min data gap = 1 day!!!!
  22 + * May 22, 2008 - V.5.4 Fedorov, DD_Var_t has a LockStartTime value
  23 + * May 27, 2008 - V.5.5 Fedorov, Maximal tracnsmition buffer
  24 + * Sep 19, 2008 - V.5.6 MAXVARLENGTH=64 REQUESTLENGTH 184
  25 + * Dec 15, 2012 - V.6.0 New multiparam Get_MultiData() function
  26 + *===================================================================================*/
  27 +
  28 +#include <stdio.h>
  29 +#include <sys/errno.h>
  30 +#include <stdlib.h>
  31 +#include <string.h>
  32 +#include <sys/types.h>
  33 +#include <sys/time.h>
  34 +#include <time.h>
  35 +#include "DD_Access.h"
  36 +
  37 +#ifdef SOLARIS
  38 +#include <sys/socket.h>
  39 +#include <netdb.h>
  40 +#include <netinet/in.h> /* internet stile addres */
  41 +#include <rpc/types.h>
  42 +#include <rpc/xdr.h>
  43 +#include <rpc/rpc.h>
  44 +#endif /* SOLARIS */
  45 +
  46 +#ifdef HPUX
  47 +#include <sys/socket.h>
  48 +#include <netinet/in.h>
  49 +#include <netdb.h>
  50 +#include <sys/un.h>
  51 +#include <rpc/xdr.h>
  52 +#include <rpc/rpc.h>
  53 +#endif
  54 +
  55 +#ifdef OSF1
  56 +#include <sys/socket.h>
  57 +#include <netdb.h>
  58 +#include <arpa/inet.h>
  59 +#include <rpc/xdr.h>
  60 +#endif /* OSF1 */
  61 +
  62 +#ifdef LINUX
  63 +#include <sys/socket.h>
  64 +#include <netinet/in.h>
  65 +#include <netdb.h>
  66 +#include <rpc/rpc.h>
  67 +#include <rpc/xdr.h>
  68 +#endif /* LINUX */
  69 +
  70 +#ifdef SUNOS
  71 +#include <sys/socket.h>
  72 +#include <sys/socketvar.h>
  73 +#include <netinet/in.h>
  74 +#include <netdb.h>
  75 +#include <rpc/xdr.h>
  76 +#endif /* SUNOS */
  77 +
  78 +/*----------------- Defenitions of request and server replies --------------------*/
  79 +/* 1. Data manipulation requests */
  80 +#define OPENINSREQ 0 /* Open virtual instrument */
  81 +#define DATAINFOREQ 1 /* Request of constant info */
  82 +#define TIMESETREQ 2 /* Position of pointer by StartTime*/
  83 +#define DATAGETREQ 3 /* Data request by time interval */
  84 +#define CLOSEINSREQ 4 /* Request to close virtual instrument */
  85 +#define MOVPOINTREQ 5 /* Move the pointer od data request*/
  86 +#define ADDVIREQ 6 /* Add New virtual instrument */
  87 +
  88 +/* 2. Security requests */
  89 +#define GETTICKETREQ 10
  90 +#define SHOWTICKETREQ 11
  91 +
  92 +/*-------- Some constants ------------------*/
  93 +#define EMPTY 0 /* Filler of the trailer */
  94 +#define FILEACCMARG 1 /* The minimum time from the last access to remove this file */
  95 +
  96 +/*------------ Important lengths and pathes ----------------*/
  97 +#define PROTOCOL 0 /* protocol TCP */
  98 +#define REPLYLENGTH 12 /* Length of header of reply packet */
  99 +#define REQUESTLENGTH 196 /* Length of request packets MAXSETLENGTH + 2*MAXVARLENGTH + 16 */
  100 +#define MAXVARLENGTH 64 /* Length (with \0) of Variable Name */
  101 +#define MAXSETLENGTH 52 /* Max Length of VI name */
  102 +#define PATHLENGTH 128 /* Length of complete path */
  103 +#define MAXFILENAME 32 /* The maximal length of the data file (info, cach, times as well)*/
  104 +#define REFNAME "/refer.nc" /* path name for databse refer file */
  105 +#define CASHLEN 20 /* Length of cash array */
  106 +#define TRY 100 /* How many tymes to ask the socket */
  107 +#define MAXPACKSIZE 5000000 /* Maximal size of one packet of transmission in bytes */
  108 +#define MAXCOMMANDL 300 /* Command in system() maximal length
  109 +/*-------------------------------------------------
  110 + * XDR length to calcolate the total len
  111 + *-------------------------------------------------*/
  112 +#define XDRINTLEN 4
  113 +#define XDRFLOATLEN 4
  114 +#define XDRDOUBLELEN 8
  115 +// String length is counted as 4B + N + r (to completed to 4 bytes)
  116 +
  117 +/*------------ List of External Call of DD_Server and ERRORS -------------------*/
  118 +#define ADDDATASETCALL "php %s/CALLEXT/createVI.php %s %s %s" /* Format to call to create new VI */
  119 +#define GETNEWDATACALL "php %s/CALLEXT/getData%s.php %s %s %s %s &" /* Format to call to get new data */
  120 +#define NOPHP 32512
  121 +#define NOSCRIPT 256
  122 +#define PHPOK 0
  123 +
  124 +/*------ Constant to understand data availabilities -------------------------------*/
  125 +#define GLOBSTARTNAME "GlobalStart"
  126 +#define GLOBSTOPNAME "GlobalStop"
  127 +#define SAMPLNAME "MinSampling"
  128 +#define REMARCHNAME "DataBaseID"
  129 +#define REMINSTNAME "DataSetID"
  130 +#define MINGAP 86400.0 /*Seconds. The minimal time gap to set up the flag DATAGAP */
  131 +#define REQTIMEINT 86400.0 /* One day, +/- of request time interval */
  132 +#define ISOTIMEF "%4u%*1c%2u%*1c%2u%*1c%2u%*1c%2u%*1c%2u%*1c%3u" /* Format to READ time in ISO format */
  133 +#define ISOTIMEP "%04u-%02u-%02uT%02u:%02u:%02u.%03uZ" /* Format to PRINT time in ISO format */
  134 +#define NODATASTR "NODATA"
  135 +#define DIRLOCK "LOCK"
  136 +
  137 +#define QUANTOFFSET 0.01
  138 +/*------------- More internal specifications -----------------------*/
  139 +/*
  140 + * See ../DOC/TECHDOC/DDGenProt.html (lyx)
  141 + */
  142 +
  143 +/* Reply variables:
  144 + * Error - negative value described in DD.h
  145 + * Type - int (see DD.h)
  146 + * Dim_Number - int ( the dimension (vector, matrix, cube, etc) ov the variable)
  147 + * Data_Size - int (the size of the data packet in bytes)
  148 + * RemID - int (number of virtual instruments still open in this session)
  149 + * Dim - int (the particular dimension )
  150 + * LastPacketFlag - int ( == OK in this packet is last, or MOREDATA)
  151 + * Data - array of Type of Dim X Dim X....X Dim size
  152 + * --------------------
  153 + * Dim_Number
  154 + * DataPacket:
  155 + *
  156 + * <LastPacketFlag> |
  157 + * <Dim> | |
  158 + * <.....> | Dim_Number | Data_Size bytes
  159 + * <Dim> | |
  160 + * <data> |
  161 + * ..... | only for real data |
  162 + * <data> | |
  163 + *
  164 + * Note is the value is scalar - the Dim = 0 (???)
  165 + */
  166 +
  167 +/* REPLY SPECIFICATION
  168 + *
  169 + * Reply consists Header 12 bytes length and Data Block
  170 + *
  171 + * on Open Virtual instrument:
  172 + * <OPENINSREQ><ID/Eroor><EMPTY><EMPTY>
  173 + * on Constant Info request:
  174 + * <DATAINFOREQ><Type/Error><Dim_Number><Data_Size><DataPacket>
  175 + * on Set pointer by StartTime:
  176 + * <SETTIMEREQ><EMPTY/Error><EMPTY><EMPTY>
  177 + * on Get Data by TimeInt :
  178 + * <DATAGETREQ><Type/Error><Dim_Numbers><Data_Size><LastRecordFlag><DataPacket>
  179 + * on Move pointer with records number
  180 + * <MOVPOINTREQ><EMPTY/Error><EMPTY><EMPTY>
  181 + * on Close Virtual Instrument
  182 + * <CLOSEINSREQ><RemID/Error><EMPTY><EMPTY>
  183 + */
  184 +
  185 +/*-------------------- TYPEDEF ---------------------------*/
  186 +typedef struct {
  187 + char CacheFilePath[PATHLENGTH];
  188 + char names[CASHLEN][MAXSETLENGTH];
  189 + long times[CASHLEN];
  190 + int FileOpen[CASHLEN]; /* 1 if file is open */
  191 + int ID; /* ID of open cach file */
  192 + int nameID; /* ID of names array */
  193 + int timeID; /* ID of times array */
  194 + int fopenID; /* ID of fopen flag */
  195 + } DD_cash_t; /* The structure holding cash informaton
  196 + * of particular virtual instrument DataBase
  197 + */
  198 +
  199 +/*
  200 + * This structure corresponds to ONE requested variable
  201 + * of some Virtual instrument
  202 + */
  203 +typedef struct { char InstrName[MAXSETLENGTH]; /* Virtual Instrument Name */
  204 + char path[PATHLENGTH]; /* Path to directory of open virtual instrument */
  205 + /*---------------------------------------
  206 + * Cache part
  207 + *--------------------------------------*/
  208 + DD_cash_t Cash; /* Cash holder */
  209 + int CurrCushN; /* Current cash pointer */
  210 + /*--------------------------------------
  211 + * This is the part of open data file and corresponding data set
  212 + *-------------------------------------*/
  213 + int ncID; /* ID of open nc_file */
  214 + size_t nc_rec; /* the current record number nc_file */
  215 + size_t Maxnc_rec; /* Maximum of records number in in the current nc file */
  216 + DD_data_t *VarData; /* Static pointer. Variables Holder */
  217 + size_t ParamSize; /* Number or requested variables to save */
  218 + /*---------------------------------------------
  219 + * This is part of times file of given VI
  220 + *--------------------------------------------*/
  221 + char TimesFileName[PATHLENGTH];
  222 + double SDTime; /* Requested Start Time in double form */
  223 + double FDTime; /* Requested Stop Time in double form */
  224 + double CDTime; /* Current Time in double form */
  225 + int tmID; /* ID of "times" file of this virtual instrument*/
  226 + int NameID; /* ID of FileName variable in times file */
  227 + int StartID; /* ID of Start variable in times file */
  228 + int StopID; /* ID of Stop variable in times file */
  229 + size_t TimeRecNumber; /* Current Record number in the "times" file */
  230 + size_t MaxTimeRecNum; /* Maximum records number in the "times" file */
  231 + int RValidMin; /* Minimal record with valid data */
  232 + int RValidMax; /* Maximal record with valid data */
  233 + double MinValidTime;
  234 + double MaxValidTime; /* Start of RValidMin, and stop of RValidMax */
  235 + int CurrRmin; /* Sure that looking time is greater than stop; -1 if NOT */
  236 + int CurrRmax; /* Sure that looking time is less than start; -1 if NOT */
  237 + /*------- Working with external Data Base ------------------------------*/
  238 + int VILocked; /* Flag to show that request to remote database has been sent */
  239 + time_t LockStartTime; /* Value to calculate a time elapsed from lock made by THIS VI */
  240 + /*---------- This is the part of Info file of given VI -----------------*/
  241 + int attrID; /* ID of constant information nc_file */
  242 + char AttrName[PATHLENGTH]; /* Name of constant information file */
  243 + DD_data_t AttrData; /* Dimensions of Attributes */
  244 + /*---- Part concerning External call ------------------*/
  245 + double MinGap; /* The minimal gap between two files */
  246 + double GlobalStart; /* The principal begin of data */
  247 + double GlobalStop; /* The principal end of data */
  248 + char BaseName[MAXSETLENGTH]; /* The name of external data archive */
  249 + char RemSetID[MAXSETLENGTH]; /* The name of VI in exterval archiving */
  250 + int ExtCallAllowed; /* 1 If Server can call external archiving */
  251 + /*------------ Flow Control -----------------------------*/
  252 + int LastPacketFlag; /* OK - request is completed,
  253 + * MOREDATA - one or several blocks expected,
  254 + * MOREDELAY - wait, system is blocked */
  255 + int LastFileStatus; /* The file status after the last SetNewFile */
  256 + int NewFile; /* 1 if File was changed, VI has to be refreshed*/
  257 + int NewFileWasOpen; /* 1 if the original position of pointer
  258 + * (in data file, times file) was lost after open
  259 + * a new data file */
  260 + } DD_Var_t;
  261 +
  262 +/*---------------- Usefull enumerations ---------------------*/
  263 +enum SearchRet {REACHLEFT, REACHRIGHT, OKLEFT, OKRIGHT};
  264 + /*
  265 + * enumerate of the status of time inteval searching
  266 + * NOONEDATA - no data at al in this VI
  267 + * INSIDE - CTime is inside valid data interval (tolerance is MINGAP)
  268 + * DATAATRIGHT, DATAATLEFT - Valid interval is on the right/left from CTime
  269 + */
  270 +enum SearchIntRet {NOONEDATA, INSIDE, DATAATRIGHT, DATAATLEFT, IDLE};
  271 +
  272 +/* Return function IsTimesLocked */
  273 +enum LockStatus {NOLOCK, LOCKED, LOCKREMOVED};
  274 +
  275 +
  276 +/*------------------ Function for Server ---------------------*/
  277 +extern int OpenInstr(char *InstrName);
  278 +
  279 +/*
  280 + * Init shared memory for cache system
  281 + */
  282 +extern void Cache_Init();
  283 +
  284 +/*
  285 + * Free shared memory used for cache system
  286 + */
  287 +extern void Cache_Free();
  288 +
  289 +/*
  290 + * Free shared memory used for cache system
  291 + */
  292 +extern int Cache_RequestDataFileAccess(DD_Var_t *D, char* dataFileName);
  293 +
  294 +/*
  295 + * Free shared memory used for cache system
  296 + */
  297 +extern int Cache_ReleaseDataFileAccess(DD_Var_t *D);
  298 +
  299 +/*
  300 + * Close cache file
  301 + */
  302 +extern int Cache_CloseFile(DD_Var_t *D);
  303 +
  304 +/*
  305 + * Open Virtual instrument by name and returns the ID
  306 + * Returns negative value in case of error (see DD.h)or OK
  307 + */
  308 +extern int GetAttribute(int ID, char *Name);
  309 +/*
  310 + * Variable - address of structure with variable description
  311 + * Name - name of attribute
  312 + * Returns OK or an error (see DD.h)
  313 + */
  314 +extern int GetMultiData(int ID, int VarSize, char **VarNames, char *TimeInterval, int BackFlag);
  315 +/*
  316 + * VarSize - size of the array of Names
  317 + * Names - array of strings with names of requested variables,
  318 + * TimeInterval - Time in DD_time.h style
  319 + * Returns negative value in case of error (see bellow)
  320 + * Returnes MOREDATA if "there is more data", and OK if data is finished.
  321 + */
  322 +
  323 +extern int SetTime(DD_Var_t *D, double CTime);
  324 +/*#################################################################
  325 + * SET TIME
  326 + * Set time and try to open appropriate data file. If not try to
  327 + * call external archive
  328 + * D - address of VI holder
  329 + * Time - Time in DD_time.h style
  330 + * Return:
  331 + * OK
  332 + * NOID - call with uncorrect VI holder
  333 + * OUTOFTIME - Requested time is out of General time limitation
  334 + * WAITEXTCALL - Server sent request to external archive
  335 + * TRYAGAIN - VI is blocked by call to external database
  336 + * NODATAATTIME - request time is inside NODATA time interval
  337 + * some return of SetNewFile(); see ...
  338 + *#################################################################*/
  339 +
  340 +extern int CloseID(int ID);
  341 +/* ID - integer identificator of opened Data Set
  342 + * Returns number of remained IDs of this communication seasson
  343 + * in case of 0 the server closes this comminication session
  344 + */
  345 +
  346 +int SetNewFile(DD_Var_t *D, int N);
  347 +/*
  348 + * Function tries to get new data for the gap beetween files, or just
  349 + * open a new data file according to offset N referring to current position in the times file.
  350 + * The current position changed if file is succesefully open.
  351 + * Return values:
  352 + * OK
  353 + * OUTOFTIME - next interval exceeeds GlobalStart/Stop
  354 + * TIMEINEMPTY - next interval marked as "NODATA"
  355 + * TRYAGAIN - the VI is blocked while new data is arriving
  356 + * WAITEXTCALL - new data is requested
  357 + * CACHTOOREC - now free space in the CACH
  358 + * CHACHERR - unrecovable error in CACH
  359 + * DATAFILEERR - unrecovable error in data file
  360 + */
  361 +
  362 +size_t MaxRecord(int ncID);
  363 +/*
  364 + * Inspect all variables and dimensions of the file (exept Time associated) and
  365 + * returm maximal record number to transmit
  366 + */
  367 +
  368 +/*------------------ Global constants ----------------------------------*/
  369 +static u_int xdrlen[] = {4,4,4,8,4};
  370 +static size_t unixlen[] = {sizeof(char),sizeof(int),sizeof(float),sizeof(double),sizeof(short)};
  371 +static bool_t ( *ConvFunc[5])() = {xdr_char, xdr_int, xdr_float, xdr_double, xdr_short};
  372 +
  373 +/*------------------ Global data variable for entire session --------------------*/
  374 +extern DD_Var_t **DD_Var ; /* Actually this variable is implimented
  375 + * in DD_GetData.c . The dimension of this array is defined
  376 + * by sysconf(_SC_OPEN_MAX)*/
  377 +extern size_t MaxIDNumber; /* Size of DD_Var array. Defined actually in DD_GetData.c */
  378 +
  379 +/*
  380 + * Fuctions prototypes in ExtDataRequest.c file
  381 + */
  382 +/*======================================================================
  383 + * IsTimesLocked
  384 + * Return 1 if there is LOCK in the VI directory
  385 + *======================================================================*/
  386 +extern int IsTimesLocked(DD_Var_t *DD_Var);
  387 +
  388 +/*======================================================================
  389 + * ExtDataRequest
  390 + * Return folowing values:
  391 + * OK - request is accepted SERVER has to wait when LOCK file is gone
  392 + * NOEXEC - error in external executable
  393 + * NODATAATTIME - time corresponds to the NODATA interval
  394 + * GAPISSMALL - Time is inside too small gap
  395 + *======================================================================*/
  396 +extern int ExtDataRequest(DD_Var_t *DD_Var, double CurrTime);
  397 +
  398 +/*=======================================================================
  399 + * UpdateTimeInfo.c
  400 + * int SearchLeft(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax)
  401 + * int SearchRight(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax)
  402 + * Search the next to the left(right) non-empty time interval
  403 + * DD_VarL - common data structure corresponding to THIS open VI
  404 + * Rmin, Rmax - start points
  405 + *
  406 + * int UpdateTimeInfo(DD_Var_t *DD_VarL)
  407 + * Function reopen "times" file and update all time constants
  408 + *======================================================================*/
  409 +extern int SearchLeft(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax);
  410 +extern int SearchRight(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax);
  411 +extern int UpdateTimeInfo(DD_Var_t *DD_VarL);
  412 +
... ...
src/DDClientLibC/INCLUDE/DD_time.h 0 → 100755
  1 +++ a/src/DDClientLibC/INCLUDE/DD_time.h
... ... @@ -0,0 +1,59 @@
  1 +/* This is header file for working with DD time */
  2 +/* V.4.1 */
  3 +/* name: DD_time.h
  4 + * Author: Andrey Fredorov
  5 + * Institution: IKI RAN
  6 + * Date: 21-Feb-1995
  7 + * Last update Sept 05, 2011
  8 + * Sept 05, 2011: V.3.2 SetIntNew => arg TimeKind => to work with 1970-1973 : BR
  9 + */
  10 +
  11 +#define TIMELENGTH 17
  12 +
  13 +typedef char dd_time_t[TIMELENGTH]; /* YYYYDDDHHMMSSMLS */
  14 +
  15 +/* ---------------- Functions prototypes ----------------------*/
  16 +extern double DD_Time2Double(dd_time_t DD_Time);
  17 +/* Convert string to double and return.
  18 + * Return negative value in case of error string format
  19 + */
  20 +extern char *Double2DD_Time(double Time);
  21 +/* Convert double Time value into string form and return pointer to static string
  22 + * allocated INSIDE the library. Thus the value is renoveted each function call.
  23 + */
  24 +
  25 +/*---------------- Backup compability with V.3.0 and earlier ----------*/
  26 +typedef struct { double times; /* time sec from 1970 */
  27 + int year;
  28 + int day;
  29 + int hour;
  30 + int min;
  31 + int sec;
  32 + int msec;
  33 + } dd_tmstr_t ;
  34 +
  35 +
  36 +extern dd_tmstr_t *ReadTime(char *UT); /* Read time from sring and fill static
  37 + * structure defined IN function.
  38 + * Returns pointer of strusture */
  39 +extern char *WriteTime(dd_tmstr_t *UT); /* Get pointer of time structure
  40 + * and convert it into string
  41 + * Function returns pointer of
  42 + * internal string */
  43 +
  44 +extern void WriteFmtTime(dd_tmstr_t *UT,char *UTstring);
  45 +
  46 +extern void SetDouble(dd_tmstr_t *UT); /* Fill double value of dd_tmstr_t */
  47 +
  48 +typedef enum {DD_TM_UNKNOWN, DD_TM_TIME_INTERVAL, DD_TM_DATE} t_DDTimeKind;
  49 +
  50 +extern void SetInt(dd_tmstr_t *UT); /* Fill int values of dd_tmstr_t */
  51 +extern void SetIntNew(dd_tmstr_t *UT,t_DDTimeKind timeKind);
  52 +
  53 +/*------- Functions for DECODERS ------------------------
  54 + *These functions works with with Gavrilova's UT representation */
  55 +extern dd_tmstr_t *UT2double(unsigned *UT); /* Set standard time
  56 + * structure and return
  57 + * its pointer
  58 + */
  59 +extern unsigned *Double2UT(double Time); /*Converts Double to Gavrilova array */
... ...
src/DDClientLibCpp/CMakeLists.txt 0 → 100644
  1 +++ a/src/DDClientLibCpp/CMakeLists.txt
... ... @@ -0,0 +1,22 @@
  1 +
  2 +PROJECT(DDClientLibCpp)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibCpp/INCLUDE/
  6 +)
  7 +
  8 +#Library configuration
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 +)
  14 +
  15 +ADD_LIBRARY( DDClientLibCpp SHARED ${source_files} )
  16 +
  17 +target_link_libraries(
  18 + DDClientLibCpp
  19 + ${CMAKE_THREAD_LIBS_INIT}
  20 +)
  21 +
  22 +install (TARGETS DDClientLibCpp DESTINATION lib)
... ...
src/DDClientLibCpp/DD_client.cc 0 → 100644
  1 +++ a/src/DDClientLibCpp/DD_client.cc
... ... @@ -0,0 +1,1113 @@
  1 +/* $Id: DD_client.c,v 1.3 2009/04/14 08:37:28 budnik Exp $ */
  2 +/*==============================================================
  3 + * DD SYSTEM
  4 + * DD_client.c
  5 + * V.4.8
  6 + * List of changes:
  7 + * November 1995, Version 1.0
  8 + * August 1999 :Access security system was installed by Alexandr Grigoriev (v3.0)
  9 + * October 22, 2002 - Communication ideology is changed (V.4.0)
  10 + * Oct 29, 2002 - Add DD_GetVersion() and some bags are corrected (V.4.1)
  11 + * May 1, 2003 - Network error is developped. (The header receiving is changed): V.4.2
  12 + * Nov 18, 2004 - Cach error is fixed.
  13 + * Jun 17, 2007 - Fedorov, V.4.5 Create new VI and Update data requests
  14 + * Sep 24, 2007 - Fedorov, V.4.6 Processing of return of Get_Data
  15 + * Dec 03, 2007 - Budnik, V.4.7 There may be several sessions with DD Server inside ONE
  16 + * Client session. Keep UserHost & UserName
  17 + * Oct 18, 2012 - Knizhnikova, V.4.8 new DD_SetTimeInfo() function
  18 + *===============================================================*/
  19 +
  20 +#include <unistd.h>
  21 +#include <stdio.h>
  22 +#include <string.h>
  23 +
  24 +#include <sys/socket.h>
  25 +#include <netinet/in.h>
  26 +#include <arpa/inet.h>
  27 +
  28 +#include "DD.hh"
  29 +
  30 +#ifdef LOG4CXX
  31 +log4cxx::LoggerPtr DD_Client::_logger = log4cxx::Logger::getLogger(
  32 + "AMDA-Kernel.DD_Client");
  33 +#endif
  34 +
  35 +/*------------------ GLOBAL STATIC VARIABLES --------------------------*/
  36 +
  37 +//extern int errno;
  38 +
  39 +/*================== FUNCTIONS =================================*/
  40 +/*----------------------- GET User Host-------------------------------*/
  41 +
  42 +static size_t unixlen[] = {sizeof(char),sizeof(int),sizeof(float),sizeof(double),sizeof(short)};
  43 +
  44 +static xdrproc_t ConvFunc[5] = {(xdrproc_t )xdr_char, (xdrproc_t )xdr_int, (xdrproc_t )xdr_float, (xdrproc_t )xdr_double, (xdrproc_t )xdr_short};
  45 +
  46 +DD_Client:: DD_Client() :
  47 + idd (DD_CHAR, 0, NULL,1, (void**) malloc(sizeof(void*))),
  48 + CurrentData(NULL),
  49 + _varNumber(0),
  50 + SocketID( -1),
  51 + UserID(0),
  52 + m1(0X000000FF),
  53 + m2( 0X0000FF00),
  54 + m3(0X00FF0000),
  55 + m4( 0XFF000000),
  56 + //Host(NULL),
  57 + buffSetVarialbe(NULL),
  58 + bufDD_SetTime (NULL),
  59 + op(TIMESETREQ),
  60 + bufDD_GetData( NULL),
  61 + LastPacketFlag(OK),
  62 + bufDD_Close (NULL),
  63 + opDD_Close(CLOSEINSREQ),
  64 + bufDD_AddDataSet(NULL),
  65 + opDD_AddDataSet(ADDVIREQ),
  66 + Version(VERSION)
  67 +
  68 + {
  69 + UserName[0] = '\0';
  70 + UserHost[0] = '\0';
  71 + RemSerName[0]='\0';
  72 + strcpy(TimeInt, "0000000000001000");
  73 + idd.Variables[0]=NULL;
  74 +}
  75 +
  76 +int DD_Client::GetUserHost() {
  77 + int userid;
  78 +
  79 + userid = getuid(); /* Get a client user ID */
  80 +
  81 +#ifdef LOG4CXX
  82 + //LOG4CXX_DEBUG(_logger, "DD_Client::GetUserHost - UserId : " << userid);
  83 +#endif
  84 +
  85 + /* UserHost can be set by extern WEB function in case of WEB communicatio,
  86 + * or it should be defined as local host if DD_client is installed at USER
  87 + * computer
  88 + */
  89 + if (UserHost[0] == '\0') {
  90 + char HostName[HOSTNAMELENGTH];
  91 +
  92 + gethostname(HostName, HOSTNAMELENGTH); /* Get a client host name */
  93 +
  94 + struct sockaddr_in addr;
  95 +
  96 + if (getInfoFromHostName(HostName,addr) != 0)
  97 + return NOHOST;
  98 +
  99 + unsigned int b1, b2, b3, b4;
  100 + sscanf(inet_ntoa( addr.sin_addr), "%3u.%3u.%3u.%3u", &b1, &b2, &b3, &b4);
  101 + snprintf(UserHost, MAXHOSTLENGTH, "%03u.%03u.%03u.%03u", b1, b2, b3, b4);
  102 +
  103 +#ifdef LOG4CXX
  104 + //LOG4CXX_DEBUG(_logger, "DD_Client::GetUserHost - UserHost : " << UserHost);
  105 +#endif
  106 + }
  107 + return userid;
  108 +}
  109 +
  110 +void DD_Client::setUserHost(const char* host) {
  111 + snprintf(UserHost, MAXHOSTLENGTH, "%s", host);
  112 +#ifdef LOG4CXX
  113 + //LOG4CXX_DEBUG(_logger, "DD_Client::setUserHost - UserHost : " << UserHost);
  114 +#endif
  115 +}
  116 +
  117 +int DD_Client::getInfoFromHostName(const char *hostName, struct sockaddr_in &addr)
  118 +{
  119 + struct addrinfo hints;
  120 + memset(&hints, 0, sizeof(struct addrinfo));
  121 + hints.ai_family = AF_INET;
  122 + hints.ai_socktype = SOCK_STREAM;
  123 + hints.ai_flags = AI_PASSIVE;
  124 + hints.ai_protocol = 0;
  125 + hints.ai_canonname = NULL;
  126 + hints.ai_addr = NULL;
  127 + hints.ai_next = NULL;
  128 +
  129 + struct addrinfo *result;
  130 + int s;
  131 +
  132 + s = getaddrinfo(hostName, NULL, &hints, &result);
  133 +
  134 + if (s != 0)
  135 + {
  136 +#ifdef LOG4CXX
  137 + LOG4CXX_ERROR(_logger, "DD_Client::getIpFromHostName - Cannot get ip from host name " << hostName);
  138 +#endif
  139 + return NOHOST;
  140 + }
  141 +
  142 + struct sockaddr_in *h;
  143 + h = (struct sockaddr_in *) result->ai_addr;
  144 +
  145 + memcpy(&addr,h,sizeof(struct sockaddr_in));
  146 +
  147 + freeaddrinfo(result);
  148 +
  149 + return 0;
  150 +}
  151 +/*-------------------------------------------------------------------*/
  152 +
  153 +/*------------------ MAKE_CONNECTION ---------------------------*/
  154 +/*
  155 + * The function returns opened socket, ready to read and write
  156 + */
  157 +int DD_Client::GetSocket()
  158 +/*
  159 + * Connect with remote server, and returns socket ID
  160 + * In case of error return error number according DD_comm.h
  161 + */
  162 +{
  163 +/*-------- Variables for resource file -----------------*/
  164 + char rname[PATHLENGTH]; /* name of res file */
  165 + char line[PATHLENGTH];
  166 + char *path;
  167 + FILE *resfile; /* resource file */
  168 +
  169 +/*---------- Variables for network ---------------------*/
  170 +
  171 + int normaddr;
  172 +/*
  173 + *---------- Getting socket and its address ---------------------*/
  174 +/*---------------- HOST and PORT ------------------------------*/
  175 + if((path = getenv("DDPATH")) == NULL)
  176 + {
  177 + strcpy(rname,"DD.res");
  178 + }
  179 + else
  180 + {
  181 + strcpy(rname,path);
  182 + strcat(rname, "/DD.res");
  183 + }
  184 +/*
  185 + (void *)strcpy(rname,"./DD.res");
  186 +*/
  187 + if((resfile = fopen(rname,"r")) == NULL)
  188 + {
  189 +#ifdef LOG4CXX
  190 + LOG4CXX_ERROR(_logger, "DD_Client::GetSocket - Cannot find resource file " << rname);
  191 +#endif
  192 +
  193 + fprintf(stderr,"No resource file, sorry\n");
  194 + exit(1);
  195 + }
  196 +
  197 + fgets(RemSerName, PATHLENGTH-1, resfile);
  198 + fgets(line, PATHLENGTH-1, resfile);
  199 + fclose(resfile);
  200 +
  201 + RemSerName[strlen(RemSerName)-1] = '\0';
  202 + sscanf(line,"%5d",&(normaddr));
  203 +
  204 +
  205 +/*---------------- END of FILE READING --------------------------*/
  206 +/*
  207 + *------- Trying to open socket with this address and name ---------
  208 + */
  209 +
  210 + if((SocketID = socket(AF_INET,SOCK_STREAM,PROTOCOL)) < 0)
  211 + {
  212 +#ifdef LOG4CXX
  213 + LOG4CXX_ERROR(_logger, "DD_Client::GetSocket - Socket error ");
  214 +#endif
  215 + perror("Socket:"); return(-1);
  216 + }
  217 +
  218 +/* Filling full internet address for socket "name"
  219 + * this address will be used to get communication point */
  220 +
  221 + struct sockaddr_in IntAFAddr;
  222 +
  223 + if (getInfoFromHostName(RemSerName,IntAFAddr) != 0)
  224 + return NOHOST;
  225 +
  226 + IntAFAddr.sin_port = htons((uint16_t)normaddr); /* Conversion of the port number to
  227 + universal net form */
  228 +#ifdef LOG4CXX
  229 + //LOG4CXX_DEBUG(_logger, "DD_Client::GetSocket - HostName : " << RemSerName << " - IP : " << inet_ntoa(IntAFAddr.sin_addr) << " - Port : " << IntAFAddr.sin_port);
  230 +#endif
  231 +
  232 + /* Connection to server socket on remote computer */
  233 + int errnum = connect(SocketID,(struct sockaddr *)&IntAFAddr,sizeof(struct sockaddr_in));
  234 + if(errnum < 0)
  235 + {
  236 +#ifdef LOG4CXX
  237 + LOG4CXX_ERROR(_logger, "DD_Client::GetSocket - Connection to server socket error - " << strerror (errnum));
  238 +#endif
  239 + perror("connect");
  240 + return(-1);
  241 + }
  242 +
  243 +/*
  244 + * Get Host name and Host ID for security application
  245 + */
  246 + if((UserID = GetUserHost()) < 0)
  247 + {
  248 +#ifdef LOG4CXX
  249 + LOG4CXX_ERROR(_logger, "DD_Client::GetSocket - NOHOST error");
  250 +#endif
  251 + return(NOHOST);
  252 + }
  253 +
  254 + return SocketID;
  255 +}
  256 +/*------------------- end of GetSocket ---------------------*/
  257 +
  258 +/*==================== Receive From Net ======================*/
  259 +/*
  260 + * Smart buffered receiver
  261 + */
  262 +int DD_Client::ReceiveFromNet(char *buf, int PacketSize)
  263 +{
  264 + int CurLength = 0;
  265 +
  266 + do
  267 + {
  268 + int i = 0;
  269 + int cc = 0;
  270 + while(( (cc = recv(SocketID,buf+ CurLength,PacketSize - CurLength,0)) < 0) && (i < TRY)) i++;
  271 + if(cc < 0) return -1;
  272 + CurLength = CurLength + cc;
  273 + } while(CurLength < PacketSize);
  274 + return 1;
  275 +}
  276 +
  277 +/*------------------ Open Virtual Instrument -----------------------*/
  278 +/*
  279 + * If no connection, connect to server, then try to order data set and return
  280 + * ID if OK or ErrorNumber if not
  281 + */
  282 +int DD_Client::DD_SetVariable(char *InstrName)
  283 +{
  284 + int InstrID; /* Instrumnet ID to return */
  285 + int Request = OPENINSREQ;
  286 + int hostlen,userlen;
  287 + char *PUserHost = UserHost, *PUserName = UserName;
  288 + /* We need this because XDR works with adresses of pointers */
  289 +
  290 +/* If there is no connection, try to get it */
  291 + if(SocketID < 0)
  292 + if((SocketID = GetSocket()) < 0)
  293 + {
  294 +#ifdef LOG4CXX
  295 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetVariable - No connection");
  296 +#endif
  297 + return(NOCONNECTION);
  298 + }
  299 +
  300 +/* Encoding request by XDR to buf */
  301 +/* Buffer and stream allocation */
  302 + buffSetVarialbe = (caddr_t)calloc(REQUESTLENGTH, 1);
  303 +
  304 + xdrmem_create(&xdrs, buffSetVarialbe, REQUESTLENGTH, XDR_ENCODE);
  305 +
  306 + xdr_int(&xdrs,&Request);
  307 + xdr_string(&xdrs, &InstrName, strlen(InstrName));
  308 +
  309 +/* Send Open Virtual Instrument request */
  310 +
  311 + if( send(SocketID,buffSetVarialbe,REQUESTLENGTH,0) < 0)
  312 + {
  313 +#ifdef LOG4CXX
  314 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetVariable - Cannot open virtual instrument");
  315 +#endif
  316 + perror("DD_SetVariable:");
  317 + free(buffSetVarialbe);
  318 + xdr_destroy(&xdrs);
  319 + return(REQSENDERR);
  320 + }
  321 + xdrmem_create(&xdrs, buffSetVarialbe, REQUESTLENGTH, XDR_FREE);
  322 +
  323 +/*-------- preparation an authorization request ----------------*/
  324 + if(UserName[0] == '\0') strcpy(UserName,NONAME);
  325 + hostlen = strlen(UserHost);
  326 + userlen = strlen(UserName);
  327 +
  328 + xdrmem_create(&xdrs, buffSetVarialbe,REQUESTLENGTH, XDR_ENCODE);
  329 +
  330 + xdr_int(&xdrs,&UserID);
  331 + xdr_string(&xdrs, &PUserHost, hostlen);
  332 + xdr_string(&xdrs, &PUserName, userlen);
  333 +/* fprintf(stderr,"userid %d host %s DD_name %s\n",UserID,UserHost,UserName); */
  334 +
  335 +/* Send request */
  336 + if( send(SocketID,buffSetVarialbe,REQUESTLENGTH,0) < 0)
  337 + {
  338 +#ifdef LOG4CXX
  339 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetVariable - Cannot send request");
  340 +#endif
  341 + perror("DD_Set_Variable:");
  342 + free(buffSetVarialbe);
  343 + xdr_destroy(&xdrs);
  344 + return(REQSENDERR);
  345 + }
  346 +
  347 + free(buffSetVarialbe);
  348 + xdr_destroy(&xdrs);
  349 +
  350 +/* Get reply */
  351 + buffSetVarialbe = (caddr_t)malloc(REPLYLENGTH);
  352 +/*
  353 + i=0;
  354 + while(((cc = recv(SocketID,buff,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  355 +*/
  356 + if( ReceiveFromNet(buffSetVarialbe, REPLYLENGTH) < 0)
  357 + {
  358 +#ifdef LOG4CXX
  359 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetVariable - Cannot receive from net");
  360 +#endif
  361 + perror("DD_SET_Variable:");
  362 + free(buffSetVarialbe);
  363 + return(REPLYRECERR);
  364 + }
  365 +
  366 + xdrmem_create(&xdrs, buffSetVarialbe, REPLYLENGTH, XDR_DECODE);
  367 + xdr_int(&xdrs,&InstrID);
  368 +
  369 +/* Free all */
  370 + free(buffSetVarialbe);
  371 + xdr_destroy(&xdrs);
  372 +
  373 + return InstrID;
  374 +}
  375 +
  376 +/*----------------------- DD_GetInform -----------------------------*/
  377 +/*
  378 + * Returns "OK" if OK, fill DD_Data structure
  379 + * Return negative value if error
  380 + */
  381 +
  382 +int DD_Client::DD_GetInform(int VarID,char *AttrName,DD_data_t **data)
  383 +{
  384 + XDR xdrs;
  385 + caddr_t bufDD_GetInform = NULL;
  386 + int length;
  387 + int op = DATAINFOREQ;
  388 + int type; /* type of information or error */
  389 + int DimNumbers;
  390 + int PacketSize;
  391 + u_int count;
  392 + u_int MaxNumber;
  393 +
  394 +/*------------------- Empty static data ------------------------*/
  395 + if(idd.Dimensions != NULL)
  396 + {
  397 + free(idd.Dimensions);
  398 + idd.Dimensions = NULL;
  399 + }
  400 + if(idd.Variables[0] != NULL)
  401 + {
  402 + free(idd.Variables[0]);
  403 + idd.Variables[0] = NULL;
  404 + }
  405 +
  406 +/*------------------ Check the Name length -----------------------*/
  407 + if(strlen(AttrName) > MAXVARLENGTH) length = MAXVARLENGTH;
  408 + else length = strlen(AttrName);
  409 +
  410 +/*----------- Allocation of memory and stream --------------------*/
  411 + bufDD_GetInform = (caddr_t)calloc(REQUESTLENGTH,1);
  412 + xdrmem_create(&xdrs, bufDD_GetInform, REQUESTLENGTH, XDR_ENCODE);
  413 +
  414 +/*------------------- Encoding the request ----------------------*/
  415 + xdr_int(&xdrs,&op);
  416 + xdr_int(&xdrs,&VarID);
  417 + xdr_string(&xdrs, &AttrName, length);
  418 +
  419 +/*------------------------ Send request ---------------------------*/
  420 + if( send(SocketID,bufDD_GetInform,REQUESTLENGTH,0) < 0)
  421 + {
  422 +#ifdef LOG4CXX
  423 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetInform - Cannot send request");
  424 +#endif
  425 + perror("DD_GetInform:");
  426 + free(bufDD_GetInform);
  427 + xdr_destroy(&xdrs);
  428 + return(REQSENDERR);
  429 + }
  430 + free(bufDD_GetInform);
  431 + xdr_destroy(&xdrs);
  432 +
  433 +/*------------------------ Get reply header ------------------------*/
  434 +
  435 + bufDD_GetInform = (caddr_t)malloc(REPLYLENGTH);
  436 +/*
  437 + i=0;
  438 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  439 + if(cc < 0)
  440 +*/
  441 + if(( ReceiveFromNet(bufDD_GetInform, REPLYLENGTH)) < 0)
  442 + {
  443 +#ifdef LOG4CXX
  444 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetInform - Cannot receive from net");
  445 +#endif
  446 + perror("DD_GetInform:");
  447 + free(bufDD_GetInform);
  448 + return(REPLYRECERR);
  449 + }
  450 +
  451 + xdrmem_create(&xdrs, bufDD_GetInform, REPLYLENGTH, XDR_DECODE);
  452 + xdr_int(&xdrs,&type);
  453 + if(type < 0)
  454 + {
  455 + free(bufDD_GetInform);
  456 + xdr_destroy(&xdrs);
  457 + return(type);
  458 + }
  459 + xdr_int(&xdrs,&DimNumbers);
  460 + xdr_int(&xdrs,&PacketSize);
  461 + free(bufDD_GetInform);
  462 + xdr_destroy(&xdrs);
  463 +
  464 + idd.DimNumber = DimNumbers;
  465 + idd.type = type;
  466 +
  467 +/*---------------------------- Get Data Packet ----------------------*/
  468 + if(PacketSize > 0) bufDD_GetInform = (caddr_t)malloc(PacketSize);
  469 + else
  470 + {
  471 +#ifdef LOG4CXX
  472 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetInform - Cannot Cannot get data packet");
  473 +#endif
  474 + return(REPLYRECERR);
  475 + }
  476 +
  477 + if(( ReceiveFromNet(bufDD_GetInform, PacketSize)) < 0)
  478 + {
  479 +#ifdef LOG4CXX
  480 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetInform - Cannot receive from net");
  481 +#endif
  482 + perror("DD_GetInform:");
  483 + free(bufDD_GetInform);
  484 + return(REPLYRECERR);
  485 + }
  486 +
  487 +/*--------------------- Decoding data packet ------------------------*/
  488 + if(DimNumbers > 0)
  489 + {
  490 +/*----------- Memory allocation and xdr creating -----------------*/
  491 + xdrmem_create(&xdrs, bufDD_GetInform, (u_int)PacketSize, XDR_DECODE);
  492 +
  493 +/*----------------- Dimensions decoding -------------------------*/
  494 + if(idd.Dimensions !=NULL) free(idd.Dimensions);
  495 + idd.Dimensions = (int *)malloc(DimNumbers*sizeof(int));
  496 +
  497 + xdr_array(&xdrs, (caddr_t *)&(idd.Dimensions),
  498 + &count,
  499 + (u_int )DimNumbers,
  500 + unixlen[DD_INT],
  501 + (xdrproc_t)xdr_int);
  502 +
  503 + count = 1;
  504 + for(int i=0; i < DimNumbers;i++)
  505 + count = count*idd.Dimensions[i];
  506 + MaxNumber = count;
  507 + }
  508 + else
  509 + {
  510 +#ifdef LOG4CXX
  511 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetInform - Cannot decoding data packet");
  512 +#endif
  513 + free(bufDD_GetInform);
  514 + return(REPLYRECERR);
  515 + }
  516 +
  517 +/*---------------- Allocate memory for Variables and decoding ------------------*/
  518 + if(idd.Variables[0] != NULL) free(idd.Variables[0]);
  519 + idd.Variables[0] = (int *)malloc(unixlen[type] * MaxNumber);
  520 +
  521 + xdr_array(&xdrs,((caddr_t*)(&idd.Variables[0])),&count,
  522 + MaxNumber, unixlen[type], ConvFunc[type]);
  523 +
  524 +/*-------------------------- Free all ------------------------------*/
  525 + free(bufDD_GetInform);
  526 + xdr_destroy(&xdrs);
  527 +
  528 + *data = &idd;
  529 + return OK;
  530 +}
  531 +
  532 +/*------------------- DD_SETTIME ------------------------------------*/
  533 +/*
  534 + * VarID - ID of Data Set
  535 + * Time - string in DD type
  536 + * Returns 1 if OK and negative in case of err
  537 + */
  538 +
  539 +int DD_Client:: DD_SetTime(int VarID,char *Time)
  540 +{
  541 + int type;
  542 + int DoneFlag = 0;
  543 +
  544 + while(DoneFlag == 0)
  545 + {
  546 +/* Allocatein memory and stream */
  547 + bufDD_SetTime = (caddr_t)calloc(REQUESTLENGTH, 1);
  548 + xdrmem_create(&xdrsDD_SetTime, bufDD_SetTime, REQUESTLENGTH, XDR_ENCODE);
  549 +
  550 +/* Encoding the request */
  551 + xdr_int(&xdrsDD_SetTime,&op);
  552 + xdr_int(&xdrsDD_SetTime,&VarID);
  553 + xdr_string(&xdrsDD_SetTime, &Time, TIMELENGTH);
  554 +
  555 +/* Send request */
  556 + if(( send(SocketID,bufDD_SetTime,REQUESTLENGTH,0)) < 0)
  557 + {
  558 +#ifdef LOG4CXX
  559 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetTime - Cannot send request");
  560 +#endif
  561 + perror("DD_SetTime:");
  562 + free(bufDD_SetTime);
  563 + xdr_destroy(&xdrsDD_SetTime);
  564 + return(REQSENDERR);
  565 + }
  566 + free(bufDD_SetTime);
  567 + xdr_destroy(&xdrsDD_SetTime);
  568 +
  569 +/* Get reply header */
  570 +
  571 + bufDD_SetTime = (caddr_t)malloc(REPLYLENGTH);
  572 +
  573 + if(( ReceiveFromNet(bufDD_SetTime, REPLYLENGTH)) < 0)
  574 + {
  575 +#ifdef LOG4CXX
  576 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetTime - Cannot receive from net");
  577 +#endif
  578 + perror("DD_SetTime:");
  579 + free(bufDD_SetTime);
  580 + return(REPLYRECERR);
  581 + }
  582 +
  583 + xdrmem_create(&xdrsDD_SetTime, bufDD_SetTime, REPLYLENGTH, XDR_DECODE);
  584 + xdr_int(&xdrsDD_SetTime,&type);
  585 +
  586 + free(bufDD_SetTime);
  587 + xdr_destroy(&xdrsDD_SetTime);
  588 +
  589 + if(type < 0)
  590 + {
  591 + if(type == CACHTOOREC) sleep((unsigned )(FILEACCMARG));
  592 + else return type;
  593 + }
  594 + else DoneFlag = 1;
  595 + }
  596 + return 1 ;
  597 +}
  598 +
  599 +/*------------------- DD_SETTIMEINFO ------------------------------------*/
  600 +/*
  601 + * VarID - ID of Data Set
  602 + * Time - string in DD type
  603 + * RealTime - double : time value pointer points to
  604 + * Returns 1 if OK and negative in case of err
  605 + */
  606 +
  607 +int DD_Client:: DD_SetTimeInfo(int VarID, char *Time, double *RealTime)
  608 +{
  609 + int err;
  610 +
  611 + DD_data_t *data;
  612 +
  613 + if ((err = DD_SetTime(VarID, Time)) < 0)
  614 + {
  615 + while ((err == WAITEXTCALL) || (err == TRYAGAIN))
  616 + {
  617 + sleep(2);
  618 + err = DD_SetTime(VarID, Time);
  619 + }
  620 + }
  621 +
  622 + if (err < 1)
  623 + {
  624 +#ifdef LOG4CXX
  625 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetTimeInfo - Cannot set time " << Time);
  626 +#endif
  627 + return err;
  628 + }
  629 +
  630 + if ((err = DD_GetData(VarID, (char *)"Time", TimeInt, &data)) < 0)
  631 + {
  632 + while ((err == WAITEXTCALL) || (err == TRYAGAIN))
  633 + {
  634 + sleep(2);
  635 + err = DD_GetData(VarID, (char *)"Time", TimeInt, &data);
  636 + }
  637 + }
  638 +
  639 + if (err < 0)
  640 + {
  641 +#ifdef LOG4CXX
  642 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetTimeInfo - Cannot get data " << Time);
  643 +#endif
  644 + return err;
  645 + }
  646 + if (data->VarNumber < 1)
  647 + {
  648 +#ifdef LOG4CXX
  649 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetTimeInfo - OUTOFTIME error " << Time);
  650 +#endif
  651 + return OUTOFTIME;
  652 + }
  653 +
  654 + *RealTime = DD_Time2Double((char *)data->Variables[0]);
  655 +
  656 + //BRE - When the corresponding time is the last one of a file, MOREDATA is returned by DDServer.
  657 + // => force recall of DD_GetData to open the next file and finish correctly the request
  658 + if (err == MOREDATA)
  659 + {
  660 + if ((err = DD_GetData(VarID, (char *)"Time", TimeInt, &data)) < 0)
  661 + {
  662 + while ((err == WAITEXTCALL) || (err == TRYAGAIN))
  663 + {
  664 + sleep(2);
  665 + err = DD_GetData(VarID, (char *)"Time", TimeInt, &data);
  666 + }
  667 + }
  668 + }
  669 +
  670 + return 1 ;
  671 +}
  672 +
  673 +/*------------------------- DD_GETDATA --------------------------------*/
  674 +/*
  675 + * VarID - ID of open virtual instrument
  676 + * VarName - Variable name associated with this virtual instrument
  677 + * TimeInt - Time interval in DD_time style
  678 + * data - returned data
  679 + * Return values:
  680 + * positives:
  681 + * MOREDELAY - call this function again after delay
  682 + * MOREDATA - call this function again to complete request
  683 + * OK - all data received
  684 + * negative value - error (see DD.h)
  685 + */
  686 +
  687 +int DD_Client::DD_GetData(int VarID,char *VarName,char *TimeInt,DD_data_t **data)
  688 +{
  689 + char *xxx=VarName;
  690 + int err = DD_GetMultiData(VarID, 1, &xxx, TimeInt, data, 1);
  691 + return err;
  692 + }
  693 +
  694 +/*------------------------- DD_GetMultiData() --------------------------------*/
  695 +/*---------------------------------------------------------
  696 + * VarID - ID of open virtual instrument
  697 + * VarSize - the size of the array names
  698 + * VarNames - array of the variables names
  699 + * TimeInt - Time interval in DD_time style
  700 + * data - returned data
  701 + * Return values:
  702 + * positives:
  703 + * MOREDELAY - call this function again after delay
  704 + * MOREDATA - call this function again to complete request
  705 + * OK - all data received
  706 + * negative value - error (see DD.h)
  707 + */
  708 +int DD_Client::DD_GetMultiData(int VarID,size_t VarSize, char **VarNames,char *TimeInt,DD_data_t **data, int BackFlag)
  709 +{
  710 + size_t id;
  711 + int *NameLength = NULL; /* Array of lengths */
  712 + int XDRStrLen; /* xdr length of a string */
  713 + int XDRReqlength; // Length in bytes the XDR stream
  714 + int op = DATAGETREQ;
  715 + int type; /* type of information or error */
  716 + int DimNumbers;
  717 + int PacketSize;
  718 + u_int count, MaxSize=0;
  719 + int i;
  720 +
  721 + /*--------------------------------------
  722 + * Create a new Current Data empty array
  723 + *-------------------------------------*/
  724 + for( int i = 0; i < _varNumber; ++i) {
  725 + CurrentData[i].clear();
  726 + }
  727 + delete[] CurrentData;
  728 + _varNumber = VarSize;
  729 + CurrentData = new DD_data_t[_varNumber];
  730 +
  731 + /*--------------------------------------------------------------
  732 + * The follows request preparation and send is performed only
  733 + * if the priveous data packed is completely received
  734 + *--------------------------------------------------------------*/
  735 + if((LastPacketFlag == OK) || (LastPacketFlag == MOREDELAY))
  736 + {
  737 + /*---------------------------------------
  738 + * Preparation of the array the name lengths
  739 + * Note that the names are cut down to the MAXVARLENGTH
  740 + * Calculation the packet size
  741 + *---------------------------------------*/
  742 + NameLength = (int *)malloc(sizeof(int)*VarSize);
  743 + XDRReqlength = 8; /* the length of the first+last arguments */
  744 + for(id = 0; id < VarSize; id++)
  745 + {
  746 + if(strlen(VarNames[id]) > MAXVARLENGTH) NameLength[id] = MAXVARLENGTH;
  747 + else NameLength[id] = strlen(VarNames[id]);
  748 + XDRStrLen = (NameLength[id] / 4) * 4;
  749 + if((NameLength[id] % 4) > 0) XDRStrLen += 4;
  750 + XDRReqlength += XDRStrLen + 4; // String length + 4 bytes length coding
  751 + //fprintf(stderr,"Variable %s, length %d, total %d\n",VarNames[id],XDRStrLen,XDRReqlength);
  752 + }
  753 + /*--------------------------------
  754 + * The first packet of the request of the standard size
  755 + * Allocation corresponding memory and stream
  756 + *------------------------------*/
  757 + bufDD_GetData = (caddr_t)calloc(REQUESTLENGTH, 1);
  758 + xdrmem_create(&xdrsDD_GetData, bufDD_GetData, REQUESTLENGTH, XDR_ENCODE);
  759 +
  760 + /* Encoding the request */
  761 + xdr_int(&xdrsDD_GetData,&op);
  762 + xdr_int(&xdrsDD_GetData,&VarID);
  763 + xdr_string(&xdrsDD_GetData,&TimeInt,TIMELENGTH);
  764 + xdr_int(&xdrsDD_GetData,&XDRReqlength);
  765 +
  766 + /* Send the first request */
  767 + if(( send(SocketID,bufDD_GetData,REQUESTLENGTH,0)) < 0)
  768 + {
  769 +#ifdef LOG4CXX
  770 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Cannot send the first request");
  771 +#endif
  772 + perror("DD_GetData: First Request");
  773 + free(bufDD_GetData);
  774 + free(NameLength);
  775 + xdr_destroy(&xdrsDD_GetData);
  776 + return(REQSENDERR);
  777 + }
  778 + free(bufDD_GetData);
  779 + xdr_destroy(&xdrsDD_GetData);
  780 +
  781 + /*--------------------------------
  782 + * The Second packet of XDRReqlength size
  783 + * Allocation corresponding memory and stream
  784 + *------------------------------*/
  785 + bufDD_GetData = (caddr_t)malloc(XDRReqlength);
  786 + xdrmem_create(&xdrsDD_GetData, bufDD_GetData, XDRReqlength, XDR_ENCODE);
  787 + xdr_int(&xdrsDD_GetData,(int *)(&VarSize));
  788 + for(id = 0; id < VarSize; id++) xdr_string(&xdrsDD_GetData, &VarNames[id], NameLength[id]);
  789 +
  790 + free(NameLength);
  791 + NameLength = NULL;
  792 + xdr_int(&xdrsDD_GetData,&BackFlag);
  793 +
  794 + /* Send the second request */
  795 + if(( send(SocketID,bufDD_GetData,XDRReqlength,0)) < 0)
  796 + {
  797 +#ifdef LOG4CXX
  798 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Cannot send the second request");
  799 +#endif
  800 + perror("DD_GetData:Second Packet");
  801 + free(bufDD_GetData);
  802 + xdr_destroy(&xdrsDD_GetData);
  803 + return(REQSENDERR);
  804 + }
  805 + free(bufDD_GetData);
  806 + xdr_destroy(&xdrsDD_GetData);
  807 + }
  808 +
  809 + /*-----------------------------------------------------------
  810 + * Get the VarSize reply headers and VarSize data
  811 + *----------------------------------------------------------*/
  812 + for(id = 0; id < VarSize; id++)
  813 + {
  814 + /*-------------------
  815 + * The header
  816 + *-----------------*/
  817 + bufDD_GetData = (caddr_t)malloc(REPLYLENGTH);
  818 + if(( ReceiveFromNet(bufDD_GetData, REPLYLENGTH)) < 0)
  819 + {
  820 +#ifdef LOG4CXX
  821 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Cannot receive header");
  822 +#endif
  823 + perror("DD_GetData:Error while header receive");
  824 + free(bufDD_GetData);
  825 + return(REPLYRECERR);
  826 + }
  827 +
  828 + xdrmem_create(&xdrsDD_GetData, bufDD_GetData, REPLYLENGTH, XDR_DECODE);
  829 + xdr_int(&xdrsDD_GetData,&type);
  830 + xdr_int(&xdrsDD_GetData,&DimNumbers);
  831 + xdr_int(&xdrsDD_GetData,&PacketSize);
  832 + free(bufDD_GetData);
  833 + xdr_destroy(&xdrsDD_GetData);
  834 +
  835 + if (type < 0) /* Server returns unrecoverable error */
  836 + {
  837 +#ifdef LOG4CXX
  838 + LOG4CXX_DEBUG(_logger, "DD_Client::DD_GetMultiData - Server returns " << type << ", no data\n");
  839 +#endif
  840 + fprintf(stderr, "DD_GetData: Server returns %d, no data\n", type);
  841 + return type;
  842 + }
  843 +
  844 + /*----------- Header is received ----------------------*/
  845 + CurrentData[id].DimNumber = DimNumbers - 1;
  846 + CurrentData[id].type = type;
  847 +
  848 + /*--------------- Receive Data Packet ------------------------------*/
  849 + if(PacketSize > 0) bufDD_GetData = (caddr_t)malloc(PacketSize);
  850 + else
  851 + {
  852 +#ifdef LOG4CXX
  853 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Cannot receive data packet");
  854 +#endif
  855 + return(REPLYRECERR);
  856 + }
  857 + if((ReceiveFromNet(bufDD_GetData, PacketSize)) < 0)
  858 + {
  859 +#ifdef LOG4CXX
  860 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Cannot receive data packet from web");
  861 +#endif
  862 + perror("DD_GetData: Error while data packet receive");
  863 + free(bufDD_GetData);
  864 + return(REPLYRECERR);
  865 + }
  866 + /*----------------- Decoding data packet --------------------*/
  867 + if(DimNumbers > 1)
  868 + {
  869 + xdrmem_create(&xdrsDD_GetData, bufDD_GetData, (u_int)PacketSize, XDR_DECODE);
  870 + count = DimNumbers-1;
  871 + /* allocation memory for dimensions */
  872 + CurrentData[id].Dimensions = (int *)malloc((DimNumbers-1)*sizeof(int));
  873 +
  874 + xdr_int(&xdrsDD_GetData,&LastPacketFlag); /* Last Paket Indicatort*/
  875 + xdr_int(&xdrsDD_GetData,&CurrentData[id].VarNumber); /* Variables number */
  876 +
  877 + if(LastPacketFlag > 2)
  878 + {
  879 + LastPacketFlag = OK;
  880 + CurrentData[id].VarNumber = 0;
  881 + free(bufDD_GetData);
  882 +#ifdef LOG4CXX
  883 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Reply received error");
  884 +#endif
  885 + return(REPLYRECERR);
  886 + }
  887 +
  888 + /*----- Decoding dimensions array -------------------*/
  889 + xdr_array(&xdrsDD_GetData, (caddr_t *)&(CurrentData[id].Dimensions),
  890 + &count,
  891 + (u_int )DimNumbers-1,
  892 + unixlen[DD_INT],
  893 + (xdrproc_t)xdr_int);
  894 +
  895 + count = 1;
  896 + for(i=0; i < DimNumbers-1;i++)
  897 + {
  898 + count = count*CurrentData[id].Dimensions[i];
  899 + }
  900 + MaxSize = count;
  901 + }
  902 + else {
  903 + if (type != NOVAR) {
  904 +#ifdef LOG4CXX
  905 + LOG4CXX_ERROR(_logger, "DD_Client::DD_GetMultiData - Reply received error");
  906 +#endif
  907 + free (bufDD_GetData);
  908 + return (REPLYRECERR);
  909 + } else {
  910 + CurrentData[id].VarNumber = 0;
  911 + }
  912 + }
  913 +
  914 + /*---------- Decoding variables -------------------------*/
  915 + if (CurrentData[id].VarNumber != 0) {
  916 + CurrentData[id].Variables = (void **) malloc(CurrentData[id].VarNumber * sizeof(void *));
  917 + } else {
  918 + CurrentData[id].Variables = NULL;
  919 + }
  920 +
  921 + for(i = 0; i < CurrentData[id].VarNumber; i++)
  922 + {
  923 + CurrentData[id].Variables[i] = (void *)malloc(unixlen[type]*MaxSize);
  924 + count = MaxSize;
  925 + xdr_array(&xdrsDD_GetData,(caddr_t *)(&(CurrentData[id].Variables[i])),&count,MaxSize,unixlen[type], (xdrproc_t)ConvFunc[type]);
  926 + }
  927 +
  928 + /* Free all */
  929 + free(bufDD_GetData);
  930 + xdr_destroy(&xdrsDD_GetData);
  931 + }
  932 + *data = CurrentData;
  933 + return(LastPacketFlag);
  934 +}
  935 +
  936 +/*===================================================================*/
  937 +
  938 +/*-------------------------- DD_CLOSE --------------------------------*/
  939 +/*
  940 + *
  941 + * VarID - entry point of ID table
  942 + * Returns 1 if OK or negative err
  943 + * Close Socket if no VarID more ( this information supplyed by server )
  944 + */
  945 +
  946 +int DD_Client:: DD_Close(int VarID)
  947 +{
  948 + int RemainedID; /* Server returns number of remained ID */
  949 +/* Allocatein memory and stream */
  950 + bufDD_Close = (caddr_t)calloc(REQUESTLENGTH, 1);
  951 + xdrmem_create(&xdrsDD_Close, bufDD_Close, REQUESTLENGTH, XDR_ENCODE);
  952 +
  953 +/* Encoding the request */
  954 + xdr_int(&xdrsDD_Close,&opDD_Close);
  955 + xdr_int(&xdrsDD_Close,&VarID);
  956 +
  957 +/* Send request */
  958 + if(( send(SocketID,bufDD_Close,REQUESTLENGTH,0)) < 0)
  959 + {
  960 +#ifdef LOG4CXX
  961 + LOG4CXX_ERROR(_logger, "DD_Client::DD_Close - Cannot send request " << VarID);
  962 +#endif
  963 + perror("DD_Close:");
  964 + free(bufDD_Close);
  965 + xdr_destroy(&xdrsDD_Close);
  966 + return(REQSENDERR);
  967 + }
  968 + free(bufDD_Close);
  969 + xdr_destroy(&xdrsDD_Close);
  970 +
  971 +/* Get reply header */
  972 +
  973 + bufDD_Close = (caddr_t)malloc(REPLYLENGTH);
  974 +/*
  975 + i = 0;
  976 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  977 + if(cc < 0)
  978 +*/
  979 + if(( ReceiveFromNet(bufDD_Close, REPLYLENGTH)) < 0)
  980 + {
  981 +#ifdef LOG4CXX
  982 + LOG4CXX_ERROR(_logger, "DD_Client::DD_Close - Cannot receive from net " << VarID);
  983 +#endif
  984 + perror("DD_Close:");
  985 + free(bufDD_Close);
  986 + return(REPLYRECERR);
  987 + }
  988 +
  989 + xdrmem_create(&xdrsDD_Close, bufDD_Close, REPLYLENGTH, XDR_DECODE);
  990 + xdr_int(&xdrsDD_Close,&RemainedID);
  991 + if(RemainedID< 0)
  992 + {
  993 + free(bufDD_Close);
  994 + xdr_destroy(&xdrsDD_Close);
  995 + return(RemainedID);
  996 + }
  997 + free(bufDD_Close);
  998 + xdr_destroy(&xdrsDD_Close);
  999 +
  1000 + if(RemainedID == 0)
  1001 + {
  1002 + shutdown(SocketID,2);
  1003 + close(SocketID);
  1004 + SocketID = -1;
  1005 +/*
  1006 + UserHost[0] = '\0';
  1007 + UserName[0] = '\0';
  1008 +*/
  1009 + }
  1010 +
  1011 + return(1);
  1012 +}
  1013 +
  1014 +DD_Client::~DD_Client() {
  1015 +
  1016 + for( int i = 0; i < _varNumber; ++i) {
  1017 + CurrentData[i].clear();
  1018 + }
  1019 + delete[] CurrentData;
  1020 +}
  1021 +
  1022 +/*------------------------------------------------------------------------------*/
  1023 +
  1024 +/*=============== DATABASE UPDATE FUNCTIONS ====================================*/
  1025 +/*------------------ DD_AddDataSet() -------------------------------------------*/
  1026 +int DD_Client:: DD_AddDataSet(char *DataSetName, char *RemSetID, char *BaseName)
  1027 +{
  1028 +
  1029 + int Err; /* Server returns OK or NOEXEC */
  1030 + int length;
  1031 + int CloseFlag = 0;
  1032 +
  1033 +/* If there is no connection, try to get it */
  1034 + if(SocketID < 0)
  1035 + {
  1036 + if((SocketID = GetSocket()) < 0)
  1037 + {
  1038 +#ifdef LOG4CXX
  1039 + LOG4CXX_ERROR(_logger, "DD_Client::DD_AddDataSet - No connection");
  1040 +#endif
  1041 + return(NOCONNECTION);
  1042 + }
  1043 + CloseFlag = 1; // To close Connection at the end
  1044 + }
  1045 +
  1046 +/* Allocatein memory and stream */
  1047 + bufDD_AddDataSet = (caddr_t)malloc(REQUESTLENGTH);
  1048 + xdrmem_create(&xdrsDD_AddDataSet, bufDD_AddDataSet, REQUESTLENGTH, XDR_ENCODE);
  1049 +
  1050 +/* Encoding the request */
  1051 + xdr_int(&xdrsDD_AddDataSet,&opDD_AddDataSet);
  1052 +
  1053 +/* Coding DataSetName */
  1054 + if((length = strlen(DataSetName)) > MAXSETLENGTH) length = MAXSETLENGTH;
  1055 + xdr_string(&xdrsDD_AddDataSet, &DataSetName, length);
  1056 +/* Coding RemSetID */
  1057 + if((length = strlen(RemSetID)) > MAXVARLENGTH) length = MAXVARLENGTH;
  1058 + xdr_string(&xdrsDD_AddDataSet, &RemSetID, length);
  1059 +/* Coding BaseName */
  1060 + if((length = strlen(BaseName)) > MAXVARLENGTH) length = MAXVARLENGTH;
  1061 + xdr_string(&xdrsDD_AddDataSet, &BaseName, length);
  1062 +
  1063 +/* Send request */
  1064 + if(( send(SocketID,bufDD_AddDataSet,REQUESTLENGTH,0)) < 0)
  1065 + {
  1066 +#ifdef LOG4CXX
  1067 + LOG4CXX_ERROR(_logger, "DD_Client::DD_AddDataSet - Cannot send request");
  1068 +#endif
  1069 + perror("DD_AddDataSet:");
  1070 + free(bufDD_AddDataSet);
  1071 + xdr_destroy(&xdrsDD_AddDataSet);
  1072 + return(REQSENDERR);
  1073 + }
  1074 + free(bufDD_AddDataSet);
  1075 + xdr_destroy(&xdrsDD_AddDataSet);
  1076 +
  1077 +/* Get reply header */
  1078 + bufDD_AddDataSet = (caddr_t)malloc(REPLYLENGTH);
  1079 + if(( ReceiveFromNet(bufDD_AddDataSet, REPLYLENGTH)) < 0)
  1080 + {
  1081 +#ifdef LOG4CXX
  1082 + LOG4CXX_ERROR(_logger, "DD_Client::DD_AddDataSet - Cannot receive from net");
  1083 +#endif
  1084 + perror("DD_AddDataSet:");
  1085 + free(bufDD_AddDataSet);
  1086 + return(REPLYRECERR);
  1087 + }
  1088 +
  1089 + xdrmem_create(&xdrsDD_AddDataSet, bufDD_AddDataSet, REPLYLENGTH, XDR_DECODE);
  1090 + xdr_int(&xdrsDD_AddDataSet,&Err);
  1091 +
  1092 + if(CloseFlag) // Close everything if function established connection
  1093 + {
  1094 + shutdown(SocketID,2);
  1095 + close(SocketID);
  1096 + SocketID = -1;
  1097 +/* Session with DD Server was closed, but User Session continues !!!!! */
  1098 + /* UserHost[0] = '\0';
  1099 + UserName[0] = '\0'; */
  1100 + }
  1101 + return Err;
  1102 +}
  1103 +/*-----------------------------------------------------------------------------*/
  1104 +
  1105 +/*---------------------- DD GET VERSION ---------------------------------------*/
  1106 +const char *DD_Client:: DD_GetVersion()
  1107 +/*
  1108 + * return static pointer to internal string with the DDLIB-SERVER package version
  1109 + */
  1110 +{
  1111 + return Version;
  1112 +}
  1113 +/*------------------------- End Library -------------------------------*/
... ...
src/DDClientLibCpp/DD_time.cc 0 → 100644
  1 +++ a/src/DDClientLibCpp/DD_time.cc
... ... @@ -0,0 +1,291 @@
  1 +/* ===================================================================
  2 + * Name : DD_time.c
  3 + * Version: : 3.2
  4 + * Author : Andrey Fedorov
  5 + * Institution : IKI RAN, Moscow , CESR, Toulouse
  6 + * Written on : Tue Feb 21 14:27:10 EET 1995
  7 + * Modified on : Oct 5, 2002
  8 + * List of modifications:
  9 + * Oct 5, 2002: V.3.0, New functions DD_Time2Double and Double2DD_Time
  10 + * were added.
  11 + * March 26, 2010: V.3.1 YEARS up to 2025
  12 + * Sept 05, 2011: V.3.2 SetIntNew => arg TimeKind => to work with 1970-1973 : BR
  13 + *==================================================================*/
  14 +
  15 +#include "DD_time.hh"
  16 +#include <stdio.h>
  17 +#include <string.h>
  18 +#include <stdarg.h>
  19 +
  20 +#define YEARS 56
  21 +
  22 +/*---- Static array of days shift from Jun-1-1970 -------*/
  23 +/* 1970 1971 1972 1973 1974 1975 1976
  24 + * 1977 1978 1979 1980 1981 1982 1983
  25 + * 1984 1985 1986 1987 1988 1989 1990
  26 + * 1991 1992 1993 1994 1995 1996 1997
  27 + * 1998 1999 2000 2001 2002 2003 2004
  28 + * 2005 2006 2007 2008 2009 2010 2011
  29 + * 2012 2013 2014 2015 2016 2017 2018
  30 + * 2019 2020 2021 2022 2023 2024 2025
  31 + */
  32 +static double
  33 + YearDays[YEARS] = { 0.0, 365.0, 730.0, 1096.0, 1461.0, 1826.0, 2191.0,
  34 + 2557.0, 2922.0, 3287.0, 3652.0, 4018.0, 4383.0, 4748.0,
  35 + 5113.0, 5479.0, 5844.0, 6209.0, 6574.0, 6940.0, 7305.0,
  36 + 7670.0, 8035.0, 8401.0, 8766.0, 9131.0, 9496.0, 9862.0,
  37 + 10227.0, 10592.0, 10957.0, 11323.0, 11688.0, 12053.0, 12418.0,
  38 + 12784.0, 13149.0, 13514.0, 13879.0, 14245.0, 14610.0, 14975.0,
  39 + 15340.0, 15706.0, 16071.0, 16436.0, 16801.0, 17167.0, 17532.0,
  40 + 17897.0, 18262.0, 18628.0, 18993.0, 19358.0, 19723.0, 20089.0};
  41 +
  42 +static int monthday[2][12] =
  43 +{
  44 +{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
  45 +{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
  46 +};
  47 +/* so, DAY = monthday[*][month-1]+day -1 */
  48 +
  49 +/*================== INTERNAL FUNCTION ====================*/
  50 +/*-------------------- SetInt ----------------------------*/
  51 +void SetInt(dd_tmstr_t *UT)
  52 +{
  53 + SetIntNew(UT,DD_TM_UNKNOWN);
  54 +}
  55 +
  56 +void SetIntNew(dd_tmstr_t *UT,t_DDTimeKind timeKind) /* Fill int values of dd_tmstr_t */
  57 +/* If the double times field of UT structure is defined,
  58 + * this function fills remains fields of Year, day .... separately
  59 + */
  60 +{
  61 + static const double msofday = 24.0*60.0*60.0;
  62 + static const double msofhour = 60.0*60.0;
  63 + static const double msofmin = 60.0;
  64 + long daynumber;
  65 + double msrest;
  66 + int i;
  67 +
  68 + daynumber = (long)(UT->times / msofday);
  69 + for(i=0;i<YEARS;i++) if(daynumber < (long)YearDays[i]) break;
  70 + i--;
  71 +
  72 + switch(timeKind)
  73 + {
  74 + case DD_TM_DATE :
  75 + {
  76 + //it's a date
  77 + UT->year = i+1970;
  78 + UT->day = (int)(daynumber - (long)YearDays[i]);
  79 + break;
  80 + }
  81 + case DD_TM_TIME_INTERVAL :
  82 + {
  83 + //it's a time interval
  84 + UT->year = 0;
  85 + UT->day = (int)(daynumber);
  86 + break;
  87 + }
  88 + default :
  89 + //compatibility mode
  90 + if(i > 3)
  91 + {
  92 + UT->year = i+1970;
  93 + UT->day = (int)(daynumber - (long)YearDays[i]);
  94 + }
  95 + else
  96 + {
  97 + UT->year = 0;
  98 + UT->day = (int)(daynumber);
  99 + }
  100 + break;
  101 + }
  102 +
  103 + msrest = UT->times - (double)daynumber * msofday;
  104 + UT->hour = (int)(msrest / msofhour);
  105 + msrest -= (double)(UT->hour)*msofhour;
  106 + UT->min = (int)(msrest / msofmin);
  107 + msrest -= (double)(UT->min)*msofmin;
  108 + UT->sec = (int)(msrest);
  109 + UT->msec = (int)((msrest - (double)(UT->sec))*1000.0);
  110 + return;
  111 +}
  112 +
  113 +/*---------------- end of SetInt -----------------------*/
  114 +
  115 +/*-----------------SetDouble ---------------------------*/
  116 +void SetDouble(dd_tmstr_t *UT) /* Fill double value of dd_tmstr_t */
  117 +/* If indeger fields of UT is defined, You can calculate double
  118 + * field - amount of sec after Jun-1-1970
  119 + */
  120 +{
  121 + if(UT->year >= 1970)
  122 + UT->times = (double)UT->msec/1000.0 +
  123 + (double)UT->sec +
  124 + (double)UT->min*60 +
  125 + (double)UT->hour*60.0*60.0 +
  126 + (double)UT->day*60.0*60.0*24.0 +
  127 + YearDays[(UT->year - 1970)]*60.0*60.0*24.0;
  128 + else if(UT->year < YEARS)
  129 + UT->times = (double)UT->msec/1000.0 +
  130 + (double)UT->sec +
  131 + (double)UT->min*60 +
  132 + (double)UT->hour*60.0*60.0 +
  133 + (double)UT->day*60.0*60.0*24.0 +
  134 + YearDays[UT->year]*60.0*60.0*24.0;
  135 + else
  136 + UT->times = 0.0;
  137 + return;
  138 +}
  139 +/*----------------- end of SetDouble ---------------------*/
  140 +
  141 +/*=================== PUBLIC FUNCTIONS ==================*/
  142 +/*------------------- DD_Time2Double --------------------*/
  143 +double DD_Time2Double(const dd_time_t UTstring)
  144 +{
  145 + dd_tmstr_t UT;
  146 + char year[5] = "0000";
  147 + char day[4] = "000";
  148 + char hour[3]= "00";
  149 + char min[3] = "00";
  150 + char sec[3]= "00";
  151 + char msec[4] = "000";
  152 +
  153 + strncpy(year,UTstring,4);
  154 + strncpy(day,UTstring+4,3);
  155 + strncpy(hour,UTstring+7,2);
  156 + strncpy(min,UTstring+9,2);
  157 + strncpy(sec,UTstring+11,2);
  158 + strncpy(msec,UTstring+13,3);
  159 +
  160 + sscanf(year,"%4d",&(UT.year));
  161 + sscanf(day,"%3d",&(UT.day));
  162 + sscanf(min,"%2d",&(UT.min));
  163 + sscanf(hour,"%2d",&(UT.hour));
  164 + sscanf(sec,"%2d",&(UT.sec));
  165 + sscanf(msec,"%3d",&(UT.msec));
  166 +
  167 + SetDouble(&UT);
  168 + return UT.times;
  169 +}
  170 +/*------------------------------------------------------*/
  171 +/*------------------- Double2DD_Time ---------------------*/
  172 +void Double2DD_Time(char * buffer, double Time)
  173 + {
  174 + dd_time_t UTstring;
  175 + dd_tmstr_t UT;
  176 +
  177 + UT.times = Time;
  178 + SetIntNew(&UT,DD_TM_DATE); //
  179 + sprintf(UTstring,"%04d%03d%02d%02d%02d%03d",(UT.year),(UT.day),(UT.hour), (UT.min), (UT.sec),(UT.msec));
  180 + strncpy(buffer, &(UTstring[0]), TIMELENGTH);
  181 + }
  182 +/*------------------------------------------------------------*/
  183 +
  184 +/*================== BACKUP COMPABILITY FUNCTIONS =================*/
  185 +/*---------------------ReadTime --------------------------*/
  186 +/* The fiunction ReadTime read standard for DD time string
  187 + * and convert it into dd_tmstr_t structure.
  188 + * see DD-time.h
  189 + * Return pointer to static internal structure or NULL in case
  190 + * of error.
  191 + */
  192 +void ReadTime(dd_tmstr_t &UT,char *UTstring)
  193 +{
  194 + char year[5] = "0000";
  195 + char day[4] = "000";
  196 + char hour[3]= "00";
  197 + char min[3] = "00";
  198 + char sec[3]= "00";
  199 + char msec[4] = "000";
  200 +
  201 + strncpy(year,UTstring,4);
  202 + strncpy(day,UTstring+4,3);
  203 + strncpy(hour,UTstring+7,2);
  204 + strncpy(min,UTstring+9,2);
  205 + strncpy(sec,UTstring+11,2);
  206 + strncpy(msec,UTstring+13,3);
  207 +
  208 + sscanf(year,"%4d",&(UT.year));
  209 + sscanf(day,"%2d",&(UT.day));
  210 + sscanf(min,"%2d",&(UT.min));
  211 + sscanf(hour,"%2d",&(UT.hour));
  212 + sscanf(sec,"%2d",&(UT.sec));
  213 + sscanf(msec,"%3d",&(UT.msec));
  214 +
  215 + SetDouble(&UT);
  216 +}
  217 +/*-------------------- end of ReadTime ------------------------*/
  218 +
  219 +/*---------------------- Write Time ---------------------------*/
  220 +/* Function Write time convert use only double times field
  221 + * of dd_tmstr_t structure to print time in DD style
  222 + * in internal static string. The integer fields redefined.
  223 + * Function return string pointer.
  224 + */
  225 +
  226 +char *WriteTime(dd_tmstr_t *UT)
  227 +{
  228 + static dd_time_t UTstring;
  229 +
  230 + SetIntNew(UT,DD_TM_DATE);
  231 + sprintf(UTstring,"%04d%03d%02d%02d%02d%03d",(UT->year),(UT->day),(UT->hour),
  232 + (UT->min), (UT->sec),(UT->msec));
  233 + return(UTstring);
  234 +}
  235 +/*------------------- end of WriteTime -------------------*/
  236 +
  237 +void WriteFmtTime(dd_tmstr_t *UT,char *UTstring)
  238 + {
  239 + SetIntNew(UT,DD_TM_DATE);
  240 + sprintf(UTstring,"%04d:%03d:%02d:%02d:%02d",(UT->year),(UT->day),(UT->hour),
  241 + (UT->min), (UT->sec));
  242 + }
  243 +
  244 +/*=================== Functions for INTERBALL DECODERS ==============*/
  245 +/*---------------------- UT 2 DOUBLE ---------------------*/
  246 +dd_tmstr_t *UT2double(unsigned *ut)
  247 +/* Fill the standard structure with double too using as
  248 + * argument 7 int length array in Gavrilova Passport Standard
  249 + */
  250 +{
  251 +static dd_tmstr_t UT;
  252 +int visocos;
  253 +
  254 +if(ut[0]%4 == 0) visocos = 1; else visocos = 0;
  255 +UT.year = ut[0];
  256 +UT.day = monthday[visocos][ut[1] - 1]+ut[2] - 1;
  257 +UT.hour = ut[3];
  258 +UT.min = ut[4];
  259 +UT.sec = ut[5];
  260 +UT.msec = ut[6];
  261 +
  262 +SetDouble(&UT);
  263 +return(&UT);
  264 +}
  265 +/*-------------------------------------------------------*/
  266 +/*---------------- DOUBLE 2 UT --------------------------*/
  267 +/*
  268 + * Converts Standard DD double time to Gavrilova UT array
  269 + */
  270 +unsigned *Double2UT(double t)
  271 +{
  272 + static unsigned UT[7];
  273 + dd_tmstr_t tm;
  274 + int i,visocos;
  275 +
  276 + tm.times = t;
  277 + SetIntNew(&tm,DD_TM_DATE);
  278 + if(tm.year % 4 == 0) visocos = 1; else visocos = 0;
  279 + i = 0;
  280 + while((i < 12) && (tm.day >= monthday[visocos][i])) i++;
  281 + UT[0] = tm.year;
  282 + UT[1] = i;
  283 + UT[2] = tm.day +1 - monthday[visocos][i-1];
  284 + UT[3] = tm.hour;
  285 + UT[4] = tm.min;
  286 + UT[5] = tm.sec;
  287 + UT[6] = tm.msec;
  288 +
  289 + return( (unsigned *)UT);
  290 +}
  291 +/*=======================================================================*/
... ...
src/DDClientLibCpp/INCLUDE/DD.hh 0 → 100644
  1 +++ a/src/DDClientLibCpp/INCLUDE/DD.hh
... ... @@ -0,0 +1,219 @@
  1 +/*=================================================================================================
  2 + * DD SYSTEM
  3 + * DD.h
  4 + * Version: 5.2
  5 + * Description: The public header to use DD library libDD.a
  6 + * List of changes:
  7 + * Apr. 17, 2002 Fedorov, - New error constant to interrupt the
  8 + * transmission if data dimensions are changed from file
  9 + * to file
  10 + * Nov 18, 2004 - V.4.2 - Fedorov, New errors for CACH manipulating
  11 + * Jun 17, 2007 - V.4.6 Fedorov New requestes and external executables
  12 + * Aug 02, 2007 - V.4.7 Fedorov Modification of call external executables
  13 + * Sep 24, 2007 - V.5.0 Fedorov New status of Get Data: MOREDELAY
  14 + * May 21, 2008 - V.5.1 Fedorov New Status of SetTime: CTIMEISSHIFTED
  15 + * Oct 18, 2012 - V.5.2 Knizhnikova New DD_SetTimeInfo() function
  16 + * Dec 15, 2012 - Fedorov, V.6.0. DD_GetMultiData(). Request structure is very changed, CurrentData is not a global structure
  17 + *=================================================================================================*/
  18 +
  19 +#ifndef DD_H_
  20 +#define DD_H_
  21 +
  22 +
  23 +#include "DD_comm.hh"
  24 +#include "DD_Access.hh"
  25 +#include "DD_time.hh"
  26 +
  27 +#ifdef LOG4CXX
  28 +#include <log4cxx/logger.h>
  29 +#endif
  30 +
  31 +#define VERSION "V.6.0"
  32 +
  33 +class DD_Client {
  34 +private:
  35 + /* variable for DD_GetInform */
  36 + DD_data_t idd;
  37 +
  38 +
  39 +public:
  40 +
  41 + DD_data_t *CurrentData; /* Data block received recently */
  42 + int _varNumber = 0;
  43 +
  44 + int SocketID; /* Global socket id for this communication session */
  45 + char UserName[USRLENGTH]; /* string for user name */
  46 + char UserHost[MAXHOSTLENGTH]; /* IP of user's host in a string form */
  47 + int UserID; /* ID of user at the user's host */ /* User's ID at a local client host */
  48 +
  49 +
  50 + unsigned int m1 ;
  51 + unsigned int m2 ;
  52 + unsigned int m3 ;
  53 + unsigned int m4 ;
  54 + //struct hostent *Host; /* name & internet (32b) address for
  55 + // remout hosts (see netdb.h) */
  56 + char RemSerName[PATHLENGTH]; /* name of remote server */
  57 +
  58 + //struct sockaddr_in IntAFAddr; /* structure of internet address of type AF_INET
  59 + // see <netinet/in.h>
  60 + // to get name of socket we should
  61 + // to convert pointer to this structure
  62 + // to pointer to "srtruct sockaddr" where
  63 + // all fields are "char array". */
  64 +
  65 + caddr_t buffSetVarialbe;
  66 + XDR xdrs;
  67 +
  68 + /* variable for DD_SetTime */
  69 + caddr_t bufDD_SetTime;
  70 + XDR xdrsDD_SetTime;
  71 + int op;
  72 + char TimeInt[17];
  73 +
  74 + /* variable for DD_GetData */
  75 + caddr_t bufDD_GetData ;
  76 + XDR xdrsDD_GetData;
  77 + int LastPacketFlag;
  78 +
  79 + /* variable for DD_Close*/
  80 + caddr_t bufDD_Close;
  81 + XDR xdrsDD_Close;
  82 + int opDD_Close;
  83 +
  84 + /* variable for DD_AddDataSet */
  85 + caddr_t bufDD_AddDataSet;
  86 + XDR xdrsDD_AddDataSet;
  87 + int opDD_AddDataSet;
  88 +
  89 + /* variable for DD_GetVersion */
  90 + const char *Version;
  91 +
  92 + DD_Client();
  93 +
  94 + ~DD_Client();
  95 +
  96 + /*------------------- FUNCTIONS ---------------------------*/
  97 + int ReceiveFromNet(char *buf, int PacketSize);
  98 +
  99 + int GetUserHost();
  100 +
  101 + void setUserHost(const char* host);
  102 +
  103 + int getInfoFromHostName(const char *hostName, struct sockaddr_in &addr);
  104 +
  105 + int GetSocket();
  106 +
  107 + int DD_SetVariable(char *VarName);
  108 + /*
  109 + * VarName - full name of variable <project>:<instrument>:<Variable>
  110 + * Returns VarID or negative in case of error (see bellow)
  111 + */
  112 +
  113 + int DD_GetInform(int VarID,char *AttrName, DD_data_t **data);
  114 + /*
  115 + * VarID - Variable ID from DD_SetVariable
  116 + * AttrName - name of attribute ( defined by konvention )
  117 + * data - address of data structure
  118 + * Returns 1 if OK and negative value in case of error (see bellow)
  119 + */
  120 +
  121 + int DD_SetTime(int VarID, char *Time);
  122 + /*
  123 + * VarID - Variable ID from DD_SetVariable
  124 + * Time - string defined in DD_time.h
  125 + * Returns 1 if OK and negative value in case of error (see bellow)
  126 + */
  127 +
  128 + int DD_SetTimeInfo(int VarID, char *Time, double *RealTime);
  129 + /*
  130 + * VarID - Variable ID from DD_SetVariable
  131 + * Time - string defined in DD_time.h
  132 + * RealTime - time pointer was set to
  133 + * Returns 1 if OK and negative value in case of error (see bellow)
  134 + */
  135 +
  136 + int DD_GetData(int VarID, char *VarName, char *TimeInt, DD_data_t **data);
  137 + /*
  138 + * VarID - Variable ID from DD_SetVariable
  139 + * VarName - Name of requested Variable
  140 + * TimeInt - String of Time interval in DD_time style
  141 + * data - address of data structure
  142 + * Returns 1 if OK and negative value in case of error (see bellow)
  143 + */
  144 +
  145 + int DD_GetMultiData(int VarID,size_t VarSize, char **VarNames,char *TimeInt,DD_data_t **data, int BackFlag);
  146 + /*
  147 + * VarID - Variable ID from DD_SetVariable
  148 + * VarSize - number of variables to return
  149 + * VarNames - the array of Names of the requested Variable
  150 + * TimeInt - String of Time interval in DD_time style
  151 + * data - Data structures array
  152 + * BackFlag - 0 - pointer is at the lasy position, 1 - pointer returns to the start point
  153 + * Returns 1 if OK and negative value in case of error (see bellow)
  154 + */
  155 +
  156 + int DD_MovePoint(int VarID, int RecordNumber);
  157 + /*
  158 + * VarID - Open virtual instrument ID
  159 + * int RecordNumber - +/- records to move
  160 + * Move pointer in the open instrument and return 1 or negative if error
  161 + */
  162 +
  163 + int DD_Close(int VarID);
  164 + /*
  165 + * VarID - Variable ID from DD_SetVariable
  166 + * Returns 1 if OK and negative value in case of error (see bellow)
  167 + */
  168 +
  169 + const char *DD_GetVersion();
  170 + /*
  171 + * return static pointer to internal string with the DDLIB-SERVER package version
  172 + */
  173 +
  174 + /*----------- Data Update functions -----------------------------------*/
  175 + int DD_AddDataSet(char *DataSetName, char *RemSetID, char *BaseName);
  176 + /*
  177 + * Request for new VI. See ../DOC/TECHDOC/DDServFunct.html
  178 + */
  179 +
  180 +private:
  181 +#ifdef LO4CXX
  182 + static log4cxx::LoggerPtr _logger;
  183 +#endif
  184 +};
  185 +/*--------------------- CONSTANTS -----------------------------------------*/
  186 +#define MOREDATA 1 /* There is data, but we have to call GetData again right now*/
  187 +#define MOREDELAY 2 /* There is data, but we have to call GetData again after delay */
  188 +#define OK 0 /* It is last data packet */
  189 +#define NOCONNECTION -1
  190 +#define TOOMANYREQ -2
  191 +#define REQSENDERR -3
  192 +#define REPLYRECERR -4
  193 +#define NOID -5
  194 +#define NOREFFILE -6
  195 +#define NOTIMESFILE -7
  196 +#define NOINFOFILE -8
  197 +#define NOVAR -9
  198 +#define OUTOFTIME -10
  199 +#define CACHERR -11 /* The error occured when program manipulated the cach */
  200 +#define CACHTOOREC -33 /* Off files in the CASH are created less then 5 sec ago */
  201 +#define WAITEXTCALL -34 /* Server Waits external call finish */
  202 +#define TRYAGAIN -35 /* Times file is locked. This request should be repeated again */
  203 +#define NODATAATTIME -36 /* Requested time is inside NODATA time interval */
  204 +#define GAPISSMALL -37 /* Gap is too small to call external archive */
  205 +#define CTIMEISSHIFTED -38 /* The request was in NoData interval, try again with time at the end */
  206 +#define DATAFILEERR -12 /* The error while manipulate with data file */
  207 +#define ENVIRERROR -13 /* Error in Environments */
  208 +#define NOPOINTER -14 /* The pointer points nowhere, SetTime were failed */
  209 +#define INTSERERR -15 /* Server internal error */
  210 +#define TIMEINEMPTY -16 /* No data for specified time interval */
  211 +#define NOEXEC -17 /* No executable */
  212 +
  213 +#define DD_SHORT 4
  214 +#define DD_INT 1
  215 +#define DD_FLOAT 2
  216 +#define DD_DOUBLE 3
  217 +#define DD_CHAR 0
  218 +
  219 +#endif /* DD_H_ */
... ...
src/DDClientLibCpp/INCLUDE/DD_Access.hh 0 → 100644
  1 +++ a/src/DDClientLibCpp/INCLUDE/DD_Access.hh
... ... @@ -0,0 +1,93 @@
  1 +/* ======================================================
  2 + *
  3 + * DD_Access.h
  4 + * V.2.0
  5 + * Last revision: Oct 7, 2002
  6 + * List of revisions: 1997 - version 1.0
  7 + * Oct 7, 2002 - version 2.0 (update a little )
  8 + */
  9 +
  10 +#define MAXHOSTLENGTH 16 /* IP-address: "255.255.255.255\0" */
  11 +#define USRLENGTH 21 /* Length of UserName: + \0 */
  12 +#define TICKETLENGTH 9 /* Length of passwd: 8 + \0 */
  13 +#define HOSTNAMELENGTH 120 /* Length of the user host name */
  14 +#define USERCASHLEN 100 /* Size of user_ticket.nc file must be 300 */
  15 +#define NONAME "no_name\0" /* Name of user in case of non-WEB connection */
  16 +#define ACCINSTR "iball:acc:all" /* Instrument which watch the access */
  17 +#define TICKET_PATH "/ACC/user_ticket.nc"
  18 +#define USERREFNAME "/ACC/user_info.nc"
  19 +#define LOGFILE "/ACC/login.log"
  20 +
  21 +/*------------ Errors of ACCESS ---------------------*/
  22 +#define NOPERMISSION -100
  23 +#define NOHOST -101
  24 +#define NOUSERSFILE -102
  25 +
  26 +/*--------------- Extern global variables -------------------*/
  27 +extern char UserName[USRLENGTH]; /* defined in DD_client.c */
  28 +extern char UserHost[MAXHOSTLENGTH]; /* defined in DD_client.c */
  29 +extern int UserID; /* defined in DD_client.c */
  30 +
  31 +/*--------------- Extern Functions ---------------------------*/
  32 +extern int FillStruct (int argc, void **argv);
  33 +/* This function used to set up the host address from IDL (when WWW access used)
  34 + * Arguments allocation is as follows:
  35 + * UserName - 0
  36 + * UserHost - 1
  37 + * Location: DD_idl.c -> DD_idl.so
  38 +*/
  39 +
  40 +extern int GetTicket(int UID, char *HostName, int DD_user_id);
  41 +/* Description: This function find the user data in user_cash.nc
  42 + * If O'k rewrite the line with new time.
  43 + * In case of a new user, remove the first line with
  44 + * older time data then a current time + 4.5 hours.
  45 + *
  46 + Takes 3 arguments: UserId (id in the romote host)
  47 + Remote host address(string,like "193.232.6.60\0")
  48 + DD_user_id(can see in user_info.nc)
  49 +
  50 + Returns 0 if O'k or NOPERMISSIONS, or ERROR
  51 +
  52 + If DD_log_name equal NULL searching for UserId, IP-address
  53 + If DD_log_name nonequal NULL searching for IP-address,DD_log_name*
  54 + *
  55 + */
  56 +extern int CheckTicket(char *NameUsr, char *Ticket);
  57 +/* Description: This function check if user exosts
  58 + * in user_info.nc file. Returns DD_id if O'k.
  59 + * It returns NOPERMISSION or other errors
  60 + */
  61 +
  62 +extern int ShowTicket(int userid, char *hostname, char *DD_name);
  63 +/*
  64 + * Show if user has authorisation to work
  65 + */
  66 +
  67 +extern int LoginRequest(char *UserPasswd, char *UserLogin, char *HostName);
  68 +/* Description: Library function for client-server using.
  69 + * Send ID, Password,UserLogin, and host to server.
  70 + * Compares the information with your {id,hostname and other}.
  71 + * Returns 0 if O'k, or a negative value in case
  72 + * of "NOPERMISSION" or error.
  73 + *
  74 + */
  75 +extern int SetUser(int UserID, char *HostName, char *LogName);
  76 +/* Description: Library function for client-server using.
  77 + * Send UserID, HostName to server.
  78 + * Compares the information with your {id,hostname}.
  79 + * Returns 1 if O'k, or a NOPERMISSION, or error number
  80 + */
  81 +
  82 +extern int CheckID(char *NameUsr);
  83 +/* Description: This function check the user name in user_info.nc file.
  84 + * Returns DD_id if exists.
  85 + * It returns NOPERMISSION or other errors
  86 + */
  87 +
  88 +extern void Put2Log(int UID, char *Host, char *LogName, int error);
  89 +/* Description: This function logs a user's ID, IP-address of a local host,
  90 + * login name and permission information into log file.
  91 + *
  92 + */
  93 +
... ...
src/DDClientLibCpp/INCLUDE/DD_comm.hh 0 → 100644
  1 +++ a/src/DDClientLibCpp/INCLUDE/DD_comm.hh
... ... @@ -0,0 +1,426 @@
  1 +/*=================================================================================
  2 + * DD SYSTEM base package
  3 + * DD_Server DD_Client library
  4 + * DD_comm.h
  5 + * V. 5.6
  6 + * Changes listing:
  7 + * Feb 27 1995 - V 1.0
  8 + * 13 Apr. 2002 - changed for NetCDF 3.3
  9 + * 03 Oct. 2002 - v.4.0 Fedorov, communication ideology is changed
  10 + * Oct 31, 2002 - V.4.1 Fedorov, UserName, UserHost and UserID transferred into DD_Access.h
  11 + * May 7, 2003 - V.4.2 Fedorov, The Cash structure is changed (flag of open file )
  12 + * June 17, 2003 - V.4.3 Fedorov, The Maximal Packet Size is changed
  13 + * Nov 18, 2004 - V.4.4 Fedorov, Some changes
  14 + * Aug 17, 2005 - V.4.5 Fedorov, Cach Time constant is changed
  15 + * Jun 17, 2007 - V.4.6 Fedorov, New requestes and external executables
  16 + * Aug 01, 2007 - V.4.7 Fedorov, Cache length = 20, New DD_Var_t structure
  17 + * Sep 20, 2007 - V.5.0 Fedorov, Update Time Info library now in the separate file
  18 + * Sep 23, 2007 - V.5.1 Fedorov, New interface of SetTime
  19 + * Sep 25, 2007 - V.5.2 Fedorov, Individual minimal gap
  20 + * Oct 08, 2007 - V.5.3 Budnik, php createVI.php <baseID> <remSetID> <ddSetID>
  21 + * Jan 25, 2008 - V.5.3.1 Budnik, min data gap = 1 day!!!!
  22 + * May 22, 2008 - V.5.4 Fedorov, DD_Var_t has a LockStartTime value
  23 + * May 27, 2008 - V.5.5 Fedorov, Maximal tracnsmition buffer
  24 + * Sep 19, 2008 - V.5.6 MAXVARLENGTH=64 REQUESTLENGTH 184
  25 + *===================================================================================*/
  26 +#ifndef DD_COMM_H_
  27 +#define DD_COMM_H_
  28 +#include <stdio.h>
  29 +#include <sys/errno.h>
  30 +#include <stdlib.h>
  31 +#include <string.h>
  32 +#include <sys/types.h>
  33 +#include <sys/time.h>
  34 +#include <time.h>
  35 +#include "DD.hh"
  36 +#include "DD_Access.hh"
  37 +
  38 +#ifdef SOLARIS
  39 +#include <sys/socket.h>
  40 +#include <netdb.h>
  41 +#include <netinet/in.h> /* internet stile addres */
  42 +#include <rpc/types.h>
  43 +#include <rpc/xdr.h>
  44 +#include <rpc/rpc.h>
  45 +#endif /* SOLARIS */
  46 +
  47 +#ifdef HPUX
  48 +#include <sys/socket.h>
  49 +#include <netinet/in.h>
  50 +#include <netdb.h>
  51 +#include <sys/un.h>
  52 +#include <rpc/xdr.h>
  53 +#include <rpc/rpc.h>
  54 +#endif
  55 +
  56 +#ifdef OSF1
  57 +#include <sys/socket.h>
  58 +#include <netdb.h>
  59 +#include <arpa/inet.h>
  60 +#include <rpc/xdr.h>
  61 +#endif /* OSF1 */
  62 +
  63 +#ifdef LINUX
  64 +#include <sys/socket.h>
  65 +#include <netinet/in.h>
  66 +#include <netdb.h>
  67 +#include <rpc/rpc.h>
  68 +#include <rpc/xdr.h>
  69 +#endif /* LINUX */
  70 +
  71 +
  72 +#ifdef SUNOS
  73 +#include <sys/socket.h>
  74 +#include <sys/socketvar.h>
  75 +#include <netinet/in.h>
  76 +#include <netdb.h>
  77 +#include <rpc/xdr.h>
  78 +#endif /* SUNOS */
  79 +
  80 +/*----------------- Defenitions of request and server replies --------------------*/
  81 +/* 1. Data manipulation requests */
  82 +#define OPENINSREQ 0 /* Open virtual instrument */
  83 +#define DATAINFOREQ 1 /* Request of constant info */
  84 +#define TIMESETREQ 2 /* Position of pointer by StartTime*/
  85 +#define DATAGETREQ 3 /* Data request by time interval */
  86 +#define CLOSEINSREQ 4 /* Request to close virtual instrument */
  87 +#define MOVPOINTREQ 5 /* Move the pointer od data request*/
  88 +#define ADDVIREQ 6 /* Add New virtual instrument */
  89 +
  90 +/* 2. Security requests */
  91 +#define GETTICKETREQ 10
  92 +#define SHOWTICKETREQ 11
  93 +
  94 +/*-------- Some constants ------------------*/
  95 +#define EMPTY 0 /* Filler of the trailer */
  96 +#define FILEACCMARG 1 /* The minimum time from the last access to remove this file */
  97 +
  98 +/*------------ Important lengths and pathes ----------------*/
  99 +#define PROTOCOL 0 /* protocol TCP */
  100 +#define REPLYLENGTH 12 /* Length of header of reply packet */
  101 +#define REQUESTLENGTH 196 /* Length of request packets MAXSETLENGTH + 2*MAXVARLENGTH + 4 */
  102 +#define MAXVARLENGTH 64 /* Length (with \0) of Variable Name */
  103 +#define MAXSETLENGTH 52 /* Max Length of VI name */
  104 +#define PATHLENGTH 128 /* Length of complete path */
  105 +#define MAXFILENAME 32 /* The maximal length of the data file (info, cach, times as well)*/
  106 +#define REFNAME "/refer.nc" /* path name for databse refer file */
  107 +#define CASHLEN 20 /* Length of cash array */
  108 +#define TRY 100 /* How many tymes to ask the socket */
  109 +#define MAXPACKSIZE 5000000 /* Maximal size of one packet of transmission in bytes */
  110 +#define MAXCOMMANDL 300 /* Command in system() maximal length */
  111 +/*-------------------------------------------------
  112 + * XDR length to calcolate the total len
  113 + *-------------------------------------------------*/
  114 +#define XDRINTLEN 4
  115 +#define XDRFLOATLEN 4
  116 +#define XDRDOUBLELEN 8
  117 +// String length is counted as 4B + N + r (to completed to 4 bytes)
  118 +
  119 +/*------------ List of External Call of DD_Server and ERRORS -------------------*/
  120 +#define ADDDATASETCALL "php %s/createVI.php %s %s %s" /* Format to call to create new VI */
  121 +#define GETNEWDATACALL "php %s/getData%s.php %s %s %s %s &" /* Format to call to get new data */
  122 +#define NOPHP 32512
  123 +#define NOSCRIPT 256
  124 +#define PHPOK 0
  125 +
  126 +/*------ Constant to understand data availabilities -------------------------------*/
  127 +#define GLOBSTARTNAME "GlobalStart"
  128 +#define GLOBSTOPNAME "GlobalStop"
  129 +#define SAMPLNAME "MinSampling"
  130 +#define REMARCHNAME "DataBaseID"
  131 +#define REMINSTNAME "DataSetID"
  132 +#define MINGAP 86400.0 /*Seconds. The minimal time gap to set up the flag DATAGAP */
  133 +#define REQTIMEINT 86400.0 /* One day, +/- of request time interval */
  134 +#define ISOTIMEF "%4u%*1c%2u%*1c%2u%*1c%2u%*1c%2u%*1c%2u%*1c%3u" /* Format to READ time in ISO format */
  135 +#define ISOTIMEP "%04u-%02u-%02uT%02u:%02u:%02u.%03uZ" /* Format to PRINT time in ISO format */
  136 +#define NODATASTR "NODATA"
  137 +#define DIRLOCK "LOCK"
  138 +
  139 +/*------------- More internal specifications -----------------------*/
  140 +/*
  141 + * See ../DOC/TECHDOC/DDGenProt.html (lyx)
  142 + */
  143 +
  144 +/* Reply variables:
  145 + * Error - negative value described in DD.h
  146 + * Type - int (see DD.h)
  147 + * Dim_Number - int ( the dimension (vector, matrix, cube, etc) ov the variable)
  148 + * Data_Size - int (the size of the data packet in bytes)
  149 + * RemID - int (number of virtual instruments still open in this session)
  150 + * Dim - int (the particular dimension )
  151 + * LastPacketFlag - int ( == OK in this packet is last, or MOREDATA)
  152 + * Data - array of Type of Dim X Dim X....X Dim size
  153 + * --------------------
  154 + * Dim_Number
  155 + * DataPacket:
  156 + *
  157 + * <LastPacketFlag> |
  158 + * <Dim> | |
  159 + * <.....> | Dim_Number | Data_Size bytes
  160 + * <Dim> | |
  161 + * <data> |
  162 + * ..... | only for real data |
  163 + * <data> | |
  164 + *
  165 + * Note is the value is scalar - the Dim = 0 (???)
  166 + */
  167 +
  168 +/* REPLY SPECIFICATION
  169 + *
  170 + * Reply consists Header 12 bytes length and Data Block
  171 + *
  172 + * on Open Virtual instrument:
  173 + * <OPENINSREQ><ID/Eroor><EMPTY><EMPTY>
  174 + * on Constant Info request:
  175 + * <DATAINFOREQ><Type/Error><Dim_Number><Data_Size><DataPacket>
  176 + * on Set pointer by StartTime:
  177 + * <SETTIMEREQ><EMPTY/Error><EMPTY><EMPTY>
  178 + * on Get Data by TimeInt :
  179 + * <DATAGETREQ><Type/Error><Dim_Numbers><Data_Size><LastRecordFlag><DataPacket>
  180 + * on Move pointer with records number
  181 + * <MOVPOINTREQ><EMPTY/Error><EMPTY><EMPTY>
  182 + * on Close Virtual Instrument
  183 + * <CLOSEINSREQ><RemID/Error><EMPTY><EMPTY>
  184 + */
  185 +
  186 +/*-------------------- TYPEDEF ---------------------------*/
  187 +
  188 + struct DD_data_t {
  189 + int type; /* Type of variable in netcdf style */
  190 + int DimNumber; /* number of dimensions */
  191 + int *Dimensions; /* Dimensions array
  192 + * fastest change is last */
  193 + int VarNumber; /* Dimension of variable array */
  194 + void **Variables;/* Variables array pointer
  195 + * It is static array refreshed
  196 + * each call
  197 + */
  198 + DD_data_t(int pType, int pDimNumber, int *pDimensions, int pVarNumber, void **pVariables):
  199 + type(pType),
  200 + DimNumber(pDimNumber),
  201 + Dimensions(pDimensions),
  202 + VarNumber(pVarNumber),
  203 + Variables(pVariables) {}
  204 +
  205 + DD_data_t(DD_data_t& pData):
  206 + type(pData.type),
  207 + DimNumber(pData.DimNumber),
  208 + Dimensions(pData.Dimensions),
  209 + VarNumber(pData.VarNumber),
  210 + Variables(pData.Variables) {}
  211 +
  212 + DD_data_t() :
  213 + type(0),
  214 + DimNumber(0),
  215 + Dimensions(NULL),
  216 + VarNumber(0),
  217 + Variables(NULL) {}
  218 +
  219 + void clear() {
  220 + if(Dimensions != NULL)
  221 + {
  222 + free(Dimensions);
  223 + Dimensions = NULL;
  224 + }
  225 + if(Variables != NULL)
  226 + {
  227 + for(int i = 0; i< VarNumber; i++)
  228 + free(Variables[i]);
  229 + free(Variables);
  230 + Variables = NULL;
  231 + VarNumber = 0;
  232 + }
  233 +
  234 + }
  235 + ~DD_data_t() {
  236 + clear();
  237 + }
  238 + } ;
  239 +
  240 +typedef struct { char names[CASHLEN][MAXSETLENGTH];
  241 + long times[CASHLEN];
  242 + int FileOpen[CASHLEN]; /* 1 if file is open */
  243 + int ID; /* ID of open cach file */
  244 + int nameID; /* ID of names array */
  245 + int timeID; /* ID of times array */
  246 + int fopenID; /* ID of fopen flag */
  247 + } DD_cash_t; /* The structure holding cash informaton
  248 + * of particular virtual instrument DataBase
  249 + */
  250 +
  251 +/*
  252 + * This structure corresponds to ONE requested variable
  253 + * of some Virtual instrument
  254 + */
  255 +typedef struct { char InstrName[MAXSETLENGTH]; /* Virtual Instrument Name */
  256 + char path[PATHLENGTH]; /* Path to directory of open virtual instrument */
  257 + /*------- Cache part --------------------------------*/
  258 + DD_cash_t Cash; /* Cash holder */
  259 + int CurrCushN; /* Current cash pointer */
  260 + /*--- This is the part of open data file ------------*/
  261 + int ncID; /* ID of open nc_file */
  262 + size_t nc_rec; /* the current record number nc_file */
  263 + size_t Maxnc_rec; /* Maximum of records number in in the current nc file */
  264 + DD_data_t *VarData; /* Dimensions of Variable */
  265 + /*--- This is part of times file of given VI --------------*/
  266 + char TimesFileName[PATHLENGTH];
  267 + double SDTime; /* Requested Start Time in double form */
  268 + double FDTime; /* Requested Stop Time in double form */
  269 + double CDTime; /* Current Time in double form */
  270 + int tmID; /* ID of "times" file of this virtual instrument*/
  271 + int NameID; /* ID of FileName variable in times file */
  272 + int StartID; /* ID of Start variable in times file */
  273 + int StopID; /* ID of Stop variable in times file */
  274 + size_t TimeRecNumber; /* Current Record number in the "times" file */
  275 + size_t MaxTimeRecNum; /* Maximum records number in the "times" file */
  276 + int RValidMin; /* Minimal record with valid data */
  277 + int RValidMax; /* Maximal record with valid data */
  278 + double MinValidTime;
  279 + double MaxValidTime; /* Start of RValidMin, and stop of RValidMax */
  280 + int CurrRmin; /* Sure that looking time is greater than stop; -1 if NOT */
  281 + int CurrRmax; /* Sure that looking time is less than start; -1 if NOT */
  282 + /*------- Working with external Data Base ------------------------------*/
  283 + int VILocked; /* Flag to show that request to remote database has been sent */
  284 + time_t LockStartTime; /* Value to calculate a time elapsed from lock made by THIS VI */
  285 + /*---------- This is the part of Info file of given VI -----------------*/
  286 + int attrID; /* ID of constant information nc_file */
  287 + char AttrName[PATHLENGTH]; /* Name of constant information file */
  288 + DD_data_t AttrData; /* Dimensions of Attributes */
  289 + /*---- Part concerning External call ------------------*/
  290 + double MinGap; /* The minimal gap between two files */
  291 + double GlobalStart; /* The principal begin of data */
  292 + double GlobalStop; /* The principal end of data */
  293 + char BaseName[MAXSETLENGTH]; /* The name of external data archive */
  294 + char RemSetID[MAXSETLENGTH]; /* The name of VI in exterval archiving */
  295 + int ExtCallAllowed; /* 1 If Server can call external archiving */
  296 + /*------------ Flow Control -----------------------------*/
  297 + int LastPacketFlag; /* OK - request is completed,
  298 + * MOREDATA - one or several blocks expected,
  299 + * MOREDELAY - wait, system is blocked */
  300 + int LastFileStatus; /* The file status after the last SetNewFile */
  301 + int NewFile; /* 1 if File was changed, VI has to be refreshed*/
  302 + int NewFileWasOpen; /* 1 if the original position of pointer
  303 + * (in data file, times file) was lost after open
  304 + * a new data file */
  305 + } DD_Var_t;
  306 +
  307 +/*---------------- Usefull enumerations ---------------------*/
  308 +enum SearchRet {REACHLEFT, REACHRIGHT, OKLEFT, OKRIGHT};
  309 + /*
  310 + * enumerate of the status of time inteval searching
  311 + * NOONEDATA - no data at al in this VI
  312 + * INSIDE - CTime is inside valid data interval (tolerance is MINGAP)
  313 + * DATAATRIGHT, DATAATLEFT - Valid interval is on the right/left from CTime
  314 + */
  315 +enum SearchIntRet {NOONEDATA, INSIDE, DATAATRIGHT, DATAATLEFT, IDLE};
  316 +
  317 +/* Return function IsTimesLocked */
  318 +enum LockStatus {NOLOCK, LOCKED, LOCKREMOVED};
  319 +
  320 +
  321 +/*------------------ Function for Server ---------------------*/
  322 +extern int OpenInstr(char *InstrName);
  323 +/*
  324 + * Open Virtual instrument by name and returns the ID
  325 + * Returns negative value in case of error (see DD.h)or OK
  326 + */
  327 +extern int GetAttribute(int ID, char *Name);
  328 +/*
  329 + * Variable - address of structure with variable description
  330 + * Name - name of attribute
  331 + * Returns OK or an error (see DD.h)
  332 + */
  333 +extern int GetData(int ID, char *Name, char *TimeInterval);
  334 +/* Name - string name of requested variable,
  335 + * TimeInterval - Time in DD_time.h style
  336 + * Returns negative value in case of error (see bellow)
  337 + * Returnes MOREDATA if "there is more data", and OK if data is finished.
  338 + */
  339 +
  340 +extern int SetTime(DD_Var_t *D, double CTime);
  341 +/*#################################################################
  342 + * SET TIME
  343 + * Set time and try to open appropriate data file. If not try to
  344 + * call external archive
  345 + * D - address of VI holder
  346 + * Time - Time in DD_time.h style
  347 + * Return:
  348 + * OK
  349 + * NOID - call with uncorrect VI holder
  350 + * OUTOFTIME - Requested time is out of General time limitation
  351 + * WAITEXTCALL - Server sent request to external archive
  352 + * TRYAGAIN - VI is blocked by call to external database
  353 + * NODATAATTIME - request time is inside NODATA time interval
  354 + * some return of SetNewFile(); see ...
  355 + *#################################################################*/
  356 +
  357 +extern int CloseID(int ID);
  358 +/* ID - integer identificator of opened Data Set
  359 + * Returns number of remained IDs of this communication seasson
  360 + * in case of 0 the server closes this comminication session
  361 + */
  362 +
  363 +int SetNewFile(DD_Var_t *D, int N);
  364 +/*
  365 + * Function tries to get new data for the gap beetween files, or just
  366 + * open a new data file according to offset N referring to current position in the times file.
  367 + * The current position changed if file is succesefully open.
  368 + * Return values:
  369 + * OK
  370 + * OUTOFTIME - next interval exceeeds GlobalStart/Stop
  371 + * TIMEINEMPTY - next interval marked as "NODATA"
  372 + * TRYAGAIN - the VI is blocked while new data is arriving
  373 + * WAITEXTCALL - new data is requested
  374 + * CACHTOOREC - now free space in the CACH
  375 + * CHACHERR - unrecovable error in CACH
  376 + * DATAFILEERR - unrecovable error in data file
  377 + */
  378 +
  379 +size_t MaxRecord(int ncID);
  380 +/*
  381 + * Inspect all variables and dimensions of the file (exept Time associated) and
  382 + * returm maximal record number to transmit
  383 + */
  384 +/*------------------ Global constants ----------------------------------*/
  385 +
  386 +/*------------------ Global data variable for entire session --------------------*/
  387 +extern DD_Var_t **DD_Var ; /* Actually this variable is implimented
  388 + * in DD_GetData.c . The dimension of this array is defined
  389 + * by sysconf(_SC_OPEN_MAX)*/
  390 +extern size_t MaxIDNumber; /* Size of DD_Var array. Defined actually in DD_GetData.c */
  391 +
  392 +/*
  393 + * Fuctions prototypes in ExtDataRequest.c file
  394 + */
  395 +/*======================================================================
  396 + * IsTimesLocked
  397 + * Return 1 if there is LOCK in the VI directory
  398 + *======================================================================*/
  399 +extern int IsTimesLocked(DD_Var_t *DD_Var);
  400 +
  401 +/*======================================================================
  402 + * ExtDataRequest
  403 + * Return folowing values:
  404 + * OK - request is accepted SERVER has to wait when LOCK file is gone
  405 + * NOEXEC - error in external executable
  406 + * NODATAATTIME - time corresponds to the NODATA interval
  407 + * GAPISSMALL - Time is inside too small gap
  408 + *======================================================================*/
  409 +extern int ExtDataRequest(DD_Var_t *DD_Var, double CurrTime);
  410 +
  411 +/*=======================================================================
  412 + * UpdateTimeInfo.c
  413 + * int SearchLeft(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax)
  414 + * int SearchRight(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax)
  415 + * Search the next to the left(right) non-empty time interval
  416 + * DD_VarL - common data structure corresponding to THIS open VI
  417 + * Rmin, Rmax - start points
  418 + *
  419 + * int UpdateTimeInfo(DD_Var_t *DD_VarL)
  420 + * Function reopen "times" file and update all time constants
  421 + *======================================================================*/
  422 +extern int SearchLeft(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax);
  423 +extern int SearchRight(DD_Var_t *DD_VarL, size_t Rmin, size_t Rmax);
  424 +extern int UpdateTimeInfo(DD_Var_t *DD_VarL);
  425 +
  426 +#endif /* DD_COMM_H_ */
... ...
src/DDClientLibCpp/INCLUDE/DD_time.hh 0 → 100644
  1 +++ a/src/DDClientLibCpp/INCLUDE/DD_time.hh
... ... @@ -0,0 +1,63 @@
  1 +/* This is header file for working with DD time */
  2 +/* V.4.1 */
  3 +/* name: DD_time.h
  4 + * Author: Andrey Fredorov
  5 + * Institution: IKI RAN
  6 + * Date: 21-Feb-1995
  7 + * Last update Sept 05, 2011
  8 + * Sept 05, 2011: V.3.2 SetIntNew => arg TimeKind => to work with 1970-1973 : BR
  9 + */
  10 +#ifndef DD_TIME_H_
  11 +#define DD_TIME_H_
  12 +
  13 +#define TIMELENGTH 17
  14 +
  15 +typedef char dd_time_t[TIMELENGTH]; /* YYYYDDDHHMMSSMLS */
  16 +
  17 +/* ---------------- Functions prototypes ----------------------*/
  18 +extern double DD_Time2Double(const dd_time_t DD_Time);
  19 +/* Convert string to double and return.
  20 + * Return negative value in case of error string format
  21 + */
  22 +extern void Double2DD_Time(char *, double Time);
  23 +/* Convert double Time value into string form and return pointer to static string
  24 + * allocated INSIDE the library. Thus the value is renoveted each function call.
  25 + */
  26 +
  27 +/*---------------- Backup compability with V.3.0 and earlier ----------*/
  28 +typedef struct { double times; /* time sec from 1970 */
  29 + int year;
  30 + int day;
  31 + int hour;
  32 + int min;
  33 + int sec;
  34 + int msec;
  35 + } dd_tmstr_t ;
  36 +
  37 +
  38 +extern void ReadTime(dd_tmstr_t &UT,char *UTstring); /* Read time from sring and fill static
  39 + * structure defined IN function.
  40 + * Returns pointer of strusture */
  41 +extern char *WriteTime(dd_tmstr_t *UT); /* Get pointer of time structure
  42 + * and convert it into string
  43 + * Function returns pointer of
  44 + * internal string */
  45 +
  46 +extern void WriteFmtTime(dd_tmstr_t *UT,char *UTstring);
  47 +
  48 +extern void SetDouble(dd_tmstr_t *UT); /* Fill double value of dd_tmstr_t */
  49 +
  50 +typedef enum {DD_TM_UNKNOWN, DD_TM_TIME_INTERVAL, DD_TM_DATE} t_DDTimeKind;
  51 +
  52 +extern void SetInt(dd_tmstr_t *UT); /* Fill int values of dd_tmstr_t */
  53 +extern void SetIntNew(dd_tmstr_t *UT,t_DDTimeKind timeKind);
  54 +
  55 +/*------- Functions for DECODERS ------------------------
  56 + *These functions works with with Gavrilova's UT representation */
  57 +extern dd_tmstr_t *UT2double(unsigned *UT); /* Set standard time
  58 + * structure and return
  59 + * its pointer
  60 + */
  61 +extern unsigned *Double2UT(double Time); /*Converts Double to Gavrilova array */
  62 +
  63 +#endif /* DD_TIME_H_ */
... ...
src/TOOLS/COMMON/DD_Access_cl.c 0 → 100755
  1 +++ a/src/TOOLS/COMMON/DD_Access_cl.c
... ... @@ -0,0 +1,187 @@
  1 +/*
  2 + *-------------------- DD_ACCESS -------------------------------
  3 + *
  4 + * name: DD_Access.c
  5 + * Version: 4.0
  6 + * author: Alexander Grigoriev, Andrei fedorov
  7 + * date : Oct 13, 2002
  8 + * Description: Set of CLIENT function for access to DD system
  9 + *
  10 + * List of revisions:
  11 + * March 1999 V1.0
  12 + * 20 Oct 1999 ; ShowTicket was corrected. V2.0
  13 + * 28 Oct 1999 ; Added LOGINS,ddcheck V3.0
  14 + * Oct 13, 2002 - revised by A. Fedorov V4.0
  15 + * see technical doc
  16 + */
  17 +#include <limits.h>
  18 +#include <unistd.h>
  19 +#include <time.h>
  20 +#include <DD.h>
  21 +#include <DD_comm.h>
  22 +#include <DD_Access.h>
  23 +
  24 +/*=========== Global Variables ===============================*/
  25 +extern int SocketID; /* The socket is defined in DD_client.c */
  26 +/*================= FUNCTIONS ================================*/
  27 +
  28 +/*------------------------ LoginRequest -------------------------------*/
  29 +LoginRequest(char *UserPasswd, char *DDUserName, char *Host)
  30 +{
  31 + static caddr_t buf = NULL;
  32 + static XDR xdrs;
  33 + int cc,i, hostlen, ticketlen, userlen;
  34 + int op = GETTICKETREQ;
  35 + int ServerReply = NOPERMISSION;
  36 +
  37 +/*------------------CONNECTNION to SERVER---------------------------*/
  38 +
  39 + /* If there is no connection, try to get it */
  40 + if(SocketID < 0)
  41 + if((SocketID = GetSocket()) < 0) return(NOCONNECTION);
  42 +
  43 +/*---------------------REQUEST TO SERVER-----------------------------*/
  44 +
  45 + if(Host != NULL) /* It is WEB client (not local) */
  46 + {
  47 + if(strlen(Host) > MAXHOSTLENGTH-2) Host[MAXHOSTLENGTH-1] = '\0';
  48 + }
  49 + else Host = UserHost; /* Local client */
  50 + hostlen = strlen(Host);
  51 + ticketlen = strlen(UserPasswd);
  52 + userlen = strlen(DDUserName);
  53 +
  54 +/* Allocation memory and stream */
  55 + buf = (caddr_t)malloc(REQUESTLENGTH);
  56 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  57 +
  58 +/* Encoding the request */
  59 + xdr_int(&xdrs,&op);
  60 +
  61 +/* Send request */
  62 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  63 + {
  64 + perror("DD_GetTicket:");
  65 + free(buf);
  66 + xdr_destroy(&xdrs);
  67 + return(REQSENDERR);
  68 + }
  69 +
  70 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_FREE);
  71 + buf = (caddr_t)realloc(buf,REQUESTLENGTH);
  72 +
  73 + xdrmem_create(&xdrs, buf,REQUESTLENGTH , XDR_ENCODE);
  74 + xdr_int(&xdrs,&UserID); /* user's ID on the local host */
  75 + xdr_string(&xdrs, &DDUserName, userlen); /* DD_login name */
  76 + xdr_string(&xdrs, &UserPasswd, ticketlen); /* user's DD-password */
  77 + xdr_string(&xdrs, &Host, hostlen); /* IP-address of the local host */
  78 +
  79 +/* Send request */
  80 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  81 + {
  82 + perror("DD_GetTicket:");
  83 + free(buf);
  84 + xdr_destroy(&xdrs);
  85 + return(REQSENDERR);
  86 + }
  87 + free(buf);
  88 + xdr_destroy(&xdrs);
  89 +
  90 +/* Get reply header */
  91 +
  92 + buf = (caddr_t)malloc(REPLYLENGTH);
  93 + i =0;
  94 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  95 + if(cc < 0)
  96 + {
  97 + perror("DD_GetTicket:");
  98 + free(buf);
  99 + return(REPLYRECERR);
  100 + }
  101 +
  102 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  103 + xdr_int(&xdrs,&ServerReply);
  104 +
  105 + free(buf);
  106 + xdr_destroy(&xdrs);
  107 +
  108 + shutdown(SocketID,2);
  109 + close(SocketID);
  110 + SocketID = -1;
  111 + return ServerReply;
  112 +}
  113 +
  114 +/*
  115 + *------------------------ SETUSER -------------------------------*/
  116 +/*
  117 + * Description: Library function for client-server using.
  118 + * Send UserID, HostName to server.
  119 + * Compares the information with your {id,hostname}.
  120 + * Returns 1 if O'k, or a NOPERMISSION, or error number
  121 + */
  122 +int SetUser(int UserIDLocal, char *Host, char *DDUserName)
  123 +{
  124 +
  125 + static caddr_t buf = NULL;
  126 + static XDR xdrs;
  127 + int cc,i, hostlen, ticketlen, userlen;
  128 + int op = SHOWTICKETREQ;
  129 + int ServerReply = NOPERMISSION;
  130 +
  131 +/*------------------CONNECTION to SERVER---------------------------*/
  132 + if(SocketID < 0)
  133 + if((SocketID = GetSocket()) < 0) return(NOCONNECTION);
  134 +
  135 +/*---------------------REQUEST TO SERVER-----------------------------*/
  136 +
  137 +/* Check the HostName length */
  138 + if(strlen(Host) > MAXHOSTLENGTH) hostlen = MAXHOSTLENGTH;
  139 + else hostlen = strlen(Host);
  140 + if(strlen(DDUserName) > USRLENGTH) userlen = USRLENGTH;
  141 + else userlen = strlen(DDUserName);
  142 +
  143 +/* Allocation memory and stream */
  144 + buf = (caddr_t)malloc(REQUESTLENGTH);
  145 + xdrmem_create(&xdrs, buf, REQUESTLENGTH, XDR_ENCODE);
  146 +
  147 +/* Encoding the request */
  148 + xdr_int(&xdrs,&op);
  149 + xdr_int(&xdrs,&UserID);
  150 + xdr_string(&xdrs, &Host, hostlen);
  151 + xdr_string(&xdrs, &DDUserName, userlen);
  152 +/* printf("UserID, HostName just more : %d %s\n",UserID,HostName);*/
  153 +/* Send request */
  154 + if((cc = send(SocketID,buf,REQUESTLENGTH,0)) < 0)
  155 + {
  156 + perror("DD_GetTicket:");
  157 + free(buf);
  158 + xdr_destroy(&xdrs);
  159 + return(REQSENDERR);
  160 + }
  161 + free(buf);
  162 + xdr_destroy(&xdrs);
  163 +
  164 +/* Get reply header */
  165 +
  166 + buf = (caddr_t)malloc(REPLYLENGTH);
  167 + i =0;
  168 + while(((cc = recv(SocketID,buf,REPLYLENGTH,0)) < 0) && (i < TRY)) i++;
  169 + if(cc < 0)
  170 + {
  171 + perror("DD_SetUser:");
  172 + free(buf);
  173 + return(REPLYRECERR);
  174 + }
  175 +
  176 + xdrmem_create(&xdrs, buf, REPLYLENGTH, XDR_DECODE);
  177 + xdr_int(&xdrs,&ServerReply);
  178 +
  179 + free(buf);
  180 + xdr_destroy(&xdrs);
  181 + shutdown(SocketID,2);
  182 + close(SocketID);
  183 + return(ServerReply);
  184 +
  185 +
  186 +}
  187 +/*############################################################################*/
... ...
src/TOOLS/DDCheckUser/CMakeLists.txt 0 → 100644
  1 +++ a/src/TOOLS/DDCheckUser/CMakeLists.txt
... ... @@ -0,0 +1,23 @@
  1 +
  2 +PROJECT(DDCheckUser)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Configuration de l'exécutable
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 + ../COMMON/DD_Access_cl.c
  14 +)
  15 +
  16 +ADD_EXECUTABLE (DDCheckUser ${source_files} )
  17 +
  18 +target_link_libraries(
  19 + DDCheckUser
  20 + DDClientLibC
  21 +)
  22 +
  23 +install (TARGETS DDCheckUser DESTINATION bin)
... ...
src/TOOLS/DDCheckUser/DD_Check.c 0 → 100755
  1 +++ a/src/TOOLS/DDCheckUser/DD_Check.c
... ... @@ -0,0 +1,41 @@
  1 +/*=============================================================
  2 + *-------------------- DD_CHECK -------------------------------
  3 + * V2.0
  4 + * name: DD_check.c
  5 + * author: Alexandr Grigoriev, Andrei Fedorov
  6 + * date : Oct 30 2002
  7 + *
  8 + * Description: Check for the current permission to work
  9 + * Uses with WEB interface
  10 + */
  11 +
  12 +#include <stdio.h>
  13 +#include <stdlib.h>
  14 +#include <string.h>
  15 +#include <DD_Access.h>
  16 +
  17 +main (int argc, char *argv[])
  18 +/*
  19 + * LocalID - the Unix ID if user, invoking this program
  20 + * LogName - the DD login name for specific user
  21 + * HostName - current local host (in 255.255.255.255 form)
  22 + */
  23 +{
  24 + int length;
  25 + char LogName[USRLENGTH],HostName[MAXHOSTLENGTH];
  26 + int LocalID;
  27 +
  28 + LocalID=getuid();
  29 +
  30 + if((argc == 3))
  31 + {
  32 + if((length = strlen(argv[2])) >= USRLENGTH) length = USRLENGTH-1;
  33 + strncpy(LogName,argv[2],length); LogName[length] = '\0';
  34 + if((length = strlen(argv[1])) >= MAXHOSTLENGTH) length = MAXHOSTLENGTH-1;
  35 + strncpy(HostName,argv[1],length); HostName[length] = '\0';
  36 + }
  37 + else return 2;
  38 +
  39 + return SetUser(LocalID,HostName,LogName);
  40 +
  41 +}
... ...
src/TOOLS/DDHtmlLogin/CMakeLists.txt 0 → 100644
  1 +++ a/src/TOOLS/DDHtmlLogin/CMakeLists.txt
... ... @@ -0,0 +1,23 @@
  1 +
  2 +PROJECT(DDHtmlLogin)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Configuration de l'exécutable
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 + ../COMMON/DD_Access_cl.c
  14 +)
  15 +
  16 +ADD_EXECUTABLE (DDHtmlLogin ${source_files} )
  17 +
  18 +target_link_libraries(
  19 + DDHtmlLogin
  20 + DDClientLibC
  21 +)
  22 +
  23 +install (TARGETS DDHtmlLogin DESTINATION bin)
... ...
src/TOOLS/DDHtmlLogin/DD_htmllogin.c 0 → 100755
  1 +++ a/src/TOOLS/DDHtmlLogin/DD_htmllogin.c
... ... @@ -0,0 +1,53 @@
  1 +/*=============================================================
  2 + * DD HTML LOGIN
  3 + *
  4 + * name: DD_htmllogin.c
  5 + * author: Alexandr Grigoriev, Andrei fedorov
  6 + * date : Oct 30, 2002
  7 + * sinopsis:
  8 + *
  9 + * usage: DD_htmllogin UserLogin UserPasswd HostName
  10 + * UserPasswd - password no longer than TICKETLENGTH - 1
  11 + * UserLogin - login name for DD System
  12 + * HostName - local host name (in 255.255.255.255 form)
  13 + *
  14 + * Description: Login to DD system and taking a ticket.
  15 + *
  16 + */
  17 +
  18 +#include <stdio.h>
  19 +#include <stdlib.h>
  20 +#include <limits.h>
  21 +#include <DD_Access.h>
  22 +#include <DD.h>
  23 +#include <DD_comm.h>
  24 +
  25 +/*=========== Global Variables ===============================*/
  26 +
  27 +
  28 +main (int argc, char *argv[])
  29 +{
  30 + int length;
  31 + char HostName[MAXHOSTLENGTH];
  32 + char UserLogin[USRLENGTH];
  33 + char UserPasswd[TICKETLENGTH];/* password of user, logged in*/
  34 + int DD_access = NOPERMISSION;
  35 +
  36 + if(argc > 3)
  37 + {
  38 +
  39 + if((length = strlen(argv[1])) >= USRLENGTH) length = USRLENGTH-1;
  40 + strncpy(UserLogin,argv[1],length); UserLogin[length] = '\0';
  41 + if((length = strlen(argv[2])) >= TICKETLENGTH) length = TICKETLENGTH -1;
  42 + strncpy(UserPasswd,argv[2],length); UserPasswd[length] = '\0';
  43 + if((length = strlen(argv[3])) >= MAXHOSTLENGTH) length = MAXHOSTLENGTH-1;
  44 + strncpy(HostName,argv[3],length); HostName[length] = '\0';
  45 + }
  46 + else
  47 + {
  48 + exit(2);
  49 + }
  50 +
  51 + return LoginRequest(UserPasswd, UserLogin, HostName);
  52 +
  53 +}
... ...
src/TOOLS/DDLogin/CMakeLists.txt 0 → 100644
  1 +++ a/src/TOOLS/DDLogin/CMakeLists.txt
... ... @@ -0,0 +1,23 @@
  1 +
  2 +PROJECT(DDLogin)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Configuration de l'exécutable
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 + ../COMMON/DD_Access_cl.c
  14 +)
  15 +
  16 +ADD_EXECUTABLE (DDLogin ${source_files} )
  17 +
  18 +target_link_libraries(
  19 + DDLogin
  20 + DDClientLibC
  21 +)
  22 +
  23 +install (TARGETS DDLogin DESTINATION bin)
... ...
src/TOOLS/DDLogin/DD_login.c 0 → 100755
  1 +++ a/src/TOOLS/DDLogin/DD_login.c
... ... @@ -0,0 +1,60 @@
  1 +/*
  2 + *-------------------- DD_LOGIN -------------------------------
  3 + *
  4 + * name: DD_login.c
  5 + * version: 2.0
  6 + * author: Alexandr Grigoriev, Andrei Fedorov
  7 + * date : March 1999
  8 + * Description: Login to DD_System for 4 hours.
  9 + *
  10 + * List of revisions:
  11 + * March 1999 - Version V.1.0
  12 + * Oct 13, 2002 - V.2.0 by Fedorov
  13 + */
  14 +
  15 +#include <stdio.h>
  16 +#include <stdlib.h>
  17 +#include <string.h>
  18 +#ifdef LINUX
  19 +#include <pwd.h>
  20 +#include <unistd.h>
  21 +#endif
  22 +#include <DD_Access.h>
  23 +#include <DD_time.h>
  24 +
  25 +/*=========== Global Variables ===============================*/
  26 +
  27 +/*================= Main =====================================*/
  28 +int main (int argc, char *argv[])
  29 +{
  30 + char *Host = NULL;
  31 + char DDUserName[USRLENGTH]; /* Login name in DD system */
  32 + char UserPasswd[TICKETLENGTH]; /* Password for DD System */
  33 +
  34 + int DD_Access = 0;
  35 + if(argc != 3) {printf("User and passwd must be gived in argmentl\n"); return (0);}
  36 +
  37 +
  38 +/*---------------Login------NewUser-------------------------*/
  39 +
  40 + strncpy(DDUserName, argv[1], USRLENGTH - 1);
  41 + DDUserName[USRLENGTH-1] = '\0';
  42 + if(strlen(DDUserName) < 2) {printf("User login should be longer than 3 chars\n"); return (0);}
  43 +
  44 +/*--------------Password-------UserInfo---------------------*/
  45 + strncpy(UserPasswd, argv[2], TICKETLENGTH - 1);
  46 + UserPasswd[TICKETLENGTH-1] = '\0';
  47 + DD_Access = LoginRequest(UserPasswd, DDUserName, Host);
  48 +
  49 + if(DD_Access == 0)
  50 + {
  51 + printf("You can work 4.5 hours in this session.\n");
  52 + }
  53 + else {
  54 + printf("Permission denied.\n");
  55 + return 0;
  56 + }
  57 +
  58 + return (1);
  59 +
  60 +}
... ...
src/TOOLS/DDSimpleTestGetData/CMakeLists.txt 0 → 100644
  1 +++ a/src/TOOLS/DDSimpleTestGetData/CMakeLists.txt
... ... @@ -0,0 +1,22 @@
  1 +
  2 +PROJECT(DDSimpleTestGetData)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Configuration de l'exécutable
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 +)
  14 +
  15 +ADD_EXECUTABLE (DDSimpleTestGetData ${source_files} )
  16 +
  17 +target_link_libraries(
  18 + DDSimpleTestGetData
  19 + DDClientLibC
  20 +)
  21 +
  22 +install (TARGETS DDSimpleTestGetData DESTINATION bin)
... ...
src/TOOLS/DDSimpleTestGetData/SimpleTest.c 0 → 100644
  1 +++ a/src/TOOLS/DDSimpleTestGetData/SimpleTest.c
... ... @@ -0,0 +1,116 @@
  1 +/*=============================================================
  2 + * SimpleTest.c
  3 + * Simple test of some critical server behaviour
  4 + * 11 Apr 2009, V.1.0, Fedorov
  5 + *=============================================================*/
  6 +#include <stdio.h>
  7 +#include <stdlib.h>
  8 +#include <unistd.h>
  9 +#include <time.h>
  10 +#include <sys/time.h>
  11 +
  12 +#include <DD.h>
  13 +
  14 +/*-------------------------*/
  15 +#define VI "ace:imf:all\0"
  16 +#define PAR "IMF\0"
  17 +#define ATTR "MinSampling\0"
  18 +#define START "2008000000000000\0"
  19 +#define TI "0000010000000000\0"
  20 +/*-------------------------*/
  21 +
  22 +int main()
  23 +{
  24 + char ViName[100] = VI;
  25 + char StartTime[17] = START;
  26 + char TimeInt[17] = TI;
  27 + char ParName[100] = PAR;
  28 + char AttrName[100] = ATTR;
  29 + double RealTime;
  30 + DD_data_t *data;
  31 +
  32 + int ID, error;
  33 + struct timeval start, end;
  34 + long secs, usecs;
  35 +
  36 + gettimeofday(&start,NULL);
  37 + ID = DD_SetVariable(ViName);
  38 + printf("ID = %d\n",ID);
  39 + if(ID < 0)
  40 + {
  41 + error = DD_Close(99);
  42 + exit(0);
  43 + }
  44 +
  45 +/*
  46 + * Get Sampling Time info (secs)
  47 + * attribute names : MinSampling (constant sampling)
  48 + * attribute names : MinSampling & MaxSampling (variable sampling)
  49 + */
  50 +
  51 + error = DD_GetInform(ID, AttrName, &data);
  52 + if(error < 0)
  53 + {
  54 + error = DD_Close(ID);
  55 + exit(0);
  56 + }
  57 + printf(" sampling %lf\n", *(double *)data->Variables[0]);
  58 +
  59 +/*
  60 + * RealTime - double time pointer points to after SetTime
  61 + */
  62 + error = DD_SetTimeInfo(ID, StartTime, &RealTime);
  63 + printf("DD_SetTimeInfo returns = %d\n",error);
  64 + if(error < 0)
  65 + {
  66 + error = DD_Close(ID);
  67 + exit(0);
  68 + }
  69 + printf("time set as %lf\n",RealTime);
  70 +
  71 +
  72 + do
  73 + {
  74 + error = DD_GetData(ID,"Time",TimeInt, &data);
  75 + printf("DD_GetData returns = %d\n",error);
  76 + if(error < 0)
  77 + {
  78 + error = DD_Close(ID);
  79 + exit(0);
  80 + }
  81 + if(error == MOREDELAY)
  82 + {
  83 + sleep(2);
  84 + error = MOREDATA;
  85 + }
  86 + }
  87 + while(error == MOREDATA);
  88 +
  89 + do
  90 + {
  91 + error = DD_GetData(ID,ParName,TimeInt, &data);
  92 + printf("DD_GetData returns = %d\n",error);
  93 + if(error < 0)
  94 + {
  95 + error = DD_Close(ID);
  96 + exit(0);
  97 + }
  98 + if(error == MOREDELAY)
  99 + {
  100 + sleep(2);
  101 + error = MOREDATA;
  102 + }
  103 + }
  104 + while(error == MOREDATA);
  105 +
  106 + /*---------- Close VI and reurn -----------------------*/
  107 + error = DD_Close(ID);
  108 +
  109 + gettimeofday(&end,NULL);
  110 + secs = end.tv_sec - start.tv_sec;
  111 + usecs = end.tv_usec - start.tv_usec;
  112 +
  113 + printf("Time elapsed: msecs %f\n",(float)(secs*1000000 + usecs)/1000.);
  114 +
  115 + return 1;
  116 +}
... ...
src/TOOLS/DDSimpleTestGetMultiData/CMakeLists.txt 0 → 100644
  1 +++ a/src/TOOLS/DDSimpleTestGetMultiData/CMakeLists.txt
... ... @@ -0,0 +1,22 @@
  1 +
  2 +PROJECT(DDSimpleTestGetMultiData)
  3 +
  4 +include_directories(
  5 + ${CMAKE_HOME_DIRECTORY}/src/DDClientLibC/INCLUDE/
  6 +)
  7 +
  8 +#Configuration de l'exécutable
  9 +file(
  10 + GLOB_RECURSE
  11 + source_files
  12 + ./*
  13 +)
  14 +
  15 +ADD_EXECUTABLE (DDSimpleTestGetMultiData ${source_files} )
  16 +
  17 +target_link_libraries(
  18 + DDSimpleTestGetMultiData
  19 + DDClientLibC
  20 +)
  21 +
  22 +install (TARGETS DDSimpleTestGetMultiData DESTINATION bin)
... ...
src/TOOLS/DDSimpleTestGetMultiData/SimpleTest.c 0 → 100644
  1 +++ a/src/TOOLS/DDSimpleTestGetMultiData/SimpleTest.c
... ... @@ -0,0 +1,101 @@
  1 +/*=============================================================
  2 + * SimpleTest.c
  3 + * Simple test of some critical server behaviour
  4 + * 11 Apr 2009, V.1.0, Fedorov
  5 + *=============================================================*/
  6 +#include <stdio.h>
  7 +#include <stdlib.h>
  8 +#include <unistd.h>
  9 +#include <DD.h>
  10 +#include <time.h>
  11 +#include <sys/time.h>
  12 +
  13 +/*-------------------------*/
  14 +#define VI "ace:imf:all\0"
  15 +#define PAR0 "IMF\0"
  16 +#define PAR1 "Time\0"
  17 +#define NVARS 2
  18 +#define ATTR "MinSampling\0"
  19 +#define START "2008000000000000\0"
  20 +#define TI "0000010000000000\0"
  21 +/*-------------------------*/
  22 +
  23 +int main()
  24 +{
  25 + char ViName[100] = VI;
  26 + char StartTime[17] = START;
  27 + char TimeInt[17] = TI;
  28 + char ParName1[20] = PAR1;
  29 + char ParName0[20] = PAR0;
  30 + char *ParNames[NVARS] = {(char *)ParName0, (char *)ParName1};
  31 + char AttrName[100] = ATTR;
  32 + double RealTime;
  33 + DD_data_t *data;
  34 +
  35 + int ID, error;
  36 + struct timeval start, end;
  37 + long secs, usecs;
  38 +
  39 + gettimeofday(&start,NULL);
  40 + ID = DD_SetVariable(ViName);
  41 + printf("ID = %d\n",ID);
  42 + if(ID < 0)
  43 + {
  44 + error = DD_Close(99);
  45 + exit(0);
  46 + }
  47 +
  48 +/*
  49 + * Get Sampling Time info (secs)
  50 + * attribute names : MinSampling (constant sampling)
  51 + * attribute names : MinSampling & MaxSampling (variable sampling)
  52 + */
  53 +
  54 + error = DD_GetInform(ID, AttrName, &data);
  55 + if(error < 0)
  56 + {
  57 + error = DD_Close(ID);
  58 + exit(0);
  59 + }
  60 + printf(" sampling %lf\n", *(double *)data->Variables[0]);
  61 +
  62 +/*
  63 + * RealTime - double time pointer points to after SetTime
  64 + */
  65 + error = DD_SetTimeInfo(ID, StartTime, &RealTime);
  66 + printf("DD_SetTimeInfo returns = %d\n",error);
  67 + if(error < 0)
  68 + {
  69 + error = DD_Close(ID);
  70 + exit(0);
  71 + }
  72 + printf("time set as %lf\n",RealTime);
  73 +
  74 + do
  75 + {
  76 + error = DD_GetMultiData(ID,NVARS, (char **)ParNames,TimeInt, &data, 1);
  77 + printf("DD_GetData returns = %d\n",error);
  78 + if(error < 0)
  79 + {
  80 + error = DD_Close(ID);
  81 + exit(0);
  82 + }
  83 + if(error == MOREDELAY)
  84 + {
  85 + sleep(2);
  86 + error = MOREDATA;
  87 + }
  88 + }
  89 + while(error == MOREDATA);
  90 +
  91 + /*---------- Close VI and reurn -----------------------*/
  92 + error = DD_Close(ID);
  93 +
  94 + gettimeofday(&end,NULL);
  95 + secs = end.tv_sec - start.tv_sec;
  96 + usecs = end.tv_usec - start.tv_usec;
  97 +
  98 + printf("Time elapsed: msecs %f\n",(float)(secs*1000000 + usecs)/1000.);
  99 +
  100 + return 1;
  101 +}
... ...