blob: c9a24d7492ba859ccaa388c7903bac7aecdd5ba2 [file] [log] [blame]
Igor Murashkin44cfcf02013-03-01 16:22:28 -08001/*
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 ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_BASE_H
19
20#include "CameraDeviceBase.h"
21#include "CameraService.h"
22
23namespace android {
24
25class IMemory;
26
27template <typename TClientBase>
28class Camera2ClientBase :
29 public TClientBase,
30 public CameraDeviceBase::NotificationListener
31{
32public:
33 typedef typename TClientBase::TCamCallbacks TCamCallbacks;
34
35 /**
36 * Base binder interface (see ICamera/IProCameraUser for details)
37 */
38 virtual status_t connect(const sp<TCamCallbacks>& callbacks);
39 virtual void disconnect();
40
41 /**
42 * Interface used by CameraService
43 */
44
45 // TODO: too many params, move into a ClientArgs<T>
46 Camera2ClientBase(const sp<CameraService>& cameraService,
47 const sp<TCamCallbacks>& remoteCallback,
48 const String16& clientPackageName,
49 int cameraId,
50 int cameraFacing,
51 int clientPid,
52 uid_t clientUid,
53 int servicePid);
54 virtual ~Camera2ClientBase();
55
56 virtual status_t initialize(camera_module_t *module);
57 virtual status_t dump(int fd, const Vector<String16>& args);
58
59 /**
60 * CameraDeviceBase::NotificationListener implementation
61 */
62
63 virtual void notifyError(int errorCode, int arg1, int arg2);
64 virtual void notifyShutter(int frameNumber, nsecs_t timestamp);
65 virtual void notifyAutoFocus(uint8_t newState, int triggerId);
66 virtual void notifyAutoExposure(uint8_t newState, int triggerId);
67 virtual void notifyAutoWhitebalance(uint8_t newState,
68 int triggerId);
69
70
71 int getCameraId() const;
72 const sp<CameraDeviceBase>&
73 getCameraDevice();
74 const sp<CameraService>&
75 getCameraService();
76
77 /**
78 * Interface used by independent components of CameraClient2Base.
79 */
80
81 // Simple class to ensure that access to TCamCallbacks is serialized
82 // by requiring mRemoteCallbackLock to be locked before access to
83 // mRemoteCallback is possible.
84 class SharedCameraCallbacks {
85 public:
86 class Lock {
87 public:
88 Lock(SharedCameraCallbacks &client);
89 ~Lock();
90 sp<TCamCallbacks> &mRemoteCallback;
91 private:
92 SharedCameraCallbacks &mSharedClient;
93 };
94 SharedCameraCallbacks(const sp<TCamCallbacks>& client);
95 SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
96 void clear();
97 private:
98 sp<TCamCallbacks> mRemoteCallback;
99 mutable Mutex mRemoteCallbackLock;
100 } mSharedCameraCallbacks;
101
102protected:
103
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104 virtual sp<IBinder> asBinderWrapper() {
105 return IInterface::asBinder();
106 }
107
Igor Murashkin44cfcf02013-03-01 16:22:28 -0800108 virtual status_t dumpDevice(int fd, const Vector<String16>& args);
109
110 /** Binder client interface-related private members */
111
112 // Mutex that must be locked by methods implementing the binder client
113 // interface. Ensures serialization between incoming client calls.
114 // All methods in this class hierarchy that append 'L' to the name assume
115 // that mBinderSerializationLock is locked when they're called
116 mutable Mutex mBinderSerializationLock;
117
118 /** CameraDeviceBase instance wrapping HAL2+ entry */
119
120 sp<CameraDeviceBase> mDevice;
121
122 /** Utility members */
123
124 // Verify that caller is the owner of the camera
125 status_t checkPid(const char *checkLocation) const;
126
127 virtual void detachDevice();
128};
129
130}; // namespace android
131
132#endif