Create a private class for the main loop.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 22 Jan 2014 18:04:25 +0000 (18:04 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 22 Jan 2014 18:04:25 +0000 (18:04 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1392 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/run.cpp

index 717d97e7a3f14ff787f5435ec0952df551f53171..ea276f2b329522a45af2cb4080b110c6ac970e2d 100644 (file)
@@ -13,9 +13,9 @@
 ///
 /// End of Transmit:
 /// There is a lot to fill in for end-of-transmit.
-/// On PTT-up, we should be sending the remaining audio in the microphone
-/// device queue first, waiting for completion of its transmission, and then
-/// un-keying the transmitter.
+/// On PTT-up, we should read the remaining audio in the microphone
+/// device queue first, allow it all to drain out the transmitter, and then
+/// un-key the transmitter.
 ///
 /// Codec to Modem connection:
 /// We need a circular buffer between the codec and the modem. It's perfectly
 /// to work upon.
 
 namespace FreeDV {
-  static void key_down(Interfaces * i);
-  static void key_up(Interfaces * i);
-  static void receive(Interfaces * i);
-  static void transmit_digital(Interfaces * i);
-  static void transmit_ssb(Interfaces * i);
+  class Run {
+  private:
+    Interfaces *       in;
+    bool               begin_transmit;
+    bool               begin_receive;
+    bool               ptt_digital;
+    bool               ptt_ssb;
+    void               key_down(Interfaces * i);
+    void               key_up(Interfaces * i);
+    void               receive(Interfaces * i);
+    void               transmit_digital(Interfaces * i);
+    void               transmit_ssb(Interfaces * i);
+  public:
+    int                        run(Interfaces * i);
+
+                       Run(Interfaces *);
+                       ~Run();
+  };
   
-  static bool begin_transmit = false;
-  static bool begin_receive = true;
+  Run::Run(Interfaces * interfaces)
+  : begin_receive(true), begin_transmit(false), ptt_digital(false),
+    ptt_ssb(false)
+  {
+    in = interfaces;
+  }
 
-  int
-  run(Interfaces * i)
+  Run::~Run()
   {
-    static bool ptt_digital = false;
-    static bool ptt_ssb = false;
+  }
 
+  int
+  Run::run(Interfaces * i)
+  {
     while ( true ) {
       if ( i->ptt_input_digital->ready() ) {
         bool state = i->ptt_input_digital->state();
@@ -81,8 +100,8 @@ namespace FreeDV {
     }
   }
 
-  static void
-  key_down(Interfaces * i)
+  void
+  Run::key_down(Interfaces * i)
   {
     if ( i->keying_output->ready() ) {
       i->keying_output->key(true);
@@ -93,8 +112,8 @@ namespace FreeDV {
     }
   }
   
-  static void
-  key_up(Interfaces * i)
+  void
+  Run::key_up(Interfaces * i)
   {
     if ( i->keying_output->ready() ) {
       i->keying_output->key(false);
@@ -105,20 +124,27 @@ namespace FreeDV {
     }
   }
   
-  static void
-  receive(Interfaces * i)
+  void
+  Run::receive(Interfaces * i)
   {
     const std::size_t  samples_to_decode = i->receiver->ready()
                         % i->modem->samples_per_frame();
   }
   
-  static void
-  transmit_digital(Interfaces * i)
+  void
+  Run::transmit_digital(Interfaces * i)
   {
   }
   
-  static void
-  transmit_ssb(Interfaces * i)
+  void
+  Run::transmit_ssb(Interfaces * i)
+  {
+  }
+
+  int
+  run(Interfaces * i)
   {
+    Run * r = new Run(i);
+    return r->run(i);
   }
 }