From: Pablo Neira Ayuso pablo@gnumonks.org
Hi!
This is the first patchset that fixes the namespace pollution in libosmocore.
You can find in the patch description the sed regular expression to automate the replacement of the function/structure names, e.g:
s/struct counter/struct osmo_counter/g s/counter_inc/osmo_counter_inc/g s/counter_get/osmo_counter_get/g s/counter_reset/osmo_counter_reset/g s/counter_alloc/osmo_counter_alloc/g s/counter_free/osmo_counter_free
You can use the following script:
cat /tmp/replace.txt | while read REPLACE do echo "performing sed "$REPLACE"..." find ./ -type f -exec sed -i "$REPLACE" {} ; done
The /tmp/replace.txt file have to contain the list of sed regular expressions, one per line. Thus, you can get in sync your branches in a couple of minutes.
The entire list of changes in this patchset is the following:
s/struct timer_list/struct osmo_timer_list/g s/bsc_add_timer/osmo_timer_add/g s/bsc_schedule_timer/osmo_timer_schedule/g s/bsc_del_timer/osmo_timer_del/g s/bsc_timer_pending/osmo_timer_pending/g s/bsc_nearest_timer/osmo_timers_nearest/g s/bsc_prepare_timers/osmo_timers_prepare/g s/bsc_update_timers/osmo_timers_update/g s/bsc_timer_check/osmo_timers_check/g s/struct bsc_fd/struct osmo_fd/g s/bsc_register_fd/osmo_fd_register/g s/bsc_unregister_fd/osmo_fd_unregister/g s/bsc_select_main/osmo_select_main/g s/signal_cbfn/osmo_signal_cbfn/g s/register_signal_handler/osmo_signal_register_handler/g s/unregister_signal_handler/osmo_signal_unregister_handler/g s/dispatch_signal/osmo_signal_dispatch/g s/struct write_queue/struct osmo_wqueue/g s/write_queue_init/osmo_wqueue_init/g s/write_queue_clear/osmo_wqueue_clear/g s/write_queue_enqueue/osmo_wqueue_enqueue/g s/write_queue_bfd_cb/osmo_wqueue_bfd_cb/g s/struct counter/struct osmo_counter/g s/counter_inc/osmo_counter_inc/g s/counter_get/osmo_counter_get/g s/counter_reset/osmo_counter_reset/g s/counter_alloc/osmo_counter_alloc/g s/counter_free/osmo_counter_free/g
You can find it in the pablo/namespace branch. Please, merge it!
Pablo Neira Ayuso (5): timer: use namespace prefix osmo_timer* select: use namespace prefix osmo_fd* and osmo_select* signal: use namespace prefix osmo_signal* write-queue: use namespace prefix osmo_wqueue* statistics: use namespace prefix osmo_counter*
include/osmocom/core/select.h | 10 +++++----- include/osmocom/core/signal.h | 15 +++++++-------- include/osmocom/core/statistics.h | 16 ++++++++-------- include/osmocom/core/timer.h | 20 ++++++++++---------- include/osmocom/core/write_queue.h | 22 +++++++++++----------- include/osmocom/vty/telnet_interface.h | 2 +- src/gsmtap_util.c | 12 ++++++------ src/rate_ctr.c | 6 +++--- src/select.c | 30 +++++++++++++++--------------- src/signal.c | 11 +++++++---- src/statistics.c | 15 ++++++++------- src/timer.c | 29 +++++++++++++++-------------- src/vty/telnet_interface.c | 18 +++++++++--------- src/write_queue.c | 14 +++++++------- tests/timer/timer_test.c | 18 +++++++++--------- 15 files changed, 121 insertions(+), 117 deletions(-)
From: Pablo Neira Ayuso pablo@gnumonks.org
Summary of changes:
s/struct timer_list/struct osmo_timer_list/g s/bsc_add_timer/osmo_timer_add/g s/bsc_schedule_timer/osmo_timer_schedule/g s/bsc_del_timer/osmo_timer_del/g s/bsc_timer_pending/osmo_timer_pending/g s/bsc_nearest_timer/osmo_timers_nearest/g s/bsc_prepare_timers/osmo_timers_prepare/g s/bsc_update_timers/osmo_timers_update/g s/bsc_timer_check/osmo_timers_check/g --- include/osmocom/core/timer.h | 20 ++++++++++---------- src/rate_ctr.c | 6 +++--- src/select.c | 8 ++++---- src/timer.c | 29 +++++++++++++++-------------- tests/timer/timer_test.c | 16 ++++++++-------- 5 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/include/osmocom/core/timer.h b/include/osmocom/core/timer.h index 1966478..db2ecbf 100644 --- a/include/osmocom/core/timer.h +++ b/include/osmocom/core/timer.h @@ -27,7 +27,7 @@
/** * Timer management: - * - Create a struct timer_list + * - Create a struct osmo_timer_list * - Fill out timeout and use add_timer or * use schedule_timer to schedule a timer in * x seconds and microseconds from now... @@ -41,7 +41,7 @@ * the timers. * */ -struct timer_list { +struct osmo_timer_list { struct llist_head entry; struct timeval timeout; unsigned int active : 1; @@ -55,18 +55,18 @@ struct timer_list { /** * timer management */ -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); +void osmo_timer_add(struct osmo_timer_list *timer); +void osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds); +void osmo_timer_del(struct osmo_timer_list *timer); +int osmo_timer_pending(struct osmo_timer_list *timer);
/** * internal timer list management */ -struct timeval *bsc_nearest_timer(); -void bsc_prepare_timers(); -int bsc_update_timers(); -int bsc_timer_check(void); +struct timeval *osmo_timers_nearest(); +void osmo_timers_prepare(); +int osmo_timers_update(); +int osmo_timers_check(void);
#endif diff --git a/src/rate_ctr.c b/src/rate_ctr.c index a0e1814..6d771a4 100644 --- a/src/rate_ctr.c +++ b/src/rate_ctr.c @@ -82,7 +82,7 @@ static void interval_expired(struct rate_ctr *ctr, enum rate_ctr_intv intv) ctr->intv[intv+1].rate += ctr->intv[intv].rate; }
-static struct timer_list rate_ctr_timer; +static struct osmo_timer_list rate_ctr_timer; static uint64_t timer_ticks;
/* The one-second interval has expired */ @@ -114,14 +114,14 @@ static void rate_ctr_timer_cb(void *data) llist_for_each_entry(ctrg, &rate_ctr_groups, list) rate_ctr_group_intv(ctrg);
- bsc_schedule_timer(&rate_ctr_timer, 1, 0); + osmo_timer_schedule(&rate_ctr_timer, 1, 0); }
int rate_ctr_init(void *tall_ctx) { tall_rate_ctr_ctx = tall_ctx; rate_ctr_timer.cb = rate_ctr_timer_cb; - bsc_schedule_timer(&rate_ctr_timer, 1, 0); + osmo_timer_schedule(&rate_ctr_timer, 1, 0);
return 0; } diff --git a/src/select.c b/src/select.c index adf3619..6c44f35 100644 --- a/src/select.c +++ b/src/select.c @@ -95,16 +95,16 @@ int bsc_select_main(int polling) FD_SET(ufd->fd, &exceptset); }
- bsc_timer_check(); + osmo_timers_check();
if (!polling) - bsc_prepare_timers(); - rc = select(maxfd+1, &readset, &writeset, &exceptset, polling ? &no_time : bsc_nearest_timer()); + osmo_timers_prepare(); + rc = select(maxfd+1, &readset, &writeset, &exceptset, polling ? &no_time : osmo_timers_nearest()); if (rc < 0) return 0;
/* fire timers */ - bsc_update_timers(); + osmo_timers_update();
/* call registered callback functions */ restart: diff --git a/src/timer.c b/src/timer.c index 9b2dd9e..ec75212 100644 --- a/src/timer.c +++ b/src/timer.c @@ -31,9 +31,9 @@ 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 bsc_add_timer(struct timer_list *timer) +void osmo_timer_add(struct osmo_timer_list *timer) { - struct timer_list *list_timer; + struct osmo_timer_list *list_timer;
/* TODO: Optimize and remember the closest item... */ timer->active = 1; @@ -47,7 +47,8 @@ void bsc_add_timer(struct timer_list *timer) llist_add(&timer->entry, &timer_list); }
-void bsc_schedule_timer(struct timer_list *timer, int seconds, int microseconds) +void +osmo_timer_schedule(struct osmo_timer_list *timer, int seconds, int microseconds) { struct timeval current_time;
@@ -56,10 +57,10 @@ void bsc_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; - bsc_add_timer(timer); + osmo_timer_add(timer); }
-void bsc_del_timer(struct timer_list *timer) +void osmo_timer_del(struct osmo_timer_list *timer) { if (timer->in_list) { timer->active = 0; @@ -68,7 +69,7 @@ void bsc_del_timer(struct timer_list *timer) } }
-int bsc_timer_pending(struct timer_list *timer) +int osmo_timer_pending(struct osmo_timer_list *timer) { return timer->active; } @@ -79,7 +80,7 @@ int bsc_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 *bsc_nearest_timer() +struct timeval *osmo_timers_nearest() { struct timeval current_time;
@@ -106,9 +107,9 @@ struct timeval *bsc_nearest_timer() /* * Find the nearest time and update s_nearest_time */ -void bsc_prepare_timers() +void osmo_timers_prepare() { - struct timer_list *timer, *nearest_timer = NULL; + struct osmo_timer_list *timer, *nearest_timer = NULL; llist_for_each_entry(timer, &timer_list, entry) { if (!nearest_timer || TIME_SMALLER(timer->timeout, nearest_timer->timeout)) { nearest_timer = timer; @@ -125,10 +126,10 @@ void bsc_prepare_timers() /* * fire all timers... and remove them */ -int bsc_update_timers() +int osmo_timers_update() { struct timeval current_time; - struct timer_list *timer, *tmp; + struct osmo_timer_list *timer, *tmp; int work = 0;
gettimeofday(¤t_time, NULL); @@ -166,16 +167,16 @@ restart: llist_for_each_entry_safe(timer, tmp, &timer_list, entry) { timer->handled = 0; if (!timer->active) { - bsc_del_timer(timer); + osmo_timer_del(timer); } }
return work; }
-int bsc_timer_check(void) +int osmo_timers_check(void) { - struct timer_list *timer; + struct osmo_timer_list *timer; int i = 0;
llist_for_each_entry(timer, &timer_list, entry) { diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index 30b08ad..69bcad9 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -27,17 +27,17 @@
static void timer_fired(void *data);
-static struct timer_list timer_one = { +static struct osmo_timer_list timer_one = { .cb = timer_fired, .data = (void*)1, };
-static struct timer_list timer_two = { +static struct osmo_timer_list timer_two = { .cb = timer_fired, .data = (void*)2, };
-static struct timer_list timer_three = { +static struct osmo_timer_list timer_three = { .cb = timer_fired, .data = (void*)3, }; @@ -48,8 +48,8 @@ static void timer_fired(void *_data) printf("Fired timer: %lu\n", data);
if (data == 1) { - bsc_schedule_timer(&timer_one, 3, 0); - bsc_del_timer(&timer_two); + osmo_timer_schedule(&timer_one, 3, 0); + osmo_timer_del(&timer_two); } else if (data == 2) { printf("Should not be fired... bug in del_timer\n"); } else if (data == 3) { @@ -63,9 +63,9 @@ int main(int argc, char** argv) { printf("Starting... timer\n");
- bsc_schedule_timer(&timer_one, 3, 0); - bsc_schedule_timer(&timer_two, 5, 0); - bsc_schedule_timer(&timer_three, 4, 0); + osmo_timer_schedule(&timer_one, 3, 0); + osmo_timer_schedule(&timer_two, 5, 0); + osmo_timer_schedule(&timer_three, 4, 0);
#ifdef HAVE_SYS_SELECT_H while (1) {
From: Pablo Neira Ayuso pablo@gnumonks.org
Summary of changes:
s/struct bsc_fd/struct osmo_fd/g s/bsc_register_fd/osmo_fd_register/g s/bsc_unregister_fd/osmo_fd_unregister/g s/bsc_select_main/osmo_select_main/g --- include/osmocom/core/select.h | 10 +++++----- include/osmocom/core/write_queue.h | 10 +++++----- include/osmocom/vty/telnet_interface.h | 2 +- src/gsmtap_util.c | 12 ++++++------ src/select.c | 22 +++++++++++----------- src/vty/telnet_interface.c | 18 +++++++++--------- src/write_queue.c | 2 +- tests/timer/timer_test.c | 2 +- 8 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h index 5ca21c3..476c564 100644 --- a/include/osmocom/core/select.h +++ b/include/osmocom/core/select.h @@ -7,16 +7,16 @@ #define BSC_FD_WRITE 0x0002 #define BSC_FD_EXCEPT 0x0004
-struct bsc_fd { +struct osmo_fd { struct llist_head list; int fd; unsigned int when; - int (*cb)(struct bsc_fd *fd, unsigned int what); + int (*cb)(struct osmo_fd *fd, unsigned int what); void *data; unsigned int priv_nr; };
-int bsc_register_fd(struct bsc_fd *fd); -void bsc_unregister_fd(struct bsc_fd *fd); -int bsc_select_main(int polling); +int osmo_fd_register(struct osmo_fd *fd); +void osmo_fd_unregister(struct osmo_fd *fd); +int osmo_select_main(int polling); #endif /* _BSC_SELECT_H */ diff --git a/include/osmocom/core/write_queue.h b/include/osmocom/core/write_queue.h index 3b730c7..8d360cb 100644 --- a/include/osmocom/core/write_queue.h +++ b/include/osmocom/core/write_queue.h @@ -27,20 +27,20 @@ #include <osmocom/core/msgb.h>
struct write_queue { - struct bsc_fd bfd; + struct osmo_fd bfd; unsigned int max_length; unsigned int current_length;
struct llist_head msg_queue;
- int (*read_cb)(struct bsc_fd *fd); - int (*write_cb)(struct bsc_fd *fd, struct msgb *msg); - int (*except_cb)(struct bsc_fd *fd); + int (*read_cb)(struct osmo_fd *fd); + int (*write_cb)(struct osmo_fd *fd, struct msgb *msg); + int (*except_cb)(struct osmo_fd *fd); };
void write_queue_init(struct write_queue *queue, int max_length); void write_queue_clear(struct write_queue *queue); int write_queue_enqueue(struct write_queue *queue, struct msgb *data); -int write_queue_bfd_cb(struct bsc_fd *fd, unsigned int what); +int write_queue_bfd_cb(struct osmo_fd *fd, unsigned int what);
#endif diff --git a/include/osmocom/vty/telnet_interface.h b/include/osmocom/vty/telnet_interface.h index 0c034e4..1d8055e 100644 --- a/include/osmocom/vty/telnet_interface.h +++ b/include/osmocom/vty/telnet_interface.h @@ -29,7 +29,7 @@ struct telnet_connection { struct llist_head entry; void *priv; - struct bsc_fd fd; + struct osmo_fd fd; struct vty *vty; struct log_target *dbg; }; diff --git a/src/gsmtap_util.c b/src/gsmtap_util.c index b47f6e3..e0bc848 100644 --- a/src/gsmtap_util.c +++ b/src/gsmtap_util.c @@ -42,8 +42,8 @@ #include <string.h> #include <errno.h>
-static struct bsc_fd gsmtap_bfd = { .fd = -1 }; -static struct bsc_fd gsmtap_sink_bfd = { .fd = -1 }; +static struct osmo_fd gsmtap_bfd = { .fd = -1 }; +static struct osmo_fd gsmtap_sink_bfd = { .fd = -1 }; static LLIST_HEAD(gsmtap_txqueue);
uint8_t chantype_rsl2gsmtap(uint8_t rsl_chantype, uint8_t link_id) @@ -137,7 +137,7 @@ int gsmtap_sendmsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type, uint8_t ss, }
/* Callback from select layer if we can write to the socket */ -static int gsmtap_fd_cb(struct bsc_fd *fd, unsigned int flags) +static int gsmtap_fd_cb(struct osmo_fd *fd, unsigned int flags) { struct msgb *msg; int rc; @@ -195,11 +195,11 @@ int gsmtap_init(uint32_t dst_ip) gsmtap_bfd.cb = gsmtap_fd_cb; gsmtap_bfd.data = NULL;
- return bsc_register_fd(&gsmtap_bfd); + return osmo_fd_register(&gsmtap_bfd); }
/* Callback from select layer if we can read from the sink socket */ -static int gsmtap_sink_fd_cb(struct bsc_fd *fd, unsigned int flags) +static int gsmtap_sink_fd_cb(struct osmo_fd *fd, unsigned int flags) { int rc; uint8_t buf[4096]; @@ -246,7 +246,7 @@ int gsmtap_sink_init(uint32_t bind_ip) gsmtap_sink_bfd.cb = gsmtap_sink_fd_cb; gsmtap_sink_bfd.data = NULL;
- return bsc_register_fd(&gsmtap_sink_bfd); + return osmo_fd_register(&gsmtap_sink_bfd);
}
diff --git a/src/select.c b/src/select.c index 6c44f35..4ea9536 100644 --- a/src/select.c +++ b/src/select.c @@ -31,10 +31,10 @@ #ifdef HAVE_SYS_SELECT_H
static int maxfd = 0; -static LLIST_HEAD(bsc_fds); +static LLIST_HEAD(osmo_fds); static int unregistered_count;
-int bsc_register_fd(struct bsc_fd *fd) +int osmo_fd_register(struct osmo_fd *fd) { int flags;
@@ -52,29 +52,29 @@ int bsc_register_fd(struct bsc_fd *fd) maxfd = fd->fd;
#ifdef BSC_FD_CHECK - struct bsc_fd *entry; - llist_for_each_entry(entry, &bsc_fds, list) { + struct osmo_fd *entry; + llist_for_each_entry(entry, &osmo_fds, list) { if (entry == fd) { - fprintf(stderr, "Adding a bsc_fd that is already in the list.\n"); + fprintf(stderr, "Adding a osmo_fd that is already in the list.\n"); return 0; } } #endif
- llist_add_tail(&fd->list, &bsc_fds); + llist_add_tail(&fd->list, &osmo_fds);
return 0; }
-void bsc_unregister_fd(struct bsc_fd *fd) +void osmo_fd_unregister(struct osmo_fd *fd) { unregistered_count++; llist_del(&fd->list); }
-int bsc_select_main(int polling) +int osmo_select_main(int polling) { - struct bsc_fd *ufd, *tmp; + struct osmo_fd *ufd, *tmp; fd_set readset, writeset, exceptset; int work = 0, rc; struct timeval no_time = {0, 0}; @@ -84,7 +84,7 @@ int bsc_select_main(int polling) FD_ZERO(&exceptset);
/* prepare read and write fdsets */ - llist_for_each_entry(ufd, &bsc_fds, list) { + llist_for_each_entry(ufd, &osmo_fds, list) { if (ufd->when & BSC_FD_READ) FD_SET(ufd->fd, &readset);
@@ -109,7 +109,7 @@ int bsc_select_main(int polling) /* call registered callback functions */ restart: unregistered_count = 0; - llist_for_each_entry_safe(ufd, tmp, &bsc_fds, list) { + llist_for_each_entry_safe(ufd, tmp, &osmo_fds, list) { int flags = 0;
if (FD_ISSET(ufd->fd, &readset)) { diff --git a/src/vty/telnet_interface.c b/src/vty/telnet_interface.c index 0d45d61..7845994 100644 --- a/src/vty/telnet_interface.c +++ b/src/vty/telnet_interface.c @@ -39,9 +39,9 @@ LLIST_HEAD(active_connections); static void *tall_telnet_ctx;
/* per network data */ -static int telnet_new_connection(struct bsc_fd *fd, unsigned int what); +static int telnet_new_connection(struct osmo_fd *fd, unsigned int what);
-static struct bsc_fd server_socket = { +static struct osmo_fd server_socket = { .when = BSC_FD_READ, .cb = telnet_new_connection, .priv_nr = 0, @@ -85,7 +85,7 @@ int telnet_init(void *tall_ctx, void *priv, int port)
server_socket.data = priv; server_socket.fd = fd; - bsc_register_fd(&server_socket); + osmo_fd_register(&server_socket);
return 0; } @@ -104,12 +104,12 @@ static void print_welcome(int fd) ret = write(fd, host.app_info->copyright, strlen(host.app_info->copyright)); }
-int telnet_close_client(struct bsc_fd *fd) +int telnet_close_client(struct osmo_fd *fd) { struct telnet_connection *conn = (struct telnet_connection*)fd->data;
close(fd->fd); - bsc_unregister_fd(fd); + osmo_fd_unregister(fd);
if (conn->dbg) { log_del_target(conn->dbg); @@ -121,7 +121,7 @@ int telnet_close_client(struct bsc_fd *fd) return 0; }
-static int client_data(struct bsc_fd *fd, unsigned int what) +static int client_data(struct osmo_fd *fd, unsigned int what) { struct telnet_connection *conn = fd->data; int rc = 0; @@ -144,7 +144,7 @@ static int client_data(struct bsc_fd *fd, unsigned int what) return rc; }
-static int telnet_new_connection(struct bsc_fd *fd, unsigned int what) +static int telnet_new_connection(struct osmo_fd *fd, unsigned int what) { struct telnet_connection *connection; struct sockaddr_in sockaddr; @@ -162,7 +162,7 @@ static int telnet_new_connection(struct bsc_fd *fd, unsigned int what) connection->fd.fd = new_connection; connection->fd.when = BSC_FD_READ; connection->fd.cb = client_data; - bsc_register_fd(&connection->fd); + osmo_fd_register(&connection->fd); llist_add_tail(&connection->entry, &active_connections);
print_welcome(new_connection); @@ -182,7 +182,7 @@ static int telnet_new_connection(struct bsc_fd *fd, unsigned int what) void vty_event(enum event event, int sock, struct vty *vty) { struct telnet_connection *connection = vty->priv; - struct bsc_fd *bfd = &connection->fd; + struct osmo_fd *bfd = &connection->fd;
if (vty->type != VTY_TERM) return; diff --git a/src/write_queue.c b/src/write_queue.c index 0642aad..c357c3f 100644 --- a/src/write_queue.c +++ b/src/write_queue.c @@ -23,7 +23,7 @@
#include <osmocom/core/write_queue.h>
-int write_queue_bfd_cb(struct bsc_fd *fd, unsigned int what) +int write_queue_bfd_cb(struct osmo_fd *fd, unsigned int what) { struct write_queue *queue;
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index 69bcad9..240bc48 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -69,7 +69,7 @@ int main(int argc, char** argv)
#ifdef HAVE_SYS_SELECT_H while (1) { - bsc_select_main(0); + osmo_select_main(0); } #else printf("Select not supported on this platform!\n");
From: Pablo Neira Ayuso pablo@gnumonks.org
Summary of changes:
s/signal_cbfn/osmo_signal_cbfn/g s/register_signal_handler/osmo_signal_register_handler/g s/unregister_signal_handler/osmo_signal_unregister_handler/g s/dispatch_signal/osmo_signal_dispatch/g --- include/osmocom/core/signal.h | 15 +++++++-------- src/signal.c | 11 +++++++---- 2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/include/osmocom/core/signal.h b/include/osmocom/core/signal.h index 02d83d2..535fd18 100644 --- a/include/osmocom/core/signal.h +++ b/include/osmocom/core/signal.h @@ -1,15 +1,14 @@ -#ifndef OSMOCORE_SIGNAL_H -#define OSMOCORE_SIGNAL_H +#ifndef OSMO_SIGNAL_H +#define OSMO_SIGNAL_H
-typedef int signal_cbfn(unsigned int subsys, unsigned int signal, - void *handler_data, void *signal_data); +typedef int osmo_signal_cbfn(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data);
/* Management */ -int register_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data); -void unregister_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data); +int osmo_signal_register_handler(unsigned int subsys, osmo_signal_cbfn *cbfn, void *data); +void osmo_signal_unregister_handler(unsigned int subsys, osmo_signal_cbfn *cbfn, void *data);
/* Dispatch */ -void dispatch_signal(unsigned int subsys, unsigned int signal, void *signal_data); +void osmo_signal_dispatch(unsigned int subsys, unsigned int signal, void *signal_data);
-#endif /* OSMOCORE_SIGNAL_H */ +#endif /* OSMO_SIGNAL_H */ diff --git a/src/signal.c b/src/signal.c index bb5c38e..bc339bb 100644 --- a/src/signal.c +++ b/src/signal.c @@ -31,12 +31,13 @@ static LLIST_HEAD(signal_handler_list); struct signal_handler { struct llist_head entry; unsigned int subsys; - signal_cbfn *cbfn; + osmo_signal_cbfn *cbfn; void *data; };
-int register_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data) +int osmo_signal_register_handler(unsigned int subsys, + osmo_signal_cbfn *cbfn, void *data) { struct signal_handler *sig_data;
@@ -57,7 +58,8 @@ int register_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data) return 0; }
-void unregister_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *data) +void osmo_signal_unregister_handler(unsigned int subsys, + osmo_signal_cbfn *cbfn, void *data) { struct signal_handler *handler;
@@ -72,7 +74,8 @@ void unregister_signal_handler(unsigned int subsys, signal_cbfn *cbfn, void *dat }
-void dispatch_signal(unsigned int subsys, unsigned int signal, void *signal_data) +void osmo_signal_dispatch(unsigned int subsys, unsigned int signal, + void *signal_data) { struct signal_handler *handler;
From: Pablo Neira Ayuso pablo@gnumonks.org
Summary of changes:
s/struct write_queue/struct osmo_wqueue/g s/write_queue_init/osmo_wqueue_init/g s/write_queue_clear/osmo_wqueue_clear/g s/write_queue_enqueue/osmo_wqueue_enqueue/g s/write_queue_bfd_cb/osmo_wqueue_bfd_cb/g --- include/osmocom/core/write_queue.h | 14 +++++++------- src/write_queue.c | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/osmocom/core/write_queue.h b/include/osmocom/core/write_queue.h index 8d360cb..41748d7 100644 --- a/include/osmocom/core/write_queue.h +++ b/include/osmocom/core/write_queue.h @@ -20,13 +20,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ -#ifndef write_queue_h -#define write_queue_h +#ifndef OSMO_WQUEUE_H +#define OSMO_WQUEUE_H
#include <osmocom/core/select.h> #include <osmocom/core/msgb.h>
-struct write_queue { +struct osmo_wqueue { struct osmo_fd bfd; unsigned int max_length; unsigned int current_length; @@ -38,9 +38,9 @@ struct write_queue { int (*except_cb)(struct osmo_fd *fd); };
-void write_queue_init(struct write_queue *queue, int max_length); -void write_queue_clear(struct write_queue *queue); -int write_queue_enqueue(struct write_queue *queue, struct msgb *data); -int write_queue_bfd_cb(struct osmo_fd *fd, unsigned int what); +void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length); +void osmo_wqueue_clear(struct osmo_wqueue *queue); +int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data); +int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what);
#endif diff --git a/src/write_queue.c b/src/write_queue.c index c357c3f..a592104 100644 --- a/src/write_queue.c +++ b/src/write_queue.c @@ -23,11 +23,11 @@
#include <osmocom/core/write_queue.h>
-int write_queue_bfd_cb(struct osmo_fd *fd, unsigned int what) +int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what) { - struct write_queue *queue; + struct osmo_wqueue *queue;
- queue = container_of(fd, struct write_queue, bfd); + queue = container_of(fd, struct osmo_wqueue, bfd);
if (what & BSC_FD_READ) queue->read_cb(fd); @@ -56,17 +56,17 @@ int write_queue_bfd_cb(struct osmo_fd *fd, unsigned int what) return 0; }
-void write_queue_init(struct write_queue *queue, int max_length) +void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length) { queue->max_length = max_length; queue->current_length = 0; queue->read_cb = NULL; queue->write_cb = NULL; - queue->bfd.cb = write_queue_bfd_cb; + queue->bfd.cb = osmo_wqueue_bfd_cb; INIT_LLIST_HEAD(&queue->msg_queue); }
-int write_queue_enqueue(struct write_queue *queue, struct msgb *data) +int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data) { // if (queue->current_length + 1 >= queue->max_length) // LOGP(DMSC, LOGL_ERROR, "The queue is full. Dropping not yet implemented.\n"); @@ -78,7 +78,7 @@ int write_queue_enqueue(struct write_queue *queue, struct msgb *data) return 0; }
-void write_queue_clear(struct write_queue *queue) +void osmo_wqueue_clear(struct osmo_wqueue *queue) { while (!llist_empty(&queue->msg_queue)) { struct msgb *msg = msgb_dequeue(&queue->msg_queue);
From: Pablo Neira Ayuso pablo@gnumonks.org
Summary of changes:
s/struct counter/struct osmo_counter/g s/counter_inc/osmo_counter_inc/g s/counter_get/osmo_counter_get/g s/counter_reset/osmo_counter_reset/g s/counter_alloc/osmo_counter_alloc/g s/counter_free/osmo_counter_free/g s/counters_for_each/osmo_counters_for_each/g --- include/osmocom/core/statistics.h | 16 ++++++++-------- src/statistics.c | 15 ++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/include/osmocom/core/statistics.h b/include/osmocom/core/statistics.h index 2c15965..1849327 100644 --- a/include/osmocom/core/statistics.h +++ b/include/osmocom/core/statistics.h @@ -1,33 +1,33 @@ #ifndef _STATISTICS_H #define _STATISTICS_H
-struct counter { +struct osmo_counter { struct llist_head list; const char *name; const char *description; unsigned long value; };
-static inline void counter_inc(struct counter *ctr) +static inline void osmo_counter_inc(struct osmo_counter *ctr) { ctr->value++; }
-static inline unsigned long counter_get(struct counter *ctr) +static inline unsigned long osmo_counter_get(struct osmo_counter *ctr) { return ctr->value; }
-static inline void counter_reset(struct counter *ctr) +static inline void osmo_counter_reset(struct osmo_counter *ctr) { ctr->value = 0; }
-struct counter *counter_alloc(const char *name); -void counter_free(struct counter *ctr); +struct osmo_counter *osmo_counter_alloc(const char *name); +void osmo_counter_free(struct osmo_counter *ctr);
-int counters_for_each(int (*handle_counter)(struct counter *, void *), void *data); +int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
-struct counter *counter_get_by_name(const char *name); +struct osmo_counter *osmo_counter_get_by_name(const char *name);
#endif /* _STATISTICS_H */ diff --git a/src/statistics.c b/src/statistics.c index 83bb6ed..e28541b 100644 --- a/src/statistics.c +++ b/src/statistics.c @@ -30,9 +30,9 @@ static LLIST_HEAD(counters);
void *tall_ctr_ctx;
-struct counter *counter_alloc(const char *name) +struct osmo_counter *osmo_counter_alloc(const char *name) { - struct counter *ctr = talloc_zero(tall_ctr_ctx, struct counter); + struct osmo_counter *ctr = talloc_zero(tall_ctr_ctx, struct osmo_counter);
if (!ctr) return NULL; @@ -43,15 +43,16 @@ struct counter *counter_alloc(const char *name) return ctr; }
-void counter_free(struct counter *ctr) +void osmo_counter_free(struct osmo_counter *ctr) { llist_del(&ctr->list); talloc_free(ctr); }
-int counters_for_each(int (*handle_counter)(struct counter *, void *), void *data) +int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), + void *data) { - struct counter *ctr; + struct osmo_counter *ctr; int rc = 0;
llist_for_each_entry(ctr, &counters, list) { @@ -63,9 +64,9 @@ int counters_for_each(int (*handle_counter)(struct counter *, void *), void *dat return rc; }
-struct counter *counter_get_by_name(const char *name) +struct osmo_counter *osmo_counter_get_by_name(const char *name) { - struct counter *ctr; + struct osmo_counter *ctr;
llist_for_each_entry(ctr, &counters, list) { if (!strcmp(ctr->name, name))
Hi Pablo,
On Fri, May 06, 2011 at 12:28:04PM +0200, pablo@gnumonks.org wrote:
This is the first patchset that fixes the namespace pollution in libosmocore.
thanks.
You can find in the patch description the sed regular expression to automate the replacement of the function/structure names, e.g:
great idea.
You can find it in the pablo/namespace branch. Please, merge it!
Ok, I have checked the 'nm' output of current libosmocore.a of that branch, and the only functions without an osmo_ prefix are:
msgb_* (which is ok) bitvec_* (which is ok, too) log_* (i guess ok, too) gsmtap_* (which is ok) talloc_* (which is ok) rate_ctr_* (which is ok) chantype_rsl2gsmtap (ok) get_string_value/get_value_string (ok)
However, there are seome others. Pablo, can you please also prefix those: bcd2char, char2bcd crc16 generate_backtrace plugin_load_all
Once this has been resolved, I will merge your branch.
We should also make a first official libosmocore release soon, and from now on make sure we keep binary (ABI) compatibility within the autotools library versioning rules. As a second step, we can try to get the library included in Debian and other distros.
Finally, we have one remaining issue: msg_entry_parse
I think msg / msgb are a bit too close and they don't do anything related. Maybe we can come up with a different name, possibly including the osmo_ prefix? Holger?
Regards, Harald
On 05/06/2011 01:39 PM, Harald Welte wrote:
I think msg / msgb are a bit too close and they don't do anything related. Maybe we can come up with a different name, possibly including the osmo_ prefix? Holger?
Good question... the file is a very limited (fixed amount of columns) CSV like list. osmo_config_list? osmo_simple_config_list? any other ideas?
holger
On 06/05/11 13:39, Harald Welte wrote:
Ok, I have checked the 'nm' output of current libosmocore.a of that branch, and the only functions without an osmo_ prefix are:
msgb_* (which is ok) bitvec_* (which is ok, too) log_* (i guess ok, too) gsmtap_* (which is ok) talloc_* (which is ok) rate_ctr_* (which is ok) chantype_rsl2gsmtap (ok) get_string_value/get_value_string (ok)
However, there are seome others. Pablo, can you please also prefix those: bcd2char, char2bcd crc16 generate_backtrace plugin_load_all
Once this has been resolved, I will merge your branch.
I have also fixed this.
You can find the patches in the mailing list and all the changes in pablo/namespace branch.
We should also make a first official libosmocore release soon, and from now on make sure we keep binary (ABI) compatibility within the autotools library versioning rules. As a second step, we can try to get the library included in Debian and other distros.
I'll make a patch to make libosmocore use:
* EXPORT_SYMBOL * a .map file with exported symbols and versions * use libversion (we only have to use revisions field, current and aging field should never be used)
I'll document the way of working, of course.
Finally, we have one remaining issue: msg_entry_parse
I think msg / msgb are a bit too close and they don't do anything related. Maybe we can come up with a different name, possibly including the osmo_ prefix? Holger?
I have used osmo_config_list and osmo_config_entry for this, as suggested by Holger.