Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / base / ie_infer_async_request_base.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 "ie_iinfer_request.hpp"
11 #include "cpp_interfaces/exception2status.hpp"
12 #include "ie_profiling.hpp"
13
14 namespace InferenceEngine {
15
16 /**
17  * @brief cpp interface for async infer request, to avoid dll boundaries and simplify internal development
18  * @tparam T Minimal CPP implementation of IInferRequest (e.g. AsyncInferRequestThreadSafeDefault)
19  */
20 template<class T>
21 class InferRequestBase : public IInferRequest {
22 protected:
23     std::shared_ptr<T> _impl;
24
25 public:
26     typedef std::shared_ptr<InferRequestBase<T>> Ptr;
27
28     explicit InferRequestBase(std::shared_ptr<T> impl) : _impl(impl) {}
29
30     StatusCode Infer(ResponseDesc *resp) noexcept override {
31         IE_PROFILING_AUTO_SCOPE(Infer);
32         TO_STATUS(_impl->Infer());
33     }
34
35     StatusCode GetPerformanceCounts(std::map<std::string, InferenceEngineProfileInfo> &perfMap,
36                                     ResponseDesc *resp) const noexcept override {
37         TO_STATUS(_impl->GetPerformanceCounts(perfMap));
38     }
39
40     StatusCode SetBlob(const char *name, const Blob::Ptr &data, ResponseDesc *resp) noexcept override {
41         TO_STATUS(_impl->SetBlob(name, data));
42     }
43
44     StatusCode GetBlob(const char *name, Blob::Ptr &data, ResponseDesc *resp) noexcept override {
45         TO_STATUS(_impl->GetBlob(name, data));
46     }
47
48     StatusCode StartAsync(ResponseDesc *resp) noexcept override {
49         IE_PROFILING_AUTO_SCOPE(StartAsync);
50         TO_STATUS(_impl->StartAsync());
51     }
52
53     StatusCode Wait(int64_t millis_timeout, ResponseDesc *resp) noexcept override {
54         IE_PROFILING_AUTO_SCOPE(Wait);
55         NO_EXCEPT_CALL_RETURN_STATUS(_impl->Wait(millis_timeout));
56     }
57
58     StatusCode SetCompletionCallback(CompletionCallback callback) noexcept override {
59         TO_STATUS_NO_RESP(_impl->SetCompletionCallback(callback));
60     }
61
62     StatusCode GetUserData(void **data, ResponseDesc *resp) noexcept override {
63         TO_STATUS(_impl->GetUserData(data));
64     }
65
66     StatusCode SetUserData(void *data, ResponseDesc *resp) noexcept override {
67         TO_STATUS(_impl->SetUserData(data));
68     }
69
70     void Release() noexcept override {
71         delete this;
72     }
73
74     StatusCode SetBatch(int batch_size, ResponseDesc *resp) noexcept override {
75         TO_STATUS(_impl->SetBatch(batch_size));
76     }
77
78 protected:
79     ~InferRequestBase() = default;
80 };
81
82 }  // namespace InferenceEngine