[ML][Pipeline] Implement {register, unregister}CustomFilter
[platform/core/api/webapi-plugins.git] / src / ml / ml_pipeline_custom_filter.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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 ML_ML_PIPELINE_CUSTOM_FILTER_H_
18 #define ML_ML_PIPELINE_CUSTOM_FILTER_H_
19
20 #include <memory>
21 #include <string>
22 #include <thread>
23 #include <unordered_map>
24
25 #include <nnstreamer/nnstreamer.h>
26
27 #include "common/extension.h"
28 #include "common/platform_result.h"
29
30 #include "ml_tensors_data_manager.h"
31 #include "ml_tensors_info_manager.h"
32
33 using common::PlatformResult;
34
35 namespace extension {
36 namespace ml {
37 namespace pipeline {
38
39 class CustomFilter {
40  public:
41   static PlatformResult CreateAndRegisterCustomFilter(
42       const std::string& name, const std::string& listener_name,
43       TensorsInfo* input_tensors_info_ptr, TensorsInfo* output_tensors_info_ptr,
44       common::Instance* instance_ptr, TensorsInfoManager* tensors_info_manager_ptr,
45       TensorsDataManager* tensors_data_manager_ptr, std::unique_ptr<CustomFilter>* out);
46
47   ~CustomFilter();
48
49   PlatformResult Unregister();
50
51   CustomFilter(const CustomFilter&) = delete;
52   CustomFilter& operator=(const CustomFilter&) = delete;
53
54  private:
55   CustomFilter(const std::string& name, const std::string& listener_name,
56                TensorsInfo* input_tensors_info, TensorsInfo* output_tensors_info,
57                common::Instance* instance_ptr, TensorsInfoManager* tensors_info_manager_ptr,
58                TensorsDataManager* tensors_data_manager_ptrr,
59                const std::thread::id& main_thread_id);
60
61   static int CustomFilterListener(const ml_tensors_data_h tensors_data_in,
62                                   ml_tensors_data_h tensors_data_out, void* user_data);
63
64   const std::string name_;
65   const std::string listener_name_;
66   TensorsInfo* input_tensors_info_ptr_;
67   TensorsInfo* output_tensors_info_ptr_;
68   ml_custom_easy_filter_h custom_filter_;
69   common::Instance* instance_ptr_;
70   TensorsInfoManager* tensors_info_manager_ptr_;
71   TensorsDataManager* tensors_data_manager_ptr_;
72
73   std::thread::id main_thread_id_;
74 };
75
76 }  // namespace pipeline
77 }  // namespace ml
78 }  // namespace extension
79
80 #endif  // ML_ML_PIPELINE_CUSTOM_FILTER_H_