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 SHILL_DBUS_CHROMEOS_DHCPCD_LISTENER_H_ 18#define SHILL_DBUS_CHROMEOS_DHCPCD_LISTENER_H_ 19 20#include <string> 21 22#include <dbus/dbus.h> 23 24#include <base/macros.h> 25#include <base/memory/ref_counted.h> 26#include <base/memory/weak_ptr.h> 27#include <dbus/bus.h> 28#include <dbus/message.h> 29 30#include <brillo/variant_dictionary.h> 31 32#include "shill/dhcp/dhcpcd_listener_interface.h" 33 34namespace shill { 35 36class DHCPProvider; 37class EventDispatcher; 38 39// The DHCPCD listener is a singleton proxy that listens to signals from all 40// DHCP clients and dispatches them through the DHCP provider to the appropriate 41// client based on the PID. 42class ChromeosDHCPCDListener final : public DHCPCDListenerInterface { 43 public: 44 ChromeosDHCPCDListener(const scoped_refptr<dbus::Bus>& bus, 45 EventDispatcher* dispatcher, 46 DHCPProvider* provider); 47 ~ChromeosDHCPCDListener() override; 48 49 private: 50 static const char kDBusInterfaceName[]; 51 static const char kSignalEvent[]; 52 static const char kSignalStatusChanged[]; 53 54 // Redirects the function call to HandleMessage 55 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, 56 DBusMessage* raw_message, 57 void* user_data); 58 59 // Handles incoming messages. 60 DBusHandlerResult HandleMessage(DBusConnection* connection, 61 DBusMessage* raw_message); 62 63 // Signal handlers. 64 void EventSignal(const std::string& sender, 65 uint32_t pid, 66 const std::string& reason, 67 const brillo::VariantDictionary& configurations); 68 void StatusChangedSignal(const std::string& sender, 69 uint32_t pid, 70 const std::string& status); 71 72 scoped_refptr<dbus::Bus> bus_; 73 EventDispatcher* dispatcher_; 74 DHCPProvider* provider_; 75 const std::string match_rule_; 76 77 base::WeakPtrFactory<ChromeosDHCPCDListener> weak_factory_{this}; 78 DISALLOW_COPY_AND_ASSIGN(ChromeosDHCPCDListener); 79}; 80 81} // namespace shill 82 83#endif // SHILL_DBUS_CHROMEOS_DHCPCD_LISTENER_H_ 84