Commit e8b5c24d authored by Arne Øslebø's avatar Arne Øslebø
Browse files

added absolute time to startstop function

git-svn-id: file:///home/svn/mapi/trunk@794 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 216204d8
......@@ -169,6 +169,8 @@ unsigned long long fhlp_str2ull(const char *str)
//Converts a string to an unsigned long long value
{
float value;
if(str[0]=='+')
str=&str[1];
sscanf(str,"%f",&value);
if(strstr(str,"ms")!=NULL)
return TIME_MS*value;
......
......@@ -6,6 +6,7 @@
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
......@@ -13,6 +14,10 @@
#include "mapid.h"
#include "fhelp.h"
//Timestamp format can be relative: +1ms +1.2s etc
//or it can be absolute following the syntax "%Y-%m-%d %H:%M:%S"
//It is not possible to mix relative and absolute
typedef struct startstop {
unsigned long long first;
......@@ -33,39 +38,84 @@ static int startstop_instance(mapidflib_function_instance_t *instance,
{
mapiFunctArg* fargs;
char *s1, *s2;
struct tm t;
fargs = instance->args;
s1 = getargstr(&fargs);
s2 = getargstr(&fargs);
if(!s1 || !s2)
if((!s1 || !s2) || (s1[0]=='+' && s2[0]!='+'))
return(MFUNCT_INVALID_ARGUMENT);
if(fhlp_str2ull(s1) > fhlp_str2ull(s2))
return MFUNCT_INVALID_ARGUMENT;
if(s1[0]!='+' && strptime(s1,"%Y-%m-%d %H:%M:%S",&t)==NULL
|| (s2[0]!='+' && strptime(s2,"%Y-%m-%d %H:%M:%S",&t)==NULL))
return MFUNCT_INVALID_ARGUMENT;
return 0;
};
static int startstop_process_absolute(mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head)
{
startstop_internal_t *ssi=instance->internal_data;
if(ssi->start!=0 && ssi->start > pkt_head->ts)
return 0;
if(ssi->stop!=0 && ssi->stop<pkt_head->ts)
return 0;
return 1;
}
static int startstop_init(mapidflib_function_instance_t *instance,
MAPI_UNUSED int fd)
{
struct tm t;
time_t tt;
char *s1, *s2;
mapiFunctArg* fargs=instance->args;
startstop_t *ss=instance->result.data;
startstop_internal_t *ssi=malloc(sizeof(startstop_internal_t));
instance->internal_data=ssi;
ssi->start=fhlp_str2ull(getargstr(&fargs));
ssi->stop=fhlp_str2ull(getargstr(&fargs));
s1 = getargstr(&fargs);
s2 = getargstr(&fargs);
if(s1[0]=='+') {
ssi->start=fhlp_str2ull(s1);
ssi->stop=ssi->start+fhlp_str2ull(s2);
} else {
strptime(s1,"%Y-%m-%d %H:%M:%S",&t);
tt=mktime(&t);
ssi->start=(unsigned long long)tt << 32;
if(s2[0]!='+') {
strptime(s2,"%Y-%m-%d %H:%M:%S",&t);
tt=mktime(&t);
ssi->stop=(unsigned long long)tt << 32;
} else
ssi->stop=ssi->start+fhlp_str2ull(s2);
instance->def->process=startstop_process_absolute;
}
ss->first=0;
ss->last=0;
ss->first_processed=0;
// printf("start: %lld stop:%lld stop-start=%lld\n",ssi->start>>32,ssi->stop>>32,(ssi->stop-ssi->start)>>32);
return 0;
}
static int startstop_process(mapidflib_function_instance_t *instance,
MAPI_UNUSED unsigned char* dev_pkt,
MAPI_UNUSED unsigned char* link_pkt,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment