1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "netlink/netlink_handler.h"
17
18 #include "disk/disk_manager.h"
19 #include "storage_service_log.h"
20
21 namespace OHOS {
22 namespace StorageDaemon {
NetlinkHandler(int32_t socket)23 NetlinkHandler::NetlinkHandler(int32_t socket) : NetlinkListener(socket) {}
24
Start()25 int32_t NetlinkHandler::Start()
26 {
27 return this->StartListener();
28 }
29
Stop()30 int32_t NetlinkHandler::Stop()
31 {
32 return this->StopListener();
33 }
34
OnEvent(char * msg)35 void NetlinkHandler::OnEvent(char *msg)
36 {
37 auto nlData = std::make_unique<NetlinkData>();
38 nlData->Decode(msg);
39 if (strcmp(nlData->GetSubsystem().c_str(), "block") == 0) {
40 LOGI("OnEvent GetSyspath: %{public}s, GetDevpath: %{public}s, GetSubsystem: %{public}s, GetAction: %{public}d",
41 nlData->GetSyspath().c_str(), nlData->GetDevpath().c_str(),
42 nlData->GetSubsystem().c_str(), nlData->GetAction());
43 DiskManager::Instance()->HandleDiskEvent(nlData.get());
44 }
45 }
46 } // StorageDaemon
47 } // OHOS
48