diff --git a/NooSphere/ActivityBar/ActivityUI.csproj b/NooSphere/ActivityBar/ActivityUI.csproj index c434ee4..c92b503 100644 --- a/NooSphere/ActivityBar/ActivityUI.csproj +++ b/NooSphere/ActivityBar/ActivityUI.csproj @@ -1,242 +1,243 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {B885C84D-D2C7-4B1A-8167-2D6544AF99E3} - WinExe - Properties - ActivityUI - ActivityUI - v4.0 - - - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - Svn - Svn - Svn - SubversionScc - true - 4.0.20525.0 - ..\ - true - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Mono.Zeroconf.0.9.0.0\lib\Net20\Mono.Zeroconf.dll - - - ..\packages\Mono.Zeroconf.0.9.0.0\lib\Net20\Mono.Zeroconf.Providers.Bonjour.dll - - - ..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - 4.0 - - - - - - - - - - MSBuild:Compile - Designer - - - - - - - - ActivityWindow.xaml - - - DeviceWindow.xaml - - - ManagerWindow.xaml - - - StartMenu.xaml - - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - ActivityBar.xaml - - - App.xaml - Code - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - LoginWindow.xaml - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - {5CD6DD93-3EA1-425F-89D7-A80FD23BBC71} - NooSphere.ActivitySystem - - - {03C072A4-5960-4A5D-B0CC-98EBD854E970} - NooSphere.Core - - - {B3333919-EE66-441A-8AB3-6E6601A8A0B1} - NooSphere.Platform.Windows - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {B885C84D-D2C7-4B1A-8167-2D6544AF99E3} + WinExe + Properties + ActivityUI + ActivityUI + v4.0 + + + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + Svn + Svn + Svn + SubversionScc + true + 4.0.20525.0 + ..\ + true + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Mono.Zeroconf.0.9.0.0\lib\Net20\Mono.Zeroconf.dll + + + ..\packages\Mono.Zeroconf.0.9.0.0\lib\Net20\Mono.Zeroconf.Providers.Bonjour.dll + + + ..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + 4.0 + + + + + + + + + + MSBuild:Compile + Designer + + + + + + + + + ActivityWindow.xaml + + + DeviceWindow.xaml + + + ManagerWindow.xaml + + + StartMenu.xaml + + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + ActivityBar.xaml + + + App.xaml + Code + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + LoginWindow.xaml + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + {5CD6DD93-3EA1-425F-89D7-A80FD23BBC71} + NooSphere.ActivitySystem + + + {03C072A4-5960-4A5D-B0CC-98EBD854E970} + NooSphere.Core + + + {B3333919-EE66-441A-8AB3-6E6601A8A0B1} + NooSphere.Platform.Windows + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NooSphere/ActivityBar/Context/InputRedirect.cs b/NooSphere/ActivityBar/Context/InputRedirect.cs new file mode 100644 index 0000000..38f44c6 --- /dev/null +++ b/NooSphere/ActivityBar/Context/InputRedirect.cs @@ -0,0 +1,180 @@ + +/**************************************************************************** + (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk) + + Pervasive Interaction Technology Laboratory (pIT lab) + IT University of Copenhagen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later, + as published by the Free Software Foundation. Check + http://www.gnu.org/licenses/gpl.html for details. +****************************************************************************/ + +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using NooSphere.ActivitySystem.Context; +using NooSphere.ActivitySystem.Context.Multicast; +using NooSphere.Platform.Windows.Hooks; + +namespace ActivityUI.Context +{ + public class InputRedirect : IContextService + { + private MulticastSocket _mSocket; + private Point _previousPoint; + private bool _unInitializedMouse = true; + public PointerRole PointerRole { get; private set; } + + public InputRedirect(PointerRole role) + { + PointerRole = role; + + } + public void Start() + { + _mSocket = new MulticastSocket("225.5.6.7", 5000, 10); + _mSocket.OnNotifyMulticastSocketListener += _mSocket_OnNotifyMulticastSocketListener; + Initialize(PointerRole); + } + public void Stop() + { + MouseHook.UnRegister(); + } + private void Initialize(PointerRole role) + { + switch (role) + { + case PointerRole.Controller: + MouseHook.Register(); + MouseHook.MouseDown += MouseHookMouseDown; + MouseHook.MouseMove += MouseHookMouseMove; + MouseHook.MouseUp += MouseHookMouseUp; + break; + case PointerRole.Slave: + MouseHook.MouseDown += MouseHookMouseDown; + MouseHook.MouseMove += MouseHookMouseMove; + MouseHook.MouseUp += MouseHookMouseUp; + _mSocket.StartReceiving(); + break; + } + } + + + private void MouseHookMouseUp(object sender, MouseEventArgs e) + { + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(e.X, e.Y, PointerEvent.MouseUp).ToString()); + } + private void MouseHookMouseMove(object sender, MouseEventArgs e) + { + if (_unInitializedMouse) + { + _previousPoint = e.Location; + _unInitializedMouse = false; + } + var xDif = _previousPoint.X - e.Location.X; + var yDif = _previousPoint.Y - e.Location.Y; + Console.WriteLine(xDif + "---" + yDif); + + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(e.Location.X, e.Location.Y+ yDif, PointerEvent.MouseMove).ToString()); + _previousPoint = e.Location; + } + private void MouseHookMouseDown(object sender, MouseEventArgs e) + { + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(e.X, e.Y, PointerEvent.MouseDown).ToString()); + } + + [DllImport("User32.dll")] + private static extern bool SetCursorPos(int x, int y); + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); + + public const int MOUSEEVENTF_LEFTDOWN = 0x02; + public const int MOUSEEVENTF_LEFTUP = 0x04; + public const int MOUSEEVENTF_RIGHTDOWN = 0x08; + public const int MOUSEEVENTF_RIGHTUP = 0x10; + private void _mSocket_OnNotifyMulticastSocketListener(object sender, NotifyMulticastSocketListenerEventArgs e) + { + if (e.Type == MulticastSocketMessageType.MessageReceived) + { + var msg = System.Text.Encoding.ASCII.GetString((byte[])e.NewObject); + var res = new PointerMessage(Convert.ToInt32(msg.Split('@')[0]), Convert.ToInt32(msg.Split('@')[1]), (PointerEvent)Enum.Parse(typeof(PointerEvent), msg.Split('@')[2])); + HandleMessage(res); + if (DataReceived != null) + { + DataReceived(this, new DataEventArgs(msg)); + } + } + } + private void HandleMessage(PointerMessage res) + { + switch (res.Message) + { + case PointerEvent.MouseMove: + SetCursorPos(res.X, res.Y); + break; + case PointerEvent.MouseDown: + mouse_event(MOUSEEVENTF_LEFTDOWN, res.X, res.Y, 0, 0); + break; + case PointerEvent.MouseUp: + mouse_event(MOUSEEVENTF_LEFTUP, res.X, res.Y, 0, 0); + break; + } + } + + + public string Name { get; set; } + public Guid Id { get; set; } + + public void Send(string message) + { + _mSocket.Send(message); + } + + public event DataReceivedHandler DataReceived; + public event System.EventHandler Started; + public event System.EventHandler Stopped; + + } + + public class PointerMessage + { + public int X { get; set; } + public int Y { get; set; } + public PointerEvent Message { get; set; } + + public PointerMessage(int x, int y, PointerEvent msg) + { + X = x; + Y = y; + Message = msg; + } + public override string ToString() + { + return X + "@" + Y + "@" + Message; + } + } + + public enum PointerRole + { + Controller, + Slave, + Both + } + + public enum PointerEvent + { + MouseMove, + MouseUp, + MouseDown, + TouchUp, + TouchDown + } + + +} diff --git a/NooSphere/ActivityBar/Xaml/ActivityBar.xaml.cs b/NooSphere/ActivityBar/Xaml/ActivityBar.xaml.cs index 1e0405b..9afb466 100644 --- a/NooSphere/ActivityBar/Xaml/ActivityBar.xaml.cs +++ b/NooSphere/ActivityBar/Xaml/ActivityBar.xaml.cs @@ -23,6 +23,7 @@ using System.Windows.Threading; using System.Runtime.InteropServices; using System.Windows.Interop; +using ActivityUI.Context; using NooSphere.ActivitySystem.Base; using NooSphere.ActivitySystem.Base.Client; using NooSphere.ActivitySystem.Base.Service; @@ -244,7 +245,10 @@ private void StartClient(string activityManagerHttpAddress) _client.ContextMessageReceived += _client_ContextMessageReceived; _client.ConnectionEstablished += ClientConnectionEstablished; - _client.ServiceIsDown += new ServiceDownHandler(_client_ServiceIsDown); + _client.ServiceIsDown += _client_ServiceIsDown; + + _client.ContextMonitor.AddContextService(new InputRedirect(PointerRole.Slave)); + _client.Open(activityManagerHttpAddress); } @@ -268,6 +272,7 @@ void _client_ContextMessageReceived(object sender, ContextEventArgs e) void ClientConnectionEstablished(object sender, EventArgs e) { + _client.ContextMonitor.Start(); BuildUi(); _startingUp = false; } diff --git a/NooSphere/ActivityTablet/ActivityTablet.csproj b/NooSphere/ActivityTablet/ActivityTablet.csproj index 853ee32..36d38cc 100644 --- a/NooSphere/ActivityTablet/ActivityTablet.csproj +++ b/NooSphere/ActivityTablet/ActivityTablet.csproj @@ -94,6 +94,7 @@ MSBuild:Compile Designer + @@ -181,6 +182,10 @@ {03C072A4-5960-4A5D-B0CC-98EBD854E970} NooSphere.Core + + {B3333919-EE66-441A-8AB3-6E6601A8A0B1} + NooSphere.Platform.Windows + diff --git a/NooSphere/ActivityTablet/Context/InputRedirect.cs b/NooSphere/ActivityTablet/Context/InputRedirect.cs new file mode 100644 index 0000000..c768380 --- /dev/null +++ b/NooSphere/ActivityTablet/Context/InputRedirect.cs @@ -0,0 +1,180 @@ + +/**************************************************************************** + (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk) + + Pervasive Interaction Technology Laboratory (pIT lab) + IT University of Copenhagen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later, + as published by the Free Software Foundation. Check + http://www.gnu.org/licenses/gpl.html for details. +****************************************************************************/ + +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using NooSphere.ActivitySystem.Context; +using NooSphere.ActivitySystem.Context.Multicast; +using NooSphere.Platform.Windows.Hooks; + +namespace ActivityTablet.Context +{ + public class InputRedirect : IContextService + { + private MulticastSocket _mSocket; + private Point _previousPoint; + private bool _unInitializedMouse = true; + public PointerRole PointerRole { get; private set; } + + public InputRedirect(PointerRole role) + { + PointerRole = role; + + } + public void Start() + { + _mSocket = new MulticastSocket("225.5.6.7", 5000, 10); + _mSocket.OnNotifyMulticastSocketListener += _mSocket_OnNotifyMulticastSocketListener; + Initialize(PointerRole); + } + public void Stop() + { + MouseHook.UnRegister(); + } + private void Initialize(PointerRole role) + { + switch (role) + { + case PointerRole.Controller: + MouseHook.Register(); + MouseHook.MouseDown += MouseHookMouseDown; + MouseHook.MouseMove += MouseHookMouseMove; + MouseHook.MouseUp += MouseHookMouseUp; + break; + case PointerRole.Slave: + MouseHook.MouseDown += MouseHookMouseDown; + MouseHook.MouseMove += MouseHookMouseMove; + MouseHook.MouseUp += MouseHookMouseUp; + _mSocket.StartReceiving(); + break; + } + } + + + private void MouseHookMouseUp(object sender, MouseEventArgs e) + { + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(e.X, e.Y, PointerEvent.MouseUp).ToString()); + } + private void MouseHookMouseMove(object sender, MouseEventArgs e) + { + if (_unInitializedMouse) + { + _previousPoint = e.Location; + _unInitializedMouse = false; + } + var xDif = _previousPoint.X - e.Location.X; + var yDif = _previousPoint.Y - e.Location.Y; + Console.WriteLine(xDif + "---" + yDif); + + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(_previousPoint.X + xDif, _previousPoint.Y + yDif, PointerEvent.MouseMove).ToString()); + _previousPoint = e.Location; + } + private void MouseHookMouseDown(object sender, MouseEventArgs e) + { + if (PointerRole == PointerRole.Controller) + Send(new PointerMessage(e.X, e.Y, PointerEvent.MouseDown).ToString()); + } + + [DllImport("User32.dll")] + private static extern bool SetCursorPos(int x, int y); + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); + + public const int MOUSEEVENTF_LEFTDOWN = 0x02; + public const int MOUSEEVENTF_LEFTUP = 0x04; + public const int MOUSEEVENTF_RIGHTDOWN = 0x08; + public const int MOUSEEVENTF_RIGHTUP = 0x10; + private void _mSocket_OnNotifyMulticastSocketListener(object sender, NotifyMulticastSocketListenerEventArgs e) + { + if (e.Type == MulticastSocketMessageType.MessageReceived) + { + var msg = System.Text.Encoding.ASCII.GetString((byte[])e.NewObject); + var res = new PointerMessage(Convert.ToInt32(msg.Split('@')[0]), Convert.ToInt32(msg.Split('@')[1]), (PointerEvent)Enum.Parse(typeof(PointerEvent), msg.Split('@')[2])); + HandleMessage(res); + if (DataReceived != null) + { + DataReceived(this, new DataEventArgs(msg)); + } + } + } + private void HandleMessage(PointerMessage res) + { + switch (res.Message) + { + case PointerEvent.MouseMove: + SetCursorPos(res.X, res.Y); + break; + case PointerEvent.MouseDown: + mouse_event(MOUSEEVENTF_LEFTDOWN, res.X, res.Y, 0, 0); + break; + case PointerEvent.MouseUp: + mouse_event(MOUSEEVENTF_LEFTUP, res.X, res.Y, 0, 0); + break; + } + } + + + public string Name { get; set; } + public Guid Id { get; set; } + + public void Send(string message) + { + _mSocket.Send(message); + } + + public event DataReceivedHandler DataReceived; + public event System.EventHandler Started; + public event System.EventHandler Stopped; + + } + + public class PointerMessage + { + public int X { get; set; } + public int Y { get; set; } + public PointerEvent Message { get; set; } + + public PointerMessage(int x, int y, PointerEvent msg) + { + X = x; + Y = y; + Message = msg; + } + public override string ToString() + { + return X + "@" + Y + "@" + Message; + } + } + + public enum PointerRole + { + Controller, + Slave, + Both + } + + public enum PointerEvent + { + MouseMove, + MouseUp, + MouseDown, + TouchUp, + TouchDown + } + + +} diff --git a/NooSphere/ActivityTablet/Xaml/Tablet.xaml.cs b/NooSphere/ActivityTablet/Xaml/Tablet.xaml.cs index be26ce9..b4ff0f7 100644 --- a/NooSphere/ActivityTablet/Xaml/Tablet.xaml.cs +++ b/NooSphere/ActivityTablet/Xaml/Tablet.xaml.cs @@ -19,6 +19,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; +using ActivityTablet.Context; using NooSphere.ActivitySystem.Base; using NooSphere.ActivitySystem.Base.Client; using NooSphere.ActivitySystem.Base.Service; @@ -191,6 +192,9 @@ private void StartClient(string addr) _client.ConnectionEstablished += ClientConnectionEstablished; _client.FileAdded += ClientFileAdded; _client.ActivitySwitched += ClientActivitySwitched; + + _client.ContextMonitor.AddContextService(new InputRedirect(PointerRole.Controller)); + _client.Open(addr); } catch (Exception ex) @@ -199,6 +203,7 @@ private void StartClient(string addr) MessageBox.Show(ex.ToString()); } } + private void PopulateResource(Activity activity) { @@ -312,6 +317,7 @@ private void ClientMessageReceived(object sender, ComEventArgs e) } private void ClientConnectionEstablished(object sender, EventArgs e) { + _client.ContextMonitor.Start(); BuildUI(); } private void BtnQuitClick(object sender, RoutedEventArgs e) diff --git a/NooSphere/NooSphere.ActivitySystem/Base/Client/ActivityClient.cs b/NooSphere/NooSphere.ActivitySystem/Base/Client/ActivityClient.cs index 799da10..c6ed502 100644 --- a/NooSphere/NooSphere.ActivitySystem/Base/Client/ActivityClient.cs +++ b/NooSphere/NooSphere.ActivitySystem/Base/Client/ActivityClient.cs @@ -27,6 +27,7 @@ #if !ANDROID using NooSphere.ActivitySystem.Host; using System.Net; +using NooSphere.ActivitySystem.Context; #endif namespace NooSphere.ActivitySystem.Base.Client @@ -62,6 +63,7 @@ public class ActivityClient : NetEventHandler,IActivityNode public User CurrentUser { get; set; } public string LocalPath { get { return _fileStore.BasePath; } } public Dictionary DeviceList { get; set; } + public ContextMonitor ContextMonitor { get; set; } #endregion @@ -76,8 +78,11 @@ public ActivityClient(string localFileDirectory,Device d) { InitializeFileService(localFileDirectory); Device = d; + ContextMonitor = new ContextMonitor(); + OnInitializedEvent(new EventArgs()); + ActivityChanged += ActivityClientActivityChanged; ActivityRemoved += ActivityClientActivityRemoved; } diff --git a/NooSphere/NooSphere.ActivitySystem/Context/IO/PointerNode.cs b/NooSphere/NooSphere.ActivitySystem/Context/IO/PointerNode.cs deleted file mode 100644 index 9ca8b2c..0000000 --- a/NooSphere/NooSphere.ActivitySystem/Context/IO/PointerNode.cs +++ /dev/null @@ -1,185 +0,0 @@ - -///**************************************************************************** -// (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk) - -// Pervasive Interaction Technology Laboratory (pIT lab) -// IT University of Copenhagen - -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later, -// as published by the Free Software Foundation. Check -// http://www.gnu.org/licenses/gpl.html for details. -//****************************************************************************/ - -//using System; -//using System.Drawing; -//using System.Runtime.InteropServices; -//using System.Windows.Forms; -//using NooSphere.ActivitySystem.Context; -//using NooSphere.Context.Multicast; -//using NooSphere.Platform.Windows.Hooks; - -//namespace NooSphere.Context.IO -//{ -// public class PointerNode : IContextService -// { -// private MulticastSocket _mSocket; - -// public PointerRole PointerRole { get; private set; } - -// public PointerNode(PointerRole role) -// { -// PointerRole = role; - -// } -// public void Start() -// { -// _mSocket = new MulticastSocket("225.5.6.7", 5000, 10); -// _mSocket.OnNotifyMulticastSocketListener += _mSocket_OnNotifyMulticastSocketListener; -// Initialize(PointerRole); -// } - -// public void Stop() -// { -// MouseHook.UnRegister(); -// } -// private void Initialize(PointerRole role) -// { -// switch (role) -// { -// case PointerRole.Controller: -// MouseHook.Register(); -// MouseHook.MouseDown += new MouseEventHandler(MouseHookMouseDown); -// MouseHook.MouseMove += new MouseEventHandler(MouseHookMouseMove); -// MouseHook.MouseUp += new MouseEventHandler(MouseHookMouseUp); -// break; -// case PointerRole.Slave: -// MouseHook.MouseDown += new MouseEventHandler(MouseHookMouseDown); -// MouseHook.MouseMove += new MouseEventHandler(MouseHookMouseMove); -// MouseHook.MouseUp += new MouseEventHandler(MouseHookMouseUp); -// _mSocket.StartReceiving(); -// break; -// } -// } - -// private Point _previousPoint; -// private bool _unInitializedMouse = true; -// private void MouseHookMouseUp(object sender, MouseEventArgs e) -// { -// if (PointerRole == PointerRole.Controller) -// Send(new PointerMessage(e.X, e.Y, PointerEvent.Up).ToString()); -// } -// private void MouseHookMouseMove(object sender, MouseEventArgs e) -// { -// if (_unInitializedMouse) -// { -// _previousPoint = e.Location; -// _unInitializedMouse = false; -// } -// var xDif = _previousPoint.X - e.Location.X; -// var yDif = _previousPoint.Y - e.Location.Y; -// Console.WriteLine(xDif + "---" + yDif); - -// if (PointerRole == PointerRole.Controller) -// Send(new PointerMessage(_previousPoint.X + xDif, _previousPoint.Y + yDif, PointerEvent.Move).ToString()); -// _previousPoint = e.Location; -// } -// private void MouseHookMouseDown(object sender, MouseEventArgs e) -// { -// if (PointerRole == PointerRole.Controller) -// Send(new PointerMessage(e.X, e.Y, PointerEvent.Down).ToString()); -// } - -// [DllImport("User32.dll")] -// private static extern bool SetCursorPos(int x, int y); -// [DllImport("user32.dll")] -// public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); - -// public const int MOUSEEVENTF_LEFTDOWN = 0x02; -// public const int MOUSEEVENTF_LEFTUP = 0x04; -// public const int MOUSEEVENTF_RIGHTDOWN = 0x08; -// public const int MOUSEEVENTF_RIGHTUP = 0x10; -// private void _mSocket_OnNotifyMulticastSocketListener(object sender, NotifyMulticastSocketListenerEventArgs e) -// { -// if (e.Type == MulticastSocketMessageType.MessageReceived) -// { -// var msg = System.Text.Encoding.ASCII.GetString((byte[])e.NewObject); - -// var res = new PointerMessage(Convert.ToInt32(msg.Split('@')[0]), Convert.ToInt32(msg.Split('@')[1]), (PointerEvent)Enum.Parse(typeof(PointerEvent), msg.Split('@')[2])); - - - -// HandleMessage(res); -// if (DataReceived != null) -// { -// DataReceived(this, new DataEventArgs(msg)); -// } -// } -// } - -// private void HandleMessage(PointerMessage res) -// { -// switch (res.Message) -// { -// case PointerEvent.Move: -// SetCursorPos(res.X, res.Y); -// break; -// case PointerEvent.Down: -// mouse_event(MOUSEEVENTF_LEFTDOWN, res.X, res.Y, 0, 0); -// break; -// case PointerEvent.Up: -// mouse_event(MOUSEEVENTF_LEFTUP, res.X, res.Y, 0, 0); -// break; -// } -// } - - -// public string Name { get; set; } - -// public void Send(string message) -// { -// _mSocket.Send(message); -// } - -// public event DataReceivedHandler DataReceived; -// public event System.EventHandler Started; -// public event System.EventHandler Stopped; - -// } - -// public class PointerMessage -// { -// public int X { get; set; } -// public int Y { get; set; } -// public PointerEvent Message { get; set; } - -// public PointerMessage(int x, int y, PointerEvent msg) -// { -// X = x; -// Y = y; -// Message = msg; -// } -// public override string ToString() -// { -// return X + "@" + Y + "@" + Message; -// } -// } - -// public enum PointerRole -// { -// Controller, -// Slave, -// Both -// } - -// public enum PointerEvent -// { -// MouseMove, -// MouseUp, -// MouseDown, -// TouchUp, -// TouchDown -// } - - -//} diff --git a/NooSphere/NooSphere.ActivitySystem/NooSphere.ActivitySystem.csproj b/NooSphere/NooSphere.ActivitySystem/NooSphere.ActivitySystem.csproj index 61d3794..96e6146 100644 --- a/NooSphere/NooSphere.ActivitySystem/NooSphere.ActivitySystem.csproj +++ b/NooSphere/NooSphere.ActivitySystem/NooSphere.ActivitySystem.csproj @@ -80,7 +80,6 @@ - diff --git a/NooSphere/NooSphere.ActivitySystem/PubSub/RestPublisher.cs b/NooSphere/NooSphere.ActivitySystem/PubSub/RestPublisher.cs index e213252..694e9a6 100644 --- a/NooSphere/NooSphere.ActivitySystem/PubSub/RestPublisher.cs +++ b/NooSphere/NooSphere.ActivitySystem/PubSub/RestPublisher.cs @@ -1,73 +1,76 @@ -/**************************************************************************** - (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk) - - Pervasive Interaction Technology Laboratory (pIT lab) - IT University of Copenhagen - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later, - as published by the Free Software Foundation. Check - http://www.gnu.org/licenses/gpl.html for details. -****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using NooSphere.ActivitySystem.Helpers; - -namespace NooSphere.ActivitySystem.PubSub -{ - public class RestPublisher - { - /// - /// Publishes an event to all suscribers - /// - /// - /// The object that needs to be published - /// The source that whishes to publish - /// Enables or disable self-publishing to source - public void Publish(string publishUrl, object netObject, object source = null, bool sendToSource = false) - { - //Log.Out("Publisher", string.Format("Published {0}",publishUrl), LogCode.Net); - var toRemove = new List(); - - var devices = Registry.ConnectedClients.Values.ToList(); - for (int i = 0; i < devices.Count;i++ ) - { - try - { - var addr = devices[i].Device.BaseAddress; - Task.Factory.StartNew( - delegate - { - Rest.Post(addr + publishUrl, netObject); - Log.Out("Publisher", - string.Format("Published {0} to {1}", publishUrl, addr), - LogCode.Net); - }); - } - catch (Exception) - { - - } - } - } - - /// - /// Publish event to one subscriber - /// - /// - /// - /// - public void PublishToSubscriber(string publishUrl, object netObject,object subscriber) - { - Task.Factory.StartNew( - delegate - { - Rest.Post(subscriber + publishUrl, netObject); - Log.Out("Publisher", string.Format("Publishing {0} to {1}", publishUrl, subscriber), LogCode.Net); - }); - } - } -} +/**************************************************************************** + (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk) + + Pervasive Interaction Technology Laboratory (pIT lab) + IT University of Copenhagen + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later, + as published by the Free Software Foundation. Check + http://www.gnu.org/licenses/gpl.html for details. +****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NooSphere.ActivitySystem.Helpers; +using NooSphere.ActivitySystem.Base.Service; + +namespace NooSphere.ActivitySystem.PubSub +{ + public class RestPublisher + { + /// + /// Publishes an event to all suscribers + /// + /// + /// The object that needs to be published + /// The source that whishes to publish + /// Enables or disable self-publishing to source + public void Publish(string publishUrl, object netObject, object source = null, bool sendToSource = false) + { + //Log.Out("Publisher", string.Format("Published {0}",publishUrl), LogCode.Net); + var toRemove = new List(); + + var devices = Registry.ConnectedClients; + for (var i = 0; i < devices.Count;i++ ) + { + var addr = devices.Values.ToList()[i].Device.BaseAddress; + try + { + Task.Factory.StartNew( + delegate + { + Rest.Post(addr + publishUrl, netObject); + Log.Out("Publisher", + string.Format("Published {0} to {1}", publishUrl, addr), + LogCode.Net); + }); + } + catch (Exception) + { + toRemove.Add(devices.Keys.ToList()[i]); + } + } + foreach (var addr in toRemove) + Registry.ConnectedClients.Remove(addr); + } + + /// + /// Publish event to one subscriber + /// + /// + /// + /// + public void PublishToSubscriber(string publishUrl, object netObject,object subscriber) + { + Task.Factory.StartNew( + delegate + { + Rest.Post(subscriber + publishUrl, netObject); + Log.Out("Publisher", string.Format("Publishing {0} to {1}", publishUrl, subscriber), LogCode.Net); + }); + } + } +}