mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Missed some files.
This commit is contained in:
35
NTwain/IMemoryManager.cs
Normal file
35
NTwain/IMemoryManager.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface that provides the correct methods for managing memory on data exchanged with TWAIN sources.
|
||||||
|
/// </summary>
|
||||||
|
public interface IMemoryManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Function to allocate memory. Calls to this must be coupled with <see cref="MemFree"/> later.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">The size in bytes.</param>
|
||||||
|
/// <returns>Handle to the allocated memory.</returns>
|
||||||
|
IntPtr MemAllocate(uint size);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function to free memory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">The handle from <see cref="MemAllocate"/>.</param>
|
||||||
|
void MemFree(IntPtr handle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function to lock some memory. Calls to this must be coupled with <see cref="MemUnlock"/> later.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">The handle to allocated memory.</param>
|
||||||
|
/// <returns>Handle to the lock.</returns>
|
||||||
|
IntPtr MemLock(IntPtr handle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function to unlock a previously locked memory region.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="handle">The handle from <see cref="MemLock"/>.</param>
|
||||||
|
void MemUnlock(IntPtr handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
NTwain/ITwainOperation.cs
Normal file
37
NTwain/ITwainOperation.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using NTwain.Triplets;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for providing TWAIN triplet operations.
|
||||||
|
/// </summary>
|
||||||
|
public interface ITwainOperation
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for audio data group.
|
||||||
|
/// </summary>
|
||||||
|
DGAudio DGAudio { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for control data group.
|
||||||
|
/// </summary>
|
||||||
|
DGControl DGControl { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for image data group.
|
||||||
|
/// </summary>
|
||||||
|
DGImage DGImage { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal interface for operations use.
|
||||||
|
/// </summary>
|
||||||
|
interface ITwainOperationInternal : ITwainOperation
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
170
NTwain/TwainSessionBase.cs
Normal file
170
NTwain/TwainSessionBase.cs
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
using NTwain.Data;
|
||||||
|
using NTwain.Triplets;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
public class TwainSessionBase : ITwainStateInternal, ITwainOperationInternal
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TwainSession" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="appId">The app id.</param>
|
||||||
|
/// <exception cref="System.ArgumentNullException"></exception>
|
||||||
|
public TwainSessionBase(TWIdentity appId)
|
||||||
|
{
|
||||||
|
if (appId == null) { throw new ArgumentNullException("appId"); }
|
||||||
|
AppId = appId;
|
||||||
|
State = 1;
|
||||||
|
EnforceState = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region ITwainStateInternal Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether calls to triplets will verify the current twain session state.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> if state value is enforced; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
public bool EnforceState { get; set; }
|
||||||
|
|
||||||
|
void ITwainStateInternal.ChangeState(int newState, bool notifyChange)
|
||||||
|
{
|
||||||
|
State = newState;
|
||||||
|
if (notifyChange)
|
||||||
|
{
|
||||||
|
RaisePropertyChanged("State");
|
||||||
|
OnStateChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ICommitable ITwainStateInternal.GetPendingStateChanger(int newState)
|
||||||
|
{
|
||||||
|
return new TentativeStateCommitable(this, newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITwainStateInternal.ChangeSourceId(TWIdentity sourceId)
|
||||||
|
{
|
||||||
|
SourceId = sourceId;
|
||||||
|
RaisePropertyChanged("SourceId");
|
||||||
|
OnSourceIdChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ITwainState Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the app id used for the session.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The app id.
|
||||||
|
/// </value>
|
||||||
|
public TWIdentity AppId { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the source id used for the session.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The source id.
|
||||||
|
/// </value>
|
||||||
|
public TWIdentity SourceId { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current state number as defined by the TWAIN spec.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The state.
|
||||||
|
/// </value>
|
||||||
|
public int State { get; private set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ITwainOperation Members
|
||||||
|
|
||||||
|
DGAudio _dgAudio;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for audio data group.
|
||||||
|
/// </summary>
|
||||||
|
public DGAudio DGAudio
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_dgAudio == null) { _dgAudio = new DGAudio(this); }
|
||||||
|
return _dgAudio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DGControl _dgControl;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for control data group.
|
||||||
|
/// </summary>
|
||||||
|
public DGControl DGControl
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_dgControl == null) { _dgControl = new DGControl(this); }
|
||||||
|
return _dgControl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DGImage _dgImage;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the triplet operations defined for image data group.
|
||||||
|
/// </summary>
|
||||||
|
public DGImage DGImage
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_dgImage == null) { _dgImage = new DGImage(this); }
|
||||||
|
return _dgImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ITwainOperationInternal Members
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region INotifyPropertyChanged Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when a property value changes.
|
||||||
|
/// </summary>
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raises the <see cref="PropertyChanged"/> event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="propertyName">Name of the property.</param>
|
||||||
|
protected void RaisePropertyChanged(string propertyName)
|
||||||
|
{
|
||||||
|
var hand = PropertyChanged;
|
||||||
|
if (hand != null) { hand(this, new PropertyChangedEventArgs(propertyName)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region custom events and overridables
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when <see cref="State"/> changed.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnStateChanged() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when <see cref="SourceId"/> changed.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnSourceIdChanged() { }
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user