aboutsummaryrefslogtreecommitdiff
path: root/src/sensor/sensor_util_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sensor/sensor_util_lib.c')
-rw-r--r--src/sensor/sensor_util_lib.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/sensor/sensor_util_lib.c b/src/sensor/sensor_util_lib.c
index b77ba48fc..0302c2046 100644
--- a/src/sensor/sensor_util_lib.c
+++ b/src/sensor/sensor_util_lib.c
@@ -295,23 +295,26 @@ load_sensor_from_file(const char *filename)
295 return sensor; 295 return sensor;
296} 296}
297 297
298
298/** 299/**
299 * Compares version numbers of two sensors 300 * Given two version numbers as major and minor, compare them.
300 * 301 *
301 * @param s1 first sensor 302 * @param v1_major First part of first version number
302 * @param s2 second sensor 303 * @param v1_minor Second part of first version number
303 * @return 1: s1 > s2, 0: s1 == s2, -1: s1 < s2 304 * @param v2_major First part of second version number
305 * @param v2_minor Second part of second version number
304 */ 306 */
305static int 307int
306sensor_version_compare (struct GNUNET_SENSOR_SensorInfo *s1, 308GNUNET_SENSOR_version_compare (uint16_t v1_major, uint16_t v1_minor,
307 struct GNUNET_SENSOR_SensorInfo *s2) 309 uint16_t v2_major, uint16_t v2_minor)
308{ 310{
309 if (s1->version_major == s2->version_major) 311 if (v1_major == v2_major)
310 return (s1->version_minor < s2->version_minor) ? -1 : (s1->version_minor > s2->version_minor); 312 return (v1_minor < v2_minor) ? -1 : (v1_minor > v2_minor);
311 else 313 else
312 return (s1->version_major < s2->version_major) ? -1 : (s1->version_major > s2->version_major); 314 return (v1_major < v2_major) ? -1 : (v1_major > v2_major);
313} 315}
314 316
317
315/** 318/**
316 * Adds a new sensor to given hashmap. 319 * Adds a new sensor to given hashmap.
317 * If the same name exist, compares versions and update if old. 320 * If the same name exist, compares versions and update if old.
@@ -332,7 +335,10 @@ add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor,
332 existing = GNUNET_CONTAINER_multihashmap_get(map, &key); 335 existing = GNUNET_CONTAINER_multihashmap_get(map, &key);
333 if(NULL != existing) //sensor with same name already exists 336 if(NULL != existing) //sensor with same name already exists
334 { 337 {
335 if(sensor_version_compare(existing, sensor) >= 0) //same or newer version already exist 338 if(GNUNET_SENSOR_version_compare (existing->version_major,
339 existing->version_minor,
340 sensor->version_major,
341 sensor->version_minor) >= 0)
336 { 342 {
337 LOG (GNUNET_ERROR_TYPE_INFO, 343 LOG (GNUNET_ERROR_TYPE_INFO,
338 _("Sensor `%s' already exists with same or newer version\n"), 344 _("Sensor `%s' already exists with same or newer version\n"),
@@ -389,9 +395,10 @@ reload_sensors_dir_cb(void *cls, const char *filename)
389} 395}
390 396
391/* 397/*
392 * Get path to the directory containing the sensor definition files 398 * Get path to the directory containing the sensor definition files with a
399 * trailing directory separator.
393 * 400 *
394 * @return sensor files directory 401 * @return sensor files directory full path
395 */ 402 */
396char * 403char *
397GNUNET_SENSOR_get_sensor_dir () 404GNUNET_SENSOR_get_sensor_dir ()
@@ -400,8 +407,10 @@ GNUNET_SENSOR_get_sensor_dir ()
400 char* sensordir; 407 char* sensordir;
401 408
402 datadir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); 409 datadir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR);
403 GNUNET_asprintf(&sensordir, "%ssensors%s", 410 GNUNET_asprintf (&sensordir,
404 datadir, DIR_SEPARATOR_STR); 411 "%ssensors%s",
412 datadir,
413 DIR_SEPARATOR_STR);
405 GNUNET_free(datadir); 414 GNUNET_free(datadir);
406 415
407 return sensordir; 416 return sensordir;