2 using MoonshotRpcInterface;
4 /* This class is the closure when we pass execution from the RPC thread
5 * to the GLib main loop thread; we need to be executing inside the main
6 * loop before we can access any state or make any Gtk+ calls.
8 /* Fixme: can you make *this* an async callback? */
9 public class IdentityRequest : Object {
10 private MainWindow main_window;
11 private Identity **result;
12 private unowned Mutex mutex;
13 private unowned Cond cond;
15 public IdentityRequest (Gtk.Window window,
20 main_window = (MainWindow)window;
26 public bool main_loop_cb ()
28 // Execution is passed from the RPC get_identity() call to
29 // here, where we are inside the main loop thread.
30 main_window.set_callback (this.id_card_selected_cb);
34 public bool id_card_selected_cb ()
36 var id_card = this.main_window.selected_id_card_widget.id_card;
39 *result = new Identity();
41 (*result)->identity = "identity";
42 (*result)->password = id_card.password;
43 (*result)->service = "certificate";
48 // 'result' is freed by the RPC runtime
54 /* This class must be a singleton, because we use a global RPC
55 * binding handle. I cannot picture a situation where more than
56 * one instance of the same interface would be needed so this
57 * shouldn't be a problem.
59 * Shutdown is automatically done by the RPC runtime when the
62 public class MoonshotServer : Object {
63 private static int counter;
64 private static MainWindow main_window;
66 private static MoonshotServer instance = null;
68 public static void start (Gtk.Window window)
70 main_window = (MainWindow) window;
71 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot");
74 public static MoonshotServer get_instance ()
77 instance = new MoonshotServer ();
81 /* Note that these RPC callbacks execute outside the GLib main loop,
82 * in threads owned by the RPC runtime
85 [CCode (cname = "moonshot_ping")]
86 public static int ping (string msg)
88 stdout.printf ("%s\n", msg);
92 [CCode (cname = "moonshot_get_identity")]
93 public static void moonshot_get_identity (Rpc.AsyncCall call,
99 Mutex mutex = new Mutex ();
100 Cond cond = new Cond ();
105 IdentityRequest request = new IdentityRequest (main_window, result, mutex, cond);
107 // Pass execution to the main loop thread and wait for
108 // the 'send' action to be signalled.
109 Idle.add (request.main_loop_cb);
110 while (*result == null)