make library optional; improve wording
[libeflvala.git] / eflvala / objects.vala
blob87f3b5baf0f9c10b73d4853207fda62abd314b9c
1 /**
2 * Copyright (C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
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.
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.
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
18 **/
20 // misc objects that need to get categorized
22 //=======================================================================
23 public class EflVala.Command : GLib.Object
24 //=======================================================================
26 public string command;
28 public Command( string command )
30 this.command = command;
31 debug( "creating command '%s' (%p)", command, this );
34 ~Command()
36 debug( "destructing command '%s' (%p)", this.command, this );
40 //=======================================================================
41 public class EflVala.BidirectionalThreadQueue : GLib.Object
42 //=======================================================================
44 public enum Identifier
46 COMMUNICATION_THREAD,
47 GUI_THREAD;
49 private static QueueWithNotifier<Command> toGuiQ;
50 private static QueueWithNotifier<Command> toCommQ;
52 private Identifier owner;
54 public BidirectionalThreadQueue( Identifier id )
56 owner = id;
57 switch ( id )
59 case Identifier.COMMUNICATION_THREAD:
60 assert ( toGuiQ == null );
61 toGuiQ = new QueueWithNotifier<Command>();
62 break;
63 case Identifier.GUI_THREAD:
64 assert ( toCommQ == null );
65 toCommQ = new QueueWithNotifier<Command>();
66 break;
67 default:
68 assert_not_reached();
72 public void getFds( out int readfd, out int writefd )
74 switch ( owner )
76 case Identifier.COMMUNICATION_THREAD:
77 readfd = toCommQ.getReadFd();
78 writefd = toGuiQ.getWriteFd();
79 break;
80 case Identifier.GUI_THREAD:
81 readfd = toGuiQ.getReadFd();
82 writefd = toCommQ.getWriteFd();
83 break;
84 default:
85 assert_not_reached();
89 public Command? read()
91 switch ( owner )
93 case Identifier.COMMUNICATION_THREAD:
94 return toCommQ.read();
95 break;
96 case Identifier.GUI_THREAD:
97 return toGuiQ.read();
98 break;
99 default:
100 assert_not_reached();
104 public void write( Command command )
106 switch ( owner )
108 case Identifier.COMMUNICATION_THREAD:
109 toGuiQ.write( command );
110 break;
111 case Identifier.GUI_THREAD:
112 toCommQ.write( command );
113 break;
114 default:
115 assert_not_reached();