2010-05-11 17:16:59 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MTP_SERVER_H
|
|
|
|
#define _MTP_SERVER_H
|
|
|
|
|
|
|
|
#include "MtpRequestPacket.h"
|
|
|
|
#include "MtpDataPacket.h"
|
|
|
|
#include "MtpResponsePacket.h"
|
2010-07-12 18:54:16 -04:00
|
|
|
#include "MtpEventPacket.h"
|
2010-05-11 17:16:59 -04:00
|
|
|
#include "mtp.h"
|
|
|
|
#include "MtpUtils.h"
|
|
|
|
|
2011-02-18 09:07:14 -05:00
|
|
|
#include <utils/threads.h>
|
|
|
|
|
2010-05-14 10:10:36 -04:00
|
|
|
namespace android {
|
|
|
|
|
2010-07-03 00:44:05 -04:00
|
|
|
class MtpDatabase;
|
|
|
|
class MtpStorage;
|
2010-05-11 17:16:59 -04:00
|
|
|
|
|
|
|
class MtpServer {
|
|
|
|
|
|
|
|
private:
|
|
|
|
// file descriptor for MTP kernel driver
|
|
|
|
int mFD;
|
|
|
|
|
2010-07-03 00:44:05 -04:00
|
|
|
MtpDatabase* mDatabase;
|
2010-05-11 17:16:59 -04:00
|
|
|
|
2010-07-02 15:15:07 -04:00
|
|
|
// group to own new files and folders
|
|
|
|
int mFileGroup;
|
|
|
|
// permissions for new files and directories
|
|
|
|
int mFilePermission;
|
|
|
|
int mDirectoryPermission;
|
|
|
|
|
2010-05-11 17:16:59 -04:00
|
|
|
// current session ID
|
|
|
|
MtpSessionID mSessionID;
|
|
|
|
// true if we have an open session and mSessionID is valid
|
|
|
|
bool mSessionOpen;
|
|
|
|
|
|
|
|
MtpRequestPacket mRequest;
|
|
|
|
MtpDataPacket mData;
|
|
|
|
MtpResponsePacket mResponse;
|
2010-07-12 18:54:16 -04:00
|
|
|
MtpEventPacket mEvent;
|
2010-05-11 17:16:59 -04:00
|
|
|
|
|
|
|
MtpStorageList mStorages;
|
|
|
|
|
|
|
|
// handle for new object, set by SendObjectInfo and used by SendObject
|
|
|
|
MtpObjectHandle mSendObjectHandle;
|
2010-07-12 08:49:01 -04:00
|
|
|
MtpObjectFormat mSendObjectFormat;
|
2010-05-11 17:16:59 -04:00
|
|
|
MtpString mSendObjectFilePath;
|
|
|
|
size_t mSendObjectFileSize;
|
|
|
|
|
2011-02-18 09:07:14 -05:00
|
|
|
Mutex mMutex;
|
|
|
|
|
2010-05-11 17:16:59 -04:00
|
|
|
public:
|
2010-07-03 00:44:05 -04:00
|
|
|
MtpServer(int fd, MtpDatabase* database,
|
2010-07-02 15:15:07 -04:00
|
|
|
int fileGroup, int filePerm, int directoryPerm);
|
2010-05-11 17:16:59 -04:00
|
|
|
virtual ~MtpServer();
|
|
|
|
|
2011-02-18 09:07:14 -05:00
|
|
|
void addStorage(MtpStorage* storage);
|
|
|
|
void removeStorage(MtpStorage* storage);
|
|
|
|
|
2010-05-11 17:16:59 -04:00
|
|
|
void run();
|
|
|
|
|
2010-07-12 18:54:16 -04:00
|
|
|
void sendObjectAdded(MtpObjectHandle handle);
|
|
|
|
void sendObjectRemoved(MtpObjectHandle handle);
|
|
|
|
|
2010-05-11 17:16:59 -04:00
|
|
|
private:
|
2011-02-18 09:07:14 -05:00
|
|
|
MtpStorage* getStorage(MtpStorageID id);
|
|
|
|
inline bool hasStorage() { return mStorages.size() > 0; }
|
|
|
|
bool hasStorage(MtpStorageID id);
|
|
|
|
void sendStoreAdded(MtpStorageID id);
|
|
|
|
void sendStoreRemoved(MtpStorageID id);
|
|
|
|
void sendEvent(MtpEventCode code, uint32_t param1);
|
|
|
|
|
2010-06-04 09:49:21 -04:00
|
|
|
bool handleRequest();
|
2010-05-11 17:16:59 -04:00
|
|
|
|
|
|
|
MtpResponseCode doGetDeviceInfo();
|
|
|
|
MtpResponseCode doOpenSession();
|
|
|
|
MtpResponseCode doCloseSession();
|
|
|
|
MtpResponseCode doGetStorageIDs();
|
|
|
|
MtpResponseCode doGetStorageInfo();
|
|
|
|
MtpResponseCode doGetObjectPropsSupported();
|
|
|
|
MtpResponseCode doGetObjectHandles();
|
2010-08-02 10:52:20 -04:00
|
|
|
MtpResponseCode doGetNumObjects();
|
2010-08-03 15:30:09 -04:00
|
|
|
MtpResponseCode doGetObjectReferences();
|
|
|
|
MtpResponseCode doSetObjectReferences();
|
2010-05-11 17:16:59 -04:00
|
|
|
MtpResponseCode doGetObjectPropValue();
|
2010-08-10 15:20:35 -04:00
|
|
|
MtpResponseCode doSetObjectPropValue();
|
|
|
|
MtpResponseCode doGetDevicePropValue();
|
|
|
|
MtpResponseCode doSetDevicePropValue();
|
|
|
|
MtpResponseCode doResetDevicePropValue();
|
2010-10-14 18:03:25 -04:00
|
|
|
MtpResponseCode doGetObjectPropList();
|
2010-05-11 17:16:59 -04:00
|
|
|
MtpResponseCode doGetObjectInfo();
|
|
|
|
MtpResponseCode doGetObject();
|
2010-11-23 09:08:01 -05:00
|
|
|
MtpResponseCode doGetPartialObject();
|
2010-05-11 17:16:59 -04:00
|
|
|
MtpResponseCode doSendObjectInfo();
|
|
|
|
MtpResponseCode doSendObject();
|
|
|
|
MtpResponseCode doDeleteObject();
|
|
|
|
MtpResponseCode doGetObjectPropDesc();
|
2010-08-10 15:20:35 -04:00
|
|
|
MtpResponseCode doGetDevicePropDesc();
|
2010-05-11 17:16:59 -04:00
|
|
|
};
|
|
|
|
|
2010-05-14 10:10:36 -04:00
|
|
|
}; // namespace android
|
|
|
|
|
2010-05-11 17:16:59 -04:00
|
|
|
#endif // _MTP_SERVER_H
|