Skip to content

Commit 2b6ea5a

Browse files
committed
chore: Minor refactoring and license header.
1 parent dbb0411 commit 2b6ea5a

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var mpfApi = new MpfApi(@"path\to\machine\folder");
2525
await mpfApi.Launch();
2626

2727
// start MPF
28-
await mpfApi.Start();
28+
mpfApi.Start();
2929

3030
// retrieve machine configuration
3131
var descr = await mpfApi.GetMachineDescription();

VisualPinball.Engine.Mpf.Test/Program.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
using System;
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using System;
213
using System.Collections.Generic;
314
using System.Diagnostics;
415
using System.Threading.Tasks;
@@ -15,7 +26,7 @@ static async Task Main(string[] args)
1526

1627
await mpfApi.Launch();
1728

18-
await mpfApi.Start(new Dictionary<string, bool> {
29+
mpfApi.Start(new Dictionary<string, bool> {
1930
{"sw_11", false},
2031
});
2132

VisualPinball.Engine.Mpf/MpfApi.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
using System;
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using System;
213
using System.Collections.Generic;
314
using System.IO;
415
using System.Threading.Tasks;
@@ -19,19 +30,21 @@ public MpfApi(string machineFolder)
1930
/// <summary>
2031
/// Launches MPF in the background and connects to it via gRPC.
2132
/// </summary>
22-
public async Task Launch()
33+
/// <param name="port">gRPC port to use for MPC/VPE communication</param>
34+
/// <returns></returns>
35+
public async Task Launch(int port = 50051)
2336
{
2437
await _spawner.Spawn();
25-
await _client.Connect();
38+
await _client.Connect($"localhost:{port}");
2639
}
2740

2841
/// <summary>
2942
/// Starts MPF, i.e. it will start polling for switches and sending events.
3043
/// </summary>
3144
/// <param name="initialSwitches">Initial switch states of the machine</param>
32-
public async Task Start(Dictionary<string, bool> initialSwitches = null)
45+
public void Start(Dictionary<string, bool> initialSwitches = null)
3346
{
34-
await _client.Start(initialSwitches ?? new Dictionary<string, bool>());
47+
_client.Start(initialSwitches ?? new Dictionary<string, bool>());
3548
}
3649

3750
/// <summary>

VisualPinball.Engine.Mpf/MpfClient.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
using Grpc.Core;
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using Grpc.Core;
213
using System;
314
using System.Collections.Generic;
415
using System.Threading.Tasks;
@@ -12,14 +23,14 @@ internal class MpfClient : IDisposable
1223
private Channel _channel;
1324
private MpfHardwareService.MpfHardwareServiceClient _client;
1425

15-
public async Task Connect(string ipPort = "localhost:50051") {
26+
public async Task Connect(string ipPort) {
1627
Console.WriteLine($"Connecting to {ipPort}...");
1728
_channel = new Channel(ipPort, ChannelCredentials.Insecure);
1829
await _channel.ConnectAsync();
1930
_client = new MpfHardwareService.MpfHardwareServiceClient(_channel);
2031
}
2132

22-
public async Task Start(Dictionary<string, bool> initialSwitches)
33+
public void Start(Dictionary<string, bool> initialSwitches)
2334
{
2435
var machineState = new MachineState();
2536
machineState.InitialSwitchStates.Add(initialSwitches);

VisualPinball.Engine.Mpf/MpfSpawner.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
using System;
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
10+
// SOFTWARE.
11+
12+
using System;
213
using System.Diagnostics;
314
using System.IO;
415
using System.Runtime.InteropServices;

0 commit comments

Comments
 (0)