1 /* 2 * task_taits.h 3 * 4 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Cody Xie <cody.xie@rock-chips.com> 19 */ 20 #ifndef TASK_TRAITS_H 21 #define TASK_TRAITS_H 22 23 #include <chrono> 24 #include <memory> 25 26 namespace XCam { 27 28 enum class TaskResult { 29 kSuccess, // Output valid 30 kAgain, // Need more inputs 31 kSkipped, // The result is skipped 32 kFailed, // Process failed 33 }; 34 35 template <typename R, typename... Ts> 36 struct Task { 37 R operator()(Ts... args); 38 }; 39 40 enum class ParamState { 41 kNull, // Holds empty value 42 kAllocated, // Initial state, allocated but no content 43 kReadyForProcess, // Filled with content, waiting to be processed 44 kProcessing, // Being proccessing by task 45 kProcessedError, // Be Processed but failed 46 kProcessedSuccess, // Be Processed, waiting to be dequeued 47 kProcessedDequed, // Be processed and dequed, canbe either error or 48 // success, 49 kMaxState, 50 }; 51 // template <typename T> 52 // using ServiceParam = std::pair<ParamState, std::shared_ptr<T>>; 53 54 template <typename T> 55 struct ServiceParam { 56 ParamState state; // params state 57 int32_t unique_id; // same as frame id 58 std::shared_ptr<T> payload; // holds actual params 59 }; 60 61 template <typename T> 62 struct ServiceTask : public Task<TaskResult, ServiceParam<T>> { 63 ServiceTask() = default; 64 // Allow inherit class to dtor 65 virtual ~ServiceTask() = default; operatorServiceTask66 virtual TaskResult operator()(ServiceParam<T>& p) { return TaskResult::kSkipped; } 67 }; 68 69 using TaskDuration = std::chrono::duration<double, std::milli>; 70 using TaskTimePoint = std::chrono::time_point<std::chrono::system_clock>; 71 72 constexpr uint8_t default_max_param_count = 5; 73 constexpr TaskDuration default_process_time = TaskDuration(33); 74 constexpr bool default_may_block = false; 75 76 } // namespace XCam 77 78 #endif // TASK_TRAITS_H 79