enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / surfaces / tranzport / init.cc
index 94f85bdc56935898824ecb0c2393fc218d7a410b..1e284b5831ff8a4d4b7ce6028b8601f3bca1dc05 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *   Copyright (C) 2006 Paul Davis 
+ *   Copyright (C) 2006 Paul Davis
  *   Copyright (C) 2007 Michael Taht
  *
  *   This program is free software; you can redistribute it and/or modify
@@ -15,7 +15,7 @@
  *   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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *  
+ *
  */
 
 #include <tranzport_common.h>
@@ -26,7 +26,7 @@ using namespace std;
 using namespace sigc;
 using namespace PBD;
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 #include <pbd/abstract_ui.cc>
 
@@ -41,35 +41,35 @@ TranzportControlProtocol::~TranzportControlProtocol ()
        set_active (false);
 }
 
-int TranzportControlProtocol::rtpriority_set(int priority) 
+int TranzportControlProtocol::rtpriority_set(int priority)
 {
        struct sched_param rtparam;
        int err;
        char *a = (char*) alloca(4096*2); a[0] = 'a'; a[4096] = 'b';
        memset (&rtparam, 0, sizeof (rtparam));
        rtparam.sched_priority = priority; /* XXX should be relative to audio (JACK) thread */
-       // Note - try SCHED_RR with a low limit 
+       // Note - try SCHED_RR with a low limit
        // - we don't care if we can't write everything this ms
        // and it will help if we lose the device
        if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) {
                PBD::info << string_compose (_("%1: thread not running with realtime scheduling (%2)"), name(), strerror (errno)) << endmsg;
                return 1;
-       } 
+       }
        return 0;
 }
 
 // Running with realtime privs is bad when you have problems
 
-int TranzportControlProtocol::rtpriority_unset(int priority) 
+int TranzportControlProtocol::rtpriority_unset(int priority)
 {
        struct sched_param rtparam;
        int err;
        memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = priority;      
+       rtparam.sched_priority = priority;
        if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) {
                PBD::info << string_compose (_("%1: can't stop realtime scheduling (%2)"), name(), strerror (errno)) << endmsg;
                return 1;
-       } 
+       }
        PBD::info << string_compose (_("%1: realtime scheduling stopped (%2)"), name(), strerror (errno)) << endmsg;
        return 0;
 }
@@ -86,18 +86,8 @@ TranzportControlProtocol::set_active (bool yn)
                                return -1;
                        }
 
-                       if (pthread_create_and_store (X_("tranzport monitor"), &thread, 0, _monitor_work, this) == 0) {
+                       if (pthread_create_and_store (X_("tranzport monitor"), &thread, _monitor_work, this) == 0) {
                                _active = true;
-#if TRANZPORT_THREADS                      
-                       if (pthread_create_and_store (X_("tranzport read"), &thread_read, 0, _read_work, this) == 0) {
-                               _active_read = true;
-                       if (pthread_create_and_store (X_("tranzport write"), &thread_write, 0, _write_work, this) == 0) {
-                               _active_write = true;
-                       if (pthread_create_and_store (X_("tranzport process"), &thread_process, 0, _process_work, this) == 0) {
-                               _active_process = true;
-                       if (pthread_create_and_store (X_("tranzport timer"), &thread_timer, 0, _process_timer, this) == 0) {
-                               _active_process = true;
-#endif
                        } else {
                                return -1;
                        }
@@ -112,19 +102,14 @@ TranzportControlProtocol::set_active (bool yn)
 // thread FIXME - wait til all writes are done
                                for(int x = 0; (x < 20/MAX_TRANZPORT_INFLIGHT) && flush(); x++) { usleep(100); }
                        }
-#if TRANZPORT_THREADS                      
-                       pthread_cancel_one (_thread_timer);
-                       pthread_cancel_one (_thread_process);
-                       pthread_cancel_one (_thread_read);
-                       pthread_cancel_one (_thread_write);
-#endif
+
                        pthread_cancel_one (thread);
 
                        cerr << "Tranzport Thread dead\n";
                        close ();
                        _active = false;
                        cerr << "End tranzport shutdown\n";
-               } 
+               }
        }
 
        return 0;
@@ -173,7 +158,7 @@ TranzportControlProtocol::monitor_work ()
        bool first_time = true;
        uint8_t offline = 0;
 
-       PBD::ThreadCreated (pthread_self(), X_("Tranzport"));
+       register_thread (X_("Tranzport"));
        pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0);
        pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
        rtpriority_set();
@@ -206,13 +191,13 @@ TranzportControlProtocol::monitor_work ()
                /* bInterval for this beastie is 10ms */
 
                if (_device_status == STATUS_OFFLINE) {
-                       first_time = true; offline++; 
+                       first_time = true; offline++;
 #if TRANZPORT_DEBUG > 3
-                       if(offline == 1) { 
+                       if(offline == 1) {
                                cerr << "Transport has gone offline\n";
                        }
 #endif
-               } else { 
+               } else {
                        offline = 0; // hate writing this
                }
                unsigned int s = (last_write_error == 0) | ((last_read_error == 0) << 1);
@@ -223,7 +208,7 @@ TranzportControlProtocol::monitor_work ()
                case 3: val = read(buf,DEFAULT_USB_TIMEOUT*2); break; // Hoo, boy, we're in trouble
                default: break; // not reached
                }
-       
+
 #if DEBUG_TRANZPORT_BITS > 9
                if(_device_status != STATUS_OFFLINE && _device_status != STATUS_ONLINE && _device_status != STATUS_OK) {
                        printf("The device has more status bits than off or online: %d\n",_device_status);
@@ -233,8 +218,8 @@ TranzportControlProtocol::monitor_work ()
 #if DEBUG_TRANZPORT_BITS > 99
                if (val != 8) {
                        printf("val = %d errno = %d\n",val,errno);
-                       buf[0] = buf[1] = buf[2] = buf[3] = 
-                               buf[4] = buf[5] = buf[6] = buf[7] = 
+                       buf[0] = buf[1] = buf[2] = buf[3] =
+                               buf[4] = buf[5] = buf[6] = buf[7] =
                                buf[8] = 0;
                }
 #endif
@@ -261,44 +246,44 @@ TranzportControlProtocol::monitor_work ()
 #if DEBUG_TRANZPORT_BITS > 10
                        // Perhaps an online message indicates something
 
-                       if(_device_status != buf[1]) { 
-                               printf("WTF- val: %d, device status != buf! %d != %d \n",val,_device_status,buf[1]); _device_status = buf[1]; 
+                       if(_device_status != buf[1]) {
+                               printf("WTF- val: %d, device status != buf! %d != %d \n",val,_device_status,buf[1]); _device_status = buf[1];
                        }
 #endif
-    
+
                }
-    
+
 #if DEBUG_TRANZPORT_BITS > 10
 
                if(val == 8) {
 
                        if(_device_status == STATUS_ONLINE) {
-                               printf("ONLINE   : %02x %02x %02x %02x %02x %02x %02x %02x\n", 
-                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); 
+                               printf("ONLINE   : %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]);
                        }
                        if(_device_status == STATUS_OFFLINE) {
-                               printf("OFFLINE  : %02x %02x %02x %02x %02x %02x %02x %02x\n", 
-                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); 
+                               printf("OFFLINE  : %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]);
                        }
-       
+
                        if(_device_status == STATUS_OK) {
-                               printf("OK       : %02x %02x %02x %02x %02x %02x %02x %02x\n", 
-                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); 
+                               printf("OK       : %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                                      buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]);
                        }
-      
+
                }
-    
+
 #endif
-    
+
                /* update whatever needs updating */
-               if(last_write_error == 0 && (_device_status == STATUS_ONLINE || _device_status == STATUS_OK)) { 
+               if(last_write_error == 0 && (_device_status == STATUS_ONLINE || _device_status == STATUS_OK)) {
                        update_state ();
-      
+
                        /* still struggling with a good means of exerting flow control without having to create threads */
                        // pending = flush();
-      
+
                        if(pending == 0) {
-                               pending = flush(); 
+                               pending = flush();
                        } else {
                                if(inflight > 0) {
                                        pending = --inflight; // we just did a whole bunch of writes so wait
@@ -308,7 +293,7 @@ TranzportControlProtocol::monitor_work ()
                        }
                }
                // pending = 0;
-       } 
+       }
        return (void*) 0;
 }