1//
2// Copyright (C) 2012 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// limitations under the License.
15//
16
17#ifndef SHILL_ETHERNET_ETHERNET_SERVICE_H_
18#define SHILL_ETHERNET_ETHERNET_SERVICE_H_
19
20#include <string>
21
22#include <base/macros.h>
23#include <base/memory/weak_ptr.h>
24#include <gtest/gtest_prod.h>  // for FRIEND_TEST
25
26#include "shill/event_dispatcher.h"
27#include "shill/service.h"
28
29namespace shill {
30
31class ControlInterface;
32class Ethernet;
33class EventDispatcher;
34class Manager;
35class Metrics;
36
37class EthernetService : public Service {
38 public:
39  EthernetService(ControlInterface* control_interface,
40                  EventDispatcher* dispatcher,
41                  Metrics* metrics,
42                  Manager* manager,
43                  base::WeakPtr<Ethernet> ethernet);
44  ~EthernetService() override;
45
46  // Inherited from Service.
47  void Connect(Error* error, const char* reason) override;
48  void Disconnect(Error* error, const char* reason) override;
49
50  // ethernet_<MAC>
51  std::string GetStorageIdentifier() const override;
52  bool IsAutoConnectByDefault() const override;
53  bool SetAutoConnectFull(const bool& connect, Error* error) override;
54
55  void Remove(Error* error) override;
56  bool IsVisible() const override;
57  bool IsAutoConnectable(const char** reason) const override;
58
59  // Called by the Ethernet device when link state has caused the service
60  // visibility to change.
61  virtual void OnVisibilityChanged();
62
63 protected:
64  // This constructor performs none of the initialization that the normal
65  // constructor does and sets the reported technology to |technology|.  It is
66  // intended for use by subclasses which want to override specific aspects of
67  // EthernetService behavior, while still retaining their own technology
68  // identifier.
69  EthernetService(ControlInterface* control_interface,
70                  EventDispatcher* dispatcher,
71                  Metrics* metrics,
72                  Manager* manager,
73                  Technology::Identifier technology,
74                  base::WeakPtr<Ethernet> ethernet);
75
76  Ethernet* ethernet() const { return ethernet_.get(); }
77  std::string GetTethering(Error* error) const override;
78
79 private:
80  FRIEND_TEST(EthernetServiceTest, GetTethering);
81
82  static const char kAutoConnNoCarrier[];
83  static const char kServiceType[];
84
85  std::string GetDeviceRpcId(Error* error) const override;
86
87  base::WeakPtr<Ethernet> ethernet_;
88  DISALLOW_COPY_AND_ASSIGN(EthernetService);
89};
90
91}  // namespace shill
92
93#endif  // SHILL_ETHERNET_ETHERNET_SERVICE_H_
94