/// =-=-=-=-=-=-=- /// @brief irods::error load_balanced_redirect_for_create_operation( irods::resource_plugin_context& _ctx, const std::string* _opr, const std::string* _curr_host, irods::hierarchy_parser* _out_parser, float* _out_vote ) { // =-=-=-=-=-=-=- // capture the name, time and load lists from the DB std::vector< std::string > names; std::vector< int > loads; std::vector< int > times; irods::error ret = get_load_lists( _ctx, names, loads, times ); if ( !ret.ok() ) { return PASS( ret ); } // =-=-=-=-=-=-=- // retrieve local time in order to check if the load information is up // to date, ie less than MAX_ELAPSE_TIME seconds old int min_load = 100; time_t time_now = 0; time( &time_now ); // =-=-=-=-=-=-=- // iterate over children and find them in the lists bool resc_found = false; irods::resource_ptr selected_resource; irods::resource_child_map::iterator itr = _ctx.child_map().begin(); for ( ; itr != _ctx.child_map().end(); ++itr ) { // =-=-=-=-=-=-=- // cache resc ptr for ease of use irods::resource_ptr resc = itr->second.second; // =-=-=-=-=-=-=- // get the resource name for comparison std::string resc_name; ret = resc->get_property< std::string >( irods::RESOURCE_NAME, resc_name ); if ( !ret.ok() ) { return PASS( ret ); } // =-=-=-=-=-=-=- // scan the list for a match for ( size_t i = 0; i < names.size(); ++i ) { if ( resc_name == names[ i ] ) { if ( loads[ i ] >= 0 && min_load > loads[ i ] && ( time_now - times[ i ] ) < MAX_ELAPSE_TIME ) { resc_found = true; min_load = loads[i]; selected_resource = resc; } } // if match } // for i } // for itr // =-=-=-=-=-=-=- // if we did not find a resource, this is definitely an error if ( !resc_found ) { return ERROR( CHILD_NOT_FOUND, "failed to find child resc in load list" ); } // =-=-=-=-=-=-=- // forward the redirect call to the child for assertion of the whole operation, // there may be more than a leaf beneath us float vote = 0.0; irods::hierarchy_parser parser = ( *_out_parser ); irods::error err = selected_resource->call < const std::string*, const std::string*, irods::hierarchy_parser*, float* > ( _ctx.comm(), irods::RESOURCE_OP_RESOLVE_RESC_HIER, _ctx.fco(), _opr, _curr_host, &parser, &vote ); std::string hier; parser.str( hier ); rodsLog( LOG_DEBUG1, "load_balanced node - hier : [%s], vote %f", hier.c_str(), vote ); if ( !err.ok() ) { irods::log( PASS( err ) ); } // =-=-=-=-=-=-=- // set the out variables ( *_out_parser ) = parser; ( *_out_vote ) = vote; return SUCCESS(); } // load_balanced_redirect_for_create_operation
int main (int argc, char **argv) { int result; guint i; test_t tests[] = { SUCCESS("/xmpp-sasl/normal-auth", NULL, TRUE), SUCCESS("/xmpp-sasl/no-plain", NULL, FALSE), SUCCESS("/xmpp-sasl/only-plain", "PLAIN", TRUE), SUCCESS("/xmpp-sasl/only-digest-md5", "DIGEST-MD5", TRUE), { "/xmpp-sasl/digest-md5-final-data-in-success", "DIGEST-MD5", TRUE, 0, 0, SERVER_PROBLEM_FINAL_DATA_IN_SUCCESS, FALSE, FALSE, "test", "test123", NULL }, FAIL("/xmpp-sasl/no-supported-mechs", "NONSENSE", TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_NO_SUPPORTED_MECHANISMS, SERVER_PROBLEM_NO_PROBLEM), FAIL("/xmpp-sasl/refuse-plain-only", "PLAIN", FALSE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_NO_SUPPORTED_MECHANISMS, SERVER_PROBLEM_NO_PROBLEM), FAIL("/xmpp-sasl/no-sasl-support", NULL, TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_NOT_SUPPORTED, SERVER_PROBLEM_NO_SASL), { "/xmpp-sasl/wrong-username-plain", "PLAIN", TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_FAILURE, SERVER_PROBLEM_INVALID_USERNAME, TRUE, FALSE, "test", "test123" }, { "/xmpp-sasl/wrong-username-md5", "DIGEST-MD5", TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_FAILURE, SERVER_PROBLEM_INVALID_USERNAME, TRUE, FALSE, "test", "test123" }, { "/xmpp-sasl/wrong-password-plain", "PLAIN", TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_FAILURE, SERVER_PROBLEM_INVALID_PASSWORD, FALSE, TRUE, "test", "test123" }, { "/xmpp-sasl/wrong-password-md5", "DIGEST-MD5", TRUE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_FAILURE, SERVER_PROBLEM_INVALID_PASSWORD, FALSE, TRUE, "test", "test123" }, /* Redo the MD5-DIGEST test with a username, password and realm that * happens to generate a \0 byte in the md5 hash of * 'username:realm:password'. This used to trigger a bug in the sasl helper * when calculating the A! part of the response MD5-DIGEST hash */ { "/xmpp-sasl/digest-md5-A1-null-byte", "DIGEST-MD5", TRUE, 0, 0, SERVER_PROBLEM_NO_PROBLEM, FALSE, FALSE, "moose", "something", "cass-x200s" }, /* Redo the MD5-DIGEST test with extra whitespace in the challenge */ { "/xmpp-sasl/digest-md5-spaced-challenge", "DIGEST-MD5", FALSE, 0, 0, SERVER_PROBLEM_SPACE_CHALLENGE, FALSE, FALSE, "moose", "something", "cass-x200s" }, /* Redo the MD5-DIGEST test with extra \ escapes in the challenge */ { "/xmpp-sasl/digest-md5-slash-challenge", "DIGEST-MD5", FALSE, 0, 0, SERVER_PROBLEM_SLASH_CHALLENGE, FALSE, FALSE, "moose", "something", "cass-x200s" }, { "/xmpp-sasl/external-handler-fail", "X-TEST", FALSE, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_FAILURE, SERVER_PROBLEM_INVALID_PASSWORD, FALSE, FALSE, "dave", "daisy daisy", "hal" }, { "/xmpp-sasl/external-handler-succeed", "X-TEST", FALSE, 0, 0, SERVER_PROBLEM_NO_PROBLEM, FALSE, FALSE, "ripley", "open sesame", "mother" }, }; test_init (argc, argv); mainloop = g_main_loop_new (NULL, FALSE); for (i = 0; i < G_N_ELEMENTS (tests); i++) g_test_add_data_func (tests[i].description, &tests[i], run_test); result = g_test_run (); test_deinit (); return result; }
irods::error operator()( rcComm_t* ) { rodsLog( LOG_NOTICE, "mockarchive_resource::post_disconnect_maintenance_operation - [%s]", name_.c_str() ); return SUCCESS(); }
// =-=-=-=-=-=-=- // private - walk the resource map and wire children up to parents error resource_manager::init_child_map( void ) { error result = SUCCESS(); // Iterate over all the resources lookup_table< boost::shared_ptr< resource > >::iterator it; for ( it = resources_.begin(); it != resources_.end(); ++it ) { resource_ptr resc = it->second; // Get the children string and resource name std::string children_string; error ret = resc->get_property<std::string>( RESOURCE_CHILDREN, children_string ); if ( !ret.ok() ) { result = PASSMSG( "init_child_map failed.", ret ); } else { std::string resc_name; error ret = resc->get_property<std::string>( RESOURCE_NAME, resc_name ); if ( !ret.ok() ) { result = PASSMSG( "init_child_map failed.", ret ); } else { // Get the list of children and their contexts from the resource children_parser parser; parser.set_string( children_string ); children_parser::children_map_t children_list; error ret = parser.list( children_list ); if ( !ret.ok() ) { result = PASSMSG( "init_child_map failed.", ret ); } else { // Iterate over all of the children children_parser::children_map_t::const_iterator itr; for ( itr = children_list.begin(); itr != children_list.end(); ++itr ) { std::string child = itr->first; std::string context = itr->second; // Lookup the child resource pointer lookup_table< boost::shared_ptr< resource > >::iterator child_itr = resources_.find( child ); if ( child_itr == resources_.end() ) { std::stringstream msg; msg << "Failed to find child \"" << child << "\" in resources."; result = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); } else { // Add a reference to the child resource pointer and its context to the resource resource_ptr child_resc = child_itr->second; error ret = resc->add_child( child, context, child_resc ); if ( !ret.ok() ) { result = PASSMSG( "init_child_map failed.", ret ); } // set the parent for the child resource child_resc->set_parent( resc ); } } // for itr } // else parse list } // else get name } // else get child string } // for it return result; } // init_child_map
// =-=-=-=-=-=-=- // public - retrieve a resource given a vault path error resource_manager::validate_vault_path( std::string _physical_path, rodsServerHost_t* _svr_host, std::string& _out_path ) { // =-=-=-=-=-=-=- // simple flag to state a resource matching the prop and value is found bool found = false; // =-=-=-=-=-=-=- // quick check on the resource table if ( resources_.empty() ) { return ERROR( SYS_INVALID_INPUT_PARAM, "empty resource table" ); } // =-=-=-=-=-=-=- // quick check on the path that it has something in it if ( _physical_path.empty() ) { return ERROR( SYS_INVALID_INPUT_PARAM, "empty property" ); } // =-=-=-=-=-=-=- // iterate through the map and search for our path lookup_table< resource_ptr >::iterator itr = resources_.begin(); for ( ; !found && itr != resources_.end(); ++itr ) { // =-=-=-=-=-=-=- // get the host pointer from the resource rodsServerHost_t* svr_host = 0; error ret = itr->second->get_property< rodsServerHost_t* >( RESOURCE_HOST, svr_host ); if ( !ret.ok() ) { PASS( ret ); } // =-=-=-=-=-=-=- // if this host matches the incoming host pointer then were good // otherwise continue searching if ( svr_host != _svr_host ) { continue; } // =-=-=-=-=-=-=- // query resource for the property value std::string path; ret = itr->second->get_property<std::string>( RESOURCE_PATH, path ); // =-=-=-=-=-=-=- // if we get a good parameter and do not match non-storage nodes with an empty physical path if ( ret.ok() ) { // =-=-=-=-=-=-=- // compare incoming value and stored value // one may be a subset of the other so compare both ways if ( !path.empty() && ( _physical_path.find( path ) != std::string::npos ) ) { found = true; _out_path = path; } } else { std::stringstream msg; msg << "resource_manager::resolve_from_physical_path - "; msg << "failed to get vault parameter from resource"; msg << ret.code(); irods::log( PASSMSG( msg.str(), ret ) ); } } // for itr // =-=-=-=-=-=-=- // did we find a resource and is the ptr valid? if ( true == found ) { return SUCCESS(); } else { std::stringstream msg; msg << "failed to find resource for path ["; msg << _physical_path; msg << "]"; return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); } } // validate_vault_path
// Read LEGACY_SERVER_CONFIG_FILE and fill server_properties::properties void server_properties::capture_legacy() { error result = SUCCESS(); std::string property; // property setting FILE *fptr; char buf[BUF_LEN]; char *fchar; int len; char *key; char DBKey[MAX_PASSWORD_LEN], DBPassword[MAX_PASSWORD_LEN]; memset( &DBKey, '\0', MAX_PASSWORD_LEN ); memset( &DBPassword, '\0', MAX_PASSWORD_LEN ); std::string cfg_file; error ret = irods::get_full_path_for_config_file( LEGACY_SERVER_CONFIG_FILE, cfg_file ); if ( !ret.ok() ) { THROW( ret.code(), ret.result() ); } if ( !fs::exists( cfg_file ) ) { return; } rodsLog( LOG_ERROR, "server_properties::capture_legacy - use of legacy configuration is deprecated" ); fptr = fopen( cfg_file.c_str(), "r" ); if ( fptr == NULL ) { rodsLog( LOG_DEBUG, "Cannot open LEGACY_SERVER_CONFIG_FILE file %s. errno = %d\n", cfg_file.c_str(), errno ); std::stringstream msg; msg << LEGACY_SERVER_CONFIG_FILE << " file error"; THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() ); } // =-=-=-=-=-=-=- // PAM configuration - init PAM values result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false ); result = config_props_.set<size_t>( PAM_PW_LEN_KW, 20 ); property.assign( "121" ); result = config_props_.set<std::string>( PAM_PW_MIN_TIME_KW, property ); property.assign( "1209600" ); result = config_props_.set<std::string>( PAM_PW_MAX_TIME_KW, property ); // init PAM values std::string initializer[] = { ICAT_HOST_KW, RE_RULESET_KW, RE_FUNCMAPSET_KW, RE_VARIABLEMAPSET_KW, DB_USERNAME_KW, PAM_PW_MIN_TIME_KW, PAM_PW_MAX_TIME_KW, CATALOG_DATABASE_TYPE_KW, KERBEROS_NAME_KW, LOCAL_ZONE_SID_KW }; std::vector<std::string> keys( initializer, initializer + sizeof( initializer ) / sizeof( std::string ) ); buf[BUF_LEN - 1] = '\0'; fchar = fgets( buf, BUF_LEN - 1, fptr ); while ( fchar ) { if ( buf[0] == '#' || buf[0] == '/' ) { buf[0] = '\0'; /* Comment line, ignore */ } /** * Parsing of server configuration settings */ key = strstr( buf, DB_PASSWORD_KW ); if ( key != NULL ) { len = strlen( DB_PASSWORD_KW ); // Store password in temporary string snprintf( DBPassword, sizeof( DBPassword ), "%s", findNextTokenAndTerm( key + len ) ); } // DB_PASSWORD_KW key = strstr( buf, DB_KEY_KW ); if ( key != NULL ) { len = strlen( DB_KEY_KW ); // Store key in temporary string snprintf( DBKey, sizeof( DBKey ), "%s", findNextTokenAndTerm( key + len ) ); } // DB_KEY_KW for ( std::vector<std::string>::iterator it = keys.begin(); it != keys.end(); it++ ) { char * pos = strstr( buf, it->c_str() ); if ( pos != NULL ) { // Set property property.assign( findNextTokenAndTerm( pos + it->size() ) ); // Update properties table result = config_props_.set<std::string>( *it, property ); rodsLog( LOG_DEBUG1, "%s=%s", it->c_str(), property.c_str() ); } } key = strstr( buf, PAM_PW_LEN_KW ); if ( key != NULL ) { len = strlen( PAM_PW_LEN_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<size_t>( PAM_PW_LEN_KW, atoi( property.c_str() ) ); rodsLog( LOG_DEBUG, "%s=%s", PAM_PW_LEN_KW, property.c_str() ); } // PAM_PW_LEN_KW key = strstr( buf, PAM_NO_EXTEND_KW ); if ( key != NULL ) { len = strlen( PAM_NO_EXTEND_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); if ( property == "true" ) { result = config_props_.set<bool>( PAM_NO_EXTEND_KW, true ); } else { result = config_props_.set<bool>( PAM_NO_EXTEND_KW, false ); } rodsLog( LOG_DEBUG, "%s=%s", PAM_NO_EXTEND_KW, property.c_str() ); } // PAM_NO_EXTEND_KW key = strstr( buf, DEF_DIR_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_DIR_MODE_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<int>( DEF_DIR_MODE_KW, strtol( property.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", DEF_DIR_MODE_KW, property.c_str() ); } // DEF_DIR_MODE_KW key = strstr( buf, DEF_FILE_MODE_KW ); if ( key != NULL ) { len = strlen( DEF_FILE_MODE_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<int>( DEF_FILE_MODE_KW, strtol( property.c_str(), 0, 0 ) ); rodsLog( LOG_DEBUG, "%s=%s", DEF_FILE_MODE_KW, property.c_str() ); } // DEF_FILE_MODE_KW key = strstr( buf, KERBEROS_KEYTAB_KW ); if ( key != NULL ) { len = strlen( KERBEROS_KEYTAB_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table result = config_props_.set<std::string>( KERBEROS_KEYTAB_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", KERBEROS_KEYTAB_KW, property.c_str() ); // Now set the appropriate kerberos environment variable setenv( "KRB5_KTNAME", property.c_str(), 1 ); } // KERBEROS_KEYTAB_KW key = strstr( buf, DEFAULT_HASH_SCHEME_KW ); if ( key != NULL ) { len = strlen( DEFAULT_HASH_SCHEME_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); // Update properties table result = config_props_.set<std::string>( DEFAULT_HASH_SCHEME_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", DEFAULT_HASH_SCHEME_KW, property.c_str() ); } // DEFAULT_HASH_SCHEME_KW key = strstr( buf, MATCH_HASH_POLICY_KW ); if ( key != NULL ) { len = strlen( MATCH_HASH_POLICY_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); std::transform( property.begin(), property.end(), property.begin(), ::tolower ); // Update properties table result = config_props_.set<std::string>( MATCH_HASH_POLICY_KW, property ); rodsLog( LOG_DEBUG, "%s=%s", MATCH_HASH_POLICY_KW, property.c_str() ); } // MATCH_HASH_POLICY_KW key = strstr( buf, REMOTE_ZONE_SID_KW ); if ( key != NULL ) { len = strlen( REMOTE_ZONE_SID_KW ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); // Update properties table std::vector<std::string> rem_sids; std::vector<std::string>::iterator sid_itr; if ( config_props_.has_entry( REMOTE_ZONE_SID_KW ) ) { result = config_props_.get< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids ); // do not want duplicate entries sid_itr = std::find( rem_sids.begin(), rem_sids.end(), property ); } if ( sid_itr == rem_sids.end() ) { rem_sids.push_back( property ); result = config_props_.set< std::vector< std::string > >( REMOTE_ZONE_SID_KW, rem_sids ); } rodsLog( LOG_DEBUG, "%s=%s", REMOTE_ZONE_SID_KW, property.c_str() ); } // REMOTE_ZONE_SID_KW key = strstr( buf, AGENT_KEY_KW.c_str() ); if ( key != NULL ) { len = strlen( AGENT_KEY_KW.c_str() ); // Set property property.assign( findNextTokenAndTerm( key + len ) ); if ( 32 != property.size() ) { rodsLog( LOG_ERROR, "%s field in %s must be 32 characters in length (currently %d characters in length).", AGENT_KEY_KW.c_str(), LEGACY_SERVER_CONFIG_FILE, property.size() ); fclose( fptr ); std::stringstream msg; msg << LEGACY_SERVER_CONFIG_FILE << " file error"; THROW( SYS_CONFIG_FILE_ERR, msg.str().c_str() ); } // Update properties table result = config_props_.set<std::string>( AGENT_KEY_KW, property ); } // AGENT_KEY_KW fchar = fgets( buf, BUF_LEN - 1, fptr ); } // for ( ; fchar != '\0'; ) fclose( fptr ); // unscramble password if ( strlen( DBKey ) > 0 && strlen( DBPassword ) > 0 ) { char sPassword[MAX_PASSWORD_LEN + 10]; strncpy( sPassword, DBPassword, MAX_PASSWORD_LEN ); obfDecodeByKey( sPassword, DBKey, DBPassword ); memset( sPassword, 0, MAX_PASSWORD_LEN ); } // store password and key in server properties property.assign( DBPassword ); result = config_props_.set<std::string>( DB_PASSWORD_KW, property ); rodsLog( LOG_DEBUG1, "%s=%s", DB_PASSWORD_KW, property.c_str() ); property.assign( DBKey ); result = config_props_.set<std::string>( DB_KEY_KW, property ); rodsLog( LOG_DEBUG1, "%s=%s", DB_KEY_KW, property.c_str() ); // add expected zone_name, zone_user, zone_port, zone_auth_scheme // as these are now read from server_properties rodsEnv env; int status = getRodsEnv( &env ); if ( status < 0 ) { THROW( status, "failure in getRodsEnv" ); } result = config_props_.set<std::string>( irods::CFG_ZONE_NAME_KW, env.rodsZone ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<std::string>( irods::CFG_ZONE_USER, env.rodsUserName ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<std::string>( irods::CFG_ZONE_AUTH_SCHEME, env.rodsAuthScheme ); if ( !result.ok() ) { irods::log( PASS( result ) ); } result = config_props_.set<int>( irods::CFG_ZONE_PORT, env.rodsPort ); if ( !result.ok() ) { irods::log( PASS( result ) ); } if ( 0 != env.xmsgPort ) { result = config_props_.set<int>( irods::CFG_XMSG_PORT, env.xmsgPort ); if ( !result.ok() ) { irods::log( PASS( result ) ); } } } // server_properties::capture()
// =-=-=-=-=-=-=- // public - take results from genQuery, extract values and create resources error resource_manager::process_init_results( genQueryOut_t* _result ) { // =-=-=-=-=-=-=- // extract results from query if ( !_result ) { return ERROR( SYS_INVALID_INPUT_PARAM, "_result parameter is null" ); } // =-=-=-=-=-=-=- // values to extract from query sqlResult_t *rescId = 0, *rescName = 0, *zoneName = 0, *rescType = 0, *rescClass = 0; sqlResult_t *rescLoc = 0, *rescVaultPath = 0, *freeSpace = 0, *rescInfo = 0; sqlResult_t *rescComments = 0, *rescCreate = 0, *rescModify = 0, *rescStatus = 0; sqlResult_t *rescChildren = 0, *rescContext = 0, *rescParent = 0, *rescObjCount = 0; // =-=-=-=-=-=-=- // extract results from query if ( ( rescId = getSqlResultByInx( _result, COL_R_RESC_ID ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_ID failed" ); } if ( ( rescName = getSqlResultByInx( _result, COL_R_RESC_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_NAME failed" ); } if ( ( zoneName = getSqlResultByInx( _result, COL_R_ZONE_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_ZONE_NAME failed" ); } if ( ( rescType = getSqlResultByInx( _result, COL_R_TYPE_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_TYPE_NAME failed" ); } if ( ( rescClass = getSqlResultByInx( _result, COL_R_CLASS_NAME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CLASS_NAME failed" ); } if ( ( rescLoc = getSqlResultByInx( _result, COL_R_LOC ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_LOC failed" ); } if ( ( rescVaultPath = getSqlResultByInx( _result, COL_R_VAULT_PATH ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_VAULT_PATH failed" ); } if ( ( freeSpace = getSqlResultByInx( _result, COL_R_FREE_SPACE ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_FREE_SPACE failed" ); } if ( ( rescInfo = getSqlResultByInx( _result, COL_R_RESC_INFO ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_INFO failed" ); } if ( ( rescComments = getSqlResultByInx( _result, COL_R_RESC_COMMENT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_COMMENT failed" ); } if ( ( rescCreate = getSqlResultByInx( _result, COL_R_CREATE_TIME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CREATE_TIME failed" ); } if ( ( rescModify = getSqlResultByInx( _result, COL_R_MODIFY_TIME ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_MODIFY_TIME failed" ); } if ( ( rescStatus = getSqlResultByInx( _result, COL_R_RESC_STATUS ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_STATUS failed" ); } if ( ( rescChildren = getSqlResultByInx( _result, COL_R_RESC_CHILDREN ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CHILDREN failed" ); } if ( ( rescContext = getSqlResultByInx( _result, COL_R_RESC_CONTEXT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CONTEXT failed" ); } if ( ( rescParent = getSqlResultByInx( _result, COL_R_RESC_PARENT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_PARENT failed" ); } if ( ( rescObjCount = getSqlResultByInx( _result, COL_R_RESC_OBJCOUNT ) ) == NULL ) { return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_OBJCOUNT failed" ); } // =-=-=-=-=-=-=- // iterate through the rows, initialize a resource for each entry for ( int i = 0; i < _result->rowCnt; ++i ) { // =-=-=-=-=-=-=- // extract row values std::string tmpRescId = &rescId->value[ rescId->len * i ]; std::string tmpRescLoc = &rescLoc->value[ rescLoc->len * i ]; std::string tmpRescName = &rescName->value[ rescName->len * i ]; std::string tmpZoneName = &zoneName->value[ zoneName->len * i ]; std::string tmpRescType = &rescType->value[ rescType->len * i ]; std::string tmpRescInfo = &rescInfo->value[ rescInfo->len * i ]; std::string tmpFreeSpace = &freeSpace->value[ freeSpace->len * i ]; std::string tmpRescClass = &rescClass->value[ rescClass->len * i ]; std::string tmpRescCreate = &rescCreate->value[ rescCreate->len * i ]; std::string tmpRescModify = &rescModify->value[ rescModify->len * i ]; std::string tmpRescStatus = &rescStatus->value[ rescStatus->len * i ]; std::string tmpRescComments = &rescComments->value[ rescComments->len * i ]; std::string tmpRescVaultPath = &rescVaultPath->value[ rescVaultPath->len * i ]; std::string tmpRescChildren = &rescChildren->value[ rescChildren->len * i ]; std::string tmpRescContext = &rescContext->value[ rescContext->len * i ]; std::string tmpRescParent = &rescParent->value[ rescParent->len * i ]; std::string tmpRescObjCount = &rescObjCount->value[ rescObjCount->len * i ]; // =-=-=-=-=-=-=- // create the resource and add properties for column values resource_ptr resc; error ret = load_resource_plugin( resc, tmpRescType, tmpRescName, tmpRescContext ); if ( !ret.ok() ) { return PASSMSG( "Failed to load Resource Plugin", ret ); } // =-=-=-=-=-=-=- // resolve the host name into a rods server host structure if ( tmpRescLoc != irods::EMPTY_RESC_HOST ) { rodsHostAddr_t addr; rstrcpy( addr.hostAddr, const_cast<char*>( tmpRescLoc.c_str() ), LONG_NAME_LEN ); rstrcpy( addr.zoneName, const_cast<char*>( tmpZoneName.c_str() ), NAME_LEN ); rodsServerHost_t* tmpRodsServerHost = 0; if ( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) { rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s", addr.hostAddr ); } resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost ); } else { resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, 0 ); } resc->set_property<long>( RESOURCE_ID, strtoll( tmpRescId.c_str(), 0, 0 ) ); resc->set_property<long>( RESOURCE_FREESPACE, strtoll( tmpFreeSpace.c_str(), 0, 0 ) ); resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT ); resc->set_property<std::string>( RESOURCE_ZONE, tmpZoneName ); resc->set_property<std::string>( RESOURCE_NAME, tmpRescName ); resc->set_property<std::string>( RESOURCE_LOCATION, tmpRescLoc ); resc->set_property<std::string>( RESOURCE_TYPE, tmpRescType ); resc->set_property<std::string>( RESOURCE_CLASS, tmpRescClass ); resc->set_property<std::string>( RESOURCE_PATH, tmpRescVaultPath ); resc->set_property<std::string>( RESOURCE_INFO, tmpRescInfo ); resc->set_property<std::string>( RESOURCE_COMMENTS, tmpRescComments ); resc->set_property<std::string>( RESOURCE_CREATE_TS, tmpRescCreate ); resc->set_property<std::string>( RESOURCE_MODIFY_TS, tmpRescModify ); resc->set_property<std::string>( RESOURCE_CHILDREN, tmpRescChildren ); resc->set_property<std::string>( RESOURCE_PARENT, tmpRescParent ); resc->set_property<std::string>( RESOURCE_CONTEXT, tmpRescContext ); resc->set_property<std::string>( RESOURCE_OBJCOUNT, tmpRescObjCount ); if ( tmpRescStatus == std::string( RESC_DOWN ) ) { resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_DOWN ); } else { resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP ); } // =-=-=-=-=-=-=- // add new resource to the map resources_[ tmpRescName ] = resc; } // for i return SUCCESS(); } // process_init_results
error SHA256Strategy::update( const std::string& data, boost::any& _context ) const { SHA256_Update( boost::any_cast<SHA256_CTX>( &_context ), data.c_str(), data.size() ); return SUCCESS(); }
int main( int argc, char **argv ) { unicap_handle_t handle; unicap_device_t device; unicap_format_t format_spec; unicap_format_t format; unicap_data_buffer_t buffer; unicap_data_buffer_t *returned_buffer; int i; SDL_Surface *screen; SDL_Overlay *overlay; int quit=0; /* Enumerate available video capture devices */ printf( "select video device\n" ); for( i = 0; SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ); i++ ) { printf( "%i: %s\n", i, device.identifier ); } if( --i > 0 ) { printf( "Select video capture device: " ); scanf( "%d", &i ); } if( !SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ) ) { fprintf( stderr, "Failed to get info for device '%s'\n", device.identifier ); exit( 1 ); } /* Acquire a handle to selected device */ if( !SUCCESS( unicap_open( &handle, &device ) ) ) { fprintf( stderr, "Failed to open device: %s\n", device.identifier ); exit( 1 ); } printf( "Opened video capture device: %s\n", device.identifier ); unicap_void_format( &format_spec ); /* Get the list of video formats */ for( i = 0; SUCCESS( unicap_enumerate_formats( handle, NULL, &format, i ) ); i++ ) { printf( "%d: %s\n", i, format.identifier ); } if( --i > 0 ) { printf( "Select video format: " ); scanf( "%d", &i ); } if( !SUCCESS( unicap_enumerate_formats( handle, &format_spec, &format, i ) ) ) { fprintf( stderr, "Failed to get video format %d\n", i ); exit( 1 ); } /* If a video format has more than one size, ask for which size to use */ if( format.size_count ) { for( i = 0; i < format.size_count; i++ ) { printf( "%d: %dx%d\n", i, format.sizes[i].width, format.sizes[i].height ); } do { printf( "Select video format size: " ); scanf( "%d", &i ); }while( ( i < 0 ) && ( i > format.size_count ) ); format.size.width = format.sizes[i].width; format.size.height = format.sizes[i].height; } /* Set this video format */ if( !SUCCESS( unicap_set_format( handle, &format ) ) ) { fprintf( stderr, "Failed to set video format\n" ); exit( 1 ); } /* Initialize the image buffer */ memset( &buffer, 0x0, sizeof( unicap_data_buffer_t ) ); /** Init SDL & SDL_Overlay **/ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); screen = SDL_SetVideoMode( format.size.width, format.size.height, 32, SDL_HWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError()); exit(1); } overlay = SDL_CreateYUVOverlay( format.size.width, format.size.height, format.fourcc, screen ); if( overlay == NULL ) { fprintf( stderr, "Unable to create overlay: %s\n", SDL_GetError() ); exit( 1 ); } /* Pass the pointer to the overlay to the unicap data buffer. */ buffer.data = overlay->pixels[0]; buffer.buffer_size = format.size.width * format.size.height * format.bpp / 8; /* Start the capture process on the device */ if( !SUCCESS( unicap_start_capture( handle ) ) ) { fprintf( stderr, "Failed to start capture on device: %s\n", device.identifier ); exit( 1 ); } while( !quit ) { SDL_Rect rect; SDL_Event event; rect.x = rect.y = 0; rect.w = format.size.width; rect.h = format.size.height; /* Queue the buffer The buffer now gets filled with image data by the capture device */ if( !SUCCESS( unicap_queue_buffer( handle, &buffer ) ) ) { fprintf( stderr, "Failed to queue a buffer on device: %s\n", device.identifier ); exit( 1 ); } /* Wait until the image buffer is ready */ if( !SUCCESS( unicap_wait_buffer( handle, &returned_buffer ) ) ) { fprintf( stderr, "Failed to wait for buffer on device: %s\n", device.identifier ); } /* Display the video data */ SDL_UnlockYUVOverlay( overlay ); SDL_DisplayYUVOverlay( overlay, &rect ); SDL_LockYUVOverlay(overlay); while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { printf( "Quit\n" ); quit=1; } } } /* Stop the device */ if( !SUCCESS( unicap_stop_capture( handle ) ) ) { fprintf( stderr, "Failed to stop capture on device: %s\n", device.identifier ); } /* Close the device This invalidates the handle */ if( !SUCCESS( unicap_close( handle ) ) ) { fprintf( stderr, "Failed to close the device: %s\n", device.identifier ); } SDL_Quit(); return 0; }
PERROR CGame::outputWrite( int key ) { PERROR error = errorSuccess; if (key == DOWN_KEY) { if (m_outputWriteRegion > 0) { m_outputWriteRegion--; } } if (key == UP_KEY) { if (m_outputRegion[m_outputWriteRegion+1].activeMask != 0) { m_outputWriteRegion++; } } { const OUTPUT_REGION *region = &m_outputRegion[m_outputWriteRegion]; if (key == SELECT_KEY) { // // Check if we need to perform a bank switch for this region. // and do that now for all the testing to be done upon it. // if (region->bankSwitch != NO_BANK_SWITCH) { error = region->bankSwitch( (void *) this ); } { UINT8 outData; // // If we're wanting to write active(on) then just use the mask. // else use the clear of the mask. This is a toggle. // if (m_outputWriteRegionOn) { errorCustom->description = "OK: Active"; outData = region->invertMask ^ region->activeMask; m_outputWriteRegionOn = false; } else { errorCustom->description = "OK: Inactive"; outData = region->invertMask; m_outputWriteRegionOn = true; } error = m_cpu->memoryWrite( region->address, outData ); } } else { STRING_IO_SUMMARY(errorCustom, region->location, region->activeMask, region->description); } } if (SUCCESS(error)) { error = errorCustom; } return error; }
error SHA256Strategy::init( boost::any& _context ) const { _context = SHA256_CTX(); SHA256_Init( boost::any_cast<SHA256_CTX>( &_context ) ); return SUCCESS(); }
PERROR CGame::ramWriteRead( int key ) { PERROR error = errorSuccess; if (key == SELECT_KEY) { const RAM_REGION *region = &m_ramRegion[m_RamWriteReadRegion]; UINT8 expData4[4] = {0x11, 0x22, 0x44, 0x88}; UINT8 expData1[4] = {0x55, 0xAA, 0x55, 0xAA}; UINT8 *expData = (UINT8*) NULL;; UINT8 recData[4] = {0}; // // This is more complicated than this simple test // as it needs the bit shift done to be correct. // if (region->mask < 4) { expData = expData1; } else { expData = expData4; } errorCustom->description = "OK:"; // // Check if we need to perform a bank switch for this region. // and do that now for all the testing to be done upon it. // if (region->bankSwitch != NO_BANK_SWITCH) { error = region->bankSwitch( (void *) this ); } // // Write the first 4 bytes, maximum. // if (SUCCESS(error)) { for (UINT16 address = 0 ; address < ARRAYSIZE(recData) ; address++) { error = m_cpu->memoryWrite( (address + region->start), expData[address] ); if (FAILED(error)) { break; } } } if (SUCCESS(error)) { // // Read the first 4 bytes, maximum. // for (UINT16 address = 0 ; address < ARRAYSIZE(recData) ; address++) { error = m_cpu->memoryRead( (address + region->start), &recData[address] ); if (FAILED(error)) { break; } STRING_UINT8_HEX(errorCustom->description, (recData[address] & region->mask) ); error = errorCustom; } } } else { error = onRamKeyMove(key); } return error; }
int test_main(void) { /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?logsort=rev&rev=210&view=markup */ test_salsa20(HL("80000000 00000000 00000000 00000000"), H("00000000 00000000"), HL("00000000 00000000"), H("4DFA5E48 1DA23EA0")); test_salsa20(HL("00000000 00000000 00000000 00000000"), H("80000000 00000000"), HL("00000000 00000000"), H("B66C1E44 46DD9557")); test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD"), H("0D74DB42A91077DE"), HL("00000000 00000000"), H("05E1E7BE B697D999")); test_salsa20(HL("80000000 00000000 00000000 00000000" "00000000 00000000 00000000 00000000"), H("00000000 00000000"), HL("00000000 00000000"), H("E3BE8FDD 8BECA2E3")); test_salsa20(HL("00000000 00000000 00000000 00000000" "00000000 00000000 00000000 00000000"), H("80000000 00000000"), HL("00000000 00000000"), H("2ABA3DC45B494700")); test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD" "3083D6297CCF2275C81B6EC11467BA0D"), H("0D74DB42A91077DE"), HL("00000000 00000000"), H("F5FAD53F 79F9DF58")); test_salsa20_stream(HL("80000000000000000000000000000000"), H("00000000 00000000"), H("4DFA5E481DA23EA09A31022050859936" "DA52FCEE218005164F267CB65F5CFD7F" "2B4F97E0FF16924A52DF269515110A07" "F9E460BC65EF95DA58F740B7D1DBB0AA" "DA9C1581F429E0A00F7D67E23B730676" "783B262E8EB43A25F55FB90B3E753AEF" "8C6713EC66C51881111593CCB3E8CB8F" "8DE124080501EEEB389C4BCB6977CF95" "7D5789631EB4554400E1E025935DFA7B" "3E9039D61BDC58A8697D36815BF1985C" "EFDF7AE112E5BB81E37ECF0616CE7147" "FC08A93A367E08631F23C03B00A8DA2F" "B375703739DACED4DD4059FD71C3C47F" "C2F9939670FAD4A46066ADCC6A564578" "3308B90FFB72BE04A6B147CBE38CC0C3" "B9267C296A92A7C69873F9F263BE9703"), H("F7A274D268316790A67EC058F45C0F2A" "067A99FCDE6236C0CEF8E056349FE54C" "5F13AC74D2539570FD34FEAB06C57205" "3949B59585742181A5A760223AFA22D4")); test_salsa20_stream(HL("48494A4B4C4D4E4F5051525354555657" "58595A5B5C5D5E5F6061626364656667"), H("0000000000000000"), H("53AD3698A011F779AD71030F3EFBEBA0" "A7EE3C55789681B1591EF33A7BE521ED" "68FC36E58F53FFD6E1369B00E390E973" "F656ACB097E0D603BE59A0B8F7975B98" "A04698274C6AC6EC03F66ED3F94C08B7" "9FFDBF2A1610E6F5814905E73AD6D0D2" "8164EEB8450D8ED0BB4B644761B43512" "52DD5DDF00C31E3DABA0BC17691CCFDC" "B826C7F071E796D34E3BFFB3C96E76A1" "209388392806947C7F19B86D379FA3AE" "DFCD19EBF49803DACC6E577E5B97B0F6" "D2036B6624D8196C96FCF02C865D30C1" "B505D41E2C207FA1C0A0E93413DDCFFC" "9BECA8030AFFAC2466E56482DA0EF428" "E63880B5021D3051F18679505A2B9D4F" "9B2C5A2D271D276DE3F51DBEBA934436"), H("7849651A820B1CDFE36D5D6632716534" "E0635EDEFD538122D80870B60FB055DB" "637C7CA2B78B116F83AFF46E40F8F71D" "4CD6D2E1B750D5E011D1DF2E80F7210A")); SUCCESS(); }
/// =-=-=-=-=-=-=- /// @brief irods::error load_balanced_redirect_for_open_operation( irods::resource_plugin_context& _ctx, const std::string* _opr, const std::string* _curr_host, irods::hierarchy_parser* _out_parser, float* _out_vote ) { // =-=-=-=-=-=-=- // data struct to hold parser and vote from the search std::map< float, irods::hierarchy_parser > result_map; // =-=-=-=-=-=-=- // iterate over all the children and pick the highest vote irods::resource_child_map::iterator itr = _ctx.child_map().begin(); for ( ; itr != _ctx.child_map().end(); ++itr ) { // =-=-=-=-=-=-=- // cache resc ptr for ease of use irods::resource_ptr resc = itr->second.second; // =-=-=-=-=-=-=- // temp results from open redirect call - init parser with incoming // hier parser float vote = 0.0; irods::hierarchy_parser parser = ( *_out_parser ); // =-=-=-=-=-=-=- // forward the redirect call to the child for assertion of the whole operation, // there may be more than a leaf beneath us irods::error err = resc->call < const std::string*, const std::string*, irods::hierarchy_parser*, float* > ( _ctx.comm(), irods::RESOURCE_OP_RESOLVE_RESC_HIER, _ctx.fco(), _opr, _curr_host, &parser, &vote ); std::string hier; parser.str( hier ); rodsLog( LOG_DEBUG1, "load_balanced node - hier : [%s], vote %f", hier.c_str(), vote ); if ( !err.ok() ) { irods::log( PASS( err ) ); } else { result_map[ vote ] = parser; } } // for // =-=-=-=-=-=-=- // now that we have collected all of the results the map // will have put the largest one at the end of the map // so grab that one and return the result if it is non zero float high_vote = result_map.rbegin()->first; if ( high_vote > 0.0 ) { ( *_out_parser ) = result_map.rbegin()->second; ( *_out_vote ) = high_vote; return SUCCESS(); } else { return ERROR( -1, "no valid data object found to open" ); } } // load_balanced_redirect_for_open_operation
int main (int argc, char *argv []) { unicap_handle_t handle; unicap_device_t device; unicap_format_t src_format; unicap_format_t dest_format; unicap_data_buffer_t src_buffer; unicap_data_buffer_t dest_buffer; unicap_data_buffer_t *returned_buffer; if (argc != 4) { fprintf (stderr, "Usage: sender <hostname> <camera name> " "<interface>\n"); exit (1); } // Initialise 0MQ infrastructure // 1. Set error handler function (to ignore disconnected receivers) zmq::set_error_handler (error_handler); // 2. Initialise basic infrastructure for 2 threads zmq::dispatcher_t dispatcher (2); // 3. Initialise local locator (to connect to global locator) zmq::locator_t locator (argv [1]); // 4. Start one working thread (to send data to receivers) zmq::poll_thread_t *pt = zmq::poll_thread_t::create (&dispatcher); // 5. Register one API thread (the application thread - the one that // is being executed at the moment) zmq::api_thread_t *api = zmq::api_thread_t::create (&dispatcher, &locator); // 6. Define an entry point for the messages. The name of the entry point // is user-defined ("camera name"). Specify that working thread "pt" // will be used to listen to new connections being created as well as // to send frames to existing connections. int e_id = api->create_exchange (argv [2], zmq::scope_global, argv [3], pt, 1, &pt); // Open first available video capture device if (!SUCCESS (unicap_enumerate_devices (NULL, &device, 0))) { fprintf (stderr, "Could not enumerate devices\n"); exit (1); } if (!SUCCESS (unicap_open (&handle, &device))) { fprintf (stderr, "Failed to open device: %s\n", device.identifier); exit (1); } printf( "Opened video capture device: %s\n", device.identifier ); // Find a suitable video format that we can convert to RGB24 bool conversion_found = false; int index = 0; while (SUCCESS (unicap_enumerate_formats (handle, NULL, &src_format, index))) { printf ("Trying video format: %s\n", src_format.identifier); if (ucil_conversion_supported (FOURCC ('R', 'G', 'B', '3'), src_format.fourcc)) { conversion_found = true; break; } index++; } if (!conversion_found) { fprintf (stderr, "Could not find a suitable video format\n"); exit (1); } src_format.buffer_type = UNICAP_BUFFER_TYPE_USER; if (!SUCCESS (unicap_set_format (handle, &src_format))) { fprintf (stderr, "Failed to set video format\n"); exit (1); } printf ("Using video format: %s [%dx%d]\n", src_format.identifier, src_format.size.width, src_format.size.height); // Clone destination format with equal dimensions, but RGB24 colorspace unicap_copy_format (&dest_format, &src_format); strcpy (dest_format.identifier, "RGB 24bpp"); dest_format.fourcc = FOURCC ('R', 'G', 'B', '3'); dest_format.bpp = 24; dest_format.buffer_size = dest_format.size.width * dest_format.size.height * 3; // Initialise image buffers memset (&src_buffer, 0, sizeof (unicap_data_buffer_t)); src_buffer.data = (unsigned char *)malloc (src_format.buffer_size); src_buffer.buffer_size = src_format.buffer_size; memset (&dest_buffer, 0, sizeof (unicap_data_buffer_t)); dest_buffer.data = (unsigned char *)malloc (dest_format.buffer_size); dest_buffer.buffer_size = dest_format.buffer_size; dest_buffer.format = dest_format; // Start video capture if (!SUCCESS (unicap_start_capture (handle))) { fprintf (stderr, "Failed to start capture on device: %s\n", device.identifier); exit (1); } // Loop, sending video to defined exchange while (1) { // Queue buffer for video capture if (!SUCCESS (unicap_queue_buffer (handle, &src_buffer))) { fprintf (stderr, "Failed to queue a buffer on device: %s\n", device.identifier); exit (1); } // Wait until buffer is ready if (!SUCCESS (unicap_wait_buffer (handle, &returned_buffer))) { fprintf (stderr, "Failed to wait for buffer on device: %s\n", device.identifier); exit (1); } // Convert colorspace if (!SUCCESS (ucil_convert_buffer (&dest_buffer, &src_buffer))) { // TODO: This fails sometimes for unknown reasons, // just skip the frame for now fprintf (stderr, "Failed to convert video buffer\n"); } // Create ZMQ message zmq::message_t msg (dest_format.buffer_size + (2 * sizeof (uint32_t))); unsigned char *data = (unsigned char *)msg.data(); // Image width in pixels zmq::put_uint32 (data, (uint32_t)dest_format.size.width); data += sizeof (uint32_t); // Image height in pixels zmq::put_uint32 (data, (uint32_t)dest_format.size.height); data += sizeof (uint32_t); // RGB24 image data memcpy (data, dest_buffer.data, dest_format.buffer_size); // Send message api->send (e_id, msg); } return 0; }
//-------------------------------------------------------------------- // If a 24 bit video format is founded this is the preferred one, if not, the first // returned by unicap is selected. // // Then it tries to set the desired width and height, if these fails, tries find the // nearest size or to set the default width and height. // // On V4L devices 24 bit format is always BGR, so it needs conversion. // On some V4L devices using non-default width/heigth it reports BGR but returns RGB. // ffmpeg color conversion void ofUCUtils::set_format(int w, int h) { if(!deviceReady) return; d_width=w; d_height=h; unicap_format_t formats[MAX_FORMATS]; int format_count; unicap_status_t status = STATUS_SUCCESS; int rgb24 = -1; ofLog(OF_LOG_NOTICE,"ofUCUtils : Available formats for this device:"); for (format_count = 0; SUCCESS (status) && (format_count < MAX_FORMATS); format_count++) { status = unicap_enumerate_formats (handle, NULL, &formats[format_count], format_count); if (SUCCESS (status)) { if (formats[format_count].bpp == 8) { rgb24 = format_count; } ofLog(OF_LOG_NOTICE, "ofUCUtils : %d: %s, min size: %dx%d, max size:%dx%d, default size: %dx%d", format_count, formats[format_count].identifier, formats[format_count].min_size.width, formats[format_count].min_size.height, formats[format_count].max_size.width, formats[format_count].max_size.height, formats[format_count].size.width, formats[format_count].size.height); ofLog(OF_LOG_VERBOSE,"ofUCUtils: available sizes for this format:"); for(int i=0; i<formats[format_count].size_count;i++){ ofLog(OF_LOG_VERBOSE," %dx%d",formats[format_count].sizes[i].width,formats[format_count].sizes[i].height); } } } if (format_count > 0) { int selected_format = 0; if (rgb24 != -1) selected_format = rgb24; else{ for(selected_format=0;selected_format<format_count;selected_format++){ format = formats[selected_format]; if(fourcc_to_pix_fmt(format.fourcc)!=-1) break; } } format = formats[selected_format]; src_pix_fmt=fourcc_to_pix_fmt(format.fourcc); if( (PixelFormat)src_pix_fmt==-1){ ofLog(OF_LOG_ERROR,"ofUCUtils : Format not suported\n"); return; } bool exactMatch = false; int sizeDiff = 99999999; int mostAproxSize = -1; for(int i=0; i<format.size_count;i++){ if(format.sizes[i].width == w && format.sizes[i].height==h){ exactMatch=true; format.size.width = format.sizes[i].width; format.size.height = format.sizes[i].height; break; }else{ if(abs(format.sizes[i].width-w)+abs(format.sizes[i].height-h)<sizeDiff){ sizeDiff=abs(format.sizes[i].width-w)+abs(format.sizes[i].height-h); mostAproxSize=i; } } } if(!exactMatch && mostAproxSize!=-1){ format.size.width = format.sizes[mostAproxSize].width; format.size.height = format.sizes[mostAproxSize].height; ofLog(OF_LOG_WARNING, "ofUCUtils : Can't set video format %s, with size %dx%d, will use %dx%d", format.identifier, w, h, format.size.width, format.size.height); }else if(format.size_count==0){ int defaultFormatWidth = format.size.width; int defaultFormatHeight = format.size.height; format.size.width = w; format.size.height = h; ofLog(OF_LOG_WARNING, "ofUCUtils : Can't recognize supported video sizes for %s, trying with requested size: %i,%i", format.identifier, format.size.width, format.size.height); if ( !SUCCESS ( unicap_set_format (handle, &format) ) ) { format.size.width = defaultFormatWidth; format.size.height = defaultFormatHeight; ofLog(OF_LOG_WARNING, "ofUCUtils : Can't set requested size, trying with format defaults: %i,%i", defaultFormatWidth, defaultFormatHeight); }else{ exactMatch=true; //if we can set the requested size -> exactMatch } ofLog(OF_LOG_WARNING, "ofUCUtils : If this doesn't work try using the reported default size in initGrabber:", defaultFormatWidth, defaultFormatHeight); } if ( !SUCCESS ( unicap_set_format (handle, &format) ) ) { ofLog(OF_LOG_ERROR, "ofUCUtils : Failed to set alternative video format!"); return; } ofLog(OF_LOG_NOTICE,"ofUCUtils : Selected format: %s, with size %dx%d\n", format.identifier, format.size.width, format.size.height); if((PixelFormat)src_pix_fmt!=PIX_FMT_RGB24 || !exactMatch){ doConversion = true; src=new AVPicture; avpicture_alloc(src, (PixelFormat)src_pix_fmt,format.size.width,format.size.height); dst=new AVPicture; avpicture_alloc(dst,PIX_FMT_RGB24,d_width,d_height); toRGB_convert_ctx = sws_getContext( format.size.width, format.size.height, (PixelFormat)src_pix_fmt, d_width, d_height, PIX_FMT_RGB24, VIDEOGRABBER_RESIZE_FLAGS, NULL, NULL, NULL); ofLog(OF_LOG_NOTICE,"ofUCUtils: Converting to RGB24 (%i,%i)\n",w,h); pixels=new unsigned char[d_width*d_height*3]; } if( !SUCCESS( unicap_get_format( handle, &format ) ) ) { ofLog(OF_LOG_ERROR, "can't get format" ); return; } format.buffer_type = UNICAP_BUFFER_TYPE_SYSTEM; if( !SUCCESS( unicap_set_format( handle, &format ) ) ) { ofLog(OF_LOG_WARNING, "ofUCUtils: Failed to activate SYSTEM_BUFFERS" ); } } }
/*******************************************************************-o-****** * test_etime * * Returns: * Number of failures. * * Test of LCD Engine ID and Time List. */ int test_etime(void) { int rval = SNMPERR_SUCCESS, failcount = 0; u_int etime, eboot; /* * ------------------------------------ -o- */ OUTPUT("Query of empty list, two set actions."); rval = ISENGINEKNOWN((const u_char *) "A", 1); if (rval == TRUE) { FAILED(SNMPERR_GENERR, "Query of empty list returned TRUE.") } rval = set_enginetime((const u_char *) "BB", 2, 2, 20, TRUE); FAILED(rval, "set_enginetime()"); rval = set_enginetime((const u_char *) "CCC", 3, 31, 90127, TRUE); FAILED(rval, "set_enginetime()"); SUCCESS("Check of empty list, and two additions."); /* * ------------------------------------ -o- */ OUTPUT("Add entries using macros, test for existence with macros."); rval = ENSURE_ENGINE_RECORD((const u_char *) "DDDD", 4); FAILED(rval, "ENSURE_ENGINE_RECORD()"); rval = MAKENEW_ENGINE_RECORD((const u_char *) "EEEEE", 5); if (rval == SNMPERR_SUCCESS) { FAILED(rval, "MAKENEW_ENGINE_RECORD returned success for " "missing record."); } rval = MAKENEW_ENGINE_RECORD((const u_char *) "BB", 2); FAILED(rval, "MAKENEW_ENGINE_RECORD()."); SUCCESS ("Added entries with macros, tested for existence with macros."); /* * ------------------------------------ -o- */ OUTPUT("Dump the list and then sleep."); #ifdef NETSNMP_ENABLE_TESTING_CODE dump_etimelist(); #endif fprintf(stdout, "# Sleeping for %d second%s... ", sleeptime, (sleeptime == 1) ? "" : "s"); sleep(sleeptime); /* * ------------------------------------ -o- */ OUTPUT ("Retrieve data from real/stubbed records, update real/stubbed."); rval = get_enginetime((const u_char *) "BB", 2, &eboot, &etime, TRUE); FAILED(rval, "get_enginetime()."); fprintf(stdout, "# BB = <%d,%d>\n", eboot, etime); if ((etime < 20) || (eboot < 2)) { FAILED(SNMPERR_GENERR, "get_enginetime() returned bad values. (1)"); } rval = get_enginetime((const u_char *) "DDDD", 4, &eboot, &etime, FALSE); FAILED(rval, "get_enginetime()."); fprintf(stdout, "# DDDD = <%d,%d>\n", eboot, etime); if ((etime < sleeptime) || (eboot != 0)) { FAILED(SNMPERR_GENERR, "get_enginetime() returned bad values. (2)"); } rval = set_enginetime((const u_char *) "CCC", 3, 234, 10000, TRUE); FAILED(rval, "set_enginetime()."); rval = set_enginetime((const u_char *) "EEEEE", 5, 9876, 55555, TRUE); FAILED(rval, "set_enginetime()."); SUCCESS("Retrieval and updates."); /* * ------------------------------------ -o- */ OUTPUT("Sleep again, then dump the list one last time."); fprintf(stdout, "# Sleeping for %d second%s...\n", sleeptime, (sleeptime == 1) ? "" : "s"); sleep(sleeptime); #ifdef NETSNMP_ENABLE_TESTING_CODE dump_etimelist(); #endif return failcount; } /* end test_etime() */
// // Write & read the first few data bytes and print them into the error string. // PERROR CRamCheck::writeReadData( const RAM_REGION *ramRegion ) { PERROR error = errorSuccess; UINT16 expData4[4] = {0x1111, 0x2222, 0x4444, 0x8888}; UINT16 expData1[4] = {0x5555, 0xAAAA, 0x5555, 0xAAAA}; UINT16 *expData = (UINT16*) NULL;; UINT16 recData[4] = {0}; UINT8 dataBusWidth = m_cpu->dataBusWidth(ramRegion->start); UINT8 dataAccessWidth = m_cpu->dataAccessWidth(ramRegion->start); // // This is more complicated than this simple test // as it needs the bit shift done to be correct. // if ((ramRegion->mask < 4) || (dataAccessWidth > 1)) { expData = expData1; } else { expData = expData4; } errorCustom->description = "OK:"; // // Check if we need to perform a bank switch for this region. // and do that now for all the testing to be done upon it. // if (ramRegion->bankSwitch != NO_BANK_SWITCH) { error = ramRegion->bankSwitch( m_bankSwitchContext ); } // // Write the first 4 bytes, maximum. // if (SUCCESS(error)) { for (UINT32 index = 0 ; index < (4 / dataAccessWidth) ; index++) { error = m_cpu->memoryWrite( (index * (dataBusWidth * ramRegion->step)) + ramRegion->start, expData[index] ); if (FAILED(error)) { break; } } } // // Read the first 4 bytes, maximum. // if (SUCCESS(error)) { if (dataAccessWidth == 1) { for (UINT32 index = 0 ; index < 4 ; index++) { error = m_cpu->memoryRead( (index * (dataBusWidth * ramRegion->step)) + ramRegion->start, &recData[index] ); if (FAILED(error)) { break; } STRING_UINT8_HEX(errorCustom->description, (recData[index] & ramRegion->mask) ); error = errorCustom; } } else if (dataAccessWidth == 2) { for (UINT32 index = 0 ; index < 2 ; index++) { error = m_cpu->memoryRead( (index * (dataBusWidth * ramRegion->step)) + ramRegion->start, &recData[index] ); if (FAILED(error)) { break; } STRING_UINT16_HEX(errorCustom->description, (recData[index] & ramRegion->mask) ); error = errorCustom; } } else { error = errorNotImplemented; } } return error; }
// =-=-=-=-=-=-=- // public - connect to the catalog and query for all the // attached resources and instantiate them error resource_manager::init_from_catalog( rsComm_t* _comm ) { // =-=-=-=-=-=-=- // clear existing resource map and initialize resources_.clear(); // =-=-=-=-=-=-=- // set up data structures for a gen query genQueryInp_t genQueryInp; genQueryOut_t* genQueryOut = NULL; error proc_ret; memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_ID, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_ZONE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_TYPE_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_CLASS_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_LOC, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_VAULT_PATH, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_FREE_SPACE, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_INFO, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_COMMENT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_CREATE_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_MODIFY_TIME, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_STATUS, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_CHILDREN, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_CONTEXT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_PARENT, 1 ); addInxIval( &genQueryInp.selectInp, COL_R_RESC_OBJCOUNT, 1 ); genQueryInp.maxRows = MAX_SQL_ROWS; // =-=-=-=-=-=-=- // init continueInx to pass for first loop int continueInx = 1; // =-=-=-=-=-=-=- // loop until continuation is not requested while ( continueInx > 0 ) { // =-=-=-=-=-=-=- // perform the general query int status = rsGenQuery( _comm, &genQueryInp, &genQueryOut ); // =-=-=-=-=-=-=- // perform the general query if ( status < 0 ) { if ( status != CAT_NO_ROWS_FOUND ) { rodsLog( LOG_NOTICE, "initResc: rsGenQuery error, status = %d", status ); } clearGenQueryInp( &genQueryInp ); return ERROR( status, "genQuery failed." ); } // if // =-=-=-=-=-=-=- // given a series of rows, each being a resource, create a resource and add it to the table proc_ret = process_init_results( genQueryOut ); // =-=-=-=-=-=-=- // if error is not valid, clear query and bail if ( !proc_ret.ok() ) { irods::error log_err = PASSMSG( "init_from_catalog - process_init_results failed", proc_ret ); irods::log( log_err ); freeGenQueryOut( &genQueryOut ); break; } else { if ( genQueryOut != NULL ) { continueInx = genQueryInp.continueInx = genQueryOut->continueInx; freeGenQueryOut( &genQueryOut ); } else { continueInx = 0; } } // else } // while clearGenQueryInp( &genQueryInp ); // =-=-=-=-=-=-=- // pass along the error if we are in an error state if ( !proc_ret.ok() ) { return PASSMSG( "process_init_results failed.", proc_ret ); } // =-=-=-=-=-=-=- // Update child resource maps proc_ret = init_child_map(); if ( !proc_ret.ok() ) { return PASSMSG( "init_child_map failed.", proc_ret ); } // =-=-=-=-=-=-=- // gather the post disconnect maintenance operations error op_ret = gather_operations(); if ( !op_ret.ok() ) { return PASSMSG( "gather_operations failed.", op_ret ); } // =-=-=-=-=-=-=- // initialize the special local file system resource // JMC :: no longer needed //error spec_ret = init_local_file_system_resource(); //if ( !spec_ret.ok() ) { // return PASSMSG( "init_local_file_system_resource failed.", op_ret ); //} // =-=-=-=-=-=-=- // call start for plugins error start_err = start_resource_plugins(); if ( !start_err.ok() ) { return PASSMSG( "start_resource_plugins failed.", start_err ); } // =-=-=-=-=-=-=- // win! return SUCCESS(); } // init_from_catalog
// // Performs all the RAM checks on the region supplied to the object. // PERROR CRamCheck::checkRandomAccess( const RAM_REGION *ramRegion ) { PERROR error = errorSuccess; UINT8 dataBusWidth = m_cpu->dataBusWidth(ramRegion->start); UINT8 dataAccessWidth = m_cpu->dataAccessWidth(ramRegion->start); UINT32 regionLength = (ramRegion->end - ramRegion->start) / ramRegion->step; UINT32 countLength = (regionLength * 3) / (dataBusWidth * ramRegion->step); // // This function only works with at least byte-wide memory. // Use a duplicate entry in the RAM_REGION for the byte-wide representation. // if ((ramRegion->mask != 0x00FF) && (ramRegion->mask != 0xFF00) && (ramRegion->mask != 0xFFFF)) { return errorNotImplemented; } // // Clear the region first to all 0. // This will also perform any bank switch. // error = write(ramRegion, 0); if (FAILED(error)) { return error; } // // Outer loop to periodically reset the region back to 0 to restart // with different seeds for the address & data values. // for (UINT8 cycle = 0 ; (cycle < 8) && SUCCESS(error) ; cycle++) { // // Pass 1 - write/read/verify, random access // randomSeed(ramRegion->start + ramRegion->step + ramRegion->mask + cycle); // // The length & step are used for the iteration count as a means to equalize the random access // density no matter what the size of the RAM. // for (UINT32 count = 0 ; count < countLength ; count++ ) { UINT32 address = (((UINT32) random(regionLength)) * (dataBusWidth * ramRegion->step)) + ramRegion->start; UINT16 expData = (((address + cycle) * 3) ^ ((address + cycle) / 5)); UINT16 recData = 0; // For 16-bit we just use the same value for hi & lo. expData = (expData & 0xFF) | (expData << 8); // // Pause to make sure the data is actually held valid. // This is done to help detect DRAM refresh failure. // if ((count % (countLength / 4)) == 0) { delay(cycle * 200); } // // Add in some blind writes to let the writes accumulate // a bit more agressively to fill in the memory with data. // if (count & 2) { error = m_cpu->memoryWrite(address, expData); if (FAILED(error)) { break; } continue; } // Read what's there. error = m_cpu->memoryRead(address, &recData); if (FAILED(error)) { break; } expData &= ramRegion->mask; recData &= ramRegion->mask; // If we a read a 0 then write out a value. if (recData == 0) { error = m_cpu->memoryWrite(address, expData); if (FAILED(error)) { break; } continue; } if (dataAccessWidth == 1) { CHECK_VALUE_UINT8_BREAK(error, ramRegion->location, address, expData, recData); } else if (dataAccessWidth == 2) { CHECK_VALUE_UINT16_BREAK(error, ramRegion->location, address, expData, recData); } else { error = errorNotImplemented; break; } // // Add in an optional clear after verify. // This is less agressive than the blind one to that // on average data accumulates in the RAM // if (count & 4) { error = m_cpu->memoryWrite(address, 0); if (FAILED(error)) { break; } } } // // Add in a variable delay between cycles. // This is to detect a very specific failure mode encountered on TMS4060 // DRAM used on Space Invaders where the RAM fails a few seconds after the // data is written. // delay(cycle * 300); // // Pass 2 - verify/clear entire contents, random access // randomSeed(ramRegion->start + ramRegion->step + ramRegion->mask + cycle); // // The length & step are used for the iteration count as a means to equalize the random access // density no matter what the size of the RAM. // for (UINT32 count = 0 ; count < countLength ; count++ ) { UINT32 address = (((UINT32) random(regionLength)) * (dataBusWidth * ramRegion->step)) + ramRegion->start; UINT16 expData = (((address + cycle) * 3) ^ ((address + cycle) / 5)); UINT16 recData = 0; // For 16-bit we just use the same value for hi & lo. expData = (expData & 0xFF) | (expData << 8); // Read what's there. error = m_cpu->memoryRead(address, &recData); if (FAILED(error)) { break; } expData &= ramRegion->mask; recData &= ramRegion->mask; // Nothing to verify if 0 if (recData == 0) { continue; } if (dataAccessWidth == 1) { CHECK_VALUE_UINT8_BREAK(error, ramRegion->location, address, expData, recData); } else if (dataAccessWidth == 2) { CHECK_VALUE_UINT16_BREAK(error, ramRegion->location, address, expData, recData); } else { error = errorNotImplemented; break; } error = m_cpu->memoryWrite(address, 0); if (FAILED(error)) { break; } } } return error; }
// =-=-=-=-=-=-=- // public - initialize the special local file system resource error resource_manager::init_local_file_system_resource( void ) { // =-=-=-=-=-=-=- // init the local fs resource resource_ptr resc; error err = init_from_type( LOCAL_USE_ONLY_RESOURCE_TYPE, LOCAL_USE_ONLY_RESOURCE, LOCAL_USE_ONLY_RESOURCE, "", resc ); // =-=-=-=-=-=-=- // error check if ( !err.ok() ) { std::stringstream msg; msg << "resource_manager::init_local_file_system_resource - failed to create resource"; return PASSMSG( msg.str(), err ); } // =-=-=-=-=-=-=- // get the zone info for the local zone zoneInfo_t* zone_info = 0; getLocalZoneInfo( &zone_info ); // =-=-=-=-=-=-=- // build a host addr struct to get the server host info char host_name[ MAX_NAME_LEN ]; gethostname( host_name, MAX_NAME_LEN ); rodsHostAddr_t addr; rstrcpy( addr.hostAddr, host_name, LONG_NAME_LEN ); rstrcpy( addr.zoneName, const_cast<char*>( zone_info->zoneName ), NAME_LEN ); rodsServerHost_t* tmpRodsServerHost = 0; if ( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) { rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s", addr.hostAddr ); } resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost ); // =-=-=-=-=-=-=- // start filling in the properties resc->set_property<long>( RESOURCE_ID, 999 ); resc->set_property<long>( RESOURCE_FREESPACE, 999 ); resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT ); resc->set_property<std::string>( RESOURCE_ZONE, zone_info->zoneName ); resc->set_property<std::string>( RESOURCE_NAME, LOCAL_USE_ONLY_RESOURCE ); resc->set_property<std::string>( RESOURCE_LOCATION, "localhost" ); resc->set_property<std::string>( RESOURCE_TYPE, LOCAL_USE_ONLY_RESOURCE_TYPE ); resc->set_property<std::string>( RESOURCE_CLASS, "cache" ); resc->set_property<std::string>( RESOURCE_PATH, LOCAL_USE_ONLY_RESOURCE_VAULT ); resc->set_property<std::string>( RESOURCE_INFO, "info" ); resc->set_property<std::string>( RESOURCE_COMMENTS, "comments" ); resc->set_property<std::string>( RESOURCE_CREATE_TS, "999" ); resc->set_property<std::string>( RESOURCE_MODIFY_TS, "999" ); resc->set_property<std::string>( RESOURCE_CHILDREN, "" ); resc->set_property<std::string>( RESOURCE_PARENT, "" ); resc->set_property<std::string>( RESOURCE_CONTEXT, "" ); resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP ); // =-=-=-=-=-=-=- // assign to the map resources_[ LOCAL_USE_ONLY_RESOURCE ] = resc; return SUCCESS(); } // init_local_file_system_resource
error hierarchy_parser::num_levels( int& levels ) const { error result = SUCCESS(); levels = resc_list_.size(); return result; }
// =-=-=-=-=-=-=- // private - gather the post disconnect maintenance operations // from the resource plugins error resource_manager::gather_operations() { // =-=-=-=-=-=-=- // vector of already processed resources std::vector< std::string > proc_vec; // =-=-=-=-=-=-=- // iterate over all of the resources lookup_table< boost::shared_ptr< resource > >::iterator resc_itr; for ( resc_itr = resources_.begin(); resc_itr != resources_.end(); ++resc_itr ) { resource_ptr& resc = resc_itr->second; // =-=-=-=-=-=-=- // skip if already processed std::string name; error get_err = resc->get_property< std::string >( RESOURCE_NAME, name ); if ( get_err.ok() ) { std::vector< std::string >::iterator itr; itr = std::find< std::vector< std::string >::iterator, std::string >( proc_vec.begin(), proc_vec.end(), name ); if ( proc_vec.end() != itr ) { continue; } } else { std::stringstream msg; msg << "resource_manager::gather_operations - failed to get property "; msg << "[name] for resource"; return PASSMSG( msg.str(), get_err ); } // =-=-=-=-=-=-=- // vector which will hold this 'top level resource' ops std::vector< pdmo_type > resc_ops; // =-=-=-=-=-=-=- // cache the parent operator pdmo_type pdmo_op; error pdmo_err = resc->post_disconnect_maintenance_operation( pdmo_op ); if ( pdmo_err.ok() ) { resc_ops.push_back( pdmo_op ); } // =-=-=-=-=-=-=- // mark this resource done proc_vec.push_back( name ); // =-=-=-=-=-=-=- // dive if children are present std::string child_str; error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str ); if ( child_err.ok() && !child_str.empty() ) { gather_operations_recursive( child_str, proc_vec, resc_ops ); } // =-=-=-=-=-=-=- // if we got ops, add vector of ops to mgr's vector if ( !resc_ops.empty() ) { maintenance_operations_.push_back( resc_ops ); } } // for itr return SUCCESS(); } // gather_operations
// =-=-=-=-=-=-=- /// @brief Start Up Operation irods::error random_start_operation( irods::plugin_property_map&, // _prop_map irods::resource_child_map& ) { // _cmap return SUCCESS(); } // random_start_operation
// =-=-=-=-=-=-=- /// private - lower level recursive call to gather the post disconnect // maintenance operations from the resources, in breadth first order error resource_manager::gather_operations_recursive( const std::string& _children, std::vector< std::string >& _proc_vec, std::vector< pdmo_type >& _resc_ops ) { // =-=-=-=-=-=-=- // create a child parser to traverse the list children_parser parser; parser.set_string( _children ); children_parser::children_map_t children_list; error ret = parser.list( children_list ); if ( !ret.ok() ) { return PASSMSG( "gather_operations_recursive failed.", ret ); } // =-=-=-=-=-=-=- // iterate over all of the children, cache the operators children_parser::children_map_t::const_iterator itr; for ( itr = children_list.begin(); itr != children_list.end(); ++itr ) { std::string child = itr->first; // =-=-=-=-=-=-=- // lookup the child resource pointer resource_ptr resc; error get_err = resources_.get( child, resc ); if ( get_err.ok() ) { // =-=-=-=-=-=-=- // cache operation if there is one pdmo_type pdmo_op; error pdmo_ret = resc->post_disconnect_maintenance_operation( pdmo_op ); if ( pdmo_ret.ok() ) { _resc_ops.push_back( pdmo_op ); } // =-=-=-=-=-=-=- // mark this child as done _proc_vec.push_back( child ); } else { std::stringstream msg; msg << "failed to get resource for key ["; msg << child; msg << "]"; return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); } } // for itr // =-=-=-=-=-=-=- // iterate over all of the children again, recurse if they have more children for ( itr = children_list.begin(); itr != children_list.end(); ++itr ) { std::string child = itr->first; // =-=-=-=-=-=-=- // lookup the child resource pointer resource_ptr resc; error get_err = resources_.get( child, resc ); if ( get_err.ok() ) { std::string child_str; error child_err = resc->get_property< std::string >( RESOURCE_CHILDREN, child_str ); if ( child_err.ok() && !child_str.empty() ) { error gather_err = gather_operations_recursive( child_str, _proc_vec, _resc_ops ); } } else { std::stringstream msg; msg << "failed to get resource for key ["; msg << child; msg << "]"; return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); } } // for itr return SUCCESS(); } // gather_operations_recursive
/// =-=-=-=-=-=-=- /// @brief find the next valid child resource for create operation irods::error get_next_valid_child_resource( irods::resource_plugin_context& _ctx, const std::string* _opr, const std::string* _curr_host, irods::hierarchy_parser* _out_parser, float* _out_vote ) { irods::error result = SUCCESS(); irods::error ret; // =-=-=-=-=-=-=- // flag bool child_found = false; // =-=-=-=-=-=-=- // the pool of resources (children) to try std::vector<irods::resource_ptr> candidate_resources; // =-=-=-=-=-=-=- // copy children from _cmap irods::resource_child_map::iterator itr = _ctx.child_map().begin(); for ( ; itr != _ctx.child_map().end(); ++itr ) { candidate_resources.push_back( itr->second.second ); } // =-=-=-=-=-=-=- // while we have not found a child and still have candidates while ( result.ok() && ( !child_found && !candidate_resources.empty() ) ) { // =-=-=-=-=-=-=- // generate random index size_t rand_index = irods::getRandom<unsigned int>() % candidate_resources.size(); // =-=-=-=-=-=-=- // pick resource in pool at random index irods::resource_ptr resc = candidate_resources[rand_index]; // =-=-=-=-=-=-=- // forward the 'create' redirect to the appropriate child ret = resc->call< const std::string*, const std::string*, irods::hierarchy_parser*, float* >( _ctx.comm(), irods::RESOURCE_OP_RESOLVE_RESC_HIER, _ctx.fco(), _opr, _curr_host, _out_parser, _out_vote ); // Found a valid child if ( ret.ok() && *_out_vote != 0 ) { child_found = true; } else { // =-=-=-=-=-=-=- // remove child from pool of candidates candidate_resources.erase( candidate_resources.begin() + rand_index ); } } // while // =-=-=-=-=-=-=- // return appropriately if ( result.ok() ) { result = ASSERT_ERROR( child_found, NO_NEXT_RESC_FOUND, "No valid child found." ); } return result; } // get_next_valid_child_resource
// =-=-=-=-=-=-=- // redirect_get - code to determine redirection for get operation irods::error mock_archive_redirect_open( irods::plugin_property_map& _prop_map, irods::file_object_ptr _file_obj, const std::string& _resc_name, const std::string& _curr_host, float& _out_vote ) { irods::error result = SUCCESS(); // =-=-=-=-=-=-=- // initially set a good default _out_vote = 0.0; // =-=-=-=-=-=-=- // determine if the resource is down int resc_status = 0; irods::error get_ret = _prop_map.get< int >( irods::RESOURCE_STATUS, resc_status ); if ( ( result = ASSERT_PASS( get_ret, "Failed to get \"status\" property." ) ).ok() ) { // =-=-=-=-=-=-=- // if the status is down, vote no. if ( INT_RESC_STATUS_DOWN != resc_status ) { // =-=-=-=-=-=-=- // get the resource host for comparison to curr host std::string host_name; get_ret = _prop_map.get< std::string >( irods::RESOURCE_LOCATION, host_name ); if ( ( result = ASSERT_PASS( get_ret, "Failed to get \"location\" property." ) ).ok() ) { // =-=-=-=-=-=-=- // set a flag to test if were at the curr host, if so we vote higher bool curr_host = ( _curr_host == host_name ); // =-=-=-=-=-=-=- // make some flags to clairify decision making bool need_repl = ( _file_obj->repl_requested() > -1 ); // =-=-=-=-=-=-=- // set up variables for iteration bool found = false; std::vector< irods::physical_object > objs = _file_obj->replicas(); std::vector< irods::physical_object >::iterator itr = objs.begin(); // =-=-=-=-=-=-=- // check to see if the replica is in this resource, if one is requested for ( ; !found && itr != objs.end(); ++itr ) { // =-=-=-=-=-=-=- // run the hier string through the parser and get the last // entry. std::string last_resc; irods::hierarchy_parser parser; parser.set_string( itr->resc_hier() ); parser.last_resc( last_resc ); // =-=-=-=-=-=-=- // more flags to simplify decision making bool repl_us = ( _file_obj->repl_requested() == itr->repl_num() ); bool resc_us = ( _resc_name == last_resc ); // =-=-=-=-=-=-=- // success - correct resource and dont need a specific // replication, or the repl nums match if ( resc_us ) { if ( !need_repl || ( need_repl && repl_us ) ) { found = true; if ( curr_host ) { _out_vote = 1.0; } else { _out_vote = 0.5; } } } // if resc_us } // for itr } } } return result; } // mock_archive_redirect_open
/// =-=-=-=-=-=-=- /// @brief used to allow the resource to determine which host /// should provide the requested operation irods::error random_redirect( irods::resource_plugin_context& _ctx, const std::string* _opr, const std::string* _curr_host, irods::hierarchy_parser* _out_parser, float* _out_vote ) { irods::error result = SUCCESS(); // =-=-=-=-=-=-=- // check incoming parameters irods::error err = random_check_params< irods::file_object >( _ctx ); if ( ( result = ASSERT_PASS( err, "Invalid resource context." ) ).ok() ) { if ( ( result = ASSERT_ERROR( _opr && _curr_host && _out_parser && _out_vote, SYS_INVALID_INPUT_PARAM, "Invalid parameters." ) ).ok() ) { // =-=-=-=-=-=-=- // get the object's hier string irods::file_object_ptr file_obj = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() ); std::string hier = file_obj->resc_hier( ); // =-=-=-=-=-=-=- // get the object's hier string std::string name; err = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, name ); if ( ( result = ASSERT_PASS( err, "Failed to get property: \"%s\".", irods::RESOURCE_NAME.c_str() ) ).ok() ) { // =-=-=-=-=-=-=- // add ourselves into the hierarchy before calling child resources _out_parser->add_child( name ); // =-=-=-=-=-=-=- // test the operation to determine which choices to make if ( irods::OPEN_OPERATION == ( *_opr ) || irods::WRITE_OPERATION == ( *_opr ) || irods::UNLINK_OPERATION == ( *_opr )) { // =-=-=-=-=-=-=- // get the next child pointer in the hierarchy, given our name and the hier string irods::resource_ptr resc; err = get_next_child_for_open_or_write( name, file_obj, _ctx.child_map(), resc ); if ( err.ok() ) { // =-=-=-=-=-=-=- // forward the redirect call to the child for assertion of the whole operation, // there may be more than a leaf beneath us err = resc->call< const std::string*, const std::string*, irods::hierarchy_parser*, float* >( _ctx.comm(), irods::RESOURCE_OP_RESOLVE_RESC_HIER, _ctx.fco(), _opr, _curr_host, _out_parser, _out_vote ); result = ASSERT_PASS( err, "Failed calling child operation." ); } else if ( err.code() == REPLICA_NOT_IN_RESC ) { *_out_vote = 0; } else { result = err; } } else if ( irods::CREATE_OPERATION == ( *_opr ) ) { // =-=-=-=-=-=-=- // get the next_child resource for create irods::resource_ptr resc; err = get_next_valid_child_resource( _ctx, _opr, _curr_host, _out_parser, _out_vote ); result = ASSERT_PASS( err, "Failed getting next valid child." ); } else { // =-=-=-=-=-=-=- // must have been passed a bad operation result = ASSERT_ERROR( false, INVALID_OPERATION, "Operation not supported: \"%s\".", _opr->c_str() ); } } } } return result; } // random_redirect
irods::error need_post_disconnect_maintenance_operation( bool& _b ) { _b = false; return SUCCESS(); }
/// =-=-=-=-=-=-=- /// @brief get the loads, times and names from the resource monitoring table irods::error get_load_lists( irods::resource_plugin_context& _ctx, std::vector< std::string >& _resc_names, std::vector< int >& _resc_loads, std::vector< int >& _resc_times ) { // =-=-=-=-=-=-=- // int i = 0, j = 0, nresc = 0, status = 0; char* tResult = 0; genQueryInp_t genQueryInp; genQueryOut_t* genQueryOut = NULL; // =-=-=-=-=-=-=- // query the database in order to retrieve the information on the // resources' load memset( &genQueryInp, 0, sizeof( genQueryInp ) ); addInxIval( &genQueryInp.selectInp, COL_SLD_RESC_NAME, 1 ); addInxIval( &genQueryInp.selectInp, COL_SLD_LOAD_FACTOR, 1 ); addInxIval( &genQueryInp.selectInp, COL_SLD_CREATE_TIME, SELECT_MAX ); // =-=-=-=-=-=-=- // a tmp fix to increase no. of resource to 256 genQueryInp.maxRows = MAX_SQL_ROWS * 10; status = rsGenQuery( _ctx.comm(), &genQueryInp, &genQueryOut ); if ( status == 0 ) { nresc = genQueryOut->rowCnt; // =-=-=-=-=-=-=- // vectors should be sized to number of resources // these vectors will be indexed directly, not built _resc_names.resize( nresc ); _resc_loads.resize( nresc ); _resc_times.resize( nresc ); for ( i = 0; i < genQueryOut->attriCnt; i++ ) { for ( j = 0; j < nresc; j++ ) { tResult = genQueryOut->sqlResult[i].value; tResult += j * genQueryOut->sqlResult[i].len; switch ( i ) { case 0: _resc_names[j] = tResult; break; case 1: _resc_loads[j] = atoi( tResult ); break; case 2: _resc_times[j] = atoi( tResult ); break; } } } } else { clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return ERROR( status, "genquery failed" ); } clearGenQueryInp( &genQueryInp ); freeGenQueryOut( &genQueryOut ); return SUCCESS(); } // get_load_lists