3 [DBus (name = "org.janet.Moonshot")]
4 public class MoonshotServer : Object {
6 private MainWindow main_window;
8 public MoonshotServer (Gtk.Window window)
10 this.main_window = (MainWindow) window;
14 * This is the function used by the GSS mechanism to get the NAI,
15 * password and certificate of the ID card for the specificated service.
17 * The function will block until the user choose the ID card.
19 * @param nai NAI of the ID Card (optional)
20 * @param password Password of the ID Card (optional)
21 * @param service Service application request an ID Card for
22 * @param nai_out NAI stored in the ID Card
23 * @param password_out Password stored in the ID Card
24 * @param certificate Certificate stored in th ID Card
26 * @return true if the user choose a correct ID card for that service,
29 public async bool get_identity (string nai,
33 out string password_out,
34 out string certificate_out)
36 bool has_service = false;
38 var request = new IdentityRequest (main_window,
42 request.set_callback ((IdentityRequest) => get_identity.callback());
50 var id_card = request.id_card;
52 if (id_card != null) {
53 foreach (string id_card_service in id_card.services)
55 if (id_card_service == service)
61 nai_out = id_card.nai;
62 password_out = id_card.password;
63 certificate_out = "certificate";
76 using MoonshotRpcInterface;
78 /* This class must be a singleton, because we use a global RPC
79 * binding handle. I cannot picture a situation where more than
80 * one instance of the same interface would be needed so this
81 * shouldn't be a problem.
83 * Shutdown is automatically done by the RPC runtime when the
86 public class MoonshotServer : Object {
87 private static MainWindow main_window;
89 private static MoonshotServer instance = null;
91 public static void start (Gtk.Window window)
93 main_window = (MainWindow) window;
94 Rpc.server_start (MoonshotRpcInterface.spec, "/org/janet/Moonshot", Rpc.Flags.PER_USER);
97 public static MoonshotServer get_instance ()
100 instance = new MoonshotServer ();
104 [CCode (cname = "moonshot_get_identity")]
105 public static void moonshot_get_identity (Rpc.AsyncCall call,
110 ref string password_out,
111 ref string certificate_out)
115 var request = new IdentityRequest (main_window,
120 // Pass execution to the main loop and block the RPC thread
121 request.mutex = new Mutex ();
122 request.cond = new Cond ();
123 request.set_callback (return_identity_cb);
125 request.mutex.lock ();
126 Idle.add (request.execute);
128 while (request.complete == false)
129 request.cond.wait (request.mutex);
133 certificate_out = "";
135 var id_card = request.id_card;
136 bool has_service = false;
138 if (id_card == null) {
139 foreach (string id_card_service in id_card.services)
141 if (id_card_service == service)
147 // The strings are freed by the RPC runtime
148 nai_out = id_card.nai;
149 password_out = id_card.password;
150 certificate_out = "certificate";
156 // The outputs must be set before this function is called. For this
157 // reason they are 'ref' not 'out' parameters - Vala assigns to the
158 // 'out' parameters only at the end of the function, which is too
160 call.return (&result);
162 request.cond.signal ();
163 request.mutex.unlock ();
166 // Called from the main loop thread when an identity has
168 static void return_identity_cb (IdentityRequest request) {
169 // Notify the RPC thread that the request is complete
170 request.mutex.lock ();
171 request.cond.signal ();
173 // Block the main loop until the RPC call has returned
174 // to avoid any races
175 request.cond.wait (request.mutex);
176 request.mutex.unlock ();