blob: 42261a94718cb302dcd78832f61d2ddf4b2ed862 [file] [log] [blame]
Mike Lockwood16864ba2010-05-11 17:16:59 -04001/*
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
Mike Lockwood7850ef92010-05-14 10:10:36 -040027namespace android {
28
Mike Lockwood16864ba2010-05-11 17:16:59 -040029class MtpStorage;
Mike Lockwood02503612010-07-02 14:03:31 -040030class MtpSqliteDatabase;
Mike Lockwood21ef7d02010-06-30 17:00:35 -040031class MtpProperty;
Mike Lockwood16864ba2010-05-11 17:16:59 -040032
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
Mike Lockwood02503612010-07-02 14:03:31 -040042 MtpSqliteDatabase* mDatabase;
Mike Lockwood16864ba2010-05-11 17:16:59 -040043
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
Mike Lockwood21ef7d02010-06-30 17:00:35 -040055 MtpPropertyList mObjectProperties;
56 MtpPropertyList mDeviceProperties;
57
Mike Lockwood16864ba2010-05-11 17:16:59 -040058 // 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
Mike Lockwood21ef7d02010-06-30 17:00:35 -040073 MtpProperty* getObjectProperty(MtpPropertyCode propCode);
74 MtpProperty* getDeviceProperty(MtpPropertyCode propCode);
75
Mike Lockwood16864ba2010-05-11 17:16:59 -040076private:
Mike Lockwood21ef7d02010-06-30 17:00:35 -040077 void initObjectProperties();
78
Mike Lockwood916076c2010-06-04 09:49:21 -040079 bool handleRequest();
Mike Lockwood16864ba2010-05-11 17:16:59 -040080
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
Mike Lockwood7850ef92010-05-14 10:10:36 -040097}; // namespace android
98
Mike Lockwood16864ba2010-05-11 17:16:59 -040099#endif // _MTP_SERVER_H