public void Pulse() { if (handle.id != UIntPtr.Zero) { InterruptHandle.Pulse(handle); } }
public bool ReleaseInterrupt() { bool ret = InterruptHandle.Dispose(handle); handle = new InterruptHandle(); return(ret); }
public bool AckInterrupt() { if (handle.id != UIntPtr.Zero) { return(InterruptHandle.Ack(handle)); } return(false); }
public bool WaitForInterrupt() { if (handle.id != UIntPtr.Zero) { return(InterruptHandle.Wait(handle)); } return(false); }
public bool RegisterInterrupt() { InterruptHandle handleOnStack; bool success = InterruptHandle.Create(irq, out handleOnStack); handle = handleOnStack; return(success); }
private async Task <string> GetResponseContent(string endpoint, string requestBody) { Logger.Verbose("Making request to " + endpoint + " endpoint..."); var restClient = new RestClient(ApiClient.ApiUrl); var restRequest = new RestRequest(endpoint, Method.POST) { RequestFormat = DataFormat.Json }; restRequest.AddParameter("application/json", requestBody, ParameterType.RequestBody); if (IsAuthenticatedRequest) { if (string.IsNullOrEmpty(ApiClient.ApiKey)) { throw new MissingFieldException("API key not provided for authenticated request."); } if (string.IsNullOrEmpty(ApiClient.PrivateKeyPem)) { throw new MissingFieldException("Private key not provided"); } var signature = AsymmetricCryptoUtil.CreateSignature(requestBody, ApiClient.PrivateKeyPem); restRequest.AddHeader("Authorization", "token " + ApiClient.ApiKey + ":" + signature); } IRestResponse restResponse = new RestResponse(); if (InterruptHandleSet) { // Perform the request asynchronously, but block on the interrupt handle. var responseReceived = false; var asyncHandle = restClient.ExecuteAsync(restRequest, response => { responseReceived = true; restResponse = response; InterruptHandle.Set(); }); InterruptHandle.WaitOne(); if (!responseReceived) { asyncHandle.Abort(); throw new RequestException("Network error. Request was interrupted."); } } else { var cancellationTokenSource = new CancellationTokenSource(); restResponse = await restClient.ExecuteTaskAsync(restRequest, cancellationTokenSource.Token); } if (restResponse.StatusCode == 0) { throw new RequestException("Network error. Could not connect to server."); } if (restResponse.StatusCode != HttpStatusCode.OK) { ErrorResponse errorResponse; try { errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(restResponse.Content); } catch (Exception) { throw new NetworkErrorException("Unknown error whilst contacting server"); } switch (restResponse.StatusCode) { case HttpStatusCode.BadRequest: throw new BadRequestException(errorResponse.Error); case HttpStatusCode.Unauthorized: throw new UnauthorizedException(errorResponse.Error); case HttpStatusCode.NotFound: throw new NotFoundException(errorResponse.Error); case HttpStatusCode.Conflict: throw new NotFoundException(errorResponse.Error); default: throw new RequestException(errorResponse.Error); } } Logger.Verbose("Received response: " + restResponse.Content); return(restResponse.Content); }