/*============================================================================= Name: ffUtil.c ffGetThreadEnumById - return thread enumeration given thread id ffGetThreadEnumByName - return thread enumeration given thread name ffGetThreadDestinationById - return the destination value for the given thread id ffGetJobEnumByName - return the ffJobs_as enum given the job name ffGetJobEnumByThreadEnum - return the ffJobs_as enum given the thread enum ffGetJobEnum - return the ffJobs_as enum for the current job ffPrintMsgheader - print msgheader Abs: general purpose utilities for the ff-aware threads reference document: LCLS Controls | Facilities | FF-Aware IOC | General Purpose Utilities Auth: 09-SEP-2004, diane fairley (DFAIRLEY): created Rev: 02 feb 2005, Debbie Rogind 28 Jul 2005, Kristi Luchini added ffPrintMsgheader -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: 28-Jul-2008, K. Luchini (LUCHINI): Added header file msgQUtil.h for messageQRelease() 14-Mar-2004, Ron MacKenzie: Change strncmp in ffGetJobEnumByName() to strcmp so we can support 3 character job names, not just 4 character ones. 08-Mar-2004, Ron MacKenzie: Change ffGetJobIndexByName() to ffGetJobEnumByName() and have it return an enum instead of an int. 09-DEC-2004, diane fairley: added header, changed a lot to meet new coding standards =============================================================================*/ #include "debugPrint.h" #ifdef DEBUG_PRINT int ffUtilFlag = DP_ERROR; #endif /* c includes */ #include /* getenv */ #include /* memcpy */ /* ff IOC includes */ #include "ffGlob.h" /* ffThreads_as, ffIocName_a, ffProxyIPAddrs_a */ /* function prototypes */ #include "msgQUtil.h" /* for messageQRelease() */ /*=========================================================== Name: ffGetThreadEnumByTid Abs: get the thread enumeration for the thread indicated by tid_ps Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- Args: const epicsThreadId tid_ps read only ptr to the epics thread id of the thread Rem: returns index into ffThreads_as array based on thread id Side: if the input poiner is NULL use epicsThreadGetIdSelf Ret: ffThread_te - the enumeration of the thread ===========================================================*/ ffThread_te ffGetThreadEnumByTid(const epicsThreadId tid_ps) { unsigned short cnt; epicsThreadId t_ps; t_ps = tid_ps; if (t_ps==NULL) { t_ps = epicsThreadGetIdSelf(); } for (cnt=0; cnt < ffEnd; cnt++) { /* search for the thread id */ if (ffThreads_as[cnt].tid_ps!=NO_THREAD) { if (ffThreads_as[cnt].tid_ps == t_ps) { return cnt; } } } return ffInvalid; /* error condition */ } /*=========================================================== Name: ffGetThreadEnumByName Abs: get the thread enumeration for the thread indicated by name Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- const char * name_c read only ptr to the epics name of the thread Rem: return index into ffThreads_as array based on thread name from epicsThreadGetName Side: if the input ptr is NULL, use epicsThreadGetNameSelf Ret: ffThread_te - the enumeration of the thread ===========================================================*/ ffThread_te ffGetThreadEnumByName(const char* name_c) { unsigned short i; char tName[MAX_THREADNAME_SIZE]; const char * inName_c; if (name_c == NULL) inName_c = epicsThreadGetNameSelf(); else inName_c = name_c; for (i=0; i < ffEnd; i++) { /* search for the name passed in */ epicsThreadGetName(ffThreads_as[i].tid_ps, (char *)&tName, MAX_THREADNAME_SIZE ); if (strcmp((char *)&tName, inName_c)==0) { return i; } } return ffInvalid; /* error condition */ } /*============================================================================= Name: ffStopThread Abs: Terminate thread by setting the active flag to false Args: Type Name Access Description ------ ----------- ---------- ---------------------------- ffThread_te thread_e read-only Index to facility Rem: The purpose of this function is to set the thread active flag false. This which will break the thread out of it's WHILE loop and cause it to begin the termination process. Side: The thread active flag is set to false. Ret: None ===============================================================================*/ void ffStopThread(ffThread_te thread_e) { if (thread_e && (thread_esource[0], msgheader->source[1],msgheader->source[2], msgheader->source[3])); DEBUGPRINT(DP_DEBUG, debugFlag, ("\tthe dest: %c%c%c%c\n",msgheader->dest[0], msgheader->dest[1],msgheader->dest[2], msgheader->dest[3])); DEBUGPRINT(DP_DEBUG, debugFlag, ("\tthe timestamp[0]: 0x%.8lx\n",msgheader->timestamp[0])); DEBUGPRINT(DP_DEBUG, debugFlag, ("\tthe timestamp[1]: 0x%.8lx\n",msgheader->timestamp[1])); DEBUGPRINT(DP_DEBUG, debugFlag, ("\tthe func: %x\n",msgheader->func)); DEBUGPRINT(DP_DEBUG, debugFlag, ("\tthe datalen: %u\n",msgheader->datalen)); return; } #endif