- Reworked the connection object and the IO system

- Reworked the support for TRICS
- Added a second generation motor
This commit is contained in:
koennecke
2009-02-03 08:05:39 +00:00
parent f6d595665e
commit 361ee9ebea
119 changed files with 16455 additions and 3674 deletions

112
sicsobj.c
View File

@ -5,6 +5,7 @@
*
* Mark Koennecke, July 2007
*/
#include <stdio.h>
#include <sics.h>
#include <tcl.h>
#include "assert.h"
@ -21,6 +22,50 @@ extern int decodeSICSPriv(char *txt); /* from access.c */
void DefaultKill(void *data){
return;
}
/*--------------------------------------------------------------------------*/
void DefaultFree(void *data){
if(data != NULL){
free(data);
}
}
/*---------------------------------------------------------------------------*/
static void saveSICSNode(pHdb node, char *prefix, FILE *fd){
char newprefix[1024], val[20];
pHdb child;
hdbValue v;
pDynString data = NULL;
if(GetHdbProperty(node,"__save",val,20) == 1){
GetHipadabaPar(node,&v,NULL);
data = formatValue(v,node);
if(data != NULL){
fprintf(fd,"%s %s\n", prefix, GetCharArray(data));
DeleteDynString(data);
}
child = node->child;
while(child != NULL){
snprintf(newprefix,1024,"%s/%s", prefix,child->name);
saveSICSNode(child,newprefix,fd);
child = child->next;
}
}
}
/*---------------------------------------------------------------------------*/
int SaveSICSOBJ(void *data, char *name, FILE *fd){
pSICSOBJ self = (pSICSOBJ)data;
char prefix[1024];
pHdb node;
if(self != NULL && self->objectNode != NULL){
node = self->objectNode->child;
while(node != NULL){
snprintf(prefix, 1024,"%s %s", name, node->name);
saveSICSNode(node, prefix, fd);
node = node->next;
}
}
return 1;
}
/*---------------------------------------------------------------------------*/
pSICSOBJ MakeSICSOBJv(char *name, char *class, int type, int priv){
pSICSOBJ pNew = NULL;
@ -32,12 +77,13 @@ pSICSOBJ MakeSICSOBJv(char *name, char *class, int type, int priv){
}
memset(pNew,0,sizeof(SICSOBJ));
pNew->pDes = CreateDescriptor(class);
pNew->pDes->SaveStatus = SaveSICSOBJ;
if (type == HIPNONE) {
pNew->objectNode = MakeHipadabaNode(name, HIPNONE, 1);
} else {
val = makeHdbValue(type,0);
pNew->objectNode = MakeSICSHdbPar(name, priv, val);
ReleaseHdbValue(&val);
val = makeHdbValue(type,0);
pNew->objectNode = MakeSICSHdbPar(name, priv, val);
ReleaseHdbValue(&val);
}
if(pNew->pDes == NULL || pNew->objectNode == NULL){
free(pNew);
@ -87,7 +133,21 @@ static int invokeOBJFunction(pSICSOBJ object, pHdb commandNode, SConnection *pCo
pHdb currentPar = NULL;
SICSOBJFunc pFunc = NULL;
pHdb parArray[64];
char buffer[1024];
/*
* If the first argument has the special name args, concatenate all arguments
* and put the result as text into this parameter. This allows for the
* object function to parse and interpret the arguments itself.
*/
if(commandNode->child != NULL && strcmp(commandNode->child->name,"args") == 0) {
Arg2Text(argc,argv,buffer,1024);
assignPar(commandNode->child,pCon,buffer);
parArray[0] = commandNode->child;
count = 1;
goto invoke;
}
/*
* assign parameters and fill parameter array for function at the same
* time. Be lenient about missing parameters: Then the old values will
@ -106,12 +166,14 @@ static int invokeOBJFunction(pSICSOBJ object, pHdb commandNode, SConnection *pCo
count++;
}
pFunc = (SICSOBJFunc)commandNode->value.v.func;
invoke: pFunc = (SICSOBJFunc)commandNode->value.v.func;
if(pFunc == NULL){
SCWrite(pCon,"ERROR: internal error, function not found",eError);
return 0;
}
SendHdbStatusMessage(commandNode,"start");
status = pFunc(object, pCon, commandNode, parArray,count);
SendHdbStatusMessage(commandNode,"stop");
return status;
}
/*---------------------------------------------------------------------------*/
@ -128,7 +190,7 @@ static int ScriptObjFunc(pSICSOBJ obj, SConnection *pCon, pHdb commandNode,
GetHdbProperty(commandNode,"priv",value,256);
status = decodeSICSPriv(value);
if(!SCMatchRights(pCon,status)){
return 0;
return 0;
}
if(GetHdbProperty(commandNode,"script",value,256) != 1){
@ -219,6 +281,42 @@ static int isNodePrintable(pHdb node){
}
}
/*---------------------------------------------------------------------------*/
static void objFormatNode(pHdb node, pDynString data){
char par[40];
pDynString val = NULL;
snprintf(par,40,"%-20s = ",node->name);
DynStringConcat(data,par);
val = formatValue(node->value,node);
if(val != NULL){
DynStringConcat(data,GetCharArray(val));
DynStringConcatChar(data,'\n');
DeleteDynString(val);
}
}
/*---------------------------------------------------------------------------*/
static int ListObj(pSICSOBJ self, SConnection *pCon, int argc, char *argv[]){
pHdb node = NULL;
pDynString data;
data = CreateDynString(128,128);
if(data == NULL){
return 0;
}
node = self->pDes->parNode;
if(node != NULL){
objFormatNode(node,data);
node = node->child;
while(node != NULL){
objFormatNode(node,data);
node = node->next;
}
}
SCWrite(pCon,GetCharArray(data),eValue);
DeleteDynString(data);
return 1;
}
/*---------------------------------------------------------------------------*/
int InvokeSICSOBJ(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]){
pSICSOBJ self = NULL;
@ -263,6 +361,8 @@ int InvokeSICSOBJ(SConnection *pCon, SicsInterp *pSics, void *pData,
if(status == -1){
if(strcmp(argv[1],"makescriptfunc") == 0) {
return MakeScriptFunc(self,pCon,argc,argv);
} else if(strcmp(argv[1],"list") == 0){
return ListObj(self,pCon,argc,argv);
}
SCPrintf(pCon, eError, "ERROR: %s %s not found", argv[0], argv[1]);
}