PSI sics-cvs-psi-2006
This commit is contained in:
215
sicvar.c
215
sicvar.c
@@ -39,6 +39,7 @@
|
||||
#include "fortify.h"
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <tcl.h>
|
||||
#include "sics.h"
|
||||
#include <string.h>
|
||||
#include "splitter.h"
|
||||
@@ -54,7 +55,7 @@
|
||||
assert(pData);
|
||||
assert(fd);
|
||||
pVar = (pSicsVariable)pData;
|
||||
if(pVar->iLock)
|
||||
if(pVar->iLock || pVar->iAccessCode == usInternal)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -373,12 +374,13 @@
|
||||
}
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int VarInterestCallback(int iEvent, void *pEvent, void *pUser)
|
||||
static int VarInterestCallback(int iEvent, void *pEvent, void *pUser,
|
||||
commandContext cc)
|
||||
{
|
||||
SConnection *pCon;
|
||||
char pBueffel[512];
|
||||
pSicsVariable pVar = NULL;
|
||||
int iVal;
|
||||
int iVal, status;
|
||||
float fVal;
|
||||
char *pText;
|
||||
|
||||
@@ -387,18 +389,21 @@
|
||||
|
||||
pVar = (pSicsVariable)pEvent;
|
||||
pCon = (SConnection *)pUser;
|
||||
SCPushContext2(pCon,cc);
|
||||
switch(pVar->eType)
|
||||
{
|
||||
case veInt:
|
||||
VarGetInt(pVar,&iVal);
|
||||
sprintf(pBueffel,"%s = %d",pVar->name,iVal);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
status = 1;
|
||||
break;
|
||||
case veFloat:
|
||||
VarGetFloat(pVar,&fVal);
|
||||
sprintf(pBueffel,"%s = %f",pVar->name,fVal);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
status = 1;
|
||||
break;
|
||||
case veText:
|
||||
VarGetText(pVar,&pText);
|
||||
sprintf(pBueffel,"%s = %s", pVar->name,pText);
|
||||
@@ -407,15 +412,48 @@
|
||||
{
|
||||
free(pText);
|
||||
}
|
||||
return 1;
|
||||
status = 1;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
SCPopContext(pCon);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int VarSetFromText(pSicsVariable self, SConnection *pCon, char *text)
|
||||
{
|
||||
int status;
|
||||
double dVal;
|
||||
char pBueffel[132];
|
||||
|
||||
if(!SCMatchRights(pCon,self->iAccessCode))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(self->eType == veText)
|
||||
{
|
||||
return VarSetText(self,text,SCGetRights(pCon));
|
||||
}
|
||||
status = Tcl_GetDouble(InterpGetTcl(pServ->pSics), text,&dVal);
|
||||
if(status != TCL_OK)
|
||||
{
|
||||
snprintf(pBueffel,131,"ERROR: failed to convert %s to number",
|
||||
text);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(self->eType == veInt)
|
||||
{
|
||||
return VarSetInt(self,(int)dVal,SCGetRights(pCon));
|
||||
}
|
||||
else if(self->eType == veFloat)
|
||||
{
|
||||
return VarSetFloat(self,(float)dVal,SCGetRights(pCon));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------
|
||||
Variables understands some commands:
|
||||
setrights : for setting uer rights
|
||||
setrights : for setting user rights
|
||||
lock : for locking the variable
|
||||
interest : for notifictaion on value change
|
||||
uninterest : delete notification
|
||||
@@ -499,7 +537,9 @@
|
||||
/* is control grabbed ? */
|
||||
if(SCGetGrab(pCon) != 0)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: somebody else has grabbed control, Request REJECTED",eError);
|
||||
SCWrite(pCon,
|
||||
"ERROR: somebody else has grabbed control, Request REJECTED",
|
||||
eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
@@ -525,7 +565,8 @@
|
||||
}
|
||||
else if(strcmp(pCurrent->text,"interest") == 0) /* interest */
|
||||
{
|
||||
lID = RegisterCallback(pVar->pCall, VALUECHANGE, VarInterestCallback,
|
||||
lID = RegisterCallback(pVar->pCall, SCGetContext(pCon),
|
||||
VALUECHANGE, VarInterestCallback,
|
||||
pCon, NULL);
|
||||
SCRegister(pCon,pInterp, pVar->pCall,lID);
|
||||
DeleteTokenList(pList);
|
||||
@@ -546,94 +587,74 @@
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/* now, only a new value is still possible */
|
||||
eStat = GetStatus();
|
||||
if( (eStat != eEager) && (eStat != eBatch) )
|
||||
else if(strcmp(pCurrent->text,"force") == 0)
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"You cannot set variables while a scan is running",eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
|
||||
/*
|
||||
Undocumented feauture: force a set even while driving etc.
|
||||
Internal privilege required to do this.
|
||||
*/
|
||||
if(!SCMatchRights(pCon,usInternal))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
if(!pCurrent)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: new value missing for force",eError);
|
||||
return 0;
|
||||
}
|
||||
Arg2Text(argc-2,&argv[2],pBueffel,255);
|
||||
iRet = VarSetFromText(pVar,pCon,pBueffel);
|
||||
if(iRet == 1)
|
||||
{
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
SCparChange(pCon);
|
||||
DeleteTokenList(pList);
|
||||
return iRet;
|
||||
}
|
||||
iRet = 0;
|
||||
if(pCurrent)
|
||||
else
|
||||
{
|
||||
/* is it locked ? */
|
||||
if(pVar->iLock)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: variable %s is configured locked!",
|
||||
argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
/* is control grabbed ? */
|
||||
if(SCGetGrab(pCon) != 0)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: somebody else has grabbed control, Request REJECTED",eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
/* do not care for typechecks if text */
|
||||
if(eTyp == veText)
|
||||
{
|
||||
Arg2Text(argc-1,&argv[1],pBueffel,255);
|
||||
iRet = VarSetText(pVar,pBueffel,SCGetRights(pCon));
|
||||
}
|
||||
else if(eTyp == veInt)
|
||||
{
|
||||
if(pCurrent->Type == eFloat)
|
||||
{
|
||||
iVal = (int)pCurrent->fVal;
|
||||
}
|
||||
else if(pCurrent->Type == eInt)
|
||||
{
|
||||
iVal = pCurrent->iVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"Wrong Type: cannot assign %s to %s",
|
||||
pCurrent->text, argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
iRet = VarSetInt(pVar,iVal,SCGetRights(pCon));
|
||||
}
|
||||
else if(eTyp == veFloat)
|
||||
{
|
||||
if(pCurrent->Type == eFloat)
|
||||
{
|
||||
fVal = pCurrent->fVal;
|
||||
}
|
||||
else if(pCurrent->Type == eInt)
|
||||
{
|
||||
fVal = (float)pCurrent->iVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"Wrong Type: cannot assign %s to %s",
|
||||
pCurrent->text, argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
iRet = VarSetFloat(pVar,fVal,SCGetRights(pCon));
|
||||
}
|
||||
if(!iRet)
|
||||
{
|
||||
sprintf(pBueffel,"Insufficient Privilege to change %s",
|
||||
argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
SCparChange(pCon);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
}
|
||||
/* now, only a new value is still possible */
|
||||
eStat = GetStatus();
|
||||
if( (eStat != eEager) && (eStat != eBatch) )
|
||||
{
|
||||
SCWrite(pCon,
|
||||
"You cannot set variables while a scan is running",eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
|
||||
}
|
||||
iRet = 0;
|
||||
if(pCurrent)
|
||||
{
|
||||
/* is it locked ? */
|
||||
if(pVar->iLock)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: variable %s is configured locked!",
|
||||
argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
/* is control grabbed ? */
|
||||
if(SCGetGrab(pCon) != 0)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: somebody else has grabbed control, Request REJECTED",eError);
|
||||
DeleteTokenList(pList);
|
||||
return 0;
|
||||
}
|
||||
Arg2Text(argc-1,&argv[1],pBueffel,255);
|
||||
iRet = VarSetFromText(pVar,pCon,pBueffel);
|
||||
if(iRet == 1)
|
||||
{
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
SCparChange(pCon);
|
||||
DeleteTokenList(pList);
|
||||
return iRet;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we are here, no valid command was found */
|
||||
SCWrite(pCon,
|
||||
|
||||
Reference in New Issue
Block a user