Beispiel #1
0
bool rm_userlist_contains(RmUserList *self, unsigned long uid, unsigned gid,
                          bool *valid_uid, bool *valid_gid) {
    rm_assert_gentle(self);
    bool gid_found = FALSE;
    bool uid_found = FALSE;

    g_mutex_lock(&self->lock);
    {
        gid_found = g_sequence_lookup(self->groups, GUINT_TO_POINTER(gid),
                                      rm_userlist_cmp_ids, NULL);
        uid_found = g_sequence_lookup(self->users, GUINT_TO_POINTER(uid),
                                      rm_userlist_cmp_ids, NULL);
    }
    g_mutex_unlock(&self->lock);

    if(valid_uid != NULL) {
        *valid_uid = uid_found;
    }

    if(valid_gid != NULL) {
        *valid_gid = gid_found;
    }

    return (gid_found && uid_found);
}
/**
 * gst_rtsp_mount_points_remove_factory:
 * @mounts: a #GstRTSPMountPoints
 * @path: a mount point
 *
 * Remove the #GstRTSPMediaFactory associated with @path in @mounts.
 */
void
gst_rtsp_mount_points_remove_factory (GstRTSPMountPoints * mounts,
    const gchar * path)
{
  GstRTSPMountPointsPrivate *priv;
  DataItem item;
  GSequenceIter *iter;

  g_return_if_fail (GST_IS_RTSP_MOUNT_POINTS (mounts));
  g_return_if_fail (path != NULL);

  priv = mounts->priv;

  item.path = (gchar *) path;

  GST_INFO ("removing media factory for path %s", path);

  g_mutex_lock (&priv->lock);
  if (priv->dirty) {
    g_sequence_sort (priv->mounts, data_item_compare, mounts);
    priv->dirty = FALSE;
  }
  iter = g_sequence_lookup (priv->mounts, &item, data_item_compare, mounts);
  if (iter) {
    g_sequence_remove (iter);
    priv->dirty = TRUE;
  }
  g_mutex_unlock (&priv->lock);
}
/**
 * ide_recent_projects_remove:
 * @self: An #IdeRecentProjects
 * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo.
 *
 * Removes the provided projects from the recent projects file.
 */
void
ide_recent_projects_remove (IdeRecentProjects *self,
                            GList             *project_infos)
{
  g_autoptr(GBookmarkFile) projects_file = NULL;
  g_autoptr(GError) error = NULL;
  GList *liter;

  g_return_if_fail (IDE_IS_RECENT_PROJECTS (self));

  projects_file = ide_recent_projects_get_bookmarks (self, &error);

  if (projects_file == NULL)
    {
      g_warning ("Failed to load bookmarks file: %s", error->message);
      return;
    }

  for (liter = project_infos; liter; liter = liter->next)
    {
      IdeProjectInfo *project_info = liter->data;
      g_autofree gchar *file_uri = NULL;
      GSequenceIter *iter;
      GFile *file;

      g_assert (IDE_IS_PROJECT_INFO (liter->data));

      iter = g_sequence_lookup (self->projects,
                                project_info,
                                (GCompareDataFunc)ide_project_info_compare,
                                NULL);

      if (iter == NULL)
        {
          g_warning ("Project \"%s\" was not found, cannot remove.",
                     ide_project_info_get_name (project_info));
          g_clear_error (&error);
          continue;
        }

      file = ide_project_info_get_file (project_info);
      file_uri = g_file_get_uri (file);

      if (!g_bookmark_file_remove_item (projects_file, file_uri, &error))
        {
          g_warning ("Failed to remove recent project: %s", error->message);
          g_clear_error (&error);
          continue;
        }


      g_sequence_remove (iter);
    }

  if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error))
    {
      g_warning ("Failed to save recent projects file: %s", error->message);
      return;
    }
}
Beispiel #4
0
static void
on_sequence_pattern_usage_changed (BtSequence * sequence, BtPattern * pattern,
    gpointer user_data)
{
  BtPatternListModel *model = BT_PATTERN_LIST_MODEL (user_data);
  BtMachine *machine;

  g_object_get (pattern, "machine", &machine, NULL);
  if (machine) {
    if (machine == model->priv->machine) {
      GSequence *seq = model->priv->seq;
      GtkTreeIter iter;
      GtkTreePath *path;

      // find the item by pattern
      iter.stamp = model->priv->stamp;
      iter.user_data = g_sequence_lookup (seq, pattern, model_item_cmp, NULL);
      path = gtk_tree_path_new ();
      gtk_tree_path_append_index (path,
          g_sequence_iter_get_position (iter.user_data));
      gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
      gtk_tree_path_free (path);
    }
    g_object_unref (machine);
  }
}
Beispiel #5
0
void g_sequence_remove_sorted ( GSequence * seq, gpointer data, GCompareDataFunc cmp_func, gpointer cmp_data )
{
    gpointer found;
    GSequenceIter * sj, * si = g_sequence_lookup( seq, data, cmp_func, cmp_data );
    if ( si == NULL )
        return;
    
    sj = si;
    while ( !g_sequence_iter_is_end( sj ) )
    {
        found = g_sequence_get( sj );
        if ( found == data )
            return g_sequence_remove( sj );
        else if ( cmp_func( found, data, cmp_data ) != 0 )
            break;
        sj = g_sequence_iter_next( sj );
    }
    
    sj = si;
    while ( !g_sequence_iter_is_begin( sj ) )
    {
        sj = g_sequence_iter_prev( sj );
        found = g_sequence_get( sj );
        if ( found == data )
            return g_sequence_remove( sj );
        else if ( cmp_func( found, data, cmp_data ) != 0 )
            break;
    }
}
Beispiel #6
0
static void
decorator_blacklist_remove (TrackerDecorator *decorator,
                            gint              id)
{
	TrackerDecoratorPrivate *priv = decorator->priv;
	GSequenceIter *iter;

	iter = g_sequence_lookup (priv->blacklist_items,
	                          GINT_TO_POINTER (id),
	                          sequence_compare_func,
	                          NULL);
	if (iter)
		g_sequence_remove (iter);
}
/**
 * ide_debugger_address_map_lookup:
 * @self: a #IdeDebuggerAddressMap
 * @address: an address to locate the containing map
 *
 * Attempts to locate which #IdeDebuggerAddressMapEntry contains @address within
 * the region specified by #IdeDebuggerAddressMapEntry.start and
 * #IdeDebuggerAddressMapEntry.end.
 *
 * Returns: (nullable): An #IdeDebuggerAddressMapEntry or %NULL
 *
 * Since: 3.32
 */
const IdeDebuggerAddressMapEntry *
ide_debugger_address_map_lookup (const IdeDebuggerAddressMap *self,
                                 guint64                      address)
{
  IdeDebuggerAddressMapEntry entry = { NULL, 0, address, 0 };
  GSequenceIter *iter;

  g_return_val_if_fail (self != NULL, NULL);

  iter = g_sequence_lookup (self->seq,
                            &entry,
                            ide_debugger_address_map_entry_compare_in_range,
                            NULL);

  if (iter == NULL || g_sequence_iter_is_end (iter))
    return NULL;

  return g_sequence_get (iter);
}
static void
gst_timed_value_control_source_set_internal (GstTimedValueControlSource *
    self, GstClockTime timestamp, const gdouble value)
{
  GstControlPoint *cp;

  g_mutex_lock (&self->lock);

  /* check if a control point for the timestamp already exists */
  if (G_LIKELY (self->values)) {
    GSequenceIter *iter = g_sequence_lookup (self->values, &timestamp,
        (GCompareDataFunc) gst_control_point_find, NULL);

    if (iter) {
      GstControlPoint *cp = g_sequence_get (iter);

      /* update control point */
      cp->value = value;
      g_mutex_unlock (&self->lock);

      g_signal_emit (self,
          gst_timed_value_control_source_signals[VALUE_CHANGED_SIGNAL], 0, cp);
      goto done;
    }
  } else {
    self->values = g_sequence_new ((GDestroyNotify) gst_control_point_free);
    GST_INFO ("create new timed value sequence");
  }

  /* sort new cp into the prop->values list */
  cp = _make_new_cp (self, timestamp, value);
  g_sequence_insert_sorted (self->values, cp,
      (GCompareDataFunc) gst_control_point_compare, NULL);
  self->nvalues++;
  g_mutex_unlock (&self->lock);

  g_signal_emit (self,
      gst_timed_value_control_source_signals[VALUE_ADDED_SIGNAL], 0, cp);

done:
  self->valid_cache = FALSE;
}
/**
 * ide_debugger_address_map_remove:
 * @self: a #IdeDebuggerAddressMap
 * @address: the address contained in the map
 *
 * Removes the entry found containing @address.
 *
 * Since: 3.32
 */
gboolean
ide_debugger_address_map_remove (IdeDebuggerAddressMap *self,
                                 IdeDebuggerAddress     address)
{
  IdeDebuggerAddressMapEntry entry = { NULL, 0, address, 0 };
  GSequenceIter *iter;

  g_return_val_if_fail (self != NULL, FALSE);

  iter = g_sequence_lookup (self->seq,
                            &entry,
                            ide_debugger_address_map_entry_compare_in_range,
                            NULL);

  if (iter == NULL || g_sequence_iter_is_end (iter))
    return FALSE;

  g_sequence_remove (iter);

  return TRUE;
}
void
desktop_file_index_text_index_add_ids (GSequence     *text_index,
                                       const gchar   *token,
                                       const guint16 *ids,
                                       gint           n_ids)
{
  DesktopFileIndexTextIndexItem *item;
  GSequenceIter *iter;

  iter = g_sequence_lookup (text_index, &token, desktop_file_index_text_index_string_compare, NULL);
  if (iter)
    {
      item = g_sequence_get (iter);
    }
  else
    {
      item = desktop_file_index_text_index_item_new (token);
      g_sequence_insert_sorted (text_index, item, desktop_file_index_text_index_string_compare, NULL);
    }

  desktop_file_index_id_list_add_ids (item->id_list, ids, n_ids);
}
Beispiel #11
0
Container* container_cache_lookup_special(ContainerCache *cc,
		Fingerprint *finger, ContainerId container_id) {
	Container tmp;
	tmp.id = container_id;
	Container *container = 0;
	GSequence *container_list = g_hash_table_lookup(cc->map, finger);
	if (container_list) {
		/*container = g_sequence_get(g_sequence_get_begin_iter(container_list));*/
		GSequenceIter *iter = g_sequence_lookup(container_list, &tmp,
				container_cmp_des, NULL);
		if (iter) {
			container = g_sequence_get(iter);
			if (container) {
				if (!lru_cache_lookup(cc->lru_cache, container_equal,
						container)) {
					printf("%s, %d: inconsistency between map and cache.\n",
							__FILE__, __LINE__);
				}
			}
		}
	}
	return container;
}
Beispiel #12
0
static void
bt_pattern_list_model_rem (BtPatternListModel * model, BtPattern * pattern)
{
  GSequence *seq = model->priv->seq;
  GtkTreePath *path;
  GSequenceIter *iter;
  gint position;

  GST_INFO ("removing pattern from model");

  // remove entry
  iter = g_sequence_lookup (seq, pattern, model_item_cmp, NULL);
  position = g_sequence_iter_get_position (iter);
  g_sequence_remove (iter);

  // signal to the view/app
  path = gtk_tree_path_new ();
  gtk_tree_path_append_index (path, position);
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
  gtk_tree_path_free (path);

  GST_INFO ("removed pattern from model at pos %d ", position);
}
/**
 * gst_timed_value_control_source_unset:
 * @self: the #GstTimedValueControlSource object
 * @timestamp: the time the control-change should be removed from
 *
 * Used to remove the value of given controller-handled property at a certain
 * time.
 *
 * Returns: FALSE if the value couldn't be unset (i.e. not found, TRUE otherwise.
 */
gboolean
gst_timed_value_control_source_unset (GstTimedValueControlSource * self,
    GstClockTime timestamp)
{
  GSequenceIter *iter;
  gboolean res = FALSE;
  GstControlPoint *cp = NULL;

  g_return_val_if_fail (GST_IS_TIMED_VALUE_CONTROL_SOURCE (self), FALSE);
  g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);

  g_mutex_lock (&self->lock);
  /* check if a control point for the timestamp exists */
  if (G_LIKELY (self->values) && (iter =
          g_sequence_lookup (self->values, &timestamp,
              (GCompareDataFunc) gst_control_point_find, NULL))) {

    /* Iter contains the iter right after timestamp, i.e.
     * we need to get the previous one and check the timestamp
     */
    cp = g_slice_dup (GstControlPoint, g_sequence_get (iter));
    g_sequence_remove (iter);
    self->nvalues--;
    self->valid_cache = FALSE;
    res = TRUE;
  }
  g_mutex_unlock (&self->lock);

  if (cp) {
    g_signal_emit (self,
        gst_timed_value_control_source_signals[VALUE_REMOVED_SIGNAL], 0, cp);
    g_slice_free (GstControlPoint, cp);
  }

  return res;
}
Beispiel #14
0
Container *container_cache_insert_container(ContainerCache *cc, ContainerId cid) {
	/* read container */
	Container *container = 0;
	TIMER_DECLARE(b, e);
	TIMER_BEGIN(b);

	if (cc->enable_data) {
		if (simulation_level >= SIMULATION_RECOVERY) {
			container = read_container_meta_only(cid);
		} else {
			container = read_container(cid);
		}
	} else {
		container = read_container_meta_only(cid);
	}

	TIMER_END(read_container_time, b, e);

	/* If this container is newly appended,
	 * maybe we can read nothing. */
	if (container == NULL) {
		return NULL;
	}

	/* insert */
	Container *evictor = lru_cache_insert(cc->lru_cache, container);

	/* evict */
	if (evictor) {
		int32_t chunknum = container_get_chunk_num(evictor);
		Fingerprint *fingers = container_get_all_fingers(evictor);
		int i = 0;
		/* evict all fingers of evictor from map */
		for (; i < chunknum; ++i) {
			GSequence* container_list = g_hash_table_lookup(cc->map,
					&fingers[i]);
			/* remove the specified container from list */
			GSequenceIter *iter = g_sequence_lookup(container_list, evictor,
					container_cmp_des, NULL);
			if (iter)
				g_sequence_remove(iter);
			else
				dprint("Error! The sequence does not contain the container.");
			if (g_sequence_get_length(container_list) == 0) {
				g_hash_table_remove(cc->map, &fingers[i]);
			}
		}
		free(fingers);
		if (fragment_stream)
			fprintf(fragment_stream, "%.4f\n",
					1.0 * evictor->used_size / CONTAINER_SIZE);
		container_free_full(evictor);
	}

	/* insert */
	int32_t num = container_get_chunk_num(container);
	Fingerprint *nfingers = container_get_all_fingers(container);
	int i = 0;
	for (; i < num; ++i) {
		GSequence* container_list = g_hash_table_lookup(cc->map, &nfingers[i]);
		if (container_list == 0) {
			container_list = g_sequence_new(NULL);
			Fingerprint *finger = (Fingerprint *) malloc(sizeof(Fingerprint));
			memcpy(finger, &nfingers[i], sizeof(Fingerprint));
			g_hash_table_insert(cc->map, finger, container_list);
		}
		g_sequence_insert_sorted(container_list, container, container_cmp_des,
				NULL);
	}
	free(nfingers);
	return container;
}
/**
 * ide_recent_projects_remove:
 * @self: An #IdeRecentProjects
 * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo.
 *
 * Removes the provided projects from the recent projects file.
 */
void
ide_recent_projects_remove (IdeRecentProjects *self,
                            GList             *project_infos)
{
  g_autoptr(GBookmarkFile) projects_file = NULL;
  g_autoptr(GError) error = NULL;
  GList *liter;

  g_return_if_fail (IDE_IS_RECENT_PROJECTS (self));

  projects_file = ide_recent_projects_get_bookmarks (self, &error);

  if (projects_file == NULL)
    {
      g_warning ("Failed to load bookmarks file: %s", error->message);
      return;
    }

  for (liter = project_infos; liter; liter = liter->next)
    {
      IdeProjectInfo *project_info = liter->data;
      g_autofree gchar *file_uri = NULL;
      GSequenceIter *iter;
      GFile *file;

      g_assert (IDE_IS_PROJECT_INFO (liter->data));

      iter = g_sequence_lookup (self->projects,
                                project_info,
                                (GCompareDataFunc)ide_project_info_compare,
                                NULL);

      if (iter == NULL)
        {
          g_warning ("Project \"%s\" was not found, cannot remove.",
                     ide_project_info_get_name (project_info));
          g_clear_error (&error);
          continue;
        }

      file = ide_project_info_get_file (project_info);
      file_uri = g_file_get_uri (file);

      if (!g_bookmark_file_remove_item (projects_file, file_uri, &error))
        {
          g_autofree gchar *with_slash = g_strdup_printf ("%s/", file_uri);

          /* Sometimes we don't get a match because the directory is missing a
           * trailing slash. Annoying, I know. See the following for the
           * upstream bug filed in GLib.
           *
           * https://bugzilla.gnome.org/show_bug.cgi?id=765449
           */
          if (!g_bookmark_file_remove_item (projects_file, with_slash, NULL))
            {
              g_warning ("Failed to remove recent project: %s", error->message);
              g_clear_error (&error);
              continue;
            }

          g_clear_error (&error);
        }

      g_sequence_remove (iter);
    }

  if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error))
    {
      g_warning ("Failed to save recent projects file: %s", error->message);
      return;
    }
}