From 6ef876f0293e85d91a1561438f68c152398fc1b3 Mon Sep 17 00:00:00 2001
From: Holger Freyther <ich@tamarin.(none)>
Date: Tue, 19 May 2009 07:23:40 +0200
Subject: [PATCH] [timer] Prefix global timer functions with bsc_

Prefix the public timer functions with bsc_ and the internal
functions (used by select.c) by a _ to not pollute the namespace
when turning libbsc.a into a true library.
---
 include/openbsc/gsm_data.h |    2 +-
 include/openbsc/timer.h    |   14 +++++++-------
 src/bs11_config.c          |    2 +-
 src/chan_alloc.c           |    6 +++---
 src/gsm_04_08.c            |    4 ++--
 src/ipaccess-find.c        |    4 ++--
 src/paging.c               |   10 +++++-----
 src/select.c               |    6 +++---
 src/timer.c                |   18 +++++++++---------
 tests/timer/timer_test.c   |   10 +++++-----
 10 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/include/openbsc/gsm_data.h b/include/openbsc/gsm_data.h
index 8ad127a..4da9e3a 100644
--- a/include/openbsc/gsm_data.h
+++ b/include/openbsc/gsm_data.h
@@ -39,7 +39,7 @@ typedef int gsm_cbfn(unsigned int hooknum,
 #define LCHAN_RELEASE_TIMEOUT 4, 0
 #define use_lchan(lchan) \
 	do {	lchan->use_count++; \
-		schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
+		bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
 
 #define put_lchan(lchan) \
 	do { lchan->use_count--; } while(0);
diff --git a/include/openbsc/timer.h b/include/openbsc/timer.h
index b3e809e..cc32f71 100644
--- a/include/openbsc/timer.h
+++ b/include/openbsc/timer.h
@@ -55,17 +55,17 @@ struct timer_list {
 /**
  * timer management
  */
-void add_timer(struct timer_list *timer);
-void schedule_timer(struct timer_list *timer, int seconds, int microseconds);
-void del_timer(struct timer_list *timer);
-int timer_pending(struct timer_list *timer);
+void bsc_add_timer(struct timer_list *timer);
+void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds);
+void bsc_del_timer(struct timer_list *timer);
+int bsc_timer_pending(struct timer_list *timer);
 
 
 /**
  * internal timer list management
  */
-struct timeval *nearest_timer();
-void prepare_timers();
-void update_timers();
+struct timeval *_nearest_timer();
+void _prepare_timers();
+void _update_timers();
 
 #endif
diff --git a/src/bs11_config.c b/src/bs11_config.c
index 25ff0e0..3da0c52 100644
--- a/src/bs11_config.c
+++ b/src/bs11_config.c
@@ -633,7 +633,7 @@ int handle_serial_msg(struct msgb *rx_msg)
 		abis_nm_bs11_factory_logon(g_bts, 1);
 		break;
 	case STATE_LOGON_ACK:
-		schedule_timer(&status_timer, 5, 0);
+		bsc_schedule_timer(&status_timer, 5, 0);
 		break;
 	default:
 		break;
diff --git a/src/chan_alloc.c b/src/chan_alloc.c
index 7edde6e..fa07273 100644
--- a/src/chan_alloc.c
+++ b/src/chan_alloc.c
@@ -178,7 +178,7 @@ struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
 		/* Configure the time and start it so it will be closed */
 		lchan->release_timer.cb = auto_release_channel;
 		lchan->release_timer.data = lchan;
-		schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
+		bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
 	}
 
 	return lchan;
@@ -199,7 +199,7 @@ void lchan_free(struct gsm_lchan *lchan)
 	}
 
 	/* stop the timer */
-	del_timer(&lchan->release_timer);
+	bsc_del_timer(&lchan->release_timer);
 
 	/* FIXME: ts_free() the timeslot, if we're the last logical
 	 * channel using it */
@@ -233,7 +233,7 @@ static void auto_release_channel(void *_lchan)
 	struct gsm_lchan *lchan = _lchan;
 
 	if (!lchan_auto_release(lchan))
-		schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
+		bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
 }
 
 struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
diff --git a/src/gsm_04_08.c b/src/gsm_04_08.c
index fe1637e..e178d99 100644
--- a/src/gsm_04_08.c
+++ b/src/gsm_04_08.c
@@ -165,7 +165,7 @@ static void release_loc_updating_req(struct gsm_lchan *lchan)
 	if (!lchan->loc_operation)
 		return;
 
-	del_timer(&lchan->loc_operation->updating_timer);
+	bsc_del_timer(&lchan->loc_operation->updating_timer);
 	free(lchan->loc_operation);
 	lchan->loc_operation = 0;
 	put_lchan(lchan);
@@ -527,7 +527,7 @@ static void schedule_reject(struct gsm_lchan *lchan)
 {
 	lchan->loc_operation->updating_timer.cb = loc_upd_rej_cb;
 	lchan->loc_operation->updating_timer.data = lchan;
-	schedule_timer(&lchan->loc_operation->updating_timer, 5, 0);
+	bsc_schedule_timer(&lchan->loc_operation->updating_timer, 5, 0);
 }
 
 static const char *lupd_name(u_int8_t type)
diff --git a/src/ipaccess-find.c b/src/ipaccess-find.c
index bada3b2..32f42e9 100644
--- a/src/ipaccess-find.c
+++ b/src/ipaccess-find.c
@@ -143,7 +143,7 @@ static void timer_cb(void *_data)
 
 	bfd->when |= BSC_FD_WRITE;
 
-	schedule_timer(&timer, 5, 0);
+	bsc_schedule_timer(&timer, 5, 0);
 }
 
 int main(int argc, char **argv)
@@ -165,7 +165,7 @@ int main(int argc, char **argv)
 	timer.cb = timer_cb;
 	timer.data = &bfd;
 
-	schedule_timer(&timer, 5, 0);
+	bsc_schedule_timer(&timer, 5, 0);
 
 	printf("Trying to find ip.access BTS by broadcast UDP...\n");
 
diff --git a/src/paging.c b/src/paging.c
index 4de93c6..d777d66 100644
--- a/src/paging.c
+++ b/src/paging.c
@@ -78,7 +78,7 @@ static void paging_remove_request(struct gsm_bts_paging_state *paging_bts,
 			paging_bts->last_request = NULL;
 	}
 
-	del_timer(&to_be_deleted->T3113);
+	bsc_del_timer(&to_be_deleted->T3113);
 	llist_del(&to_be_deleted->entry);
 	subscr_put(to_be_deleted->subscr);
 	free(to_be_deleted);
@@ -158,7 +158,7 @@ static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_b
 	} while (paging_bts->available_slots > 0
 		    &&  initial_request != current_request);
 
-	schedule_timer(&paging_bts->work_timer, 1, 0);
+	bsc_schedule_timer(&paging_bts->work_timer, 1, 0);
 }
 
 static void paging_worker(void *data)
@@ -230,11 +230,11 @@ void paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
 	req->cbfn_param = data;
 	req->T3113.cb = paging_T3113_expired;
 	req->T3113.data = req;
-	schedule_timer(&req->T3113, T3113_VALUE);
+	bsc_schedule_timer(&req->T3113, T3113_VALUE);
 	llist_add_tail(&req->entry, &bts_entry->pending_requests);
 
-	if (!timer_pending(&bts_entry->work_timer))
-		schedule_timer(&bts_entry->work_timer, 1, 0);
+	if (!bsc_timer_pending(&bts_entry->work_timer))
+		bsc_schedule_timer(&bts_entry->work_timer, 1, 0);
 }
 
 /* we consciously ignore the type of the request here */
diff --git a/src/select.c b/src/select.c
index 925f339..335d386 100644
--- a/src/select.c
+++ b/src/select.c
@@ -75,13 +75,13 @@ int bsc_select_main()
 			FD_SET(ufd->fd, &exceptset);
 	}
 
-	prepare_timers();
-	i = select(maxfd+1, &readset, &writeset, &exceptset, nearest_timer());
+	_prepare_timers();
+	i = select(maxfd+1, &readset, &writeset, &exceptset, _nearest_timer());
 	if (i < 0)
 		return i;
 
 	/* fire timers */
-	update_timers();
+	_update_timers();
 
 	/* call registered callback functions */
 	llist_for_each_entry_safe(ufd, tmp, &bsc_fds, list) {
diff --git a/src/timer.c b/src/timer.c
index 3ec085b..c0f04df 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -31,7 +31,7 @@ static struct timeval s_select_time;
 #define TIME_SMALLER(left, right) \
         (left.tv_sec*MICRO_SECONDS+left.tv_usec) <= (right.tv_sec*MICRO_SECONDS+right.tv_usec)
 
-void add_timer(struct timer_list *timer)
+void bsc_add_timer(struct timer_list *timer)
 {
 	struct timer_list *list_timer;
 
@@ -47,7 +47,7 @@ void add_timer(struct timer_list *timer)
 	llist_add(&timer->entry, &timer_list);
 }
 
-void schedule_timer(struct timer_list *timer, int seconds, int microseconds)
+void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds)
 {
 	struct timeval current_time;
 
@@ -56,10 +56,10 @@ void schedule_timer(struct timer_list *timer, int seconds, int microseconds)
 	currentTime += seconds * MICRO_SECONDS + microseconds;
 	timer->timeout.tv_sec = currentTime / MICRO_SECONDS;
 	timer->timeout.tv_usec = currentTime % MICRO_SECONDS;
-	add_timer(timer);
+	bsc_add_timer(timer);
 }
 
-void del_timer(struct timer_list *timer)
+void bsc_del_timer(struct timer_list *timer)
 {
 	if (timer->in_list) {
 		timer->active = 0;
@@ -68,7 +68,7 @@ void del_timer(struct timer_list *timer)
 	}
 }
 
-int timer_pending(struct timer_list *timer)
+int bsc_timer_pending(struct timer_list *timer)
 {
 	return timer->active;
 }
@@ -79,7 +79,7 @@ int timer_pending(struct timer_list *timer)
  * If the nearest timer timed out return NULL and then we will
  * dispatch everything after the select
  */
-struct timeval *nearest_timer()
+struct timeval *_nearest_timer()
 {
 	struct timeval current_time;
 
@@ -106,7 +106,7 @@ struct timeval *nearest_timer()
 /*
  * Find the nearest time and update s_nearest_time
  */
-void prepare_timers()
+void _prepare_timers()
 {
 	struct timer_list *timer, *nearest_timer = NULL;
 	llist_for_each_entry(timer, &timer_list, entry) {
@@ -125,7 +125,7 @@ void prepare_timers()
 /*
  * fire all timers... and remove them
  */
-void update_timers()
+void _update_timers()
 {
 	struct timeval current_time;
 	struct timer_list *timer, *tmp;
@@ -164,7 +164,7 @@ restart:
 	llist_for_each_entry_safe(timer, tmp, &timer_list, entry) {
 		timer->handled = 0;
 		if (!timer->active) {
-			del_timer(timer);
+			bsc_del_timer(timer);
 		}
 	}
 }
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 3f5828b..339404e 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -45,8 +45,8 @@ static void timer_fired(unsigned long data)
     printf("Fired timer: %lu\n", data);
 
     if (data == 1) {
-        schedule_timer(&timer_one, 3, 0);
-        del_timer(&timer_two);
+        bsc_schedule_timer(&timer_one, 3, 0);
+        bsc_del_timer(&timer_two);
     } else if (data == 2) {
         printf("Should not be fired... bug in del_timer\n");
     } else if (data == 3) {
@@ -60,9 +60,9 @@ int main(int argc, char** argv)
 {
     printf("Starting... timer\n");
 
-    schedule_timer(&timer_one, 3, 0);
-    schedule_timer(&timer_two, 5, 0);
-    schedule_timer(&timer_three, 4, 0);
+    bsc_schedule_timer(&timer_one, 3, 0);
+    bsc_schedule_timer(&timer_two, 5, 0);
+    bsc_schedule_timer(&timer_three, 4, 0);
 
     while (1) {
         bsc_select_main();
-- 
1.6.0.4

