]> code.delx.au - pulseaudio/blobdiff - polyp/tagstruct.c
add support for module search path as command line argument
[pulseaudio] / polyp / tagstruct.c
index 5aa79e6c203262c8bcabfb1247fb8a0de130538e..55132caee57d5329ee670a09fdef85e34a2452d2 100644 (file)
@@ -43,6 +43,7 @@ enum tags {
     TAG_ARBITRARY = 'x',
     TAG_BOOLEAN_TRUE = '1',
     TAG_BOOLEAN_FALSE = '0',
+    TAG_TIMEVAL = 'T',
 };
 
 struct pa_tagstruct {
@@ -145,6 +146,15 @@ void pa_tagstruct_put_boolean(struct pa_tagstruct*t, int b) {
     t->length += 1;
 }
 
+void pa_tagstruct_put_timeval(struct pa_tagstruct*t, const struct timeval *tv) {
+    assert(t);
+    extend(t, 9);
+    t->data[t->length] = TAG_TIMEVAL;
+    *((uint32_t*) (t->data+t->length+1)) = htonl(tv->tv_sec);
+    *((uint32_t*) (t->data+t->length+5)) = htonl(tv->tv_usec);
+    t->length += 9;
+}
+
 int pa_tagstruct_gets(struct pa_tagstruct*t, const char **s) {
     int error = 0;
     size_t n;
@@ -263,4 +273,18 @@ int pa_tagstruct_get_boolean(struct pa_tagstruct*t, int *b) {
     return 0;
 }
 
+int pa_tagstruct_get_timeval(struct pa_tagstruct*t, struct timeval *tv) {
+
+    if (t->rindex+9 > t->length)
+        return -1;
+
+    if (t->data[t->rindex] != TAG_TIMEVAL)
+        return -1;
+    
+    tv->tv_sec = ntohl(*((uint32_t*) (t->data+t->rindex+1)));
+    tv->tv_usec = ntohl(*((uint32_t*) (t->data+t->rindex+5)));
+    t->rindex += 9;
+    return 0;
+    
+}