#ifndef _CWRITEOML_H_
#define _CWRITEOML_H_

#include <iostream>
#include <vector>
#include <map>
#include <string.h>
#include "oml2/omlc.h"

#include <boost/lexical_cast.hpp>


#define FALSE (unsigned int) 0
#define TRUE  (unsigned int) 1


class CWriteOml
{
  private:
    unsigned int bReady;
    unsigned int _MeasurementPoints;
    std::string _HostName;
    OmlValueU* _values;

    std::map<std::string, std::pair<OmlValueT, OmlValueU*> >            _KTVMap;
    std::map<std::string, std::pair<OmlValueT, OmlValueU*> >::iterator  _KTVMapIter;


    OmlMPDef* mp_def;
    OmlMP* _mp_handle;
    std::string _db_filename;
    std::string _server_name;

    void createMeasurementPoint(OmlMPDef* pOmlMPDef, std::string str, OmlValueT type);

    std::vector< std::pair<std::string, OmlValueT> > _oml_mps; // this is a container of measurement points
                                                               // used start().

  public:

    
    // Create OML object
    CWriteOml();

    // Create OML object & connection to oml server
    //  * oml_id      - unique identifier assoicated with all measured values from this object
    //  * oml_domain  - sqlite3 database file
    //  * oml_collect - OML storage option
    //                  network storage example: oml:3003
    //                  local text file example: file:oml_file
    CWriteOml(std::string oml_id, std::string oml_domain, std::string oml_collect);

    // Stops oml collections, closes connections oml server, garbage collection
    ~CWriteOml();

    // Create connection to oml server
    //  * oml_expid   - unique OML experiment identifier
    //  * db_filename - sqlite3 database file
    //  * server_name - OML storage option
    //                  network storage example: oml:3003
    //                  local text file example: file:oml_file
    void init(std::string oml_expid, std::string db_filename, std::string server_name);



    // Register variable names and corresponding type.
    // * str_variable is the name of the measurement point
    // * oml_value_type is the associate variable type. 
    void register_mp(std::string str_variable, OmlValueT oml_value_type);
  
    // Start measurement recording session
    void start();

    // Update OML keys (ie. sensor values) with measured value or state
    void set_mp(std::string key_str, void* val_ptr);
    void set_mp_blob(std::string key_str, void* val_ptr, unsigned int omlblob_bytes);

    // Send all the OML type-value pairs to the database for storage as a timestamped database entry.
    void insert();

    // Stops OML measurement recording session and flushes all measurements to storage
    void stop();

    unsigned int isReady() { return bReady; }

};

#endif
