namespace StudySystemClient { public errordomain ClientError { ERROR_RESPONSE, UNEXPECTED_RESPONSE, } public class Client { private Connection connection; public Client(string cert_dir) throws Error { connection = new Connection(cert_dir); } public async void ping() throws ClientError { var response = yield connection.send(new Request.Ping()); if (response is Response.Ack) { return; } else if (response is Response.Error) { throw new ClientError.ERROR_RESPONSE( "Error response to Ping: %s", response.value.to_string()); } else { throw new ClientError.UNEXPECTED_RESPONSE( "Unexpected response to Ping"); } } public async Array list_activities() throws ClientError { var request = new Request.ListActivities(); var response = yield connection.send(request); if (response is Response.Activities) { return response.value; } else if (response is Response.Error) { throw new ClientError.ERROR_RESPONSE( "Error response to ListActivities: %s", response.value.to_string()); } else { throw new ClientError.UNEXPECTED_RESPONSE( "Unexpected response to ListActivities"); } } public async void log_session(string subject, ActivityType type, int minutes) throws ClientError { var timestamp = new DateTime.now_utc().to_unix(); var request = new Request.LogSession(subject, type, timestamp, minutes); var response = yield connection.send(request); if (response is Response.Ack) { return; } else if (response is Response.Error) { throw new ClientError.ERROR_RESPONSE( "Error response to LogSession: %s", response.value.to_string()); } else { throw new ClientError.UNEXPECTED_RESPONSE( "Unexpected response to LogSession"); } } } }