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_WIMAX_WIMAX_SERVICE_H_ 18 #define SHILL_WIMAX_WIMAX_SERVICE_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include <gtest/gtest_prod.h> // for FRIEND_TEST 24 25 #include "shill/refptr_types.h" 26 #include "shill/service.h" 27 #include "shill/wimax/wimax_network_proxy_interface.h" 28 29 namespace shill { 30 31 class KeyValueStore; 32 33 class WiMaxService : public Service { 34 public: 35 static const char kStorageNetworkId[]; 36 37 // TODO(petkov): Declare this in chromeos/dbus/service_constants.h. 38 static const char kNetworkIdProperty[]; 39 40 WiMaxService(ControlInterface* control, 41 EventDispatcher* dispatcher, 42 Metrics* metrics, 43 Manager* manager); 44 ~WiMaxService() override; 45 46 // Returns the parameters to be passed to WiMaxManager.Device.Connect() when 47 // connecting to the network associated with this service. 48 void GetConnectParameters(KeyValueStore* parameters) const; 49 50 // Returns the RPC object path for the WiMaxManager.Network object associated 51 // with this service. Must only be called after |proxy_| is set by Start(). 52 virtual RpcIdentifier GetNetworkObjectPath() const; 53 54 // Starts the service by associating it with the RPC network object |proxy| 55 // and listening for its signal strength. Returns true on success, false 56 // otherwise. Takes ownership of proxy, regardless of the result of the 57 // operation. The proxy will be destroyed on failure. 58 virtual bool Start(WiMaxNetworkProxyInterface* proxy); 59 60 // Stops the service by disassociating it from |proxy_| and resetting its 61 // signal strength to 0. If the service is connected, it notifies the carrier 62 // device that the service is stopped. 63 virtual void Stop(); 64 65 virtual bool IsStarted() const; 66 67 const std::string& network_name() const { return network_name_; } 68 const WiMaxNetworkId& network_id() const { return network_id_; } 69 void set_network_id(const WiMaxNetworkId& id) { network_id_ = id; } 70 bool is_default() const { return is_default_; } 71 void set_is_default(bool is_default) { is_default_ = is_default; } 72 73 static WiMaxNetworkId ConvertIdentifierToNetworkId(uint32_t identifier); 74 75 // Initializes the storage identifier. Note that the friendly service name and 76 // the |network_id_| must already be initialized. 77 void InitStorageIdentifier(); 78 static std::string CreateStorageIdentifier(const WiMaxNetworkId& id, 79 const std::string& name); 80 81 virtual void ClearPassphrase(); 82 83 // Inherited from Service. 84 void Connect(Error* error, const char* reason) override; 85 void Disconnect(Error* error, const char* reason) override; 86 std::string GetStorageIdentifier() const override; 87 bool Is8021x() const override; 88 bool IsVisible() const override; 89 void OnEapCredentialsChanged( 90 Service::UpdateCredentialsReason reason) override; 91 bool Save(StoreInterface* storage) override; 92 bool Unload() override; 93 void SetState(ConnectState state) override; 94 95 private: 96 friend class WiMaxServiceTest; 97 FRIEND_TEST(WiMaxServiceTest, Connect); 98 FRIEND_TEST(WiMaxServiceTest, Connectable); 99 FRIEND_TEST(WiMaxServiceTest, GetDeviceRpcId); 100 FRIEND_TEST(WiMaxServiceTest, IsAutoConnectable); 101 FRIEND_TEST(WiMaxServiceTest, OnSignalStrengthChanged); 102 FRIEND_TEST(WiMaxServiceTest, SetState); 103 FRIEND_TEST(WiMaxServiceTest, StartStop); 104 105 // Inherited from Service. 106 std::string GetDeviceRpcId(Error* error) const override; 107 bool IsAutoConnectable(const char** reason) const override; 108 109 void OnSignalStrengthChanged(int strength); 110 111 void UpdateConnectable(); 112 113 // Update |device_|, and inform RPC listeners of the change. 114 void SetDevice(WiMaxRefPtr new_device); 115 116 WiMaxRefPtr device_; // Update via SetDevice(). 117 std::unique_ptr<WiMaxNetworkProxyInterface> proxy_; 118 std::string storage_id_; 119 120 WiMaxNetworkId network_id_; 121 std::string network_name_; 122 bool need_passphrase_; 123 bool is_default_; 124 125 DISALLOW_COPY_AND_ASSIGN(WiMaxService); 126 }; 127 128 } // namespace shill 129 130 #endif // SHILL_WIMAX_WIMAX_SERVICE_H_ 131