// // Copyright (C) 2015 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef PROXY_DBUS_CLIENT_H #define PROXY_DBUS_CLIENT_H #include #include #include #include #include #include #include #include #include #include #include #include using ManagerProxy = org::chromium::flimflam::ManagerProxy; using DeviceProxy = org::chromium::flimflam::DeviceProxy; using ServiceProxy = org::chromium::flimflam::ServiceProxy; using ProfileProxy = org::chromium::flimflam::ProfileProxy; typedef base::Callback DbusPropertyChangeCallback; class ProxyDbusClient { public: enum Technology { TECHNOLOGY_CELLULAR, TECHNOLOGY_ETHERNET, TECHNOLOGY_VPN, TECHNOLOGY_WIFI, TECHNOLOGY_WIMAX }; static const char kCommonLogScopes[]; static const char kDbusErrorObjectUnknown[]; static const int kLogLevel; ProxyDbusClient(scoped_refptr bus); void SetLogging(Technology tech); std::vector> GetDeviceProxies(); std::vector> GetServiceProxies(); std::vector> GetProfileProxies(); std::unique_ptr GetMatchingDeviceProxy( const brillo::VariantDictionary& expected_properties); std::unique_ptr GetMatchingServiceProxy( const brillo::VariantDictionary& expected_properties); std::unique_ptr GetMatchingProfileProxy( const brillo::VariantDictionary& expected_properties); bool GetPropertyValueFromDeviceProxy(DeviceProxy* proxy, const std::string& property_name, brillo::Any* property_value); bool GetPropertyValueFromServiceProxy(ServiceProxy* proxy, const std::string& property_name, brillo::Any* property_value); bool GetPropertyValueFromProfileProxy(ProfileProxy* proxy, const std::string& property_name, brillo::Any* property_value); // Optional outparams: |final_value| & |elapsed_time_seconds|. Pass nullptr // if not required. bool WaitForDeviceProxyPropertyValueIn( const dbus::ObjectPath& object_path, const std::string& property_name, const std::vector& expected_values, long timeout_milliseconds, brillo::Any* final_value, long* elapsed_time_milliseconds); bool WaitForServiceProxyPropertyValueIn( const dbus::ObjectPath& object_path, const std::string& property_name, const std::vector& expected_values, long timeout_milliseconds, brillo::Any* final_value, long* elapsed_time_milliseconds); bool WaitForProfileProxyPropertyValueIn( const dbus::ObjectPath& object_path, const std::string& property_name, const std::vector& expected_values, long timeout_milliseconds, brillo::Any* final_value, long* elapsed_time_milliseconds); std::unique_ptr GetServiceProxy( const brillo::VariantDictionary& expected_properties); std::unique_ptr GetActiveProfileProxy(); // Optional outparam: |elapsed_time_seconds|. Pass nullptr // if not required. std::unique_ptr WaitForMatchingServiceProxy( const brillo::VariantDictionary& service_properties, const std::string& service_type, long timeout_milliseconds, int rescan_interval_milliseconds, long* elapsed_time_milliseconds); bool ConfigureService(const brillo::VariantDictionary& config_params); bool ConfigureServiceByGuid(const std::string& guid, const brillo::VariantDictionary& config_params); bool ConnectService(const dbus::ObjectPath& object_path, long timeout_milliseconds); bool DisconnectService(const dbus::ObjectPath& object_path, long timeout_milliseconds); bool CreateProfile(const std::string& profile_name); bool RemoveProfile(const std::string& profile_name); bool PushProfile(const std::string& profile_name); bool PopProfile(const std::string& profile_name); bool PopAnyProfile(); bool RequestServiceScan(const std::string& service_type); bool GetServiceOrder(std::string* order); bool SetServiceOrder(const std::string& order); bool SetSchedScan(bool enable); private: bool GetPropertyValueFromManager(const std::string& property_name, brillo::Any* property_value); dbus::ObjectPath GetObjectPathForActiveProfile(); bool SetLoggingInternal(int level, const std::string& tags); template std::unique_ptr GetProxyForObjectPath( const dbus::ObjectPath& object_path); template std::vector> GetProxies( const std::string& object_paths_property_name); template std::unique_ptr GetMatchingProxy( const std::string& object_paths_property_name, const brillo::VariantDictionary& expected_properties); template bool WaitForProxyPropertyValueIn( const dbus::ObjectPath& object_path, const std::string& property_name, const std::vector& expected_values, long timeout_milliseconds, brillo::Any* final_value, long* elapsed_time_milliseconds); void IsMatchingServicePresent( const brillo::VariantDictionary& service_properties, base::Time wait_start_time, bool* is_success, std::unique_ptr* service_proxy_out, long* elapsed_time_milliseconds); // This is invoked periodically to check if a service mathching the required // params are found. void FindServiceOrRestartScan( const brillo::VariantDictionary& service_properties, const std::string& service_type); void InitiateScanForService( base::TimeDelta rescan_interval, const std::string& service_type, const base::Closure& timer_callback); void RestartScanForService( const std::string& service_type); scoped_refptr dbus_bus_; ManagerProxy shill_manager_proxy_; std::unique_ptr wait_for_service_timer_; base::WeakPtrFactory weak_ptr_factory_; }; #endif //PROXY_DBUS_CLIENT_H