SafeNet/ConsoleApplication1/Definitions.cs

207 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Threading;
namespace ConsoleApplication1
{
public class SDRegistration
{
private string Ip;
public string ip
{
get { return Ip; }
set { Ip = value; }
}
private Boolean hasGps;
public Boolean gps
{
get { return hasGps; }
set { hasGps = value; }
}
private Boolean hasSms;
public Boolean sms
{
get { return hasSms; }
set { hasSms = value; }
}
private Boolean hasReports;
public Boolean reports
{
get { return hasReports; }
set { hasReports = value; }
}
private Boolean hasVoice;
public Boolean voice
{
get { return hasVoice; }
set { hasVoice = value; }
}
private Boolean hasZones;
public Boolean zones
{
get { return hasZones; }
set { hasZones = value; }
}
private Boolean hasTelemetry;
public Boolean telemetry
{
get { return hasTelemetry; }
set { hasTelemetry = value; }
}
private Int16 mapType;
public Int16 map_type
{
get { return mapType; }
set { mapType = value; }
}
public String Map_TypeS;
public String MapTypeS
{
get { return Map_TypeS; }
set { Map_TypeS = value; }
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
SDRegistration p = obj as SDRegistration;
if ((System.Object)p == null)
{
return false;
}
if (ip != p.ip)
{
return false;
}
if (gps != p.gps)
{
return false;
}
if (sms != p.sms)
{
return false;
}
if (reports != p.reports)
{
return false;
}
if (voice != p.voice)
{
return false;
}
if (zones != p.zones)
{
return false;
}
if (telemetry != p.telemetry)
{
return false;
}
if (map_type != p.map_type)
{
return false;
}
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public class GatewayRegistration
{
private string Ip;
public string ip
{
get { return Ip; }
set { Ip = value; }
}
}
public class InterthreadMessageQueue<T>
{
System.Collections.Generic.Queue<T> _queue = new
System.Collections.Generic.Queue<T>();
/// <summary>
/// Post a message to the queue.
/// </summary>
public void PostItem(T item)
{
lock (_queue)
{
_queue.Enqueue(item);
if (_queue.Count == 1)
Monitor.Pulse(_queue);
}
}
/// <summary>
/// Retrieve a message from the queue.
/// </summary>
/// <param name="maxWait">Number of milliseconds to block ifnothing is available. -1 means "block indefinitely"</param>
/// <returns>The next item in the queue, or default(T) if queue is empty</returns>
public T GetItem(int maxWait)
{
lock (_queue)
{
if (_queue.Count == 0)
{
if (maxWait == 0)
return default(T);
Monitor.Wait(_queue, maxWait);
if (_queue.Count == 0)
return default(T);
}
return _queue.Dequeue();
}
}
public T Peek(int maxWait)
{
lock (_queue)
{
if (_queue.Count == 0)
{
if (maxWait == 0)
return default(T);
Monitor.Wait(_queue, maxWait);
if (_queue.Count == 0)
return default(T);
}
return _queue.Peek();
}
}
public void Remove(T item)
{
lock (_queue)
{
if (_queue.Count != 0)
{
T itemPeek = _queue.Peek();
if (itemPeek.Equals(item))
{
_queue.Dequeue();
}
}
}
}
}
}