1 /*
2  * Copyright (C) 2016 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 V4L2_CAMERA_HAL_METADATA_STATE_H_
18 #define V4L2_CAMERA_HAL_METADATA_STATE_H_
19 
20 #include "common.h"
21 #include "metadata_common.h"
22 #include "partial_metadata_interface.h"
23 #include "state_delegate_interface.h"
24 
25 namespace v4l2_camera_hal {
26 
27 // A State is a PartialMetadata that only has a single dynamic value.
28 template <typename T>
29 class State : public PartialMetadataInterface {
30  public:
State(int32_t tag,std::unique_ptr<StateDelegateInterface<T>> delegate)31   State(int32_t tag, std::unique_ptr<StateDelegateInterface<T>> delegate)
32       : tag_(tag), delegate_(std::move(delegate)){};
33 
StaticTags()34   virtual std::vector<int32_t> StaticTags() const override { return {}; };
ControlTags()35   virtual std::vector<int32_t> ControlTags() const override { return {}; };
DynamicTags()36   virtual std::vector<int32_t> DynamicTags() const override { return {tag_}; };
37 
38   virtual int PopulateStaticFields(
39       android::CameraMetadata* metadata) const override;
40   virtual int PopulateDynamicFields(
41       android::CameraMetadata* metadata) const override;
42   virtual int PopulateTemplateRequest(
43       int template_type, android::CameraMetadata* metadata) const override;
44   virtual bool SupportsRequestValues(
45       const android::CameraMetadata& metadata) const override;
46   virtual int SetRequestValues(
47       const android::CameraMetadata& metadata) override;
48 
49  private:
50   int32_t tag_;
51   std::unique_ptr<StateDelegateInterface<T>> delegate_;
52 };
53 
54 // -----------------------------------------------------------------------------
55 
56 template <typename T>
PopulateStaticFields(android::CameraMetadata *)57 int State<T>::PopulateStaticFields(android::CameraMetadata* /*metadata*/) const {
58   HAL_LOG_ENTER();
59   return 0;
60 }
61 
62 template <typename T>
PopulateDynamicFields(android::CameraMetadata * metadata)63 int State<T>::PopulateDynamicFields(android::CameraMetadata* metadata) const {
64   HAL_LOG_ENTER();
65 
66   T value;
67   int res = delegate_->GetValue(&value);
68   if (res) {
69     return res;
70   }
71   return UpdateMetadata(metadata, tag_, value);
72 };
73 
74 template <typename T>
PopulateTemplateRequest(int,android::CameraMetadata *)75 int State<T>::PopulateTemplateRequest(int /*template_type*/,
76                                       android::CameraMetadata* /*metadata*/) const {
77   HAL_LOG_ENTER();
78   return 0;
79 };
80 
81 template <typename T>
SupportsRequestValues(const android::CameraMetadata &)82 bool State<T>::SupportsRequestValues(
83     const android::CameraMetadata& /*metadata*/) const {
84   HAL_LOG_ENTER();
85   return true;
86 };
87 
88 template <typename T>
SetRequestValues(const android::CameraMetadata &)89 int State<T>::SetRequestValues(const android::CameraMetadata& /*metadata*/) {
90   HAL_LOG_ENTER();
91   return 0;
92 };
93 
94 }  // namespace v4l2_camera_hal
95 
96 #endif  // V4L2_CAMERA_HAL_METADATA_STATE_H_
97