Skip to content

Commit

Permalink
Event Return Values, Begin Fix Networking
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Dec 1, 2023
1 parent 4ffee9d commit 09f3b98
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BUILD_COMPLETE ?= make runQ
AS_PARAMS = --32
LD_PARAMS = -melf_i386 --verbose
QEMU_PARAMS = -device pcnet,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:1234 \
-netdev user,id=net0,hostfwd=tcp::1234-:1234 \
-m 512 \
-hda maxOS.img \
-vga std \
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ Kernel Cleanup
- [x] Kernel Boot Rewrite
- [x] Rewrite Event Handlers
- [x] Network Touch Up
- [ ] HTTP Protocol, DCHP protocol
- [ ] DCHP protocol
- [ ] GUI Bug Fixes
- [ ] Better Commenting and Doxygen Documentation
- [ ] Use better c++ coding conventions
- [ ] Fix filesystem (move to linux one?)
- [ ] HTTP Protocol
- [ ] USB
- [ ] Custom Toolchain
- [ ] CMAKE Build System (and maybe get it building and debugging in CLion)
Expand Down
21 changes: 15 additions & 6 deletions kernel/include/common/eventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ namespace maxOS{
~Event();

EventType type;
union {
common::uint8_t* bufferValue;
common::uint32_t intValue;
bool boolValue;
} returnValue;
};

template <typename EventType> class EventHandler
{
public:
EventHandler();
~EventHandler();
virtual void onEvent(Event<EventType>* event);
virtual Event<EventType>* onEvent(Event<EventType>* event);
};

template <typename EventType> class EventManager
Expand All @@ -39,7 +44,7 @@ namespace maxOS{
~EventManager();
void connectEventHandler(EventHandler<EventType>* handler);
void disconnectEventHandler(EventHandler<EventType>* handler);
void raiseEvent(Event<EventType>* event);
Vector<Event<EventType>*> raiseEvent(Event<EventType>* event);
};


Expand Down Expand Up @@ -67,8 +72,8 @@ namespace maxOS{
* @tparam EventType The type of event
* @param event The event that was raised
*/
template<typename EventType> void EventHandler<EventType>::onEvent(Event<EventType> *event) {

template<typename EventType> Event<EventType>* EventHandler<EventType>::onEvent(Event<EventType> *event) {
return event;
}

template<typename EventType> EventManager<EventType>::EventManager() {
Expand Down Expand Up @@ -114,11 +119,15 @@ namespace maxOS{
* @tparam EventType The type of event
* @param event The event to raise
*/
template<typename EventType> void EventManager<EventType>::raiseEvent(Event<EventType> *event) {
template<typename EventType> Vector<Event<EventType>*> EventManager<EventType>::raiseEvent(Event<EventType> *event) {


// Store a list of the results of the event handlers
Vector<Event<EventType>*> results;
for(typename Vector<EventHandler<EventType>*>::iterator handler = handlers.begin(); handler != handlers.end(); ++handler) {
(*handler)->onEvent(event);
results.pushBack((*handler)->onEvent(event));
}
return results;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/drivers/clock/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace maxOS {
ClockEventHandler();
~ClockEventHandler();

void onEvent(common::Event<ClockEvents>* event);
common::Event<ClockEvents>* onEvent(common::Event<ClockEvents>* event);

virtual void onTime(const common::Time& time);

Expand Down
4 changes: 2 additions & 2 deletions kernel/include/drivers/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace maxOS

class Driver {
protected:
common::OutputStream* driverMessageStream;

public:

common::OutputStream* driverMessageStream;
Driver(common::OutputStream* driverMessageStream = 0);
~Driver();

Expand Down
2 changes: 1 addition & 1 deletion kernel/include/drivers/ethernet/ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace maxOS{
EthernetDriverEventHandler();
~EthernetDriverEventHandler();

virtual void onEvent(common::Event<EthernetDriverEvents>* event);
virtual common::Event<EthernetDriverEvents>* onEvent(common::Event<EthernetDriverEvents>* event);

virtual void BeforeSend(common::uint8_t* buffer, common::uint32_t size);
virtual void DataSent(common::uint8_t* buffer, common::uint32_t size);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/drivers/peripherals/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace maxOS
KeyboardEventHandler();
~KeyboardEventHandler();

virtual void onEvent(common::Event<KeyboardEvents>* event);
virtual common::Event<KeyboardEvents>* onEvent(common::Event<KeyboardEvents>* event);

virtual void onKeyDown(KeyCode keyDownCode, KeyboardState keyDownState);
virtual void onKeyUp(KeyCode keyUpCode, KeyboardState keyUpState);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/drivers/peripherals/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace maxOS {
MouseEventHandler();
~MouseEventHandler();

void onEvent(common::Event<MouseEvents>* event);
common::Event<MouseEvents>* onEvent(common::Event<MouseEvents>* event);

virtual void onMouseDownEvent(common::uint8_t button);
virtual void onMouseUpEvent(common::uint8_t button);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/gui/widgets/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace maxOS {
ButtonEventHandler();
~ButtonEventHandler();

virtual void onEvent(common::Event<ButtonEvents>* event);
virtual common::Event<ButtonEvents>* onEvent(common::Event<ButtonEvents>* event);

virtual void onButtonPressed(Button* source);
virtual void onButtonReleased(Button* source);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/gui/widgets/inputbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace maxOS{
InputBoxEventHandler();
~InputBoxEventHandler();

virtual void onEvent(common::Event<InputBoxEvents>* event);
virtual common::Event<InputBoxEvents>* onEvent(common::Event<InputBoxEvents>* event);

virtual void onInputBoxTextChanged(common::string newText);
};
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/net/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace maxOS{
common::OutputStream* errorMessages);
~InternetProtocolHandler();

bool handleEthernetframePayload(common::uint8_t* etherframePayload, common::uint32_t size);
bool handleEthernetframePayload(common::uint8_t* ethernetframePayload, common::uint32_t size);
void sendInternetProtocolPacket(common::uint32_t dstIP_BE, common::uint8_t protocol, common::uint8_t* data, common::uint32_t size);

static common::uint16_t Checksum(common::uint16_t* data, common::uint32_t lengthInBytes);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace maxOS{
TransmissionControlProtocolPayloadHandler();
~TransmissionControlProtocolPayloadHandler();

void onEvent(common::Event<TransmissionControlProtocolPayloadHandlerEvents>* event);
common::Event<TransmissionControlProtocolPayloadHandlerEvents>* onEvent(common::Event<TransmissionControlProtocolPayloadHandlerEvents>* event);

virtual void handleTransmissionControlProtocolPayload(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size);
virtual void Connected(TransmissionControlProtocolSocket* socket);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/net/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace maxOS
UserDatagramProtocolPayloadHandler();
~UserDatagramProtocolPayloadHandler();

void onEvent(common::Event<UserDatagramProtocolEvents>* event);
common::Event<UserDatagramProtocolEvents>* onEvent(common::Event<UserDatagramProtocolEvents>* event);

virtual void handleUserDatagramProtocolMessage(UserDatagramProtocolSocket* socket, common::uint8_t* data, common::uint16_t size);

Expand Down
5 changes: 4 additions & 1 deletion kernel/src/drivers/clock/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ClockEventHandler::onTime(const Time &time) {

}

void ClockEventHandler::onEvent(Event<ClockEvents>* event) {
Event<ClockEvents>* ClockEventHandler::onEvent(Event<ClockEvents>* event) {

switch (event -> type) {
case TIME:
Expand All @@ -38,6 +38,9 @@ void ClockEventHandler::onEvent(Event<ClockEvents>* event) {
default:
break;
}

// Return the event
return event;
}

///__Clock__
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/drivers/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ DriverSelector::~DriverSelector()
{
}

void DriverSelector::selectDrivers(DriverSelectorEventHandler*, MemoryManager*, hardwarecommunication::InterruptManager*, OutputStream*)
void DriverSelector::selectDrivers(DriverSelectorEventHandler*, hardwarecommunication::InterruptManager*, OutputStream*)
{
}

Expand Down
12 changes: 0 additions & 12 deletions kernel/src/drivers/ethernet/amd_am79c973.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ amd_am79c973::~amd_am79c973()
void amd_am79c973::activate()
{

//TODO: Implment new console driver and use the stream for it here, causes GPF erorr int so return for now
return;

driverMessageStream -> write("Activating AMD 79C973 Ethernet Controller ");


initDone = false; // Set initDone to false
registerAddressPort.Write(0); // Tell device to write to register 0
registerDataPort.Write(0x41); // Enable Interrupts and start the device
Expand All @@ -132,7 +126,6 @@ void amd_am79c973::activate()
registerDataPort.Write(0x42); // Tell device that it is initialised and can begin operating

active = true; // Set active to true
driverMessageStream -> write("AMD am79c973 INIT DONE\n");
}

/**
Expand Down Expand Up @@ -206,8 +199,6 @@ void amd_am79c973::DoSend(common::uint8_t *buffer, uint32_t size) {

}



// What this loop does is copy the information passed as the parameter buffer (src) to the send buffer in the ram (dst) which the card will then use to send the data
for (uint8_t *src = buffer + size -1, // Set src pointer to the end of the data that is being sent
*dst = (uint8_t*)(sendBufferDescr[sendDescriptor].address + size -1); // Take the buffer that has been slected
Expand All @@ -227,9 +218,6 @@ void amd_am79c973::DoSend(common::uint8_t *buffer, uint32_t size) {

registerAddressPort.Write(0); // Tell device to write to register 0
registerDataPort.Write(0x48); // Tell device to send the data currently in the buffer

driverMessageStream -> write(" Done\n");

}

void amd_am79c973::FetchDataReceived()
Expand Down
36 changes: 21 additions & 15 deletions kernel/src/drivers/ethernet/ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void EthernetDriverEventHandler::DataSent(uint8_t*, uint32_t)
{
}

void EthernetDriverEventHandler::onEvent(common::Event<EthernetDriverEvents> *event) {
Event<EthernetDriverEvents>* EthernetDriverEventHandler::onEvent(common::Event<EthernetDriverEvents> *event) {

switch (event -> type) {

Expand All @@ -47,12 +47,14 @@ void EthernetDriverEventHandler::onEvent(common::Event<EthernetDriverEvents> *ev
break;

case EthernetDriverEvents::DATA_RECEIVED:
DataReceived(((DataReceivedEvent*)event) -> buffer, ((DataReceivedEvent*)event) -> size);
event->returnValue.boolValue = DataReceived(((DataReceivedEvent*)event) -> buffer, ((DataReceivedEvent*)event) -> size);
break;

default:
break;
}

return event;
}


Expand Down Expand Up @@ -99,7 +101,6 @@ void EthernetDriver::Send(uint8_t* buffer, uint32_t size)
// Raise the event
raiseEvent(new BeforeSendEvent(buffer, size));

//Used for debuging printf("Status: ");
DoSend(buffer, size);
}

Expand Down Expand Up @@ -128,19 +129,24 @@ void EthernetDriver::FireDataReceived(uint8_t* buffer, uint32_t size)
}
driverMessageStream -> write("\n");


bool SendBack = false;

//TODO: For now raise event cant return a value, need to find a workaround
for(Vector<EventHandler<EthernetDriverEvents>*>::iterator i = handlers.begin(); i != handlers.end(); i++)
if(((EthernetDriverEventHandler*)i)->DataReceived(buffer, size))
SendBack = true;

if(SendBack){
driverMessageStream -> write("Sending back... \n");
Send(buffer, size);
// Raise the event
Vector<Event<EthernetDriverEvents>*> values = raiseEvent(new DataReceivedEvent(buffer, size));

// Loop through the events
for(typename Vector<Event<EthernetDriverEvents>*>::iterator event = values.begin(); event != values.end(); ++event) {
switch ((*event)->type) {
case EthernetDriverEvents::DATA_RECEIVED:
if((*event)->returnValue.boolValue){
driverMessageStream -> write("Sending back... \n");
Send(buffer, size);
}
break;

default:
break;
}
}

driverMessageStream -> write("DATA HANDLED\n");
}

/**
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/drivers/peripherals/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void KeyboardEventHandler::onKeyUp(KeyCode keyUpCode, KeyboardState keyUpState)
{
}

void KeyboardEventHandler::onEvent(Event<KeyboardEvents> *event) {
Event<KeyboardEvents>* KeyboardEventHandler::onEvent(Event<KeyboardEvents> *event) {

switch (event -> type) {

Expand All @@ -46,6 +46,8 @@ void KeyboardEventHandler::onEvent(Event<KeyboardEvents> *event) {
break;
}

return event;

}


Expand Down
5 changes: 4 additions & 1 deletion kernel/src/drivers/peripherals/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MouseEventHandler::MouseEventHandler() {
* @details This function is called when an event is triggered and calls the appropriate function
* @param event The event that was triggered
*/
void MouseEventHandler::onEvent(Event<MouseEvents> *event) {
Event<MouseEvents>* MouseEventHandler::onEvent(Event<MouseEvents> *event) {
switch (event->type){

case MOUSE_MOVE:
Expand All @@ -35,6 +35,9 @@ void MouseEventHandler::onEvent(Event<MouseEvents> *event) {
break;

}

// Return the event
return event;
}


Expand Down
4 changes: 3 additions & 1 deletion kernel/src/gui/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ButtonEventHandler::~ButtonEventHandler() {
* @details Handles the button events
* @param event The event to handle
*/
void ButtonEventHandler::onEvent(Event<ButtonEvents> *event) {
Event<ButtonEvents>* ButtonEventHandler::onEvent(Event<ButtonEvents> *event) {

// Check the event type
switch (event -> type) {
Expand All @@ -41,6 +41,8 @@ void ButtonEventHandler::onEvent(Event<ButtonEvents> *event) {

}

return event;

}

/**
Expand Down
4 changes: 3 additions & 1 deletion kernel/src/gui/widgets/inputbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ InputBoxEventHandler::~InputBoxEventHandler() {

}

void InputBoxEventHandler::onEvent(Event<InputBoxEvents> *event) {
Event<InputBoxEvents>* InputBoxEventHandler::onEvent(Event<InputBoxEvents> *event) {
switch (event->type) {
case INPUTBOX_TEXT_CHANGED:
onInputBoxTextChanged(((InputBoxTextChangedEvent*)event)->newText);
break;
}

return event;
}

void InputBoxEventHandler::onInputBoxTextChanged(string newText) {
Expand Down
Loading

0 comments on commit 09f3b98

Please sign in to comment.