DRDE/AusRegCliever/server/mdState.cpp

153 lines
4.2 KiB
C++

#include "cliever-md.h"
#include "masterDaemon.h"
class mdResponse;
using namespace std;
mdOperationalDataElement::mdOperationalDataElement() {
stringValue = std::string("");
ode = new mdODEPOD;
ode->bitValue = false;
ode->realValue = 0.0;
ode->intValue = 0;
ode->realtime = true;
ode->acType = 's';
ode->sValSize = ode->sVal = 0;
}
mdOperationalDataElement::mdOperationalDataElement(mdODEPOD *shared) {
stringValue = std::string("");
ode = shared;
}
void mdOperationalDataElement::source(mdResponse *mdr) {
int sValSize;
mdODEPOD *flat = (mdODEPOD *)&mdr->reply.dg.payLoad[0];
memcpy(flat,&this->ode,sizeof(mdODEPOD));
strcpy(&flat->sVal,this->stringValue.c_str());
sValSize = this->stringValue.length();
flat->sValSize = sValSize + 1;
mdr->reply.dg.hdr.primeOffset = mdr->reply.dg.hdr.payloadSize = sizeof(mdODEPOD) + sValSize;
}
std::string mdState::create(int deviceHandle,std::string &typeSig,std::string &dataName) {
mdOperationalDataElement *newName;
std::string rc("OK");
if (thisConfig->allClients[deviceHandle]->devType == MDDEV_CLIENT) {
if ( thisConfig->allEPPPeers[deviceHandle]->state.localODEs.find(dataName) !=
thisConfig->allEPPPeers[deviceHandle]->state.localODEs.end() ) {
rc = std::string("Dataname already defined.");
}
else {
newName = &(thisConfig->allEPPPeers[deviceHandle]->state.localODEs[dataName]);
newName->ode->acType = typeSig[0];
}}
else if (thisConfig->allClients[deviceHandle]->devType == MACHINE)
{
if ( theMachine->state.localODEs.find(dataName) !=
theMachine->state.localODEs.end() ) {
rc = std::string("Dataname already defined.");
}
else {
newName = &(theMachine->state.localODEs[dataName]);
newName->ode->acType = typeSig[0];
}
}
else rc = NOT_OK;
if (rc == "OK")
theseLogs->logNdebug(MAX_DEBUG/1000,2,"New ODE: '%s' defined by device: %d.",dataName.c_str(),deviceHandle);
else
theseLogs->logNdebug(0,3,"Failed New ODE: '%s' attemptd by device: %d: %s.",dataName.c_str(),deviceHandle,rc.c_str());
return rc;
}
void *mdState::get(int deviceHandle,std::string &dataname) {
map<string, void *> returnData;
return NULL;
}
std::string mdState::set(int deviceHandle,std::string &inbound) {
std::string dataname("dataname"),svalue("sValue"),rc("NOT OK");
return rc;
}
void mdState::registerData(const char *dataName,const mdIncoming &thisOne) {
const char *msg;
char *name;
int value = OK;
std::string arg = std::string(dataName);
std::map<int,mdACClient*>::iterator iter = thisConfig->allClients.find(thisOne.dg.hdr.handle);
mdResponse *result = new mdResponse(thisService->bg,thisOne.ip);
mdOperationalDataElement sourced=NULL;
result->reply.dg.hdr = thisOne.dg.hdr;
result->dCat = DV_MDQUERY;
if( iter == thisConfig->allClients.end() ) {
theseLogs->logN(1,"Query for device whose handle (%d) absent, ignored.", thisOne.dg.hdr.handle );
value = MDERR_NOTREADY;
goto done;
}
result->mdStdDevIdx = iter->second->mdStdDevIdx;
if (dataName[0] != '_') {
} else {
if (localODEs.empty()) {
theseLogs->logN(1,"attempt to register '%s' but device not ready to accept data element registration.",dataName);
value = MDERR_NOTREADY;
goto done;
}
if( localODEs.find(arg) == localODEs.end() ) {
theseLogs->logN(1,"attempt to register '%s' which does not yet exist.",dataName);
value = MDERR_MISSING;
goto done;
}
}
sourced = localODEs[arg];
done:
if (value == OK) {
msg = dataName;
result->reply.dg.hdr.dgType.value = 1;
}
else msg = thisConfig->err[value];
result->reply.dg.hdr.msgType = MDDG_MDQUERY;
name = (char *)(&result->reply.dg.payLoad[0] + result->reply.dg.hdr.primeOffset);
strcpy(name,msg);
result->reply.dg.hdr.payloadSize = result->reply.dg.hdr.primeOffset + strlen(name) + 1;
result->send();
}