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 Rpc.AsyncCall call;
10 private MainWindow main_window;
11 private Identity **result;
13 public IdentityRequest (Rpc.AsyncCall _call,
18 main_window = (MainWindow)window;
22 public bool main_loop_cb ()
24 // Execution is passed from the RPC get_identity() call to
25 // here, where we are inside the main loop thread.
26 main_window.set_callback (this.id_card_selected_cb);
30 public bool id_card_selected_cb ()
32 var id_card = this.main_window.selected_id_card_widget.id_card;
34 *result = new Identity();
36 (*result)->identity = "identity";
37 (*result)->password = id_card.password;
38 (*result)->service = "certificate";
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 int counter;
58 private static MainWindow main_window;
60 private static MoonshotServer instance = null;
62 public static void start (Gtk.Window window)
64 main_window = (MainWindow) window;
65 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot");
68 public static MoonshotServer get_instance ()
71 instance = new MoonshotServer ();
75 /* Note that these RPC callbacks execute outside the GLib main loop,
76 * in threads owned by the RPC runtime
79 [CCode (cname = "moonshot_ping")]
80 public static int ping (string msg)
82 stdout.printf ("%s\n", msg);
86 [CCode (cname = "moonshot_get_identity")]
87 public static void moonshot_get_identity (Rpc.AsyncCall call,
93 IdentityRequest request = new IdentityRequest (call, main_window, result);
95 // Pass execution to the main loop thread
96 Idle.add (request.main_loop_cb);