Example #1
0
int
main (int argc, char *argv[])
{
  pwr_tStatus	sts = 1;
  qdb_sPort	port;
  qdb_sPort	*pp;
  qcom_sQid	qid = qdb_cQimport;
  qdb_sNode	*np;

  errh_Init("pwr_qimp");

  if (!qcom_Init(&sts, NULL)) exit(sts);

  if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts);

  port.sa.sin_family = AF_INET;  
  port.sa.sin_addr.s_addr = htonl(INADDR_ANY);
  port.sa.sin_port = qdb->my_node->sa.sin_port;

  pp = qnet_Open(&sts, &port);

  while (qdb->g->up) {
    np = qnet_Get(&sts, pp);
    if (np->bp == NULL) pwr_Bugcheck(QCOM__WEIRD, "(np->bp == NULL)");
    linkEvent(pp, np);
  }

  qnet_Close(&sts, pp);
  qcom_Exit(&sts);

  exit(QCOM__SUCCESS);
}
Example #2
0
static pwr_tStatus events (
  ini_sContext	*cp
)
{
  pwr_tStatus	sts = INI__SUCCESS;
  qcom_sGet	get;
#if defined(OS_LYNX) || defined(OS_LINUX)
  int		tmo_ms = 1000;
#else
  int		tmo_ms = qcom_cTmoEternal;
#endif

  cp->myQ.qix = 550715;
  cp->myQ.nid = 0;

  qcom_CreateQ(&sts, &cp->myQ, NULL, "events");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (;;) {

    get.data = NULL;
    qcom_Get(&sts, &cp->myQ, &get, tmo_ms);
    
    /* Request for termination ?? */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.type.b == 11) {
      sts = terminate(cp);
      return sts;
    }    

  }
  return INI__SUCCESS;
}
Example #3
0
main (int argc, char *argv[])
{
  pwr_tStatus	sts;
  qcom_sQid	qid;
  qcom_sQid	fqid;
  qcom_sGet	get;
  qcom_sPut	put;
  qdb_sInit	init;
  qdb_sNode	*np;
  qcom_sQattr	attr;
  void		*p;

  if (!qcom_Init(&sts, NULL)) exit(sts);

  attr.type = qcom_eQtype_forward;
  attr.quota = 100;
  fqid.nid = pwr_cNNodeId;
  fqid.qix = 550715;

  if(!qcom_CreateQ(&sts, &fqid, &attr)) exit(sts);

  qid.nid = pwr_cNNodeId;
  qid.qix = qdb_cIloopBack;

  if(!qcom_CreateQ(&sts, &qid, NULL)) exit(sts);
  if(!qcom_Bind(&sts, &qid, &fqid)) exit(sts);

  while (1) {
    get.data = NULL;
    p = qcom_Get(&sts, &qid, &get, 60000);  
    if (p == NULL) continue;
//    printf("\nsender..: %d,%d\n", get.sender.nid, get.pid);
//    printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix);
//    printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix);
//    printf("type....: %d,%d\n", get.type.b, get.type.s);
//    printf("size....: %d\n", get.size);
    put.reply = qid;
    put.type = get.type;
    put.size = get.size;
    put.data = p;
    qcom_Put(&sts, &get.reply, &put);
    if (EVEN(sts))
      qcom_Free(&sts, p);
  }
}
Example #4
0
static pwr_sClass_IOHandler *
init (qcom_sQid *qid, lst_sEntry **csup_lh)
{
  pwr_tStatus sts = 1;
  pwr_sClass_IOHandler *ihp;
  qcom_sQattr qAttr;
  qcom_sQid qini;
  pwr_tObjid oid;

  errh_Init("pwr_io", errh_eAnix_io);

#if defined(OS_ELN)
  /* Event to kill dioc */
  ker$create_event(&sts, &io_comm_terminate, EVENT$CLEARED);
#endif

  if (!qcom_Init(&sts, 0, "pwr_io")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  sts = gdh_Init("pwr_io");
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted\n%m", sts);
    exit(sts);
  }

  sts = io_get_iohandler_object(&ihp, &oid);
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted, no IoHandler object found\n%m", sts);
    exit(sts);
  }

  aproc_RegisterObject( oid);

  *csup_lh = csup_Init(&sts, oid, ihp->CycleTimeBus);

  return ihp;
}
Example #5
0
pwr_tStatus
plc_UtlWaitForPlc ()
{
  pwr_tStatus sts = 1;
  qcom_sQid wait_q;

  if (!qcom_CreateQ(&sts, &wait_q, NULL, "plcUtlWaitForPlc"))
    return sts;

  qcom_WaitAnd(&sts, &wait_q, &qcom_cQini, ini_mEvent_newPlcStartDone, qcom_cTmoEternal);

  qcom_DeleteQ(NULL, &wait_q);

  return sts;
}
Example #6
0
static plc_sProcess *
init_process ()
{
  plc_sProcess	*pp;
  pwr_tStatus	sts = PLC__SUCCESS;

#if 0
  thread_SetPrio(NULL, 15);
#endif

  errh_Init("pwr_plc", errh_eAnix_plc);
  errh_SetStatus( PWR__SRVSTARTUP);

  pp = (plc_sProcess *) calloc(1, sizeof(*pp));
  if (pp == NULL) {
    errh_Fatal("Out of virtual memory");
    exit(0);
  }

  sts = gdh_Init("pwr_plc");
  if (EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

#if defined OS_VMS
  qdb->thread_lock.isThreaded = 1;
  qdb->thread_lock.cond_signal = thread_CondSignal;
  qdb->thread_lock.cond_wait = thread_CondWait;
#endif

  qcom_CreateQ(&sts, &pp->eventQ, NULL, "plcEvent");
  if (EVEN(sts)) {
    errh_Fatal("qcom_CreateQ(eventQ), %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

  sts = thread_MutexInit(&pp->io_copy_mutex);
  if (EVEN(sts)) {
    errh_Fatal("thread_MutexInit(io_copy_mutex), %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

  return pp;
}
Example #7
0
int Jop::create_que()
{
  int sts;
  qcom_sQattr attr;
  qcom_qid = qcom_cNQid;

  attr.type = qcom_eQtype_private;
  attr.quota = 100;
  if (!qcom_CreateQ(&sts, &qcom_qid, &attr, "XttCommands")) 
  {
    printf("Failed to create QCOM que %d\n", sts);
    return sts;
  }
  printf( "Qcom que qix : %d, nid: %d\n", qcom_qid.qix, qcom_qid.nid);
  return XNAV__SUCCESS;
}
Example #8
0
static void init(qcom_sQid* myQid)
{
  pwr_tStatus sts;

  sts = gdh_Init("pwr_nacp");
  if (EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

#if defined OS_CYGWIN
  qcom_sQattr qAttr;
  qcom_sQid qid = qcom_cQnacp;

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &qid, &qAttr, "nacp")) {
    errh_Error("Failed to create QCOM que\n%m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
#else
  if (!qcom_AttachQ(&sts, &qcom_cQnacp)) {
    errh_Fatal("qcom_AttachQ, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }
#endif
  *myQid = qcom_cQnacp;

  if (!qcom_Bind(&sts, myQid, &qcom_cQini)) {
    errh_Fatal("qcom_Bind, %m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(-1);
  }

  /* Activate all subscriptions that were requested before we started!  */

  gdb_ScopeLock
  {
    gdbroot->db->neth_acp = *myQid;
    subc_ActivateList(&gdbroot->my_node->subc_lh, pwr_cNObjid);
    subc_ActivateList(&gdbroot->no_node->subc_lh, pwr_cNObjid);
  }
  gdb_ScopeUnlock;
}
Example #9
0
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createQ
  (JNIEnv *env, jobject object, jint qix, jint nid, jstring jname)
{
  jclass 	qcomrCreateQ_id;
  jmethodID 	qcomrCreateQ_cid;
  jobject 	return_obj;
  jint		jsts;
  qcom_sQid	qid;
  qcom_sQattr	attr;
  int		sts;
  char		*cstr;
  const char 	*name;

//  qcom_sQid other_que = qcom_cQapplEvent;

  qcomrCreateQ_id = (*env)->FindClass( env, "jpwr/rt/QcomrCreateQ");
  qcomrCreateQ_cid = (*env)->GetMethodID( env, qcomrCreateQ_id,
    	"<init>", "(III)V");

  name = (*env)->GetStringUTFChars( env, jname, 0);
  cstr = (char *)name;

  attr.type = qcom_eQtype_private;
  attr.quota = 100;
  qid.qix = qix;
  qid.nid = nid;
  qcom_CreateQ( &sts, &qid, &attr, cstr);
  (*env)->ReleaseStringUTFChars( env, jname, cstr);
  //printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts);
  jsts = (jint) sts;
  return_obj = (*env)->NewObject( env, qcomrCreateQ_id,
  	qcomrCreateQ_cid, qid.qix, qid.nid, jsts);

  // Bind to broadcast que
  // qcom_Bind( &sts, &qid, &other_que);
  // if ( EVEN(sts))
  //   printf("** Unable to bind to qcom broadcast que\n");

  return return_obj;
}
Example #10
0
void init( qcom_sQid *qid)
{
  qcom_sQid qini;
  qcom_sQattr qAttr;
  pwr_tStatus sts;

  sts = gdh_Init("rt_sysmon");
  if ( EVEN(sts)) {
    errh_Fatal( "gdh_Init, %m", sts);
    exit(sts);
  }

  errh_Init("pwr_sysmon", errh_eAnix_sysmon);
  errh_SetStatus( PWR__SRVSTARTUP);

  if (!qcom_Init(&sts, 0, "pwr_sysmon")) {
    errh_Fatal("qcom_Init, %m", sts); 
    errh_SetStatus( PWR__SRVTERM);
   exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(-1);
  }
}
Example #11
0
static pwr_tStatus
interactive (
  int		argc,
  char		**argv,
  ini_sContext	*cp
)
{
  pwr_tStatus	sts;
  qcom_sQid	qid;
  qcom_sPut	put;
  qcom_sGet	get;
  char		*bp, *sp;
  int		i;
  int		len;
  int		totlen;

  errh_Interactive();

  if (!qcom_Init(&sts, 0, "pwr_ini_restart")) {
    errh_LogFatal(&cp->log, "qcom_Init, %m", sts);
    exit(sts);
  } 

  qcom_CreateQ(&sts, &cp->myQ, NULL, "pwr_ini_restart");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (i = 0, totlen = 0; i < argc; i++) {
    len = strlen(argv[i]);
    totlen += 1 + len;
    errh_LogInfo(&cp->log, "argv[%d]: %d \"%s\"", i, len, argv[i]);
  }
  bp = malloc(totlen);
  for (i = 0, sp = bp; i < argc; i++) {
    len = strlen(argv[i]);
    memcpy(sp, argv[i], len + 1);
    sp += len + 1;
  }
  
  qid.qix = 550715;
  qid.nid = 0;
    put.type.b = 10;
    put.type.s = 1;
    put.reply = cp->myQ;
    put.data = bp;
    put.size = totlen;
  qcom_Put(&sts, &qid, &put);

  while (1) {
    char *s;

    get.data = NULL;
    s = qcom_Get(&sts, &cp->myQ, &get, 100000);
    if (sts == QCOM__TMO && sts == QCOM__QEMPTY) {
      break;
    } else if (s != NULL) {
      printf("%s\n", s);
      qcom_Free(NULL, s);
    }
    if (get.type.s == 2)
      break;
  }

  return sts;
}
Example #12
0
static pwr_tStatus
start (
  ini_sContext *cp
)
{
  pwr_tStatus sts;
  char console[80];

#if defined OS_POSIX
  int	fd;

  if ( strcmp( cp->console, "") == 0)
    strcpy( console, "/dev/console");
  else
    strcpy( console, cp->console);
  if ((fd = open(console, O_APPEND | O_WRONLY)) == -1)
    errl_Init(NULL, ini_errl_cb, cp);
  else {
    close(fd);
    errl_Init(console, ini_errl_cb, cp);
  }
#else
  errl_Init("CONSOLE:", ini_errl_cb, cp);
#endif

  errh_Init("pwr_ini", errh_eAnix_ini);

  if ( cp->flags.b.interactive)    
    errh_Interactive();

  mh_UtilCreateEvent();

  ini_CheckContext(&sts, cp);

  ini_ReadBootFile(&sts, cp);
  ini_ReadNodeFile(&sts, cp);
  ini_CheckNode(&sts, cp);

  cp->me = tree_Find(&sts, cp->nid_t, &cp->node.nid);
  if (cp->me == NULL) {
    errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name);
    exit(QCOM__WEIRD);
  }

  if (!checkErrors(cp))
    exit(0);

  if (cp->flags.b.verbose)
    logCardinality(cp);

  ini_CreateDb(&sts, cp);

  ini_LoadNode(&sts, cp);

  ini_BuildNode(&sts, cp);

  if (cp->np != NULL) {
    if (cp->np->ErrLogTerm[0] != '\0') {
      errh_LogInfo(&cp->log, "Setting log terminal to: %s", cp->np->ErrLogTerm);
      errl_SetTerm(cp->np->ErrLogTerm);
    }

/* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ 

    char fname[256];
    sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename);
    dcli_translate_filename(fname, fname);
    errl_SetFile(fname);
    errh_LogInfo(&cp->log, "Setting log file to: %s", fname);

/*
    if (cp->np->ErrLogFile[0] != '\0') {
      struct tm *tp;
      char fname[256];
      time_t t;

      time(&t);
      tp = localtime(&t);
      strftime(fname, sizeof(fname), cp->np->ErrLogFile, tp );
      dcli_translate_filename( fname, fname);
      errl_SetFile(fname);
      errh_LogInfo(&cp->log, "Setting log file to: %s", cp->np->ErrLogFile);
    }
*/
  }

  ini_SetSystemStatus( cp, PWR__STARTUP);
  errh_SetStatus( PWR__STARTUP);

  sts = ini_RcReadAndSet(cp->dir, cp->nodename, cp->busid);
  if (EVEN(sts))
    errh_LogError(&cp->log, "ini_RcReadAndSet, %m", sts);

  sts = ini_SetAttribute(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttribute, %m", sts);

  qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid);

  io_init_signals();

  load_backup();

#if defined OS_ELN
  ker$initialization_done(NULL);
#endif

  ini_ProcTable(&sts, cp);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_system, 0, ini_ProcPrio);

  net_Connect(&sts, &gdbroot->my_aid, &gdbroot->my_qid, NULL, "pwr_ini");
  /*if (!qcom_Init(&sts, 0)) {*/
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "net_Connect, %m", sts);
    exit(sts);
  }   

  qcom_SignalOr(&sts, &qcom_cQini, ini_mEvent_newPlcInit | ini_mEvent_newPlcStart);

  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcLoad);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_user, 0, ini_ProcPrio);

  qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  qcom_WaitAnd(&sts, &cp->eventQ, &qcom_cQini, ini_mEvent_newPlcStartDone | cp->plc_sigmask, qcom_cTmoEternal);

  sts = ini_SetAttributeAfterPlc(cp->aliasfile.name, cp->nodename, 0);
  if (EVEN(sts) && sts != INI__FILE)
    errh_LogError(&cp->log, "ini_SetAttributeAfterPlc, %m", sts);
         
  ini_SetSystemStatus( cp, PWR__RUNNING);
  errh_SetStatus( PWR__SRUN);

  return sts;
}
Example #13
0
int main (int argc, char **argv)
{
  pwr_tStatus      sts;
  unsigned int     size;
  qcom_sQid        myQId;
  alimsrv_sSupDataBuf *bp;
  qcom_sGet        get;
  qcom_sPut        put;
  alimsrv_sRequest request;
  XDR              xdrs;
  qcom_sQattr      qAttr;

  errh_Init("pwr_alim", errh_eAnix_alim);
  errh_SetStatus( PWR__SRVSTARTUP);

  if (!qcom_Init(&sts, 0, "pwr_alim")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(-1);
  } 

  myQId.qix = alimsrv_cQix;
  myQId.nid = 0;
  qAttr.type  = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &myQId,  &qAttr, "pwr_alim")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(-1);
  } 
  if (!qcom_Bind(&sts, &myQId, &qcom_cQini)) {
    errh_Fatal("qcom_Bind, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(-1);
  }

  sts = gdh_Init("pwr_alim");
  if (EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(-1);
  } 

  init();

  errh_SetStatus( PWR__SRUN);

  /* Loop forever and receive objid's */

  for (;;) {
    do {
      get.maxSize = sizeof(request);
      get.data = (char *)&request;
      qcom_Get(&sts, &myQId, &get, qcom_cTmoEternal);
      if (sts != QCOM__TMO && sts != QCOM__QEMPTY) {
        if (get.type.b == qcom_eBtype_event) {
          event(&get);
        }
      }
    } while (ODD(sts) && get.type.s != alimsrv_eSubType_Request && get.type.b != alimsrv_cMsgType);

    if (EVEN(sts)) {
      errh_Error("qcom_Get, %m",sts);
      continue;
    }

    if (request.Xdr) {
      xdrmem_create(&xdrs, (char *)&request, sizeof(request), XDR_DECODE);
      if (!xdr_alimsrv_sRequest(&xdrs, &request)) {
	errh_Error("XDR Decode failed");
	continue;
      }
    }

    bp = buildBuffer(&request, &size);

    if (ODD(sts)) {
      bp->Xdr = TRUE;
      xdrmem_create(&xdrs, (char *)bp, size, XDR_ENCODE);
      if (!xdr_alimsrv_sSupDataBuf(&xdrs, bp)) {
	errh_Error("XDR Encode failed");
      } else {
	put.type.b = alimsrv_cMsgType;
	put.type.s = alimsrv_eSubType_Answer;
	put.reply = myQId;
	put.data = (char *) bp;
	put.size = size;

	if (!qcom_Reply(&sts, &get, &put))
	  errh_Error("qcom_Respond, %m", sts);
      }            

      free(bp);
    }
  }    
}
Example #14
0
int main (int argc, char **argv)
{
  pwr_tStatus	    sts;
  pwr_tObjid	    ObjId;
  pwr_sClass_DsTrendConf *TConfP;
  pwr_tBoolean    InitOK;
  pwr_tTime		CurrentTime, LastScan, NextScan;
  pwr_tDeltaTime	ScanDeltaTime, WaitTime;
  qcom_sQid qini;
  qcom_sQattr qAttr;
  int tmo;
  char mp[2000];
  qcom_sQid qid = qcom_cNQid;
  qcom_sGet get;
  int swap = 0;
  trend_tCtx ctx;

  errh_Init("pwr_trend", errh_eAnix_trend);
  errh_SetStatus( PWR__SRVSTARTUP);

  sts = gdh_Init("ds_trend");
  If_Error_Log_Exit(sts, "gdh_Init");

  if (!qcom_Init(&sts, 0, "pwr_trend")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, &qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx));

  /* Wait until local nethandler has started */
  while(EVEN(gdh_NethandlerRunning()))
    sleep(1);

  /* Fetch ScanTime */
  sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId);
  if (EVEN(sts)) {
    errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s");
    ctx->scantime = 1;
    ctx->scantime_tc = 1.0;
  } 
  else {
    gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP);
    ctx->scantime = TConfP->ScanTime;
    if ( ctx->scantime > 3600)
      ctx->scantime = 3600;
    else if ( ctx->scantime < 1)
      ctx->scantime = 1;

    ctx->scantime_tc = TConfP->ScanTime;
    if ( ctx->scantime_tc > 3600)
      ctx->scantime_tc = 3600;
  }
  ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5);

  aproc_RegisterObject( ObjId);

  InitOK = FALSE;
  sts = InitTrendList( ctx);
  if ( EVEN(sts)) { 
    /* This should be removed when we can wait for init messages. */
    errh_SetStatus(0);
    errh_Info("No DsTrend objects configured");
    exit(0);
  }

  /* If even sts, just wait for init message */

  time_GetTimeMonotonic(&LastScan);
  time_FloatToD( &ScanDeltaTime, ctx->scantime_tc);

  aproc_TimeStamp( ctx->scantime, 5.0);
  errh_SetStatus( PWR__SRUN);

  for (;;) {

    time_GetTimeMonotonic(&CurrentTime);
    time_Aadd(&NextScan, &LastScan, &ScanDeltaTime);
    if (time_Acomp(&CurrentTime, &NextScan) < 0) { 
      time_Adiff(&WaitTime, &NextScan, &CurrentTime);
      tmo = 1000 * time_DToFloat( 0, &WaitTime);

      get.maxSize = sizeof(mp);
      get.data = mp;
      qcom_Get( &sts, &qid, &get, tmo);
      if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
	if ( !swap)
	  StoreData( ctx);
      } 
      else {
	ini_mEvent  new_event;
	qcom_sEvent *ep = (qcom_sEvent*) get.data;

	new_event.m  = ep->mask;
	if (new_event.b.oldPlcStop && !swap) {
	  swap = 1;
	  errh_SetStatus( PWR__SRVRESTART);
	  CloseTrendList( ctx);
	} 
	else if (new_event.b.swapDone && swap) {
	  swap = 0;
	  sts = InitTrendList( ctx);
	  errh_SetStatus( PWR__SRUN);
	  errh_Info("Warm restart completed");
	}
	else if (new_event.b.terminate) {
	  exit(0);
	}
      }
    }
    else if ( !swap)
      StoreData( ctx);

    LastScan = NextScan;

    aproc_TimeStamp( ctx->scantime, 5.0);
  }

  return 1;
}
Example #15
0
int
main (
  int			argc,
  char			**argv
)
{
  pwr_tStatus           sts;
  time_tClock		wait_clock;
  qcom_sQid	        my_q = qcom_cNQid;
  qcom_sGet	        get;
  int                   tmo_ms = 0;

  // mcheck(memCheck);
  
  init();

  if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) {
    exit(sts);
  }
  if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) {
    exit(-1);
  }

  gdbroot->db->log.b.tmon = 0;

  for (wait_clock = 0;;) {

    if (wait_clock != 0) {
      waitClock(wait_clock, &tmo_ms);
    }
    else {
      tmo_ms = 0;
    }

#if defined OS_POSIX
    aproc_TimeStamp( ((float)tmo_ms)/1000, 5);

    get.data = NULL;
    qcom_Get(&sts, &my_q, &get, tmo_ms);
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY) {
      if (get.type.b == qcom_eBtype_event) {
        event(&get);
      }
      qcom_Free(&sts, get.data);
    }      
#endif

    now_clock = time_Clock(NULL, NULL);
    if (now_clock < last_clock) { 
      errh_Info("The uptime clock has wrapped");
      toggleWrapped();
      executeExpired(&wrap_lh, 1);
    }

    getNewTimers();
    executeExpired(&timer_lh, 0);

    last_clock = now_clock;
    now_clock = time_Clock(NULL, NULL);

    getWaitClock(&wait_clock, last_clock);
    
  }
}
Example #16
0
static pwr_tStatus start( ini_sContext *cp)
{
  pwr_tStatus sts;
  char console[80];
  qini_sNode		*nep;
  qcom_sAid aid;

  int	fd;

  if ( strcmp( cp->console, "") == 0)
    strcpy( console, "/dev/console");
  else
    strcpy( console, cp->console);
  if ((fd = open(console, O_APPEND | O_WRONLY)) == -1)
    errl_Init(NULL, ini_errl_cb, cp);
  else {
    close(fd);
    errl_Init(console, ini_errl_cb, cp);
  }

  errh_Init("pwr_ini", errh_eAnix_ini);

  if ( cp->flags.b.interactive)    
    errh_Interactive();

  ini_CheckContext(&sts, cp);

  ini_ReadBootFile(&sts, cp);
  ini_ReadNodeFile(&sts, cp);


  for (nep = tree_Minimum(&sts, cp->nid_t); nep != NULL; nep = tree_Successor(&sts, cp->nid_t, nep)) {
    if ( strcmp( cp->nodename, nep->name) == 0) {
      cp->me = nep;
      break;
    }
  }      
  if (cp->me == NULL) {
    errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name);
    exit(QCOM__WEIRD);
  }

  if (!checkErrors(cp))
    exit(0);

  /* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ 

  char fname[256];
  sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename);
  dcli_translate_filename(fname, fname);
  errl_SetFile(fname);
  errh_LogInfo(&cp->log, "Setting log file to: %s", fname);

  // ini_SetSystemStatus( cp, PWR__STARTUP);
  errh_SetStatus( PWR__STARTUP);

  qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid);


  ini_ProcTable(&sts, cp);
  ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcPrio);

  ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcStart);
  ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcPrio);

  qcom_Init(&sts, &aid, "pwr_sev_init");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_Init, %m", sts);
    exit(sts);
  }

  qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }
         
  // ini_SetSystemStatus( cp, PWR__RUNNING);
  errh_SetStatus( PWR__SRUN);

  return sts;
}
Example #17
0
int main()
{
	logg_ctx	loggctx;
	pwr_tStatus	sts;
	pwr_tUInt32	ident;
	char		*msg;
	logg_t_loggconf_list	*conflist_ptr;
	int		i;

#if defined OS_LYNX || defined OS_LINUX

	/* Exit handler */

	atexit(&exit_hdlr);
	signal(SIGINT, interrupt_hdlr);

#endif

	sts = gdh_Init("rs_remote_logg");
	if (EVEN(sts)) LogAndExit(sts);

	/* Errh init */

	errh_Init("rs_remote_logg", 0);

	/* Initialize qcom que attributes */

	remlogg_qattr.type = qcom_eQtype_private;
	remlogg_qattr.quota = 100;

	/* Delete the queue if it exists */

        qcom_DeleteQ(&sts, &remlogg_qid);
	
	/* Create the remlogg queue */

        if (!qcom_CreateQ(&sts, &remlogg_qid, &remlogg_qattr, "Logg")) {
	  LogAndExit(sts);
        }

	/* Bind it to rt_ini event-queue */
	
        if (!qcom_Bind(&sts, &remlogg_qid, &qcom_cQini)) {
          errh_Fatal("qcom_Bind, %m", sts);
//          errh_SetStatus( PWR__SRVTERM);
          exit(-1);
        }

	loggctx = calloc( 1 , sizeof( *loggctx));
	if ( loggctx == 0 ) LogAndExit( REM__NOMEMORY);

	sts = logg_init( loggctx);
	if ( EVEN(sts)) LogAndExit(sts);
	
	for (;;)
	{
	  /* Get logg message */
	  sts = logg_get_message( loggctx, &ident, &msg);
	  if ( EVEN(sts))
	  {
	    Log( REM__LOGGRCV, sts);
	  }
	  else if ( sts != REM__TIMEOUT)
	  {
	    logg_print( loggctx, ident, msg);
	    sts = logg_free_message();
	  }

	  /* Check if its time to open any file... */
	  conflist_ptr = loggctx->loggconflist;
	  for ( i = 0; i < loggctx->loggconf_count; i++)
	  {
	    if ( conflist_ptr->loggconf->NewVersion)
	    {
	      conflist_ptr->loggconf->NewVersion = 0;
	      if ( conflist_ptr->file_open)
	      {
	        fclose( conflist_ptr->outfile);
	        conflist_ptr->file_open = 0;
	        sts = logg_open_file( conflist_ptr, 1);
	      }
	    }
	    else if ( !conflist_ptr->file_open)
	    {
	      sts = logg_open_file( conflist_ptr, 0);
	    }
	    conflist_ptr++;
	  }
	}
}
Example #18
0
main (int argc, char *argv[])
{
  pwr_tStatus	sts;
  qcom_sQid	qid;
  qcom_sGet	get;
  qcom_sPut	put;
  qcom_sQid	loop;
  int		data[500];
  int		i;
  int		j;
  int		max = 1000;
  char		*sp;
  int tmo;

  qid = qcom_cNQid;

  if (argc < 2) exit(12);
  if (argc > 2) max = atoi(argv[2]);

  for (j = 0; j < 500; j++)
    data[j] = j;

  loop.nid = atoi(argv[1]);
  loop.qix = qcom_cIloopBack;

  if (!qcom_Init(&sts, NULL)) exit(sts);
  if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts);

  for (i = 1; i < max; i++) {
    for (j = 0; j < 500; j++)
      ++data[j];
    sp = qcom_Alloc(&sts, sizeof(data));
    if (sp == NULL) exit(sts);
    memcpy(sp, &data, sizeof(data));
    put.type.b = 10;
    put.type.s = i;
    put.reply = qid;
    put.size = sizeof(data);
    put.data = sp;

    get.data = NULL;

    
    tmo = 10 + (i%3)*3000;
    sp = qcom_Request(&sts, &loop, &put, &qid, &get, tmo);

    if (sp == NULL) {
      printf("\n%d tmo: %d empty buffer\n", i, tmo);
      continue;
    }
    for (j = 0; j < 500; j++) {
      if (data[j] != *(int *)sp) break;
      sp += sizeof(int);
    }
    printf("\nsender..: %d,%X\n", get.sender.nid, get.pid);
    printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix);
    printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix);
    printf("type....: %d,%d\n", get.type.b, get.type.s);
    printf("size....: %d\n", get.size);
    printf("memcmp..: %d\n", memcmp(get.data, &data, sizeof(data)));
    printf("index...: %d, (%d)\n", j, data[j]);
    qcom_Free(&sts, get.data);
  }

  qcom_Exit(&sts);
}
Example #19
0
int 
main ()
{
  pwr_tStatus sts;
  pwr_tObjid  oid;
  qcom_sQid   my_q = qcom_cNQid;
  qcom_sGet   get;

  pwr_tBoolean firstTime = TRUE;
  pwr_tUInt32 nrOfEvents = 0;
  pwr_tUInt32 nrOfKeys = 0;
  
  errh_Init("pwr_elog", errh_eAnix_elog);
  errh_SetStatus( PWR__SRVSTARTUP);

  memset(&lHelCB, 0, sizeof(lHelCB));

  /* Declare process */
  sts = gdh_Init("pwr_elog");
  If_Error_Log_Exit(sts, "gdh_Init");

  Init();

  /* Create queue for receival of events */
  if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    errh_SetStatus( PWR__APPLTERM);
    exit(sts);
  } 

  if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    errh_SetStatus( PWR__APPLTERM);
    exit(-1);
  }
  
  oid.vid = lHelCB.Nid;
  oid.oix = pwr_cNVolumeId;

  sts = mh_OutunitConnect(
    oid, 
    mh_eOutunitType_Logger, 
    mh_mOutunitFlags_ReadWait, 
    (mh_cbOutunitAck)Insert, 
    (mh_cbOutunitAlarm)Insert, 
    (mh_cbOutunitBlock)Insert, 
    (mh_cbOutunitCancel)Insert, 
    NULL, 
    NULL, 
    (mh_cbOutunitInfo)Insert,
    (mh_cbOutunitReturn)Insert,
    NULL
  );
  If_Error_Log_Exit(sts, "mh_OutunitConnect");

  sts = mh_OutunitSetTimeout(lHelCB.ScanTime);

  errh_SetStatus( PWR__SRUN);

  for (;;) {
    sts = mh_OutunitReceive();
    if (EVEN(sts) && sts != MH__TMO)
      Log_Error(sts, "mh_OutunitReceive");
    Store(&firstTime, &nrOfEvents, &nrOfKeys);

    get.data = NULL;
    qcom_Get(&sts, &my_q, &get, 0);
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY) {
      if (get.type.b == qcom_eBtype_event) {
        qcom_sEvent  *ep = (qcom_sEvent*) get.data;
        ini_mEvent    new_event;
        if (get.type.s == qcom_cIini) {
          new_event.m = ep->mask;
          if (new_event.b.terminate) {
            errh_SetStatus( PWR__APPLTERM);
            exit(0);
          }
        }
      }
      qcom_Free(&sts, get.data);
    }

    aproc_TimeStamp( lHelCB.ScanTime/1000, 5.0);
  }
}
Example #20
0
static pwr_tStatus
events (
  ini_sContext	*cp
)
{
  lst_sEntry	*pl;
  ini_sProc	*pp;
  pid_t		pid;
  pid_t		last_pid = 1;
  pwr_tStatus	sts = INI__SUCCESS;
  qcom_sGet	get;
#if defined OS_POSIX
  int		tmo_ms = 1000;
#else
  int		tmo_ms = qcom_cTmoEternal;
#endif

  cp->myQ.qix = 550715;
  cp->myQ.nid = 0;

  qcom_CreateQ(&sts, &cp->myQ, NULL, "events");
  if (EVEN(sts)) {
    errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts);
    exit(sts);
  }

  for (;;) {
    int status;

    get.data = NULL;
    qcom_Get(&sts, &cp->myQ, &get, tmo_ms);
    
    /* Request for termination ?? */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.type.b == 11) {
      sts = terminate(cp);
      return sts;
    }
    
    /* Request for restart */
    if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.data != NULL) {
      int len, i, argc, totlen;
      char **argv, *s;
      ini_sContext *ncp;

      for (argc = 0, s = get.data, totlen = 0; totlen < get.size; argc++) {
	len = strlen(s);
	s += len + 1;
	totlen += len + 1;
      }
      argv = (char **) calloc(sizeof(void*), argc);
      for (i = 0, s = get.data; i < argc; i++) {
	len = strlen(s);
	argv[i] = s;
	s += len + 1;
      }
      ncp = createContext(argc, argv);
      if (ncp != NULL) {
	ncp->log.put.type.b = 10;
	ncp->log.put.type.s = 1;
	ncp->log.send = 1;
	ncp->log.put.reply = cp->myQ;
	ncp->log.logQ = get.reply;
	ncp->eventQ = cp->eventQ;
	ncp->yourQ = get.reply;
	restart(ncp);
	free(ncp);
      }
      free(argv);
      qcom_Free(NULL, get.data);
    }

#if defined OS_POSIX
    if (lst_Succ(NULL, &cp->proc_lh, &pl) == NULL) break;
    pid = waitpid(-1, &status, WNOHANG|WUNTRACED);
    if (pid == 0) continue;
    if (pid == last_pid) break;
    
    for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) {
      if (pp->proc.pid == pid) {
	errh_LogInfo(&cp->log, "Process %s exited with status %d", pp->proc.name, status);
	break;
      }
    }
#endif

  }
  return INI__SUCCESS;
}
Example #21
0
main (int argc, char *argv[])
{
  pwr_tStatus	sts;
  qcom_sQid	qid;
  qcom_sGet	get;
  qcom_sPut	put;
  qcom_sQid	loop;
  int		data[DATA_SIZE];
  int		i;
  int		j;
  int		max = 1000;
  char		*sp;

  qid = qcom_cNQid;

  if (argc < 2) exit(12);
  if (argc > 2) max = atoi(argv[2]);

  for (j = 0; j < DATA_SIZE; j++)
    data[j] = j;

  loop.nid = atoi(argv[1]);
  loop.qix = qcom_cIloopBack;

  if (!qcom_Init(&sts, NULL)) exit(sts);
  if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts);

  for (i = 1; i < max; i++) {
    for (j = 0; j < DATA_SIZE; j++)
      ++data[j];
    sp = qcom_Alloc(&sts, sizeof(data));
    if (sp == NULL) exit(sts);
    memcpy(sp, &data, sizeof(data));
    put.type.b = 10;
    put.type.s = i;
    put.reply = qid;
    put.size = sizeof(data);
    put.data = sp;
    qcom_Put(&sts, &loop, &put);
    if (EVEN(sts)) exit(sts);
    get.data = NULL;
    sp = qcom_Get(&sts, &qid, &get, qcom_cTmoEternal);  
    if (sp == NULL) continue;
    for (j = 0; j < DATA_SIZE; j++) {
      if (data[j] != *(int *)sp) {
	printf("index...: %d, (%d)\n", j, data[j]);
	break;
      }
      sp += sizeof(int);
    }
//    printf("\nsender..: %d,%X\n", get.sender.nid, get.pid);
//    printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix);
//    printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix);
//    printf("type....: %d,%d\n", get.type.b, get.type.s);
//    printf("size....: %d\n", get.size);
//    printf("memcmp..: %d\n", memcmp(get.data, &data, sizeof(data)));
//    printf("index...: %d, (%d)\n", j, data[j]);
    qcom_Free(&sts, get.data);
  }

  qcom_Exit(&sts);
}
Example #22
0
/*
 * Class:     jpwr_rt_Qcom
 * Method:    createIniEventQ
 * Signature: ()Ljpwr/rt/QcomrCreateQ;
 */
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createIniEventQ
  (JNIEnv *env, jobject object, jstring jname)
{

  jclass 	qcomrCreateQ_id;
  jmethodID 	qcomrCreateQ_cid;
  jobject 	return_obj;
  jint		jsts;
  qcom_sQid	qid = qcom_cNQid;
  qcom_sQattr	qAttr;
  qcom_sQid     qini;
  int		sts;
  char		*cstr;
  const char 	*name;

  qcomrCreateQ_id = (*env)->FindClass( env, "jpwr/rt/QcomrCreateQ");
  qcomrCreateQ_cid = (*env)->GetMethodID( env, qcomrCreateQ_id,
    	"<init>", "(III)V");

  name = (*env)->GetStringUTFChars( env, jname, 0);
  cstr = (char *)name;


  //printf("%s\n", cstr);
  // Create a queue to receive stop and restart events
  if (!qcom_Init(&sts, 0, cstr)) {
    errh_Fatal("qcom_Init, %m", sts); 
    errh_SetStatus( PWR__APPLTERM);
    exit(sts);
  } 



  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100; 
  if (!qcom_CreateQ(&sts, &qid, &qAttr, cstr)) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    errh_SetStatus( PWR__APPLTERM);
    exit(sts);
  } 

  (*env)->ReleaseStringUTFChars( env, jname, cstr);


  //printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts);
  jsts = (jint) sts;
  return_obj = (*env)->NewObject( env, qcomrCreateQ_id,
  	qcomrCreateQ_cid, qid.qix, qid.nid, jsts);


  qini = qcom_cQini;
  if (!qcom_Bind(&sts, &qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    errh_SetStatus( PWR__APPLTERM);
    exit(-1);
  }


  return return_obj;

}
Example #23
0
int main (int argc, char ** argv)
{
  pwr_tStatus	sts;
  qcom_sQid	my_q = qcom_cNQid;
  qcom_sGet	get;

  errh_Init("pwr_linksup", errh_eAnix_linksup);
  errh_SetStatus( PWR__SRVSTARTUP);

  if (!qcom_Init(&sts, NULL, "pwr_linksup")) {
    errh_Error("qcom_Init, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

  sts = gdh_Init("pwr_linksup");
  if (EVEN(sts)) {
    errh_Fatal("gdh_Init, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }

  if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(sts);
  }
  if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    errh_SetStatus( PWR__SRVTERM);
    exit(-1);
  }

  /* Wait for local nethandler to start */

  while (EVEN(gdh_NethandlerRunning()))
    sleep(1);   

  plc_UtlWaitForPlc();

  LstIni(&node_l);
  LstIni(&timer_l);

  init_nodes();
  if (!LstEmp(&node_l)) {
    list_state = eListState_Scan;
  } else {
    errh_Info("No nodes to supervise, exiting");
    errh_SetStatus( pwr_cNStatus);
    exit(0);
  }

  errh_SetStatus( PWR__SRUN);

  for (;;) {
    scan_timers();
    scan_nodes();
    get.data = NULL;
    if (qcom_Get(&sts, &my_q, &get, cTimerTimeScan) != NULL) {
      if (get.type.b == qcom_eBtype_event) {
	event(&get);
      } else {
	errh_Info("unexpected message type, type: %d", get.type.b);
      }
      qcom_Free(&sts, get.data);
    }
    aproc_TimeStamp(((float)cTimerTimeScan)/1000, 5);
  }
}
Example #24
0
int main(int argc, char** argv)
{
  pwr_tStatus sts;
  io_tCtx io_ctx;
  float ctime = 1;

  pwr_sClass_EplHandler* plhp;
  pwr_tOid oid;
  int tmo;
  char mp[2000];
  qcom_sGet get;
  qcom_sQattr qAttr;
  qcom_sQid qini;
  qcom_sQid qid = qcom_cNQid;

  if (argc > 1) {
    if (streq(argv[1], "-m")) {
      io_methods_print();
      exit(0);
    }
    if (streq(argv[1], "-h")) {
      usage();
      exit(0);
    }
  }

  // Make connection to error handler
  errh_Init("pwr_powerlink", errh_eAnix_powerlink);
  errh_SetStatus(PWR__SRVSTARTUP);

  if (!qcom_Init(&sts, 0, "pwr_powerlink")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  }

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  }

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, &qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  // Make connection to realtime database
  sts = gdh_Init("rt_powerlink");
  if (EVEN(sts)) {
    errh_Fatal("rt_powerlink aborted, gdh_Init failed\n%m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  sts = gdh_GetClassList(pwr_cClass_Epl_CNServer, &oid);
  if (ODD(sts)) {
    system("rt_powerlink_cn &");
    exit(0);
  }

  // Get Powerlink handler object
  sts = io_get_plhandler_object(&plhp, &oid);
  if (EVEN(sts)) {
    errh_SetStatus(0);
    errh_Info("rt_powerlink terminated, no EplHandler object found");
    exit(sts);
  }

  // Create context and call init functions of all agent,
  // rack and cardobjects
  sts = io_init(io_mProcess_Powerlink, pwr_cNObjid, &io_ctx, 1, ctime);
  if (EVEN(sts)) {
    errh_SetStatus(PWR__SRVTERM);
    errh_Fatal("rt_powerlink aborted, io_init() failed\n%m", sts);
    exit(sts);
  }

  tmo = (plhp->CycleTime) * 1000;

  aproc_TimeStamp(plhp->CycleTime, 5.0);
  errh_SetStatus(PWR__SRUN);
  aproc_RegisterObject(oid);

  // Call IoAgentRead() IoAgentWrite() IoCardRead() IoCardWrite()
  // IoModuleRead() IoModuleWrite() forever
  for (;;) {
    get.maxSize = sizeof(mp);
    get.data = mp;
    qcom_Get(&sts, &qid, &get, tmo);
    if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
      sts = io_read(io_ctx);
      sts = io_write(io_ctx);

      aproc_TimeStamp(plhp->CycleTime, 5.0);

    } else {
      ini_mEvent new_event;
      qcom_sEvent* ep = (qcom_sEvent*)get.data;

      new_event.m = ep->mask;
      if (new_event.b.oldPlcStop) {
        // TODO
      } else if (new_event.b.swapDone) {
        // TODO
      } else if (new_event.b.terminate) {
        // io_close(io_ctx);
        exit(0);
      }
    }
  }
}