Web Interfaces for C++ Introspection? 66
Milo_Mindbender asks: "For a C++ application I'm working on I want to be able to pop up an interface to a class that will display all the 'tunable' parameters of the class and let me inspect/modify them, while the program is running. The catch is that I'm running on a minimal embedded OS with Open GL but no GUI library. Rather than porting a widget set or writing my own, I was thinking about having the application talk to a web browser, and then use the browser to display the GUI, take user input, and finally push the data back to the app. The classes have metadata that describes the public data locations/types so they can be accessed, but not being a web-wizard I'm not sure of the best way of generating the information I need to create the UI. My first thought is to generate HTML and push that to the browser, but it seems like there must be a better way than this, maybe someone has written a library specifically for doing this sort of thing? Any help/suggestions would be appreciated!"
Why GUI (Score:4, Insightful)
Re:Why GUI (Score:2, Insightful)
get myvar, set myvar xxyy, toggle myvar, listvars etc etc
Yeah, web interfaces are nice for end-users, but since you just want to debug your own one-off app and it's quite likely you will be the only person doing it, might as well be lazy - I mean efficient -
Re:Why GUI (Score:2)
And if you want a GUI, then it's a simple bit of Python to add a front end to that serial comms and text. A web interface is usually a pretty dumb move, unless you're sure that the person using the interface won't have the relevant software.
Grab.
Uhh, AJAX? (Score:2)
Rather than porting a widget set or writing my own, I was thinking about having the application talk to a web browser, and then use the browser to display the GUI, take user input, and finally push the data back to the app.
WARNING: BUZZWORD COMPLIANCE ALERT!!!
Uhh, isn't this exactly what AJAX was invented for? If his "minimal embedded OS with Open GL but no GUI library" had an eency-weency [itsy-bitsy?] little webserver, like thttpd, with some sort of an AJAX extension, then he could interactively push
This question is odd.... (Score:3, Insightful)
So either he isn't being completely accurate in so much that he might not be as knowledgeable as he claims or just by freak chance managed never to write a web-server in a couple of hours like everyone else...
Re:This question is odd.... (Score:3, Interesting)
Re:This question is odd.... (Score:2, Interesting)
Re:This question is odd.... (Score:3, Informative)
Re:This question is odd.... (Score:4, Informative)
You're right...you should use pthreads or nptl [wikipedia.org] instead.
Some advice from someone who makes the same mistake every now and then...When you learn something in class, don't talk about it on Slashdot for at least a month. That'll give you a chance to think before you type.
In the mean time, dissing UNIX around here is likely to get you modded "Troll."
Re:This question is odd.... (Score:1)
Re:This question is odd.... (Score:1)
Other examples:
Re:This question is odd.... (Score:2)
Personally, I think threads are a stupid thing to use unless there's no other way to achieve your goal. I would suggest looking at the 'epoll' call on Linux and the kernel queue (kqueue?) on BSD. select and poll aren't that great.
Re:This question is odd.... (Score:2)
Re:This question is odd.... (Score:1)
That's true. Though I consider the interface itself to be a little ugly. :-) And using select, poll, or epoll still makes signal handlers a pain, though they aren't with kqueues.
Re:This question is odd.... (Score:5, Informative)
Why would you want to use a CSP-style concurrency model instead of threads? To quote from the occam compiler homepage:
In layman's terms, you get concurrency that can be built up from easily understood pieces (instead of a monolithically concurrent system with locks scattered throughout the code), and an underlying theory of concurrency that lets you understand and analyze your design and ensure that it is, for example, free of deadlocks (I've personally created complex networks of 1000+ interacting processes in a dynamically evolving topology, with nary a hitch). And did I mentioned that the context-switching performance of most of these systems is amazingly good?
Re:This question is odd.... (Score:2)
I see: you indeed are a future Windows programmer, and you are ready to produce the same bloated and flaky software that your predecessors produce.
(FWIW, you don't have to use fork for parallelism on UNIX; UNIX systems have always had better threads than Windows, it's just that UNIX programmers have the good sense not to use threads if they can help it.)
Re:This question is odd.... (Score:3, Interesting)
Re:This question is odd.... (Score:2)
whereas if you code the web server yourself you can just build it into your daemon and access the daemons transiant data through direct procedure/method calls or even direct reading of global variables or fields.
and provided you don't care about things like chunked enc
Re:This question is odd.... (Score:1, Interesting)
The guy clearly knows C++ and is able to develop on an embedded OS which isn't an easy thing to do but yet can't write himself a simple web-server
Sorry, you've just given yourself away as an amateur. Every professional with two brain cells to rub together quickly realises that writing everything yourself is a non-starter, and that decent libraries can make you more productive than dozens of programmers who choose to write everything themselves.
Re:This question is odd.... (Score:4, Insightful)
Well, I didn't assume he was asking how to write an http server. I assumed he was looking for introspection facilities like Java's, which C++ doesn't have. I wish it did. typeinfo could be that if any compiler manufacturer implemented a rich enough set of extensions to it.
It would be nice to get, at runtime, a list of pointers to functions a class supported as well as their names and type signatures. It would also be nice to be able to get a list of members and their types and their offsets from the beginning of the class.
Re:This question is odd.... (Score:2)
I've been using C for over 25 years, and C++ for nearly 20, and I don't remember writing a web server when I was a newbie.
(Of course, the web did not yet exist when I was a newbie, so that's probably why.)
The point is, I've also written device drivers and othe
Well, you don't necessarily need a web browser... (Score:3, Insightful)
If it must be accessible via the web/intranet/browser/etc, set up some of your favorite CGI/PHP/JSP/Python/Ruby and have it talk to the application via TCP/IP and to the browser with HTTP.
Re:Well, you don't necessarily need a web browser. (Score:2)
So yeah, write a text interface to a socket, and telnet to it from off the box. It may not be clickably pretty, but he can probably solve his problems quickly. It's what I used to do twelve yea
Tell us about your metadata! (Score:2)
Of course, I don't know of any such libraries, but anyway. I am very interested in how you'd be doing reflection-type stuff in C++. I'd like to investigate doing that to do mock objects, like nmock does.
Remote XUL (Score:3, Informative)
You may be interested in XUL [mozilla.org] then. Especially, in remote XUL [mozilla.org].
Also, see Remote XUL Application Development with_Mozilla I [mozilla.org] and Remote XUL Application Development with Mozilla II [mozilla.org].
You may even be able to create the UI XML files automatically from your interfaces, using a script, or introspection.
You can then send the data back to your host, using RPCs or a REST-like interface.
Light minimal XML interface (Score:3, Interesting)
You could display your state as a single XML document that is gotten at a single URL. Each setting could be manipulated by posting to a URL specified in the XML document. These sets of documents and post URLs could become a simple CGI set of interfaces you could describe for anything from webservers, application servers, or other web-aware C++ programs to hook into.
Re:Light minimal XML interface (Score:2)
I suspect the biggest bang for the buck would be embedding a python interpreter with a subset of its standard library. Figure maybe 2-3 MB VM size and about the same on disk. Everything the poster needs is in there; the web server, the xml, and the ability to update his C++ code in-process.
Re:Light minimal XML interface (Score:2)
Better hope that "minimal embedded OS" he's using isn't running on a "minimal embedded system" as well. Otherwise 2-3 MB of VM may well be out of the question.
Re:Light minimal XML interface (Score:2)
Re:Light minimal XML interface (Score:1)
Can't tell if you're joking or not, but (modern) computers since the beginning of time read and wrote text. The mainframe at MIT worked with text (and much more) back when the first megabyte stick of memory cost over a million dollars, without adjusting that sum for inflation. Of course, you need enough memory to hold the text you're working with, but to work with it, you need, at most, kilobytes.
Re:Light minimal XML interface (Score:2)
Markup Languages (Score:1)
XML is pretty and human readable, but there's a lot of space wasted to make it so - especially for just representing a small structure. A binary markup language would probably be better. For example, two bytes of ASCII would get you the < and one character of an XML tag (even less in Unicode) whereas with a special binary format, you could represent the tag as 1 "start of tag" byte followed by 1 "type of tag" byte. Not pretty and not human readable, but you're proposing having another machine parse it
Re:Markup Languages (Score:2)
At this point I'll point out that the original poster was talking about deploying an entire HTTP server with HTML in the device. If it was even possible to do that, then we know the device was in a class that would allow such waste as an XML export. His idea of pushing HTML from his device to the browser is perhaps one of the single worst ideas I've ever heard. If this is a one off project that nobody cares about, then fine, but i
GLUI (Score:3, Interesting)
Re:GLUI (Score:2)
Just link something like libhttpd. You can find enough information in the documentation to get you started. Just use httpdPrintd(server, "Mijn var is %s, foo) to show your variables and myvar = httpdGetVariableByName(server) to get posted (changed) values back. [hughes.com.au]
It would help.... (Score:2)
Assuming only a socket API, the easiest thing to do is use a simple text-based protocol, talking to a minimalistic TCP server, probably written in PHP, Perl, or Java, and acting as a FastCGI script. You'll find it much quicker and less error prone, chatty, and code-heav
Re:It would help.... (Score:1)
He did, it's a minimal embedded OS. There are a thousand and one of these out on the market, plus tens of thousands of others written from scratch in-house.
What about ICE or CORBA? (Score:3, Insightful)
PS. Good alternative to CORBA is ICE (http://www.zeroc.com/ice.html [zeroc.com]), which is basically the same thing as CORBA, and founded by one of the CORBA gurus. ICE has much better C++ mapping, and lots of other nice features.
Hope this helps!
use openGL (Score:2)
Perl and GUIs (Score:1)
Database (Score:2)
Webapp Your App
Consider:
Webapp Database Your App
Now you have 2 simpler problems: get your app to get its data from a database, and get your webapp to display and modify values in the database.
Re:Database (Score:2)
And by database I don't mean say, ASE, MSSQL, Oracle or DB2. You can get very small, very fast in-memory databases.
Use Qt (Score:3, Interesting)
Have you looked at thttpd? (Score:2)
It's a tiny web server with CGI support. You didn't say anything about your target platform, so it's possible that it's still to large, but it's only about 70KB compiled. It would have to be ported to your OS, of course, but at only 8000 lines of code, that shouldn't be too difficult.
As for what to serve up, in the interest of keeping the code small I would suggest defining a custom XML markup rather than HTML. That way your on-board code doesn't have to generate all of the formatting markup to make it
interactive scripting (Score:1)
RPC Server (Score:1)
Slight variation on the 'generate HTML' theme (Score:2, Informative)
How about minimal server-side XML + Client side XSLT?
Requirements:
Now all you have to do is serve the XML and stylesheet, attach the stylesheet to the XML file and watch any XSLT-aware browser do the heavy work of transforming that simp
I guess I wasn't clear enough (Score:2)
Specifically, each object in the app has metadata describing the class m
Re:I guess I wasn't clear enough (Score:2)
Re:I guess I wasn't clear enough (Score:1)
As for how and what to do, look at this:
http://72.14.203.104/search?q=cache:sZENqumprsYJ:w ww.cs.rpi.edu/courses/sysprog/sockets/sock.html [72.14.203.104]
and this:
http://72.14.203.104/search?q=cache:FztWl-yhet8J:w ww.cs.wustl.edu/~schmidt/cs544/socket1.html [72.14.203.104]
After that you just write a few fu
Re:I guess I wasn't clear enough (Score:1)
As to how to do the intro
Suggestions, request for more details (Score:1)
- Changing the runtime state (introspection)
- The GUI
First, I'd like to ask how much memory you have available on the embedded system, and how many classes you are planning on using this introspection approach on. Do you have threads or processes on the embedded platform? Does your parameter tuning program have to run on multiple platforms?
If you have enough memory, you may want to embed something like lua, tcl, ruby, guile or pyt