Merged latest pmt and mblock into trunk (eb/wip -r4262:4268)
[debian/gnuradio] / mblock / src / lib / mb_protocol_class.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <mb_protocol_class.h>
27
28 static pmt_t s_ALL_PROTOCOL_CLASSES = PMT_NIL;
29
30 pmt_t 
31 mb_make_protocol_class(pmt_t name, pmt_t incoming, pmt_t outgoing)
32 {
33   // (protocol-class <name> <incoming> <outgoing>)
34
35   if (!pmt_is_symbol(name))
36     throw pmt_wrong_type("mb_make_protocol_class: NAME must be symbol", name);
37   if (!(pmt_is_pair(incoming) || pmt_is_null(incoming)))
38     throw pmt_wrong_type("mb_make_protocol_class: INCOMING must be a list", name);
39   if (!(pmt_is_pair(outgoing) || pmt_is_null(outgoing)))
40     throw pmt_wrong_type("mb_make_protocol_class: OUTGOING must be a list", name);
41
42   pmt_t t = pmt_cons(pmt_intern("protocol-class"),
43                      pmt_cons(name,
44                               pmt_cons(incoming,
45                                        pmt_cons(outgoing, PMT_NIL))));
46
47   // Remember this protocol class.
48   s_ALL_PROTOCOL_CLASSES = pmt_cons(t, s_ALL_PROTOCOL_CLASSES);
49   return t;
50 }
51
52 pmt_t
53 mb_protocol_class_name(pmt_t pc)
54 {
55   return pmt_nth(1, pc);
56 }
57
58 pmt_t
59 mb_protocol_class_incoming(pmt_t pc)
60 {
61   return pmt_nth(2, pc);
62 }
63
64 pmt_t
65 mb_protocol_class_outgoing(pmt_t pc)
66 {
67   return pmt_nth(3, pc);
68 }
69
70 pmt_t
71 mb_protocol_class_lookup(pmt_t name)
72 {
73   pmt_t lst = s_ALL_PROTOCOL_CLASSES;
74
75   while (pmt_is_pair(lst)){
76     if (pmt_eq(name, mb_protocol_class_name(pmt_car(lst))))
77       return pmt_car(lst);
78     lst = pmt_cdr(lst);
79   }
80
81   return PMT_NIL;
82 }