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