예제 #1
0
/*
 * Get information about port on bridge.
 */
int br_get_port_info(const char *brname, const char *port, 
		     struct port_info *info)
{
	DIR *d;
	char path[SYSFS_PATH_MAX];

	snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brport", port);
	d = opendir(path);
	if (!d)
		goto fallback;

	memset(info, 0, sizeof(*info));

	fetch_id(path, "designated_root", &info->designated_root);
	fetch_id(path, "designated_bridge", &info->designated_bridge);
	info->port_no = fetch_int(path, "port_no");
	info->port_id = fetch_int(path, "port_id");
	info->designated_port = fetch_int(path, "designated_port");
	info->path_cost = fetch_int(path, "path_cost");
	info->designated_cost = fetch_int(path, "designated_cost");
	info->state = fetch_int(path, "state");
	info->top_change_ack = fetch_int(path, "change_ack");
	info->config_pending = fetch_int(path, "config_pending");
	fetch_tv(path, "message_age_timer", &info->message_age_timer_value);
	fetch_tv(path, "forward_delay_timer", &info->forward_delay_timer_value);
	fetch_tv(path, "hold_timer", &info->hold_timer_value);
	closedir(d);

	return 0;
fallback:
	return old_get_port_info(brname, port, info);
}
예제 #2
0
bool IndDBase::fetch( Individual * person )
{

  if ( ! attached() ) return false;

  // Look-up this individual based upon their ID. 
  // Attach all phenotype and meta-information we find
  // Return true if find somebody matching that description
  
  uint64_t idx = fetch_id( person->id() );
 
  if ( idx == 0 ) return false;
  
  if ( fetch( person , fetch_id( person->id() ) ) )
    {
      person->missing( false );
      return true;
    }
  else
    {
      person->missing( true );
      return false;
    }

}
예제 #3
0
/*
 * Get information about port on bridge.
 */
int br_get_port_info(const char *brname, const char *port, 
		     struct port_info *info)
{
#ifndef HAVE_LIBSYSFS
	return old_get_port_info(brname, port, info);
#else
	struct sysfs_directory *sdir
		= bridge_sysfs_directory(port, SYSFS_BRIDGE_PORT_ATTR);

	if (!sdir) 
		return old_get_port_info(brname, port, info);

	memset(info, 0, sizeof(*info));
	fetch_id(sdir, "designated_root", &info->designated_root);
	fetch_id(sdir, "designated_bridge", &info->designated_bridge);
	info->port_no = fetch_int(sdir, "port_no");
	info->port_id = fetch_int(sdir, "port_id");
	info->designated_port = fetch_int(sdir, "designated_port");
	info->path_cost = fetch_int(sdir, "path_cost");
	info->designated_cost = fetch_int(sdir, "designated_cost");
	info->state = fetch_int(sdir, "state");
	info->top_change_ack = fetch_int(sdir, "change_ack");
	info->config_pending = fetch_int(sdir, "config_pending");
	fetch_tv(sdir, "message_age_timer", 
		 &info->message_age_timer_value);
	fetch_tv(sdir, "forward_delay_timer",
		 &info->forward_delay_timer_value);
	fetch_tv(sdir, "hold_timer",
		 &info->hold_timer_value);
	sysfs_close_directory(sdir);

	return 0;
#endif
}
예제 #4
0
/*
 * Get bridge parameters using either sysfs or old
 * ioctl.
 */
static int br_get_bridge_info(const char *bridge, struct bridge_info *info)
{
#ifdef HAVE_LIBSYSFS
	struct sysfs_class_device *dev;
	char path[SYSFS_PATH_MAX];

	if (!br_class_net)
		goto fallback;

	dev = sysfs_get_class_device(br_class_net, bridge);
	if (!dev) {
		dprintf("get_class_device '%s' failed\n", bridge);
		goto fallback;
	}

	snprintf(path, SYSFS_PATH_MAX, "%s/bridge", dev->path);
	if (sysfs_path_is_dir(path)) {
		dprintf("path '%s' is not a directory\n", path);
		sysfs_close_class_device(dev);
		goto fallback;
	}

	memset(info, 0, sizeof(*info));
	fetch_id(dev, BRIDGEATTR("root_id"), &info->designated_root);
	fetch_id(dev, BRIDGEATTR("bridge_id"), &info->bridge_id);
	info->root_path_cost = fetch_int(dev, BRIDGEATTR("root_path_cost"));
	fetch_tv(dev, BRIDGEATTR("max_age"), &info->max_age);
	fetch_tv(dev, BRIDGEATTR("hello_time"), &info->hello_time);
	fetch_tv(dev, BRIDGEATTR("forward_delay"), &info->forward_delay);
	fetch_tv(dev, BRIDGEATTR("max_age"), &info->bridge_max_age);
	fetch_tv(dev, BRIDGEATTR("hello_time"), &info->bridge_hello_time);
	fetch_tv(dev, BRIDGEATTR("forward_delay"), &info->bridge_forward_delay);
	fetch_tv(dev, BRIDGEATTR("ageing_time"), &info->ageing_time);
	fetch_tv(dev, BRIDGEATTR("hello_timer"), &info->hello_timer_value);
	fetch_tv(dev, BRIDGEATTR("tcn_timer"), &info->tcn_timer_value);
	fetch_tv(dev, BRIDGEATTR("topology_change_timer"),
		 &info->topology_change_timer_value);;
	fetch_tv(dev, BRIDGEATTR("gc_timer"), &info->gc_timer_value);

	info->root_port = fetch_int(dev, BRIDGEATTR("root_port"));
	info->stp_enabled = fetch_int(dev, BRIDGEATTR("stp_state"));
	info->topology_change = fetch_int(dev, BRIDGEATTR("topology_change"));
	info->topology_change_detected = fetch_int(dev,
						   BRIDGEATTR
						   ("topology_change_detected"));
	sysfs_close_class_device(dev);

	return 0;

fallback:
#endif
	return old_get_bridge_info(bridge, info);
}
예제 #5
0
/*
 * Get bridge parameters using either sysfs or old
 * ioctl.
 */
int br_get_bridge_info(const char *bridge, struct bridge_info *info)
{
	DIR *dir;
	char path[SYSFS_PATH_MAX];

	snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/bridge", bridge);
	dir = opendir(path);
	if (dir == NULL) {
		dprintf("path '%s' is not a directory\n", path);
		goto fallback;
	}

	memset(info, 0, sizeof(*info));
	fetch_id(path, "root_id", &info->designated_root);
	fetch_id(path, "bridge_id", &info->bridge_id);
	info->root_path_cost = fetch_int(path, "root_path_cost");
	fetch_tv(path, "max_age", &info->max_age);
	fetch_tv(path, "hello_time", &info->hello_time);
	fetch_tv(path, "forward_delay", &info->forward_delay);
	fetch_tv(path, "max_age", &info->bridge_max_age);
	fetch_tv(path, "hello_time", &info->bridge_hello_time);
	fetch_tv(path, "forward_delay", &info->bridge_forward_delay);
	fetch_tv(path, "ageing_time", &info->ageing_time);
	fetch_tv(path, "hello_timer", &info->hello_timer_value);
	fetch_tv(path, "tcn_timer", &info->tcn_timer_value);
	fetch_tv(path, "topology_change_timer", 
		 &info->topology_change_timer_value);;
	fetch_tv(path, "gc_timer", &info->gc_timer_value);

	info->root_port = fetch_int(path, "root_port");
	info->stp_enabled = fetch_int(path, "stp_state");
	info->topology_change = fetch_int(path, "topology_change");
	info->topology_change_detected = fetch_int(path, "topology_change_detected");

	closedir(dir);
	return 0;

fallback:
	return old_get_bridge_info(bridge, info);
}
예제 #6
0
uint64_t IndDBase::insert( const Individual & ind , bool * newone )
{

  int id = fetch_id( ind.id() );
  
  if ( id == 0 ) 
    {
      
      // This is a new record
      
      sql.bind_text( stmt_insert_individual , ":name" , ind.id() );
      sql.bind_text( stmt_insert_individual , ":fid" , ind.fid() );
      sql.bind_text( stmt_insert_individual , ":iid" , ind.iid() );
      sql.bind_text( stmt_insert_individual , ":pat" , ind.father() );
      sql.bind_text( stmt_insert_individual , ":mat" , ind.mother() );
      sql.bind_text( stmt_insert_individual , ":sex" , Helper::int2str( ind.sex() ) ); 
      
      sql.step( stmt_insert_individual );
      sql.reset( stmt_insert_individual );
      
      if ( newone ) *newone = true;      
      id = fetch_id( ind.id() );
    }
  else
    {
      // ..append an existing record
      
      sql.bind_text( stmt_update_individual , ":name" , ind.id() );
      sql.bind_text( stmt_update_individual , ":fid" , ind.fid() );
      sql.bind_text( stmt_update_individual , ":iid" , ind.iid() );
      sql.bind_text( stmt_update_individual , ":pat" , ind.father() );
      sql.bind_text( stmt_update_individual , ":mat" , ind.mother() );
      sql.bind_text( stmt_update_individual , ":sex" , Helper::int2str( ind.sex() ) );
      
      sql.step( stmt_update_individual );
      sql.reset( stmt_update_individual );
      if( newone ) *newone = false;      
    }  
  return id;
}
예제 #7
0
/*
 * Get bridge parameters using either sysfs or old
 * ioctl.
 */
int br_get_bridge_info(const char *bridge, struct bridge_info *info)
{
#ifndef HAVE_LIBSYSFS
	return old_get_bridge_info(bridge, info);
#else
	struct sysfs_directory *sdir;

	sdir = bridge_sysfs_directory(bridge, SYSFS_BRIDGE_ATTR);
	if (!sdir) 
		return old_get_bridge_info(bridge,info);

	memset(info, 0, sizeof(*info));
	fetch_id(sdir, "root_id", &info->designated_root);
	fetch_id(sdir, "bridge_id", &info->bridge_id);
	info->root_path_cost = fetch_int(sdir, "root_path_cost");
	fetch_tv(sdir, "max_age", &info->max_age);
	fetch_tv(sdir, "hello_time", &info->hello_time);
	fetch_tv(sdir, "forward_delay", &info->forward_delay);
	fetch_tv(sdir, "max_age", &info->bridge_max_age);
	fetch_tv(sdir, "hello_time", &info->bridge_hello_time);
	fetch_tv(sdir, "forward_delay", &info->bridge_forward_delay);
	fetch_tv(sdir, "ageing_time", &info->ageing_time);
	fetch_tv(sdir, "hello_timer", &info->hello_timer_value);
	fetch_tv(sdir, "tcn_timer", &info->tcn_timer_value);
	fetch_tv(sdir, "topology_change_timer", 
		 &info->topology_change_timer_value);;
	fetch_tv(sdir, "gc_timer", &info->gc_timer_value);

	info->root_port = fetch_int(sdir, "root_port");
	info->stp_enabled = fetch_int(sdir, "stp_state");
	info->topology_change = fetch_int(sdir, "topology_change");
	info->topology_change_detected = fetch_int(sdir, "topology_change_detected");
	sysfs_close_directory(sdir);

	return 0;
#endif
}
예제 #8
0
bool IndDBase::load_phenotypes( const std::string & filename )
{

  if ( ! attached() ) Helper::halt( "no attached INDDB" );

  if ( ! Helper::fileExists(filename) ) 
    {
      plog.warn("could not find phenotype file " + filename );
      return false;
    }

  // Expect a variant of FAM file format
  
  InFile f( filename );

  std::map<std::string,int> phe_codes1;
  std::map<int,int> phe_codes2;
  std::vector<std::string> phe_codes;
  std::map<std::string,mType> type_codes;
  
  std::map<std::string,std::string> mis_codes;
  
  int expected_col_count = -1;
  int inserted = 0;
  
  sql.begin();

  drop_index();
 
  while ( ! f.eof() )
    {
      
      std::string s = f. readLine();
      
      if ( s == "" ) continue;
      
      // Meta-information? 
      
      if ( s.size() > 2 && s.substr(0,2) == "##" )
	{
	  
	  std::vector<std::string> tok = Helper::quoted_parse( s.substr(2) );
	  
	  // need at least a name
	  if ( tok.size() < 1 ) continue;	  
	  std::string name = tok[0];

	  // defaults
	  std::string type = "Integer"; 
	  std::string miss = "0";
	  std::string desc = "Dichotomous phenotype";	  
	  if ( tok.size() >= 2 ) type = tok[1];
	  if ( tok.size() >= 3 ) miss = tok[2];
	  if ( tok.size() >= 4 ) desc = tok[3];
	  
	  int code = insert_phenotype( name, type, miss, desc );

	  phe_codes1[ name ] = code;
	  mis_codes[ name ] = miss;
	  
	  if ( Helper::is_int( type ) ) type_codes[ name ] = META_INT;
	  else if ( Helper::is_float( type ) ) type_codes[ name ] = META_FLOAT;
	  else type_codes[ name ] = META_TEXT;

	}

      // Or header line?
      
      else if ( s.substr(0,1) == "#" )
	{
	  
	  // #ID phe1 phe2 phe3
	  
	  std::vector<std::string> tok = Helper::parse( s , " \t");
	  
	  if ( tok.size() < 2 ) { plog.warn("malformed phenotype file"); continue; } 
	  if ( tok[0] != "#ID" ) { plog.warn("malformed phenotype file"); continue; } 
	  
	  for ( int i = 1 ; i < tok.size(); i++ )
	    {
	      std::map<std::string,int>::iterator k = phe_codes1.find( tok[i] );	      

	      if ( k == phe_codes1.end() ) 
		Helper::halt( tok[i] + " in header of phenotype file but not defined" );
	      
	      phe_codes2[ i ] = k->second;
	      phe_codes.push_back( tok[i] );
	      
	    }
	  expected_col_count = tok.size();
	}
      
      // Or data ? 
      
      else 
	{
	  
	  // Skip, if we haven't seen a header
	  if ( expected_col_count == -1 ) continue;
	 
	  std::vector<std::string> tok = Helper::parse( s , " \t");
	  
	  if ( tok.size() != expected_col_count ) 
	    {
	      plog.warn("row in phenotype file with wrong number of fields");
	      continue;
	    }
	  
	  int indiv_id = fetch_id( tok[0] );
	  
	  // if individual does not exist, create

	  if ( indiv_id == 0 ) 
	    {
	      std::string period = ".";

	      sql.bind_text( stmt_insert_individual , ":name" , tok[0] );
	      sql.bind_text( stmt_insert_individual , ":fid" , period );
	      sql.bind_text( stmt_insert_individual , ":fid" , period );
	      sql.bind_text( stmt_insert_individual , ":iid" , period );
	      sql.bind_text( stmt_insert_individual , ":pat" , period );
	      sql.bind_text( stmt_insert_individual , ":mat" , period );
	      sql.bind_text( stmt_insert_individual , ":sex" , period );
	      
	      sql.step( stmt_insert_individual );
	      sql.reset( stmt_insert_individual );
	      
	      // and grab the ID
	      indiv_id = fetch_id( tok[0] );

	    }
	  
	  //
	  // Insert actual phenotypes
	  //
	  
	  for ( int i = 1; i < tok.size(); i++ )
	    {

	      // skip undefined phenotypes
	      if ( phe_codes2[i] == 0 ) continue;

	      // skip missing values
	      if ( tok[i] == mis_codes[ phe_codes[i-1] ] ) continue;
	      
	      mType mt = type_codes[ phe_codes[ i-1 ] ];
	      
	      // skip invalid values for numerics (as MT will be registered)
	      
 	      if ( mt == META_INT )
 		{    
 		  int x;
 		  if ( Helper::str2int( tok[i] , x ) )
 		    insert( indiv_id , phe_codes2[i] , x );
 		}
 	      else if ( mt == META_FLOAT )
 		{
 		  double x;
 		  if ( Helper::str2dbl( tok[i] , x ) )
 		    insert( indiv_id , phe_codes2[i] , x );
 		}
 	      else 
 		{
 		  insert( indiv_id , phe_codes2[i] , tok[i] );
 		}


	    }
	  ++inserted;	    
	}
    }
  
  f.close();

  index();
  
  sql.commit();

  plog << "Processed " << inserted << " rows\n";
  
  if ( inserted && GP && GP->has_project_file() ) 
    GP->fIndex.append_to_projectfile( Helper::fullpath( filename ) , "PHE" );
    
  return true;
}