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 #ifndef RESPONSE_H 17 #define RESPONSE_H 18 19 #include <string> 20 21 #include "protocol/data_channel/include/i_request.h" 22 23 namespace OHOS { 24 namespace AI { 25 class Response { 26 public: 27 explicit Response(IRequest *request); 28 ~Response(); 29 30 /** 31 * Get request Id. 32 * 33 * @return Request Id. 34 */ 35 int GetRequestId() const; 36 37 /** 38 * Get inner sequence Id, which is globally unique. 39 * 40 * @return Inner sequence Id. 41 */ 42 long long GetInnerSequenceId() const; 43 44 /** 45 * Set inner sequence Id, which is globally unique. 46 * 47 * @param [in] seqId Inner sequence Id. 48 */ 49 void SetInnerSequenceId(long long seqId); 50 51 /** 52 * Get request transaction Id. 53 * 54 * @return Request transaction Id. 55 */ 56 long long GetTransactionId() const; 57 58 /** 59 * Set request transaction Id. 60 * 61 * @param [in] transactionId Transaction Id. 62 */ 63 void SetTransactionId(long long transactionId); 64 65 /** 66 * Get algorithm plugin type. 67 * 68 * @return Algorithm plugin type. 69 */ 70 int GetAlgoPluginType() const; 71 72 /** 73 * Set algorithm plugin type. 74 * 75 * @param [in] type Algorithm plugin type. 76 */ 77 void SetAlgoPluginType(int type); 78 79 /** 80 * Get response return code. 81 * 82 * @return Response return code. 83 */ 84 int GetRetCode() const; 85 86 /** 87 * Set response return code. 88 * 89 * @param [in] retCode Response return code. 90 */ 91 void SetRetCode(int retCode); 92 93 /** 94 * Get client uid. 95 * 96 * @return Client uid. 97 */ 98 uid_t GetClientUid() const; 99 100 /** 101 * Set client uid. 102 * 103 * @param [in] clientUid Client uid. 104 */ 105 void SetClientUid(const uid_t clientUid); 106 107 /** 108 * Get response return description. 109 * 110 * @return Response return description. 111 */ 112 const std::string &GetRetDesc() const; 113 114 /** 115 * Set response return description. 116 * 117 * @param [in] retDesc Response return description. 118 */ 119 void SetRetDesc(const std::string &retDesc); 120 121 /** 122 * Get response result. 123 * 124 * @return Response result. 125 */ 126 const DataInfo &GetResult() const; 127 128 /** 129 * Set response result. 130 * 131 * @param [in] resLen Message length. 132 */ 133 void SetResult(const DataInfo &result); 134 135 /** 136 * detach DataInfo data ptr 137 */ 138 void Detach(); 139 140 private: 141 int requestId_; 142 long long innerSequenceId_; 143 long long transactionId_; 144 int retCode_; 145 uid_t clientUid_ = 0; 146 std::string retDesc_; 147 int algoPluginType_; 148 DataInfo result_; 149 }; 150 } // namespace AI 151 } // namespace OHOS 152 153 #endif // RESPONSE_H 154