1 /**
2 * Copyright 2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "ps/core/communicator/http_msg_handler.h"
18 #include <memory>
19
20 namespace mindspore {
21 namespace ps {
22 namespace core {
HttpMsgHandler(const std::shared_ptr<HttpMessageHandler> & http_msg,uint8_t * const data,size_t len)23 HttpMsgHandler::HttpMsgHandler(const std::shared_ptr<HttpMessageHandler> &http_msg, uint8_t *const data, size_t len)
24 : http_msg_(http_msg), data_(data), len_(len) {}
25
data() const26 void *HttpMsgHandler::data() const {
27 MS_ERROR_IF_NULL_W_RET_VAL(data_, nullptr);
28 return data_;
29 }
30
len() const31 size_t HttpMsgHandler::len() const { return len_; }
32
SendResponse(const void * data,const size_t & len)33 bool HttpMsgHandler::SendResponse(const void *data, const size_t &len) {
34 MS_ERROR_IF_NULL_W_RET_VAL(data, false);
35 http_msg_->QuickResponse(kHttpSuccess, data, len);
36 return true;
37 }
38
SendResponseInference(const void * data,const size_t & len,RefBufferRelCallback cb)39 bool HttpMsgHandler::SendResponseInference(const void *data, const size_t &len, RefBufferRelCallback cb) {
40 MS_ERROR_IF_NULL_W_RET_VAL(data, false);
41 http_msg_->QuickResponseInference(kHttpSuccess, data, len, cb);
42 return true;
43 }
44 } // namespace core
45 } // namespace ps
46 } // namespace mindspore
47