diff options
author | Rob Staudinger <robsta@linux.intel.com> | 2012-01-26 18:20:33 +0100 |
---|---|---|
committer | Rob Staudinger <robsta@linux.intel.com> | 2012-01-26 18:20:33 +0100 |
commit | 9e4a3659a69b93dc5c14e7243cd91d65ba7e806e (patch) | |
tree | 04f6901af9b15381bc4a2745b3ef6a92f9bf3422 | |
parent | b571ce1569cf1212fe7502b29582b4d5aafa7733 (diff) |
examples: Update "dictionary-message" so it can also run with C2S
All examples consistently run in C2S mode by default now, passing -p
runs them in P2P mode.
-rw-r--r-- | examples/dictionary-message.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/examples/dictionary-message.c b/examples/dictionary-message.c index d8f02d4..6393a10 100644 --- a/examples/dictionary-message.c +++ b/examples/dictionary-message.c @@ -27,7 +27,10 @@ #define CAPABILITY "org.freedesktop.ytstenut.DictionaryMessage" #define CLIENT_UID "org.freedesktop.ytstenut.DictionaryMessageClient" +#define CLIENT_JID "ytstenut2@test.collabora.co.uk0" + #define SERVER_UID "org.freedesktop.ytstenut.DictionaryMessageServer" +#define SERVER_JID "ytstenut1@test.collabora.co.uk0" /* * Client @@ -83,13 +86,19 @@ _client_roster_service_added (YtsRoster *roster, } static int -run_client (void) +run_client (bool p2p) { YtsClient *client; YtsRoster *roster; GMainLoop *mainloop; - client = yts_client_new_p2p (CLIENT_UID); + if (p2p) + client = yts_client_new_p2p (CLIENT_UID); + else + client = yts_client_new_c2s (CLIENT_JID, CLIENT_UID); + + yts_client_add_capability (client, CAPABILITY, YTS_CAPABILITY_MODE_CONSUMED); + g_signal_connect (client, "authenticated", G_CALLBACK (_client_authenticated), NULL); g_signal_connect (client, "ready", @@ -156,12 +165,16 @@ _server_dictionary_message (YtsClient *client, } static int -run_server (void) +run_server (bool p2p) { YtsClient *client; GMainLoop *mainloop; - client = yts_client_new_p2p (SERVER_UID); + if (p2p) + client = yts_client_new_p2p (SERVER_UID); + else + client = yts_client_new_c2s (SERVER_JID, SERVER_UID); + yts_client_add_capability (client, CAPABILITY, YTS_CAPABILITY_MODE_PROVIDED); g_signal_connect (client, "authenticated", G_CALLBACK (_server_authenticated), NULL); @@ -187,9 +200,11 @@ main (int argc, { bool client = false; bool server = true; + bool p2p = false; GOptionEntry entries[] = { { "client", 'c', 0, G_OPTION_ARG_NONE, &client, "Run as client", NULL }, { "server", 's', 0, G_OPTION_ARG_NONE, &server, "Run as server (default)", NULL }, + { "p2p", 'p', 0, G_OPTION_ARG_NONE, &p2p, "Run in p2p mode", NULL }, { NULL, } }; @@ -209,10 +224,10 @@ main (int argc, if (client) { g_message ("Running as client ..."); - ret = run_client (); + ret = run_client (p2p); } else if (server) { g_message ("Running as server ..."); - ret = run_server (); + ret = run_server (p2p); } else { g_warning ("%s : Not running as server or client, quitting", G_STRLOC); ret = -1; |