aboutsummaryrefslogtreecommitdiff
path: root/src/sensordashboard
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-07-29 14:01:37 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-07-29 14:01:37 +0000
commit5051244c80bd93e1599c5c39aeeefebaeef40d61 (patch)
tree5b64b237d5af7a25f2e75b150fbb3396a360820e /src/sensordashboard
parent764a37c57035bb131d4cf265bf24396c1e422efb (diff)
downloadgnunet-5051244c80bd93e1599c5c39aeeefebaeef40d61.tar.gz
gnunet-5051244c80bd93e1599c5c39aeeefebaeef40d61.zip
sensor, sensordashboard: doxygen fixes + indentation
Diffstat (limited to 'src/sensordashboard')
-rw-r--r--src/sensordashboard/gnunet-sensordashboard.c11
-rw-r--r--src/sensordashboard/gnunet-service-sensordashboard.c143
-rw-r--r--src/sensordashboard/sensordashboard.h4
3 files changed, 68 insertions, 90 deletions
diff --git a/src/sensordashboard/gnunet-sensordashboard.c b/src/sensordashboard/gnunet-sensordashboard.c
index 630a3cf77..97330f389 100644
--- a/src/sensordashboard/gnunet-sensordashboard.c
+++ b/src/sensordashboard/gnunet-sensordashboard.c
@@ -64,11 +64,12 @@ main (int argc, char *const *argv)
64 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 64 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
65 return 2; 65 return 2;
66 66
67 ret = (GNUNET_OK == 67 ret =
68 GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard", 68 (GNUNET_OK ==
69 gettext_noop ("help text"), options, &run, 69 GNUNET_PROGRAM_run (argc, argv, "gnunet-sensordashboard",
70 NULL)) ? ret : 1; 70 gettext_noop ("help text"), options, &run,
71 GNUNET_free ((void*) argv); 71 NULL)) ? ret : 1;
72 GNUNET_free ((void *) argv);
72 return ret; 73 return ret;
73} 74}
74 75
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c
index 0046ba488..52302603b 100644
--- a/src/sensordashboard/gnunet-service-sensordashboard.c
+++ b/src/sensordashboard/gnunet-service-sensordashboard.c
@@ -251,8 +251,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251 * with the channel is stored 251 * with the channel is stored
252 */ 252 */
253static void 253static void
254cadet_channel_destroyed (void *cls, 254cadet_channel_destroyed (void *cls, const struct GNUNET_CADET_Channel *channel,
255 const struct GNUNET_CADET_Channel *channel,
256 void *channel_ctx) 255 void *channel_ctx)
257{ 256{
258 struct ClientPeerContext *cp = channel_ctx; 257 struct ClientPeerContext *cp = channel_ctx;
@@ -284,8 +283,7 @@ cadet_channel_destroyed (void *cls,
284 * (can be NULL -- that's not an error) 283 * (can be NULL -- that's not an error)
285 */ 284 */
286static void * 285static void *
287cadet_channel_created (void *cls, 286cadet_channel_created (void *cls, struct GNUNET_CADET_Channel *channel,
288 struct GNUNET_CADET_Channel *channel,
289 const struct GNUNET_PeerIdentity *initiator, 287 const struct GNUNET_PeerIdentity *initiator,
290 uint32_t port, enum GNUNET_CADET_ChannelOption options) 288 uint32_t port, enum GNUNET_CADET_ChannelOption options)
291{ 289{
@@ -295,6 +293,7 @@ cadet_channel_created (void *cls,
295 "Received a channel connection from peer `%s'.\n", 293 "Received a channel connection from peer `%s'.\n",
296 GNUNET_i2s (initiator)); 294 GNUNET_i2s (initiator));
297 cp = GNUNET_new (struct ClientPeerContext); 295 cp = GNUNET_new (struct ClientPeerContext);
296
298 cp->peerid = *initiator; 297 cp->peerid = *initiator;
299 cp->ch = channel; 298 cp->ch = channel;
300 cp->destroying = GNUNET_NO; 299 cp->destroying = GNUNET_NO;
@@ -356,12 +355,11 @@ trigger_send_next_msg (struct ClientPeerContext *cp)
356 if (NULL != cp->th) 355 if (NULL != cp->th)
357 return; 356 return;
358 pm = cp->pm_head; 357 pm = cp->pm_head;
359 cp->th = GNUNET_CADET_notify_transmit_ready (cp->ch, 358 cp->th =
360 GNUNET_YES, 359 GNUNET_CADET_notify_transmit_ready (cp->ch, GNUNET_YES,
361 GNUNET_TIME_UNIT_FOREVER_REL, 360 GNUNET_TIME_UNIT_FOREVER_REL,
362 ntohs (pm->msg->size), 361 ntohs (pm->msg->size), &do_send_msg,
363 &do_send_msg, 362 cp);
364 cp);
365} 363}
366 364
367 365
@@ -377,6 +375,7 @@ queue_msg (struct GNUNET_MessageHeader *msg, struct ClientPeerContext *cp)
377 struct PendingMessage *pm; 375 struct PendingMessage *pm;
378 376
379 pm = GNUNET_new (struct PendingMessage); 377 pm = GNUNET_new (struct PendingMessage);
378
380 pm->msg = msg; 379 pm->msg = msg;
381 GNUNET_CONTAINER_DLL_insert_tail (cp->pm_head, cp->pm_tail, pm); 380 GNUNET_CONTAINER_DLL_insert_tail (cp->pm_head, cp->pm_tail, pm);
382 trigger_send_next_msg (cp); 381 trigger_send_next_msg (cp);
@@ -393,9 +392,7 @@ queue_msg (struct GNUNET_MessageHeader *msg, struct ClientPeerContext *cp)
393 * @return #GNUNET_YES to continue iteration 392 * @return #GNUNET_YES to continue iteration
394 */ 393 */
395static int 394static int
396send_sensor_brief (void *cls, 395send_sensor_brief (void *cls, const struct GNUNET_HashCode *key, void *value)
397 const struct GNUNET_HashCode *key,
398 void *value)
399{ 396{
400 struct ClientPeerContext *cp = cls; 397 struct ClientPeerContext *cp = cls;
401 struct GNUNET_SENSOR_SensorInfo *sensor = value; 398 struct GNUNET_SENSOR_SensorInfo *sensor = value;
@@ -405,8 +402,8 @@ send_sensor_brief (void *cls,
405 402
406 /* Create message struct */ 403 /* Create message struct */
407 sensorname_size = strlen (sensor->name) + 1; 404 sensorname_size = strlen (sensor->name) + 1;
408 total_size = sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + 405 total_size =
409 sensorname_size; 406 sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + sensorname_size;
410 msg = GNUNET_malloc (total_size); 407 msg = GNUNET_malloc (total_size);
411 msg->header.size = htons (total_size); 408 msg->header.size = htons (total_size);
412 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_BRIEF); 409 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_BRIEF);
@@ -415,7 +412,7 @@ send_sensor_brief (void *cls,
415 msg->version_minor = htons (sensor->version_minor); 412 msg->version_minor = htons (sensor->version_minor);
416 memcpy (&msg[1], sensor->name, sensorname_size); 413 memcpy (&msg[1], sensor->name, sensorname_size);
417 /* Queue the msg */ 414 /* Queue the msg */
418 queue_msg ((struct GNUNET_MessageHeader *)msg, cp); 415 queue_msg ((struct GNUNET_MessageHeader *) msg, cp);
419 return GNUNET_YES; 416 return GNUNET_YES;
420} 417}
421 418
@@ -435,8 +432,7 @@ send_sensor_brief (void *cls,
435 * #GNUNET_SYSERR to close it (signal serious error). 432 * #GNUNET_SYSERR to close it (signal serious error).
436 */ 433 */
437static int 434static int
438handle_sensor_list_req (void *cls, 435handle_sensor_list_req (void *cls, struct GNUNET_CADET_Channel *channel,
439 struct GNUNET_CADET_Channel *channel,
440 void **channel_ctx, 436 void **channel_ctx,
441 const struct GNUNET_MessageHeader *message) 437 const struct GNUNET_MessageHeader *message)
442{ 438{
@@ -446,10 +442,9 @@ handle_sensor_list_req (void *cls,
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Received a sensor list request from peer `%s'.\n", 443 "Received a sensor list request from peer `%s'.\n",
448 GNUNET_i2s (&cp->peerid)); 444 GNUNET_i2s (&cp->peerid));
449 GNUNET_CONTAINER_multihashmap_iterate (sensors, 445 GNUNET_CONTAINER_multihashmap_iterate (sensors, &send_sensor_brief, cp);
450 &send_sensor_brief,
451 cp);
452 end_msg = GNUNET_new (struct GNUNET_MessageHeader); 446 end_msg = GNUNET_new (struct GNUNET_MessageHeader);
447
453 end_msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 448 end_msg->size = htons (sizeof (struct GNUNET_MessageHeader));
454 end_msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_END); 449 end_msg->type = htons (GNUNET_MESSAGE_TYPE_SENSOR_END);
455 queue_msg (end_msg, cp); 450 queue_msg (end_msg, cp);
@@ -485,11 +480,11 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg,
485 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); 480 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
486 return NULL; 481 return NULL;
487 } 482 }
488 rm = (struct GNUNET_SENSOR_ReadingMessage *)msg; 483 rm = (struct GNUNET_SENSOR_ReadingMessage *) msg;
489 sensorname_size = ntohs (rm->sensorname_size); 484 sensorname_size = ntohs (rm->sensorname_size);
490 value_size = ntohs (rm->value_size); 485 value_size = ntohs (rm->value_size);
491 if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) 486 if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size +
492 + sensorname_size + value_size) != msg_size) 487 value_size) != msg_size)
493 { 488 {
494 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); 489 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n");
495 return NULL; 490 return NULL;
@@ -497,13 +492,13 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg,
497 dummy = &rm[1]; 492 dummy = &rm[1];
498 sensorname = GNUNET_malloc (sensorname_size); 493 sensorname = GNUNET_malloc (sensorname_size);
499 memcpy (sensorname, dummy, sensorname_size); 494 memcpy (sensorname, dummy, sensorname_size);
500 GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key); 495 GNUNET_CRYPTO_hash (sensorname, sensorname_size, &key);
501 GNUNET_free (sensorname); 496 GNUNET_free (sensorname);
502 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); 497 sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key);
503 if (NULL == sensor) 498 if (NULL == sensor)
504 { 499 {
505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 500 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
506 "Unknown sensor name in reading message.\n"); 501 "Unknown sensor name in reading message.\n");
507 return NULL; 502 return NULL;
508 } 503 }
509 if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || 504 if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) ||
@@ -546,8 +541,7 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg,
546 * #GNUNET_SYSERR to close it (signal serious error). 541 * #GNUNET_SYSERR to close it (signal serious error).
547 */ 542 */
548static int 543static int
549handle_sensor_reading (void *cls, 544handle_sensor_reading (void *cls, struct GNUNET_CADET_Channel *channel,
550 struct GNUNET_CADET_Channel *channel,
551 void **channel_ctx, 545 void **channel_ctx,
552 const struct GNUNET_MessageHeader *message) 546 const struct GNUNET_MessageHeader *message)
553{ 547{
@@ -564,13 +558,9 @@ handle_sensor_reading (void *cls,
564 } 558 }
565 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 559 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
566 "Received a sensor reading from peer `%s':\n" 560 "Received a sensor reading from peer `%s':\n"
567 "# Sensor name: `%s'\n" 561 "# Sensor name: `%s'\n" "# Timestamp: %" PRIu64 "\n"
568 "# Timestamp: %" PRIu64 "\n" 562 "# Value size: %" PRIu64 ".\n", GNUNET_i2s (&cp->peerid),
569 "# Value size: %" PRIu64 ".\n", 563 reading->sensor->name, reading->timestamp, reading->value_size);
570 GNUNET_i2s (&cp->peerid),
571 reading->sensor->name,
572 reading->timestamp,
573 reading->value_size);
574 GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid, 564 GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid,
575 reading->sensor->name, reading->value, 565 reading->sensor->name, reading->value,
576 reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, 566 reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS,
@@ -609,12 +599,10 @@ create_full_sensor_msg (char *sensorname)
609 if (NULL == sensor) 599 if (NULL == sensor)
610 return NULL; 600 return NULL;
611 sensor_dir = GNUNET_SENSOR_get_sensor_dir (); 601 sensor_dir = GNUNET_SENSOR_get_sensor_dir ();
612 GNUNET_asprintf (&sensor_path, "%s%s", 602 GNUNET_asprintf (&sensor_path, "%s%s", sensor_dir, sensorname);
613 sensor_dir, sensorname); 603 if (GNUNET_OK !=
614 if (GNUNET_OK != GNUNET_DISK_file_size (sensor_path, 604 GNUNET_DISK_file_size (sensor_path, &sensorfile_size, GNUNET_NO,
615 &sensorfile_size, 605 GNUNET_YES))
616 GNUNET_NO,
617 GNUNET_YES))
618 { 606 {
619 GNUNET_free (sensor_dir); 607 GNUNET_free (sensor_dir);
620 GNUNET_free (sensor_path); 608 GNUNET_free (sensor_path);
@@ -626,25 +614,19 @@ create_full_sensor_msg (char *sensorname)
626 /* Test if there is an associated script */ 614 /* Test if there is an associated script */
627 if (NULL != sensor->ext_process) 615 if (NULL != sensor->ext_process)
628 { 616 {
629 GNUNET_asprintf (&sensorscript_path, "%s%s-files%s%s", 617 GNUNET_asprintf (&sensorscript_path, "%s%s-files%s%s", sensor_dir,
630 sensor_dir, 618 sensor->name, DIR_SEPARATOR_STR, sensor->ext_process);
631 sensor->name, 619 if (GNUNET_OK ==
632 DIR_SEPARATOR_STR, 620 GNUNET_DISK_file_size (sensorscript_path, &sensorscript_size, GNUNET_NO,
633 sensor->ext_process); 621 GNUNET_YES))
634 if (GNUNET_OK == GNUNET_DISK_file_size (sensorscript_path,
635 &sensorscript_size,
636 GNUNET_NO,
637 GNUNET_YES))
638 { 622 {
639 sensorscriptname_size = strlen (sensor->ext_process) + 1; 623 sensorscriptname_size = strlen (sensor->ext_process) + 1;
640 } 624 }
641 } 625 }
642 /* Construct the msg */ 626 /* Construct the msg */
643 total_size = sizeof (struct GNUNET_SENSOR_SensorFullMessage) + 627 total_size =
644 sensorname_size + 628 sizeof (struct GNUNET_SENSOR_SensorFullMessage) + sensorname_size +
645 sensorfile_size + 629 sensorfile_size + sensorscriptname_size + sensorscript_size;
646 sensorscriptname_size +
647 sensorscript_size;
648 msg = GNUNET_malloc (total_size); 630 msg = GNUNET_malloc (total_size);
649 msg->header.size = htons (total_size); 631 msg->header.size = htons (total_size);
650 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL); 632 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_FULL);
@@ -685,8 +667,7 @@ create_full_sensor_msg (char *sensorname)
685 * #GNUNET_SYSERR to close it (signal serious error). 667 * #GNUNET_SYSERR to close it (signal serious error).
686 */ 668 */
687static int 669static int
688handle_sensor_full_req (void *cls, 670handle_sensor_full_req (void *cls, struct GNUNET_CADET_Channel *channel,
689 struct GNUNET_CADET_Channel *channel,
690 void **channel_ctx, 671 void **channel_ctx,
691 const struct GNUNET_MessageHeader *message) 672 const struct GNUNET_MessageHeader *message)
692{ 673{
@@ -700,10 +681,10 @@ handle_sensor_full_req (void *cls,
700 /* parse & error check */ 681 /* parse & error check */
701 if (msg_size > sizeof (struct GNUNET_SENSOR_SensorBriefMessage)) 682 if (msg_size > sizeof (struct GNUNET_SENSOR_SensorBriefMessage))
702 { 683 {
703 sbm = (struct GNUNET_SENSOR_SensorBriefMessage *)message; 684 sbm = (struct GNUNET_SENSOR_SensorBriefMessage *) message;
704 sensorname_size = ntohs (sbm->name_size); 685 sensorname_size = ntohs (sbm->name_size);
705 if (msg_size != sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + 686 if (msg_size !=
706 sensorname_size) 687 sizeof (struct GNUNET_SENSOR_SensorBriefMessage) + sensorname_size)
707 sbm = NULL; 688 sbm = NULL;
708 } 689 }
709 if (NULL == sbm) 690 if (NULL == sbm)
@@ -714,15 +695,15 @@ handle_sensor_full_req (void *cls,
714 return GNUNET_SYSERR; 695 return GNUNET_SYSERR;
715 } 696 }
716 /* Create and send msg with full sensor info */ 697 /* Create and send msg with full sensor info */
717 sfm = create_full_sensor_msg ((char *)&sbm[1]); 698 sfm = create_full_sensor_msg ((char *) &sbm[1]);
718 if (NULL == sfm) 699 if (NULL == sfm)
719 { 700 {
720 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
721 "Error creating full sensor info msg for sensor `%s'.\n", 702 "Error creating full sensor info msg for sensor `%s'.\n",
722 (char *)&sbm[1]); 703 (char *) &sbm[1]);
723 return GNUNET_SYSERR; 704 return GNUNET_SYSERR;
724 } 705 }
725 queue_msg ((struct GNUNET_MessageHeader *)sfm, cp); 706 queue_msg ((struct GNUNET_MessageHeader *) sfm, cp);
726 GNUNET_CADET_receive_done (channel); 707 GNUNET_CADET_receive_done (channel);
727 return GNUNET_OK; 708 return GNUNET_OK;
728} 709}
@@ -740,32 +721,30 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
740 const struct GNUNET_CONFIGURATION_Handle *cfg) 721 const struct GNUNET_CONFIGURATION_Handle *cfg)
741{ 722{
742 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 723 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
743 {NULL, NULL, 0, 0} 724 {NULL, NULL, 0, 0}
744 }; 725 };
745 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { 726 static struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
746 {&handle_sensor_reading, 727 {&handle_sensor_reading,
747 GNUNET_MESSAGE_TYPE_SENSOR_READING, 0}, 728 GNUNET_MESSAGE_TYPE_SENSOR_READING, 0},
748 {&handle_sensor_list_req, 729 {&handle_sensor_list_req,
749 GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ, 730 GNUNET_MESSAGE_TYPE_SENSOR_LIST_REQ,
750 sizeof (struct GNUNET_MessageHeader)}, 731 sizeof (struct GNUNET_MessageHeader)},
751 {&handle_sensor_full_req, 732 {&handle_sensor_full_req,
752 GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ, 733 GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ,
753 sizeof (struct GNUNET_MessageHeader)}, 734 sizeof (struct GNUNET_MessageHeader)},
754 {NULL, 0, 0} 735 {NULL, 0, 0}
755 }; 736 };
756 static uint32_t cadet_ports[] = { 737 static uint32_t cadet_ports[] = {
757 GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, 738 GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
758 GNUNET_APPLICATION_TYPE_SENSORUPDATE, 739 GNUNET_APPLICATION_TYPE_SENSORUPDATE,
759 GNUNET_APPLICATION_TYPE_END 740 GNUNET_APPLICATION_TYPE_END
760 }; 741 };
761 sensors = GNUNET_SENSOR_load_all_sensors (); 742 sensors = GNUNET_SENSOR_load_all_sensors ();
762 GNUNET_assert (NULL != sensors); 743 GNUNET_assert (NULL != sensors);
763 cadet = GNUNET_CADET_connect(cfg, 744 cadet =
764 NULL, 745 GNUNET_CADET_connect (cfg, NULL, &cadet_channel_created,
765 &cadet_channel_created, 746 &cadet_channel_destroyed, cadet_handlers,
766 &cadet_channel_destroyed, 747 cadet_ports);
767 cadet_handlers,
768 cadet_ports);
769 if (NULL == cadet) 748 if (NULL == cadet)
770 { 749 {
771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/sensordashboard/sensordashboard.h b/src/sensordashboard/sensordashboard.h
index c7758e26e..22eba4df1 100644
--- a/src/sensordashboard/sensordashboard.h
+++ b/src/sensordashboard/sensordashboard.h
@@ -25,6 +25,4 @@
25 25
26#include "gnunet_sensordashboard_service.h" 26#include "gnunet_sensordashboard_service.h"
27 27
28GNUNET_NETWORK_STRUCT_BEGIN 28GNUNET_NETWORK_STRUCT_BEGIN GNUNET_NETWORK_STRUCT_END
29
30GNUNET_NETWORK_STRUCT_END