-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathQueueCommon.cs
69 lines (62 loc) · 2.58 KB
/
QueueCommon.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DigiRite
{
// There are multiple queing implementations. One is optimized for
// contest-style everything-in-one-exchange and the other
// for casual two-messages-for-a-qso. This class is what they both do.
abstract class QueueCommon : IQsoQueue
{
protected QsosPanel qsosPanel;
protected string myCall;
protected string myBaseCall;
protected QueueCommon(QsosPanel qp)
{ qsosPanel = qp; }
public string MyCall { set { myCall = value; } }
public string MyBaseCall { set { myBaseCall = value; } }
public bool InitiateQso(RecentMessage rm, short band, bool onHisFrequency, System.Action onUsed=null)
{
var inProgList = qsosPanel.QsosInProgressDictionary;
QsoInProgress q = null;
if (inProgList.TryGetValue(QsoInProgress.GetKey(rm.Message, band), out q))
{
if (!q.Active)
{
q.Active = true;
StartQso(q);
}
return false; // we're already trying to work this guy
}
if (null != onUsed) onUsed();
QsoInProgress newStn = new QsoInProgress(rm, band);
if (onHisFrequency)
newStn.TransmitFrequency = rm.Message.Hz;
qsosPanel.Add(newStn);
StartQso(newStn);// transmit to him.
return true;
}
public void OnCycleBeginning(int cycleNumber)
{
var inProgList = qsosPanel.QsosInProgressDictionary;
foreach (var qp in inProgList)
{
var q = qp.Value;
bool wasReceiveCycle = (q.Message.CycleNumber & 1) != (cycleNumber & 1);
bool messagedThisCycle = q.OnCycleBegin(wasReceiveCycle);
if (!q.InLoggedInactiveState && wasReceiveCycle && q.Sequencer != null )
{
q.Sequencer.OnReceiveCycleEnd(messagedThisCycle, q.OnHold);
if (!messagedThisCycle && q.Sequencer.IsFinished && q.IsLogged)
q.Active = false;
}
}
}
// interface method present but we don't implement. pass it down to subclass
public abstract void MessageForMycall(RecentMessage recentMessage, bool directlyToMe, CallQsled callQsled,
short band, bool autoStart, IsConversationMessage onUsed);
protected abstract void StartQso(QsoInProgress qp);
}
}