Merge remote branch 'ets/grc-usrp2-clock-source'
[debian/gnuradio] / grc / python / Connection.py
1 """
2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
4
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 """
19
20 from .. base.Connection import Connection as _Connection
21 from .. gui.Connection import Connection as _GUIConnection
22
23 class Connection(_Connection, _GUIConnection):
24
25         def __init__(self, **kwargs):
26                 _Connection.__init__(self, **kwargs)
27                 _GUIConnection.__init__(self)
28
29         def is_msg(self):
30                 return self.get_source().get_type() == self.get_sink().get_type() == 'msg'
31
32         def validate(self):
33                 """
34                 Validate the connections.
35                 The ports must match in type and vector length.
36                 """
37                 _Connection.validate(self) #checks type
38                 #check vector length
39                 source_vlen = self.get_source().get_vlen()
40                 sink_vlen = self.get_sink().get_vlen()
41                 try: assert source_vlen == sink_vlen
42                 except AssertionError: self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))