Ejemplo n.º 1
0
  /**
   * Starts {@link ControlPanelService} which discovers controllable devices in its proximity. <br>
   * The ControlPanelService user is informed about the devices in proximity via the {@link
   * DeviceRegistry} interface. <br>
   * The discovery mechanism is implemented by receiving Announcement signals. <br>
   *
   * @param bus BusAttachment that the service should use
   * @param deviceRegistry Holds the information about the devices in proximity<br>
   *     {@link DefaultDeviceRegistry} may be passed in to receive information about the devices
   * @throws ControlPanelException if failed to initialize the control panel service
   */
  public void init(BusAttachment bus, DeviceRegistry deviceRegistry) throws ControlPanelException {
    if (deviceRegistry == null) {
      throw new ControlPanelException("deviceRegistry can't be NULL");
    }

    AboutService aboutService = AboutServiceImpl.getInstance();
    if (!aboutService.isClientRunning()) {
      throw new ControlPanelException(
          "The AboutService is not running, impossible to receive Announcement signals");
    }

    // Perform the basic service initialization
    init(bus);

    this.deviceRegistry = deviceRegistry;

    Log.d(TAG, "Start listening for Announcement signals");
    connMgr.registerEventListener(ConnManagerEventType.ANNOUNCEMENT_RECEIVED, this);

    // Add an announcement handler
    announcementReceiver = new AnnouncementReceiver();
    for (String iface : ANNOUNCEMENT_IFACES) {
      aboutService.addAnnouncementHandler(announcementReceiver, new String[] {iface});
    }
  } // init
Ejemplo n.º 2
0
  /** Shutdown the {@link ControlPanelService} */
  public void shutdown() {
    Log.d(TAG, "Shutdown ControlPanelService");

    if (announcementReceiver != null) {

      AboutService aboutService = AboutServiceImpl.getInstance();
      for (String iface : ANNOUNCEMENT_IFACES) {
        aboutService.removeAnnouncementHandler(announcementReceiver, new String[] {iface});
      }
    }

    if (deviceRegistry != null) {
      Log.d(TAG, "Clear devices registry");
      for (ControllableDevice device : deviceRegistry.getDevices().values()) {
        stopControllableDevice(device);
      }
      deviceRegistry = null;
    }

    TaskManager taskManager = TaskManager.getInstance();
    if (taskManager.isRunning()) {
      taskManager.shutdown();
    }

    connMgr.shutdown();
  } // shutdown