1 //
2 // Copyright (c) 2010-2022 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using AntShell.Terminal;
9 
10 namespace Antmicro.Renode.Utilities
11 {
12     public class SocketIOSource : IActiveIOSource
13     {
SocketIOSource(int port)14         public SocketIOSource(int port)
15         {
16             server = new SocketServerProvider();
17             server.Start(port);
18         }
19 
Dispose()20         public void Dispose()
21         {
22             server.Stop();
23         }
24 
Flush()25         public void Flush()
26         {
27         }
28 
Pause()29         public void Pause()
30         {
31             // Required by IActiveIOSource interface
32         }
33 
Resume()34         public void Resume()
35         {
36             // Required by IActiveIOSource interface
37         }
38 
Write(byte b)39         public void Write(byte b)
40         {
41             server.SendByte(b);
42         }
43 
44         public event System.Action<int> ByteRead
45         {
46             add { server.DataReceived += value; }
47             remove { server.DataReceived -= value; }
48         }
49 
50         public bool IsAnythingAttached { get { return server.IsAnythingReceiving; } }
51 
52         private readonly SocketServerProvider server;
53     }
54 }
55 
56