2 using MoonshotRpcInterface;
4 /* This class must be a singleton, because we use a global RPC
5 * binding handle. I cannot picture a situation where more than
6 * one instance of the same interface would be needed so this
7 * shouldn't be a problem.
9 * Shutdown is automatically done by the RPC runtime when the
12 public class MoonshotServer : Object {
13 private static MainWindow main_window;
15 private static MoonshotServer instance = null;
17 public static void start (Gtk.Window window)
19 main_window = (MainWindow) window;
20 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot");
23 public static MoonshotServer get_instance ()
26 instance = new MoonshotServer ();
30 [CCode (cname = "moonshot_get_identity")]
31 public static void moonshot_get_identity (Rpc.AsyncCall call,
36 ref string password_out,
37 ref string certificate_out)
40 Mutex mutex = new Mutex ();
41 Cond cond = new Cond ();
45 var request = new IdentityRequest (main_window,
50 // Pass execution to the main loop and block the RPC thread
51 request.set_data ("mutex", mutex);
52 request.set_data ("cond", cond);
53 request.set_return_identity_callback (this.return_identity_cb);
54 Idle.add (request.execute);
56 while (request.complete == false)
63 var id_card = request.id_card;
65 if (id_card == null) {
66 foreach (string id_card_service in id_card.services)
68 if (id_card_service == service)
74 // The strings are freed by the RPC runtime
75 nai_out = id_card.nai;
76 password_out = id_card.password;
77 certificate_out = "certificate";
83 // The outputs must be set before this function is called. For this
84 // reason they are 'ref' not 'out' parameters - Vala assigns to the
85 // 'out' parameters only at the end of the function, which is too
87 call.return (&result);
93 // Called from the main loop thread when an identity has
95 public void return_identity_cb (IdentityRequest request) {
96 Mutex mutex = request.get_data ("mutex");
97 Cond cond = request.get_data ("cond");
99 // Notify the RPC thread that the request is complete
103 // Block the main loop until the RPC call has returned
104 // to avoid any races