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 <utils/String8.h> 29 #include <utils/Vector.h> 30 #include "EmulatedCamera2.h" 31 32 namespace android { 33 class EmulatedCameraHotplugThread : public Thread { 34 public: 35 EmulatedCameraHotplugThread(size_t totalCameraCount); 36 ~EmulatedCameraHotplugThread(); 37 38 virtual void requestExit(); 39 virtual status_t requestExitAndWait(); 40 41 private: 42 virtual status_t readyToRun(); 43 virtual bool threadLoop(); 44 45 struct SubscriberInfo { 46 int CameraID; 47 int WatchID; 48 }; 49 50 bool addWatch(int cameraId); 51 bool removeWatch(int cameraId); 52 SubscriberInfo* getSubscriberInfo(int cameraId); 53 54 int getCameraId(String8 filePath) const; 55 int getCameraId(int wd) const; 56 57 String8 getFilePath(int cameraId) const; 58 int readFile(String8 filePath) const; 59 60 bool createFileIfNotExists(int cameraId) const; 61 62 Vector<int> mSubscribedCameraIds; 63 Vector<SubscriberInfo> mSubscribers; 64 65 // variables above are unguarded: 66 // -- accessed in thread loop or in constructor only 67 68 Mutex mMutex; 69 70 bool mRunning; // guarding only when it's important 71 }; 72 } // namespace android 73 74 #endif 75