• 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(), type(eType) {}
40 
from()41   explicit MessageBase(const std::string &sName, Type eType = Type::KMSG) : from(), name(sName), type(eType) {}
42 
43   explicit MessageBase(const AID &aFrom, const AID &aTo, Type eType = Type::KMSG)
from(aFrom)44       : from(aFrom), to(aTo), name(), body(), type(eType) {}
45 
46   explicit MessageBase(const AID &aFrom, const AID &aTo, const std::string &sName, Type eType = Type::KMSG)
from(aFrom)47       : from(aFrom), to(aTo), name(sName), body(), type(eType) {}
48 
49   explicit MessageBase(const AID &aFrom, const AID &aTo, const std::string &sName, std::string &&sBody,
50                        Type eType = Type::KMSG)
from(aFrom)51       : from(aFrom), to(aTo), name(sName), body(std::move(sBody)), type(eType) {}
52 
~MessageBase()53   virtual ~MessageBase() {}
54 
Name()55   inline std::string &Name() { return name; }
56 
SetName(const std::string & aName)57   inline void SetName(const std::string &aName) { this->name = aName; }
58 
From()59   inline AID &From() { return from; }
60 
Body()61   inline std::string &Body() { return body; }
62 
SetFrom(const AID & aFrom)63   inline void SetFrom(const AID &aFrom) { from = aFrom; }
64 
To()65   inline AID &To() { return to; }
66 
SetTo(const AID & aTo)67   inline void SetTo(const AID &aTo) { to = aTo; }
68 
GetType()69   inline Type GetType() const { return type; }
70 
SetType(Type eType)71   inline void SetType(Type eType) { type = eType; }
72 
Run(ActorBase * actor)73   virtual void Run(ActorBase *actor) {}
74 
75   friend class ActorBase;
76   friend class TCPMgr;
77   AID from;
78   AID to;
79   std::string name;
80   std::string body;
81   Type type;
82 };
83 
84 }  // namespace mindspore
85 
86 #endif
87