Index: cloud_print/gcp20/prototype/dns_sd_server.h |
diff --git a/cloud_print/gcp20/prototype/dns_sd_server.h b/cloud_print/gcp20/prototype/dns_sd_server.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c8ed96b7d33d62790d7797dc061f5b963911f2f |
--- /dev/null |
+++ b/cloud_print/gcp20/prototype/dns_sd_server.h |
@@ -0,0 +1,62 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef GCP20_PROTOTYPE_DNS_SD_H_ |
+#define GCP20_PROTOTYPE_DNS_SD_H_ |
+ |
+#include <vector> |
+ |
+#include "net/dns/dns_protocol.h" |
+#include "net/udp/udp_socket.h" |
+ |
+// Class for sending multicast announcements, receiving queries and answering on |
+// them. Client should call |ProccessMessages| periodically to make server work. |
+class DnsSdServer { |
+ public: |
+ // Constructs unstarted server. |
+ DnsSdServer(); |
+ |
+ // Stops server. |
+ ~DnsSdServer(); |
+ |
+ // Starts the server. Returns |true| if server works. Also sends |
+ // announcement. |
+ bool Start(); |
+ |
+ // Sends announcement if server works. |
+ void Update(); |
+ |
+ // Stops server with announcement. |
+ void Shutdown(); |
+ |
+ // Process pending queries for the server. |
+ void ProcessMessages(); |
+ |
+ // Returns |true| if server works. |
+ bool is_online() { return is_online_; } |
+ |
+ private: |
+ // Binds a socket to multicast address. Returns |true| on success. |
+ bool CreateSocket(); |
+ |
+ // Sends announcement. |
+ void SendAnnouncement(uint32 ttl); |
+ |
+ // Returns |true| if server received some questions. |
+ bool CheckPendingQueries(); |
+ |
+ // Stores |true| if server was started. |
+ bool is_online_; |
+ |
+ // Stores socket to multicast address. |
+ scoped_ptr<net::UDPSocket> socket_; |
+ |
+ // Stores multicast address end point. |
+ net::IPEndPoint multicast_address_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DnsSdServer); |
+}; |
+ |
+#endif // GCP20_PROTOTYPE_DNS_SD_H_ |
+ |