Ejemplo n.º 1
0
pwr_tStatus wsx_CheckAttrRef( ldh_tSesContext	sesctx,
			      pwr_tAttrRef	aref,
			      const pwr_tObjName attribute,
			      pwr_tCid		*cid_vect,
			      int		null_is_ok,
			      int		*errorcount,
			      int		*warningcount)
{
  pwr_tAttrRef value;
  wb_session *sp = (wb_session *)sesctx;

  wb_attribute a = sp->attribute( &aref);
  if ( !a) return a.sts();

  wb_attribute a_attr( a, 0, attribute);
  if ( !a_attr) return a_attr.sts();
    
  a_attr.value( &value);
  if ( !a_attr) return a_attr.sts();

  if ( !null_is_ok && cdh_ObjidIsNull( value.Objid)) {
    char msg[80];
    sprintf ( msg, "Attribute reference is null in \"%s\"", attribute);
    wsx_error_msg_str( sesctx, msg, aref, 'E', errorcount, warningcount);
  }
  if ( cdh_ObjidIsNotNull( value.Objid)) {
    wb_attribute a_value = sp->attribute( &value);
    if ( !a_value) {
      char msg[80];
      sprintf ( msg, "Undefined attribute reference in \"%s\"", attribute);
      wsx_error_msg_str( sesctx, msg, aref, 'E', errorcount, warningcount);
    }
    else if ( cid_vect) {
      // Check attribute reference class
      bool found = false;
      for ( int i = 0; cid_vect[i]; i++) {
	if ( cid_vect[i] == a_value.tid()) {
	  found = true;
	  break;
	}
      }
      if ( !found) {
	char msg[80];
	sprintf ( msg, "Invalid class of attribute reference in \"%s\"", attribute);
	wsx_error_msg_str( sesctx, msg, aref, 'E', errorcount, warningcount);
      }
    }
  }
  return WSX__SUCCESS;
}
Ejemplo n.º 2
0
int main( int argc, char *argv[])
{
  pwr_tObjName volume;

  for ( int i = 1; i < argc; i++) {
    if ( argv[i][0] == '-') {
      switch ( argv[i][1]) {
      case 'h':
	usage();
	exit(0);
      case 'v':
	if ( i+1 >= argc) {
	  usage();
	  exit(0);
	}
	strncpy( volume, argv[i+1], sizeof(volume));
	i++;
	break;
      default:
	printf("Unknown argument: %s\n", argv[i]);
	usage();
	exit(0);
      }
    }
  }

  wb_env env;
  env.load( volume);

  wb_volume vol;
  for ( vol = env.volume(); vol.oddSts(); vol.next()) {
    if ( vol.cid() == pwr_eClass_RootVolume ||
	 vol.cid() == pwr_eClass_SubVolume ||
	 vol.cid() == pwr_eClass_SharedVolume) {
      break;
    }
  }
  if ( vol.evenSts()) exit( vol.sts());

  wb_session session(vol);
  if ( ! session.access( ldh_eAccess_ReadWrite)) {
    cout << "** No write access" << endl;
    exit(0);
  }

#if 0
  wb_object o;
  for ( o = session.object(); o.oddSts(); o = o.after()) {
    process( session, o);
  }
#endif


  // Replace Pb modules $IoConnect references with Io modules references
  pwr_tAttrRef aref;
  pwr_tCid cid;
  pwr_tAttrRef value_aref;
    
  for ( unsigned int i = 0; i < sizeof(upg_sigchancon)/sizeof(upg_sigchancon[0]); i++) {
    wb_object co = session.object( upg_sigchancon[i].cname);
    if ( !co) {
      printf( "** Class not loaded: %s\n", upg_sigchancon[i].cname);
      continue;
    }
    
    cid = cdh_ClassObjidToId( co.oid());

    for ( session.aref( cid, &aref);
	  session.oddSts();
	  session.nextAref( cid, &aref, &aref)) {


      wb_attribute a = session.attribute(&aref);
      if (!a) continue;


      wb_attribute a_ioconnect( a, 0, "IoConnect");
      if ( a_ioconnect.evenSts())
	continue;

      a_ioconnect.value( &value_aref);
      if ( a_ioconnect.evenSts())
	continue;

      wb_attribute a_pbmodule = session.attribute( &value_aref);
      if ( a_pbmodule.oddSts()) {
	wb_attribute a_iomodule( a_pbmodule, 0, "Io");
	if ( a_iomodule.oddSts()) {
	  value_aref = a_iomodule.aref();
	  session.writeAttribute( a_ioconnect, &value_aref, sizeof( value_aref));
	  printf( "Set %s -> %s\n", a_iomodule.longName().c_str(), a_ioconnect.longName().c_str());
	}
      }

      for ( unsigned int j = 0; j < sizeof(upg_sigchancon[0].attr)/sizeof(upg_sigchancon[0].attr[0]); j++) {
	if ( strcmp( upg_sigchancon[i].attr[j], "") == 0)
	  break;

	try {
	  wb_attribute a_attr2( a, 0, upg_sigchancon[i].attr[j]);
	  if ( a_attr2.evenSts())
	    continue;
    
	  wb_attribute a_attr( a_attr2, 0, "SigChanCon");
	  if ( a_attr.evenSts())
	    continue;
    
	  a_attr.value( &value_aref);
	  if ( a_attr.evenSts())
	    continue;

	  if ( value_aref.Objid.vid == cdh_cIoConnectVolume) {
	    wb_attribute a_value = session.attribute( upg_sigchancon[i].value[j]);
	    value_aref = a_value.aref();
	    if ( a_value.evenSts())
	      continue;

	    session.writeAttribute( a_attr, &value_aref, sizeof( value_aref));
	    // printf( "Updating SigChanCon \"%s\" %s\n", a_attr.longName().c_str(), upg_sigchancon[i].value[j]);
	  }
	}
	catch ( wb_error& e) {
	  continue;
	}
      }      
    }
  }

  session.commit();
}