• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/network_service_manager.h"
6 
7 namespace {
8 
9 openscreen::osp::NetworkServiceManager* g_network_service_manager_instance =
10     nullptr;
11 
12 }  //  namespace
13 
14 namespace openscreen {
15 namespace osp {
16 
17 // static
Create(std::unique_ptr<ServiceListener> mdns_listener,std::unique_ptr<ServicePublisher> mdns_publisher,std::unique_ptr<ProtocolConnectionClient> connection_client,std::unique_ptr<ProtocolConnectionServer> connection_server)18 NetworkServiceManager* NetworkServiceManager::Create(
19     std::unique_ptr<ServiceListener> mdns_listener,
20     std::unique_ptr<ServicePublisher> mdns_publisher,
21     std::unique_ptr<ProtocolConnectionClient> connection_client,
22     std::unique_ptr<ProtocolConnectionServer> connection_server) {
23   // TODO(mfoltz): Convert to assertion failure
24   if (g_network_service_manager_instance)
25     return nullptr;
26   g_network_service_manager_instance = new NetworkServiceManager(
27       std::move(mdns_listener), std::move(mdns_publisher),
28       std::move(connection_client), std::move(connection_server));
29   return g_network_service_manager_instance;
30 }
31 
32 // static
Get()33 NetworkServiceManager* NetworkServiceManager::Get() {
34   // TODO(mfoltz): Convert to assertion failure
35   if (!g_network_service_manager_instance)
36     return nullptr;
37   return g_network_service_manager_instance;
38 }
39 
40 // static
Dispose()41 void NetworkServiceManager::Dispose() {
42   // TODO(mfoltz): Convert to assertion failure
43   if (!g_network_service_manager_instance)
44     return;
45   delete g_network_service_manager_instance;
46   g_network_service_manager_instance = nullptr;
47 }
48 
GetMdnsServiceListener()49 ServiceListener* NetworkServiceManager::GetMdnsServiceListener() {
50   return mdns_listener_.get();
51 }
52 
GetMdnsServicePublisher()53 ServicePublisher* NetworkServiceManager::GetMdnsServicePublisher() {
54   return mdns_publisher_.get();
55 }
56 
GetProtocolConnectionClient()57 ProtocolConnectionClient* NetworkServiceManager::GetProtocolConnectionClient() {
58   return connection_client_.get();
59 }
60 
GetProtocolConnectionServer()61 ProtocolConnectionServer* NetworkServiceManager::GetProtocolConnectionServer() {
62   return connection_server_.get();
63 }
64 
NetworkServiceManager(std::unique_ptr<ServiceListener> mdns_listener,std::unique_ptr<ServicePublisher> mdns_publisher,std::unique_ptr<ProtocolConnectionClient> connection_client,std::unique_ptr<ProtocolConnectionServer> connection_server)65 NetworkServiceManager::NetworkServiceManager(
66     std::unique_ptr<ServiceListener> mdns_listener,
67     std::unique_ptr<ServicePublisher> mdns_publisher,
68     std::unique_ptr<ProtocolConnectionClient> connection_client,
69     std::unique_ptr<ProtocolConnectionServer> connection_server)
70     : mdns_listener_(std::move(mdns_listener)),
71       mdns_publisher_(std::move(mdns_publisher)),
72       connection_client_(std::move(connection_client)),
73       connection_server_(std::move(connection_server)) {}
74 
75 NetworkServiceManager::~NetworkServiceManager() = default;
76 
77 }  // namespace osp
78 }  // namespace openscreen
79