some clean-ups
[senf.git] / Socket / Protocols / DVB / DVBFrontendHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief DVBFrontendHandle public header */
25
26 #ifndef HH_SENF_Socket_Protocols_DVB_DVBFrontendHandle_
27 #define HH_SENF_Socket_Protocols_DVB_DVBFrontendHandle_ 1
28
29 // Custom includes
30 #include <boost/cstdint.hpp>
31 #include <boost/bind.hpp>
32 #include <boost/function.hpp>
33 #include <linux/dvb/frontend.h>
34 #include "../../../Socket/FramingPolicy.hh"
35 #include "../../../Socket/CommunicationPolicy.hh"
36 #include "../../../Socket/ReadWritePolicy.hh"
37 #include "../../../Socket/ProtocolClientSocketHandle.hh"
38 #include "../../../Socket/SocketProtocol.hh"
39 #include <string>
40 #include <fstream>
41
42
43
44 //#include "DVBFrontendHandle.mpp"
45 ///////////////////////////////hh.p////////////////////////////////////////
46
47 namespace senf {
48
49     /// \addtogroup concrete_protocol_group
50     /// @{
51
52     typedef MakeSocketPolicy<
53         NoAddressingPolicy,
54         DatagramFramingPolicy,
55         UnconnectedCommunicationPolicy,
56         NotReadablePolicy,
57         NotWriteablePolicy
58 >    ::policy DVBFrontend_Policy; ///< Socket Policy for DVBFrontendSocketProtocol
59         
60
61     /** \brief SocketProtocol for the dvb frontend device
62
63         The DVB frontend device controls the tuner and DVB demodulator hardware.
64      */
65     
66     class DVBFrontendSocketProtocol
67         : public ConcreteSocketProtocol<DVBFrontend_Policy, DVBFrontendSocketProtocol>
68     {
69     private: 
70         dvb_frontend_event tune(const struct dvb_frontend_parameters & frontend);
71         struct dvb_frontend_event waitTune(const struct dvb_frontend_parameters & frontend);
72         struct dvb_frontend_event asyncTune(const struct dvb_frontend_parameters & frontend);
73         boost::function<struct dvb_frontend_event (const struct dvb_frontend_parameters & frontend)> cb2_X_Tune;
74     public:
75         ///////////////////////////////////////////////////////////////////////////
76         // internal interface
77
78         ///\name Constructors
79         ///@{
80         void init_client(unsigned const short adapter = 0, unsigned const short device = 0);
81                                         ///< Opens the specified frontend device in read-only mode.
82                                         /**< \note This member is implicitly called from the
83                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
84                                              constructor */
85
86         ///@}
87         
88         void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
89                                                                         ///< Tunes a DVB-C device
90                                                                         /**< Tunes a DVB-C device. Needs full configuration */
91         void tuneDVB_T(unsigned int frequency, 
92                 fe_spectral_inversion_t inversion,
93                 fe_bandwidth_t bandwidth, 
94                 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
95                 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
96                 fe_modulation_t constellation, /* modulation type (see above) */
97                 fe_transmit_mode_t transmission_mode, 
98                 fe_guard_interval_t guard_interval,
99                 fe_hierarchy_t hierarchy_information
100                 );                                                      ///< Tunes a DVB-T device
101                                                                         /**< Tunes a DVB-T device. Needs full configuration */
102         void tuneDVB_C(unsigned int frequency, 
103                 fe_spectral_inversion_t inversion,
104                 unsigned int symbol_rate,
105                 fe_code_rate_t fec_inner,
106                 fe_modulation_t modulation);        
107                                                                         ///< Tunes a DVB-C device
108                                                                         /**< Tunes a DVB-C device. Needs full configuration */
109         struct dvb_frontend_info getInfo() const;                     ///< Returns information struct.
110                                                                         /**< Returns information struct, which contains information 
111                                                                              about the device which is associated with the current frontend.*/
112         struct dvb_frontend_parameters getFrontendParam() const;        ///< Returns dvb_frontend_parameters struct.
113                                                                         /**< Returns dvb_frontend_parameters struct, which contains the actual 
114                                                                              configuration of the device.*/
115         void setFrequency(unsigned int frequency);                      ///< Sets frequency
116                                                                         /**< Sets frequency. This can be done for all device types.*/
117         void setInversion(fe_spectral_inversion_t inversion);           ///< Sets inversion
118                                                                         /**< Sets inversion. This can be done for all device types.*/
119         void setCodeRate(fe_code_rate_t fec_inner);                     ///< Sets code rate
120                                                                         /**< Sets code rate. This can be done for all device types. Attention 
121                                                                              for DVB-T devices the high and low priority stream code rate will be set to 
122                                                                              the given value.*/
123         void setSymbolRate(unsigned int symbol_rate);                   ///< Sets symbol rate
124                                                                         /**< Sets symbol rate. This can only be done for DVB-S or DVB-C devices.
125                                                                              Other attempts will throw an exception.*/
126         void setModulation(fe_modulation_t modulation);                 ///< Sets modulation
127                                                                         /**< Sets modulation. This can only be done for DVB-T or DVB-C devices.
128                                                                              Other attempts will throw an exception.*/
129         void setBandwidth(fe_bandwidth_t bandwidth);                    ///< Sets bandwidth
130                                                                         /**< Sets bandwidth. This can only be done for DVB-T devices.
131                                                                              Other attempts will throw an exception.*/
132         void setHighPriorityCodeRate(fe_code_rate_t code_rate_HP);      ///< Sets high priority stream code rate
133                                                                         /**< Sets high priority stream code rate. This can only be done for DVB-T devices.
134                                                                              Other attempts will throw an exception.*/
135         void setLowPriorityCodeRate(fe_code_rate_t code_rate_LP);       ///< Sets low priority stream code rate
136                                                                         /**< Sets low priority stream code rate. This can only be done for DVB-T devices.
137                                                                              Other attempts will throw an exception.*/
138         void setGuardInterval(fe_guard_interval_t guard_interval);      ///< Sets guard interval
139                                                                         /**< Sets guard interval. This can only be done for DVB-T devices.
140                                                                              Other attempts will throw an exception.*/
141         void setHierarchyInformation(fe_hierarchy_t hierarchy_information);  ///< Sets hierarchy information
142                                                                             /**< Sets hierarchy information. This can only be done for DVB-T devices.
143                                                                                  Other attempts will throw an exception.*/
144         
145         
146         ///\name Abstract Interface Implementation
147         ///@{
148
149         unsigned available() const;     ///< Returns always <tt>0</tt>
150                                         /**< Returns always <tt>0</tt>, since the DVB frontend
151                                              socket is not readable. */
152         bool eof() const;               ///< Returns always <tt>false</tt>
153                                         /**< Returns always <tt>false</tt>, since the DVB frontend
154                                              socket does not support the notion of EOF. */
155
156         ///@}
157
158         int16_t signalStrength() const; ///< Returns current signal strength
159                                         /**< Returns the signal strength value for the signal
160                                              currently received by the front-end. For this method,
161                                              read-only access to the device is sufficient.*/
162
163         int16_t signalNoiseRatio() const;
164                                         ///< Returns current signal-to-noise ratio
165                                         /**< Returns the signal-to-noise ratio for the signal
166                                              currently received by the front-end. For this method,
167                                              read-only access to the device is sufficient. */
168
169         uint32_t bitErrorRate() const;  ///< Returns the current bit error rate for the signal
170                                         /**< Returns the bit error rate for the signal currently
171                                              received/demodulated by the front-end. For this method,
172                                              read-only access to the device is sufficient. */
173     };
174
175     typedef ProtocolClientSocketHandle<DVBFrontendSocketProtocol> DVBFrontendHandle;
176
177     ///@}
178 }
179
180
181 ///////////////////////////////hh.e////////////////////////////////////////
182 //#include "DVBFrontendHandle.cci"
183 //#include "DVBFrontendHandle.ct"
184 //#include "DVBFrontendHandle.cti"
185 #endif
186
187
188 // Local Variables:
189 // mode: c++
190 // fill-column: 100
191 // c-file-style: "senf"
192 // indent-tabs-mode: nil
193 // ispell-local-dictionary: "american"
194 // compile-command: "scons -u test"
195 // comment-column: 40
196 // End: