| | | 1 | | // Copyright 2025 Digital Holography Foundation |
| | | 2 | | // |
| | | 3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
| | | 4 | | // you may not use this file except in compliance with the License. |
| | | 5 | | // You may obtain a copy of the License at |
| | | 6 | | // |
| | | 7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
| | | 8 | | // |
| | | 9 | | // Unless required by applicable law or agreed to in writing, software |
| | | 10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
| | | 11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | 12 | | // See the License for the specific language governing permissions and |
| | | 13 | | // limitations under the License. |
| | | 14 | | |
| | | 15 | | #pragma once |
| | | 16 | | |
| | | 17 | | #include <nlohmann/json.hpp> |
| | | 18 | | #include <span> |
| | | 19 | | |
| | | 20 | | #include "holoflow/core/tasks.hh" |
| | | 21 | | |
| | | 22 | | namespace holotask::asyncs { |
| | | 23 | | |
| | | 24 | | // ------------------------------------------------------------------------------------------------- |
| | | 25 | | // Settings |
| | | 26 | | // ------------------------------------------------------------------------------------------------- |
| | | 27 | | |
| | | 28 | | struct SlidingAverageSettings { |
| | | 29 | | size_t target_capacity; |
| | | 30 | | size_t window_size; |
| | | 31 | | size_t discard_first = 0; |
| | | 32 | | |
| | | 33 | | bool operator==(const SlidingAverageSettings &) const = default; |
| | | 34 | | }; |
| | | 35 | | |
| | | 36 | | void to_json(nlohmann::json &j, const SlidingAverageSettings &s); |
| | | 37 | | void from_json(const nlohmann::json &j, SlidingAverageSettings &s); |
| | | 38 | | |
| | | 39 | | // ------------------------------------------------------------------------------------------------- |
| | | 40 | | // Factory |
| | | 41 | | // ------------------------------------------------------------------------------------------------- |
| | | 42 | | |
| | | 43 | | class SlidingAverageFactory : public holoflow::core::IAsyncTaskFactory { |
| | | 44 | | public: |
| | 0 | 45 | | ~SlidingAverageFactory() override = default; |
| | | 46 | | |
| | | 47 | | holoflow::core::InferResult infer(std::span<const holoflow::core::TDesc> input_descs, |
| | | 48 | | const nlohmann::json &jsettings) const override; |
| | | 49 | | |
| | | 50 | | std::unique_ptr<holoflow::core::IAsyncTask> |
| | | 51 | | create(std::span<const holoflow::core::TDesc> input_descs, const nlohmann::json &jsettings, |
| | | 52 | | const holoflow::core::AsyncCreateCtx &ctx) const override; |
| | | 53 | | |
| | | 54 | | std::unique_ptr<holoflow::core::IAsyncTask> |
| | | 55 | | update(std::unique_ptr<holoflow::core::IAsyncTask> old_task, |
| | | 56 | | std::span<const holoflow::core::TDesc> input_descs, const nlohmann::json &jsettings, |
| | | 57 | | const holoflow::core::AsyncCreateCtx &ctx) const override; |
| | | 58 | | }; |
| | | 59 | | |
| | | 60 | | } // namespace holotask::asyncs |