1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: dom nov 16 13:03:33 ART 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/plant.h"
29 #include <glibmm/timer.h>
30 #include <sigc++/slot.h>
46 cerr << __FILE__ << ": destructor." << endl;
48 // Termino transmisiones.
49 Glib::Mutex::Lock lock(transmissions_mutex);
50 for (TransmitterList::iterator trans = transmissions.end();
51 trans != transmissions.end(); trans++) {
52 (*trans)->finish(true);
56 Plant::Plant(const string& filename): simulator(filename), filename(filename) {
58 cerr << __FILE__ << ": constructor. filename = " << filename << endl;
61 /* simulator.add_pump("bomba1");
62 simulator.add_conduct("c");
63 simulator.add_conduct("c1");
64 simulator.add_drainage("d");
65 simulator.add_tank("tanque");
67 simulator.connect("bomba1", "c", Model::IConector::OUT);
68 simulator.connect("c", "tanque", Model::IConector::OUT);
69 simulator.connect("tanque", "c1", Model::IConector::OUT);
70 simulator.connect("c1", "d", Model::IConector::OUT);
74 void Plant::real_run(void) {
76 cerr << __FILE__ << ": real_run." << endl;
80 Glib::Mutex::Lock lock(transmissions_mutex);
81 for (TransmitterList::iterator i = transmissions.begin();
82 i != transmissions.end(); i++) {
83 (*i)->send(simulator.get_state_as_xml());
85 Glib::usleep(1000000);
89 bool Plant::transmission_start(string& host, Connection::Port& port) {
90 Glib::Mutex::Lock lock(transmissions_mutex);
91 for (TransmitterList::iterator i = transmissions.begin();
92 i != transmissions.end(); i++) {
93 if (((*i)->get_host() == host) && ((*i)->get_port() == port)) {
99 trans = new Transmitter(host, port);
100 } catch (...) { // TODO - Hace mas selectivo el catch?
104 transmissions.push_back(trans);
109 bool Plant::transmission_stop(const string& host,
110 const Connection::Port& port) {
111 Glib::Mutex::Lock lock(transmissions_mutex);
112 for (TransmitterList::iterator i = transmissions.begin();
113 i != transmissions.end(); i++) {
114 if (((*i)->get_host() == host) && ((*i)->get_port() == port)) {
119 return false; // No la encontró.
122 const string Plant::get_xml(void) const {
125 ifstream ifs(filename.c_str());
127 copy(istream_iterator<char>(ifs), istream_iterator<char>(),
128 ostream_iterator<char>(oss));
129 } catch (...) { // TODO hacerlo mas selectivo?
136 bool Plant::transmission_exists(const string& host,
137 const Connection::Port& port) {
138 Glib::Mutex::Lock lock(transmissions_mutex);
139 for (TransmitterList::const_iterator i = transmissions.begin();
140 i != transmissions.end(); i++) {
141 if (((*i)->get_host() == host) && ((*i)->get_oprt() == port)) {
145 return false; // No la encontró.
149 //const std::string& Plant::get_name(void) const {
153 /// \todo FIXME esto deberia estar protegido por un mutex.
154 //Plant::SignalUpdated& Plant::signal_updated(void) {
158 } // namespace Server
160 } // namespace PlaQui