Console Driver Problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
codemastersnake

Console Driver Problem

Post by codemastersnake »

Hello everybody!

Well I am developing a 32 bit PM OS and have already developed a Console driver for it....

I am developing my OS in C++....

Well my problem is :

I have developed a C++ console mode vriver and it has a constructor whicxh gets initialized whenever an object of Console class is created and what this constructor does is initializes the xpos and ypos variables with zero and then clears the screen and places cursor on the top left of the screen.....

I will also be devloping other drivers in C++ also say for Clock.... What I want is that when ever clock clase's object is created I want to put a message on the screen like in linux that clock mode driver is loaded in the memory... to do this I'll need console driver (but obviously) but if I creat anothe console object in clock class then the whole screen will get resetted and message will get printed on the top left of the screen....

what could I do to make this work....

I WILL USE CLASSES AND NOTHING ELSE....

plz help...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Console Driver Problem

Post by Solar »

Obviously you cannot initialize a new console for the output, so you have to use an already existing one. How you solve this depends on where you want that output to end up.

One way would be to provide a static member function in class Console that returns a reference to a certain Console object - perhaps the first one initialized, or the one currently displayed.

Another would be to pass a reference to a Console object to the constructor of class Clock.
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Console Driver Problem

Post by Candy »

Solar wrote: One way would be to provide a static member function in class Console that returns a reference to a certain Console object - perhaps the first one initialized, or the one currently displayed.
This would be called an implementation of a design pattern called "singleton". Use design patterns in your OO software (all of it), it helps build good designs when used properly.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Console Driver Problem

Post by Solar »

Candy wrote: This would be called an implementation of a design pattern called "singleton".
Nope. A Singleton is a design pattern ensuring that there can only be one instance of a class. (And it's the most over- and abused design pattern of all.)
Use design patterns in your OO software (all of it), it helps build good designs when used properly.
Emphasis is mine. You should be very familiar with OO programming before you start extensive use of design patterns. Nine out of ten pattern implementations I have seen were misplaced, didn't solve the problem at hand and / or introduced needless complexity.

They are nice, but as everything, they should be understood as a tool, not a religion.
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Console Driver Problem

Post by Candy »

Solar wrote:
Candy wrote: This would be called an implementation of a design pattern called "singleton".
Nope. A Singleton is a design pattern ensuring that there can only be one instance of a class. (And it's the most over- and abused design pattern of all.)
I would most certainly qualify a console controller as a place to use a singleton, since it's a class that may only be instantiated once for its proper function. Why do you claim it's a bad place for a singleton?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Console Driver Problem

Post by Solar »

Candy wrote: Why do you claim it's a bad place for a singleton?
Codemaster Snake wrote (emphasis is mine):
I have developed a C++ console mode vriver and it has a constructor whicxh gets initialized whenever an object of Console class is created...
I assume he means to make multiple consoles possible, like those offered by Linux if you press Alt-F1, Alt-F2 etc.

That means there can be more than one Console object, but you'd need either a global variable or a class method to get "the right one". Class method is preferred, of course.
Every good solution is obvious once you've found it.
codemastersnake

Re:Console Driver Problem

Post by codemastersnake »

No I don't want multiple consoles...

Can anyone plz provide some good example for it or a weblink
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Console Driver Problem

Post by Solar »

After reading this excellent article on the hubbub you can perform around the Singleton pattern you will perhaps agree that this pattern isn't really necessary, and that instanciating a single global Console object and using that might suffice. ;)
Every good solution is obvious once you've found it.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Console Driver Problem

Post by Candy »

Solar wrote: After reading this excellent article on the hubbub you can perform around the Singleton pattern you will perhaps agree that this pattern isn't really necessary, and that instanciating a single global Console object and using that might suffice. ;)
Naturally, a singleton is only a nice wrapper around a global object in the most common implementation.
Post Reply