int
screenlist_goto_prev(void)
{
	Screen *s;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	if (!current_screen)
		return -1;

	/* Find current screen in screenlist */
	for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist));

	/* One step back */
	s = LL_GetPrev(screenlist);
	if (!s) {
		/* We're at the start of the screenlist. We should find the
		 * last screen with the same priority as the first screen.
		 */
		Screen *f = LL_GetFirst(screenlist);
		Screen *n;

		s = f;
		while ((n = LL_GetNext(screenlist)) && n->priority == f->priority) {
			s = n;
		}
	}
	screenlist_switch(s);
	return 0;
}
Exemple #2
0
int input_reserve_key(const char *key, bool exclusive, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", exclusive=%d, client=[%d])", __FUNCTION__, key, exclusive, (client?client->sock:-1));

	/* Find out if this key is already reserved in a way that interferes
	 * with the new reservation.
	 */
	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (strcmp(kr->key, key) == 0) {
			if (kr->exclusive || exclusive) {
				/* Sorry ! */
				return -1;
			}
		}
	}

	/* We can now safely add it ! */
	kr = malloc(sizeof(KeyReservation));
	kr->key = strdup(key);
	kr->exclusive = exclusive;
	kr->client = client;
	LL_Push(keylist, kr);

	report(RPT_INFO, "Key \"%.40s\" is now reserved in %s mode by client [%d]", key, (exclusive?"exclusive":"shared"), (client?client->sock:-1));

	return 0;
}
Exemple #3
0
/** Find a widget on a screen by its id.
 * \param s   Screen where to look for the widget.
 * \param id  Identifier of the widget.
 * \return    Pointerr to the widget; \c NULL if widget was not found or error.
 */
Widget *
screen_find_widget(Screen *s, char *id)
{
	Widget *w;

	if (!s)
		return NULL;
	if (!id)
		return NULL;

	debug(RPT_DEBUG, "%s(s=[%.40s], id=\"%.40s\")", __FUNCTION__, s->id, id);

	for (w = LL_GetFirst(s->widgetlist); w != NULL; w = LL_GetNext(s->widgetlist)) {
		if (0 == strcmp(w->id, id)) {
			debug(RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
			return w;
		}
		/* Search subscreens recursively */
		if (w->type == WID_FRAME) {
			w = widget_search_subs(w, id);
			if (w != NULL)
				return w;
		}
	}
	debug(RPT_DEBUG, "%s: Not found", __FUNCTION__);
	return NULL;
}
Exemple #4
0
/** Destroy a screen.
 * \param s    Screen to destroy.
 * \retval <0  Error; no screen given.
 * \retval  0  Success.
 */
int
screen_destroy(Screen *s)
{
	Widget *w;

	debug(RPT_DEBUG, "%s(s=[%.40s])", __FUNCTION__, s->id);

	menuscreen_remove_screen(s);

	screenlist_remove(s);

	for (w = LL_GetFirst(s->widgetlist); w; w = LL_GetNext(s->widgetlist)) {
		/* Free a widget...*/
		widget_destroy(w);
	}
	LL_Destroy(s->widgetlist);
	s->widgetlist = NULL;

	if (s->id != NULL) {
		free(s->id);
		s->id = NULL;
	}
	if (s->name != NULL) {
		free(s->name);
		s->name = NULL;
	}

	free(s);
	s = NULL;

	return 0;
}
int
screenlist_goto_next(void)
{
	Screen *s;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	if (!current_screen)
		return -1;

	/* Find current screen in screenlist */
	for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist))
		;

	/* One step forward */
	s = LL_GetNext(screenlist);
	if (!s || s->priority < current_screen->priority) {
		/* To far, go back to start of screenlist */
		s = LL_GetFirst(screenlist);
	}
	screenlist_switch(s);
	return 0;
}
Exemple #6
0
KeyReservation *input_find_key(const char *key, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", client=[%d])", __FUNCTION__, key, (client?client->sock:-1));

	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (strcmp(kr->key, key) == 0) {
			if (kr->exclusive || client==kr->client) {
				return kr;
			}
		}
	}
	return NULL;
}
Exemple #7
0
/* remove it from the list */
void 
delete_schedule (schedule_t *schedule)
{
   if (schedule->flags & MRT_SCHEDULE_DELETED)
	return;
   pthread_mutex_lock (&SCHEDULE_MASTER->mutex_lock);
   if (SCHEDULE_MASTER->last_schedule == schedule)
      SCHEDULE_MASTER->last_schedule = 
	 LL_GetNext (SCHEDULE_MASTER->ll_schedules, schedule);
   LL_RemoveFn (SCHEDULE_MASTER->ll_schedules, schedule, 0);
   pthread_mutex_unlock (&SCHEDULE_MASTER->mutex_lock);
#ifdef MRT_DEBUG
   trace (TR_THREAD, schedule->trace, 
	  "THREAD Deleted schedule for %s\n", schedule->description);
#endif /* MRT_DEBUG */
   schedule->flags |= MRT_SCHEDULE_DELETED;
}
Exemple #8
0
void input_release_key(const char *key, Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(key=\"%.40s\", client=[%d])", __FUNCTION__, key, (client?client->sock:-1));

	for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
		if (kr->client == client
		&& strcmp(kr->key, key) == 0) {
			free(kr->key);
			free(kr);
			LL_DeleteNode(keylist);
			report(RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
			return;
		}
	}
}
void menuitem_destroy_ring(MenuItem *item)
{
	debug(RPT_DEBUG, "%s(item=[%s])", __FUNCTION__,
			((item != NULL) ? item->id : "(null)"));

	if (item != NULL) {
	char *s;

		/* deallocate the strings */
		for (s = LL_GetFirst(item->data.ring.strings);
		     s != NULL;
		     s = LL_GetNext(item->data.ring.strings)) {
			free(s);
		}
		/* and the list */
		LL_Destroy(item->data.ring.strings);
	}
}
Exemple #10
0
void input_release_client_keys(Client *client)
{
	KeyReservation *kr;

	debug(RPT_DEBUG, "%s(client=[%d])", __FUNCTION__, (client?client->sock:-1));

	kr=LL_GetFirst(keylist);
	while (kr) {
		if (kr->client == client) {
			report(RPT_INFO, "Key \"%.40s\" was reserved in %s mode by client [%d] and is now released", kr->key, (kr->exclusive?"exclusive":"shared"), (client?client->sock:-1));
			free(kr->key);
			free(kr);
			LL_DeleteNode(keylist);
			kr = LL_Get(keylist);
		} else {
			kr = LL_GetNext(keylist);
		}
	}
}
Exemple #11
0
int 
process_all_schedules (void)
{
  schedule_t *schedule;
  event_t *event = NULL;
  int i;
  pthread_t save;

  pthread_mutex_lock (&SCHEDULE_MASTER->mutex_lock);
  schedule = SCHEDULE_MASTER->last_schedule;
  for (i = 0; i < LL_GetCount (SCHEDULE_MASTER->ll_schedules); i++) {

    if (schedule == NULL) {
	schedule = LL_GetHead (SCHEDULE_MASTER->ll_schedules);
    }
    else {
        schedule = LL_GetNext (SCHEDULE_MASTER->ll_schedules, schedule);
        if (schedule == NULL)
	    schedule = LL_GetHead (SCHEDULE_MASTER->ll_schedules);
    }

    assert (schedule != NULL);

    if (schedule->is_running > 0 && !schedule->can_pass)
	continue;

    if (schedule->new_event_flag > 0) {
  	pthread_mutex_lock (&schedule->mutex_lock);
        event = LL_GetHead (schedule->ll_events);
        LL_RemoveFn (schedule->ll_events, event, NULL);
        schedule->new_event_flag --;
        schedule->lastrun = time (NULL);
  	pthread_mutex_unlock (&schedule->mutex_lock);
	SCHEDULE_MASTER->last_schedule = schedule;
        break;
    }
  }
  pthread_mutex_unlock (&SCHEDULE_MASTER->mutex_lock);

  if (event == NULL) {
    return (0);
  }

#ifdef MRT_DEBUG
  if (event->description)
    trace (TR_THREAD, schedule->trace, 
      "THREAD Event %s now run (%d events left) for %s\n", 
      event->description, LL_GetCount (schedule->ll_events),
      schedule->description);
  else
    trace (TR_THREAD, schedule->trace, 
      "THREAD Event %x now run (%d events left) for %s\n", 
      event->call_fn, LL_GetCount (schedule->ll_events),
      schedule->description);
#endif /* MRT_DEBUG */

  save = set_thread_id (schedule->self);
  schedule->is_running++;
  schedule_event_dispatch (event);
  schedule->is_running--;
  if (BIT_TEST (schedule->flags, MRT_SCHEDULE_DELETED))
    destroy_schedule (schedule);
  set_thread_id (save);
  return (1);
}