Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #ifndef _MTP_SERVER_H |
| 18 | #define _MTP_SERVER_H |
| 19 | |
| 20 | #include "MtpRequestPacket.h" |
| 21 | #include "MtpDataPacket.h" |
| 22 | #include "MtpResponsePacket.h" |
Mike Lockwood | 873871f | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 23 | #include "MtpEventPacket.h" |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 24 | #include "mtp.h" |
| 25 | |
| 26 | #include "MtpUtils.h" |
| 27 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Mike Lockwood | 1865a5d | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 30 | class MtpDatabase; |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 31 | class MtpProperty; |
Mike Lockwood | 1865a5d | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 32 | class MtpStorage; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 33 | |
| 34 | class MtpServer { |
| 35 | |
| 36 | private: |
| 37 | // file descriptor for MTP kernel driver |
| 38 | int mFD; |
| 39 | |
Mike Lockwood | 1865a5d | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 40 | MtpDatabase* mDatabase; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 41 | |
Mike Lockwood | 8e2a280 | 2010-07-02 15:15:07 -0400 | [diff] [blame] | 42 | // group to own new files and folders |
| 43 | int mFileGroup; |
| 44 | // permissions for new files and directories |
| 45 | int mFilePermission; |
| 46 | int mDirectoryPermission; |
| 47 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 48 | // current session ID |
| 49 | MtpSessionID mSessionID; |
| 50 | // true if we have an open session and mSessionID is valid |
| 51 | bool mSessionOpen; |
| 52 | |
| 53 | MtpRequestPacket mRequest; |
| 54 | MtpDataPacket mData; |
| 55 | MtpResponsePacket mResponse; |
Mike Lockwood | 873871f | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 56 | MtpEventPacket mEvent; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 57 | |
| 58 | MtpStorageList mStorages; |
| 59 | |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 60 | MtpPropertyList mObjectProperties; |
| 61 | MtpPropertyList mDeviceProperties; |
| 62 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 63 | // handle for new object, set by SendObjectInfo and used by SendObject |
| 64 | MtpObjectHandle mSendObjectHandle; |
Mike Lockwood | 4714b07 | 2010-07-12 08:49:01 -0400 | [diff] [blame] | 65 | MtpObjectFormat mSendObjectFormat; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 66 | MtpString mSendObjectFilePath; |
| 67 | size_t mSendObjectFileSize; |
| 68 | |
| 69 | public: |
Mike Lockwood | 1865a5d | 2010-07-03 00:44:05 -0400 | [diff] [blame] | 70 | MtpServer(int fd, MtpDatabase* database, |
Mike Lockwood | 8e2a280 | 2010-07-02 15:15:07 -0400 | [diff] [blame] | 71 | int fileGroup, int filePerm, int directoryPerm); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 72 | virtual ~MtpServer(); |
| 73 | |
| 74 | void addStorage(const char* filePath); |
| 75 | inline void addStorage(MtpStorage* storage) { mStorages.push(storage); } |
| 76 | MtpStorage* getStorage(MtpStorageID id); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 77 | void run(); |
| 78 | |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 79 | MtpProperty* getObjectProperty(MtpPropertyCode propCode); |
| 80 | MtpProperty* getDeviceProperty(MtpPropertyCode propCode); |
| 81 | |
Mike Lockwood | 873871f | 2010-07-12 18:54:16 -0400 | [diff] [blame] | 82 | void sendObjectAdded(MtpObjectHandle handle); |
| 83 | void sendObjectRemoved(MtpObjectHandle handle); |
| 84 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 85 | private: |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 86 | void initObjectProperties(); |
| 87 | |
Mike Lockwood | 916076c | 2010-06-04 09:49:21 -0400 | [diff] [blame] | 88 | bool handleRequest(); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 89 | |
| 90 | MtpResponseCode doGetDeviceInfo(); |
| 91 | MtpResponseCode doOpenSession(); |
| 92 | MtpResponseCode doCloseSession(); |
| 93 | MtpResponseCode doGetStorageIDs(); |
| 94 | MtpResponseCode doGetStorageInfo(); |
| 95 | MtpResponseCode doGetObjectPropsSupported(); |
| 96 | MtpResponseCode doGetObjectHandles(); |
Mike Lockwood | 343af4e | 2010-08-02 10:52:20 -0400 | [diff] [blame^] | 97 | MtpResponseCode doGetNumObjects(); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 98 | MtpResponseCode doGetObjectPropValue(); |
| 99 | MtpResponseCode doGetObjectInfo(); |
| 100 | MtpResponseCode doGetObject(); |
| 101 | MtpResponseCode doSendObjectInfo(); |
| 102 | MtpResponseCode doSendObject(); |
| 103 | MtpResponseCode doDeleteObject(); |
| 104 | MtpResponseCode doGetObjectPropDesc(); |
| 105 | }; |
| 106 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 107 | }; // namespace android |
| 108 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 109 | #endif // _MTP_SERVER_H |