void runnableTest() { Worker worker; Thread thread(&worker); thread.start(); worker.start(); CPPUNIT_ASSERT(worker.isQuit() == false); worker.quit(); const unsigned int result = thread.join(); CPPUNIT_ASSERT(result == 1); CPPUNIT_ASSERT(worker.isQuit() == true); worker.join(); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate worker threads\n"), 1); int timeout = 30; int now = 0; while (now < timeout && ((expect_ex_kind != TAO::FOE_NON && worker.received_ex_kind () != expect_ex_kind && worker.num_received_ex () != expect_num_ex) || expect_ex_kind == TAO::FOE_NON)) { std::cout << "."; now += 1; ACE_Time_Value tv (1, 0); orb->run (tv); } std::cout << std::endl; worker.done (); if (do_shutdown) { CORBA::Object_var object = orb->string_to_object (ior); Simple_Server_var server = Simple_Server::_narrow (object.in ()); server->shutdown (); } ACE_OS::sleep (1); orb->destroy (); worker.thr_mgr ()->wait (); if (worker.received_ex_kind () != expect_ex_kind || worker.num_received_ex () != expect_num_ex) { ACE_ERROR_RETURN ((LM_ERROR, ("(%P|%t)client: test failed - expected is different from received. " "expected %d/%d received %d/%d.\n"), expect_ex_kind, expect_num_ex, worker.received_ex_kind (), worker.num_received_ex()), 1); } ACE_DEBUG ((LM_DEBUG, "(%P|%t)client: test passed.\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main:"); return 1; } return 0; }
// // Shows the selected item's disk starting sector, size, and queue depth. // void CPageDisk::ShowSettings() { Manager *manager; Worker *worker; int disk_size; int disk_start; int queue_depth; // Get the values for the disk settings from memory. switch ( theApp.pView->m_pWorkerView->GetSelectedType() ) { case WORKER: worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); disk_size = worker->GetDiskSize( GenericDiskType ); disk_start = worker->GetDiskStart( GenericDiskType ); queue_depth = worker->GetQueueDepth( GenericDiskType ); break; case MANAGER: manager = theApp.pView->m_pWorkerView->GetSelectedManager(); disk_size = manager->GetDiskSize( GenericDiskType ); disk_start = manager->GetDiskStart( GenericDiskType ); queue_depth = manager->GetQueueDepth( GenericDiskType ); break; default: disk_size = theApp.manager_list.GetDiskSize( GenericDiskType ); disk_start = theApp.manager_list.GetDiskStart( GenericDiskType ); queue_depth = theApp.manager_list.GetQueueDepth( GenericDiskType ); } // If there is a displayable value, display it. Otherwise, hide the content // of the edit box. if ( disk_size == AMBIGUOUS_VALUE ) { m_EDiskSize.SetPasswordChar( 32 ); m_EDiskSize.Invalidate(); } else { m_EDiskSize.SetPasswordChar( 0 ); SetDlgItemInt( EDiskSize, disk_size ); } if ( disk_start == AMBIGUOUS_VALUE ) { m_EDiskStart.SetPasswordChar( 32 ); m_EDiskStart.Invalidate(); } else { m_EDiskStart.SetPasswordChar( 0 ); SetDlgItemInt( EDiskStart, disk_start ); } if ( queue_depth == AMBIGUOUS_VALUE ) { m_EQueueDepth.SetPasswordChar( 32 ); m_EQueueDepth.Invalidate(); } else { m_EQueueDepth.SetPasswordChar( 0 ); SetDlgItemInt( EQueueDepth, queue_depth ); } }
void CPageDisk::ShowTargetSelection() { Manager *manager; Worker *worker; HTREEITEM hiface; int w, i, expected_worker, iface_count, wkr_count; TargetSelType state; Target_Spec target_info; // Get the selected manager. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); // Get the first disk item from the target tree. hiface = m_TTargets.GetRootItem(); switch ( theApp.pView->m_pWorkerView->GetSelectedType() ) { case WORKER: // A worker is selected, show its assigned targets. worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); // Loop through the manager's disks, and mark which ones are selected // for the worker. iface_count = manager->InterfaceCount( GenericDiskType ); for ( i = 0; i < iface_count; i++ ) { if ( worker->IsTargetAssigned( manager->GetInterface(i, GenericDiskType))) SetSelectionCheck( hiface, TargetChecked ); else SetSelectionCheck( hiface, TargetUnChecked ); hiface = m_TTargets.GetNextSiblingItem( hiface ); } break; case MANAGER: // Show the targets assigned to a manager's workers if possible. expected_worker = 0; // Loop through the manager's disks, and see if they are assigned // to the expected worker. If not, gray all of them and return. iface_count = manager->InterfaceCount( GenericDiskType ); wkr_count = manager->WorkerCount( GenericDiskType ); for ( i = 0; i < iface_count; i++ ) { memcpy( &target_info, manager->GetInterface( i, GenericDiskType ), sizeof( Target_Spec ) ); state = TargetUnChecked; for ( w = 0; w < wkr_count; w++ ) { // If the disk is selected by any other than expected // worker, all the disk check boxes are grayed. if ( manager->GetWorker(w, GenericDiskType)->IsTargetAssigned( &target_info ) ) { if ( w != expected_worker || state != TargetUnChecked ) { SetAllCheck( TargetGrayed ); return; } state = TargetChecked; if ( ++expected_worker == wkr_count ) { expected_worker = 0; } } } SetSelectionCheck( hiface, state ); hiface = m_TTargets.GetNextSiblingItem( hiface ); } break; default: SetAllCheck( TargetGrayed ); break; } }
// // Stores the targets that have been selected by the user with the appropriate // worker. // void CPageDisk::StoreTargetSelection() { HTREEITEM hdisk; Manager *manager; Worker *worker; int target = 0; int next_worker; // Get the selected manager and worker. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); // Make sure we have a selected manager (or worker). if ( !manager ) { ErrorMessage( "Unexpectedly found no selected manager in " "CPageDisk::StoreTargetSelection." ); return; } if ( worker ) { // Assign the targets to the selected worker in the order that they // appear in the GUI. worker->RemoveTargets( GenericDiskType ); for ( hdisk = m_TTargets.GetRootItem(); hdisk; hdisk = m_TTargets.GetNextSiblingItem( hdisk ) ) { if ( GetSelectionCheck( hdisk ) == TargetChecked ) worker->AddTarget( manager->GetInterface( target, GenericDiskType ) ); target++; } } else { // Clear the assigned targets from all the manager's workers. manager->RemoveTargets( GenericDiskType ); // Set the first worker to receive targets. worker = manager->GetWorker( 0, GenericDiskType ); next_worker = 0; // Assign the targets to the workers of the selected manager. for ( hdisk = m_TTargets.GetRootItem(); hdisk; hdisk = m_TTargets.GetNextSiblingItem( hdisk ) ) { // If the disk is selected in the GUI, assign it to the expected // worker. if ( GetSelectionCheck( hdisk ) == TargetChecked ) { worker->AddTarget( manager->GetInterface( target, GenericDiskType )); // Update who the next worker to receive a target is. if ( ++next_worker >= manager->WorkerCount( GenericDiskType ) ) next_worker = 0; worker = manager->GetWorker( next_worker, GenericDiskType ); } target++; } } ShowTargetSelection(); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int priority = (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority); priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority); // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, priority, ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) { ACE_DEBUG ((LM_DEBUG, "server (%P|%t): user is not superuser, " "test runs in time-shared class\n")); } else ACE_ERROR ((LM_ERROR, "server (%P|%t): sched_params failed\n")); } try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var progress_object = orb->string_to_object (ior); Progress_var progress = Progress::_narrow (progress_object.in ()); ACE_Time_Value delay (0, interval); Peer_i peer; peer.init (orb.in (), progress.in (), delay); Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1); worker.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
void* Worker::dispatch(void *arg) { Worker *worker = (Worker *) arg; worker->handleTasks(); //delete worker; return 0; }
Worker* PeopleGenerator::GenerateWorker() { std::string spriteName = "Worker"; Worker* result = new Worker(); result->Speed = 1.5f; result->Happiness = 0.5f; result->Age = 30; if (rand() % 2) { result->PersonGender = Person::Gender::Male; spriteName += "_Male"; int blarand = rand() % 7; if (blarand == 0) { spriteName += "_Asian"; result->CleaningOffsets[0] = sf::Vector2f(153, 38); result->CleaningOffsets[1] = sf::Vector2f(-163, 48); result->CleaningOffsets[2] = sf::Vector2f(-49, -86); result->CleaningOffsets[3] = sf::Vector2f(33, -87); } if (blarand == 1) { spriteName += "_Black"; result->CleaningOffsets[0] = sf::Vector2f(230, -40); result->CleaningOffsets[1] = sf::Vector2f(-246, -30); result->CleaningOffsets[2] = sf::Vector2f(-110, -243); result->CleaningOffsets[3] = sf::Vector2f(23, -243); } if (blarand == 2) { spriteName += "_Grandpa"; } if (blarand == 3) { spriteName += "_Indian"; result->CleaningOffsets[0] = sf::Vector2f(39, 40); result->CleaningOffsets[1] = sf::Vector2f(-54, 50); result->CleaningOffsets[2] = sf::Vector2f(-63, -40); result->CleaningOffsets[3] = sf::Vector2f(0, -41); } if (blarand == 4) { spriteName += "_Intern"; } if (blarand == 5) { spriteName += "_Mexican"; result->CleaningOffsets[0] = sf::Vector2f(111, 39); result->CleaningOffsets[1] = sf::Vector2f(-126, 49); result->CleaningOffsets[2] = sf::Vector2f(-16, -47); result->CleaningOffsets[3] = sf::Vector2f(3, -46); } if (blarand == 6) { spriteName += "_Russian"; } } else { result->PersonGender = Person::Gender::Female; spriteName += "_Female"; int blarand = rand() % 2; if (blarand == 0) { spriteName += "_Bitch"; } if (blarand == 1) { spriteName += "_Intern"; result->CleaningOffsets[0] = sf::Vector2f(16, -90); result->CleaningOffsets[1] = sf::Vector2f(-2, -80); result->CleaningOffsets[2] = sf::Vector2f(-40, -143); result->CleaningOffsets[3] = sf::Vector2f(73, -161); } } std::wstring name = L""; if (result->PersonGender == Person::Gender::Male) { name += this->FirstNamesMale[rand() % this->FirstNamesMale.size()] + L" "; } else { name += this->FirstNamesFemale[rand() % this->FirstNamesFemale.size()] + L" "; } if (rand() % 100 < 5) { if (result->PersonGender == Person::Gender::Male) { name += this->FirstNamesMale[rand() % this->FirstNamesMale.size()] + L" "; } else { name += this->FirstNamesFemale[rand() % this->FirstNamesFemale.size()] + L" "; } if (rand() % 100 < 5) { if (result->PersonGender == Person::Gender::Male) { name += this->FirstNamesMale[rand() % this->FirstNamesMale.size()] + L" "; } else { name += this->FirstNamesFemale[rand() % this->FirstNamesFemale.size()] + L" "; } } } name += this->Surnames[rand() % this->Surnames.size()]; result->Name = name; result->Grid = this->Grid; result->CleaningEfficiency = (float)(rand() % 100 + 1) / 100.0f; result->CashieringEfficiency = (float)(rand() % 100 + 1) / 100.0f; result->RefillingEfficiency = (float)(rand() % 100 + 1) / 100.0f; result->calculateWageExpectency(); result->Messages = this->Messages; result->ThePathfinder = this->ThePathfinder; result->Sprite = this->TexHandler->GetSprite(spriteName + "_Front"); result->BackSprite = this->TexHandler->GetSprite(spriteName + "_Back"); result->SpriteName = spriteName; result->Origins = this->TexHandler->GetOrigins(spriteName); result->WorkerType = Worker::Type::Storager; result->Jobs = this->Jobs; result->TheStorage = this->ProductStorage; result->Wage = 7.00; result->WorkHours = 8; result->WorkDays[0] = true; result->WorkDays[1] = true; result->WorkDays[2] = true; result->WorkDays[3] = true; result->WorkDays[4] = true; result->WorkDays[5] = true; result->WorkDays[6] = false; result->Feed = this->Feed; return result; }
int Worker::main(void* _worker) { Worker* worker = static_cast<Worker*>(_worker); worker->loop(); return 0; }
int main(int argc, char const *argv[]) { Worker john; john.greeting(); exiter(); return 0; }
void Controller::restore(QString filename) { Worker *worker = new Worker(this, Controller::RESTORE, filename); worker->start(); }
void Controller::backup(QString filename) { Worker *worker = new Worker(this, Controller::BACKUP, filename); worker->start(); }
Tbb_Folder(Worker & w) :w_(w) { out_ = w.neutral_(nt2::meta::as_<result_type>()); }
static void *worker_run(void *arg) { Worker *worker = (Worker *)arg; worker->run(); return NULL; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate worker threads\n"), 1); int timeout = 30; int now = 0; while (now < timeout && ((expect_ex_kind == 0 && !worker.invocation_completed ()) || (expect_ex_kind != 0 && expect_ex_kind != worker.received_ex_kind ())) ) { std::cout << "." << std::flush; now += 1; ACE_Time_Value tv (1, 0); orb->run (tv); } ACE_ASSERT (now != 0); std::cout << std::endl; worker.done (); CORBA::Object_var object = orb->string_to_object (ior); Simple_Server_var server = Simple_Server::_narrow (object.in ()); server->shutdown (); ACE_OS::sleep (1); orb->destroy (); worker.thr_mgr ()->wait (); bool expect_no_ex = expect_ex_kind == TAO::FOE_NON && worker.num_received_ex () == 0 && worker.invocation_completed (); bool expect_ex_received = expect_ex_kind == worker.received_ex_kind () && worker.num_received_ex () > 0 && !worker.invocation_completed (); if (expect_no_ex || expect_ex_received) { ACE_DEBUG ((LM_DEBUG, "(%P|%t)client: test passed.\n")); return 0; } else { ACE_DEBUG ((LM_ERROR, "(%P|%t)client: test failed.\n")); return 1; } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main:"); return 1; } return 0; }
int main(int argc, char** argv){ MPI_Init(&argc, &argv); Worker worker; worker.run(); MPI_Finalize(); }
void TntnetImpl::run() { log_debug("worker-process"); _stop = false; if (_listeners.empty()) throwRuntimeError("no listeners defined"); log_debug(_listeners.size() << " listeners"); if (_listeners.size() >= _minthreads) { log_warn("at least one more worker than listeners needed - set MinThreads to " << _listeners.size() + 1); _minthreads = _listeners.size() + 1; } if (_maxthreads < _minthreads) { log_warn("MaxThreads < MinThreads - set MaxThreads = MinThreads = " << _minthreads); _maxthreads = _minthreads; } // initialize worker-process // SIGPIPE must be ignored ::signal(SIGPIPE, SIG_IGN); // create worker-threads log_info("create " << _minthreads << " worker threads"); for (unsigned i = 0; i < _minthreads; ++i) { log_debug("create worker " << i); Worker* s = new Worker(*this); s->create(); } // create poller-thread log_debug("start poller thread"); _pollerthread.start(); log_debug("start timer thread"); cxxtools::AttachedThread timerThread(cxxtools::callable(*this, &TntnetImpl::timerTask)); timerThread.start(); { cxxtools::MutexLock lock(allTntnetInstancesMutex); allRunningTntnetInstances.insert(this); } // mainloop cxxtools::Mutex mutex; while (!_stop) { { cxxtools::MutexLock lock(mutex); _queue.noWaitThreads.wait(lock); } if (_stop) break; if (Worker::getCountThreads() < _maxthreads) { log_info("create workerthread"); Worker* s = new Worker(*this); s->create(); } else log_info("max worker-threadcount " << _maxthreads << " reached"); if (TntConfig::it().threadStartDelay > 0) usleep(TntConfig::it().threadStartDelay.totalUSecs()); } log_info("stopping TntnetImpl"); { cxxtools::MutexLock lock(allTntnetInstancesMutex); allRunningTntnetInstances.erase(this); } log_info("stop listener"); for (listeners_type::iterator it = _listeners.begin(); it != _listeners.end(); ++it) (*it)->terminate(); log_info("stop poller thread"); _poller.doStop(); _pollerthread.join(); log_info("stop timer thread"); timerThread.join(); if (Worker::getCountThreads() > 0) { log_info("wait for " << Worker::getCountThreads() << " worker threads to stop"); while (Worker::getCountThreads() > 0) { log_debug("wait for worker threads to stop; " << Worker::getCountThreads() << " left"); usleep(100); } } log_debug("destroy listener"); for (listeners_type::iterator it = _listeners.begin(); it != _listeners.end(); ++it) delete *it; _listeners.clear(); HttpReply::postRunCleanup(); HttpRequest::postRunCleanup(); log_info("all threads stopped"); }
int main(int argc, char* argv[]){ Worker wk; wk.Start(); return 0; }
int Query_Processor::svc() { Worker * worker; int ret,cached; //ScribeProxyClient *client=NULL; std::vector<std::string> category; int queueLen = 0; cerr<<"initialized thread..."<<endl; pthread_barrier_wait(processor_init); while ((worker = m_task_list.get()) != NULL) { queueLen = m_task_list.len(); ret = parse_worker(worker); if(ret >= 0) { // TODO: process the request and fill the result in result //snprintf(result, MAX_HTTP_CONTENT_LENGTH, "<h1>Hello world!</h1>Query string: %s", worker->querystring); ret = 0; //clock_t start=clock(); //Chat Server string szOrigInput = worker->querystring; string res = ""; //usleep(300000); if(szOrigInput == "register_slave") { std::string server_ip = get_param("server_ip=", worker->uri); std::string recv_realtime_req_str = get_param("recv_real_time_request=", worker->uri); bool recv_realtime_req = (recv_realtime_req_str == "True")?true:false; m_validation->registerSlave(server_ip, recv_realtime_req); } else if(szOrigInput == "validate") { string req = get_param("req", worker->uri); string type = get_param("type", worker->uri); m_validation->handleValidReq(req, type, res); } // copy the result into worker int max_len = 65536000; worker->result = (char*)worker->GetMem(max_len); if (worker->result == NULL) { pthread_mutex_unlock(&gMutex);//解锁 m_httpserver->retrieve_worker(worker); continue; } if("" != res) { //int max_len = MAX_HTTP_CONTENT_LENGTH; worker->result_len = std::min(res.length(), size_t(max_len) - 1) + 1; memcpy(worker->result, res.c_str(), worker->result_len); worker->result[worker->result_len] = 0; _INFO("[ Result: %s]", worker->result); } //pthread_mutex_unlock(&gMutex);//解锁 }//if int retlen = (ret==-1)?-1:worker->result_len; const char * queryStr = (worker->query_len<=0)?"NULL":worker->querystring; _INFO("[Observer,cost=%d,ret=%d,querystring=%s,Owner=OP]",WASTE_TIME_US(worker->receive_time),retlen,queryStr); m_httpserver->retrieve_worker(worker); }//while cerr<<"closed thread!!"<<endl; return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { Fixed_Priority_Scheduler* scheduler=0; RTScheduling::Current_var current; long flags; int sched_policy = ACE_SCHED_RR; int sched_scope = ACE_SCOPE_THREAD; 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; task_stats.init (100000); try { RTScheduling::Scheduler_var sched_owner; CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; if (enable_dynamic_scheduling) { 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 ()); } Simple_Server_i server_impl (orb.in (), current.in (), task_stats, enable_yield); Simple_Server_var server = server_impl._this (); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { 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", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } poa_manager->activate (); Worker worker (orb.in ()); if (worker.activate (flags, nthreads, 0, ACE_Sched_Params::priority_max(sched_policy, sched_scope)) != 0) { ACE_ERROR ((LM_ERROR, "Cannot activate threads in RT class.", "Trying to activate in non-RT class\n")); flags = THR_NEW_LWP | THR_JOINABLE | THR_BOUND; if (worker.activate (flags, nthreads) != 0) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate server threads\n"), 1); } } worker.wait (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); ACE_DEBUG ((LM_DEBUG, "shutting down scheduler\n")); scheduler->shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } ACE_DEBUG ((LM_DEBUG, "Exiting main...\n")); task_stats.dump_samples (ACE_TEXT("timeline.txt"), ACE_TEXT("Time\t\tGUID")); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; Simple_Server_i *server_impl = 0; ACE_NEW_RETURN (server_impl, Simple_Server_i (orb.in ()), -1); PortableServer::ServantBase_var owner_transfer(server_impl); PortableServer::ObjectId_var id = root_poa->activate_object (server_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Simple_Server_var server = Simple_Server::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } poa_manager->activate (); Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate client threads\n"), 1); SelfClient selfabuse (orb.in(), server.in(), niterations); if (selfabuse.activate (THR_NEW_LWP | THR_JOINABLE, nclient_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate abusive threads\n"), 1); selfabuse.thr_mgr()->wait(); worker.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) event loop finished\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int handleConnection(ClientSocket* socket) { Worker* worker = new Worker(socket); worker->run(); return 0; }
//--------- Begin of function Firm::spy_birbe_succeed_chance ---------// // // The money the spy offers to bribe the unit. // // <int> bribeAmount - the amount offered // <short> birberSpyRecno - spy recno of the briber // <short> workerId - if 0, then bribe the overseer, // if >0, then bribe a worker. // // return: <int> 1 - bribing succeeded // 0 - bribing failed // int Firm::spy_bribe_succeed_chance(int bribeAmount, short briberSpyRecno, short workerId) { Spy* spyPtr = spy_array[briberSpyRecno]; err_when( spyPtr->spy_place != SPY_FIRM ); err_when( spyPtr->spy_place_para != firm_recno ); //---- if the bribing target is a worker ----// int unitLoyalty, unitRaceId, targetSpyRecno, unitCommandPower; if( workerId ) { Worker* workerPtr = worker_array+workerId-1; unitLoyalty = workerPtr->loyalty(); unitRaceId = workerPtr->race_id; unitCommandPower = 0; targetSpyRecno = workerPtr->spy_recno; } else if( overseer_recno ) { Unit* unitPtr = unit_array[overseer_recno]; unitLoyalty = unitPtr->loyalty; unitRaceId = unitPtr->race_id; unitCommandPower = unitPtr->commander_power(); targetSpyRecno = unitPtr->spy_recno; } else err_here(); err_when( unitRaceId < 1 || unitRaceId > MAX_RACE ); //---- determine whether the bribe will be successful ----// int succeedChance; if( targetSpyRecno ) // if the bribe target is also a spy { err_when( spy_array[targetSpyRecno]->true_nation_recno == spyPtr->true_nation_recno ); // the player shouldn't be able to bribe units of his own succeedChance = 0; } else { succeedChance = spyPtr->spy_skill - unitLoyalty - unitCommandPower + (int) nation_array[spyPtr->true_nation_recno]->reputation + 200 * bribeAmount / MAX_BRIBE_AMOUNT; //-- the chance is higher if the spy or the spy's king is racially homongenous to the bribe target, int spyKingRaceId = nation_array[ spyPtr->true_nation_recno ]->race_id; succeedChance += race_res.is_same_race(spyPtr->race_id, unitRaceId) * 10 + race_res.is_same_race(spyKingRaceId, unitRaceId) * 10; if( unitLoyalty > 60 ) // harder for bribe units with over 60 loyalty succeedChance -= (unitLoyalty-60); if( unitLoyalty > 70 ) // harder for bribe units with over 70 loyalty succeedChance -= (unitLoyalty-70); if( unitLoyalty > 80 ) // harder for bribe units with over 80 loyalty succeedChance -= (unitLoyalty-80); if( unitLoyalty > 90 ) // harder for bribe units with over 90 loyalty succeedChance -= (unitLoyalty-90); if( unitLoyalty == 100 ) succeedChance = 0; } return succeedChance; }
int main(int argc, char **argv) { std::srand ( 0 ); std::cout.precision(10); Config config; if (!config.fromCommandline(argc, argv)) { return 1; } #ifdef __ANDROID__ std::cout << "Parsed the commandline" << std::endl; #endif Worker worker; liboscar::Static::OsmCompleter & osmCompleter = worker.completer; osmCompleter.setAllFilesFromPrefix(config.inFileName); #ifdef __ANDROID__ std::cout << "Trying to energize" << std::endl; #endif try { osmCompleter.energize(); } catch (const std::exception & e) { std::cerr << "Error occured: " << e.what() << std::endl; return 1; } #ifdef __ANDROID__ std::cout << "Doing the work" << std::endl; #endif bool allOk = true; for(std::size_t i(0), s(config.workItems.size()); i < s; ++i) { Config::WorkItem & workItem = config.workItems[i]; // try { switch (workItem.type) { case Config::WorkItem::SELECT_TEXT_COMPLETER: worker.selectTextCompleter(*workItem.data->as<WD_SelectTextCompleter>()); break; case Config::WorkItem::SELECT_GEO_COMPLETER: worker.selectGeoCompleter(*workItem.data->as<WD_SelectGeoCompleter>()); case Config::WorkItem::PRINT_SELECTED_TEXT_COMPLETER: worker.printSelectedTextCompleter(); break; case Config::WorkItem::PRINT_SELECTED_GEO_COMPLETER: worker.printSelectedGeoCompleter(); break; case Config::WorkItem::GH_ID_2_STORE_ID: worker.ghId2StoreId(*workItem.data->as<WD_GhId2StoreId>()); break; case Config::WorkItem::DUMP_INDEX: worker.dumpIndex(*workItem.data->as<WD_DumpIndex>()); break; case Config::WorkItem::DUMP_ITEM: worker.dumpItem(*workItem.data->as<WD_DumpItem>()); break; case Config::WorkItem::DUMP_ALL_ITEMS: worker.dumpAllItems(*workItem.data->as<WD_DumpAllItems>()); break; case Config::WorkItem::DUMP_ALL_ITEM_TAGS_WITH_INHERITED_TAGS: worker.dumpAllItemTagsWithInheritedTags(*workItem.data->as<WD_DumpAllItemTagsWithInheritedTags>()); break; case Config::WorkItem::DUMP_GH_REGION: worker.dumpGhRegion(*workItem.data->as<WD_DumpGhRegion>()); break; case Config::WorkItem::DUMP_GH_CELL: worker.dumpGhCell(*workItem.data->as<WD_DumpGhCell>()); break; case Config::WorkItem::DUMP_GH_CELL_PARENTS: worker.dumpGhCellParents(*workItem.data->as<WD_DumpGhCellParents>()); break; case Config::WorkItem::DUMP_GH_CELL_ITEMS: worker.dumpGhCellItems(*workItem.data->as<WD_DumpGhCellItems>()); break; case Config::WorkItem::DUMP_GH_REGION_CHILDREN: worker.dumpGhRegionChildren(*workItem.data->as<WD_DumpGhRegionChildren>()); break; case Config::WorkItem::DUMP_GH_REGION_ITEMS: worker.dumpGhRegionItems(*workItem.data->as<WD_DumpGhRegionItems>()); break; case Config::WorkItem::DUMP_GH: worker.dumpGh(*workItem.data->as<WD_DumpGh>()); break; case Config::WorkItem::DUMP_KEY_STRING_TABLE: worker.dumpKeyStringTable(*workItem.data->as<WD_DumpKeyStringTable>()); break; case Config::WorkItem::DUMP_VALUE_STRING_TABLE: worker.dumpValueStringTable(*workItem.data->as<WD_DumpValueStringTable>()); break; case Config::WorkItem::DUMP_ITEM_TAGS: worker.dumpItemTags(*workItem.data->as<WD_DumpItemTags>()); break; case Config::WorkItem::PRINT_STATS: worker.printStats(*workItem.data->as<WD_PrintStats>()); break; case Config::WorkItem::PRINT_PAPER_STATS_DB: worker.printPaperStatsDb(*workItem.data->as<WD_PrintPaperStatsDb>()); break; case Config::WorkItem::PRINT_PAPER_STATS_GH: worker.printPaperStatsGh(*workItem.data->as<WD_PrintPaperStatsGh>()); break; case Config::WorkItem::PRINT_CTC_STATS: worker.printCTCStorageStats(*workItem.data->as<WD_PrintCTCStorageStats>()); break; case Config::WorkItem::PRINT_CTC_SELECTIVE_STATS: worker.printCTCSelectiveStorageStats(*workItem.data->as<WD_PrintCTCSelectiveStorageStats>()); break; case Config::WorkItem::PRINT_CQR_DATA_SIZE: worker.printCQRDataSize(*workItem.data->as<WD_PrintCQRDataSize>()); break; case Config::WorkItem::LIST_COMPLETERS: worker.listCompleters(); break; case Config::WorkItem::INTERACTIVE_PARTIAL: worker.interactivePartial(*workItem.data->as<WD_InteractivePartial>()); break; case Config::WorkItem::INTERACTIVE_SIMPLE: worker.interactiveSimple(*workItem.data->as<WD_InteractiveSimple>()); break; case Config::WorkItem::INTERACTIVE_FULL: worker.interactiveFull(*workItem.data->as<WD_InteractiveFull>()); break; case Config::WorkItem::COMPLETE_STRING_PARTIAL: worker.completeStringPartial(*workItem.data->as<WD_CompleteStringPartial>()); break; case Config::WorkItem::COMPLETE_STRING_SIMPLE: worker.completeStringSimple(*workItem.data->as<WD_CompleteStringSimple>()); break; case Config::WorkItem::COMPLETE_STRING_FULL: worker.completeStringFull(*workItem.data->as<WD_CompleteStringFull>()); break; case Config::WorkItem::COMPLETE_STRING_CLUSTERED: worker.completeStringClustered(*workItem.data->as<WD_CompleteStringClustered>(), false); break; case Config::WorkItem::COMPLETE_STRING_CLUSTERED_TREED_CQR: worker.completeStringClustered(*workItem.data->as<WD_CompleteStringClustered>(), true); break; case Config::WorkItem::COMPLETE_FROM_FILE_PARTIAL: worker.completeFromFilePartial(*workItem.data->as<WD_CompleteFromFilePartial>()); break; case Config::WorkItem::COMPLETE_FROM_FILE_SIMPLE: worker.completeFromFileSimple(*workItem.data->as<WD_CompleteFromFileSimple>()); break; case Config::WorkItem::COMPLETE_FROM_FILE_FULL: worker.completeFromFileFull(*workItem.data->as<WD_CompleteFromFileFull>()); break; case Config::WorkItem::COMPLETE_FROM_FILE_CLUSTERED: worker.completeFromFileClustered(*workItem.data->as<WD_CompleteFromFileClustered>(), false); break; case Config::WorkItem::COMPLETE_FROM_FILE_CLUSTERED_TREED_CQR: worker.completeFromFileClustered(*workItem.data->as<WD_CompleteFromFileClustered>(), true); break; case Config::WorkItem::SYMDIFF_ITEMS_COMPLETERS: worker.symDiffCompleters(*workItem.data->as<WD_SymDiffItemsCompleters>()); case Config::WorkItem::CONSISTENCY_CHECK: worker.consistencyCheck(*workItem.data->as<WD_ConsistencyCheck>()); break; case Config::WorkItem::CREATE_COMPLETION_STRINGS: worker.createCompletionStrings(*workItem.data->as<WD_CreateCompletionStrings>()); break; case Config::WorkItem::BENCHMARK: worker.benchmark(*workItem.data->as<WD_Benchmark>()); break; default: throw std::runtime_error("Bad operation. Unkown work item."); }; // } // catch(std::exception & e) { // std::cerr << "Error occured: " << e.what() << std::endl; // allOk = false; // } } return (allOk ? 0 : 1); }
// // Enabling controls on the form for user access. // void CPageDisk::EnableWindow( BOOL enable ) { Manager *manager; Worker *worker; CWnd *last_focused; // Only enable things if a test is not running. if ( theApp.test_state != TestIdle ) return; // Get the current worker and manager selections. manager = theApp.pView->m_pWorkerView->GetSelectedManager(); worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); switch ( theApp.pView->m_pWorkerView->GetSelectedType() ) { case WORKER: // Enable the target list only if the selected worker is a disk worker. enable = enable && IsType( worker->Type(), GenericDiskType ); m_TTargets.EnableWindow( enable ); // If the selected worker is not a disk worker, switch to the network // target page. if ( !IsType( worker->Type(), GenericDiskType ) && theApp.pView->m_pPropSheet->GetActiveIndex() == DISK_PAGE ) { last_focused = GetFocus(); theApp.pView->m_pPropSheet->SetActivePage( NETWORK_PAGE ); if ( last_focused ) last_focused->SetFocus(); } break; case MANAGER: // Enable the target list only if the selected manager has a // disk worker. enable = enable && manager->WorkerCount( GenericDiskType ); m_TTargets.EnableWindow( enable ); // If the selected manager has no disk workers but has network server // workers, switch to the network target page. if ( !manager->WorkerCount( GenericDiskType ) && manager->WorkerCount( GenericServerType ) && theApp.pView->m_pPropSheet->GetActiveIndex() == DISK_PAGE ) { enable = FALSE; last_focused = GetFocus(); theApp.pView->m_pPropSheet->SetActivePage( NETWORK_PAGE ); if ( last_focused ) last_focused->SetFocus(); } break; case ALL_MANAGERS: // Only enable the connection rate controls if there exists a // GenericDiskType worker. enable = enable && theApp.manager_list.WorkerCount( GenericDiskType ); // The target list is disabled for all managers. m_TTargets.EnableWindow( FALSE ); } // Enable the connection rate check box. m_CConnectionRate.EnableWindow( enable ); // Enable the connection rate edit box and spin control if the connection // rate check box is checked. m_EConnectionRate.EnableWindow( enable && m_CConnectionRate.GetCheck() == 1 ); m_SConnectionRate.EnableWindow( enable && m_CConnectionRate.GetCheck() == 1 ); // Enable the disk parameter controls. m_EDiskStart.EnableWindow( enable ); m_EDiskSize.EnableWindow( enable ); m_EQueueDepth.EnableWindow( enable ); // The spin button sometimes needs to be redrawn even if it didn't change // when the edit box was partially redrawn. m_SConnectionRate.Invalidate( TRUE ); // Redraw the page. Note that all the child windows will be redrawn too. // Also note that only windows that have already been invalidated will get // redrawn, avoiding much flicker. RedrawWindow( NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_ERASE ); }
// // Saving the access specification list to a result file. // Saves only the currently active access specs. // BOOL AccessSpecList::SaveResults( ostream& outfile ) { int i, j; int access_count, manager_count, worker_count, current_access_index; Manager *mgr; Worker *wkr; BOOL *spec_active; Test_Spec *spec; outfile << "'Access specifications" << endl; access_count = Count(); spec_active = new BOOL[ access_count ]; // Determine which access specs are active for the current test // Start by marking all access specs inactive. for ( i = 1; i < access_count; i++ ) { spec_active[i] = FALSE; } current_access_index = theApp.pView->GetCurrentAccessIndex(); // Now go through all the workers and mark each worker's current access spec // as active, IF the worker is actually doing anything in this test. manager_count = theApp.manager_list.ManagerCount(); for ( i = 0; i < manager_count; i++ ) { mgr = theApp.manager_list.GetManager( i ); worker_count = mgr->WorkerCount(); for ( j = 0; j < worker_count; j++ ) { wkr = mgr->GetWorker( j ); if ( wkr->ActiveInCurrentTest() ) { spec_active[ IndexByRef( wkr->GetAccessSpec( current_access_index ) ) ] = TRUE; } } } // Save all the active access specs except the idle spec. for ( i = 1; i < access_count; i++ ) { if ( !spec_active[i] ) continue; spec = Get( i ); outfile << "'Access specification name,default assignment" << endl; outfile << spec->name << "," << spec->default_assignment << endl; // Write access specifications to a file, data comma separated. outfile << "'size,% of size,% reads,% random,delay,burst,align,reply" << endl; for ( int line_index = 0; line_index < MAX_ACCESS_SPECS; line_index++ ) { if ( spec->access[line_index].of_size == IOERROR ) break; outfile << spec->access[line_index].size << "," << spec->access[line_index].of_size << "," << spec->access[line_index].reads << "," << spec->access[line_index].random << "," << spec->access[line_index].delay << "," << spec->access[line_index].burst << "," << spec->access[line_index].align << "," << spec->access[line_index].reply << endl; } } outfile << "'End access specifications" << endl; delete spec_active; return TRUE; }
// // Displays the connection rate settings for the current selection in the // worker view. If the selection is a manager or all managers, displays // a value if all the children's values are the same. // void CPageDisk::ShowConnectionRate() { Manager *manager; Worker *worker; int trans_per_conn=0; int test_connection_rate=0; switch ( theApp.pView->m_pWorkerView->GetSelectedType() ) { case WORKER: // update controls with worker's data worker = theApp.pView->m_pWorkerView->GetSelectedWorker(); if ( IsType( worker->Type(), GenericDiskType ) ) { trans_per_conn = worker->GetTransPerConn( GenericDiskType ); test_connection_rate = worker->GetConnectionRate( GenericDiskType ); } break; case MANAGER: manager = theApp.pView->m_pWorkerView->GetSelectedManager(); trans_per_conn = manager->GetTransPerConn( GenericDiskType ); test_connection_rate = manager->GetConnectionRate( GenericDiskType ); break; default: trans_per_conn = theApp.manager_list.GetTransPerConn( GenericDiskType ); test_connection_rate = theApp.manager_list.GetConnectionRate( GenericDiskType ); break; } // If the test connection rate settings are different between a manager's // workers, set the state of the check box to AUTO3STATE and disable the // edit box and spin control. SetDlgItemInt( EConnectionRate, trans_per_conn ); if ( test_connection_rate == AMBIGUOUS_VALUE ) { m_CConnectionRate.SetButtonStyle( BS_AUTO3STATE ); m_EConnectionRate.SetPasswordChar( 32 ); m_EConnectionRate.Invalidate( TRUE ); // Set check box to undetermined state. CheckDlgButton( CConnectionRate, 2 ); } else { m_CConnectionRate.SetButtonStyle( BS_AUTOCHECKBOX ); CheckDlgButton( CConnectionRate, test_connection_rate ); if ( test_connection_rate == ENABLED_VALUE && trans_per_conn != AMBIGUOUS_VALUE ) { m_EConnectionRate.SetPasswordChar( 0 ); } else { m_EConnectionRate.SetPasswordChar( 32 ); m_EConnectionRate.Invalidate(); } } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; TestServer *test_impl = 0; ACE_NEW_RETURN (test_impl, TestServer (), 1); PortableServer::ServantBase_var owner_transfer(test_impl); PortableServer::ObjectId_var id = root_poa->activate_object (test_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::TestServer_var test = Test::TestServer::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (test.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", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); // Run a CORBA worker thread Worker work (orb.in()); work.activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, 1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - waiting for client to call\n")); ACE_OS::sleep (10); if (test_impl->got_callback() == false) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - client did not make call\n")); return 1; } ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - making repeated calls to client\n")); for (int i = 0; i < 10; i++) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - calling client attempt %d\n", i)); test_impl->make_callback(); } ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - stopping client\n")); test_impl->shutdown_client(); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - test completed\n")); orb->shutdown (); // shutdown our ORB work.wait (); // wait for the worker to finish root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int main() { Worker w; int dataThree = w.doubleValue(); cout<<dataThree<<endl; }
void CPageNetwork::StoreTargetSelection() { HTREEITEM hmgr, hifc; Manager *manager; Worker *worker; Target_Spec new_target; int local_interface_no; int interface_no; int target_count = 0; int expected_worker = 0; // Make sure we have a selected manager (or worker). manager = theApp.pView->m_pWorkerView->GetSelectedManager(); if (!manager) { ErrorMessage("Unexpectedly found no selected manager in " "CPageNetwork::StoreTargetSelection."); return; } // Count the number of assigned targets. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { for (hifc = m_TTargets.GetChildItem(hmgr); hifc; hifc = m_TTargets.GetNextSiblingItem(hifc)) { if (GetSelectionCheck(hifc) == TargetChecked) target_count++; } } // Make sure we are not assigning more targets than we have workers. if (target_count > manager->WorkerCount(GenericServerType)) { ErrorMessage("You do not have enough network workers to assign all " "the selected targets."); // Restore the last selection. ShowTargetSelection(); // Set the focus to the target list. ::SetFocus(m_TTargets); return; } // The selection will succeed. Remove current network clients. if (worker = theApp.pView->m_pWorkerView->GetSelectedWorker()) worker->RemoveTargets(GenericNetType); else manager->RemoveTargets(GenericNetType); // Get the assigned local interface to use for the connection. local_interface_no = m_DInterface.GetCurSel(); // Assign the targets. // Loop through all managers. for (hmgr = m_TTargets.GetRootItem(); hmgr; hmgr = m_TTargets.GetNextSiblingItem(hmgr)) { // Loop through all interfaces of a manager. interface_no = 0; for (hifc = m_TTargets.GetChildItem(hmgr); hifc; hifc = m_TTargets.GetNextSiblingItem(hifc)) { if (GetSelectionCheck(hifc) == TargetChecked) { // Are we dealing with a worker or a manager? if (!worker) { // A manager is selected. Get the next available // network server worker. worker = manager->GetWorker(expected_worker++, GenericServerType); } // Get the interface of the selected target from the manager // whose interface is selected. memcpy(&new_target, ((Manager *) m_TTargets.GetItemData(hmgr))->GetInterface(interface_no, GenericNetType), sizeof(Target_Spec)); // Set the local and remote addresses of the connection. // The remote address used by the server is stored as the local // address for some manager's interface. if (IsType(new_target.type, TCPClientType)) { strcpy(new_target.tcp_info.remote_address, new_target.name); // Verify that the locally assigned interface matches the // selected target's interface. if (local_interface_no >= manager->InterfaceCount(GenericTCPType)) { // Use the first TCP interface. local_interface_no = 0; m_DInterface.SetCurSel(local_interface_no); } } else if (IsType(new_target.type, VIClientType)) { strcpy(new_target.vi_info.remote_nic_name, new_target.name); memcpy(&new_target.vi_info.remote_address, &new_target.vi_info.local_address, VI_ADDRESS_SIZE); // Verify that the locally assigned interface matches the // selected target's interface. if (local_interface_no <= manager->InterfaceCount(GenericTCPType)) { // Use the first VI interface. local_interface_no = manager->InterfaceCount(GenericTCPType); m_DInterface.SetCurSel(local_interface_no); } } else { ErrorMessage("Invalid target type for new target in " "CPageNetwork::StoreTargetSelection()."); } worker->AddTarget(&new_target); // Record information about what local interface the server // should use. worker->SetLocalNetworkInterface(local_interface_no); // Create the corresponding network client. worker->CreateNetClient((Manager *) m_TTargets.GetItemData(hmgr), new_target.type); // Clear the worker pointer so that the next iteration // through the loop (for a manager with multiple selected // interfaces) will get the next available network server. worker = NULL; } interface_no++; } } }