Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / p2p / base / transportdescription.cc
1 /*
2  *  Copyright 2013 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include "webrtc/p2p/base/transportdescription.h"
12
13 #include "webrtc/p2p/base/constants.h"
14 #include "webrtc/base/stringutils.h"
15
16 namespace cricket {
17
18 bool StringToConnectionRole(const std::string& role_str, ConnectionRole* role) {
19   const char* const roles[] = {
20       CONNECTIONROLE_ACTIVE_STR,
21       CONNECTIONROLE_PASSIVE_STR,
22       CONNECTIONROLE_ACTPASS_STR,
23       CONNECTIONROLE_HOLDCONN_STR
24   };
25
26   for (size_t i = 0; i < ARRAY_SIZE(roles); ++i) {
27     if (_stricmp(roles[i], role_str.c_str()) == 0) {
28       *role = static_cast<ConnectionRole>(CONNECTIONROLE_ACTIVE + i);
29       return true;
30     }
31   }
32   return false;
33 }
34
35 bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str) {
36   switch (role) {
37     case cricket::CONNECTIONROLE_ACTIVE:
38       *role_str = cricket::CONNECTIONROLE_ACTIVE_STR;
39       break;
40     case cricket::CONNECTIONROLE_ACTPASS:
41       *role_str = cricket::CONNECTIONROLE_ACTPASS_STR;
42       break;
43     case cricket::CONNECTIONROLE_PASSIVE:
44       *role_str = cricket::CONNECTIONROLE_PASSIVE_STR;
45       break;
46     case cricket::CONNECTIONROLE_HOLDCONN:
47       *role_str = cricket::CONNECTIONROLE_HOLDCONN_STR;
48       break;
49     default:
50       return false;
51   }
52   return true;
53 }
54
55 }  // namespace cricket