| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cloud_print/gcp20/prototype/printer.h" | 5 #include "cloud_print/gcp20/prototype/printer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 const char kPrinterStatePathDefault[] = "printer_state.json"; | 32 const char kPrinterStatePathDefault[] = "printer_state.json"; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const uint16 kHttpPortDefault = 10101; | 36 const uint16 kHttpPortDefault = 10101; |
| 37 const uint32 kTtlDefault = 60*60; // in seconds | 37 const uint32 kTtlDefault = 60*60; // in seconds |
| 38 | 38 |
| 39 const char kServiceType[] = "_privet._tcp.local"; | 39 const char kServiceType[] = "_privet._tcp.local"; |
| 40 const char kSecondaryServiceType[] = "_printer._sub._privet._tcp.local"; | 40 const char kSecondaryServiceType[] = "_printer._sub._privet._tcp.local"; |
| 41 const char kServiceNamePrefixDefault[] = "first_gcp20_device"; | 41 const char kServiceNamePrefixDefault[] = "gcp20_device_"; |
| 42 const char kServiceDomainNameFormatDefault[] = "my-privet-device%d.local"; | 42 const char kServiceDomainNameFormatDefault[] = "my-privet-device%d.local"; |
| 43 | 43 |
| 44 const char kPrinterName[] = "Google GCP2.0 Prototype"; | 44 const char kPrinterName[] = "Google GCP2.0 Prototype"; |
| 45 const char kPrinterDescription[] = "Printer emulator"; | 45 const char kPrinterDescription[] = "Printer emulator"; |
| 46 | 46 |
| 47 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you " | 47 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you " |
| 48 "agree and any other to discard\n"; | 48 "agree and any other to discard\n"; |
| 49 const int kUserConfirmationTimeout = 30; // in seconds | 49 const int kUserConfirmationTimeout = 30; // in seconds |
| 50 const int kRegistrationTimeout = 60; // in seconds | 50 const int kRegistrationTimeout = 60; // in seconds |
| 51 const int kReconnectTimeout = 5; // in seconds | 51 const int kReconnectTimeout = 5; // in seconds |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 net::IPAddressNumber ip = GetLocalIp("", false); | 836 net::IPAddressNumber ip = GetLocalIp("", false); |
| 837 if (ip.empty()) { | 837 if (ip.empty()) { |
| 838 LOG(ERROR) << "No local IP found. Cannot start printer."; | 838 LOG(ERROR) << "No local IP found. Cannot start printer."; |
| 839 return false; | 839 return false; |
| 840 } | 840 } |
| 841 VLOG(0) << "Local address: " << net::IPAddressToString(ip); | 841 VLOG(0) << "Local address: " << net::IPAddressToString(ip); |
| 842 | 842 |
| 843 uint16 port = command_line_reader::ReadHttpPort(kHttpPortDefault); | 843 uint16 port = command_line_reader::ReadHttpPort(kHttpPortDefault); |
| 844 | 844 |
| 845 std::string service_name_prefix = | 845 std::string service_name_prefix = |
| 846 command_line_reader::ReadServiceNamePrefix(net::IPAddressToString(ip) + | 846 command_line_reader::ReadServiceNamePrefix(kServiceNamePrefixDefault + |
| 847 kServiceNamePrefixDefault); | 847 net::IPAddressToString(ip)); |
| 848 std::replace(service_name_prefix .begin(), service_name_prefix .end(), | 848 std::replace(service_name_prefix .begin(), service_name_prefix .end(), |
| 849 '.', '_'); | 849 '.', '_'); |
| 850 | 850 |
| 851 std::string service_domain_name = | 851 std::string service_domain_name = |
| 852 command_line_reader::ReadDomainName( | 852 command_line_reader::ReadDomainName( |
| 853 base::StringPrintf(kServiceDomainNameFormatDefault, | 853 base::StringPrintf(kServiceDomainNameFormatDefault, |
| 854 base::RandInt(0, INT_MAX))); | 854 base::RandInt(0, INT_MAX))); |
| 855 | 855 |
| 856 ServiceParameters params(kServiceType, kSecondaryServiceType, | 856 ServiceParameters params(kServiceType, kSecondaryServiceType, |
| 857 service_name_prefix, | 857 service_name_prefix, service_domain_name, |
| 858 service_domain_name, ip, port); | 858 ip, GetLocalIp("", true), port); |
| 859 | 859 |
| 860 return dns_server_.Start(params, | 860 return dns_server_.Start(params, |
| 861 command_line_reader::ReadTtl(kTtlDefault), | 861 command_line_reader::ReadTtl(kTtlDefault), |
| 862 CreateTxt()); | 862 CreateTxt()); |
| 863 } | 863 } |
| 864 | 864 |
| 865 bool Printer::StartHttpServer() { | 865 bool Printer::StartHttpServer() { |
| 866 DCHECK(state_.local_settings.local_discovery); | 866 DCHECK(state_.local_settings.local_discovery); |
| 867 using command_line_reader::ReadHttpPort; | 867 using command_line_reader::ReadHttpPort; |
| 868 return http_server_.Start(ReadHttpPort(kHttpPortDefault)); | 868 return http_server_.Start(ReadHttpPort(kHttpPortDefault)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 | 933 |
| 934 dns_server_.UpdateMetadata(CreateTxt()); | 934 dns_server_.UpdateMetadata(CreateTxt()); |
| 935 | 935 |
| 936 if (connection_state_ == OFFLINE) { | 936 if (connection_state_ == OFFLINE) { |
| 937 requester_.reset(); | 937 requester_.reset(); |
| 938 xmpp_listener_.reset(); | 938 xmpp_listener_.reset(); |
| 939 } | 939 } |
| 940 | 940 |
| 941 return true; | 941 return true; |
| 942 } | 942 } |
| OLD | NEW |