using System;
using LibGit2Sharp.Core;
using LibGit2Sharp.Handlers;
namespace LibGit2Sharp
{
///
/// Class to handle the mapping between libgit2 git_transfer_progress_callback function and
/// a corresponding . Generates a delegate that
/// wraps the delegate with a delegate that matches
/// the git_transfer_progress_callback signature.
///
internal class TransferCallbacks
{
///
/// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2.
///
private readonly TransferProgressHandler onTransferProgress;
///
/// Constructor to set up the native callback given managed delegate.
///
/// The delegate that the git_transfer_progress_callback will call.
private TransferCallbacks(TransferProgressHandler onTransferProgress)
{
this.onTransferProgress = onTransferProgress;
}
///
/// Generates a delegate that matches the native git_transfer_progress_callback function's signature and wraps the delegate.
///
/// The delegate to call in responde to a the native git_transfer_progress_callback callback.
/// A delegate method with a signature that matches git_transfer_progress_callback.
internal static NativeMethods.git_transfer_progress_callback GenerateCallback(TransferProgressHandler onTransferProgress)
{
if (onTransferProgress == null)
{
return null;
}
return new TransferCallbacks(onTransferProgress).OnGitTransferProgress;
}
///
/// The delegate with the signature that matches the native git_transfer_progress_callback function's signature.
///
/// structure containing progress information.
/// Payload data.
/// the result of the wrapped
private int OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload)
{
return onTransferProgress(new TransferProgress(progress));
}
}
}