Event Handling!
Posted: Mon Dec 15, 2014 9:04 pm
Hi,
I am developing an x86/x86_64 operating system. You can read more about it here.
So now as I am able to do advanced process handling (obviously I can load ELF executables), I have ported libstdc++ and libc (used newlib) for me to directly build applications for my operating system. Playing around with this, I decided to write a library (like the .Net framework) to do "basic" operations for the user. I recently wrote a library called "iVGA", which is a graphics compositor that allows advanced 2D graphics. And this library (I am calling it "VX Framework" for now) will be an extension to this library where it will support buttons, windows, file I/O, ... and other high-level interfaces that allow easy development. All this will be done in C++. (Really, for those who ONLY use C, this is 21st century, we have to move on. It is true that C and ASM are the best languages to use for low-level programming, but when it comes to userland programs, C++ is better).
So then I ran into a problem.
How do I handle events?
I have already created a basic class structure (VX-->vObject-->vButton, vWindow, vFileStream, ... --> ... --> ...
The events will be represented by the "vEvent" class objects, which will be instantiated automatically once a vObject is instantiated. Each vObject-inherited classes, depending on their needs, may define as many events as they want
For instance:
like this.
The constructors of the class will configure the "vEvent" objects so that the events are properly linked (binded) to a function that the user desires. (You could link "MouseDownEvent" against "Application::Exit" for close buttons.)
This approach is used because even after the constructor is called, the developers actually are able to modify, unlink , and link new functions against the predefined events. Like this:
(In case anybody is wondering, the "vEventArgs" class is used as like a little packet for the vEvent to send information about the event (e.g. mouse x coordinate, y coordinate, duration) to the function. It will have a "char bin[]" field so that special events (non-"standard" and irregular) can just send the information in bytes.)
So getting to the point, how could I write the "vEvent" class so that it allows the selection of different events (mouse up, mouse down, etc.), creation of new events, and call the linked function(s) once the corresponding events have occurred?
btw, I have something called the ICN (Intercomponent Network) system, which allows the kernel, processses, and/or threads to communicate with each other.
Thank you!
I am developing an x86/x86_64 operating system. You can read more about it here.
So now as I am able to do advanced process handling (obviously I can load ELF executables), I have ported libstdc++ and libc (used newlib) for me to directly build applications for my operating system. Playing around with this, I decided to write a library (like the .Net framework) to do "basic" operations for the user. I recently wrote a library called "iVGA", which is a graphics compositor that allows advanced 2D graphics. And this library (I am calling it "VX Framework" for now) will be an extension to this library where it will support buttons, windows, file I/O, ... and other high-level interfaces that allow easy development. All this will be done in C++. (Really, for those who ONLY use C, this is 21st century, we have to move on. It is true that C and ASM are the best languages to use for low-level programming, but when it comes to userland programs, C++ is better).
So then I ran into a problem.
How do I handle events?
I have already created a basic class structure (VX-->vObject-->vButton, vWindow, vFileStream, ... --> ... --> ...
The events will be represented by the "vEvent" class objects, which will be instantiated automatically once a vObject is instantiated. Each vObject-inherited classes, depending on their needs, may define as many events as they want
For instance:
Code: Select all
class vButton : (public vObject) {
...
vEvent MouseDownEvent;
vEvent MouseUpEvent;
vEvent MouseDragEvent;
...
};
The constructors of the class will configure the "vEvent" objects so that the events are properly linked (binded) to a function that the user desires. (You could link "MouseDownEvent" against "Application::Exit" for close buttons.)
This approach is used because even after the constructor is called, the developers actually are able to modify, unlink , and link new functions against the predefined events. Like this:
Code: Select all
int foo (vEventArgs e) {
std::cout << "Close Button Clicked! Closing..." << std::endl;
}
int main (int __argc, char* __argv[]) {
vButton btn1 ("Close", Application::Close); // constructor links button mousedown event
// against "Application::Close"
btn1.MouseDownEvent.unlink(); // unlink previous linkage against mousedown event
btn1.MouseDownEvent.link(foo); // re-link mousedown events against new function
}
So getting to the point, how could I write the "vEvent" class so that it allows the selection of different events (mouse up, mouse down, etc.), creation of new events, and call the linked function(s) once the corresponding events have occurred?
btw, I have something called the ICN (Intercomponent Network) system, which allows the kernel, processses, and/or threads to communicate with each other.
Thank you!