[ML][Single] Implemented setTimeout and close
[platform/core/api/webapi-plugins.git] / src / ml / ml_single_manager.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_SINGLE_MANAGER_H_
18 #define ML_ML_SINGLE_MANAGER_H_
19
20 #include <mutex>
21
22 #include "common/platform_result.h"
23
24 #include "ml_singleshot.h"
25 #include "ml_tensors_info_manager.h"
26 #include "nnstreamer/nnstreamer-single.h"
27
28 using common::PlatformResult;
29
30 namespace extension {
31 namespace ml {
32
33 class SingleManager {
34  public:
35   SingleManager(TensorsInfoManager* tim);
36   ~SingleManager();
37
38   SingleManager() = delete;
39   SingleManager(const SingleManager&) = delete;
40   SingleManager& operator=(const SingleManager&) = delete;
41
42   // MachineLearningSingle::openModel()
43   PlatformResult OpenModel(const std::string& modelPath, TensorsInfo* inTensorsInfo,
44                            TensorsInfo* outTensorsInfo, ml_nnfw_type_e nnfw_e, ml_nnfw_hw_e hw_e,
45                            bool isDynamicMode, int* res_id);
46   // MachineLearningSingle::openModelAsync()
47   // OpenModelSuccessCallback
48   PlatformResult GetNativeTensorsInfo(int id, bool get_input_mode, int* res_id);
49   PlatformResult SetNativeInputInfo(int id, TensorsInfo* inTensorsInfo);
50   PlatformResult Invoke(int id, TensorsData* in_tensors_data, TensorsData** out_tensors_data);
51   PlatformResult GetValue(int id, const std::string& name, std::string& value);
52   PlatformResult SetValue(int id, const std::string& name, const std::string& value);
53   PlatformResult SetTimeout(int id, unsigned long timeout);
54   PlatformResult Close(int id);
55
56  private:
57   int nextId_;
58   std::map<int, std::unique_ptr<SingleShot>> singles_;
59   std::mutex singles_mutex_;
60   TensorsInfoManager* tim_;
61   SingleShot* GetSingleShot(int id);
62 };
63
64 }  // namespace ml
65 }  // namespace extension
66
67 #endif  // ML_ML_SINGLE_MANAGER_H_