00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdexcept>
00022 #include <iostream>
00023 #include "servicedirectory.hh"
00024
00025 using namespace LSD;
00026 using namespace std;
00027
00028 class testcb : public virtual ServiceAdvertismentListener {
00029 public:
00030 virtual void notifyNewService(int id, const Service& s)
00031 {
00032 cout << "* found service (for query id " << id << ")!\n";
00033 cout << "* title: " << s.title << "\n";
00034 cout << "* description: " << s.description << "\n";
00035 cout << "* url: " << s.url << "\n\n";
00036 }
00037 };
00038
00039 int main(int argc, char** argv)
00040 {
00041 try {
00042 ServiceDirectory sd;
00043 sd.listenTCP();
00044 try {
00045 cerr << "Relaying to tcp localhost:4444...\n";
00046 sd.addRelay("localhost", 4444);
00047 } catch(...) {
00048 cerr << "Cannot relay to localhost:4444 (connection failed)\n";
00049 }
00050 cerr << "Advertising a new service...\n";
00051 set<string> types;
00052 types.insert("hello:hello");
00053 sd.addService(new Service(types, "some title", "la la de da", "httvosnmldaftirc://shwing"));
00054 cerr << "Making query (url matches /htt.*/)...\n";
00055 int q = sd.query("", "", "", "htt.*", new testcb());
00056 cerr << "query id is " << q << endl;
00057 while(true)
00058 sd.handleIncoming();
00059 } catch(runtime_error& e) {
00060 cerr << "Error: " << e.what() << endl;
00061 }
00062 }