Pārlūkot izejas kodu

Change string types to enum

Murat Dogan 5 gadi atpakaļ
vecāks
revīzija
dffca48e69
4 mainītis faili ar 56 papildinājumiem un 22 dzēšanām
  1. 8 2
      include/rtc/candidate.hpp
  2. 32 0
      src/candidate.cpp
  3. 14 18
      src/icetransport.cpp
  4. 2 2
      src/icetransport.hpp

+ 8 - 2
include/rtc/candidate.hpp

@@ -26,11 +26,13 @@
 namespace rtc {
 
 #if not USE_JUICE
+enum class CandidateType { HOST = 0, SERVER_REFLEXIVE, PEER_REFLEXIVE, RELAYED };
+enum class CandidateTransportType { UDP = 0, TCP_ACTIVE, TCP_PASSIVE, TCP_SO };
 struct CandidateInfo {
 	string address;
 	int port;
-	string type;
-	string transportType;
+	CandidateType type;
+	CandidateTransportType transportType;
 };
 #endif
 
@@ -55,6 +57,10 @@ private:
 } // namespace rtc
 
 std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate);
+#if not USE_JUICE
+std::ostream &operator<<(std::ostream &out, const rtc::CandidateType &type);
+std::ostream &operator<<(std::ostream &out, const rtc::CandidateTransportType &transportType);
+#endif
 
 #endif
 

+ 32 - 0
src/candidate.cpp

@@ -131,3 +131,35 @@ Candidate::operator string() const {
 std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate) {
 	return out << std::string(candidate);
 }
+
+#if not USE_JUICE
+std::ostream &operator<<(std::ostream &out, const rtc::CandidateType &type) {
+	switch (type) {
+	case rtc::CandidateType::HOST:
+		return out << "HOST";
+	case rtc::CandidateType::PEER_REFLEXIVE:
+		return out << "PEER_REFLEXIVE";
+	case rtc::CandidateType::RELAYED:
+		return out << "RELAYED";
+	case rtc::CandidateType::SERVER_REFLEXIVE:
+		return out << "SERVER_REFLEXIVE";
+	default:
+		return out << "UNKOWN";
+	}
+}
+
+std::ostream &operator<<(std::ostream &out, const rtc::CandidateTransportType &transportType) {
+	switch (transportType) {
+	case rtc::CandidateTransportType::TCP_ACTIVE:
+		return out << "TCP_ACTIVE";
+	case rtc::CandidateTransportType::TCP_PASSIVE:
+		return out << "TCP_PASSIVE";
+	case rtc::CandidateTransportType::TCP_SO:
+		return out << "TCP_SO";
+	case rtc::CandidateTransportType::UDP:
+		return out << "UDP";
+	default:
+		return out << "UNKOWN";
+	}
+}
+#endif

+ 14 - 18
src/icetransport.cpp

@@ -667,47 +667,43 @@ bool IceTransport::getSelectedCandidatePair(CandidateInfo *localInfo, CandidateI
 	nice_address_to_string(&local->addr, ipaddr);
 	localInfo->address = std::string(ipaddr);
 	localInfo->port = nice_address_get_port(&local->addr);
-	localInfo->type = IceTransport::CandidateTypeToString(local->type);
-	localInfo->transportType = IceTransport::CandidateTransportTypeToString(local->transport);
+	localInfo->type = IceTransport::NiceTypeToCandidateType(local->type);
+	localInfo->transportType = IceTransport::NiceTransportTypeToCandidateTransportType(local->transport);
 
 	nice_address_to_string(&remote->addr, ipaddr);
 	remoteInfo->address = std::string(ipaddr);
 	remoteInfo->port = nice_address_get_port(&remote->addr);
-	remoteInfo->type = IceTransport::CandidateTypeToString(remote->type);
-	remoteInfo->transportType = IceTransport::CandidateTransportTypeToString(remote->transport);
+	remoteInfo->type = IceTransport::NiceTypeToCandidateType(remote->type);
+	remoteInfo->transportType = IceTransport::NiceTransportTypeToCandidateTransportType(remote->transport);
 
 	nice_candidate_free(local);
 	nice_candidate_free(remote);
 	return true;
 }
 
-const std::string IceTransport::CandidateTypeToString(NiceCandidateType type) {
+const CandidateType IceTransport::NiceTypeToCandidateType(NiceCandidateType type) {
 	switch (type) {
 	case NiceCandidateType::NICE_CANDIDATE_TYPE_HOST:
-		return "HOST";
+		return CandidateType::HOST;
 	case NiceCandidateType::NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
-		return "PEER_REFLEXIVE";
+		return CandidateType::PEER_REFLEXIVE;
 	case NiceCandidateType::NICE_CANDIDATE_TYPE_RELAYED:
-		return "RELAYED";
+		return CandidateType::RELAYED;
 	case NiceCandidateType::NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
-		return "SERVER_REFLEXIVE";
-	default:
-		break;
+		return CandidateType::SERVER_REFLEXIVE;
 	}
 }
 
-const std::string IceTransport::CandidateTransportTypeToString(NiceCandidateTransport type) {
+const CandidateTransportType IceTransport::NiceTransportTypeToCandidateTransportType(NiceCandidateTransport type) {
 	switch (type) {
 	case NiceCandidateTransport::NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE:
-		return "TCP_ACTIVE";
+		return CandidateTransportType::TCP_ACTIVE;
 	case NiceCandidateTransport::NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE:
-		return "TCP_PASSIVE";
+		return CandidateTransportType::TCP_PASSIVE;
 	case NiceCandidateTransport::NICE_CANDIDATE_TRANSPORT_TCP_SO:
-		return "TCP_SO";
+		return CandidateTransportType::TCP_SO;
 	case NiceCandidateTransport::NICE_CANDIDATE_TRANSPORT_UDP:
-		return "UDP";
-	default:
-		break;
+		return CandidateTransportType::UDP;
 	}
 }
 

+ 2 - 2
src/icetransport.hpp

@@ -135,8 +135,8 @@ private:
 	static gboolean TimeoutCallback(gpointer userData);
 	static void LogCallback(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message,
 	                        gpointer user_data);
-	static const std::string CandidateTypeToString(NiceCandidateType type);
-	static const std::string CandidateTransportTypeToString(NiceCandidateTransport type);
+	static const CandidateType NiceTypeToCandidateType(NiceCandidateType type);
+	static const CandidateTransportType NiceTransportTypeToCandidateTransportType(NiceCandidateTransport type);
 #endif
 };