- Switched motor to hdb
- Changes to Hipadaba - Added project to histogram memory code - Started regression testing code - Added hill climbing as optimization method to optimise
This commit is contained in:
473
sicshipadaba.c
473
sicshipadaba.c
@@ -54,6 +54,7 @@ pHdbCallback MakeCheckPermissionCallback(int priv){
|
||||
if(testPriv == NULL){
|
||||
return NULL;
|
||||
}
|
||||
*testPriv = priv;
|
||||
return MakeHipadabaCallback(SICSCheckPermissionCallback, testPriv,free,-1,-1);
|
||||
}
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
@@ -352,6 +353,117 @@ pHdbCallback MakeFloatRangeCallback(double min, double max){
|
||||
return MakeHipadabaCallback(SICSFloatRangeCallback, range,
|
||||
free,-1,-1);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int MemReadCallback(void *userData, void *callData, pHdb node,
|
||||
hdbValue v){
|
||||
float *value = NULL;
|
||||
|
||||
value = (float *)userData;
|
||||
if(value != NULL){
|
||||
v.dataType = HIPFLOAT;
|
||||
v.v.doubleValue = (float) *value;
|
||||
node->value.v.doubleValue = (double)*value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int MemGenReadCallback(void *userData, void *callData, pHdb node,
|
||||
hdbValue v){
|
||||
switch(node->value.dataType){
|
||||
case HIPINT:
|
||||
node->value.v.intValue = *(int *)userData;
|
||||
break;
|
||||
case HIPFLOAT:
|
||||
node->value.v.doubleValue = *(double *)userData;
|
||||
break;
|
||||
case HIPTEXT:
|
||||
if(node->value.v.text != NULL){
|
||||
free(node->value.v.text);
|
||||
}
|
||||
node->value.v.text = strdup((char *)userData);
|
||||
break;
|
||||
case HIPINTAR:
|
||||
memcpy(&node->value.v.intArray,userData,
|
||||
node->value.arrayLength *sizeof(int));
|
||||
break;
|
||||
case HIPFLOATAR:
|
||||
memcpy(&node->value.v.floatArray,userData,
|
||||
node->value.arrayLength *sizeof(double));
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pHdbCallback MakeMemGenReadCallback(void *address){
|
||||
return MakeHipadabaCallback(MemReadCallback, address,
|
||||
NULL,-1,-1);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pHdbCallback MakeMemReadCallback(float *address){
|
||||
return MakeHipadabaCallback(MemReadCallback, address,
|
||||
NULL,-1,-1);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int MemSetCallback(void *userData, void *callData, pHdb node,
|
||||
hdbValue v){
|
||||
float *value = NULL;
|
||||
|
||||
value = (float *)userData;
|
||||
if(value != NULL){
|
||||
*value = (float)v.v.doubleValue;
|
||||
}
|
||||
UpdateHipadabaPar(node,v,callData);
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int MemGenSetCallback(void *userData, void *callData, pHdb node,
|
||||
hdbValue v){
|
||||
const char *pPtr = NULL;
|
||||
|
||||
if(v.dataType != node->value.dataType){
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch(node->value.dataType){
|
||||
case HIPINT:
|
||||
memcpy(userData,&v.v.intValue,sizeof(int));
|
||||
break;
|
||||
case HIPFLOAT:
|
||||
memcpy(userData,&v.v.doubleValue,sizeof(double));
|
||||
break;
|
||||
case HIPTEXT:
|
||||
strncpy((char *)userData,(const char *)v.v.text,
|
||||
node->value.arrayLength);
|
||||
break;
|
||||
case HIPINTAR:
|
||||
memcpy(userData,&v.v.intArray,node->value.arrayLength*sizeof(int));
|
||||
break;
|
||||
case HIPFLOATAR:
|
||||
memcpy(userData,&v.v.floatArray,
|
||||
node->value.arrayLength*sizeof(double));
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
UpdateHipadabaPar(node,v,callData);
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pHdbCallback MakeMemSetCallback(float *address){
|
||||
return MakeHipadabaCallback(MemSetCallback, address,
|
||||
NULL,-1,-1);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
pHdbCallback MakeMemGenSetCallback(void *address){
|
||||
return MakeHipadabaCallback(MemSetCallback, address,
|
||||
NULL,-1,-1);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void killHdbValue(void *pData){
|
||||
hdbValue *v = NULL;
|
||||
@@ -384,7 +496,7 @@ static int SICSIntFixedCallback(void *userData, void *callData, pHdb node,
|
||||
return SICSCBBADFIXED;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pHdbCallback MakeIntFixedCallback(long *data, int length){
|
||||
pHdbCallback MakeIntFixedCallback(int *data, int length){
|
||||
pHdbCallback result = NULL;
|
||||
hdbValue *v = NULL;
|
||||
|
||||
@@ -394,11 +506,11 @@ pHdbCallback MakeIntFixedCallback(long *data, int length){
|
||||
}
|
||||
v->dataType = HIPINTAR;
|
||||
v->arrayLength = length;
|
||||
v->v.intArray = malloc(length*sizeof(long));
|
||||
v->v.intArray = malloc(length*sizeof(int));
|
||||
if(v->v.intArray == NULL){
|
||||
return NULL;
|
||||
}
|
||||
memcpy(v->v.intArray,data,length*sizeof(long));
|
||||
memcpy(v->v.intArray,data,length*sizeof(int));
|
||||
return MakeHipadabaCallback(SICSIntFixedCallback, v,
|
||||
killHdbValue,-1,-1);
|
||||
}
|
||||
@@ -462,6 +574,39 @@ pHdb MakeSICSHdbDriv(char *name, int priv, void *sicsObject, int dataType){
|
||||
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
pHdb MakeSICSMemPar(char *name, int priv, float *address){
|
||||
pHdb result = NULL;
|
||||
pHdbCallback pHcb = NULL;
|
||||
|
||||
result = MakeHipadabaNode(name,HIPFLOAT,1);
|
||||
if(result == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pHcb = MakeCheckPermissionCallback(priv);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(result);
|
||||
return NULL;
|
||||
}
|
||||
AppendHipadabaCallback(result,HCBSET,pHcb);
|
||||
|
||||
pHcb = MakeMemSetCallback(address);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(result);
|
||||
return NULL;
|
||||
}
|
||||
AppendHipadabaCallback(result,HCBSET,pHcb);
|
||||
|
||||
pHcb = MakeMemReadCallback(address);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(result);
|
||||
return NULL;
|
||||
}
|
||||
AppendHipadabaCallback(result,HCBREAD,pHcb);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
pHdb MakeSICSROPar(char *name, hdbValue v){
|
||||
pHdb result = NULL;
|
||||
@@ -566,6 +711,68 @@ void RemoveSICSPar(pHdb node){
|
||||
|
||||
SICSDeleteNodeData(node);
|
||||
}
|
||||
/*===================== add functions =======================================*/
|
||||
int AddSICSHdbPar(pHdb node, char *name, int priv, hdbValue v){
|
||||
pHdb child = NULL;
|
||||
|
||||
child = MakeSICSHdbPar(name,priv,v);
|
||||
if(child == NULL){
|
||||
return 0;
|
||||
}
|
||||
AddHipadabaChild(node,child);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int AddSICSHdbROPar(pHdb node, char *name, hdbValue v){
|
||||
pHdb child = NULL;
|
||||
|
||||
child = MakeSICSROPar(name,v);
|
||||
if(child == NULL){
|
||||
return 0;
|
||||
}
|
||||
AddHipadabaChild(node,child);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int AddSICSHdbMemPar(pHdb node, char *name, int priv,
|
||||
void *data, int datalength, int type, int length){
|
||||
pHdb child = NULL;
|
||||
pHdbCallback pHcb = NULL;
|
||||
|
||||
if(type == HIPINTVARAR || type == HIPFLOATVARAR){
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
child = MakeHipadabaNode(name,type,length);
|
||||
if(child == NULL){
|
||||
return 0;
|
||||
}
|
||||
|
||||
pHcb = MakeCheckPermissionCallback(priv);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(child);
|
||||
return 0;
|
||||
}
|
||||
AppendHipadabaCallback(child,HCBSET,pHcb);
|
||||
|
||||
pHcb = MakeMemGenSetCallback(data);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(child);
|
||||
return 0;
|
||||
}
|
||||
AppendHipadabaCallback(child,HCBSET,pHcb);
|
||||
|
||||
pHcb = MakeMemGenReadCallback(data);
|
||||
if(pHcb == NULL){
|
||||
DeleteHipadabaNode(child);
|
||||
return 0;
|
||||
}
|
||||
AppendHipadabaCallback(child,HCBREAD,pHcb);
|
||||
AddHipadabaChild(node,child);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*==================== access suport functions ==============================*/
|
||||
int SICSHdbGetFloat(pHdb parent, SConnection *pCon,
|
||||
char *path, float *value){
|
||||
@@ -620,7 +827,7 @@ int SICSHdbSetFloat(pHdb parent, SConnection *pCon,
|
||||
if(v.dataType == HIPFLOAT){
|
||||
v.v.doubleValue = (double)value;
|
||||
} else if(v.dataType == HIPINT){
|
||||
v.v.intValue = (long)value;
|
||||
v.v.intValue = (int)value;
|
||||
} else {
|
||||
/*
|
||||
* it is an error to call this for array dada types
|
||||
@@ -668,7 +875,7 @@ int ProcessSICSHdbPar(pHdb root, SConnection *pCon,
|
||||
assert(root != NULL && pCon != NULL);
|
||||
|
||||
if(argc < 1){
|
||||
SCWrite(pCon,"ERROR: nor parameter to treat specified",eError);
|
||||
SCWrite(pCon,"ERROR: no parameter to treat specified",eError);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -705,6 +912,10 @@ int ProcessSICSHdbPar(pHdb root, SConnection *pCon,
|
||||
DeleteDynString(parData);
|
||||
status = SetHipadabaPar(parNode,input,pCon);
|
||||
ReleaseHdbValue(&input);
|
||||
if(status == 1){
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
/*
|
||||
@@ -730,6 +941,65 @@ int ProcessSICSHdbPar(pHdb root, SConnection *pCon,
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void PrintSICSParList(pHdb node, SConnection *pCon, char *prefix){
|
||||
char childPrefix[1024];
|
||||
pHdb child = NULL;
|
||||
pDynString value = NULL;
|
||||
hdbValue v;
|
||||
|
||||
child = node->child;
|
||||
while(child != NULL){
|
||||
if(child->value.dataType != HIPNONE){
|
||||
GetHipadabaPar(child,&v,pCon);
|
||||
value = formatValue(child->value);
|
||||
if(value != NULL){
|
||||
SCPrintf(pCon,eValue,"%s%s = %s", prefix, child->name,
|
||||
GetCharArray(value));
|
||||
DeleteDynString(value);
|
||||
}
|
||||
}
|
||||
if(child->child != NULL){
|
||||
strncpy(childPrefix,prefix,1024);
|
||||
strncat(childPrefix,child->name, 1024);
|
||||
strncat(childPrefix,"/",1024);
|
||||
PrintSICSParList(child, pCon,prefix);
|
||||
}
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void SaveSICSHipadaba(FILE *fd, pHdb node, char *prefix){
|
||||
pHdb currentChild = NULL;
|
||||
pDynString data = NULL;
|
||||
hdbValue v;
|
||||
|
||||
currentChild = node->child;
|
||||
while(currentChild != NULL){
|
||||
if(currentChild->value.dataType != HIPNONE && !isSICSHdbRO(currentChild)){
|
||||
GetHipadabaPar(currentChild,&v,NULL);
|
||||
data = formatValue(currentChild->value);
|
||||
if(data != NULL){
|
||||
fprintf(fd,"%s%s %s\n", prefix, currentChild->name, GetCharArray(data));
|
||||
DeleteDynString(data);
|
||||
}
|
||||
}
|
||||
if(currentChild->child != NULL){
|
||||
/*
|
||||
* build a new prefix string and recurse
|
||||
*/
|
||||
data = CreateDynString(64,64);
|
||||
if(data != NULL){
|
||||
DynStringCopy(data,prefix);
|
||||
DynStringConcat(data,currentChild->name);
|
||||
DynStringConcat(data,"/");
|
||||
SaveSICSHipadaba(fd,currentChild,GetCharArray(data));
|
||||
DeleteDynString(data);
|
||||
}
|
||||
}
|
||||
currentChild = currentChild->next;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int SICSHipadabaTask(void *pData){
|
||||
pHdbUpdateTask self = NULL;
|
||||
@@ -798,7 +1068,7 @@ pDynString formatValue(hdbValue v){
|
||||
case HIPNONE:
|
||||
break;
|
||||
case HIPINT:
|
||||
snprintf(number,30,"%ld", v.v.intValue);
|
||||
snprintf(number,30,"%d", v.v.intValue);
|
||||
DynStringCopy(result,number);
|
||||
break;
|
||||
case HIPFLOAT:
|
||||
@@ -811,7 +1081,7 @@ pDynString formatValue(hdbValue v){
|
||||
case HIPINTAR:
|
||||
case HIPINTVARAR:
|
||||
for(i = 0; i < v.arrayLength; i++){
|
||||
snprintf(number,30," %ld", v.v.intArray[i]);
|
||||
snprintf(number,30," %d", v.v.intArray[i]);
|
||||
DynStringConcat(result,number);
|
||||
}
|
||||
break;
|
||||
@@ -861,11 +1131,11 @@ static int adjustDataLength(hdbValue *v, char *data){
|
||||
if(v->v.intArray != NULL){
|
||||
free(v->v.intArray);
|
||||
}
|
||||
v->v.intArray = malloc(count*sizeof(long));
|
||||
v->v.intArray = malloc(count*sizeof(int));
|
||||
if(v->v.intArray == NULL){
|
||||
return 0;
|
||||
}
|
||||
memset(v->v.intArray,0,count*sizeof(long));
|
||||
memset(v->v.intArray,0,count*sizeof(int));
|
||||
}
|
||||
if(v->dataType == HIPFLOATVARAR){
|
||||
if(v->v.floatArray != NULL){
|
||||
@@ -883,7 +1153,7 @@ static int adjustDataLength(hdbValue *v, char *data){
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
|
||||
int i, status;
|
||||
long lValue;
|
||||
int lValue;
|
||||
double dValue;
|
||||
char number[80];
|
||||
char *pPtr = NULL;
|
||||
@@ -893,7 +1163,7 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
|
||||
break;
|
||||
case HIPINT:
|
||||
getNextHdbNumber(data,number);
|
||||
status = sscanf(number,"%ld", &v->v.intValue);
|
||||
status = sscanf(number,"%d", &v->v.intValue);
|
||||
if(status != 1){
|
||||
snprintf(error,errlen,"Failed to convert %s to integer",
|
||||
data);
|
||||
@@ -928,7 +1198,7 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
|
||||
i);
|
||||
return 0;
|
||||
}
|
||||
status = sscanf(number,"%ld", &lValue);
|
||||
status = sscanf(number,"%d", &lValue);
|
||||
if(status != 1){
|
||||
snprintf(error,errlen,"Failed to convert %s to integer",
|
||||
data);
|
||||
@@ -1286,6 +1556,90 @@ static int GetHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int countChildren(pHdb node){
|
||||
pHdb current = NULL;
|
||||
int count = 0;
|
||||
|
||||
current = node->child;
|
||||
while(current != NULL){
|
||||
count++;
|
||||
current = current->next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int HdbNodeInfo(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
char error[512], oriPath[512], info[512];
|
||||
int i, status, length;
|
||||
|
||||
if(argc < 2) {
|
||||
SCWrite(pCon,"ERROR: need path to node to get info",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(oriPath,argv[1], 511);
|
||||
targetNode = locateSICSNode(pSics,pCon,argv[1]);
|
||||
if(targetNode == NULL){
|
||||
return 0;
|
||||
}
|
||||
length = targetNode->value.arrayLength;
|
||||
if(length == 0){
|
||||
length = 1;
|
||||
}
|
||||
snprintf(info,511,"%s,%d,%d",hdbTypeToText(targetNode->value.dataType),
|
||||
countChildren(targetNode), length);
|
||||
SCWrite(pCon,info,eValue);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int HdbNodeVal(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb targetNode = NULL;
|
||||
hdbValue newValue;
|
||||
pDynString parData = NULL;
|
||||
char error[512];
|
||||
int i, status;
|
||||
|
||||
if(argc < 2) {
|
||||
SCWrite(pCon,"ERROR: need path to node to print",eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
targetNode = locateSICSNode(pSics,pCon,argv[1]);
|
||||
if(targetNode == NULL){
|
||||
return 0;
|
||||
}
|
||||
memset(&newValue,0,sizeof(hdbValue));
|
||||
GetHipadabaPar(targetNode, &newValue, pCon);
|
||||
parData = formatValue(newValue);
|
||||
if(parData == NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory formatting data",eError);
|
||||
return 0;
|
||||
}
|
||||
SCWrite(pCon,GetCharArray(parData),eValue);
|
||||
DeleteDynString(parData);
|
||||
ReleaseHdbValue(&newValue);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int isSICSHdbRO(pHdb node){
|
||||
pHdbCallback current = NULL;
|
||||
|
||||
current = node->writeCallbacks;
|
||||
while(current != NULL){
|
||||
if(current->userCallback == SICSReadOnlyCallback) {
|
||||
return 1;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static pDynString formatPlainList(pHdb node){
|
||||
pHdb current;
|
||||
@@ -1317,30 +1671,20 @@ static pDynString formatListWithVal(pHdb node){
|
||||
|
||||
current = node->child;
|
||||
while(current != NULL){
|
||||
DynStringConcat(result,current->name);
|
||||
data = formatValue(current->value);
|
||||
if(data != NULL){
|
||||
DynStringConcat(result," = ");
|
||||
DynStringConcat(result,GetCharArray(data));
|
||||
DeleteDynString(data);
|
||||
if(current->value.dataType != HIPNONE){
|
||||
DynStringConcat(result,current->name);
|
||||
data = formatValue(current->value);
|
||||
if(data != NULL){
|
||||
DynStringConcat(result," = ");
|
||||
DynStringConcat(result,GetCharArray(data));
|
||||
DeleteDynString(data);
|
||||
}
|
||||
DynStringConcat(result,"\n");
|
||||
}
|
||||
DynStringConcat(result,"\n");
|
||||
current = current->next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int countChildren(pHdb node){
|
||||
pHdb current = NULL;
|
||||
int count = 0;
|
||||
|
||||
current = node->child;
|
||||
while(current != NULL){
|
||||
count++;
|
||||
current = current->next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static pDynString formatClientList(pHdb node){
|
||||
pHdb current;
|
||||
@@ -1375,7 +1719,7 @@ static pDynString formatClientList(pHdb node){
|
||||
case HIPNONE:
|
||||
break;
|
||||
case HIPINT:
|
||||
snprintf(number,50,"%ld",current->value.v.intValue);
|
||||
snprintf(number,50,"%d",current->value.v.intValue);
|
||||
DynStringConcat(result,number);
|
||||
break;
|
||||
case HIPFLOAT:
|
||||
@@ -1388,7 +1732,7 @@ static pDynString formatClientList(pHdb node){
|
||||
case HIPINTAR:
|
||||
case HIPINTVARAR:
|
||||
for(i = 0; i < length; i++){
|
||||
snprintf(number,50,"%ld",current->value.v.intArray[i]);
|
||||
snprintf(number,50,"%d",current->value.v.intArray[i]);
|
||||
DynStringConcat(result,number);
|
||||
if(i > length -1){
|
||||
DynStringConcat(result,",");
|
||||
@@ -1495,6 +1839,66 @@ static int RemoveHdbCallback(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int LinkHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pHdb node = NULL;
|
||||
char buffer[256];
|
||||
CommandList *pCom = NULL;
|
||||
pDummy pDum = NULL;
|
||||
|
||||
|
||||
if(argc < 3) {
|
||||
SCWrite(pCon,"ERROR: need path and object name to link",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if(!SCMatchRights(pCon,usMugger)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
node = GetHipadabaNode(root,argv[1]);
|
||||
if(node == NULL){
|
||||
snprintf(buffer,255,"ERROR: path %s NOT found!", argv[1]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCom = FindCommand(pSics,argv[2]);
|
||||
if(pCom == NULL){
|
||||
snprintf(buffer,255,"ERROR: failed to find object %s", argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return 0;
|
||||
}
|
||||
pDum = pCom->pData;
|
||||
if(pDum == NULL || pDum->pDescriptor->parNode == NULL){
|
||||
snprintf(buffer,255,
|
||||
"ERROR: Object %s does not use Hipadaba natively and thus cannot be linked",
|
||||
argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(pDum->pDescriptor->parNode->mama != NULL){
|
||||
snprintf(buffer,255,
|
||||
"ERROR: Object %s is already linked somewhere else",
|
||||
argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AddHipadabaChild(node,pDum->pDescriptor->parNode);
|
||||
|
||||
if(argc > 3){
|
||||
if(pDum->pDescriptor->parNode->name != NULL){
|
||||
free(pDum->pDescriptor->parNode->name);
|
||||
}
|
||||
pDum->pDescriptor->parNode->name = strdup(argv[3]);
|
||||
}
|
||||
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void killSICSHipadaba(){
|
||||
if(root != NULL){
|
||||
DeleteHipadabaNode(root);
|
||||
@@ -1535,6 +1939,9 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
AddCommand(pSics,"hlist", ListHdbNode, NULL, NULL);
|
||||
AddCommand(pSics,"hnotify", AutoNotifyHdbNode, NULL, NULL);
|
||||
AddCommand(pSics,"hdelcb", RemoveHdbCallback, NULL, NULL);
|
||||
AddCommand(pSics,"hlink", LinkHdbNode, NULL, NULL);
|
||||
AddCommand(pSics,"hinfo", HdbNodeInfo, NULL, NULL);
|
||||
AddCommand(pSics,"hval", HdbNodeVal, NULL, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user