Changeset 9532981 in mainline for uspace/srv/sysman/edge.c


Ignore:
Timestamp:
2019-08-07T09:35:37Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

sysman: Rename dependency to edge (more generic)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/edge.c

    raf92309 r9532981  
    3232#include <str.h>
    3333
    34 #include "dep.h"
     34#include "edge.h"
    3535
    36 static void dep_dependency_init(unit_dependency_t *dep)
     36static void edge_init(unit_edge_t *e)
    3737{
    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);
    4341}
    4442
    45 unit_dependency_t *dep_dependency_create(void)
     43unit_edge_t *edge_create(void)
    4644{
    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);
    5048        }
    51         return dep;
     49        return e;
    5250}
    5351
    54 void dep_dependency_destroy(unit_dependency_t **dep_ptr)
     52void edge_destroy(unit_edge_t **e_ptr)
    5553{
    56         unit_dependency_t *dep = *dep_ptr;
    57         if (dep == NULL) {
     54        unit_edge_t *e = *e_ptr;
     55        if (e == NULL) {
    5856                return;
    5957        }
    6058
    61         list_remove(&dep->dependencies);
    62         list_remove(&dep->dependants);
     59        list_remove(&e->edges_in);
     60        list_remove(&e->edges_out);
    6361
    64         free(dep->dependency_name);
    65         free(dep);
     62        free(e->output_name);
     63        free(e);
    6664
    67         *dep_ptr = NULL;
     65        *e_ptr = NULL;
    6866}
    6967
    70 int dep_sprout_dependency(unit_t *dependant, const char *dependency_name)
     68int edge_sprout_out(unit_t *input, const char *output_name)
    7169{
    72         unit_dependency_t *dep = dep_dependency_create();
     70        unit_edge_t *e = edge_create();
    7371        int rc;
    7472
    75         if (dep == NULL) {
     73        if (e == NULL) {
    7674                rc = ENOMEM;
    7775                goto finish;
    7876        }
    7977
    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) {
    8280                rc = ENOMEM;
    8381                goto finish;
    8482        }
    8583
    86         list_append(&dep->dependencies, &dependant->dependencies);
    87         dep->dependant = dependant;
     84        list_append(&e->edges_out, &input->edges_out);
     85        e->input = input;
    8886
    8987        rc = EOK;
     
    9189finish:
    9290        if (rc != EOK) {
    93                 dep_dependency_destroy(&dep);
     91                edge_destroy(&e);
    9492        }
    9593        return rc;
    9694}
    9795
    98 void dep_resolve_dependency(unit_dependency_t *dep, unit_t *unit)
     96void edge_resolve_output(unit_edge_t *e, unit_t *unit)
    9997{
    100         assert(dep->dependency == NULL);
    101         assert(dep->dependency_name != NULL);
     98        assert(e->output == NULL);
     99        assert(e->output_name != NULL);
    102100
    103         // TODO add to other side dependants list
    104         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;
    107105}
    108106
     
    112110 * @return        ENOMEM
    113111 */
    114 int dep_add_dependency(unit_t *dependant, unit_t *dependency)
     112int edge_connect(unit_t *input, unit_t *output)
    115113{
    116         unit_dependency_t *dep = dep_dependency_create();
    117         if (dep == NULL) {
     114        unit_edge_t *e = edge_create();
     115        if (e == NULL) {
    118116                return ENOMEM;
    119117        }
    120118
    121         // TODO check existence of the dep
     119        // TODO check existence of the e
    122120        // TODO locking
    123121        // 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);
    126124
    127         dep->dependant = dependant;
    128         dep->dependency = dependency;
     125        e->input = input;
     126        e->output = output;
    129127        return EOK;
    130128}
    131129
    132 /** Remove dependency from dependency graph
     130/** Remove output from output graph
    133131 *
    134  * Given dependency is removed from graph and unallocated.
     132 * Given output is removed from graph and unallocated.
    135133 */
    136 void dep_remove_dependency(unit_dependency_t **dep_ptr)
     134void edge_remove(unit_edge_t **e_ptr)
    137135{
    138136        // TODO here should be some checks, othewise replace this wrapper with
    139137        //      direct destroy
    140         dep_dependency_destroy(dep_ptr);
     138        edge_destroy(e_ptr);
    141139}
Note: See TracChangeset for help on using the changeset viewer.