Re: [PATCH 2/2] SPICE port basic implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pavel,

The Uint8Array is an event. i don't know if there are more events than port opened or port closed. The value 0 is sent when the port device file is opened in the VM side and the 1 is sent when in the VM side you close device file, so I left it as is because I don't know if there are other possible events that can be handled by the user.

About the format for the data arriving in the port you're right. We can leave it "as-is".

I will change the console messages for printing just the events and that we received data to avoid browser locking. Also will add a DEBUG > 0 && for showing them only when debugging.

Finally I will put the code as a coment then. :)

Thanks. Will send the last commit again in a few.

Cheers!

On Fri, Sep 30, 2016 at 10:51 AM, Pavel Grunt <pgrunt@xxxxxxxxxx> wrote:
Hi Oliver,

I tested it (in FF) and it works nicely, I just have minor comments:
in the console:
SPICE port com.spice.fc.1 event data: Uint8Array { 0=0}
SPICE port com.spice.fc.1 message text: CHILI
SPICE port com.spice.fc.1 event data: Uint8Array { 0=1}

1) what is the Uint8Array - it has just one value (port opened ?), a
boolean could be more clear

2) there is no guarantee that data are text, i think it would be
better to have it as Uint8Array

3) not sure if it is a good idea to print to console by default,
consider someone does:
dd=if=/dev/urandom of=/dev/virtio-ports/port ...
it could block the browser


The code handling the event in the html files could be just an comment
(to server as an example for somebody implementing something on top of
the port channel)

Thanks for the contribution,
Pavel


On Thu, 2016-09-29 at 08:59 +0200, Oliver Gutierrez wrote:
> Here is an small guide to test this for the ones that want to check
> it faster:
>
> Add a spiceport to a virtual machine adding this under devices in
> the XML
>
> <channel type='spiceport'>
>       <source channel='org.freedesktop.FleetCommander.0'/>
>       <target type='virtio'
> name='org.freedesktop.FleetCommander.0'/>
>       <address type='virtio-serial' controller='0' bus='0'
> port='2'/>
>     </channel>
>
>
> Boot machine, Connect to it as usual using spice-html5 and as root:
>
> echo "CHILI" > /dev/virtio-ports/org.freedesktop.FleetCommander.0
>
> In the browser console yo sould see the events for opening the port,
> the message and the port closing.
>
> If in a week or so there is no other feedback then I will contact
> you Jeremy.
>
> Thanks and cheers!
>
> On Wed, Sep 28, 2016 at 10:10 PM, Jeremy White <jwhite@codeweavers.c
> om> wrote:
> > Looks good to me.  I don't have the time to test this myself, so
> > I'll
> > leave this open for others to kibitz for now.
> >
> > I don't think it will do harm, so if no one else expresses an
> > opinion
> > after a while, you can probably nudge me into pushing it.
> >
> > Reviewed-by: Jeremy White <jwhite@xxxxxxxxxxxxxxx>
> >
> > Cheers,
> >
> > Jeremy
> >
> > On 09/27/2016 10:29 AM, Oliver Gutierrez wrote:
> > > ---
> > >  enums.js        |  9 ++++++
> > >  main.js         |  3 ++
> > >  port.js         | 85
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  spice.html      | 10 +++++++
> > >  spice_auto.html | 10 +++++++
> > >  spicemsg.js     | 18 ++++++++++++
> > >  utils.js        |  7 +++++
> > >  7 files changed, 142 insertions(+)
> > >  create mode 100644 port.js
> > >
> > > diff --git a/enums.js b/enums.js
> > > index 301fea0..b6e013c 100644
> > > --- a/enums.js
> > > +++ b/enums.js
> > > @@ -166,6 +166,15 @@ var SPICE_MSG_PLAYBACK_VOLUME           =
> > 105;
> > >  var SPICE_MSG_PLAYBACK_MUTE             = 106;
> > >  var SPICE_MSG_PLAYBACK_LATENCY          = 107;
> > >
> > > +var SPICE_MSG_SPICEVMC_DATA             = 101;
> > > +var SPICE_MSG_PORT_INIT                 = 201;
> > > +var SPICE_MSG_PORT_EVENT                = 202;
> > > +var SPICE_MSG_END_PORT                  = 203;
> > > +
> > > +var SPICE_MSGC_SPICEVMC_DATA            = 101;
> > > +var SPICE_MSGC_PORT_EVENT               = 201;
> > > +var SPICE_MSGC_END_PORT                 = 202;
> > > +
> > >  var SPICE_PLAYBACK_CAP_CELT_0_5_1       = 0;
> > >  var SPICE_PLAYBACK_CAP_VOLUME           = 1;
> > >  var SPICE_PLAYBACK_CAP_LATENCY          = 2;
> > > diff --git a/main.js b/main.js
> > > index 874a038..2d8a1ff 100644
> > > --- a/main.js
> > > +++ b/main.js
> > > @@ -59,6 +59,7 @@ function SpiceMainConn()
> > >      this.file_xfer_tasks = {};
> > >      this.file_xfer_task_id = 0;
> > >      this.file_xfer_read_queue = [];
> > > +    this.ports = [];
> > >  }
> > >
> > >  SpiceMainConn.prototype = Object.create(SpiceConn.prototype);
> > > @@ -154,6 +155,8 @@
> > SpiceMainConn.prototype.process_channel_message = function(msg)
> > >                  this.cursor = new SpiceCursorConn(conn);
> > >              else if (chans.channels[i].type ==
> > SPICE_CHANNEL_PLAYBACK)
> > >                  this.cursor = new SpicePlaybackConn(conn);
> > > +            else if (chans.channels[i].type ==
> > SPICE_CHANNEL_PORT)
> > > +                this.ports.push(new SpicePortConn(conn));
> > >              else
> > >              {
> > >                  if (! ("extra_channels" in this))
> > > diff --git a/port.js b/port.js
> > > new file mode 100644
> > > index 0000000..ee22073
> > > --- /dev/null
> > > +++ b/port.js
> > > @@ -0,0 +1,85 @@
> > > +"use strict";
> > > +/*
> > > +   Copyright (C) 2016 by Oliver Gutierrez <ogutsua@xxxxxxxxx>
> > > +                         Miroslav Chodil <mchodil@xxxxxxxxxx>
> > > +
> > > +   This file is part of spice-html5.
> > > +
> > > +   spice-html5 is free software: you can redistribute it and/or
> > modify
> > > +   it under the terms of the GNU Lesser General Public License
> > as published by
> > > +   the Free Software Foundation, either version 3 of the
> > License, or
> > > +   (at your option) any later version.
> > > +
> > > +   spice-html5 is distributed in the hope that it will be
> > useful,
> > > +   but WITHOUT ANY WARRANTY; without even the implied warranty
> > of
> > > +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> > the
> > > +   GNU Lesser General Public License for more details.
> > > +
> > > +   You should have received a copy of the GNU Lesser General
> > Public License
> > > +   along with spice-html5.  If not, see <http://www.gnu.org/lic
> > enses/>.
> > > +*/
> > > +
> > > +/*-------------------------------------------------------------
> > ---------------
> > > +**  SpicePortConn
> > > +**      Drive the Spice Port Channel
> > > +**-------------------------------------------------------------
> > -------------*/
> > > +function SpicePortConn()
> > > +{
> > > +    DEBUG > 0 && console.log('SPICE port: created SPICE port
> > channel. Args:', arguments);
> > > +    SpiceConn.apply(this, arguments);
> > > +    this.port_name = null;
> > > +}
> > > +
> > > +SpicePortConn.prototype = Object.create(SpiceConn.prototype);
> > > +
> > > +SpicePortConn.prototype.process_channel_message = function(msg)
> > > +{
> > > +    if (msg.type == SPICE_MSG_PORT_INIT)
> > > +    {
> > > +        if (this.port_name === null)
> > > +        {
> > > +            var m = new SpiceMsgPortInit(msg.data);
> > > +            this.portName = arraybuffer_to_str(new
> > Uint8Array(m.name));
> > > +            this.portOpened = m.opened
> > > +            DEBUG > 0 && console.log('SPICE port: Port',
> > this.portName, 'initialized');
> > > +            return true;
> > > +        }
> > > +
> > > +        DEBUG > 0 && console.log('SPICE port: Port',
> > this.port_name, 'is already initialized.');
> > > +    }
> > > +    else if (msg.type == SPICE_MSG_PORT_EVENT)
> > > +    {
> > > +        DEBUG > 0 && console.log('SPICE port: Port event
> > received for', this.portName, msg);
> > > +        var event = new CustomEvent('spice-port-event', {
> > > +            detail: {
> > > +                channel: this,
> > > +                spiceEvent: new Uint8Array(msg.data)
> > > +            },
> > > +            bubbles: true,
> > > +            cancelable: true
> > > +        });
> > > +
> > > +        window.dispatchEvent(event);
> > > +        return true;
> > > +    }
> > > +    else if (msg.type == SPICE_MSG_SPICEVMC_DATA)
> > > +    {
> > > +        DEBUG > 0 && console.log('SPICE port: Data received in
> > port', this.portName, msg);
> > > +        var event = new CustomEvent('spice-port-data', {
> > > +            detail: {
> > > +                channel: this,
> > > +                data: msg.data
> > > +            },
> > > +            bubbles: true,
> > > +            cancelable: true
> > > +        });
> > > +        window.dispatchEvent(event);
> > > +        return true;
> > > +    }
> > > +    else
> > > +    {
> > > +        DEBUG > 0 && console.log('SPICE port: SPICE message
> > type not recognized:', msg)
> > > +    }
> > > +
> > > +    return false;
> > > +};
> > > diff --git a/spice.html b/spice.html
> > > index c473678..f736c59 100644
> > > --- a/spice.html
> > > +++ b/spice.html
> > > @@ -42,6 +42,7 @@
> > >          <script src=""> > > >          <script src=""> > > >          <script src=""> > > > +        <script src=""> > > >          <script src=""> > > >          <script src=""> > > >          <script src=""> > > > @@ -142,6 +143,15 @@
> > >                  }
> > >              }
> > >
> > > +            window.addEventListener('spice-port-data',
> > function(event) {
> > > +                var msg_text = arraybuffer_to_str(new
> > Uint8Array(event.detail.data));
> > > +                console.log('SPICE port',
> > event.detail.channel.portName, 'message text:', msg_text);
> > > +            });
> > > +
> > > +            window.addEventListener('spice-port-event',
> > function(event) {
> > > +                console.log('SPICE port',
> > event.detail.channel.portName, 'event data:',
> > event.detail.spiceEvent);
> > > +            });
> > > +
> > >          </script>
> > >
> > >      </head>
> > > diff --git a/spice_auto.html b/spice_auto.html
> > > index 1179ebe..304655c 100644
> > > --- a/spice_auto.html
> > > +++ b/spice_auto.html
> > > @@ -42,6 +42,7 @@
> > >          <script src=""> > > >          <script src=""> > > >          <script src=""> > > > +        <script src=""> > > >          <script src=""> > > >          <script src=""> > > >          <script src=""> > > > @@ -182,6 +183,15 @@
> > >                  }
> > >              }
> > >
> > > +            window.addEventListener('spice-port-data',
> > function(event) {
> > > +                var msg_text = arraybuffer_to_str(new
> > Uint8Array(event.detail.data));
> > > +                console.log('SPICE port',
> > event.detail.channel.portName, 'message text:', msg_text);
> > > +            });
> > > +
> > > +            window.addEventListener('spice-port-event',
> > function(event) {
> > > +                console.log('SPICE port',
> > event.detail.channel.portName, 'event data:',
> > event.detail.spiceEvent);
> > > +            });
> > > +
> > >              connect();
> > >          </script>
> > >
> > > diff --git a/spicemsg.js b/spicemsg.js
> > > index 0321cc7..3619996 100644
> > > --- a/spicemsg.js
> > > +++ b/spicemsg.js
> > > @@ -1278,3 +1278,21 @@ SpiceMsgDisplayInvalList.prototype =
> > >          }
> > >      },
> > >  }
> > > +
> > > +function SpiceMsgPortInit(a, at)
> > > +{
> > > +    this.from_buffer(a,at);
> > > +};
> > > +
> > > +SpiceMsgPortInit.prototype =
> > > +{
> > > +    from_buffer: function (a, at)
> > > +    {
> > > +        at = at || 0;
> > > +        var dv = new SpiceDataView(a);
> > > +        var namesize = dv.getUint32(at, true); at += 4;
> > > +        var offset = dv.getUint32(at, true); at += 4;
> > > +        this.opened = dv.getUint8(at, true); at += 1;
> > > +        this.name = a.slice(offset, offset + namesize - 1);
> > > +    }
> > > +}
> > > diff --git a/utils.js b/utils.js
> > > index 9093a24..a22d0ae 100644
> > > --- a/utils.js
> > > +++ b/utils.js
> > > @@ -100,6 +100,13 @@ function hexdump_buffer(a)
> > >  }
> > >
> > >  /*-------------------------------------------------------------
> > ---------------
> > > +**  Convert arraybuffer to string
> > > +**-------------------------------------------------------------
> > -------------*/
> > > +function arraybuffer_to_str(buf) {
> > > +  return String.fromCharCode.apply(null, new Uint16Array(buf));
> > > +}
> > > +
> > > +/*-------------------------------------------------------------
> > ---------------
> > >  ** Converting keycodes to AT scancodes is very hard.
> > >  ** luckly there are some resources on the web and in the Xorg
> > driver that help
> > >  ** us figure out what browser dependent keycodes match to what
> > scancodes.
> > >
> >
> > _______________________________________________
> > Spice-devel mailing list
> > Spice-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/spice-devel
> >
>
>
>
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
>



--
Oliver Gutierrez
Associate Software Engineer - Desktop Management tools
Red Hat
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]