public CompletionCallbackWithOutput(CompletionCallbackWithOutputFunc <T> completionCallback, int flags = 0) { CompletionCallbackFunc = completionCallback; if (typeof(T).IsArray) { OutputAdapter = new ArrayOutputAdapterWithStorage <T>(); if (OutputAdapter.Adapter is PPArrayOutput) { ArrayOutput = (PPArrayOutput)OutputAdapter.Adapter; } } else { this.OutputAdapter = new APIArgumentAdapter <T>(); } Callback = new PPCompletionCallback(); Callback.func = OnCallBack; GCHandle userHandle = GCHandle.Alloc(this, GCHandleType.Normal); Callback.user_data = (IntPtr)userHandle; Callback.flags = flags; }
private async Task <DirectoryEntries> ReadDirectoryEntriesAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <DirectoryEntries>(); EventHandler <DirectoryEntries> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleReadDirectoryEntries += handler; if (MessageLoop == null && messageLoop == null) { ReadDirectoryEntries(); } else { Action <PPError> action = new Action <PPError>((e) => { var output = new ArrayOutputAdapterWithStorage <PPDirectoryEntry[]>(); var result = (PPError)PPBFileRef.ReadDirectoryEntries(this, output.PPArrayOutput, new BlockUntilComplete() ); var entries = new List <DirectoryEntry>(); foreach (var entry in output.Output) { entries.Add(new DirectoryEntry(entry)); } tcs.TrySetResult(new DirectoryEntries(result, entries.AsReadOnly())); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new DirectoryEntries(PPError.Aborted, new List <DirectoryEntry> ().AsReadOnly())); } finally { HandleReadDirectoryEntries -= handler; } }
private async Task <VideoProfileInfo> GetSupportedProfilesAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <VideoProfileInfo>(); EventHandler <VideoProfileInfo> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleEncoderProbed += handler; if (MessageLoop == null && messageLoop == null) { GetSupportedProfiles(); } else { Action <PPError> action = new Action <PPError>((e) => { var output = new ArrayOutputAdapterWithStorage <PPVideoProfileDescription01[]>(); var result = (PPError)PPBVideoEncoder.GetSupportedProfiles(this, output.PPArrayOutput, new BlockUntilComplete() ); var profiles = new List <VideoProfileDescription>(); foreach (var entry in output.Output) { profiles.Add(new VideoProfileDescription(entry)); } tcs.TrySetResult(new VideoProfileInfo(result, profiles.AsReadOnly())); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new VideoProfileInfo(PPError.Aborted, new List <VideoProfileDescription>().AsReadOnly())); } finally { HandleEncoderProbed -= handler; } }
private async Task <FileIOResult> ReadAsyncCore(ArraySegment <byte> buffer, int offset, int size, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <FileIOResult>(); EventHandler <FileIOResult> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleReadData += handler; if (MessageLoop == null && messageLoop == null) { Read(buffer, offset, size); } else { Action <PPError> action = new Action <PPError>((e) => { using (var arrayOutput = new ArrayOutputAdapterWithStorage <byte[]>()) { PPArrayOutput ao = arrayOutput.PPArrayOutput; var result = (PPError)PPBFileIO.ReadToArray(this, offset, size, ref ao, new BlockUntilComplete()); var bytes = arrayOutput.Output; Array.Copy(bytes, buffer.Array, Math.Min(bytes.Length, buffer.Count)); tcs.TrySetResult(new FileIOResult((int)result, (int)result == 0)); } } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new FileIOResult((int)PPError.Aborted, true)); } finally { HandleReadData -= handler; } }
internal NetworkInterface(PPResource networkList, uint index) { Name = ((Var)PPBNetworkList.GetName(networkList, index)).AsString(); DisplayName = ((Var)PPBNetworkList.GetDisplayName(networkList, index)).AsString(); State = (NetworkInterfaceState)PPBNetworkList.GetState(networkList, index); NetworkType = (NetworkInterfaceType)PPBNetworkList.GetType(networkList, index); MTU = PPBNetworkList.GetMTU(networkList, index); using (var varIPAddresses = new VarArray()) { var IPAddresses = new ArrayOutputAdapterWithStorage <PPResource []> (); var result = (PPError)PPBNetworkList.GetIpAddresses(networkList, index, (PPArrayOutput)IPAddresses.Adapter); if (result == PPError.Ok) { var length = IPAddresses.Output.Length; for (uint j = 0; j < IPAddresses.Output.Length; ++j) { ipAddress.Add(new NetAddress(IPAddresses.Output [j])); } } } }