mirror of
https://github.com/jwetzell/qController.git
synced 2026-08-21 06:59:17 +00:00
Don't crash when no tcp connection can be created.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace qController.Communication
|
|||||||
public QParser qParser;
|
public QParser qParser;
|
||||||
string Address;
|
string Address;
|
||||||
int Port;
|
int Port;
|
||||||
|
public bool connected;
|
||||||
|
|
||||||
public QClient(string address, int port)
|
public QClient(string address, int port)
|
||||||
{
|
{
|
||||||
@@ -20,8 +21,7 @@ namespace qController.Communication
|
|||||||
Port = port;
|
Port = port;
|
||||||
qParser = new QParser();
|
qParser = new QParser();
|
||||||
tcpClient = new TCPClient(Address, Port);
|
tcpClient = new TCPClient(Address, Port);
|
||||||
tcpClient.Connect();
|
connected = tcpClient.Connect();
|
||||||
|
|
||||||
tcpClient.MessageReceived += OnMessageReceived;
|
tcpClient.MessageReceived += OnMessageReceived;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,70 +8,7 @@ using Serilog;
|
|||||||
|
|
||||||
namespace qController.Communication
|
namespace qController.Communication
|
||||||
{
|
{
|
||||||
public class CueEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public QCue Cue
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WorkspaceEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public QWorkspace UpdatedWorkspace
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PlaybackPositionArgs : EventArgs
|
|
||||||
{
|
|
||||||
public string PlaybackPosition
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConnectEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public string Status
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string WorkspaceId
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WorkspaceInfoArgs : EventArgs
|
|
||||||
{
|
|
||||||
public List<QWorkspaceInfo> WorkspaceInfo
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ChildrenEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public string cue_id
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
public List<QCue> children
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class QParser
|
public class QParser
|
||||||
{
|
{
|
||||||
@@ -80,15 +17,7 @@ namespace qController.Communication
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void SelectedCueUpdatedHandler(object source, CueEventArgs args);
|
|
||||||
public delegate void WorkspaceUpdatedHandler(object source, WorkspaceEventArgs args);
|
|
||||||
public delegate void CueInfoUpdatedHandler(object source, CueEventArgs args);
|
|
||||||
public delegate void PlaybackPositionUpdatedHandler(object source, PlaybackPositionArgs args);
|
|
||||||
public delegate void ConnectionStatusHandler(object source, ConnectEventArgs args);
|
|
||||||
public delegate void ChildrenUpdateHandler(object source, ChildrenEventArgs args);
|
|
||||||
public delegate void WorkspaceDisconnectHandler(object source, EventArgs args);
|
|
||||||
public delegate void WorkspaceInfoHandler(object source, WorkspaceInfoArgs args);
|
|
||||||
public delegate void WorkspaceLoadErrorHandler(object source, WorkspaceEventArgs args);
|
|
||||||
public event WorkspaceLoadErrorHandler WorkspaceLoadError;
|
public event WorkspaceLoadErrorHandler WorkspaceLoadError;
|
||||||
public event WorkspaceInfoHandler WorkspaceInfoReceived;
|
public event WorkspaceInfoHandler WorkspaceInfoReceived;
|
||||||
public event WorkspaceDisconnectHandler WorkspaceDisconnect;
|
public event WorkspaceDisconnectHandler WorkspaceDisconnect;
|
||||||
@@ -214,50 +143,41 @@ namespace qController.Communication
|
|||||||
|
|
||||||
protected virtual void OnWorkspaceUpdated(QWorkspace workspace)
|
protected virtual void OnWorkspaceUpdated(QWorkspace workspace)
|
||||||
{
|
{
|
||||||
if (WorkspaceUpdated != null)
|
WorkspaceUpdated?.Invoke(this, new WorkspaceEventArgs() { UpdatedWorkspace = workspace });
|
||||||
WorkspaceUpdated(this, new WorkspaceEventArgs() { UpdatedWorkspace = workspace });
|
|
||||||
}
|
}
|
||||||
protected virtual void OnSelectedCueUpdated(QCue cue)
|
protected virtual void OnSelectedCueUpdated(QCue cue)
|
||||||
{
|
{
|
||||||
if (SelectedCueUpdated != null)
|
SelectedCueUpdated?.Invoke(this, new CueEventArgs() { Cue = cue });
|
||||||
SelectedCueUpdated(this, new CueEventArgs() { Cue = cue });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnCueInfoUpdated(QCue cue)
|
protected virtual void OnCueInfoUpdated(QCue cue)
|
||||||
{
|
{
|
||||||
if (CueInfoUpdated != null)
|
CueInfoUpdated?.Invoke(this, new CueEventArgs() { Cue = cue });
|
||||||
CueInfoUpdated(this, new CueEventArgs() { Cue = cue });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnPlaybackPositionUpdated(string id)
|
protected virtual void OnPlaybackPositionUpdated(string id)
|
||||||
{
|
{
|
||||||
if (PlaybackPositionUpdated != null)
|
PlaybackPositionUpdated?.Invoke(this, new PlaybackPositionArgs() { PlaybackPosition = id });
|
||||||
PlaybackPositionUpdated(this, new PlaybackPositionArgs() { PlaybackPosition = id });
|
|
||||||
}
|
}
|
||||||
protected virtual void OnConnectionStatusChanged(string status, string workspace_id)
|
protected virtual void OnConnectionStatusChanged(string status, string workspace_id)
|
||||||
{
|
{
|
||||||
if (ConnectionStatusChanged != null)
|
ConnectionStatusChanged?.Invoke(this, new ConnectEventArgs() { Status = status, WorkspaceId = workspace_id });
|
||||||
ConnectionStatusChanged(this, new ConnectEventArgs() { Status = status, WorkspaceId = workspace_id });
|
|
||||||
}
|
}
|
||||||
protected virtual void OnChildrenUpdated(string id, List<QCue> cues)
|
protected virtual void OnChildrenUpdated(string id, List<QCue> cues)
|
||||||
{
|
{
|
||||||
if (ChildrenUpdated != null)
|
ChildrenUpdated?.Invoke(this, new ChildrenEventArgs() { cue_id = id, children = cues });
|
||||||
ChildrenUpdated(this, new ChildrenEventArgs() { cue_id = id, children = cues });
|
|
||||||
}
|
}
|
||||||
protected virtual void OnWorkspaceDisconnect()
|
protected virtual void OnWorkspaceDisconnect()
|
||||||
{
|
{
|
||||||
if (WorkspaceDisconnect != null)
|
WorkspaceDisconnect?.Invoke(this, new EventArgs());
|
||||||
WorkspaceDisconnect(this, new EventArgs());
|
|
||||||
}
|
}
|
||||||
protected virtual void OnWorkspaceInfoReceived(List<QWorkspaceInfo> workspaces)
|
protected virtual void OnWorkspaceInfoReceived(List<QWorkspaceInfo> workspaces)
|
||||||
{
|
{
|
||||||
if (WorkspaceInfoReceived != null)
|
WorkspaceInfoReceived?.Invoke(this, new WorkspaceInfoArgs() { WorkspaceInfo = workspaces });
|
||||||
WorkspaceInfoReceived(this, new WorkspaceInfoArgs() { WorkspaceInfo = workspaces });
|
|
||||||
}
|
}
|
||||||
protected virtual void OnWorkspaceLoadError(string id)
|
protected virtual void OnWorkspaceLoadError(string id)
|
||||||
{
|
{
|
||||||
if (WorkspaceLoadError != null)
|
WorkspaceLoadError?.Invoke(this, new WorkspaceEventArgs { UpdatedWorkspace = new QWorkspace(id) });
|
||||||
WorkspaceLoadError(this, new WorkspaceEventArgs { UpdatedWorkspace = new QWorkspace(id) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace SharpOSC
|
namespace SharpOSC
|
||||||
{
|
{
|
||||||
@@ -47,12 +46,22 @@ namespace SharpOSC
|
|||||||
_address = address;
|
_address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect()
|
public bool Connect()
|
||||||
{
|
{
|
||||||
client = new TcpClient(Address, Port);
|
try
|
||||||
Log.Debug($"TCPClient - connect called for <{Address}:{Port}>");
|
{
|
||||||
Thread receivingThread = new Thread(ReceiveLoop);
|
client = new TcpClient(Address, Port);
|
||||||
receivingThread.Start();
|
Thread receivingThread = new Thread(ReceiveLoop);
|
||||||
|
receivingThread.Start();
|
||||||
|
//Console.WriteLine($"TCPClient - connected to <{Address}:{Port}>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(byte[] message)
|
public void Send(byte[] message)
|
||||||
@@ -68,13 +77,21 @@ namespace SharpOSC
|
|||||||
Send(data);
|
Send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsConnected
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return client.Connected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ReceiveLoop()
|
public void ReceiveLoop()
|
||||||
{
|
{
|
||||||
while (client.Connected)
|
while (client.Connected)
|
||||||
{
|
{
|
||||||
Receive();
|
Receive();
|
||||||
}
|
}
|
||||||
Log.Debug("TCPClient - Receive Loop has exited for some reason");
|
Console.WriteLine("TCPClient - Receive Loop has exited for some reason");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Receive()
|
public void Receive()
|
||||||
@@ -102,15 +119,15 @@ namespace SharpOSC
|
|||||||
//Log.Debug("Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.UTF8.GetString(buffer));
|
//Log.Debug("Thread " + num + ": Bytes read: " + bytesRead + " - " + Encoding.UTF8.GetString(buffer));
|
||||||
} while (netStream.DataAvailable);
|
} while (netStream.DataAvailable);
|
||||||
|
|
||||||
//Log.Debug("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray()));
|
//Console.WriteLine("Raw TCP In: " + System.Text.Encoding.UTF8.GetString(responseData.ToArray()));
|
||||||
OscMessage response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray());
|
OscMessage response = (OscMessage)OscPacket.GetPacket(responseData.Skip(1).ToArray());
|
||||||
//watch.Stop();
|
//watch.Stop();
|
||||||
//Log.Debug($"TCPCLient - message receive took {watch.ElapsedMilliseconds}ms and {reads} reads");
|
//Console.WriteLine($"TCPCLient - message receive took {watch.ElapsedMilliseconds}ms and {reads} reads");
|
||||||
OnMessageReceived(response);
|
OnMessageReceived(response);
|
||||||
}
|
}
|
||||||
} catch(Exception e)
|
} catch(Exception e)
|
||||||
{
|
{
|
||||||
//Log.Debug("TCPSENDER - Receive Exception: " + e.ToString());
|
//Console.WriteLine("TCPSENDER - Receive Exception: " + e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,8 +167,7 @@ namespace SharpOSC
|
|||||||
|
|
||||||
protected virtual void OnMessageReceived(OscMessage msg)
|
protected virtual void OnMessageReceived(OscMessage msg)
|
||||||
{
|
{
|
||||||
if (MessageReceived != null)
|
MessageReceived?.Invoke(this, new MessageEventArgs() { Message = msg });
|
||||||
MessageReceived(this, new MessageEventArgs() { Message = msg });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ namespace qController
|
|||||||
|
|
||||||
InitGUI();
|
InitGUI();
|
||||||
|
|
||||||
|
if (!qController.qClient.connected)
|
||||||
|
{
|
||||||
|
App.showToast("Error connecting...make sure QLab is running");
|
||||||
|
Back();
|
||||||
|
}
|
||||||
qController.KickOff();
|
qController.KickOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +225,8 @@ namespace qController
|
|||||||
|
|
||||||
void Back()
|
void Back()
|
||||||
{
|
{
|
||||||
qController.Kill();
|
if(qController.qClient.connected)
|
||||||
|
qController.Kill();
|
||||||
App.rootPage.MenuItemSelected -= OnMenuItemSelected;
|
App.rootPage.MenuItemSelected -= OnMenuItemSelected;
|
||||||
Device.BeginInvokeOnMainThread(() =>
|
Device.BeginInvokeOnMainThread(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,11 +83,9 @@
|
|||||||
<EmbeddedResource Include="App.xaml" />
|
<EmbeddedResource Include="App.xaml" />
|
||||||
</ItemGroup>-->
|
</ItemGroup>-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Classes\" />
|
|
||||||
<Folder Include="Pages\" />
|
<Folder Include="Pages\" />
|
||||||
<Folder Include="Classes\QItems\" />
|
<Folder Include="Classes\QItems\" />
|
||||||
<Folder Include="Classes\Cell\" />
|
<Folder Include="Classes\Cell\" />
|
||||||
<Folder Include="Classes\Communication\" />
|
|
||||||
<Folder Include="Classes\Settings\" />
|
<Folder Include="Classes\Settings\" />
|
||||||
<Folder Include="Classes\Dialogs\" />
|
<Folder Include="Classes\Dialogs\" />
|
||||||
<Folder Include="Classes\Buttons\" />
|
<Folder Include="Classes\Buttons\" />
|
||||||
|
|||||||
Reference in New Issue
Block a user