MtpServer.h revision 8e2a280ab7f98bf00ff2651f1f93c8f8bd46c08d
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" 23#include "mtp.h" 24 25#include "MtpUtils.h" 26 27namespace android { 28 29class MtpStorage; 30class MtpSqliteDatabase; 31class MtpProperty; 32 33class MtpServer { 34 35private: 36 // file descriptor for MTP kernel driver 37 int mFD; 38 39 // path to our sqlite3 database 40 const char* mDatabasePath; 41 42 MtpSqliteDatabase* mDatabase; 43 44 // group to own new files and folders 45 int mFileGroup; 46 // permissions for new files and directories 47 int mFilePermission; 48 int mDirectoryPermission; 49 50 // current session ID 51 MtpSessionID mSessionID; 52 // true if we have an open session and mSessionID is valid 53 bool mSessionOpen; 54 55 MtpRequestPacket mRequest; 56 MtpDataPacket mData; 57 MtpResponsePacket mResponse; 58 59 MtpStorageList mStorages; 60 61 MtpPropertyList mObjectProperties; 62 MtpPropertyList mDeviceProperties; 63 64 // handle for new object, set by SendObjectInfo and used by SendObject 65 MtpObjectHandle mSendObjectHandle; 66 MtpString mSendObjectFilePath; 67 size_t mSendObjectFileSize; 68 69public: 70 MtpServer(int fd, const char* databasePath, 71 int fileGroup, int filePerm, int directoryPerm); 72 virtual ~MtpServer(); 73 74 void addStorage(const char* filePath); 75 inline void addStorage(MtpStorage* storage) { mStorages.push(storage); } 76 MtpStorage* getStorage(MtpStorageID id); 77 void scanStorage(); 78 void run(); 79 80 MtpProperty* getObjectProperty(MtpPropertyCode propCode); 81 MtpProperty* getDeviceProperty(MtpPropertyCode propCode); 82 83private: 84 void initObjectProperties(); 85 86 bool handleRequest(); 87 88 MtpResponseCode doGetDeviceInfo(); 89 MtpResponseCode doOpenSession(); 90 MtpResponseCode doCloseSession(); 91 MtpResponseCode doGetStorageIDs(); 92 MtpResponseCode doGetStorageInfo(); 93 MtpResponseCode doGetObjectPropsSupported(); 94 MtpResponseCode doGetObjectHandles(); 95 MtpResponseCode doGetObjectPropValue(); 96 MtpResponseCode doGetObjectInfo(); 97 MtpResponseCode doGetObject(); 98 MtpResponseCode doSendObjectInfo(); 99 MtpResponseCode doSendObject(); 100 MtpResponseCode doDeleteObject(); 101 MtpResponseCode doGetObjectPropDesc(); 102}; 103 104}; // namespace android 105 106#endif // _MTP_SERVER_H 107