Android-cuttlefish cvd tool
server_connection.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14//
15
16#pragma once
17
18#include <string.h>
19
20#include <memory>
21#include <string>
22
23#include "json/json.h"
24
25namespace cuttlefish {
26namespace webrtc_streaming {
27
29 public:
30 virtual ~ServerConnectionObserver() = default;
31 // Called when the connection to the server has been established. This is the
32 // cue to start using Send().
33 virtual void OnOpen() = 0;
34 virtual void OnClose() = 0;
35 // Called when the connection to the server has failed with an unrecoverable
36 // error.
37 virtual void OnError(const std::string& error) = 0;
38 virtual void OnReceive(const uint8_t* msg, size_t length, bool is_binary) = 0;
39};
40
41// Represents a connection to the signaling server. When a connection is created
42// it connects with the server automatically but sends no info.
43// Only Send() can be called from multiple threads simultaneously. Reconnect(),
44// Send() and the destructor will run into race conditions if called
45// concurrently.
47 public:
48 static std::unique_ptr<ServerConnection> Connect(
49 const std::string& operator_path,
50 std::weak_ptr<ServerConnectionObserver> observer);
51
52 // Destroying the connection will disconnect from the signaling server and
53 // release any open fds.
54 virtual ~ServerConnection() = default;
55
56 // Sends data to the server encoded as JSON.
57 virtual bool Send(const Json::Value&) = 0;
58
59 // makes re-connect request
60 virtual void Reconnect();
61
62 private:
63 virtual void Connect() = 0;
64};
65
66} // namespace webrtc_streaming
67} // namespace cuttlefish
virtual void OnReceive(const uint8_t *msg, size_t length, bool is_binary)=0
virtual void OnError(const std::string &error)=0
Definition: server_connection.h:46
virtual bool Send(const Json::Value &)=0
virtual void Reconnect()
Definition: server_connection.cpp:66
#define error(format, args...)
Definition: fec_private.h:201
Definition: alloc_utils.cpp:23