Apollo 10.0
自动驾驶开放平台
writer_base.h
浏览该文件的文档.
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
27namespace apollo {
28namespace cyber {
29
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
91 const uint64_t GetChannelId() const { return role_attr_.channel_id(); }
92
99 bool IsInit() const {
100 std::lock_guard<std::mutex> g(lock_);
101 return init_;
102 }
103
104 protected:
106 mutable std::mutex lock_;
107 bool init_;
108};
109
110} // namespace cyber
111} // namespace apollo
112
113#endif // CYBER_NODE_WRITER_BASE_H_
Base class for a Writer.
Definition writer_base.h:37
bool IsInit() const
Is Writer initialized?
Definition writer_base.h:99
WriterBase(const proto::RoleAttributes &role_attr)
Construct a new Writer Base object
Definition writer_base.h:44
virtual bool HasReader()
Is there any Reader that subscribes our Channel? You can publish message when this return true
Definition writer_base.h:68
const std::string & GetChannelName() const
Get Writer'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
const uint64_t GetChannelId() const
Get Writer's Channel id
Definition writer_base.h:91
proto::RoleAttributes role_attr_
virtual bool Init()=0
Init the Writer
virtual void Shutdown()=0
Shutdown the Writer
class register implement
Definition arena_queue.h:37