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 public class IdentityRequest : Object {
9 private MainWindow main_window;
10 private unowned Mutex mutex;
11 private unowned Cond cond;
13 internal IdCard? id_card = null;
15 public IdentityRequest (Gtk.Window window,
19 main_window = (MainWindow)window;
24 public bool main_loop_cb ()
26 // Execution is passed from the RPC get_identity() call to
27 // here, where we are inside the main loop thread.
28 main_window.set_callback (this.id_card_selected_cb);
32 public bool id_card_selected_cb ()
34 this.id_card = this.main_window.selected_id_card_widget.id_card;
39 // Block the mainloop until the ID card details have been read and
40 // sent, to prevent races
48 /* This class must be a singleton, because we use a global RPC
49 * binding handle. I cannot picture a situation where more than
50 * one instance of the same interface would be needed so this
51 * shouldn't be a problem.
53 * Shutdown is automatically done by the RPC runtime when the
56 public class MoonshotServer : Object {
57 private static MainWindow main_window;
59 private static MoonshotServer instance = null;
61 public static void start (Gtk.Window window)
63 main_window = (MainWindow) window;
64 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot");
67 public static MoonshotServer get_instance ()
70 instance = new MoonshotServer ();
74 [CCode (cname = "moonshot_get_identity")]
75 public static void moonshot_get_identity (Rpc.AsyncCall call,
80 ref string password_out,
81 ref string certificate_out)
83 Mutex mutex = new Mutex ();
84 Cond cond = new Cond ();
89 IdentityRequest request = new IdentityRequest (main_window, mutex, cond);
91 // Pass execution to the main loop thread and wait for
92 // the 'send' action to be signalled.
93 Idle.add (request.main_loop_cb);
94 while (request.id_card == null)
97 // Send back the results. Memory is freed by the RPC runtime.
98 if (request.id_card.nai == nai || request.id_card.password == password)
100 nai_out = request.id_card.nai;
101 password_out = request.id_card.password;
102 certificate_out = "certificate";
110 // The outputs must be set before this function is called. For this
111 // reason they are 'ref' not 'out' parameters - Vala assigns to the
112 // 'out' parameters only at the end of the function, which is too
114 call.return (&result);