blob: 81b1c81b403d4cc2a3c5a678f536f30907c93fa4 [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
27class MtpStorage;
28class MtpDatabase;
29
30class MtpServer {
31
32private:
33 // file descriptor for MTP kernel driver
34 int mFD;
35
36 // path to our sqlite3 database
37 const char* mDatabasePath;
38
39 MtpDatabase* mDatabase;
40
41 // current session ID
42 MtpSessionID mSessionID;
43 // true if we have an open session and mSessionID is valid
44 bool mSessionOpen;
45
46 MtpRequestPacket mRequest;
47 MtpDataPacket mData;
48 MtpResponsePacket mResponse;
49
50 MtpStorageList mStorages;
51
52 // handle for new object, set by SendObjectInfo and used by SendObject
53 MtpObjectHandle mSendObjectHandle;
54 MtpString mSendObjectFilePath;
55 size_t mSendObjectFileSize;
56
57public:
58 MtpServer(int fd, const char* databasePath);
59 virtual ~MtpServer();
60
61 void addStorage(const char* filePath);
62 inline void addStorage(MtpStorage* storage) { mStorages.push(storage); }
63 MtpStorage* getStorage(MtpStorageID id);
64 void scanStorage();
65 void run();
66
67private:
68 void handleRequest();
69
70 MtpResponseCode doGetDeviceInfo();
71 MtpResponseCode doOpenSession();
72 MtpResponseCode doCloseSession();
73 MtpResponseCode doGetStorageIDs();
74 MtpResponseCode doGetStorageInfo();
75 MtpResponseCode doGetObjectPropsSupported();
76 MtpResponseCode doGetObjectHandles();
77 MtpResponseCode doGetObjectPropValue();
78 MtpResponseCode doGetObjectInfo();
79 MtpResponseCode doGetObject();
80 MtpResponseCode doSendObjectInfo();
81 MtpResponseCode doSendObject();
82 MtpResponseCode doDeleteObject();
83 MtpResponseCode doGetObjectPropDesc();
84};
85
86#endif // _MTP_SERVER_H