Example #1
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 #2
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 #3
0
void
Init ()
{
  pwr_tUInt32 sts;
  pwr_tInt32 ret;
  char msg[80];
  pwr_tObjid	MHObjId;
  pwr_sAttrRef	AttrRef; 
  pwr_tDlid	DLId;
  pwr_sClass_MessageHandler *MH;
  char fname[200];
    
  dcli_translate_filename( fname, DATABASE);
  dcli_translate_filename( info_fname, DATABASE_INFO);
  
  sts = gdh_GetNodeIndex(&lHelCB.Nid);
  If_Error_Log_Exit(sts, "gdh_GetNodeIndex");

  sts = gdh_GetClassList(pwr_cClass_MessageHandler, &MHObjId);
  If_Error_Log_Exit(sts, "Couldn't find message handler object");

  AttrRef.Objid = MHObjId;
  AttrRef.Body = 0;
  AttrRef.Offset = 0;
  AttrRef.Size = sizeof(pwr_sClass_MessageHandler);
  AttrRef.Flags.m = 0;

  sts = gdh_DLRefObjectInfoAttrref(&AttrRef, (pwr_tAddress *)&MH, &DLId);
  If_Error_Log_Exit(sts,"Couldn't get direct link to message handler object");
  
  if (MH->EventLogSize == 0) {
    Log("EventLogSize = 0, no event logger will run on this node.");
    errh_SetStatus( pwr_cNStatus);
    exit(1);
  }

  lHelCB.MaxCardinality = MH->EventLogSize;
  lHelCB.MaxStoreLSize = 1000; /*not used*/
  lHelCB.ScanTime = 2000; /* 5 seconds */

  /*create the database if it's not already created*/
  if((ret = db_create(&dataBaseP, NULL, 0)) != 0)
  {
    /*error creating db-handle send the mess to errh, then exit*/
    sprintf(msg, "db_create: %s, no eventlogger will run", db_strerror(ret));
    errh_Error(msg);
    exit(1);
  }
  /*open the database*/

#if (DB_VERSION_MAJOR > 3) && (DB_VERSION_MINOR > 0)
  ret = dataBaseP->open(dataBaseP, NULL, fname, NULL, DATABASETYPE, DB_CREATE, 0664);
#else
  ret = dataBaseP->open(dataBaseP, fname, NULL, DATABASETYPE, DB_CREATE, 0664);
#endif
  if(ret != 0)
  {
    /*error opening/creating db send the mess to errh, then exit*/
    sprintf(msg, "db_open: %s, no eventlogger will run", db_strerror(ret));
    Log(msg);
    exit(1);
  }
  
  newhead(&listhead);
}