Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1311)

Side by Side Diff: cloud_print/gcp20/prototype/printer.cc

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdio.h> 7 #include <stdio.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/guid.h" 14 #include "base/guid.h"
14 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
17 #include "cloud_print/gcp20/prototype/command_line_reader.h" 19 #include "cloud_print/gcp20/prototype/command_line_reader.h"
18 #include "cloud_print/gcp20/prototype/service_parameters.h" 20 #include "cloud_print/gcp20/prototype/service_parameters.h"
19 #include "cloud_print/gcp20/prototype/special_io.h" 21 #include "cloud_print/gcp20/prototype/special_io.h"
20 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
21 #include "net/base/url_util.h" 23 #include "net/base/url_util.h"
22 24
23 const char kPrinterStatePath[] = "printer_state.json"; 25 const char kPrinterStatePath[] = "printer_state.json";
24 26
27 typedef std::vector<Printjob> PrintjobList;
28
25 namespace { 29 namespace {
26 30
27 const char kServiceType[] = "_privet._tcp.local"; 31 const char kServiceType[] = "_privet._tcp.local";
28 const char kServiceNamePrefix[] = "first_gcp20_device"; 32 const char kServiceNamePrefix[] = "first_gcp20_device";
29 const char kServiceDomainName[] = "my-privet-device.local"; 33 const char kServiceDomainName[] = "my-privet-device.local";
30 34
31 const char kPrinterName[] = "Google GCP2.0 Prototype"; 35 const char kPrinterName[] = "Google GCP2.0 Prototype";
32 const char kPrinterDescription[] = "Printer emulator"; 36 const char kPrinterDescription[] = "Printer emulator";
33 37
34 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you " 38 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you "
35 "agree and any other to discard"; 39 "agree and any other to discard";
36 const uint kUserConfirmationTimeout = 30; // in seconds 40 const uint kUserConfirmationTimeout = 30; // in seconds
37 41
42 const uint32 kReconnectTimeout = 5; // in seconds
43 const uint32 kPrintjobsTimeout = 10; // in seconds
44
38 const char kCdd[] = 45 const char kCdd[] =
39 "{\n" 46 "{\n"
40 " 'version': '1.0',\n" 47 " 'version': '1.0',\n"
41 " 'printer': {\n" 48 " 'printer': {\n"
42 " 'vendor_capability': [\n" 49 " 'vendor_capability': [\n"
43 " {\n" 50 " {\n"
44 " 'id': 'psk:MediaType',\n" 51 " 'id': 'psk:MediaType',\n"
45 " 'display_name': 'Media Type',\n" 52 " 'display_name': 'Media Type',\n"
46 " 'type': 'SELECT',\n" 53 " 'type': 'SELECT',\n"
47 " 'select_cap': {\n" 54 " 'select_cap': {\n"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } // namespace 99 } // namespace
93 100
94 Printer::RegistrationInfo::RegistrationInfo() 101 Printer::RegistrationInfo::RegistrationInfo()
95 : state(DEV_REG_UNREGISTERED), 102 : state(DEV_REG_UNREGISTERED),
96 confirmation_state(CONFIRMATION_PENDING) { 103 confirmation_state(CONFIRMATION_PENDING) {
97 } 104 }
98 105
99 Printer::RegistrationInfo::~RegistrationInfo() { 106 Printer::RegistrationInfo::~RegistrationInfo() {
100 } 107 }
101 108
102 Printer::Printer() : http_server_(this) { 109 Printer::Printer() : http_server_(this), connection_state_(OFFLINE) {
103 } 110 }
104 111
105 Printer::~Printer() { 112 Printer::~Printer() {
106 Stop(); 113 Stop();
107 } 114 }
108 115
109 bool Printer::Start() { 116 bool Printer::Start() {
110 if (IsOnline()) 117 if (IsOnline())
111 return true; 118 return true;
112 119
(...skipping 26 matching lines...) Expand all
139 146
140 // Creating Cloud Requester. 147 // Creating Cloud Requester.
141 requester_.reset( 148 requester_.reset(
142 new CloudPrintRequester( 149 new CloudPrintRequester(
143 base::MessageLoop::current()->message_loop_proxy(), 150 base::MessageLoop::current()->message_loop_proxy(),
144 this)); 151 this));
145 152
146 xtoken_ = XPrivetToken(); 153 xtoken_ = XPrivetToken();
147 starttime_ = base::Time::Now(); 154 starttime_ = base::Time::Now();
148 155
156 printjob_handler_.reset(new PrintjobHandler);
157 connection_state_ = CONNECTING;
158 if (IsRegistered())
159 WakeUp();
160
149 return true; 161 return true;
150 } 162 }
151 163
152 bool Printer::IsOnline() const { 164 bool Printer::IsOnline() const {
153 return requester_; 165 return requester_;
154 } 166 }
155 167
168 void Printer::WakeUp() {
169 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
170
171 if (!IsRegistered())
172 return;
173
174 FetchPrintjobs();
175 }
176
156 void Printer::Stop() { 177 void Printer::Stop() {
157 dns_server_.Shutdown(); 178 dns_server_.Shutdown();
158 http_server_.Shutdown(); 179 http_server_.Shutdown();
159 requester_.reset(); 180 requester_.reset();
181 printjob_handler_.reset();
160 } 182 }
161 183
162 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart( 184 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart(
163 const std::string& user) { 185 const std::string& user) {
164 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); 186 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user);
165 if (status != PrivetHttpServer::REG_ERROR_OK) 187 if (status != PrivetHttpServer::REG_ERROR_OK)
166 return status; 188 return status;
167 189
168 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED) 190 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED)
169 return PrivetHttpServer::REG_ERROR_INVALID_ACTION; 191 return PrivetHttpServer::REG_ERROR_INVALID_ACTION;
170 192
171 reg_info_ = RegistrationInfo(); 193 reg_info_ = RegistrationInfo();
172 reg_info_.user = user; 194 reg_info_.user = user;
173 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_STARTED; 195 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_STARTED;
174 196
175 printf("%s\n", kUserConfirmationTitle); 197 printf("%s\n", kUserConfirmationTitle);
176 base::Time valid_until = base::Time::Now() + 198 base::Time valid_until = base::Time::Now() +
177 base::TimeDelta::FromSeconds(kUserConfirmationTimeout); 199 base::TimeDelta::FromSeconds(kUserConfirmationTimeout);
178 base::MessageLoop::current()->PostTask( 200 base::MessageLoop::current()->PostTask(
179 FROM_HERE, 201 FROM_HERE,
180 base::Bind(&Printer::WaitUserConfirmation, 202 base::Bind(&Printer::WaitUserConfirmation, this->AsWeakPtr(),
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 remote this->
maksymb 2013/07/22 22:56:53 Done.
181 base::Unretained(this), valid_until)); 203 valid_until));
182 204
183 requester_->StartRegistration(GenerateProxyId(), kPrinterName, user, kCdd); 205 requester_->StartRegistration(GenerateProxyId(), kPrinterName, user, kCdd);
184 206
185 return PrivetHttpServer::REG_ERROR_OK; 207 return PrivetHttpServer::REG_ERROR_OK;
186 } 208 }
187 209
188 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const {
189 return xtoken_.CheckValidXToken(token);
190 }
191
192 bool Printer::IsRegistered() const {
193 return reg_info_.state == RegistrationInfo::DEV_REG_REGISTERED;
194 }
195
196 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationGetClaimToken( 210 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationGetClaimToken(
197 const std::string& user, 211 const std::string& user,
198 std::string* token, 212 std::string* token,
199 std::string* claim_url) { 213 std::string* claim_url) {
200 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); 214 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user);
201 if (status != PrivetHttpServer::REG_ERROR_OK) 215 if (status != PrivetHttpServer::REG_ERROR_OK)
202 return status; 216 return status;
203 217
204 if (reg_info_.state != RegistrationInfo::DEV_REG_REGISTRATION_STARTED && 218 if (reg_info_.state != RegistrationInfo::DEV_REG_REGISTRATION_STARTED &&
205 reg_info_.state != 219 reg_info_.state !=
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void Printer::CreateInfo(PrivetHttpServer::DeviceInfo* info) { 282 void Printer::CreateInfo(PrivetHttpServer::DeviceInfo* info) {
269 // TODO(maksymb): Replace "text" with constants. 283 // TODO(maksymb): Replace "text" with constants.
270 284
271 *info = PrivetHttpServer::DeviceInfo(); 285 *info = PrivetHttpServer::DeviceInfo();
272 info->version = "1.0"; 286 info->version = "1.0";
273 info->name = kPrinterName; 287 info->name = kPrinterName;
274 info->description = kPrinterDescription; 288 info->description = kPrinterDescription;
275 info->url = kCloudPrintUrl; 289 info->url = kCloudPrintUrl;
276 info->id = reg_info_.device_id; 290 info->id = reg_info_.device_id;
277 info->device_state = "idle"; 291 info->device_state = "idle";
278 info->connection_state = "offline"; 292 info->connection_state = ConnectionStateToString(connection_state_);
279 info->manufacturer = "Google"; 293 info->manufacturer = "Google";
280 info->model = "Prototype"; 294 info->model = "Prototype";
281 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203"; 295 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203";
282 info->firmware = "3.7.31.127.8191.131071.524287.2147483647"; 296 info->firmware = "3.7.31.127.8191.131071.524287.2147483647";
283 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds()); 297 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds());
284 298
285 info->x_privet_token = xtoken_.GenerateXToken(); 299 info->x_privet_token = xtoken_.GenerateXToken();
286 300
287 if (reg_info_.state == RegistrationInfo::DEV_REG_UNREGISTERED) 301 if (reg_info_.state == RegistrationInfo::DEV_REG_UNREGISTERED)
288 info->api.push_back("/privet/register"); 302 info->api.push_back("/privet/register");
289 303
290 info->type.push_back("printer"); 304 info->type.push_back("printer");
291 } 305 }
292 306
307 bool Printer::IsRegistered() const {
308 return reg_info_.state == RegistrationInfo::DEV_REG_REGISTERED;
309 }
310
311 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const {
312 return xtoken_.CheckValidXToken(token);
313 }
314
293 void Printer::OnRegistrationStartResponseParsed( 315 void Printer::OnRegistrationStartResponseParsed(
294 const std::string& registration_token, 316 const std::string& registration_token,
295 const std::string& complete_invite_url, 317 const std::string& complete_invite_url,
296 const std::string& device_id) { 318 const std::string& device_id) {
297 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_CLAIM_TOKEN_READY; 319 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_CLAIM_TOKEN_READY;
298 reg_info_.device_id = device_id; 320 reg_info_.device_id = device_id;
299 reg_info_.registration_token = registration_token; 321 reg_info_.registration_token = registration_token;
300 reg_info_.complete_invite_url = complete_invite_url; 322 reg_info_.complete_invite_url = complete_invite_url;
301 } 323 }
302 324
303 void Printer::OnGetAuthCodeResponseParsed(const std::string& refresh_token) { 325 void Printer::OnGetAuthCodeResponseParsed(const std::string& refresh_token) {
304 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED; 326 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED;
305 reg_info_.refresh_token = refresh_token; 327 reg_info_.refresh_token = refresh_token;
306 SaveToFile(kPrinterStatePath); 328 SaveToFile(kPrinterStatePath);
329 FetchPrintjobs();
307 } 330 }
308 331
309 void Printer::OnRegistrationError(const std::string& description) { 332 void Printer::OnRegistrationError(const std::string& description) {
310 LOG(ERROR) << "server_error: " << description; 333 LOG(ERROR) << "server_error: " << description;
311 334
312 // TODO(maksymb): Implement waiting after error and timeout of registration. 335 // TODO(maksymb): Implement waiting after error and timeout of registration.
313 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_ERROR; 336 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_ERROR;
314 reg_info_.error_description = description; 337 reg_info_.error_description = description;
315 } 338 }
316 339
340 void Printer::OnServerError(const std::string& description) {
341 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
342 LOG(ERROR) << "Server error: " << description;
343
344 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
345 }
346
347 void Printer::OnNetworkError() {
348 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
349 ChangeState(OFFLINE);
350 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
351 }
352
353 void Printer::OnPrintjobsAvailable(const std::vector<Printjob>& printjobs) {
354 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
355 ChangeState(ONLINE);
356
357 LOG(INFO) << "Available printjobs: " << printjobs.size();
358
359 if (printjobs.empty()) {
360 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kPrintjobsTimeout));
361 return;
362 }
363
364 // TODO(maksymb): After finishing XMPP add 'Printjobs available' flag.
365 LOG(INFO) << "Downloading first printjob.";
366 requester_->RequestPrintjob(printjobs[0]);
367 return;
368 }
369
370 void Printer::OnPrintjobDownloaded(const Printjob& printjob) {
371 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
372 printjob_handler_->SavePrintjob(
373 printjob.file,
374 printjob.ticket,
375 base::StringPrintf("%s.%s",
376 printjob.create_time.c_str(), printjob.jobid.c_str()),
377 printjob.title);
378 requester_->SendPrintjobDone(printjob.jobid);
379 }
380
381 void Printer::OnPrintjobDone() {
382 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
383 // TODO(maksymb): Replace PostTask with with XMPP notifications.
384 PostWakeUp();
385 }
386
317 PrivetHttpServer::RegistrationErrorStatus Printer::CheckCommonRegErrors( 387 PrivetHttpServer::RegistrationErrorStatus Printer::CheckCommonRegErrors(
318 const std::string& user) const { 388 const std::string& user) const {
319 DCHECK(!IsRegistered()); 389 DCHECK(!IsRegistered());
320 390
321 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED && 391 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED &&
322 user != reg_info_.user) { 392 user != reg_info_.user) {
323 return PrivetHttpServer::REG_ERROR_DEVICE_BUSY; 393 return PrivetHttpServer::REG_ERROR_DEVICE_BUSY;
324 } 394 }
325 395
326 if (reg_info_.state == RegistrationInfo::DEV_REG_REGISTRATION_ERROR) 396 if (reg_info_.state == RegistrationInfo::DEV_REG_REGISTRATION_ERROR)
(...skipping 16 matching lines...) Expand all
343 LOG(INFO) << "Registration confirmed by user."; 413 LOG(INFO) << "Registration confirmed by user.";
344 } else { 414 } else {
345 reg_info_.confirmation_state = RegistrationInfo::CONFIRMATION_DISCARDED; 415 reg_info_.confirmation_state = RegistrationInfo::CONFIRMATION_DISCARDED;
346 LOG(INFO) << "Registration discarded by user."; 416 LOG(INFO) << "Registration discarded by user.";
347 } 417 }
348 return; 418 return;
349 } 419 }
350 420
351 base::MessageLoop::current()->PostDelayedTask( 421 base::MessageLoop::current()->PostDelayedTask(
352 FROM_HERE, 422 FROM_HERE,
353 base::Bind(&Printer::WaitUserConfirmation, base::Unretained(this), 423 base::Bind(&Printer::WaitUserConfirmation, this->AsWeakPtr(),
354 valid_until), 424 valid_until),
355 base::TimeDelta::FromMilliseconds(100)); 425 base::TimeDelta::FromMilliseconds(100));
356 } 426 }
357 427
358 std::string Printer::GenerateProxyId() const { 428 std::string Printer::GenerateProxyId() const {
359 return "{" + base::GenerateGUID() +"}"; 429 return "{" + base::GenerateGUID() +"}";
360 } 430 }
361 431
362 std::vector<std::string> Printer::CreateTxt() const { 432 std::vector<std::string> Printer::CreateTxt() const {
363 std::vector<std::string> txt; 433 std::vector<std::string> txt;
364 txt.push_back("txtvers=1"); 434 txt.push_back("txtvers=1");
365 txt.push_back("ty=" + std::string(kPrinterName)); 435 txt.push_back("ty=" + std::string(kPrinterName));
366 txt.push_back("note=" + std::string(kPrinterDescription)); 436 txt.push_back("note=" + std::string(kPrinterDescription));
367 txt.push_back("url=" + std::string(kCloudPrintUrl)); 437 txt.push_back("url=" + std::string(kCloudPrintUrl));
368 txt.push_back("type=printer"); 438 txt.push_back("type=printer");
369 txt.push_back("id=" + reg_info_.device_id); 439 txt.push_back("id=" + reg_info_.device_id);
370 txt.push_back("cs=offline"); 440 txt.push_back("cs=" + ConnectionStateToString(connection_state_));
371 441
372 return txt; 442 return txt;
373 } 443 }
374 444
445 void Printer::FetchPrintjobs() {
446 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
447
448 if (!IsRegistered())
449 return;
450
451 if (requester_->IsBusy()) {
452 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
453 } else {
454 requester_->FetchPrintjobs(reg_info_.refresh_token, reg_info_.device_id);
455 }
456 }
457
375 void Printer::SaveToFile(const std::string& filename) const { 458 void Printer::SaveToFile(const std::string& filename) const {
376 base::DictionaryValue json; 459 base::DictionaryValue json;
377 // TODO(maksymb): Get rid of in-place constants. 460 // TODO(maksymb): Get rid of in-place constants.
378 if (IsRegistered()) { 461 if (IsRegistered()) {
379 json.SetBoolean("registered", true); 462 json.SetBoolean("registered", true);
380 json.SetString("user", reg_info_.user); 463 json.SetString("user", reg_info_.user);
381 json.SetString("device_id", reg_info_.device_id); 464 json.SetString("device_id", reg_info_.device_id);
382 json.SetString("refresh_token", reg_info_.refresh_token); 465 json.SetString("refresh_token", reg_info_.refresh_token);
383 } else { 466 } else {
384 json.SetBoolean("registered", false); 467 json.SetBoolean("registered", false);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 529
447 reg_info_ = RegistrationInfo(); 530 reg_info_ = RegistrationInfo();
448 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED; 531 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED;
449 reg_info_.user = user; 532 reg_info_.user = user;
450 reg_info_.device_id = device_id; 533 reg_info_.device_id = device_id;
451 reg_info_.refresh_token = refresh_token; 534 reg_info_.refresh_token = refresh_token;
452 535
453 return true; 536 return true;
454 } 537 }
455 538
539 void Printer::PostWakeUp() {
540 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
541 base::MessageLoop::current()->PostTask(
542 FROM_HERE,
543 base::Bind(&Printer::WakeUp, this->AsWeakPtr()));
544 }
545
546 void Printer::PostDelayedWakeUp(const base::TimeDelta& delay) {
547 LOG_IF(INFO, kFunctionVebose) << "Function: " << __FUNCTION__;
548 base::MessageLoop::current()->PostDelayedTask(
549 FROM_HERE,
550 base::Bind(&Printer::WakeUp, this->AsWeakPtr()),
551 delay);
552 }
553
456 PrivetHttpServer::RegistrationErrorStatus 554 PrivetHttpServer::RegistrationErrorStatus
457 Printer::ConfirmationToRegistrationError( 555 Printer::ConfirmationToRegistrationError(
458 RegistrationInfo::ConfirmationState state) { 556 RegistrationInfo::ConfirmationState state) {
459 switch (state) { 557 switch (state) {
460 case RegistrationInfo::CONFIRMATION_PENDING: 558 case RegistrationInfo::CONFIRMATION_PENDING:
461 return PrivetHttpServer::REG_ERROR_PENDING_USER_ACTION; 559 return PrivetHttpServer::REG_ERROR_PENDING_USER_ACTION;
462 case RegistrationInfo::CONFIRMATION_DISCARDED: 560 case RegistrationInfo::CONFIRMATION_DISCARDED:
463 return PrivetHttpServer::REG_ERROR_USER_CANCEL; 561 return PrivetHttpServer::REG_ERROR_USER_CANCEL;
464 case RegistrationInfo::CONFIRMATION_CONFIRMED: 562 case RegistrationInfo::CONFIRMATION_CONFIRMED:
465 NOTREACHED(); 563 NOTREACHED();
466 return PrivetHttpServer::REG_ERROR_OK; 564 return PrivetHttpServer::REG_ERROR_OK;
467 case RegistrationInfo::CONFIRMATION_TIMEOUT: 565 case RegistrationInfo::CONFIRMATION_TIMEOUT:
468 return PrivetHttpServer::REG_ERROR_CONFIRMATION_TIMEOUT; 566 return PrivetHttpServer::REG_ERROR_CONFIRMATION_TIMEOUT;
469 default: 567 default:
470 NOTREACHED(); 568 NOTREACHED();
471 return PrivetHttpServer::REG_ERROR_OK; 569 return PrivetHttpServer::REG_ERROR_OK;
472 } 570 }
473 } 571 }
474 572
573 std::string Printer::ConnectionStateToString(ConnectionState state) const {
574 if (state == OFFLINE)
575 return "offline";
576 if (state == ONLINE)
577 return "online";
578 if (state == CONNECTING)
579 return "connecting";
580 if (state == NOT_CONFIGURED)
581 return "not-configured";
582
583 NOTREACHED();
584 return "";
585 }
586
587 bool Printer::ChangeState(ConnectionState new_state) {
588 if (connection_state_ == new_state)
589 return false;
590
591 VLOG(1) << "Printer is now " << ConnectionStateToString(new_state);
592 connection_state_ = new_state;
593 dns_server_.UpdateMetadata(CreateTxt());
594 return true;
595 }
596
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698