public SendFileOperation(string filename, WriteCallback callback) { this.filename = filename; this.callback = callback; Length = -1; }
public void WriteReport(HidReport report, WriteCallback callback, int timeout) { var writeReportDelegate = new WriteReportDelegate(WriteReport); var asyncState = new HidAsyncState(writeReportDelegate, callback); writeReportDelegate.BeginInvoke(report, timeout, EndWriteReport, asyncState); }
public void Write(byte[] data, WriteCallback callback, int timeout) { var writeDelegate = new WriteDelegate(Write); var asyncState = new HidAsyncState(writeDelegate, callback); writeDelegate.BeginInvoke(data, timeout, EndWrite, asyncState); }
/// <summary> /// 读取由filePath指定的xml文件,若文件不存在则自行创建.wsy /// writeFunc:向xml文件中写入某结构体数据的方法委托.wsy /// </summary> public XmlFile(string filePath, WriteCallback writeFunc) { this.filePath = filePath; this.writeFunc = writeFunc; xmlDoc = new XmlDocument(); string directoryPath = Path.GetDirectoryName(filePath); if (Directory.Exists(directoryPath) == false) { Log.Fatlin("Create Directory: " + directoryPath); Directory.CreateDirectory(directoryPath); } if (File.Exists(filePath)) { xmlDoc.Load(filePath); xmlRoot = xmlDoc.SelectSingleNode("root"); } else { XmlElement xe = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(xe); xmlRoot = (XmlNode)xe; } }
private void write_implTcpSocket(string data, int len, WriteCallback cb, double timeout) { bool success = false; if (netStream_.CanWrite) { StdErrorOut.Instance.StdOut(LogLevel.debug, "IoSocket.write_implTcpSocket after netStream_.CanWrite"); var cts = new CancellationTokenSource(); var token = cts.Token; StdErrorOut.Instance.StdOut(LogLevel.debug, "data = " + data); var task = netStream_.WriteAsync(Encoding.Default.GetBytes(data), 0, len, token); success = task.Wait((int)timeout, token); StdErrorOut.Instance.StdOut(LogLevel.debug, "IoSocket.write_implTcpSocket after success = task.Wait((int)timeout, token)"); if (!task.IsCompleted && token.CanBeCanceled) { StdErrorOut.Instance.StdOut(LogLevel.debug, "IoSocket.write_implTcpSocket before cts.Cancel()"); cts.Cancel(); } } if (!success) { StdErrorOut.Instance.StdOut(LogLevel.debug, "IoSocket.write_implTcpSocket after if (!success)"); close(); StdErrorOut.Instance.StdOut(LogLevel.debug, "IoSocket.write_implTcpSocket after close()"); } cb(success, !success ? "" : "Failed to connect."); }
public bool Combine(IWriteOperation other) { WriteBytesOperation write_op = other as WriteBytesOperation; if (write_op == null) return false; int offset = bytes.Count; foreach (var op in write_op.bytes) { bytes.Add (op); } if (write_op.callback != null) { if (callback == null && callbacks == null) callback = write_op.callback; else { if (callbacks == null) { callbacks = new List<CallbackInfo> (); callbacks.Add (new CallbackInfo (offset - 1, callback)); callback = null; } callbacks.Add (new CallbackInfo (bytes.Count - 1, write_op.callback)); } } return true; }
public FlacReader(string input, WavWriter output) { if (output == null) { throw new ArgumentNullException("WavWriter"); } stream = File.OpenRead(input); reader = new BinaryReader(stream); writer = output; context = FLAC__stream_decoder_new(); if (context == IntPtr.Zero) { throw new ApplicationException("FLAC: Could not initialize stream decoder!"); } write = new WriteCallback(Write); metadata = new MetadataCallback(Metadata); error = new ErrorCallback(Error); if (FLAC__stream_decoder_init_file(context, input, write, metadata, error, IntPtr.Zero) != 0) { throw new ApplicationException("FLAC: Could not open stream for reading!"); } }
/// <summary> /// Writes data to the application process, using the supplied callback method. /// </summary> /// <param name="range">Ranges of physical memory where the data is located</param> /// <param name="data">Data to be written</param> /// <param name="writeCallback">Callback method that will perform the write</param> private static void WriteImpl(MultiRange range, ReadOnlySpan <byte> data, WriteCallback writeCallback) { if (range.Count == 1) { var singleRange = range.GetSubRange(0); if (singleRange.Address != MemoryManager.PteUnmapped) { writeCallback(singleRange.Address, data); } } else { int offset = 0; for (int i = 0; i < range.Count; i++) { var currentRange = range.GetSubRange(i); int size = (int)currentRange.Size; if (currentRange.Address != MemoryManager.PteUnmapped) { writeCallback(currentRange.Address, data.Slice(offset, size)); } offset += size; } } }
public void WriteMetadata(WriteCallback callback) { if (pending_length_cbs > 0) { return; } if (AddHeaders) { if (chunk_encode) { HttpEntity.Headers.SetNormalizedHeader("Transfer-Encoding", "chunked"); } else { HttpEntity.Headers.ContentLength = Length; } } StringBuilder builder = new StringBuilder(); HttpEntity.WriteMetadata(builder); byte [] data = Encoding.ASCII.GetBytes(builder.ToString()); metadata_written = true; var bytes = new List <ByteBuffer> (); bytes.Add(new ByteBuffer(data, 0, data.Length)); var write_bytes = new SendBytesOperation(bytes.ToArray(), callback); SocketStream.QueueWriteOperation(write_bytes); }
public void Write(byte reportId, byte[] data, WriteCallback callback, int timeout) { var d = new _WriteDelegate(Write); var asyncState = new AsyncState(d, callback); d.BeginInvoke(reportId, data, timeout, _EndWrite, asyncState); }
/// <summary> /// Writes data to possibly non-contiguous GPU mapped memory. /// </summary> /// <param name="va">GPU virtual address of the region to write into</param> /// <param name="data">Data to be written</param> /// <param name="writeCallback">Write callback</param> private void WriteImpl(ulong va, ReadOnlySpan <byte> data, WriteCallback writeCallback) { if (IsContiguous(va, data.Length)) { writeCallback(Translate(va), data); } else { int offset = 0, size; if ((va & PageMask) != 0) { ulong pa = Translate(va); size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask)); writeCallback(pa, data.Slice(0, size)); offset += size; } for (; offset < data.Length; offset += size) { ulong pa = Translate(va + (ulong)offset); size = Math.Min(data.Length - offset, (int)PageSize); writeCallback(pa, data.Slice(offset, size)); } } }
public void WriteReport(HidReport report, WriteCallback callback) { WriteReportDelegate writeReportDelegate = WriteReport; HidAsyncState @object = new HidAsyncState(writeReportDelegate, callback); writeReportDelegate.BeginInvoke(report, EndWriteReport, @object); }
public void Write(byte[] data, WriteCallback callback) { WriteDelegate writeDelegate = Write; HidAsyncState @object = new HidAsyncState(writeDelegate, callback); writeDelegate.BeginInvoke(data, EndWrite, @object); }
public FlacReader(Stream input, WavWriter output) { if (output == null) { throw new ArgumentNullException("output"); } stream = input; writer = output; context = _flacStreamDecoderNew(); if (context == IntPtr.Zero) { throw new ApplicationException("FLAC: Could not initialize stream decoder!"); } write = Write; metadata = Metadata; error = Error; read = Read; seek = Seek; tell = Tell; length = Length; eof = Eof; if (_flacStreamDecoderInitStream(context, read, seek, tell, length, eof, write, metadata, error, IntPtr.Zero) != 0) { throw new ApplicationException("FLAC: Could not open stream for reading!"); } }
public SendFileOperation(FileStream file, WriteCallback callback) { this.file = file; this.callback = callback; // TODO: async. Don't think there is a good reason to do any locking here. file_length = file.Length; }
private void SetupIOEntry(ushort port, ReadCallback read, WriteCallback write) { var entry = new IOEntry { Read = read, Write = write }; ioPorts.Add(port, entry); }
public WriteFileOperation(FileStream file, WriteCallback callback) { this.file = file; this.callback = callback; file_length = (int) file.Length; ReadFile (); }
public SendFileOperation(FileStream file, WriteCallback callback) { this.file = file; this.callback = callback; file_length = (int)file.Length; ReadFile(); }
public void Write(byte[] data, int offset, int count, WriteCallback callback) { var write_bytes = new SendBytesOperation(new[] { new ByteBuffer(data, offset, count) }, callback); QueueWriteOperation(write_bytes); }
public SendFileOperation(string filename, long size, WriteCallback callback) { this.filename = filename; this.callback = callback; // TODO: async. Don't think there is a good reason to do any locking here. file_length = file.Length; }
public SendFileOperation(string filename, WriteCallback callback) { this.file = new FileStream (file_name, FileMode.Open, FileAccess.Read) this.callback = callback; file_length = (int) file.Length; ReadFile (); }
public SendFileOperation(string filename, WriteCallback callback) { this.file = new FileStream(file_name, FileMode.Open, FileAccess.Read) this.callback = callback; file_length = (int)file.Length; ReadFile(); }
protected void EndWriteCallback(IAsyncResult ar) { // Because you passed your original delegate in the asyncState parameter // of the Begin call, you can get it back here to complete the call. WriteCallback dlgt = (WriteCallback)ar.AsyncState; // Complete the call. dlgt.EndInvoke(ar); }
private static void EndWriteReport(IAsyncResult ar) { HidAsyncState hidAsyncState = (HidAsyncState)ar.AsyncState; WriteReportDelegate writeReportDelegate = (WriteReportDelegate)hidAsyncState.CallerDelegate; WriteCallback writeCallback = (WriteCallback)hidAsyncState.CallbackDelegate; bool success = writeReportDelegate.EndInvoke(ar); writeCallback?.Invoke(success); }
public void DoIOWrite(Operand dest, Operand source) { WriteCallback ioWrite = IOWrite; if (ioWrite != null) { ioWrite((ushort)dest.Value, source.Value, (int)source.Size); } }
public void Write(byte [] data, int offset, int count, WriteCallback callback) { var bytes = new List <ArraySegment <byte> > (); bytes.Add(new ArraySegment <byte> (data, offset, count)); var write_bytes = new SendBytesOperation(bytes, callback); QueueWriteOperation(write_bytes); }
public void Write(byte [] data, int offset, int count, WriteCallback callback) { var bytes = new List <ByteBuffer> (); bytes.Add(new ByteBuffer(data, offset, count)); var write_bytes = new SendBytesOperation(bytes, callback); QueueWriteOperation(write_bytes); }
/// <summary>Initializes a new instance of the <see cref="WriteBuffer"/> class.</summary> /// <param name="write">The method that is called when the buffer needs to be emptied.</param> /// <param name="bufferSize">The size of the buffer in bytes.</param> /// <exception cref="ArgumentNullException"><paramref name="write"/> equals <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is 0 or negative.</exception> public WriteBuffer(WriteCallback write, int bufferSize) : base(bufferSize) { if (write == null) { throw new ArgumentNullException(nameof(write)); } this.write = write; this.writeAsync = (b, o, c, t) => ThrowInvalidAsyncOperationException(); }
public void End(WriteCallback callback) { if (chunk_encode) { SendFinalChunk(callback); return; } WriteMetadata(null); SendBufferedOps(callback); }
public static int stbi_write_bmp_to_func(WriteCallback func, void *context, int x, int y, int comp, void *data) { var s = new stbi__write_context(); stbi__start_write_callbacks(s, func, context); return(stbi_write_bmp_core(s, x, y, comp, data)); }
public PacketLoggerFrm(MainFrm main) { InitializeComponent(); MainUI = main; _write = Write; _writeHighlight = WriteHighlight; Intercepted = new Queue <InterceptedEventArgs>(); MainUI.Connection.DataIncoming += DataIncoming; MainUI.Connection.DataOutgoing += DataOutgoing; }
private void WriteLine(string Line = "", bool Date = true) { if (txtHistory.InvokeRequired) { var Callback = new WriteCallback(WriteLine); Invoke(Callback, Line, Date); } else { txtHistory.AppendText(string.Format(((Date) ? "[{0}] - " : "") + "{1}{2}", DateTime.Now.ToShortTimeString(), Line, Environment.NewLine)); } }
public static int stbi_write_jpg_to_func(WriteCallback func, void *context, int x, int y, int comp, void *data, int quality) { stbi__write_context s = new stbi__write_context(); stbi__start_write_callbacks(s, func, context); return(stbi_write_jpg_core(s, x, y, comp, data, quality)); }
public static int stbi_write_hdr_to_func(WriteCallback func, void *context, int x, int y, int comp, float *data ) { StbiWriteContext s = new StbiWriteContext(); stbi__start_write_callbacks(s, func, context); return(stbi_write_hdr_core(s, x, y, comp, data)); }
internal WriteLineHelper(bool lineWrap, WriteCallback wlc, WriteCallback wc, DisplayCells displayCells) { if (wlc == null) { throw PSTraceSource.NewArgumentNullException("wlc"); } if (displayCells == null) { throw PSTraceSource.NewArgumentNullException("displayCells"); } this._displayCells = displayCells; this.writeLineCall = wlc; this.writeCall = (wc != null) ? wc : wlc; this.lineWrap = lineWrap; }
public FlacWriter(Stream output, int bitDepth, int channels, int sampleRate) { stream = output; writer = new BinaryWriter(stream); inputBitDepth = bitDepth; inputChannels = channels; inputSampleRate = sampleRate; context = FLAC__stream_encoder_new(); if (context == IntPtr.Zero) throw new ApplicationException("FLAC: Could not initialize stream encoder!"); Check( FLAC__stream_encoder_set_channels(context, channels), "set channels"); Check( FLAC__stream_encoder_set_bits_per_sample(context, bitDepth), "set bits per sample"); Check( FLAC__stream_encoder_set_sample_rate(context, sampleRate), "set sample rate"); Check( FLAC__stream_encoder_set_compression_level(context, 5), "set compression level"); //Check( // FLAC__stream_encoder_set_blocksize(context, 8192), // "set block size"); write = new WriteCallback(Write); seek = new SeekCallback(Seek); tell = new TellCallback(Tell); if (FLAC__stream_encoder_init_stream(context, write, seek, tell, null, IntPtr.Zero) != 0) throw new ApplicationException("FLAC: Could not open stream for writing!"); }
public FlacReader(string input, WavWriter output) { if (output == null) throw new ArgumentNullException("WavWriter"); stream = File.OpenRead(input); reader = new BinaryReader(stream); writer = output; context = FLAC__stream_decoder_new(); if (context == IntPtr.Zero) throw new ApplicationException("FLAC: Could not initialize stream decoder!"); write = new WriteCallback(Write); metadata = new MetadataCallback(Metadata); error = new ErrorCallback(Error); if (FLAC__stream_decoder_init_file(context, input, write, metadata, error, IntPtr.Zero) != 0) throw new ApplicationException("FLAC: Could not open stream for reading!"); }
public void WriteReport(HidReport report, WriteCallback callback) { var writeReportDelegate = new WriteReportDelegate(WriteReport); var asyncState = new HidAsyncState(writeReportDelegate, callback); writeReportDelegate.BeginInvoke(report, EndWriteReport, asyncState); }
public void Write(byte[] data, WriteCallback callback) { var writeDelegate = new WriteDelegate(Write); var asyncState = new HidAsyncState(writeDelegate, callback); writeDelegate.BeginInvoke(data, EndWrite, asyncState); }
public void SendFinalChunk(WriteCallback callback) { EnsureMetadata (); if (!chunk_encode || final_chunk_sent) return; final_chunk_sent = true; var bytes = new List<ByteBuffer> (); WriteChunk (bytes, 0, true); var write_bytes = new SendBytesOperation (bytes, callback); QueueWriteOperation (write_bytes); }
public void WriteMetadata(WriteCallback callback) { if (pending_length_cbs > 0) return; if (AddHeaders) { if (chunk_encode) { HttpEntity.Headers.SetNormalizedHeader ("Transfer-Encoding", "chunked"); } else { HttpEntity.Headers.ContentLength = Length; } } StringBuilder builder = new StringBuilder (); HttpEntity.WriteMetadata (builder); byte [] data = Encoding.ASCII.GetBytes (builder.ToString ()); metadata_written = true; var bytes = new List<ByteBuffer> (); bytes.Add (new ByteBuffer (data, 0, data.Length)); var write_bytes = new SendBytesOperation (bytes, callback); SocketStream.QueueWriteOperation (write_bytes); }
private void Write(string pText) { if (this.txtLog.InvokeRequired) { WriteCallback d = new WriteCallback(Write); this.Invoke(d, new object[] { pText }); } else { if (txtLog.Text.Length > 2000) { txtLog.Text = txtLog.Text.Substring((txtLog.Text.Length - 2000)); } pText = pText + " " + DateTime.Now.ToString(); txtLog.Text = txtLog.Text + pText + Environment.NewLine; txtLog.SelectionStart = txtLog.Text.Length; txtLog.ScrollToCaret(); } }
public WriteBytesOperation(IList<ArraySegment<byte>> bytes, WriteCallback callback) { this.bytes = bytes; this.callback = callback; }
public void SendFile(string file, WriteCallback callback) { CheckCanRead (); write_callback = callback; send_file = new FileStream (file, FileMode.Open, FileAccess.Read); send_file_offset = 0; send_file_count = send_file.Length; EnableWriting (); }
public Genesis(CoreComm comm, GameInfo game, byte[] rom) { ServiceProvider = new BasicServiceProvider(this); CoreComm = comm; MainCPU = new MC68000(); SoundCPU = new Z80A(); YM2612 = new YM2612() { MaxVolume = 23405 }; PSG = new SN76489() { MaxVolume = 4681 }; VDP = new GenVDP(); VDP.DmaReadFrom68000 = ReadWord; (ServiceProvider as BasicServiceProvider).Register<IVideoProvider>(VDP); SoundMixer = new SoundMixer(YM2612, PSG); MainCPU.ReadByte = ReadByte; MainCPU.ReadWord = ReadWord; MainCPU.ReadLong = ReadLong; MainCPU.WriteByte = WriteByte; MainCPU.WriteWord = WriteWord; MainCPU.WriteLong = WriteLong; MainCPU.IrqCallback = InterruptCallback; // ---------------------- musashi ----------------------- #if MUSASHI _vdp = vdpcallback; read8 = Read8; read16 = Read16; read32 = Read32; write8 = Write8; write16 = Write16; write32 = Write32; Musashi.RegisterVdpCallback(Marshal.GetFunctionPointerForDelegate(_vdp)); Musashi.RegisterRead8(Marshal.GetFunctionPointerForDelegate(read8)); Musashi.RegisterRead16(Marshal.GetFunctionPointerForDelegate(read16)); Musashi.RegisterRead32(Marshal.GetFunctionPointerForDelegate(read32)); Musashi.RegisterWrite8(Marshal.GetFunctionPointerForDelegate(write8)); Musashi.RegisterWrite16(Marshal.GetFunctionPointerForDelegate(write16)); Musashi.RegisterWrite32(Marshal.GetFunctionPointerForDelegate(write32)); #endif // ---------------------- musashi ----------------------- SoundCPU.ReadMemory = ReadMemoryZ80; SoundCPU.WriteMemory = WriteMemoryZ80; SoundCPU.WriteHardware = (a, v) => { Console.WriteLine("Z80: Attempt I/O Write {0:X2}:{1:X2}", a, v); }; SoundCPU.ReadHardware = x => 0xFF; SoundCPU.IRQCallback = () => SoundCPU.Interrupt = false; Z80Reset = true; RomData = new byte[0x400000]; for (int i = 0; i < rom.Length; i++) RomData[i] = rom[i]; SetupMemoryDomains(); #if MUSASHI Musashi.Init(); Musashi.Reset(); VDP.GetPC = () => Musashi.PC; #else MainCPU.Reset(); VDP.GetPC = () => MainCPU.PC; #endif InitializeCartHardware(game); }
public void End(WriteCallback callback) { if (pending_length_cbs > 0) { waiting_for_length = true; end_callback = callback; return; } if (chunk_encode) { SendFinalChunk (callback); return; } WriteMetadata (null); SendBufferedOps (callback); }
private void FinishWrite() { WriteCallback callback = write_callback; write_data = null; write_callback = null; callback (); }
private void FinishSendFile() { WriteCallback callback = write_callback; write_callback = null; send_file.Close (); send_file = null; send_file_count = 0; send_file_offset = 0; callback (); }
public void Write(IList<ArraySegment<byte>> data, WriteCallback callback) { CheckCanWrite (); write_data = data; write_callback = callback; EnableWriting (); }
public void SendBufferedOps(WriteCallback callback) { if (write_ops != null) { IWriteOperation [] ops = write_ops.ToArray (); for (int i = 0; i < ops.Length; i++) { SocketStream.QueueWriteOperation (ops [i]); } write_ops.Clear (); } SocketStream.QueueWriteOperation (new NopWriteOperation (callback)); }
private void SetupIOEntry(ushort port, ReadCallback read, WriteCallback write) { var entry = new IOEntry {Read = read, Write = write}; ioPorts.Add(port, entry); }
public WriteOperation(int index, WriteCallback callback) { this.index = index; this.callback = callback; }
/// <summary> /// Starts writing specified data to source stream. /// </summary> /// <param name="data">Data what to write to source stream.</param> /// <param name="callback">Callback to be callled if write completes.</param> /// <exception cref="ArgumentNullException">Raised when <b>data</b> is null.</exception> /// <exception cref="InvalidOperationException">Raised when there already is pending write operation.</exception> public void BeginWrite(byte[] data,WriteCallback callback) { if(data == null){ throw new ArgumentNullException("data"); } BeginWrite(data,0,data.Length,callback); }
static extern int FLAC__stream_encoder_init_stream(IntPtr context, WriteCallback write, SeekCallback seek, TellCallback tell, MetadataCallback metadata, IntPtr userData);
public FlacWriter(Stream output, int bitDepth, int channels, int sampleRate) { stream = output; writer = new BinaryWriter(stream); inputBitDepth = bitDepth; inputChannels = channels; inputSampleRate = sampleRate; context = FLAC__stream_encoder_new(); if (context == IntPtr.Zero) throw new ApplicationException("FLAC: Could not initialize stream encoder!"); Check( FLAC__stream_encoder_set_channels(context, channels), "set channels"); Check( FLAC__stream_encoder_set_bits_per_sample(context, bitDepth), "set bits per sample"); Check( FLAC__stream_encoder_set_sample_rate(context, sampleRate), "set sample rate"); Check( FLAC__stream_encoder_set_verify(context, false), "set verify"); Check( FLAC__stream_encoder_set_streamable_subset(context, true), "set verify"); Check( FLAC__stream_encoder_set_do_mid_side_stereo(context, true), "set verify"); Check( FLAC__stream_encoder_set_loose_mid_side_stereo(context, true), "set verify"); Check( FLAC__stream_encoder_set_compression_level(context, 5), "set compression level"); Check( FLAC__stream_encoder_set_blocksize(context, 4608), "set block size"); write = new WriteCallback(Write); seek = new SeekCallback(Seek); tell = new TellCallback(Tell); if (FLAC__stream_encoder_init_stream(context, write, seek, tell, null, IntPtr.Zero) != 0) throw new ApplicationException("FLAC: Could not open stream for writing!"); //if (FLAC__stream_encoder_init_file(context, @"wav\miles_fisher-this_must_be_the_place-iphone2.flac", IntPtr.Zero, IntPtr.Zero) != 0) // throw new ApplicationException("FLAC: Could not open stream for writing!"); }
/// <summary> /// Starts writing specified data to source stream. /// </summary> /// <param name="data">Data what to write to source stream.</param> /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the source stream.</param> /// <param name="count">The number of bytes to be written to the source stream.</param> /// <param name="callback">Callback to be callled if write completes.</param> /// <exception cref="ArgumentNullException">Raised when <b>data</b> is null.</exception> /// <exception cref="InvalidOperationException">Raised when there already is pending write operation.</exception> public void BeginWrite(byte[] data,int offset,int count,WriteCallback callback) { if(data == null){ throw new ArgumentNullException("data"); } lock(this){ if(m_IsWriteActive){ throw new InvalidOperationException("There is pending write operation, multiple write operations not allowed !"); } m_IsWriteActive = true; } // Start writing data block. m_pStream.BeginWrite( data, offset, count, new AsyncCallback(this.InternalBeginWriteCallback), new object[]{count,callback} ); }
public CopyingSendFileOperation(string filename, WriteCallback callback) : base(filename, callback) { }