add ability to check supported status

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-07-14 02:01:24 +03:00
parent cc43ee4e06
commit f6acfdfdad
13 changed files with 157 additions and 6 deletions

View File

@ -83,6 +83,7 @@ type Encoding interface {
Type() EncodingType
Read(Conn, *Rectangle) error
Write(Conn, *Rectangle) error
Supported(Conn) bool
}
func setBit(n uint8, pos uint8) uint8 {

View File

@ -28,6 +28,10 @@ type AtenHermonSubrect struct {
Data []byte
}
func (*AtenHermon) Supported(Conn) bool {
return false
}
func (*AtenHermon) Type() EncodingType { return EncAtenHermon }
func (enc *AtenHermon) Read(c Conn, rect *Rectangle) error {
@ -113,6 +117,14 @@ func (enc *AtenHermon) Read(c Conn, rect *Rectangle) error {
}
func (enc *AtenHermon) Write(c Conn, rect *Rectangle) error {
if !enc.Supported(c) {
for _, ew := range enc.Encodings {
if err := ew.Write(c, rect); err != nil {
return err
}
}
return nil
}
var pad4 [4]byte
if err := binary.Write(c, binary.BigEndian, pad4); err != nil {
@ -148,6 +160,10 @@ func (enc *AtenHermon) Write(c Conn, rect *Rectangle) error {
return nil
}
func (*AtenHermonSubrect) Supported(Conn) bool {
return false
}
func (enc *AtenHermonSubrect) Type() EncodingType {
return EncAtenHermonSubrect
}
@ -173,6 +189,9 @@ func (enc *AtenHermonSubrect) Read(c Conn, rect *Rectangle) error {
}
func (enc *AtenHermonSubrect) Write(c Conn, rect *Rectangle) error {
if !enc.Supported(c) {
return nil
}
if err := binary.Write(c, binary.BigEndian, enc.A); err != nil {
return err
}

View File

@ -6,7 +6,11 @@ type CopyRectEncoding struct {
SX, SY uint16
}
func (CopyRectEncoding) Type() EncodingType { return EncCopyRect }
func (*CopyRectEncoding) Supported(Conn) bool {
return true
}
func (*CopyRectEncoding) Type() EncodingType { return EncCopyRect }
func (enc *CopyRectEncoding) Read(c Conn, rect *Rectangle) error {
if err := binary.Read(c, binary.BigEndian, &enc.SX); err != nil {

View File

@ -7,6 +7,10 @@ type CursorPseudoEncoding struct {
BitMask []byte
}
func (*CursorPseudoEncoding) Supported(Conn) bool {
return true
}
func (*CursorPseudoEncoding) Type() EncodingType { return EncCursorPseudo }
func (enc *CursorPseudoEncoding) Read(c Conn, rect *Rectangle) error {

View File

@ -7,6 +7,10 @@ type DesktopNamePseudoEncoding struct {
Name []byte
}
func (*DesktopNamePseudoEncoding) Supported(Conn) bool {
return true
}
func (*DesktopNamePseudoEncoding) Type() EncodingType { return EncDesktopNamePseudo }
// Read implements the Encoding interface.

View File

@ -3,6 +3,10 @@ package vnc
// DesktopSizePseudoEncoding represents a desktop size message from the server.
type DesktopSizePseudoEncoding struct{}
func (*DesktopSizePseudoEncoding) Supported(Conn) bool {
return true
}
func (*DesktopSizePseudoEncoding) Type() EncodingType { return EncDesktopSizePseudo }
// Read implements the Encoding interface.

View File

@ -4,6 +4,10 @@ type RawEncoding struct {
Colors []Color
}
func (*RawEncoding) Supported(Conn) bool {
return true
}
func (enc *RawEncoding) Write(c Conn, rect *Rectangle) error {
var err error

View File

@ -28,6 +28,10 @@ const (
type TightEncoding struct{}
func (*TightEncoding) Supported(Conn) bool {
return true
}
func (*TightEncoding) Type() EncodingType { return EncTight }
func (enc *TightEncoding) Write(c Conn, rect *Rectangle) error {

View File

@ -11,6 +11,10 @@ import (
"io"
)
func (*TightPngEncoding) Supported(Conn) bool {
return true
}
func (enc *TightPngEncoding) Write(c Conn, rect *Rectangle) error {
if err := writeTightCC(c, enc.TightCC); err != nil {
return err

View File

@ -16,6 +16,10 @@ type XCursorPseudoEncoding struct {
Bitmask []byte
}
func (*XCursorPseudoEncoding) Supported(Conn) bool {
return true
}
func (*XCursorPseudoEncoding) Type() EncodingType { return EncXCursorPseudo }
// Read implements the Encoding interface.

View File

@ -50,15 +50,16 @@ func NewRectangle() *Rectangle {
// Write marshal color to conn
func (clr *Color) Write(c Conn) error {
var err error
order := clr.pf.order()
pf := c.PixelFormat()
order := pf.order()
pixel := clr.cmIndex
if clr.pf.TrueColor != 0 {
pixel = uint32(clr.R) << clr.pf.RedShift
pixel |= uint32(clr.G) << clr.pf.GreenShift
pixel |= uint32(clr.B) << clr.pf.BlueShift
pixel = uint32(clr.R) << pf.RedShift
pixel |= uint32(clr.G) << pf.GreenShift
pixel |= uint32(clr.B) << pf.BlueShift
}
switch clr.pf.BPP {
switch pf.BPP {
case 8:
err = binary.Write(c, order, byte(pixel))
case 16:

View File

@ -70,6 +70,7 @@ type ClientMessage interface {
Type() ClientMessageType
Read(Conn) (ClientMessage, error)
Write(Conn) error
Supported(Conn) bool
}
type ServerMessage interface {
@ -77,6 +78,7 @@ type ServerMessage interface {
Type() ServerMessageType
Read(Conn) (ServerMessage, error)
Write(Conn) error
Supported(Conn) bool
}
// FramebufferUpdate holds a FramebufferUpdate wire format message.
@ -91,6 +93,10 @@ func (msg *FramebufferUpdate) String() string {
return fmt.Sprintf("rects %d rectangle[]: { %v }", msg.NumRect, msg.Rects)
}
func (msg *FramebufferUpdate) Supported(c Conn) bool {
return true
}
// Type return MessageType
func (*FramebufferUpdate) Type() ServerMessageType {
return FramebufferUpdateMsgType
@ -144,6 +150,10 @@ type ServerCutText struct {
Text []byte
}
func (msg *ServerCutText) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *ServerCutText) String() string {
return fmt.Sprintf("lenght: %d text: %s", msg.Length, msg.Text)
@ -200,6 +210,10 @@ func (msg *ServerCutText) Write(c Conn) error {
// Bell server message
type Bell struct{}
func (*Bell) Supported(c Conn) bool {
return true
}
// String return string
func (*Bell) String() string {
return fmt.Sprintf("bell")
@ -231,6 +245,10 @@ type SetColorMapEntries struct {
Colors []Color
}
func (msg *SetColorMapEntries) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *SetColorMapEntries) String() string {
return fmt.Sprintf("first color: %d, numcolors: %d, colors[]: { %v }", msg.FirstColor, msg.ColorsNum, msg.Colors)
@ -308,6 +326,10 @@ type SetPixelFormat struct {
PF PixelFormat // pixel-format
}
func (msg *SetPixelFormat) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *SetPixelFormat) String() string {
return fmt.Sprintf("%s", msg.PF)
@ -353,6 +375,10 @@ type SetEncodings struct {
Encodings []EncodingType
}
func (msg *SetEncodings) Supported(c Conn) bool {
return true
}
// String return string
func (msg *SetEncodings) String() string {
return fmt.Sprintf("encnum: %d, encodings[]: { %v }", msg.EncNum, msg.Encodings)
@ -417,6 +443,10 @@ type FramebufferUpdateRequest struct {
Width, Height uint16 // width, height
}
func (msg *FramebufferUpdateRequest) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *FramebufferUpdateRequest) String() string {
return fmt.Sprintf("incremental: %d, x: %d, y: %d, width: %d, height: %d", msg.Inc, msg.X, msg.Y, msg.Width, msg.Height)
@ -454,6 +484,10 @@ type KeyEvent struct {
Key Key // key
}
func (msg *KeyEvent) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *KeyEvent) String() string {
return fmt.Sprintf("down: %d, key: %v", msg.Down, msg.Key)
@ -490,6 +524,10 @@ type PointerEvent struct {
X, Y uint16 // x-, y-position
}
func (msg *PointerEvent) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *PointerEvent) String() string {
return fmt.Sprintf("mask %d, x: %d, y: %d", msg.Mask, msg.X, msg.Y)
@ -527,6 +565,10 @@ type ClientCutText struct {
Text []byte
}
func (msg *ClientCutText) Supported(c Conn) bool {
return true
}
// String returns string
func (msg *ClientCutText) String() string {
return fmt.Sprintf("length: %d, text: %s", msg.Length, msg.Text)

View File

@ -39,6 +39,10 @@ type AteniKVMPointerEvent struct {
_ [11]byte // padding
}
func (msg *AteniKVMPointerEvent) Supported(c Conn) bool {
return false
}
func (msg *AteniKVMPointerEvent) String() string {
return fmt.Sprintf("mask: %d, x:%d, y:%d", msg.Mask, msg.X, msg.Y)
}
@ -56,6 +60,9 @@ func (*AteniKVMPointerEvent) Read(c Conn) (ClientMessage, error) {
}
func (msg *AteniKVMPointerEvent) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
}
@ -65,6 +72,10 @@ func (msg *AteniKVMPointerEvent) Write(c Conn) error {
return c.Flush()
}
func (msg *AteniKVMKeyEvent) Supported(c Conn) bool {
return false
}
func (msg *AteniKVMKeyEvent) String() string {
return fmt.Sprintf("down:%d, key:%s", msg.Down, msg.Key)
}
@ -82,6 +93,9 @@ func (*AteniKVMKeyEvent) Read(c Conn) (ClientMessage, error) {
}
func (msg *AteniKVMKeyEvent) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
}
@ -96,6 +110,10 @@ type AteniKVMFrontGroundEvent struct {
_ [20]byte
}
func (msg *AteniKVMFrontGroundEvent) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMFrontGroundEvent) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -118,6 +136,9 @@ func (*AteniKVMFrontGroundEvent) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMFrontGroundEvent) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [20]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
@ -133,6 +154,10 @@ type AteniKVMKeepAliveEvent struct {
_ [1]byte
}
func (msg *AteniKVMKeepAliveEvent) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMKeepAliveEvent) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -155,6 +180,9 @@ func (*AteniKVMKeepAliveEvent) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMKeepAliveEvent) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [1]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
@ -170,6 +198,10 @@ type AteniKVMVideoGetInfo struct {
_ [20]byte
}
func (msg *AteniKVMVideoGetInfo) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMVideoGetInfo) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -192,6 +224,9 @@ func (*AteniKVMVideoGetInfo) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMVideoGetInfo) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [4]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
@ -207,6 +242,10 @@ type AteniKVMMouseGetInfo struct {
_ [2]byte
}
func (msg *AteniKVMMouseGetInfo) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMMouseGetInfo) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -229,6 +268,9 @@ func (*AteniKVMMouseGetInfo) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMMouseGetInfo) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [2]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
@ -244,6 +286,10 @@ type AteniKVMSessionMessage struct {
_ [264]byte
}
func (msg *AteniKVMSessionMessage) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMSessionMessage) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -266,6 +312,9 @@ func (*AteniKVMSessionMessage) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMSessionMessage) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [264]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
@ -281,6 +330,10 @@ type AteniKVMGetViewerLang struct {
_ [8]byte
}
func (msg *AteniKVMGetViewerLang) Supported(c Conn) bool {
return false
}
// String return string representation
func (msg *AteniKVMGetViewerLang) String() string {
return fmt.Sprintf("%s", msg.Type())
@ -303,6 +356,9 @@ func (*AteniKVMGetViewerLang) Read(c Conn) (ServerMessage, error) {
// Write marshal message to conn
func (msg *AteniKVMGetViewerLang) Write(c Conn) error {
if !msg.Supported(c) {
return nil
}
var pad [8]byte
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err