void insert2(long long int B[],long long int i) { state=0; val=0; count2++; B[count2]=i; //We simply insert the element at the end of the array and then check throughout the tree above it (worker function). //We can store i in A[count+1] as count+1'th location is empty as of now. In a heap, suppose there are n elements until now then the n elements are arranged in array locations 1 to n, n+1th location is untouched. This is because its a balanced binary tree, so n+1th location is filled only after nth location is filled and so on..... worker2(B,count2); }
void worker2(long long int B[],long long int j) //Goes up the tree swapping with the parent wherever required. { long long int temp; if(j>=2) { if(B[j/2]>B[j]) { temp=B[j/2]; B[j/2]=B[j]; B[j]=temp; worker2(B,j/2); } } }
int main(int argc, char **argv) { ros::init(argc, argv, "temp_node"); bool simulated = true; TempSimNode *node1 = new TempSimNode(argc, argv, 1, "HULL"); TempSimNode *node2 = new TempSimNode(argc, argv, 10, "HULL2"); /* * This is the general structure for using threads. The runThread function * has already been defined in QuboNode. Just call the thread here to run * a sub-node. */ std::thread worker1(&TempSimNode::runThread, node1); std::thread worker2(&TempSimNode::runThread, node2); worker1.join(); worker2.join(); }
int main(int argc, char* argv[]) { std::cout << "main: startup" << std::endl; Work* work1 = new Work(); Work* work2 = new Work(); std::string data[2]; boost::thread worker1(boost::bind(&Work::handle, work1, boost::ref(data[0]))); boost::thread worker2(boost::bind(&Work::handle, work2, boost::ref(data[1]))); std::cout << "main: waiting for thread" << std::endl; worker1.join(); worker2.join(); std::cout << "data[0] "<< data[0] << std::endl; std::cout << "data[1] "<< data[1] << std::endl; std::cout << "main: done" << std::endl; return 0; }
int main() { /* Basic test. Run some coroutines. */ int cr1 = go(worker(3, 7)); errno_assert(cr1 >= 0); int cr2 = go(worker(1, 11)); errno_assert(cr2 >= 0); int cr3 = go(worker(2, 5)); errno_assert(cr3 >= 0); int rc = msleep(now() + 100); errno_assert(rc == 0); rc = hclose(cr1); errno_assert(rc == 0); rc = hclose(cr2); errno_assert(rc == 0); rc = hclose(cr3); errno_assert(rc == 0); assert(sum == 42); /* Test whether stack deallocation works. */ int i; int hndls2[20]; for(i = 0; i != 20; ++i) { hndls2[i] = go(dummy()); errno_assert(hndls2[i] >= 0); } rc = msleep(now() + 100); errno_assert(rc == 0); for(i = 0; i != 20; ++i) { rc = hclose(hndls2[i]); errno_assert(rc == 0); } /* Test whether immediate cancelation works. */ cr1 = go(worker2()); errno_assert(cr1 >= 0); cr2 = go(worker2()); errno_assert(cr2 >= 0); cr3 = go(worker2()); errno_assert(cr3 >= 0); rc = msleep(now() + 30); errno_assert(rc == 0); rc = hclose(cr1); errno_assert(rc == 0); rc = hclose(cr2); errno_assert(rc == 0); rc = hclose(cr3); errno_assert(rc == 0); assert(worker2_done == 3); /* Test whether finished coroutine can be canceled. */ cr1 = go(worker3()); errno_assert(cr1 >= 0); rc = hclose(cr1); errno_assert(rc == 0); /* Let the test running for a while to detect possible errors if there was a bug that left any corotines running. */ rc = msleep(now() + 100); errno_assert(rc == 0); /* Test go_mem. */ char *stack = malloc(4096); assert(stack); cr1 = go_mem(dummy(), stack, 4096); errno_assert(cr1 >= 0); rc = msleep(now() + 100); errno_assert(rc == 0); rc = hclose(cr1); errno_assert(rc == 0); free(stack); return 0; }
int Task::svc (void) { try { // Priority Mapping Manager. CORBA::Object_var object = this->orb_->resolve_initial_references ("PriorityMappingManager"); RTCORBA::PriorityMappingManager_var mapping_manager = RTCORBA::PriorityMappingManager::_narrow (object.in ()); if (check_for_nil (mapping_manager.in (), "Mapping Manager") == -1) return -1; RTCORBA::PriorityMapping *pm = mapping_manager->mapping (); // RTCurrent. object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); if (check_for_nil (current.in (), "RTCurrent") == -1) return -1; // Obtain Test object reference. object = this->orb_->string_to_object (ior); Test_var server = Test::_narrow (object.in ()); if (check_for_nil (server.in (), "Test object") == -1) return -1; // Check that test object is configured with CLIENT_PROPAGATED // PriorityModelPolicy. CORBA::Policy_var policy = server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE); RTCORBA::PriorityModelPolicy_var priority_policy = RTCORBA::PriorityModelPolicy::_narrow (policy.in ()); if (check_for_nil (priority_policy.in (), "PriorityModelPolicy") == -1) return -1; RTCORBA::PriorityModel priority_model = priority_policy->priority_model (); if (priority_model != RTCORBA::CLIENT_PROPAGATED) ACE_ERROR_RETURN ((LM_ERROR, "ERROR: priority_model != " "RTCORBA::CLIENT_PROPAGATED!\n"), -1); // Spawn two worker threads. ACE_Barrier thread_barrier (2); int flags = THR_NEW_LWP | THR_JOINABLE | this->orb_->orb_core ()->orb_params ()->thread_creation_flags (); // Worker 1. Worker_Thread worker1 (this->orb_.in (), server.in (), protocol1, &thread_barrier); CORBA::Short native_priority1 = 0; if (pm->to_native (priority1, native_priority1) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot convert corba priority %d to native priority\n", priority1), -1); if (worker1.activate (flags, 1, 0, native_priority1) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate first client worker threads\n"), -1); // Worker 2. Worker_Thread worker2 (this->orb_.in (), server.in (), protocol2, &thread_barrier); CORBA::Short native_priority2 = 0; if (pm->to_native (priority2, native_priority2) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot convert corba priority %d to native priority\n", priority2), -1); if (worker2.activate (flags, 1, 0, native_priority2) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate second client worker threads\n"), -1); // Wait for worker threads to finish. ACE_Thread_Manager::instance ()->wait (); // Testing over. Shut down the server. ACE_DEBUG ((LM_DEBUG, "Client threads finished\n")); current->the_priority (priority1); server->shutdown (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Unexpected exception in MT_Client_Protocol_Priority test client:"); return -1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB first. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Obtain the RootPOA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); // Get the POA_var object from Object_var. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Policies for the new POA. CORBA::PolicyList policies (2); policies.length (2); policies[0] = root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION); policies[1] = root_poa->create_thread_policy (PortableServer::SINGLE_THREAD_MODEL); // Creation of the child POA. PortableServer::POA_var child_poa = root_poa->create_POA ("child", poa_manager.in (), policies); // Destroy the policies for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } poa_manager->activate (); test_i servant1 (child_poa.in ()); test_i servant2 (child_poa.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&servant1); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); test_var object1 = test::_narrow (object_act.in ()); id = root_poa->activate_object (&servant2); object_act = root_poa->id_to_reference (id.in ()); test_var object2 = test::_narrow (object_act.in ()); Worker worker1 (object1.in ()); Worker worker2 (object2.in ()); int result = worker1.activate () != 0 || worker2.activate () != 0; ACE_ASSERT (result == 0); result = ACE_Thread_Manager::instance ()->wait (); ACE_ASSERT (result == 0); // In non-debug compiles, asserts will disappear. ACE_UNUSED_ARG (result); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }
bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) { #ifndef NO_NET const char *HOSTNAME = "http://thegamesdb.net"; const char *PLATFORM_REQ = "api/GetPlatformsList.php"; const char *GAME_REQ = "api/GetGame.php?name=$1"; // // Get a list of valid platforms // FeNetQueue q; q.add_buffer_task( HOSTNAME, PLATFORM_REQ, 0 ); sf::Http::Response::Status status; q.do_next_task( status ); if ( status != sf::Http::Response::Ok ) { get_resource( "Error getting platform list from thegamesdb.net. Code: $1", as_str( status ), c.user_message ); std::cout << " * " << c.user_message << std::endl; return true; } int temp; std::string body; q.pop_completed_task( temp, body ); FeGameDBPlatformParser gdbpp; gdbpp.parse( body ); const std::vector<std::string> &sl_temp = c.emulator.get_systems(); std::vector<std::string> system_list; for ( std::vector<std::string>::const_iterator itr = sl_temp.begin(); itr!=sl_temp.end(); ++itr ) { if ( gdbpp.m_set.find( *itr ) != gdbpp.m_set.end() ) system_list.push_back( *itr ); else std::cout << " * System identifier '" << (*itr) << "' not recognized by " << HOSTNAME << std::endl; } if ( system_list.size() < 1 ) { // Correct if we can based on the configured info source, // otherwise we error out const std::string source = c.emulator.get_info( FeEmulatorInfo::Info_source ); if ( source.compare( "mame" ) == 0 ) system_list.push_back( "Arcade" ); else if ( source.compare( "steam" ) == 0 ) system_list.push_back( "PC" ); else { get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.", c.user_message ); std::cout << " * " << c.user_message << std::endl; return true; } } std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name ); // // Build a map for looking up parents // std::map < std::string, FeRomInfo * > parent_map; build_parent_map( parent_map, c.romlist ); // // Build a worklist of the roms where we need to lookup // std::vector<FeRomInfo *> worklist; worklist.reserve( c.romlist.size() ); for ( FeRomInfoListType::iterator itr=c.romlist.begin(); itr!=c.romlist.end(); ++itr ) { (*itr).set_info( FeRomInfo::Emulator, emu_name ); // Don't scrape for a clone if its parent has the same name // if ( has_same_name_as_parent( *itr, parent_map ) ) continue; if ( !c.scrape_art || m_scrape_fanart || ( m_scrape_flyers && (!has_artwork( *itr, "flyer" ) ) ) || ( m_scrape_wheels && (!has_artwork( *itr, "wheel" ) ) ) || ( m_scrape_snaps && (!has_artwork( *itr, "snap" ) ) ) || ( m_scrape_marquees && (!has_artwork( *itr, "marquee" ) ) ) ) worklist.push_back( &(*itr) ); } const int NUM_ARTS=5; // the number of scrape-able artwork types int done_count( 0 ); // // Set up our initial queue of network tasks // for ( unsigned int i=0; i<worklist.size(); i++ ) { std::string req_string = GAME_REQ; std::string game = url_escape( name_with_brackets_stripped( worklist[i]->get_info( FeRomInfo::Title ) ) ); perform_substitution( req_string, "$1", game ); // // If we don't need to scrape a wheel artwork, then add the specific platform to our request // If we are scraping a wheel, we want to be able to grab them where the game name (but // not the system) matches, so we don't limit ourselves by system... // if (( system_list.size() == 1 ) && ( !c.scrape_art || !m_scrape_wheels || has_artwork( *(worklist[i]), "wheel" ) )) { req_string += "&platform="; req_string += url_escape( system_list.front() ); } q.add_buffer_task( HOSTNAME, req_string, i ); } std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR; base_path += emu_name + "/"; // // Create worker threads to process the queue, adding new tasks to download // artwork files where appropriate // FeNetWorker worker1( q ), worker2( q ), worker3( q ), worker4( q ); // // Process the output queue from our worker threads // while ( !q.input_done() || !q.output_done() ) { int id; std::string result; if ( q.pop_completed_task( id, result ) ) { if ( id < 0 ) { if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask )) { std::cout << " + Downloaded: " << result << std::endl; c.download_count++; } if ( id == FeNetTask::FileTask ) // we don't increment if id = FeNetTask::SpecialFileTask done_count++; } else { FeGameDBArt my_art; FeGameDBParser gdbp( system_list, *(worklist[id]), ( c.scrape_art ? &my_art : NULL ) ); gdbp.parse( result ); if ( c.scrape_art && !my_art.base.empty() ) { std::string hostn = HOSTNAME; std::string base_req = "banners/"; size_t pos=0; for ( int i=0; i<3 && ( pos != std::string::npos ); i++ ) pos = my_art.base.find_first_of( '/', pos+1 ); if (( pos != std::string::npos ) && ( pos < my_art.base.size()-1 ) ) { hostn = my_art.base.substr( 0, pos+1 ); base_req = my_art.base.substr( pos+1 ); } FeRomInfo &rom = *(worklist[id]); if ( m_scrape_flyers && ( !my_art.flyer.empty() ) && (!has_artwork( rom, "flyer" )) ) { const char *FLYER = "flyer/"; std::string fname = base_path + FLYER + rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, FLYER ); q.add_file_task( hostn, base_req + my_art.flyer, fname ); } else done_count++; if ( m_scrape_wheels && ( !my_art.wheel.empty() ) && (!has_artwork( rom, "wheel" )) ) { const char *WHEEL = "wheel/"; std::string fname = base_path + WHEEL + rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, WHEEL ); q.add_file_task( hostn, base_req + my_art.wheel, fname ); } else done_count++; if ( m_scrape_marquees && (!my_art.marquee.empty() ) && (!has_artwork( rom, "marquee" )) ) { const char *MARQUEE = "marquee/"; std::string fname = base_path + MARQUEE + rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, MARQUEE ); q.add_file_task( hostn, base_req + my_art.marquee, fname ); } else done_count++; if ( m_scrape_snaps && (!my_art.snap.empty() ) && (!has_artwork( rom, "snap" )) ) { const char *SNAP = "snap/"; std::string fname = base_path + SNAP + rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, SNAP ); q.add_file_task( hostn, base_req + my_art.snap, fname ); } else done_count++; if ( m_scrape_fanart && !my_art.fanart.empty() ) { const char *FANART = "fanart/"; std::string fname_base = base_path + FANART + rom.get_info( FeRomInfo::Romname ) + "/"; confirm_directory( base_path, "" ); confirm_directory( base_path + FANART, rom.get_info( FeRomInfo::Romname ) ); bool done_first=false; // we only count the first fanart against our percentage completed... for ( std::vector<std::string>::iterator itr = my_art.fanart.begin(); itr != my_art.fanart.end(); ++itr ) { size_t start_pos = (*itr).find_last_of( "/\\" ); size_t end_pos = (*itr).find_last_of( '.' ); if (( start_pos != std::string::npos ) && ( !file_exists( fname_base + (*itr).substr( start_pos+1 ) ) )) { if (( end_pos != std::string::npos ) && ( end_pos > start_pos )) { q.add_file_task( hostn, base_req + (*itr), fname_base + (*itr).substr( start_pos+1, end_pos-start_pos-1 ), done_first ); done_first=true; } } } } else done_count++; } else done_count+=NUM_ARTS; } if ( c.uiupdate ) { int p = c.progress_past + done_count * c.progress_range / ( NUM_ARTS * worklist.size() ); if ( c.uiupdate( c.uiupdatedata, p ) == false ) return false; } } else if ( q.output_done() ) { sf::Http::Response::Status status; q.do_next_task( status ); } else sf::sleep( sf::milliseconds( 10 ) ); } #endif return true; }
bool FeSettings::mamedb_scraper( FeImporterContext &c ) { #ifndef NO_NET if (( c.emulator.get_info( FeEmulatorInfo::Info_source ).compare( "mame" ) != 0 ) || ( !m_scrape_snaps && !m_scrape_marquees )) return true; // // Build a map for looking up parents // std::map < std::string, FeRomInfo * > parent_map; build_parent_map( parent_map, c.romlist ); const char *MAMEDB = "http://mamedb.com"; std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name ); std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR; base_path += emu_name + "/"; FeNetQueue q; int taskc( 0 ); int done( 0 ); for ( FeRomInfoListType::iterator itr=c.romlist.begin(); itr!=c.romlist.end(); ++itr ) { // ugh, this must be set for has_artwork() to correctly function (*itr).set_info( FeRomInfo::Emulator, emu_name ); // Don't scrape for a clone if its parent has the same name // if ( has_same_name_as_parent( *itr, parent_map ) ) continue; if ( m_scrape_marquees && !has_artwork( *itr, "marquee" ) ) { const char *MARQUEE = "marquee/"; std::string fname = base_path + MARQUEE + (*itr).get_info( FeRomInfo::Romname ); confirm_directory( base_path, MARQUEE ); q.add_file_task( MAMEDB, "marquees/" + (*itr).get_info( FeRomInfo::Romname ) +".png", fname ); taskc++; } if ( m_scrape_snaps && !has_artwork( *itr, "snap" ) ) { const char *SNAP = "snap/"; std::string fname = base_path + SNAP + (*itr).get_info( FeRomInfo::Romname ); confirm_directory( base_path, SNAP ); q.add_file_task( MAMEDB, SNAP + (*itr).get_info( FeRomInfo::Romname ) +".png", fname ); taskc++; } } // // Create worker threads to process the queue. // FeNetWorker worker1( q ), worker2( q ), worker3( q ), worker4( q ); // // Process the output queue from our worker threads // while ( !( q.input_done() && q.output_done() ) ) { int id; std::string result; if ( q.pop_completed_task( id, result ) ) { if ( id < 0 ) { if ( id == -1 ) { std::cout << " + Downloaded: " << result << std::endl; c.download_count++; } done++; } } if ( c.uiupdate ) { int p = c.progress_past + done * c.progress_range / taskc; if ( c.uiupdate( c.uiupdatedata, p ) == false ) return false; } } #endif return true; }
bool FeSettings::thegamesdb_scraper( FeImporterContext &c ) { #ifndef NO_NET const char *HOSTNAME = "http://thegamesdb.net"; const char *PLATFORM_LIST_REQ = "api/GetPlatformsList.php"; const char *PLAT_REQ = "api/GetPlatform.php?id=$1"; const char *GAME_REQ = "api/GetGame.php?name=$1"; const char *FLYER = "flyer/"; const char *WHEEL = "wheel/"; const char *MARQUEE = "marquee/"; const char *SNAP = "snap/"; const char *FANART = "fanart/"; // // Get a list of valid platforms // FeNetQueue q; q.add_buffer_task( HOSTNAME, PLATFORM_LIST_REQ, 0 ); sf::Http::Response::Status status; std::string err_req; q.do_next_task( status, err_req ); if ( status != sf::Http::Response::Ok ) { get_resource( "Error getting platform list from thegamesdb.net. Code: $1", as_str( status ), c.user_message ); std::cerr << " ! " << c.user_message << " (" << err_req << ")" << std::endl; return true; } int temp; std::string body; q.pop_completed_task( temp, body ); FeGameDBPlatformListParser gdbplp; gdbplp.parse( body ); std::vector<std::string> system_list; std::vector<int> system_ids; const std::vector<std::string> &sl_temp = c.emulator.get_systems(); for ( std::vector<std::string>::const_iterator itr = sl_temp.begin(); itr != sl_temp.end(); ++itr ) { std::string comp_fuzz = get_fuzzy( *itr ); for ( size_t i=0; i<gdbplp.m_names.size(); i++ ) { ASSERT( gdbplp.m_names.size() == gdbplp.m_ids.size() ); std::string &n = gdbplp.m_names[i]; int id = ( i < gdbplp.m_ids.size() ) ? i : 0; if ( comp_fuzz.compare( get_fuzzy( n ) ) == 0 ) { system_list.push_back( n ); system_ids.push_back( id ); break; } else { size_t pos = n.find_first_of( "(" ); if (( pos != std::string::npos ) && (( comp_fuzz.compare( get_fuzzy( n.substr(0,pos-1))) == 0 ) || ( comp_fuzz.compare(get_fuzzy( n.substr(pos+1,n.size()-pos-1 ))) == 0 ))) { system_list.push_back( n ); system_ids.push_back( id ); break; } } } } if ( system_list.size() < 1 ) { // Correct if we can based on the configured info source, // otherwise we error out switch( c.emulator.get_info_source() ) { case FeEmulatorInfo::Listxml: system_list.push_back( "Arcade" ); break; case FeEmulatorInfo::Steam: system_list.push_back( "PC" ); break; default: get_resource( "Error: None of the configured system identifier(s) are recognized by thegamesdb.net.", c.user_message ); std::cerr << " ! " << c.user_message << std::endl; return true; } } std::string emu_name = c.emulator.get_info( FeEmulatorInfo::Name ); std::string base_path = get_config_dir() + FE_SCRAPER_SUBDIR; base_path += emu_name + "/"; if ( c.scrape_art ) { // // Get emulator-specific images // for ( std::vector<int>::iterator iti=system_ids.begin(); iti != system_ids.end(); ++iti ) { std::string plat_string = PLAT_REQ; perform_substitution( plat_string, "$1", as_str( *iti ) ); q.add_buffer_task( HOSTNAME, plat_string, 0 ); q.do_next_task( status, err_req ); if ( status != sf::Http::Response::Ok ) { std::cout << " * Unable to get platform information. Status code: " << status << " (" << err_req << ")" << std::endl; continue; } body.clear(); q.pop_completed_task( temp, body ); FeGameDBArt my_art; FeGameDBPlatformParser gdbpp( my_art ); gdbpp.parse( body ); std::string hostn = HOSTNAME; std::string base_req = "banners/"; get_url_components( my_art.base, hostn, base_req ); std::string path = base_path + FLYER; if ( m_scrape_flyers && ( !my_art.flyer.empty() ) && ( !art_exists( path, emu_name ) )) { confirm_directory( base_path, FLYER ); q.add_file_task( hostn, base_req + my_art.flyer, path + emu_name ); } path = base_path + WHEEL; if ( m_scrape_wheels && ( !my_art.wheel.empty() ) && ( !art_exists( path, emu_name ) )) { confirm_directory( base_path, WHEEL ); q.add_file_task( hostn, base_req + my_art.wheel, path + emu_name ); } path = base_path + MARQUEE; if ( m_scrape_marquees && ( !my_art.marquee.empty() ) && ( !art_exists( path, emu_name ) )) { confirm_directory( base_path, MARQUEE ); q.add_file_task( hostn, base_req + my_art.marquee, path + emu_name ); } if ( m_scrape_fanart && !my_art.fanart.empty() ) { std::string path_base = base_path + FANART + emu_name + "/"; confirm_directory( base_path, "" ); confirm_directory( base_path + FANART, emu_name ); for ( std::vector<std::string>::iterator itr = my_art.fanart.begin(); itr != my_art.fanart.end(); ++itr ) { size_t start_pos = (*itr).find_last_of( "/\\" ); size_t end_pos = (*itr).find_last_of( '.' ); if (( start_pos != std::string::npos ) && ( !file_exists( path_base + (*itr).substr( start_pos+1 ) ) )) { if (( end_pos != std::string::npos ) && ( end_pos > start_pos )) { q.add_file_task( hostn, base_req + (*itr), path_base + (*itr).substr( start_pos+1, end_pos-start_pos-1 ) ); } } } } } } bool prefer_alt_filename = c.emulator.is_mess(); // // Build a map for looking up parents // ParentMapType parent_map; build_parent_map( parent_map, c.romlist, prefer_alt_filename ); // // Build a worklist of the roms where we need to lookup // std::vector<FeRomInfo *> worklist; worklist.reserve( c.romlist.size() ); for ( FeRomInfoListType::iterator itr=c.romlist.begin(); itr!=c.romlist.end(); ++itr ) { (*itr).set_info( FeRomInfo::Emulator, emu_name ); // Don't scrape for a clone if its parent has the same name // if ( has_same_name_as_parent( *itr, parent_map ) ) continue; if ( !c.scrape_art || m_scrape_fanart || ( m_scrape_flyers && (!has_artwork( *itr, "flyer" ) ) ) || ( m_scrape_wheels && (!has_artwork( *itr, "wheel" ) ) ) || ( m_scrape_snaps && (!has_image_artwork( *itr, "snap" ) ) ) || ( m_scrape_marquees && (!has_artwork( *itr, "marquee" ) ) ) ) worklist.push_back( &(*itr) ); } const int NUM_ARTS=5; // the number of scrape-able artwork types int done_count( 0 ); // // Set up our initial queue of network tasks // for ( unsigned int i=0; i<worklist.size(); i++ ) { std::string req_string = GAME_REQ; std::string game = url_escape( name_with_brackets_stripped( worklist[i]->get_info( FeRomInfo::Title ) ) ); perform_substitution( req_string, "$1", game ); // // If we don't need to scrape a wheel artwork, then add the specific platform to our request // If we are scraping a wheel, we want to be able to grab them where the game name (but // not the system) matches, so we don't limit ourselves by system... // if (( system_list.size() == 1 ) && ( !c.scrape_art || !m_scrape_wheels || has_artwork( *(worklist[i]), "wheel" ) )) { req_string += "&platform="; req_string += url_escape( system_list.front() ); } q.add_buffer_task( HOSTNAME, req_string, i ); } // // Create worker threads to process the queue, adding new tasks to download // artwork files where appropriate // FeNetWorker worker1( q ), worker2( q ), worker3( q ), worker4( q ); std::string aux; // // Process the output queue from our worker threads // while ( !( q.input_done() && q.output_done() ) ) { int id; std::string result; if ( q.pop_completed_task( id, result ) ) { if ( id < 0 ) { if (( id == FeNetTask::FileTask ) || ( id == FeNetTask::SpecialFileTask )) { std::cout << " + Downloaded: " << result << std::endl; c.download_count++; // find second last forward slash in filename // we assume that there will always be at least two size_t pos = result.find_last_of( "\\/" ); if ( pos != std::string::npos ) { pos = result.find_last_of( "\\/", pos-1 ); if ( pos != std::string::npos ) aux = result.substr( pos ); } } if ( id == FeNetTask::FileTask ) // we don't increment if id = FeNetTask::SpecialFileTask done_count++; } else { FeGameDBArt my_art; FeGameDBParser gdbp( system_list, *(worklist[id]), ( c.scrape_art ? &my_art : NULL ) ); gdbp.parse( result ); if ( c.scrape_art && !my_art.base.empty() ) { std::string hostn = HOSTNAME; std::string base_req = "banners/"; get_url_components( my_art.base, hostn, base_req ); const FeRomInfo &rom = *(worklist[id]); if ( m_scrape_flyers && ( !my_art.flyer.empty() ) && (!has_artwork( rom, "flyer" )) ) { std::string fname = base_path + FLYER; const std::string &altname = rom.get_info( FeRomInfo::AltRomname ); if ( prefer_alt_filename && !altname.empty() ) fname += rom.get_info( FeRomInfo::AltRomname ); else fname += rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, FLYER ); q.add_file_task( hostn, base_req + my_art.flyer, fname ); } else done_count++; if ( m_scrape_wheels && ( !my_art.wheel.empty() ) && (!has_artwork( rom, "wheel" )) ) { std::string fname = base_path + WHEEL; const std::string &altname = rom.get_info( FeRomInfo::AltRomname ); if ( prefer_alt_filename && !altname.empty() ) fname += rom.get_info( FeRomInfo::AltRomname ); else fname += rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, WHEEL ); q.add_file_task( hostn, base_req + my_art.wheel, fname ); } else done_count++; if ( m_scrape_marquees && (!my_art.marquee.empty() ) && (!has_artwork( rom, "marquee" )) ) { std::string fname = base_path + MARQUEE; const std::string &altname = rom.get_info( FeRomInfo::AltRomname ); if ( prefer_alt_filename && !altname.empty() ) fname += rom.get_info( FeRomInfo::AltRomname ); else fname += rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, MARQUEE ); q.add_file_task( hostn, base_req + my_art.marquee, fname ); } else done_count++; if ( m_scrape_snaps && (!my_art.snap.empty() ) && (!has_image_artwork( rom, "snap" )) ) { std::string fname = base_path + SNAP; const std::string &altname = rom.get_info( FeRomInfo::AltRomname ); if ( prefer_alt_filename && !altname.empty() ) fname += rom.get_info( FeRomInfo::AltRomname ); else fname += rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path, SNAP ); q.add_file_task( hostn, base_req + my_art.snap, fname ); } else done_count++; if ( m_scrape_fanart && !my_art.fanart.empty() ) { std::string fname_base = base_path + FANART; confirm_directory( base_path, "" ); const std::string &altname = rom.get_info( FeRomInfo::AltRomname ); if ( prefer_alt_filename && !altname.empty() ) { fname_base += rom.get_info( FeRomInfo::AltRomname ); confirm_directory( base_path + FANART, rom.get_info( FeRomInfo::AltRomname ) ); } else { fname_base += rom.get_info( FeRomInfo::Romname ); confirm_directory( base_path + FANART, rom.get_info( FeRomInfo::Romname ) ); } fname_base += "/"; bool done_first=false; // we only count the first fanart against our percentage completed... for ( std::vector<std::string>::iterator itr = my_art.fanart.begin(); itr != my_art.fanart.end(); ++itr ) { size_t start_pos = (*itr).find_last_of( "/\\" ); size_t end_pos = (*itr).find_last_of( '.' ); if (( start_pos != std::string::npos ) && ( !file_exists( fname_base + (*itr).substr( start_pos+1 ) ) )) { if (( end_pos != std::string::npos ) && ( end_pos > start_pos )) { q.add_file_task( hostn, base_req + (*itr), fname_base + (*itr).substr( start_pos+1, end_pos-start_pos-1 ), done_first ); done_first=true; } } } } else done_count++; } else { aux = (worklist[id])->get_info( FeRomInfo::Title ); done_count+=NUM_ARTS; } } if (( c.uiupdate ) && !worklist.empty() ) { int p = c.progress_past + done_count * c.progress_range / ( NUM_ARTS * worklist.size() ); if ( c.uiupdate( c.uiupdatedata, p, aux ) == false ) return false; } } else if ( q.output_done() ) { sf::Http::Response::Status status; std::string err_req; q.do_next_task( status, err_req ); if ( status != sf::Http::Response::Ok ) { std::cout << " * Error processing request. Status code: " << status << " (" << err_req << ")" << std::endl; } } else sf::sleep( sf::milliseconds( 10 ) ); } #endif return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { Fixed_Priority_Scheduler* scheduler=0; RTScheduling::Current_var current; int prio; int max_prio; ACE_Sched_Params::Policy sched_policy = ACE_SCHED_RR; int sched_scope = ACE_SCOPE_THREAD; long flags; if (sched_policy == ACE_SCHED_RR) flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_RR; else flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_FIFO; ACE_hthread_t main_thr_handle; ACE_Thread::self (main_thr_handle); max_prio = ACE_Sched_Params::priority_max (sched_policy, sched_scope); //FUZZ: disable check_for_lack_ACE_OS ACE_Sched_Params sched_params (sched_policy, max_prio); //FUZZ: enable check_for_lack_ACE_OS ACE_OS::sched_params (sched_params); if (ACE_Thread::getprio (main_thr_handle, prio) == -1) { if (errno == ENOTSUP) { ACE_ERROR((LM_ERROR, ACE_TEXT ("getprio not supported\n") )); } else { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n") ACE_TEXT ("thr_getprio failed"))); } } ACE_DEBUG ((LM_DEBUG, "(%t): main thread prio is %d\n", prio)); try { RTScheduling::Scheduler_var sched_owner; CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var object = orb->string_to_object (ior); Simple_Server_var server = Simple_Server::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); } if (enable_dynamic_scheduling) { ACE_DEBUG ((LM_DEBUG, "Dyn Sched enabled\n")); CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager"); TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ()); Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type; if (enable_yield) { disp_impl_type = Kokyu::DSRT_CV_BASED; } else { disp_impl_type = Kokyu::DSRT_OS_BASED; } ACE_NEW_RETURN (scheduler, Fixed_Priority_Scheduler (orb.in (), disp_impl_type, sched_policy, sched_scope), -1); sched_owner = scheduler; manager->rtscheduler (scheduler); CORBA::Object_var object = orb->resolve_initial_references ("RTScheduler_Current"); current = RTScheduling::Current::_narrow (object.in ()); } Worker worker1 (orb.in (), server.in (), current.in (), scheduler, 10, 15); if (worker1.activate (flags, 1, 0, max_prio) != 0) { ACE_ERROR ((LM_ERROR, "(%t|%T) cannot activate worker thread.\n")); } ACE_OS::sleep(2); Worker worker2 (orb.in (), server.in (), current.in (), scheduler, 12, 5); if (worker2.activate (flags, 1, 0, max_prio) != 0) { ACE_ERROR ((LM_ERROR, "(%t|%T) cannot activate scheduler thread in RT mode.\n")); } worker1.wait (); worker2.wait (); ACE_DEBUG ((LM_DEBUG, "(%t): wait for worker threads done in main thread\n")); if (do_shutdown) { if (enable_dynamic_scheduling) { FP_Scheduling::SegmentSchedulingParameter sched_param; sched_param.base_priority = 0; CORBA::Policy_var sched_param_policy = scheduler->create_segment_scheduling_parameter (sched_param); CORBA::Policy_ptr implicit_sched_param = 0; current->begin_scheduling_segment (0, sched_param_policy.in (), implicit_sched_param); } ACE_DEBUG ((LM_DEBUG, "(%t): about to call server shutdown\n")); server->shutdown (); ACE_DEBUG ((LM_DEBUG, "after shutdown call in main thread\n")); if (enable_dynamic_scheduling) { current->end_scheduling_segment (0); } } scheduler->shutdown (); ACE_DEBUG ((LM_DEBUG, "scheduler shutdown done\n")); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { CORBA::ORB_var orb_; int result = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) START OF SERVER TEST\n")); orb_ = CORBA::ORB_init (argc, argv, "myorb-server"); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); PortableServer::POA_var poa = root_poa; poa_manager->activate (); ACE_DEBUG((LM_INFO,"(%P|%t) ORB initialized\n")); // Creating the servant and activating it // Test_Idl_SharedIntf_i* intf_i = new Test_Idl_SharedIntf_i(orb_.in()); PortableServer::ServantBase_var base_var = intf_i; PortableServer::ObjectId_var intfId_var = poa->activate_object(base_var.in()); CORBA::Object_var obj_var = poa->id_to_reference(intfId_var.in()); Test_Idl::SharedIntf_var intf_var = Test_Idl::SharedIntf::_narrow(obj_var.in()); // Creating stringified IOR of the servant and writing it to a file. // CORBA::String_var intfString_var = orb_->object_to_string(intf_var.in()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", intfString_var.in ()); ACE_OS::fclose (output_file); ACE_DEBUG((LM_INFO,"(%P|%t) server IOR to %s\n", ior_output_file)); // Running ORB in separate thread Worker worker (orb_.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nr_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "Cannot activate server thread(s)"), -1); ACE_DEBUG((LM_INFO,"(%P|%t) Await client initialization\n")); poll ("./client.ior"); ACE_DEBUG((LM_INFO,"(%P|%t) Client IOR file was detected\n")); ACE_Mutex mutex; ACE_Condition<ACE_Mutex> stop_condition (mutex); { ACE_GUARD_RETURN (ACE_Mutex, guard, mutex, -1); Chatter worker2 (orb_.in (), ACE_TEXT("file://client.ior"), stop_condition); if (worker2.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0) { ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "Cannot activate chatty client threads"), -1); } do { stop_condition.wait (); ACE_DEBUG((LM_INFO,"(%P|%t) So far, %d/%d requests/replies have been processed\n", worker2.nrequests (), worker2.nreplies ())); } while (worker2.nrequests () < 1); worker.thr_mgr()->wait (); root_poa->destroy(1, 1); orb_->destroy(); ACE_DEBUG((LM_INFO,"(%P|%t) Server Test %C\n", (worker2.nrequests() == worker2.nreplies())?"succeeded":"failed")); result = (worker2.nrequests() == worker2.nreplies())? 0 : -1; } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Error: Exception caught:"); } ACE_OS::unlink ("server.ior"); return result; }