Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 44 additions & 48 deletions src/src/TapiLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public int RingModeCount
/// </summary>
public AnswerModes AnswerMode
{
get { return (AnswerModes) _ldc.dwAnswerMode; }
get { return (AnswerModes)_ldc.dwAnswerMode; }
}

/// <summary>
Expand Down Expand Up @@ -419,7 +419,7 @@ public Guid Guid
/// </summary>
public string[] AvailableDeviceClasses
{
get { return (string[]) _devClasses.Clone(); }
get { return (string[])_devClasses.Clone(); }
}

/// <summary>
Expand Down Expand Up @@ -520,7 +520,7 @@ public int OpenCount
/// </summary>
public MediaModes OpenMediaModes
{
get { return (MediaModes) _lds.dwOpenMediaModes; }
get { return (MediaModes)_lds.dwOpenMediaModes; }
}

/// <summary>
Expand Down Expand Up @@ -663,7 +663,7 @@ public bool Locked
/// </summary>
public bool Connected
{
get { return (_lds.dwDevStatusFlags & NativeMethods.LINEDEVSTATUSFLAGS_CONNECTED) > 0;}
get { return (_lds.dwDevStatusFlags & NativeMethods.LINEDEVSTATUSFLAGS_CONNECTED) > 0; }
set { _lineOwner.SetDeviceState(NativeMethods.LINEDEVSTATUSFLAGS_CONNECTED, value); }
}

Expand All @@ -685,7 +685,7 @@ public byte[] DeviceSpecificData
/// </summary>
public MediaModes AvailableMediaModes
{
get { return (MediaModes) _lds.dwAvailableMediaModes; }
get { return (MediaModes)_lds.dwAvailableMediaModes; }
}

/// <summary>
Expand Down Expand Up @@ -763,12 +763,12 @@ public string ToString(string format, IFormatProvider formatProvider)
/// </summary>
public sealed class TapiLine : IDisposable, ITapiLine
{
private const int MinTapiVersion = (int) TapiVersion.V13;
private const int MaxTapiVersion = (int) TapiVersion.V31;
private const int MinTapiVersion = (int)TapiVersion.V13;
private const int MaxTapiVersion = (int)TapiVersion.V31;

private readonly TapiManager _mgr;
private readonly int _deviceId;
private readonly int _negotiatedVersion;
private readonly int _deviceId;
private readonly int _negotiatedVersion;
private int _negotiatedExtVersion;
private readonly int _stringFormat;
private string _lineName = string.Empty;
Expand Down Expand Up @@ -811,13 +811,13 @@ public sealed class TapiLine : IDisposable, ITapiLine
/// <param name="mgr">Owner</param>
/// <param name="deviceId">Device ID for this line</param>
internal TapiLine(TapiManager mgr, int deviceId)
{
{
_mgr = mgr;
_deviceId = deviceId;
_deviceId = deviceId;
_lcb = LineCallback;

LINEEXTENSIONID extId;
int rc = NativeMethods.lineNegotiateAPIVersion(_mgr.LineHandle, _deviceId,
int rc = NativeMethods.lineNegotiateAPIVersion(_mgr.LineHandle, _deviceId,
MinTapiVersion, MaxTapiVersion, out _negotiatedVersion, out extId);
if (rc == NativeMethods.LINEERR_OK)
{
Expand All @@ -832,9 +832,9 @@ internal TapiLine(TapiManager mgr, int deviceId)
{
_addresses[i] = new TapiAddress(this, i);
// Forward events from this address
_addresses[i].Changed += delegate(object sender, AddressInfoChangeEventArgs e) { if (AddressChanged != null) AddressChanged(this, e); };
_addresses[i].CallStateChanged += delegate(object sender, CallStateEventArgs e) { if (CallStateChanged != null) CallStateChanged(this, e); };
_addresses[i].CallInfoChanged += delegate(object sender, CallInfoChangeEventArgs e) { if (CallInfoChanged != null) CallInfoChanged(this, e); };
_addresses[i].Changed += delegate (object sender, AddressInfoChangeEventArgs e) { if (AddressChanged != null) AddressChanged(this, e); };
_addresses[i].CallStateChanged += delegate (object sender, CallStateEventArgs e) { if (CallStateChanged != null) CallStateChanged(this, e); };
_addresses[i].CallInfoChanged += delegate (object sender, CallInfoChangeEventArgs e) { if (CallInfoChanged != null) CallInfoChanged(this, e); };
}

_extensionId = String.Format(CultureInfo.CurrentCulture, "{0}.{1}.{2}.{3}", extId.dwExtensionID0, extId.dwExtensionID1, extId.dwExtensionID2, extId.dwExtensionID3);
Expand All @@ -845,7 +845,7 @@ internal TapiLine(TapiManager mgr, int deviceId)
_addresses = new TapiAddress[0];
_props = new LineCapabilities(new LINEDEVCAPS(), null);
}
}
}

private LINEDEVCAPS GatherDevCaps()
{
Expand All @@ -870,7 +870,7 @@ private LINEDEVCAPS GatherDevCaps()
rawBuffer = new byte[ldc.dwUsedSize];
Marshal.Copy(pLdc, rawBuffer, 0, ldc.dwUsedSize);
}
Marshal.FreeHGlobal(pLdc);
Marshal.FreeHGlobal(pLdc);
}
while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL);
_props = new LineCapabilities(ldc, rawBuffer);
Expand Down Expand Up @@ -947,9 +947,9 @@ internal int StringFormat
/// The numeric device ID representing the line.
/// </summary>
public int Id
{
{
get { return _deviceId; }
}
}

/// <summary>
/// The permanent numeric ID representing this line
Expand All @@ -963,9 +963,9 @@ public int PermanentId
/// The <see cref="TapiVersion"/> that this line negotiated to.
/// </summary>
public TapiVersion NegotiatedVersion
{
get { return (TapiVersion) _negotiatedVersion; }
}
{
get { return (TapiVersion)_negotiatedVersion; }
}

/// <summary>
/// This associates an arbitrary object with the line device
Expand All @@ -988,7 +988,7 @@ public int NegotiateExtensions(int minVersion, int maxVersion, EventHandler<Devi
}

_devsCallback = dsc;

// Must re-read dev caps
GatherDevCaps();

Expand All @@ -1009,7 +1009,7 @@ public string DeviceSpecificExtensionID
/// </summary>
public ITapiAddress[] Addresses
{
get { return (TapiAddress[]) _addresses.Clone(); }
get { return (TapiAddress[])_addresses.Clone(); }
}

/// <summary>
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public ITapiAddress FindAddress(string number)
/// </summary>
public string Name
{
get
get
{
if (_lineName.Length == 0 && _props != null)
_lineName = _props.LineName;
Expand Down Expand Up @@ -1091,9 +1091,9 @@ public LineStatus Status
/// </summary>
/// <returns>String</returns>
public override string ToString()
{
return Name;
}
{
return Name;
}

/// <summary>
/// Returns true/false whether the line is currently open.
Expand Down Expand Up @@ -1137,7 +1137,7 @@ public void Monitor()
/// <param name="mediaMode"></param>
/// <param name="addressId">Address ID to open (-1 for all)</param>
private void Open(Privilege openMode, MediaModes mediaMode, int addressId)
{
{
if (IsOpen)
throw new TapiException("Line is already open", NativeMethods.LINEERR_OPERATIONUNAVAIL);

Expand All @@ -1155,7 +1155,7 @@ private void Open(Privilege openMode, MediaModes mediaMode, int addressId)

uint hLine;
int rc = NativeMethods.lineOpen(_mgr.LineHandle, _deviceId, out hLine, _negotiatedVersion, _negotiatedExtVersion,
Marshal.GetFunctionPointerForDelegate(_lcb), privilege, (int) mediaMode, ref lcp);
Marshal.GetFunctionPointerForDelegate(_lcb), privilege, (int)mediaMode, ref lcp);

if (rc == NativeMethods.LINEERR_OK)
{
Expand All @@ -1177,7 +1177,7 @@ private void Open(Privilege openMode, MediaModes mediaMode, int addressId)
}
else
throw new TapiException("lineOpen failed", rc);
}
}

/// <summary>
/// This closes the line device.
Expand Down Expand Up @@ -1233,8 +1233,8 @@ public ITapiCall MakeCall(string address)
/// <returns><see cref="TapiCall"/> object or null.</returns>
public ITapiCall MakeCall(string address, Country country, MakeCallParams param)
{
return (from addr in Addresses
where addr.Status.CanMakeCall
return (from addr in Addresses
where addr.Status.CanMakeCall
select addr.MakeCall(address, (country == null) ? 0 : country.CountryCode, param)
).FirstOrDefault();
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ public void CancelForward()
int rc = NativeMethods.lineForward(Handle, 1, 0, IntPtr.Zero, 0, out hCall, IntPtr.Zero);
if (rc < 0)
throw new TapiException("lineForward failed", rc);

// Wait for the LINE_REPLY so we don't need to deal with the value type
// issues of IntPtr being filled in async.
var req = new PendingTapiRequest(rc, null, null);
Expand Down Expand Up @@ -1563,7 +1563,7 @@ public byte[] GetDeviceConfig(string deviceClass)
Marshal.FreeHGlobal(pVs);
}
while (rc == NativeMethods.LINEERR_STRUCTURETOOSMALL);

if (rc != 0)
throw new TapiException("lineGetDevConfig failed", rc);
return rawBuffer;
Expand Down Expand Up @@ -1629,7 +1629,7 @@ private void LineCallback(TapiEvent dwMessage, IntPtr dwParam1, IntPtr dwParam2,
case TapiEvent.LINE_ADDRESSSTATE:
_addresses[dwParam1.ToInt32()].OnAddressStateChange(dwParam2.ToInt32());
break;

case TapiEvent.LINE_LINEDEVSTATE:
HandleDevStateChange(dwParam1.ToInt32(), dwParam2, dwParam3);
break;
Expand Down Expand Up @@ -1675,24 +1675,20 @@ internal void OnDeviceSpecific(TapiCall call, IntPtr dwParam1, IntPtr dwParam2,

private void HandleNewCall(TapiCall call, int callPrivileges)
{
f
if (NewCall != null)
{
Privilege priv = (callPrivileges == NativeMethods.LINECALLPRIVILEGE_NONE) ? Privilege.None :
(callPrivileges == NativeMethods.LINECALLPRIVILEGE_MONITOR) ? Privilege.Monitor : Privilege.Owner;
foreach (EventHandler<NewCallEventArgs> nc in NewCall.GetInvocationList())
{
nc.BeginInvoke(this, new NewCallEventArgs(call, priv),
delegate(IAsyncResult ar)
{
try
{
var nce = (EventHandler<NewCallEventArgs>)ar.AsyncState;
nce.EndInvoke(ar);
}
catch
{
}
}, nc);
try
{
await Task.Run(() => nc(this, new NewCallEventArgs(call, priv)));
}
catch
{
}
}
}
}
Expand Down
Loading