]> git.tdb.fi Git - r2c2.git/blobdiff - source/remote/remote.cpp
Add networking library and a remote control program
[r2c2.git] / source / remote / remote.cpp
diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp
new file mode 100644 (file)
index 0000000..57080c1
--- /dev/null
@@ -0,0 +1,53 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2009  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/net/resolve.h>
+#include <msp/time/units.h>
+#include "remote.h"
+#include "trainpanel.h"
+
+using namespace std;
+using namespace Msp;
+
+Application::RegApp<Remote> Remote::reg;
+
+Remote::Remote(int argc, char **argv):
+       client(catalogue),
+       gtk(argc, argv)
+{
+       if(argc<2)
+               throw UsageError("No address given");
+
+       DataFile::load(catalogue, "locos.dat");
+
+       client.use_event_dispatcher(event_disp);
+       client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added));
+       string addr_str = argv[1];
+       if(addr_str.find(':')==string::npos)
+               addr_str += ":8315";
+       Net::SockAddr *addr = Net::resolve(addr_str);
+       client.connect(*addr);
+       delete addr;
+
+       window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0));
+       window.set_border_width(5);
+       train_box = new Gtk::VBox(false, 5);
+       window.add(*manage(train_box));
+       window.show_all();
+}
+
+void Remote::tick()
+{
+       event_disp.tick(Time::zero);
+       gtk.iteration(false);
+}
+
+void Remote::train_added(Marklin::NetTrain &t)
+{
+       TrainPanel *panel = new TrainPanel(t);
+       train_box->add(*manage(panel));
+}