HEAD: an extra unit test for wvbase64 that I forgot to check in a while ago.
[wvapps.git] / wvprint / wvzeroconfbrowser.h
blobee2f00f7e331efea3b1e3eb6a9fabd3d613b1f91
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2004 Net Integration Technologies, Inc.
5 * Authors:
6 * Hubert Figuiere <hub@nit.ca>
8 * This is the Zeroconf browser class
9 * Needs Howl http://www.porchdogsoft.com/products/howl/
15 #ifndef _WVZEROCONF_H_
16 #define _WVZEROCONF_H_
18 #include "howl.h"
20 #include "wvfdstream.h"
21 #include "wvlog.h"
22 #include "wvlinklist.h"
24 class UniConf;
25 class WvZeroconfBrowser;
27 /**
28 This data model describe a ZeroConf service
30 class WvZeroconfService
32 public:
33 WvZeroconfService(WvZeroconfBrowser &_resolver,
34 sw_discovery_browse_status _status,
35 sw_const_string _name,
36 sw_const_string _type,
37 sw_const_string _domain,
38 sw_uint32 _interface_index)
39 : resolver(_resolver), status(_status), name(_name),
40 type(_type), domain(_domain), interface_index(_interface_index)
44 WvZeroconfService(const WvZeroconfService &_obj)
45 : resolver(_obj.resolver), status(_obj.status), name(_obj.name),
46 type(_obj.type), domain(_obj.domain),
47 interface_index(_obj.interface_index)
51 /** will store the ip in cfg["ip"] and the port in cfg["port"] */
52 bool resolve(UniConf &cfg);
54 WvZeroconfBrowser &resolver;
55 sw_discovery_browse_status status;
56 WvString name;
57 WvString type;
58 WvString domain;
59 private:
60 sw_uint32 interface_index;
62 static sw_result zeroconf_resolver(sw_discovery discovery,
63 sw_discovery_oid oid,
64 sw_uint32 interface_index,
65 sw_const_string name,
66 sw_const_string type,
67 sw_const_string domain,
68 sw_ipv4_address address,
69 sw_port port,
70 sw_octets text_record,
71 sw_uint32 text_record_len,
72 sw_opaque_t extra);
75 /**
76 Listen for a specific ZeroConf declared service using mDNS
78 class WvZeroconfBrowser
79 : public WvFdStream
81 private:
82 WvLog log;
83 sw_discovery zeroconf_session;
84 WvList<WvZeroconfService> services;
86 public:
87 WvZeroconfBrowser(WvStringParm service);
89 virtual void close();
91 /**
92 Pop a WvZeroconfService from the registered services
93 found on the network. The value is poped out of the
94 list, se next call, it will be different.
96 \retval returns a newly allocated WvZeroconfService
97 that should be deleted by the caller after use.
99 WvZeroconfService *pop_first_service(void);
100 bool isempty()
101 { return !isok() || services.isempty(); };
103 /** publish the ZeroConf service name of type on port */
104 bool publish(WvStringParm name, WvStringParm type, WvStringParm port);
106 /** returns the session for zeroconf */
107 sw_discovery session(void)
109 return zeroconf_session;
112 protected:
113 virtual ~WvZeroconfBrowser();
115 virtual void execute(void);
117 private:
118 /* all of these are forbidden to be used */
119 virtual size_t read(void *buf, size_t count)
120 { assert(false); }
121 virtual size_t read(WvBuf &outbuf, size_t count)
122 { assert(false); }
123 virtual void unread(WvBuf &outbuf, size_t count)
124 { assert(false); }
125 virtual size_t write(const void *buf, size_t count)
126 { assert(false); }
127 virtual size_t write(WvBuf &inbuf, size_t count = INT_MAX)
128 { assert(false); }
129 virtual size_t uread(void *buf, size_t count)
130 { assert(false); }
131 virtual size_t uwrite(const void *buf, size_t count)
132 { assert(false); }
135 sw_result _zeroconf_browser(sw_discovery discovery, sw_discovery_oid oid,
136 sw_discovery_browse_status status,
137 sw_uint32 interface_index,
138 sw_const_string name, sw_const_string type,
139 sw_const_string domain);
141 /* libhowl callbacks */
142 static sw_result zeroconf_browser(sw_discovery discovery,
143 sw_discovery_oid oid,
144 sw_discovery_browse_status status,
145 sw_uint32 interface_index,
146 sw_const_string name,
147 sw_const_string type,
148 sw_const_string domain,
149 sw_opaque_t extra);
150 static sw_result zeroconf_resolver(sw_discovery discovery,
151 sw_discovery_oid oid,
152 sw_uint32 interface_index,
153 sw_const_string name,
154 sw_const_string type,
155 sw_const_string domain,
156 sw_ipv4_address address,
157 sw_port port,
158 sw_octets text_record,
159 sw_uint32 text_record_len,
160 sw_opaque_t extra);
163 #endif