1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "osp/public/protocol_connection_client.h"
6
7 namespace openscreen {
8 namespace osp {
9
10 ProtocolConnectionClient::ConnectRequest::ConnectRequest() = default;
11
ConnectRequest(ProtocolConnectionClient * parent,uint64_t request_id)12 ProtocolConnectionClient::ConnectRequest::ConnectRequest(
13 ProtocolConnectionClient* parent,
14 uint64_t request_id)
15 : parent_(parent), request_id_(request_id) {}
16
ConnectRequest(ConnectRequest && other)17 ProtocolConnectionClient::ConnectRequest::ConnectRequest(ConnectRequest&& other)
18 : parent_(other.parent_), request_id_(other.request_id_) {
19 other.request_id_ = 0;
20 }
21
~ConnectRequest()22 ProtocolConnectionClient::ConnectRequest::~ConnectRequest() {
23 if (request_id_)
24 parent_->CancelConnectRequest(request_id_);
25 }
26
27 ProtocolConnectionClient::ConnectRequest&
operator =(ConnectRequest && other)28 ProtocolConnectionClient::ConnectRequest::operator=(ConnectRequest&& other) {
29 using std::swap;
30 swap(parent_, other.parent_);
31 swap(request_id_, other.request_id_);
32 return *this;
33 }
34
ProtocolConnectionClient(MessageDemuxer * demuxer,ProtocolConnectionServiceObserver * observer)35 ProtocolConnectionClient::ProtocolConnectionClient(
36 MessageDemuxer* demuxer,
37 ProtocolConnectionServiceObserver* observer)
38 : demuxer_(demuxer),
39 endpoint_request_ids_(EndpointRequestIds::Role::kClient),
40 observer_(observer) {}
41
42 ProtocolConnectionClient::~ProtocolConnectionClient() = default;
43
operator <<(std::ostream & os,ProtocolConnectionClient::State state)44 std::ostream& operator<<(std::ostream& os,
45 ProtocolConnectionClient::State state) {
46 switch (state) {
47 case ProtocolConnectionClient::State::kStopped:
48 return os << "STOPPED";
49 case ProtocolConnectionClient::State::kStarting:
50 return os << "STARTING";
51 case ProtocolConnectionClient::State::kRunning:
52 return os << "RUNNING";
53 case ProtocolConnectionClient::State::kStopping:
54 return os << "STOPPING";
55 default:
56 return os << "UNKNOWN";
57 }
58 }
59
60 } // namespace osp
61 } // namespace openscreen
62