Skip to content

Commit

Permalink
Merge pull request #756 from gbirchmeier/nopublic
Browse files Browse the repository at this point in the history
privatize DDField setters; change many Get/SetNextSenderMsgSeqNum & Get/SetNextTargetMsgSeqNum functions into Properties
  • Loading branch information
gbirchmeier authored Jan 5, 2023
2 parents ed56bf5 + 3caa46d commit 05cb09e
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 173 deletions.
27 changes: 13 additions & 14 deletions QuickFIXn/DataDictionary/DDField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ public DDField(int tag, String name, Dictionary<String, String> enums, String fi
this.Name = name;
this.EnumDict = enums;
this.FixFldType = fixFldType;
this.FieldType = FieldTypeFromFix(this.FixFldType, out this._isMultipleValueFieldWithEnums);
this.FieldType = FieldTypeFromFix(this.FixFldType, out bool isMVFWE);
this.IsMultipleValueFieldWithEnums = isMVFWE;
}

//TODO in version 2.0 - these probably shouldn't be public writable
public int Tag;
public String Name;
public Dictionary<String, String> EnumDict;
public String FixFldType;
public Type FieldType;
public int Tag { get; private set; }
public String Name { get; private set; }
public Dictionary<String, String> EnumDict { get; private set; }
public String FixFldType { get; private set; }
public Type FieldType { get; private set; }

/// <summary>
/// true if FIX field has an enum and if its type is one of: {MultipleValueString,MultipleStringValue,MultipleCharValue}
/// </summary>
public bool IsMultipleValueFieldWithEnums { get { return _isMultipleValueFieldWithEnums; } }
private bool _isMultipleValueFieldWithEnums;
public bool IsMultipleValueFieldWithEnums { get; private set; }

public Boolean HasEnums()
{
return EnumDict.Count > 0;
}

private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums )
private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums)
{
multipleValueFieldWithEnums = false;

Expand All @@ -52,9 +51,9 @@ private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums
case "AMT": return typeof(Fields.DecimalField);
case "QTY": return typeof(Fields.DecimalField);
case "CURRENCY": return typeof(Fields.StringField);
case "MULTIPLEVALUESTRING": multipleValueFieldWithEnums = true; return typeof( Fields.StringField );
case "MULTIPLESTRINGVALUE": multipleValueFieldWithEnums = true; return typeof( Fields.StringField );
case "MULTIPLECHARVALUE": multipleValueFieldWithEnums = true; return typeof( Fields.StringField );
case "MULTIPLEVALUESTRING": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
case "MULTIPLESTRINGVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
case "MULTIPLECHARVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
case "EXCHANGE": return typeof(Fields.StringField);
case "UTCTIMESTAMP": return typeof(Fields.DateTimeField);
case "BOOLEAN": return typeof(Fields.BooleanField);
Expand All @@ -75,7 +74,7 @@ private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums
case "LENGTH": return typeof(Fields.IntField);
case "COUNTRY": return typeof(Fields.StringField);
case "TZTIMEONLY": return typeof(Fields.StringField);
case "TZTIMESTAMP": return typeof(Fields.StringField);
case "TZTIMESTAMP": return typeof(Fields.StringField);
case "XMLDATA": return typeof(Fields.StringField);
case "LANGUAGE": return typeof(Fields.StringField);
case "XID": return typeof(Fields.StringField);
Expand Down
32 changes: 13 additions & 19 deletions QuickFIXn/FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ private void ConstructFromFileCache()
string[] parts = seqNumReader.ReadToEnd().Split(':');
if (parts.Length == 2)
{
cache_.SetNextSenderMsgSeqNum(Convert.ToInt32(parts[0]));
cache_.SetNextTargetMsgSeqNum(Convert.ToInt32(parts[1]));
cache_.NextSenderMsgSeqNum = Convert.ToInt32(parts[0]);
cache_.NextTargetMsgSeqNum = Convert.ToInt32(parts[1]);
}
}
}
Expand Down Expand Up @@ -225,26 +225,20 @@ public bool Set(int msgSeqNum, string msg)
return true;
}

public int GetNextSenderMsgSeqNum()
{
return cache_.GetNextSenderMsgSeqNum();
}

public int GetNextTargetMsgSeqNum()
{
return cache_.GetNextTargetMsgSeqNum();
}

public void SetNextSenderMsgSeqNum(int value)
{
cache_.SetNextSenderMsgSeqNum(value);
public int NextSenderMsgSeqNum {
get { return cache_.NextSenderMsgSeqNum; }
set {
cache_.NextSenderMsgSeqNum = value;
setSeqNum();
}
}

public void SetNextTargetMsgSeqNum(int value)
{
cache_.SetNextTargetMsgSeqNum(value);
public int NextTargetMsgSeqNum {
get { return cache_.NextTargetMsgSeqNum; }
set {
cache_.NextTargetMsgSeqNum = value;
setSeqNum();
}
}

public void IncrNextSenderMsgSeqNum()
Expand All @@ -264,7 +258,7 @@ private void setSeqNum()
seqNumsFile_.Seek(0, System.IO.SeekOrigin.Begin);
System.IO.StreamWriter writer = new System.IO.StreamWriter(seqNumsFile_);

writer.Write(GetNextSenderMsgSeqNum().ToString("D10") + " : " + GetNextTargetMsgSeqNum().ToString("D10") + " ");
writer.Write(NextSenderMsgSeqNum.ToString("D10") + " : " + NextTargetMsgSeqNum.ToString("D10") + " ");
writer.Flush();
}

Expand Down
8 changes: 3 additions & 5 deletions QuickFIXn/IMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public interface IMessageStore : IDisposable
/// <returns>true if successful, false otherwise</returns>
bool Set(int msgSeqNum, string msg);

/// FIXME v2 - property-ize these get/set functions
int GetNextSenderMsgSeqNum();
int GetNextTargetMsgSeqNum();
void SetNextSenderMsgSeqNum(int value);
void SetNextTargetMsgSeqNum(int value);
int NextSenderMsgSeqNum { get; set; }
int NextTargetMsgSeqNum { get; set; }

void IncrNextSenderMsgSeqNum();
void IncrNextTargetMsgSeqNum();

Expand Down
23 changes: 6 additions & 17 deletions QuickFIXn/MemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class MemoryStore : IMessageStore
#region Private Members

System.Collections.Generic.Dictionary<int, string> messages_;
int nextSenderMsgSeqNum_;
int nextTargetMsgSeqNum_;
DateTime? creationTime;

#endregion
Expand Down Expand Up @@ -40,23 +38,14 @@ public bool Set(int msgSeqNum, string msg)
return true;
}

public int GetNextSenderMsgSeqNum()
{ return nextSenderMsgSeqNum_; }

public int GetNextTargetMsgSeqNum()
{ return nextTargetMsgSeqNum_; }

public void SetNextSenderMsgSeqNum(int value)
{ nextSenderMsgSeqNum_ = value; }

public void SetNextTargetMsgSeqNum(int value)
{ nextTargetMsgSeqNum_ = value; }
public int NextSenderMsgSeqNum { get; set; }
public int NextTargetMsgSeqNum { get; set; }

public void IncrNextSenderMsgSeqNum()
{ ++nextSenderMsgSeqNum_; }
{ ++NextSenderMsgSeqNum; }

public void IncrNextTargetMsgSeqNum()
{ ++nextTargetMsgSeqNum_; }
{ ++NextTargetMsgSeqNum; }

public System.DateTime? CreationTime
{
Expand All @@ -66,8 +55,8 @@ public System.DateTime? CreationTime

public void Reset()
{
nextSenderMsgSeqNum_ = 1;
nextTargetMsgSeqNum_ = 1;
NextSenderMsgSeqNum = 1;
NextTargetMsgSeqNum = 1;
messages_.Clear();
creationTime = DateTime.UtcNow;
}
Expand Down
44 changes: 22 additions & 22 deletions QuickFIXn/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public int NextSenderMsgSeqNum
{
get
{
return state_.GetNextSenderMsgSeqNum();
return state_.NextSenderMsgSeqNum;
}
set
{
state_.SetNextSenderMsgSeqNum(value);
state_.NextSenderMsgSeqNum = value;
}
}

Expand All @@ -95,11 +95,11 @@ public int NextTargetMsgSeqNum
{
get
{
return state_.GetNextTargetMsgSeqNum();
return state_.NextTargetMsgSeqNum;
}
set
{
state_.SetNextTargetMsgSeqNum(value);
state_.NextTargetMsgSeqNum = value;
}
}

Expand Down Expand Up @@ -786,13 +786,13 @@ protected void NextResendRequest(Message resendReq)

if ((endSeqNo == 999999) || (endSeqNo == 0))
{
endSeqNo = state_.GetNextSenderMsgSeqNum() - 1;
endSeqNo = state_.NextSenderMsgSeqNum - 1;
}

if (!PersistMessages)
{
endSeqNo++;
int next = state_.GetNextSenderMsgSeqNum();
int next = state_.NextSenderMsgSeqNum;
if (endSeqNo > next)
endSeqNo = next;
GenerateSequenceReset(resendReq, begSeqNo, endSeqNo);
Expand Down Expand Up @@ -845,7 +845,7 @@ protected void NextResendRequest(Message resendReq)
current = msgSeqNum + 1;
}

int nextSeqNum = state_.GetNextSenderMsgSeqNum();
int nextSeqNum = state_.NextSenderMsgSeqNum;
if (++endSeqNo > nextSeqNum)
{
endSeqNo = nextSeqNum;
Expand Down Expand Up @@ -932,15 +932,15 @@ protected void NextSequenceReset(Message sequenceReset)
if (sequenceReset.IsSetField(Fields.Tags.NewSeqNo))
{
int newSeqNo = sequenceReset.GetInt(Fields.Tags.NewSeqNo);
this.Log.OnEvent("Received SequenceReset FROM: " + state_.GetNextTargetMsgSeqNum() + " TO: " + newSeqNo);
this.Log.OnEvent("Received SequenceReset FROM: " + state_.NextTargetMsgSeqNum + " TO: " + newSeqNo);

if (newSeqNo > state_.GetNextTargetMsgSeqNum())
if (newSeqNo > state_.NextTargetMsgSeqNum)
{
state_.SetNextTargetMsgSeqNum(newSeqNo);
state_.NextTargetMsgSeqNum = newSeqNo;
}
else
{
if (newSeqNo < state_.GetNextTargetMsgSeqNum())
if (newSeqNo < state_.NextTargetMsgSeqNum)
GenerateReject(sequenceReset, FixValues.SessionRejectReason.VALUE_IS_INCORRECT);
}
}
Expand Down Expand Up @@ -1077,8 +1077,8 @@ protected bool ShouldSendReset()
{
return (this.SessionID.BeginString.CompareTo(FixValues.BeginString.FIX41) >= 0)
&& (this.ResetOnLogon || this.ResetOnLogout || this.ResetOnDisconnect)
&& (state_.GetNextSenderMsgSeqNum() == 1)
&& (state_.GetNextTargetMsgSeqNum() == 1);
&& (state_.NextSenderMsgSeqNum == 1)
&& (state_.NextTargetMsgSeqNum == 1);
}

protected bool IsCorrectCompID(string senderCompID, string targetCompID)
Expand All @@ -1097,19 +1097,19 @@ protected bool IsTimeToGenerateLogon()

protected bool IsTargetTooHigh(int msgSeqNum)
{
return msgSeqNum > state_.GetNextTargetMsgSeqNum();
return msgSeqNum > state_.NextTargetMsgSeqNum;
}

protected bool IsTargetTooLow(int msgSeqNum)
{
return msgSeqNum < state_.GetNextTargetMsgSeqNum();
return msgSeqNum < state_.NextTargetMsgSeqNum;
}

protected void DoTargetTooHigh(Message msg, int msgSeqNum)
{
string beginString = msg.Header.GetString(Fields.Tags.BeginString);

this.Log.OnEvent("MsgSeqNum too high, expecting " + state_.GetNextTargetMsgSeqNum() + " but received " + msgSeqNum);
this.Log.OnEvent("MsgSeqNum too high, expecting " + state_.NextTargetMsgSeqNum + " but received " + msgSeqNum);
state_.Queue(msgSeqNum, msg);

if (state_.ResendRequested())
Expand All @@ -1134,7 +1134,7 @@ protected void DoTargetTooLow(Message msg, int msgSeqNum)

if (!possDupFlag)
{
string err = "MsgSeqNum too low, expecting " + state_.GetNextTargetMsgSeqNum() + " but received " + msgSeqNum;
string err = "MsgSeqNum too low, expecting " + state_.NextTargetMsgSeqNum + " but received " + msgSeqNum;
GenerateLogout(err);
throw new QuickFIXException(err);
}
Expand Down Expand Up @@ -1224,7 +1224,7 @@ protected bool GenerateResendRequestRange(string beginString, int startSeqNum, i

protected bool GenerateResendRequest(string beginString, int msgSeqNum)
{
int beginSeqNum = state_.GetNextTargetMsgSeqNum();
int beginSeqNum = state_.NextTargetMsgSeqNum;
int endRangeSeqNum = msgSeqNum - 1;
int endChunkSeqNum;
if (this.MaxMessagesInResendRequest > 0)
Expand Down Expand Up @@ -1436,7 +1436,7 @@ public bool GenerateReject(Message message, FixValues.SessionRejectReason reason
}
if (!MsgType.LOGON.Equals(msgType)
&& !MsgType.SEQUENCE_RESET.Equals(msgType)
&& (msgSeqNum == state_.GetNextTargetMsgSeqNum()))
&& (msgSeqNum == state_.NextTargetMsgSeqNum))
{
state_.IncrNextTargetMsgSeqNum();
}
Expand Down Expand Up @@ -1511,7 +1511,7 @@ protected void InitializeHeader(Message m, int msgSeqNum)
if (msgSeqNum > 0)
m.Header.SetField(new Fields.MsgSeqNum(msgSeqNum));
else
m.Header.SetField(new Fields.MsgSeqNum(state_.GetNextSenderMsgSeqNum()));
m.Header.SetField(new Fields.MsgSeqNum(state_.NextSenderMsgSeqNum));

if (this.EnableLastMsgSeqNumProcessed && !m.Header.IsSetField(Tags.LastMsgSeqNumProcessed))
{
Expand Down Expand Up @@ -1599,7 +1599,7 @@ protected void InsertOrigSendingTime(FieldMap header, System.DateTime sendingTim
}
protected void NextQueued()
{
while (NextQueued(state_.MessageStore.GetNextTargetMsgSeqNum()))
while (NextQueued(state_.MessageStore.NextTargetMsgSeqNum))
{
// continue
}
Expand Down Expand Up @@ -1653,7 +1653,7 @@ protected bool SendRaw(Message message, int seqNum)
if (resetSeqNumFlag.getValue())
{
state_.Reset("ResetSeqNumFlag");
message.Header.SetField(new Fields.MsgSeqNum(state_.GetNextSenderMsgSeqNum()));
message.Header.SetField(new Fields.MsgSeqNum(state_.NextSenderMsgSeqNum));
}
state_.SentReset = resetSeqNumFlag.Obj;
}
Expand Down
20 changes: 6 additions & 14 deletions QuickFIXn/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,16 @@ public bool Set(int msgSeqNum, string msg)
lock (sync_) { return this.MessageStore.Set(msgSeqNum, msg); }
}

public int GetNextSenderMsgSeqNum()
public int NextSenderMsgSeqNum
{
lock (sync_) { return this.MessageStore.GetNextSenderMsgSeqNum(); }
get { lock (sync_) { return this.MessageStore.NextSenderMsgSeqNum; } }
set { lock (sync_) { this.MessageStore.NextSenderMsgSeqNum = value; } }
}

public int GetNextTargetMsgSeqNum()
public int NextTargetMsgSeqNum
{
lock (sync_) { return this.MessageStore.GetNextTargetMsgSeqNum(); }
}

public void SetNextSenderMsgSeqNum(int value)
{
lock (sync_) { this.MessageStore.SetNextSenderMsgSeqNum(value); }
}

public void SetNextTargetMsgSeqNum(int value)
{
lock (sync_) { this.MessageStore.SetNextTargetMsgSeqNum(value); }
get { lock (sync_) { return this.MessageStore.NextTargetMsgSeqNum; } }
set { lock (sync_) { this.MessageStore.NextTargetMsgSeqNum = value; } }
}

public void IncrNextSenderMsgSeqNum()
Expand Down
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ We decided this wasn't big enough to warrant a v2 release, even though
it technically violates semantic versioning.

**Breaking changes in release**
* #748 - Update all csproj files to net6.0, fix .NET deprecations, update pwsh scripts, remove some non-pwsh scripts (gbirchmeier)
* #749 - All deprecations are removed (gbirchmeier)
* #746 - remove some unused public `FIXnn_LAST_FIELD` constants; corrected FIX44 DD `UNKOWN_ID` typo (gbirchmeier)
* #748 - Update all csproj files to net6.0, fix .NET deprecations, update pwsh scripts, remove some non-pwsh scripts (gbirchmeier)
* #756 - privatize DDField property setters,
change various Get/SetNextSenderMsgSeqNum & Get/SetNextTargetMsgSeqNum functions to properties (gbirchmeier)

**Non-breaking changes**
* (patch) #647 - replace lock with memory barrier to avoid deadlocks (brunobelmondo)
Expand Down
Loading

0 comments on commit 05cb09e

Please sign in to comment.