MtpServer.h revision 1865a5ddcfe7b0e8dc211419aea1094b1491a5fd
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 MtpDatabase;
30class MtpProperty;
31class MtpStorage;
32
33class MtpServer {
34
35private:
36    // file descriptor for MTP kernel driver
37    int                 mFD;
38
39    MtpDatabase*        mDatabase;
40
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
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;
55
56    MtpStorageList      mStorages;
57
58    MtpPropertyList     mObjectProperties;
59    MtpPropertyList     mDeviceProperties;
60
61    // handle for new object, set by SendObjectInfo and used by SendObject
62    MtpObjectHandle     mSendObjectHandle;
63    MtpString           mSendObjectFilePath;
64    size_t              mSendObjectFileSize;
65
66public:
67                        MtpServer(int fd, MtpDatabase* database,
68                                    int fileGroup, int filePerm, int directoryPerm);
69    virtual             ~MtpServer();
70
71    void                addStorage(const char* filePath);
72    inline void         addStorage(MtpStorage* storage) { mStorages.push(storage); }
73    MtpStorage*         getStorage(MtpStorageID id);
74    void                scanStorage();
75    void                run();
76
77    MtpProperty*        getObjectProperty(MtpPropertyCode propCode);
78    MtpProperty*        getDeviceProperty(MtpPropertyCode propCode);
79
80private:
81    void                initObjectProperties();
82
83    bool                handleRequest();
84
85    MtpResponseCode     doGetDeviceInfo();
86    MtpResponseCode     doOpenSession();
87    MtpResponseCode     doCloseSession();
88    MtpResponseCode     doGetStorageIDs();
89    MtpResponseCode     doGetStorageInfo();
90    MtpResponseCode     doGetObjectPropsSupported();
91    MtpResponseCode     doGetObjectHandles();
92    MtpResponseCode     doGetObjectPropValue();
93    MtpResponseCode     doGetObjectInfo();
94    MtpResponseCode     doGetObject();
95    MtpResponseCode     doSendObjectInfo();
96    MtpResponseCode     doSendObject();
97    MtpResponseCode     doDeleteObject();
98    MtpResponseCode     doGetObjectPropDesc();
99};
100
101}; // namespace android
102
103#endif // _MTP_SERVER_H
104