Skip to content

Commit 7e29aad

Browse files
authored
Network code basics (#6)
* temp * Some new ideas * packet framework + reorganize some files
1 parent f594544 commit 7e29aad

File tree

125 files changed

+3373
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+3373
-1757
lines changed

include/revolution/SO/SOCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ typedef enum {
7272

7373
typedef enum {
7474
SO_SO_REUSEADDR = 0x0004,
75-
SO_SO_SNDBUF = 0x1002,
76-
SO_SO_RCVBUF = 0x1003,
75+
SO_SO_SNDBUF = 0x1001,
76+
SO_SO_RCVBUF = 0x1002,
7777
} SOSockOpt;
7878

7979
typedef enum { SO_SHUT_RD, SO_SHUT_WR, SO_SHUT_RDWR } SOShutdownType;

lib/libkiwi/core/kiwiJSON.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void Reader::DecodeImpl() {
143143
ParseEncoding(pos);
144144
}
145145

146-
// TODO: Implement UTF-16 parsing
146+
// TODO(kiwi) Implement UTF-16 parsing
147147
K_ASSERT_EX(mEncoding == EEncoding_UTF8,
148148
"UTF-16 encoding is not yet supported");
149149

@@ -1231,7 +1231,7 @@ void PrintVisitor::Visit(const Element& rElement) {
12311231
it != rElement.Get<Object>().End(); ++it, i++) {
12321232
Print('\"' + (it->key + "\": "));
12331233

1234-
// TODO: Fix this somehow?
1234+
// TODO(kiwi) Fix this somehow?
12351235
Visit(it->value);
12361236

12371237
// Values are comma separated

lib/libkiwi/core/kiwiJSON.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class Element {
153153
K_ASSERT(mType == EType_Object);
154154
const Element* pElement = Get<Object>().Find(rKey);
155155

156-
// TODO: Better way to return a dummy element?
156+
// TODO(kiwi) Better way to return a dummy element?
157157
if (pElement == nullptr) {
158158
static const Element undefined;
159159
return undefined;

lib/libkiwi/core/kiwiJSONImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ template <> K_INLINE void Element::Set<Object>(const Object& rValue) {
139139
/**@{*/
140140
template <> K_INLINE Null_t& Element::Get<Null_t>() {
141141
K_ASSERT(mType == EType_Null);
142-
// TODO: Better way to solve this problem?
142+
// TODO(kiwi) Better way to solve this problem?
143143
return const_cast<Null_t&>(json::null);
144144
}
145145
template <> K_INLINE const Null_t& Element::Get<Null_t>() const {

lib/libkiwi/core/kiwiMemoryMgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class MemoryMgr : public StaticSingleton<MemoryMgr> {
8282
EGG::Heap* GetHeap(EMemory memory) const;
8383

8484
private:
85-
// TODO: How to get more MEM1 memory from WS2?
85+
// TODO(kiwi) How to get more MEM1 memory from WS2?
8686
#if defined(PACK_SPORTS) || defined(PACK_PLAY)
8787
//! Initial size for each heap
8888
static const u32 HEAP_SIZE = OS_MEM_KB_TO_B(1024);
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <libkiwi/prim/kiwiBitCast.h>
2-
31
#include <libkiwi.h>
42

53
namespace kiwi {
@@ -8,37 +6,38 @@ namespace detail {
86
/**
97
* @brief Constructor
108
*/
11-
ThreadImpl::ThreadImpl() : mpOSThread(nullptr), mpThreadStack(nullptr) {
9+
StdThreadImpl::StdThreadImpl() : mpOSThread(nullptr), mpThreadStack(nullptr) {
1210
// Thread & stack aligned to 32
1311
mpOSThread = new (32) OSThread();
1412
K_ASSERT_PTR(mpOSThread);
1513
mpThreadStack = new (32) u8[scStackSize];
1614
K_ASSERT_PTR(mpThreadStack);
1715

18-
BOOL success =
19-
OSCreateThread(mpOSThread, nullptr, nullptr,
20-
mpThreadStack + scStackSize, scStackSize, scPriority, 0);
16+
BOOL success = OSCreateThread(mpOSThread, nullptr, nullptr,
17+
mpThreadStack + scStackSize, scStackSize,
18+
OS_PRIORITY_MAX - 1, 0);
19+
2120
K_ASSERT(success);
2221
}
2322

2423
/**
2524
* @brief Destructor
2625
*/
27-
ThreadImpl::~ThreadImpl() {
26+
StdThreadImpl::~StdThreadImpl() {
2827
K_ASSERT_PTR(mpOSThread);
2928
K_ASSERT_EX(*mpOSThread->stackEnd == OS_THREAD_STACK_MAGIC,
3029
"Thread stack overflow!!!");
3130

3231
OSDetachThread(mpOSThread);
3332

3433
delete mpOSThread;
35-
delete mpThreadStack;
34+
delete[] mpThreadStack;
3635
}
3736

3837
/**
3938
* @brief Begins execution on this thread
4039
*/
41-
void ThreadImpl::Start() {
40+
void StdThreadImpl::Start() {
4241
K_ASSERT_PTR(mpOSThread);
4342
K_ASSERT(mpOSThread->state == OS_THREAD_STATE_READY);
4443
K_ASSERT_EX(mpOSThread->context.srr0 != 0, "No function to call");
@@ -51,7 +50,7 @@ void ThreadImpl::Start() {
5150
/**
5251
* @brief Waits for this thread to finish executing
5352
*/
54-
void ThreadImpl::Join() {
53+
void StdThreadImpl::Join() {
5554
K_ASSERT_PTR(mpOSThread);
5655

5756
BOOL success = OSJoinThread(mpOSThread, nullptr);
@@ -63,7 +62,7 @@ void ThreadImpl::Join() {
6362
*
6463
* @param addr Function address (new SRR0 value)
6564
*/
66-
void ThreadImpl::SetFunction(const void* addr) {
65+
void StdThreadImpl::SetFunction(const void* addr) {
6766
K_ASSERT_PTR(mpOSThread);
6867
K_ASSERT(addr != 0);
6968
mpOSThread->context.srr0 = BitCast<u32>(addr);
@@ -75,7 +74,7 @@ void ThreadImpl::SetFunction(const void* addr) {
7574
* @param i GPR number
7675
* @param value New value
7776
*/
78-
void ThreadImpl::SetGPR(u32 idx, u32 value) {
77+
void StdThreadImpl::SetGPR(u32 idx, u32 value) {
7978
K_ASSERT_PTR(mpOSThread);
8079
K_ASSERT(idx >= 0 && idx < K_LENGTHOF(mpOSThread->context.gprs));
8180
mpOSThread->context.gprs[idx] = value;
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef LIBKIWI_CORE_THREAD_H
2-
#define LIBKIWI_CORE_THREAD_H
1+
#ifndef LIBKIWI_CORE_STD_THREAD_H
2+
#define LIBKIWI_CORE_STD_THREAD_H
33
#include <libkiwi/debug/kiwiAssert.h>
44
#include <libkiwi/k_types.h>
55

@@ -16,7 +16,7 @@ namespace detail {
1616
/**
1717
* @brief Common thread implementation
1818
*/
19-
class ThreadImpl {
19+
class StdThreadImpl {
2020
public:
2121
/**
2222
* @brief Waits for this thread to finish executing
@@ -27,11 +27,11 @@ class ThreadImpl {
2727
/**
2828
* @brief Constructor
2929
*/
30-
ThreadImpl();
30+
StdThreadImpl();
3131
/**
3232
* @brief Destructor
3333
*/
34-
~ThreadImpl();
34+
~StdThreadImpl();
3535

3636
/**
3737
* @brief Begins execution on this thread
@@ -77,7 +77,7 @@ class ThreadImpl {
7777
* @details Similar to std::thread.
7878
* @note Only allows GPR arguments
7979
*/
80-
class Thread : public detail::ThreadImpl {
80+
class StdThread : public detail::StdThreadImpl {
8181
public:
8282
// Thread function parameter
8383
typedef void* Param;
@@ -92,14 +92,14 @@ class Thread : public detail::ThreadImpl {
9292
*
9393
* @param pFunc Static, no-parameter function
9494
*/
95-
template <typename TRet> Thread(TRet (*pFunc)());
95+
template <typename TRet> StdThread(TRet (*pFunc)());
9696
/**
9797
* @brief Constructor
9898
*
9999
* @param pFunc Static, single-parameter function
100100
* @param pArg Function argument
101101
*/
102-
template <typename TRet> Thread(TRet (*pFunc)(Param), Param pArg);
102+
template <typename TRet> StdThread(TRet (*pFunc)(Param), Param pArg);
103103
/**@}*/
104104

105105
/**
@@ -113,7 +113,7 @@ class Thread : public detail::ThreadImpl {
113113
* @param rObj Class instance
114114
*/
115115
template <typename TRet, typename TClass>
116-
Thread(TRet (TClass::*pFunc)(), TClass& rObj);
116+
StdThread(TRet (TClass::*pFunc)(), TClass& rObj);
117117
/**
118118
* @brief Constructor
119119
*
@@ -122,7 +122,7 @@ class Thread : public detail::ThreadImpl {
122122
* @param pArg Function argument
123123
*/
124124
template <typename TRet, typename TClass>
125-
Thread(TRet (TClass::*pFunc)(Param), TClass& rObj, Param pArg);
125+
StdThread(TRet (TClass::*pFunc)(Param), TClass& rObj, Param pArg);
126126
/**@}*/
127127

128128
/**
@@ -136,7 +136,7 @@ class Thread : public detail::ThreadImpl {
136136
* @param rObj Class instance
137137
*/
138138
template <typename TRet, typename TClass>
139-
Thread(TRet (TClass::*pFunc)() const, const TClass& rObj);
139+
StdThread(TRet (TClass::*pFunc)() const, const TClass& rObj);
140140
/**
141141
* @brief Constructor
142142
*
@@ -145,7 +145,8 @@ class Thread : public detail::ThreadImpl {
145145
* @param pArg Function argument
146146
*/
147147
template <typename TRet, typename TClass>
148-
Thread(TRet (TClass::*pFunc)(Param) const, const TClass& rObj, Param pArg);
148+
StdThread(TRet (TClass::*pFunc)(Param) const, const TClass& rObj,
149+
Param pArg);
149150
/**@}*/
150151
};
151152

@@ -154,7 +155,7 @@ class Thread : public detail::ThreadImpl {
154155

155156
// Implementation header
156157
#ifndef LIBKIWI_CORE_THREAD_IMPL_HPP
157-
#include <libkiwi/core/kiwiThreadImpl.hpp>
158+
#include <libkiwi/core/kiwiStdThreadImpl.hpp>
158159
#endif
159160

160161
#endif
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Implementation header
2-
#ifndef LIBKIWI_CORE_THREAD_IMPL_HPP
3-
#define LIBKIWI_CORE_THREAD_IMPL_HPP
2+
#ifndef LIBKIWI_CORE_STD_THREAD_IMPL_HPP
3+
#define LIBKIWI_CORE_STD_THREAD_IMPL_HPP
44

55
// Declaration header
6-
#ifndef LIBKIWI_CORE_THREAD_H
7-
#include <libkiwi/core/kiwiThread.h>
6+
#ifndef LIBKIWI_CORE_STD_THREAD_H
7+
#include <libkiwi/core/kiwiStdThread.h>
88
#endif
99

1010
#include <libkiwi/prim/kiwiBitCast.h>
@@ -22,7 +22,7 @@ namespace kiwi {
2222
*
2323
* @param pFunc Static, no-parameter function
2424
*/
25-
template <typename TRet> Thread::Thread(TRet (*pFunc)()) {
25+
template <typename TRet> StdThread::StdThread(TRet (*pFunc)()) {
2626
K_ASSERT_PTR(pFunc);
2727

2828
SetFunction(pFunc);
@@ -36,7 +36,7 @@ template <typename TRet> Thread::Thread(TRet (*pFunc)()) {
3636
* @param pArg Function argument
3737
*/
3838
template <typename TRet>
39-
Thread::Thread(TRet (*pFunc)(Thread::Param), Thread::Param pArg) {
39+
StdThread::StdThread(TRet (*pFunc)(StdThread::Param), StdThread::Param pArg) {
4040
K_ASSERT_PTR(pFunc);
4141

4242
SetFunction(pFunc);
@@ -56,7 +56,7 @@ Thread::Thread(TRet (*pFunc)(Thread::Param), Thread::Param pArg) {
5656
* @param rObj Class instance
5757
*/
5858
template <typename TRet, typename TClass>
59-
Thread::Thread(TRet (TClass::*pFunc)(), TClass& rObj) {
59+
StdThread::StdThread(TRet (TClass::*pFunc)(), TClass& rObj) {
6060
K_ASSERT(pFunc);
6161

6262
SetMemberFunction(pFunc, rObj);
@@ -71,8 +71,8 @@ Thread::Thread(TRet (TClass::*pFunc)(), TClass& rObj) {
7171
* @param pArg Function argument
7272
*/
7373
template <typename TRet, typename TClass>
74-
Thread::Thread(TRet (TClass::*pFunc)(Thread::Param), TClass& rObj,
75-
Thread::Param pArg) {
74+
StdThread::StdThread(TRet (TClass::*pFunc)(StdThread::Param), TClass& rObj,
75+
StdThread::Param pArg) {
7676
K_ASSERT(pFunc);
7777

7878
SetMemberFunction(pFunc, rObj);
@@ -92,7 +92,7 @@ Thread::Thread(TRet (TClass::*pFunc)(Thread::Param), TClass& rObj,
9292
* @param rObj Class instance
9393
*/
9494
template <typename TRet, typename TClass>
95-
Thread::Thread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
95+
StdThread::StdThread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
9696
K_ASSERT(pFunc);
9797

9898
SetMemberFunction(pFunc, rObj);
@@ -107,8 +107,8 @@ Thread::Thread(TRet (TClass::*pFunc)() const, const TClass& rObj) {
107107
* @param pArg Function argument
108108
*/
109109
template <typename TRet, typename TClass>
110-
Thread::Thread(TRet (TClass::*pFunc)(Thread::Param) const, const TClass& rObj,
111-
Thread::Param pArg) {
110+
StdThread::StdThread(TRet (TClass::*pFunc)(StdThread::Param) const,
111+
const TClass& rObj, StdThread::Param pArg) {
112112
K_ASSERT(pFunc);
113113

114114
SetMemberFunction(pFunc, rObj);
@@ -139,8 +139,8 @@ struct MemberFunction {
139139
* @param rObj Class instance
140140
*/
141141
template <typename TFunc, typename TClass>
142-
K_DONT_INLINE void ThreadImpl::SetMemberFunction(TFunc pFunc,
143-
const TClass& rObj) {
142+
K_DONT_INLINE void StdThreadImpl::SetMemberFunction(TFunc pFunc,
143+
const TClass& rObj) {
144144

145145
K_STATIC_ASSERT_EX(sizeof(TFunc) == sizeof(MemberFunction),
146146
"Not a member function");

lib/libkiwi/debug/kiwiNw4rDirectPrint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void Nw4rDirectPrint::SetupXfb() {
7777
// Initialize direct print
7878
SetColor(Color::WHITE);
7979

80-
// TODO: WS2 framebuffer is 608x456. Why?
80+
// TODO(kiwi) WS2 framebuffer is 608x456. Why?
8181
#if defined(PACK_SPORTS) || defined(PACK_PLAY)
8282
// Try to repurpose current framebuffer
8383
void* pXfb = VIGetCurrentFrameBuffer();
File renamed without changes.

0 commit comments

Comments
 (0)