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 <errno.h> |
| 19 | |
| 20 | #define LOG_TAG "Vold" |
| 21 | |
| 22 | #include <cutils/log.h> |
| 23 | |
| 24 | #include "VolumeManager.h" |
| 25 | #include "DeviceVolume.h" |
| 26 | #include "ErrorCode.h" |
| 27 | |
| 28 | VolumeManager *VolumeManager::sInstance = NULL; |
| 29 | |
| 30 | VolumeManager *VolumeManager::Instance() { |
| 31 | if (!sInstance) |
| 32 | sInstance = new VolumeManager(); |
| 33 | return sInstance; |
| 34 | } |
| 35 | |
| 36 | VolumeManager::VolumeManager() { |
| 37 | mBlockDevices = new BlockDeviceCollection(); |
| 38 | mVolumes = new VolumeCollection(); |
| 39 | mBroadcaster = NULL; |
| 40 | } |
| 41 | |
| 42 | VolumeManager::~VolumeManager() { |
| 43 | delete mBlockDevices; |
| 44 | } |
| 45 | |
| 46 | int VolumeManager::start() { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | int VolumeManager::stop() { |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int VolumeManager::addVolume(Volume *v) { |
| 55 | mVolumes->push_back(v); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | void VolumeManager::handleDiskInserted(const char *devpath, int maj, int min, |
| 60 | int nr_parts) { |
| 61 | |
| 62 | /* Lookup possible candidate DeviceVolumes */ |
| 63 | VolumeCollection::iterator it; |
| 64 | bool hit = false; |
| 65 | for (it = mVolumes->begin(); it != mVolumes->end(); ++it) { |
| 66 | if (!(*it)->handleDiskInsertion(devpath, maj, min, nr_parts)) { |
| 67 | hit = true; |
| 68 | LOGD("Volume '%s' has handled disk insertion for '%s'", |
| 69 | (*it)->getLabel(), devpath); |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (!hit) { |
| 75 | LOGW("No volumes handled insertion of disk '%s'", devpath); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void VolumeManager::handleDiskRemoved(int maj, int min) { |
| 80 | } |
| 81 | |
| 82 | void VolumeManager::handlePartCreated(const char *devpath, int maj, int min, |
| 83 | int part_no) { |
| 84 | } |
| 85 | |
| 86 | void VolumeManager::handlePartRemoved(int maj, int min) { |
| 87 | } |
| 88 | |
| 89 | |
| 90 | int VolumeManager::listVolumes(SocketClient *cli) { |
| 91 | VolumeCollection::iterator i; |
| 92 | |
| 93 | for (i = mVolumes->begin(); i != mVolumes->end(); ++i) { |
| 94 | char *buffer; |
| 95 | asprintf(&buffer, "%s %s %d", |
| 96 | (*i)->getLabel(), (*i)->getMountpoint(), |
| 97 | (*i)->getState()); |
| 98 | cli->sendMsg(ErrorCode::VolumeListResult, buffer, false); |
| 99 | free(buffer); |
| 100 | } |
| 101 | cli->sendMsg(ErrorCode::CommandOkay, "Volumes Listed", false); |
| 102 | return 0; |
| 103 | } |