1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ 6#define CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ 7 8#include <map> 9#include <string> 10 11#include "base/memory/linked_ptr.h" 12#include "chrome/common/local_discovery/service_discovery_client.h" 13 14namespace local_discovery { 15 16// Resolves a service and prints out information regarding it to the 17// console. |client| must outlive the ServicePrinter. 18class ServicePrinter { 19 public: 20 ServicePrinter(ServiceDiscoveryClient* client, 21 const std::string& service_name); 22 ~ServicePrinter(); 23 24 void Added(); 25 void Changed(); 26 void Removed(); 27 28 private: 29 void OnServiceResolved(ServiceResolver::RequestStatus status, 30 const ServiceDescription& service); 31 32 bool changed_; 33 scoped_ptr<ServiceResolver> service_resolver_; 34 35 DISALLOW_COPY_AND_ASSIGN(ServicePrinter); 36}; 37 38// Monitors a service type and prints information regarding all services on it 39// to the console. |client| must outlive the ServiceTypePrinter. 40class ServiceTypePrinter { 41 public: 42 ServiceTypePrinter(ServiceDiscoveryClient* client, 43 const std::string& service_type); 44 virtual ~ServiceTypePrinter(); 45 46 void Start(); 47 void OnServiceUpdated(ServiceWatcher::UpdateType, 48 const std::string& service_name); 49 50 private: 51 typedef std::map<std::string, linked_ptr<ServicePrinter> > ServiceMap; 52 53 ServiceMap services_; 54 scoped_ptr<ServiceWatcher> watcher_; 55 ServiceDiscoveryClient* client_; 56 57 DISALLOW_COPY_AND_ASSIGN(ServiceTypePrinter); 58}; 59 60} // namespace local_discovery 61 62#endif // CHROME_TOOLS_SERVICE_DISCOVERY_SNIFFER_SERVICE_DISCOVERY_SNIFFER_H_ 63