Warning: Can't synchronize with repository "(default)" (No changeset 96d22ec3fa3ef6de3ea8dc0d7d398adc9aa071cf in the repository). Look in the Trac log for more information.

source: fsogsmd/src/lib/commandqueue.vala @ 77cac89

Revision 77cac89, 2.2 KB checked in by Michael 'Mickey' Lauer <mickey@…>, 4 years ago (diff)

fsogsmd: open serial transport and enqueue a test command

  • Property mode set to 100644
Line 
1/**
2 * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17 *
18 */
19
20using GLib;
21
22public delegate void FsoGsm.ResponseHandler( string response );
23
24public struct FsoGsm.Command
25{
26    public string command;
27    public ResponseHandler handler;
28}
29
30public abstract interface FsoGsm.CommandQueue : Object
31{
32    public abstract void enqueue( Command command );
33}
34
35public class FsoGsm.BaseCommandQueue : FsoGsm.CommandQueue, Object
36{
37    protected Queue<Command?> q;
38    protected FsoFramework.Transport transport;
39
40    /**
41     * create new command queue using @a transport.
42     **/
43    public BaseCommandQueue( FsoFramework.Transport transport )
44    {
45        q = new Queue<Command?>();
46        this.transport = transport;
47        transport.setDelegates( onReadFromTransport, onHupFromTransport );
48    }
49
50    public void enqueue( Command command )
51    {
52        debug( "enqueuing %s", command.command );
53        var retriggerWriting = ( q.length == 0 );
54        q.push_head( command );
55        if ( retriggerWriting )
56            writeNextCommand();
57    }
58
59    protected void writeNextCommand()
60    {
61        var command = q.peek_tail();
62        transport.write( command.command, (int)command.command.size() );
63    }
64
65    protected void onReadFromTransport( FsoFramework.Transport transport )
66    {
67        debug( "read from transport" );
68    }
69
70    protected void onHupFromTransport( FsoFramework.Transport transport )
71    {
72        debug( "HUP from transport" );
73    }
74
75}
Note: See TracBrowser for help on using the repository browser.