Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/servicediscovery/test.cc

Go to the documentation of this file.
00001 /* $Id: test.cc,v 1.5 2003/06/29 03:09:34 tetron Exp $
00002 
00003     Copyright (C) 2002 Peter Amstutz <tetron@interreality.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
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 }

Generated on Tue Aug 12 03:55:39 2003 for Interreality Project - VOS by doxygen 1.3.2