/* * Error.c * * Created by Stephen Norum. * Copyright 2007 Stanford Linear Accelerator Center. All rights reserved. * */ #include #include #include #include "mpsCommon.h" #include "privateMpsError.h" struct threadErrorStruct { epicsThreadId id; char *string; }; typedef struct threadErrorStruct threadError; static threadError errors[mpsMaxThreadErrorCount]; /* Will only work for the first mpsMaxThreadErrorCount threads */ void mpsSetLastErrorString(char *errorString) { unsigned int i; epicsThreadId currentThreadId; currentThreadId = epicsThreadGetIdSelf(); for (i = 0; i < sizeof(errors)/sizeof(errors[0]); i++) { if (epicsThreadIsEqual(errors[i].id, currentThreadId)) { errors[i].string = errorString; return; } } errors[i - 1].id = currentThreadId; errors[i - 1].string = errorString; } char * MPSGetLastErrorString() { unsigned int i; epicsThreadId currentThreadId; currentThreadId = epicsThreadGetIdSelf(); for (i = 0; i < sizeof(errors)/sizeof(errors[0]); i++) { if (epicsThreadIsEqual(errors[i].id, currentThreadId)) { return errors[i].string; } } return ""; } int mpsInitializeError() { static int hasInitialized = FALSE; unsigned int i; if (hasInitialized) { return MPS_SUCCESS; } for (i = 0; i < sizeof(errors)/sizeof(errors[0]); i++) { errors[i].id = 0; errors[i].string = ""; } hasInitialized = TRUE; return MPS_SUCCESS; } epicsRegisterFunction(MPSGetLastErrorString);