Added DAT_XFERGROUP calls

This commit is contained in:
Eugene Wang
2018-11-17 11:10:48 -05:00
parent 12d74b88f5
commit a17ce310ae
5 changed files with 104 additions and 8 deletions

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NTwain.Data
{
delegate ReturnCode Callback32(TW_IDENTITY origin, TW_IDENTITY destination,
DataGroups dg, DataArgumentType dat, Message msg, IntPtr data);
}

View File

@@ -0,0 +1,82 @@
using NTwain.Data;
using NTwain.Internals;
namespace NTwain.Triplets.Control
{
/// <summary>
/// Represents <see cref="DataArgumentType.XferGroup"/>.
/// </summary>
public sealed class XferGroup : BaseTriplet
{
internal XferGroup(TwainSession session) : base(session) { }
/// <summary>
/// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to
/// only supply one of the DGs specified in the SupportedGroups field of origin.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode Get(ref DataGroups value)
{
if (Is32Bit)
{
if (IsWin)
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
if (IsLinux)
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
if (IsMac)
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
}
if (IsWin)
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
if (IsLinux)
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
if (IsMac)
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value);
return ReturnCode.Failure;
}
/// <summary>
/// The transfer group determines the kind of data being passed from the Source to the Application.
/// By default a TWAIN Source must default to DG_IMAGE. Currently the only other data group
/// supported is DG_AUDIO, which is a feature supported by some digital cameras.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public ReturnCode Set(DataGroups value)
{
if (Is32Bit)
{
if (IsWin)
return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
if (IsLinux)
return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
if (IsMac)
return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
}
if (IsWin)
return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
if (IsLinux)
return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
if (IsMac)
return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value);
return ReturnCode.Failure;
}
}
}

View File

@@ -38,5 +38,11 @@ namespace NTwain.Triplets
DeviceEvent _devEvent;
internal DeviceEvent DeviceEvent => _devEvent ?? (_devEvent = new DeviceEvent(Session));
XferGroup _xferGroup;
/// <summary>
/// Gets the operations defined for DAT_XFERGROUP.
/// </summary>
public XferGroup XferGroup => _xferGroup ?? (_xferGroup = new XferGroup(Session));
}
}

View File

@@ -11,10 +11,6 @@ using System.Threading;
namespace NTwain
{
//[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate ReturnCode CallbackDelegate(TW_IDENTITY origin, TW_IDENTITY destination,
DataGroups dg, DataArgumentType dat, Message msg, IntPtr data);
/// <summary>
/// Manages a TWAIN session.
/// </summary>
@@ -26,7 +22,7 @@ namespace NTwain
// cache generated twain sources so if you get same source from same session it'll return the same object
readonly Dictionary<string, DataSource> _ownedSources = new Dictionary<string, DataSource>();
// need to keep delegate around to prevent GC?
readonly CallbackDelegate _callbackDelegate;
readonly Callback32 _callback32Delegate;
/// <summary>
@@ -41,7 +37,7 @@ namespace NTwain
case PlatformID.MacOSX:
case PlatformID.Unix:
default:
_callbackDelegate = new CallbackDelegate(Handle32BitCallback);
_callback32Delegate = new Callback32(Handle32BitCallback);
break;
}
}
@@ -107,7 +103,8 @@ namespace NTwain
internal void RegisterCallback()
{
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_callbackDelegate);
// TODO: support other platforms
var callbackPtr = Marshal.GetFunctionPointerForDelegate(_callback32Delegate);
// try new callback first
var cb2 = new TW_CALLBACK2 { CallBackProc = callbackPtr };