com.qualcomm.robotcore.eventloop

## Class EventLoopManager

- java.lang.Object
- - com.qualcomm.robotcore.eventloop.EventLoopManager

- All Implemented Interfaces:
    SyncdDevice.Manager

      public class EventLoopManager
      extends java.lang.Object
      implements SyncdDevice.Manager

  Event Loop Manager

  Takes RobocolDatagram messages, converts them into the appropriate data type, and then passes it to the current EventLoop.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `EventLoopManager.EventLoopMonitor` Callback to monitor when event loop changes state

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `isPeerConnected`
    `static java.lang.String` | `RC_BATTERY_STATUS_KEY`
    `static java.lang.String` | `ROBOT_BATTERY_LEVEL_KEY`
    `RobotState` | `state`
    `static java.lang.String` | `SYSTEM_ERROR_KEY`
    `static java.lang.String` | `SYSTEM_NONE_KEY`
    `static java.lang.String` | `SYSTEM_WARNING_KEY`
    `static java.lang.String` | `TAG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EventLoopManager(Context context, EventLoopManagerClient eventLoopManagerClient, EventLoop idleEventLoop)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `buildAndSendTelemetry(java.lang.String tag, java.lang.String msg)`
    `void` | `close()`
    `CallbackResult` | `commandEvent(Command command)`
    `CallbackResult` | `emptyEvent(RobocolDatagram packet)`
    `CallbackResult` | `gamepadEvent(RobocolDatagram packet)`
    `EventLoop` | `getEventLoop()` Get the current event loop
    `Gamepad` | `getGamepad(int port)` Get the gamepad connected to a particular user
    `Gamepad[]` | `getGamepads()` Get the gamepads
    `Heartbeat` | `getHeartbeat()` Get the current heartbeat state
    `EventLoopManager.EventLoopMonitor` | `getMonitor()` return any event loop monitor previously set
    `WebServer` | `getWebServer()`
    `CallbackResult` | `heartbeatEvent(RobocolDatagram packet, long tReceived)`
    `CallbackResult` | `onNetworkConnectionEvent(NetworkConnection.NetworkEvent event)`
    `CallbackResult` | `packetReceived(RobocolDatagram packet)`
    `void` | `peerConnected(boolean peerLikelyChanged)`
    `void` | `peerDisconnected()`
    `CallbackResult` | `peerDiscoveryEvent(RobocolDatagram packet)`
    `void` | `refreshSystemTelemetry()` Do our best to maintain synchrony of the system error / warning state between applications without incurring undo overhead.
    `void` | `refreshSystemTelemetryNow()` Forces an immediate refresh of the system telemetry
    `void` | `registerSyncdDevice(SyncdDevice device)` Register a sync'd device
    `CallbackResult` | `reportGlobalError(java.lang.String error, boolean recoverable)`
    `void` | `sendTelemetryData(TelemetryMessage telemetry)` Send telemetry data
    `void` | `setEventLoop(EventLoop eventLoop)` Replace the current event loop with a new event loop
    `void` | `setMonitor(EventLoopManager.EventLoopMonitor monitor)` Set a monitor for this event loop
    `void` | `shutdown()` Performs the logical inverse of `start(EventLoop)`.
    `void` | `start(EventLoop eventLoop)` Starts up the `EventLoopManager`.
    `CallbackResult` | `telemetryEvent(RobocolDatagram packet)`
    `void` | `unregisterSyncdDevice(SyncdDevice device)` Unregisters a device from this event loop.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TAG

          public static final java.lang.String TAG

      See Also:
        Constant Field Values

    - #### SYSTEM_NONE_KEY

          public static final java.lang.String SYSTEM_NONE_KEY

      See Also:
        Constant Field Values

    - #### SYSTEM_ERROR_KEY

          public static final java.lang.String SYSTEM_ERROR_KEY

      See Also:
        Constant Field Values

    - #### SYSTEM_WARNING_KEY

          public static final java.lang.String SYSTEM_WARNING_KEY

      See Also:
        Constant Field Values

    - #### ROBOT_BATTERY_LEVEL_KEY

          public static final java.lang.String ROBOT_BATTERY_LEVEL_KEY

      See Also:
        Constant Field Values

    - #### RC_BATTERY_STATUS_KEY

          public static final java.lang.String RC_BATTERY_STATUS_KEY

      See Also:
        Constant Field Values

    - #### state

          public RobotState state

    - #### isPeerConnected

          protected boolean isPeerConnected

  - ### Constructor Detail

    - #### EventLoopManager

          public EventLoopManager(Context context,
                                  EventLoopManagerClient eventLoopManagerClient,
                                  EventLoop idleEventLoop)

      Constructor

  - ### Method Detail

    - #### getWebServer

          public WebServer getWebServer()

    - #### setMonitor

          public void setMonitor(EventLoopManager.EventLoopMonitor monitor)

      Set a monitor for this event loop
      Parameters:
        `monitor` - event loop monitor

    - #### getMonitor

          public EventLoopManager.EventLoopMonitor getMonitor()

      return any event loop monitor previously set

    - #### getEventLoop

          public EventLoop getEventLoop()

      Get the current event loop
      Returns:
        current event loop

    - #### getGamepad

          public Gamepad getGamepad(int port)

      Get the gamepad connected to a particular user
      Parameters:
        `port` - user 0 and 1 are valid
      Returns:
        gamepad

    - #### getGamepads

          public Gamepad[] getGamepads()

      Get the gamepads

      Array index will match the user number

      Returns:
        gamepad

    - #### getHeartbeat

          public Heartbeat getHeartbeat()

      Get the current heartbeat state
      Returns:
        heartbeat

    - #### telemetryEvent

          public CallbackResult telemetryEvent(RobocolDatagram packet)

    - #### reportGlobalError

          public CallbackResult reportGlobalError(java.lang.String error,
                                                  boolean recoverable)

    - #### packetReceived

          public CallbackResult packetReceived(RobocolDatagram packet)

    - #### refreshSystemTelemetryNow

          public void refreshSystemTelemetryNow()

      Forces an immediate refresh of the system telemetry

    - #### refreshSystemTelemetry

          public void refreshSystemTelemetry()

      Do our best to maintain synchrony of the system error / warning state between applications without incurring undo overhead.

    - #### onNetworkConnectionEvent

          public CallbackResult onNetworkConnectionEvent(NetworkConnection.NetworkEvent event)

    - #### start

          public void start(EventLoop eventLoop)
                     throws RobotCoreException

      Starts up the `EventLoopManager`. This mostly involves setting up the network connections and listeners and senders, then getting the event loop thread going. Note that shutting down the `EventLoopManager` does not do a full complete inverse. Rather, it leaves the underlying network connection alive and running, as this, among other things, helps remote toasts to continue to function correctly. Thus, we must be aware of that possibility here as we start.
      Throws:
        `RobotCoreException`
      See Also:
        `shutdown()`

    - #### shutdown

          public void shutdown()

      Performs the logical inverse of `start(EventLoop)`.
      See Also:
        `start(EventLoop)`

    - #### close

          public void close()

    - #### registerSyncdDevice

          public void registerSyncdDevice(SyncdDevice device)

      Register a sync'd device
      Specified by:
        `registerSyncdDevice` in interface `SyncdDevice.Manager`
      Parameters:
        `device` - sync'd device
      See Also:
        `unregisterSyncdDevice(SyncdDevice)`

    - #### unregisterSyncdDevice

          public void unregisterSyncdDevice(SyncdDevice device)

      Unregisters a device from this event loop. It is specifically permitted to unregister a device which is not currently registered; such an operation has no effect.
      Specified by:
        `unregisterSyncdDevice` in interface `SyncdDevice.Manager`
      Parameters:
        `device` - the device to be unregistered. May not be null.
      See Also:
        `registerSyncdDevice(SyncdDevice)`

    - #### setEventLoop

          public void setEventLoop(EventLoop eventLoop)
                            throws RobotCoreException

      Replace the current event loop with a new event loop
      Parameters:
        `eventLoop` - new event loop
      Throws:
        `RobotCoreException` - if event loop fails to init

    - #### sendTelemetryData

          public void sendTelemetryData(TelemetryMessage telemetry)

      Send telemetry data

      Send the telemetry data, and then clear the sent data

      Parameters:
        `telemetry` - telemetry data

    - #### gamepadEvent

          public CallbackResult gamepadEvent(RobocolDatagram packet)
                                      throws RobotCoreException

      Throws:
        `RobotCoreException`

    - #### heartbeatEvent

          public CallbackResult heartbeatEvent(RobocolDatagram packet,
                                               long tReceived)
                                        throws RobotCoreException

      Throws:
        `RobotCoreException`

    - #### peerConnected

          public void peerConnected(boolean peerLikelyChanged)

    - #### peerDisconnected

          public void peerDisconnected()

    - #### peerDiscoveryEvent

          public CallbackResult peerDiscoveryEvent(RobocolDatagram packet)
                                            throws RobotCoreException

      Throws:
        `RobotCoreException`

    - #### commandEvent

          public CallbackResult commandEvent(Command command)
                                      throws RobotCoreException

      Throws:
        `RobotCoreException`

    - #### emptyEvent

          public CallbackResult emptyEvent(RobocolDatagram packet)

    - #### buildAndSendTelemetry

          public void buildAndSendTelemetry(java.lang.String tag,
                                            java.lang.String msg)