- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
132
background.c
132
background.c
@ -12,76 +12,76 @@
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
SConnection *con;
|
||||
char *command;
|
||||
SConnection *con;
|
||||
char *command;
|
||||
} BckTask, *pBckTask;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void KillBckTask(void *data){
|
||||
pBckTask self = (pBckTask)data;
|
||||
if(self == NULL){
|
||||
return;
|
||||
}
|
||||
if(self->con){
|
||||
SCDeleteConnection(self->con);
|
||||
}
|
||||
if(self->command){
|
||||
free(self->command);
|
||||
}
|
||||
static void KillBckTask(void *data)
|
||||
{
|
||||
pBckTask self = (pBckTask) data;
|
||||
if (self == NULL) {
|
||||
return;
|
||||
}
|
||||
if (self->con) {
|
||||
SCDeleteConnection(self->con);
|
||||
}
|
||||
if (self->command) {
|
||||
free(self->command);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int BackgroundTask(void *data){
|
||||
pBckTask self = (pBckTask)data;
|
||||
|
||||
assert(self != NULL);
|
||||
|
||||
InterpExecute(pServ->pSics,self->con,self->command);
|
||||
return 0;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int BackgroundCommand(SConnection *pCon, char *command){
|
||||
pBckTask self = NULL;
|
||||
|
||||
self = calloc(1,sizeof(BckTask));
|
||||
if(self == NULL){
|
||||
return 0;
|
||||
}
|
||||
|
||||
self->con = SCCopyConnection(pCon);
|
||||
self->command = strdup(command);
|
||||
if(self->con == NULL || self->command == NULL){
|
||||
free(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TaskRegister(pServ->pTasker,
|
||||
BackgroundTask,
|
||||
NULL,
|
||||
KillBckTask,
|
||||
self,
|
||||
1);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int BackgroundAction(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[]){
|
||||
int status;
|
||||
char command[1024];
|
||||
|
||||
memset(command,0,1024);
|
||||
Arg2Text(argc-1,&argv[1], command, 1024);
|
||||
status = BackgroundCommand(pCon,command);
|
||||
if(status == 0){
|
||||
SCWrite(pCon,"ERROR: out of memory starting task", eError);
|
||||
return 0;
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int BackgroundTask(void *data)
|
||||
{
|
||||
pBckTask self = (pBckTask) data;
|
||||
|
||||
assert(self != NULL);
|
||||
|
||||
InterpExecute(pServ->pSics, self->con, self->command);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int BackgroundCommand(SConnection * pCon, char *command)
|
||||
{
|
||||
pBckTask self = NULL;
|
||||
|
||||
self = calloc(1, sizeof(BckTask));
|
||||
if (self == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
self->con = SCCopyConnection(pCon);
|
||||
self->command = strdup(command);
|
||||
if (self->con == NULL || self->command == NULL) {
|
||||
free(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TaskRegister(pServ->pTasker, BackgroundTask, NULL, KillBckTask, self, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
int BackgroundAction(SConnection * pCon, SicsInterp * pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
int status;
|
||||
char command[1024];
|
||||
|
||||
memset(command, 0, 1024);
|
||||
Arg2Text(argc - 1, &argv[1], command, 1024);
|
||||
status = BackgroundCommand(pCon, command);
|
||||
if (status == 0) {
|
||||
SCWrite(pCon, "ERROR: out of memory starting task", eError);
|
||||
return 0;
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void InstallBackground(SicsInterp *pSics){
|
||||
AddCommand(pSics,
|
||||
"bg",
|
||||
BackgroundAction,
|
||||
NULL,
|
||||
NULL);
|
||||
void InstallBackground(SicsInterp * pSics)
|
||||
{
|
||||
AddCommand(pSics, "bg", BackgroundAction, NULL, NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user