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