Ejemplo n.º 1
0
static void
init (
)
{
  pwr_sClass_ASup *asp;
  pwr_sClass_DSup *dsp; 
  pwr_tStatus sts;
  sAttribute *ap;
  sObject *op;
  sSupObject *sp;
  pwr_tObjid oid;

  ltp = tree_CreateTable(&sts, sizeof(pwr_tObjid), offsetof(sObject, oid),
    sizeof(sObject), 200, tree_Comp_oid);

  sts = gdh_GetClassList(pwr_cClass_ASup, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void **)&asp);
    op = tree_Find(&sts, ltp, &asp->Attribute.Objid);
    if (op == NULL) {
      op = tree_Insert(&sts, ltp, &asp->Attribute.Objid);
      LstIni(&op->attr_l);
    }

    ap = findAttribute(op, &asp->Attribute, pwr_cClass_ASup);
    
    sp = calloc(1, sizeof(*sp));
    (void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); 
    sp->oid = oid;
    sp->p = asp;
    op->sup_c++;
    ap->sup_c++;

    sts = gdh_GetNextObject(oid, &oid);
  }

  sts = gdh_GetClassList(pwr_cClass_DSup, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void **)&dsp);
    op = tree_Find(&sts, ltp, &dsp->Attribute.Objid);
    if (op == NULL) {
      op = tree_Insert(&sts, ltp, &dsp->Attribute.Objid);
      LstIni(&op->attr_l);
    }

    ap = findAttribute(op, &dsp->Attribute, pwr_cClass_DSup);
    
    sp = calloc(1, sizeof(*sp));
    (void)LstIns(LstEnd(&ap->sup_l), sp, sup_l); 
    sp->oid = oid;
    sp->p = dsp;
    op->sup_c++;
    ap->sup_c++;

    sts = gdh_GetNextObject(oid, &oid);
  }

}
Ejemplo n.º 2
0
static pwr_tStatus	logg_init( logg_ctx	loggctx)
{
	pwr_tStatus	sts;
	pwr_tObjid	objid;
	logg_t_loggconf_list	*conflist_ptr;
	int		i;

	/* Get the logg config objects on this node */
	sts = gdh_GetClassList ( pwr_cClass_LoggConfig, &objid);
	while ( ODD(sts))
	{
          /* Store and direct link the LoggConfig objects */
          sts = logg_loggconflist_add( loggctx, objid,
		&loggctx->loggconflist,
		&loggctx->loggconf_count);
	  if (EVEN(sts)) Log( REM__CONFINIT, sts);

	  sts = gdh_GetNextObject( objid, &objid);
	}

	/* Open the files */
	conflist_ptr = loggctx->loggconflist;
	for ( i = 0; i < loggctx->loggconf_count; i++)
	{
	  sts = logg_open_file( conflist_ptr, 1);
	  conflist_ptr++;
	}

	return REM__SUCCESS;
}
Ejemplo n.º 3
0
static pwr_tStatus
init_nodes ()
{
  pwr_tStatus sts;
  LstLink(sNode) *nl;
  sNode *np;
  pwr_tObjid oid;

  nl = LstEnd(&node_l);

  for (
    sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid);
    ODD(sts);
    sts = gdh_GetNextObject(oid, &oid)
  ) {
    np = init_node(oid, NULL, 1);
    if (np != NULL) {
      nl = LstIns(nl, np, node_l);
    }
  }

  if (LstEmp(&node_l))
    errh_Info("No NodeLink objects");

  return(sts);
}
Ejemplo n.º 4
0
int xnav_open_URL( pwr_tURL url)
{
  char cmd[200];
  int sts;
  pwr_sClass_WebBrowserConfig *config_p = 0;
  char browser[40] = "firefox";
  pwr_tObjid config_objid;

  sts = gdh_GetClassList( pwr_cClass_WebBrowserConfig, &config_objid);
  if ( ODD(sts))
    sts = gdh_ObjidToPointer( config_objid, (void **)&config_p);

  if ( ODD(sts)) {
    if ( strcmp( config_p->WebBrowser, "") != 0)
      strcpy( browser, config_p->WebBrowser);
  }

  if ( strncmp( url, "$pwr_lang/", 10) == 0) {
    // If file in $pwr_lang, check if file exist, else take en_us

    if ( Lng::current() != lng_eLanguage_en_US) {
      pwr_tURL testurl;
      pwr_tTime t;
      
      replace_symbol( url, testurl, config_p);
      dcli_translate_filename( testurl, testurl);
      sts = dcli_file_time( testurl, &t);
      if ( EVEN(sts)) {
	// Try en_us
	strcpy( testurl, "$pwr_doc/en_us/");
	strcat( testurl, &url[10]);
	strcpy( url, testurl);
      }
    }
  }
  
  replace_symbol( url, url, config_p);

  if ( strcmp( browser, "mozilla") == 0 ||
       strcmp( browser, "rt_mozilla") == 0) {
    // Try remote display first
    sprintf( cmd, "%s -remote \"openurl(%s,new-window)\"", browser, url);
    sts = system(cmd);
    if ( sts) {
      // Not started yet 
      sprintf( cmd, "%s %s &", browser, url);
      system( cmd);
    }
  }
  else {
    sprintf( cmd, "%s %s &", browser, url);
    system( cmd);
  }
  return XNAV__SUCCESS;
}
Ejemplo n.º 5
0
/*_*
  @aref cyclesup CycleSup
  */
lst_sEntry *
csup_Init (
    pwr_tStatus	*status,
    pwr_tObjid	tid,
    float		scanTime
)
{
    lst_sEntry	*lh;
    pwr_tObjid	cid;
    pwr_tObjid	pid;
    csup_sObject	*cp;
    int		tv_sec;
    pwr_tFloat32	max_delay;

    pwr_dStatus(sts, status, CSUP__SUCCESS);

    lh = calloc(1, sizeof(*lh));
    if (lh == NULL)
        pwr_Return(NULL, sts, CSUP__INSVIRMEM);

    lst_Init(NULL, lh, NULL);

    for (
        *sts = gdh_GetClassList(pwr_cClass_CycleSup, &cid);
        ODD(*sts);
        *sts = gdh_GetNextObject(cid, &cid)
    ) {
        cp = calloc(1, sizeof(*cp));
        cp->aref.Objid = cid;
        *sts = gdh_DLRefObjectInfoAttrref(&cp->aref, (void**)&cp->o, &cp->dlid);
        if (EVEN(*sts))
            goto error;

        if ( ODD(gdh_GetParent( cid, &pid)) && cdh_ObjidIsEqual( pid, tid))
            cp->is_owner = 1;

        lst_InsertSucc(NULL, lh, &cp->le, cp);
        max_delay = cp->o->MaxDelay;
        cp->o->DelayLimit.tv_sec = tv_sec = (int)max_delay;
        cp->o->DelayLimit.tv_nsec = (int)((max_delay - (float)tv_sec + FLT_EPSILON) * 1.0e9);
        // printf("maxdelay: %f, tv_sec: %d, tv_nsec: %d\n", cp->o->MaxDelay, cp->o->DelayLimit.tv_sec, cp->o->DelayLimit.tv_nsec);
        errh_Info("maxdelay: %f, tv_sec: %d, tv_nsec: %d", cp->o->MaxDelay,
                  cp->o->DelayLimit.tv_sec, cp->o->DelayLimit.tv_nsec);
    }

    if (lst_IsEmpty(NULL, lh))
        goto error;

    return lh;

error:
    csup_Exit(NULL, lh);
    return NULL;
}
Ejemplo n.º 6
0
//
// Set Scan filter
//
static pwr_tStatus SetScanFilter( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_sClass_windowplc *window_p;
    pwr_tClassId classid;
    int enable;

    if ( !ip->Priv & pwr_mPrv_System)
        return XNAV__INSENSITIVE;

    if ( strcmp( "Enable", ip->ItemList[ip->ChosenItem].FilterArguments[0]) == 0)
        enable = 1;
    else if ( strcmp( "Disable", ip->ItemList[ip->ChosenItem].FilterArguments[0]) == 0)
        enable = 0;
    else
        return XNAV__SUCCESS;

    // Only on local objects
    sts = gdh_GetObjectLocation( ip->Pointed.Objid, &local);
    if ( EVEN(sts) || !local)
        return XNAV__INSENSITIVE;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return sts;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return XNAV__INSENSITIVE;

    sts = gdh_GetChild( ip->Pointed.Objid, &child);
    while( ODD(sts)) {
        sts = gdh_GetObjectClass( child, &classid);
        if ( EVEN(sts)) return sts;

        if ( classid == pwr_cClass_windowplc) {
            sts = gdh_ObjidToPointer( child, (void **) &window_p);
            if ( EVEN(sts)) return sts;

            if ( (enable && window_p->ScanOff) ||
                    (!enable && !window_p->ScanOff))
                return XNAV__SUCCESS;
            else
                return XNAV__INSENSITIVE;
        }
    }
    return XNAV__INVISIBLE;
}
Ejemplo n.º 7
0
JNIEXPORT jobject JNICALL Java_jpwr_rt_RtSecurity_checkUser
  (JNIEnv *env , jclass object, jstring jsystemgroup, jstring juser, 
	jstring jpassword)
{
  int sts;
  const char *systemgroup;
  char *csystemgroup;
  const char *user;
  char *cuser;
  const char *password;
  char *cpassword;
  jclass cdhrInt_id;
  jmethodID cdhrInt_cid;
  jobject return_obj;
  unsigned int priv;
  jint jsts;
  jint jpriv;
  pwr_tObjid	oid;
  pwr_sSecurity	sec;	
  pwr_tAttrRef aref;

  cdhrInt_id = (*env)->FindClass( env, "jpwr/rt/CdhrInt");
  cdhrInt_cid = (*env)->GetMethodID( env, cdhrInt_id,
    	"<init>", "(II)V");

  systemgroup = (*env)->GetStringUTFChars( env, jsystemgroup, 0);
  csystemgroup = (char *)systemgroup;
  user = (*env)->GetStringUTFChars( env, juser, 0);
  cuser = (char *)user;
  password = (*env)->GetStringUTFChars( env, jpassword, 0);
  cpassword = (char *)password;

  sts = gdh_GetClassList ( pwr_eClass_Security, &oid);
  if (ODD(sts)) {
    aref = cdh_ObjidToAref( oid);
    sts = gdh_GetObjectInfoAttrref( &aref, &sec, sizeof(sec));
    if ( ODD(sts)){
      sts = user_CheckUser( sec.WebSystemGroup, cuser, cpassword, &priv);
    }
  }
  (*env)->ReleaseStringUTFChars( env, jsystemgroup, csystemgroup);
  (*env)->ReleaseStringUTFChars( env, juser, cuser);
  (*env)->ReleaseStringUTFChars( env, jpassword, cpassword);

  jsts = (jint) sts;
  if ( sts % 2 == 0)
    priv = pwr_mPrv_RtRead;
  jpriv = priv;
  return_obj = (*env)->NewObject( env, cdhrInt_id,
  	cdhrInt_cid, jpriv, jsts);
  return return_obj; 
}
Ejemplo n.º 8
0
//
// Set scan
//
static pwr_tStatus SetScan( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_tBoolean value = 0;
    pwr_tOName name;
    pwr_tClassId classid;

    if ( strcmp( "Enable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 0;
    else if ( strcmp( "Disable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 1;
    else
        return XNAV__SUCCESS;

    // Only on local objects
    sts = gdh_GetObjectLocation( ip->Pointed.Objid, &local);
    if ( EVEN(sts) || !local)
        return 0;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return sts;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return 0;

    sts = gdh_GetChild( ip->Pointed.Objid, &child);
    while( ODD(sts)) {
        sts = gdh_GetObjectClass( child, &classid);
        if ( EVEN(sts)) return sts;

        if ( classid == pwr_cClass_windowplc) {
            sts = gdh_ObjidToName( child, name, sizeof(name),
                                   cdh_mName_volumeStrict);
            if ( EVEN(sts)) return sts;
            strcat( name, ".ScanOff");
            sts = gdh_SetObjectInfo( name, (void *) &value, sizeof( value));
            if ( EVEN(sts)) return sts;

            return XNAV__SUCCESS;
        }
    }
    return 0;
}
Ejemplo n.º 9
0
/*----------------------------------------------------------------------------*\
  Find classes belonging to an specific IO-type.
\*----------------------------------------------------------------------------*/
pwr_tStatus io_GetIoTypeClasses( 
  io_eType	type,
  pwr_tClassId 	**classes,
  int		*size
)
{
  pwr_tStatus 	sts;
  pwr_sClassDef cdef;
  pwr_tOid	oid;
  int		add_class;
  pwr_sAttrRef  aref;

  *size = 0;
  *classes = calloc( IO_CLASSES_SIZE, sizeof(pwr_tCid));

  for ( sts = gdh_GetClassList( pwr_eClass_ClassDef, &oid);
	ODD(sts);
	sts = gdh_GetNextObject( oid, &oid)) {
    
    aref = cdh_ObjidToAref( oid);
    sts = gdh_GetObjectInfoAttrref( &aref, &cdef, sizeof(cdef));
    if ( EVEN(sts)) return sts;

    add_class = 0;
    switch ( type) {
    case io_eType_Agent:
      if ( cdef.Flags.b.IOAgent)
	add_class = 1;
      break;
    case io_eType_Rack:
      if ( cdef.Flags.b.IORack)
	add_class = 1;
      break;
    case io_eType_Card:
      if ( cdef.Flags.b.IOCard)
	add_class = 1;
      break;
    default:
      return IO__NOMETHOD;
    }

    if ( add_class) {
      if ( *size >= IO_CLASSES_SIZE)
	return IO__CLASSEXCEED;

      (*classes)[ *size] = cdh_ClassObjidToId( oid);
      (*size)++;
    }
  }
  return IO__SUCCESS;
}
Ejemplo n.º 10
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());
    }
  }
}
Ejemplo n.º 11
0
static pwr_tStatus SimulateOn( xmenu_sMenuCall *ip)
{
    int sts;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return XNAV__INVISIBLE;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return XNAV__INVISIBLE;

    return XNAV__SUCCESS;
}
Ejemplo n.º 12
0
pwr_tStatus io_get_plhandler_object(pwr_sClass_EplHandler** o, pwr_tObjid* roid)
{
  pwr_tStatus sts;
  pwr_tObjid oid;

  // Get EplHandler object
  sts = gdh_GetClassList(pwr_cClass_EplHandler, &oid);
  if (EVEN(sts))
    return sts;

  sts = gdh_ObjidToPointer(oid, (void*)o);
  if (EVEN(sts))
    return sts;

  if (roid != NULL)
    *roid = oid;
  return IO__SUCCESS;
}
Ejemplo n.º 13
0
static void
reinit_nodes ()
{
  pwr_tStatus sts;
  LstLink(sNode) *nl;
  sNode *np;
  pwr_tObjid oid;

  /* Mark all links in the NodeLink list */
  for (nl= LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl))
    LstObj(nl)->found = FALSE;

  for (
    sts = gdh_GetClassList(pwr_cClass_NodeLinkSup, &oid);
    ODD(sts);
    sts = gdh_GetNextObject(oid, &oid)
  ) {
    if ((np = get_nodes(oid)) == NULL) {
      np = init_node(oid, NULL, 1);
      if (np != NULL) {
	nl = LstIns(nl, np, node_l);
	np->found = TRUE;
      }
    } else {
      update_node(np);
    }
  }

  for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
    np = LstObj(nl);
    if (!np->found) {
      nl = LstPre(&np->node_l);
      LstRem(&np->node_l);
      LstNul(&np->node_l);
      gdh_SubUnrefObjectInfo (np->o->SubId);
      gdh_DLUnrefObjectInfo(np->dlid);
      free(np);
    }
  }	    
}
Ejemplo n.º 14
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());
    }
  }
}
Ejemplo n.º 15
0
static void
init_grafcet ()
{
  pwr_tStatus	sts;
  pwr_tObjid	oid;
  pwr_sClass_initstep *o;

  sts = gdh_GetClassList(pwr_cClass_initstep, &oid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(oid, (void *)&o);
    if (EVEN(sts)) {
      errh_Error("Initialize all GRAFCET init steps, %m", sts);
      return;
    }
    if (!o->StatusInit) {
      /* This InitStep is not initialized. */
      o->Status[0] = 1;
      o->StatusInit = 1;
    }
    sts = gdh_GetNextObject(oid, &oid);
  }
}
Ejemplo n.º 16
0
void
pwrb_IOHandler_Exec (
  void (* handler_event_cb)(int, int),
  int swap
)
{
  static pwr_tBoolean old_CardErrorSoftLimit = 0;
  static pwr_tBoolean old_CardErrorHardLimit = 0;

  if ( !iop || swap) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetClassList( pwr_cClass_IOHandler, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &iop);
    if ( EVEN(sts)) return;
  }

  if ( !iop)
    return;

  if ( handler_event_cb) {
    if ( iop->CardErrorSoftLimit && !old_CardErrorSoftLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorSoftLimit, 1);
    else if ( !iop->CardErrorSoftLimit && old_CardErrorSoftLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorSoftLimit, 0);
    
    if ( iop->CardErrorHardLimit && !old_CardErrorHardLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorHardLimit, 1);
    else if ( !iop->CardErrorHardLimit && old_CardErrorHardLimit)
      (handler_event_cb)(pwr_eSystemEventTypeEnum_IOErrorHardLimit, 0);  
  }
  old_CardErrorSoftLimit = iop->CardErrorSoftLimit;
  old_CardErrorHardLimit = iop->CardErrorHardLimit;
}
Ejemplo n.º 17
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);
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
int Op::sup_init()
{
  pwr_tOid node_oid;
  pwr_tOid sup_oid;
  pwr_tAName aname;
  pwr_tStatus sts;
  

  // Index 0 is current node
  sts = gdh_GetNodeObject( 0, &node_oid);
  if ( EVEN(sts)) return sts;

  OpSup sup;
  sup.node_oid = node_oid;
  sts = gdh_ObjidToName( node_oid, sup.object_name, sizeof(sup.object_name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) return sts;

  strcpy( aname, sup.object_name);
  strcat( aname, ".SystemStatus");
  sts = gdh_RefObjectInfo( aname, (void **)&sup.p, &sup.refid, sizeof(pwr_tStatus));
  if ( EVEN(sts)) return sts;

  syi_NodeName( &sts, sup.node_name, sizeof(sup.node_name));

  sup_vect.push_back(sup);			 

  // Add nodes in NodeLinkSup objects
  for ( sts = gdh_GetClassList( pwr_cClass_NodeLinkSup, &sup_oid);
	ODD(sts);
	sts = gdh_GetNextObject( sup_oid, &sup_oid)) {
    pwr_sClass_NodeLinkSup *sup_p;
    qcom_sNode 		qnode;
    pwr_tNid		nid;

    sts = gdh_ObjidToPointer( sup_oid, (void **)&sup_p);

    OpSup nsup;

    nsup.node_oid = sup_p->Node;

    sts = gdh_ObjidToName( nsup.node_oid, nsup.object_name, sizeof(nsup.object_name), 
			   cdh_mName_volumeStrict);
    if ( EVEN(sts)) strcpy( nsup.object_name, "");
    
    sts = gdh_ObjidToName( sup_oid, aname, sizeof(aname), cdh_mName_volumeStrict);
    if ( EVEN(sts)) return sts;
    
    strcat( aname, ".SystemStatus");
    sts = gdh_RefObjectInfo( aname, (void **)&nsup.p, &sup.refid, sizeof(pwr_tStatus));
    if ( EVEN(sts)) return sts;

    int found = 0;
    for (nid = qcom_cNNid; qcom_NextNode(&sts, &qnode, nid); nid = qnode.nid) {
      if ( qnode.nid == nsup.node_oid.vid) {
	strcpy( nsup.node_name, qnode.name);
	found = 1;
	break;
      }
    }
    if ( !found)
      strcpy( nsup.node_name, "Unknown");

    sup_vect.push_back(nsup);			 
  }
  return 1;
}
Ejemplo n.º 20
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);
      }
    }
  }
}
Ejemplo n.º 21
0
void rt_post::open()
{
  pwr_tStatus sts;
  pwr_tObjid oid;
  pwr_tFileName filename;

  // Open server configuration object PostConfig
  sts = gdh_GetClassList( pwr_cClass_PostConfig, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf);
    if ( EVEN(sts)) throw co_error( sts);

    aproc_RegisterObject( oid);
  }
  else {
    errh_Info( "No Post configuration");
    errh_SetStatus( 0);
    exit(0);
  }

  conf->Status = PWR__SRVSTARTUP;

  // Connect to mh
  mh_UtilWaitForMh();

  sts = mh_OutunitConnect(
		oid,
		mh_eOutunitType_Post,
		0,
		mh_ack_bc,
		mh_alarm_bc,
		mh_block_bc,
		mh_cancel_bc,
		mh_clear_alarmlist_bc,
		mh_clear_blocklist_bc,
		mh_info_bc,
		mh_return_bc,
		NULL
		);
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  // Load user database
	
  sts = gdh_GetObjectInfo( "pwrNode-System.SystemGroup", &systemgroup, 
			   sizeof(systemgroup));
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  udb = new GeUser();
  sts = dcli_get_defaultfilename( user_cFilename, filename, "");
  udb->load( filename);

  conf->Status = PWR__SRUN;

}
Ejemplo n.º 22
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */
Ejemplo n.º 23
0
void ini_StartApplications ()
{
    pwr_tStatus sts;
    pwr_sAppl *applp;
    pwr_tObjid objid;
#ifdef	OS_ELN
    $DESCRIPTOR(prognamedsc, "");
    $DESCRIPTOR(nulldsc, "");
    $DESCRIPTOR(argdsc, "");
    VARYING_STRING(255) filename;
    VARYING_STRING(41) progname;
    char tmpfilename[255],hostspec[20],*cp;
    PORT jobport;
#endif
#ifdef	OS_VMS
    $DESCRIPTOR(prognamedsc, "");
    $DESCRIPTOR(nulldsc, "");
    $DESCRIPTOR(argdsc, "");
    char spawnbuf [512] = "";
    $DESCRIPTOR (SpawnCommand, "");
    $DESCRIPTOR (SpawnPrcnam, "Appl Start");
    pwr_tUInt32 Flags;
#endif

    /* Find the $Appl objects on this particular node */

    sts = gdh_GetClassList(pwr_eClass_Appl, &objid);
    while (ODD(sts)) {
        if (ODD(gdh_ObjidToPointer(objid, (pwr_tAddress *)&applp))) {

            /* Found an object on this node, load the program */

#ifdef	OS_ELN

            if (strlen(applp->FileName) > 0) {

                /* Check whether we booted from a local disk or not */
                if (ini_LocalBoot()) {

                    /* Local boot */

                    /* Find the filename. Beyond the last ':' */
                    cp = strrchr(applp->FileName,':');
                    if ( cp )
                        *cp++;
                    else
                        cp = applp->FileName;

                    /* Build the application filename. */
                    sprintf(tmpfilename,"%s%s",ini_BootFilesLocation(),cp);

                } else {

                    /* Remote boot */

                    /* Check if application name contains '::'. If not - add hostspec */
                    cp = strstr(applp->FileName,"::");
                    if (!cp ) {
                        ini_GetNodeInfo(NULL, NULL, NULL, hostspec, NULL, NULL);
                        sprintf(tmpfilename,"%s::%s",hostspec,applp->FileName);
                    } else {
                        strcpy(tmpfilename,applp->FileName);
                    }
                }
                errh_Info("Load program '%s'", tmpfilename);

                CSTRING_TO_VARYING(tmpfilename, filename);
                CSTRING_TO_VARYING(applp->ProgramName, progname);

                eln$load_program(&filename, &progname, applp->KernelMode,
                                 applp->StartWithDebug, FALSE, applp->KernelStackSize, 1,
                                 10, applp->JobPriority, applp->ProcessPriority, &sts);
                if (EVEN(sts)) errh_Error("eln$load_program '%s'\n%m", applp->ProgramName, sts);
            }

            if (ODD(sts)) {

                /* Start it */

                errh_Info("Start program '%s'", applp->ProgramName);

                prognamedsc.dsc$a_pointer = applp->ProgramName;
                prognamedsc.dsc$w_length = strlen(applp->ProgramName);

                argdsc.dsc$a_pointer = applp->Arg;
                argdsc.dsc$w_length = strlen (applp->Arg);

                ker$create_job(&sts, &jobport, &prognamedsc, NULL, &nulldsc, &nulldsc, &nulldsc, &argdsc);

                if (EVEN(sts)) errh_Error("ker$create_job '%s'\n%m", applp->ProgramName, sts);
            }


#elif defined(OS_VMS)

            sprintf(spawnbuf, "$ @pwr_exe:rt_ini_appl_start %s \"%s\" %d %d \"%s\"",
                    applp->FileName, applp->ProgramName,
                    applp->StartWithDebug, applp->JobPriority,
                    applp->Arg);
            SpawnCommand.dsc$w_length = strlen(spawnbuf);
            SpawnCommand.dsc$a_pointer = spawnbuf;
            Flags = 1; /* Nowait and Notify */
            errh_Info("Starting %s\nin process %s", applp->FileName, applp->ProgramName);
            sts = lib$spawn(&SpawnCommand, NULL, NULL, &Flags);
            if (EVEN(sts)) errh_Error("lib$spawn '%s'\n%m", spawnbuf, sts);

#elif defined(OS_LYNX) || defined(OS_LINUX)

            errh_Error("NYI. start %s \"%s\" %d %d \"%s\"",
                       applp->FileName, applp->ProgramName,
                       applp->StartWithDebug, applp->JobPriority,
                       applp->Arg);
#endif

        } /* Local appl object */

        sts = gdh_GetNextObject (objid, &objid);
    }
}
Ejemplo n.º 24
0
static pwr_tStatus 
init_plc (
  plc_sProcess	*pp
)
{
  pwr_tStatus	sts = PLC__SUCCESS;
  pwr_tObjid   	oid;
  pwr_tObjid   	pp_oid;
  pwr_tObjid   	io_oid;
  pwr_tObjid	thread_oid;
  int		sec;
  int		msec;
  int		i;
  pwr_tCid	cid;

  sts = gdh_GetNodeObject(0, &oid);
  if (EVEN(sts)) {
    errh_Fatal("gdh_GetNodeObject, %m", sts);
    exit(sts);
  }

  sts = gdh_ObjidToPointer(oid, (void *)&pp->Node);
  if (EVEN(sts)) return sts;

  sts = gdh_GetClassList(pwr_cClass_PlcProcess, &pp_oid);
  if (EVEN(sts)) {
    errh_Error("Found no PlcProcess-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(pp_oid, (void *)&pp->PlcProcess);
  if (EVEN(sts)) return sts;

  i = 0;
  sts = gdh_GetChild( pp_oid, &thread_oid);
  while ( ODD(sts)) {
    sts = gdh_GetObjectClass( thread_oid, &cid);
    if ( EVEN(sts)) return sts;
    
    if ( cid == pwr_cClass_PlcThread)
      pp->PlcProcess->PlcThreadObjects[i++] = thread_oid;

    sts = gdh_GetNextSibling( thread_oid, &thread_oid);
  }
  for ( ; i > sizeof(pp->PlcProcess->PlcThreadObjects)/sizeof(pp->PlcProcess->PlcThreadObjects[0]); i++)
    pp->PlcProcess->PlcThreadObjects[i] = pwr_cNObjid;

  aproc_RegisterObject( pp_oid);

  sts = gdh_GetClassList(pwr_cClass_IOHandler, &io_oid);
  if (EVEN(sts)) {
    errh_Error("Found no IOHandler-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(io_oid, (void *)&pp->IOHandler);
  if (EVEN(sts)) return sts;

  /* Set subscription defaults for PLC job */

  sts = gdh_SetSubscriptionDefaults(
    (pwr_tInt32)(pp->PlcProcess->SubscriptionInterval * 1000.), 10000);

  sec = pp->PlcProcess->SubscriptionInterval;
  msec = (int)((pp->PlcProcess->SubscriptionInterval - sec) * 1000.);
  errh_Info("Setting subscription defaults to %d.%03d seconds", sec, msec);

  sts = gdh_ObjidToName(oid, pp->nodeName, sizeof(pp->nodeName), cdh_mNName);
  if (EVEN(sts)) return sts;

  init_grafcet(pp);
  link_io_base_areas(pp);

  return sts;
}
Ejemplo n.º 25
0
int main (int argc, char **argv)
{
  pwr_tStatus sts;
  char *c;
  int cidopt = 0;
  pwr_tObjName cidstr;
  pwr_tAName astr;
  int i;

  if ( argc <= 1) {
    usage();
    exit(1);
  }

  sts = gdh_Init("rt_gdhget");
  if ( EVEN(sts)) {
    exit(sts);
  }

  for ( i = 1; i < argc; i++) {
    c = argv[i];
    if ( *c == '-') {
      c++;
      switch ( *c) {
      case 'h':
	usage();
	exit(0);
     
      case 'c':
	if ( argc <= i+1) {
	  usage();
	  exit(1);
	}
	strncpy( cidstr, argv[i+1], sizeof(cidstr));
	cidopt = 1;
	i++;
	break;
      }
    }
    else
      strcpy( astr, argv[i]);
  }
  
  if ( cidopt) {
    // Get the first object of class cidstr, and print the value of attribute 
    // astr in this object

    pwr_tCid cid;
    pwr_tOid oid;
    pwr_tAttrRef aref, aaref;
    pwr_tTid a_tid;
    unsigned int a_size, a_offs, a_dim;
    void *a_valp;
    char str[256];

    sts = gdh_ClassNameToId( cidstr, &cid);
    if ( EVEN(sts)) {
      exit(sts);
    }

    sts = gdh_GetClassList( cid, &oid);
    if ( EVEN(sts)) {
      exit(sts);
    }

    aref = cdh_ObjidToAref( oid);
    sts = gdh_ArefANameToAref( &aref, astr, &aaref);
    if ( EVEN(sts)) {
      exit(sts);
    }

    sts = gdh_GetAttributeCharAttrref( &aaref, &a_tid, &a_size, &a_offs, &a_dim);
    if ( EVEN(sts)) {
      exit(sts);
    }
    a_valp = calloc( 1, a_size);
    sts = gdh_GetObjectInfoAttrref( &aaref, a_valp, a_size);
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }
    
    sts = cdh_AttrValueToString( a_tid, a_valp, str, sizeof(str));
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }

    printf( "%s\n", str);
    free( a_valp);

    exit(0);

  }
  else {
    // Print the value of the attriute in astr

    pwr_tTypeId a_tid;
    pwr_tUInt32 a_size, a_offs, a_elem;
    void *a_valp;
    char str[256];
    
    sts = gdh_GetAttributeCharacteristics( astr,
					 &a_tid, &a_size, &a_offs, &a_elem);
    if ( EVEN(sts)) {
      exit(sts);
    }
    a_valp = calloc( 1, a_size);

    sts = gdh_GetObjectInfo( astr, a_valp, a_size);
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }
    
    sts = cdh_AttrValueToString( a_tid, a_valp, str, sizeof(str));
    if ( EVEN(sts)) {
      free( a_valp);
      exit(sts);
    }

    printf( "%s\n", str);
    free( a_valp);

    exit(0);
  }    
  exit(1);
}
Ejemplo n.º 26
0
pwr_tStatus bck_LoadBackup()
{
  pwr_tStatus sts;
  pwr_tInt32 csts;
  pwr_tObjid objid;
  pwr_sClass_Backup_Conf* backup_confp = NULL; /* Backup_Conf object pointer */
  FILE* f;
  BCK_FILEHEAD_STRUCT fh; /* File header */
  BCK_CYCLEHEAD_STRUCT ch_old;
  bck_t_cycleheader ch;
  BCK_DATAHEAD_STRUCT dh_old;
  bck_t_writeheader dh;
  pwr_tUInt32 c;
  pwr_tUInt32 d;
  char* strp;
  char* datap = NULL;
  char* namep = NULL;
  char fname[200];
  pwr_tAName objectname;

  /* Find the local Backup_Conf object.  */

  sts = gdh_GetClassList(pwr_cClass_Backup_Conf, &objid);
  while (ODD(sts)) {
    sts = gdh_ObjidToPointer(objid, (pwr_tAddress*)&backup_confp);
    if (ODD(sts))
      break;
    sts = gdh_GetNextObject(objid, &objid);
  }
  if (EVEN(sts))
    return sts;

  /* Open the backup file.  */
  dcli_translate_filename(fname, backup_confp->BackupFile);

  f = fopen(fname, "r+" A_MODE);

  if (f == NULL) {
    SET_ERRNO_STS;
    errh_Error("Load Backup: Failed to open %s, errno = %d",
        backup_confp->BackupFile, sts);
    return sts;
  }

  errh_Info("BACKUP loading information from %s", FGETNAME);

  sts = 1; /* Guess all ok */

  /* Read the header.  */

  csts = fread(&fh, sizeof fh, 1, f);
  if (csts == 0) {
    SET_ERRNO_STS;
  } else {
    if (fh.version < BCK_FILE_VERSION - 1) {
      errh_Info("BACKUP Loading old file version : %d", fh.version);
      /* Read the cycle data.  */

      BCK_FILEHEAD_STRUCT_V6* fhp_v6 = (BCK_FILEHEAD_STRUCT_V6*)&fh;

      for (c = 0; c < 2; c++) {
        fseek(f, fhp_v6->curdata[c], 0);
        fread(&ch_old, sizeof ch_old, 1, f);

        /* Work thru the data segments */

        for (d = 0; d < ch_old.segments; d++) {
          csts = fread(&dh_old, sizeof dh_old, 1, f);
          if (csts != 0) {
            datap = malloc(dh_old.attrref.Size);
            csts = fread(datap, dh_old.attrref.Size, 1, f);
          }
          if (csts == 0) {
            SET_ERRNO_STS;
            break;
          }

          if (dh_old.valid) {
            /* Find object */

            if (dh_old.dynamic) {
              strp
                  = strchr(dh_old.dataname, '.'); /* always is a full object! */
              if (strp != NULL)
                *strp = '\0'; /* Just make sure... */

              sts = gdh_CreateObject(dh_old.dataname, dh_old.cid,
                  dh_old.attrref.Size, &objid, dh_old.attrref.Objid, 0,
                  pwr_cNObjid);

              if (strp != NULL)
                *strp = '.';

              if (ODD(sts))
                sts = gdh_SetObjectInfo(
                    dh_old.dataname, datap, dh_old.attrref.Size);
            } /* Dynamic object */
            else {
              sts = gdh_SetObjectInfoAttrref(
                  &dh_old.attrref, datap, dh_old.attrref.Size);
            }
          } /* valid segment */

          free(datap);

          if (EVEN(sts)) {
            errh_Error(
                "BACKUP error reloading %s, reason:\n%m", dh_old.dataname, sts);
            sts = 1;
          }

        } /* For all data segments */
        if (EVEN(sts))
          break; /* Fatal! Get out! */
      } /* For each cycle */
    } else if (fh.version == BCK_FILE_VERSION - 1) {
      /* Read the cycle data.  */
      BCK_FILEHEAD_STRUCT_V6* fhp_v6 = (BCK_FILEHEAD_STRUCT_V6*)&fh;
      BCK_CYCLEHEAD_STRUCT_V6 ch_v6;

      for (c = 0; c < 2; c++) {
        fseek(f, fhp_v6->curdata[c], 0);
        fread(&ch_v6, sizeof ch_v6, 1, f);

        /* Work thru the data segments */

        for (d = 0; d < ch_v6.segments; d++) {
          csts = fread(&dh, sizeof dh, 1, f);
          if (csts != 0) {
            if (dh.namesize > 0) {
              namep = malloc(dh.namesize + 1);
              csts = fread(namep, dh.namesize + 1, 1, f);
            } else
              namep = NULL;
            datap = malloc(dh.size);
            csts = fread(datap, dh.size, 1, f);
          }
          if (csts == 0) {
            SET_ERRNO_STS;
            break;
          }

          if (dh.valid) {
            /* Find object */

            if (dh.dynamic) {
              strp = strchr(namep, '.'); /* always is a full object! */
              if (strp != NULL)
                *strp = '\0'; /* Just make sure... */

              sts = gdh_CreateObject(
                  namep, dh.cid, dh.size, &objid, dh.objid, 0, pwr_cNObjid);

              if (strp != NULL)
                *strp = '.';

              if (ODD(sts))
                sts = gdh_SetObjectInfo(namep, datap, dh.size);

              strncpy(objectname, namep, pwr_cSizAName);
            } /* Dynamic object */
            else {
              sts = gdh_ObjidToName(
                  dh.objid, objectname, sizeof(objectname), cdh_mNName);
              if (ODD(sts)) {
                strcat(objectname, namep);
                sts = gdh_SetObjectInfo(objectname, datap, dh.size);
              }
            }
          } /* valid segment */

          if (EVEN(sts)) {
            errh_Error(
                "BACKUP error reloading %s, reason:\n%m", objectname, sts);
            sts = 1;
          }

          free(datap);
          free(namep);

        } /* For all data segments */
        if (EVEN(sts))
          break; /* Fatal! Get out! */
      } /* For each cycle */
    } else if (fh.version == BCK_FILE_VERSION) {
      /* Read the cycle data.  */

      for (c = 0; c < 2; c++) {
        fseek(f, fh.curdata[c], 0);
        fread(&ch, sizeof ch, 1, f);

        /* Work thru the data segments */

        for (d = 0; d < ch.segments; d++) {
          csts = fread(&dh, sizeof dh, 1, f);
          if (csts != 0) {
            if (dh.namesize > 0) {
              namep = malloc(dh.namesize + 1);
              csts = fread(namep, dh.namesize + 1, 1, f);
            } else
              namep = NULL;
            datap = malloc(dh.size);
            csts = fread(datap, dh.size, 1, f);
          }
          if (csts == 0) {
            SET_ERRNO_STS;
            break;
          }

          if (dh.valid) {
            /* Find object */
            strcpy(objectname, "");

            if (dh.dynamic) {
              strp = strchr(namep, '.'); /* always is a full object! */
              if (strp != NULL)
                *strp = '\0'; /* Just make sure... */

              sts = gdh_CreateObject(
                  namep, dh.cid, dh.size, &objid, dh.objid, 0, pwr_cNObjid);

              if (strp != NULL)
                *strp = '.';

              if (ODD(sts))
                sts = gdh_SetObjectInfo(namep, datap, dh.size);

              strncpy(objectname, namep, pwr_cSizAName);
            } /* Dynamic object */
            else {
              sts = gdh_ObjidToName(
                  dh.objid, objectname, sizeof(objectname), cdh_mNName);
              if (ODD(sts)) {
                strcat(objectname, namep);
                sts = gdh_SetObjectInfo(objectname, datap, dh.size);
              } else
                cdh_OidToString(objectname, sizeof(objectname), dh.objid, 1);
            }
          } /* valid segment */

          if (EVEN(sts)) {
            errh_Error(
                "BACKUP error reloading %s, reason:\n%m", objectname, sts);
            sts = 1;
          }

          free(datap);
          free(namep);

        } /* For all data segments */
        if (EVEN(sts))
          break; /* Fatal! Get out! */
      } /* For each cycle */
    } /* File version format ok */
    else {
      errh_Error("BACKUP Cannot load backup file with version %d", fh.version);
    }
  } /* Successful header read */

  fclose(f);

  return sts;
}