Erick / Mbed 2 deprecated ICE-F412

Dependencies:   mbed-rtos mbed

ICE-Application/src/ConfigurationHandler/Controls/CompositeControl.h

Committer:
jmarkel44
Date:
2017-01-24
Revision:
0:61364762ee0e

File content as of revision 0:61364762ee0e:

/******************************************************************************
 *
 * File:                CompositeControl.h
 * Desciption:          ICE Composite Control Class
 *
 *****************************************************************************/
#ifndef COMPOSITECONTROL_H
#define COMPOSITECONTROL_H

#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include "global.h"
#include "./Algorithms/CompositeAlgorithm.h"

typedef enum {
    COMPOSITE_CONTROL_OK,
    COMPOSITE_CONTROL_UNK_STATE, 
    COMPOSITE_CONTROL_ERROR,
    COMPOSITE_CONTROL_DESTROY
} CompositeControlError_t;

//! Composite Control - used to implement a composite control
class CompositeControl
{
private:
    typedef struct oe_tag {
        std::string     tag;
        std::string     response;
    } OutputElement;

    std::string                 controlFile;    // the control file
    std::string                 id;             // composite identifier
    std::string                 tag;            // i/o tag to evaluate
    unsigned int                priority;       // control priority
    std::string                 ca;             // control algorithm
    std::vector<OutputElement>  outputs;        // (virtual) output(s)

    enum State {
        STATE_INIT,
        STATE_START,
        STATE_CONTROL_OFF,
        STATE_CONTROL_ON,
        STATE_MAX
    };
    State                       currentState;   // current state
        
    bool        validateControlData(const char *buf);
    void        copyControlData(const char *buf);

    std::string executeCommand(void);
    std::string executeOperation(const CompositeAlgorithm*);
    void        triggerOutputs(std::string result);
    void        sendMail(std::string io_tag, OutputAction action);

public:
    /// constructor
    CompositeControl() { }
    
    /// destructor
    ~CompositeControl() {
        printf("\r%s invoked\n", __func__);
    }

    /// load a composite control from a JSON configuration file
    bool load(std::string controlFile);

    /// start a composite control instance
    void start(void);

    /// update a composite control instance 
    CompositeControlError_t update(void);

    /// unregister a composite control(s) instance 
    void unregisterControls();

    /// get the composite control's control filename 
    std::string getControlFile(void) const {
        return controlFile;
    }
    
    /// get the composite control's identifier
    std::string getId(void) const {
        return id;
    }

    /// get the composite control's current state 
    State getState(void) const {
        return currentState;
    }

    /// get the composite control's tag 
    std::string getTag(void) const {
        return tag;
    }
    
    /// get a list of a composite control's outputs
    std::vector<std::string> getOutputs(void) const;

    void display(void);
};

#endif