priority_mux.h
Go to the documentation of this file.
1 #pragma once
2 
11 #include <list>
12 #include <map>
13 #include <string>
14 #include <unordered_map>
15 #include <utility>
16 
17 #include <std_msgs/Bool.h>
18 #include <topic_tools/shape_shifter.h>
19 
21 
22 namespace cras
23 {
24 
25 namespace priority_mux
26 {
27 
28 static const ::std::string NONE_TOPIC = "__none"; // NOLINT
29 
31 {
32  ::std::string name;
33  ::std::string inTopic;
34  ::std::string outTopic;
35  int priority{0};
37  size_t queueSize{0u};
38 };
39 
40 struct LockConfig
41 {
42  ::std::string name;
43  ::std::string topic;
44  int priority{0};
46  size_t queueSize{0u};
47 };
48 
49 }
50 
52 {
53 protected:
54  void onInit() override;
55 
56  virtual void cb(const ::ros::MessageEvent<::topic_tools::ShapeShifter const>& event, const ::std::string& inTopic);
57  virtual void lockCb(const ::std::string& topic, const ::std_msgs::BoolConstPtr& msg);
58  virtual void updatePriorities(int newPriority, const ::std::string& newTopic);
59 
60  void publishPriorityChange(int newPriority, const ::ros::Duration& timeout);
61  void publishSelectedTopicChange(const ::std::string& outTopic, const ::std::string& newTopic,
62  const ::ros::Duration& timeout);
63  void onPriorityTimeout(const ::ros::TimerEvent&);
64  void onSelectedTopicTimeout(const ::std::string& outTopic, const ::ros::TimerEvent&);
65  void onLockTimeout(const ::std::string& topic, const ::ros::TimerEvent&);
66 
67  ::std::list<::ros::Subscriber> subscribers;
68  ::std::unordered_map<::std::string, ::ros::Publisher> publishers;
70  ::std::unordered_map<::std::string, ::ros::Publisher> selectedPublishers;
71  ::std::unordered_map<::std::string, ::ros::Publisher> lockedPublishers;
72 
74  ::std::unordered_map<::std::string, ::ros::Timer> selectedBackToNoneTimers;
75  ::std::unordered_map<::std::string, ::ros::Timer> lockTimeoutTimers;
76 
77  ::std::unordered_map<::std::string, ::cras::priority_mux::TopicConfig> topicConfigs;
78  ::std::unordered_map<::std::string, ::cras::priority_mux::LockConfig> lockConfigs;
79 
80  ::std::map<::std::pair<int, ::std::string>, ::ros::Time> lastReceiveStamps;
81  ::std::map<::std::pair<int, ::std::string>, ::ros::Time> lastLockStamps;
82 
83  size_t outQueueSize {10u};
84  int priorityNone {0};
85  int lastActivePriority {0};
86  ::std::unordered_map<::std::string, ::std::string> lastSelectedTopics;
87 };
88 
89 }
msg
::std::unordered_map<::std::string, ::ros::Publisher > lockedPublishers
Definition: priority_mux.h:71
::ros::Timer priorityBackToNoneTimer
Definition: priority_mux.h:73
::std::unordered_map<::std::string, ::ros::Publisher > publishers
Definition: priority_mux.h:68
::std::map<::std::pair< int, ::std::string >, ::ros::Time > lastLockStamps
Definition: priority_mux.h:81
::ros::Publisher activePriorityPub
Definition: priority_mux.h:69
::std::map<::std::pair< int, ::std::string >, ::ros::Time > lastReceiveStamps
Definition: priority_mux.h:80
::std::list<::ros::Subscriber > subscribers
Definition: priority_mux.h:67
::std::unordered_map<::std::string, ::cras::priority_mux::TopicConfig > topicConfigs
Definition: priority_mux.h:77
::std::unordered_map<::std::string, ::std::string > lastSelectedTopics
Definition: priority_mux.h:86
::std::unordered_map<::std::string, ::ros::Timer > selectedBackToNoneTimers
Definition: priority_mux.h:74
::std::unordered_map<::std::string, ::ros::Publisher > selectedPublishers
Definition: priority_mux.h:70
::std::unordered_map<::std::string, ::ros::Timer > lockTimeoutTimers
Definition: priority_mux.h:75
::std::unordered_map<::std::string, ::cras::priority_mux::LockConfig > lockConfigs
Definition: priority_mux.h:78
static const ::std::string NONE_TOPIC
Definition: priority_mux.h:28


cras_topic_tools
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:33:13