summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8bc9c72)
raw | patch | inline | side by side (parent: 8bc9c72)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 2 Apr 2007 06:21:19 +0000 (06:21 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 2 Apr 2007 06:21:19 +0000 (06:21 +0000) |
strings const char* instead of char*). The only difference between
rrd_fetch_r() and rrd_fetch_fn() is that rrd_fetch_r() receives the
consolidation function as a string (instead of an enum cf_en) and is thread-safe -- Sam Umbach
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1028 a5681a0c-68f1-0310-ab6d-d61299d08faa
rrd_fetch_r() and rrd_fetch_fn() is that rrd_fetch_r() receives the
consolidation function as a string (instead of an enum cf_en) and is thread-safe -- Sam Umbach
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1028 a5681a0c-68f1-0310-ab6d-d61299d08faa
doc/rrdthreads.pod | patch | blob | history | |
src/fnv.h | patch | blob | history | |
src/hash_32.c | patch | blob | history | |
src/rrd.h | patch | blob | history | |
src/rrd_create.c | patch | blob | history | |
src/rrd_fetch.c | patch | blob | history | |
src/rrd_format.c | patch | blob | history | |
src/rrd_rpncalc.c | patch | blob | history | |
src/rrd_rpncalc.h | patch | blob | history | |
src/rrd_tool.h | patch | blob | history | |
src/rrd_update.c | patch | blob | history |
diff --git a/doc/rrdthreads.pod b/doc/rrdthreads.pod
index f05d6ea227d5ad418898ed5e84db2121d5dea30c..ace7ee8c395c0d0eb4d95e1aaab036f3a03bce8b 100644 (file)
--- a/doc/rrdthreads.pod
+++ b/doc/rrdthreads.pod
=head2 CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS
Currently there exist thread-safe variants of C<rrd_update>,
-C<rrd_create>, C<rrd_dump>, C<rrd_info> and C<rrd_last>.
+C<rrd_create>, C<rrd_dump>, C<rrd_info>, C<rrd_last>, and C<rrd_fetch>.
=head1 AUTHOR
diff --git a/src/fnv.h b/src/fnv.h
index 22f6ff69fc7aa647bf6d3e025ad5ab605883752c..e69f9cee1af9ec9f1da41d5aaf45d1df38773c73 100644 (file)
--- a/src/fnv.h
+++ b/src/fnv.h
*/
#define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
-Fnv32_t fnv_32_buf(void *, size_t, Fnv32_t);
+Fnv32_t fnv_32_buf(const void *, size_t, Fnv32_t);
-Fnv32_t fnv_32_str(char *, Fnv32_t );
+Fnv32_t fnv_32_str(const char *, Fnv32_t );
-unsigned long FnvHash(char *);
+unsigned long FnvHash(const char *);
#endif /* __FNV_H__ */
diff --git a/src/hash_32.c b/src/hash_32.c
index 3fda164c2d3cfd951168d56c5c5524adda20eb7d..d7edbee753327a079846b8199eb8deede5195a5e 100644 (file)
--- a/src/hash_32.c
+++ b/src/hash_32.c
* argument on the first call to either fnv_32_buf() or fnv_32_str().
*/
Fnv32_t
-fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
+fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
{
- unsigned char *bp = (unsigned char *)buf; /* start of buffer */
- unsigned char *be = bp + len; /* beyond end of buffer */
+ const unsigned char *bp = (const unsigned char *)buf; /* start of buffer */
+ const unsigned char *be = bp + len; /* beyond end of buffer */
/*
* FNV-1 hash each octet in the buffer
* argument on the first call to either fnv_32_buf() or fnv_32_str().
*/
Fnv32_t
-fnv_32_str(char *str, Fnv32_t hval)
+fnv_32_str(const char *str, Fnv32_t hval)
{
- unsigned char *s = (unsigned char *)str; /* unsigned string */
+ const unsigned char *s = (const unsigned char *)str; /* unsigned string */
/*
* FNV-1 hash each octet in the buffer
}
/* a wrapper function for fnv_32_str */
-unsigned long FnvHash(char *str)
+unsigned long FnvHash(const char *str)
{
return fnv_32_str(str,FNV1_32_INIT);
}
diff --git a/src/rrd.h b/src/rrd.h
index e83afcd121a9d013c6dbc44eb0300353439cb7f4..abc183ec36d6afdcc368f3914e06304e73b0d01b 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
char ***, rrd_value_t **);
/* thread-safe (hopefully) */
-int rrd_create_r(char *filename,
+int rrd_create_r(const char *filename,
unsigned long pdp_step, time_t last_up,
- int argc, char **argv);
+ int argc, const char **argv);
/* NOTE: rrd_update_r are only thread-safe if no at-style time
specifications get used!!! */
-int rrd_update_r(char *filename, char *_template,
- int argc, char **argv);
+int rrd_update_r(const char *filename, const char *_template,
+ int argc, const char **argv);
+int rrd_fetch_r(const char *filename, const char* cf,
+ time_t *start, time_t *end,
+ unsigned long *step,
+ unsigned long *ds_cnt,
+ char ***ds_namv,
+ rrd_value_t **data);
int rrd_dump_r(const char *filename, char *outname);
time_t rrd_last_r(const char *filename);
time_t rrd_first_r(const char *filename, int rraindex);
diff --git a/src/rrd_create.c b/src/rrd_create.c
index 8af9e9aba8921c0d4e28260b57943f4a5aaba362..1c3edc182d4e057e5aa44923fad85a3bedc37859 100644 (file)
--- a/src/rrd_create.c
+++ b/src/rrd_create.c
#include "rrd_is_thread_safe.h"
-unsigned long FnvHash(char *str);
+unsigned long FnvHash(const char *str);
int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name);
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx);
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx);
int
rrd_create(int argc, char **argv)
/* #define DEBUG */
int
-rrd_create_r(char *filename,
+rrd_create_r(const char *filename,
unsigned long pdp_step, time_t last_up,
- int argc, char **argv)
+ int argc, const char **argv)
{
rrd_t rrd;
long i;
return rrd_create_fn(filename, &rrd);
}
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx)
{
char minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];
/*
@@ -547,7 +547,7 @@ create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashe
/* create and empty rrd file according to the specs given */
int
-rrd_create_fn(char *file_name, rrd_t *rrd)
+rrd_create_fn(const char *file_name, rrd_t *rrd)
{
unsigned long i,ii;
FILE *rrd_file;
diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c
index 3a794e9c9022a9f0a5fc88771963698127879867..927cc30376d75150d5a60b8f26953a7d42a2682f 100644 (file)
--- a/src/rrd_fetch.c
+++ b/src/rrd_fetch.c
*****************************************************************************/
#include "rrd_tool.h"
+
+#include "rrd_is_thread_safe.h"
/*#define DEBUG*/
int
long step_tmp =1;
time_t start_tmp=0, end_tmp=0;
- enum cf_en cf_idx;
+ const char *cf;
struct rrd_time_value start_tv, end_tv;
char *parsetime_error = NULL;
rrd_set_error("not enough arguments");
return -1;
}
-
- if ((int)(cf_idx=cf_conv(argv[optind+1])) == -1 ){
- return -1;
- }
- if (rrd_fetch_fn(argv[optind],cf_idx,start,end,step,ds_cnt,ds_namv,data) == -1)
+ cf = argv[optind+1];
+
+ if (rrd_fetch_r(argv[optind],cf,start,end,step,ds_cnt,ds_namv,data) == -1)
return(-1);
return (0);
}
+int
+rrd_fetch_r(
+ const char *filename, /* name of the rrd */
+ const char *cf, /* which consolidation function ?*/
+ time_t *start,
+ time_t *end, /* which time frame do you want ?
+ * will be changed to represent reality */
+ unsigned long *step, /* which stepsize do you want?
+ * will be changed to represent reality */
+ unsigned long *ds_cnt, /* number of data sources in file */
+ char ***ds_namv, /* names of data_sources */
+ rrd_value_t **data) /* two dimensional array containing the data */
+{
+ enum cf_en cf_idx;
+
+ if ((int)(cf_idx=cf_conv(cf)) == -1 ){
+ return -1;
+ }
+
+ return (rrd_fetch_fn(filename,cf_idx,start,end,step,ds_cnt,ds_namv,data));
+}
+
int
rrd_fetch_fn(
- char *filename, /* name of the rrd */
+ const char *filename, /* name of the rrd */
enum cf_en cf_idx, /* which consolidation function ?*/
time_t *start,
time_t *end, /* which time frame do you want ?
diff --git a/src/rrd_format.c b/src/rrd_format.c
index 0fd043a8f43b6820c2bd4dd1426b729aa15aab2c..ecd0c60d7537b5f880e54613203b66bba732dd26 100644 (file)
--- a/src/rrd_format.c
+++ b/src/rrd_format.c
}
-enum cf_en cf_conv(char *string)
+enum cf_en cf_conv(const char *string)
{
converter(AVERAGE,CF_AVERAGE)
diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c
index 972f486b023ed054a6bd2915543c71eb877015f9..3892e384600eb1dbe7fdedc54f8c3272b7176d06 100644 (file)
--- a/src/rrd_rpncalc.c
+++ b/src/rrd_rpncalc.c
return 0;
}
-void parseCDEF_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseCDEF_DS(const char *def,rrd_t *rrd, int ds_idx)
{
rpnp_t *rpnp = NULL;
rpn_cdefds_t *rpnc = NULL;
diff --git a/src/rrd_rpncalc.h b/src/rrd_rpncalc.h
index 357580825df30b7dafe07ef407aa37e827c1d12b..cbde13f5faa15776f3aaf4fa73e1299a852f6a4c 100644 (file)
--- a/src/rrd_rpncalc.h
+++ b/src/rrd_rpncalc.h
void rpnstack_init(rpnstack_t *rpnstack);
void rpnstack_free(rpnstack_t *rpnstack);
-void parseCDEF_DS(char *def, rrd_t *rrd, int ds_idx);
+void parseCDEF_DS(const char *def, rrd_t *rrd, int ds_idx);
long lookup_DS(void *rrd_vptr, char *ds_name);
short rpn_compact(rpnp_t *rpnp,rpn_cdefds_t **rpnc,short *count);
diff --git a/src/rrd_tool.h b/src/rrd_tool.h
index 954dac8989cafef26b4c7ec58dbfd18cb478e6f2..3f6416ee90124886c3e23f32104bd28b79943ba7 100644 (file)
--- a/src/rrd_tool.h
+++ b/src/rrd_tool.h
int PngSize(FILE *, long *, long *);
-int rrd_create_fn(char *file_name, rrd_t *rrd);
-int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
+int rrd_create_fn(const char *file_name, rrd_t *rrd);
+int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
time_t *start,time_t *end,
unsigned long *step,
unsigned long *ds_cnt,
#define RRD_READONLY 0
#define RRD_READWRITE 1
-enum cf_en cf_conv(char *string);
+enum cf_en cf_conv(const char *string);
enum dst_en dst_conv(char *string);
long ds_match(rrd_t *rrd,char *ds_nam);
double rrd_diff(char *a, char *b);
diff --git a/src/rrd_update.c b/src/rrd_update.c
index 0143e9e68db29c9e5ccbf85812f96044ff89770d..d853c5b166c3984b632505147be500c17025d679 100644 (file)
--- a/src/rrd_update.c
+++ b/src/rrd_update.c
unsigned short CDP_scratch_idx, FILE *rrd_file,
info_t *pcdp_summary, time_t *rra_time);
#endif
-int rrd_update_r(char *filename, char *tmplt, int argc, char **argv);
-int _rrd_update(char *filename, char *tmplt, int argc, char **argv,
+int rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv);
+int _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv,
info_t*);
#define IFDNAN(X,Y) (isnan(X) ? (Y) : (X));
}
int
-rrd_update_r(char *filename, char *tmplt, int argc, char **argv)
+rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv)
{
return _rrd_update(filename, tmplt, argc, argv, NULL);
}
int
-_rrd_update(char *filename, char *tmplt, int argc, char **argv,
+_rrd_update(const char *filename, const char *tmplt, int argc, const char **argv,
info_t *pcdp_summary)
{
/* we should work on a writeable copy here */
char *dsname;
unsigned int tmpl_len;
- tmplt = strdup(tmplt);
- dsname = tmplt;
+ char *tmplt_copy = strdup(tmplt);
+ dsname = tmplt_copy;
tmpl_cnt = 1; /* the first entry is the time */
- tmpl_len = strlen(tmplt);
+ tmpl_len = strlen(tmplt_copy);
for(i=0;i<=tmpl_len ;i++) {
- if (tmplt[i] == ':' || tmplt[i] == '\0') {
- tmplt[i] = '\0';
+ if (tmplt_copy[i] == ':' || tmplt_copy[i] == '\0') {
+ tmplt_copy[i] = '\0';
if (tmpl_cnt>rrd.stat_head->ds_cnt){
rrd_set_error("tmplt contains more DS definitions than RRD");
free(updvals); free(pdp_temp);
if ((tmpl_idx[tmpl_cnt++] = ds_match(&rrd,dsname)) == -1){
rrd_set_error("unknown DS name '%s'",dsname);
free(updvals); free(pdp_temp);
- free(tmplt);
+ free(tmplt_copy);
free(tmpl_idx); rrd_free(&rrd);
fclose(rrd_file); return(-1);
} else {
/* the first element is always the time */
tmpl_idx[tmpl_cnt-1]++;
- /* go to the next entry on the tmplt */
- dsname = &tmplt[i+1];
+ /* go to the next entry on the tmplt_copy */
+ dsname = &tmplt_copy[i+1];
/* fix the damage we did before */
if (i<tmpl_len) {
- tmplt[i]=':';
+ tmplt_copy[i]=':';
}
}
}
}
- free(tmplt);
+ free(tmplt_copy);
}
if ((pdp_new = malloc(sizeof(rrd_value_t)
*rrd.stat_head->ds_cnt))==NULL){