Ejemplo n.º 1
0
static void
port_status( uint64_t datapath_id, uint32_t transaction_id, uint8_t reason,
             struct ofp_phy_port phy_port, void *user_data ) {
  UNUSED( transaction_id );
  UNUSED( user_data );

  sw_entry *sw = lookup_sw_entry( &datapath_id );
  if ( sw == NULL ) {
    warn( "Received port-status, but switch(%#" PRIx64 ") is not found.", datapath_id );
    return;
  }
  port_entry *port = lookup_port_entry( sw, phy_port.port_no, phy_port.name );
  switch ( reason ) {
    case OFPPR_ADD:
      if ( port != NULL ) {
        warn( "Failed to add port(%u, `%s'), switch(%#" PRIx64 ").",
              phy_port.port_no, phy_port.name, datapath_id );
        return;
      }
      add_notification( sw, &phy_port );
      break;

    case OFPPR_DELETE:
      if ( port == NULL ) {
        warn( "Failed to delete port(%u, `%s'), switch(%#" PRIx64 ").",
              phy_port.port_no, phy_port.name, datapath_id );
        return;
      }
      delete_notification( sw, port );
      break;

    case OFPPR_MODIFY:
      if ( port == NULL ) {
        warn( "Failed to modify port(%u, `%s'), switch(%#" PRIx64 ").",
              phy_port.port_no, phy_port.name, datapath_id );
        return;
      }
      if ( port->port_no != phy_port.port_no ) {
        delete_notification( sw, port );
        add_notification( sw, &phy_port );
      } else {
        update_notification( sw, port, &phy_port );
      }
      break;
    default:
      warn( "Failed to handle port status: unknown reason(%u) from switch(%#" PRIx64 ").",
            reason, datapath_id );
      return;
  }
}
Ejemplo n.º 2
0
/*!	Notifies all interested listeners of this transaction about the \a event.
	If \a event is a closing event (ie. TRANSACTION_ENDED, and
	TRANSACTION_ABORTED), all listeners except those listening to
	TRANSACTION_WRITTEN will be removed.
*/
static void
notify_transaction_listeners(block_cache* cache, cache_transaction* transaction,
	int32_t event)
{
	bool isClosing = is_closing_event(event);
	bool isWritten = is_written_event(event);

	ListenerList::Iterator iterator = transaction->listeners.GetIterator();
	while (iterator.HasNext()) {
		cache_listener* listener = iterator.Next();

		bool remove = (isClosing && !is_written_event(listener->events))
			|| (isWritten && is_written_event(listener->events));
		if (remove)
			iterator.Remove();

		if ((listener->events & event) != 0)
			add_notification(cache, listener, event, remove);
		else if (remove)
			delete_notification(listener);
	}

	// This must work asynchronously in the kernel, but since we're not using
	// most transaction events, we can do it here.
	flush_pending_notifications(cache);
}
static void bt_handler(bool connected)
{
    if (!connected)
    {
        static char text[] = "Bluetooth Disconnected\0\0Your pebble has been disconnected from the phone.";
        static uint8_t textSize = sizeof(text) / sizeof(char);

        //Find empty notification ID
        int32_t id = 0;
        while (find_notification(id) != NULL)
            id++;

        Notification* notification = add_notification(textSize - 1);
        notification->id = id;
        notification->inList = false;
        notification->scrollToEnd = false;
        notification->showMenuOnSelectPress = false;
        notification->showMenuOnSelectHold = false;
        notification->shakeAction = 0;
        notification->numOfActionsInDefaultMenu = 0;
        notification->subtitleStart = 9999;
        notification->bodyStart = 24;
        notification->fontTitle = 7;
        notification->fontSubtitle = 4;
        notification->fontBody = 4;
        notification->onlyDismissable = true;
        notification->currentTextLength = textSize - 1;
        memcpy(notification->text, text, textSize);

        #ifdef PBL_COLOR
            notification->notificationColor = GColorBlack;
        #endif

        nw_switch_to_notification(numOfNotifications - 1);
        vibes_double_pulse();
    }
}
Ejemplo n.º 4
0
/* Handler for sending outgoing message; called by transport manager. */
static pj_status_t loop_send_msg( pjsip_transport *tp, 
				  pjsip_tx_data *tdata,
				  const pj_sockaddr_t *rem_addr,
				  int addr_len,
				  void *token,
				  void (*cb)(pjsip_transport *transport,
					     void *token, 
					     pj_ssize_t sent_bytes))
{
    struct loop_transport *loop = (struct loop_transport*)tp;
    struct recv_list *recv_pkt;
    
    PJ_ASSERT_RETURN(tp && (tp->key.type == PJSIP_TRANSPORT_LOOP ||
	             tp->key.type == PJSIP_TRANSPORT_LOOP_DGRAM), PJ_EINVAL);

    PJ_UNUSED_ARG(rem_addr);
    PJ_UNUSED_ARG(addr_len);


    /* Need to send failure? */
    if (loop->fail_mode) {
	if (loop->send_delay == 0) {
	    return PJ_STATUS_FROM_OS(OSERR_ECONNRESET);
	} else {
	    add_notification(loop, tdata, -PJ_STATUS_FROM_OS(OSERR_ECONNRESET),
			     token, cb);

	    return PJ_EPENDING;
	}
    }

    /* Discard any packets? */
    if (loop->discard)
	return PJ_SUCCESS;

    /* Create rdata for the "incoming" packet. */
    recv_pkt = create_incoming_packet(loop, tdata);
    if (!recv_pkt)
	return PJ_ENOMEM;

    /* If delay is not configured, deliver this packet now! */
    if (loop->recv_delay == 0) {
	pj_ssize_t size_eaten;

	size_eaten = pjsip_tpmgr_receive_packet( loop->base.tpmgr, 
						 &recv_pkt->rdata);
	pj_assert(size_eaten == recv_pkt->rdata.pkt_info.len);

	pjsip_endpt_release_pool(loop->base.endpt, 
				 recv_pkt->rdata.tp_info.pool);

    } else {
	/* Otherwise if delay is configured, add the "packet" to the 
	 * receive list to be processed by worker thread.
	 */
	pj_lock_acquire(loop->base.lock);
	pj_list_push_back(&loop->recv_list, recv_pkt);
	pj_lock_release(loop->base.lock);
    }

    if (loop->send_delay != 0) {
	add_notification(loop, tdata, tdata->buf.cur - tdata->buf.start,
			 token, cb);
	return PJ_EPENDING;
    } else {
	return PJ_SUCCESS;
    }
}