Do not connect unrequested.

Do not register for int/uint interrupts without need.
This commit is contained in:
zimoch
2013-09-20 12:06:56 +00:00
parent 5f6319ed3d
commit 054e74d04a

View File

@ -203,7 +203,7 @@ class AsynDriverInterface : StreamBusInterface
// local methods // local methods
void timerExpired(); void timerExpired();
bool connectToBus(const char* busname, int addr); bool connectToBus(const char* portname, int addr);
void lockHandler(); void lockHandler();
void writeHandler(); void writeHandler();
void readHandler(); void readHandler();
@ -247,7 +247,7 @@ class AsynDriverInterface : StreamBusInterface
public: public:
// static creator method // static creator method
static StreamBusInterface* getBusInterface(Client* client, static StreamBusInterface* getBusInterface(Client* client,
const char* busname, int addr, const char* param); const char* portname, int addr, const char* param);
}; };
RegisterStreamBusInterface(AsynDriverInterface); RegisterStreamBusInterface(AsynDriverInterface);
@ -331,19 +331,19 @@ AsynDriverInterface::
} }
// interface function getBusInterface(): // interface function getBusInterface():
// do we have this bus/addr ? // do we have this port/addr ?
StreamBusInterface* AsynDriverInterface:: StreamBusInterface* AsynDriverInterface::
getBusInterface(Client* client, getBusInterface(Client* client,
const char* busname, int addr, const char*) const char* portname, int addr, const char*)
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %s, %d)\n", debug ("AsynDriverInterface::getBusInterface(%s, %s, %d)\n",
client->name(), busname, addr); client->name(), portname, addr);
AsynDriverInterface* interface = new AsynDriverInterface(client); AsynDriverInterface* interface = new AsynDriverInterface(client);
if (interface->connectToBus(busname, addr)) if (interface->connectToBus(portname, addr))
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %d): " debug ("AsynDriverInterface::getBusInterface(%s, %d): "
"new Interface allocated\n", "new interface allocated\n",
busname, addr); portname, addr);
return interface; return interface;
} }
delete interface; delete interface;
@ -355,13 +355,11 @@ getBusInterface(Client* client,
bool AsynDriverInterface:: bool AsynDriverInterface::
supportsEvent() supportsEvent()
{ {
if (intrPvtInt32 || intrPvtInt32) return true; if (intrPvtInt32 || intrPvtUInt32) return true;
// look for interfaces for events // look for interfaces for events
asynInterface* pasynInterface; asynInterface* pasynInterface;
connectToAsynPort();
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynInt32Type, true); asynInt32Type, true);
if (pasynInterface) if (pasynInterface)
@ -378,7 +376,7 @@ supportsEvent()
intrCallbackInt32, this, &intrPvtInt32); intrCallbackInt32, this, &intrPvtInt32);
return true; return true;
} }
error("%s: bus does not allow to register for " error("%s: port does not allow to register for "
"Int32 interrupts: %s\n", "Int32 interrupts: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
pasynInt32 = NULL; pasynInt32 = NULL;
@ -404,7 +402,7 @@ supportsEvent()
intrCallbackUInt32, this, 0xFFFFFFFF, &intrPvtInt32); intrCallbackUInt32, this, 0xFFFFFFFF, &intrPvtInt32);
return true; return true;
} }
error("%s: bus does not allow to register for " error("%s: port does not allow to register for "
"UInt32 interrupts: %s\n", "UInt32 interrupts: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
pasynUInt32 = NULL; pasynUInt32 = NULL;
@ -424,24 +422,26 @@ supportsAsyncRead()
if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser, if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser,
intrCallbackOctet, this, &intrPvtOctet) != asynSuccess) intrCallbackOctet, this, &intrPvtOctet) != asynSuccess)
{ {
error("%s: bus does not support asynchronous input: %s\n", const char *portname;
clientName(), pasynUser->errorMessage); pasynManager->getPortName(pasynUser, &portname);
error("%s: asyn port %s does not support asynchronous input: %s\n",
clientName(), portname, pasynUser->errorMessage);
return false; return false;
} }
return true; return true;
} }
bool AsynDriverInterface:: bool AsynDriverInterface::
connectToBus(const char* busname, int addr) connectToBus(const char* portname, int addr)
{ {
asynStatus status = pasynManager->connectDevice(pasynUser, busname, addr); asynStatus status = pasynManager->connectDevice(pasynUser, portname, addr);
debug("%s: AsynDriverInterface::connectToBus(%s, %d): " debug("%s: AsynDriverInterface::connectToBus(%s, %d): "
"pasynManager->connectDevice(%p, %s, %d) = %s\n", "pasynManager->connectDevice(%p, %s, %d) = %s\n",
clientName(), busname, addr, pasynUser,busname, addr, clientName(), portname, addr, pasynUser,portname, addr,
asynStatusStr[status]); asynStatusStr[status]);
if (status != asynSuccess) if (status != asynSuccess)
{ {
// asynDriver does not know this busname/address // asynDriver does not know this portname/address
return false; return false;
} }
@ -452,8 +452,8 @@ connectToBus(const char* busname, int addr)
asynCommonType, true); asynCommonType, true);
if (!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynCommon interface\n", error("%s: asyn port %s does not support asynCommon interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface); pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface);
@ -464,8 +464,8 @@ connectToBus(const char* busname, int addr)
asynOctetType, true); asynOctetType, true);
if (!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynOctet interface\n", error("%s: asyn port %s does not support asynOctet interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface); pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface);
@ -596,21 +596,49 @@ connectToAsynPort()
void AsynDriverInterface:: void AsynDriverInterface::
lockHandler() lockHandler()
{ {
asynStatus status;
int connected; int connected;
debug("AsynDriverInterface::lockHandler(%s)\n", debug("AsynDriverInterface::lockHandler(%s)\n",
clientName()); clientName());
pasynManager->blockProcessCallback(pasynUser, false);
connected = connectToAsynPort(); status = pasynManager->isConnected(pasynUser, &connected);
lockCallback(connected ? StreamIoSuccess : StreamIoFault); if (status != asynSuccess)
{
error("%s: pasynManager->isConnected() failed: %s\n",
clientName(), pasynUser->errorMessage);
lockCallback(StreamIoFault);
return;
}
if (!connected) lockCallback(StreamIoFault);
status = pasynManager->blockProcessCallback(pasynUser, false);
if (status != asynSuccess)
{
error("%s: pasynManager->blockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
lockCallback(StreamIoFault);
return;
}
lockCallback(StreamIoSuccess);
} }
// interface function: we don't need exclusive access any more // interface function: we don't need exclusive access any more
bool AsynDriverInterface:: bool AsynDriverInterface::
unlock() unlock()
{ {
asynStatus status;
debug("AsynDriverInterface::unlock(%s)\n", debug("AsynDriverInterface::unlock(%s)\n",
clientName()); clientName());
pasynManager->unblockProcessCallback(pasynUser, false); status = pasynManager->unblockProcessCallback(pasynUser, false);
if (status != asynSuccess)
{
error("%s: pasynManager->unblockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
lockCallback(StreamIoFault);
return false;
}
return true; return true;
} }
@ -661,10 +689,10 @@ writeHandler()
// thus do not use pasynOctet->flush() // thus do not use pasynOctet->flush()
do { do {
char buffer [256]; char buffer [256];
size_t received = sizeof(buffer); size_t received = 0;
int eomReason = 0; int eomReason = 0;
status = pasynOctet->read(pvtOctet, pasynUser, status = pasynOctet->read(pvtOctet, pasynUser,
buffer, received, &received, &eomReason); buffer, sizeof(buffer), &received, &eomReason);
if (received == 0) break; if (received == 0) break;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
if (received) debug("AsynDriverInterface::writeHandler(%s): flushing %ld bytes: \"%s\"\n", if (received) debug("AsynDriverInterface::writeHandler(%s): flushing %ld bytes: \"%s\"\n",