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 #include "remoting/protocol/name_value_map.h" | |
| 8 | 9 |
| 9 namespace remoting { | 10 namespace remoting { |
| 10 namespace protocol { | 11 namespace protocol { |
| 11 | 12 |
| 12 #define RETURN_STRING_LITERAL(x) \ | 13 namespace { |
| 13 case x: \ | 14 |
| 14 return #x; | 15 const NameMapElement<ErrorCode> kErrorCodeNames[] = { |
| 16 { OK, "OK" }, | |
| 17 { PEER_IS_OFFLINE, "PEER_IS_OFFLINE" }, | |
| 18 { SESSION_REJECTED, "SESSION_REJECTED" }, | |
| 19 { INCOMPATIBLE_PROTOCOL, "INCOMPATIBLE_PROTOCOL" }, | |
| 20 { AUTHENTICATION_FAILED, "AUTHENTICATION_FAILED" }, | |
| 21 { INVALID_ACCOUNT, "INVALID_ACCOUNT" }, | |
| 22 { CHANNEL_CONNECTION_ERROR, "CHANNEL_CONNECTION_ERROR" }, | |
| 23 { SIGNALING_ERROR, "SIGNALING_ERROR" }, | |
| 24 { SIGNALING_TIMEOUT, "SIGNALING_TIMEOUT" }, | |
| 25 { HOST_OVERLOAD, "HOST_OVERLOAD" }, | |
| 26 { MAX_SESSION_LENGTH, "MAX_SESSION_LENGTH" }, | |
| 27 { HOST_CONFIGURATION_ERROR, "HOST_CONFIGURATION_ERROR" }, | |
| 28 { UNKNOWN_ERROR, "UNKNOWN_ERROR" }, | |
| 29 }; | |
| 30 | |
| 31 } | |
|
Sergey Ulanov
2016/06/07 16:22:23
// namespace
Hzj_jie
2016/06/07 19:29:56
Done.
| |
| 15 | 32 |
| 16 const char* ErrorCodeToString(ErrorCode error) { | 33 const char* ErrorCodeToString(ErrorCode error) { |
| 17 switch (error) { | 34 return ValueToName(kErrorCodeNames, error); |
| 18 RETURN_STRING_LITERAL(OK); | 35 } |
| 19 RETURN_STRING_LITERAL(PEER_IS_OFFLINE); | 36 |
| 20 RETURN_STRING_LITERAL(SESSION_REJECTED); | 37 bool ParseErrorCode(const std::string& name, ErrorCode* result) { |
| 21 RETURN_STRING_LITERAL(INCOMPATIBLE_PROTOCOL); | 38 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 } | 39 } |
| 35 | 40 |
| 36 } // namespace protocol | 41 } // namespace protocol |
| 37 } // namespace remoting | 42 } // namespace remoting |
| OLD | NEW |