Changeset bb154c6 in mainline for uspace/srv/sysman/dep.c
- Timestamp:
- 2019-08-03T08:15:25Z (5 years ago)
- Children:
- 09a8006
- Parents:
- 6006f35
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-04-15 15:14:58)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 08:15:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/dep.c
r6006f35 rbb154c6 1 #include <assert.h> 1 2 #include <errno.h> 2 3 #include <stdlib.h> 4 #include <str.h> 3 5 4 6 #include "dep.h" 7 8 static void dep_dependency_init(unit_dependency_t *dep) 9 { 10 link_initialize(&dep->dependants); 11 link_initialize(&dep->dependencies); 12 13 dep->dependency_name = NULL; 14 dep->state = DEP_EMBRYO; 15 } 16 17 unit_dependency_t *dep_dependency_create(void) 18 { 19 unit_dependency_t *dep = malloc(sizeof(unit_dependency_t)); 20 if (dep) { 21 dep_dependency_init(dep); 22 } 23 return dep; 24 } 25 26 void dep_dependency_destroy(unit_dependency_t **dep_ptr) 27 { 28 unit_dependency_t *dep = *dep_ptr; 29 if (dep == NULL) { 30 return; 31 } 32 33 list_remove(&dep->dependencies); 34 list_remove(&dep->dependants); 35 36 free(dep->dependency_name); 37 free(dep); 38 39 *dep_ptr = NULL; 40 } 41 42 int dep_sprout_dependency(unit_t *dependant, const char *dependency_name) 43 { 44 unit_dependency_t *dep = dep_dependency_create(); 45 int rc; 46 47 if (dep == NULL) { 48 rc = ENOMEM; 49 goto finish; 50 } 51 52 dep->dependency_name = str_dup(dependency_name); 53 if (dep->dependency_name == NULL) { 54 rc = ENOMEM; 55 goto finish; 56 } 57 58 list_append(&dep->dependencies, &dependant->dependencies); 59 dep->dependant = dependant; 60 61 rc = EOK; 62 63 finish: 64 if (rc != EOK) { 65 dep_dependency_destroy(&dep); 66 } 67 return rc; 68 } 69 70 void dep_resolve_dependency(unit_dependency_t *dep, unit_t *unit) 71 { 72 assert(dep->dependency == NULL); 73 assert(dep->dependency_name != NULL); 74 75 // TODO add to other side dependants list 76 dep->dependency = unit; 77 free(dep->dependency_name); 78 dep->dependency_name = NULL; 79 } 80 5 81 6 82 /** … … 10 86 int dep_add_dependency(unit_t *dependant, unit_t *dependency) 11 87 { 12 unit_dependency_t * edge = malloc(sizeof(unit_dependency_t));13 if ( edge== NULL) {88 unit_dependency_t *dep = dep_dependency_create(); 89 if (dep == NULL) { 14 90 return ENOMEM; 15 91 } 16 link_initialize(&edge->dependants);17 link_initialize(&edge->dependencies);18 92 19 // TODO check existence of the edge93 // TODO check existence of the dep 20 94 // TODO locking 21 95 // TODO check types and states of connected units 22 list_append(& edge->dependants, &dependency->dependants);23 list_append(& edge->dependencies, &dependant->dependencies);96 list_append(&dep->dependants, &dependency->dependants); 97 list_append(&dep->dependencies, &dependant->dependencies); 24 98 25 edge->dependant = dependant;26 edge->dependency = dependency;99 dep->dependant = dependant; 100 dep->dependency = dependency; 27 101 return EOK; 28 102 } 103 104 /** Remove dependency from dependency graph 105 * 106 * Given dependency is removed from graph and unallocated. 107 */ 108 void dep_remove_dependency(unit_dependency_t **dep_ptr) 109 { 110 // TODO here should be some checks, othewise replace this wrapper with 111 // direct destroy 112 dep_dependency_destroy(dep_ptr); 113 }
Note:
See TracChangeset
for help on using the changeset viewer.