Added documentation for DVBSocketController
[senf.git] / Socket / Protocols / DVB / DVBSocketController.cc
index 1242ff2..85b5222 100644 (file)
@@ -1,6 +1,29 @@
-#include "../../../Utils/Exception.hh"
-#include "../../../Utils/Logger/Logger.hh"
-#include <../../../Utils/membind.hh>
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Anton Gillert <atx@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+
+#include "senf/Utils/Exception.hh"
+#include "senf/Utils/Logger/Logger.hh"
+#include "senf/Utils/membind.hh"
 
 #include "DVBSocketController.hh"
 #include <sstream>
@@ -24,24 +47,20 @@ senf::DVBSocketController::DVBSocketController(DVBFrontendHandle frontendHandle_
 prefix_ senf::DVBSocketController::~DVBSocketController()
 {
 }
-prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, const string & mode){
+prefix_ void senf::DVBSocketController::tuneToCMD(const string & input, const string & mode){
     struct dvb_frontend_parameters frontend;
     
   
     // no valid configline, so it will be treaten like a channel name
-    if (configLine.find(":")==string::npos){
-        if (mode.c_str()[0]=='a'){
-            tuneTo(configLine);
-            return "async readConfFile";
-        }
-        else{
-            tuneTo_sync(configLine);
-            return "sync readConfFile";
-        }
-        
+    if (input.find(":")==string::npos){
+        if (mode.c_str()[0]=='a')
+            tuneTo(input);
+        else
+            tuneTo_sync(input);
+        return;
     }
-    // add psydo name to complete configline syntax
-    frontend = parser.getFrontendParam("foo:"+configLine);
+    // add psydo name "foo" to complete configline syntax
+    frontend = parser.getFrontendParam("foo:"+input);
     
     if (mode.c_str()[0]=='a'){
         switch (type) {
@@ -57,7 +76,6 @@ prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, c
             default:
                 SENF_THROW_SYSTEM_EXCEPTION("Could not determine type of card.");
         }
-        return "async get directly";
     }
     else {
         switch (type) {
@@ -73,7 +91,6 @@ prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, c
             default:
                 SENF_THROW_SYSTEM_EXCEPTION("Could not determine type of card.");
         }
-        return "sync get directly";
     }
 }
 
@@ -83,7 +100,6 @@ prefix_ void senf::DVBSocketController::tuneTo(const string & channel)
    
     string configLine = parser.getConfigLine(channel);
     
-    SENF_LOG((senf::log::MESSAGE) ("async: configline found: " << channel) );
     frontend = parser.getFrontendParam(configLine);
     switch (type) {
         case FE_QPSK:
@@ -113,7 +129,9 @@ prefix_ void senf::DVBSocketController::tuneDVB_T(unsigned int frequency,
 {
     if(type != FE_OFDM)
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-T Card!";
+    
     event.enable();
+    
     frontendHandle.protocol().setNonBlock();
     frontendHandle.protocol().tuneDVB_T(frequency, 
                 inversion, 
@@ -129,7 +147,9 @@ prefix_ void senf::DVBSocketController::tuneDVB_T(unsigned int frequency,
 prefix_ void senf::DVBSocketController::tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate){
     if(type != FE_QPSK)
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-S Card!";
+    
     event.enable();
+    
     frontendHandle.protocol().setNonBlock();
     frontendHandle.protocol().tuneDVB_S(frequency, inversion, symbole_rate, code_rate);
 }
@@ -145,6 +165,7 @@ prefix_ void senf::DVBSocketController::tuneDVB_C(unsigned int frequency,
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-C Card!";
     
     event.enable();
+    
     frontendHandle.protocol().setNonBlock();
     
     frontendHandle.protocol().tuneDVB_C(frequency, inversion, symbol_rate, fec_inner, modulation);
@@ -156,7 +177,6 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneTo_sync(const string &
     dvb_frontend_event ev;
     string configLine = parser.getConfigLine(channel);
     
-    SENF_LOG((senf::log::MESSAGE) ("sync: configline found: " << channel) );
     frontend = parser.getFrontendParam(configLine);
     switch (type) {
         case FE_QPSK:
@@ -187,7 +207,9 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_T_sync(unsigned in
 {
     if(type != FE_OFDM)
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-T Card!";
+    
     event.disable();
+    
     frontendHandle.protocol().setNonBlock(false);
     
     frontendHandle.protocol().tuneDVB_T(frequency, 
@@ -209,8 +231,11 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_T_sync(unsigned in
 prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate){
     if(type != FE_QPSK)
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-S Card!";
+    
     event.disable();
+    
     frontendHandle.protocol().setNonBlock(false);
+    
     frontendHandle.protocol().tuneDVB_S(frequency, inversion, symbole_rate, code_rate);
     
     if(!frontendHandle.waitOOBReadable(senf::ClockService::seconds(2)))
@@ -229,7 +254,9 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_C_sync(unsigned in
         SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-C Card!";
     
     event.disable();
+    
     frontendHandle.protocol().setNonBlock(false);
+    
     frontendHandle.protocol().tuneDVB_C(frequency, inversion, symbol_rate, fec_inner, modulation);
     if(!frontendHandle.waitOOBReadable(senf::ClockService::seconds(2)))
         SENF_THROW_SYSTEM_EXCEPTION("Could not tune to channel!");
@@ -268,6 +295,7 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){
     stringstream info;
     
     fe_status_t status;
+    frontendHandle.protocol().setNonBlock(false);
     uint16_t snr, signal;
     uint32_t ber, uncorrected_blocks;
     status = frontendHandle.protocol().status();
@@ -279,21 +307,23 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){
     info << hex;
     
     for(unsigned int i = 0; i < conf.size(); ++i){
+        if(i>0)
+            info << " | ";
         switch(cConf[i]){
             case 'S' :
-                info << " | signal " << signal;
+                info << "signal " << signal;
                 break;
             case 's' : 
-                info << " | snr " << snr;
+                info << "snr " << snr;
                 break;
             case 'b' :
-                info << " | ber " << ber;
+                info << "ber " << ber;
                 break;
             case 'u' :
-                info << " | unc " << uncorrected_blocks;
+                info << "unc " << uncorrected_blocks;
                 break;
             case 'f' :
-                info << " | status: " << status2String(status);
+                info << "status: " << status2String(status);
                 break;
             default:
                 break;
@@ -304,28 +334,28 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){
 prefix_ string senf::DVBSocketController::status2String(fe_status_t status){
    string s("");
     if (status & FE_HAS_LOCK)
-        return s += "|HAS LOCK"; 
+        return s += "HAS LOCK"; 
     if (status & FE_HAS_CARRIER)
-        s += "|HAS CARRIER";
+        s += "HAS CARRIER";
     if (status & FE_HAS_VITERBI)
-        s += "|HAS VITERBI";
+        s += "HAS VITERBI";
     if (status & FE_HAS_SYNC)
-        s += "|HAS SYNC";
+        s += "HAS SYNC";
     if (status & FE_HAS_SIGNAL)
-        s += "|HAS SIGNAL";
+        s += "HAS SIGNAL";
     if (status & FE_TIMEDOUT)
-        s += "|TIMED OUT";
+        s += "TIMED OUT";
     if (status & FE_REINIT)
-        s += "|REINIT";
+        s += "REINIT";
 
     return s;
 }
 
 prefix_ void senf::DVBSocketController::setSectionFilter(unsigned short int pid, 
-        unsigned char filter,
+        u_int8_t filter,
         unsigned int flags, 
-        unsigned char mask, 
-        unsigned char mode,
+        u_int8_t mask, 
+        u_int8_t mode,
         unsigned int timeout)
 {
     sectionHandle.protocol().setSectionFilter(pid, timeout, flags, filter, mask, mode);
@@ -347,13 +377,13 @@ prefix_ void senf::DVBSocketController::stopFiltering()
     sectionHandle.protocol().stopFiltering();
 }
 
-
 prefix_ fe_type_t senf::DVBSocketController::getType(){
     return type;
 }
 
 prefix_ void senf::DVBSocketController::readEvent(int event){
-    cb(frontendHandle.protocol().getEvent());
+    if(cb)
+        cb(frontendHandle.protocol().getEvent());
 }
 
 prefix_ void senf::DVBSocketController::initConsole(){
@@ -376,7 +406,7 @@ prefix_ void senf::DVBSocketController::initConsole(){
             and could end in throwing an exception!")
     .arg("conf", "Ssbuf", kw::default_value = "Ssbuf");
     
-    dir.add("tuneTo", &DVBSocketController::tuneToCMD)
+    dir.add("tune", &DVBSocketController::tuneToCMD)
         .doc("tunes to channel listet in the configfile.")
         .arg("channel", "channel to tune")
         .arg("mode", "mode \"sync\" or \"async\"", kw::default_value = "async");