/*
 * object.h
 *
 *  Created on: 3 Jun 2013
 *      Author: john
 */

#ifndef OBJECT_H_
#define OBJECT_H_

#include <taglist.h>
#include <objectlist.h>
#include <kouriermsg.h>
#include <jansson.h>

class cObjectList;

class cObject
{
public:
   enum eObjectTypes
   {
      OBJ_DEVICE,
      OBJ_PORT,
      OBJ_PORT_DIN,
      OBJ_PORT_DOUT,
      OBJ_PORT_AIN,
      OBJ_EVENT,
      OBJ_MSG_INFO,
      OBJ_SITE_CFG,
      OBJ_TREND_EVENT,
      OBJ_ANALOG_SAMPLE,
      OBJ_ACCESS,
      OBJ_PORT_AOUT,
      OBJ_CAPABILITY,
      OBJ_ADHOC_EVENT,
      OBJ_NUM_OBJECT_TYPES
   };
   enum eObjectStatus
       {
          OBJ_STATUS_ALARM_UNKNOWN,
          OBJ_STATUS_ALARM_SET,
          OBJ_STATUS_ALARM_CLEAR,
          // Added for analog, default if set is ERROR level else warning
          OBJ_STATUS_ALARM_WARN
       };
   enum eObjectOpState
       {
          OBJ_OP_STATE_UNKNOWN,
          OBJ_OP_STATE_DISCOVERED,
          OBJ_OP_STATE_MAINTENANCE,
          OBJ_OP_STATE_OPERATIONAL
       };
   enum eObjectIOState
   {
      OBJ_IO_STATE_UNKNOWN,
      OBJ_IO_STATE_SET,
      OBJ_IO_STATE_CLEAR
   };

   cObject();
   cObject(eObjectTypes tpe);

   virtual ~cObject();

   static cObject * create(eObjectTypes tpe);
   static cObjectList * parseMsg(KMsg * msg);
   //returns a char * that the caller is responsible for freeing
   static cObjectList * parseJSON(const char *);
   static char * getJSON(cObjectList *);
   static void deleteJSON(char *);


   virtual cTagList * getTags() = 0;
   virtual json_t * getJSONObj() = 0; //for JSON
   virtual bool parse(KourierObject *ko,std::vector<KTag*>* ct = NULL) = 0;
   virtual bool parse(json_t* data) = 0; //for JSON
   virtual bool compIndex(cObject *) = 0;
   virtual bool operator < (cObject &rhs) = 0;
   virtual char * printKey() = 0;
   virtual cObject *clone() = 0;

   eObjectTypes getType();
   static eObjectTypes getObjectTypeForJSON(const char * str);
   void setType(eObjectTypes t);

private:
   eObjectTypes mType;
};


#endif /* OBJECT_H_ */
