Skip to content

Commit 6a14e60

Browse files
blackspherefollowerqdot
authored andcommitted
Various review tweaks
1 parent 66488d5 commit 6a14e60

22 files changed

Lines changed: 278 additions & 141 deletions

File tree

Buttplug.Apps.DeviceSimulatorGUI/PipeMessages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public IDeviceSimulatorPipeMessage Deserialize(string aJsonMsg)
185185
}
186186

187187
var msgName = o.Properties().First().Name;
188-
if (!_messageTypes.Keys.Any() || !_messageTypes.Keys.Contains(msgName))
188+
if (!_messageTypes.Any() || !_messageTypes.ContainsKey(msgName))
189189
{
190190
return new ErrorMsg($"{msgName} is not a valid message class");
191191
}

Buttplug.Apps.ExampleClientGUI/ExampleClientPanel.xaml.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ private void SendVibrate_Click(object sender, RoutedEventArgs e)
166166
{
167167
_client.SendDeviceMessage(dev,
168168
new VibrateCmd(dev.Index,
169-
new List<VibrateCmd.VibrateIndex>
170-
{ new VibrateCmd.VibrateIndex(i, VibrateSpeed.Value) },
169+
new List<VibrateCmd.VibrateSubcommand>
170+
{ new VibrateCmd.VibrateSubcommand(i, VibrateSpeed.Value) },
171171
_client.nextMsgId));
172172
}
173173
}
@@ -198,8 +198,8 @@ private void SendRotate_Click(object sender, RoutedEventArgs e)
198198
bool clockwise = RotateSpeed.Value > 0;
199199
_client.SendDeviceMessage(dev,
200200
new RotateCmd(dev.Index,
201-
new List<RotateCmd.RotateIndex>
202-
{ new RotateCmd.RotateIndex(i, RotateSpeed.Value * (clockwise ? 1 : -1), clockwise) },
201+
new List<RotateCmd.RotateSubcommand>
202+
{ new RotateCmd.RotateSubcommand(i, RotateSpeed.Value * (clockwise ? 1 : -1), clockwise) },
203203
_client.nextMsgId));
204204
}
205205
}
@@ -222,9 +222,11 @@ private void SendLinear2_Click(object sender, RoutedEventArgs e)
222222
if (dev.AllowedMessages.ContainsKey("FleshlightLaunchFW12Cmd"))
223223
{
224224
_client.SendDeviceMessage(dev,
225-
new LinearCmd(dev.Index, new List<LinearCmd.VectorIndex>()
225+
new LinearCmd(dev.Index, new List<LinearCmd.VectorSubcommands>()
226226
{
227-
new LinearCmd.VectorIndex(0, Convert.ToUInt32(LinearDuration.Text), Linear2Position.Value),
227+
new LinearCmd.VectorSubcommands(0,
228+
Convert.ToUInt32(LinearDuration.Text),
229+
Linear2Position.Value),
228230
}, _client.nextMsgId));
229231
}
230232
}

Buttplug.Apps.GameVibrationRouter.GUI/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ await Dispatcher.Invoke(async () =>
107107
foreach (var device in _devices)
108108
{
109109
// For now, we only handle devices that can take vibration messages.
110-
if (!device.Messages.Keys.Contains(typeof(SingleMotorVibrateCmd).Name))
110+
if (!device.SupportsMessage(typeof(SingleMotorVibrateCmd)))
111111
{
112112
continue;
113113
}

Buttplug.Apps.KiirooEmulatorGUI/MainWindow.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void ClosingHandler(object aObj, CancelEventArgs e)
8080
private void SelectionChangedHandler(object aObj, List<ButtplugDeviceInfo> aDevices)
8181
{
8282
_devices = aDevices;
83-
if (_devices.Any(aDevice => aDevice.Messages.Keys.Contains("SingleMotorVibrateCmd")))
83+
if (_devices.Any(aDevice => aDevice.SupportsMessage(typeof(SingleMotorVibrateCmd))))
8484
{
8585
_translator.StartVibrateTimer();
8686
return;
@@ -133,7 +133,7 @@ private void OnVibrateEvent(object aObj, VibrateEventArgs aEvent)
133133
{
134134
foreach (var device in _devices)
135135
{
136-
if (device.Messages.Keys.Contains("SingleMotorVibrateCmd"))
136+
if (device.SupportsMessage(typeof(SingleMotorVibrateCmd)))
137137
{
138138
await _bpServer.SendMessage(new SingleMotorVibrateCmd(device.Index, aEvent.VibrateValue));
139139
}
@@ -150,19 +150,19 @@ await Dispatcher.InvokeAsync(async () =>
150150
FleshlightLaunchFW12Cmd currentTranslatedCommand = null;
151151
foreach (var device in _devices)
152152
{
153-
if (device.Messages.Keys.Contains(typeof(KiirooCmd).Name))
153+
if (device.SupportsMessage(typeof(KiirooCmd)))
154154
{
155155
await _bpServer.SendMessage(new KiirooCmd(device.Index, aEvent.Position));
156156
}
157-
else if (device.Messages.Keys.Contains("FleshlightLaunchFW12Cmd") ||
158-
device.Messages.Keys.Contains("SingleMotorVibrateCmd"))
157+
else if (device.SupportsMessage(typeof(FleshlightLaunchFW12Cmd)) ||
158+
device.SupportsMessage(typeof(SingleMotorVibrateCmd)))
159159
{
160160
if (currentTranslatedCommand == null)
161161
{
162162
currentTranslatedCommand = _translator.Translate(new KiirooCmd(device.Index, aEvent.Position));
163163
}
164164
currentTranslatedCommand.DeviceIndex = device.Index;
165-
if (device.Messages.Keys.Contains("FleshlightLaunchFW12Cmd"))
165+
if (device.SupportsMessage(typeof(FleshlightLaunchFW12Cmd)))
166166
{
167167
await _bpServer.SendMessage(currentTranslatedCommand);
168168
}

Buttplug.Client/ButtplugWSClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ public async Task Connect(Uri aURL, bool aIgnoreSSLErrors = false)
154154
}
155155

156156
_messageSchemaVersion = si.MessageVersion;
157-
if (_messageSchemaVersion < ButtplugMessage.CurrentMessageVersion)
157+
if (_messageSchemaVersion < ButtplugMessage.CurrentSchemaVersion)
158158
{
159159
throw new Exception("Buttplug Server's schema version (" + _messageSchemaVersion +
160-
") is less than the client's (" + ButtplugMessage.CurrentMessageVersion +
161-
"). A newer server is required!");
160+
") is less than the client's (" + ButtplugMessage.CurrentSchemaVersion +
161+
"). A newer server is required.");
162162
}
163163

164164
break;
@@ -447,12 +447,12 @@ protected async Task<ButtplugMessage> SendMessage(ButtplugMessage aMsg)
447447

448448
protected string Serialize(ButtplugMessage aMsg)
449449
{
450-
return _parser.Serialize(aMsg, ButtplugMessage.CurrentMessageVersion);
450+
return _parser.Serialize(aMsg, ButtplugMessage.CurrentSchemaVersion);
451451
}
452452

453453
protected string Serialize(ButtplugMessage[] aMsgs)
454454
{
455-
return _parser.Serialize(aMsgs, ButtplugMessage.CurrentMessageVersion);
455+
return _parser.Serialize(aMsgs, ButtplugMessage.CurrentSchemaVersion);
456456
}
457457

458458
protected ButtplugMessage[] Deserialize(string aMsg)

Buttplug.Components.Controls/ButtplugDeviceInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using Buttplug.Core.Messages;
3+
using System;
34

45
namespace Buttplug.Components.Controls
56
{
@@ -23,5 +24,10 @@ public override string ToString()
2324
{
2425
return $"{Index}: {Name}";
2526
}
27+
28+
public bool SupportsMessage(Type aMsg)
29+
{
30+
return Messages.ContainsKey(aMsg.Name);
31+
}
2632
}
2733
}

Buttplug.Core/ButtplugDeviceMessage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Newtonsoft.Json;
23

34
namespace Buttplug.Core
45
{
@@ -7,8 +8,8 @@ public class ButtplugDeviceMessage : ButtplugMessage
78
[JsonProperty(Required = Required.Always)]
89
public uint DeviceIndex { get; set; }
910

10-
public ButtplugDeviceMessage(uint aId, uint aDeviceIndex)
11-
: base(aId)
11+
public ButtplugDeviceMessage(uint aId, uint aDeviceIndex, uint aSchemaVersion = 0, Type aPreviousType = null)
12+
: base(aId, aSchemaVersion, aPreviousType)
1213
{
1314
DeviceIndex = aDeviceIndex;
1415
}

Buttplug.Core/ButtplugJsonMessageParser.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public ButtplugMessage[] Deserialize(string aJsonMsg)
123123
}
124124

125125
var msgName = o.Properties().First().Name;
126-
if (!_messageTypes.Keys.Any() || !_messageTypes.Keys.Contains(msgName))
126+
if (!_messageTypes.Any() || !_messageTypes.ContainsKey(msgName))
127127
{
128128
var err = new Error($"{msgName} is not a valid message class", ErrorClass.ERROR_MSG, ButtplugConsts.SystemMsgId);
129129
_bpLogger?.LogErrorMsg(err);
@@ -163,9 +163,9 @@ public string Serialize([NotNull] ButtplugMessage aMsg, uint clientSchemaVersion
163163

164164
// Support downgrading messages
165165
var tmp = aMsg;
166-
while (tmp.MessageVersioningVersion > clientSchemaVersion)
166+
while (tmp.SchemaVersion > clientSchemaVersion)
167167
{
168-
if (tmp.MessageVersioningPrevious == null)
168+
if (tmp.PreviousType == null)
169169
{
170170
if (tmp.Id == ButtplugConsts.SystemMsgId)
171171
{
@@ -179,7 +179,7 @@ public string Serialize([NotNull] ButtplugMessage aMsg, uint clientSchemaVersion
179179
continue;
180180
}
181181

182-
tmp = (ButtplugMessage)aMsg.MessageVersioningPrevious.GetConstructor(
182+
tmp = (ButtplugMessage)aMsg.PreviousType.GetConstructor(
183183
new Type[] { tmp.GetType() }).Invoke(new object[] { tmp });
184184
}
185185

@@ -197,9 +197,9 @@ public string Serialize([NotNull] IEnumerable<ButtplugMessage> aMsgs, uint clien
197197
{
198198
// Support downgrading messages
199199
var tmp = msg;
200-
while (tmp.MessageVersioningVersion > clientSchemaVersion)
200+
while (tmp.SchemaVersion > clientSchemaVersion)
201201
{
202-
if (tmp.MessageVersioningPrevious == null)
202+
if (tmp.PreviousType == null)
203203
{
204204
if (tmp.Id == ButtplugConsts.SystemMsgId)
205205
{
@@ -212,7 +212,7 @@ public string Serialize([NotNull] IEnumerable<ButtplugMessage> aMsgs, uint clien
212212
continue;
213213
}
214214

215-
tmp = (ButtplugMessage)tmp.MessageVersioningPrevious.GetConstructor(
215+
tmp = (ButtplugMessage)tmp.PreviousType.GetConstructor(
216216
new Type[] { tmp.GetType() }).Invoke(new object[] { tmp });
217217
}
218218

Buttplug.Core/ButtplugMessage.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Buttplug.Core
66
public class ButtplugMessage
77
{
88
/*
9-
* Message versions
9+
* Message schema versions
1010
*
1111
* These are here for backwards compatibility support, but
1212
* this also serves as a changelog of sorts.
@@ -19,50 +19,52 @@ public class ButtplugMessage
1919
* Addition of message attributes
2020
*/
2121
[JsonIgnore]
22-
public const uint CurrentMessageVersion = 1;
22+
public const uint CurrentSchemaVersion = 1;
2323

2424
[JsonProperty(Required = Required.Always)]
2525
public uint Id { get; set; }
2626

2727
[JsonIgnore]
28-
public uint MessageVersioningVersion
28+
public uint SchemaVersion
2929
{
3030
get
3131
{
32-
return _messageVersioningVersion;
32+
return _schemaVersion;
3333
}
3434

3535
protected set
3636
{
37-
_messageVersioningVersion = value;
37+
_schemaVersion = value;
3838
}
3939
}
4040

4141
[JsonIgnore]
42-
public Type MessageVersioningPrevious
42+
public Type PreviousType
4343
{
4444
get
4545
{
46-
return _messageVersioningPrevious;
46+
return _previousType;
4747
}
4848

4949
protected set
5050
{
51-
_messageVersioningPrevious = value;
51+
_previousType = value;
5252
}
5353
}
5454

5555
// Base class starts at version 0
5656
[JsonIgnore]
57-
private uint _messageVersioningVersion = 0;
57+
private uint _schemaVersion = 0;
5858

5959
// No previous version for base classes
6060
[JsonIgnore]
61-
private Type _messageVersioningPrevious = null;
61+
private Type _previousType = null;
6262

63-
public ButtplugMessage(uint aId)
63+
public ButtplugMessage(uint aId, uint aSchemaVersion = 0, Type aPreviousType = null)
6464
{
6565
Id = aId;
66+
SchemaVersion = aSchemaVersion;
67+
PreviousType = aPreviousType;
6668
}
6769
}
6870

0 commit comments

Comments
 (0)