Privacy and Security Notice

Archived Messages for CDEV_1997@cebaf.gov: code question?

code question?

Kim Gillies (gillies@noao.edu)
Thu, 08 May 1997 14:28:45 -0700

All,
I've been tracing the code trying to figure out why something of mine fails
and I found the following code that seems like it might not be doing the
correct thing.
The following is cdevDevice::attachPtr. When I trace into the code
the device class is looked up. If it is found and it is not a collection
a new cdevDevice is created in "system". Then it goes to the next
line and creates another cdevDevice (the //unknown device comment).
Is this really the desired behavior? I'm wondering if there should be
a return inside the "CDEV_SUCCESS" clause or an "else" for the no success
case.

Just wondering,
Kim

cdevDevice *
cdevDevice::attachPtr (char *name, cdevSystem& system)
{
cdevDevice *dev = 0;
cdevService *service = 0;

if (system.deviceCreated (name)){
dev = system.device (name);
dev->refCount_ ++;
}
else{
cdevData data, result;
data.insert("device",name);
int status = (system.nameServer()).send("queryClass",data,result);
if (status==CDEV_SUCCESS) { // device is defined in directory
char *name;
result.find("value",(void* &)name);
if (::strcmp(name,"collection")==0) // is it a collection?
dev = new cdevCollection (name, system); // yes
else
dev = new cdevDevice (name, system); // no, it is a known simple device
}
dev = new cdevDevice (name, system); // unknown device
}
return dev;
}