1 // 2 // Copyright (C) 2015 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 APMANAGER_DBUS_FIREWALLD_DBUS_PROXY_H_ 18 #define APMANAGER_DBUS_FIREWALLD_DBUS_PROXY_H_ 19 20 #include <string> 21 22 #include <base/macros.h> 23 #include <base/memory/scoped_ptr.h> 24 #include <firewalld/dbus-proxies.h> 25 26 #include "apmanager/firewall_proxy_interface.h" 27 28 namespace apmanager { 29 30 class EventDispatcher; 31 32 class FirewalldDBusProxy : public FirewallProxyInterface { 33 public: 34 FirewalldDBusProxy(const scoped_refptr<dbus::Bus>& bus, 35 const base::Closure& service_appeared_callback, 36 const base::Closure& service_vanished_callback); 37 ~FirewalldDBusProxy() override; 38 39 // Request/release access for an UDP port |port} on an interface |interface|. 40 bool RequestUdpPortAccess(const std::string& interface, 41 uint16_t port) override; 42 bool ReleaseUdpPortAccess(const std::string& interface, 43 uint16_t port) override; 44 45 private: 46 // Called when service appeared or vanished. 47 void OnServiceAvailable(bool service_available); 48 49 // Service name owner changed handler. 50 void OnServiceOwnerChanged(const std::string& old_owner, 51 const std::string& new_owner); 52 53 std::unique_ptr<org::chromium::FirewalldProxy> proxy_; 54 EventDispatcher* dispatcher_; 55 base::Closure service_appeared_callback_; 56 base::Closure service_vanished_callback_; 57 bool service_available_; 58 59 base::WeakPtrFactory<FirewalldDBusProxy> weak_factory_{this}; 60 DISALLOW_COPY_AND_ASSIGN(FirewalldDBusProxy); 61 }; 62 63 } // namespace apmanager 64 65 #endif // APMANAGER_DBUS_FIREWALLD_DBUS_PROXY_H_ 66