示例#1
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);
}
示例#2
0
int Graph::init_object_graph( int mode)
{
    char 		classname[120];
    pwr_tClassId 	classid;
    char		*s;
    int 		sts;
    int		i;
    int		is_type = 0;
    pwr_sAttrRef	attrref;

    if ( mode == 0) {
        if ( strcmp( filename, "_none_.pwg") == 0) {
            if ( strcmp( object_name[0], "collect") == 0) {
                sts = graph_object_collect_build( this, 0);
                return sts;
            }
        }
        return 1;
    }
    if ( strcmp( filename, "_none_.pwg") == 0) {
        if ( strcmp( object_name[0], "collect") == 0)
            return 1;
    }

    // Get class from filename
    if ( (s = strrchr( filename, '/')) ||
            (s = strrchr( filename, '>')) ||
            (s = strrchr( filename, ']')) ||
            (s = strrchr( filename, ':')))
    {
        if ( strncmp( s+1, "pwr_t_", 6) == 0)
        {
            is_type = 1;
            strcpy( classname, s+7);
        }
        else if ( strncmp( s+1, "pwr_c_", 6) == 0)
            strcpy( classname, s+7);
        else
            strcpy( classname, s+1);
    }
    else
        strcpy( classname, filename);
    if ( (s = strrchr( classname, '.')))
        *s = 0;

    if ( is_type)
    {
        sts = gdh_NameToAttrref( pwr_cNObjid, object_name[0], &attrref);
        if ( EVEN(sts)) return sts;

        // Types are removed
        return 0;

    }
    else
    {
        sts = gdh_ClassNameToId( classname, &classid);
        if ( EVEN(sts)) return sts;

        sts = gdh_NameToAttrref( pwr_cNObjid, object_name[0], &attrref);
        if ( EVEN(sts)) return sts;

        for ( i = 0; graph_object_functions[i].classid; i++)
        {
            if ( classid == graph_object_functions[i].classid)
            {
                sts = (graph_object_functions[i].func)( this, &attrref);
                return sts;
            }
        }
    }
    return 0;
}