Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * main.cpp - World Info Viewer 00004 * 00005 * Created: Wed April 09 20:04:46 2008 00006 * Copyright 2008 Daniel Beck 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 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 <iostream> 00031 #include <string> 00032 00033 using namespace fawkes; 00034 00035 int main(int argc, char** argv) 00036 { 00037 Thread::init_main(); 00038 00039 HostInfo* host_info = new HostInfo(); 00040 Configuration* config = new SQLiteConfiguration(CONFDIR); 00041 config->load(host_info->short_name(), "default"); 00042 delete host_info; 00043 00044 std::string addr; 00045 unsigned int port; 00046 std::string key; 00047 std::string iv; 00048 try 00049 { 00050 addr = config->get_string("/worldinfo/multicast_addr"); 00051 port = config->get_uint("/worldinfo/udp_port"); 00052 key = config->get_string("/worldinfo/encryption_key"); 00053 iv = config->get_string("/worldinfo/encryption_iv"); 00054 } 00055 catch (Exception &e) 00056 { 00057 delete config; 00058 e.append("Could not get required configuration data for world info viewer"); 00059 e.print_trace(); 00060 throw; 00061 } 00062 00063 delete config; 00064 00065 Clock* clock = Clock::instance(); 00066 WorldInfoDataContainer* data_container = new WorldInfoDataContainer(clock, 10000); 00067 WorldInfoViewerBackendThread* backend_thread = 00068 new WorldInfoViewerBackendThread( data_container, addr.c_str(), port, 00069 key.c_str(), iv.c_str() ); 00070 00071 backend_thread->start(); 00072 00073 try 00074 { 00075 Gtk::Main kit(argc, argv); 00076 #ifdef GLIBMM_EXCEPTIONS_ENABLED 00077 Glib::RefPtr<Gtk::Builder> builder = 00078 Gtk::Builder::create_from_file( RESDIR"/guis/worldinfo_viewer/" 00079 "worldinfo_viewer.ui" ); 00080 #else 00081 std::auto_ptr<Gtk::BuilderError> error; 00082 Glib::RefPtr<Gtk::Builder> builder = 00083 Gtk::Builder::create_from_file(RESDIR"/guis/worldinfo_viewer/worldinfo_viewer.ui", error); 00084 if (error.get()) { 00085 throw fawkes::Exception("Failed to load UI file: %s", error->what().c_str()); 00086 } 00087 #endif 00088 00089 WorldInfoViewer viewer(builder, 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 }