• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_MESSAGE_HANDLER_H_
18 #define MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_MESSAGE_HANDLER_H_
19 
20 namespace mindspore {
21 namespace ps {
22 namespace core {
23 typedef void (*RefBufferRelCallback)(const void *data, size_t datalen, void *extra);
24 // MessageHandler class is used to handle requests from clients and send response from server.
25 // It's the base class of HttpMsgHandler and TcpMsgHandler.
26 class MessageHandler {
27  public:
28   MessageHandler() = default;
29   virtual ~MessageHandler() = default;
30 
31   // Raw data of this message in bytes.
32   virtual void *data() const = 0;
33 
34   // Raw data size of this message.(Number of bytes)
35   virtual size_t len() const = 0;
36 
37   virtual bool SendResponse(const void *data, const size_t &len) = 0;
SendResponseInference(const void * data,const size_t & len,RefBufferRelCallback cb)38   virtual bool SendResponseInference(const void *data, const size_t &len, RefBufferRelCallback cb) {
39     auto ret = SendResponse(data, len);
40     if (cb) {
41       cb(data, len, nullptr);
42     }
43     return ret;
44   }
45 };
46 }  // namespace core
47 }  // namespace ps
48 }  // namespace mindspore
49 #endif  // MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_MESSAGE_HANDLER_H_
50