Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
  /**
   * 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
Exemplo n.º 5
0
  /**
   * Called when we need to send a signal
   *
   * @param version The version of the message signature
   * @param msgId notification Id the id of the sent signal
   * @param messageType The message type of the sent message
   * @param deviceId Device id
   * @param deviceName Device name
   * @param appId App id
   * @param appName App name
   * @param attributes All the notification metadata
   * @param customAttributes The customAttributes
   * @param text Array of texts to be sent
   * @param ttl Notification message TTL
   * @throws NotificationServiceException
   */
  public void sendNotification(
      int version,
      int msgId,
      NotificationMessageType messageType,
      String deviceId,
      String deviceName,
      byte[] appId,
      String appName,
      Map<Integer, Variant> attributes,
      Map<String, String> customAttributes,
      TransportNotificationText[] text,
      int ttl)
      throws NotificationServiceException {

    GenericLogger logger = nativePlatform.getNativeLogger();

    if (stopSending) {
      logger.debug(TAG, "In stopSending mode NOT sending notification!!!");
      return;
    }

    TransportChannelObject senderChannel = transportSenderChannels.get(messageType);
    if (senderChannel == null) {
      throw new NotificationServiceException(
          "Received an unknown message type: '"
              + messageType
              + "', can't find a transport channel to send the notification");
    }

    // send this notification to the correct object based on messageType
    senderChannel.sendNotification(
        version,
        msgId,
        messageType.getTypeId(),
        deviceId,
        deviceName,
        appId,
        appName,
        attributes,
        customAttributes,
        text,
        ttl);
  } // sendNotification
Exemplo n.º 6
0
  /** @param notifId The notification id of the notification message to be deleted */
  private void deleteNotificationById(int notifId) {

    GenericLogger logger = nativePlatform.getNativeLogger();
    logger.debug(
        TAG,
        "Trying to delete the notification by id: '"
            + notifId
            + "', searching for the relevant object");

    boolean isObjFound = false;

    for (TransportChannelObject channelObj : transportSenderChannels.values()) {

      channelObj.acquireLock(); // Lock the object to prevent changing its
      // state

      Integer chanObjNotifId = channelObj.getNotificationId();

      if (chanObjNotifId != null && chanObjNotifId == notifId) { // Found
        // the
        // object
        // to be
        // cancelled
        logger.debug(TAG, "Found the object with notifId: '" + notifId + "' to be cancelled");
        channelObj.deleteNotification();
        isObjFound = true;
        channelObj.releaseLock(); // release the lock
        break;
      } else {
        channelObj.releaseLock(); // release the lock and continue
        // iterating
      }
    }

    if (!isObjFound) {
      logger.debug(TAG, "Failed to find the Notification with Id: '" + notifId + "'");
    }
  }