summaryrefslogtreecommitdiff
path: root/src/m_Do/m_Do_hostIO.cpp
blob: 6a3347efb55d00861efa7a51edab3bf96cb6d299 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "m_Do/m_Do_hostIO.h"
#include "JSystem/JHostIO/JORServer.h"
#ifdef __REVOLUTION_SDK__
#include <revolution.h>
#else
#include <dolphin.h>
#endif

#if DEBUG

mDoHIO_root_c mDoHIO_root;

mDoHIO_root_c::~mDoHIO_root_c() {}

mDoHIO_subRoot_c::~mDoHIO_subRoot_c() {}

mDoHIO_child_c::~mDoHIO_child_c() {}

void mDoHIO_root_c::genMessage(JORMContext* i_context) {
    i_context->genNode("Node", &mSub, 0, 0);
}

void mDoHIO_subRoot_c::genMessage(JORMContext* i_context) {
    for (int i = 0; i < 80; i++) {
        JORReflexible* node = mChildren[i].getPt();

        if (node != NULL) {
            i_context->genNode(mChildren[i].getName(), node, 0, 0);
        }
    }
}

void mDoHIO_root_c::update() {
    JORMContext* context = attachJORMContext(5);
    context->invalidNode(this, 3);
    releaseJORMContext(context);
}

s8 mDoHIO_subRoot_c::createChild(const char* i_name, JORReflexible* i_node) {
    for (int i = 0; i < 80; i++) {
        if (mChildren[i].getPt() == i_node) {
            OSReport_Error("危険:既に登録されているホストIOをふたたび登録\nしようとしているのを発見しました。<%s>%08x\n削除処理が正しく呼ばれていない可能性があります。\n登録と削除は1:1で呼ぶように修正してください。\n", i_name, i_node);
            return -1;
        }
    }

    for (int i = 0; i < 80; i++) {
        if (mChildren[i].getPt() == NULL) {
            mChildren[i].setName(i_name);
            mChildren[i].setPt(i_node);
            return i + 1;
        }
    }

    OSReport_Error("ホストIOの空きエントリがありません。登録できませんでした。<%s>\n", i_name);
    return -1;
}

void mDoHIO_subRoot_c::deleteChild(s8 i_no) {
    i_no--;
    
    if (i_no >= 0) {
        if (mChildren[i_no].getPt() == NULL) {
            OSReport_Error("危険:削除済みホストIOをさらに削除しようとしています<%s>\n", mChildren[i_no].getName());
        } else {
            mChildren[i_no].setPt(NULL);
        }
    } else {
        OSReport_Error("mDoHIO_subRoot_c::deleteChild\n");
    }
}

void mDoHIO_subRoot_c::updateChild(s8 i_no) {
    i_no--;
    
    if (i_no >= 0) {
        JORMContext* context = attachJORMContext(5);
        context->invalidNode(mChildren[i_no].getPt(), 3);
        releaseJORMContext(context);
    }
}

mDoHIO_entry_c::mDoHIO_entry_c() {
    mNo = -1;
    mCount = 0;
}

mDoHIO_entry_c::~mDoHIO_entry_c() {
    if (mCount != 0) {
        OSReport_Error("~mDoHIO_entry_c mCount=%d mNo=%d\n", mCount, mNo);
        mDoHIO_deleteChild(mNo);
        mDoHIO_deleteChild(mNo);  
    }
}

void mDoHIO_deleteChild(s8 i_no) {
    mDoHIO_root.deleteChild(i_no);
}

void mDoHIO_root_c::deleteChild(s8 i_no) {
    mSub.deleteChild(i_no);
}

void mDoHIO_entry_c::entryHIO(const char* i_name) {
    if (mCount >= 127) {
        // "mDoHIO_entry_c::entryHIO too many calls\n"
        OSReport_Error("mDoHIO_entry_c::entryHIO 呼びすぎです\n");
        return;
    }
    
    if (mNo == -1 && i_name != NULL) {
        mNo = mDoHIO_createChild(i_name, this);
    }

    mCount++;
}

void mDoHIO_entry_c::removeHIO() {
    if (mCount != 0) {
        mCount--;

        if (mCount == 0 && mNo != -1) {
            mDoHIO_deleteChild(mNo);
            mNo =-1;
        }
    } else {
        OSReport_Error("mDoHIO_entry_c::removeHIO 呼びすぎです\n");
    }
}

void mDoHIO_updateChild(s8 i_no) {
    mDoHIO_root.updateChild(i_no);
}

void mDoHIO_root_c::updateChild(s8 i_no) {
    mSub.updateChild(i_no);
}

#endif