1 /* 2 * Copyright (C) 2013 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 HW_EMULATOR_CAMERA_EMULATED_CAMERA_HOTPLUG_H 18 #define HW_EMULATOR_CAMERA_EMULATED_CAMERA_HOTPLUG_H 19 20 /** 21 * This class emulates hotplug events by inotifying on a file, specific 22 * to a camera ID. When the file changes between 1/0 the hotplug 23 * status goes between PRESENT and NOT_PRESENT. 24 * 25 * Refer to FAKE_HOTPLUG_FILE in EmulatedCameraHotplugThread.cpp 26 */ 27 28 #include <vector> 29 #include "EmulatedCamera2.h" 30 #include <utils/String8.h> 31 #include <utils/Vector.h> 32 33 namespace android { 34 class EmulatedCameraHotplugThread : public Thread { 35 public: 36 EmulatedCameraHotplugThread(std::vector<int> subscribedCameraIds); 37 ~EmulatedCameraHotplugThread(); 38 39 virtual void requestExit(); 40 virtual status_t requestExitAndWait(); 41 42 private: 43 44 45 virtual status_t readyToRun(); 46 virtual bool threadLoop(); 47 48 struct SubscriberInfo { 49 int CameraID; 50 int WatchID; 51 }; 52 53 bool addWatch(int cameraId); 54 bool removeWatch(int cameraId); 55 SubscriberInfo* getSubscriberInfo(int cameraId); 56 57 int getCameraId(const String8& filePath) const; 58 int getCameraId(int wd) const; 59 60 String8 getFilePath(int cameraId) const; 61 int readFile(const String8& filePath) const; 62 63 int mInotifyFd; 64 std::vector<int> mSubscribedCameraIds; 65 Vector<SubscriberInfo> mSubscribers; 66 67 // variables above are unguarded: 68 // -- accessed in thread loop or in constructor only 69 70 Mutex mMutex; 71 72 bool mRunning; // guarding only when it's important 73 }; 74 } // namespace android 75 76 #endif 77