Beispiel #1
0
bool is_cylinder_used(struct dive *dive, int idx)
{
	struct divecomputer *dc;
	bool firstGasExplicit = false;
	if (cylinder_none(&dive->cylinder[idx]))
		return false;

	if ((dive->cylinder[idx].start.mbar - dive->cylinder[idx].end.mbar) > SOME_GAS)
		return true;
	for_each_dc(dive, dc) {
		struct event *event = get_next_event(dc->events, "gaschange");
		while (event) {
			if (dc->sample && (event->time.seconds == 0 ||
					   (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
				firstGasExplicit = true;
			if (get_cylinder_index(dive, event) == idx)
				return true;
			event = get_next_event(event->next, "gaschange");
		}
		if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
			return true;
	}
	if (idx == 0 && !firstGasExplicit)
		return true;
	return false;
}
int SquiggleRead::get_closest_event_to(int k_idx, uint32_t strand) const
{
    int stop_before = std::max(0, k_idx - 1000);
    int stop_after = std::min(k_idx + 1000, (int32_t)read_sequence.size() - K + 1);
    
    int event_before = get_next_event(k_idx, stop_before, -1, strand);
    int event_after = get_next_event(k_idx, stop_after, 1, strand);

    // TODO: better selection of "best" event to return
    if(event_before == -1)
        return event_after;
    return event_before;
}
static void configure_next_event()
{
    //this function should only be called from an atomic context
	timer_tick_t next_fire_time;
    do
    {
		//find the next event that has not yet passed, and schedule
		//the 'late' events while we're at it
		NG(next_event) = get_next_event();

		if(NG(next_event) != NO_EVENT)
		{
			next_fire_time = NG(timers)[NG(next_event)].next_event;
			if ( (((int32_t)next_fire_time) - ((int32_t)timer_get_counter_value())) <= 0 )
			{
				sched_post_task_prio(NG(timers)[NG(next_event)].f, NG(timers)[NG(next_event)].priority);
				NG(timers)[NG(next_event)].f = 0x0;
			}
		}
    }
    while(NG(next_event) != NO_EVENT && ( (((int32_t)next_fire_time) - ((int32_t)timer_get_counter_value())) <= 0  ) );

    //at this point NG(next_event) is eiter equal to NO_EVENT (no tasks left)
    //or we have the next event we can schedule
    if(NG(next_event) == NO_EVENT)
    {
		//cancel the timer in case it is still running (can happen if we're called from timer_cancel_event)
		NG(hw_event_scheduled) = false;
		hw_timer_cancel(HW_TIMER_ID);
    }
    else
    {
		//calculate schedule time relative to current time rather than
		//latest overflow time, to counteract any delays in updating counter_offset
		//(eg when we're scheduling an event from an interrupt and thereby delaying
		//the updating of counter_offset)
    	timer_tick_t fire_delay = (next_fire_time - timer_get_counter_value());
		//if the timer should fire in less ticks than supported by the HW timer --> schedule it
		//(otherwise it is scheduled from timer_overflow when needed)
		if(fire_delay < COUNTER_OVERFLOW_INCREASE)
		{
			NG(hw_event_scheduled) = true;
			hw_timer_schedule_delay(HW_TIMER_ID, (hwtimer_tick_t)fire_delay);
#ifndef NDEBUG	    
			//check that we didn't try to schedule a timer in the past
			//normally this shouldn't happen but it IS theoretically possible...
			fire_delay = (next_fire_time - timer_get_counter_value());
			//fire_delay should be in [0,COUNTER_OVERFLOW_INCREASE]. if this is not the case, it is because timer_get_counter() is
			//now larger than next_fire_event, which means we 'missed' the event
			assert(((int32_t)fire_delay) > 0);
#endif
		}
		else
		{
			//set hw_event_scheduled explicitly to false to allow timer_overflow
			//to schedule the event when needed
			NG(hw_event_scheduled) = false;
		}
    }
}
Beispiel #4
0
        boost::shared_ptr<receiver> accept(
            Parcelport & parcelport, util::memory_chunk_pool & pool, boost::system::error_code &ec)
        {
            boost::shared_ptr<receiver> rcv;
            rdma_cm_event event;
            if(!get_next_event(event_channel_, event, this, ec))
            {
                return rcv;
            }

            if(event.event == RDMA_CM_EVENT_CONNECT_REQUEST)
            {
                rdma_conn_param cm_params;
                std::memset(&cm_params, 0, sizeof(rdma_conn_param));
                cm_params.initiator_depth = cm_params.responder_resources = 1;
                cm_params.rnr_retry_count = 7; // infinite retry

                rcv.reset(new receiver(parcelport, pool));
                rcv->context().build_connection(parcelport, event.id, ec);
                if(ec)
                {
                    rcv.reset();
                    return rcv;
                }

                rcv->context().on_preconnect(event.id, ec);
                if(ec)
                {
                    rcv.reset();
                    return rcv;
                }

                rdma_accept(event.id, &cm_params);
                pending_recv_list.push_back(std::make_pair(event, rcv));
                rcv.reset();
                return rcv;
            }

            if(event.event == RDMA_CM_EVENT_ESTABLISHED)
            {
                for(pending_recv_list_type::iterator it = pending_recv_list.begin();
                    it != pending_recv_list.end();)
                {
                    if(it->first.id == event.id)
                    {
                        rcv = it->second;
                        rcv->context().on_connection(event.id, ec);
                        it = pending_recv_list.erase(it);
                        break;
                    }
                    else
                    {
                        ++it;
                    }
                }
                HPX_ASSERT(rcv);
            }

            return rcv;
        }
Beispiel #5
0
int cros_ec_get_next_event(struct cros_ec_device *ec_dev)
{
	if (ec_dev->mkbp_event_supported)
		return get_next_event(ec_dev);
	else
		return get_keyboard_state_event(ec_dev);
}
Beispiel #6
0
int main(int argc, char **argv)
{
    struct system_t system;

    init(&system);
    //performance_begin();

#ifdef __10000_CUSTOMER__
    while (system.total_served < SIM_CUSTOMER)
#else
    while (system.current_time < SIM_TIME)
#endif
    {
        enum event_type_t event = get_next_event(&system);
        switch (event)
        {
        case ARRIVAL:
            arrival_process(&system);
            break;
        case DEPARTURE:
            departure_process(&system);
            break;
        default:
            break;
        }
    }

    performance_end(&system);
    deinit(&system);

    return 0;
}
Beispiel #7
0
int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event)
{
	u32 host_event;
	int ret;

	if (!ec_dev->mkbp_event_supported) {
		ret = get_keyboard_state_event(ec_dev);
		if (ret < 0)
			return ret;

		if (wake_event)
			*wake_event = true;

		return ret;
	}

	ret = get_next_event(ec_dev);
	if (ret < 0)
		return ret;

	if (wake_event) {
		host_event = cros_ec_get_host_event(ec_dev);

		/* Consider non-host_event as wake event */
		*wake_event = !host_event ||
			      !!(host_event & ec_dev->host_event_wake_mask);
	}

	return ret;
}
Beispiel #8
0
/**
 * @brief
 * 		returns 1 if there exists a timed run event in
 *		the event list between the current event
 *		and the last event, or the end time if it is set
 *
 * @param[in] calendar 	- event list
 * @param[in] end 		- optional end time (0 means search all events)
 *
 * @return	int
 * @retval	1	: there exists a run event
 * @retval	0	: there doesn't exist a run event
 *
 */
int
exists_run_event(event_list *calendar, time_t end)
{
	timed_event *te;

	if (calendar == NULL)
		return 0;

	te = get_next_event(calendar);

	if (te == NULL) /* no events in our calendar */
		return 0;

	te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, TIMED_RUN_EVENT);

	if (te == NULL) /* no run event */
		return 0;

	/* there is a run event, but it's after end */
	if (end != 0 && te->event_time > end)
		return 0;

	/* if we got here, we have a happy run event */
	return 1;
}
Beispiel #9
0
/**
 * @brief
 * 		generic simulation function which will call a function pointer over
 *      events of a calendar from now up to (but not including) the end time.
 * @par
 *	  	The simulation works by looping searching for a success or failure.
 *	  	The loop will stop if the function returns 1 for success or -1 for
 *	  	failure.  We continue looping if the function returns 0.  If we run
 *	  	out of events, we return the default passed in.
 *
 * @par Function:
 * 		The function can return three return values
 *	 	>0 success - stop looping and return success
 *	  	0 failure - keep looping
 *	 	<0 failure - stop looping and return failure
 *
 * @param[in] calendar 		- calendar of timed events
 * @param[in] event_mask 	- mask of timed_events which we want to simulate
 * @param[in] end 			- end of simulation (0 means search all events)
 * @param[in] default_ret 	- default return value if we reach the end of the simulation
 * @param[in] func 			- the function to call on each timed event
 * @param[in] arg1 			- generic arg1 to function
 * @param[in] arg2 			- generic arg2 to function
 *
 * @return success of simulate
 * @retval 1 : if simulation is success
 * @retval 0 : if func returns failure or there is an error
 */
int
generic_sim(event_list *calendar, unsigned int event_mask, time_t end, int default_ret,
	int (*func)(timed_event*, void*, void*), void *arg1, void *arg2)
{
	timed_event *te;
	int rc = 0;
	if (calendar == NULL || func == NULL)
		return 0;

	/* We need to handle the calendar's initial event special because
	 * get_next_event() only returns the calendar's next_event member.
	 * We need to make sure the initial event is of the correct type.
	 */
	te = get_next_event(calendar);

	for (te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask);
		te != NULL && rc == 0 && (end == 0 || te->event_time < end);
		te = find_next_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask)) {
		rc = func(te, arg1, arg2);
	}

	if (rc > 0)
		return 1;
	else if (rc < 0)
		return 0;

	return default_ret;
}
Beispiel #10
0
/* Execute the server-side duties for remote on-the-wire testing using
 * a real NIC. Basically the server side just needs to send packets
 * over the wire (to the kernel under test) and sniff and verify
 * packets on the wire (from the kernel under test). This is analogous
 * to run_script(), which executes scripts for stand-alone mode,
 * and also executes the client side for remote on-the-wire testing
 * using a real NIC.
 */
static int wire_server_run_script(struct wire_server *wire_server,
				  char **error)
{
	struct state *state = wire_server->state;
	struct event *event = NULL;

	DEBUGP("wire_server_run_script\n");

	state->live_start_time_usecs = now_usecs();
	DEBUGP("live_start_time_usecs is %lld\n",
	       state->live_start_time_usecs);

	while (1) {
		if (get_next_event(state, error))
			return STATUS_ERR;
		event = state->event;
		if (event == NULL)
			break;

		if (wire_server_next_event(wire_server, event))
			return STATUS_ERR;

		/* We adjust relative times after getting notification
		 * that previous client-side events have completed.
		 */
		adjust_relative_event_times(state, event);

		switch (event->type) {
		case PACKET_EVENT:
			if (wire_server_run_packet_event(wire_server, event,
							 event->event.packet,
							 error) == STATUS_ERR)
				return STATUS_ERR;
			break;
		case SYSCALL_EVENT:
			DEBUGP("SYSCALL_EVENT happens on client side...\n");
			break;
		case COMMAND_EVENT:
			DEBUGP("COMMAND_EVENT happens on client side...\n");
			break;
		case CODE_EVENT:
			DEBUGP("CODE_EVENT happens on client side...\n");
			break;
		case INVALID_EVENT:
		case NUM_EVENT_TYPES:
			assert(!"bogus type");
			break;
		/* We omit default case so compiler catches missing values. */
		}
	}

	/* Tell the client about any outstanding packet events it requested. */
	wire_server_next_event(wire_server, NULL);

	DEBUGP("wire_server_run_script: done running\n");

	return STATUS_OK;
}
Beispiel #11
0
static INLINE void send_event(part_evtlist_t *evlist, void **val, bool (*match_func)(void **a, void **b))
{
	elistdata_t  eld_p;
	mempart_evt_t  *reg_event = get_first_event(evlist, &eld_p);

	while (reg_event != NULL)
	{
		struct evt_info_s *evt = &reg_event->evt_reg;

		if (reg_event->onlist == &evlist->active)
		{
			/* if this event has been deactivated, don't send it */
			if (evt->flags & evtflags_DEACTIVATE) {
				deactivate_event(evlist, (part_evt_t *)reg_event);
			}
			/* check for event send conditions */
			else if (reg_event->evt_dest.rcvid > 0)
			{
				void **compare_val_p = GET_COMPARE_VAL_P(evt);
				CRASHCHECK(compare_val_p == NULL);

				/*
				 * if the caller did not provide a match function, or a match
				 * function was provided and it returns TRUE, deliver the event
				*/
				if ((match_func == NULL) ||
					(match_func(compare_val_p, val) == bool_t_TRUE))
				{
					int r;
					struct sigevent se = evt->sig;		// make a local copy
					/*
					 * if the caller has set evtflags_SIGEV_FLAG_SIGINFO, we
					 * can return some useful information
					*/
					if (evt->flags & evtflags_SIGEV_FLAG_SIGINFO) {
						se.sigev_value.sival_ptr = *val;
					}
					r = apm_deliver_event(&reg_event->evt_dest, &se);

					if (r == EOK) reg_event->undeliverable_count = 0;
					else if (r == ESRCH) ++reg_event->undeliverable_count;

					if ((reg_event->undeliverable_count > ORPHAN_RETRY_COUNT) ||
						(!(evt->flags & evtflags_REARM)))
					{
						/* remove the event from the list */
						deactivate_event(evlist, (part_evt_t *)reg_event);
					}
				}
			}
		}
		reg_event = get_next_event(evlist, reg_event, &eld_p);
	}
}
Beispiel #12
0
static void check_gas_change_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
	int i = 0, cylinderindex = 0;
	struct event *ev = get_next_event(dc->events, "gaschange");

	// for dive computers that tell us their first gas as an event on the first sample
	// we need to make sure things are setup correctly
	cylinderindex = explicit_first_cylinder(dive, dc);
	set_first_cylinder_index(pi, 0, cylinderindex, ~0u);

	if (!ev)
		return;

	do {
		i = set_cylinder_index(pi, i, cylinderindex, ev->time.seconds);
		cylinderindex = get_cylinder_index(dive, ev);
		ev = get_next_event(ev->next, "gaschange");
	} while (ev);
	set_cylinder_index(pi, i, cylinderindex, ~0u);
}
Beispiel #13
0
static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
	int i = 0;
	pressure_t setpoint;

	setpoint.mbar = 0;
	struct event *ev = get_next_event(dc->events, "SP change");

	if (!ev)
		return;

	do {
		i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
		setpoint.mbar = ev->value;
		if (setpoint.mbar)
			dc->divemode = CCR;
		ev = get_next_event(ev->next, "SP change");
	} while (ev);
	set_setpoint(pi, i, setpoint.mbar, ~0u);
}
Beispiel #14
0
void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
	Q_UNUSED(topLeft);
	Q_UNUSED(bottomRight);
	// We don't have enougth data to calculate things, quit.
	if (!dataModel || !pInfoEntry || !pInfoNr)
		return;

	// remove the old rectangles
	foreach (QGraphicsRectItem *r, rects) {
		delete(r);
	}
	rects.clear();

	qreal width, left;

	// Find correct end of the dive plot for correct end of the tankbar
	struct plot_data *last_entry = &pInfoEntry[pInfoNr-1];

	// get the information directly from the displayed_dive (the dc always exists)
	struct divecomputer *dc = get_dive_dc(&displayed_dive, dc_number);

	// start with the first gasmix and at the start of the dive
	int cyl = explicit_first_cylinder(&displayed_dive, dc);
	struct gasmix *gasmix = &displayed_dive.cylinder[cyl].gasmix;
	int startTime = 0;

	// work through all the gas changes and add the rectangle for each gas while it was used
	struct event *ev = get_next_event(dc->events, "gaschange");
	while (ev && ev->time.seconds < last_entry->sec) {
		width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime);
		left = hAxis->posAtValue(startTime);
		createBar(left, width, gasmix);
		startTime = ev->time.seconds;
		gasmix = get_gasmix_from_event(&displayed_dive, ev);
		ev = get_next_event(ev->next, "gaschange");
	}
	width = hAxis->posAtValue(last_entry->sec) - hAxis->posAtValue(startTime);
	left = hAxis->posAtValue(startTime);
	createBar(left, width, gasmix);
}
Beispiel #15
0
errval_t event_dispatch(struct waitset *ws)
{
    struct event_closure closure;
    errval_t err = get_next_event(ws, &closure);
    if (err_is_fail(err)) {
        return err;
    }

    assert(closure.handler != NULL);
    closure.handler(closure.arg);
    return SYS_ERR_OK;
}
Beispiel #16
0
/* look at all dive computers and figure out if this cylinder is used anywhere
 * d has to be a valid dive (test before calling)
 * cyl does not have to be a cylinder that is part of this dive structure */
bool cylinder_is_used(struct dive *d, cylinder_t *cyl)
{
	struct divecomputer *dc = &d->dc;
	bool same_as_first = gasmix_distance(&cyl->gasmix, &d->cylinder[0].gasmix) < 200;
	while (dc) {
		struct event *ev = get_next_event(dc->events, "gaschange");
		if (same_as_first && (!ev || ev->time.seconds > 30)) {
			// unless there is a gas change in the first 30 seconds we can
			// always mark the first cylinder as used
			return true;
		}
		while (ev) {
			if (gasmix_distance(&cyl->gasmix, get_gasmix_from_event(ev)) < 200)
				return true;

			ev = get_next_event(ev->next, "gaschange");
		}
		dc = dc->next;
	}
	return false;
}
Beispiel #17
0
bool is_cylinder_used(struct dive *dive, int idx)
{
	struct divecomputer *dc;
	bool firstGasExplicit = false;
	if (cylinder_none(&dive->cylinder[idx]))
		return false;

	for_each_dc(dive, dc) {
		struct event *event = get_next_event(dc->events, "gaschange");
		while (event) {
			if (event->time.seconds < 30)
				firstGasExplicit = true;
			if (get_cylinder_index(dive, event) == idx)
				return true;
			event = get_next_event(event->next, "gaschange");
		}
	}
	if (idx == 0 && !firstGasExplicit)
		return true;
	return false;
}
Beispiel #18
0
    inline bool get_next_event(
        rdma_event_channel *event_channel, rdma_cm_event & event_copy, Connection * c
      , boost::system::error_code &ec
    )
    {
        if(!event_channel)
        {
            HPX_IBVERBS_THROWS_IF(ec, boost::asio::error::not_connected);
            return false;
        }

        rdma_cm_event * event = NULL;

        if(rdma_get_cm_event(event_channel, &event) == 0)
        {
            std::memcpy(&event_copy, event, sizeof(rdma_cm_event));

            rdma_ack_cm_event(event);

            if(event_copy.event == RDMA_CM_EVENT_DISCONNECTED)
            {
                c->on_disconnect(event_copy.id);
                return get_next_event(event_channel, event_copy, c, ec);
            }

            return true;
        }
        else
        {
            int verrno = errno;
            if(verrno == EBADF) return false;
            if(verrno == EAGAIN) return false;
            if(verrno == EWOULDBLOCK) return false;

            boost::system::error_code err(verrno, boost::system::system_category());
            HPX_IBVERBS_THROWS_IF(
                ec
              , err
            );

            return false;
        }
        HPX_ASSERT(false);
        return false;
    }
static void received_event_add_request(gint fd)
{
	gchar *vevent;
	gchar *msg;
	gchar *new_vevent = NULL;

	vevent = get_next_event();

	g_print("Event to add: '%s'\n",vevent);

	if (vevent) {
		AlertValue val;
		val = G_ALERTALTERNATE;
		if (opensync_config.event_ask_add) {
			msg = g_strdup_printf(_("Really add event:\n%s?"),vevent);
			val = alertpanel(_("OpenSync plugin"),msg,
											 GTK_STOCK_CANCEL,GTK_STOCK_ADD,NULL);
			g_free(msg);
		}
		if (!opensync_config.event_ask_add || (val != G_ALERTDEFAULT)) {
			if((new_vevent = vcal_add_event(vevent)) != NULL) {
				g_print("adding successful\n");
			}
			else
				g_print("could not add event\n");
		}
		else {
			g_print("Error: User refused to add event '%s'\n", vevent);
		}
	}
	else {
		g_print("Error: Not able to get the event to add\n");
	}
	if(new_vevent)
		event_send_cb(new_vevent);
	else
		sock_send(fd, ":failure:\n");

	g_free(vevent);
}
Beispiel #20
0
void track::del_event(unsigned short int row, int needlock) {
    event *e,*e2;
    if (event_list) {
        if (needlock)
            lock_mutex(song->hEditMutex,EDIT_LOCK_TIMEOUT);

        if (event_list->row == row) {
            e = (event *)event_list->next_event;
            delete event_list;
            event_list = e;
            file_changed++;
        } else {
            if (e=get_next_event(row)) {
                e2 = (event *)e->next_event;
                e->next_event = e2->next_event;
                delete e2;
                file_changed++;
            }
        }
        if (needlock)
            unlock_mutex(song->hEditMutex);
    }
}
Beispiel #21
0
/**
 * @brief finds if there is a reservation run event between now and 'end'
 * @param[in] calendar - the calendar to search
 * @param[in] end - when to stop searching
 *
 * @returns int
 * @retval 1 found a reservation event
 * @retval 0 did not find a reservation event
 */
int
exists_resv_event(event_list *calendar, time_t end)
{
	timed_event *te;
	timed_event *te_list;

	if (calendar == NULL)
		return 0;

	te_list = get_next_event(calendar);
	if (te_list == NULL) /* no events in our calendar */
		return 0;

	for (te = te_list; te != NULL && te->event_time <= end;
		te = find_next_timed_event(te, 0, TIMED_RUN_EVENT)) {
		if (te->event_type == TIMED_RUN_EVENT) {
			resource_resv *resresv = (resource_resv *)te->event_ptr;
			if(resresv->is_resv)
				return 1;
		}
	}
	return 0;
}
Beispiel #22
0
/* THIS IS MAIN */
int main(int argc, char *argv[])
{
	nge_connection *c = NULL;
	nge_event *e = NULL;

	/* open correct socket */
	if (strstr(argv[0], "ngde"))
		c = ngeclient_connect(NGE_TEST);
	else
		c = ngeclient_connect(NGE_REAL);

	/* if open_socket fails, ngeclient_error is set */
	if (ngeclient_error) {
		fprintf(stderr, "NGECLIENT ERROR: %s\n", ngeclient_error);
		exit(1);
	}
	assert(c);

	while ((e = get_next_event(c, 20000))) {
		/*printf("Got an event: %i!\n", e->state_type); */
		handle_event(e);

		ngeclient_event_free(e);
	}

	/* clean up */
	ngeclient_close(c);

	/* check so there is no ngeclient_error set */
	if (ngeclient_error) {
		fprintf(stderr, "NGECLIENT ERROR: %s\n", ngeclient_error);
		exit(1);
	}

	exit(0);
}
Beispiel #23
0
int
main(int argc, char **argv)
{
  unsigned int  mainWndId;
  unsigned int  gc;
  KWEvent       event;
  
  mainWndId = new_main_window_simple(50, 50, WIDTH, HEIGHT, "Window 1, This is the first one.");
  if (mainWndId == BAD_WND_ID) {
    LOG(("%s\n", "<Demo2 Error> can not create the main window."));
    exit (-1);
  }
  
  gc = new_gc();
  
  select_events(mainWndId, EVENT_MASK_EXPOSURE);
  map_window(mainWndId);
  
  for (;;) {
    get_next_event(&event);
    switch (event.type) {
    }
  }
}
/* THIS IS MAIN */
int main(int argc, char *argv[])
{
	nge_connection *c = NULL;
	nge_event *e = NULL;
	pid_t fork_pid;

	/* open up for usplash */
	if (chdir("/dev/.initramfs") != 0) {
		printf("Error chdir \"/dev/.initramfs\"\n");
		exit(1);
	}

	/* set some progress */
	/*usplash("TEXT Launching InitNG"); */
	usplash("PROGRESS 10");
	usplash("TIMEOUT 180");

	/* ok, now fork */
	fork_pid = fork();

	/* make sure this is not the fork */
	if (fork_pid != 0) {
		/* Now make sure this is not a fork */
		char initng_path[] = "/sbin/initng";

		argv[0] = initng_path;
		execve(argv[0], argv, environ);
		_exit(1);
	}

	/* FROM HERE, IS run in a fork. */

	/* open correct socket */
	while (!c) {
		/* reset error every time, or you get an can not connect to socket */
		ngeclient_error = NULL;
		c = ngeclient_connect(NGE_REAL);
		usleep(100);
	}

	/* if open_socket fails, ngeclient_error is set */
	if (ngeclient_error) {
		usplash("QUIT");
		fprintf(stderr, "NGECLIENT ERROR: %s\n", ngeclient_error);
		exit(1);
	}
	assert(c);

	while ((e = get_next_event(c, 200000))) {
		/*printf("Got an event: %i!\n", e->state_type); */
		handle_event(e);

		ngeclient_event_free(e);
	}

	/* clean up */
	ngeclient_close(c);

	/* check so there is no ngeclient_error set */
	if (ngeclient_error) {
		usplash("QUIT");
		fprintf(stderr, "NGECLIENT ERROR: %s\n", ngeclient_error);
		exit(1);
	}

	/* stop usplash daemon */
	usplash("QUIT");
	exit(0);
}
Beispiel #25
0
 bool get_next_rdma_event(rdma_cm_event & event, boost::system::error_code &ec)
 {
     return get_next_event(event_channel_, event, this, ec);
 }
Beispiel #26
0
void run_script(struct config *config, struct script *script)
{
	char *error = NULL;
	struct state *state = NULL;
	struct netdev *netdev = NULL;
	struct event *event = NULL;

	DEBUGP("run_script: running script\n");

	set_scheduling_priority();
	lock_memory();

	/* This interpreter loop runs for local mode or wire client mode. */
	assert(!config->is_wire_server);

	/* How we use the network is of course a little different in
	 * each of the two cases....
	 */
	if (config->is_wire_client)
		netdev = wire_client_netdev_new(config);
	else
		netdev = local_netdev_new(config);

	state = state_new(config, script, netdev);

	if (config->is_wire_client)
	{
		state->wire_client = wire_client_new();
		wire_client_init(state->wire_client, config, script, state);
	}

	if (script->init_command != NULL)
	{
		if (safe_system(script->init_command->command_line,
		                &error))
		{
			die("%s: error executing init command: %s\n",
			    config->script_path, error);
		}
	}

	signal(SIGPIPE, SIG_IGN);	/* ignore EPIPE */

	state->live_start_time_usecs = schedule_start_time_usecs();
	DEBUGP("live_start_time_usecs is %lld\n",
	       state->live_start_time_usecs);

	if (state->wire_client != NULL)
		wire_client_send_client_starting(state->wire_client);

	while (1)
	{
		if (get_next_event(state, &error))
			die("%s", error);
		event = state->event;
		if (event == NULL)
			break;

		if (state->wire_client != NULL)
			wire_client_next_event(state->wire_client, event);

		/* In wire mode, we adjust relative times after
		 * getting notification that previous packet events
		 * have completed, if any.
		 */
		adjust_relative_event_times(state, event);

		switch (event->type)
		{
		case PACKET_EVENT:
			/* For wire clients, the server handles packets. */
			if (!config->is_wire_client)
			{
				run_local_packet_event(state, event,
				                       event->event.packet);
			}
			break;
		case SYSCALL_EVENT:
			run_system_call_event(state, event,
			                      event->event.syscall);
			break;
		case COMMAND_EVENT:
			run_command_event(state, event,
			                  event->event.command);
			break;
		case CODE_EVENT:
			run_code_event(state, event,
			               event->event.code->text);
			break;
		case INVALID_EVENT:
		case NUM_EVENT_TYPES:
			assert(!"bogus type");
			break;
			/* We omit default case so compiler catches missing values. */
		}
	}

	/* Wait for any outstanding packet events we requested on the server. */
	if (state->wire_client != NULL)
		wire_client_next_event(state->wire_client, NULL);

	if (code_execute(state->code, &error))
	{
		die("%s: error executing code: %s\n",
		    state->config->script_path, error);
		free(error);
	}

	state_free(state);

	DEBUGP("run_script: done running\n");
}
Beispiel #27
0
// app event loop
static void check_events(void) {
  static event_t e;
  //  u8 launch = 0;
  //  print_dbg("\r\n checking events...");
  if( get_next_event(&e) ) {
  /* print_dbg("\r\n handling event, type: "); */
  /* print_dbg_hex(e.eventType); */
  /* print_dbg("\r\n , data: "); */
  /* print_dbg_hex(e.eventData); */

    if(startup) {
      if( e.eventType == kEventSwitch0
  	  || e.eventType == kEventSwitch1
  	  || e.eventType == kEventSwitch2
  	  || e.eventType == kEventSwitch3
  	  || e.eventType == kEventSwitch4
  	  ) {
  	startup = 0;
  	print_dbg("\r\n key pressed, launching ");
  	// return 1 if app completed firstrun tasks
	//  	launch = app_launch(firstrun);
  	delay_ms(10);
  	if( firstrun) {
  	  //	  if(launch) {
  	    // successfully launched on firstrun, so write magic number to flash
  	    flash_write_firstrun();
  	    //	    return;
  	    //	  } else {
  	    // firstrun, but app launch failed, so clear magic number to try again
	    //   flash_clear_firstrun();
  	    //	  }
  	}
      }
    } else {
      switch(e.eventType) {
	
      case kEventRefresh:
  	// refresh the screen hardware
  	//	screen_refresh();

	/// draw ADC values
	
  	break;
      case kEventMonomePoll :
  	// poll monome serial input and spawn relevant events
  	monome_read_serial();
  	break;
      case kEventMonomeRefresh :
  	// refresh monome device from led state buffer
  	monome_grid_refresh();
  	break;
  	//--------------------------------------
      case kEventFtdiConnect:
  	// perform setup tasks for new ftdi device connection.
  	// won't work if called from an interrupt.
  	ftdi_setup();
  	break;
      case kEventFtdiDisconnect:
	break;
      case kEventHidConnect :
	break;
      case kEventHidDisconnect :
	break;
      case kEventMidiConnect :
	break;
      case kEventMidiDisconnect :
	break;
      case  kEventEncoder0 :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventEncoder0");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	dac_inc(0, scale_knob_value(e.eventData));
	break;
      case  kEventEncoder1 :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventEncoder1");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	dac_inc(1, scale_knob_value(e.eventData));
	break;
      case  kEventEncoder2  :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventEncoder2");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	dac_inc(2, scale_knob_value(e.eventData));
	break;
      case  kEventEncoder3  :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventEncoder3");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	dac_inc(3, scale_knob_value(e.eventData));
	break;
      case  kEventSwitch0 : // fn
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch0");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch1 :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch1");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch2 :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch2");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch3 :
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch3");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch4 : // mode
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch4");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch5 : // power
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch5");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch6 :  // foot
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch6");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventSwitch7 : 
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventSwitch7");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventAdc0 : 
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventAdc0");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventAdc1 : 
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventAdc1");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventAdc2 : 
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventAdc2");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case  kEventAdc3 : 
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventAdc3");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	break;
      case kEventMonomeGridKey:
	print_dbg("\r\n ( 0x"); print_dbg_hex((u32)tcTicks); print_dbg(" )  kEventMonomeGridKey");
	print_dbg(" : 0x"); print_dbg_hex((u32) e.eventData);
	handle_monome_grid_key((u32)e.eventData);
	break;


      default:
	//  	(*appEventHandler)(&e);
  	break;
      } // event switch
    } // startup
  } // got event
}
Beispiel #28
0
int main(int argc, char *argv[])
{
    ssl_init();
    OrderBook order_book(3);
    Orders<1000> orders;
    auto poller = Poller::create();

    Url diff_url("wss://ws.pusherapp.com/app/de504dc5763aeef9ff52?protocol=5");
    auto diff_socket = create_tcp_socket(diff_url.host(), 80);
    diff_socket->set_callbacks<DiffLogic<1000>>(std::ref(diff_url), std::ref(orders));
    poller->update_socket(diff_socket, EPOLLIN | EPOLLOUT);

    Url order_book_url("https://www.bitstamp.net/api/order_book");
    auto order_book_socket = create_tcp_socket(order_book_url.host(), 443);
    order_book_socket->set_callbacks<ReceiveOrderBookLogic>(std::ref(order_book_url), std::ref(order_book));
    poller->update_socket(order_book_socket, EPOLLOUT | EPOLLIN);

    //----------------------

    std::shared_ptr<Order> order;
    Timer reconect_timer;
    Timer update_timer;
    Timer stop_timer;
    stop_timer.reset();
    uint64_t last_time = 0;
    const uint64_t RECONECT_INTERVAL = 20;

    bool order_book_ready = false;

    for (;;)
    {
        poller->poll();

        for (;;)
        {
            auto event = poller->get_next_event();
            if (!event.action)
                break;

            try
            {
                if (event.action & PollerEvent::READ)
                    event.socket->read();

                if (event.action & PollerEvent::WRITE)
                    event.socket->write();

                if (event.action & PollerEvent::CLOSE)
                    event.socket->close(event.close_reason);
            }
            catch (const std::exception & e)
            {
                std::cerr << "Exception in callback: " << e.what() << std::endl << "Closing socket." << std::endl;
                event.socket->close();
            }
        }

        if (!order_book)
        {
            if (!order_book_socket.get() && reconect_timer.elapsed_seconds() > RECONECT_INTERVAL)
            {
                std::cerr << "creating new order_book_socket" << std::endl;
                order_book_socket = create_tcp_socket(order_book_url.host(), 443);
                order_book_socket->set_callbacks<ReceiveOrderBookLogic>(std::ref(order_book_url), std::ref(order_book));
                poller->update_socket(order_book_socket, EPOLLOUT | EPOLLIN);
            }

            continue;
        }

        if (!order_book_ready)
        {
            uint64_t first_diff_timestamp = orders.get_first_timestamp();
            uint64_t last_book_timestamp  = order_book.get_last_timestamp();

            std::cerr << first_diff_timestamp << "/" << last_book_timestamp << std::endl;

            if (last_book_timestamp < first_diff_timestamp)
            {
                order_book.clear();
                reconect_timer.reset();
                order_book_socket.reset();
                continue;
            }

            order_book_ready = true;
        }

        while (order = orders.get_order())
            order_book.add(*order);

        if (update_timer.elapsed_seconds() != last_time)
        {
            last_time = update_timer.elapsed_seconds();
            order_book.print();
        }
    }

    ssl_destroy();
    return 0;
}
Beispiel #29
0
/**
 * @brief
 * 		simulate the minimum amount of a resource list
 *		for an event list until a point in time.  The
 *		comparison we are simulating the minimum for is
 *		(resources_available.foo - resources_assigned.foo)
 *		The minimum is simulated by holding resources_available
 *		constant and maximizing the resources_assigned value
 *
 * @note
 * 		This function only simulates START and END events.  If at some
 *		point in the future we start simulating events such as
 *		qmgr -c 's s resources_available.ncpus + =5' this function will
 *		will have to be revisited.
 *
 * @param[in] reslist	- resource list to simulate
 * @param[in] end	- end time
 * @param[in] calendar	- calendar to simulate
 * @param[in] incl_arr	- only use events for resresvs in this array (can be NULL)
 * @param[in] exclude	- job/resv to ignore (possibly NULL)
 *
 * @return static pointer to amount of resources available during
 * @retval the entire length from now to end
 * @retval	NULL	: on error
 *
 * @par MT-safe: No
 */
schd_resource *
simulate_resmin(schd_resource *reslist, time_t end, event_list *calendar,
	resource_resv **incl_arr, resource_resv *exclude)
{
	static schd_resource *retres = NULL;	/* return pointer */

	schd_resource *cur_res;
	schd_resource *cur_resmin;
	resource_req *req;
	schd_resource *res;
	schd_resource *resmin = NULL;
	timed_event *te;
	resource_resv *resresv;
	unsigned int event_mask = (TIMED_RUN_EVENT | TIMED_END_EVENT);

	if (reslist == NULL)
		return NULL;

	/* if there is no calendar, then there is nothing to do */
	if (calendar == NULL)
		return reslist;

	/* If there are no run events in the calendar between now and the end time
	 * then there is nothing to do. Nothing will reduce resources (only increase)
	 */
	if (exists_run_event(calendar, end) == 0)
		return reslist;

	if (retres != NULL) {
		free_resource_list(retres);
		retres = NULL;
	}

	if ((res = dup_resource_list(reslist)) == NULL)
		return NULL;
	if ((resmin = dup_resource_list(reslist)) == NULL) {
		free_resource_list(res);
		return NULL;
	}

	te = get_next_event(calendar);
	for (te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask);
		te != NULL && (end == 0 || te->event_time < end);
		te = find_next_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask)) {
		resresv = (resource_resv*) te->event_ptr;
		if (incl_arr == NULL || find_resource_resv_by_rank(incl_arr, resresv->rank) !=NULL) {
			if (resresv != exclude) {
				req = resresv->resreq;

				for (; req != NULL; req = req->next) {
					if (req->type.is_consumable) {
						cur_res = find_alloc_resource(res, req->def);

						if (cur_res == NULL) {
							free_resource_list(res);
							free_resource_list(resmin);
							return NULL;
						}

						if (te->event_type == TIMED_RUN_EVENT)
							cur_res->assigned += req->amount;
						else
							cur_res->assigned -= req->amount;

						cur_resmin = find_alloc_resource(resmin, req->def);
						if (cur_resmin == NULL) {
							free_resource_list(res);
							free_resource_list(resmin);
							return NULL;
						}
						if (cur_res->assigned > cur_resmin->assigned)
							cur_resmin->assigned = cur_res->assigned;
					}
				}
			}
		}
	}
	free_resource_list(res);
	retres = resmin;
	return retres;
}
Beispiel #30
0
static INLINE void
send_delta_events(part_evtlist_t *evlist, memsize_t cur_size, memsize_t prev_size,
					bool (*compare_func)(memsize_t delta, memsize_t last_sz, memsize_t cur_sz))
{
	elistdata_t  eld_p;
	mempart_evt_t  *reg_event = get_first_event(evlist, &eld_p);

	while (reg_event != NULL)
	{
		struct evt_info_s *evt = &reg_event->evt_reg;

		if (reg_event->onlist == &evlist->active)
		{
			memsize_t *delta_p = GET_DELTA_P(evt);
			CRASHCHECK(delta_p == NULL);

			initial_delta_conditions_check(reg_event, prev_size, (void *)compare_func);

			/* if this event has been deactivated, don't send it */
			if (evt->flags & evtflags_DEACTIVATE) {
				deactivate_event(evlist, (part_evt_t *)reg_event);
			}
			/* check for event send conditions */
			else if ((reg_event->evt_dest.rcvid > 0) &&
					 ((compare_func == NULL) ||
					  (compare_func(*delta_p, reg_event->evt_data.size, cur_size) == bool_t_TRUE)))
			{
				int r;
				struct sigevent se = evt->sig;		// make a local copy
				/*
				 * if the caller has set evtflags_SIGEV_FLAG_SIGINFO, we
				 * can return some useful information
				*/
				if (evt->flags & evtflags_SIGEV_FLAG_SIGINFO)
				{
					/*
					 * if the 'cur_size' is too large to fit in the sival_int field
					 * then send back UINT_MAX. This otherwise illegal size value
					 * (because UINT_MAX & (__PAGESIZE - 1) != 0) will be an indication
					 * to the event receiver that o information was provided and
					 * that they need to request the current size if they need it
					*/
					if (cur_size > UINT_MAX) {
						se.sigev_value.sival_int = UINT_MAX;
					} else {
						se.sigev_value.sival_int = (_Uint32t)cur_size;
					}
				}
				r = apm_deliver_event(&reg_event->evt_dest, &se);

				if (r == EOK) reg_event->undeliverable_count = 0;
				else if (r == ESRCH) ++reg_event->undeliverable_count;

				if ((reg_event->undeliverable_count > ORPHAN_RETRY_COUNT) ||
					(!(evt->flags & evtflags_REARM)))
				{
					/* remove the event from the list */
					deactivate_event(evlist, (part_evt_t *)reg_event);
				}
				else {
					reg_event->evt_data.size = cur_size;
				}
			}
		}
		reg_event = get_next_event(evlist, reg_event, &eld_p);
	}
}