diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | cast/common/BUILD.gn | 12 | ||||
-rw-r--r-- | cast/common/discovery/service_info.h | 72 | ||||
-rw-r--r-- | platform/base/ip_address.cc | 4 | ||||
-rw-r--r-- | platform/base/ip_address.h | 5 | ||||
-rw-r--r-- | platform/base/ip_address_unittest.cc | 22 |
6 files changed, 114 insertions, 2 deletions
@@ -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 |