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