| 1 | #ifndef _CWRITEOML_H_
|
|---|
| 2 | #define _CWRITEOML_H_
|
|---|
| 3 |
|
|---|
| 4 | #include <iostream>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 | #include <map>
|
|---|
| 7 | #include <string.h>
|
|---|
| 8 | #include "oml2/omlc.h"
|
|---|
| 9 |
|
|---|
| 10 | #include <boost/lexical_cast.hpp>
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | #define FALSE (unsigned int) 0
|
|---|
| 14 | #define TRUE (unsigned int) 1
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | class CWriteOml
|
|---|
| 18 | {
|
|---|
| 19 | private:
|
|---|
| 20 | unsigned int bReady;
|
|---|
| 21 | unsigned int _MeasurementPoints;
|
|---|
| 22 | std::string _HostName;
|
|---|
| 23 | OmlValueU* _values;
|
|---|
| 24 |
|
|---|
| 25 | std::map<std::string, std::pair<OmlValueT, OmlValueU*> > _KTVMap;
|
|---|
| 26 | std::map<std::string, std::pair<OmlValueT, OmlValueU*> >::iterator _KTVMapIter;
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | OmlMPDef* mp_def;
|
|---|
| 30 | OmlMP* _mp_handle;
|
|---|
| 31 | std::string _db_filename;
|
|---|
| 32 | std::string _server_name;
|
|---|
| 33 |
|
|---|
| 34 | void createMeasurementPoint(OmlMPDef* pOmlMPDef, std::string str, OmlValueT type);
|
|---|
| 35 |
|
|---|
| 36 | std::vector< std::pair<std::string, OmlValueT> > _oml_mps; // this is a container of measurement points
|
|---|
| 37 | // used start().
|
|---|
| 38 |
|
|---|
| 39 | public:
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | // Create OML object
|
|---|
| 43 | CWriteOml();
|
|---|
| 44 |
|
|---|
| 45 | // Create OML object & connection to oml server
|
|---|
| 46 | // * oml_id - unique identifier assoicated with all measured values from this object
|
|---|
| 47 | // * oml_domain - sqlite3 database file
|
|---|
| 48 | // * oml_collect - OML storage option
|
|---|
| 49 | // network storage example: oml:3003
|
|---|
| 50 | // local text file example: file:oml_file
|
|---|
| 51 | CWriteOml(std::string oml_id, std::string oml_domain, std::string oml_collect);
|
|---|
| 52 |
|
|---|
| 53 | // Stops oml collections, closes connections oml server, garbage collection
|
|---|
| 54 | ~CWriteOml();
|
|---|
| 55 |
|
|---|
| 56 | // Create connection to oml server
|
|---|
| 57 | // * oml_expid - unique OML experiment identifier
|
|---|
| 58 | // * db_filename - sqlite3 database file
|
|---|
| 59 | // * server_name - OML storage option
|
|---|
| 60 | // network storage example: oml:3003
|
|---|
| 61 | // local text file example: file:oml_file
|
|---|
| 62 | void init(std::string oml_expid, std::string db_filename, std::string server_name);
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | // Register variable names and corresponding type.
|
|---|
| 67 | // * str_variable is the name of the measurement point
|
|---|
| 68 | // * oml_value_type is the associate variable type.
|
|---|
| 69 | void register_mp(std::string str_variable, OmlValueT oml_value_type);
|
|---|
| 70 |
|
|---|
| 71 | // Start measurement recording session
|
|---|
| 72 | void start();
|
|---|
| 73 |
|
|---|
| 74 | // Update OML keys (ie. sensor values) with measured value or state
|
|---|
| 75 | void set_mp(std::string key_str, void* val_ptr);
|
|---|
| 76 | void set_mp_blob(std::string key_str, void* val_ptr, unsigned int omlblob_bytes);
|
|---|
| 77 |
|
|---|
| 78 | // Send all the OML type-value pairs to the database for storage as a timestamped database entry.
|
|---|
| 79 | void insert();
|
|---|
| 80 |
|
|---|
| 81 | // Stops OML measurement recording session and flushes all measurements to storage
|
|---|
| 82 | void stop();
|
|---|
| 83 |
|
|---|
| 84 | unsigned int isReady() { return bReady; }
|
|---|
| 85 |
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | #endif
|
|---|