MtpServer.h revision 7850ef999740f214a1990a9c090d3f3865d435aa
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 MtpDatabase; 31 32class MtpServer { 33 34private: 35 // file descriptor for MTP kernel driver 36 int mFD; 37 38 // path to our sqlite3 database 39 const char* mDatabasePath; 40 41 MtpDatabase* mDatabase; 42 43 // current session ID 44 MtpSessionID mSessionID; 45 // true if we have an open session and mSessionID is valid 46 bool mSessionOpen; 47 48 MtpRequestPacket mRequest; 49 MtpDataPacket mData; 50 MtpResponsePacket mResponse; 51 52 MtpStorageList mStorages; 53 54 // handle for new object, set by SendObjectInfo and used by SendObject 55 MtpObjectHandle mSendObjectHandle; 56 MtpString mSendObjectFilePath; 57 size_t mSendObjectFileSize; 58 59public: 60 MtpServer(int fd, const char* databasePath); 61 virtual ~MtpServer(); 62 63 void addStorage(const char* filePath); 64 inline void addStorage(MtpStorage* storage) { mStorages.push(storage); } 65 MtpStorage* getStorage(MtpStorageID id); 66 void scanStorage(); 67 void run(); 68 69private: 70 void handleRequest(); 71 72 MtpResponseCode doGetDeviceInfo(); 73 MtpResponseCode doOpenSession(); 74 MtpResponseCode doCloseSession(); 75 MtpResponseCode doGetStorageIDs(); 76 MtpResponseCode doGetStorageInfo(); 77 MtpResponseCode doGetObjectPropsSupported(); 78 MtpResponseCode doGetObjectHandles(); 79 MtpResponseCode doGetObjectPropValue(); 80 MtpResponseCode doGetObjectInfo(); 81 MtpResponseCode doGetObject(); 82 MtpResponseCode doSendObjectInfo(); 83 MtpResponseCode doSendObject(); 84 MtpResponseCode doDeleteObject(); 85 MtpResponseCode doGetObjectPropDesc(); 86}; 87 88}; // namespace android 89 90#endif // _MTP_SERVER_H 91