blob: e65ddb0c0c91e8c8097fc9c8f673bd4c3c596135 [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"
Mike Lockwood873871f2010-07-12 18:54:16 -040023#include "MtpEventPacket.h"
Mike Lockwood16864ba2010-05-11 17:16:59 -040024#include "mtp.h"
25
26#include "MtpUtils.h"
27
Mike Lockwood7850ef92010-05-14 10:10:36 -040028namespace android {
29
Mike Lockwood1865a5d2010-07-03 00:44:05 -040030class MtpDatabase;
Mike Lockwood1865a5d2010-07-03 00:44:05 -040031class MtpStorage;
Mike Lockwood16864ba2010-05-11 17:16:59 -040032
33class MtpServer {
34
35private:
36 // file descriptor for MTP kernel driver
37 int mFD;
38
Mike Lockwood1865a5d2010-07-03 00:44:05 -040039 MtpDatabase* mDatabase;
Mike Lockwood16864ba2010-05-11 17:16:59 -040040
Mike Lockwood8e2a2802010-07-02 15:15:07 -040041 // group to own new files and folders
42 int mFileGroup;
43 // permissions for new files and directories
44 int mFilePermission;
45 int mDirectoryPermission;
46
Mike Lockwood16864ba2010-05-11 17:16:59 -040047 // 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;
Mike Lockwood873871f2010-07-12 18:54:16 -040055 MtpEventPacket mEvent;
Mike Lockwood16864ba2010-05-11 17:16:59 -040056
57 MtpStorageList mStorages;
58
59 // handle for new object, set by SendObjectInfo and used by SendObject
60 MtpObjectHandle mSendObjectHandle;
Mike Lockwood4714b072010-07-12 08:49:01 -040061 MtpObjectFormat mSendObjectFormat;
Mike Lockwood16864ba2010-05-11 17:16:59 -040062 MtpString mSendObjectFilePath;
63 size_t mSendObjectFileSize;
64
65public:
Mike Lockwood1865a5d2010-07-03 00:44:05 -040066 MtpServer(int fd, MtpDatabase* database,
Mike Lockwood8e2a2802010-07-02 15:15:07 -040067 int fileGroup, int filePerm, int directoryPerm);
Mike Lockwood16864ba2010-05-11 17:16:59 -040068 virtual ~MtpServer();
69
70 void addStorage(const char* filePath);
71 inline void addStorage(MtpStorage* storage) { mStorages.push(storage); }
72 MtpStorage* getStorage(MtpStorageID id);
Mike Lockwood16864ba2010-05-11 17:16:59 -040073 void run();
74
Mike Lockwood873871f2010-07-12 18:54:16 -040075 void sendObjectAdded(MtpObjectHandle handle);
76 void sendObjectRemoved(MtpObjectHandle handle);
77
Mike Lockwood16864ba2010-05-11 17:16:59 -040078private:
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();
Mike Lockwood343af4e2010-08-02 10:52:20 -040088 MtpResponseCode doGetNumObjects();
Mike Lockwood438344f2010-08-03 15:30:09 -040089 MtpResponseCode doGetObjectReferences();
90 MtpResponseCode doSetObjectReferences();
Mike Lockwood16864ba2010-05-11 17:16:59 -040091 MtpResponseCode doGetObjectPropValue();
Mike Lockwood8277cec2010-08-10 15:20:35 -040092 MtpResponseCode doSetObjectPropValue();
93 MtpResponseCode doGetDevicePropValue();
94 MtpResponseCode doSetDevicePropValue();
95 MtpResponseCode doResetDevicePropValue();
Mike Lockwoodb6da06e2010-10-14 18:03:25 -040096 MtpResponseCode doGetObjectPropList();
Mike Lockwood16864ba2010-05-11 17:16:59 -040097 MtpResponseCode doGetObjectInfo();
98 MtpResponseCode doGetObject();
99 MtpResponseCode doSendObjectInfo();
100 MtpResponseCode doSendObject();
101 MtpResponseCode doDeleteObject();
102 MtpResponseCode doGetObjectPropDesc();
Mike Lockwood8277cec2010-08-10 15:20:35 -0400103 MtpResponseCode doGetDevicePropDesc();
Mike Lockwood16864ba2010-05-11 17:16:59 -0400104};
105
Mike Lockwood7850ef92010-05-14 10:10:36 -0400106}; // namespace android
107
Mike Lockwood16864ba2010-05-11 17:16:59 -0400108#endif // _MTP_SERVER_H