San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <errno.h> |
Olivier Bailly | 37dcda6 | 2010-11-16 10:41:53 -0800 | [diff] [blame] | 20 | #include <string.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 21 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 22 | #include <android-base/logging.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 23 | |
| 24 | #include <sysutils/NetlinkEvent.h> |
| 25 | #include "NetlinkHandler.h" |
| 26 | #include "VolumeManager.h" |
| 27 | |
| 28 | NetlinkHandler::NetlinkHandler(int listenerSocket) : |
Wink Saville | 5fb760a | 2011-01-09 12:18:21 -0800 | [diff] [blame] | 29 | NetlinkListener(listenerSocket) { |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | NetlinkHandler::~NetlinkHandler() { |
| 33 | } |
| 34 | |
| 35 | int NetlinkHandler::start() { |
| 36 | return this->startListener(); |
| 37 | } |
| 38 | |
| 39 | int NetlinkHandler::stop() { |
| 40 | return this->stopListener(); |
| 41 | } |
| 42 | |
| 43 | void NetlinkHandler::onEvent(NetlinkEvent *evt) { |
| 44 | VolumeManager *vm = VolumeManager::Instance(); |
| 45 | const char *subsys = evt->getSubsystem(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 46 | |
| 47 | if (!subsys) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 48 | LOG(WARNING) << "No subsystem found in netlink event"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 49 | return; |
| 50 | } |
| 51 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 52 | if (std::string(subsys) == "block") { |
San Mehat | fd7f587 | 2009-10-12 11:32:47 -0700 | [diff] [blame] | 53 | vm->handleBlockEvent(evt); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 54 | } |
| 55 | } |