Changeset 9532981 in mainline for uspace/srv/sysman/edge.c
- Timestamp:
- 2019-08-07T09:35:37Z (6 years ago)
- Children:
- db34424
- Parents:
- af92309
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-02 23:10:51)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:35:37)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/edge.c
raf92309 r9532981 32 32 #include <str.h> 33 33 34 #include " dep.h"34 #include "edge.h" 35 35 36 static void dep_dependency_init(unit_dependency_t *dep)36 static void edge_init(unit_edge_t *e) 37 37 { 38 memset(dep, 0, sizeof(*dep)); 39 link_initialize(&dep->dependants); 40 link_initialize(&dep->dependencies); 41 42 dep->state = DEP_EMBRYO; 38 memset(e, 0, sizeof(*e)); 39 link_initialize(&e->edges_in); 40 link_initialize(&e->edges_out); 43 41 } 44 42 45 unit_ dependency_t *dep_dependency_create(void)43 unit_edge_t *edge_create(void) 46 44 { 47 unit_ dependency_t *dep = malloc(sizeof(unit_dependency_t));48 if ( dep) {49 dep_dependency_init(dep);45 unit_edge_t *e = malloc(sizeof(unit_edge_t)); 46 if (e) { 47 edge_init(e); 50 48 } 51 return dep;49 return e; 52 50 } 53 51 54 void dep_dependency_destroy(unit_dependency_t **dep_ptr)52 void edge_destroy(unit_edge_t **e_ptr) 55 53 { 56 unit_ dependency_t *dep = *dep_ptr;57 if ( dep== NULL) {54 unit_edge_t *e = *e_ptr; 55 if (e == NULL) { 58 56 return; 59 57 } 60 58 61 list_remove(& dep->dependencies);62 list_remove(& dep->dependants);59 list_remove(&e->edges_in); 60 list_remove(&e->edges_out); 63 61 64 free( dep->dependency_name);65 free( dep);62 free(e->output_name); 63 free(e); 66 64 67 * dep_ptr = NULL;65 *e_ptr = NULL; 68 66 } 69 67 70 int dep_sprout_dependency(unit_t *dependant, const char *dependency_name)68 int edge_sprout_out(unit_t *input, const char *output_name) 71 69 { 72 unit_ dependency_t *dep = dep_dependency_create();70 unit_edge_t *e = edge_create(); 73 71 int rc; 74 72 75 if ( dep== NULL) {73 if (e == NULL) { 76 74 rc = ENOMEM; 77 75 goto finish; 78 76 } 79 77 80 dep->dependency_name = str_dup(dependency_name);81 if ( dep->dependency_name == NULL) {78 e->output_name = str_dup(output_name); 79 if (e->output_name == NULL) { 82 80 rc = ENOMEM; 83 81 goto finish; 84 82 } 85 83 86 list_append(& dep->dependencies, &dependant->dependencies);87 dep->dependant = dependant;84 list_append(&e->edges_out, &input->edges_out); 85 e->input = input; 88 86 89 87 rc = EOK; … … 91 89 finish: 92 90 if (rc != EOK) { 93 dep_dependency_destroy(&dep);91 edge_destroy(&e); 94 92 } 95 93 return rc; 96 94 } 97 95 98 void dep_resolve_dependency(unit_dependency_t *dep, unit_t *unit)96 void edge_resolve_output(unit_edge_t *e, unit_t *unit) 99 97 { 100 assert( dep->dependency== NULL);101 assert( dep->dependency_name != NULL);98 assert(e->output == NULL); 99 assert(e->output_name != NULL); 102 100 103 // TODO add to other side dependantslist104 dep->dependency= unit;105 free( dep->dependency_name);106 dep->dependency_name = NULL;101 // TODO add to other side edges_in list 102 e->output = unit; 103 free(e->output_name); 104 e->output_name = NULL; 107 105 } 108 106 … … 112 110 * @return ENOMEM 113 111 */ 114 int dep_add_dependency(unit_t *dependant, unit_t *dependency)112 int edge_connect(unit_t *input, unit_t *output) 115 113 { 116 unit_ dependency_t *dep = dep_dependency_create();117 if ( dep== NULL) {114 unit_edge_t *e = edge_create(); 115 if (e == NULL) { 118 116 return ENOMEM; 119 117 } 120 118 121 // TODO check existence of the dep119 // TODO check existence of the e 122 120 // TODO locking 123 121 // TODO check types and states of connected units 124 list_append(& dep->dependants, &dependency->dependants);125 list_append(& dep->dependencies, &dependant->dependencies);122 list_append(&e->edges_in, &output->edges_in); 123 list_append(&e->edges_out, &input->edges_out); 126 124 127 dep->dependant = dependant;128 dep->dependency = dependency;125 e->input = input; 126 e->output = output; 129 127 return EOK; 130 128 } 131 129 132 /** Remove dependency from dependencygraph130 /** Remove output from output graph 133 131 * 134 * Given dependencyis removed from graph and unallocated.132 * Given output is removed from graph and unallocated. 135 133 */ 136 void dep_remove_dependency(unit_dependency_t **dep_ptr)134 void edge_remove(unit_edge_t **e_ptr) 137 135 { 138 136 // TODO here should be some checks, othewise replace this wrapper with 139 137 // direct destroy 140 dep_dependency_destroy(dep_ptr);138 edge_destroy(e_ptr); 141 139 }
Note:
See TracChangeset
for help on using the changeset viewer.