main.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <tools/worldinfo_viewer/worldinfo_viewer.h>
00024 #include <tools/worldinfo_viewer/backend_thread.h>
00025 #include <worldinfo_utils/data_container.h>
00026 #include <utils/system/hostinfo.h>
00027 #include <utils/time/clock.h>
00028 #include <config/sqlite.h>
00029
00030 #include <libglademm/xml.h>
00031 #include <iostream>
00032 #include <string>
00033
00034 using namespace fawkes;
00035
00036 int main(int argc, char** argv)
00037 {
00038 Thread::init_main();
00039
00040 HostInfo* host_info = new HostInfo();
00041 Configuration* config = new SQLiteConfiguration(CONFDIR);
00042 config->load(host_info->short_name(), "default.db");
00043 delete host_info;
00044
00045 std::string addr;
00046 unsigned int port;
00047 std::string key;
00048 std::string iv;
00049 try
00050 {
00051 addr = config->get_string("/worldinfo/multicast_addr");
00052 port = config->get_uint("/worldinfo/udp_port");
00053 key = config->get_string("/worldinfo/encryption_key");
00054 iv = config->get_string("/worldinfo/encryption_iv");
00055 }
00056 catch (Exception &e)
00057 {
00058 delete config;
00059 e.append("Could not get required configuration data for world info viewer");
00060 e.print_trace();
00061 throw;
00062 }
00063
00064 delete config;
00065
00066 Clock* clock = Clock::instance();
00067 WorldInfoDataContainer* data_container = new WorldInfoDataContainer(clock, 10000);
00068 WorldInfoViewerBackendThread* backend_thread =
00069 new WorldInfoViewerBackendThread( data_container, addr.c_str(), port,
00070 key.c_str(), iv.c_str() );
00071
00072 backend_thread->start();
00073
00074 try
00075 {
00076 Gtk::Main kit(argc, argv);
00077 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00078 Glib::RefPtr<Gnome::Glade::Xml> ref_xml =
00079 Gnome::Glade::Xml::create( RESDIR"/guis/worldinfo_viewer/"
00080 "worldinfo_viewer.glade" );
00081 #else
00082 std::auto_ptr<Gnome::Glade::XmlError> error;
00083 Glib::RefPtr<Gnome::Glade::Xml> ref_xml = Gnome::Glade::Xml::create(RESDIR"/guis/worldinfo_viewer/worldinfo_viewer.glade", "", "", error);
00084 if (error.get()) {
00085 throw fawkes::Exception("Failed to load Glade file: %s", error->what().c_str());
00086 }
00087 #endif
00088
00089 WorldInfoViewer viewer(ref_xml, data_container);
00090 backend_thread->new_gamestate_data().connect( sigc::mem_fun(viewer, &WorldInfoViewer::gamestate_changed ) );
00091
00092 kit.run( viewer.get_window() );
00093 }
00094 catch (std::exception const& e)
00095 {
00096 std::cerr << "Error: " << e.what() << std::endl;
00097 }
00098
00099 backend_thread->cancel();
00100 backend_thread->join();
00101 delete backend_thread;
00102
00103 delete data_container;
00104 Clock::finalize();
00105
00106 Thread::destroy_main();
00107
00108 return 0;
00109 }