1 // List recently-released Linux applications. (Written in C++.)
2 // For more details about O'Reilly's excellent Meerkat news service, see:
3 // http://www.oreillynet.com/pub/a/rss/2000/11/14/meerkat_xmlrpc.html */
11 #include <xmlrpc-c/oldcppwrapper.hpp>
13 #define NAME "XML-RPC C++ Meerkat Query Demo"
15 #define MEERKAT_URL "http://www.oreillynet.com/meerkat/xml-rpc/server.php"
16 #define SOFTWARE_LINUX (6)
19 list_apps(unsigned int const hours) {
21 // Build our time_period parameter.
22 ostringstream time_period_stream;
23 time_period_stream << hours << "HOUR";
24 string const time_period(time_period_stream.str());
26 // Assemble our meerkat query recipe.
27 XmlRpcValue recipe = XmlRpcValue::makeStruct();
28 recipe.structSetValue("category", XmlRpcValue::makeInt(SOFTWARE_LINUX));
29 recipe.structSetValue("time_period", XmlRpcValue::makeString(time_period));
30 recipe.structSetValue("descriptions", XmlRpcValue::makeInt(76));
32 // Build our parameter array.
33 XmlRpcValue param_array(XmlRpcValue::makeArray());
34 param_array.arrayAppendItem(recipe);
36 // Create a client pointing to Meerkat.
37 XmlRpcClient meerkat(MEERKAT_URL);
40 XmlRpcValue const apps(meerkat.call("meerkat.getItems", param_array));
43 size_t const app_count(apps.arraySize());
46 for (i = 0, first=false; i < app_count; ++i, first = false) {
47 XmlRpcValue const app(apps.arrayGetItem(i));
49 // Get some information about our application.
50 string const title(app.structGetValue("title").getString());
51 string const link(app.structGetValue("link").getString());
52 string const description(
53 app.structGetValue("description").getString());
55 // Print a separator line if necessary.
59 // Print this application entry.
60 if (description.size() > 0)
61 cout << title << endl << description << endl << link << endl;
63 cout << title << endl << description << endl << link << endl;
70 main(int argc, char **argv) {
74 // Parse our command-line arguments.
77 } else if (argc == 2) {
78 hours = atoi(argv[1]);
81 cerr << "Hours must be positive" << endl;
85 cerr << "It's not nice to ask for > 49 hours at once." << endl;
89 // Start up our client library.
90 XmlRpcClient::Initialize(NAME, VERSION);
92 // Call our implementation, and watch out for faults.
96 } catch (XmlRpcFault& fault) {
97 cerr << argv[0] << ": XML-RPC fault #" << fault.getFaultCode()
98 << ": " << fault.getFaultString() << endl;
102 // Shut down our client library.
103 XmlRpcClient::Terminate();