summaryrefslogtreecommitdiffstats
path: root/lib/libjove/include/object-dir.h
blob: 53aada8f0e653974fa7b4a77c6d30cc085a2183b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef _LIBJOVE_OBJDIR_H
#define _LIBJOVE_OBJDIR_H 1

#include <stdint.h>
#include <stddef.h>
#include <kernel/object.h>

#include <jove/object-typed.h>
#include <jove/error.h>

/**@STRUCT Represents cached information about a KO_OBJDIR.
 * To update the information this struct contains, call jove_objdir_sync.*/
typedef struct _KernelObjectDirectory {
    KernelObjectTyped typed;

    uint8_t lastmemb;
    uint8_t firstfree;

    KernelObjectTyped *children[256];
} KernelObjectDirectory;
extern KernelObjectDirectory __rootdir;
extern KernelObjectTyped __jove_work_obj;

KernelObjectDirectory *jove_object_as_objdir(KernelObjectTyped *typed);

/**@FUNC Populates a objdir struct for an empty directory at dir:memb.
 * @PARAM dir address to populate.
 * @PARAM parent directory to make dir child of.
 * @PARAM memb index to place new objdir.*/
void _jove_alloc_objdir_inplace(
        KernelObjectDirectory *dir, 
        KernelObjectDirectory *parent, 
        uint8_t memb);

/**@FUNC Allocates a block of memory to represent a kernel objdir.
 * @PARAM parent directory to place new member into.
 * @PARAM memb index to place new objdir.
 * @RETURN pointer to new objdir.
 * Possible failures:
 *      EJOVE_NOALLOC: libjove is missing an allocator.
 *      EJOVE_FULL: space at memb is already taken.*/
KernelObjectDirectory *_jove_alloc_objdir(
        KernelObjectDirectory *parent,
        uint8_t memb);

/**@FUNC Updates the dir struct with information obtained through the kernel.
 * @PARAM dir directory to sync.
 * @RETURN error code. 0 on success*/
JoveError jove_objdir_sync(KernelObjectDirectory *dir);

/**@FUNC Updates the dir struct at the given index with information obtained
 * through the kernel.
 * @PARAM dir directory to sync.
 * @PARAM i index to sync.
 * @PARAM memb pointer to place typed object in. Nullable
 * @RETURN error code. 0 on success.*/
JoveError jove_objdir_sync_at(KernelObjectDirectory *dir, uint8_t i, KernelObjectTyped** memb);

/**@FUNC Returns the number of populated entries this directory holds.
 * @PARAM dir directory to check
 * @RETURN number of entries. negative return values indicate an error.*/
int jove_objdir_nmemb(KernelObjectDirectory *dir);

/**@FUNC Gets the highest populated index in a given directory.
 * @PARAM dir directory to check.
 * @RETURN last populated entry. negative return values indicate an error.*/
int jove_objdir_lastmemb(KernelObjectDirectory *dir);

/**@FUNC Gets the kernel object at a given index.
 * This function only checks the cached result. If the directory has changed
 * without updating the cache, jove_objdir_sync MUST be called first.
 *
 * @PARAM dir directory to check in.
 * @PARAM index index to check.
 * @RETURN the object at the given index. NULL if the spot is empty.*/
KernelObjectTyped *jove_objdir_get(KernelObjectDirectory *dir, uint8_t index);

/**@FUNC Moves a kernel object in this directory to a different place/directory.
 * @PARAM dir directory holding the object.
 * @PARAM memb member index of the object.
 * @PARAM dest_dir destination directory.
 * @PARAM dest_memb destination member.*/
JoveError jove_objdir_move(
        KernelObjectDirectory *dir,
        uint8_t memb,
        KernelObjectDirectory *dest_dir,
        uint8_t dest_memb);

JoveError jove_object_move(
        KernelObjectTyped *typed,
        KernelObjectDirectory *dest_dir,
        uint8_t dest_memb);

JoveError jove_object_move_inplace(
        KernelObjectTyped *typed,
        KernelObjectTyped *dest);

#endif