blob: 907a80bd94c3871fa319c1f7bccdaa7430780c9f [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_CLIENT_H
18#define _MTP_CLIENT_H
19
Mike Lockwood335dd2b2010-05-19 10:33:39 -040020#include "MtpTypes.h"
Mike Lockwood16864ba2010-05-11 17:16:59 -040021
Mike Lockwoodcff0ef92010-07-01 11:32:08 -040022struct usb_host_context;
23
Mike Lockwood7850ef92010-05-14 10:10:36 -040024namespace android {
25
Mike Lockwoodcff0ef92010-07-01 11:32:08 -040026class MtpClientThread;
27
Mike Lockwood16864ba2010-05-11 17:16:59 -040028class MtpClient {
29private:
Mike Lockwoodcff0ef92010-07-01 11:32:08 -040030 MtpDeviceList mDeviceList;
31 MtpClientThread* mThread;
32 struct usb_host_context* mUsbHostContext;
33 bool mDone;
Mike Lockwood16864ba2010-05-11 17:16:59 -040034
35public:
Mike Lockwood5ed68d22010-05-25 19:08:48 -040036 MtpClient();
Mike Lockwoode13401b2010-05-19 15:12:14 -040037 virtual ~MtpClient();
Mike Lockwood16864ba2010-05-11 17:16:59 -040038
Mike Lockwood5ed68d22010-05-25 19:08:48 -040039 bool start();
Mike Lockwoodcff0ef92010-07-01 11:32:08 -040040 void stop();
Mike Lockwood16864ba2010-05-11 17:16:59 -040041
Mike Lockwood5ed68d22010-05-25 19:08:48 -040042 inline MtpDeviceList& getDeviceList() { return mDeviceList; }
43 MtpDevice* getDevice(int id);
44
45
46 virtual void deviceAdded(MtpDevice *device) = 0;
47 virtual void deviceRemoved(MtpDevice *device) = 0;
Mike Lockwood335dd2b2010-05-19 10:33:39 -040048
Mike Lockwood16864ba2010-05-11 17:16:59 -040049private:
Mike Lockwoodcff0ef92010-07-01 11:32:08 -040050 // these return true if we should stop monitoring USB and clean up
51 bool usbDeviceAdded(const char *devname);
52 bool usbDeviceRemoved(const char *devname);
53
54 friend class MtpClientThread;
55 bool threadLoop();
56 static int usb_device_added(const char *devname, void* client_data);
57 static int usb_device_removed(const char *devname, void* client_data);
Mike Lockwood16864ba2010-05-11 17:16:59 -040058};
59
Mike Lockwood7850ef92010-05-14 10:10:36 -040060}; // namespace android
61
Mike Lockwood16864ba2010-05-11 17:16:59 -040062#endif // _MTP_CLIENT_H