コード例 #1
0
ファイル: botnet-connection.c プロジェクト: svn2github/irssi
/* send botnet links to specified bot */
static void botnet_send_links(BOT_REC *bot, int downlinks)
{
	GNode *node;

	if (!downlinks) {
		/* send uplinks */
		if (bot->botnet->uplink == NULL)
			return;

		node = g_node_find(bot->botnet->bots, G_IN_ORDER,
				   G_TRAVERSE_ALL, bot->botnet->uplink);
		if (node == NULL)
			return;

		g_node_traverse(node, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1,
				(GNodeTraverseFunc) botnet_send_botinfo, bot);
		return;
	}

        /* send downlinks = all non-uplink nodes */
	for (node = bot->botnet->bots->children; node != NULL; node = node->next) {
		BOT_REC *rec = node->data;

		if (rec == bot || rec->uplink || !rec->connected)
			continue;

		g_node_traverse(node, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1,
				(GNodeTraverseFunc) botnet_send_botinfo, bot);
	}
}
コード例 #2
0
ファイル: state.cpp プロジェクト: Patrick6289/navguide
/* apply the observation update to the belief state
 * limiting the application to <radius> distance to edge <e>
 */
void state_observation_update (dijk_graph_t *dg, dijk_edge_t *e, int radius, navlcm_feature_list_t *f, GQueue *path, double *variance)
{
    if (!e || !e->start)
        return;

    // convert to dual tree
    GNode *tr = dijk_to_tree (e->start, radius);

    // apply observation update to the tree 
    g_node_traverse (tr, G_PRE_ORDER, G_TRAVERSE_ALL, -1, state_observation_cb, f);

    // compute variance across tree
    *variance = .0;
    g_node_traverse (tr, G_PRE_ORDER, G_TRAVERSE_ALL, -1, state_compute_variance_cb, variance);
    *variance /= radius;

    // destroy tree
    g_node_destroy (tr);

    // set to zero for all nodes out of the tree
    for (GList *iter=g_queue_peek_head_link(dg->nodes);iter;iter=iter->next) {
        dijk_node_t *nd = (dijk_node_t*)iter->data;
        if (nd->timestamp != f->utime) {
            nd->pdf0 = .0;
            nd->pdf1 = .0;
        }
    }

    // hack: set to zero for all nodes out of the path
    for (GList *iter=g_queue_peek_head_link(dg->nodes);iter;iter=iter->next) {
        dijk_node_t *nd = (dijk_node_t*)iter->data;
        if (!path) continue;
        gboolean on_path = FALSE;
        for (GList *eiter=g_queue_peek_head_link (path);eiter;eiter=eiter->next) {
            dijk_edge_t *e = (dijk_edge_t*)eiter->data;
            if (e->start == nd || e->end == nd) {
                on_path = TRUE;
            }
        }
        if (!on_path) {
    //        nd->pdf0 = .0;
    //        nd->pdf1 = .0;
        }
    }

    // normalize
    double t = state_sum (dg);

    if (t > 1E-6) {
        for (GList *iter=g_queue_peek_head_link(dg->nodes);iter;iter=iter->next) {
            dijk_node_t *nd = (dijk_node_t*)iter->data;
            nd->pdf1 /= t;
        }
    }

}
コード例 #3
0
static void
ltable_remove_if  (LTable                 *ltable,
                   MateConfListenersPredicate predicate,
                   gpointer                user_data)
{
  GSList *tmp;
  struct NodeRemoveData rd;
  rd.predicate = predicate;
  rd.user_data = user_data;
  rd.dead = NULL;
  
  if (ltable->tree == NULL)
    return;
  
  g_node_traverse (ltable->tree,
                   G_IN_ORDER,
                   G_TRAVERSE_ALL,
                   -1,
                   node_remove_func,
                   &rd);

  tmp = rd.dead;
  while (tmp != NULL)
    {
      ltable_remove (ltable, GPOINTER_TO_INT (tmp->data));

      tmp = g_slist_next (tmp);
    }

  g_slist_free (rd.dead);
}
コード例 #4
0
ファイル: clutter-score.c プロジェクト: gramozeka/GSB-NEW
/**
 * clutter_score_remove:
 * @score: a #ClutterScore
 * @id: the id of the timeline to remove
 *
 * Removes the #ClutterTimeline with the given id inside @score. If
 * the timeline has other timelines attached to it, those are removed
 * as well.
 *
 * Since: 0.6
 */
void
clutter_score_remove (ClutterScore *score,
                      gulong        id)
{
  ClutterScorePrivate *priv;
  TraverseClosure closure;

  g_return_if_fail (CLUTTER_IS_SCORE (score));
  g_return_if_fail (id > 0);

  priv = score->priv;

  closure.action = REMOVE_BY_ID;
  closure.score = score;
  closure.d.id = id;
  closure.result = NULL;

  g_node_traverse (priv->root,
                   G_POST_ORDER,
                   G_TRAVERSE_ALL,
                   -1,
                   traverse_children, &closure);

  if (closure.result)
    g_node_destroy (closure.result);
}
コード例 #5
0
ファイル: print_manager.c プロジェクト: Pronghorn/pronghorn
int print_manager_add_node(print_manager_t _pm, GNode * node)
{
  prong_assert(_pm != NULL);
  prong_assert(node != NULL);
  struct print_manager *pm = (struct print_manager *) _pm;

  prong_assert(pm->magic == PRINT_MANAGER_MAGIC);

  // Traversing through all nodes, dividing the abs_offset to be a block offset
  // and recording their block ranges
  g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) divide_abs_off_and_record_block_ranges, pm);

  // Setting the nodes 'parent' to be itself
  struct job_node_data *data = (struct job_node_data *) node->data;

  data->parent_absolute_offset = contract_get_absolute_offset(data->node_contract);

//debug_print_state_of_play(pm);
  print_and_process_tree(pm, node);
  // Because this isn't part of the abs_tree we need to destroy it manually
  g_node_safe_destroy(node);

  while (do_tree_check(pm) > 0)
  {
    // Do nothing
  }

  return 0;
}
コード例 #6
0
ファイル: parse.c プロジェクト: tfogal/qdv
/** Calls the destructor on every element of the tree. */
void
destroy(GNode* root)
{
  g_debug("Destroying %p...", root);
  g_node_traverse(root, G_POST_ORDER, G_TRAVERSE_ALL, -1, destroy_, NULL);
  g_node_destroy(root);
}
コード例 #7
0
ファイル: parse.c プロジェクト: tfogal/qdv
void
pt_print(GNode* root)
{
  g_node_traverse(root, G_PRE_ORDER, G_TRAVERSE_LEAVES, VISIT_ALL_NODES,
                  print_, stdout);
  g_print("\n");
}
コード例 #8
0
ファイル: commit2.cpp プロジェクト: beamerblvd/vyatta-cfg
static boolean
validate_configuration(GNode *root_node, boolean mode,
                       GSList **nodes_visited_coll) 
{
  if (root_node == NULL) {
    return FALSE;
  }

  struct Result result;
  result._err_code = 0;
  result._mode = (int)mode;
  result._data = (void*)*nodes_visited_coll;

  //handles both syntax and commit
  result._action = syntax_act;
  g_node_traverse((GNode*)root_node,
                  G_PRE_ORDER,
                  G_TRAVERSE_ALL,
                  -1,
                  (GNodeTraverseFunc)validate_func,
                  (gpointer)&result);
  
  if (result._err_code != 0) {
    d_dplog("commit2::process_priority_node(): failure on processing "
            "pass: %d", syntax_act);
    return FALSE;
  }

  GList **c_tmp = (GList**)result._data;
  *nodes_visited_coll = (GSList*)c_tmp;
  return TRUE;
}
コード例 #9
0
static void service_item(GNode* node, __unused__ gpointer data) {
	if (!node->data) {
		node = node->children;
	} else {
		LOG(MOD "Unexpected non-sequence data at %s!\n", (char*)node->data);
	}

	if (!node->children) {
		LOG(MOD "service action %s provided but no service name to apply action to\n!", (char*)node->data);
		return;
	}

	if ((g_strcmp0(node->data, "enable") != 0) &&
	    (g_strcmp0(node->data, "disable") != 0) &&
	    (g_strcmp0(node->data, "start") != 0) &&
	    (g_strcmp0(node->data, "stop") != 0) &&
	    (g_strcmp0(node->data, "restart") != 0) &&
	    (g_strcmp0(node->data, "reload") != 0) &&
	    (g_strcmp0(node->data, "isolate") != 0) &&
	    (g_strcmp0(node->data, "mask") != 0) &&
	    (g_strcmp0(node->data, "unmask") != 0)) {
		LOG(MOD "service action %s is not a valid service action\n", (char*)node->data);
		return;
	}

	g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, service_action, node->data);
}
コード例 #10
0
ファイル: circle-method.c プロジェクト: Ninja-1/Circle2
static GnomeVFSResult
remove_fake_node_by_uri (const GnomeVFSURI *uri)
{
	FakeNode *file;
	GNode    *gnode;

	file = get_fake_node_from_uri (uri);
	if (!file) {
		return GNOME_VFS_ERROR_INVALID_URI;
	}
	
	gnode = file->gnode;
	g_node_unlink (gnode);
	
	g_node_traverse (gnode,
			 G_PRE_ORDER,
			 G_TRAVERSE_ALL,
			 -1,
			 free_files_func,
			 NULL);

	g_node_destroy (gnode);

	print_tree (root, 0);

	return GNOME_VFS_OK;
}
コード例 #11
0
ファイル: botnet-connection.c プロジェクト: svn2github/irssi
static void cmd_bots(void)
{
	BOTNET_REC *botnet = botnet_find("ircnet");

	fprintf(stderr, "\r\n");
	g_node_traverse(botnet->bots, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1,
			(GNodeTraverseFunc) print_bot, NULL);
}
コード例 #12
0
ファイル: print_manager.c プロジェクト: Pronghorn/pronghorn
static gboolean traverse_abs_tree(long long *abs_offset, GNode * node, gpointer data)
{
  int first = 1;

  g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) debug_print_node, &first);

  return FALSE;
}
コード例 #13
0
void packages_handler(GNode *node) {
	LOG(MOD "Packages Handler running...\n");
	/*
	 * due to node possibly being a list of lists, just ignore all
	 * non-leave nodes.
	 */
	g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, packages_item, NULL);
}
コード例 #14
0
ファイル: mh.c プロジェクト: ignatenkobrain/claws
static void mh_remove_missing_folder_items(Folder *folder)
{
	cm_return_if_fail(folder != NULL);

	debug_print("searching missing folders...\n");

	g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
			mh_remove_missing_folder_items_func, folder);
}
コード例 #15
0
ファイル: xml.c プロジェクト: eworm-de/claws-mail
void xml_free_tree(GNode *node)
{
	cm_return_if_fail(node != NULL);

	g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, xml_free_func,
			NULL);

	g_node_destroy(node);
}
コード例 #16
0
ファイル: clutter-score.c プロジェクト: gramozeka/GSB-NEW
/* multi-purpose traversal function for the N-ary tree used by the score */
static gboolean
traverse_children (GNode    *node,
                   gpointer  data)
{
  TraverseClosure *closure = data;
  ClutterScoreEntry *entry = node->data;
  gboolean retval = FALSE;

  /* root */
  if (!entry)
    return TRUE;

  switch (closure->action)
    {
    case FIND_BY_TIMELINE:
      if (closure->d.timeline == entry->timeline)
        {
          closure->result = node;
          retval = TRUE;
        }
      break;

    case FIND_BY_ID:
      if (closure->d.id == entry->id)
        {
          closure->result = node;
          retval = TRUE;
        }
      break;

    case REMOVE_BY_ID:
      if (closure->d.id == entry->id)
        {
          /* Destroy all the child entries of this node */
          g_node_traverse (node,
                           G_POST_ORDER,
                           G_TRAVERSE_ALL,
                           -1,
                           destroy_entry, NULL);

          /* Keep track of this node so that it will be destroyed
             further up */
          closure->result = node;

          retval = TRUE;
        }
      break;

    case LIST_TIMELINES:
      closure->result = g_slist_prepend (closure->result, entry->timeline);
      retval = FALSE;
      break;
    }

  return retval;
}
コード例 #17
0
void
glade_model_data_tree_free (GNode * node)
{
  if (node)
    {
      g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1,
                       (GNodeTraverseFunc) model_data_traverse_free, NULL);
      g_node_destroy (node);
    }
}
コード例 #18
0
ファイル: print_manager.c プロジェクト: Pronghorn/pronghorn
void g_node_safe_destroy(GNode * node)
{
//printf("Destroying node\n");
  prong_assert(node != NULL);
  g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) free_job_node, NULL);

  // Free nodes themselves
  g_node_destroy(node);
//printf("Finished destroying node\n");
}
コード例 #19
0
ファイル: commit2.cpp プロジェクト: beamerblvd/vyatta-cfg
/**
 * Gets a flat collection of nodes, sorted by priority
 **/
GNode*
get_transactions(GNode *config, boolean priority_mode)
{
  d_dplog("commit2::get_transactions()");
  if (config == NULL) {
    return NULL;
  }

  gpointer gp = ((GNode*)config)->data;

  GNode *trans_root = g_node_new(gp);
  if (priority_mode) {
    g_node_traverse(config,
                    G_POST_ORDER,
                    G_TRAVERSE_ALL,
                    -1,
                    (GNodeTraverseFunc)sort_func_priority,
                    (gpointer)trans_root);

    //only do this if the root isn't empty
    if (g_node_n_children(config) != 0) {
      g_node_insert(trans_root,-1,config); //add what's left
    }

    //now need pass to handle extended priority system
    g_node_traverse(trans_root,
                    G_POST_ORDER,
                    G_TRAVERSE_ALL,
                    -1,
                    (GNodeTraverseFunc)sort_func_priority_extended,
                    (gpointer)trans_root);
  }
  else {
    g_node_traverse(config,
                    G_IN_ORDER,
                    G_TRAVERSE_ALL,
                    -1,
                    (GNodeTraverseFunc)sort_func_simple,
                    (gpointer)trans_root);
  }
  return trans_root;
}
コード例 #20
0
/*
	Free a previously allocated tree
*/
int vat_free(GNode **tree)
{
	if (*tree != NULL) 
	{
	    g_node_traverse(*tree, G_IN_ORDER, G_TRAVERSE_ALL, -1, free_vse, NULL);
		g_node_destroy(*tree);
		*tree = NULL;
	}

	return 0;
}
コード例 #21
0
ファイル: as-node.c プロジェクト: cosimoc/appstream-glib
/**
 * as_node_unref:
 * @node: a #AsNode.
 *
 * Deallocates all notes in the tree.
 *
 * Since: 0.1.0
 **/
void
as_node_unref (AsNode *node)
{
	g_node_traverse (node,
			 G_PRE_ORDER,
			 G_TRAVERSE_ALL,
			 -1,
			 as_node_destroy_node_cb,
			 NULL);
	g_node_destroy (node);
}
コード例 #22
0
ファイル: url-router.c プロジェクト: catch/postal
void
url_router_free (UrlRouter *router)
{
   g_node_traverse(router,
                   G_POST_ORDER,
                   G_TRAVERSE_ALL,
                   -1,
                   url_node_data_free_func,
                   NULL);
   g_node_destroy(router);
}
コード例 #23
0
void ssh_authorized_keys_handler(GNode *node) {
	LOG(MOD "SSH authorized keys Handler running...\n");
	gchar *username = cloud_config_get_global("first_user");
	if (!username) {
		username = DEFAULT_USER_USERNAME;
	}

	LOG(MOD "User %s\n", (char*)username);
	g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES,
			-1, ssh_authorized_keys_item, username);
}
コード例 #24
0
ファイル: botnet.c プロジェクト: svn2github/irssi
BOT_REC *botnet_find_master(BOTNET_REC *botnet, BOT_REC *old_master)
{
	BOT_FIND_REC rec;

	g_return_val_if_fail(botnet != NULL, NULL);

	rec.node = NULL;
	rec.priority = old_master == NULL ? -1 : old_master->priority;
	g_node_traverse(botnet->bots, 0, G_TRAVERSE_ALL, -1,
			(GNodeTraverseFunc) gnode_find_master, &rec);
	return rec.node == NULL ? old_master : rec.node->data;
}
コード例 #25
0
ファイル: mh.c プロジェクト: ignatenkobrain/claws
static gint mh_rename_folder(Folder *folder, FolderItem *item,
			     const gchar *name)
{
 	gchar *real_name;
	gchar *oldpath;
	gchar *dirname;
	gchar *newpath, *utf8newpath;
	gchar *paths[2];

	cm_return_val_if_fail(folder != NULL, -1);
	cm_return_val_if_fail(item != NULL, -1);
	cm_return_val_if_fail(item->path != NULL, -1);
	cm_return_val_if_fail(name != NULL, -1);

	oldpath = folder_item_get_path(item);
	if (!is_dir_exist(oldpath))
		make_dir_hier(oldpath);

	dirname = g_path_get_dirname(oldpath);
	real_name = mh_filename_from_utf8(name);
	newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
	g_free(real_name);

	if (g_rename(oldpath, newpath) < 0) {
		FILE_OP_ERROR(oldpath, "rename");
		g_free(oldpath);
		g_free(newpath);
		return -1;
	}

	g_free(oldpath);
	g_free(newpath);

	if (strchr(item->path, G_DIR_SEPARATOR) != NULL) {
		dirname = g_path_get_dirname(item->path);
		utf8newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S,
					  name, NULL);
		g_free(dirname);
	} else
		utf8newpath = g_strdup(name);

	g_free(item->name);
	item->name = g_strdup(name);

	paths[0] = g_strdup(item->path);
	paths[1] = utf8newpath;
	g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
			mh_rename_folder_func, paths);

	g_free(paths[0]);
	g_free(paths[1]);
	return 0;
}
コード例 #26
0
    void
ph_stats_free(ph_stats_t *ps)
{
    if (ps->stats_tree) {
        g_node_traverse(ps->stats_tree, G_IN_ORDER,
                G_TRAVERSE_ALL, -1,
                stat_node_free, NULL);
        g_node_destroy(ps->stats_tree);
    }

    g_free(ps);
}
コード例 #27
0
ファイル: test-menu-parser.c プロジェクト: Distrotech/garcon
static void
print_child_nodes (GNode *node,
                   gint   depth)
{
  GNode *child;

  for (child = g_node_first_child (node); child != NULL; child = g_node_next_sibling (child))
    {
      g_node_traverse (child, G_PRE_ORDER, G_TRAVERSE_ALL, 1,
                       (GNodeTraverseFunc) print_node, GINT_TO_POINTER (depth+2));
    }
}
コード例 #28
0
ファイル: tracker-storage.c プロジェクト: Codeminded/tracker
static void
mount_node_free (GNode *node)
{
	g_node_traverse (node,
	                 G_POST_ORDER,
	                 G_TRAVERSE_ALL,
	                 -1,
	                 mount_info_free,
	                 NULL);

	g_node_destroy (node);
}
コード例 #29
0
ファイル: clutter-score.c プロジェクト: gramozeka/GSB-NEW
static inline void
clutter_score_clear (ClutterScore *score)
{
  ClutterScorePrivate *priv = score->priv;

  g_node_traverse (priv->root,
                   G_POST_ORDER,
                   G_TRAVERSE_ALL,
                   -1,
                   destroy_entry, NULL);
  g_node_destroy (priv->root);
}
コード例 #30
0
ファイル: commit2.cpp プロジェクト: beamerblvd/vyatta-cfg
/**
 * Look for begin/end statements to begin processing
 * of actions.
 **/
static gboolean
enclosing_process_func(GNode *node, gpointer data)
{
  if (node == NULL) {
    return TRUE;
  }

  struct Result *result = (struct Result*)data;
  struct VyattaNode *gp = (struct VyattaNode *) node->data;
  struct Config *c = &(gp->_config);
  struct Data *d = &(gp->_data);

  //does this node contain a begin or end statement?
  if (c->_def.actions  && (c->_def.actions[end_act].vtw_list_head
                           || c->_def.actions[begin_act].vtw_list_head)) {
    /* gotten to this point need to do a call around this enclosing
     * being/end node
     */
    g_node_unlink(node); //removed this...

    d_dplog("commit2::enclosing_process_func(): enclosing statement found "
            "on: %s", d->_path);
    //perform recursive calling on new process node...

    int i;
    for (i = 0; i < g_num_actions; ++i) {
      // again should be enum
      GTraverseType order;
      if (delete_act != ActionOrder[i]) {
        order = G_PRE_ORDER;
      }
      else {
        order = G_POST_ORDER;
      }

      result->_action = ActionOrder[i];
      g_node_traverse((GNode*)node,
                      order,
                      G_TRAVERSE_ALL,
                      -1,
                      (GNodeTraverseFunc)process_func,
                      (gpointer)result);
    
      if (result->_err_code != 0) {
        //EXECUTE_LIST RETURNS FALSE ON FAILURE....
        d_dplog("commit2::enclosing_process_func(): FAILURE: status: %d",
                result->_err_code);
        return TRUE; //WILL STOP AT THIS POINT
      }
    }
  }
  return FALSE;
}