Simplified IPC code to use less different IPC messages. Share more code. More qork on MQTT code.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/endpoint_tcpd.h>
|
||||
#include <gwenhywfar/endpoint_msgio.h>
|
||||
#include <gwenhywfar/endpoint_multilayer.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
@@ -113,7 +114,6 @@ int testMqttConnection2()
|
||||
AQH_Init();
|
||||
|
||||
epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", "127.0.0.1", 1883, NULL, 1);
|
||||
|
||||
for (loop=0;; loop++) {
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop);
|
||||
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
|
||||
@@ -199,6 +199,55 @@ int testMqttSubscribe2(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
int testMqttSubscribe3(int argc, char **argv)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epClient;
|
||||
int rv;
|
||||
//const char *host="127.0.0.1";
|
||||
const char *host="192.168.117.192";
|
||||
|
||||
AQH_Init();
|
||||
|
||||
if (argc>1)
|
||||
host=argv[1];
|
||||
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Connecting to %s (%s)", host, argv[1]);
|
||||
epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", host, 1883, NULL, 1);
|
||||
GWEN_MsgEndpoint_AddFlags(epClient, AQH_ENDPOINT2_MQTTCLIENT_FLAGS_SUBSCRIBEALL);
|
||||
rv=GWEN_MultilayerEndpoint_StartConnect(epClient);
|
||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
||||
DBG_ERROR(NULL, "Error on startConnect: %d", rv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient);
|
||||
if (msg) {
|
||||
if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0)) {
|
||||
GWEN_BUFFER *buf;
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
AQH_PublishMqttMsg_DumpToBuffer(msg, buf, "received");
|
||||
fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Received this message:");
|
||||
GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2);
|
||||
}
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _mqttConnect2(GWEN_MSG_ENDPOINT *epClient)
|
||||
{
|
||||
int loop;
|
||||
@@ -423,6 +472,7 @@ int main(int argc, char **argv)
|
||||
//return testMqttConnection2();
|
||||
//return testMqttSubscribe2(argc, argv);
|
||||
//return testHttpDaemon();
|
||||
return testMqttSubscribe3(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user