MtpServer.h revision 21ef7d0e70c5ad599bc2602cb484f8cd647055ca
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;
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    MtpDatabase*        mDatabase;
43
44    // current session ID
45    MtpSessionID        mSessionID;
46    // true if we have an open session and mSessionID is valid
47    bool                mSessionOpen;
48
49    MtpRequestPacket    mRequest;
50    MtpDataPacket       mData;
51    MtpResponsePacket   mResponse;
52
53    MtpStorageList      mStorages;
54
55    MtpPropertyList     mObjectProperties;
56    MtpPropertyList     mDeviceProperties;
57
58    // handle for new object, set by SendObjectInfo and used by SendObject
59    MtpObjectHandle     mSendObjectHandle;
60    MtpString           mSendObjectFilePath;
61    size_t              mSendObjectFileSize;
62
63public:
64                        MtpServer(int fd, const char* databasePath);
65    virtual             ~MtpServer();
66
67    void                addStorage(const char* filePath);
68    inline void         addStorage(MtpStorage* storage) { mStorages.push(storage); }
69    MtpStorage*         getStorage(MtpStorageID id);
70    void                scanStorage();
71    void                run();
72
73    MtpProperty*        getObjectProperty(MtpPropertyCode propCode);
74    MtpProperty*        getDeviceProperty(MtpPropertyCode propCode);
75
76private:
77    void                initObjectProperties();
78
79    bool                handleRequest();
80
81    MtpResponseCode     doGetDeviceInfo();
82    MtpResponseCode     doOpenSession();
83    MtpResponseCode     doCloseSession();
84    MtpResponseCode     doGetStorageIDs();
85    MtpResponseCode     doGetStorageInfo();
86    MtpResponseCode     doGetObjectPropsSupported();
87    MtpResponseCode     doGetObjectHandles();
88    MtpResponseCode     doGetObjectPropValue();
89    MtpResponseCode     doGetObjectInfo();
90    MtpResponseCode     doGetObject();
91    MtpResponseCode     doSendObjectInfo();
92    MtpResponseCode     doSendObject();
93    MtpResponseCode     doDeleteObject();
94    MtpResponseCode     doGetObjectPropDesc();
95};
96
97}; // namespace android
98
99#endif // _MTP_SERVER_H
100