blob: fa5c5278714b35c42c88c5dbde464828ea6599f8 [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_CLIENT_H
18#define _MTP_CLIENT_H
19
Mike Lockwood5bae7f62010-05-19 10:33:39 -040020#include "MtpTypes.h"
Mike Lockwood56118b52010-05-11 17:16:59 -040021
Mike Lockwood108505b2010-07-20 09:48:35 -040022#include <utils/threads.h>
23
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040024struct usb_host_context;
25
Mike Lockwood8d3257a2010-05-14 10:10:36 -040026namespace android {
27
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040028class MtpClientThread;
29
Mike Lockwood56118b52010-05-11 17:16:59 -040030class MtpClient {
31private:
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040032 MtpDeviceList mDeviceList;
33 MtpClientThread* mThread;
Mike Lockwood108505b2010-07-20 09:48:35 -040034 Condition mThreadStartCondition;
35 Mutex mMutex;
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040036 struct usb_host_context* mUsbHostContext;
37 bool mDone;
Mike Lockwood56118b52010-05-11 17:16:59 -040038
39public:
Mike Lockwood755fd612010-05-25 19:08:48 -040040 MtpClient();
Mike Lockwood37433652010-05-19 15:12:14 -040041 virtual ~MtpClient();
Mike Lockwood56118b52010-05-11 17:16:59 -040042
Mike Lockwood755fd612010-05-25 19:08:48 -040043 bool start();
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040044 void stop();
Mike Lockwood56118b52010-05-11 17:16:59 -040045
Mike Lockwood755fd612010-05-25 19:08:48 -040046 inline MtpDeviceList& getDeviceList() { return mDeviceList; }
47 MtpDevice* getDevice(int id);
48
49
50 virtual void deviceAdded(MtpDevice *device) = 0;
51 virtual void deviceRemoved(MtpDevice *device) = 0;
Mike Lockwood5bae7f62010-05-19 10:33:39 -040052
Mike Lockwood56118b52010-05-11 17:16:59 -040053private:
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040054 // these return true if we should stop monitoring USB and clean up
55 bool usbDeviceAdded(const char *devname);
56 bool usbDeviceRemoved(const char *devname);
Mike Lockwood108505b2010-07-20 09:48:35 -040057 bool usbDiscoveryDone();
Mike Lockwoodd0e1a9f2010-07-01 11:32:08 -040058
59 friend class MtpClientThread;
60 bool threadLoop();
61 static int usb_device_added(const char *devname, void* client_data);
62 static int usb_device_removed(const char *devname, void* client_data);
Mike Lockwood108505b2010-07-20 09:48:35 -040063 static int usb_discovery_done(void* client_data);
Mike Lockwood56118b52010-05-11 17:16:59 -040064};
65
Mike Lockwood8d3257a2010-05-14 10:10:36 -040066}; // namespace android
67
Mike Lockwood56118b52010-05-11 17:16:59 -040068#endif // _MTP_CLIENT_H