Apollo  6.0
Open source self driving car software
writer_base.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 CYBER_NODE_WRITER_BASE_H_
18 #define CYBER_NODE_WRITER_BASE_H_
19 
20 #include <atomic>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
25 #include "cyber/proto/role_attributes.pb.h"
26 
27 namespace apollo {
28 namespace cyber {
29 
37 class WriterBase {
38  public:
44  explicit WriterBase(const proto::RoleAttributes& role_attr)
45  : role_attr_(role_attr), init_(false) {}
46  virtual ~WriterBase() {}
47 
54  virtual bool Init() = 0;
55 
59  virtual void Shutdown() = 0;
60 
68  virtual bool HasReader() { return false; }
69 
75  virtual void GetReaders(std::vector<proto::RoleAttributes>* readers) {}
76 
82  const std::string& GetChannelName() const {
83  return role_attr_.channel_name();
84  }
85 
92  bool IsInit() const {
93  std::lock_guard<std::mutex> g(lock_);
94  return init_;
95  }
96 
97  protected:
98  proto::RoleAttributes role_attr_;
99  mutable std::mutex lock_;
100  bool init_;
101 };
102 
103 } // namespace cyber
104 } // namespace apollo
105 
106 #endif // CYBER_NODE_WRITER_BASE_H_
virtual ~WriterBase()
Definition: writer_base.h:46
std::mutex lock_
Definition: writer_base.h:99
proto::RoleAttributes role_attr_
Definition: writer_base.h:98
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool init_
Definition: writer_base.h:100
const std::string & GetChannelName() const
Get Writer&#39;s Channel name.
Definition: writer_base.h:82
virtual void GetReaders(std::vector< proto::RoleAttributes > *readers)
Get all Readers that subscriber our writing channel.
Definition: writer_base.h:75
bool IsInit() const
Is Writer initialized?
Definition: writer_base.h:92
Base class for a Writer. A Writer is an object to send messages through a &#39;Channel&#39;.
Definition: writer_base.h:37
virtual bool HasReader()
Is there any Reader that subscribes our Channel? You can publish message when this return true...
Definition: writer_base.h:68
virtual void Shutdown()=0
Shutdown the Writer.
WriterBase(const proto::RoleAttributes &role_attr)
Construct a new Writer Base object.
Definition: writer_base.h:44
virtual bool Init()=0
Init the Writer.