root/chrome/tools/service_discovery_sniffer/service_discovery_sniffer.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


// 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/common/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:
  ServiceTypePrinter(ServiceDiscoveryClient* client,
                     const std::string& service_type);
  virtual ~ServiceTypePrinter();

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

 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_

/* [<][>][^][v][top][bottom][index][help] */