1 /* 2 * Copyright (C) 2017 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 #ifndef COMMON_LIBS_NET_NETLINK_CLIENT_H_ 17 #define COMMON_LIBS_NET_NETLINK_CLIENT_H_ 18 19 #include <stddef.h> 20 #include <memory> 21 #include <string> 22 #include "common/libs/net/netlink_request.h" 23 24 namespace cuttlefish { 25 26 // Abstraction of Netlink client class. 27 class NetlinkClient { 28 public: NetlinkClient()29 NetlinkClient() {} ~NetlinkClient()30 virtual ~NetlinkClient() {} 31 32 // Send netlink message to kernel. 33 virtual bool Send(const NetlinkRequest& message) = 0; 34 35 private: 36 NetlinkClient(const NetlinkClient&); 37 NetlinkClient& operator= (const NetlinkClient&); 38 }; 39 40 class NetlinkClientFactory { 41 public: 42 // Create new NetlinkClient instance of a specified type. 43 // type can be any of the NETLINK_* types (eg. NETLINK_ROUTE). 44 virtual std::unique_ptr<NetlinkClient> New(int type) = 0; 45 46 static NetlinkClientFactory* Default(); 47 48 protected: 49 NetlinkClientFactory() = default; 50 virtual ~NetlinkClientFactory() = default; 51 }; 52 53 } // namespace cuttlefish 54 55 #endif // COMMON_LIBS_NET_NETLINK_CLIENT_H_ 56