void polyconn_update_data(PolyConn *poly) { int i; DiaObject *obj = &poly->object; /* handle the case of whole points array update (via set_prop) */ if (poly->numpoints != obj->num_handles) { g_assert(0 == obj->num_connections); obj->handles = g_realloc(obj->handles, poly->numpoints*sizeof(Handle *)); obj->num_handles = poly->numpoints; for (i=0;i<poly->numpoints;i++) { obj->handles[i] = g_malloc(sizeof(Handle)); if (0 == i) setup_handle(obj->handles[i], PC_HANDLE_START); else if (i == poly->numpoints-1) setup_handle(obj->handles[i], PC_HANDLE_END); else setup_handle(obj->handles[i], PC_HANDLE_CORNER); } } /* Update handles: */ for (i=0;i<poly->numpoints;i++) { obj->handles[i]->pos = poly->points[i]; } }
void polyconn_init(PolyConn *poly, int num_points) { DiaObject *obj; int i; obj = &poly->object; object_init(obj, num_points, 0); poly->numpoints = num_points; poly->points = g_malloc(num_points*sizeof(Point)); for (i=0;i<num_points;i++) { obj->handles[i] = g_malloc(sizeof(Handle)); if (0 == i) setup_handle(obj->handles[i], PC_HANDLE_START); else if (i == num_points-1) setup_handle(obj->handles[i], PC_HANDLE_END); else setup_handle(obj->handles[i], PC_HANDLE_CORNER); } polyconn_update_data(poly); }
/* Add a point by splitting segment into two, putting the new point at 'point' or, if NULL, in the middle */ ObjectChange * beziershape_add_segment(BezierShape *bezier, int segment, Point *point) { BezPoint realpoint; BezCornerType corner_type = BEZ_CORNER_SYMMETRIC; Handle *new_handle1, *new_handle2, *new_handle3; ConnectionPoint *new_cp1, *new_cp2; Point startpoint; Point other; if (segment != 1) startpoint = bezier->points[segment-1].p3; else startpoint = bezier->points[0].p1; other = bezier->points[segment].p3; if (point == NULL) { realpoint.p1.x = (startpoint.x + other.x)/6; realpoint.p1.y = (startpoint.y + other.y)/6; realpoint.p2.x = (startpoint.x + other.x)/3; realpoint.p2.y = (startpoint.y + other.y)/3; realpoint.p3.x = (startpoint.x + other.x)/2; realpoint.p3.y = (startpoint.y + other.y)/2; } else { realpoint.p2.x = point->x+(startpoint.x-other.x)/6; realpoint.p2.y = point->y+(startpoint.y-other.y)/6; realpoint.p3 = *point; /* this really goes into the next segment ... */ realpoint.p1.x = point->x-(startpoint.x-other.x)/6; realpoint.p1.y = point->y-(startpoint.y-other.y)/6; } realpoint.type = BEZ_CURVE_TO; new_handle1 = g_new0(Handle,1); new_handle2 = g_new0(Handle,1); new_handle3 = g_new0(Handle,1); setup_handle(new_handle1, HANDLE_RIGHTCTRL); setup_handle(new_handle2, HANDLE_LEFTCTRL); setup_handle(new_handle3, HANDLE_BEZMAJOR); new_cp1 = g_new0(ConnectionPoint, 1); new_cp2 = g_new0(ConnectionPoint, 1); new_cp1->object = &bezier->object; new_cp2->object = &bezier->object; add_handles(bezier, segment, &realpoint, corner_type, new_handle1, new_handle2, new_handle3, new_cp1, new_cp2); return beziershape_create_point_change(bezier, TYPE_ADD_POINT, &realpoint, corner_type, segment, new_handle1, new_handle2, new_handle3, new_cp1, new_cp2); }
static DiaObject * compound_create (Point * start_point, void * user_data, Handle **handle1, Handle **handle2) { Compound * comp; DiaObject * obj; Handle * handle; gint num_handles; gint i; comp = g_new0 (Compound, 1); obj = &comp->object; obj->type = &compound_type; obj->ops = &compound_ops; comp->num_arms = DEFAULT_NUMARMS; comp->line_width = attributes_get_default_linewidth (); comp->line_color = attributes_get_foreground (); /* init our mount-point */ setup_mount_point (&comp->mount_point, obj, start_point); num_handles = comp->num_arms + 1; /* init the inherited object */ object_init (obj, num_handles, 1); obj->connections[0] = &comp->mount_point; comp->handles = g_new0 (Handle, num_handles); /* init the handle on the mount-point */ obj->handles[0] = &comp->handles[0]; setup_handle (obj->handles[0], HANDLE_MOUNT_POINT, HANDLE_MAJOR_CONTROL, HANDLE_NONCONNECTABLE); /* now init the rest of the handles */ for (i = 1; i < num_handles; i++) { handle = &comp->handles[i]; obj->handles[i] = handle; setup_handle (handle, HANDLE_ARM, HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK); } init_default_handle_positions (comp); compound_update_data (comp); compound_sanity_check (comp, "Created"); *handle1 = &comp->handles[0]; *handle2 = &comp->handles[1]; return &comp->object; }
void polyconn_copy(PolyConn *from, PolyConn *to) { int i; DiaObject *toobj, *fromobj; toobj = &to->object; fromobj = &from->object; object_copy(fromobj, toobj); to->object.handles[0] = g_new(Handle,1); *to->object.handles[0] = *from->object.handles[0]; for (i=1;i<toobj->num_handles-1;i++) { to->object.handles[i] = g_malloc(sizeof(Handle)); setup_handle(to->object.handles[i], PC_HANDLE_CORNER); } to->object.handles[toobj->num_handles-1] = g_new(Handle,1); *to->object.handles[toobj->num_handles-1] = *from->object.handles[toobj->num_handles-1]; polyconn_set_points(to, from->numpoints, from->points); memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing)); polyconn_update_data(to); }
/* Add a point by splitting segment into two, putting the new point at 'point' or, if NULL, in the middle */ ObjectChange * polyshape_add_point(PolyShape *poly, int segment, Point *point) { Point realpoint; Handle *new_handle; ConnectionPoint *new_cp1, *new_cp2; if (point == NULL) { realpoint.x = (poly->points[segment].x+poly->points[segment+1].x)/2; realpoint.y = (poly->points[segment].y+poly->points[segment+1].y)/2; } else { realpoint = *point; } new_handle = g_new(Handle, 1); new_cp1 = g_new0(ConnectionPoint, 1); new_cp1->object = &poly->object; new_cp2 = g_new0(ConnectionPoint, 1); new_cp2->object = &poly->object; setup_handle(new_handle); add_handle(poly, segment+1, &realpoint, new_handle, new_cp1, new_cp2); return polyshape_create_change(poly, TYPE_ADD_POINT, &realpoint, segment+1, new_handle, new_cp1, new_cp2); }
void polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Does object_init() */ { int i; AttributeNode attr; DataNode data; DiaObject *obj = &poly->object; object_load(obj, obj_node, ctx); attr = object_find_attribute(obj_node, "poly_points"); if (attr != NULL) poly->numpoints = attribute_num_data(attr); else poly->numpoints = 0; object_init(obj, poly->numpoints, 0); data = attribute_first_data(attr); poly->points = g_malloc(poly->numpoints*sizeof(Point)); for (i=0;i<poly->numpoints;i++) { data_point(data, &poly->points[i], ctx); data = data_next(data); } obj->handles[0] = g_malloc(sizeof(Handle)); obj->handles[0]->connect_type = HANDLE_CONNECTABLE; obj->handles[0]->connected_to = NULL; obj->handles[0]->type = HANDLE_MAJOR_CONTROL; obj->handles[0]->id = HANDLE_MOVE_STARTPOINT; obj->handles[poly->numpoints-1] = g_malloc(sizeof(Handle)); obj->handles[poly->numpoints-1]->connect_type = HANDLE_CONNECTABLE; obj->handles[poly->numpoints-1]->connected_to = NULL; obj->handles[poly->numpoints-1]->type = HANDLE_MAJOR_CONTROL; obj->handles[poly->numpoints-1]->id = HANDLE_MOVE_ENDPOINT; for (i=1;i<poly->numpoints-1;i++) { obj->handles[i] = g_malloc(sizeof(Handle)); setup_handle(obj->handles[i], PC_HANDLE_CORNER); } polyconn_update_data(poly); }
static DiaObject * compound_copy (Compound * comp) { Compound * copy; Handle * ch, * oh; DiaObject * copy_obj, * comp_obj; gint i, num_handles; comp_obj = &comp->object; num_handles = comp->object.num_handles; g_assert (comp->num_arms >= 2); g_assert (comp->num_arms+1 == num_handles); copy = g_new0 (Compound, 1); copy_obj = ©->object; /* copy the properties */ copy->num_arms = comp->num_arms; copy->line_width = comp->line_width; copy->line_color = comp->line_color; /* this will allocate the object's pointer arrays for handles and connection_points */ object_copy (comp_obj, copy_obj); /* copy the handles */ copy->handles = g_new (Handle, num_handles); for (i = 0; i < num_handles; i++) { ch = ©->handles[i]; oh = &comp->handles[i]; setup_handle (ch, oh->id, oh->type, oh->connect_type); ch->pos = oh->pos; copy_obj->handles[i] = ch; } /* copy the connection/mount point */ copy_obj->connections[0] = ©->mount_point; setup_mount_point (copy_obj->connections[0], copy_obj, ©_obj->handles[0]->pos); compound_update_data (comp); compound_sanity_check (copy, "Copied"); return ©->object; }
/* Add a point by splitting segment into two, putting the new point at 'point' or, if NULL, in the middle */ ObjectChange * polyconn_add_point(PolyConn *poly, int segment, Point *point) { Point realpoint; Handle *new_handle; if (point == NULL) { realpoint.x = (poly->points[segment].x+poly->points[segment+1].x)/2; realpoint.y = (poly->points[segment].y+poly->points[segment+1].y)/2; } else { realpoint = *point; } new_handle = g_malloc(sizeof(Handle)); setup_handle(new_handle, PC_HANDLE_CORNER); add_handle(poly, segment+1, &realpoint, new_handle); return polyconn_create_change(poly, TYPE_ADD_POINT, &realpoint, segment+1, new_handle, NULL); }
/** * Add or remove handles, so that comp->object.num_handles will equal to * the specified value. When there have been no changes done 0 is * returned, otherwise the number of handles removed (negative value) or * the number of added handles (positive value) will be returned. */ static gint adjust_handle_count_to (Compound * comp, gint to) { DiaObject * obj = &comp->object; gint old_count = obj->num_handles; gint new_count = to; Handle * h; gint i; gint diff = 0; /* we require to have always at least two arms! */ g_assert (new_count >= 3); if (new_count == old_count) return diff; /* every thing is ok */ obj->handles = g_realloc (obj->handles, new_count * sizeof(Handle *)); obj->num_handles = new_count; comp->num_arms = new_count-1; if (new_count < old_count) /* removing */ { for (i = new_count; i < old_count; i++) object_unconnect (obj, &comp->handles[i]); comp->handles = g_realloc (comp->handles, sizeof(Handle) * new_count); } else /* adding */ { comp->handles = g_realloc (comp->handles, sizeof(Handle) * new_count); for (i = old_count; i < new_count; i++) { h = &comp->handles[i]; setup_handle (h, HANDLE_ARM, HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK); } } for (i = 0; i < new_count; i++) obj->handles[i] = &comp->handles[i]; return new_count - old_count; }
static int run(void) { char *node, *service; uint64_t flags; int ret; ret = ft_read_addr_opts(&node, &service, hints, &flags, &opts); if (ret) return ret; if (!opts.src_port) opts.src_port = "9229"; if (!opts.src_addr) { fprintf(stderr, "Source address (-s) is required for this test\n"); return -EXIT_FAILURE; } ret = setup_handle(); if (ret) return ret; if (!opts.dst_addr) { ret = server_listen(); if (ret) return ret; } ret = opts.dst_addr ? client_connect() : server_connect(); if (ret) { return ret; } ret = send_recv(); fi_shutdown(ep, 0); return ret; }
static DiaObject * compound_load (ObjectNode obj_node, int version, DiaContext *ctx) { Compound * comp; DiaObject * obj; AttributeNode attr; DataNode data; gint i, num_handles; comp = g_new0 (Compound, 1); obj = &comp->object; /* load the objects position and bounding box */ object_load (obj, obj_node, ctx); /* init the object */ obj->type = &compound_type; obj->ops = &compound_ops; /* load the object's handles and its positions */ attr = object_find_attribute (obj_node, "comp_points"); g_assert (attr != NULL); num_handles = attribute_num_data (attr); g_assert (num_handles >= 3); /* allocate space for object handles and connectionpoints point arrays */ object_init (obj, num_handles, 1); data = attribute_first_data (attr); /* init our mount_point */ setup_mount_point (&comp->mount_point, obj, NULL); data_point (data, &comp->mount_point.pos, ctx); obj->connections[0] = &comp->mount_point; /* now init the handles */ comp->num_arms = num_handles-1; comp->handles = g_new0 (Handle, num_handles); setup_handle (&comp->handles[0], HANDLE_MOUNT_POINT, HANDLE_MAJOR_CONTROL, HANDLE_NONCONNECTABLE); comp->handles[0].pos = comp->mount_point.pos; obj->handles[0] = &comp->handles[0]; data = data_next (data); for (i = 1; i < num_handles; i++) { obj->handles[i] = &comp->handles[i]; setup_handle (obj->handles[i], HANDLE_ARM, HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK); data_point (data, &obj->handles[i]->pos, ctx); data = data_next (data); } /* load remainding properties */ attr = object_find_attribute (obj_node, PROP_STDTYPE_LINE_WIDTH); if (attr == NULL) comp->line_width = 0.1; else comp->line_width = data_real (attribute_first_data (attr), ctx); attr = object_find_attribute (obj_node, "line_colour"); if (attr == NULL) comp->line_color = color_black; else data_color (attribute_first_data (attr), &comp->line_color, ctx); compound_update_data (comp); compound_sanity_check (comp, "Loaded"); return &comp->object; }
int test(char *URL) { int res = 0; CURLM *m = NULL; CURLMsg *msg; /* for picking up messages with the transfer status */ int msgs_left; /* how many messages are left */ int running; int handlenum = 0; struct timeval last_handle_add; if(parse_url_file("log/urls.txt") <= 0) goto test_cleanup; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); multi_init(m); create_handles(); multi_setopt(m, CURLMOPT_PIPELINING, 1L); multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L); multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L); multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, 15000L); multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, 10000L); multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_blacklist); multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_blacklist); last_handle_add = tutil_tvnow(); for(;;) { struct timeval interval; struct timeval now; long int msnow, mslast; fd_set rd, wr, exc; int maxfd = -99; long timeout; interval.tv_sec = 1; interval.tv_usec = 0; if(handlenum < num_handles) { now = tutil_tvnow(); msnow = now.tv_sec * 1000 + now.tv_usec / 1000; mslast = last_handle_add.tv_sec * 1000 + last_handle_add.tv_usec / 1000; if(msnow - mslast >= urltime[handlenum] && handlenum < num_handles) { fprintf(stdout, "Adding handle %d\n", handlenum); setup_handle(URL, m, handlenum); last_handle_add = now; handlenum++; } } curl_multi_perform(m, &running); abort_on_test_timeout(); /* See how the transfers went */ while ((msg = curl_multi_info_read(m, &msgs_left))) { if (msg->msg == CURLMSG_DONE) { int i, found = 0; /* Find out which handle this message is about */ for (i = 0; i < num_handles; i++) { found = (msg->easy_handle == handles[i]); if(found) break; } printf("Handle %d Completed with status %d\n", i, msg->data.result); curl_multi_remove_handle(m, handles[i]); } } if(handlenum == num_handles && !running) { break; /* done */ } FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); curl_multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ curl_multi_timeout(m, &timeout); if(timeout < 0) timeout = 1; interval.tv_sec = timeout / 1000; interval.tv_usec = (timeout % 1000) * 1000; interval.tv_sec = 0; interval.tv_usec = 1000; select_test(maxfd+1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: remove_handles(); /* undocumented cleanup sequence - type UB */ curl_multi_cleanup(m); curl_global_cleanup(); free_urls(); return res; }