diff --git a/eo/src/paradisEO/comm/eoLocalListener.h b/eo/src/paradisEO/comm/eoLocalListener.h new file mode 100644 index 00000000..e106e3d0 --- /dev/null +++ b/eo/src/paradisEO/comm/eoLocalListener.h @@ -0,0 +1,156 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +// "eoLocalListener.h" + +// (c) OPAC Team, LIFL, 2002 + +/* This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: cahon@lifl.fr +*/ + +#ifndef eoLocalListener_h +#define eoLocalListener_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + A local listener to pack any coming message or, on contrary, to + send any data to another distributed process. + */ + +// Well, not very nice, but necessary for multiples header inclusions :-/ + +template class eoHeaderMessFrom ; +template class eoMessFrom ; +template class eoMessTo ; +template class eoEOReceiveMessFrom ; +template class eoEOSendMessFrom ; +template class eoPublishMessFrom ; +template class eoKillMessFrom ; + +template class eoLocalListener : public queue > { + +public : + + /** + Constructor + */ + + eoLocalListener (int _num_id) : + + num_id (_num_id), + comm (& MPI :: COMM_WORLD), // Shared communicator ... + req_EO (false) { + + gethostname (host_name, 255) ; // Host ? + } + + /** + Any distributed algorithm or agent has its own integer + identifiant, which lets us to distinguish them. + */ + + bool operator == (eoLocalListener & loc_listen) { + + return loc_listen.num_id == num_id ; + } + + /** + To import awaiting messages from other algorithms. + For each one, an action may be performed. + */ + + void update () { + + while (comm -> Iprobe (num_id, 0)) { + // While any more messages + + eoHeaderMessFrom header (* this) ; + eoMessFrom * mess ; + + /* The header identifies the kind of messages. + Currently, only four are necessary and so defined */ + + if (header == "eoEOReceiveMessTo") + mess = new eoEOReceiveMessFrom (* this) ; + else if (header == "eoEOSendMessTo") + mess = new eoEOSendMessFrom (* this) ; + else if (header == "eoPublishMessTo") + mess = new eoPublishMessFrom (* this) ; + else { + mess = new eoKillMessFrom (* this) ; + } + // Any side effects ? + mess -> operator () () ; + delete mess ; + } + } + + /** + String identifier of this algo/agent ? + */ + + string & label () { + + return name_id ; + } + + bool & need_immigration () { + + return req_EO ; + } + + int number () { + + return num_id ; + } + + void destroy () { + + cout << "Agent [" << name_id << "] stopped ..." << endl ; + MPI :: Finalize () ; + exit (0) ; + } + + char host_name [255] ; // Host string identifier + +private : + + MPI :: Comm * comm ; // MPI Communicator + + string name_id ; // String id. + int num_id ; // MPI id. + bool req_EO ; + + // Friendly classes + friend class eoMessFrom ; + friend class eoMessTo ; + +} ; + +#endif + + +