Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / impl / ie_infer_async_request_internal.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <memory>
8 #include <map>
9 #include <string>
10 #include <cpp_interfaces/ie_task.hpp>
11 #include "cpp_interfaces/interface/ie_iinfer_async_request_internal.hpp"
12 #include "cpp_interfaces/impl/ie_infer_request_internal.hpp"
13
14 namespace InferenceEngine {
15
16 /**
17  * @brief minimum API to be implemented by plugin, which is used in InferRequestBase forwarding mechanism
18  */
19 class AsyncInferRequestInternal : public IAsyncInferRequestInternal, public InferRequestInternal {
20 public:
21     typedef std::shared_ptr<AsyncInferRequestInternal> Ptr;
22
23     explicit AsyncInferRequestInternal(InputsDataMap networkInputs, OutputsDataMap networkOutputs)
24             : InferRequestInternal(networkInputs, networkOutputs), _callback(nullptr) {}
25
26     void SetCompletionCallback(InferenceEngine::IInferRequest::CompletionCallback callback) override {
27         _callback = callback;
28     }
29
30     void GetUserData(void **data) override {
31         if (data == nullptr) THROW_IE_EXCEPTION << NOT_ALLOCATED_str;
32         *data = _userData;
33     }
34
35     void SetUserData(void *data) override {
36         _userData = data;
37     }
38
39     /**
40      * @brief Set weak pointer to the corresponding public interface: IInferRequest. This allow to pass it to
41      * IInferRequest::CompletionCallback
42      * @param ptr - weak pointer to InferRequestBase
43      */
44     void SetPublicInterfacePtr(IInferRequest::Ptr ptr) {
45         _publicInterface = ptr;
46     }
47
48     /**
49      * @brief The minimal infer function to be implemented by plugins. It starts inference of specified input(s) in asynchronous mode
50      * @note: It returns immediately. Inference starts also immediately.
51      */
52     virtual void StartAsyncImpl() = 0;
53
54     void StartAsync() override {
55         checkBlobs();
56         StartAsyncImpl();
57     };
58
59 protected:
60     IInferRequest::WeakPtr _publicInterface;
61     InferenceEngine::IInferRequest::CompletionCallback _callback;
62     void *_userData;
63 };
64
65 }  // namespace InferenceEngine