Apollo  6.0
Open source self driving car software
scene_service.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 #pragma once
17 
18 #include <memory>
19 #include <string>
20 
21 #include "cyber/common/macros.h"
23 
24 namespace apollo {
25 namespace perception {
26 namespace lidar {
27 
29  public:
30  SceneServiceContent() = default;
31  virtual ~SceneServiceContent() = default;
32  // @brief: get service content name
33  // @return: name
34  virtual std::string Name() const = 0;
35  // @brief: get a copy of this service content
36  // @param [out]: copy of the service content
37  virtual void GetCopy(SceneServiceContent* content) const = 0;
38  // @brief: set service content from outside
39  // @param [in]: input service content
40  virtual void SetContent(const SceneServiceContent& content) = 0;
41  // @brief: whether service is ready
42  // @return: status
43  bool IsServiceReady() const { return service_ready_; }
44 
45  protected:
46  bool service_ready_ = false;
47 
48  private:
49  DISALLOW_COPY_AND_ASSIGN(SceneServiceContent);
50 };
51 
53 #define PERCEPTION_REGISTER_SCENESERVICECONTENT(name) \
54  PERCEPTION_REGISTER_CLASS(SceneServiceContent, name)
55 
56 typedef std::shared_ptr<SceneServiceContent> SceneServiceContentPtr;
57 typedef std::shared_ptr<const SceneServiceContent> SceneServiceContentConstPtr;
58 
60 
61 class SceneService {
62  public:
63  SceneService() = default;
64  virtual ~SceneService() = default;
65  // @brief: initialize scene service
66  // @param [in]: init options
67  virtual bool Init(
68  const SceneServiceInitOptions& options = SceneServiceInitOptions()) = 0;
69  // @brief: get service name
70  // @return: name
71  virtual std::string Name() const = 0;
72  // @brief: get a copy of service content
73  // @param [in]: service content
75  std::lock_guard<std::mutex> lock(mutex_);
76  self_content_->GetCopy(content);
77  }
78  // @brief: update service content from copy
79  // @param [in]: service content
81  std::lock_guard<std::mutex> lock(mutex_);
82  self_content_->SetContent(content);
83  }
84 
85  protected:
86  SceneServiceContentPtr self_content_;
87  std::mutex mutex_;
88 
89  private:
91 };
92 
94 #define PERCEPTION_REGISTER_SCENESERVICE(name) \
95  PERCEPTION_REGISTER_CLASS(SceneService, name)
96 
97 typedef std::shared_ptr<SceneService> SceneServicePtr;
98 typedef std::shared_ptr<const SceneService> SceneServiceConstPtr;
99 
100 } // namespace lidar
101 } // namespace perception
102 } // namespace apollo
std::shared_ptr< SceneServiceContent > SceneServiceContentPtr
Definition: scene_service.h:56
virtual void GetCopy(SceneServiceContent *content) const =0
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: scene_service.h:61
#define DISALLOW_COPY_AND_ASSIGN(classname)
Definition: macros.h:48
virtual void SetContent(const SceneServiceContent &content)=0
virtual std::string Name() const =0
std::mutex mutex_
Definition: scene_service.h:87
std::shared_ptr< const SceneServiceContent > SceneServiceContentConstPtr
Definition: scene_service.h:57
void GetServiceContentCopy(SceneServiceContent *content)
Definition: scene_service.h:74
void UpdateServiceContent(const SceneServiceContent &content)
Definition: scene_service.h:80
bool service_ready_
Definition: scene_service.h:46
bool Init(const char *binary_name)
SceneServiceContentPtr self_content_
Definition: scene_service.h:86
PERCEPTION_REGISTER_REGISTERER(BaseOneShotTypeFusion)
std::shared_ptr< SceneService > SceneServicePtr
Definition: scene_service.h:97
bool IsServiceReady() const
Definition: scene_service.h:43
std::shared_ptr< const SceneService > SceneServiceConstPtr
Definition: scene_service.h:98