diff --git a/src/libCom/assertUNIX.c b/src/libCom/assertUNIX.c index b378faded..bf86621f4 100644 --- a/src/libCom/assertUNIX.c +++ b/src/libCom/assertUNIX.c @@ -27,6 +27,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.7 1997/01/22 22:06:49 jhill + * doc + * * Revision 1.6 1996/11/02 01:56:55 jhill * improved message * @@ -46,9 +49,9 @@ #include #include -#include -#include -#include +#include "epicsAssert.h" +#include "epicsPrint.h" +#include "epicsVersion.h" /* diff --git a/src/libCom/assertVX.c b/src/libCom/assertVX.c index 8260c655b..6e75fcd2b 100644 --- a/src/libCom/assertVX.c +++ b/src/libCom/assertVX.c @@ -27,6 +27,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.6 1997/01/22 22:07:22 jhill + * doc + * * Revision 1.5 1996/06/19 17:14:12 jhill * print out the EPICS release when there is an assert failure * @@ -47,9 +50,9 @@ #include #include -#include -#include -#include +#include "epicsAssert.h" +#include "epicsPrint.h" +#include "epicsVersion.h" /* diff --git a/src/libCom/bucketLib.c b/src/libCom/bucketLib.c index 3bea24794..3e3ccc073 100644 --- a/src/libCom/bucketLib.c +++ b/src/libCom/bucketLib.c @@ -41,8 +41,8 @@ #include #include -#include -#include +#include "epicsAssert.h" +#include "bucketLib.h" #ifndef TRUE #define TRUE 1 diff --git a/src/libCom/bucketLib.h b/src/libCom/bucketLib.h index 6b6828533..6d4439e94 100644 --- a/src/libCom/bucketLib.h +++ b/src/libCom/bucketLib.h @@ -33,6 +33,9 @@ * .02 121693 joh added bucketFree() * .03 052395 joh use std EPICS status * $Log$ + * Revision 1.2 1996/06/19 19:44:53 jhill + * C++ support + * * * NOTES: * .01 Storage for identifier must persist until an item is deleted @@ -45,8 +48,8 @@ extern "C" { #endif -#include -#include +#include "errMdef.h" +#include "epicsTypes.h" typedef unsigned BUCKETID; diff --git a/src/libCom/bucketLib/bucketLib.c b/src/libCom/bucketLib/bucketLib.c index 3bea24794..3e3ccc073 100644 --- a/src/libCom/bucketLib/bucketLib.c +++ b/src/libCom/bucketLib/bucketLib.c @@ -41,8 +41,8 @@ #include #include -#include -#include +#include "epicsAssert.h" +#include "bucketLib.h" #ifndef TRUE #define TRUE 1 diff --git a/src/libCom/bucketLib/bucketLib.h b/src/libCom/bucketLib/bucketLib.h index 6b6828533..6d4439e94 100644 --- a/src/libCom/bucketLib/bucketLib.h +++ b/src/libCom/bucketLib/bucketLib.h @@ -33,6 +33,9 @@ * .02 121693 joh added bucketFree() * .03 052395 joh use std EPICS status * $Log$ + * Revision 1.2 1996/06/19 19:44:53 jhill + * C++ support + * * * NOTES: * .01 Storage for identifier must persist until an item is deleted @@ -45,8 +48,8 @@ extern "C" { #endif -#include -#include +#include "errMdef.h" +#include "epicsTypes.h" typedef unsigned BUCKETID; diff --git a/src/libCom/calc/calcPerform.c b/src/libCom/calc/calcPerform.c index 3eaf4aae0..050985a7d 100644 --- a/src/libCom/calc/calcPerform.c +++ b/src/libCom/calc/calcPerform.c @@ -109,8 +109,8 @@ #endif #include -#include -#include +#include "dbDefs.h" +#include "post.h" #include static double local_random(); diff --git a/src/libCom/calc/postfix.c b/src/libCom/calc/postfix.c index bd1719fb0..2f3092e60 100644 --- a/src/libCom/calc/postfix.c +++ b/src/libCom/calc/postfix.c @@ -98,8 +98,8 @@ #endif #include -#include -#include +#include "dbDefs.h" +#include "post.h" #include /* declarations for postfix */ diff --git a/src/libCom/calcPerform.c b/src/libCom/calcPerform.c index 3eaf4aae0..050985a7d 100644 --- a/src/libCom/calcPerform.c +++ b/src/libCom/calcPerform.c @@ -109,8 +109,8 @@ #endif #include -#include -#include +#include "dbDefs.h" +#include "post.h" #include static double local_random(); diff --git a/src/libCom/cvtFast.c b/src/libCom/cvtFast.c index 8c9baff85..b5bb2d1f2 100644 --- a/src/libCom/cvtFast.c +++ b/src/libCom/cvtFast.c @@ -55,7 +55,7 @@ #include #include #include /* XPG2/XPG3/POSIX.1/FIPS151-1/ANSI-C */ -#include +#include "cvtFast.h" /* * This routine converts numbers less than 10,000,000. It defers to f_to_str for diff --git a/src/libCom/cvtFast/cvtFast.c b/src/libCom/cvtFast/cvtFast.c index 8c9baff85..b5bb2d1f2 100644 --- a/src/libCom/cvtFast/cvtFast.c +++ b/src/libCom/cvtFast/cvtFast.c @@ -55,7 +55,7 @@ #include #include #include /* XPG2/XPG3/POSIX.1/FIPS151-1/ANSI-C */ -#include +#include "cvtFast.h" /* * This routine converts numbers less than 10,000,000. It defers to f_to_str for diff --git a/src/libCom/ellLib.c b/src/libCom/ellLib.c index 947910c10..aae33c911 100644 --- a/src/libCom/ellLib.c +++ b/src/libCom/ellLib.c @@ -38,7 +38,7 @@ #include -#include +#include "ellLib.h" #if !defined(NULL) #define NULL 0 diff --git a/src/libCom/ellLib.h b/src/libCom/ellLib.h index c2333bc5c..40f489ccd 100644 --- a/src/libCom/ellLib.h +++ b/src/libCom/ellLib.h @@ -51,7 +51,7 @@ struct ELLLIST { }; typedef struct ELLLIST ELLLIST; -#ifdef __STDC__ +#if defined(__STDC__) || defined(__cplusplus) #ifdef DLLLIB_USE_MACROS diff --git a/src/libCom/ellLib/ellLib.c b/src/libCom/ellLib/ellLib.c index 947910c10..aae33c911 100644 --- a/src/libCom/ellLib/ellLib.c +++ b/src/libCom/ellLib/ellLib.c @@ -38,7 +38,7 @@ #include -#include +#include "ellLib.h" #if !defined(NULL) #define NULL 0 diff --git a/src/libCom/ellLib/ellLib.h b/src/libCom/ellLib/ellLib.h index c2333bc5c..40f489ccd 100644 --- a/src/libCom/ellLib/ellLib.h +++ b/src/libCom/ellLib/ellLib.h @@ -51,7 +51,7 @@ struct ELLLIST { }; typedef struct ELLLIST ELLLIST; -#ifdef __STDC__ +#if defined(__STDC__) || defined(__cplusplus) #ifdef DLLLIB_USE_MACROS diff --git a/src/libCom/env/envDefs.h b/src/libCom/env/envDefs.h index e707ea62a..9aceef795 100644 --- a/src/libCom/env/envDefs.h +++ b/src/libCom/env/envDefs.h @@ -32,6 +32,7 @@ * .05 04-20-95 anj moved defaults to CONFIG_ENV * .06 09-11-96 joh ANSI prototypes * .07 09-18-96 joh added envParamIsEmpty() + * .08 03-18-97 joh remove env param length limit * * make options * -DvxWorks makes a version for VxWorks @@ -59,35 +60,39 @@ #ifndef envDefsH #define envDefsH +#ifdef __cplusplus +extern "C" { +#endif + #include "shareLib.h" #include "osiSock.h" typedef struct envParam { char *name; /* text name of the parameter */ - char dflt[80]; /* default value for the parameter */ + char *pdflt; } ENV_PARAM; /* * bldEnvData looks for "epicsShareExtern ENV_PARAM" */ -epicsShareExtern ENV_PARAM EPICS_CA_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CA_CONN_TMO; -epicsShareExtern ENV_PARAM EPICS_CA_BEACON_PERIOD; -epicsShareExtern ENV_PARAM EPICS_CA_AUTO_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CA_REPEATER_PORT; -epicsShareExtern ENV_PARAM EPICS_CA_SERVER_PORT; -epicsShareExtern ENV_PARAM EPICS_CAS_INTF_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CAS_BEACON_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CAS_SERVER_PORT; -epicsShareExtern ENV_PARAM EPICS_TS_MIN_WEST; -epicsShareExtern ENV_PARAM EPICS_TS_NTP_INET; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_PORT; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_INET; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_LIMIT; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_NAME; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_COMMAND; -epicsShareExtern ENV_PARAM EPICS_CMD_PROTO_PORT; -epicsShareExtern ENV_PARAM EPICS_AR_PORT; +epicsShareExtern const ENV_PARAM EPICS_CA_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CA_CONN_TMO; +epicsShareExtern const ENV_PARAM EPICS_CA_BEACON_PERIOD; +epicsShareExtern const ENV_PARAM EPICS_CA_AUTO_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CA_REPEATER_PORT; +epicsShareExtern const ENV_PARAM EPICS_CA_SERVER_PORT; +epicsShareExtern const ENV_PARAM EPICS_CAS_INTF_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CAS_BEACON_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CAS_SERVER_PORT; +epicsShareExtern const ENV_PARAM EPICS_TS_MIN_WEST; +epicsShareExtern const ENV_PARAM EPICS_TS_NTP_INET; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_PORT; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_INET; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_LIMIT; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_NAME; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_COMMAND; +epicsShareExtern const ENV_PARAM EPICS_CMD_PROTO_PORT; +epicsShareExtern const ENV_PARAM EPICS_AR_PORT; #define EPICS_ENV_VARIABLE_COUNT 18 /* @@ -97,30 +102,34 @@ epicsShareExtern ENV_PARAM EPICS_AR_PORT; * bldEnvData looks for "epicsShareExtern ENV_PARAM" so * this always needs to be divided into two lines */ -epicsShareExtern ENV_PARAM +epicsShareExtern const ENV_PARAM *env_param_list[EPICS_ENV_VARIABLE_COUNT+1]; -#ifdef __STDC__ -char * epicsShareAPI envGetConfigParam(ENV_PARAM *pParam, +#if defined(__STDC__) || defined(__cplusplus) +char * epicsShareAPI envGetConfigParam(const ENV_PARAM *pParam, int bufDim, char *pBuf); -long epicsShareAPI envPrtConfigParam(ENV_PARAM *pParam); -long epicsShareAPI envSetConfigParam(ENV_PARAM *pParam, +const char * epicsShareAPI envGetConfigParamPtr(const ENV_PARAM *pParam); +long epicsShareAPI envPrtConfigParam(const ENV_PARAM *pParam); +long epicsShareAPI envSetConfigParam(const ENV_PARAM *pParam, char *value); -long epicsShareAPI envGetInetAddrConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetInetAddrConfigParam(const ENV_PARAM *pParam, struct in_addr *pAddr); -long epicsShareAPI envGetDoubleConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetDoubleConfigParam(const ENV_PARAM *pParam, double *pDouble); -long epicsShareAPI envGetLongConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetLongConfigParam(const ENV_PARAM *pParam, long *pLong); -int epicsShareAPI envParamIsEmpty(ENV_PARAM *pParam); #else char * epicsShareAPI envGetConfigParam(); +const char * epicsShareAPI envGetConfigParamPtr(); long epicsShareAPI envPrtConfigParam(); long epicsShareAPI envSetConfigParam(); long epicsShareAPI envGetInetAddrConfigParam(); long epicsShareAPI envGetDoubleConfigParam(); long epicsShareAPI envGetLongConfigParam(); -int epicsShareAPI envParamIsEmpty(); +#endif + +#ifdef __cplusplus +} #endif #endif /*envDefsH*/ diff --git a/src/libCom/env/envSubr.c b/src/libCom/env/envSubr.c index 7a57f25e4..676b09c88 100644 --- a/src/libCom/env/envSubr.c +++ b/src/libCom/env/envSubr.c @@ -35,7 +35,10 @@ * .07 11-03-96 joh fixed bug occuring when diagnostic is * printed and the env var cant be found * .08 09-11-96 joh ANSI prototypes - * .09 10-18-96 joh added envParamIsEmpty() + * .09 10-18-96 joh added envParamIsEmpty() + * .10 03-18-97 joh added envGetConfigParamPtr() + * (replaces envParamIsEmpty()) + * .11 03-18-97 joh remove env param length limits * * make options * -DvxWorks makes a version for VxWorks @@ -54,16 +57,15 @@ * Many EPICS environment parameters are predefined in envDefs.h. * * QUICK REFERENCE -* #include +* #include "envDefs.h" * ENV_PARAM param; +* char *envGetConfigParamPtr( pParam ) * char *envGetConfigParam( pParam, bufDim, pBuf ) * long envGetLongConfigParam( pParam, pLong ) * long envGetDoubleConfigParam( pParam, pDouble ) * long envGetInetAddrConfigParam( pParam, pAddr ) * long envPrtConfigParam( pParam ) * long envSetConfigParam( pParam, valueString ) -* int envParamIsEmpty( pParam ) -) * * SEE ALSO * $epics/share/bin/envSetupParams, envDefs.h @@ -84,6 +86,55 @@ #define epicsExportSharedSymbols #include "envDefs.h" + +/*+/subr********************************************************************** +* NAME envGetConfigParamPtr - returns a pointer to the configuration +* parameter value string +* +* DESCRIPTION +* Returns a pointer to a configuration parameter value. +* If the configuration parameter isn't found in the environment, +* then a pointer to the default value for the parameter is copied. +* If no parameter is found and there is no default, then +* NULL is returned. +* +* RETURNS +* pointer to the environment variable value string, or +* NULL if no parameter value and no default value was found +* +* EXAMPLES +* 1. Get the value for the EPICS-defined environment parameter +* EPICS_TS_MIN_WEST. +* +* #include "envDefs.h" +* const char *pStr; +* +* pStr = envGetConfigParamPtr(&EPICS_TS_MIN_WEST); +* if (pStr) { +* printf("minutes west of UTC is: %s\n", pStr); +* } +* +*-*/ +const char * epicsShareAPI envGetConfigParamPtr( +const ENV_PARAM *pParam /* I pointer to config param structure */ +) +{ + const char *pEnv; /* pointer to environment string */ + + pEnv = getenv(pParam->name); + + if (pEnv == NULL) { + pEnv = pParam->pdflt; + } + + if (pEnv) { + if (pEnv[0u] == '\0') { + pEnv = NULL; + } + } + + return pEnv; +} /*+/subr********************************************************************** @@ -104,39 +155,34 @@ * 1. Get the value for the EPICS-defined environment parameter * EPICS_TS_MIN_WEST. * -* #include +* #include "envDefs.h" * char temp[80]; * * printf("minutes west of UTC is: %s\n", -* envGetConfigParam(&EPICS_TS_MIN_WEST, 80, temp)); +* envGetConfigParam(&EPICS_TS_MIN_WEST, sizeof(temp), temp)); * * 2. Get the value for the DISPLAY environment parameter under UNIX. * -* #include +* #include "envDefs.h" * char temp[80]; * ENV_PARAM display={"DISPLAY",""} * -* if (envGetConfigParam(&display, 80, temp) == NULL) +* if (envGetConfigParam(&display, sizeof(temp), temp) == NULL) * printf("DISPLAY isn't defined\n"); * else * printf("DISPLAY is %s\n", temp); * *-*/ char * epicsShareAPI envGetConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ int bufDim, /* I dimension of parameter buffer */ char *pBuf /* I pointer to parameter buffer */ ) { - char *pEnv; /* pointer to environment string */ + const char *pEnv; /* pointer to environment string */ - pEnv = getenv(pParam->name); - - if (pEnv == NULL) { - pEnv = pParam->dflt; - } - - if (pEnv[0u] == '\0') { + pEnv = epicsShareAPI envGetConfigParamPtr(pParam); + if (!pEnv) { return NULL; } @@ -165,7 +211,7 @@ char *pBuf /* I pointer to parameter buffer */ * EXAMPLE * 1. Get the value for the real environment parameter EPICS_THRESHOLD. * -* #include +* #include "envDefs.h" * double threshold; * long status; * @@ -180,7 +226,7 @@ char *pBuf /* I pointer to parameter buffer */ * *-*/ long epicsShareAPI envGetDoubleConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ double *pDouble /* O pointer to place to store value */ ) { @@ -194,7 +240,7 @@ double *pDouble /* O pointer to place to store value */ if (count == 1) { return 0; } - (void)printf("Unable to find a real number in %s=%s\n", + (void)fprintf(stderr,"Unable to find a real number in %s=%s\n", pParam->name, text); } @@ -220,7 +266,7 @@ double *pDouble /* O pointer to place to store value */ * EXAMPLE * 1. Get the value for the inet address environment parameter EPICS_INET. * -* #include +* #include "envDefs.h" * struct in_addr addr; * long status; * @@ -235,7 +281,7 @@ double *pDouble /* O pointer to place to store value */ * *-*/ long epicsShareAPI envGetInetAddrConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ ) { @@ -250,7 +296,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ pAddr->s_addr = status; return 0; } - (void)printf("Unable to find an IP address in %s=%s\n", + (void)fprintf(stderr,"Unable to find an IP address in %s=%s\n", pParam->name, text); } return -1; @@ -276,7 +322,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ * 1. Get the value as a long for the integer environment parameter * EPICS_NUMBER_OF_ITEMS. * -* #include +* #include "envDefs.h" * long count; * long status; * @@ -291,7 +337,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ * *-*/ long epicsShareAPI envGetLongConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ long *pLong /* O pointer to place to store value */ ) { @@ -304,7 +350,7 @@ long *pLong /* O pointer to place to store value */ count = sscanf(text, "%ld", pLong); if (count == 1) return 0; - (void)printf("Unable to find an integer in %s=%s\n", + (void)fprintf(stderr,"Unable to find an integer in %s=%s\n", pParam->name, text); } return -1; @@ -323,19 +369,21 @@ long *pLong /* O pointer to place to store value */ * 1. Print the value for the EPICS-defined environment parameter * EPICS_TS_MIN_WEST. * -* #include +* #include "envDefs.h" * * envPrtConfigParam(&EPICS_TS_MIN_WEST); * *-*/ long epicsShareAPI envPrtConfigParam( -ENV_PARAM *pParam) /* pointer to config param structure */ +const ENV_PARAM *pParam) /* pointer to config param structure */ { - char text[80]; - if (envGetConfigParam(pParam, 80, text) == NULL) - printf("%s is undefined\n", pParam->name); + const char *pVal; + + pVal = epicsShareAPI envGetConfigParamPtr(pParam); + if (pVal == NULL) + fprintf(stderr, "%s is undefined\n", pParam->name); else - printf("%s: %s\n", pParam->name, text); + fprintf(stdout,"%s: %s\n", pParam->name, pVal); return 0; } @@ -361,7 +409,7 @@ ENV_PARAM *pParam) /* pointer to config param structure */ * * In a program running under VxWorks: * -* #include +* #include "envDefs.h" * * envSetConfigParam(&EPICS_TS_MIN_WEST, "360"); * @@ -371,12 +419,12 @@ ENV_PARAM *pParam) /* pointer to config param structure */ * *-*/ long epicsShareAPI envSetConfigParam ( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam, /* I pointer to config param structure */ char *value /* I pointer to value string */ ) { #ifndef vxWorks - printf("envSetConfigParam can only be used under vxWorks\n"); + fprintf(stderr, "envSetConfigParam can only be used under vxWorks\n"); return -1L; #else long retCode = 0; @@ -437,7 +485,7 @@ char *value /* I pointer to value string */ * EXAMPLE * 1. Print the value for all EPICS-defined environment parameters. * -* #include +* #include "envDefs.h" * * epicsPrtEnvParams(); * @@ -445,7 +493,7 @@ char *value /* I pointer to value string */ long epicsPrtEnvParams() { - ENV_PARAM **ppParam = env_param_list; + const ENV_PARAM **ppParam = env_param_list; while (*ppParam != NULL) envPrtConfigParam(*(ppParam++)); @@ -453,38 +501,3 @@ epicsPrtEnvParams() return 0; } -/*+/subr********************************************************************** -* NAME envParamIsEmpty - test for empty environment parameter -* -* DESCRIPTION -* Return TRUE if the environment parameter is empty - else false -* -* AUTHOR -* Jeff Hill -* RETURNS -* 0 or 1 -* -* EXAMPLE -* #include -* -* if (envParamIsEmpty(&EPICS_CAS_SERVER_PORT)) { -* port = caFetchPortConfig(&EPICS_CA_SERVER_PORT, CA_SERVER_PORT); -* } -* -*-*/ -int epicsShareAPI envParamIsEmpty( -ENV_PARAM *pParam /* I pointer to config param structure */ -) -{ - char *pEnv; /* pointer to environment string */ - - pEnv = getenv(pParam->name); - - if (pEnv == NULL && pParam->dflt[0u] == '\0') { - return 1; - } - else { - return 0; - } -} - diff --git a/src/libCom/envDefs.h b/src/libCom/envDefs.h index e707ea62a..9aceef795 100644 --- a/src/libCom/envDefs.h +++ b/src/libCom/envDefs.h @@ -32,6 +32,7 @@ * .05 04-20-95 anj moved defaults to CONFIG_ENV * .06 09-11-96 joh ANSI prototypes * .07 09-18-96 joh added envParamIsEmpty() + * .08 03-18-97 joh remove env param length limit * * make options * -DvxWorks makes a version for VxWorks @@ -59,35 +60,39 @@ #ifndef envDefsH #define envDefsH +#ifdef __cplusplus +extern "C" { +#endif + #include "shareLib.h" #include "osiSock.h" typedef struct envParam { char *name; /* text name of the parameter */ - char dflt[80]; /* default value for the parameter */ + char *pdflt; } ENV_PARAM; /* * bldEnvData looks for "epicsShareExtern ENV_PARAM" */ -epicsShareExtern ENV_PARAM EPICS_CA_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CA_CONN_TMO; -epicsShareExtern ENV_PARAM EPICS_CA_BEACON_PERIOD; -epicsShareExtern ENV_PARAM EPICS_CA_AUTO_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CA_REPEATER_PORT; -epicsShareExtern ENV_PARAM EPICS_CA_SERVER_PORT; -epicsShareExtern ENV_PARAM EPICS_CAS_INTF_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CAS_BEACON_ADDR_LIST; -epicsShareExtern ENV_PARAM EPICS_CAS_SERVER_PORT; -epicsShareExtern ENV_PARAM EPICS_TS_MIN_WEST; -epicsShareExtern ENV_PARAM EPICS_TS_NTP_INET; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_PORT; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_INET; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_LIMIT; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_NAME; -epicsShareExtern ENV_PARAM EPICS_IOC_LOG_FILE_COMMAND; -epicsShareExtern ENV_PARAM EPICS_CMD_PROTO_PORT; -epicsShareExtern ENV_PARAM EPICS_AR_PORT; +epicsShareExtern const ENV_PARAM EPICS_CA_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CA_CONN_TMO; +epicsShareExtern const ENV_PARAM EPICS_CA_BEACON_PERIOD; +epicsShareExtern const ENV_PARAM EPICS_CA_AUTO_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CA_REPEATER_PORT; +epicsShareExtern const ENV_PARAM EPICS_CA_SERVER_PORT; +epicsShareExtern const ENV_PARAM EPICS_CAS_INTF_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CAS_BEACON_ADDR_LIST; +epicsShareExtern const ENV_PARAM EPICS_CAS_SERVER_PORT; +epicsShareExtern const ENV_PARAM EPICS_TS_MIN_WEST; +epicsShareExtern const ENV_PARAM EPICS_TS_NTP_INET; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_PORT; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_INET; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_LIMIT; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_NAME; +epicsShareExtern const ENV_PARAM EPICS_IOC_LOG_FILE_COMMAND; +epicsShareExtern const ENV_PARAM EPICS_CMD_PROTO_PORT; +epicsShareExtern const ENV_PARAM EPICS_AR_PORT; #define EPICS_ENV_VARIABLE_COUNT 18 /* @@ -97,30 +102,34 @@ epicsShareExtern ENV_PARAM EPICS_AR_PORT; * bldEnvData looks for "epicsShareExtern ENV_PARAM" so * this always needs to be divided into two lines */ -epicsShareExtern ENV_PARAM +epicsShareExtern const ENV_PARAM *env_param_list[EPICS_ENV_VARIABLE_COUNT+1]; -#ifdef __STDC__ -char * epicsShareAPI envGetConfigParam(ENV_PARAM *pParam, +#if defined(__STDC__) || defined(__cplusplus) +char * epicsShareAPI envGetConfigParam(const ENV_PARAM *pParam, int bufDim, char *pBuf); -long epicsShareAPI envPrtConfigParam(ENV_PARAM *pParam); -long epicsShareAPI envSetConfigParam(ENV_PARAM *pParam, +const char * epicsShareAPI envGetConfigParamPtr(const ENV_PARAM *pParam); +long epicsShareAPI envPrtConfigParam(const ENV_PARAM *pParam); +long epicsShareAPI envSetConfigParam(const ENV_PARAM *pParam, char *value); -long epicsShareAPI envGetInetAddrConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetInetAddrConfigParam(const ENV_PARAM *pParam, struct in_addr *pAddr); -long epicsShareAPI envGetDoubleConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetDoubleConfigParam(const ENV_PARAM *pParam, double *pDouble); -long epicsShareAPI envGetLongConfigParam(ENV_PARAM *pParam, +long epicsShareAPI envGetLongConfigParam(const ENV_PARAM *pParam, long *pLong); -int epicsShareAPI envParamIsEmpty(ENV_PARAM *pParam); #else char * epicsShareAPI envGetConfigParam(); +const char * epicsShareAPI envGetConfigParamPtr(); long epicsShareAPI envPrtConfigParam(); long epicsShareAPI envSetConfigParam(); long epicsShareAPI envGetInetAddrConfigParam(); long epicsShareAPI envGetDoubleConfigParam(); long epicsShareAPI envGetLongConfigParam(); -int epicsShareAPI envParamIsEmpty(); +#endif + +#ifdef __cplusplus +} #endif #endif /*envDefsH*/ diff --git a/src/libCom/envSubr.c b/src/libCom/envSubr.c index 7a57f25e4..676b09c88 100644 --- a/src/libCom/envSubr.c +++ b/src/libCom/envSubr.c @@ -35,7 +35,10 @@ * .07 11-03-96 joh fixed bug occuring when diagnostic is * printed and the env var cant be found * .08 09-11-96 joh ANSI prototypes - * .09 10-18-96 joh added envParamIsEmpty() + * .09 10-18-96 joh added envParamIsEmpty() + * .10 03-18-97 joh added envGetConfigParamPtr() + * (replaces envParamIsEmpty()) + * .11 03-18-97 joh remove env param length limits * * make options * -DvxWorks makes a version for VxWorks @@ -54,16 +57,15 @@ * Many EPICS environment parameters are predefined in envDefs.h. * * QUICK REFERENCE -* #include +* #include "envDefs.h" * ENV_PARAM param; +* char *envGetConfigParamPtr( pParam ) * char *envGetConfigParam( pParam, bufDim, pBuf ) * long envGetLongConfigParam( pParam, pLong ) * long envGetDoubleConfigParam( pParam, pDouble ) * long envGetInetAddrConfigParam( pParam, pAddr ) * long envPrtConfigParam( pParam ) * long envSetConfigParam( pParam, valueString ) -* int envParamIsEmpty( pParam ) -) * * SEE ALSO * $epics/share/bin/envSetupParams, envDefs.h @@ -84,6 +86,55 @@ #define epicsExportSharedSymbols #include "envDefs.h" + +/*+/subr********************************************************************** +* NAME envGetConfigParamPtr - returns a pointer to the configuration +* parameter value string +* +* DESCRIPTION +* Returns a pointer to a configuration parameter value. +* If the configuration parameter isn't found in the environment, +* then a pointer to the default value for the parameter is copied. +* If no parameter is found and there is no default, then +* NULL is returned. +* +* RETURNS +* pointer to the environment variable value string, or +* NULL if no parameter value and no default value was found +* +* EXAMPLES +* 1. Get the value for the EPICS-defined environment parameter +* EPICS_TS_MIN_WEST. +* +* #include "envDefs.h" +* const char *pStr; +* +* pStr = envGetConfigParamPtr(&EPICS_TS_MIN_WEST); +* if (pStr) { +* printf("minutes west of UTC is: %s\n", pStr); +* } +* +*-*/ +const char * epicsShareAPI envGetConfigParamPtr( +const ENV_PARAM *pParam /* I pointer to config param structure */ +) +{ + const char *pEnv; /* pointer to environment string */ + + pEnv = getenv(pParam->name); + + if (pEnv == NULL) { + pEnv = pParam->pdflt; + } + + if (pEnv) { + if (pEnv[0u] == '\0') { + pEnv = NULL; + } + } + + return pEnv; +} /*+/subr********************************************************************** @@ -104,39 +155,34 @@ * 1. Get the value for the EPICS-defined environment parameter * EPICS_TS_MIN_WEST. * -* #include +* #include "envDefs.h" * char temp[80]; * * printf("minutes west of UTC is: %s\n", -* envGetConfigParam(&EPICS_TS_MIN_WEST, 80, temp)); +* envGetConfigParam(&EPICS_TS_MIN_WEST, sizeof(temp), temp)); * * 2. Get the value for the DISPLAY environment parameter under UNIX. * -* #include +* #include "envDefs.h" * char temp[80]; * ENV_PARAM display={"DISPLAY",""} * -* if (envGetConfigParam(&display, 80, temp) == NULL) +* if (envGetConfigParam(&display, sizeof(temp), temp) == NULL) * printf("DISPLAY isn't defined\n"); * else * printf("DISPLAY is %s\n", temp); * *-*/ char * epicsShareAPI envGetConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ int bufDim, /* I dimension of parameter buffer */ char *pBuf /* I pointer to parameter buffer */ ) { - char *pEnv; /* pointer to environment string */ + const char *pEnv; /* pointer to environment string */ - pEnv = getenv(pParam->name); - - if (pEnv == NULL) { - pEnv = pParam->dflt; - } - - if (pEnv[0u] == '\0') { + pEnv = epicsShareAPI envGetConfigParamPtr(pParam); + if (!pEnv) { return NULL; } @@ -165,7 +211,7 @@ char *pBuf /* I pointer to parameter buffer */ * EXAMPLE * 1. Get the value for the real environment parameter EPICS_THRESHOLD. * -* #include +* #include "envDefs.h" * double threshold; * long status; * @@ -180,7 +226,7 @@ char *pBuf /* I pointer to parameter buffer */ * *-*/ long epicsShareAPI envGetDoubleConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ double *pDouble /* O pointer to place to store value */ ) { @@ -194,7 +240,7 @@ double *pDouble /* O pointer to place to store value */ if (count == 1) { return 0; } - (void)printf("Unable to find a real number in %s=%s\n", + (void)fprintf(stderr,"Unable to find a real number in %s=%s\n", pParam->name, text); } @@ -220,7 +266,7 @@ double *pDouble /* O pointer to place to store value */ * EXAMPLE * 1. Get the value for the inet address environment parameter EPICS_INET. * -* #include +* #include "envDefs.h" * struct in_addr addr; * long status; * @@ -235,7 +281,7 @@ double *pDouble /* O pointer to place to store value */ * *-*/ long epicsShareAPI envGetInetAddrConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ ) { @@ -250,7 +296,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ pAddr->s_addr = status; return 0; } - (void)printf("Unable to find an IP address in %s=%s\n", + (void)fprintf(stderr,"Unable to find an IP address in %s=%s\n", pParam->name, text); } return -1; @@ -276,7 +322,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ * 1. Get the value as a long for the integer environment parameter * EPICS_NUMBER_OF_ITEMS. * -* #include +* #include "envDefs.h" * long count; * long status; * @@ -291,7 +337,7 @@ struct in_addr *pAddr /* O pointer to struct to receive inet addr */ * *-*/ long epicsShareAPI envGetLongConfigParam( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam,/* I pointer to config param structure */ long *pLong /* O pointer to place to store value */ ) { @@ -304,7 +350,7 @@ long *pLong /* O pointer to place to store value */ count = sscanf(text, "%ld", pLong); if (count == 1) return 0; - (void)printf("Unable to find an integer in %s=%s\n", + (void)fprintf(stderr,"Unable to find an integer in %s=%s\n", pParam->name, text); } return -1; @@ -323,19 +369,21 @@ long *pLong /* O pointer to place to store value */ * 1. Print the value for the EPICS-defined environment parameter * EPICS_TS_MIN_WEST. * -* #include +* #include "envDefs.h" * * envPrtConfigParam(&EPICS_TS_MIN_WEST); * *-*/ long epicsShareAPI envPrtConfigParam( -ENV_PARAM *pParam) /* pointer to config param structure */ +const ENV_PARAM *pParam) /* pointer to config param structure */ { - char text[80]; - if (envGetConfigParam(pParam, 80, text) == NULL) - printf("%s is undefined\n", pParam->name); + const char *pVal; + + pVal = epicsShareAPI envGetConfigParamPtr(pParam); + if (pVal == NULL) + fprintf(stderr, "%s is undefined\n", pParam->name); else - printf("%s: %s\n", pParam->name, text); + fprintf(stdout,"%s: %s\n", pParam->name, pVal); return 0; } @@ -361,7 +409,7 @@ ENV_PARAM *pParam) /* pointer to config param structure */ * * In a program running under VxWorks: * -* #include +* #include "envDefs.h" * * envSetConfigParam(&EPICS_TS_MIN_WEST, "360"); * @@ -371,12 +419,12 @@ ENV_PARAM *pParam) /* pointer to config param structure */ * *-*/ long epicsShareAPI envSetConfigParam ( -ENV_PARAM *pParam, /* I pointer to config param structure */ +const ENV_PARAM *pParam, /* I pointer to config param structure */ char *value /* I pointer to value string */ ) { #ifndef vxWorks - printf("envSetConfigParam can only be used under vxWorks\n"); + fprintf(stderr, "envSetConfigParam can only be used under vxWorks\n"); return -1L; #else long retCode = 0; @@ -437,7 +485,7 @@ char *value /* I pointer to value string */ * EXAMPLE * 1. Print the value for all EPICS-defined environment parameters. * -* #include +* #include "envDefs.h" * * epicsPrtEnvParams(); * @@ -445,7 +493,7 @@ char *value /* I pointer to value string */ long epicsPrtEnvParams() { - ENV_PARAM **ppParam = env_param_list; + const ENV_PARAM **ppParam = env_param_list; while (*ppParam != NULL) envPrtConfigParam(*(ppParam++)); @@ -453,38 +501,3 @@ epicsPrtEnvParams() return 0; } -/*+/subr********************************************************************** -* NAME envParamIsEmpty - test for empty environment parameter -* -* DESCRIPTION -* Return TRUE if the environment parameter is empty - else false -* -* AUTHOR -* Jeff Hill -* RETURNS -* 0 or 1 -* -* EXAMPLE -* #include -* -* if (envParamIsEmpty(&EPICS_CAS_SERVER_PORT)) { -* port = caFetchPortConfig(&EPICS_CA_SERVER_PORT, CA_SERVER_PORT); -* } -* -*-*/ -int epicsShareAPI envParamIsEmpty( -ENV_PARAM *pParam /* I pointer to config param structure */ -) -{ - char *pEnv; /* pointer to environment string */ - - pEnv = getenv(pParam->name); - - if (pEnv == NULL && pParam->dflt[0u] == '\0') { - return 1; - } - else { - return 0; - } -} - diff --git a/src/libCom/epicsAssert.h b/src/libCom/epicsAssert.h index e7b99a8e4..9c4f8a11a 100644 --- a/src/libCom/epicsAssert.h +++ b/src/libCom/epicsAssert.h @@ -45,8 +45,16 @@ extern "C" { #if defined(__STDC__) || defined(__cplusplus) -extern void epicsAssert (const char *pFile, const unsigned line, - const char *pMsg, const char *pAuthorName); + extern void epicsAssert (const char *pFile, const unsigned line, + const char *pMsg, const char *pAuthorName); + +#else /*__STDC__ or __cplusplus*/ + + extern void epicsAssert (); + +#endif /*__STDC__ or __cplusplus*/ + +#if (defined(__STDC__) || defined(__cplusplus)) && !defined(VAXC) #ifdef epicsAssertAuthor #define assert(exp) \ @@ -58,7 +66,6 @@ extern void epicsAssert (const char *pFile, const unsigned line, #else /*__STDC__ or __cplusplus*/ -extern void epicsAssert (); #ifdef epicsAssertAuthor #define assert(exp) \ @@ -68,7 +75,7 @@ extern void epicsAssert (); {if (!(exp)) epicsAssert (__FILE__, __LINE__, "", 0);} #endif /* epicsAssertAuthor */ -#endif /*__STDC__ or __cplusplus*/ +#endif /* (__STDC__ or __cplusplus) and not VAXC */ #endif /* NDEBUG */ diff --git a/src/libCom/errMdef.h b/src/libCom/errMdef.h index 571d3718f..ef713a2a3 100644 --- a/src/libCom/errMdef.h +++ b/src/libCom/errMdef.h @@ -50,7 +50,7 @@ extern "C" { #else # include #endif -#include +#include "ellLib.h" #define RTN_SUCCESS(STATUS) ((STATUS)==0) diff --git a/src/libCom/errPrintfUNIX.c b/src/libCom/errPrintfUNIX.c index 4e447674b..3153f7646 100644 --- a/src/libCom/errPrintfUNIX.c +++ b/src/libCom/errPrintfUNIX.c @@ -41,10 +41,10 @@ #include #include -#include -#include -#include -#include +#include "epicsAssert.h" +#include "dbDefs.h" +#include "errMdef.h" +#include "epicsPrint.h" #include "errSymTbl.h" diff --git a/src/libCom/errPrintfVX.c b/src/libCom/errPrintfVX.c index 7c30dd307..a0756f81d 100644 --- a/src/libCom/errPrintfVX.c +++ b/src/libCom/errPrintfVX.c @@ -28,6 +28,9 @@ * ----------------- * .01 02-16-95 mrk Extracted from errSymLib.c * $Log$ + * Revision 1.8 1996/09/04 21:46:20 jhill + * fixed gcc warning + * * Revision 1.7 1995/11/08 23:44:41 jhill * changes associated with fixing the log client * @@ -50,12 +53,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include "epicsAssert.h" +#include "ellLib.h" +#include "dbDefs.h" +#include "task_params.h" +#include "errMdef.h" +#include "epicsPrint.h" #ifndef LOCAL #define LOCAL static #endif /* LOCAL */ diff --git a/src/libCom/errSymLib.c b/src/libCom/errSymLib.c index 884fc73d3..7e48cd675 100644 --- a/src/libCom/errSymLib.c +++ b/src/libCom/errSymLib.c @@ -70,9 +70,9 @@ #include #include -#include -#include -#include +#include "ellLib.h" +#include "dbDefs.h" +#include "errMdef.h" #include "errSymTbl.h" #ifdef vxWorks diff --git a/src/libCom/error/errMdef.h b/src/libCom/error/errMdef.h index 571d3718f..ef713a2a3 100644 --- a/src/libCom/error/errMdef.h +++ b/src/libCom/error/errMdef.h @@ -50,7 +50,7 @@ extern "C" { #else # include #endif -#include +#include "ellLib.h" #define RTN_SUCCESS(STATUS) ((STATUS)==0) diff --git a/src/libCom/error/errSymLib.c b/src/libCom/error/errSymLib.c index 884fc73d3..7e48cd675 100644 --- a/src/libCom/error/errSymLib.c +++ b/src/libCom/error/errSymLib.c @@ -70,9 +70,9 @@ #include #include -#include -#include -#include +#include "ellLib.h" +#include "dbDefs.h" +#include "errMdef.h" #include "errSymTbl.h" #ifdef vxWorks diff --git a/src/libCom/fdManager.cc b/src/libCom/fdManager.cc index 4b8168b0f..05c48f1c6 100644 --- a/src/libCom/fdManager.cc +++ b/src/libCom/fdManager.cc @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.3 1996/11/02 02:04:42 jhill +// fixed several subtle bugs +// // Revision 1.2 1996/09/04 21:50:16 jhill // added hashed fd to fdi convert // @@ -31,16 +34,21 @@ #define epicsExportSharedSymbols #include "osiTimer.h" #include "fdManager.h" - -#if !defined(__SUNPRO_CC) +#define INSTANCIATE_RES_LIB_STATIC +#include "resourceLib.cc" + +// +// if the compiler supports explicit instantiation of +// template member functions +// +#if defined(EXPL_TEMPL) // // From Stroustrups's "The C++ Programming Language" // Appendix A: r.14.9 // // This explicitly instantiates the template class's member - // functions into "fdManager.o" + // functions used by fdManager // -# include template class resTable ; #endif @@ -94,7 +102,9 @@ fdManager::~fdManager() // void fdManager::process (const osiTime &delay) { - tsDLFwdIter regIter(this->regList); + static const tsDLIterBD eol; // end of list + tsDLIterBD iter; + tsDLIterBD tmp; osiTime minDelay; osiTime zeroDelay; fdReg *pReg; @@ -126,8 +136,8 @@ void fdManager::process (const osiTime &delay) minDelay = delay; } - while ( (pReg=regIter()) ) { - FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); + for (iter=this->regList.first(); iter!=eol; ++iter) { + FD_SET(iter->getFD(), &this->fdSets[iter->getType()]); } minDelay.getTV (tv.tv_sec, tv.tv_usec); status = select (this->maxFD, &this->fdSets[fdrRead], @@ -152,14 +162,17 @@ void fdManager::process (const osiTime &delay) // // Look for activity // - regIter.reset(); - while ( (pReg=regIter()) ) { - if (FD_ISSET(pReg->getFD(), &this->fdSets[pReg->getType()])) { - FD_CLR(pReg->getFD(), &this->fdSets[pReg->getType()]); - regIter.remove(); - this->activeList.add(*pReg); - pReg->state = fdrActive; + iter=this->regList.first(); + while (iter!=eol) { + tmp = iter; + tmp++; + if (FD_ISSET(iter->getFD(), &this->fdSets[iter->getType()])) { + FD_CLR(iter->getFD(), &this->fdSets[iter->getType()]); + this->regList.remove(*iter); + this->activeList.add(*iter); + iter->state = fdrActive; } + iter=tmp; } // diff --git a/src/libCom/fdManager.h b/src/libCom/fdManager.h index b8d8c4cc8..cf60f4302 100644 --- a/src/libCom/fdManager.h +++ b/src/libCom/fdManager.h @@ -32,6 +32,9 @@ * * History * $Log$ + * Revision 1.3 1996/11/02 02:04:41 jhill + * fixed several subtle bugs + * * Revision 1.2 1996/09/04 21:50:16 jhill * added hashed fd to fdi convert * @@ -114,17 +117,7 @@ public: virtual ~fdReg (); virtual void show(unsigned level) const; -private: - - // - // called when there is activity on the fd - // NOTES - // 1) the fdManager will call this only once during the - // lifetime of a fdReg object if the constructor - // specified "onceOnly" - // - virtual void callBack ()=0; - + // // Called by the file descriptor manager: // 1) If the fdManager is deleted and there are still @@ -135,6 +128,16 @@ private: // fdReg::destroy() does a "delete this" // virtual void destroy (); +private: + + // + // called when there is activity on the fd + // NOTES + // 1) the fdManager will call this only once during the + // lifetime of a fdReg object if the constructor + // specified "onceOnly" + // + virtual void callBack ()=0; unsigned char state; // fdRegState goes here unsigned char onceOnly; diff --git a/src/libCom/fdmgr.c b/src/libCom/fdmgr.c index 3ee07c0db..b6cbaf0e5 100644 --- a/src/libCom/fdmgr.c +++ b/src/libCom/fdmgr.c @@ -71,6 +71,9 @@ * we eliminate delete ambiguity (chance of the same * being reused). * $Log$ + * Revision 1.22 1996/07/09 23:01:31 jhill + * nill 2nd arg to gettimeofday() + * * Revision 1.21 1996/06/19 17:12:40 jhill * check for fd>FD_SETSIZE and improved func proto * @@ -122,12 +125,12 @@ static char *pSccsId = "@(#) $Id$"; #include #endif -#include -#include -#include +#include "epicsAssert.h" +#include "fdmgr.h" +#include "epicsTypes.h" #define NOBSDNETPROTO -#include +#include "bsdProto.h" #ifndef TRUE #define TRUE 1 diff --git a/src/libCom/fdmgr.h b/src/libCom/fdmgr.h index c7fcf9944..c92200210 100644 --- a/src/libCom/fdmgr.h +++ b/src/libCom/fdmgr.h @@ -46,8 +46,8 @@ extern "C" { #endif -#include -#include +#include "ellLib.h" +#include "bucketLib.h" #if defined(vxWorks) # include @@ -71,7 +71,7 @@ extern "C" { # include # include # include -# include +# include # define FDMGR_OS WIN32 #endif diff --git a/src/libCom/fdmgr/fdManager.cpp b/src/libCom/fdmgr/fdManager.cpp index 4b8168b0f..05c48f1c6 100644 --- a/src/libCom/fdmgr/fdManager.cpp +++ b/src/libCom/fdmgr/fdManager.cpp @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.3 1996/11/02 02:04:42 jhill +// fixed several subtle bugs +// // Revision 1.2 1996/09/04 21:50:16 jhill // added hashed fd to fdi convert // @@ -31,16 +34,21 @@ #define epicsExportSharedSymbols #include "osiTimer.h" #include "fdManager.h" - -#if !defined(__SUNPRO_CC) +#define INSTANCIATE_RES_LIB_STATIC +#include "resourceLib.cc" + +// +// if the compiler supports explicit instantiation of +// template member functions +// +#if defined(EXPL_TEMPL) // // From Stroustrups's "The C++ Programming Language" // Appendix A: r.14.9 // // This explicitly instantiates the template class's member - // functions into "fdManager.o" + // functions used by fdManager // -# include template class resTable ; #endif @@ -94,7 +102,9 @@ fdManager::~fdManager() // void fdManager::process (const osiTime &delay) { - tsDLFwdIter regIter(this->regList); + static const tsDLIterBD eol; // end of list + tsDLIterBD iter; + tsDLIterBD tmp; osiTime minDelay; osiTime zeroDelay; fdReg *pReg; @@ -126,8 +136,8 @@ void fdManager::process (const osiTime &delay) minDelay = delay; } - while ( (pReg=regIter()) ) { - FD_SET(pReg->getFD(), &this->fdSets[pReg->getType()]); + for (iter=this->regList.first(); iter!=eol; ++iter) { + FD_SET(iter->getFD(), &this->fdSets[iter->getType()]); } minDelay.getTV (tv.tv_sec, tv.tv_usec); status = select (this->maxFD, &this->fdSets[fdrRead], @@ -152,14 +162,17 @@ void fdManager::process (const osiTime &delay) // // Look for activity // - regIter.reset(); - while ( (pReg=regIter()) ) { - if (FD_ISSET(pReg->getFD(), &this->fdSets[pReg->getType()])) { - FD_CLR(pReg->getFD(), &this->fdSets[pReg->getType()]); - regIter.remove(); - this->activeList.add(*pReg); - pReg->state = fdrActive; + iter=this->regList.first(); + while (iter!=eol) { + tmp = iter; + tmp++; + if (FD_ISSET(iter->getFD(), &this->fdSets[iter->getType()])) { + FD_CLR(iter->getFD(), &this->fdSets[iter->getType()]); + this->regList.remove(*iter); + this->activeList.add(*iter); + iter->state = fdrActive; } + iter=tmp; } // diff --git a/src/libCom/fdmgr/fdManager.h b/src/libCom/fdmgr/fdManager.h index b8d8c4cc8..cf60f4302 100644 --- a/src/libCom/fdmgr/fdManager.h +++ b/src/libCom/fdmgr/fdManager.h @@ -32,6 +32,9 @@ * * History * $Log$ + * Revision 1.3 1996/11/02 02:04:41 jhill + * fixed several subtle bugs + * * Revision 1.2 1996/09/04 21:50:16 jhill * added hashed fd to fdi convert * @@ -114,17 +117,7 @@ public: virtual ~fdReg (); virtual void show(unsigned level) const; -private: - - // - // called when there is activity on the fd - // NOTES - // 1) the fdManager will call this only once during the - // lifetime of a fdReg object if the constructor - // specified "onceOnly" - // - virtual void callBack ()=0; - + // // Called by the file descriptor manager: // 1) If the fdManager is deleted and there are still @@ -135,6 +128,16 @@ private: // fdReg::destroy() does a "delete this" // virtual void destroy (); +private: + + // + // called when there is activity on the fd + // NOTES + // 1) the fdManager will call this only once during the + // lifetime of a fdReg object if the constructor + // specified "onceOnly" + // + virtual void callBack ()=0; unsigned char state; // fdRegState goes here unsigned char onceOnly; diff --git a/src/libCom/fdmgr/fdmgr.h b/src/libCom/fdmgr/fdmgr.h index c7fcf9944..c92200210 100644 --- a/src/libCom/fdmgr/fdmgr.h +++ b/src/libCom/fdmgr/fdmgr.h @@ -46,8 +46,8 @@ extern "C" { #endif -#include -#include +#include "ellLib.h" +#include "bucketLib.h" #if defined(vxWorks) # include @@ -71,7 +71,7 @@ extern "C" { # include # include # include -# include +# include # define FDMGR_OS WIN32 #endif diff --git a/src/libCom/freeList.h b/src/libCom/freeList.h index 9d2784a7a..e2da27aa7 100644 --- a/src/libCom/freeList.h +++ b/src/libCom/freeList.h @@ -60,4 +60,5 @@ void *freeListCalloc(void *pvt); void *freeListMalloc(void *pvt); void freeListFree(void *pvt,void*pmem); void freeListCleanup(void *pvt); +size_t freeListItemsAvail(void *pvt); #endif /*INCfreeListh*/ diff --git a/src/libCom/freeList/freeList.h b/src/libCom/freeList/freeList.h index 9d2784a7a..e2da27aa7 100644 --- a/src/libCom/freeList/freeList.h +++ b/src/libCom/freeList/freeList.h @@ -60,4 +60,5 @@ void *freeListCalloc(void *pvt); void *freeListMalloc(void *pvt); void freeListFree(void *pvt,void*pmem); void freeListCleanup(void *pvt); +size_t freeListItemsAvail(void *pvt); #endif /*INCfreeListh*/ diff --git a/src/libCom/freeList/freeListLib.c b/src/libCom/freeList/freeListLib.c index b8d1c7b22..cc5642cd0 100644 --- a/src/libCom/freeList/freeListLib.c +++ b/src/libCom/freeList/freeListLib.c @@ -49,17 +49,19 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). * Modification Log: * ----------------- * .01 04-19-94 mrk Initial Implementation + * .02 03-28-97 joh added freeListItemAvail() function */ #ifdef vxWorks #include -#include +#include +#include "fast_lock.h" #endif #include #include #include -#include +#include "freeList.h" typedef struct allocMem { struct allocMem *next; @@ -70,6 +72,7 @@ typedef struct { int nmalloc; void *head; allocMem *mallochead; + size_t nBlocksAvailable; #ifdef vxWorks FAST_LOCK lock; #endif @@ -90,6 +93,7 @@ void freeListInitPvt(void **ppvt,int size,int nmalloc) pfl->nmalloc = nmalloc; pfl->head = NULL; pfl->mallochead = NULL; + pfl->nBlocksAvailable = 0u; #ifdef vxWorks FASTLOCKINIT(&pfl->lock); #endif @@ -139,9 +143,11 @@ void *freeListMalloc(void *pvt) ptemp = ((char *)ptemp) + pfl->size; } ptemp = pfl->head; + pfl->nBlocksAvailable += pfl->nmalloc; } ppnext = pfl->head; pfl->head = *ppnext; + pfl->nBlocksAvailable--; #ifdef vxWorks FASTUNLOCK(&pfl->lock); #endif @@ -159,6 +165,7 @@ void freeListFree(void *pvt,void*pmem) ppnext = pmem; *ppnext = pfl->head; pfl->head = pmem; + pfl->nBlocksAvailable++; #ifdef vxWorks FASTUNLOCK(&pfl->lock); #endif @@ -179,3 +186,10 @@ void freeListCleanup(void *pvt) } free(pvt); } + +size_t freeListItemsAvail(void *pvt) +{ + FREELISTPVT *pfl = pvt; + return pfl->nBlocksAvailable; +} + diff --git a/src/libCom/freeListLib.c b/src/libCom/freeListLib.c index b8d1c7b22..cc5642cd0 100644 --- a/src/libCom/freeListLib.c +++ b/src/libCom/freeListLib.c @@ -49,17 +49,19 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). * Modification Log: * ----------------- * .01 04-19-94 mrk Initial Implementation + * .02 03-28-97 joh added freeListItemAvail() function */ #ifdef vxWorks #include -#include +#include +#include "fast_lock.h" #endif #include #include #include -#include +#include "freeList.h" typedef struct allocMem { struct allocMem *next; @@ -70,6 +72,7 @@ typedef struct { int nmalloc; void *head; allocMem *mallochead; + size_t nBlocksAvailable; #ifdef vxWorks FAST_LOCK lock; #endif @@ -90,6 +93,7 @@ void freeListInitPvt(void **ppvt,int size,int nmalloc) pfl->nmalloc = nmalloc; pfl->head = NULL; pfl->mallochead = NULL; + pfl->nBlocksAvailable = 0u; #ifdef vxWorks FASTLOCKINIT(&pfl->lock); #endif @@ -139,9 +143,11 @@ void *freeListMalloc(void *pvt) ptemp = ((char *)ptemp) + pfl->size; } ptemp = pfl->head; + pfl->nBlocksAvailable += pfl->nmalloc; } ppnext = pfl->head; pfl->head = *ppnext; + pfl->nBlocksAvailable--; #ifdef vxWorks FASTUNLOCK(&pfl->lock); #endif @@ -159,6 +165,7 @@ void freeListFree(void *pvt,void*pmem) ppnext = pmem; *ppnext = pfl->head; pfl->head = pmem; + pfl->nBlocksAvailable++; #ifdef vxWorks FASTUNLOCK(&pfl->lock); #endif @@ -179,3 +186,10 @@ void freeListCleanup(void *pvt) } free(pvt); } + +size_t freeListItemsAvail(void *pvt) +{ + FREELISTPVT *pfl = pvt; + return pfl->nBlocksAvailable; +} + diff --git a/src/libCom/gpHash.h b/src/libCom/gpHash.h index 7d9623273..a1f320e3c 100644 --- a/src/libCom/gpHash.h +++ b/src/libCom/gpHash.h @@ -56,9 +56,9 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). #ifndef INCgpHashh #define INCgpHashh 1 -#include +#include "ellLib.h" #ifdef vxWorks -#include +#include "fast_lock.h" #endif typedef struct{ diff --git a/src/libCom/gpHash/gpHash.h b/src/libCom/gpHash/gpHash.h index 7d9623273..a1f320e3c 100644 --- a/src/libCom/gpHash/gpHash.h +++ b/src/libCom/gpHash/gpHash.h @@ -56,9 +56,9 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). #ifndef INCgpHashh #define INCgpHashh 1 -#include +#include "ellLib.h" #ifdef vxWorks -#include +#include "fast_lock.h" #endif typedef struct{ diff --git a/src/libCom/gpHash/gpHashLib.c b/src/libCom/gpHash/gpHashLib.c index ff5bd26e8..d2625ddbf 100644 --- a/src/libCom/gpHash/gpHashLib.c +++ b/src/libCom/gpHash/gpHashLib.c @@ -57,13 +57,13 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). #include #endif -#include +#include "dbDefs.h" #include #include #include -#include -#include -#include +#include "gpHash.h" +#include "ellLib.h" +#include "epicsPrint.h" typedef struct gphPvt { int tableSize; diff --git a/src/libCom/gpHashLib.c b/src/libCom/gpHashLib.c index ff5bd26e8..d2625ddbf 100644 --- a/src/libCom/gpHashLib.c +++ b/src/libCom/gpHashLib.c @@ -57,13 +57,13 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000). #include #endif -#include +#include "dbDefs.h" #include #include #include -#include -#include -#include +#include "gpHash.h" +#include "ellLib.h" +#include "epicsPrint.h" typedef struct gphPvt { int tableSize; diff --git a/src/libCom/impExpand.c b/src/libCom/impExpand.c index 69acc9fb8..01ad14ff7 100644 --- a/src/libCom/impExpand.c +++ b/src/libCom/impExpand.c @@ -20,7 +20,7 @@ of this distribution. #include #include #include -#include +#include "impLib.h" #define MAX_SIZE 256 diff --git a/src/libCom/impLib.c b/src/libCom/impLib.c index 3dd3a7a44..aec16397e 100644 --- a/src/libCom/impLib.c +++ b/src/libCom/impLib.c @@ -24,9 +24,9 @@ of this distribution. #include #include #include -#include -#include -#include +#include "ellLib.h" +#include "epicsPrint.h" +#include "impLib.h" /*private declarations*/ typedef struct pathNode { diff --git a/src/libCom/memDebugLib.c b/src/libCom/memDebugLib.c index c8700c1b2..0c1128aa2 100644 --- a/src/libCom/memDebugLib.c +++ b/src/libCom/memDebugLib.c @@ -33,8 +33,8 @@ #include #include -#include -#include +#include "epicsAssert.h" +#include "ellLib.h" #ifdef vxWorks #define LOCKS_REQUIRED @@ -42,7 +42,7 @@ #endif /*vxWorks*/ #ifdef LOCKS_REQUIRED -#include +#include "fast_lock.h" #else /*LOCKS_REQUIRED*/ #define FASTLOCK(A) #define FASTUNLOCK(A) @@ -65,7 +65,7 @@ typedef struct debugMallocHeader{ unsigned long magic; }DMH; -#include +#include "memDebugLib.h" #undef free #undef malloc #undef calloc diff --git a/src/libCom/nextFieldSubr.c b/src/libCom/nextFieldSubr.c index 45aacd55b..53fcca73d 100644 --- a/src/libCom/nextFieldSubr.c +++ b/src/libCom/nextFieldSubr.c @@ -140,8 +140,8 @@ # include # include #endif -#include -#include +#include "epicsAssert.h" +#include "tsDefs.h" /*----------------------------------------------------------------------------- diff --git a/src/libCom/osi/epicsAssert.h b/src/libCom/osi/epicsAssert.h index e7b99a8e4..9c4f8a11a 100644 --- a/src/libCom/osi/epicsAssert.h +++ b/src/libCom/osi/epicsAssert.h @@ -45,8 +45,16 @@ extern "C" { #if defined(__STDC__) || defined(__cplusplus) -extern void epicsAssert (const char *pFile, const unsigned line, - const char *pMsg, const char *pAuthorName); + extern void epicsAssert (const char *pFile, const unsigned line, + const char *pMsg, const char *pAuthorName); + +#else /*__STDC__ or __cplusplus*/ + + extern void epicsAssert (); + +#endif /*__STDC__ or __cplusplus*/ + +#if (defined(__STDC__) || defined(__cplusplus)) && !defined(VAXC) #ifdef epicsAssertAuthor #define assert(exp) \ @@ -58,7 +66,6 @@ extern void epicsAssert (const char *pFile, const unsigned line, #else /*__STDC__ or __cplusplus*/ -extern void epicsAssert (); #ifdef epicsAssertAuthor #define assert(exp) \ @@ -68,7 +75,7 @@ extern void epicsAssert (); {if (!(exp)) epicsAssert (__FILE__, __LINE__, "", 0);} #endif /* epicsAssertAuthor */ -#endif /*__STDC__ or __cplusplus*/ +#endif /* (__STDC__ or __cplusplus) and not VAXC */ #endif /* NDEBUG */ diff --git a/src/libCom/osiTime.h b/src/libCom/osiTime.h index e8b4560c6..8f8f2178e 100644 --- a/src/libCom/osiTime.h +++ b/src/libCom/osiTime.h @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.4 1996/11/02 02:06:00 jhill + * const param => #define + * * Revision 1.3 1996/09/04 21:53:36 jhill * allow use with goofy vxWorks 5.2 time spec - which has unsigned sec and * signed nsec @@ -62,20 +65,20 @@ #define nSecPerUSec 1000u #define secPerMin 60u -#include +#include "shareLib.h" class epicsShareClass osiTime { - static friend osiTime operator+ + static friend inline osiTime operator+ (const osiTime &lhs, const osiTime &rhs); - static friend osiTime operator- + static friend inline osiTime operator- (const osiTime &lhs, const osiTime &rhs); - static friend int operator>= + static friend inline int operator>= (const osiTime &lhs, const osiTime &rhs); - static friend int operator> + static friend inline int operator> (const osiTime &lhs, const osiTime &rhs); - static friend int operator<= + static friend inline int operator<= (const osiTime &lhs, const osiTime &rhs); - static friend int operator< + static friend inline int operator< (const osiTime &lhs, const osiTime &rhs); public: osiTime () : sec(0u), nSec(0u) {} diff --git a/src/libCom/osiTimer.cc b/src/libCom/osiTimer.cc index 3e722bcfc..6be8073e4 100644 --- a/src/libCom/osiTimer.cc +++ b/src/libCom/osiTimer.cc @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.6 1996/11/02 02:06:58 jhill + * fixed several subtle problems + * * Revision 1.5 1996/09/16 21:19:25 jhill * removed unused variable * @@ -62,16 +65,17 @@ #include #define epicsExportSharedSymbols -#include +#include "osiTimer.h" osiTimerQueue staticTimerQueue; +static const tsDLIterBD eol; // end of list // // osiTimer::arm() // void osiTimer::arm (const osiTime * const pInitialDelay) { - osiTimer *pTmr; + tsDLIterBD iter; # ifdef DEBUG unsigned preemptCount=0u; # endif @@ -97,27 +101,27 @@ void osiTimer::arm (const osiTime * const pInitialDelay) // // **** this should use a binary tree ???? // - tsDLIter iter (staticTimerQueue.pending); - while ( (pTmr = iter.prev()) ) { - if (pTmr->exp <= this->exp) { + iter = staticTimerQueue.pending.last(); + while (1) { + if (iter==eol) { + // + // add to the beginning of the list + // + staticTimerQueue.pending.push (*this); + break; + } + if (iter->exp <= this->exp) { + // + // add after the item found that expires earlier + // + staticTimerQueue.pending.insertAfter (*this, *iter); break; } # ifdef DEBUG preemptCount++; # endif + --iter; } - if (pTmr) { - // - // add after the item found that expires earlier - // - staticTimerQueue.pending.insertAfter (*this, *pTmr); - } - else { - // - // add to the beginning of the list - // - staticTimerQueue.pending.push (*this); - } this->state = ositPending; # ifdef DEBUG @@ -228,17 +232,11 @@ osiTime osiTimerQueue::delayToFirstExpire() const { osiTimer *pTmr; osiTime cur(osiTime::getCurrent()); - tsDLIter iter(this->pending); osiTime delay; - pTmr = iter.next(); + pTmr = this->pending.first(); if (pTmr) { - if (pTmr->exp>=cur) { - delay = pTmr->exp - cur; - } - else { - delay = osiTime(0u,0u); - } + delay = pTmr->timeRemaining(); } else { // @@ -257,7 +255,8 @@ osiTime osiTimerQueue::delayToFirstExpire() const // void osiTimerQueue::process() { - tsDLFwdIter pendIter (this->pending); + tsDLIterBD iter; + tsDLIterBD tmp; osiTime cur(osiTime::getCurrent()); osiTimer *pTmr; @@ -267,13 +266,17 @@ void osiTimerQueue::process() } this->inProcess = osiTrue; - while ( (pTmr = pendIter.next()) ) { - if (pTmr->exp >= cur) { + iter = this->pending.first(); + while ( iter!=eol ) { + if (iter->exp >= cur) { break; } - pendIter.remove(); - pTmr->state = ositExpired; - this->expired.add(*pTmr); + tmp = iter; + ++tmp; + this->pending.remove(*iter); + iter->state = ositExpired; + this->expired.add(*iter); + iter = tmp; } // @@ -320,13 +323,12 @@ void osiTimerQueue::process() // void osiTimerQueue::show(unsigned level) const { - osiTimer *pTmr; - - printf("osiTimerQueue with %d items pending and %d items expired\n", + printf("osiTimerQueue with %u items pending and %u items expired\n", this->pending.count(), this->expired.count()); - tsDLIter iter (this->pending); - while ( (pTmr = iter.next()) ) { - pTmr->show(level); + tsDLIterBD iter(this->pending.first()); + while ( iter!=eol ) { + iter->show(level); + ++iter; } } @@ -363,3 +365,55 @@ const char *osiTimer::name() const return "osiTimer"; } +// +// osiTimer::reschedule() +// +// pull this timer out of the queue ans reinstall +// it with a new experation time +// +void osiTimer::reschedule(const osiTime &newDelay) +{ + // + // signal the timer queue if this + // occurrring during the expire call + // back + // + if (this == staticTimerQueue.pExpireTmr) { + staticTimerQueue.pExpireTmr = 0; + } + switch (this->state) { + case ositPending: + staticTimerQueue.pending.remove(*this); + break; + case ositExpired: + staticTimerQueue.expired.remove(*this); + break; + case ositLimbo: + break; + default: + assert(0); + } + this->state = ositLimbo; + this->arm(&newDelay); +} + +// +// osiTimer::timeRemaining() +// +// return the number of seconds remaining before +// this timer will expire +// +osiTime osiTimer::timeRemaining() +{ + osiTime cur = osiTime::getCurrent(); + osiTime delay; + + if (this->exp>cur) { + delay = this->exp - cur; + } + else { + delay = osiTime(0u,0u); + } + return delay; +} + diff --git a/src/libCom/osiTimer.h b/src/libCom/osiTimer.h index 4fb0c7b02..ec8b95256 100644 --- a/src/libCom/osiTimer.h +++ b/src/libCom/osiTimer.h @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.3 1996/11/02 02:06:59 jhill + * fixed several subtle problems + * * Revision 1.2 1996/08/05 21:51:11 jhill * fixed delete this confusion * @@ -45,8 +48,8 @@ #ifndef osiTimerHInclude #define osiTimerHInclude -#include -#include +#include "tsDLList.h" +#include "osiTime.h" enum osiBool {osiFalse=0, osiTrue=1}; enum osiTimerState {ositPending, ositExpired, ositLimbo}; @@ -95,6 +98,18 @@ public: // virtual const osiTime delay() const; + // + // change the timers expiration to newDelay + // seconds after when reschedule() is called + // + void reschedule(const osiTime &newDelay); + + // + // return the number of seconds remaining before + // this timer will expire + // + osiTime timeRemaining(); + virtual void show (unsigned level) const; // diff --git a/src/libCom/postfix.c b/src/libCom/postfix.c index bd1719fb0..2f3092e60 100644 --- a/src/libCom/postfix.c +++ b/src/libCom/postfix.c @@ -98,8 +98,8 @@ #endif #include -#include -#include +#include "dbDefs.h" +#include "post.h" #include /* declarations for postfix */ diff --git a/src/libCom/sigPipeIgnore.h b/src/libCom/sigPipeIgnore.h new file mode 100644 index 000000000..c0cefd3c4 --- /dev/null +++ b/src/libCom/sigPipeIgnore.h @@ -0,0 +1,18 @@ + +/* + * install NOOP SIGPIPE handler + * + * escape into C to call signal because of a brain dead + * signal() func proto supplied in signal.h by gcc 2.7.2 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +void installSigPipeIgnore (void); + +#ifdef __cplusplus +} +#endif + diff --git a/src/libCom/timer/osiTimer.cpp b/src/libCom/timer/osiTimer.cpp index 3e722bcfc..6be8073e4 100644 --- a/src/libCom/timer/osiTimer.cpp +++ b/src/libCom/timer/osiTimer.cpp @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.6 1996/11/02 02:06:58 jhill + * fixed several subtle problems + * * Revision 1.5 1996/09/16 21:19:25 jhill * removed unused variable * @@ -62,16 +65,17 @@ #include #define epicsExportSharedSymbols -#include +#include "osiTimer.h" osiTimerQueue staticTimerQueue; +static const tsDLIterBD eol; // end of list // // osiTimer::arm() // void osiTimer::arm (const osiTime * const pInitialDelay) { - osiTimer *pTmr; + tsDLIterBD iter; # ifdef DEBUG unsigned preemptCount=0u; # endif @@ -97,27 +101,27 @@ void osiTimer::arm (const osiTime * const pInitialDelay) // // **** this should use a binary tree ???? // - tsDLIter iter (staticTimerQueue.pending); - while ( (pTmr = iter.prev()) ) { - if (pTmr->exp <= this->exp) { + iter = staticTimerQueue.pending.last(); + while (1) { + if (iter==eol) { + // + // add to the beginning of the list + // + staticTimerQueue.pending.push (*this); + break; + } + if (iter->exp <= this->exp) { + // + // add after the item found that expires earlier + // + staticTimerQueue.pending.insertAfter (*this, *iter); break; } # ifdef DEBUG preemptCount++; # endif + --iter; } - if (pTmr) { - // - // add after the item found that expires earlier - // - staticTimerQueue.pending.insertAfter (*this, *pTmr); - } - else { - // - // add to the beginning of the list - // - staticTimerQueue.pending.push (*this); - } this->state = ositPending; # ifdef DEBUG @@ -228,17 +232,11 @@ osiTime osiTimerQueue::delayToFirstExpire() const { osiTimer *pTmr; osiTime cur(osiTime::getCurrent()); - tsDLIter iter(this->pending); osiTime delay; - pTmr = iter.next(); + pTmr = this->pending.first(); if (pTmr) { - if (pTmr->exp>=cur) { - delay = pTmr->exp - cur; - } - else { - delay = osiTime(0u,0u); - } + delay = pTmr->timeRemaining(); } else { // @@ -257,7 +255,8 @@ osiTime osiTimerQueue::delayToFirstExpire() const // void osiTimerQueue::process() { - tsDLFwdIter pendIter (this->pending); + tsDLIterBD iter; + tsDLIterBD tmp; osiTime cur(osiTime::getCurrent()); osiTimer *pTmr; @@ -267,13 +266,17 @@ void osiTimerQueue::process() } this->inProcess = osiTrue; - while ( (pTmr = pendIter.next()) ) { - if (pTmr->exp >= cur) { + iter = this->pending.first(); + while ( iter!=eol ) { + if (iter->exp >= cur) { break; } - pendIter.remove(); - pTmr->state = ositExpired; - this->expired.add(*pTmr); + tmp = iter; + ++tmp; + this->pending.remove(*iter); + iter->state = ositExpired; + this->expired.add(*iter); + iter = tmp; } // @@ -320,13 +323,12 @@ void osiTimerQueue::process() // void osiTimerQueue::show(unsigned level) const { - osiTimer *pTmr; - - printf("osiTimerQueue with %d items pending and %d items expired\n", + printf("osiTimerQueue with %u items pending and %u items expired\n", this->pending.count(), this->expired.count()); - tsDLIter iter (this->pending); - while ( (pTmr = iter.next()) ) { - pTmr->show(level); + tsDLIterBD iter(this->pending.first()); + while ( iter!=eol ) { + iter->show(level); + ++iter; } } @@ -363,3 +365,55 @@ const char *osiTimer::name() const return "osiTimer"; } +// +// osiTimer::reschedule() +// +// pull this timer out of the queue ans reinstall +// it with a new experation time +// +void osiTimer::reschedule(const osiTime &newDelay) +{ + // + // signal the timer queue if this + // occurrring during the expire call + // back + // + if (this == staticTimerQueue.pExpireTmr) { + staticTimerQueue.pExpireTmr = 0; + } + switch (this->state) { + case ositPending: + staticTimerQueue.pending.remove(*this); + break; + case ositExpired: + staticTimerQueue.expired.remove(*this); + break; + case ositLimbo: + break; + default: + assert(0); + } + this->state = ositLimbo; + this->arm(&newDelay); +} + +// +// osiTimer::timeRemaining() +// +// return the number of seconds remaining before +// this timer will expire +// +osiTime osiTimer::timeRemaining() +{ + osiTime cur = osiTime::getCurrent(); + osiTime delay; + + if (this->exp>cur) { + delay = this->exp - cur; + } + else { + delay = osiTime(0u,0u); + } + return delay; +} + diff --git a/src/libCom/timer/osiTimer.h b/src/libCom/timer/osiTimer.h index 4fb0c7b02..ec8b95256 100644 --- a/src/libCom/timer/osiTimer.h +++ b/src/libCom/timer/osiTimer.h @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.3 1996/11/02 02:06:59 jhill + * fixed several subtle problems + * * Revision 1.2 1996/08/05 21:51:11 jhill * fixed delete this confusion * @@ -45,8 +48,8 @@ #ifndef osiTimerHInclude #define osiTimerHInclude -#include -#include +#include "tsDLList.h" +#include "osiTime.h" enum osiBool {osiFalse=0, osiTrue=1}; enum osiTimerState {ositPending, ositExpired, ositLimbo}; @@ -95,6 +98,18 @@ public: // virtual const osiTime delay() const; + // + // change the timers expiration to newDelay + // seconds after when reschedule() is called + // + void reschedule(const osiTime &newDelay); + + // + // return the number of seconds remaining before + // this timer will expire + // + osiTime timeRemaining(); + virtual void show (unsigned level) const; // diff --git a/src/libCom/tsDefs.h b/src/libCom/tsDefs.h index 5b4a86cf8..9e37b1474 100644 --- a/src/libCom/tsDefs.h +++ b/src/libCom/tsDefs.h @@ -54,9 +54,9 @@ extern "C" { #endif -#include +#include "shareLib.h" -#include /* get M_ts for this subsystem's `number' */ +#include "errMdef.h" /* get M_ts for this subsystem's `number' */ /*--------------------------------------------------------------------------- - @@ -185,7 +185,7 @@ struct tsDetail { #ifndef TS_PRIVATE_DATA epicsShareExtern char *glTsStatText[7]; #else - char *glTsStatText[] = { + epicsShareDecl char *glTsStatText[] = { /* S_ts_OK */ "success", /* S_ts_sysTimeError */ "error getting system time", /* S_ts_badTextCode */ "invalid TS_TEXT_xxx code", diff --git a/src/libCom/tsSubr.c b/src/libCom/tsSubr.c index d4148aa86..a1447ad3b 100644 --- a/src/libCom/tsSubr.c +++ b/src/libCom/tsSubr.c @@ -73,7 +73,7 @@ * time zone. * * QUICK REFERENCE -* #include +* #include "tsDefs.h" * TS_STAMP timeStamp; * void date( ) * void tsAddDouble( >pStampSum, pStamp, secAsDouble )