コード例 #1
0
ファイル: shd-internetwork.c プロジェクト: ln5/shadow
void internetwork_connectNetworks(Internetwork* internet, GQuark sourceClusterID, GQuark destinationClusterID,
		guint64 latency, guint64 jitter, gdouble packetloss, guint64 latencymin, guint64 latencyQ1,
		guint64 latencymean, guint64 latencyQ3, guint64 latencymax) {
	MAGIC_ASSERT(internet);
	g_assert(!internet->isReadOnly);

	/* lookup our networks */
	Network* sourceNetwork = internetwork_getNetwork(internet, sourceClusterID);
	Network* destinationNetwork = internetwork_getNetwork(internet, destinationClusterID);
	g_assert(sourceNetwork && destinationNetwork);

	/* create the links */
	Link* link = link_new(sourceNetwork, destinationNetwork, latency, jitter, packetloss,
			latencymin, latencyQ1, latencymean, latencyQ3, latencymax);
	network_addLink(sourceNetwork, link);
	_internetwork_trackLatency(internet, link);

	/* if not the same clusters, create the reverse link */
	if(sourceClusterID != destinationClusterID) {
	    link = link_new(destinationNetwork, sourceNetwork, latency, jitter, packetloss,
				latencymin, latencyQ1, latencymean, latencyQ3, latencymax);
	    network_addLink(destinationNetwork, link);
        _internetwork_trackLatency(internet, link);
	}
}
コード例 #2
0
ファイル: link.c プロジェクト: fd/telehash-c
link_t link_key(mesh_t mesh, lob_t key)
{
  uint8_t csid;
  hashname_t hn;
  link_t link;

  if(!mesh || !key) return LOG("invalid args");
  csid = hashname_id(mesh->keys,key);
  if(!csid) return LOG("no supported key");

  hn = hashname_key(key);
  if(!hn) return LOG("invalid key");

  link = link_get(mesh, hn->hashname);
  if(link)
  {
    hashname_free(hn);
  }else{
    link = link_new(mesh,hn);
  }

  // load key if it's not yet
  if(!link->key) return link_load(link, csid, key);

  return link;
}
コード例 #3
0
ファイル: tool_link.c プロジェクト: GNOME/horizon
static void
tool_link_set_state_link (Label    *label,
			  gpointer  data)
{
  Tool     *tool = data;
  Easel    *easel = tool->easel;
  View     *view  = (View*)easel;
  ToolLink *tool_link = data;
  Link     *link;

  if (tool_link->src.width == 0)
    return;

  link = link_new ();
  link_set_src (link, tool_link->src.x, tool_link->src.y,
                      tool_link->src.width, tool_link->src.height);
  link_set_dst (link, tool_link->dst.x, tool_link->dst.y,
                      tool_link->dst.width, tool_link->dst.height);
  links_add (link);

  horizon_status (tool->horizon, "Creating link..");
  action (tool->horizon, "refresh");
  
  link_redraw (view_get_canvas (view), link);
  view_set_rect_visible (view, FALSE);
  tool_link_set_state_dst (NULL, tool);
  horizon_status (tool->horizon, "Created link.");
}
コード例 #4
0
ファイル: link.c プロジェクト: GNOME/horizon
void
links_load (const char *path)
{
  FILE *file;
  char buf[256];
  /*char path[256];
  sprintf (path, "%s/links", canvas->path);*/

  file = fopen (path, "r");
  if (!file)
    {
      g_warning ("unable to open link file %s for reading", path);
      return;
    }

  while (fgets (buf, 256, file))
    {
      Link *link = link_new ();
      gint src_x, src_y, src_width, src_height;
      gint dst_x, dst_y, dst_width, dst_height;

      sscanf (buf, "%i %i %i %i - %i %i %i %i\n",
         &src_x, &src_y, &src_width, &src_height,
         &dst_x, &dst_y, &dst_width, &dst_height);

      link_set_src (link, src_x, src_y, src_width, src_height);
      link_set_dst (link, dst_x, dst_y, dst_width, dst_height);

      links_add (link);
    }

  fclose (file);
  //canvas_draw_links (canvas);
}
コード例 #5
0
ファイル: ui_bookmarks.c プロジェクト: xn1224/chmsee
static void
on_bookmark_add(GtkWidget *widget, UiBookmarks *bookmarks)
{
    gchar *name;
    GList *find_link;
    Link *link;

    g_message("on_bookmark_add");

    name = g_strdup(gtk_entry_get_text(GTK_ENTRY (bookmarks->entry)));

    find_link = g_list_find_custom(bookmarks->links, bookmarks->current_uri, link_uri_compare);

    if (find_link == NULL) { /* new bookmark item */
        link = link_new(LINK_TYPE_PAGE, name, bookmarks->current_uri);
        bookmarks->links = g_list_append(bookmarks->links, link);
    } else {
        link = LINK (find_link->data);

        /* Update bookmark item name */
        if (ncase_compare_utf8_string(link->name, name) != 0) {
            g_free(link->name);
            link->name = g_strdup(name);
        }
    }

    g_free(name);
    update_bookmarks_treeview(bookmarks, link->uri);
}
コード例 #6
0
/* Randomly select something to do with a directory */
static void operate_on_dir(struct dir_info *dir)
{
	size_t r;
	struct dir_entry_info *entry;
	struct file_info *file;

	r = tests_random_no(14);
	if (r == 0 && grow)
		/* When growing, 1 time in 14 create a file */
		file_new(dir, make_name(dir));
	else if (r == 1 && grow)
		/* When growing, 1 time in 14 create a directory */
		dir_new(dir, make_name(dir));
	else if (r == 2 && grow && (file = pick_file()) != NULL)
		/* When growing, 1 time in 14 create a hard link */
		link_new(dir, make_name(dir), file);
	else if (r == 3 && grow && tests_random_no(5) == 0)
		/* When growing, 1 time in 70 create a symbolic link */
		symlink_new(dir, make_name(dir));
	else {
		/* Otherwise randomly select an entry to operate on */
		r = tests_random_no(dir->number_of_entries);
		entry = dir->first;
		while (entry && r) {
			entry = entry->next;
			--r;
		}
		if (entry)
			operate_on_entry(entry);
	}
}
コード例 #7
0
ファイル: u_lst.c プロジェクト: BlackBoxe/minuit
// add an item to the list, make a new link, push it back
t_link *lst_add(t_lst *lst,void *data,const char *name)
{
	t_link *link=link_new(name);
	link->data=data;
	lst_push_back(lst,link);
	return link;
}
コード例 #8
0
ファイル: sparse.c プロジェクト: AsherBond/MondocosmOS
struct BM *BM_create_sparse(int x, int y)
{
    struct BM *map;
    int i;

    if (NULL == (map = (struct BM *)malloc(sizeof(struct BM))))
	return (NULL);
    map->bytes = (x + 7) / 8;

    if (NULL == (map->data = (unsigned char *)
		 malloc(sizeof(struct BMlink *) * y)))
	return (NULL);

    map->rows = y;
    map->cols = x;
    map->sparse = 1;

    link_set_chunk_size(500);
    map->token = link_init(sizeof(struct BMlink));

    for (i = 0; i < map->rows; i++) {
	((struct BMlink **)(map->data))[i] =
	    (struct BMlink *)link_new(map->token);
	((struct BMlink **)(map->data))[i]->count = x;
	((struct BMlink **)(map->data))[i]->val = 0;
	((struct BMlink **)(map->data))[i]->next = NULL;
    }


    depth++;

    return map;
}
コード例 #9
0
ファイル: link.c プロジェクト: telehash/telehash-c
link_t link_get(mesh_t mesh, hashname_t id)
{
  link_t link;

  if(!mesh || !id) return LOG("invalid args");
  for(link = mesh->links;link;link = link->next) if(hashname_cmp(id,link->id) == 0) return link;
  return link_new(mesh,id);
}
コード例 #10
0
ファイル: link.c プロジェクト: fd/telehash-c
link_t link_get(mesh_t mesh, char *hashname)
{
  link_t link;
  hashname_t id;

  if(!mesh || !hashname) return LOG("invalid args");
  link = xht_get(mesh->index,hashname);
  if(!link)
  {
    id = hashname_str(hashname);
    if(!id) return LOG("invalid hashname %s",hashname);
    link = link_new(mesh,id);
  }

  return link;
}
コード例 #11
0
ファイル: wifid.c プロジェクト: albfan/miraclecast
static void manager_add_udev_link(struct manager *m,
				  struct udev_device *d)
{
	struct link *l;
	unsigned int ifindex;
	const char *ifname;
	int r;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return;

	ifname = udev_device_get_property_value(d, "INTERFACE");
	if (!ifname)
		return;

	if (interface_name && strcmp(interface_name, ifname)) {
		return;
	}

	/* ignore dynamic p2p interfaces */
	if (shl_startswith(ifname, "p2p-"))
		return;

	r = link_new(m, ifindex, ifname, &l);
	if (r < 0)
		return;

   if (m->friendly_name && l->managed)
	   link_set_friendly_name(l, m->friendly_name);
   if (m->config_methods)
	   link_set_config_methods(l, m->config_methods);

	if(use_dev)
        link_use_dev(l);

#ifdef RELY_UDEV
	bool managed = udev_device_has_tag(d, "miracle") && !lazy_managed;
#else
	bool managed = (!interface_name || !strcmp(interface_name, ifname)) && !lazy_managed;
#endif
	if (managed) {
		link_set_managed(l, true);
	} else {
		log_debug("ignored device: %s", ifname);
	}
}
コード例 #12
0
static void test_link(Manager *manager, struct udev_device *loopback) {
        Link *link = NULL;

        assert_se(link_new(manager, loopback, &link) >= 0);
        assert_se(link);
}
コード例 #13
0
ファイル: wifid.c プロジェクト: Al3n/miraclecast
static void manager_add_udev_link(struct manager *m,
				  struct udev_device *d)
{
	struct link *l;
	unsigned int ifindex;
	const char *ifname;
	int r;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return;

	ifname = udev_device_get_property_value(d, "INTERFACE");
	if (!ifname)
		return;

	if (interface_name && strcmp(interface_name, ifname)) {
		return;
	}

	/* ignore dynamic p2p interfaces */
	if (shl_startswith(ifname, "p2p-"))
		return;

	r = link_new(m, ifindex, ifname, &l);
	if (r < 0)
		return;

	link_set_friendly_name(l, m->friendly_name);

#ifdef RELY_UDEV
	if (udev_device_has_tag(d, "miracle")) {
#else
	if (!interface_name || !strcmp(interface_name, ifname)) {
#endif
		link_set_managed(l, true);
	} else {
		log_debug("ignored device: %s", ifname);
	}
}

static int manager_udev_fn(sd_event_source *source,
			   int fd,
			   uint32_t mask,
			   void *data)
{
	_cleanup_udev_device_ struct udev_device *d = NULL;
	struct manager *m = data;
	const char *action, *ifname;
	unsigned int ifindex;
	struct link *l;

	d = udev_monitor_receive_device(m->udev_mon);
	if (!d)
		return 0;

	ifindex = ifindex_from_udev_device(d);
	if (!ifindex)
		return 0;

	l = manager_find_link(m, ifindex);

	action = udev_device_get_action(d);
	if (action && !strcmp(action, "remove")) {
		if (l)
			link_free(l);
	} else if (l) {
		ifname = udev_device_get_property_value(d, "INTERFACE");
		if (action && !strcmp(action, "move")) {
			if (ifname)
				link_renamed(l, ifname);
		}

#ifdef RELY_UDEV
		if (udev_device_has_tag(d, "miracle"))
			link_set_managed(l, true);
		else
			link_set_managed(l, false);
#else
		if (!interface_name || !strcmp(interface_name, ifname)) {
			link_set_managed(l, true);
		} else {
			log_debug("ignored device: %s", ifname);
		}
#endif
	} else {
		manager_add_udev_link(m, d);
	}

	return 0;
}
コード例 #14
0
ファイル: sparse.c プロジェクト: AsherBond/MondocosmOS
int BM_set_sparse(struct BM *map, int x, int y, int val)
{
    struct BMlink *p, *p2, *prev;
    int cur_x = 0;
    int Tcount, Tval;
    int dist_a, dist_b;

    val = !(!val);		/* set val == 1 or 0 */

    p = ((struct BMlink **)(map->data))[y];
    prev = NULL;
    while (p != NULL) {
	if (cur_x + p->count > x) {
	    if (p->val == val)	/* no change */
		return 0;

	    Tcount = p->count;	/* save current state */
	    Tval = p->val;

	    /* if x is on edge, then we probably want to merge it with 
	     ** its neighbor for efficiency 
	     */

	    /* dist_a is how far x is from Left  edge of group */
	    /* dist_b is how far x is from right edge of group */

	    dist_a = x - cur_x;
	    dist_b = (cur_x + p->count - 1) - x;

	    /* if on both edges, then we should be able to  merge 3 into one */
	    if (dist_b == 0 && p->next && p->next->val == val) {
		if (dist_a == 0 && x > 0) {
		    if (prev != NULL && prev->val == val) {
			prev->count += p->next->count + 1;
			prev->next = p->next->next;
			link_dispose(map->token, (VOID_T *) p->next);
			link_dispose(map->token, (VOID_T *) p);
			return 0;
		    }
		}
	    }

	    /* handle right edge merge */
	    if (dist_b == 0 && p->next && p->next->val == val) {
		p->count--;
		p->next->count++;
		if (p->count == 0) {
		    if (prev) {
			prev->next = p->next;
		    }
		    else {
			((struct BMlink **)(map->data))[y] = p->next;
		    }
		    link_dispose(map->token, (VOID_T *) p);
		}
		return 0;
	    }

	    /* handle left edge merge */
	    if (dist_a == 0 && x > 0) {

		if (prev != NULL && prev->val == val) {
		    prev->count++;
		    p->count--;
		    if (p->count == 0) {
			prev->next = p->next;
			link_dispose(map->token, (VOID_T *) p);
		    }
		    return 0;
		}
	    }

	    /* if not on edge, have to add link for each side */
	    if (dist_a > 0) {
		p->count = dist_a;
		p->val = Tval;
		p2 = (struct BMlink *)link_new(map->token);
		p2->next = p->next;
		p->next = p2;
		p = p2;
	    }
	    p->count = 1;
	    p->val = val;

	    if (dist_b > 0) {
		p2 = (struct BMlink *)link_new(map->token);
		p2->count = dist_b;
		p2->val = Tval;

		p2->next = p->next;
		p->next = p2;
	    }

	    return 0;

	}
	cur_x += p->count;
	prev = p;
	p = p->next;
    }

    return 0;
}