aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Keane <rwkeane@google.com>2019-12-16 23:46:55 -0800
committerCommit Bot <commit-bot@chromium.org>2019-12-17 07:55:30 +0000
commitb7cdb6cb46466e1a6d53ca5c0bcc772f12efc78e (patch)
tree5aa722d3e9c530a548d7995993488f94197d6c0d
parent74e98d10f7adc798da2b0d3e0b2d837662a11b5e (diff)
downloadopenscreen-b7cdb6cb46466e1a6d53ca5c0bcc772f12efc78e.tar.gz
Discovery: CastV2 Struct
This CL introduces a new CastV2 specific struct to hold all service- instance related information. It is intended for use with the top-level discovery API shown here: https://chromium-review.googlesource.com/c/openscreen/+/1959588 Change-Id: I47230dc785e557598c7f56754f247e873d1dd433 Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1961045 Commit-Queue: Ryan Keane <rwkeane@google.com> Reviewed-by: mark a. foltz <mfoltz@chromium.org>
-rw-r--r--BUILD.gn1
-rw-r--r--cast/common/BUILD.gn12
-rw-r--r--cast/common/discovery/service_info.h72
-rw-r--r--platform/base/ip_address.cc4
-rw-r--r--platform/base/ip_address.h5
-rw-r--r--platform/base/ip_address_unittest.cc22
6 files changed, 114 insertions, 2 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 45c89852..056c7d0d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -11,6 +11,7 @@ group("gn_all") {
deps = [
"cast/common:certificate",
"cast/common:channel",
+ "cast/common:discovery",
"cast/sender:channel",
"cast/streaming:receiver",
"cast/streaming:sender",
diff --git a/cast/common/BUILD.gn b/cast/common/BUILD.gn
index 537153bd..5e3227da 100644
--- a/cast/common/BUILD.gn
+++ b/cast/common/BUILD.gn
@@ -59,6 +59,18 @@ source_set("channel") {
]
}
+source_set("discovery") {
+ sources = [
+ "discovery/service_info.h",
+ ]
+
+ deps = []
+
+ public_deps = [
+ "../../platform",
+ ]
+}
+
source_set("test_helpers") {
testonly = true
sources = [
diff --git a/cast/common/discovery/service_info.h b/cast/common/discovery/service_info.h
new file mode 100644
index 00000000..cd028f86
--- /dev/null
+++ b/cast/common/discovery/service_info.h
@@ -0,0 +1,72 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CAST_COMMON_DISCOVERY_SERVICE_INFO_H_
+#define CAST_COMMON_DISCOVERY_SERVICE_INFO_H_
+
+#include <memory>
+#include <string>
+
+#include "platform/base/ip_address.h"
+
+namespace openscreen {
+namespace cast {
+
+// This represents the ‘st’ flag in the CastV2 TXT record.
+enum ReceiverStatus {
+ // The receiver is idle and does not need to be connected now.
+ kIdle = 0,
+
+ // The receiver is hosting an activity and invites the sender to join. The
+ // receiver should connect to the running activity using the channel
+ // establishment protocol, and then query the activity to determine the next
+ // step, such as showing a description of the activity and prompting the user
+ // to launch the corresponding app.
+ kBusy = 1,
+ kJoin = kBusy
+};
+
+// This represents the ‘ca’ field in the CastV2 spec.
+enum ReceiverCapabilities : uint64_t {
+ kHasVideoOutput = 0x01 << 0,
+ kHasVideoInput = 0x01 << 1,
+ kHasAudioOutput = 0x01 << 2,
+ kHasAudioInput = 0x01 << 3,
+ kIsDevModeEnabled = 0x01 << 4,
+};
+
+// This is the top-level service info class for CastV2. It describes a specific
+// service instance.
+struct ServiceInfo {
+ // Endpoints for the service. Present if an endpoint of this address type
+ // exists and empty otherwise.
+ IPEndpoint v4_address;
+ IPEndpoint v6_address;
+
+ // A UUID for the Cast receiver. This should be a universally unique
+ // identifier for the receiver, and should (but does not have to be) be stable
+ // across factory resets.
+ std::string unique_id;
+
+ // Cast protocol version supported. Begins at 2 and is incremented by 1 with
+ // each version.
+ uint8_t protocol_version;
+
+ // Capabilities supported by this service instance.
+ ReceiverCapabilities capabilities;
+
+ // Status of the service instance.
+ ReceiverStatus status;
+
+ // The model name of the device, e.g. “Eureka v1”, “Mollie”.
+ std::string model_name;
+
+ // The friendly name of the device, e.g. “Living Room TV".
+ std::string friendly_name;
+};
+
+} // namespace cast
+} // namespace openscreen
+
+#endif // CAST_COMMON_DISCOVERY_SERVICE_INFO_H_
diff --git a/platform/base/ip_address.cc b/platform/base/ip_address.cc
index b95a443e..97870f6c 100644
--- a/platform/base/ip_address.cc
+++ b/platform/base/ip_address.cc
@@ -203,6 +203,10 @@ ErrorOr<IPAddress> IPAddress::ParseV6(const std::string& s) {
return IPAddress(hextets);
}
+IPEndpoint::operator bool() const {
+ return address || port;
+}
+
bool operator==(const IPEndpoint& a, const IPEndpoint& b) {
return (a.address == b.address) && (a.port == b.port);
}
diff --git a/platform/base/ip_address.h b/platform/base/ip_address.h
index 2cd35352..aae3a13c 100644
--- a/platform/base/ip_address.h
+++ b/platform/base/ip_address.h
@@ -90,9 +90,10 @@ class IPAddress {
struct IPEndpoint {
public:
IPAddress address;
- uint16_t port;
-};
+ uint16_t port = 0;
+ explicit operator bool() const;
+};
bool operator==(const IPEndpoint& a, const IPEndpoint& b);
bool operator!=(const IPEndpoint& a, const IPEndpoint& b);
diff --git a/platform/base/ip_address_unittest.cc b/platform/base/ip_address_unittest.cc
index c012cc89..b18e8de0 100644
--- a/platform/base/ip_address_unittest.cc
+++ b/platform/base/ip_address_unittest.cc
@@ -257,4 +257,26 @@ TEST(IPAddressTest, V6ParseThreeDigitValue) {
0x01, 0x23}));
}
+TEST(IPAddressTest, IPEndpointBoolOperator) {
+ IPEndpoint endpoint;
+ if (endpoint) {
+ FAIL();
+ }
+
+ endpoint = IPEndpoint{{192, 168, 0, 1}, 80};
+ if (!endpoint) {
+ FAIL();
+ }
+
+ endpoint = IPEndpoint{{192, 168, 0, 1}, 0};
+ if (!endpoint) {
+ FAIL();
+ }
+
+ endpoint = IPEndpoint{{}, 80};
+ if (!endpoint) {
+ FAIL();
+ }
+}
+
} // namespace openscreen