summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-06-30 11:03:07 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-07-19 20:07:20 +0200
commit3118191f59c066ec47e5e34c5ce28677b4351399 (patch)
tree61a4772be8143566ac6b4ff24bb000d32ac4f1f4
parentfa2218cbc90345fc2f4c9505cbfe48e8095a8b20 (diff)
osmo_bsc: Track the last three locations.
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_main.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 4ae37a1a9..69622bbe8 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -29,6 +29,7 @@
#include <openbsc/ipaccess.h>
#include <osmocom/core/application.h>
+#include <osmocom/core/linuxlist.h>
#include <osmocom/core/talloc.h>
#include <osmocom/gsm/protocol/gsm_12_21.h>
@@ -171,6 +172,7 @@ static void signal_handler(int signal)
}
struct location {
+ struct llist_head list;
unsigned long age;
int valid;
double lat;
@@ -178,12 +180,38 @@ struct location {
double height;
};
-static struct location myloc;
+static LLIST_HEAD(locations);
+
+void cleanup_locations()
+{
+ struct location *myloc, *tmp;
+ int i = 0;
+
+ LOGP(DCTRL, LOGL_DEBUG, "Checking position list.\n");
+ llist_for_each_entry_safe(myloc, tmp, &locations, list) {
+ i++;
+ if (i > 3) {
+ LOGP(DCTRL, LOGL_DEBUG, "Deleting old position.\n");
+ llist_del(&myloc->list);
+ talloc_free(myloc);
+ }
+ }
+ LOGP(DCTRL, LOGL_DEBUG, "Found %i positions.\n", i);
+}
CTRL_CMD_DEFINE(net_loc, "location");
int get_net_loc(struct ctrl_cmd *cmd, void *data)
{
- cmd->reply = talloc_asprintf(cmd, "%lu,%i,%f,%f,%f", myloc.age, myloc.valid, myloc.lat, myloc.lon, myloc.height);
+ struct location *myloc;
+
+ if (llist_empty(&locations)) {
+ cmd->reply = talloc_asprintf(cmd, "0,0,0,0,0");
+ return CTRL_CMD_REPLY;
+ } else {
+ myloc = llist_entry(locations.next, struct location, list);
+ }
+
+ cmd->reply = talloc_asprintf(cmd, "%lu,%i,%f,%f,%f", myloc->age, myloc->valid, myloc->lat, myloc->lon, myloc->height);
if (!cmd->reply) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
@@ -195,11 +223,19 @@ int get_net_loc(struct ctrl_cmd *cmd, void *data)
int set_net_loc(struct ctrl_cmd *cmd, void *data)
{
char *saveptr, *lat, *lon, *height, *age, *valid, *tmp;
+ struct location *myloc;
tmp = talloc_strdup(cmd, cmd->value);
if (!tmp)
goto oom;
+ myloc = talloc_zero(tall_bsc_ctx, struct location);
+ if (!myloc) {
+ talloc_free(tmp);
+ goto oom;
+ }
+ INIT_LLIST_HEAD(&myloc->list);
+
age = strtok_r(tmp, ",", &saveptr);
valid = strtok_r(NULL, ",", &saveptr);
@@ -207,13 +243,17 @@ int set_net_loc(struct ctrl_cmd *cmd, void *data)
lon = strtok_r(NULL, ",", &saveptr);
height = strtok_r(NULL, "\0", &saveptr);
- myloc.age = atol(age);
- myloc.valid = atoi(valid);
- myloc.lat = atof(lat);
- myloc.lon = atof(lon);
- myloc.height = atof(height);
+ myloc->age = atol(age);
+ myloc->valid = atoi(valid);
+ myloc->lat = atof(lat);
+ myloc->lon = atof(lon);
+ myloc->height = atof(height);
talloc_free(tmp);
+ /* Add location to the end of the list */
+ llist_add(&myloc->list, &locations);
+ cleanup_locations();
+
return get_net_loc(cmd, data);
oom:
cmd->reply = "OOM";