blob: 68a6564909136e62d4e6168c396a1e6f7bd7c9f9 [file] [log] [blame]
Mike Lockwood56118b52010-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 Lockwoodbe125a52010-07-12 18:54:16 -040023#include "MtpEventPacket.h"
Mike Lockwood56118b52010-05-11 17:16:59 -040024#include "mtp.h"
25
26#include "MtpUtils.h"
27
Mike Lockwood8d3257a2010-05-14 10:10:36 -040028namespace android {
29
Mike Lockwoodd21eac92010-07-03 00:44:05 -040030class MtpDatabase;
Mike Lockwoodd21eac92010-07-03 00:44:05 -040031class MtpStorage;
Mike Lockwood56118b52010-05-11 17:16:59 -040032
33class MtpServer {
34
35private:
36 // file descriptor for MTP kernel driver
37 int mFD;
38
Mike Lockwoodd21eac92010-07-03 00:44:05 -040039 MtpDatabase* mDatabase;
Mike Lockwood56118b52010-05-11 17:16:59 -040040
Mike Lockwooddad69272010-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 Lockwood56118b52010-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 Lockwoodbe125a52010-07-12 18:54:16 -040055 MtpEventPacket mEvent;
Mike Lockwood56118b52010-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 Lockwoodd815f792010-07-12 08:49:01 -040061 MtpObjectFormat mSendObjectFormat;
Mike Lockwood56118b52010-05-11 17:16:59 -040062 MtpString mSendObjectFilePath;
63 size_t mSendObjectFileSize;
64
65public:
Mike Lockwoodd21eac92010-07-03 00:44:05 -040066 MtpServer(int fd, MtpDatabase* database,
Mike Lockwooddad69272010-07-02 15:15:07 -040067 int fileGroup, int filePerm, int directoryPerm);
Mike Lockwood56118b52010-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 Lockwood56118b52010-05-11 17:16:59 -040073 void run();
74
Mike Lockwoodbe125a52010-07-12 18:54:16 -040075 void sendObjectAdded(MtpObjectHandle handle);
76 void sendObjectRemoved(MtpObjectHandle handle);
77
Mike Lockwood56118b52010-05-11 17:16:59 -040078private:
Mike Lockwooda82d3c52010-06-04 09:49:21 -040079 bool handleRequest();
Mike Lockwood56118b52010-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 Lockwood7a047c82010-08-02 10:52:20 -040088 MtpResponseCode doGetNumObjects();
Mike Lockwood9a2046f2010-08-03 15:30:09 -040089 MtpResponseCode doGetObjectReferences();
90 MtpResponseCode doSetObjectReferences();
Mike Lockwood56118b52010-05-11 17:16:59 -040091 MtpResponseCode doGetObjectPropValue();
Mike Lockwood828d19d2010-08-10 15:20:35 -040092 MtpResponseCode doSetObjectPropValue();
93 MtpResponseCode doGetDevicePropValue();
94 MtpResponseCode doSetDevicePropValue();
95 MtpResponseCode doResetDevicePropValue();
Mike Lockwood56118b52010-05-11 17:16:59 -040096 MtpResponseCode doGetObjectInfo();
97 MtpResponseCode doGetObject();
98 MtpResponseCode doSendObjectInfo();
99 MtpResponseCode doSendObject();
100 MtpResponseCode doDeleteObject();
101 MtpResponseCode doGetObjectPropDesc();
Mike Lockwood828d19d2010-08-10 15:20:35 -0400102 MtpResponseCode doGetDevicePropDesc();
Mike Lockwood56118b52010-05-11 17:16:59 -0400103};
104
Mike Lockwood8d3257a2010-05-14 10:10:36 -0400105}; // namespace android
106
Mike Lockwood56118b52010-05-11 17:16:59 -0400107#endif // _MTP_SERVER_H