mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: Ic2bdb234e89f3c5860d1b483dd4bce689f13d057
This commit is contained in:
@@ -21,53 +21,99 @@
|
||||
#include "core/internal/pcp.h"
|
||||
#include "core/listeners.h"
|
||||
#include "core/options.h"
|
||||
#include "core/params.h"
|
||||
#include "core/status.h"
|
||||
#include "core/strategy.h"
|
||||
#include "platform/port/string.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
inline Pcp StrategyToPcp(Strategy strategy) {
|
||||
if (strategy == Strategy::kP2pCluster) return Pcp::kP2pCluster;
|
||||
if (strategy == Strategy::kP2pStar) return Pcp::kP2pStar;
|
||||
if (strategy == Strategy::kP2pPointToPoint) return Pcp::kP2pPointToPoint;
|
||||
return Pcp::kUnknown;
|
||||
}
|
||||
|
||||
inline Strategy PcpToStrategy(Pcp pcp) {
|
||||
if (pcp == Pcp::kP2pCluster) return Strategy::kP2pCluster;
|
||||
if (pcp == Pcp::kP2pStar) return Strategy::kP2pStar;
|
||||
if (pcp == Pcp::kP2pPointToPoint) return Strategy::kP2pPointToPoint;
|
||||
return Strategy::kNone;
|
||||
}
|
||||
|
||||
// Defines the set of methods that need to be implemented to handle the
|
||||
// per-PCP-specific operations in the OfflineServiceController.
|
||||
//
|
||||
// <p>These methods are all meant to be synchronous, and should return only
|
||||
// after knowing they've done what they were supposed to do (or unequivocally
|
||||
// failed to do so).
|
||||
template <typename Platform>
|
||||
class PCPHandler {
|
||||
// These methods are all meant to be synchronous, and should return only after
|
||||
// knowing they've done what they were supposed to do (or unequivocally failed
|
||||
// to do so).
|
||||
//
|
||||
// See details here:
|
||||
// cpp/core/core.h
|
||||
class PcpHandler {
|
||||
public:
|
||||
virtual ~PCPHandler() {}
|
||||
virtual ~PcpHandler() = default;
|
||||
|
||||
virtual Strategy getStrategy() = 0;
|
||||
virtual PCP::Value getPCP() = 0;
|
||||
// Return strategy supported by this protocol.
|
||||
virtual Strategy GetStrategy() const = 0;
|
||||
|
||||
virtual Status::Value startAdvertising(
|
||||
Ptr<ClientProxy<Platform> > client_proxy, const string& service_id,
|
||||
const string& local_endpoint_name,
|
||||
const AdvertisingOptions& advertising_options,
|
||||
Ptr<ConnectionLifecycleListener> connection_lifecycle_listener) = 0;
|
||||
virtual void stopAdvertising(Ptr<ClientProxy<Platform> > client_proxy) = 0;
|
||||
// Return concrete variant of protocol.
|
||||
virtual Pcp GetPcp() const = 0;
|
||||
|
||||
virtual Status::Value startDiscovery(
|
||||
Ptr<ClientProxy<Platform> > client_proxy, const string& service_id,
|
||||
const DiscoveryOptions& discovery_options,
|
||||
Ptr<DiscoveryListener> discovery_listener) = 0;
|
||||
virtual void stopDiscovery(Ptr<ClientProxy<Platform> > client_proxy) = 0;
|
||||
// We have been asked by the client to start advertising. Once we successfully
|
||||
// start advertising, we'll change the ClientProxy's state.
|
||||
// ConnectionListener (info.listener) will be notified in case of any event.
|
||||
// See
|
||||
// cpp/core/listeners.h
|
||||
virtual Status StartAdvertising(ClientProxy* client,
|
||||
const std::string& service_id,
|
||||
const ConnectionOptions& options,
|
||||
const ConnectionRequestInfo& info) = 0;
|
||||
|
||||
virtual Status::Value requestConnection(
|
||||
Ptr<ClientProxy<Platform> > client_proxy,
|
||||
const string& local_endpoint_name, const string& endpoint_id,
|
||||
Ptr<ConnectionLifecycleListener> connection_lifecycle_listener) = 0;
|
||||
virtual Status::Value acceptConnection(
|
||||
Ptr<ClientProxy<Platform> > clientProxy, const string& endpoint_id,
|
||||
Ptr<PayloadListener> payload_listener) = 0;
|
||||
virtual Status::Value rejectConnection(
|
||||
Ptr<ClientProxy<Platform> > client_proxy, const string& endpoint_id) = 0;
|
||||
// If Advertising is active, stop it, and change CLientProxy state,
|
||||
// otherwise do nothing.
|
||||
virtual void StopAdvertising(ClientProxy* client) = 0;
|
||||
|
||||
virtual proto::connections::Medium getBandwidthUpgradeMedium() = 0;
|
||||
// Start discovery of endpoints that may be advertising.
|
||||
// Update ClientProxy state once discovery started.
|
||||
// DiscoveryListener will get called in case of any event.
|
||||
virtual Status StartDiscovery(ClientProxy* client,
|
||||
const std::string& service_id,
|
||||
const ConnectionOptions& options,
|
||||
const DiscoveryListener& listener) = 0;
|
||||
|
||||
// If Discovery is active, stop it, and change CLientProxy state,
|
||||
// otherwise do nothing.
|
||||
virtual void StopDiscovery(ClientProxy* client) = 0;
|
||||
|
||||
// If Discovery is active with is_out_of_band_connection == true, invoke the
|
||||
// callback with the provided endpoint info.
|
||||
virtual void InjectEndpoint(ClientProxy* client,
|
||||
const std::string& service_id,
|
||||
const OutOfBandConnectionMetadata& metadata) = 0;
|
||||
|
||||
// If remote endpoint has been successfully discovered, request it to form a
|
||||
// connection, update state on ClientProxy.
|
||||
virtual Status RequestConnection(ClientProxy* client,
|
||||
const std::string& endpoint_id,
|
||||
const ConnectionRequestInfo& info,
|
||||
const ConnectionOptions& options) = 0;
|
||||
|
||||
// Either party may call this to accept connection on their part.
|
||||
// Until both parties call it, connection will not reach a data phase.
|
||||
// Update state in ClientProxy.
|
||||
virtual Status AcceptConnection(ClientProxy* client,
|
||||
const std::string& endpoint_id,
|
||||
const PayloadListener& payload_listener) = 0;
|
||||
|
||||
// Either party may call this to reject connection on their part before
|
||||
// connection reaches data phase. If either party does call it, connection
|
||||
// will terminate. Update state in ClientProxy.
|
||||
virtual Status RejectConnection(ClientProxy* client,
|
||||
const std::string& endpoint_id) = 0;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
Reference in New Issue
Block a user