blob: 25635afbe0ea796cc131b609d5edd89b6deddfd8 [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
Mike Lockwood8e2a2802010-07-02 15:15:07 -040044 // group to own new files and folders
45 int mFileGroup;
46 // permissions for new files and directories
47 int mFilePermission;
48 int mDirectoryPermission;
49
Mike Lockwood16864ba2010-05-11 17:16:59 -040050 // current session ID
51 MtpSessionID mSessionID;
52 // true if we have an open session and mSessionID is valid
53 bool mSessionOpen;
54
55 MtpRequestPacket mRequest;
56 MtpDataPacket mData;
57 MtpResponsePacket mResponse;
58
59 MtpStorageList mStorages;
60
Mike Lockwood21ef7d02010-06-30 17:00:35 -040061 MtpPropertyList mObjectProperties;
62 MtpPropertyList mDeviceProperties;
63
Mike Lockwood16864ba2010-05-11 17:16:59 -040064 // handle for new object, set by SendObjectInfo and used by SendObject
65 MtpObjectHandle mSendObjectHandle;
66 MtpString mSendObjectFilePath;
67 size_t mSendObjectFileSize;
68
69public:
Mike Lockwood8e2a2802010-07-02 15:15:07 -040070 MtpServer(int fd, const char* databasePath,
71 int fileGroup, int filePerm, int directoryPerm);
Mike Lockwood16864ba2010-05-11 17:16:59 -040072 virtual ~MtpServer();
73
74 void addStorage(const char* filePath);
75 inline void addStorage(MtpStorage* storage) { mStorages.push(storage); }
76 MtpStorage* getStorage(MtpStorageID id);
77 void scanStorage();
78 void run();
79
Mike Lockwood21ef7d02010-06-30 17:00:35 -040080 MtpProperty* getObjectProperty(MtpPropertyCode propCode);
81 MtpProperty* getDeviceProperty(MtpPropertyCode propCode);
82
Mike Lockwood16864ba2010-05-11 17:16:59 -040083private:
Mike Lockwood21ef7d02010-06-30 17:00:35 -040084 void initObjectProperties();
85
Mike Lockwood916076c2010-06-04 09:49:21 -040086 bool handleRequest();
Mike Lockwood16864ba2010-05-11 17:16:59 -040087
88 MtpResponseCode doGetDeviceInfo();
89 MtpResponseCode doOpenSession();
90 MtpResponseCode doCloseSession();
91 MtpResponseCode doGetStorageIDs();
92 MtpResponseCode doGetStorageInfo();
93 MtpResponseCode doGetObjectPropsSupported();
94 MtpResponseCode doGetObjectHandles();
95 MtpResponseCode doGetObjectPropValue();
96 MtpResponseCode doGetObjectInfo();
97 MtpResponseCode doGetObject();
98 MtpResponseCode doSendObjectInfo();
99 MtpResponseCode doSendObject();
100 MtpResponseCode doDeleteObject();
101 MtpResponseCode doGetObjectPropDesc();
102};
103
Mike Lockwood7850ef92010-05-14 10:10:36 -0400104}; // namespace android
105
Mike Lockwood16864ba2010-05-11 17:16:59 -0400106#endif // _MTP_SERVER_H