//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <stdio.h>
+#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
static int g_testCase = 0;
static int g_connectivity = 0;
+static GMainLoop *g_mainloop = NULL;
+pthread_t g_thread;
+
static const char *DEVICE_DISCOVERY_QUERY = "%s/oic/d";
static const char *PLATFORM_DISCOVERY_QUERY = "%s/oic/p";
static const char *RESOURCE_DISCOVERY_QUERY = "%s/oic/res";
if(clientResponse)
{
cout << "\nStackResult: " << getResult(clientResponse->result);
- //OC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ //OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
}
else
{
cout << "\nStackResult: " << getResult(clientResponse->result);
cout << "\nSEQUENCE NUMBER: " << clientResponse->sequenceNumber;
- //OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
+ //OIC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
if (clientResponse->numRcvdVendorSpecificHeaderOptions > 0)
{
cout << "\nStackResult: " << getResult(clientResponse->result);
cout << "\nSEQUENCE NUMBER: " << clientResponse->sequenceNumber;
cout << "\nCallback Context for OBSERVE notification recvd successfully ";
- //OC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ //OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
gNumObserveNotifies++;
if (gNumObserveNotifies == 15) //large number to test observing in DELETE case.
{
cout << "\nStackResult: " << getResult(clientResponse->result);
cout << "\nNONCE NUMBER: " << clientResponse->sequenceNumber;
cout << "\nCallback Context for Presence notification recvd successfully ";
- //OC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ //OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
gNumPresenceNotifies++;
if (gNumPresenceNotifies == 20)
{
{
cout << ":" << clientResponse->devAddr.port;
}
- //OC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ //OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
cout << "\nConnectivity type: " << clientResponse->connType;
g_connType = clientResponse->connType;
g_serverAddr = clientResponse->devAddr;
if (clientResponse)
{
- //OC_LOG truncates the response as it is too long.
- //OC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ //OIC_LOG truncates the response as it is too long.
+ //OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
}
else
{
if (clientResponse)
{
- //OC_LOG truncates the response as it is too long.
+ //OIC_LOG truncates the response as it is too long.
cout << "\nDiscovery response: ";
cout << clientResponse->payload;
}
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[64] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, PLATFORM_DISCOVERY_QUERY, g_discoveryAddr);
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[100] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, DEVICE_DISCOVERY_QUERY, g_discoveryAddr);
{
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[100] = { 0 };
+ char szQueryUri[MAX_QUERY_LENGTH] = { 0 };
snprintf(szQueryUri, sizeof (szQueryUri) - 1, RESOURCE_DISCOVERY_QUERY, g_discoveryAddr);
return ret;
}
+void *GMainLoopThread(void *param)
+{
+
+ if (g_unicastDiscovery == 0 && g_testCase == TEST_DISCOVER_DEV_REQ)
+ {
+ InitDeviceDiscovery(OC_LOW_QOS);
+ }
+ else if (g_unicastDiscovery == 0 && g_testCase == TEST_DISCOVER_PLATFORM_REQ)
+ {
+ InitPlatformDiscovery(OC_LOW_QOS);
+ }
+ else
+ {
+ InitDiscovery(OC_LOW_QOS);
+ }
+
+ while (!gQuitFlag)
+ {
+ if (OCProcess() != OC_STACK_OK)
+ {
+ cout << "\nOCStack process error";
+ return NULL;
+ }
+#ifndef ROUTING_GATEWAY
+ sleep(1);
+#endif
+ }
+
+ if (g_mainloop)
+ {
+ g_main_loop_quit(g_mainloop);
+ }
+ return NULL;
+}
+
int main(int argc, char* argv[])
{
int opt;
+ g_mainloop = g_main_loop_new(NULL, FALSE);
+ if(!g_mainloop)
+ {
+ printf("g_main_loop_new failed\n");
+ return 0;
+ }
+
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
{
switch(opt)
{
if (OCProcess() != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack process error");
+ OIC_LOG(ERROR, TAG, "OCStack process error");
return 0;
}
usleep(SLEEP_DURATION);
}
}
- if (g_unicastDiscovery == 0 && g_testCase == TEST_DISCOVER_DEV_REQ)
- {
- InitDeviceDiscovery(OC_LOW_QOS);
- }
- else if (g_unicastDiscovery == 0 && g_testCase == TEST_DISCOVER_PLATFORM_REQ)
- {
- InitPlatformDiscovery(OC_LOW_QOS);
- }
- else
- {
- InitDiscovery(OC_LOW_QOS);
- }
// Break from loop with Ctrl+C
- OC_LOG(INFO, TAG, "Entering occlient main loop...");
+ OIC_LOG(INFO, TAG, "Entering occlient main loop...");
signal(SIGINT, handleSigInt);
- while (!gQuitFlag)
- {
- if (OCProcess() != OC_STACK_OK)
- {
- cout << "\nOCStack process error\n";
- return 0;
- }
-#ifndef ROUTING_GATEWAY
- sleep(1);
-#endif
+ int result = pthread_create(&g_thread, NULL, GMainLoopThread, (void *)NULL);
+ if (result < 0)
+ {
+ printf("pthread_create failed in initialize\n");
+ return 0;
}
+ g_main_loop_run(g_mainloop);
+
cout << "\nExiting occlient main loop...\n";
if (OCStop() != OC_STACK_OK)