示例#1
0
        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;
        }
示例#2
0
 /**
  * ReadToArray() reads from an offset in the file.  A PP_ArrayOutput must be
  * provided so that output will be stored in its allocated buffer.  This
  * function might perform a partial read. The FileIO object must have been
  * opened with read access.
  *
  * @param[in] file_io A <code>PP_Resource</code> corresponding to a file
  * FileIO.
  * @param[in] offset The offset into the file.
  * @param[in] max_read_length The maximum number of bytes to read from
  * <code>offset</code>.
  * @param[in] output A <code>PP_ArrayOutput</code> to hold the output data.
  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
  * completion of ReadToArray().
  *
  * @return The number of bytes read or an error code from
  * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was
  * reached. It is valid to call ReadToArray() multiple times with a completion
  * callback to queue up parallel reads from the file, but pending reads
  * cannot be interleaved with other operations.
  */
 public static int ReadToArray(PPResource file_io,
                               long offset,
                               int max_read_length,
                               ref PPArrayOutput output,
                               PPCompletionCallback callback)
 {
     return(_ReadToArray(file_io,
                         offset,
                         max_read_length,
                         ref output,
                         callback));
 }
示例#3
0
        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;
            }
        }
示例#4
0
 /**
  * ReadDirectoryEntries() reads all entries in a directory.
  *
  * @param[in] file_ref A <code>PP_Resource</code> corresponding to a directory
  * reference.
  * @param[in] output An output array which will receive
  * <code>PP_DirectoryEntry</code> objects on success.
  * @param[in] callback A <code>PP_CompletionCallback</code> to run on
  * completion.
  *
  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
  */
 public static int ReadDirectoryEntries(PPResource file_ref,
                                        PPArrayOutput output,
                                        PPCompletionCallback callback)
 {
     return(_ReadDirectoryEntries(file_ref, output, callback));
 }
示例#5
0
 extern static int _ReadDirectoryEntries(PPResource file_ref,
                                         PPArrayOutput output,
                                         PPCompletionCallback callback);
示例#6
0
 /**
  * Gets an array of supported audio encoder profiles.
  * These can be used to choose a profile before calling Initialize().
  *
  * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
  * encoder.
  * @param[in] output A <code>PP_ArrayOutput</code> to receive the supported
  * <code>PP_AudioProfileDescription</code> structs.
  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
  * completion.
  *
  * @return If >= 0, the number of supported profiles returned, otherwise an
  * error code from <code>pp_errors.h</code>.
  */
 public static int GetSupportedProfiles(PPResource audio_encoder,
                                        PPArrayOutput output,
                                        PPCompletionCallback callback)
 {
     return(_GetSupportedProfiles(audio_encoder, output, callback));
 }
示例#7
0
 extern static int _GetSupportedProfiles(PPResource audio_encoder,
                                         PPArrayOutput output,
                                         PPCompletionCallback callback);
示例#8
0
 extern static int _ReadToArray(PPResource file_io,
                                long offset,
                                int max_read_length,
                                ref PPArrayOutput output,
                                PPCompletionCallback callback);
示例#9
0
 /**
  * Gets list of IP addresses for a network interface.
  *
  * @param[in] resource A <code>PP_Resource</code> corresponding to a
  * network list.
  * @param[in] index Index of the network interface.
  * @param[in] output An output array which will receive
  * <code>PPB_NetAddress</code> resources on success. Please note that the
  * ref count of those resources has already been increased by 1 for the
  * caller.
  *
  * @return An error code from <code>pp_errors.h</code>.
  */
 public static int GetIpAddresses(PPResource resource,
                                  uint index,
                                  PPArrayOutput output)
 {
     return(_GetIpAddresses(resource, index, output));
 }
示例#10
0
 extern static int _GetIpAddresses(PPResource resource,
                                   uint index,
                                   PPArrayOutput output);