|
| 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 <stdlib.h> |
| 18 | +#include <sys/socket.h> |
| 19 | +#include <netinet/in.h> |
| 20 | +#include <arpa/inet.h> |
| 21 | +#include <errno.h> |
| 22 | + |
| 23 | +#define LOG_TAG "CommandListener" |
| 24 | +#include <cutils/log.h> |
| 25 | + |
| 26 | +#include <sysutils/SocketClient.h> |
| 27 | + |
| 28 | +#include "CommandListener.h" |
| 29 | +#include "VolumeManager.h" |
| 30 | +#include "ErrorCode.h" |
| 31 | + |
| 32 | +CommandListener::CommandListener() : |
| 33 | + FrameworkListener("vold") { |
| 34 | + registerCmd(new ListVolumesCmd()); |
| 35 | + registerCmd(new MountVolumeCmd()); |
| 36 | + registerCmd(new UnmountVolumeCmd()); |
| 37 | + registerCmd(new ShareVolumeCmd()); |
| 38 | + registerCmd(new UnshareVolumeCmd()); |
| 39 | +} |
| 40 | + |
| 41 | +CommandListener::ListVolumesCmd::ListVolumesCmd() : |
| 42 | + VoldCommand("list_volumes") { |
| 43 | +} |
| 44 | + |
| 45 | +int CommandListener::ListVolumesCmd::runCommand(SocketClient *cli, |
| 46 | + int argc, char **argv) { |
| 47 | + return VolumeManager::Instance()->listVolumes(cli); |
| 48 | +} |
| 49 | + |
| 50 | +CommandListener::MountVolumeCmd::MountVolumeCmd() : |
| 51 | + VoldCommand("mount_volume") { |
| 52 | +} |
| 53 | + |
| 54 | +int CommandListener::MountVolumeCmd::runCommand(SocketClient *cli, |
| 55 | + int argc, char **argv) { |
| 56 | + VolumeManager *nm = VolumeManager::Instance(); |
| 57 | + errno = ENOSYS; |
| 58 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to mount volume", true); |
| 59 | + return 0; |
| 60 | +} |
| 61 | + |
| 62 | +CommandListener::UnmountVolumeCmd::UnmountVolumeCmd() : |
| 63 | + VoldCommand("unmount_volume") { |
| 64 | +} |
| 65 | + |
| 66 | +int CommandListener::UnmountVolumeCmd::runCommand(SocketClient *cli, |
| 67 | + int argc, char **argv) { |
| 68 | + VolumeManager *nm = VolumeManager::Instance(); |
| 69 | + errno = ENOSYS; |
| 70 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to unmount volume", true); |
| 71 | + return 0; |
| 72 | +} |
| 73 | + |
| 74 | +CommandListener::ShareVolumeCmd::ShareVolumeCmd() : |
| 75 | + VoldCommand("share_volume") { |
| 76 | +} |
| 77 | + |
| 78 | +int CommandListener::ShareVolumeCmd::runCommand(SocketClient *cli, |
| 79 | + int argc, char **argv) { |
| 80 | + VolumeManager *nm = VolumeManager::Instance(); |
| 81 | + errno = ENOSYS; |
| 82 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to share volume", true); |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +CommandListener::UnshareVolumeCmd::UnshareVolumeCmd() : |
| 87 | + VoldCommand("unshare_volume") { |
| 88 | +} |
| 89 | + |
| 90 | +int CommandListener::UnshareVolumeCmd::runCommand(SocketClient *cli, |
| 91 | + int argc, char **argv) { |
| 92 | + VolumeManager *nm = VolumeManager::Instance(); |
| 93 | + errno = ENOSYS; |
| 94 | + cli->sendMsg(ErrorCode::OperationFailed, "Failed to unshare volume", true); |
| 95 | + return 0; |
| 96 | +} |
0 commit comments