Skip to content

Commit f8509d2

Browse files
💾 Feat(DeviceService): 添加设备登录状态检查、获取设备令牌及已登录设备列表功能;新增 ServerStatus 枚举
💾 Feat(Plugin): 新增插件连接接口及相关事件,支持插件连接状态管理和消息处理
1 parent 6cf48eb commit f8509d2

6 files changed

Lines changed: 148 additions & 2 deletions

File tree

KitX Core Contracts/KitX.Core.Contract/Device/IDeviceService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ public interface IDeviceServer
126126
/// Stops the device server
127127
/// </summary>
128128
void Stop();
129+
130+
/// <summary>
131+
/// Checks if a device is signed in
132+
/// </summary>
133+
/// <param name="locator">The device locator</param>
134+
/// <returns>True if the device is signed in</returns>
135+
bool IsDeviceSignedIn(KitX.Shared.CSharp.Device.DeviceLocator locator);
136+
137+
/// <summary>
138+
/// Gets the signed device token for a device locator
139+
/// </summary>
140+
/// <param name="locator">The device locator</param>
141+
/// <returns>The token or null if not found</returns>
142+
string? GetDeviceToken(KitX.Shared.CSharp.Device.DeviceLocator locator);
143+
144+
/// <summary>
145+
/// Gets all signed-in device locators
146+
/// </summary>
147+
/// <returns>Read-only list of signed-in device locators</returns>
148+
System.Collections.Generic.IReadOnlyList<KitX.Shared.CSharp.Device.DeviceLocator> GetSignedInDevices();
129149
}
130150

131151
/// <summary>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace KitX.Core.Contract.Device;
2+
3+
/// <summary>
4+
/// Server status enumeration
5+
/// </summary>
6+
public enum ServerStatus
7+
{
8+
Pending,
9+
Starting,
10+
Running,
11+
Stopping,
12+
Errored
13+
}

KitX Core Contracts/KitX.Core.Contract/Plugin/Events/PluginEventArgs.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,42 @@ public class PluginUnregisteredEventArgs : EventArgs
8181
/// Gets or sets the plugin info
8282
/// </summary>
8383
public PluginInfo? PluginInfo { get; set; }
84+
}
85+
86+
/// <summary>
87+
/// Plugin connected event arguments
88+
/// </summary>
89+
public class PluginConnectedEventArgs : EventArgs
90+
{
91+
/// <summary>
92+
/// Gets or sets the connection ID
93+
/// </summary>
94+
public string? ConnectionId { get; set; }
95+
}
96+
97+
/// <summary>
98+
/// Plugin disconnected event arguments
99+
/// </summary>
100+
public class PluginDisconnectedEventArgs : EventArgs
101+
{
102+
/// <summary>
103+
/// Gets or sets the connection ID
104+
/// </summary>
105+
public string? ConnectionId { get; set; }
106+
}
107+
108+
/// <summary>
109+
/// Plugin message received event arguments
110+
/// </summary>
111+
public class PluginMessageReceivedEventArgs : EventArgs
112+
{
113+
/// <summary>
114+
/// Gets or sets the connection ID
115+
/// </summary>
116+
public string? ConnectionId { get; set; }
117+
118+
/// <summary>
119+
/// Gets or sets the message
120+
/// </summary>
121+
public string? Message { get; set; }
84122
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using KitX.Shared.CSharp.Plugin;
3+
using KitX.Core.Contract.Device;
4+
using CTask = System.Threading.Tasks.Task;
5+
6+
namespace KitX.Core.Contract.Plugin;
7+
8+
/// <summary>
9+
/// Plugin connection interface
10+
/// </summary>
11+
public interface IPluginConnection : IPluginConnector
12+
{
13+
/// <summary>
14+
/// Gets or sets the plugin info
15+
/// </summary>
16+
new PluginInfo? PluginInfo { get; set; }
17+
18+
/// <summary>
19+
/// Gets the connection status
20+
/// </summary>
21+
ServerStatus Status { get; }
22+
23+
/// <summary>
24+
/// Event raised when a message is received
25+
/// </summary>
26+
event EventHandler<string>? MessageReceived;
27+
28+
/// <summary>
29+
/// Event raised when connection is closed
30+
/// </summary>
31+
event EventHandler? Closed;
32+
33+
/// <summary>
34+
/// Initializes the connection
35+
/// </summary>
36+
void Initialize();
37+
38+
/// <summary>
39+
/// Sends a message
40+
/// </summary>
41+
/// <param name="message">The message to send</param>
42+
void Send(string message);
43+
44+
/// <summary>
45+
/// Closes the connection
46+
/// </summary>
47+
CTask CloseAsync();
48+
}

KitX Core Contracts/KitX.Core.Contract/Plugin/IPluginConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IPluginConnector
1212
/// <summary>
1313
/// Gets the connection ID
1414
/// </summary>
15-
string ConnectionId { get; }
15+
string? ConnectionId { get; }
1616

1717
/// <summary>
1818
/// Gets the plugin info

KitX Core Contracts/KitX.Core.Contract/Plugin/IPluginServer.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IPluginServer
1818
/// <summary>
1919
/// Gets the list of currently connected plugins
2020
/// </summary>
21-
IReadOnlyList<IPluginConnector> Connections { get; }
21+
IReadOnlyList<IPluginConnection> Connections { get; }
2222

2323
/// <summary>
2424
/// Starts the plugin server
@@ -38,11 +38,33 @@ public interface IPluginServer
3838
/// <returns>The plugin connector or null if not found</returns>
3939
IPluginConnector? FindConnector(PluginInfo pluginInfo);
4040

41+
/// <summary>
42+
/// Finds a connection by connection ID
43+
/// </summary>
44+
/// <param name="connectionId">The connection ID</param>
45+
/// <returns>The plugin connection or null if not found</returns>
46+
IPluginConnection? FindConnection(string connectionId);
47+
4148
/// <summary>
4249
/// Event raised when server port changes
4350
/// </summary>
4451
event EventHandler<int>? PortChanged;
4552

53+
/// <summary>
54+
/// Event raised when a plugin connects
55+
/// </summary>
56+
event EventHandler<PluginConnectedEventArgs>? PluginConnected;
57+
58+
/// <summary>
59+
/// Event raised when a plugin disconnects
60+
/// </summary>
61+
event EventHandler<PluginDisconnectedEventArgs>? PluginDisconnected;
62+
63+
/// <summary>
64+
/// Event raised when a plugin message is received
65+
/// </summary>
66+
event EventHandler<PluginMessageReceivedEventArgs>? PluginMessageReceived;
67+
4668
/// <summary>
4769
/// Event raised when a plugin registers with the server
4870
/// </summary>
@@ -52,4 +74,9 @@ public interface IPluginServer
5274
/// Event raised when a plugin unregisters/disconnects from the server
5375
/// </summary>
5476
event EventHandler<PluginUnregisteredEventArgs>? PluginUnregistered;
77+
78+
/// <summary>
79+
/// Event raised when a plugin sends a response (has RequestId)
80+
/// </summary>
81+
event EventHandler<PluginResponseEventArgs>? PluginResponse;
5582
}

0 commit comments

Comments
 (0)