• 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_CORE_MINDRT_INCLUDE_ACTOR_MSG_H
18 #define MINDSPORE_CORE_MINDRT_INCLUDE_ACTOR_MSG_H
19 
20 #include <utility>
21 #include <string>
22 
23 #include "actor/aid.h"
24 
25 namespace mindspore {
26 class ActorBase;
27 class MessageBase {
28  public:
29   enum class Type : char {
30     KMSG = 1,
31     KUDP,
32     KHTTP,
33     KASYNC,
34     KLOCAL,
35     KEXIT,
36     KTERMINATE,
37   };
38 
from()39   explicit MessageBase(Type eType = Type::KMSG) : from(), name(), data(nullptr), size(0), type(eType), func_id_(0) {}
40 
41   explicit MessageBase(const std::string &sName, Type eType = Type::KMSG)
from()42       : from(), name(sName), data(nullptr), size(0), type(eType), func_id_(0) {}
43 
44   explicit MessageBase(const AID &aFrom, const AID &aTo, Type eType = Type::KMSG)
from(aFrom)45       : from(aFrom), to(aTo), name(), body(), data(nullptr), size(0), type(eType), func_id_(0) {}
46 
47   explicit MessageBase(const AID &aFrom, const AID &aTo, const std::string &sName, Type eType = Type::KMSG)
from(aFrom)48       : from(aFrom), to(aTo), name(sName), body(), data(nullptr), size(0), type(eType), func_id_(0) {}
49 
50   explicit MessageBase(const AID &aFrom, const AID &aTo, const std::string &sName, std::string &&sBody,
51                        Type eType = Type::KMSG)
from(aFrom)52       : from(aFrom), to(aTo), name(sName), body(std::move(sBody)), data(nullptr), size(0), type(eType), func_id_(0) {}
53 
~MessageBase()54   virtual ~MessageBase() {}
55 
Name()56   inline std::string &Name() { return name; }
57 
SetName(const std::string & aName)58   inline void SetName(const std::string &aName) { this->name = aName; }
59 
From()60   inline AID &From() { return from; }
61 
Body()62   inline std::string &Body() { return body; }
63 
SetFrom(const AID & aFrom)64   inline void SetFrom(const AID &aFrom) { from = aFrom; }
65 
To()66   inline AID &To() { return to; }
67 
SetTo(const AID & aTo)68   inline void SetTo(const AID &aTo) { to = aTo; }
69 
GetType()70   inline Type GetType() const { return type; }
71 
SetType(Type eType)72   inline void SetType(Type eType) { type = eType; }
73 
Run(ActorBase * actor)74   virtual void Run(ActorBase *actor) {}
75 
76   friend class ActorBase;
77   friend class TCPMgr;
78   AID from;
79   AID to;
80   std::string name;
81   std::string body;
82 
83   // The raw bytes of data to be sent and the length of data.
84   void *data;
85   size_t size;
86 
87   Type type;
88 
89   // The id of remote function to call.
90   uint32_t func_id_;
91 };
92 }  // namespace mindspore
93 
94 #endif
95