summaryrefslogtreecommitdiffstats
path: root/chrome/tools/service_discovery_sniffer/service_discovery_sniffer.h
blob: 12f87935be843b3c5595c5e9952e68a74a1292e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_
#define CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_

#include <map>
#include <string>

#include "base/memory/linked_ptr.h"
#include "chrome/browser/local_discovery/service_discovery_client.h"

namespace local_discovery {

// Resolves a service and prints out information regarding it to the
// console. |client| must outlive the ServicePrinter.
class ServicePrinter {
 public:
  ServicePrinter(ServiceDiscoveryClient* client,
                 const std::string& service_name);
  ~ServicePrinter();

  void Added();
  void Changed();
  void Removed();

 private:
  void OnServiceResolved(ServiceResolver::RequestStatus status,
                         const ServiceDescription& service);

  bool changed_;
  scoped_ptr<ServiceResolver> service_resolver_;

  DISALLOW_COPY_AND_ASSIGN(ServicePrinter);
};

// Monitors a service type and prints information regarding all services on it
// to the console. |client| must outlive the ServiceTypePrinter.
class ServiceTypePrinter : public ServiceWatcher::Delegate {
 public:
  ServiceTypePrinter(ServiceDiscoveryClient* client,
                     const std::string& service_type);
  virtual ~ServiceTypePrinter();

  bool Start();
  virtual void OnServiceUpdated(ServiceWatcher::UpdateType,
                                const std::string& service_name) OVERRIDE;

 private:
  typedef std::map<std::string, linked_ptr<ServicePrinter> > ServiceMap;

  ServiceMap services_;
  scoped_ptr<ServiceWatcher> watcher_;
  ServiceDiscoveryClient* client_;

  DISALLOW_COPY_AND_ASSIGN(ServiceTypePrinter);
};

}  // namespace local_discovery

#endif  // CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_