Hi,
I have another questions , in order to test just the sending, i have created a file named client3.cpp which enable to connect with the agent.I also added in the fonction that is in the file Agent and which enable to send a message to the agent;
/*--Sending--*/
CSCPMessage *pMsg;
CSCP_MESSAGE *pRawMsg;
BOOL bResult;
pRawMsg = pMsg->CreateMessage();
bResult = (SendEx(m_hSocket, (char *)pRawMsg, ntohl(pRawMsg->dwSize), 0) == (int)ntohl(pRawMsg->dwSize));
free(pRawMsg);
return bResult;
In order to test. I create also a header where i have included the class and structure that i needed.
#ifndef _CSCPMessage_h_
#define _CSCPMessage_h_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "nms_common.h"
//#include "netxms-regex.h"
#define VID_RCC ((float)28) /* RCC == Request Completion Code */
#define CMD_REQUEST_COMPLETED 0x001D
#define CMD_KEEPALIVE 0x0003
typedef struct
{
DWORD dwBufSize;
DWORD dwBufPos;
char szBuffer[10000000];
} CSCP_BUFFER;
/*--Structure CSCP_DF--*/
typedef struct
{
DWORD dwVarId; // Variable identifier
BYTE bType; // Data type
BYTE bPadding; // Padding
WORD wInt16;
union
{
DWORD dwInteger;
//QWORD qwInt64;
double dFloat;
struct
{
DWORD dwLen;
WORD szValue[1];
} string;
} data;
} CSCP_DF;
/*--Structure CSCP_MESSAGE--*/
typedef struct
{
WORD wCode; // Message (command) code
WORD wFlags; // Message flags
DWORD dwSize; // Message size (including header) in bytes
DWORD dwId; // Unique message identifier
DWORD dwNumVars; // Number of variables in message
CSCP_DF df[1]; // Data fields
} CSCP_MESSAGE;
/*--Classe CSCPMessage--*/
class LIBNETXMS_EXPORTABLE CSCPMessage
{
private:
WORD m_wCode;
WORD m_wFlags;
DWORD m_dwId;
DWORD m_dwNumVar; // Number of variables
CSCP_DF **m_ppVarList; // List of variables
int m_nVersion; // Protocol version
void *Set(DWORD dwVarId, BYTE bType, const void *pValue, DWORD dwSize = 0);
void *Get(DWORD dwVarId, BYTE bType);
DWORD FindVariable(DWORD dwVarId);
public:
CSCPMessage(int nVersion = NXCP_VERSION);
CSCPMessage(CSCPMessage *pMsg);
CSCPMessage(CSCP_MESSAGE *pMsg, int nVersion = NXCP_VERSION);
CSCPMessage(const char *xml);
~CSCPMessage();
CSCP_MESSAGE *CreateMessage(void);
char *CreateXML(void);
void ProcessXMLToken(void *state, const char **attrs);
void ProcessXMLData(void *state);
WORD GetCode(void) { return m_wCode; }
void SetCode(WORD wCode) { m_wCode = wCode; }
DWORD GetId(void) { return m_dwId; }
void SetId(DWORD dwId) { m_dwId = dwId; }
BOOL IsVariableExist(DWORD dwVarId) { return (FindVariable(dwVarId) != INVALID_INDEX) ? TRUE : FALSE; }
BOOL IsEndOfSequence(void) { return (m_wFlags & MF_END_OF_SEQUENCE) ? TRUE : FALSE; }
BOOL IsReverseOrder(void) { return (m_wFlags & MF_REVERSE_ORDER) ? TRUE : FALSE; }
void SetVariable(DWORD dwVarId, WORD wValue) { Set(dwVarId, CSCP_DT_INT16, &wValue); }
void SetVariable(DWORD dwVarId, DWORD dwValue) { Set(dwVarId, CSCP_DT_INTEGER, &dwValue); }
void SetVariable(DWORD dwVarId, QWORD qwValue) { Set(dwVarId, CSCP_DT_INT64, &qwValue); }
void SetVariable(DWORD dwVarId, double dValue) { Set(dwVarId, CSCP_DT_FLOAT, &dValue); }
void SetVariable(DWORD dwVarId, const TCHAR *pszValue) { Set(dwVarId, CSCP_DT_STRING, pszValue); }
void SetVariable(DWORD dwVarId, BYTE *pValue, DWORD dwSize) { Set(dwVarId, CSCP_DT_BINARY, pValue, dwSize); }
void SetVariableToInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwData);
BOOL SetVariableFromFile(DWORD dwVarId, const TCHAR *pszFileName);
DWORD GetVariableLong(DWORD dwVarId);
QWORD GetVariableInt64(DWORD dwVarId);
WORD GetVariableShort(DWORD dwVarId);
LONG GetVariableShortAsInt32(DWORD dwVarId);
double GetVariableDouble(DWORD dwVarId);
TCHAR *GetVariableStr(DWORD dwVarId, TCHAR *szBuffer = NULL, DWORD dwBufSize = 0);
DWORD GetVariableBinary(DWORD dwVarId, BYTE *pBuffer, DWORD dwBufSize);
DWORD GetVariableInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwBuffer);
void DeleteAllVariables(void);
void DisableEncryption(void) { m_wFlags |= MF_DONT_ENCRYPT; }
void SetEndOfSequence(void) { m_wFlags |= MF_END_OF_SEQUENCE; }
void SetReverseOrderFlag(void) { m_wFlags |= MF_REVERSE_ORDER; }
};
//
// Message waiting queue class
//
class LIBNETXMS_EXPORTABLE MsgWaitQueue
{
private:
MUTEX m_mutexDataAccess;
CONDITION m_condStop;
CONDITION m_condNewMsg;
DWORD m_dwMsgHoldTime;
DWORD m_dwNumElements;
WAIT_QUEUE_ELEMENT *m_pElements;
THREAD m_hHkThread;
void Lock(void) { MutexLock(m_mutexDataAccess, INFINITE); }
void Unlock(void) { MutexUnlock(m_mutexDataAccess); }
void HousekeeperThread(void);
void *WaitForMessageInternal(WORD wIsBinary, WORD wCode, DWORD dwId, DWORD dwTimeOut);
static THREAD_RESULT THREAD_CALL MWQThreadStarter(void *);
public:
MsgWaitQueue();
~MsgWaitQueue();
void Put(CSCPMessage *pMsg);
void Put(CSCP_MESSAGE *pMsg);
CSCPMessage *WaitForMessage(WORD wCode, DWORD dwId, DWORD dwTimeOut)
{
return (CSCPMessage *)WaitForMessageInternal(0, wCode, dwId, dwTimeOut);
}
CSCP_MESSAGE *WaitForRawMessage(WORD wCode, DWORD dwId, DWORD dwTimeOut)
{
return (CSCP_MESSAGE *)WaitForMessageInternal(1, wCode, dwId, dwTimeOut);
}
void Clear(void);
void SetHoldTime(DWORD dwHoldTime) { m_dwMsgHoldTime = dwHoldTime; }
};
#endif /* _CSCPMessage_h_ */
I include in it the link to "nms_common.h" for the definition of the type DWORD, word ETC.
In my makefile, i have integrated the file message.c
When i compile, it didn t work.
g++ client3.cpp -c -I /usr/local/include -I ./include -o client3.o
In file included from client3.cpp:11:
include/CSCPMessage.h:59: error: syntax error before `{' token
include/CSCPMessage.h:71: error: syntax error before `public'
In file included from client3.cpp:11:
include/CSCPMessage.h:4:1: unterminated #ifndef
*** Error code 1
There is a problem with the class CSCPMessage. Do i have forget a header to include?
I also wanted to know what is LIBNETXMS_EXPORTABLE?
I searched in the header nms util but i dont understand the using of it.
Sorry to disturb you :-
Thank you