MtpServer.h revision 8277cec96ffa55082962591bca1c55abbeec8c26
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 "MtpEventPacket.h"
24#include "mtp.h"
25
26#include "MtpUtils.h"
27
28namespace android {
29
30class MtpDatabase;
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    MtpEventPacket      mEvent;
56
57    MtpStorageList      mStorages;
58
59    // handle for new object, set by SendObjectInfo and used by SendObject
60    MtpObjectHandle     mSendObjectHandle;
61    MtpObjectFormat     mSendObjectFormat;
62    MtpString           mSendObjectFilePath;
63    size_t              mSendObjectFileSize;
64
65public:
66                        MtpServer(int fd, MtpDatabase* database,
67                                    int fileGroup, int filePerm, int directoryPerm);
68    virtual             ~MtpServer();
69
70    void                addStorage(const char* filePath);
71    inline void         addStorage(MtpStorage* storage) { mStorages.push(storage); }
72    MtpStorage*         getStorage(MtpStorageID id);
73    void                run();
74
75    void                sendObjectAdded(MtpObjectHandle handle);
76    void                sendObjectRemoved(MtpObjectHandle handle);
77
78private:
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     doGetNumObjects();
89    MtpResponseCode     doGetObjectReferences();
90    MtpResponseCode     doSetObjectReferences();
91    MtpResponseCode     doGetObjectPropValue();
92    MtpResponseCode     doSetObjectPropValue();
93    MtpResponseCode     doGetDevicePropValue();
94    MtpResponseCode     doSetDevicePropValue();
95    MtpResponseCode     doResetDevicePropValue();
96    MtpResponseCode     doGetObjectInfo();
97    MtpResponseCode     doGetObject();
98    MtpResponseCode     doSendObjectInfo();
99    MtpResponseCode     doSendObject();
100    MtpResponseCode     doDeleteObject();
101    MtpResponseCode     doGetObjectPropDesc();
102    MtpResponseCode     doGetDevicePropDesc();
103};
104
105}; // namespace android
106
107#endif // _MTP_SERVER_H
108