Home | History | Annotate | Download | only in camera
      1 /*
      2 **
      3 ** Copyright 2013, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 //#define LOG_NDEBUG 0
     19 #define LOG_TAG "IProCameraCallbacks"
     20 #include <utils/Log.h>
     21 #include <stdint.h>
     22 #include <sys/types.h>
     23 
     24 #include <binder/Parcel.h>
     25 #include <gui/IGraphicBufferProducer.h>
     26 #include <gui/Surface.h>
     27 #include <utils/Mutex.h>
     28 
     29 #include <camera/IProCameraCallbacks.h>
     30 
     31 #include "camera/CameraMetadata.h"
     32 
     33 namespace android {
     34 
     35 enum {
     36     NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
     37     LOCK_STATUS_CHANGED,
     38     RESULT_RECEIVED,
     39 };
     40 
     41 class BpProCameraCallbacks: public BpInterface<IProCameraCallbacks>
     42 {
     43 public:
     44     BpProCameraCallbacks(const sp<IBinder>& impl)
     45         : BpInterface<IProCameraCallbacks>(impl)
     46     {
     47     }
     48 
     49     // generic callback from camera service to app
     50     void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
     51     {
     52         ALOGV("notifyCallback");
     53         Parcel data, reply;
     54         data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
     55         data.writeInt32(msgType);
     56         data.writeInt32(ext1);
     57         data.writeInt32(ext2);
     58         remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
     59     }
     60 
     61     void onLockStatusChanged(LockStatus newLockStatus) {
     62         ALOGV("onLockStatusChanged");
     63         Parcel data, reply;
     64         data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
     65         data.writeInt32(newLockStatus);
     66         remote()->transact(LOCK_STATUS_CHANGED, data, &reply,
     67                            IBinder::FLAG_ONEWAY);
     68     }
     69 
     70     void onResultReceived(int32_t requestId, camera_metadata* result) {
     71         ALOGV("onResultReceived");
     72         Parcel data, reply;
     73         data.writeInterfaceToken(IProCameraCallbacks::getInterfaceDescriptor());
     74         data.writeInt32(requestId);
     75         CameraMetadata::writeToParcel(data, result);
     76         remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY);
     77     }
     78 };
     79 
     80 IMPLEMENT_META_INTERFACE(ProCameraCallbacks,
     81                                         "android.hardware.IProCameraCallbacks");
     82 
     83 // ----------------------------------------------------------------------
     84 
     85 status_t BnProCameraCallbacks::onTransact(
     86     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     87 {
     88     ALOGV("onTransact - code = %d", code);
     89     switch(code) {
     90         case NOTIFY_CALLBACK: {
     91             ALOGV("NOTIFY_CALLBACK");
     92             CHECK_INTERFACE(IProCameraCallbacks, data, reply);
     93             int32_t msgType = data.readInt32();
     94             int32_t ext1 = data.readInt32();
     95             int32_t ext2 = data.readInt32();
     96             notifyCallback(msgType, ext1, ext2);
     97             return NO_ERROR;
     98         } break;
     99         case LOCK_STATUS_CHANGED: {
    100             ALOGV("LOCK_STATUS_CHANGED");
    101             CHECK_INTERFACE(IProCameraCallbacks, data, reply);
    102             LockStatus newLockStatus
    103                                  = static_cast<LockStatus>(data.readInt32());
    104             onLockStatusChanged(newLockStatus);
    105             return NO_ERROR;
    106         } break;
    107         case RESULT_RECEIVED: {
    108             ALOGV("RESULT_RECEIVED");
    109             CHECK_INTERFACE(IProCameraCallbacks, data, reply);
    110             int32_t requestId = data.readInt32();
    111             camera_metadata_t *result = NULL;
    112             CameraMetadata::readFromParcel(data, &result);
    113             onResultReceived(requestId, result);
    114             return NO_ERROR;
    115             break;
    116         }
    117         default:
    118             return BBinder::onTransact(code, data, reply, flags);
    119     }
    120 }
    121 
    122 // ----------------------------------------------------------------------------
    123 
    124 }; // namespace android
    125 
    126