TOC PREV NEXT INDEX

Put your logo here!


11 EXAMPLES

11.1 CONTROL SERVER EXTENSION

The following example for a derived server is also contained in the test directory of the iracq module:

mySERVER.h:

#ifndef __cplusplus

#error This is a C++ include file and cannot be used from plain C

#endif

#include "iracqEVH.h"

#define myFRAME_TYPE (sdmaFRAME_USER << 1)

class mySRV: public iracqEVH

{

public:

mySRV(); // constructor

~mySRV(); // destructor

void PrintUsage(const char *);

ccsCOMPL_STAT ParseInputPars(int, char **);

// verbose callback

void Verbose(const char *, ...);

// server state callback

void StateHandler(int, int);

// data transfer task event callback

void DataHandler(iracqDATA_EVT *);

// exit callback

void ExitHandler(int);

// parameter callbacks

ccsCOMPL_STAT SetParam(const char *, const char *, vltLOGICAL *);

ccsCOMPL_STAT GetParam(const char *, char *, vltINT32 *,vltLOGICAL *);

// sequencer program handler

ccsCOMPL_STAT SeqHandler(const char *, vltINT32 *, vltINT32 *);

// initialization routine

ccsCOMPL_STAT Init();

// command callbacks

evhCB_COMPL_STAT MyCB(msgMESSAGE &msg, void *udata);

protected:

private:

// callback structure

evhOBJ_CALLBACK cb_;

cmdPARAM_LIST paramList_;

// just some dummy variables to be added to FITS-header

int dummyInt_;

float dummyFloat_;

double dummyDouble_;

char dummyString_[128];

};

myServer.C

#define _POSIX_SOURCE 1

// Uncomment this if you are using the VLT environment

#include "vltPort.h"

#include <stdlib.h>

#include <stdio.h>

#include "mySERVER.h"

static char *rcsId="@(#) $Id: myServer.C,v 1.54+ 2000/12/20 16:43:03 vltsccm Exp $";

static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

/*

* control server

*/

static int serverProcess(int argc, char *argv[])

{

mySRV server;

int exitStatus = 0;

/*

* parse command line arguments

*/

if (server.ParseInputPars(argc, argv) == FAILURE)

{

server.PrintUsage(argv[0]);

errResetStack();

return (0);

}

/*

* intialize

*/

if (server.Init() == FAILURE)

{

fprintf(stdout, "\nmyServer: initialization failed\n");

errDisplay(ccsTRUE);

errPrint();

return (1);

}

if (server.InitTest())

{

return (0);

}

/*

* main loop

*/

server.Verbose("\nmyServer: entering main loop and waiting for commands!\n");

evhHandler->UseSelect(TRUE);

exitStatus = evhHandler->MainLoop();

return (exitStatus);

}

int main(int argc, char *argv[])

{

ccsERROR error;

int exitStatus;

char procName[64];

/*

* CCS init

*/

memset(procName, 0, sizeof(procName));

iracqRtapEnv(argc, argv, procName);

if (ccsInit(procName, 0, NULL, NULL, &error) == FAILURE)

{

errPrint();

exit(1);

}

/*

* call server

*/

exitStatus = serverProcess(argc, argv);

if (exitStatus == 1)

{

errCloseStack();

}

/*

* CCS exit

*/

ccsExit();

exit(exitStatus);

}

/*___oOo___*/

mySERVER.C:

#define _POSIX_SOURCE 1

#include "vltPort.h"

static char *rcsId="@(#) $Id: mySERVER.C,v 1.54+ 2000/12/20 16:43:04 vltsccm Exp $";

static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

/*

* System Headers

*/

#include <stdlib.h>

#include <stdio.h>

/*

* Local Headers

*/

#include "mySERVER.h"

mySRV *myPtr;

mySRV::mySRV()

{

myPtr = this;

/*

* initialize dummy value to be added to FITS-header

*/

dummyInt_ = 55;

dummyFloat_ = 55.5;

dummyDouble_ = 55.5;

strcpy(dummyString_, "dummy");

/*

* initialize parameter list for callback

*/

memset (&paramList_, `\0', sizeof(cmdPARAM_LIST));

}

mySRV::~mySRV()

{

iracqVB ("\nmyServer: terminating...");

cmdParamFree(&paramList_, stdErr);

}

void mySRV::PrintUsage(const char *argv0)

{

/*

* print out standard options

*/

iracqEVH::PrintUsage(argv0);

/*

* print out additional options

*/

fprintf(stdout, "\nmyOptions:");

fprintf(stdout, "\n\n");

}

ccsCOMPL_STAT mySRV::ParseInputPars(int argc, char *argv[])

{

ccsCOMPL_STAT retValOrig;

ccsCOMPL_STAT retVal;

/*

* pass arguments first to control server

*/

retValOrig = iracqEVH::ParseInputPars(argc, argv);

/*

* now parse arguments for additional options

* and decide, whether to return the original

* return value or an error

*/

retVal = retValOrig;

return (retVal);

}

ccsCOMPL_STAT mySRV::Init()

{

evhMSG_TYPE_KEY key;

ErrReset();

/*

* intitialize control server

*/

if (iracqEVH::Init() != SUCCESS)

{

return (FAILURE);

}

/*

* some dummy FITS-header additions

*/

if (AddFits("MY.INT", &dummyInt_, "My int") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MY.FLOAT", &dummyFloat_, "My float") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MY.DOUBLE", &dummyDouble_, "My double") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MY.STRING", dummyString_, "My string") == FAILURE)

{

return (FAILURE);

}

if (AddFits("My comment") == FAILURE)

{

return (FAILURE);

}

/*

* trace some dynamic parameters (if existing in read-out mode)

*/

if (AddFitsDynPar("DET.NC.MYPARAM1", "My dynamic parameter1") == FAILURE)

{

return (FAILURE);

}

if (AddFitsDynPar("DET.NC.MYPARAM2", "My dynamic parameter2") == FAILURE)

{

return (FAILURE);

}

/*

* introduce a new frame type

*/

if (AddFrame(myFRAME_TYPE, "MY-FRAME",

FALSE, FALSE, TRUE, "DET.NC.MYFRAME") == FAILURE)

{

ErrAdd(iracqMOD_ID, iracqERR_INIT, __FILE_LINE__,

"cannot add new frame");

return (FAILURE);

}

/*

* initialize additional database values

*/

iracqVB("\nmyServer: instance is %s...", Instance());

/*

* add additional callbacks

*/

iracqVB("\nmyServer: adding my callback...");

cb_.Object(this);

cb_.Proc((evhCB_METHOD2) &mySRV::MyCB);

key.MsgType(msgTYPE_COMMAND);

key.CommandId(0);

if (evhHandler->AddCallback(key.Command("MYCMD"), cb_) == FAILURE)

{

AbortServer();

ErrAdd(iracqMOD_ID, iracqERR_INIT, __FILE_LINE__,

"unable to add MYCMD callback");

return (FAILURE);

}

return (SUCCESS);

}

void mySRV::Verbose(const char *str, ...)

{

iracqEVH::Verbose(str);

/*

* here you can add your own verbose handler

*/

}

void mySRV::StateHandler(int state, int subState)

{

iracqEVH::StateHandler(state, subState);

/*

* here you can add your own status handler

*/

}

void mySRV::DataHandler(iracqDATA_EVT *evt)

{

iracqEVH::DataHandler(evt);

/*

* here you can add your own data event handler

*/

}

void mySRV::ExitHandler(int sig)

{

/*

* here you can add your own exit handler

*/

iracqVB("\nmyServer: exiting...");

iracqEVH::ExitHandler(sig);

}

ccsCOMPL_STAT mySRV::SeqHandler(const char *seqFile,

vltINT32 *loopCmd,

vltINT32 *loopCmdLen)

{

USE(loopCmd);

USE(seqFile);

*loopCmdLen = 0;

ErrAdd(iracqMOD_ID, iracqERR_SYSTEM, __FILE_LINE__,

"format of sequencer program is not supported");

return (FAILURE);

}

ccsCOMPL_STAT mySRV::SetParam(const char *name,

const char *value,

vltLOGICAL *handled)

{

char tmpStr[64];

*handled = TRUE;

if (strcmp(name, "DET.MYSETUP") == 0)

{

fprintf(stdout, "\nmyServer: doing MYSETUP (value = %s)...",

value);

sprintf(tmpStr, "-myArg %s", value);

/*

* do some action

*/

if (AcqParam(tmpStr) == FAILURE)

{

return (FAILURE);

}

fprintf(stdout, "\nmyServer: MYSETUP done...");

/*

* leave `handled' set to FALSE to apply the value also

* in sequence file or acq-process (if applicable)

*/

}

else if (strcmp(name, "DET.MYVAL") == 0)

{

fprintf(stdout, "\nmyServer: MYVAL = %s...",

value);

}

else

{

*handled = FALSE;

}

return (SUCCESS);

}

ccsCOMPL_STAT mySRV::GetParam(const char *name,

char *value,

vltINT32 *type,

vltLOGICAL *handled)

{

USE(name);

USE(value);

*handled = FALSE;

if (strcmp(name, "DET.MYVAL") == 0)

{

sprintf(value, "%d", dummyInt_);

*type = iracqTYPE_INT;

*handled = TRUE;

}

return (SUCCESS);

}

evhCB_COMPL_STAT mySRV::MyCB(msgMESSAGE &msg, void *)

{

void *paramValues;

char **stringVal;

vltINT32 paramNb;

cmdPARAM_TYPE paramType;

int i;

ErrReset();

EnterCB(msg, iracqDO_UPDATE);

fprintf(stdout, "\nmyServer: handling MYCMD (buffer is <%s>)...",

msg.Buffer());

/*

* unpack message buffer

*/

if (cmdParamList("MYCMD", msg.Buffer(), msg.Buflen(), &paramList_,

stdErr) == FAILURE)

{

ExitCB(msg);

return (evhCB_NO_DELETE);

}

/*

* -myParam

*/

if (cmdParamGetByName(&paramList_, "myParam", &paramNb, &paramType,

&paramValues, stdErr) == FAILURE)

{

ExitCB(msg);

return (evhCB_NO_DELETE);

}

if (paramNb > 0)

{

stringVal = (char **)paramValues;

fprintf(stdout, "\nmyServer: myParam = ");

for (i=0;i<paramNb;i++)

{

fprintf(stdout, "<%s> ", stringVal[i]);

}

}

fflush(stdout);

msg.Buffer("My-Reply");

ExitCB(msg);

return (evhCB_NO_DELETE);

}

/*___oOo___*/

11.2 DATA TRANSFER TASK EXTENSION

The following example for a derived data transfer task is also contained in the test directory of the iracq module:

myDTT.h:

#ifndef __cplusplus

#error This is a C++ include file and cannot be used from plain C

#endif

#include "iracqDTT_EVH.h"

class myDTT: public iracqDTT_EVH

{

public:

myDTT(); // constructor

virtual ~myDTT(); // destructor

// initialization routine

ccsCOMPL_STAT Init();

// command callbacks

evhCB_COMPL_STAT MyCB(msgMESSAGE &msg, void *udata);

// application specific frame processing

int ProcessFrame(sdmaFRAME_T *, char *);

protected:

private:

// callback structure

evhOBJ_CALLBACK cb_;

cmdPARAM_LIST paramList_;

// just some dummy variables to be added to FITS-header

int dummyInt_;

float dummyFloat_;

double dummyDouble_;

char dummyString_[128];

};

myDtt.C:

#define _POSIX_SOURCE 1

#include "vltPort.h"

static char *rcsId="@(#) $Id: myDtt.C,v 1.12+ 1999/12/14 11:42:19 vltsccm Exp $";

static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include <stdio.h>

#include <stdlib.h>

#include "myDTT.h"

/*

* control server

*/

static int server(int argc, char *argv[])

{

myDTT server;

int exitStatus = 0;

/*

* parse command line arguments

*/

if (server.ParseInputPars(argc, argv) == FAILURE)

{

server.PrintUsage(argv[0]);

errResetStack();

return (0);

}

/*

* intialize

*/

if (server.Init() == FAILURE)

{

fprintf(stderr, "\nmyDtt: initialization failed\n");

errPrint();

return (1);

}

/*

* main loop

*/

iracqVB("\nmyDtt: entering the main loop and waiting for commands!");

evhHandler->UseSelect(TRUE);

exitStatus = evhHandler->MainLoop();

return (exitStatus);

}

int main(int argc, char *argv[])

{

ccsERROR error;

int exitStatus;

char procName[64];

/*

* CCS init

*/

iracqRtapEnv(argc, argv, procName);

if (ccsInit(procName, 0, NULL, NULL, &error) == FAILURE)

{

errPrint(&error);

exit(1);

}

/*

* call server

*/

exitStatus = server(argc, argv);

if (exitStatus == 1)

{

errCloseStack();

}

/*

* CCS exit

*/

ccsExit();

fprintf(stderr, "\n");

exit(exitStatus);

}

/*___oOo___*/

myDTT.C:

#ifdef HP

#define _POSIX_SOURCE 1

#endif

#include "vltPort.h"

static char *rcsId="@(#) $Id: myDTT.C,v 1.54+ 2000/12/20 16:43:04 vltsccm Exp $";

static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include <stdio.h>

#include <stdlib.h>

#include "myDTT.h"

myDTT *myPtr;

myDTT::myDTT()

{

myPtr = this;

/*

* initialize dummy value to be added to FITS-header

*/

dummyInt_ = 65;

dummyFloat_ = 65.5;

dummyDouble_ = 65.5;

strcpy(dummyString_, "dtt dummy");

/*

* initialize parameter list for callback

*/

memset (&paramList_, `\0', sizeof(cmdPARAM_LIST));

}

myDTT::~myDTT()

{

iracqVB ("\nmyDtt: terminating...");

cmdParamFree(&paramList_, stdErr);

}

ccsCOMPL_STAT myDTT::Init()

{

evhMSG_TYPE_KEY key;

if (iracqDTT_EVH::Init() != SUCCESS)

{

return (FAILURE);

}

/*

* add additional callbacks

*/

iracqVB("\nmyDtt: adding my callback...");

cb_.Object(this);

cb_.Proc((evhCB_METHOD2) &myDTT::MyCB);

key.MsgType(msgTYPE_COMMAND);

key.CommandId(0);

if (evhHandler->AddCallback(key.Command("MYCMD"), cb_) == FAILURE)

{

ErrAdd(iracqMOD_ID, iracqERR_INIT, __FILE_LINE__,

"unable to add MYCMD callback");

return (FAILURE);

}

/*

* some dummy FITS-header additions

*/

if (AddFits("MYDTT.INT", &dummyInt_, "My int") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MYDTT.FLOAT", &dummyFloat_, "My float") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MYDTT.DOUBLE", &dummyDouble_, "My double") == FAILURE)

{

return (FAILURE);

}

if (AddFits("MYDTT.STRING", dummyString_, "My dtt string") == FAILURE)

{

return (FAILURE);

}

if (AddFits("My dtt comment") == FAILURE)

{

return (FAILURE);

}

return (SUCCESS);

}

evhCB_COMPL_STAT myDTT::MyCB(msgMESSAGE &msg, void *)

{

void *paramValues;

char **stringVal;

vltINT32 paramNb;

cmdPARAM_TYPE paramType;

int i;

ErrReset();

fprintf(stdout, "\nmyDtt: handling MYCMD (buffer is <%s>)...",

msg.Buffer());

/*

* unpack message buffer

*/

if (cmdParamList("MYCMD", msg.Buffer(), msg.Buflen(), &paramList_,

stdErr) == FAILURE)

{

return (evhCB_NO_DELETE);

}

/*

* -myParam

*/

if (cmdParamGetByName(&paramList_, "myParam", &paramNb, &paramType,

&paramValues, stdErr) == FAILURE)

{

return (evhCB_NO_DELETE);

}

if (paramNb > 0)

{

stringVal = (char **)paramValues;

fprintf(stdout, "\nmyDtt: myParam = ");

for (i=0;i<paramNb;i++)

{

fprintf(stdout, "<%s> ", stringVal[i]);

}

}

fflush(stdout);

msg.LastReply(ccsTRUE);

msg.Buffer("My-Reply");

msg.SendReply();

ErrStackClose();

return (evhCB_NO_DELETE);

}

int myDTT::ProcessFrame(sdmaFRAME_T *frame, char *erms)

{

USE(erms);

USE(frame);

printf("\nmyDTT: processing frame...");

dummyInt_++;

if (frame->h.ftype == sdmaFRAME_DIT)

{

FrameHandled();

}

return (iracqSUCCESS);

}

/*___oOo___*/



Quadralay Corporation
http://www.webworks.com
Voice: (512) 719-3399
Fax: (512) 719-3606
sales@webworks.com
TOC PREV NEXT INDEX