Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 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 Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 20 | #include "MtpTypes.h" |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 21 | |
Mike Lockwood | 108505b | 2010-07-20 09:48:35 -0400 | [diff] [blame] | 22 | #include <utils/threads.h> |
| 23 | |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 24 | struct usb_host_context; |
| 25 | |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 28 | class MtpClientThread; |
| 29 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 30 | class MtpClient { |
| 31 | private: |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 32 | MtpDeviceList mDeviceList; |
| 33 | MtpClientThread* mThread; |
Mike Lockwood | 108505b | 2010-07-20 09:48:35 -0400 | [diff] [blame] | 34 | Condition mThreadStartCondition; |
| 35 | Mutex mMutex; |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 36 | struct usb_host_context* mUsbHostContext; |
| 37 | bool mDone; |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 38 | |
| 39 | public: |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 40 | MtpClient(); |
Mike Lockwood | 3743365 | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 41 | virtual ~MtpClient(); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 42 | |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 43 | bool start(); |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 44 | void stop(); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 45 | |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 46 | 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 Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 52 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 53 | private: |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 54 | // 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 Lockwood | 108505b | 2010-07-20 09:48:35 -0400 | [diff] [blame] | 57 | bool usbDiscoveryDone(); |
Mike Lockwood | d0e1a9f | 2010-07-01 11:32:08 -0400 | [diff] [blame] | 58 | |
| 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 Lockwood | 108505b | 2010-07-20 09:48:35 -0400 | [diff] [blame] | 63 | static int usb_discovery_done(void* client_data); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 66 | }; // namespace android |
| 67 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 68 | #endif // _MTP_CLIENT_H |