Remove the final users of robot_state and joystick_state

This means we can remove them from the .q file.

Change-Id: Iefded3cf4537b2635341f3248c5f50af1534a241
diff --git a/aos/controls/BUILD b/aos/controls/BUILD
index 8c44823..30fe5c6 100644
--- a/aos/controls/BUILD
+++ b/aos/controls/BUILD
@@ -27,6 +27,7 @@
         "control_loop_test.h",
     ],
     deps = [
+        "//aos/events:shm-event-loop",
         "//aos/logging:queue_logging",
         "//aos/robot_state",
         "//aos/testing:googletest",
diff --git a/aos/controls/control_loop_test.h b/aos/controls/control_loop_test.h
index 66fb174..95f1c7d 100644
--- a/aos/controls/control_loop_test.h
+++ b/aos/controls/control_loop_test.h
@@ -5,6 +5,7 @@
 
 #include "gtest/gtest.h"
 
+#include "aos/events/shm-event-loop.h"
 #include "aos/logging/queue_logging.h"
 #include "aos/robot_state/robot_state.q.h"
 #include "aos/testing/test_shm.h"
@@ -22,17 +23,16 @@
 class ControlLoopTestTemplated : public TestBaseClass {
  public:
   ControlLoopTestTemplated() {
-    ::aos::joystick_state.Clear();
-    ::aos::robot_state.Clear();
+    robot_state_sender_ =
+        test_event_loop_.MakeSender<::aos::RobotState>(".aos.robot_state");
+    joystick_state_sender_ =
+        test_event_loop_.MakeSender<::aos::JoystickState>(".aos.joystick_state");
 
     ::aos::time::EnableMockTime(current_time_);
 
     SendMessages(false);
   }
   virtual ~ControlLoopTestTemplated() {
-    ::aos::joystick_state.Clear();
-    ::aos::robot_state.Clear();
-
     ::aos::time::DisableMockTime();
   }
 
@@ -44,7 +44,7 @@
     if (current_time_ >= kDSPacketTime + last_ds_time_ ||
         last_enabled_ != enabled) {
       last_ds_time_ = current_time_;
-      auto new_state = ::aos::joystick_state.MakeMessage();
+      auto new_state = joystick_state_sender_.MakeMessage();
       new_state->fake = true;
 
       new_state->enabled = enabled;
@@ -56,7 +56,7 @@
     }
 
     {
-      auto new_state = ::aos::robot_state.MakeMessage();
+      auto new_state = robot_state_sender_.MakeMessage();
 
       new_state->reader_pid = reader_pid_;
       new_state->outputs_enabled = enabled;
@@ -113,6 +113,11 @@
   ::aos::testing::TestSharedMemory my_shm_;
 
   bool last_enabled_ = false;
+
+  ::aos::ShmEventLoop test_event_loop_;
+
+  ::aos::Sender<::aos::RobotState> robot_state_sender_;
+  ::aos::Sender<::aos::JoystickState> joystick_state_sender_;
 };
 
 typedef ControlLoopTestTemplated<::testing::Test> ControlLoopTest;
diff --git a/aos/controls/replay_control_loop.h b/aos/controls/replay_control_loop.h
index d1436dd..1626c0a 100644
--- a/aos/controls/replay_control_loop.h
+++ b/aos/controls/replay_control_loop.h
@@ -33,10 +33,10 @@
     loop_group_->status.FetchLatest();
     loop_group_->output.FetchLatest();
 
-    replayer_.AddDirectQueueSender("wpilib_interface.DSReader",
-                                   "joystick_state", ::aos::joystick_state);
-    replayer_.AddDirectQueueSender("wpilib_interface.SensorReader",
-                                   "robot_state", ::aos::robot_state);
+    AddDirectQueueSender<::aos::JoystickState>(
+        "wpilib_interface.DSReader", "joystick_state", ".aos.joystick_state");
+    AddDirectQueueSender<::aos::RobotState>("wpilib_interface.SensorReader",
+                                            "robot_state", ".aos.robot_state");
 
     replayer_.AddHandler(
         process_name, "position",
@@ -49,14 +49,15 @@
         ::std::function<void(const StatusType &)>(::std::ref(status_)));
     // The timing of goal messages doesn't matter, and we don't need to look
     // back at them after running the loop.
-    replayer_.AddDirectQueueSender(process_name, "goal", loop_group_->goal);
+    AddDirectQueueSender<GoalType>(
+        process_name, "goal", ::std::string(loop_group_->name()) + ".goal");
   }
 
   template <class QT>
   void AddDirectQueueSender(const ::std::string &process_name,
                             const ::std::string &log_message,
-                            const ::aos::Queue<QT> &queue) {
-    replayer_.AddDirectQueueSender<QT>(process_name, log_message, queue);
+                            const ::std::string &name) {
+    replayer_.AddDirectQueueSender<QT>(process_name, log_message, name);
   }
 
   // Replays messages from a file.
@@ -93,6 +94,8 @@
   // Returns after going through the entire file.
   void DoProcessFile();
 
+  ::aos::ShmEventLoop event_loop_;
+
   T *const loop_group_;
 
   CaptureMessage<PositionType> position_;
diff --git a/aos/events/event-loop.h b/aos/events/event-loop.h
index 90eb721..c827c46 100644
--- a/aos/events/event-loop.h
+++ b/aos/events/event-loop.h
@@ -34,6 +34,8 @@
 template <typename T>
 class Sender {
  public:
+  typedef T Type;
+
   Sender() {}
 
   // Represents a single message about to be sent to the queue.
diff --git a/aos/logging/BUILD b/aos/logging/BUILD
index ebc03f6..49bb321 100644
--- a/aos/logging/BUILD
+++ b/aos/logging/BUILD
@@ -13,10 +13,10 @@
     visibility = ["//visibility:public"],
     deps = [
         ":sizes",
+        "//aos:complex_thread_local",
         "//aos:die",
         "//aos:macros",
         "//aos/libc:aos_strerror",
-        "//aos:complex_thread_local",
     ],
 )
 
@@ -33,6 +33,7 @@
         ":binary_log_file",
         ":logging",
         "//aos:queues",
+        "//aos/events:event-loop",
         "//aos/ipc_lib:queue",
     ],
 )
@@ -47,12 +48,12 @@
         ":binary_log_file",
         ":implementations",
         ":logging",
-        "//aos:die",
-        "//aos:queue_types",
-        "//aos/time:time",
         "//aos:configuration",
+        "//aos:die",
         "//aos:init",
+        "//aos:queue_types",
         "//aos/ipc_lib:queue",
+        "//aos/time",
     ],
 )
 
@@ -65,9 +66,9 @@
     deps = [
         ":implementations",
         ":logging",
-        "//aos/time:time",
         "//aos:init",
         "//aos/ipc_lib:queue",
+        "//aos/time",
     ],
 )
 
@@ -81,10 +82,10 @@
         ":binary_log_file",
         ":implementations",
         ":logging",
-        "//aos:queue_types",
-        "//aos/util:string_to_num",
         "//aos:configuration",
         "//aos:init",
+        "//aos:queue_types",
+        "//aos/util:string_to_num",
     ],
 )
 
@@ -182,13 +183,13 @@
     deps = [
         ":logging",
         ":sizes",
-        "//aos:once",
         "//aos:die",
         "//aos:macros",
-        "//aos/mutex:mutex",
+        "//aos:once",
         "//aos:queue_types",
-        "//aos/time:time",
-        "//aos/type_traits:type_traits",
         "//aos/ipc_lib:queue",
+        "//aos/mutex",
+        "//aos/time",
+        "//aos/type_traits",
     ],
 )
diff --git a/aos/logging/replay.h b/aos/logging/replay.h
index ffb3b7d..679b760 100644
--- a/aos/logging/replay.h
+++ b/aos/logging/replay.h
@@ -6,11 +6,12 @@
 #include <functional>
 #include <memory>
 
+#include "aos/events/event-loop.h"
+#include "aos/ipc_lib/queue.h"
 #include "aos/logging/binary_log_file.h"
-#include "aos/queue.h"
 #include "aos/logging/logging.h"
 #include "aos/macros.h"
-#include "aos/ipc_lib/queue.h"
+#include "aos/queue.h"
 #include "aos/queue_types.h"
 
 namespace aos {
@@ -68,10 +69,10 @@
   template <class T>
   void AddDirectQueueSender(const ::std::string &process_name,
                             const ::std::string &log_message,
-                            const ::aos::Queue<T> &queue) {
+                            const ::std::string &name) {
     AddHandler(process_name, log_message,
                ::std::function<void(const T &)>(
-                   QueueDumpStructHandler<T>(queue.name())));
+                   QueueDumpStructHandler<T>(name.c_str())));
   }
 
  private:
diff --git a/aos/queue-tmpl.h b/aos/queue-tmpl.h
index 1362515..2ca79b8 100644
--- a/aos/queue-tmpl.h
+++ b/aos/queue-tmpl.h
@@ -11,16 +11,6 @@
 }
 
 template <class T>
-bool ScopedMessagePtr<T>::SendBlocking() {
-  assert(msg_ != NULL);
-  msg_->SetTimeToNow();
-  assert(queue_ != NULL);
-  bool return_value = queue_->WriteMessage(msg_, RawQueue::kBlock);
-  msg_ = NULL;
-  return return_value;
-}
-
-template <class T>
 void ScopedMessagePtr<T>::reset(T *msg) {
   if (queue_ != NULL && msg_ != NULL) {
     queue_->FreeMessage(msg_);
diff --git a/aos/queue.h b/aos/queue.h
index 47540f6..fb11f4f 100644
--- a/aos/queue.h
+++ b/aos/queue.h
@@ -58,12 +58,6 @@
   // The message will be freed.
   bool Send();
 
-  // Sends the message and removes our reference to it.
-  // If the queue is full, block until it is no longer full.
-  // Returns true on success, and false otherwise.
-  // The message will be freed.
-  bool SendBlocking();
-
   // Frees the contained message.
   ~ScopedMessagePtr() {
     reset();
diff --git a/aos/robot_state/robot_state.q b/aos/robot_state/robot_state.q
index 7eb10f5..e482c5d 100644
--- a/aos/robot_state/robot_state.q
+++ b/aos/robot_state/robot_state.q
@@ -11,6 +11,8 @@
   int32_t pov;
 };
 
+// This message is checked by all control loops to make sure that the
+// joystick code hasn't died.  It is published on ".aos.joystick_state"
 message JoystickState {
   Joystick[6] joysticks;
 
@@ -34,10 +36,10 @@
   bool fake;
 };
 
-// This queue is checked by all control loops to make sure that the
-// joystick code hasn't died.
-queue JoystickState joystick_state;
-
+// This message is sent out on this queue when sensors are read. It contains
+// global robot state and information about whether the process reading sensors
+// has been restarted, along with all counters etc it keeps track of.  It is
+// published on ".aos.robot_state"
 message RobotState {
   // The PID of the process reading sensors.
   // This is here so control loops can tell when it changes.
@@ -66,7 +68,3 @@
   double voltage_battery;
 };
 
-// Messages are sent out on this queue along with reading sensors. It contains
-// global robot state and information about whether the process reading sensors
-// has been restarted, along with all counters etc it keeps track of.
-queue RobotState robot_state;