Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PackbuilderCallbacks.cs « Core « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c496654c6717da75e70bcfebf2e2b8dc25d6e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using LibGit2Sharp.Handlers;

namespace LibGit2Sharp.Core
{
    internal class PackbuilderCallbacks
    {
        private readonly PackBuilderProgressHandler onPackBuilderProgress;

        /// <summary>S
        /// Constructor to set up the native callback given managed delegate.
        /// </summary>
        /// <param name="onPackBuilderProgress">The <see cref="PackBuilderProgressHandler"/> delegate that the git_packbuilder_progress will call.</param>
        internal PackbuilderCallbacks(PackBuilderProgressHandler onPackBuilderProgress)
        {
            this.onPackBuilderProgress = onPackBuilderProgress;
        }

        /// <summary>
        /// Generates a delegate that matches the native git_packbuilder_progress function's signature and wraps the <see cref="PackBuilderProgressHandler"/> delegate.
        /// </summary>
        /// <returns>A delegate method with a signature that matches git_transfer_progress_callback.</returns>
        internal NativeMethods.git_packbuilder_progress GenerateCallback()
        {
            if (onPackBuilderProgress == null)
            {
                return null;
            }

            return new PackbuilderCallbacks(onPackBuilderProgress).OnGitPackBuilderProgress;
        }

        private int OnGitPackBuilderProgress(int stage, uint current, uint total, IntPtr payload)
        {
            return Proxy.ConvertResultToCancelFlag(onPackBuilderProgress((PackBuilderStage)stage, (int)current, (int)total));
        }
    }
}