Пример #1
0
/** Create a new datastream with no entities enabled
 *
 * Returns the ID of this new datastream so it can be specifically referenced
 *
 * The cache size is the number of empty buffers the datastream will hold in
 * its cache, and the mode determines whether the datastream writes events
 * as it recieves them, or holds them in a circular ringbuffer until
 * it is explicitly flushed
 */
int dsui_open_datastream(char *logfile, int cache_size, enum datastream_mode mode)
{
	int id;
	struct datastream *d;
	struct logging_thread *log;

	km_rdwr_wlock(&dsui_rwlock);


	log = hashtable_search(logging_threads, logfile);
	if (!log) {
		eprintf("Unknown logging thread '%s'. Is it open?\n", logfile);
		id = -1;
		goto out;
	}

	for(id = 0; id == MAX_DS; id++) {
		if (ds_array[id] == NULL) break;
	}
	if (id == MAX_DS) {
		eprintf("no free datastreams\n");
		id =  -1;
		goto out;
	}

	d = datastream_create(id, global_buffer_pool, log,
			cache_size, mode);

	ds_array[id] = d;

out:
	km_rdwr_wunlock(&dsui_rwlock);
	return id;
}
Пример #2
0
int osdb_create_datastream(osdb_t* db, 
                           id_t id,
                           timestamp_t min_period,
                           timestamp_t max_period,
                           timestamp_t tolerance)
{
        if (filemanager_datastream_exists(id))
                return 0;
        datastream_t* d = datastream_create(id, min_period, max_period, tolerance);
        if (d == NULL)
                return -1;
        osdb_cache_put(db, d);
        return 0;
}
Пример #3
0
static int import_csv(const char* path) 
{
        FILE* fp = fopen(path, "r");
        if (fp == NULL) {
                fprintf(stderr, "File not found: %s\n", path);
                return -1;
        }

        hashtable_t* datastreams = new_hashtable(NULL);

        while (1) {
                unsigned long id;
                double t, v;

                int n = fscanf(fp, "%lu,%lf,%lf\n", &id, &t, &v);
                if (n < 3)
                        break;

                datastream_t* d = NULL;
                hashtable_lookup(datastreams, id, (void**) &d);
                
                if (d == NULL) {
                        d = datastream_load(id);
                        if (d == NULL) {
                                d = datastream_create(id, 0.5, 3600.0, 0.1);
                                if (d == NULL) {
                                        fprintf(stderr, "Failed to create the datastream\n");
                                        goto error_recovery;
                                }
                        }
                        hashtable_insert(datastreams, id, d);
                }

                printf("id=%d, t=%d, v=%f\n", (int) id, (int) t, v);

                int err = datastream_insert(d, (timestamp_t) t, (value_t) v);
                if (err != 0)
                        goto error_recovery;
        }

        fclose(fp);
        hashtable_foreach(datastreams, store_datastreams_callback, NULL);
        return 0;

 error_recovery:
        fclose(fp);
        hashtable_foreach(datastreams, store_datastreams_callback, NULL);
        return -1;
}