network plugin: Introduce new types for the "high resolution" time fields.
authorFlorian Forster <octo@huhu.verplant.org>
Tue, 16 Nov 2010 08:20:04 +0000 (09:20 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 16 Nov 2010 08:20:04 +0000 (09:20 +0100)
src/network.c
src/network.h

index 43193cf..eb32ad1 100644 (file)
@@ -1378,7 +1378,18 @@ static int parse_packet (sockent_t *se, /* {{{ */
                        if (status == 0)
                        {
                                vl.time = TIME_T_TO_CDTIME_T (tmp);
-                               n.time = TIME_T_TO_CDTIME_T (tmp);
+                               n.time  = TIME_T_TO_CDTIME_T (tmp);
+                       }
+               }
+               else if (pkg_type == TYPE_TIME_HR)
+               {
+                       uint64_t tmp = 0;
+                       status = parse_part_number (&buffer, &buffer_size,
+                                       &tmp);
+                       if (status == 0)
+                       {
+                               vl.time = (cdtime_t) tmp;
+                               n.time  = (cdtime_t) tmp;
                        }
                }
                else if (pkg_type == TYPE_INTERVAL)
@@ -1389,6 +1400,14 @@ static int parse_packet (sockent_t *se, /* {{{ */
                        if (status == 0)
                                vl.interval = TIME_T_TO_CDTIME_T (tmp);
                }
+               else if (pkg_type == TYPE_INTERVAL_HR)
+               {
+                       uint64_t tmp = 0;
+                       status = parse_part_number (&buffer, &buffer_size,
+                                       &tmp);
+                       if (status == 0)
+                               vl.interval = (cdtime_t) tmp;
+               }
                else if (pkg_type == TYPE_HOST)
                {
                        status = parse_part_string (&buffer, &buffer_size,
@@ -2583,18 +2602,16 @@ static int add_to_buffer (char *buffer, int buffer_size, /* {{{ */
 
        if (vl_def->time != vl->time)
        {
-               time_t tmp = CDTIME_T_TO_TIME_T (vl->time);
-               if (write_part_number (&buffer, &buffer_size, TYPE_TIME,
-                                       (uint64_t) tmp))
+               if (write_part_number (&buffer, &buffer_size, TYPE_TIME_HR,
+                                       (uint64_t) vl->time))
                        return (-1);
                vl_def->time = vl->time;
        }
 
        if (vl_def->interval != vl->interval)
        {
-               /* TODO: Create a new type for sub-second intervals. */
-               if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL,
-                                       (uint64_t) CDTIME_T_TO_TIME_T (vl->interval)))
+               if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL_HR,
+                                       (uint64_t) vl->interval))
                        return (-1);
                vl_def->interval = vl->interval;
        }
@@ -3072,14 +3089,11 @@ static int network_notification (const notification_t *n,
   char *buffer_ptr = buffer;
   int   buffer_free = sizeof (buffer);
   int   status;
-  time_t tmp;
 
   memset (buffer, '\0', sizeof (buffer));
 
-
-  tmp = CDTIME_T_TO_TIME_T (n->time);
-  status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME,
-      (uint64_t) tmp);
+  status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME_HR,
+      (uint64_t) n->time);
   if (status != 0)
     return (-1);
 
index 777616c..1b35456 100644 (file)
 
 #define TYPE_HOST            0x0000
 #define TYPE_TIME            0x0001
+#define TYPE_TIME_HR         0x0008
 #define TYPE_PLUGIN          0x0002
 #define TYPE_PLUGIN_INSTANCE 0x0003
 #define TYPE_TYPE            0x0004
 #define TYPE_TYPE_INSTANCE   0x0005
 #define TYPE_VALUES          0x0006
 #define TYPE_INTERVAL        0x0007
+#define TYPE_INTERVAL_HR     0x0009
 
 /* Types to transmit notifications */
 #define TYPE_MESSAGE         0x0100