]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/plant.cpp
se borran las lineas al eliminar un item, esto no esta totalmente testeado
[z.facultad/75.42/plaqui.git] / Server / src / plant.cpp
index 49ad53ae60e25b7b878fe491d82deafa4bc7bd6a..e46e692671fb7dc864a909e7862b4f338794ee49 100644 (file)
@@ -28,6 +28,9 @@
 #include "plaqui/server/plant.h"
 #include <glibmm/timer.h>
 #include <sigc++/slot.h>
 #include "plaqui/server/plant.h"
 #include <glibmm/timer.h>
 #include <sigc++/slot.h>
+#include <fstream>
+#include <iterator>
+#include <algorithm>
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
@@ -50,12 +53,12 @@ Plant::~Plant(void) {
        }
 }
 
        }
 }
 
-Plant::Plant(const string& filename): simulator(filename) {
+Plant::Plant(const string& filename): simulator(filename), filename(filename) {
 #ifdef DEBUG
        cerr << __FILE__ << ": constructor. filename = " << filename << endl;
 #endif // DEBUG
        // TODO plant
 #ifdef DEBUG
        cerr << __FILE__ << ": constructor. filename = " << filename << endl;
 #endif // DEBUG
        // TODO plant
-       simulator.add_pump("bomba1");
+/*     simulator.add_pump("bomba1");
        simulator.add_conduct("c");
        simulator.add_conduct("c1");
        simulator.add_drainage("d");
        simulator.add_conduct("c");
        simulator.add_conduct("c1");
        simulator.add_drainage("d");
@@ -65,7 +68,7 @@ Plant::Plant(const string& filename): simulator(filename) {
        simulator.connect("c", "tanque", Model::IConector::OUT);
        simulator.connect("tanque", "c1", Model::IConector::OUT);
        simulator.connect("c1", "d", Model::IConector::OUT);
        simulator.connect("c", "tanque", Model::IConector::OUT);
        simulator.connect("tanque", "c1", Model::IConector::OUT);
        simulator.connect("c1", "d", Model::IConector::OUT);
-       
+*/     
 }
 
 void Plant::real_run(void) {
 }
 
 void Plant::real_run(void) {
@@ -73,18 +76,20 @@ void Plant::real_run(void) {
        cerr << __FILE__ << ": real_run." << endl;
 #endif // DEBUG
        while (!stop) {
        cerr << __FILE__ << ": real_run." << endl;
 #endif // DEBUG
        while (!stop) {
+               simulator_mutex.lock();
                simulator.simulate();
                simulator.simulate();
-               Glib::Mutex::Lock lock(transmissions_mutex);
+               simulator_mutex.unlock();
+               transmissions_mutex.lock();
                for (TransmitterList::iterator i = transmissions.begin();
                                i != transmissions.end(); i++) {
                        (*i)->send(simulator.get_state_as_xml());
                }
                for (TransmitterList::iterator i = transmissions.begin();
                                i != transmissions.end(); i++) {
                        (*i)->send(simulator.get_state_as_xml());
                }
+               transmissions_mutex.unlock();
                Glib::usleep(1000000);
        }
 }
 
                Glib::usleep(1000000);
        }
 }
 
-bool Plant::transmission_start(const string& host,
-               const Connection::Port& port) {
+bool Plant::transmission_start(string& host, Connection::Port& port) {
        Glib::Mutex::Lock lock(transmissions_mutex);
        for (TransmitterList::iterator i = transmissions.begin();
                        i != transmissions.end(); i++) {
        Glib::Mutex::Lock lock(transmissions_mutex);
        for (TransmitterList::iterator i = transmissions.begin();
                        i != transmissions.end(); i++) {
@@ -117,6 +122,24 @@ bool Plant::transmission_stop(const string& host,
        return false; // No la encontró.
 }
 
        return false; // No la encontró.
 }
 
+bool Plant::set_open(const std::string& element, bool open) {
+       Glib::Mutex::Lock lock(simulator_mutex);
+       return simulator.set_open(element, open);
+}
+
+const string Plant::get_xml(void) const {
+       ostringstream oss;
+       try {
+               ifstream ifs(filename.c_str());
+               ifs >> noskipws;
+               copy(istream_iterator<char>(ifs), istream_iterator<char>(),
+                               ostream_iterator<char>(oss));
+       } catch (...) { // TODO hacerlo mas selectivo?
+               return "";
+       }
+       return oss.str();
+}
+
 /*
 bool Plant::transmission_exists(const string& host,
                const Connection::Port& port) {
 /*
 bool Plant::transmission_exists(const string& host,
                const Connection::Port& port) {