Exemplo n.º 1
0
RmUserList *rm_userlist_new(void) {
    struct passwd *node = NULL;
    struct group *grp = NULL;

    RmUserList *self = g_malloc0(sizeof(RmUserList));
    self->users = g_sequence_new(NULL);
    self->groups = g_sequence_new(NULL);
    g_mutex_init(&self->mutex);

    setpwent();
    while((node = getpwent()) != NULL) {
        g_sequence_insert_sorted(
            self->users, GUINT_TO_POINTER(node->pw_uid), rm_userlist_cmp_ids, NULL
        );
        g_sequence_insert_sorted(
            self->groups, GUINT_TO_POINTER(node->pw_gid), rm_userlist_cmp_ids, NULL
        );
    }
    endpwent();

    /* add all groups, not just those that are user primary gid's */
    while((grp = getgrent()) != NULL) {
        g_sequence_insert_sorted(
            self->groups, GUINT_TO_POINTER(grp->gr_gid), rm_userlist_cmp_ids, NULL
        );
    }

    endgrent();
    return self;
}
Exemplo n.º 2
0
extern power_supply*
power_supply_new() {
    power_supply* tmp = g_new(power_supply, 1);
    tmp->ac_list = g_sequence_new(&ac_free);
    tmp->bat_list = g_sequence_new(&bat_free);
    return tmp;
}
Exemplo n.º 3
0
void fm_folder_model_set_folder(FmFolderModel* model, FmFolder* dir)
{
    GSequenceIter *it;
    if( model->dir == dir )
        return;

    model->iter_age++;

    if( model->dir )
    {
        g_signal_handlers_disconnect_by_func(model->dir,
                                             _fm_folder_model_files_added, model);
        g_signal_handlers_disconnect_by_func(model->dir,
                                             _fm_folder_model_files_removed, model);
        g_signal_handlers_disconnect_by_func(model->dir,
                                             _fm_folder_model_files_changed, model);
        g_signal_handlers_disconnect_by_func(model->dir,
                                             on_folder_loaded, model);

        g_sequence_free(model->items);
        g_sequence_free(model->hidden);
        g_object_unref(model->dir);
    }
    model->dir = dir;
    model->items = g_sequence_new((GDestroyNotify)fm_folder_item_free);
    model->hidden = g_sequence_new((GDestroyNotify)fm_folder_item_free);
    if( !dir )
        return;

    model->dir = (FmFolder*)g_object_ref(model->dir);

    g_signal_connect(model->dir, "files-added",
                     G_CALLBACK(_fm_folder_model_files_added),
                     model);
    g_signal_connect(model->dir, "files-removed",
                     G_CALLBACK(_fm_folder_model_files_removed),
                     model);
    g_signal_connect(model->dir, "files-changed",
                     G_CALLBACK(_fm_folder_model_files_changed),
                     model);
    g_signal_connect(model->dir, "loaded",
                     G_CALLBACK(on_folder_loaded), model);

    if( !fm_list_is_empty(dir->files) )
    {
        GList *l;
        for( l = fm_list_peek_head_link(dir->files); l; l = l->next )
            _fm_folder_model_add_file(model, (FmFileInfo*)l->data);
    }

    if( fm_folder_get_is_loaded(model->dir) ) /* if it's already loaded */
        on_folder_loaded(model->dir, model);  /* emit 'loaded' signal */
}
Exemplo n.º 4
0
static void
swfdec_text_buffer_init (SwfdecTextBuffer *buffer)
{
  buffer->text = g_string_new ("");
  buffer->attributes = g_sequence_new ((GDestroyNotify) swfdec_text_buffer_format_free);
  swfdec_text_attributes_reset (&buffer->default_attributes);
}
Exemplo n.º 5
0
// Called when the hub is disconnected. All users should be removed in one go,
// this is faster than a _userchange() for every user.
void uit_userlist_disconnect(ui_tab_t *tab) {
  tab_t *t = (tab_t *)tab;

  g_sequence_free(t->list->list);
  ui_listing_free(t->list);
  t->list = ui_listing_create(g_sequence_new(NULL), NULL, t, get_name);
}
Exemplo n.º 6
0
ui_tab_t *uit_userlist_create(hub_t *hub) {
  tab_t *t = g_new0(tab_t, 1);
  t->tab.name = g_strdup_printf("@%s", hub->tab->name+1);
  t->tab.type = uit_userlist;
  t->tab.hub = hub;
  t->opfirst = TRUE;
  t->hide_conn = TRUE;
  t->hide_mail = TRUE;
  t->hide_ip = TRUE;

  GSequence *users = g_sequence_new(NULL);
  // populate the list
  // g_sequence_sort() uses insertion sort? in that case it is faster to insert
  // all items using g_sequence_insert_sorted() rather than inserting them in
  // no particular order and then sorting them in one go. (which is faster for
  // linked lists, since it uses a faster sorting algorithm)
  GHashTableIter iter;
  g_hash_table_iter_init(&iter, hub->users);
  hub_user_t *u;
  while(g_hash_table_iter_next(&iter, NULL, (gpointer *)&u))
    u->iter = g_sequence_insert_sorted(users, u, sort_func, t);
  t->list = ui_listing_create(users, NULL, t, get_name);

  return (ui_tab_t *)t;
}
Exemplo n.º 7
0
SortedSequence * sorted_sequence_new(GDestroyNotify data_destroy, GCompareDataFunc cmp_func)
{
	SortedSequence * sorted_sequence = g_object_new(GOSM_TYPE_SORTED_SEQUENCE, NULL);
	sorted_sequence -> seq = g_sequence_new(data_destroy);
	sorted_sequence -> cmp_func = cmp_func;
	return sorted_sequence;
}
Exemplo n.º 8
0
/* Filesystem-level operations.  A filesystem is like a directory tree that we
 * are willing to export. */
BlueSkyFS *bluesky_new_fs(gchar *name)
{
    BlueSkyFS *fs = g_new0(BlueSkyFS, 1);
    fs->lock = g_mutex_new();
    fs->name = g_strdup(name);
    fs->inodes = g_hash_table_new(bluesky_fs_key_hash_func,
                                  bluesky_fs_key_equal_func);
    fs->next_inum = BLUESKY_ROOT_INUM + 1;
    fs->store = bluesky_store_new("file");
    fs->flushd_lock = g_mutex_new();
    fs->flushd_cond = g_cond_new();
    fs->locations = g_hash_table_new(bluesky_cloudlog_hash,
                                     bluesky_cloudlog_equal);
    fs->inode_map = g_sequence_new(NULL);

    fs->log_state = g_new0(BlueSkyCloudLogState, 1);
    fs->log_state->data = g_string_new("");
    fs->log_state->latest_cleaner_seq_seen = -1;
    fs->log_state->uploads_pending_lock = g_mutex_new();
    fs->log_state->uploads_pending_cond = g_cond_new();

    bluesky_cloudlog_threads_init(fs);
    fs->inode_fetch_thread_pool = g_thread_pool_new(inode_fetch_task, NULL,
                                  bluesky_max_threads,
                                  FALSE, NULL);

    return fs;
}
Exemplo n.º 9
0
int main (int argc, char** argv)
{
    gchar *filename;

    // open the file
    if (argc > 1) {
	filename = argv[1];
    } else {
	filename = "emma.txt";
    }

    FILE *fp = g_fopen(filename, "r");
    if (fp == NULL) {
	perror (filename);
	exit (-10);
    }
    /* string array is a (two-L) NULL terminated array of pointers to
       (one-L) NUL terminated strings */

    gchar **array;
    gchar line[128];

    GHashTable* hash = g_hash_table_new_full (g_str_hash, 
					      g_str_equal,
					      g_free,
					      g_free);

    int i;

    // read lines from the file and build the hash table
    while (1) {
	gchar *res = fgets (line, sizeof(line), fp);
	if (res == NULL) break;

	array = g_strsplit (line, " ", 0);
	for (i=0; array[i] != NULL; i++) {
	    incr (hash, array[i]);
	}
	g_strfreev (array);
    }
    fclose (fp);

    // print the hash table
    // g_hash_table_foreach (hash,  (GHFunc) kv_printor, "Word %s freq %d\n");

    // iterate the hash table and build the sequence
    GSequence *seq = g_sequence_new ((GDestroyNotify) pair_destructor);
    g_hash_table_foreach (hash,  (GHFunc) accumulator, (gpointer) seq);

    // iterate the sequence and print the pairs
    g_sequence_foreach (seq,  (GFunc) pair_printor, NULL);

    // free everything
    g_hash_table_destroy (hash);

    g_sequence_free (seq);
    
    return 0;
}
Exemplo n.º 10
0
static IsStoreEntry *
entry_new(const gchar *name)
{
	IsStoreEntry *entry = g_slice_new0(IsStoreEntry);
	entry->name = g_strdup(name);
	entry->entries = g_sequence_new((GDestroyNotify)entry_free);
	return entry;
}
Exemplo n.º 11
0
struct segment* new_segment() {
	struct segment * s = (struct segment*) malloc(sizeof(struct segment));
	s->id = TEMPORARY_ID;
	s->chunk_num = 0;
	s->chunks = g_sequence_new(NULL);
	s->features = NULL;
	return s;
}
Exemplo n.º 12
0
static GSequence*
_sequence_new (gchar *data)
{
    GSequence *value = NULL;
    value = g_sequence_new (NULL);
    g_sequence_append (value, (guint8 *)data);
    return value;
}
Exemplo n.º 13
0
RmOffsetTable rm_offset_create_table(const char *path) {
    int fd = rm_sys_open(path, O_RDONLY);
    if(fd == -1) {
        rm_log_info("Error opening %s in setup_fiemap_extents\n", path);
        return NULL;
    }

    /* struct fiemap does not allocate any extents by default,
     * so we choose ourself how many of them we allocate.
     * */
    const int n_extents = 256;
    struct fiemap *fiemap = g_malloc0(sizeof(struct fiemap) + n_extents * sizeof(struct fiemap_extent));
    struct fiemap_extent *fm_ext = fiemap->fm_extents;

    /* data structure we save our offsets in */
    GSequence *self = g_sequence_new((GFreeFunc)rm_offset_free_func);

    bool last = false;
    while(!last) {
        fiemap->fm_flags = 0;
        fiemap->fm_extent_count = n_extents;
        fiemap->fm_length = FIEMAP_MAX_OFFSET;

        if(ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap) == -1) {
            break;
        }

        /* This might happen on empty files - those have no
         * extents, but they have an offset on the disk.
         */
        if(fiemap->fm_mapped_extents <= 0) {
            break;
        }

        /* used for detecting contiguous extents, which we ignore */
        unsigned long expected = 0;

        /* Remember all non contiguous extents */
        for(unsigned i = 0; i < fiemap->fm_mapped_extents && !last; i++) {
            if (i == 0 || fm_ext[i].fe_physical != expected) {
                RmOffsetEntry *offset_entry = g_slice_new(RmOffsetEntry);
                offset_entry->logical = fm_ext[i].fe_logical;
                offset_entry->physical = fm_ext[i].fe_physical;
                g_sequence_append(self, offset_entry);
            }

            expected = fm_ext[i].fe_physical + fm_ext[i].fe_length;
            fiemap->fm_start = fm_ext[i].fe_logical + fm_ext[i].fe_length;
            last = fm_ext[i].fe_flags & FIEMAP_EXTENT_LAST;
        }
    }

    rm_sys_close(fd);
    g_free(fiemap);

    g_sequence_sort(self, (GCompareDataFunc)rm_offset_sort_logical, NULL);
    return self;
}
Exemplo n.º 14
0
static void lbmc_stream_dlg_reset_stream_table(lbmc_stream_dlg_info_t * info)
{
    if (info->stream_table != NULL)
    {
        g_sequence_free(info->stream_table);
        info->stream_table = NULL;
    }
    info->stream_table = g_sequence_new(lbmc_stream_dlg_stream_entry_destroy_cb);
}
Exemplo n.º 15
0
static void
g_dbus_menu_group_changed (GDBusMenuGroup *group,
                           guint           menu_id,
                           gint            position,
                           gint            removed,
                           GVariant       *added)
{
  GSequenceIter *point;
  GVariantIter iter;
  GDBusMenuModel *proxy;
  GSequence *items;
  GVariant *item;
  gint n_added;

  /* We could have signals coming to us when we're not active (due to
   * some other process having subscribed to this group) or when we're
   * pending.  In both of those cases, we want to ignore the signal
   * since we'll get our own information when we call "Start" for
   * ourselves.
   */
  if (group->state != GROUP_ONLINE)
    return;

  items = g_hash_table_lookup (group->menus, GINT_TO_POINTER (menu_id));

  if (items == NULL)
    {
      items = g_sequence_new (g_dbus_menu_model_item_free);
      g_hash_table_insert (group->menus, GINT_TO_POINTER (menu_id), items);
    }

  point = g_sequence_get_iter_at_pos (items, position + removed);

  g_return_if_fail (point != NULL);

  if (removed)
    {
      GSequenceIter *start;

      start = g_sequence_get_iter_at_pos (items, position);
      g_sequence_remove_range (start, point);
    }

  n_added = g_variant_iter_init (&iter, added);
  while (g_variant_iter_loop (&iter, "@a{sv}", &item))
    g_sequence_insert_before (point, g_dbus_menu_group_create_item (item));

  if (g_sequence_get_length (items) == 0)
    {
      g_hash_table_remove (group->menus, GINT_TO_POINTER (menu_id));
      items = NULL;
    }

  if ((proxy = g_hash_table_lookup (group->proxies, GINT_TO_POINTER (menu_id))))
    g_dbus_menu_model_changed (proxy, items, position, removed, n_added);
}
Exemplo n.º 16
0
static void
ide_recent_projects_init (IdeRecentProjects *self)
{
  self->projects = g_sequence_new (g_object_unref);
  self->recent_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
  self->file_uri = g_build_filename (g_get_user_data_dir (),
                                     ide_get_program_name (),
                                     IDE_RECENT_PROJECTS_BOOKMARK_FILENAME,
                                     NULL);
}
Exemplo n.º 17
0
GtkWidget * splittable_collection_new()
{
	SplittableCollection * sc = g_object_new(VEX_TYPE_SPLITTABLE_COLLECTION, NULL);

	sc -> descendents_to_splittables = g_map_new(compare_pointers, NULL);
	sc -> splittables = g_sequence_new(NULL);
	sc -> focussed_descendent = NULL;

	return GTK_WIDGET(sc);
}
Exemplo n.º 18
0
static void
fm_ogl_model_init (FMOGLModel *model)
{
	model->details = g_new0 (FMOGLModelDetails, 1);
	model->details->files = g_sequence_new ((GDestroyNotify)file_entry_free);
	model->details->top_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
	model->details->directory_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
	model->details->stamp = g_random_int ();
	model->details->sort_attribute = 0;
}
Exemplo n.º 19
0
/**
 * ide_debugger_address_map:
 *
 * Creates a new #IdeDebuggerAddressMap.
 *
 * The map is used to track the locations of mapped files in the inferiors
 * address space. This allows relatively quick lookup to determine what file
 * contains a given execution address (instruction pointer, etc).
 *
 * See also: ide_debugger_address_map_free()
 *
 * Returns: (transfer full): A new #IdeDebuggerAddressMap
 *
 * Since: 3.32
 */
IdeDebuggerAddressMap *
ide_debugger_address_map_new (void)
{
  IdeDebuggerAddressMap *ret;

  ret = g_slice_new0 (IdeDebuggerAddressMap);
  ret->seq = g_sequence_new (ide_debugger_address_map_entry_free);
  ret->chunk = g_string_chunk_new (4096);

  return ret;
}
Exemplo n.º 20
0
static void
is_store_init(IsStore *self)
{
	IsStorePrivate *priv =
		G_TYPE_INSTANCE_GET_PRIVATE(self, IS_TYPE_STORE,
					    IsStorePrivate);

	self->priv = priv;
	priv->entries = g_sequence_new((GDestroyNotify)entry_free);
	priv->stamp = g_random_int();
}
Exemplo n.º 21
0
static void rclib_lyric_instance_init(RCLibLyric *lyric)
{
    RCLibLyricPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(lyric,
        RCLIB_TYPE_LYRIC, RCLibLyricPrivate);
    lyric->priv = priv;
    priv->parsed_data1.seq = g_sequence_new((GDestroyNotify)
        rclib_lyric_lyric_data_free);
    priv->parsed_data2.seq = g_sequence_new((GDestroyNotify)
        rclib_lyric_lyric_data_free);
    priv->regex = g_regex_new("(?P<time>\\[[0-9]+:[0-9]+([\\.:][0-9]+)*\\])|"
        "(?P<text>[^\\]]*$)|(?P<title>\\[ti:.+\\])|(?P<artist>\\[ar:.+\\])|"
        "(?P<album>\\[al:.+\\])|(?P<author>\\[by:.+\\])|"
        "(?P<offset>\\[offset:.+\\])", 0, 0, NULL);
    priv->timer = g_timeout_add(100, (GSourceFunc)rclib_lyric_watch_timer,
        NULL);
    priv->tag_found_handler = rclib_core_signal_connect("tag-found",
        G_CALLBACK(rclib_lyric_tag_found_cb), lyric);
    priv->uri_changed_handler = rclib_core_signal_connect("uri-changed",
        G_CALLBACK(rclib_lyric_uri_changed_cb), lyric);
}
Exemplo n.º 22
0
static void
bt_pattern_list_model_init (BtPatternListModel * self)
{
  self->priv =
      G_TYPE_INSTANCE_GET_PRIVATE (self, BT_TYPE_PATTERN_LIST_MODEL,
      BtPatternListModelPrivate);

  self->priv->seq = g_sequence_new (NULL);
  // random int to check whether an iter belongs to our model
  self->priv->stamp = g_random_int ();
}
Exemplo n.º 23
0
static void
clutter_list_model_init (ClutterListModel *model)
{
  model->priv = CLUTTER_LIST_MODEL_GET_PRIVATE (model);

  model->priv->sequence = g_sequence_new (NULL);
  model->priv->temp_iter = g_object_new (CLUTTER_TYPE_LIST_MODEL_ITER,
                                         "model",
                                         model,
                                         NULL);
}
Exemplo n.º 24
0
static int
alarm_queue_create(void)
{
    gAlarmQueue = g_new0(_AlarmQueue, 1);
    gAlarmQueue->alarms = g_sequence_new((GDestroyNotify)alarm_free);
    gAlarmQueue->seq_id = 0;

    gAlarmQueue->alarm_db =
        g_build_filename(PREFERENCE_DIR, "alarms.xml", NULL);

    return 0;
}
Exemplo n.º 25
0
static int
alarm_queue_create(void)
{
	gAlarmQueue = g_new0(_AlarmQueue, 1);
	gAlarmQueue->alarms = g_sequence_new((GDestroyNotify)alarm_free);
	gAlarmQueue->seq_id = 0;

	gAlarmQueue->alarm_db =
	    g_build_filename(gSleepConfig.preference_dir, "alarms.xml", NULL);

	return 0;
}
Exemplo n.º 26
0
static void
gst_rtsp_mount_points_init (GstRTSPMountPoints * mounts)
{
  GstRTSPMountPointsPrivate *priv = GST_RTSP_MOUNT_POINTS_GET_PRIVATE (mounts);

  GST_DEBUG_OBJECT (mounts, "created");

  mounts->priv = priv;

  g_mutex_init (&priv->lock);
  priv->mounts = g_sequence_new (data_item_free);
  priv->dirty = FALSE;
}
Exemplo n.º 27
0
static void
photos_base_manager_init (PhotosBaseManager *self)
{
  PhotosBaseManagerPrivate *priv;

  priv = photos_base_manager_get_instance_private (self);
  priv->objects = g_hash_table_new_full (g_str_hash,
                                         g_str_equal,
                                         g_free,
                                         (GDestroyNotify) photos_base_manager_object_data_free);
  priv->sequence = g_sequence_new (g_object_unref);
  priv->last_position = G_MAXUINT;
}
Exemplo n.º 28
0
static gboolean
idle_populate_proposals (GscProviderDevhelp *devhelp)
{
	guint idx = 0;

	if (devhelp->priv->view == NULL)
	{
		devhelp->priv->proposals = g_sequence_new ((GDestroyNotify)g_object_unref);
		devhelp->priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
		devhelp->priv->view = dh_assistant_view_new ();

		gtk_widget_show (devhelp->priv->view);

		gtk_container_add (GTK_CONTAINER (devhelp->priv->scrolled_window),
				   devhelp->priv->view);

		dh_assistant_view_set_base (DH_ASSISTANT_VIEW (devhelp->priv->view), 
		                            devhelp->priv->dhbase);

		gtk_widget_set_size_request (devhelp->priv->scrolled_window,
					     400, 300);
		
		devhelp->priv->populateptr = dh_base_get_keywords (devhelp->priv->dhbase);
	}
	
	while (idx < POPULATE_BATCH && devhelp->priv->populateptr)
	{
		DhLink *link = (DhLink *)devhelp->priv->populateptr->data;
		gchar const *name = dh_link_get_name (link);
		
		if (valid_link_type (dh_link_get_link_type (link)) &&
		    name != NULL && *name != '\0')
		{
			GscDevhelpItem *proposal = g_object_new (gsc_devhelp_item_get_type (), 
				                                     NULL);

			proposal->link = link;
			proposal->word = string_for_compare (dh_link_get_name (proposal->link));

			g_sequence_insert_sorted (devhelp->priv->proposals,
				                      proposal,
				                      (GCompareDataFunc)compare_two_items,
				                      NULL);
		}

		++idx;
		devhelp->priv->populateptr = g_list_next (devhelp->priv->populateptr);
	}
	
	return devhelp->priv->populateptr != NULL;
}
static void
rhythmdb_property_model_init (RhythmDBPropertyModel *model)
{
	model->priv = RHYTHMDB_PROPERTY_MODEL_GET_PRIVATE (model);

	model->priv->stamp = g_random_int ();

	model->priv->properties = g_sequence_new (NULL);
	model->priv->reverse_map = g_hash_table_new (g_str_hash, g_str_equal);
	model->priv->entries = g_hash_table_new (g_direct_hash, g_direct_equal);

	model->priv->all = g_new0 (RhythmDBPropertyModelEntry, 1);
	model->priv->all->string = rb_refstring_new (_("All"));

	model->priv->sort_propids = g_array_new (FALSE, FALSE, sizeof (RhythmDBPropType));
}
Exemplo n.º 30
0
EggSortedHash *
egg_sorted_hash_new (GHashFunc      hash_func,
                     GEqualFunc     equal_func,
                     GDestroyNotify key_free_func,
                     GDestroyNotify value_free_func)
{
  EggSortedHash *hash;

  hash = g_new0 (EggSortedHash, 1);

  hash->items = g_sequence_new (value_free_func);
  hash->iters = g_hash_table_new_full (hash_func, equal_func, key_free_func, NULL);
  hash->key_free_func = key_free_func;
  hash->value_free_func = value_free_func;

  return hash;
}