示例#1
0
pwr_tStatus bck_print( char *filename)
{
  char fname[256];
  pwr_sAttrRef aref;
  pwr_tAName objname;
  FILE *fp = 0;
  pwr_sAttrRef dataname;
  int sts;

  if ( filename) {
    dcli_translate_filename( fname, filename);
    fp = fopen( fname, "w");
    if ( !fp) return 0;
  }

  sts = gdh_Init("pwr_bck_print");
  if (EVEN(sts)) return sts;

  sts = gdh_GetClassListAttrRef( pwr_cClass_Backup, &aref);
  while ( ODD(sts)) {
    if ( aref.Objid.vid < cdh_cUserVolMin) {
      // In template plc, continue
      sts = gdh_GetNextAttrRef( pwr_cClass_Backup, &aref, &aref);
      continue;
    }


    sts = gdh_AttrrefToName( &aref, objname, sizeof(objname), cdh_mName_volumeStrict); 
    if ( EVEN(sts)) return sts;

    if ( fp)
      fprintf( fp, "// %s\n", objname);
    else
      printf( "// %s\n", objname);

    strcat( objname, ".DataName");
    sts = gdh_GetObjectInfo( objname, &dataname, sizeof(dataname));

    sts = print_data( &dataname, fp);
    if ( EVEN(sts)) error_msg( sts, fp);
    
    sts = gdh_GetNextAttrRef( pwr_cClass_Backup, &aref, &aref);
  }

  if ( fp)
    fclose(fp);	     

  return 1;
}
示例#2
0
void rt_sysmon::open()
{
  pwr_tStatus sts;
  pwr_sAttrRef aref;
  pwr_tObjid oid;

  // Open server configuration object SysMonConfig
  sts = gdh_GetClassList( pwr_cClass_SysMonConfig, &oid);
  if ( ODD(sts)) {
    aref = cdh_ObjidToAref( oid);
    sts = gdh_DLRefObjectInfoAttrref( &aref, (void **)&conf, &conf_dlid); 
    if ( EVEN(sts)) throw co_error(sts);
  }

  if ( ODD(sts)) {
    scan_time = 1.0 / conf->ScanTime;
  }
  else {
    scan_time = 1;
    errh_Info( "No sysmon configuration, using base frequency 1 Hz");
    oid = pwr_cNObjid;
    conf = 0;
  }

  aproc_RegisterObject( oid);

  // Open DiskSup objects
  for ( sts = gdh_GetClassListAttrRef( pwr_cClass_DiskSup, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef( pwr_cClass_DiskSup, &aref, &aref)) {
    disksup_object *o = new disksup_object( &aref);
    objects.push_back( o);
    try {
      o->open( scan_time);
      if ( conf)
	conf->DiskSupObjects[sysmon_cnt] = aref.Objid;
      sysmon_cnt++;
    }    
    catch ( co_error& e) {
      delete o;
      objects.pop_back();
      errh_Error( "DiskSup configuration error: &s", (char *)e.what().c_str());
    }
  }
}
示例#3
0
void rt_fast::open()
{
  pwr_tStatus sts;
  pwr_sAttrRef aref;
  pwr_tObjid oid;
  pwr_sClass_DsFastConf *conf_p;

  // Open server configuration object DsFastConf
  sts = gdh_GetClassList( pwr_cClass_DsFastConf, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf_p);
    if ( EVEN(sts)) throw co_error( sts);

    scan_time = 1.0 / conf_p->BaseFrequency;
  }
  else {
    scan_time = 0.1;
    errh_Info( "No fast configuration, using base frequency 10 Hz");
    oid = pwr_cNObjid;
  }

  aproc_RegisterObject( oid);

  // Open FastCurve object
  for ( sts = gdh_GetClassListAttrRef( pwr_cClass_DsFastCurve, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef( pwr_cClass_DsFastCurve, &aref, &aref)) {
    fastobject *o = new fastobject( &aref);
    objects.push_back( o);
    try {
      o->open( scan_time);
      fast_cnt++;
    }    
    catch ( co_error& e) {
      delete o;
      objects.pop_back();
      errh_Error( "DsFastCurve configuration error: &s", (char *)e.what().c_str());
    }
  }
}
示例#4
0
static void
load_backup ()
{
  pwr_tObjid			oid;
  pwr_sClass_AvArea		*avp;
  pwr_sClass_DvArea		*dvp;
  pwr_sClass_IvArea		*ivp;
  pwr_sClass_InitArea		*iavp;
  pwr_sClass_InitArea		*idvp;
  pwr_sClass_InitArea		*iivp;
  pwr_tStatus			sts;
  int				i;
  pwr_sClass_IOHandler		*iop;
  pwr_sAttrRef			aref;
 
  sts = io_get_iohandler_object(&iop, NULL);  
  if (EVEN(sts)) {
    errh_Error("io_get_iohandler_object, %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-av", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-av, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &avp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &avp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-av_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-av_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &iavp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &iavp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-dv", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-dv, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &dvp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &dvp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-dv_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-dv_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &idvp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &idvp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-iv", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-iv, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &ivp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &ivp), %m", sts);
    return;
  }

  sts = gdh_NameToObjid("pwrNode-active-io-iv_init", &oid);
  if (EVEN(sts)) {
    errh_Error("gdh_NameToObjid(pwrNode-active-io-iv_init, &oid), %m", sts);
    return;
  }

  sts = gdh_ObjidToPointer(oid, (void *) &iivp);
  if (EVEN(sts)) {
    errh_Error("gdh_ObjidToPointer(oid, (void *) &iivp), %m", sts);
    return;
  }

  for (i = 0; i < iop->AvCount; i++) {
    pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]);
    avp->Value[i]= *ifp;
  }

  for (i = 0; i < iop->DvCount; i++) {
    pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]);
    dvp->Value[i] = *ibp;
  }

  for (i = 0; i < iop->IvCount; i++) {
    pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]);
    ivp->Value[i] = *iip;
  }

  typedef struct {
    union {
      pwr_tFloat32 *f;
      pwr_tInt32   *i;
      pwr_tBoolean *b;
    } actval_p;
    pwr_tUInt32  validx;
    union {
      pwr_sClass_Av *av;
      pwr_sClass_Iv *iv;
      pwr_sClass_Dv *dv;
      pwr_sClass_Ai *ai;
      pwr_sClass_Ao *ao;
      pwr_sClass_Ii *ii;
      pwr_sClass_Io *io;
      pwr_sClass_Di *di;
      pwr_sClass_Do *dox;
      pwr_sClass_Co *co;
    } op;
  } ini_sRestoreSig;

  // Store ActualValue pointers
  ini_sRestoreSig *rsav = calloc( sizeof(ini_sRestoreSig), iop->AvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Av, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Av, &aref, &aref)) {
    if ( i >= iop->AvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsav[i].op.av);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsav[i].actval_p.f = rsav[i].op.av->ActualValue;
    rsav[i].validx = rsav[i].op.av->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdv = calloc( sizeof(ini_sRestoreSig), iop->DvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Dv, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Dv, &aref, &aref)) {
    if ( i >= iop->DvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdv[i].op.dv);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdv[i].actval_p.b = rsdv[i].op.dv->ActualValue;
    rsdv[i].validx = rsdv[i].op.dv->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsiv = calloc( sizeof(ini_sRestoreSig), iop->IvCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Iv, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Iv, &aref, &aref)) {
    if ( i >= iop->IvCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsiv[i].op.iv);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsiv[i].actval_p.i = rsiv[i].op.iv->ActualValue;
    rsiv[i].validx = rsiv[i].op.iv->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsai = calloc( sizeof(ini_sRestoreSig), iop->AiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ai, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ai, &aref, &aref)) {
    if ( i >= iop->AiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsai[i].op.ai);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsai[i].actval_p.f = rsai[i].op.ai->ActualValue;
    rsai[i].validx = rsai[i].op.ai->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsao = calloc( sizeof(ini_sRestoreSig), iop->AoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ao, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ao, &aref, &aref)) {
    if ( i >= iop->AoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsao[i].op.ao);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsao[i].actval_p.f = rsao[i].op.ao->ActualValue;
    rsao[i].validx = rsao[i].op.ao->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsii = calloc( sizeof(ini_sRestoreSig), iop->IiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ii, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Ii, &aref, &aref)) {
    if ( i >= iop->IiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsii[i].op.ii);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsii[i].actval_p.i = rsii[i].op.ii->ActualValue;
    rsii[i].validx = rsii[i].op.ii->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsio = calloc( sizeof(ini_sRestoreSig), iop->IoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Io, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Io, &aref, &aref)) {
    if ( i >= iop->IoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsio[i].op.io);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsio[i].actval_p.i = rsio[i].op.io->ActualValue;
    rsio[i].validx = rsio[i].op.io->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdi = calloc( sizeof(ini_sRestoreSig), iop->DiCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Di, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Di, &aref, &aref)) {
    if ( i >= iop->DiCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdi[i].op.di);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdi[i].actval_p.b = rsdi[i].op.di->ActualValue;
    rsdi[i].validx = rsdi[i].op.di->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsdo = calloc( sizeof(ini_sRestoreSig), iop->DoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Do, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Do, &aref, &aref)) {
    if ( i >= iop->DoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdo[i].op.dox);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsdo[i].actval_p.b = rsdo[i].op.dox->ActualValue;
    rsdo[i].validx = rsdo[i].op.dox->ValueIndex;
    i++;
  }
  
  ini_sRestoreSig *rsco = calloc( sizeof(ini_sRestoreSig), iop->CoCount);
  pwr_tInt32 **rscoa = calloc( sizeof(pwr_tInt32*), iop->CoCount);
  i = 0;
  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Co, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef(pwr_cClass_Co, &aref, &aref)) {
    if ( i >= iop->CoCount) break;

    sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsco[i].op.co);
    if ( EVEN(sts)) {
      errh_Error("gdh_AttrRefToPointer Iv, %m", sts);
      return;
    }

    rsco[i].actval_p.i = rsco[i].op.co->RawValue;
    rsco[i].validx = rsco[i].op.co->ValueIndex;
    rscoa[i] = rsco[i].op.co->AbsValue;
    i++;
  }
  

  sts = bck_LoadBackup();
  if (EVEN(sts)) {
    errh_Error("bck_LoadBackup, %m", sts);
    return;
  }

  // Set stored ActualValue pointers
  for ( i = 0; i < iop->AvCount; i++) {
    rsav[i].op.av->ActualValue = rsav[i].actval_p.f;
    rsav[i].op.av->ValueIndex = rsav[i].validx;
  }
  free( rsav);

  for ( i = 0; i < iop->DvCount; i++) {
    rsdv[i].op.dv->ActualValue = rsdv[i].actval_p.b;
    rsdv[i].op.dv->ValueIndex = rsdv[i].validx;
  }
  free( rsdv);

  for ( i = 0; i < iop->IvCount; i++) {
    rsiv[i].op.iv->ActualValue = rsiv[i].actval_p.i;
    rsiv[i].op.iv->ValueIndex = rsiv[i].validx;
  }
  free( rsiv);

  for ( i = 0; i < iop->AiCount; i++) {
    rsai[i].op.ai->ActualValue = rsai[i].actval_p.f;
    rsai[i].op.ai->ValueIndex = rsai[i].validx;
  }
  free( rsai);

  for ( i = 0; i < iop->AoCount; i++) {
    rsao[i].op.ao->ActualValue = rsao[i].actval_p.f;
    rsao[i].op.ao->ValueIndex = rsao[i].validx;
  }
  free( rsao);

  for ( i = 0; i < iop->IiCount; i++) {
    rsii[i].op.ii->ActualValue = rsii[i].actval_p.i;
    rsii[i].op.ii->ValueIndex = rsii[i].validx;
  }
  free( rsii);

  for ( i = 0; i < iop->IoCount; i++) {
    rsio[i].op.io->ActualValue = rsio[i].actval_p.i;
    rsio[i].op.io->ValueIndex = rsio[i].validx;
  }
  free( rsio);

  for ( i = 0; i < iop->DiCount; i++) {
    rsdi[i].op.di->ActualValue = rsdi[i].actval_p.b;
    rsdi[i].op.di->ValueIndex = rsdi[i].validx;
  }
  free( rsdi);

  for ( i = 0; i < iop->DoCount; i++) {
    rsdo[i].op.dox->ActualValue = rsdo[i].actval_p.b;
    rsdo[i].op.dox->ValueIndex = rsdo[i].validx;
  }
  free( rsdo);

  for ( i = 0; i < iop->CoCount; i++) {
    rsco[i].op.co->RawValue = rsco[i].actval_p.i;
    rsco[i].op.co->AbsValue = rscoa[i];
    rsco[i].op.co->ValueIndex = rsco[i].validx;
  }
  free( rsco);
  free( rscoa);


  for (i = 0; i < iop->AvCount; i++) {
    pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]);
    *ifp = avp->Value[i];
  }

  for (i = 0; i < iop->DvCount; i++) {
    pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]);
    *ibp = dvp->Value[i];
  }

  for (i = 0; i < iop->IvCount; i++) {
    pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]);
    *iip = ivp->Value[i];
  }
}
示例#5
0
static pwr_tStatus InitTrendList( trend_tCtx ctx)
{
  pwr_tStatus	    sts;
  pwr_tUInt32	    dummy;
  pwr_tTypeId	    type;
  int		    tix;
  pwr_tAttrRef	    aref;
  pwr_tAttrRef	    oaref;
  pwr_tAName   	    name;
  pwr_tDisableAttr  disabled;

  /* Init DsTrend objects */
  /* Scan through typelist and insert valid objects in list and initiate */
  /* the DsTrend objects. */

  for ( sts = gdh_GetClassListAttrRef(pwr_cClass_DsTrend, &aref); 
	ODD(sts); 
	sts = gdh_GetNextAttrRef( pwr_cClass_DsTrend, &aref, &aref) ) {
    trend_sListEntry    *ep;
    pwr_sClass_DsTrend  *o;

    sts = gdh_AttrrefToName( &aref, name, sizeof(name), cdh_mNName);  
    if (EVEN(sts))
      continue;

    /* Check if parent object is disabled */
    sts = gdh_AttrArefToObjectAref( &aref, &oaref);
    if ( ODD(sts)) {
      sts = gdh_ArefDisabled( &oaref, &disabled);
      if ( ODD(sts) && disabled)
	continue;
    }

    ep = calloc(1, sizeof(*ep));
    if (ep == NULL) {
      errh_CErrLog(DS__ERRALLOC, NULL);
      errh_SetStatus( PWR__SRVTERM);
      exit(DS__ERRALLOC);
    }

    sts = gdh_RefObjectInfo(name, (pwr_tAddress *)&ep->o, 
		      &ep->o_subid, sizeof(*ep->o));
    if (EVEN(sts)) {
      errh_Error("Couldn't get subscription for '%s'\n%m", name, sts);
      free(ep);
      continue;
    }
    o = ep->o;       

   /* Set init values */
    o->BufferStatus[0] = 1;
    o->BufferStatus[1] = 1;
    o->NoOfBuffers = 2;
    o->NoOfBufElement = 239;

    /* Initiate DsTrend object, sampled attribute must be on local node */	  

    sts = gdh_DLRefObjectInfoAttrref((pwr_sAttrRef *)&o->DataName, 
		  (pwr_tAddress *)&o->DataPointer, &o->DataSubId);
    if (EVEN(sts)) {
      if ( sts == GDH__RTDBNULL && IsDisabled( &o->DataName))
	  continue;

      errh_Error("Couldn't get direct link to %s's attribute DataName\n%m", name, sts);
      gdh_UnrefObjectInfo(ep->o_subid);
      free(ep);
      continue;
    }

    sts = gdh_GetAttributeCharAttrref((pwr_sAttrRef *)&o->DataName,
					&type, &dummy, &dummy, &dummy);
    if (EVEN(sts)) {
      errh_Error("Couldn't get datatype for %s's attribute DataName\n%m", name, sts);
      gdh_UnrefObjectInfo(ep->o_subid);
      free(ep);
      continue;
    }
    tix = cdh_TypeIdToIndex(type);

    if (!IsValidType(tix)) {
      errh_Error("No valid datatype for %s's attribute DataName\n%m", name, DS__ERRTYPE);
      gdh_UnrefObjectInfo(ep->o_subid);
      free(ep);
      continue;
    }
      
    o->DataType = tix;
    if ( o->Multiple == 0)
      o->Multiple = 1;
    o->NoOfSample = (o->StorageTime * ctx->scantime) / o->Multiple;

    if(o->NoOfSample > o->NoOfBufElement)
      o->NoOfSample = o->NoOfBufElement;

    o->ScanTime = ctx->scantime;

    ep->next = ctx->o_list;
    ctx->o_list = ep;
  }

  /* Init DsTrendCurve objects */

  /* Scan through typelist and insert valid objects in list and initiate
     the DsTrend objects.  */

  for (sts = gdh_GetClassListAttrRef(pwr_cClass_DsTrendCurve, &aref); 
       ODD(sts); 
       sts = gdh_GetNextAttrRef( pwr_cClass_DsTrendCurve, &aref, &aref) ) {
    trend_sListEntryTC  *ep;
    pwr_sClass_DsTrendCurve  *o;
    int i;
    int found;

    sts = gdh_AttrrefToName( &aref, name, sizeof(name), cdh_mNName);  
    if (EVEN(sts))
      continue;

    /* Check if parent object is disabled */
    sts = gdh_AttrArefToObjectAref( &aref, &oaref);
    if ( ODD(sts)) {
      sts = gdh_ArefDisabled( &oaref, &disabled);
      if ( ODD(sts) && disabled)
	continue;
    }

    ep = calloc(1, sizeof(*ep));
    if (ep == NULL) {
      errh_CErrLog(DS__ERRALLOC, NULL);
      errh_SetStatus( PWR__SRVTERM);
      exit(DS__ERRALLOC);
    }

    ep->first_scan = 1;

    sts = gdh_RefObjectInfo(name, (pwr_tAddress *)&ep->o, 
		      &ep->o_subid, sizeof(*ep->o));
    if (EVEN(sts)) {
      errh_Error("Couldn't get subscription for '%s'\n%m", name, sts);
      free(ep);
      continue;
    }
    o = ep->o;       

    if ( o->Function & 1) {
      /* Data stored by user */
      gdh_UnrefObjectInfo(ep->o_subid);
      free(ep);
      continue;
    }

    ep->multiple = (int) (o->ScanTime / ctx->scantime_tc + 0.5);
    o->NoOfSample = (int) (o->StorageTime / ctx->scantime_tc * ep->multiple + 0.5);

    /* Initiate DsTrendCuve object, sampled attribute must be on local node */	  

    found = 0;
    for ( i = 0; i < 10; i++) {
      if ( cdh_ObjidIsNull( o->Attribute[i].Objid))
	continue;

      /* Link to attribute */
      sts = gdh_DLRefObjectInfoAttrref((pwr_sAttrRef *)&o->Attribute[i], 
				       (pwr_tAddress *)&ep->datap[i], &ep->data_subid[i]);
      if (EVEN(sts)) {
	if ( sts == GDH__RTDBNULL && IsDisabled( &o->Attribute[i]))
	  continue;
	
	errh_Error("Couldn't get direct link to %s's attribute %d, %m", name, i+1, sts);
	ep->datap[i] = 0;
	continue;
      }
     
      sts = gdh_GetAttributeCharAttrref((pwr_sAttrRef *)&o->Attribute[i],
					&type, &dummy, &dummy, &dummy);
      if (EVEN(sts)) {
	errh_Error("Couldn't get datatype for %s's attribute DataName\n%m", name, sts);
	gdh_UnrefObjectInfo(ep->data_subid[i]);
	ep->datap[i] = 0;
	continue;
      }
      tix = cdh_TypeIdToIndex(type);
      ep->data_size[i] = cdh_TypeToSize( type);

      if (!IsValidType(tix)) {
	errh_Error("No valid datatype for %s's attribute DataName\n%m", name, DS__ERRTYPE);
	gdh_UnrefObjectInfo(ep->data_subid[i]);
	ep->datap[i] = 0;
	continue;
      }
      
      o->AttributeType[i] = type;

      /* Link to buffer */
      sts = gdh_DLRefObjectInfoAttrref((pwr_sAttrRef *)&o->Buffers[i], 
				       (pwr_tAddress *)&ep->buffheadp[i], &ep->buff_subid[i]);
      if (EVEN(sts)) {
	errh_Error("Couldn't get direct link to %s's buffer %d, %m", name, i+1, sts);
	gdh_UnrefObjectInfo(ep->data_subid[i]);
	ep->datap[i] = 0;
	continue;
      }
      ep->buffp[i] = (char *)ep->buffheadp[i] + pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader));

      /* Get buffer size */
      sts = gdh_GetAttributeCharAttrref( &o->Buffers[i], 0, &ep->buff_size[i], 0, 0);
      if ( EVEN(sts)) return sts;

      ep->buff_size[i] -= pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader));

      found = 1;
    }
    if ( !found) {
      errh_Error("No valid attributes for %s", name);
      gdh_UnrefObjectInfo(ep->o_subid);
      free(ep);
      continue;
    }

    /* Link to time buffer */
    if ( cdh_ObjidIsNotNull( o->TimeBuffer.Objid)) {
      sts = gdh_DLRefObjectInfoAttrref((pwr_sAttrRef *)&o->TimeBuffer, 
				       (pwr_tAddress *)&ep->timeheadp, &ep->timebuff_subid);
      if (EVEN(sts)) {
	errh_Error("Couldn't get direct link to %s's time buffer, %m", name, sts);
	ep->timeheadp = 0;
	ep->timebuffp = 0;
      }
      else
 	ep->timebuffp = (char *)ep->timeheadp + pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader));
	
      if ( o->TimeResolution == pwr_eTimeResolutionEnum_Nanosecond)
	ep->time_size = 8;
      else
	ep->time_size = 4;

      /* Get buffer size */
      sts = gdh_GetAttributeCharAttrref( &o->TimeBuffer, 0, &ep->timebuff_size, 0, 0);
      if ( EVEN(sts)) return sts;

      ep->timebuff_size -= pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader));
    }

    /* Calculate number of samples */
    for ( i = 0; i < 10; i++) {
      if ( !ep->datap[i])
	continue;

      if ( o->NoOfSample > ep->buff_size[i] / ep->data_size[i])
	o->NoOfSample = ep->buff_size[i] / ep->data_size[i];
    }
    if ( ep->timebuffp) {
      if ( o->NoOfSample > ep->timebuff_size / ep->time_size)
	o->NoOfSample = ep->timebuff_size / ep->time_size;
    }
    for ( i = 0; i < 10; i++) {
      if ( !ep->datap[i])
	continue;

      ep->buffheadp[i]->Size = o->NoOfSample;
      ep->buffheadp[i]->ElementSize = ep->data_size[i];
    }
    if ( ep->timebuffp) {
      ep->timeheadp->Size = o->NoOfSample;
      ep->timeheadp->ElementSize = ep->time_size;
    }
     
    ep->next = ctx->o_list_tc;
    ctx->o_list_tc = ep;
  }

  if ( ctx->o_list == NULL && ctx->o_list_tc == NULL)
    return DS__NOOBJECT;
  else
    return DS__SUCCESS;
}