Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
time2ntp() catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver authored and jerzyjamroz committed Apr 14, 2020
1 parent ef2d697 commit 84fd380
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions evrApp/src/ntpShm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,43 +265,47 @@ static void ntpshmhooks(initHookState state)

void time2ntp(const char* evrname, int segid, int event)
{
if(event==0)
event = MRF_EVENT_TS_COUNTER_RST;
else if(event<=0 || event >255) {
fprintf(stderr, "Invalid 1Hz event # %d\n", event);
return;
}
if(segid<0 || segid>4) {
fprintf(stderr, "Invalid segment ID %d\n", segid);
return;
}
mrf::Object *obj = mrf::Object::getObject(evrname);
if(!obj) {
fprintf(stderr, "Unknown EVR: %s\n", evrname);
return;
}
try {
if(event==0)
event = MRF_EVENT_TS_COUNTER_RST;
else if(event<=0 || event >255) {
fprintf(stderr, "Invalid 1Hz event # %d\n", event);
return;
}
if(segid<0 || segid>4) {
fprintf(stderr, "Invalid segment ID %d\n", segid);
return;
}
mrf::Object *obj = mrf::Object::getObject(evrname);
if(!obj) {
fprintf(stderr, "Unknown EVR: %s\n", evrname);
return;
}

EVR *evr = dynamic_cast<EVR*>(obj);
if(!evr) {
fprintf(stderr, "\"%s\" is not an EVR\n", evrname);
return;
}
EVR *evr = dynamic_cast<EVR*>(obj);
if(!evr) {
fprintf(stderr, "\"%s\" is not an EVR\n", evrname);
return;
}

epicsThreadOnce(&ntponce, &ntpshminit, 0);
epicsThreadOnce(&ntponce, &ntpshminit, 0);

epicsMutexMustLock(ntpShm.ntplock);
epicsMutexMustLock(ntpShm.ntplock);

if(ntpShm.evr) {
epicsMutexUnlock(ntpShm.ntplock);
fprintf(stderr, "ntpShm already initialized.\n");
return;
}
if(ntpShm.evr) {
epicsMutexUnlock(ntpShm.ntplock);
fprintf(stderr, "ntpShm already initialized.\n");
return;
}

ntpShm.event = event;
ntpShm.evr = evr;
ntpShm.segid = segid;
ntpShm.event = event;
ntpShm.evr = evr;
ntpShm.segid = segid;

epicsMutexUnlock(ntpShm.ntplock);
epicsMutexUnlock(ntpShm.ntplock);
} catch(std::exception& e) {
fprintf(stderr, "Error: %s\n", e.what());
}
}

static const iocshArg time2ntpArg0 = { "evr name",iocshArgString};
Expand Down

0 comments on commit 84fd380

Please sign in to comment.