Esempio n. 1
0
  /**
   * Try to find and delete the notification by the given notifId, and then send dismiss
   * session-less-signal
   *
   * @param notifId
   */
  public void dismiss(int notifId) {
    GenericLogger logger = nativePlatform.getNativeLogger();
    Transport transport = Transport.getInstance();

    logger.debug(
        TAG,
        "Dismiss method has been called, trying to find and delete the notification by its id: '"
            + notifId
            + "'");
    deleteNotificationById(notifId);

    // Sending dismiss signal
    try {
      UUID appId = transport.getAppId(transport.readAllProperties());
      DismissEmitter.send(notifId, appId);
    } catch (NotificationServiceException nse) {
      logger.error(
          TAG,
          "Unable to send the Dismiss signal for notifId: '"
              + notifId
              + "', Error: '"
              + nse.getMessage()
              + "'");
    }
  } // dismiss
  /**
   * This method will be called by the AJ bus when a notification is received
   *
   * @see org.alljoyn.ns.transport.interfaces.NotificationTransport#notify(int, int, short, String,
   *     String, byte[], String, Map, Map, TransportNotificationText[])
   */
  @Override
  public void notify(
      int version,
      int msgId,
      short messageType,
      String deviceId,
      String deviceName,
      byte[] appId,
      String appName,
      Map<Integer, Variant> attributes,
      Map<String, String> customAttributes,
      TransportNotificationText[] text) {

    Transport transport = Transport.getInstance();
    BusAttachment busAttachment = transport.getBusAttachment();
    busAttachment.enableConcurrentCallbacks();

    try {

      GenericLogger logger = NativePlatformFactory.getPlatformObject().getNativeLogger();

      try {
        String sender = busAttachment.getMessageContext().sender;
        logger.debug(
            TAG,
            "Received notification from: '"
                + sender
                + "' by '"
                + servicePath
                + "' object, notification id: '"
                + msgId
                + "', handling");

        logger.debug(
            TAG, "Forwarding the received notification id: '" + msgId + "' to PayloadAdapter");
        PayloadAdapter.receivePayload(
            version,
            msgId,
            sender,
            messageType,
            deviceId,
            deviceName,
            appId,
            appName,
            attributes,
            customAttributes,
            text);
      } catch (NotificationServiceException nse) {
        logger.error(TAG, "Failed to read the received notification, Error: " + nse.getMessage());
      }
    } catch (NativePlatformFactoryException npfe) {
      System.out.println(TAG + ": Unexpected error occured: " + npfe.getMessage());
    }
  } // notify
Esempio n. 3
0
  /**
   * Starts the service in the Notification Sender mode
   *
   * @throws NotificationServiceException Is thrown if failed to start the SenderTransport
   */
  public void startSenderTransport() throws NotificationServiceException {

    GenericLogger logger = nativePlatform.getNativeLogger();
    BusAttachment busAttachment = Transport.getInstance().getBusAttachment();

    logger.debug(TAG, "Starting a sender transport");

    // Creating transportChannel objects
    transportSenderChannels =
        new EnumMap<NotificationMessageType, TransportChannelObject>(NotificationMessageType.class);
    try {
      for (NotificationMessageType messageType : NotificationMessageType.values()) {
        transportSenderChannels.put(
            messageType, new TransportChannelObject(messageType, busAttachment, nativePlatform));
      }
    } catch (NotificationServiceException nse) {
      logger.error(TAG, nse.getMessage());
      throw nse;
    }

    // Initialize the NotificationProducer BusObject
    notifProducerBusObj = new NotificationProducerImpl(this, nativePlatform);
    notifProducerBusObj.init();

    // Create session listener to be ready to handle incoming connections
    sessionListener = new SenderSessionListener(nativePlatform);
    sessionListener.init();

    // //Send the Announce signal with all the NotificationService related
    // BusObjectDescription objects
    // if ( aboutObj != null ) {
    // aboutObj.announce();
    // }
  } // startSenderTransport
Esempio n. 4
0
  /** SenderTransport cleanups */
  public void stopSenderTransport() {

    GenericLogger logger = nativePlatform.getNativeLogger();
    BusAttachment busAttachment = Transport.getInstance().getBusAttachment();
    logger.debug(TAG, "Stopping SenderTransport");

    if (transportSenderChannels != null) {
      for (NotificationMessageType pr : transportSenderChannels.keySet()) {
        transportSenderChannels.get(pr).clean(busAttachment);
      }

      transportSenderChannels = null;
    }

    if (sessionListener != null) {
      sessionListener.clean();
      sessionListener = null;
    }

    if (notifProducerBusObj != null) {
      notifProducerBusObj.clean();
      notifProducerBusObj = null;
    }

    // if ( aboutObj != null ) {
    // //Send the Announce signal after removing NotificationService related
    // BusObjectDescription objects
    // aboutObj.announce();
    // }
  } // stopSenderTransport