/// <inheritdoc/> public string HandleRequest(MemoryRequest request) { uint address = request.Address - MainChunk.Address; if (address == 0) { if (request.Action == MemoryAction.Set) { currentLine += request.Value; return(null); } else if (request.Action == MemoryAction.Get) { throw new NotImplementedException(); } else if (request.Action == MemoryAction.Poke) { Configuration.ConsoleWriter.EmitValue(currentLine); currentLine = string.Empty; return(null); } else { throw new ArgumentException($"The given memory request attempted action {request.Action} which was not supported.", "request"); } } else { throw new MemoryAccessException("This device could not find the requested memory.", request); } }
private string HandleRequest(MemoryChunk chunk, MemoryRequest request) { var mem = storage[chunk]; uint index = request.Address - chunk.Address; if (request.Action == MemoryAction.Get) { return(mem[index]); } else if (request.Action == MemoryAction.Set) { mem[index] = request.Value; return(null); } else if (request.Action == MemoryAction.Poke) { if (!this.Manages(request.Address)) { throw new MemoryAccessException("Sending a poke request to a core requires that the core manages the specific memory.", request); } else { QueueExecution(request.Address); return(null); } } else { throw new ArgumentException($"The given memory request attempted action {request.Action} which was not supported.", "request"); } }
/// <inheritdoc/> public string HandleRequest(MemoryRequest request) { uint address = request.Address - MainChunk.Address; if (address == 0) { if (request.Action == MemoryAction.Set) { //// Set listening key. return(null); } else if (request.Action == MemoryAction.Get) { //// Get listening key. return(false.ToString()); } else { throw new ArgumentException($"The given memory request attempted action {request.Action} which was not supported.", "request"); } } else { throw new MemoryAccessException("This device could not find the requested memory.", request); } }
IClientResponse RedirectIfNeeded(IClientResponse response, MemoryRequest request) { if (response.Status.Code == 301 || response.Status.Code == 302 || response.Status.Code == 303 || response.Status.Code == 307) { return _client.CreateRequest(response.Headers["Location"].ToUri()).Method(request.Method).Send(); } return response; }
IClientResponse RedirectIfNeeded(IClientResponse response, MemoryRequest request) { if (response.Status.Code == 301 || response.Status.Code == 302 || response.Status.Code == 303 || response.Status.Code == 307) { return(_client.CreateRequest(response.Headers["Location"].ToUri()).Method(request.Method).Send()); } return(response); }
/// <summary> /// Starts a local <see cref="MemoryRequest"/> to manage memory internally stored on the <see cref="ICore"/>'s <see cref="Chunks"/>. /// </summary> /// <param name="request">The <see cref="MemoryRequest"/> to execute.</param> /// <returns>A <see cref="string"/> value returned by the memory operation.</returns> /// <exception cref="MemoryAccessException">The operation failed because the given memory could not be accessed by this <see cref="ICore"/> in the requested manner.</exception> public string LocalRequest(MemoryRequest request) { var chunk = this.GetChunk(request.Address); if (chunk.HasValue) { return(HandleRequest(chunk.Value, request)); } else { throw new MemoryAccessException("This core could not find the requested memory.", request); } }
/// <inheritdoc/> public string HandleRequest(MemoryRequest request) { var chunk = this.GetChunk(request.Address, false); if (chunk.HasValue) { return(HandleRequest(chunk.Value, request)); } else { throw new MemoryAccessException("This core does not manage the requested memory.", request); } }
private void Initialize() { // startup state Address.IsEnabled = true; BusAcknowledge.Write(DigitalLevel.High); Halt.Write(DigitalLevel.High); IoRequest.Write(DigitalLevel.High); MemoryRequest.Write(DigitalLevel.High); MachineCycle1.Write(DigitalLevel.High); Refresh.Write(DigitalLevel.High); Read.Write(DigitalLevel.High); Write.Write(DigitalLevel.High); }
public override Task <MemoryResponse> GetMemoryInfo(MemoryRequest request, ServerCallContext context) { logger.LogInformation(nameof(GetMemoryInfo)); var process = Process.GetCurrentProcess(); _ = new byte[8192]; var result = new MemoryResponse { ProcessId = process.Id, WorkintSet = process.WorkingSet64 }; return(Task.FromResult(result)); }
/// <inheritdoc/> public string HandleRequest(MemoryRequest request) { if (this.Manages(request.Address)) { if (request.Action == MemoryAction.Set) { Volume[request.Address - MainChunk.Address] = request.Value; return(null); } else if (request.Action == MemoryAction.Get) { return(Volume[request.Address - MainChunk.Address]); } else { throw new ArgumentException($"The given memory request attempted action {request.Action} which was not supported.", "request"); } } else { throw new MemoryAccessException("The bootloader does not manage the requested memory.", request); } }
public override async Task monitorMemory(MemoryRequest request, IServerStreamWriter <MemoryReply> responseStream, ServerCallContext context) { Console.WriteLine(request); try { List <long> memoryUsage = new List <long>(); while (!context.CancellationToken.IsCancellationRequested) { await Task.Delay(100); Process currentProcess = Process.GetCurrentProcess(); currentProcess.Refresh(); long totalBytesOfMemoryUsed = currentProcess.WorkingSet64; memoryUsage.Add(totalBytesOfMemoryUsed); if (memoryUsage.Count >= 1) { var avg = memoryUsage.Average(); if (!context.CancellationToken.IsCancellationRequested) { await responseStream.WriteAsync(new MemoryReply { MemoryUsgageInBytes = (long)avg, }); } memoryUsage.Clear(); } } } catch (Exception e) { Console.WriteLine("MEMORY MONITOR EXCEPTION"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
/// <inheritdoc/> public string HandleRequest(MemoryRequest request) { uint address = request.Address - MainChunk.Address; if (request.Action == MemoryAction.Poke) { if (dispCmd == 3) { Commands.Clear(); } else if (dispCmd == 2) { Commands.Remove(id); } else if (dispCmd == 1 || dispCmd == 0) { if (Commands.ContainsKey(id)) { Commands[id] = currentCommand; } else { Commands.Add(id, currentCommand); } if (dispCmd == 1) { Configuration.GraphicsView.RequestUpdate(); } } else { throw new ArgumentException($"The given memory request attempted display action {dispCmd} which was not found.", "request"); } return(null); } else if (request.Action == MemoryAction.Set) { if (address == 0) { dispCmd = int.Parse(request.Value); } else if (address == 1) { currentCommand.X = float.Parse(request.Value); } else if (address == 2) { currentCommand.Y = float.Parse(request.Value); } else if (address == 3) { currentCommand.Pen = int.Parse(request.Value); } else if (address == 4) { currentCommand.Size = float.Parse(request.Value); } else if (address == 5) { id = int.Parse(request.Value); } else { throw new MemoryAccessException("This device could not find the requested memory.", request); } return(null); } else if (request.Action == MemoryAction.Get) { if (address == 0) { return(dispCmd.ToString()); } else if (address == 1) { return(currentCommand.X.ToString()); } else if (address == 2) { return(currentCommand.Y.ToString()); } else if (address == 3) { return(currentCommand.Pen.ToString()); } else if (address == 4) { return(currentCommand.Size.ToString()); } else if (address == 5) { return(id.ToString()); } else { throw new MemoryAccessException("This device could not find the requested memory.", request); } } else { throw new ArgumentException($"The given memory request attempted action {request.Action} which was not supported.", "request"); } }