*** empty log message ***
This commit is contained in:
124
status.c
124
status.c
@ -9,6 +9,9 @@
|
||||
|
||||
Updated in order to prevent status floods
|
||||
Mark Koennecke, July 2004
|
||||
|
||||
Reworked restore to keep parameters from uninitialized devices
|
||||
Mark Koennecke, November 2007
|
||||
|
||||
Copyright:
|
||||
|
||||
@ -50,6 +53,9 @@
|
||||
#include "interrupt.h"
|
||||
#include "devexec.h"
|
||||
#include "sicshipadaba.h"
|
||||
#include "lld_str.h"
|
||||
#include "lld.h"
|
||||
#include "exebuf.h"
|
||||
#undef VALUECHANGE
|
||||
#define VALUECHANGE 2
|
||||
|
||||
@ -397,28 +403,116 @@ static int motorSave = 0;
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int restoreOccurred = 0;
|
||||
int hasRestored(){
|
||||
return restoreOccurred;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
pObjectDescriptor pDes;
|
||||
int errList;
|
||||
}RestoreObj, *pRestoreObj;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void killRestore(void *data){
|
||||
pRestoreObj self = (pRestoreObj)data;
|
||||
if(self == NULL){
|
||||
return;
|
||||
}
|
||||
if(self->errList >= 0){
|
||||
LLDdeleteBlob(self->errList);
|
||||
}
|
||||
if(self->pDes != NULL){
|
||||
DeleteDescriptor(self->pDes);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int SaveRestore(void *obj, char *name, FILE *fd){
|
||||
int status;
|
||||
char buffer[1024];
|
||||
|
||||
pRestoreObj self = (pRestoreObj)obj;
|
||||
if(self == NULL){
|
||||
return 0;
|
||||
}
|
||||
status = LLDnodePtr2First(self->errList);
|
||||
while(status == 1){
|
||||
LLDstringData(self->errList,buffer);
|
||||
fprintf(fd,"%s\n", buffer);
|
||||
status = LLDnodePtr2Next(self->errList);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int InstallBckRestore(SConnection *pCon, SicsInterp *pSics){
|
||||
pRestoreObj pNew = NULL;
|
||||
|
||||
pNew = malloc(sizeof(RestoreObj));
|
||||
if(pNew == NULL){
|
||||
SCWrite(pCon,"ERROR: no memory to create restore object! This is SERIOUS!!!",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pNew->pDes = CreateDescriptor("BckRestore");
|
||||
pNew->errList = LLDstringCreate();
|
||||
if(pNew->pDes == NULL || pNew->errList < 0){
|
||||
SCWrite(pCon,"ERROR: no memory to create restore object! This is SERIOUS!!!",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pNew->pDes->SaveStatus = SaveRestore;
|
||||
AddCommand(pSics,"Backup",BackupStatus,NULL,NULL);
|
||||
AddCommand(pSics,"Restore",RestoreStatus,killRestore,pNew);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int listRestoreErr(pRestoreObj self, SConnection *pCon){
|
||||
char buffer[1024];
|
||||
int status;
|
||||
pDynString data = NULL;
|
||||
|
||||
SCStartBuffering(pCon);
|
||||
status = LLDnodePtr2First(self->errList);
|
||||
while(status == 1){
|
||||
LLDstringData(self->errList,buffer);
|
||||
SCWrite(pCon,buffer,eValue);
|
||||
status = LLDnodePtr2Next(self->errList);
|
||||
}
|
||||
data = SCEndBuffering(pCon);
|
||||
if(data != NULL){
|
||||
SCWrite(pCon,GetCharArray(data),eValue);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int RestoreStatus(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
char pBueffel[512];
|
||||
int iRights;
|
||||
int iRet;
|
||||
char *pFile = NULL;
|
||||
writeFunc oldWrite;
|
||||
pExeBuf buffi = NULL;
|
||||
pRestoreObj self = (pRestoreObj)pData;
|
||||
|
||||
assert(pSics);
|
||||
assert(pCon);
|
||||
assert(self != NULL);
|
||||
|
||||
|
||||
if(argc < 2)
|
||||
{
|
||||
pFile = IFindOption(pSICSOptions,"statusfile");
|
||||
if(pFile)
|
||||
{
|
||||
sprintf(pBueffel,"FileEval %s",pFile);
|
||||
sprintf(pBueffel,"%s",pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
SCWrite(pCon,"ERROR: No filename given for backup, Aborted.",
|
||||
eError);
|
||||
return 0;
|
||||
@ -426,16 +520,35 @@ static int motorSave = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"FileEval %s",argv[1]);
|
||||
if(strcmp(argv[1],"listerr") == 0){
|
||||
return listRestoreErr(self,pCon);
|
||||
} else {
|
||||
sprintf(pBueffel,"%s",argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
buffi = exeBufCreate("restore");
|
||||
if(buffi == NULL){
|
||||
SCWrite(pCon,"ERROR: failed to allocate buffer for restore",eError);
|
||||
return 0;
|
||||
}
|
||||
iRet = exeBufLoad(buffi,pBueffel);
|
||||
if(iRet != 1){
|
||||
exeBufDelete(buffi);
|
||||
SCWrite(pCon,"ERROR: failed open status file",eError);
|
||||
return 0;
|
||||
}
|
||||
LLDdeleteBlob(self->errList);
|
||||
self->errList = LLDstringCreate();
|
||||
iRights = SCGetRights(pCon);
|
||||
pCon->iUserRights = usInternal;
|
||||
oldWrite = SCGetWriteFunc(pCon);
|
||||
SCSetWriteFunc(pCon,SCNotWrite);
|
||||
iRet = InterpExecute(pSics,pCon,pBueffel);
|
||||
iRet = exeBufProcessErrList(buffi,pSics,pCon,self->errList);
|
||||
restoreOccurred = 1;
|
||||
SCSetWriteFunc(pCon,oldWrite);
|
||||
pCon->iUserRights = iRights;
|
||||
exeBufDelete(buffi);
|
||||
/*
|
||||
if we do not override parameterChange here, the backup file
|
||||
would be overwritten after each restore... Not the right thing
|
||||
@ -445,4 +558,3 @@ static int motorSave = 0;
|
||||
SCSendOK(pCon);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user