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