osmo-trx: Add osmo_signal to stop whole transceiver chain correctly on error

Transceiver::stop() can only be called from either CTRL iface thread or
from main thread (running osmocom loop). That's because stop attempts to
cancel and then join all the other threads, which would then lock if
attempting to stop from some of them.
As a result, the best option is to indicate to the user of the
transceiver option (osmo-trx.cpp) to stop it in a correct fashion by
destroying the object from the main thread.

Change-Id: Iac1d2dbe2328e735db2d4b933cb67b1af1babca1
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 1c40fcf..d01a4cf 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -55,6 +55,7 @@
 #include "convert.h"
 #include "trx_vty.h"
 #include "debug.h"
+#include "osmo_signal.h"
 }
 
 #define DEFAULT_CONFIG_FILE	"osmo-trx.cfg"
@@ -112,6 +113,20 @@
 	return radio;
 }
 
+/* Callback function to be called every time we receive a signal from TRANSC */
+static int transc_sig_cb(unsigned int subsys, unsigned int signal,
+		     void *handler_data, void *signal_data)
+{
+	switch (signal) {
+	case S_TRANSC_STOP_REQUIRED:
+		gshutdown = true;
+                break;
+	default:
+                break;
+	}
+	return 0;
+}
+
 /* Create transceiver core
  *     The multi-threaded modem core operates at multiples of the GSM rate of
  *     270.8333 ksps and consists of GSM specific modulation, demodulation,
@@ -132,6 +147,8 @@
 		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))