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/request.h"
17 
18 #include "protocol/struct_definition/aie_info_define.h"
19 #include "utils/inf_cast_impl.h"
20 
21 namespace OHOS {
22 namespace AI {
Request()23 Request::Request()
24     : innerSequenceId_(0),
25       requestId_(0),
26       operationId_(0),
27       clientUid_(0),
28       transactionId_(0),
29       algoPluginType_(0)
30 {
31     msg_.data = nullptr;
32     msg_.length = 0;
33 }
34 
~Request()35 Request::~Request()
36 {
37     if (msg_.data != nullptr) {
38         free(msg_.data);
39         msg_.data = nullptr;
40         msg_.length = 0;
41     }
42 }
43 
GetInnerSequenceId() const44 long long Request::GetInnerSequenceId() const
45 {
46     return innerSequenceId_;
47 }
48 
SetInnerSequenceId(long long seqId)49 void Request::SetInnerSequenceId(long long seqId)
50 {
51     innerSequenceId_ = seqId;
52 }
53 
GetRequestId() const54 int Request::GetRequestId() const
55 {
56     return requestId_;
57 }
58 
SetRequestId(int requestId)59 void Request::SetRequestId(int requestId)
60 {
61     requestId_ = requestId;
62 }
63 
GetOperationId() const64 int Request::GetOperationId() const
65 {
66     return operationId_;
67 }
68 
SetOperationId(int operationId)69 void Request::SetOperationId(int operationId)
70 {
71     operationId_ = operationId;
72 }
73 
GetClientUid() const74 uid_t Request::GetClientUid() const
75 {
76     return clientUid_;
77 }
78 
SetClientUid(const uid_t clientUid)79 void Request::SetClientUid(const uid_t clientUid)
80 {
81     clientUid_ = clientUid;
82 }
83 
GetTransactionId() const84 long long Request::GetTransactionId() const
85 {
86     return transactionId_;
87 }
88 
SetTransactionId(long long transactionId)89 void Request::SetTransactionId(long long transactionId)
90 {
91     transactionId_ = transactionId;
92 }
93 
GetAlgoPluginType() const94 int Request::GetAlgoPluginType() const
95 {
96     return algoPluginType_;
97 }
98 
SetAlgoPluginType(int type)99 void Request::SetAlgoPluginType(int type)
100 {
101     algoPluginType_ = type;
102 }
103 
GetMsg() const104 const DataInfo &Request::GetMsg() const
105 {
106     return msg_;
107 }
108 
SetMsg(const DataInfo & msg)109 void Request::SetMsg(const DataInfo &msg)
110 {
111     msg_ = msg;
112 }
113 
114 DEFINE_IMPL_CLASS_CAST(RequestCast, IRequest, Request);
115 
Create()116 IRequest *IRequest::Create()
117 {
118     return RequestCast::Create();
119 }
120 
Destroy(IRequest * & request)121 void IRequest::Destroy(IRequest *&request)
122 {
123     RequestCast::Destroy(request);
124 }
125 
GetRequestId() const126 int IRequest::GetRequestId() const
127 {
128     return RequestCast::Ref(this).GetRequestId();
129 }
130 
SetRequestId(int requestId)131 void IRequest::SetRequestId(int requestId)
132 {
133     RequestCast::Ref(this).SetRequestId(requestId);
134 }
135 
GetOperationId() const136 int IRequest::GetOperationId() const
137 {
138     return RequestCast::Ref(this).GetOperationId();
139 }
140 
SetOperationId(int operationId)141 void IRequest::SetOperationId(int operationId)
142 {
143     RequestCast::Ref(this).SetOperationId(operationId);
144 }
145 
GetClientUid() const146 uid_t IRequest::GetClientUid() const
147 {
148     return RequestCast::Ref(this).GetClientUid();
149 }
150 
SetClientUid(const uid_t clientUid)151 void IRequest::SetClientUid(const uid_t clientUid)
152 {
153     RequestCast::Ref(this).SetClientUid(clientUid);
154 }
155 
GetTransactionId() const156 long long IRequest::GetTransactionId() const
157 {
158     return RequestCast::Ref(this).GetTransactionId();
159 }
160 
SetTransactionId(long long transactionId)161 void IRequest::SetTransactionId(long long transactionId)
162 {
163     RequestCast::Ref(this).SetTransactionId(transactionId);
164 }
165 
GetAlgoPluginType() const166 int IRequest::GetAlgoPluginType() const
167 {
168     return RequestCast::Ref(this).GetAlgoPluginType();
169 }
170 
SetAlgoPluginType(int type)171 void IRequest::SetAlgoPluginType(int type)
172 {
173     RequestCast::Ref(this).SetAlgoPluginType(type);
174 }
175 
GetMsg() const176 const DataInfo &IRequest::GetMsg() const
177 {
178     return RequestCast::Ref(this).GetMsg();
179 }
180 
SetMsg(const DataInfo & msg)181 void IRequest::SetMsg(const DataInfo &msg)
182 {
183     RequestCast::Ref(this).SetMsg(msg);
184 }
185 } // namespace AI
186 } // namespace OHOS
187