Changeset bb154c6 in mainline for uspace/srv/sysman/dep.c


Ignore:
Timestamp:
2019-08-03T08:15:25Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

Add skeleton for configuration files loading

  • Create content of /cfg directory,
  • create sample configuration file,
  • refactored polymorphism.

Conflicts:

boot/Makefile

File:
1 edited

Legend:

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

    r6006f35 rbb154c6  
     1#include <assert.h>
    12#include <errno.h>
    23#include <stdlib.h>
     4#include <str.h>
    35
    46#include "dep.h"
     7
     8static 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
     17unit_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
     26void 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
     42int 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
     63finish:
     64        if (rc != EOK) {
     65                dep_dependency_destroy(&dep);
     66        }
     67        return rc;
     68}
     69
     70void 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
    581
    682/**
     
    1086int dep_add_dependency(unit_t *dependant, unit_t *dependency)
    1187{
    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) {
    1490                return ENOMEM;
    1591        }
    16         link_initialize(&edge->dependants);
    17         link_initialize(&edge->dependencies);
    1892
    19         // TODO check existence of the edge
     93        // TODO check existence of the dep
    2094        // TODO locking
    2195        // 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);
    2498
    25         edge->dependant = dependant;
    26         edge->dependency = dependency;
     99        dep->dependant = dependant;
     100        dep->dependency = dependency;
    27101        return EOK;
    28102}
     103
     104/** Remove dependency from dependency graph
     105 *
     106 * Given dependency is removed from graph and unallocated.
     107 */
     108void 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.