BMutex olock;
};
BoapnsObject::BoapnsObject(BoapServer& server, BString name) : Boapns::BoapnsService(server, name){
onextId = 0;
#ifdef ZAP
oservices.append(Boapns::BoapEntry("test1", 0, 0, 1));
oservices.append(Boapns::BoapEntry("test2", 0, 0, 2));
oservices.append(Boapns::BoapEntry("test3", 0, 0, 3));
#endif
}
void BoapnsObject::entryPrint(Boapns::BoapEntry entry){
BIter i;
BString al;
for(entry.addressList.start(i); !entry.addressList.isEnd(i); entry.addressList.next(i)){
if(al.len())
al = al + ",";
al = al + entry.addressList[i];
}
printf("%-32.32s %s:%d %d\n", entry.name.retStr(), al.retStr(), entry.port, entry.service);
}
BError BoapnsObject::getVersion(BString& version){
BError err;
version = "1.0.0";
return err;
}
BError BoapnsObject::getEntryList(BList<Boapns::BoapEntry>& entryList){
BError err;
dprintf("%s:\n", __FUNCTION__);
olock.lock();
entryList = oservices;
olock.unlock();
dprintf("%s: End\n", __FUNCTION__);
return err;
}
BError BoapnsObject::getEntry(BString name, Boapns::BoapEntry& entry){
BError err;
BIter i;
dprintf("BoapnsObject::getEntry: %s\n", name.retStr());
olock.lock();
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
if(oservices[i].name == name){
entry = oservices[i];
olock.unlock();
return err;
}
}
olock.unlock();
err.set(1, BString("Boapns: No such service: ") + name);
return err;
}
BError BoapnsObject::addEntry(Boapns::BoapEntry entry){
BError err;
BIter i;
dprintf("BoapnsObject::addEntry: %s %s:%d %d\n", entry.name.retStr(), entry.addressList[0].retStr(), entry.port, entry.service);
olock.lock();
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
if(oservices[i].name == entry.name){
oservices.del(i);
break;
}
}
oservices.append(entry);
olock.unlock();
#if DEBUG
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
entryPrint(oservices[i]);
}
#endif
return err;
}
BError BoapnsObject::delEntry(BString name){
BError err;
BIter i;
dprintf("%s:\n", __FUNCTION__);
olock.lock();
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
if(oservices[i].name == name){
oservices.del(i);
break;
}
}
olock.unlock();
return err;
}
BError BoapnsObject::getNewName(BString& name){
BError err;
name = BString("object") + onextId++;
return err;
}
void BoapnsObject::pingAll(){
BIter i;
BError err;
BoapClientObject obj;
printf("PingAll\n");
olock.lock();
#ifdef ZAP
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
printf("Ping: %s\n", oservices[i].name.retStr());
obj.connectService(oservices[i].name);
printf("Ping: Do %s\n", oservices[i].name.retStr());
err = obj.ping();
printf("PinRes: %d\n", err.getErrorNo());
}
#endif
olock.unlock();
}
BError BoapnsObject::processEvent(BoapPacket& rx){
BError err;
BIter i;
BSocketAddressINET nadd;