• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
16 #include "protocol/data_channel/include/response.h"
17 
18 #include "protocol/data_channel/include/i_response.h"
19 #include "protocol/data_channel/include/request.h"
20 #include "utils/inf_cast_impl.h"
21 
22 namespace OHOS {
23 namespace AI {
24 namespace {
25     const int INVALID_ALGO_PLUGIN_TYPE = -1;
26 }
Response(IRequest * request)27 Response::Response(IRequest *request) : requestId_(0), innerSequenceId_(0), transactionId_(0),
28     retCode_(RETCODE_SUCCESS), algoPluginType_(INVALID_ALGO_PLUGIN_TYPE)
29 {
30     result_.data = nullptr;
31     result_.length = 0;
32     if (request != nullptr) {
33         requestId_ = request->GetRequestId();
34         innerSequenceId_ = (reinterpret_cast<Request *>(request))->GetInnerSequenceId();
35         transactionId_ = request->GetTransactionId();
36         algoPluginType_ = request->GetAlgoPluginType();
37         clientUid_ = request->GetClientUid();
38     }
39 }
40 
~Response()41 Response::~Response()
42 {
43     if (result_.data != nullptr) {
44         free(result_.data);
45         result_.data = nullptr;
46         result_.length = 0;
47     }
48 }
49 
GetRequestId() const50 int Response::GetRequestId() const
51 {
52     return requestId_;
53 }
54 
GetInnerSequenceId() const55 long long Response::GetInnerSequenceId() const
56 {
57     return innerSequenceId_;
58 }
59 
SetInnerSequenceId(long long seqId)60 void Response::SetInnerSequenceId(long long seqId)
61 {
62     innerSequenceId_ = seqId;
63 }
64 
GetTransactionId() const65 long long Response::GetTransactionId() const
66 {
67     return transactionId_;
68 }
69 
SetTransactionId(long long transactionId)70 void Response::SetTransactionId(long long transactionId)
71 {
72     transactionId_ = transactionId;
73 }
74 
GetAlgoPluginType() const75 int Response::GetAlgoPluginType() const
76 {
77     return algoPluginType_;
78 }
79 
SetAlgoPluginType(int type)80 void Response::SetAlgoPluginType(int type)
81 {
82     algoPluginType_ = type;
83 }
84 
GetRetCode() const85 int Response::GetRetCode() const
86 {
87     return retCode_;
88 }
89 
SetRetCode(int retCode)90 void Response::SetRetCode(int retCode)
91 {
92     retCode_ = retCode;
93 }
94 
GetClientUid() const95 uid_t Response::GetClientUid() const
96 {
97     return clientUid_;
98 }
99 
SetClientUid(const uid_t clientUid)100 void Response::SetClientUid(const uid_t clientUid)
101 {
102     clientUid_ = clientUid;
103 }
104 
GetRetDesc() const105 const std::string &Response::GetRetDesc() const
106 {
107     return retDesc_;
108 }
109 
SetRetDesc(const std::string & retDesc)110 void Response::SetRetDesc(const std::string &retDesc)
111 {
112     retDesc_ = retDesc;
113 }
114 
GetResult() const115 const DataInfo &Response::GetResult() const
116 {
117     return result_;
118 }
119 
SetResult(const DataInfo & result)120 void Response::SetResult(const DataInfo &result)
121 {
122     result_ = result;
123 }
124 
Detach()125 void Response::Detach()
126 {
127     result_.data = nullptr;
128 }
129 
130 DEFINE_IMPL_CLASS_CAST(ResponseCast, IResponse, Response);
131 
Create(IRequest * request)132 IResponse *IResponse::Create(IRequest *request)
133 {
134     return ResponseCast::Create(request);
135 }
136 
Destroy(IResponse * & response)137 void IResponse::Destroy(IResponse *&response)
138 {
139     ResponseCast::Destroy(response);
140 }
141 
GetRequestId() const142 int IResponse::GetRequestId() const
143 {
144     return ResponseCast::Ref(this).GetRequestId();
145 }
146 
GetTransactionId() const147 long long IResponse::GetTransactionId() const
148 {
149     return ResponseCast::Ref(this).GetTransactionId();
150 }
151 
SetTransactionId(long long transactionId)152 void IResponse::SetTransactionId(long long transactionId)
153 {
154     ResponseCast::Ref(this).SetTransactionId(transactionId);
155 }
156 
GetRetCode() const157 int IResponse::GetRetCode() const
158 {
159     return ResponseCast::Ref(this).GetRetCode();
160 }
161 
SetRetCode(int retCode)162 void IResponse::SetRetCode(int retCode)
163 {
164     ResponseCast::Ref(this).SetRetCode(retCode);
165 }
166 
GetClientUid() const167 uid_t IResponse::GetClientUid() const
168 {
169     return ResponseCast::Ref(this).GetClientUid();
170 }
171 
SetClientUid(const uid_t clientUid)172 void IResponse::SetClientUid(const uid_t clientUid)
173 {
174     ResponseCast::Ref(this).SetClientUid(clientUid);
175 }
176 
GetRetDesc() const177 const std::string &IResponse::GetRetDesc() const
178 {
179     return ResponseCast::Ref(this).GetRetDesc();
180 }
181 
SetRetDesc(const std::string & retDesc)182 void IResponse::SetRetDesc(const std::string &retDesc)
183 {
184     ResponseCast::Ref(this).SetRetDesc(retDesc);
185 }
186 
GetResult() const187 const DataInfo &IResponse::GetResult() const
188 {
189     return ResponseCast::Ref(this).GetResult();
190 }
191 
SetResult(const DataInfo & result)192 void IResponse::SetResult(const DataInfo &result)
193 {
194     ResponseCast::Ref(this).SetResult(result);
195 }
196 
Detach()197 void IResponse::Detach()
198 {
199     ResponseCast::Ref(this).Detach();
200 }
201 } // namespace AI
202 } // namespace OHOS
203