I want to make some debug console for my application. It shou开发者_运维知识库ld output some data and take input commands. How can I do this? The best way is updating console like: drawing information and prompt for input after the data. I'm developing under Linux. For example, gdb could take input from console.
If you're familiar with socket programming (or actually, any other kind of IPC mechanism), you might want to enable some listener within your application, and develop an external application that will do all the "console" stuff for you, while communicating with the main application.
Let's suppose you have an application that has a single button and a single text label, and every time you press that button - the text label goes up by 1, from 1 to 2 to 3 etc.
You can build a socket listener into that application. When the socket listener accepts a new incoming connection, you'd start a connection thread that can:
- Receive a "shutdown" command
- Receive a "reset counter" command
- Send an update regarding the current count on every click
- etc.
Then you build another, external application, which connects to the main application, and sends messages to it, based on console input it gets from the user. It would also listen to incoming updates and show them to the user.
Using an external application for debug-controlling your main application is extremely helpful, with the following reasons being some of the advantages:
- No matter how the debug application is buggy, it cannot hurt the release version of your main application.
- All the code that deals with the console management, which is redundant to your main application, can be kept outside of the main app.
- Making two projects out of it can make it easier to collaborate your work with someone else, as long as you are both aware of the protocol between the two sides.
- Implementing what I suggested means you can debug your application remotely, in case you don't have access to the main application (for example, if it's on a customer site).
精彩评论