mirror of
https://github.com/wavetermdev/backup.git
synced 2026-04-22 15:26:58 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 523eafd85a | |||
| fe3ffd1545 |
@@ -72,16 +72,16 @@ func (*ModelUpdatePacketType) GetType() string {
|
||||
return ModelUpdateStr
|
||||
}
|
||||
|
||||
func (mu *ModelUpdatePacketType) IsEmpty() bool {
|
||||
if mu == nil || mu.Data == nil {
|
||||
func (upk *ModelUpdatePacketType) IsEmpty() bool {
|
||||
if upk == nil {
|
||||
return true
|
||||
}
|
||||
return mu.Data.IsEmpty()
|
||||
return upk.Data.IsEmpty()
|
||||
}
|
||||
|
||||
// Clean the ClientData in an update, if present
|
||||
func (upk *ModelUpdatePacketType) Clean() {
|
||||
if upk == nil || upk.Data == nil {
|
||||
if upk.IsEmpty() {
|
||||
return
|
||||
}
|
||||
for _, item := range *(upk.Data) {
|
||||
@@ -106,6 +106,9 @@ func MakeUpdatePacket() *ModelUpdatePacketType {
|
||||
|
||||
// Returns the items in the update that are of type I
|
||||
func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I {
|
||||
if upk.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
ret := make([]*I, 0)
|
||||
for _, item := range *(upk.Data) {
|
||||
if i, ok := (item).(I); ok {
|
||||
@@ -123,4 +126,7 @@ type CleanableUpdateItem interface {
|
||||
func init() {
|
||||
// Register the model update packet type
|
||||
packet.RegisterPacketType(ModelUpdateStr, reflect.TypeOf(ModelUpdatePacketType{}))
|
||||
|
||||
// Enforce the UpdatePacket interface
|
||||
var _ UpdatePacket = (*ModelUpdatePacketType)(nil)
|
||||
}
|
||||
|
||||
@@ -47,4 +47,7 @@ func MakePtyDataUpdate(update *PtyDataUpdate) *PtyDataUpdatePacketType {
|
||||
func init() {
|
||||
// Register the PtyDataUpdatePacketType with the packet package
|
||||
packet.RegisterPacketType(PtyDataUpdateStr, reflect.TypeOf(PtyDataUpdatePacketType{}))
|
||||
|
||||
// Enforce the UpdatePacket interface
|
||||
var _ UpdatePacket = (*PtyDataUpdatePacketType)(nil)
|
||||
}
|
||||
|
||||
@@ -67,6 +67,9 @@ type UpdatePacket interface {
|
||||
IsEmpty() bool
|
||||
}
|
||||
|
||||
// Enforce that UpdatePacket is a packet.PacketType
|
||||
var _ packet.PacketType = (UpdatePacket)(nil)
|
||||
|
||||
// A channel for sending model updates to the client
|
||||
type UpdateChannel struct {
|
||||
ScreenId string
|
||||
@@ -89,6 +92,9 @@ func (sch *UpdateChannel) Match(screenId string) bool {
|
||||
return screenId == sch.ScreenId
|
||||
}
|
||||
|
||||
// Enforce that UpdateChannel is a Channel
|
||||
var _ Channel[UpdatePacket] = (*UpdateChannel)(nil)
|
||||
|
||||
// A collection of channels that can transmit updates
|
||||
type UpdateBus struct {
|
||||
Bus[UpdatePacket]
|
||||
@@ -110,7 +116,7 @@ func MakeUpdateBus() *UpdateBus {
|
||||
|
||||
// Send an update to all channels in the collection
|
||||
func (bus *UpdateBus) DoUpdate(update UpdatePacket) {
|
||||
if update == nil || update.IsEmpty() {
|
||||
if update.IsEmpty() {
|
||||
return
|
||||
}
|
||||
update.Clean()
|
||||
@@ -128,7 +134,7 @@ func (bus *UpdateBus) DoUpdate(update UpdatePacket) {
|
||||
|
||||
// Send a model update to only clients that are subscribed to the given screenId
|
||||
func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket) {
|
||||
if update == nil {
|
||||
if update.IsEmpty() {
|
||||
return
|
||||
}
|
||||
update.Clean()
|
||||
@@ -206,6 +212,9 @@ func (ch *RpcChannel) Match(string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Enforce that RpcChannel is a Channel
|
||||
var _ Channel[RpcResponse] = (*RpcChannel)(nil)
|
||||
|
||||
// Send a user input request to the frontend and wait for a response
|
||||
func (bus *RpcBus) DoRpc(ctx context.Context, pk RpcPacket) (RpcResponse, error) {
|
||||
id := uuid.New().String()
|
||||
|
||||
@@ -74,4 +74,8 @@ func GetUserInput(ctx context.Context, bus *scbus.RpcBus, userInputRequest *User
|
||||
func init() {
|
||||
// Register the user input request packet type
|
||||
packet.RegisterPacketType(UserInputResponsePacketStr, reflect.TypeOf(UserInputResponsePacketType{}))
|
||||
|
||||
// Enforce the interfaces
|
||||
var _ scbus.RpcResponse = (*UserInputResponsePacketType)(nil)
|
||||
var _ scbus.RpcPacket = (*UserInputRequestType)(nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user