/* * Get value from a channel, with timeout. */ epicsShareFunc pvStat seq_pvGetTmo(SS_ID ss, CH_ID chId, enum compType compType, double tmo) { PROG *sp = ss->prog; CHAN *ch = sp->chan + chId; pvStat status; PVREQ *req; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); /* Anonymous PV and safe mode, just copy from shared buffer. Note that completion is always immediate, so no distinction between SYNC and ASYNC needed. See also pvGetComplete. */ if (optTest(sp, OPT_SAFE) && !dbch) { /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); return pvStatOK; } /* No named PV and traditional mode => user error */ if (!dbch) { errlogSevPrintf(errlogMajor, "pvGet(%s): user error (not assigned to a PV)\n", ch->varName ); return pvStatERROR; } if (compType == DEFAULT) { compType = optTest(sp, OPT_ASYNC) ? ASYNC : SYNC; } status = check_pending(pvEventGet, ss, ss->getReq + chId, ch->varName, dbch, meta, compType, tmo); if (status != pvStatOK) return status; /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->getReq[chId] == NULL); ss->getReq[chId] = req; /* Perform the PV get operation with a callback routine specified. Requesting more than db channel has available is ok. */ status = pvVarGetCallback( &dbch->pvid, /* PV id */ ch->type->getType, /* request type */ ch->count, /* element count */ req); /* user arg */ if (status != pvStatOK) { pv_call_failure(dbch, meta, status); errlogSevPrintf(errlogFatal, "pvGet(var %s, pv %s): pvVarGetCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); ss->getReq[chId] = NULL; /* cancel the request */ freeListFree(sp->pvReqPool, req); check_connected(dbch, meta); return status; } /* Synchronous: wait for completion */ if (compType == SYNC) { pvSysFlush(sp->pvSys); status = wait_complete(pvEventGet, ss, ss->getReq + chId, dbch, meta, tmo); if (status != pvStatOK) return status; if (optTest(sp, OPT_SAFE)) /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); } return pvStatOK; }
/* * Get value from a channel. * TODO: add optional timeout argument. */ epicsShareFunc pvStat epicsShareAPI seq_pvGet(SS_ID ss, VAR_ID varId, enum compType compType) { SPROG *sp = ss->sprog; CHAN *ch = sp->chan + varId; pvStat status; PVREQ *req; epicsEventId getSem = ss->getSemId[varId]; DBCHAN *dbch = ch->dbch; PVMETA *meta = metaPtr(ch,ss); double tmo = seq_sync_timeout; /* Anonymous PV and safe mode, just copy from shared buffer. Note that completion is always immediate, so no distinction between SYNC and ASYNC needed. See also pvGetComplete. */ if ((sp->options & OPT_SAFE) && !dbch) { /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); return pvStatOK; } /* No named PV and traditional mode => user error */ if (!dbch) { errlogSevPrintf(errlogMajor, "pvGet(%s): user error (variable not assigned)\n", ch->varName ); return pvStatERROR; } if (compType == DEFAULT) { compType = (sp->options & OPT_ASYNC) ? ASYNC : SYNC; } if (compType == SYNC) { double before, after; pvTimeGetCurrentDouble(&before); switch (epicsEventWaitWithTimeout(getSem, tmo)) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status) return epicsEventSignal(getSem), status; pvTimeGetCurrentDouble(&after); tmo -= (after - before); break; case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "pvGet(ss %s, var %s, pv %s): failed (timeout " "waiting for other get requests to finish)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->getReq[varId] = NULL; epicsEventSignal(getSem); errlogSevPrintf(errlogFatal, "pvGet: epicsEventWaitWithTimeout() failure\n"); return pvStatERROR; } } else if (compType == ASYNC) { switch (epicsEventTryWait(getSem)) { case epicsEventWaitOK: if (ss->getReq[varId] != NULL) { /* previous request timed out but user did not call pvGetComplete */ ss->getReq[varId] = NULL; } status = check_connected(dbch, meta); if (status) return epicsEventSignal(getSem), status; break; case epicsEventWaitTimeout: errlogSevPrintf(errlogMajor, "pvGet(ss %s, var %s, pv %s): user error " "(there is already a get pending for this variable/" "state set combination)\n", ss->ssName, ch->varName, dbch->dbName ); return pvStatERROR; case epicsEventWaitError: /* try to recover */ ss->getReq[varId] = NULL; epicsEventSignal(getSem); errlogSevPrintf(errlogFatal, "pvGet: epicsEventTryWait() failure\n"); return pvStatERROR; } } /* Allocate and initialize a pv request */ req = (PVREQ *)freeListMalloc(sp->pvReqPool); req->ss = ss; req->ch = ch; assert(ss->getReq[varId] == NULL); ss->getReq[varId] = req; /* Perform the PV get operation with a callback routine specified. Requesting more than db channel has available is ok. */ status = pvVarGetCallback( dbch->pvid, /* PV id */ ch->type->getType, /* request type */ ch->count, /* element count */ seq_get_handler, /* callback handler */ req); /* user arg */ if (status != pvStatOK) { meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "get failure"; errlogSevPrintf(errlogFatal, "pvGet(var %s, pv %s): pvVarGetCallback() failure: %s\n", ch->varName, dbch->dbName, pvVarGetMess(dbch->pvid)); ss->getReq[varId] = NULL; freeListFree(sp->pvReqPool, req); epicsEventSignal(getSem); check_connected(dbch, meta); return status; } /* Synchronous: wait for completion */ if (compType == SYNC) { epicsEventWaitStatus event_status; pvSysFlush(sp->pvSys); event_status = epicsEventWaitWithTimeout(getSem, tmo); ss->getReq[varId] = NULL; epicsEventSignal(getSem); switch (event_status) { case epicsEventWaitOK: status = check_connected(dbch, meta); if (status) return status; if (sp->options & OPT_SAFE) /* Copy regardless of whether dirty flag is set or not */ ss_read_buffer(ss, ch, FALSE); break; case epicsEventWaitTimeout: meta->status = pvStatTIMEOUT; meta->severity = pvSevrMAJOR; meta->message = "get completion timeout"; return meta->status; case epicsEventWaitError: meta->status = pvStatERROR; meta->severity = pvSevrMAJOR; meta->message = "get completion failure"; return meta->status; } } return pvStatOK; }