aqhome: started working on MTQQ client.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "aqhome/msg/endpoint_log.h"
|
||||
#include "aqhome/msg/endpoint_tty.h"
|
||||
#include "aqhome/ipc/endpoint_node_ipc_tcp.h"
|
||||
#include "aqhome/mqtt/endpoint_mqttc.h"
|
||||
#include "aqhome/mqtt/msg_mqtt_connect.h"
|
||||
#include "aqhome/msgmanager.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
@@ -17,7 +19,8 @@
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/gwentime.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/endpoint_ipc_tcp.h>
|
||||
#include <gwenhywfar/endpoint_tcpd_ipc.h>
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
@@ -120,7 +123,7 @@ int testEndpoints()
|
||||
}
|
||||
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epLog);
|
||||
|
||||
epTcp=AQH_TcpIpcNodeEndpoint_new(NULL, "127.0.0.1", 45454, AQH_MSGMGR_ENDPOINTGROUP_IPC);
|
||||
epTcp=AQH_TcpdIpcNodeEndpoint_new("127.0.0.1", 45454, NULL, AQH_MSGMGR_ENDPOINTGROUP_IPC);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error creating endpoint TCP");
|
||||
return 2;
|
||||
@@ -136,11 +139,92 @@ int testEndpoints()
|
||||
|
||||
|
||||
|
||||
int testMsgMqttConnect()
|
||||
{
|
||||
GWEN_MSG *msg;
|
||||
GWEN_BUFFER *dbuf;
|
||||
|
||||
msg=GWEN_ConnectMqttMsg_new("MQTT", 4,
|
||||
AQH_MQTTMSG_CONNECT_FLAGS_USERNAME | AQH_MQTTMSG_CONNECT_FLAGS_PASSWD,
|
||||
512,
|
||||
"CLIENTID123",
|
||||
"USER123",
|
||||
"PASSWD123");
|
||||
if (msg==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return 2;
|
||||
}
|
||||
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
AQH_ConnectMqttMsg_DumpToBuffer(msg, dbuf, "created");
|
||||
fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(dbuf));
|
||||
GWEN_Buffer_free(dbuf);
|
||||
|
||||
GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testMqttConnection()
|
||||
{
|
||||
int rv;
|
||||
GWEN_MSG_ENDPOINT_MGR *emgr;
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
rv=AQH_Init();
|
||||
if (rv<0) {
|
||||
}
|
||||
|
||||
//emgr=AQH_MsgManager_new(0xc0);
|
||||
emgr=GWEN_MsgEndpointMgr_new();
|
||||
|
||||
epTcp=AQH_MqttClientEndpoint_new("127.0.0.1", 1883, "MQTTClient", 0);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating endpoint TCPc");
|
||||
return 2;
|
||||
}
|
||||
GWEN_MsgEndpointMgr_AddEndpoint(emgr, epTcp);
|
||||
rv=GWEN_TcpcEndpoint_StartConnect(epTcp);
|
||||
if (rv<0) {
|
||||
DBG_ERROR(NULL, "Error starting connect (%d)", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
msgOut=GWEN_ConnectMqttMsg_new("MQTT", 4, 0, 10, "CLIENTID123", NULL, NULL);
|
||||
if (msgOut==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return 2;
|
||||
}
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Next loop");
|
||||
//GWEN_MsgManager_LoopOnce(emgr);
|
||||
GWEN_MsgEndpointMgr_IoLoopOnce(emgr);
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
DBG_ERROR(NULL, "Received this message:");
|
||||
GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2);
|
||||
GWEN_Msg_free(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return testEndpoints();
|
||||
//return testEndpoints();
|
||||
//return testMsgMqttConnect();
|
||||
return testMqttConnection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user