#ifndef __EDOS_PROXY_API__
#define __EDOS_PROXY_API__

#define EDOSPROXYAPI_EXPORTS

#ifdef EDOSPROXYAPI_EXPORTS
#define EDOSPROXYAPI_API __declspec(dllexport) 
#else
#define EDOSPROXYAPI_API __declspec(dllimport)
#endif

#pragma pack(push, __EDOS_PROXY__)
#pragma pack(1)

#define ERROR_LOGIN_FAILED				 -2000
#define ERROR_USER_ALREADY_EXIST  -2001
#define ERROR_USER_NOT_EXIST  -2002
#define ERROR_USER_ACCOUNT_ALREADY_EXIST  -2003
#define ERROR_IDENTITY_ALREADY_EXIST  -2004
#define ERROR_IDENTITY_NOT_EXIST  -2005
#define ERROR_SERVICE_ALREADY_EXIST  -2006
#define ERROR_SERVICE_NOT_EXIST  -2007
#define ERROR_POINT_ALREADY_EXIST  -2008
#define ERROR_POINT_NOT_EXIST  -2009
#define ERROR_HISTORY_FULL  -2010
#define ERROR_NO_LOGIN		  -2011
#define ERROR_NO_PERMISSION  -2012
#define ERROR_CHANGE_ADMIN_SETTING  -2013
#define ERROR_CONNECT_TO_HISTORY  -2014
#define ERROR_GET_CAPACITY_FAILED = -2015
#define ERROR_NOT_EQUAL_CAPACITY = -2016
#define ERROR_HISTORY_NAME  -2017
#define ERROR_PARAM_EMPTY  -2018
#define ERROR_PARAM_VALUE_ERROR  -2019
#define ERROR_GET_POINT_INFO  -2020
#define ERROR_DELETE_POINT  -2021
#define ERROR_GET_POINT_INDEXES  -2022
#define ERROR_PARAM_CONTAIN_DOT  -2023
#define ERROR_HISTORY_NOT_RUNNING -2024
#define ERROR_POINT_NAME = -2025
#define ERROR_NOT_STRING_HISTORY -2026
#define ERROR_NOT_DOUBLE_HISTORY -2027
#define ERROR_INSTANCE_TYPE -2028
#define ERROR_NOT_POINT_EXTEND_DATA -2029
#define ERROR_NOT_INSTANCE_DESC -2030
#define ERROR_NOT_IMAGE_HISTORY -2031

#define SERVICE_BUSY									 -1
#define PROXY_NOT_WORKING					-1001
#define SEND_DATA_TO_BUF						-1002
#define SOCKET_NOT_OPEN						-1003
#define REQUEST_BUFFER_NOT_ENOUGH	-1004
#define NO_COMMUNICATION_KEY			-1005
#define ERROR_HIST_REQUEST_TIME -1006

#define  INFO_LENGTH					200
#define  IMAGE_SIZE						10000

#define POINT_ALLOW_READ   1
#define POINT_ALLOW_WRITE  2
#define POINT_FULL_CONTROL 3

#define FLOAT_ERROR -1.7E308

typedef struct
{
	int dateUTC;
	int bLowWarn;
	double lowWarn;
	int bLowAlarm;
	double lowAlarm;
	int bLowOutOfRange;
	double lowOutOfRange;
	int bHighWarn;
	double highWarn;
	int bHighAlarm;
	double highAlarm;
	int bHighOutOfRange;
	double highOutOfRange;
	char reservedField[INFO_LENGTH];
	char reservedField2[INFO_LENGTH];
	char reservedField3[INFO_LENGTH];
	char reservedField4[INFO_LENGTH];
	char reservedField5[INFO_LENGTH];
	char reservedField6[INFO_LENGTH];
	char reservedField7[INFO_LENGTH];
	char reservedField8[INFO_LENGTH];
	char reservedField9[INFO_LENGTH];
	char reservedField10[INFO_LENGTH];
	int bNoDataCheck;
	int bForceDataToHistory;
	int forcePeriod;
} POINT_EXTEND_BACKUP_DATA;


typedef struct
{
	int bLowWarn;
	double lowWarn;
	int bLowAlarm;
	double lowAlarm;
	int bLowOutOfRange;
	double lowOutOfRange;
	int bHighWarn;
	double highWarn;
	int bHighAlarm;
	double highAlarm;
	int bHighOutOfRange;
	double highOutOfRange;
	char reservedField[INFO_LENGTH];
	char reservedField2[INFO_LENGTH];
	char reservedField3[INFO_LENGTH];
	char reservedField4[INFO_LENGTH];
	char reservedField5[INFO_LENGTH];
	char reservedField6[INFO_LENGTH];
	char reservedField7[INFO_LENGTH];
	char reservedField8[INFO_LENGTH];
	char reservedField9[INFO_LENGTH];
	char reservedField10[INFO_LENGTH];
	int bNoDataCheck;
	int bForceDataToHistory;
	int forcePeriod;
} POINT_EXTEND_DATA;

typedef struct  
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	char ip[50];
	unsigned short port;
	int capacity;
}	HISTORY;

typedef struct  
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
} IDENTITY;

typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
} PERMISSION;

typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	char account[INFO_LENGTH];
	char password[INFO_LENGTH];
} USER;

typedef struct
{
	char name[INFO_LENGTH];
	int  count;
	int  stringCount;
	char description[INFO_LENGTH];
	char system[INFO_LENGTH];
	char subSystem[INFO_LENGTH];
} POINT_INSTANCE_INFO;

typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	char system[INFO_LENGTH];
	char subSystem[INFO_LENGTH];
} POINT_INSTANCE_DESC;

typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	unsigned short nPrecision;
	double deadBand;
	int expireDays;
	unsigned short pointType;
	char units[50];
	char instance[INFO_LENGTH];
	char instanceAttribute[INFO_LENGTH];
	char instanceAttributeDescription[INFO_LENGTH];
	char type[INFO_LENGTH];
	int minimumUpdateFreq;
	double dValue;
	int tTime;
	unsigned short status;
} HISTORY_POINT;

typedef struct
{
	HISTORY_POINT point;
	POINT_EXTEND_DATA data;
} HISTORY_POINT_EX;


typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	int expireDays;
	char units[50];
	char instance[INFO_LENGTH];
	char instanceAttribute[INFO_LENGTH];
	char instanceAttributeDescription[INFO_LENGTH];
	char type[INFO_LENGTH];
	int minimumUpdateFreq;
	char sValue[INFO_LENGTH];
	int tTime;
	unsigned short status;
} HISTORY_STRING_POINT;

typedef struct
{
	char name[INFO_LENGTH];
	char description[INFO_LENGTH];
	int expireDays;
	char units[50];
	char instance[INFO_LENGTH];
	char instanceAttribute[INFO_LENGTH];
	char instanceAttributeDescription[INFO_LENGTH];
	char type[INFO_LENGTH];
	int minimumUpdateFreq;
	char image[IMAGE_SIZE];
	int tTime;
	unsigned short status;
} HISTORY_IMAGE_POINT;

typedef struct
{
	int tTime;
	double dValue;
	unsigned short status;
} HISTORY_VALUE;

typedef struct
{
	int tTime;
	char sValue[INFO_LENGTH];
	unsigned short status;
} HISTORY_STRING_VALUE;

typedef struct
{
	char name[INFO_LENGTH];
	HISTORY_VALUE rec;
} POINT_VALUE;

typedef struct
{
	char name[INFO_LENGTH];
	HISTORY_STRING_VALUE rec;
} POINT_STRING_VALUE;

typedef struct
{
	int tTime;
	char image[IMAGE_SIZE];
	unsigned short status;
} HISTORY_IMAGE_VALUE;

typedef struct
{
	char name[INFO_LENGTH];
	HISTORY_IMAGE_VALUE rec;
} POINT_IMAGE_VALUE;


typedef struct
{
	HISTORY_VALUE maxValue;
	HISTORY_VALUE minValue;
	HISTORY_VALUE avgValue;
} HIST_STAT_VALUE;

typedef struct
{
	char name[INFO_LENGTH];
	int instanceCount;
} TYPE_INSTANCE_INFO;

typedef struct
{
	unsigned short n_days;      /* number of days until data expires */
	long           earliest;    /* time of earliest entry for this point */
	long           latest;      /* time of last entry for this point */
	long           n_entries;   /* how many entries available for point */
} POINT_INFO;


extern "C" EDOSPROXYAPI_API int InitCommunicationKey(unsigned long *key,bool cacheEnable,char *cacheFolder,int maxCacheSizeInMB);

extern "C" EDOSPROXYAPI_API int ConnectToServer(unsigned long key,char *serverIP,unsigned short serverPort);

extern "C" EDOSPROXYAPI_API int Login(unsigned long key,char *account,char *password);

extern "C" EDOSPROXYAPI_API int CreateServ(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int UpdateServ(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int DeleteServ(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int LoadAllServices(unsigned long key,HISTORY *service,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int LoadHistoryInfo(unsigned long key,HISTORY service,int *pointCount,int *capacity);

extern "C" EDOSPROXYAPI_API int CreateIdentity(unsigned long key,IDENTITY identity,PERMISSION *permission,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int UpdateIdentity(unsigned long key,IDENTITY identity,PERMISSION *permission,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int DeleteIdentity(unsigned long key,IDENTITY identity);

extern "C" EDOSPROXYAPI_API int LoadAllIdentity(unsigned long key,IDENTITY *identities,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int LoadIdentityPermission(unsigned long key,IDENTITY identity,PERMISSION *permission,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int LoadAllPermission(unsigned long key,PERMISSION *permission,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int CreateUser(unsigned long key,USER user,IDENTITY identity);

extern "C" EDOSPROXYAPI_API int UpdateUser(unsigned long key,USER user,IDENTITY identity);

extern "C" EDOSPROXYAPI_API int DeleteUser(unsigned long key,USER user);

extern "C" EDOSPROXYAPI_API int GetCurrentLoginIdentity(unsigned long key,IDENTITY *identity);

extern "C" EDOSPROXYAPI_API int LoadAllUsers(unsigned long key,USER *user,IDENTITY *identities,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int CreatePoint(unsigned long key,HISTORY_POINT point,IDENTITY *identities,unsigned short *usMode,unsigned short nCount); // usMode can be POINT_ALLOW_READ,POINT_ALLOW_WRITE,POINT_FULL_CONTROL

extern "C" EDOSPROXYAPI_API int UpdatePoint(unsigned long key,HISTORY_POINT point,IDENTITY *identities,unsigned short *usMode,unsigned short nCount); // usMode can be POINT_ALLOW_READ,POINT_ALLOW_WRITE,POINT_FULL_CONTROL

extern "C" EDOSPROXYAPI_API int DeletePoint(unsigned long key,HISTORY_POINT point);

extern "C" EDOSPROXYAPI_API int GetHistoryPoints(unsigned long key,HISTORY service,char *filterName,char *filterDesc,char *filterInstance,char * filterInstanceAttribute,char * filterInstanceAttributeDescription,char *type,HISTORY_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetHistoryPointsEX(unsigned long key, HISTORY service, char *filterName, char *filterDesc, char *filterInstance, char * filterInstanceAttribute, char * filterInstanceAttributeDescription, char *type, HISTORY_POINT_EX *point, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int SendMultiPoint(unsigned long key,POINT_VALUE *recs,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int SendMultiPointBigData(unsigned long key, POINT_VALUE *recs,int nCount);

extern "C" EDOSPROXYAPI_API int InitMultiPoint(unsigned long key, POINT_VALUE *recs, unsigned short nCount);

extern "C" EDOSPROXYAPI_API int InitMultiPointBigData(unsigned long key, POINT_VALUE *recs, int nCount);

extern "C" EDOSPROXYAPI_API int SendSinglePoint(unsigned long key,char *name,HISTORY_VALUE *recs,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int GetRTValue(unsigned long key,char *name,HISTORY_VALUE *rec);

extern "C" EDOSPROXYAPI_API int GetPointID(unsigned long key, char *name, int *id);

extern "C" EDOSPROXYAPI_API int GetRTValueList(unsigned long key,char **nameList,HISTORY_VALUE *rec,int nCount);

extern "C" EDOSPROXYAPI_API int GetHistSnap(unsigned long key,char *name,int tStart,int tEnd,int period,HISTORY_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetHistStat(unsigned long key,char *name,int tStart,int tEnd,int period,HIST_STAT_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetHistRaw(unsigned long key,char *name,int tStart,int tEnd,HISTORY_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetHistMatrix(unsigned long key,char **nameList,int tTime,HISTORY_VALUE *rec,int nCount);

extern "C" EDOSPROXYAPI_API int UpdatePointData(unsigned long key,char *name,HISTORY_VALUE *rec,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int UpdateBigPointData(unsigned long key, char *name, HISTORY_VALUE *rec, int nCount);

extern "C" EDOSPROXYAPI_API int GetPointIdentities(unsigned long key,char *name,IDENTITY *identities,unsigned short *usModes,unsigned short nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetPointInstances(unsigned long key,POINT_INSTANCE_INFO *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetInstancePoints(unsigned long key,char *instance,int start,int count,HISTORY_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetPointsUnderHistory(unsigned long key,char *history,int start,int count,HISTORY_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetPointInfo(unsigned long key,char *name,HISTORY_POINT *point);

extern "C" EDOSPROXYAPI_API int SendData(unsigned long key,unsigned char *data,unsigned long len);

extern "C" EDOSPROXYAPI_API int CreateStringPoint(unsigned long key,HISTORY_STRING_POINT point);

extern "C" EDOSPROXYAPI_API int UpdateStringPoint(unsigned long key,HISTORY_STRING_POINT point);

extern "C" EDOSPROXYAPI_API int DeleteStringPoint(unsigned long key,HISTORY_STRING_POINT point);

extern "C" EDOSPROXYAPI_API int SendMultiStringPoint(unsigned long key,POINT_STRING_VALUE *recs,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int SendSingleStringPoint(unsigned long key,char *name,HISTORY_STRING_VALUE *recs,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int GetPointsUnderStringHistory(unsigned long key,char *history,int start,int count,HISTORY_STRING_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetStringRTValue(unsigned long key,char *name,HISTORY_STRING_VALUE *rec);

extern "C" EDOSPROXYAPI_API int GetStringRTValueList(unsigned long key,char **nameList,HISTORY_STRING_VALUE *rec,int nCount);

extern "C" EDOSPROXYAPI_API int GetStringHistoryPoints(unsigned long key,HISTORY service,char *filterName,char *filterDesc,char *filterInstance,char * filterInstanceAttribute,char * filterInstanceAttributeDescription,char *type,HISTORY_STRING_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetStringHistSnap(unsigned long key,char *name,int tStart,int tEnd,int period,HISTORY_STRING_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetStringHistRaw(unsigned long key,char *name,int tStart,int tEnd,HISTORY_STRING_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetStringHistMatrix(unsigned long key,char **nameList,int tTime,HISTORY_STRING_VALUE *rec,int nCount);

extern "C" EDOSPROXYAPI_API int UpdateStringPointData(unsigned long key,char *name,HISTORY_STRING_VALUE *rec,unsigned short nCount);

extern "C" EDOSPROXYAPI_API int GetInstanceStringPoints(unsigned long key,char *instance,int start,int count,HISTORY_STRING_POINT *point,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int CreateStringService(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int UpdateStringService(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int DeleteStringService(unsigned long key,HISTORY service);

extern "C" EDOSPROXYAPI_API int GetStringPointInfo(unsigned long key,char *name,HISTORY_STRING_POINT *point);

extern "C" EDOSPROXYAPI_API int LoadAllTypes(unsigned long key,TYPE_INSTANCE_INFO *types,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetPointInstancesUnderType(unsigned long key,char* type,POINT_INSTANCE_INFO *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int DeletePointData(unsigned long key,char *name,int tStart,int tEnd);

extern "C" EDOSPROXYAPI_API int GetPointStat(unsigned long key,char *name,POINT_INFO* info);

extern "C" EDOSPROXYAPI_API bool IsConnected(unsigned long key);

extern "C" EDOSPROXYAPI_API int DisposeKey(unsigned long key);

extern "C" EDOSPROXYAPI_API int CreateOrUpdatePointExtendData(unsigned long key,char *name,POINT_EXTEND_DATA data);

extern "C" EDOSPROXYAPI_API int SearchPointExtendData(unsigned long key,char *name,POINT_EXTEND_DATA *data);

extern "C" EDOSPROXYAPI_API int DeletePointExtendData(unsigned long key,char *name);

extern "C" EDOSPROXYAPI_API int SearchPointExtendBackUpData(unsigned long key,char *name,int tStart,int tEnd,POINT_EXTEND_BACKUP_DATA *data,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetStringHistSnapRaw(unsigned long key,char *name,int tStart,int tEnd,int period,HISTORY_STRING_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int GetHistSnapRaw(unsigned long key,char *name,int tStart,int tEnd,int period,HISTORY_VALUE *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int CreateOrUpdateInstanceDesc(unsigned long key,POINT_INSTANCE_DESC desc);

extern "C" EDOSPROXYAPI_API int RemoveInstanceDesc(unsigned long key,char *instanceName);

extern "C" EDOSPROXYAPI_API int SearchInstance(unsigned long key,char *type,char *description,char *system,char *subSystem,POINT_INSTANCE_INFO *rec,int nCount,int *retsize);

extern "C" EDOSPROXYAPI_API int CreateImageService(unsigned long key, HISTORY service);

extern "C" EDOSPROXYAPI_API int UpdateImageService(unsigned long key, HISTORY service);

extern "C" EDOSPROXYAPI_API int DeleteImageService(unsigned long key, HISTORY service);

extern "C" EDOSPROXYAPI_API int CreateImagePoint(unsigned long key, HISTORY_IMAGE_POINT point);

extern "C" EDOSPROXYAPI_API int UpdateImagePoint(unsigned long key, HISTORY_IMAGE_POINT point);

extern "C" EDOSPROXYAPI_API int DeleteImagePoint(unsigned long key, HISTORY_IMAGE_POINT point);

extern "C" EDOSPROXYAPI_API int SendMultiImagePoint(unsigned long key, POINT_IMAGE_VALUE *recs, unsigned short nCount);

extern "C" EDOSPROXYAPI_API int SendSingleImagePoint(unsigned long key, char *name, HISTORY_IMAGE_VALUE *recs, unsigned short nCount);

extern "C" EDOSPROXYAPI_API int GetPointsUnderImageHistory(unsigned long key, char *history, int start, int count, HISTORY_IMAGE_POINT *point, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImageRTValue(unsigned long key, char *name, HISTORY_IMAGE_VALUE *rec);

extern "C" EDOSPROXYAPI_API int GetImageRTValueList(unsigned long key, char **nameList, HISTORY_IMAGE_VALUE *rec, int nCount);

extern "C" EDOSPROXYAPI_API int GetImageHistoryPoints(unsigned long key, HISTORY service, char *filterName, char *filterDesc, char *filterInstance, char * filterInstanceAttribute, char * filterInstanceAttributeDescription, char *type, HISTORY_IMAGE_POINT *point, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImageHistSnap(unsigned long key, char *name, int tStart, int tEnd, int period, HISTORY_IMAGE_VALUE *rec, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImageHistSnapRaw(unsigned long key, char *name, int tStart, int tEnd, int period, HISTORY_IMAGE_VALUE *rec, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImageHistRaw(unsigned long key, char *name, int tStart, int tEnd, HISTORY_IMAGE_VALUE *rec, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImageHistMatrix(unsigned long key, char **nameList, int tTime, HISTORY_IMAGE_VALUE *rec, int nCount);

extern "C" EDOSPROXYAPI_API int GetInstanceImagePoints(unsigned long key, char *instance, int start, int count, HISTORY_IMAGE_POINT *point, int nCount, int *retsize);

extern "C" EDOSPROXYAPI_API int GetImagePointInfo(unsigned long key, char *name, HISTORY_IMAGE_POINT *point);

extern "C" EDOSPROXYAPI_API int UpdateImagePointData(unsigned long key, char *name, HISTORY_IMAGE_VALUE *rec, unsigned short nCount);

extern "C" EDOSPROXYAPI_API int TracePoint(unsigned long key, char *name);

#pragma pack(pop, __EDOS_PROXY__)

#endif