From 0d0c90cee7da6aff92f34183a56f66c704b54936 Mon Sep 17 00:00:00 2001 From: Koennecke Mark Date: Thu, 19 Mar 2015 16:12:35 +0100 Subject: [PATCH] Another try ad getting write to work --- conman.c | 9 ++++++++- conman.h | 1 + interface.c | 6 ++++++ remoteobject.c | 27 +++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/conman.c b/conman.c index 88b2ad1f..f9ca2242 100644 --- a/conman.c +++ b/conman.c @@ -229,6 +229,7 @@ static SConnection *CreateConnection(SicsInterp * pSics) pRes->conStart = time(NULL); pRes->write = SCNormalWrite; pRes->runLevel = RUNDRIVE; + pRes->remote = 0; /* initialise context variables */ pRes->iCmdCtr = 0; @@ -461,6 +462,7 @@ SConnection *SCCopyConnection(SConnection * pCon) result->iList = -1; result->runLevel = pCon->runLevel; result->data = pCon->data; + result->remote = pCon->remote; return result; } @@ -1768,6 +1770,7 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand) config File Filename Logs to another file config output normal | withcode | ACT Sets output mode config listen 0 | 1 enables commandlog listen mode + config remote sets the remote connection flag ---------------------------------------------------------------------------*/ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, @@ -1825,7 +1828,11 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, SCSendOK(pCon); return 1; } - } + } else if(strcmp(argv[1],"remote") == 0) { + pMaster->remote = 1; + pCon->remote = 1; + return 1; + } /* check no or args */ if (argc < 3) { diff --git a/conman.h b/conman.h index 91befe22..99a9dd16 100644 --- a/conman.h +++ b/conman.h @@ -71,6 +71,7 @@ typedef struct __SConnection { pCosta pStack; /* stack of pending commands */ int contextStack; /* context stack: may go? */ mkChannel *pSock; /* for temporary backwards compatability */ + int remote; /* true if this is a remote object connection */ } SConnection; #include "nserver.h" diff --git a/interface.c b/interface.c index d661b2c3..f3b9790f 100644 --- a/interface.c +++ b/interface.c @@ -241,6 +241,9 @@ static int DriveTaskFunc(void *data) } else { ExeInterest(pServ->pExecutor,taskData->name, "finished with problem"); } + if(taskData->pCon->remote){ + SCPrintf(taskData->pCon,eValue,"TASKFINISHED:%s", taskData->name); + } traceSys("drive","DriveTask %s finished with state %d", taskData->name,status); return 0; } @@ -393,6 +396,9 @@ static int CountTaskFunc(void *data) ExeInterest(pServ->pExecutor,taskData->name, "finished with problem"); } traceSys("count","CountTask %s finished with state %d", taskData->name,status); + if(taskData->pCon->remote){ + SCPrintf(taskData->pCon,eValue,"TASKFINISHED:%s", taskData->name); + } return 0; } /*--------------------------------------------------------------------------*/ diff --git a/remoteobject.c b/remoteobject.c index 5cad0a91..c1912769 100644 --- a/remoteobject.c +++ b/remoteobject.c @@ -240,8 +240,9 @@ static void ConnectRemoteObject(pRemoteOBJ self) status = LLDnodePtr2Next(self->readList); } - transactCommand(self->writeHandle,"protocol set withcode\r\n", command,sizeof(command)); - + transactCommand(self->writeHandle,"protocol set withcode\r\n", command,sizeof(command)-1); + transactCommand(self->writeHandle,"config remote\r\n",command,sizeof(command)-1); + self->connected = 1; self->writeInUse = 0; } @@ -537,7 +538,7 @@ static void printSICS(char *answer, SConnection *pCon) while(pPtr != NULL){ memset(line,0,sizeof(line)); pPtr = stptok(pPtr,line,sizeof(line),"\n"); - if(strstr(line,"OK") == NULL){ + if(strstr(line,"OK") == NULL && strstr(line,"TASKFINISHED") == NULL){ pCode = strstr(line,"@@"); if(pCode != NULL){ *pCode = '\0'; @@ -578,6 +579,7 @@ static int PrepareWriteHandle(pRemoteOBJ self, SConnection *pCon, int *newHandle *newHandle = 1; transactCommand(handle,"protocol set withcode\r\n", command,sizeof(command)); + transactCommand(handle,"config remote\r\n",command,sizeof(command)-1); } else { self->writeInUse = 1; @@ -609,7 +611,7 @@ static void ProcessWriteResponse(pRemoteOBJ self, int handle, SConnection *pCon) printSICS(answer,pCon); } traceIO("RO","%s:%d: Received %s", self->host, self->port,answer); - ANETreadConsume(handle,length); + ANETreadConsume(handle,pEnd+strlen("TRANSACTIONFINISHED") - answer); break; } } @@ -688,6 +690,23 @@ static hdbCallbackReturn ROWriteCallback(pHdb currentNode, void *userData, } } + /* + Do I have to wait for a TASKFINISHED? + */ + command = GetHdbProp(currentNode,"taskwait"); + if(command != NULL){ + while(1) { + TaskYield(pServ->pTasker); + answer = ANETreadPtr(handle,&length); + if(length > 0 && strstr(answer,"TASKFINISHED") != NULL){ + printSICS(answer,pCon); + traceIO("RO","%s:%d:Received %s", self->host,self->port,answer); + ANETreadConsume(handle,length); + break; + } + } + } + if(newHandle){ ANETclose(handle);