Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_avahi_browser.cpp - QA for AvahiBrowser 00004 * 00005 * Created: Fri Nov 10 10:19:39 2006 (recreated after stupid delete) 00006 * Copyright 2006 Tim Niemueller [www.niemueller.de] 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. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 /// @cond QA 00025 00026 #include <netcomm/dns-sd/avahi_thread.h> 00027 #include <netcomm/service_discovery/browse_handler.h> 00028 00029 #include <core/exception.h> 00030 #include <utils/system/signal.h> 00031 00032 #include <cstdio> 00033 00034 using namespace fawkes; 00035 00036 class QAAvahiBrowserMain : public SignalHandler, public ServiceBrowseHandler 00037 { 00038 public: 00039 QAAvahiBrowserMain() 00040 { 00041 at = new AvahiThread();; 00042 at->watch_service("_fawkes._udp", this); 00043 } 00044 00045 ~QAAvahiBrowserMain() 00046 { 00047 delete at; 00048 } 00049 00050 void handle_signal(int signum) 00051 { 00052 at->cancel(); 00053 } 00054 00055 void run() 00056 { 00057 at->start(); 00058 at->join(); 00059 } 00060 00061 virtual void all_for_now() 00062 { 00063 printf("ALL_FOR_NOW\n"); 00064 } 00065 00066 virtual void cache_exhausted() 00067 { 00068 printf("CACHE_EXHAUSTED\n"); 00069 } 00070 00071 virtual void browse_failed(const char *name, 00072 const char *type, 00073 const char *domain) 00074 { 00075 printf("FAILED: name=%s type=%s domain=%s\n", name, type, domain); 00076 } 00077 00078 virtual void service_added(const char *name, 00079 const char *type, 00080 const char *domain, 00081 const char *host_name, 00082 const struct sockaddr *addr, 00083 const socklen_t addr_size, 00084 uint16_t port, 00085 std::list<std::string> &txt, 00086 int flags 00087 ) 00088 { 00089 printf("SERVICE_ADDED: name=%s type=%s domain=%s hostname=%s\n", 00090 name, type, domain, host_name); 00091 } 00092 00093 virtual void service_removed(const char *name, 00094 const char *type, 00095 const char *domain) 00096 { 00097 printf("SERVICE_REMOVED: name=%s type=%s domain=%s\n", name, type, domain); 00098 } 00099 00100 private: 00101 AvahiThread *at; 00102 00103 }; 00104 00105 int 00106 main(int argc, char **argv) 00107 { 00108 try { 00109 00110 QAAvahiBrowserMain m; 00111 SignalManager::register_handler(SIGINT, &m); 00112 00113 m.run(); 00114 00115 } catch (Exception &e) { 00116 e.print_trace(); 00117 } 00118 00119 SignalManager::finalize(); 00120 } 00121 00122 /// @endcond