// Copyright (C) 2000 Stephen A. Torri // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Questions, comments or improvements should be sent to: // s.torri@lancaster.ac.uk or storri@stratos.net // // DGCC headers #include #include #include //******************************* // Variables //******************************* //******************************* // Constructor & Destructor //******************************* Overseer::Overseer() {} Overseer::Overseer(Job_List* jobs, Slave_Service* slv_serv) : jobs_(jobs), slv_serv_(slv_serv) { } Overseer::~Overseer() {} //******************************** // Runtime functions //******************************** //-------------------------------- // pre: Overseer is running and waiting to handle work. // post: Overseer is awakened and handling requests // function: This is the "main" function for the overseer. Whenever a slave // is registered or free the overseer is awakened to get a new job sent // to this slave. //-------------------------------- void Overseer::awaken() { Comms::Slave_ptr s_ptr; string file = "None"; string directory = "Somewhere"; Job_List_Item* nextJob = NULL; dout << "Overseer::awaken - Overseer awakened." << endl; // get slave s_ptr = slv_serv_ -> getFreeSlave(); if(CORBA::is_nil(s_ptr)){ cerr << "Overseer::awaken - getFreeSlave did not return a slave" << endl; exit(1); } if (jobs_ -> size() > 0 ) { dout << "Overseer::awaken - jobs_ is not 0. Work to be done." << endl; dout << "Overseer::awaken - get next Job" << endl; nextJob = jobs_ -> getJob(); while( nextJob -> isComment ) { dout << "Overseer::awaken - next job is a comment" << endl; dout << "Overseer::awaken - comment: " << nextJob->command << endl; nextJob = jobs_ -> getJob(); } } else { // stop slave we have a reference to now dout << "Overseer::awaken - calling stop_slave on slave reference" << endl; s_ptr -> stop_slave(true); // stop all slave in free list dout << "Overseer::awaken - calling stop_slave on all free slaves" << endl; for (int i = 0; i < (slv_serv_ -> getFreeListSize()); i++) { s_ptr = slv_serv_ -> returnSlave(0); s_ptr -> stop_slave(true); } // for all slave in busy list // wait for them to finish work then stop if ( ((slv_serv_ -> getBusyListSize()) == 0) && ((slv_serv_ -> getFreeListSize()) == 0)) { cout << "Overseer::awaken - Job done" << endl; cout << "\tExiting" << endl; exit(1); } } dout << "Overseer::awaken - nextJob.command = " << nextJob -> command << endl; dout << "Overseer::awaken - nextjob.directory = " << nextJob -> directory << endl; try { s_ptr -> send_command(nextJob -> command.c_str(), nextJob -> directory.c_str()); } catch(const CORBA::Exception &e){ cerr << "Overseer::awaken - CORBA Exception: " << e << endl; } }