Rename and move STOP signal from Transceiver to main

The callback actually belongs there, since it's the code/thread in main the one
actually in charge of stopping everything. It simplifies current code,
and more important, allows for new clients of this signal to use it.
This callback will also be used in forthcoming commits by code
controlling rate_ctr thresholds to stop the process if the VTY
configured threshold is used.

Change-Id: Id4159e64225c6606fef34a74b24f37c3a071aceb
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index 54b9ddd..9c55d02 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -119,7 +119,7 @@
   : mBasePort(wBasePort), mLocalAddr(TRXAddress), mRemoteAddr(GSMcoreAddress),
     mClockSocket(TRXAddress, wBasePort, GSMcoreAddress, wBasePort + 100),
     mTransmitLatency(wTransmitLatency), mRadioInterface(wRadioInterface),
-    rssiOffset(wRssiOffset), sig_cbfn(NULL),
+    rssiOffset(wRssiOffset),
     mSPSTx(tx_sps), mSPSRx(rx_sps), mChans(chans), mEdge(false), mOn(false), mForceClockInterface(false),
     mTxFreq(0.0), mRxFreq(0.0), mTSC(0), mMaxExpectedDelayAB(0), mMaxExpectedDelayNB(0),
     mWriteBurstToDiskMask(0)
@@ -225,17 +225,6 @@
   return true;
 }
 
-void Transceiver::setSignalHandler(osmo_signal_cbfn cbfn)
-{
-  if (this->sig_cbfn)
-    osmo_signal_unregister_handler(SS_TRANSC, this->sig_cbfn, NULL);
-
-  if (cbfn) {
-    this->sig_cbfn = cbfn;
-    osmo_signal_register_handler(SS_TRANSC, this->sig_cbfn, NULL);
-  }
-}
-
 /*
  * Start the transceiver
  *
@@ -910,7 +899,7 @@
     usleep(100000);
   } else if (rc < 0) {
     LOG(FATAL) << "radio Interface receive failed, requesting stop.";
-    osmo_signal_dispatch(SS_TRANSC, S_TRANSC_STOP_REQUIRED, this);
+    osmo_signal_dispatch(SS_MAIN, S_MAIN_STOP_REQUIRED, NULL);
   } else if (mForceClockInterface || mTransmitDeadlineClock > mLastClockUpdateTime + GSM::Time(216,0)) {
     mForceClockInterface = false;
     writeClockInterface();
diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h
index 432e3b4..4614efe 100644
--- a/Transceiver52M/Transceiver.h
+++ b/Transceiver52M/Transceiver.h
@@ -130,8 +130,6 @@
   /** accessor for number of channels */
   size_t numChans() const { return mChans; };
 
-  void setSignalHandler(osmo_signal_cbfn cbfn);
-
   /** Codes for channel combinations */
   typedef enum {
     FILL,               ///< Channel is transmitted, but unused
@@ -181,8 +179,6 @@
 
   double rssiOffset;                      ///< RSSI to dBm conversion offset
 
-  osmo_signal_cbfn *sig_cbfn;              ///< Registered Signal Handler to announce events.
-
   /** modulate and add a burst to the transmit queue */
   void addRadioVector(size_t chan, BitVector &bits,
                       int RSSI, GSM::Time &wTime);
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index a79c26e..05489bd 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -123,7 +123,7 @@
 		     void *handler_data, void *signal_data)
 {
 	switch (signal) {
-	case S_TRANSC_STOP_REQUIRED:
+	case S_MAIN_STOP_REQUIRED:
 		gshutdown = true;
                 break;
 	default:
@@ -152,8 +152,6 @@
 		return -1;
 	}
 
-        transceiver->setSignalHandler(transc_sig_cb);
-
 	for (size_t i = 0; i < trx->cfg.num_chans; i++) {
 		fifo = radio->receiveFIFO(i);
 		if (fifo && transceiver->receiveFIFO(fifo, i))
@@ -627,6 +625,7 @@
 			return EXIT_FAILURE;
 	}
 
+	osmo_signal_register_handler(SS_MAIN, transc_sig_cb, NULL);
 	trx_rate_ctr_init(tall_trx_ctx, g_trx_ctx);
 
 	srandom(time(NULL));
@@ -641,5 +640,6 @@
 
 	osmo_fd_unregister(&signal_ofd);
 	osmo_fd_close(&signal_ofd);
+	osmo_signal_unregister_handler(SS_MAIN, transc_sig_cb, NULL);
 	return 0;
 }