Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/protocol/errors.h" | 5 #include "remoting/protocol/errors.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 namespace protocol { | 10 namespace protocol { |
| 11 | 11 |
| 12 #define RETURN_STRING_LITERAL(x) \ | 12 #define MAP_STRING_LITERAL(x) \ |
|
Sergey Ulanov
2016/06/03 08:43:22
remove this define
Hzj_jie
2016/06/03 21:46:33
Done.
| |
| 13 case x: \ | 13 { x, #x } |
| 14 return #x; | 14 namespace { |
| 15 | |
| 16 const NameMapElement<ErrorCode> kErrorCodeNames[] = { | |
| 17 { OK, "OK" }, | |
| 18 { PEER_IS_OFFLINE, "PEER_IS_OFFLINE" }, | |
| 19 { SESSION_REJECTED, "SESSION_REJECTED" }, | |
| 20 { INCOMPATIBLE_PROTOCOL, "INCOMPATIBLE_PROTOCOL" }, | |
| 21 { AUTHENTICATION_FAILED, "AUTHENTICATION_FAILED" }, | |
| 22 { INVALID_ACCOUNT, "INVALID_ACCOUNT" }, | |
| 23 { CHANNEL_CONNECTION_ERROR, "CHANNEL_CONNECTION_ERROR" }, | |
| 24 { SIGNALING_ERROR, "SIGNALING_ERROR" }, | |
| 25 { SIGNALING_TIMEOUT, "SIGNALING_TIMEOUT" }, | |
| 26 { HOST_OVERLOAD, "HOST_OVERLOAD" }, | |
| 27 { MAX_SESSION_LENGTH, "MAX_SESSION_LENGTH" }, | |
| 28 { HOST_CONFIGURATION_ERROR, "HOST_CONFIGURATION_ERROR" }, | |
| 29 { UNKNOWN_ERROR, "UNKNOWN_ERROR" }, | |
| 30 }; | |
| 31 | |
| 32 } | |
| 15 | 33 |
| 16 const char* ErrorCodeToString(ErrorCode error) { | 34 const char* ErrorCodeToString(ErrorCode error) { |
| 17 switch (error) { | 35 return ValueToName(kErrorCodeNames, error); |
| 18 RETURN_STRING_LITERAL(OK); | 36 } |
| 19 RETURN_STRING_LITERAL(PEER_IS_OFFLINE); | 37 |
| 20 RETURN_STRING_LITERAL(SESSION_REJECTED); | 38 bool ParseErrorCode(const std::string& name, ErrorCode* result) { |
| 21 RETURN_STRING_LITERAL(INCOMPATIBLE_PROTOCOL); | 39 return NameToValue(kErrorCodeNames, name, result); |
| 22 RETURN_STRING_LITERAL(AUTHENTICATION_FAILED); | |
| 23 RETURN_STRING_LITERAL(INVALID_ACCOUNT); | |
| 24 RETURN_STRING_LITERAL(CHANNEL_CONNECTION_ERROR); | |
| 25 RETURN_STRING_LITERAL(SIGNALING_ERROR); | |
| 26 RETURN_STRING_LITERAL(SIGNALING_TIMEOUT); | |
| 27 RETURN_STRING_LITERAL(HOST_OVERLOAD); | |
| 28 RETURN_STRING_LITERAL(MAX_SESSION_LENGTH); | |
| 29 RETURN_STRING_LITERAL(HOST_CONFIGURATION_ERROR); | |
| 30 RETURN_STRING_LITERAL(UNKNOWN_ERROR); | |
| 31 } | |
| 32 NOTREACHED(); | |
| 33 return nullptr; | |
| 34 } | 40 } |
| 35 | 41 |
| 36 } // namespace protocol | 42 } // namespace protocol |
| 37 } // namespace remoting | 43 } // namespace remoting |
| OLD | NEW |