blob: a3836510743622740d35f571f8214535bc3a6105 [file] [log] [blame]
San Mehatf1b736b2009-10-10 17:22:08 -07001/*
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>
San Mehatfd7f5872009-10-12 11:32:47 -070018#include <stdlib.h>
19#include <string.h>
San Mehatf1b736b2009-10-10 17:22:08 -070020#include <errno.h>
21
22#define LOG_TAG "Vold"
23
24#include <cutils/log.h>
25
San Mehatfd7f5872009-10-12 11:32:47 -070026#include <sysutils/NetlinkEvent.h>
27
San Mehatf1b736b2009-10-10 17:22:08 -070028#include "VolumeManager.h"
29#include "DeviceVolume.h"
30#include "ErrorCode.h"
31
32VolumeManager *VolumeManager::sInstance = NULL;
33
34VolumeManager *VolumeManager::Instance() {
35 if (!sInstance)
36 sInstance = new VolumeManager();
37 return sInstance;
38}
39
40VolumeManager::VolumeManager() {
41 mBlockDevices = new BlockDeviceCollection();
42 mVolumes = new VolumeCollection();
43 mBroadcaster = NULL;
44}
45
46VolumeManager::~VolumeManager() {
47 delete mBlockDevices;
48}
49
50int VolumeManager::start() {
51 return 0;
52}
53
54int VolumeManager::stop() {
55 return 0;
56}
57
58int VolumeManager::addVolume(Volume *v) {
59 mVolumes->push_back(v);
60 return 0;
61}
62
San Mehatfd7f5872009-10-12 11:32:47 -070063void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
64 const char *devpath = evt->findParam("DEVPATH");
San Mehatf1b736b2009-10-10 17:22:08 -070065
San Mehatfd7f5872009-10-12 11:32:47 -070066 /* Lookup a volume to handle this device */
San Mehatf1b736b2009-10-10 17:22:08 -070067 VolumeCollection::iterator it;
68 bool hit = false;
69 for (it = mVolumes->begin(); it != mVolumes->end(); ++it) {
San Mehatfd7f5872009-10-12 11:32:47 -070070 if (!(*it)->handleBlockEvent(evt)) {
San Mehatf1b736b2009-10-10 17:22:08 -070071 hit = true;
San Mehatf1b736b2009-10-10 17:22:08 -070072 break;
73 }
74 }
75
76 if (!hit) {
San Mehatfd7f5872009-10-12 11:32:47 -070077 LOGW("No volumes handled block event for '%s'", devpath);
San Mehatf1b736b2009-10-10 17:22:08 -070078 }
79}
80
San Mehatf1b736b2009-10-10 17:22:08 -070081int VolumeManager::listVolumes(SocketClient *cli) {
82 VolumeCollection::iterator i;
83
84 for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
85 char *buffer;
86 asprintf(&buffer, "%s %s %d",
87 (*i)->getLabel(), (*i)->getMountpoint(),
88 (*i)->getState());
89 cli->sendMsg(ErrorCode::VolumeListResult, buffer, false);
90 free(buffer);
91 }
92 cli->sendMsg(ErrorCode::CommandOkay, "Volumes Listed", false);
93 return 0;
94}