ms: Add timer

Currently the MS object is immediately idle when all TBFs are
detached and if no guard is being used. Since the plan is to use the
MS objects to pass information from one TBF to the next one even
across the gap of some seconds of inactivity, a mechanism is needed
to keep the MS objects around for some time.

This commit extends the GprsMs class by a timer that keeps the MS
objects in non-idle state for some time after all TBFs have been
detached. The set_timeout method must be used with a non-zero value
to activate this feature.

Sponsored-by: On-Waves ehf
diff --git a/src/gprs_ms.h b/src/gprs_ms.h
index 9c3acb4..db55bad 100644
--- a/src/gprs_ms.h
+++ b/src/gprs_ms.h
@@ -25,6 +25,11 @@
 struct gprs_rlcmac_ul_tbf;
 
 #include "cxx_linuxlist.h"
+
+extern "C" {
+	#include <osmocom/core/timer.h>
+}
+
 #include <stdint.h>
 #include <stddef.h>
 
@@ -62,6 +67,8 @@
 	uint8_t ta() const;
 	void set_ta(uint8_t ta);
 
+	void set_timeout(unsigned secs);
+
 	void attach_tbf(gprs_rlcmac_tbf *tbf);
 	void attach_ul_tbf(gprs_rlcmac_ul_tbf *tbf);
 	void attach_dl_tbf(gprs_rlcmac_dl_tbf *tbf);
@@ -76,10 +83,15 @@
 	LListHead<GprsMs>& list() {return this->m_list;}
 	const LListHead<GprsMs>& list() const {return this->m_list;}
 
+	/* internal use */
+	static void timeout(void *priv_);
+
 protected:
 	void update_status();
-	void ref();
+	GprsMs *ref();
 	void unref();
+	void start_timer();
+	void stop_timer();
 
 private:
 	Callback * m_cb;
@@ -96,6 +108,8 @@
 	bool m_is_idle;
 	int m_ref;
 	LListHead<GprsMs> m_list;
+	struct osmo_timer_list m_timer;
+	unsigned m_delay;
 };
 
 inline uint32_t GprsMs::tlli() const
@@ -120,3 +134,8 @@
 {
 	return m_ta;
 }
+
+inline void GprsMs::set_timeout(unsigned secs)
+{
+	m_delay = secs;
+}