38 lines
926 B
C++
38 lines
926 B
C++
#include "CoreThing.h"
|
|
|
|
CoreThing::CoreThing(
|
|
// Participant *client,
|
|
unsigned char networkId, unsigned char thingId, unsigned char thingType) {
|
|
// this->client = client;
|
|
this->id = thingId;
|
|
this->type = thingType;
|
|
this->networkId = networkId;
|
|
this->Init();
|
|
CoreThing::Add(this);
|
|
}
|
|
|
|
void CoreThing::Init() {}
|
|
|
|
CoreThing *CoreThing::allThings[256] = {nullptr};
|
|
|
|
CoreThing *CoreThing::Get(unsigned char networkId, unsigned char thingId) {
|
|
for (unsigned char ix = 0; ix < 256; ix++) {
|
|
CoreThing *thing = allThings[ix];
|
|
if (thing == nullptr)
|
|
continue;
|
|
if (thing->networkId == networkId && thing->id == thingId)
|
|
return thing;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
bool CoreThing::Add(CoreThing *newThing) {
|
|
for (unsigned char ix = 0; ix < 256; ix++) {
|
|
CoreThing *thing = allThings[ix];
|
|
if (thing == nullptr) {
|
|
allThings[ix] = newThing;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
} |