00001
00002
00003
00004
00005
00006
00007
00008 #include "wvargs.h"
00009 #include "wvdbusconn.h"
00010 #include "wvistreamlist.h"
00011 #include "wvlinkerhack.h"
00012
00013 WV_LINK_TO(WvTCPConn);
00014
00015 static WvStringList paths;
00016
00017 static bool incoming(WvDBusMsg &msg)
00018 {
00019 WvStringList::Iter i(paths);
00020 for (i.rewind(); i.next(); )
00021 {
00022 if (*i == msg.get_path())
00023 {
00024 fprintf(stderr, "\n * %s\n\n", ((WvString)msg).cstr());
00025 return true;
00026 }
00027 }
00028 return false;
00029 }
00030
00031
00032 int main(int argc, char *argv[])
00033 {
00034 WvArgs args;
00035 WvString moniker("dbus:session");
00036 WvStringList names, remaining_args;
00037 bool sigtest = false, methtest = false, wait = false;
00038
00039
00040 args.add_option('m', "moniker", "Specify the dbus bus to use",
00041 "MONIKER", moniker);
00042 args.add_option('p', "path", "Listen on <path>",
00043 "PATH", paths);
00044 args.add_option('n', "name", "Register as <name>",
00045 "NAME", names);
00046 args.add_set_bool_option('S', "signaltest", "Send a test signal", sigtest);
00047 args.add_set_bool_option('M', "methodtest", "Call test method", methtest);
00048 args.add_set_bool_option('w', "wait", "Wait forever", wait);
00049 args.process(argc, argv, &remaining_args);
00050
00051 WvDBusConn conn(moniker);
00052 WvIStreamList::globallist.append(&conn, false, "wvdbus conn");
00053
00054 conn.add_callback(WvDBusConn::PriNormal, incoming);
00055
00056 WvStringList::Iter i(names);
00057 for (i.rewind(); i.next(); )
00058 conn.request_name(*i);
00059
00060 if (sigtest)
00061 WvDBusSignal("/ca/nit/foo", "ca.nit.foo", "BarSignal").send(conn);
00062
00063 if (methtest)
00064 {
00065 WvDBusMsg("ca.nit.MyListener", "/ca/nit/foo",
00066 "ca.nit.foo", "BarMethod")
00067 .append("bee").send(conn);
00068 }
00069
00070 while (conn.isok() && (wait || !conn.isidle()))
00071 WvIStreamList::globallist.runonce();
00072 return 0;
00073 }